summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto')
-rw-r--r--src/lib/libcrypto/LPdir_nyi.c42
-rw-r--r--src/lib/libcrypto/LPdir_unix.c127
-rw-r--r--src/lib/libcrypto/LPdir_vms.c199
-rw-r--r--src/lib/libcrypto/LPdir_win.c155
-rw-r--r--src/lib/libcrypto/LPdir_win32.c30
-rw-r--r--src/lib/libcrypto/LPdir_wince.c31
-rw-r--r--src/lib/libcrypto/Makefile.ssl218
-rw-r--r--src/lib/libcrypto/acss/acss.h47
-rw-r--r--src/lib/libcrypto/acss/acss_enc.c177
-rw-r--r--src/lib/libcrypto/acss/acss_skey.c86
-rw-r--r--src/lib/libcrypto/aes/Makefile130
-rw-r--r--src/lib/libcrypto/aes/Makefile.ssl103
-rw-r--r--src/lib/libcrypto/aes/aes.h27
-rw-r--r--src/lib/libcrypto/aes/aes_cbc.c2
-rw-r--r--src/lib/libcrypto/aes/aes_core.c304
-rw-r--r--src/lib/libcrypto/aes/aes_locl.h6
-rw-r--r--src/lib/libcrypto/aes/aes_misc.c2
-rw-r--r--src/lib/libcrypto/aes/asm/aes-586.pl1657
-rw-r--r--src/lib/libcrypto/asn1/Makefile885
-rw-r--r--src/lib/libcrypto/asn1/Makefile.ssl1152
-rw-r--r--src/lib/libcrypto/asn1/a_bitstr.c13
-rw-r--r--src/lib/libcrypto/asn1/a_bool.c4
-rw-r--r--src/lib/libcrypto/asn1/a_bytes.c24
-rw-r--r--src/lib/libcrypto/asn1/a_d2i_fp.c32
-rw-r--r--src/lib/libcrypto/asn1/a_digest.c2
-rw-r--r--src/lib/libcrypto/asn1/a_dup.c18
-rw-r--r--src/lib/libcrypto/asn1/a_enum.c12
-rw-r--r--src/lib/libcrypto/asn1/a_gentm.c246
-rw-r--r--src/lib/libcrypto/asn1/a_hdr.c119
-rw-r--r--src/lib/libcrypto/asn1/a_i2d_fp.c8
-rw-r--r--src/lib/libcrypto/asn1/a_int.c26
-rw-r--r--src/lib/libcrypto/asn1/a_mbstr.c20
-rw-r--r--src/lib/libcrypto/asn1/a_meth.c84
-rw-r--r--src/lib/libcrypto/asn1/a_object.c100
-rw-r--r--src/lib/libcrypto/asn1/a_octet.c2
-rw-r--r--src/lib/libcrypto/asn1/a_set.c21
-rw-r--r--src/lib/libcrypto/asn1/a_sign.c23
-rw-r--r--src/lib/libcrypto/asn1/a_strex.c32
-rw-r--r--src/lib/libcrypto/asn1/a_type.c28
-rw-r--r--src/lib/libcrypto/asn1/a_utctm.c303
-rw-r--r--src/lib/libcrypto/asn1/a_verify.c12
-rw-r--r--src/lib/libcrypto/asn1/asn1.h341
-rw-r--r--src/lib/libcrypto/asn1/asn1_err.c91
-rw-r--r--src/lib/libcrypto/asn1/asn1_lib.c73
-rw-r--r--src/lib/libcrypto/asn1/asn1_mac.h39
-rw-r--r--src/lib/libcrypto/asn1/asn1_par.c58
-rw-r--r--src/lib/libcrypto/asn1/asn1t.h109
-rw-r--r--src/lib/libcrypto/asn1/asn_moid.c64
-rw-r--r--src/lib/libcrypto/asn1/asn_pack.c26
-rw-r--r--src/lib/libcrypto/asn1/d2i_pr.c24
-rw-r--r--src/lib/libcrypto/asn1/d2i_pu.c19
-rw-r--r--src/lib/libcrypto/asn1/evp_asn1.c4
-rw-r--r--src/lib/libcrypto/asn1/f.c80
-rw-r--r--src/lib/libcrypto/asn1/i2d_pr.c9
-rw-r--r--src/lib/libcrypto/asn1/i2d_pu.c7
-rw-r--r--src/lib/libcrypto/asn1/n_pkey.c49
-rw-r--r--src/lib/libcrypto/asn1/p5_pbe.c15
-rw-r--r--src/lib/libcrypto/asn1/p5_pbev2.c6
-rw-r--r--src/lib/libcrypto/asn1/p8_key.c131
-rw-r--r--src/lib/libcrypto/asn1/t_crl.c4
-rw-r--r--src/lib/libcrypto/asn1/t_pkey.c548
-rw-r--r--src/lib/libcrypto/asn1/t_req.c22
-rw-r--r--src/lib/libcrypto/asn1/t_spki.c16
-rw-r--r--src/lib/libcrypto/asn1/t_x509.c39
-rw-r--r--src/lib/libcrypto/asn1/tasn_dec.c1059
-rw-r--r--src/lib/libcrypto/asn1/tasn_enc.c514
-rw-r--r--src/lib/libcrypto/asn1/tasn_fre.c149
-rw-r--r--src/lib/libcrypto/asn1/tasn_new.c234
-rw-r--r--src/lib/libcrypto/asn1/tasn_typ.c4
-rw-r--r--src/lib/libcrypto/asn1/tasn_utl.c128
-rw-r--r--src/lib/libcrypto/asn1/x_algor.c57
-rw-r--r--src/lib/libcrypto/asn1/x_bignum.c6
-rw-r--r--src/lib/libcrypto/asn1/x_cinf.c201
-rw-r--r--src/lib/libcrypto/asn1/x_crl.c2
-rw-r--r--src/lib/libcrypto/asn1/x_exten.c5
-rw-r--r--src/lib/libcrypto/asn1/x_long.c8
-rw-r--r--src/lib/libcrypto/asn1/x_name.c52
-rw-r--r--src/lib/libcrypto/asn1/x_pkey.c6
-rw-r--r--src/lib/libcrypto/asn1/x_pubkey.c285
-rw-r--r--src/lib/libcrypto/asn1/x_req.c2
-rw-r--r--src/lib/libcrypto/asn1/x_x509.c27
-rw-r--r--src/lib/libcrypto/asn1/x_x509a.c29
-rw-r--r--src/lib/libcrypto/bf/Makefile107
-rw-r--r--src/lib/libcrypto/bf/Makefile.ssl115
-rw-r--r--src/lib/libcrypto/bf/asm/bf-586.pl2
-rw-r--r--src/lib/libcrypto/bf/asm/bf-686.pl127
-rw-r--r--src/lib/libcrypto/bf/asm/readme10
-rw-r--r--src/lib/libcrypto/bf/bf_ecb.c2
-rw-r--r--src/lib/libcrypto/bf/bf_enc.c4
-rw-r--r--src/lib/libcrypto/bf/bf_opts.c328
-rw-r--r--src/lib/libcrypto/bf/bf_skey.c4
-rw-r--r--src/lib/libcrypto/bf/bfs.cpp67
-rw-r--r--src/lib/libcrypto/bf/bfspeed.c274
-rw-r--r--src/lib/libcrypto/bf/bftest.c536
-rw-r--r--src/lib/libcrypto/bf/blowfish.h5
-rw-r--r--src/lib/libcrypto/bio/Makefile221
-rw-r--r--src/lib/libcrypto/bio/Makefile.ssl216
-rw-r--r--src/lib/libcrypto/bio/b_dump.c75
-rw-r--r--src/lib/libcrypto/bio/b_print.c25
-rw-r--r--src/lib/libcrypto/bio/b_sock.c60
-rw-r--r--src/lib/libcrypto/bio/bf_nbio.c4
-rw-r--r--src/lib/libcrypto/bio/bio.h133
-rw-r--r--src/lib/libcrypto/bio/bio_err.c10
-rw-r--r--src/lib/libcrypto/bio/bio_lcl.h28
-rw-r--r--src/lib/libcrypto/bio/bio_lib.c60
-rw-r--r--src/lib/libcrypto/bio/bss_acpt.c4
-rw-r--r--src/lib/libcrypto/bio/bss_conn.c10
-rw-r--r--src/lib/libcrypto/bio/bss_fd.c30
-rw-r--r--src/lib/libcrypto/bio/bss_file.c109
-rw-r--r--src/lib/libcrypto/bio/bss_log.c2
-rw-r--r--src/lib/libcrypto/bio/bss_rtcp.c294
-rw-r--r--src/lib/libcrypto/bio/bss_sock.c7
-rw-r--r--src/lib/libcrypto/bn/Makefile351
-rw-r--r--src/lib/libcrypto/bn/Makefile.ssl326
-rw-r--r--src/lib/libcrypto/bn/asm/README27
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s3199
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.s.works533
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/add.pl119
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/div.pl144
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul.pl116
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl120
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl213
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl98
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl177
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr.pl113
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl109
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl132
-rw-r--r--src/lib/libcrypto/bn/asm/alpha.works/sub.pl108
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/add.pl118
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/div.pl144
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul.pl104
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_add.pl123
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c4.pl215
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl98
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/mul_c8.pl177
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr.pl113
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl109
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl132
-rw-r--r--src/lib/libcrypto/bn/asm/alpha/sub.pl108
-rw-r--r--src/lib/libcrypto/bn/asm/bn-586.pl86
-rw-r--r--src/lib/libcrypto/bn/asm/bn-alpha.pl571
-rw-r--r--src/lib/libcrypto/bn/asm/ca.pl33
-rw-r--r--src/lib/libcrypto/bn/asm/co-alpha.pl116
-rw-r--r--src/lib/libcrypto/bn/asm/ia64.S35
-rw-r--r--src/lib/libcrypto/bn/asm/mips1.s539
-rw-r--r--src/lib/libcrypto/bn/asm/mips3.s2201
-rw-r--r--src/lib/libcrypto/bn/asm/mo-586.pl603
-rw-r--r--src/lib/libcrypto/bn/asm/pa-risc.s710
-rw-r--r--src/lib/libcrypto/bn/asm/r3000.s646
-rw-r--r--src/lib/libcrypto/bn/asm/vms.mar6440
-rw-r--r--src/lib/libcrypto/bn/asm/x86/f3
-rw-r--r--src/lib/libcrypto/bn/bn.h399
-rw-r--r--src/lib/libcrypto/bn/bn.mul19
-rw-r--r--src/lib/libcrypto/bn/bn_add.c96
-rw-r--r--src/lib/libcrypto/bn/bn_asm.c28
-rw-r--r--src/lib/libcrypto/bn/bn_blind.c249
-rw-r--r--src/lib/libcrypto/bn/bn_ctx.c417
-rw-r--r--src/lib/libcrypto/bn/bn_div.c299
-rw-r--r--src/lib/libcrypto/bn/bn_err.c29
-rw-r--r--src/lib/libcrypto/bn/bn_exp.c133
-rw-r--r--src/lib/libcrypto/bn/bn_exp2.c56
-rw-r--r--src/lib/libcrypto/bn/bn_gcd.c164
-rw-r--r--src/lib/libcrypto/bn/bn_kron.c8
-rw-r--r--src/lib/libcrypto/bn/bn_lcl.h114
-rw-r--r--src/lib/libcrypto/bn/bn_lib.c225
-rw-r--r--src/lib/libcrypto/bn/bn_mod.c7
-rw-r--r--src/lib/libcrypto/bn/bn_mont.c377
-rw-r--r--src/lib/libcrypto/bn/bn_mpi.c1
-rw-r--r--src/lib/libcrypto/bn/bn_mul.c539
-rw-r--r--src/lib/libcrypto/bn/bn_prime.c114
-rw-r--r--src/lib/libcrypto/bn/bn_prime.h4
-rw-r--r--src/lib/libcrypto/bn/bn_prime.pl6
-rw-r--r--src/lib/libcrypto/bn/bn_print.c41
-rw-r--r--src/lib/libcrypto/bn/bn_rand.c24
-rw-r--r--src/lib/libcrypto/bn/bn_recp.c22
-rw-r--r--src/lib/libcrypto/bn/bn_shift.c27
-rw-r--r--src/lib/libcrypto/bn/bn_sqr.c18
-rw-r--r--src/lib/libcrypto/bn/bn_sqrt.c76
-rw-r--r--src/lib/libcrypto/bn/bn_word.c67
-rw-r--r--src/lib/libcrypto/bn/bnspeed.c233
-rw-r--r--src/lib/libcrypto/bn/bntest.c1290
-rw-r--r--src/lib/libcrypto/bn/divtest.c41
-rw-r--r--src/lib/libcrypto/bn/exp.c62
-rw-r--r--src/lib/libcrypto/bn/expspeed.c353
-rw-r--r--src/lib/libcrypto/bn/exptest.c201
-rw-r--r--src/lib/libcrypto/bn/todo3
-rw-r--r--src/lib/libcrypto/bn/vms-helper.c68
-rw-r--r--src/lib/libcrypto/buffer/Makefile90
-rw-r--r--src/lib/libcrypto/buffer/Makefile.ssl94
-rw-r--r--src/lib/libcrypto/buffer/buf_err.c12
-rw-r--r--src/lib/libcrypto/buffer/buffer.c31
-rw-r--r--src/lib/libcrypto/buffer/buffer.h17
-rw-r--r--src/lib/libcrypto/camellia/Makefile103
-rw-r--r--src/lib/libcrypto/cast/Makefile106
-rw-r--r--src/lib/libcrypto/cast/Makefile.ssl120
-rw-r--r--src/lib/libcrypto/cast/asm/cast-586.pl2
-rw-r--r--src/lib/libcrypto/cast/asm/readme7
-rw-r--r--src/lib/libcrypto/cast/c_ecb.c2
-rw-r--r--src/lib/libcrypto/cast/c_enc.c2
-rw-r--r--src/lib/libcrypto/cast/c_skey.c5
-rw-r--r--src/lib/libcrypto/cast/cast.h7
-rw-r--r--src/lib/libcrypto/cast/cast_spd.c275
-rw-r--r--src/lib/libcrypto/cast/castopts.c339
-rw-r--r--src/lib/libcrypto/cast/casts.cpp70
-rw-r--r--src/lib/libcrypto/cast/casttest.c232
-rw-r--r--src/lib/libcrypto/cms/Makefile183
-rw-r--r--src/lib/libcrypto/comp/Makefile108
-rw-r--r--src/lib/libcrypto/comp/Makefile.ssl114
-rw-r--r--src/lib/libcrypto/comp/c_zlib.c600
-rw-r--r--src/lib/libcrypto/comp/comp.h37
-rw-r--r--src/lib/libcrypto/comp/comp_err.c26
-rw-r--r--src/lib/libcrypto/comp/comp_lib.c6
-rw-r--r--src/lib/libcrypto/conf/Makefile152
-rw-r--r--src/lib/libcrypto/conf/Makefile.ssl183
-rw-r--r--src/lib/libcrypto/conf/cnf_save.c106
-rw-r--r--src/lib/libcrypto/conf/conf.h6
-rw-r--r--src/lib/libcrypto/conf/conf_api.c2
-rw-r--r--src/lib/libcrypto/conf/conf_def.c36
-rw-r--r--src/lib/libcrypto/conf/conf_err.c11
-rw-r--r--src/lib/libcrypto/conf/conf_lib.c4
-rw-r--r--src/lib/libcrypto/conf/conf_mod.c17
-rw-r--r--src/lib/libcrypto/conf/conf_sap.c4
-rw-r--r--src/lib/libcrypto/conf/test.c98
-rw-r--r--src/lib/libcrypto/cpt_err.c9
-rw-r--r--src/lib/libcrypto/cryptlib.c226
-rw-r--r--src/lib/libcrypto/cryptlib.h8
-rw-r--r--src/lib/libcrypto/crypto-lib.com1299
-rw-r--r--src/lib/libcrypto/crypto.h182
-rw-r--r--src/lib/libcrypto/cversion.c3
-rw-r--r--src/lib/libcrypto/des/DES.pm19
-rw-r--r--src/lib/libcrypto/des/DES.xs268
-rw-r--r--src/lib/libcrypto/des/FILES096
-rw-r--r--src/lib/libcrypto/des/INSTALL69
-rw-r--r--src/lib/libcrypto/des/Imakefile35
-rw-r--r--src/lib/libcrypto/des/KERBEROS41
-rw-r--r--src/lib/libcrypto/des/Makefile292
-rw-r--r--src/lib/libcrypto/des/Makefile.ssl316
-rw-r--r--src/lib/libcrypto/des/README54
-rw-r--r--src/lib/libcrypto/des/VERSION412
-rw-r--r--src/lib/libcrypto/des/asm/des-586.pl12
-rw-r--r--src/lib/libcrypto/des/asm/des686.pl230
-rw-r--r--src/lib/libcrypto/des/asm/readme131
-rw-r--r--src/lib/libcrypto/des/cbc3_enc.c99
-rw-r--r--src/lib/libcrypto/des/cfb64ede.c4
-rw-r--r--src/lib/libcrypto/des/cfb_enc.c71
-rw-r--r--src/lib/libcrypto/des/des-lib.com1003
-rw-r--r--src/lib/libcrypto/des/des.c932
-rw-r--r--src/lib/libcrypto/des/des.h17
-rw-r--r--src/lib/libcrypto/des/des.pod217
-rw-r--r--src/lib/libcrypto/des/des3s.cpp67
-rw-r--r--src/lib/libcrypto/des/des_enc.c10
-rw-r--r--src/lib/libcrypto/des/des_locl.h2
-rw-r--r--src/lib/libcrypto/des/des_old.c271
-rw-r--r--src/lib/libcrypto/des/des_old.h441
-rw-r--r--src/lib/libcrypto/des/des_old2.c82
-rw-r--r--src/lib/libcrypto/des/des_opts.c604
-rw-r--r--src/lib/libcrypto/des/des_ver.h71
-rw-r--r--src/lib/libcrypto/des/dess.cpp67
-rw-r--r--src/lib/libcrypto/des/destest.c948
-rw-r--r--src/lib/libcrypto/des/ecb3_enc.c4
-rw-r--r--src/lib/libcrypto/des/ecb_enc.c4
-rw-r--r--src/lib/libcrypto/des/ede_cbcm_enc.c2
-rw-r--r--src/lib/libcrypto/des/fcrypt.c3
-rw-r--r--src/lib/libcrypto/des/makefile.bc50
-rw-r--r--src/lib/libcrypto/des/options.txt39
-rw-r--r--src/lib/libcrypto/des/read2pwd.c139
-rw-r--r--src/lib/libcrypto/des/read_pwd.c521
-rw-r--r--src/lib/libcrypto/des/rpc_des.h131
-rw-r--r--src/lib/libcrypto/des/rpc_enc.c98
-rw-r--r--src/lib/libcrypto/des/rpw.c99
-rw-r--r--src/lib/libcrypto/des/set_key.c10
-rw-r--r--src/lib/libcrypto/des/speed.c310
-rw-r--r--src/lib/libcrypto/des/str2key.c1
-rw-r--r--src/lib/libcrypto/des/t/test27
-rw-r--r--src/lib/libcrypto/des/times/486-50.sol16
-rw-r--r--src/lib/libcrypto/des/times/586-100.lnx20
-rw-r--r--src/lib/libcrypto/des/times/686-200.fre18
-rw-r--r--src/lib/libcrypto/des/times/aix.cc26
-rw-r--r--src/lib/libcrypto/des/times/alpha.cc18
-rw-r--r--src/lib/libcrypto/des/times/hpux.cc17
-rw-r--r--src/lib/libcrypto/des/times/sparc.gcc17
-rw-r--r--src/lib/libcrypto/des/times/usparc.cc31
-rw-r--r--src/lib/libcrypto/des/typemap34
-rw-r--r--src/lib/libcrypto/des/xcbc_enc.c4
-rw-r--r--src/lib/libcrypto/dh/Makefile133
-rw-r--r--src/lib/libcrypto/dh/Makefile.ssl133
-rw-r--r--src/lib/libcrypto/dh/dh.h57
-rw-r--r--src/lib/libcrypto/dh/dh1024.pem5
-rw-r--r--src/lib/libcrypto/dh/dh192.pem3
-rw-r--r--src/lib/libcrypto/dh/dh2048.pem16
-rw-r--r--src/lib/libcrypto/dh/dh4096.pem14
-rw-r--r--src/lib/libcrypto/dh/dh512.pem4
-rw-r--r--src/lib/libcrypto/dh/dh_check.c10
-rw-r--r--src/lib/libcrypto/dh/dh_err.c18
-rw-r--r--src/lib/libcrypto/dh/dh_gen.c50
-rw-r--r--src/lib/libcrypto/dh/dh_key.c37
-rw-r--r--src/lib/libcrypto/dh/dh_lib.c2
-rw-r--r--src/lib/libcrypto/dh/dhtest.c216
-rw-r--r--src/lib/libcrypto/dh/example50
-rw-r--r--src/lib/libcrypto/dh/generate65
-rw-r--r--src/lib/libcrypto/dh/p1024.c92
-rw-r--r--src/lib/libcrypto/dh/p192.c80
-rw-r--r--src/lib/libcrypto/dh/p512.c85
-rw-r--r--src/lib/libcrypto/doc/DH_set_method.pod2
-rw-r--r--src/lib/libcrypto/doc/DSA_set_method.pod2
-rw-r--r--src/lib/libcrypto/doc/EVP_BytesToKey.pod2
-rw-r--r--src/lib/libcrypto/doc/EVP_DigestInit.pod8
-rw-r--r--src/lib/libcrypto/doc/EVP_SealInit.pod6
-rw-r--r--src/lib/libcrypto/doc/EVP_SignInit.pod8
-rw-r--r--src/lib/libcrypto/doc/RAND_bytes.pod3
-rw-r--r--src/lib/libcrypto/doc/RAND_set_rand_method.pod2
-rw-r--r--src/lib/libcrypto/doc/RSA_get_ex_new_index.pod12
-rw-r--r--src/lib/libcrypto/doc/RSA_set_method.pod2
-rw-r--r--src/lib/libcrypto/doc/RSA_sign.pod4
-rw-r--r--src/lib/libcrypto/doc/bn.pod25
-rw-r--r--src/lib/libcrypto/doc/dsa.pod3
-rw-r--r--src/lib/libcrypto/dsa/Makefile164
-rw-r--r--src/lib/libcrypto/dsa/Makefile.ssl171
-rw-r--r--src/lib/libcrypto/dsa/README4
-rw-r--r--src/lib/libcrypto/dsa/dsa.h59
-rw-r--r--src/lib/libcrypto/dsa/dsa_err.c9
-rw-r--r--src/lib/libcrypto/dsa/dsa_gen.c111
-rw-r--r--src/lib/libcrypto/dsa/dsa_key.c15
-rw-r--r--src/lib/libcrypto/dsa/dsa_lib.c5
-rw-r--r--src/lib/libcrypto/dsa/dsa_ossl.c108
-rw-r--r--src/lib/libcrypto/dsa/dsa_sign.c14
-rw-r--r--src/lib/libcrypto/dsa/dsa_vrf.c9
-rw-r--r--src/lib/libcrypto/dsa/dsagen.c111
-rw-r--r--src/lib/libcrypto/dsa/dsatest.c251
-rw-r--r--src/lib/libcrypto/dsa/fips186a.txt122
-rw-r--r--src/lib/libcrypto/dso/Makefile142
-rw-r--r--src/lib/libcrypto/dso/Makefile.ssl142
-rw-r--r--src/lib/libcrypto/dso/README22
-rw-r--r--src/lib/libcrypto/dso/dso.h52
-rw-r--r--src/lib/libcrypto/dso/dso_dl.c317
-rw-r--r--src/lib/libcrypto/dso/dso_dlfcn.c120
-rw-r--r--src/lib/libcrypto/dso/dso_err.c22
-rw-r--r--src/lib/libcrypto/dso/dso_lib.c29
-rw-r--r--src/lib/libcrypto/dso/dso_null.c2
-rw-r--r--src/lib/libcrypto/dso/dso_vms.c379
-rw-r--r--src/lib/libcrypto/dso/dso_win32.c298
-rw-r--r--src/lib/libcrypto/ebcdic.c218
-rw-r--r--src/lib/libcrypto/ebcdic.h19
-rw-r--r--src/lib/libcrypto/ec/Makefile193
-rw-r--r--src/lib/libcrypto/ec/Makefile.ssl128
-rw-r--r--src/lib/libcrypto/ec/ec.h319
-rw-r--r--src/lib/libcrypto/ec/ec2_smpt.c74
-rw-r--r--src/lib/libcrypto/ec/ec_cvt.c76
-rw-r--r--src/lib/libcrypto/ec/ec_err.c114
-rw-r--r--src/lib/libcrypto/ec/ec_lcl.h241
-rw-r--r--src/lib/libcrypto/ec/ec_lib.c678
-rw-r--r--src/lib/libcrypto/ec/ec_mult.c673
-rw-r--r--src/lib/libcrypto/ec/ecp_mont.c151
-rw-r--r--src/lib/libcrypto/ec/ecp_nist.c180
-rw-r--r--src/lib/libcrypto/ec/ecp_recp.c133
-rw-r--r--src/lib/libcrypto/ec/ecp_smpl.c335
-rw-r--r--src/lib/libcrypto/ec/ectest.c643
-rw-r--r--src/lib/libcrypto/ecdh/Makefile111
-rw-r--r--src/lib/libcrypto/ecdh/ecdhtest.c368
-rw-r--r--src/lib/libcrypto/ecdh/ech_ossl.c213
-rw-r--r--src/lib/libcrypto/ecdsa/Makefile125
-rw-r--r--src/lib/libcrypto/ecdsa/ecdsatest.c500
-rw-r--r--src/lib/libcrypto/engine/Makefile288
-rw-r--r--src/lib/libcrypto/engine/Makefile.ssl538
-rw-r--r--src/lib/libcrypto/engine/eng_all.c31
-rw-r--r--src/lib/libcrypto/engine/eng_cnf.c7
-rw-r--r--src/lib/libcrypto/engine/eng_cryptodev.c1133
-rw-r--r--src/lib/libcrypto/engine/eng_ctrl.c12
-rw-r--r--src/lib/libcrypto/engine/eng_dyn.c108
-rw-r--r--src/lib/libcrypto/engine/eng_err.c16
-rw-r--r--src/lib/libcrypto/engine/eng_fat.c26
-rw-r--r--src/lib/libcrypto/engine/eng_init.c5
-rw-r--r--src/lib/libcrypto/engine/eng_int.h9
-rw-r--r--src/lib/libcrypto/engine/eng_lib.c18
-rw-r--r--src/lib/libcrypto/engine/eng_list.c43
-rw-r--r--src/lib/libcrypto/engine/eng_openssl.c25
-rw-r--r--src/lib/libcrypto/engine/eng_pkey.c3
-rw-r--r--src/lib/libcrypto/engine/eng_table.c94
-rw-r--r--src/lib/libcrypto/engine/engine.h158
-rw-r--r--src/lib/libcrypto/engine/enginetest.c283
-rw-r--r--src/lib/libcrypto/engine/hw.ec8
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca.c969
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca_err.c149
-rw-r--r--src/lib/libcrypto/engine/hw_4758_cca_err.h93
-rw-r--r--src/lib/libcrypto/engine/hw_aep.c1120
-rw-r--r--src/lib/libcrypto/engine/hw_aep_err.c157
-rw-r--r--src/lib/libcrypto/engine/hw_aep_err.h101
-rw-r--r--src/lib/libcrypto/engine/hw_atalla.c595
-rw-r--r--src/lib/libcrypto/engine/hw_atalla_err.c145
-rw-r--r--src/lib/libcrypto/engine/hw_atalla_err.h89
-rw-r--r--src/lib/libcrypto/engine/hw_cryptodev.c1355
-rw-r--r--src/lib/libcrypto/engine/hw_cswift.c1109
-rw-r--r--src/lib/libcrypto/engine/hw_cswift_err.c149
-rw-r--r--src/lib/libcrypto/engine/hw_cswift_err.h93
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher.c1388
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher_err.c157
-rw-r--r--src/lib/libcrypto/engine/hw_ncipher_err.h101
-rw-r--r--src/lib/libcrypto/engine/hw_nuron.c418
-rw-r--r--src/lib/libcrypto/engine/hw_nuron_err.c142
-rw-r--r--src/lib/libcrypto/engine/hw_nuron_err.h86
-rw-r--r--src/lib/libcrypto/engine/hw_sureware.c1039
-rw-r--r--src/lib/libcrypto/engine/hw_sureware_err.c150
-rw-r--r--src/lib/libcrypto/engine/hw_sureware_err.h94
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec.c1061
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec_err.c151
-rw-r--r--src/lib/libcrypto/engine/hw_ubsec_err.h95
-rw-r--r--src/lib/libcrypto/engine/tb_cipher.c2
-rw-r--r--src/lib/libcrypto/engine/tb_dh.c2
-rw-r--r--src/lib/libcrypto/engine/tb_digest.c2
-rw-r--r--src/lib/libcrypto/engine/tb_dsa.c2
-rw-r--r--src/lib/libcrypto/engine/tb_rand.c2
-rw-r--r--src/lib/libcrypto/engine/tb_rsa.c2
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/aep.h178
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/atalla.h48
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/cswift.h234
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h149
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h100
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h486
-rw-r--r--src/lib/libcrypto/engine/vendor_defns/sureware.h239
-rw-r--r--src/lib/libcrypto/err/Makefile109
-rw-r--r--src/lib/libcrypto/err/Makefile.ssl119
-rw-r--r--src/lib/libcrypto/err/err.c86
-rw-r--r--src/lib/libcrypto/err/err.h28
-rw-r--r--src/lib/libcrypto/err/err_all.c25
-rw-r--r--src/lib/libcrypto/err/err_prn.c9
-rw-r--r--src/lib/libcrypto/err/openssl.ec7
-rw-r--r--src/lib/libcrypto/evp/Makefile646
-rw-r--r--src/lib/libcrypto/evp/Makefile.ssl1059
-rw-r--r--src/lib/libcrypto/evp/bio_b64.c2
-rw-r--r--src/lib/libcrypto/evp/bio_enc.c4
-rw-r--r--src/lib/libcrypto/evp/bio_md.c11
-rw-r--r--src/lib/libcrypto/evp/bio_ok.c575
-rw-r--r--src/lib/libcrypto/evp/c_all.c6
-rw-r--r--src/lib/libcrypto/evp/c_allc.c188
-rw-r--r--src/lib/libcrypto/evp/c_alld.c113
-rw-r--r--src/lib/libcrypto/evp/digest.c61
-rw-r--r--src/lib/libcrypto/evp/e_acss.c85
-rw-r--r--src/lib/libcrypto/evp/e_aes.c22
-rw-r--r--src/lib/libcrypto/evp/e_bf.c2
-rw-r--r--src/lib/libcrypto/evp/e_cast.c4
-rw-r--r--src/lib/libcrypto/evp/e_des.c36
-rw-r--r--src/lib/libcrypto/evp/e_des3.c61
-rw-r--r--src/lib/libcrypto/evp/e_dsa.c71
-rw-r--r--src/lib/libcrypto/evp/e_idea.c4
-rw-r--r--src/lib/libcrypto/evp/e_null.c5
-rw-r--r--src/lib/libcrypto/evp/e_rc2.c12
-rw-r--r--src/lib/libcrypto/evp/e_rc4.c8
-rw-r--r--src/lib/libcrypto/evp/e_rc5.c125
-rw-r--r--src/lib/libcrypto/evp/e_seed.c83
-rw-r--r--src/lib/libcrypto/evp/e_xcbc_d.c5
-rw-r--r--src/lib/libcrypto/evp/encode.c10
-rw-r--r--src/lib/libcrypto/evp/evp.h259
-rw-r--r--src/lib/libcrypto/evp/evp_acnf.c73
-rw-r--r--src/lib/libcrypto/evp/evp_enc.c127
-rw-r--r--src/lib/libcrypto/evp/evp_err.c39
-rw-r--r--src/lib/libcrypto/evp/evp_key.c2
-rw-r--r--src/lib/libcrypto/evp/evp_lib.c125
-rw-r--r--src/lib/libcrypto/evp/evp_locl.h24
-rw-r--r--src/lib/libcrypto/evp/evp_pbe.c5
-rw-r--r--src/lib/libcrypto/evp/evp_pkey.c398
-rw-r--r--src/lib/libcrypto/evp/evp_test.c422
-rw-r--r--src/lib/libcrypto/evp/evptests.txt288
-rw-r--r--src/lib/libcrypto/evp/m_dss.c8
-rw-r--r--src/lib/libcrypto/evp/m_dss1.c18
-rw-r--r--src/lib/libcrypto/evp/m_md2.c97
-rw-r--r--src/lib/libcrypto/evp/m_md4.c10
-rw-r--r--src/lib/libcrypto/evp/m_md5.c10
-rw-r--r--src/lib/libcrypto/evp/m_mdc2.c97
-rw-r--r--src/lib/libcrypto/evp/m_null.c2
-rw-r--r--src/lib/libcrypto/evp/m_ripemd.c9
-rw-r--r--src/lib/libcrypto/evp/m_sha.c99
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c46
-rw-r--r--src/lib/libcrypto/evp/names.c11
-rw-r--r--src/lib/libcrypto/evp/openbsd_hw.c446
-rw-r--r--src/lib/libcrypto/evp/p5_crpt.c14
-rw-r--r--src/lib/libcrypto/evp/p5_crpt2.c21
-rw-r--r--src/lib/libcrypto/evp/p_dec.c2
-rw-r--r--src/lib/libcrypto/evp/p_enc.c2
-rw-r--r--src/lib/libcrypto/evp/p_lib.c177
-rw-r--r--src/lib/libcrypto/evp/p_open.c10
-rw-r--r--src/lib/libcrypto/evp/p_seal.c2
-rw-r--r--src/lib/libcrypto/evp/p_verify.c2
-rw-r--r--src/lib/libcrypto/ex_data.c10
-rw-r--r--src/lib/libcrypto/hmac/Makefile85
-rw-r--r--src/lib/libcrypto/hmac/Makefile.ssl101
-rw-r--r--src/lib/libcrypto/hmac/hmac.c20
-rw-r--r--src/lib/libcrypto/hmac/hmac.h13
-rw-r--r--src/lib/libcrypto/hmac/hmactest.c175
-rw-r--r--src/lib/libcrypto/idea/Makefile86
-rw-r--r--src/lib/libcrypto/idea/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/idea/idea.h9
-rw-r--r--src/lib/libcrypto/idea/ideatest.c235
-rw-r--r--src/lib/libcrypto/idea/version12
-rw-r--r--src/lib/libcrypto/install.com138
-rw-r--r--src/lib/libcrypto/krb5/Makefile84
-rw-r--r--src/lib/libcrypto/krb5/Makefile.ssl90
-rw-r--r--src/lib/libcrypto/krb5/krb5_asn.h2
-rw-r--r--src/lib/libcrypto/lhash/Makefile88
-rw-r--r--src/lib/libcrypto/lhash/Makefile.ssl93
-rw-r--r--src/lib/libcrypto/lhash/lh_test.c88
-rw-r--r--src/lib/libcrypto/lhash/lhash.c20
-rw-r--r--src/lib/libcrypto/lhash/lhash.h17
-rw-r--r--src/lib/libcrypto/lhash/num.pl17
-rw-r--r--src/lib/libcrypto/md2/Makefile89
-rw-r--r--src/lib/libcrypto/md2/Makefile.ssl93
-rw-r--r--src/lib/libcrypto/md2/md2.c124
-rw-r--r--src/lib/libcrypto/md2/md2.h94
-rw-r--r--src/lib/libcrypto/md2/md2_dgst.c229
-rw-r--r--src/lib/libcrypto/md2/md2_one.c94
-rw-r--r--src/lib/libcrypto/md2/md2test.c139
-rw-r--r--src/lib/libcrypto/md32_common.h473
-rw-r--r--src/lib/libcrypto/md4/Makefile86
-rw-r--r--src/lib/libcrypto/md4/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/md4/md4.c127
-rw-r--r--src/lib/libcrypto/md4/md4.h10
-rw-r--r--src/lib/libcrypto/md4/md4_dgst.c95
-rw-r--r--src/lib/libcrypto/md4/md4_locl.h44
-rw-r--r--src/lib/libcrypto/md4/md4_one.c2
-rw-r--r--src/lib/libcrypto/md4/md4s.cpp78
-rw-r--r--src/lib/libcrypto/md4/md4test.c136
-rw-r--r--src/lib/libcrypto/md5/Makefile102
-rw-r--r--src/lib/libcrypto/md5/Makefile.ssl127
-rw-r--r--src/lib/libcrypto/md5/asm/md5-586.pl2
-rw-r--r--src/lib/libcrypto/md5/asm/md5-sparcv9.S1031
-rw-r--r--src/lib/libcrypto/md5/md5.c127
-rw-r--r--src/lib/libcrypto/md5/md5.h10
-rw-r--r--src/lib/libcrypto/md5/md5_dgst.c112
-rw-r--r--src/lib/libcrypto/md5/md5_locl.h52
-rw-r--r--src/lib/libcrypto/md5/md5_one.c2
-rw-r--r--src/lib/libcrypto/md5/md5s.cpp78
-rw-r--r--src/lib/libcrypto/md5/md5test.c136
-rw-r--r--src/lib/libcrypto/mdc2/Makefile98
-rw-r--r--src/lib/libcrypto/mdc2/Makefile.ssl98
-rw-r--r--src/lib/libcrypto/mdc2/mdc2.h97
-rw-r--r--src/lib/libcrypto/mdc2/mdc2test.c149
-rw-r--r--src/lib/libcrypto/mem.c401
-rw-r--r--src/lib/libcrypto/mem_dbg.c10
-rw-r--r--src/lib/libcrypto/o_dir.c83
-rw-r--r--src/lib/libcrypto/o_dir.h53
-rw-r--r--src/lib/libcrypto/o_dir_test.c70
-rw-r--r--src/lib/libcrypto/o_str.h68
-rw-r--r--src/lib/libcrypto/objects/Makefile119
-rw-r--r--src/lib/libcrypto/objects/Makefile.ssl123
-rw-r--r--src/lib/libcrypto/objects/o_names.c6
-rw-r--r--src/lib/libcrypto/objects/obj_dat.c254
-rw-r--r--src/lib/libcrypto/objects/obj_dat.pl4
-rw-r--r--src/lib/libcrypto/objects/obj_err.c9
-rw-r--r--src/lib/libcrypto/objects/obj_lib.c3
-rw-r--r--src/lib/libcrypto/objects/obj_mac.num115
-rw-r--r--src/lib/libcrypto/objects/objects.h7
-rw-r--r--src/lib/libcrypto/objects/objects.pl13
-rw-r--r--src/lib/libcrypto/objects/objects.txt185
-rw-r--r--src/lib/libcrypto/ocsp/Makefile213
-rw-r--r--src/lib/libcrypto/ocsp/Makefile.ssl293
-rw-r--r--src/lib/libcrypto/ocsp/ocsp.h42
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_asn.c2
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_cl.c2
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_err.c14
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ext.c35
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_ht.c468
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_lib.c4
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_prn.c4
-rw-r--r--src/lib/libcrypto/ocsp/ocsp_vfy.c2
-rw-r--r--src/lib/libcrypto/opensslconf.h.in158
-rw-r--r--src/lib/libcrypto/opensslv.h10
-rw-r--r--src/lib/libcrypto/ossl_typ.h57
-rw-r--r--src/lib/libcrypto/pem/Makefile241
-rw-r--r--src/lib/libcrypto/pem/Makefile.ssl336
-rw-r--r--src/lib/libcrypto/pem/pem.h173
-rw-r--r--src/lib/libcrypto/pem/pem_all.c233
-rw-r--r--src/lib/libcrypto/pem/pem_err.c18
-rw-r--r--src/lib/libcrypto/pem/pem_info.c58
-rw-r--r--src/lib/libcrypto/pem/pem_lib.c33
-rw-r--r--src/lib/libcrypto/pem/pem_oth.c7
-rw-r--r--src/lib/libcrypto/pem/pem_pk8.c7
-rw-r--r--src/lib/libcrypto/pem/pem_pkey.c12
-rw-r--r--src/lib/libcrypto/pem/pem_seal.c2
-rw-r--r--src/lib/libcrypto/pem/pem_xaux.c1
-rw-r--r--src/lib/libcrypto/perlasm/alpha.pl434
-rw-r--r--src/lib/libcrypto/perlasm/cbc.pl4
-rw-r--r--src/lib/libcrypto/perlasm/x86asm.pl33
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl380
-rw-r--r--src/lib/libcrypto/perlasm/x86nasm.pl370
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl628
-rw-r--r--src/lib/libcrypto/pkcs12/Makefile286
-rw-r--r--src/lib/libcrypto/pkcs12/Makefile.ssl417
-rw-r--r--src/lib/libcrypto/pkcs12/p12_add.c6
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crpt.c16
-rw-r--r--src/lib/libcrypto/pkcs12/p12_crt.c336
-rw-r--r--src/lib/libcrypto/pkcs12/p12_decr.c13
-rw-r--r--src/lib/libcrypto/pkcs12/p12_init.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_key.c2
-rw-r--r--src/lib/libcrypto/pkcs12/p12_kiss.c20
-rw-r--r--src/lib/libcrypto/pkcs12/p12_mutl.c20
-rw-r--r--src/lib/libcrypto/pkcs12/p12_npas.c37
-rw-r--r--src/lib/libcrypto/pkcs12/pk12err.c18
-rw-r--r--src/lib/libcrypto/pkcs12/pkcs12.h22
-rw-r--r--src/lib/libcrypto/pkcs7/Makefile187
-rw-r--r--src/lib/libcrypto/pkcs7/Makefile.ssl243
-rw-r--r--src/lib/libcrypto/pkcs7/bio_ber.c466
-rw-r--r--src/lib/libcrypto/pkcs7/dec.c248
-rw-r--r--src/lib/libcrypto/pkcs7/des.pem15
-rw-r--r--src/lib/libcrypto/pkcs7/doc24
-rw-r--r--src/lib/libcrypto/pkcs7/enc.c174
-rw-r--r--src/lib/libcrypto/pkcs7/es1.pem66
-rw-r--r--src/lib/libcrypto/pkcs7/example.c329
-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/p7/a12
-rw-r--r--src/lib/libcrypto/pkcs7/p7/a21
-rw-r--r--src/lib/libcrypto/pkcs7/p7/cert.p7cbin0 -> 1728 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7mbin0 -> 4894 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/p7/smime.p7sbin0 -> 2625 bytes
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_asn1.c41
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_attr.c3
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_dgst.c66
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_doit.c354
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_enc.c76
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_lib.c117
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_mime.c104
-rw-r--r--src/lib/libcrypto/pkcs7/pk7_smime.c109
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7.h15
-rw-r--r--src/lib/libcrypto/pkcs7/pkcs7err.c15
-rw-r--r--src/lib/libcrypto/pkcs7/server.pem24
-rw-r--r--src/lib/libcrypto/pkcs7/sign.c154
-rw-r--r--src/lib/libcrypto/pkcs7/t/3des.pem16
-rw-r--r--src/lib/libcrypto/pkcs7/t/3dess.pem32
-rw-r--r--src/lib/libcrypto/pkcs7/t/c.pem48
-rw-r--r--src/lib/libcrypto/pkcs7/t/ff32
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-e20
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-e.pem22
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-0162
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-01.pem66
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-0290
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-enc-02.pem106
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-s-a-e91
-rw-r--r--src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem106
-rw-r--r--src/lib/libcrypto/pkcs7/t/nav-smime157
-rw-r--r--src/lib/libcrypto/pkcs7/t/s.pem57
-rw-r--r--src/lib/libcrypto/pkcs7/t/server.pem57
-rw-r--r--src/lib/libcrypto/pkcs7/verify.c263
-rw-r--r--src/lib/libcrypto/pqueue/Makefile84
-rw-r--r--src/lib/libcrypto/pqueue/pq_compat.h147
-rw-r--r--src/lib/libcrypto/pqueue/pq_test.c95
-rw-r--r--src/lib/libcrypto/pqueue/pqueue.c236
-rw-r--r--src/lib/libcrypto/pqueue/pqueue.h95
-rw-r--r--src/lib/libcrypto/rand/Makefile159
-rw-r--r--src/lib/libcrypto/rand/Makefile.ssl196
-rw-r--r--src/lib/libcrypto/rand/md_rand.c581
-rw-r--r--src/lib/libcrypto/rand/rand.h15
-rw-r--r--src/lib/libcrypto/rand/rand_egd.c303
-rw-r--r--src/lib/libcrypto/rand/rand_err.c15
-rw-r--r--src/lib/libcrypto/rand/rand_lcl.h158
-rw-r--r--src/lib/libcrypto/rand/rand_lib.c18
-rw-r--r--src/lib/libcrypto/rand/rand_nw.c183
-rw-r--r--src/lib/libcrypto/rand/rand_os2.c147
-rw-r--r--src/lib/libcrypto/rand/rand_unix.c281
-rw-r--r--src/lib/libcrypto/rand/rand_vms.c136
-rw-r--r--src/lib/libcrypto/rand/rand_win.c747
-rw-r--r--src/lib/libcrypto/rand/randfile.c16
-rw-r--r--src/lib/libcrypto/rand/randtest.c216
-rw-r--r--src/lib/libcrypto/rc2/Makefile86
-rw-r--r--src/lib/libcrypto/rc2/Makefile.ssl91
-rw-r--r--src/lib/libcrypto/rc2/rc2.h7
-rw-r--r--src/lib/libcrypto/rc2/rc2_ecb.c2
-rw-r--r--src/lib/libcrypto/rc2/rc2_skey.c21
-rw-r--r--src/lib/libcrypto/rc2/rc2speed.c274
-rw-r--r--src/lib/libcrypto/rc2/rc2test.c271
-rw-r--r--src/lib/libcrypto/rc2/tab.c86
-rw-r--r--src/lib/libcrypto/rc4/Makefile115
-rw-r--r--src/lib/libcrypto/rc4/Makefile.ssl110
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-586.pl11
-rwxr-xr-xsrc/lib/libcrypto/rc4/asm/rc4-amd64.pl227
-rw-r--r--src/lib/libcrypto/rc4/asm/rc4-ia64.S159
-rw-r--r--src/lib/libcrypto/rc4/rc4.c192
-rw-r--r--src/lib/libcrypto/rc4/rc4.h6
-rw-r--r--src/lib/libcrypto/rc4/rc4_enc.c4
-rw-r--r--src/lib/libcrypto/rc4/rc4_skey.c55
-rw-r--r--src/lib/libcrypto/rc4/rc4s.cpp73
-rw-r--r--src/lib/libcrypto/rc4/rc4speed.c250
-rw-r--r--src/lib/libcrypto/rc4/rc4test.c203
-rw-r--r--src/lib/libcrypto/rc4/rrc4.doc278
-rw-r--r--src/lib/libcrypto/rc5/Makefile103
-rw-r--r--src/lib/libcrypto/rc5/Makefile.ssl108
-rw-r--r--src/lib/libcrypto/rc5/rc5.h119
-rw-r--r--src/lib/libcrypto/rc5/rc5_locl.h207
-rw-r--r--src/lib/libcrypto/rc5/rc5s.cpp70
-rw-r--r--src/lib/libcrypto/rc5/rc5test.c386
-rw-r--r--src/lib/libcrypto/ripemd/Makefile99
-rw-r--r--src/lib/libcrypto/ripemd/Makefile.ssl108
-rw-r--r--src/lib/libcrypto/ripemd/README2
-rw-r--r--src/lib/libcrypto/ripemd/asm/rips.cpp82
-rw-r--r--src/lib/libcrypto/ripemd/asm/rmd-586.pl4
-rw-r--r--src/lib/libcrypto/ripemd/ripemd.h10
-rw-r--r--src/lib/libcrypto/ripemd/rmd160.c127
-rw-r--r--src/lib/libcrypto/ripemd/rmd_dgst.c214
-rw-r--r--src/lib/libcrypto/ripemd/rmd_locl.h14
-rw-r--r--src/lib/libcrypto/ripemd/rmd_one.c2
-rw-r--r--src/lib/libcrypto/ripemd/rmdtest.c145
-rw-r--r--src/lib/libcrypto/rsa/Makefile239
-rw-r--r--src/lib/libcrypto/rsa/Makefile.ssl241
-rw-r--r--src/lib/libcrypto/rsa/rsa.h96
-rw-r--r--src/lib/libcrypto/rsa/rsa_asn1.c8
-rw-r--r--src/lib/libcrypto/rsa/rsa_chk.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_eay.c564
-rw-r--r--src/lib/libcrypto/rsa/rsa_err.c22
-rw-r--r--src/lib/libcrypto/rsa/rsa_gen.c160
-rw-r--r--src/lib/libcrypto/rsa/rsa_lib.c130
-rw-r--r--src/lib/libcrypto/rsa/rsa_null.c150
-rw-r--r--src/lib/libcrypto/rsa/rsa_oaep.c38
-rw-r--r--src/lib/libcrypto/rsa/rsa_saos.c3
-rw-r--r--src/lib/libcrypto/rsa/rsa_sign.c4
-rw-r--r--src/lib/libcrypto/rsa/rsa_test.c318
-rw-r--r--src/lib/libcrypto/seed/Makefile87
-rw-r--r--src/lib/libcrypto/seed/seed.c286
-rw-r--r--src/lib/libcrypto/seed/seed.h135
-rw-r--r--src/lib/libcrypto/seed/seed_cbc.c129
-rw-r--r--src/lib/libcrypto/seed/seed_cfb.c144
-rw-r--r--src/lib/libcrypto/seed/seed_ecb.c60
-rw-r--r--src/lib/libcrypto/seed/seed_locl.h116
-rw-r--r--src/lib/libcrypto/seed/seed_ofb.c128
-rw-r--r--src/lib/libcrypto/sha/Makefile139
-rw-r--r--src/lib/libcrypto/sha/Makefile.ssl116
-rw-r--r--src/lib/libcrypto/sha/asm/README1
-rw-r--r--src/lib/libcrypto/sha/asm/sha1-586.pl472
-rw-r--r--src/lib/libcrypto/sha/asm/sha512-sse2.pl404
-rw-r--r--src/lib/libcrypto/sha/sha.c124
-rw-r--r--src/lib/libcrypto/sha/sha.h90
-rw-r--r--src/lib/libcrypto/sha/sha1.c127
-rw-r--r--src/lib/libcrypto/sha/sha1_one.c4
-rw-r--r--src/lib/libcrypto/sha/sha1dgst.c11
-rw-r--r--src/lib/libcrypto/sha/sha1s.cpp82
-rw-r--r--src/lib/libcrypto/sha/sha1test.c174
-rw-r--r--src/lib/libcrypto/sha/sha256t.c147
-rw-r--r--src/lib/libcrypto/sha/sha512t.c184
-rw-r--r--src/lib/libcrypto/sha/sha_dgst.c73
-rw-r--r--src/lib/libcrypto/sha/sha_locl.h306
-rw-r--r--src/lib/libcrypto/sha/sha_one.c78
-rw-r--r--src/lib/libcrypto/sha/shatest.c174
-rw-r--r--src/lib/libcrypto/stack/Makefile84
-rw-r--r--src/lib/libcrypto/stack/Makefile.ssl88
-rw-r--r--src/lib/libcrypto/stack/safestack.h512
-rw-r--r--src/lib/libcrypto/stack/stack.c29
-rw-r--r--src/lib/libcrypto/stack/stack.h1
-rw-r--r--src/lib/libcrypto/store/Makefile112
-rw-r--r--src/lib/libcrypto/store/README95
-rw-r--r--src/lib/libcrypto/store/store.h554
-rw-r--r--src/lib/libcrypto/store/str_err.c211
-rw-r--r--src/lib/libcrypto/store/str_lib.c1824
-rw-r--r--src/lib/libcrypto/store/str_locl.h124
-rw-r--r--src/lib/libcrypto/store/str_mem.c357
-rw-r--r--src/lib/libcrypto/store/str_meth.c250
-rw-r--r--src/lib/libcrypto/symhacks.h275
-rw-r--r--src/lib/libcrypto/threads/README14
-rw-r--r--src/lib/libcrypto/threads/mttest.c1096
-rw-r--r--src/lib/libcrypto/threads/netware.bat79
-rw-r--r--src/lib/libcrypto/threads/profile.sh4
-rw-r--r--src/lib/libcrypto/threads/ptest.bat4
-rw-r--r--src/lib/libcrypto/threads/pthread.sh9
-rw-r--r--src/lib/libcrypto/threads/pthread2.sh7
-rw-r--r--src/lib/libcrypto/threads/pthreads-vms.com9
-rw-r--r--src/lib/libcrypto/threads/purify.sh4
-rw-r--r--src/lib/libcrypto/threads/solaris.sh4
-rw-r--r--src/lib/libcrypto/threads/th-lock.c387
-rw-r--r--src/lib/libcrypto/threads/win32.bat4
-rw-r--r--src/lib/libcrypto/tmdiff.c249
-rw-r--r--src/lib/libcrypto/tmdiff.h81
-rw-r--r--src/lib/libcrypto/txt_db/Makefile84
-rw-r--r--src/lib/libcrypto/txt_db/Makefile.ssl88
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.c23
-rw-r--r--src/lib/libcrypto/txt_db/txt_db.h5
-rw-r--r--src/lib/libcrypto/ui/Makefile111
-rw-r--r--src/lib/libcrypto/ui/Makefile.ssl117
-rw-r--r--src/lib/libcrypto/ui/ui.h20
-rw-r--r--src/lib/libcrypto/ui/ui_compat.c67
-rw-r--r--src/lib/libcrypto/ui/ui_err.c9
-rw-r--r--src/lib/libcrypto/ui/ui_lib.c8
-rw-r--r--src/lib/libcrypto/ui/ui_locl.h5
-rw-r--r--src/lib/libcrypto/ui/ui_openssl.c51
-rw-r--r--src/lib/libcrypto/ui/ui_util.c2
-rw-r--r--src/lib/libcrypto/uid.c89
-rw-r--r--src/lib/libcrypto/util/FreeBSD.sh6
-rw-r--r--src/lib/libcrypto/util/add_cr.pl123
-rw-r--r--src/lib/libcrypto/util/bat.sh134
-rw-r--r--src/lib/libcrypto/util/checkhash.pl222
-rw-r--r--src/lib/libcrypto/util/ck_errf.pl45
-rw-r--r--src/lib/libcrypto/util/clean-depend.pl54
-rw-r--r--src/lib/libcrypto/util/copy.pl59
-rw-r--r--src/lib/libcrypto/util/cygwin.sh127
-rw-r--r--src/lib/libcrypto/util/deleof.pl7
-rw-r--r--src/lib/libcrypto/util/dirname.pl18
-rw-r--r--src/lib/libcrypto/util/do_ms.sh19
-rw-r--r--src/lib/libcrypto/util/domd34
-rw-r--r--src/lib/libcrypto/util/err-ins.pl33
-rw-r--r--src/lib/libcrypto/util/extract-names.pl26
-rw-r--r--src/lib/libcrypto/util/extract-section.pl12
-rw-r--r--src/lib/libcrypto/util/files.pl61
-rw-r--r--src/lib/libcrypto/util/fipslink.pl78
-rw-r--r--src/lib/libcrypto/util/fixNT.sh14
-rw-r--r--src/lib/libcrypto/util/install.sh108
-rw-r--r--src/lib/libcrypto/util/libeay.num2907
-rw-r--r--src/lib/libcrypto/util/mk1mf.pl1165
-rw-r--r--src/lib/libcrypto/util/mkcerts.sh220
-rw-r--r--src/lib/libcrypto/util/mkdef.pl1407
-rw-r--r--src/lib/libcrypto/util/mkdir-p.pl33
-rw-r--r--src/lib/libcrypto/util/mkerr.pl135
-rw-r--r--src/lib/libcrypto/util/mkfiles.pl126
-rw-r--r--src/lib/libcrypto/util/mklink.pl73
-rw-r--r--src/lib/libcrypto/util/mkstack.pl1
-rwxr-xr-xsrc/lib/libcrypto/util/opensslwrap.sh26
-rw-r--r--src/lib/libcrypto/util/perlpath.pl35
-rw-r--r--src/lib/libcrypto/util/pl/BC-16.pl151
-rw-r--r--src/lib/libcrypto/util/pl/BC-32.pl144
-rw-r--r--src/lib/libcrypto/util/pl/Mingw32.pl109
-rw-r--r--src/lib/libcrypto/util/pl/OS2-EMX.pl125
-rw-r--r--src/lib/libcrypto/util/pl/VC-16.pl177
-rw-r--r--src/lib/libcrypto/util/pl/VC-32-GMAKE.pl222
-rw-r--r--src/lib/libcrypto/util/pl/VC-32.pl220
-rw-r--r--src/lib/libcrypto/util/pl/VC-CE.pl116
-rw-r--r--src/lib/libcrypto/util/pl/linux.pl109
-rw-r--r--src/lib/libcrypto/util/pl/netware.pl526
-rw-r--r--src/lib/libcrypto/util/pl/ultrix.pl43
-rw-r--r--src/lib/libcrypto/util/pl/unix.pl101
-rw-r--r--src/lib/libcrypto/util/pod2man.pl1184
-rw-r--r--src/lib/libcrypto/util/pod2mantest58
-rw-r--r--src/lib/libcrypto/util/pod2mantest.pod15
-rw-r--r--src/lib/libcrypto/util/point.sh10
-rw-r--r--src/lib/libcrypto/util/selftest.pl201
-rwxr-xr-xsrc/lib/libcrypto/util/shlib_wrap.sh91
-rw-r--r--src/lib/libcrypto/util/sp-diff.pl80
-rw-r--r--src/lib/libcrypto/util/speed.sh39
-rw-r--r--src/lib/libcrypto/util/src-dep.pl147
-rw-r--r--src/lib/libcrypto/util/ssleay.num217
-rw-r--r--src/lib/libcrypto/util/tab_num.pl17
-rw-r--r--src/lib/libcrypto/util/x86asm.sh42
-rw-r--r--src/lib/libcrypto/x509/Makefile406
-rw-r--r--src/lib/libcrypto/x509/Makefile.ssl594
-rw-r--r--src/lib/libcrypto/x509/by_dir.c10
-rw-r--r--src/lib/libcrypto/x509/x509.h140
-rw-r--r--src/lib/libcrypto/x509/x509_att.c45
-rw-r--r--src/lib/libcrypto/x509/x509_cmp.c59
-rw-r--r--src/lib/libcrypto/x509/x509_err.c19
-rw-r--r--src/lib/libcrypto/x509/x509_lu.c30
-rw-r--r--src/lib/libcrypto/x509/x509_r2x.c6
-rw-r--r--src/lib/libcrypto/x509/x509_req.c49
-rw-r--r--src/lib/libcrypto/x509/x509_trs.c4
-rw-r--r--src/lib/libcrypto/x509/x509_txt.c10
-rw-r--r--src/lib/libcrypto/x509/x509_v3.c10
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.c481
-rw-r--r--src/lib/libcrypto/x509/x509_vfy.h143
-rw-r--r--src/lib/libcrypto/x509/x509spki.c3
-rw-r--r--src/lib/libcrypto/x509/x509type.c6
-rw-r--r--src/lib/libcrypto/x509/x_all.c137
-rw-r--r--src/lib/libcrypto/x509v3/Makefile591
-rw-r--r--src/lib/libcrypto/x509v3/Makefile.ssl603
-rw-r--r--src/lib/libcrypto/x509v3/ext_dat.h13
-rw-r--r--src/lib/libcrypto/x509v3/tabtest.c88
-rw-r--r--src/lib/libcrypto/x509v3/v3_addr.c1280
-rw-r--r--src/lib/libcrypto/x509v3/v3_akey.c190
-rw-r--r--src/lib/libcrypto/x509v3/v3_alt.c289
-rw-r--r--src/lib/libcrypto/x509v3/v3_asid.c842
-rw-r--r--src/lib/libcrypto/x509v3/v3_bcons.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_bitst.c14
-rw-r--r--src/lib/libcrypto/x509v3/v3_conf.c73
-rw-r--r--src/lib/libcrypto/x509v3/v3_cpols.c24
-rw-r--r--src/lib/libcrypto/x509v3/v3_crld.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_enum.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_extku.c8
-rw-r--r--src/lib/libcrypto/x509v3/v3_ia5.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_info.c17
-rw-r--r--src/lib/libcrypto/x509v3/v3_int.c17
-rw-r--r--src/lib/libcrypto/x509v3/v3_lib.c7
-rw-r--r--src/lib/libcrypto/x509v3/v3_ocsp.c22
-rw-r--r--src/lib/libcrypto/x509v3/v3_pku.c2
-rw-r--r--src/lib/libcrypto/x509v3/v3_prn.c5
-rw-r--r--src/lib/libcrypto/x509v3/v3_purp.c18
-rw-r--r--src/lib/libcrypto/x509v3/v3_skey.c10
-rw-r--r--src/lib/libcrypto/x509v3/v3_sxnet.c6
-rw-r--r--src/lib/libcrypto/x509v3/v3_utl.c347
-rw-r--r--src/lib/libcrypto/x509v3/v3conf.c127
-rw-r--r--src/lib/libcrypto/x509v3/v3err.c52
-rw-r--r--src/lib/libcrypto/x509v3/v3prin.c99
-rw-r--r--src/lib/libcrypto/x509v3/x509v3.h281
884 files changed, 121131 insertions, 18936 deletions
diff --git a/src/lib/libcrypto/LPdir_nyi.c b/src/lib/libcrypto/LPdir_nyi.c
new file mode 100644
index 0000000000..6c1a50e6a8
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_nyi.c
@@ -0,0 +1,42 @@
1/* $LP: LPlib/source/LPdir_win.c,v 1.1 2004/06/14 10:07:56 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 */
27
28#ifndef LPDIR_H
29#include "LPdir.h"
30#endif
31
32struct LP_dir_context_st { void *dummy; };
33const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
34 {
35 errno = EINVAL;
36 return 0;
37 }
38int LP_find_file_end(LP_DIR_CTX **ctx)
39 {
40 errno = EINVAL;
41 return 0;
42 }
diff --git a/src/lib/libcrypto/LPdir_unix.c b/src/lib/libcrypto/LPdir_unix.c
new file mode 100644
index 0000000000..b004cd99e8
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_unix.c
@@ -0,0 +1,127 @@
1/* $LP: LPlib/source/LPdir_unix.c,v 1.11 2004/09/23 22:07:22 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <stddef.h>
29#include <stdlib.h>
30#include <limits.h>
31#include <string.h>
32#include <sys/types.h>
33#include <dirent.h>
34#include <errno.h>
35#ifndef LPDIR_H
36#include "LPdir.h"
37#endif
38
39/* The POSIXly macro for the maximum number of characters in a file path
40 is NAME_MAX. However, some operating systems use PATH_MAX instead.
41 Therefore, it seems natural to first check for PATH_MAX and use that,
42 and if it doesn't exist, use NAME_MAX. */
43#if defined(PATH_MAX)
44# define LP_ENTRY_SIZE PATH_MAX
45#elif defined(NAME_MAX)
46# define LP_ENTRY_SIZE NAME_MAX
47#endif
48
49/* Of course, there's the possibility that neither PATH_MAX nor NAME_MAX
50 exist. It's also possible that NAME_MAX exists but is define to a
51 very small value (HP-UX offers 14), so we need to check if we got a
52 result, and if it meets a minimum standard, and create or change it
53 if not. */
54#if !defined(LP_ENTRY_SIZE) || LP_ENTRY_SIZE<255
55# undef LP_ENTRY_SIZE
56# define LP_ENTRY_SIZE 255
57#endif
58
59struct LP_dir_context_st
60{
61 DIR *dir;
62 char entry_name[LP_ENTRY_SIZE+1];
63};
64
65const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
66{
67 struct dirent *direntry = NULL;
68
69 if (ctx == NULL || directory == NULL)
70 {
71 errno = EINVAL;
72 return 0;
73 }
74
75 errno = 0;
76 if (*ctx == NULL)
77 {
78 *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX));
79 if (*ctx == NULL)
80 {
81 errno = ENOMEM;
82 return 0;
83 }
84 memset(*ctx, '\0', sizeof(LP_DIR_CTX));
85
86 (*ctx)->dir = opendir(directory);
87 if ((*ctx)->dir == NULL)
88 {
89 int save_errno = errno; /* Probably not needed, but I'm paranoid */
90 free(*ctx);
91 *ctx = NULL;
92 errno = save_errno;
93 return 0;
94 }
95 }
96
97 direntry = readdir((*ctx)->dir);
98 if (direntry == NULL)
99 {
100 return 0;
101 }
102
103 strncpy((*ctx)->entry_name, direntry->d_name, sizeof((*ctx)->entry_name) - 1);
104 (*ctx)->entry_name[sizeof((*ctx)->entry_name) - 1] = '\0';
105 return (*ctx)->entry_name;
106}
107
108int LP_find_file_end(LP_DIR_CTX **ctx)
109{
110 if (ctx != NULL && *ctx != NULL)
111 {
112 int ret = closedir((*ctx)->dir);
113
114 free(*ctx);
115 switch (ret)
116 {
117 case 0:
118 return 1;
119 case -1:
120 return 0;
121 default:
122 break;
123 }
124 }
125 errno = EINVAL;
126 return 0;
127}
diff --git a/src/lib/libcrypto/LPdir_vms.c b/src/lib/libcrypto/LPdir_vms.c
new file mode 100644
index 0000000000..85b427a623
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_vms.c
@@ -0,0 +1,199 @@
1/* $LP: LPlib/source/LPdir_vms.c,v 1.20 2004/08/26 13:36:05 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#include <stddef.h>
29#include <stdlib.h>
30#include <string.h>
31#include <errno.h>
32#include <descrip.h>
33#include <namdef.h>
34#include <rmsdef.h>
35#include <libfildef.h>
36#include <lib$routines.h>
37#include <strdef.h>
38#include <str$routines.h>
39#include <stsdef.h>
40#ifndef LPDIR_H
41#include "LPdir.h"
42#endif
43
44/* Because some compiler options hide this macor */
45#ifndef EVMSERR
46#define EVMSERR 65535 /* error for non-translatable VMS errors */
47#endif
48
49struct LP_dir_context_st
50{
51 unsigned long VMS_context;
52#ifdef NAML$C_MAXRSS
53 char filespec[NAML$C_MAXRSS+1];
54 char result[NAML$C_MAXRSS+1];
55#else
56 char filespec[256];
57 char result[256];
58#endif
59 struct dsc$descriptor_d filespec_dsc;
60 struct dsc$descriptor_d result_dsc;
61};
62
63const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
64{
65 int status;
66 char *p, *r;
67 size_t l;
68 unsigned long flags = 0;
69#ifdef NAML$C_MAXRSS
70 flags |= LIB$M_FIL_LONG_NAMES;
71#endif
72
73 if (ctx == NULL || directory == NULL)
74 {
75 errno = EINVAL;
76 return 0;
77 }
78
79 errno = 0;
80 if (*ctx == NULL)
81 {
82 size_t filespeclen = strlen(directory);
83 char *filespec = NULL;
84
85 /* MUST be a VMS directory specification! Let's estimate if it is. */
86 if (directory[filespeclen-1] != ']'
87 && directory[filespeclen-1] != '>'
88 && directory[filespeclen-1] != ':')
89 {
90 errno = EINVAL;
91 return 0;
92 }
93
94 filespeclen += 4; /* "*.*;" */
95
96 if (filespeclen >
97#ifdef NAML$C_MAXRSS
98 NAML$C_MAXRSS
99#else
100 255
101#endif
102 )
103 {
104 errno = ENAMETOOLONG;
105 return 0;
106 }
107
108 *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX));
109 if (*ctx == NULL)
110 {
111 errno = ENOMEM;
112 return 0;
113 }
114 memset(*ctx, '\0', sizeof(LP_DIR_CTX));
115
116 strcpy((*ctx)->filespec,directory);
117 strcat((*ctx)->filespec,"*.*;");
118 (*ctx)->filespec_dsc.dsc$w_length = filespeclen;
119 (*ctx)->filespec_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
120 (*ctx)->filespec_dsc.dsc$b_class = DSC$K_CLASS_S;
121 (*ctx)->filespec_dsc.dsc$a_pointer = (*ctx)->filespec;
122 (*ctx)->result_dsc.dsc$w_length = 0;
123 (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
124 (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D;
125 (*ctx)->result_dsc.dsc$a_pointer = 0;
126 }
127
128 (*ctx)->result_dsc.dsc$w_length = 0;
129 (*ctx)->result_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
130 (*ctx)->result_dsc.dsc$b_class = DSC$K_CLASS_D;
131 (*ctx)->result_dsc.dsc$a_pointer = 0;
132
133 status = lib$find_file(&(*ctx)->filespec_dsc, &(*ctx)->result_dsc,
134 &(*ctx)->VMS_context, 0, 0, 0, &flags);
135
136 if (status == RMS$_NMF)
137 {
138 errno = 0;
139 vaxc$errno = status;
140 return NULL;
141 }
142
143 if(!$VMS_STATUS_SUCCESS(status))
144 {
145 errno = EVMSERR;
146 vaxc$errno = status;
147 return NULL;
148 }
149
150 /* Quick, cheap and dirty way to discard any device and directory,
151 since we only want file names */
152 l = (*ctx)->result_dsc.dsc$w_length;
153 p = (*ctx)->result_dsc.dsc$a_pointer;
154 r = p;
155 for (; *p; p++)
156 {
157 if (*p == '^' && p[1] != '\0') /* Take care of ODS-5 escapes */
158 {
159 p++;
160 }
161 else if (*p == ':' || *p == '>' || *p == ']')
162 {
163 l -= p + 1 - r;
164 r = p + 1;
165 }
166 else if (*p == ';')
167 {
168 l = p - r;
169 break;
170 }
171 }
172
173 strncpy((*ctx)->result, r, l);
174 (*ctx)->result[l] = '\0';
175 str$free1_dx(&(*ctx)->result_dsc);
176
177 return (*ctx)->result;
178}
179
180int LP_find_file_end(LP_DIR_CTX **ctx)
181{
182 if (ctx != NULL && *ctx != NULL)
183 {
184 int status = lib$find_file_end(&(*ctx)->VMS_context);
185
186 free(*ctx);
187
188 if(!$VMS_STATUS_SUCCESS(status))
189 {
190 errno = EVMSERR;
191 vaxc$errno = status;
192 return 0;
193 }
194 return 1;
195 }
196 errno = EINVAL;
197 return 0;
198}
199
diff --git a/src/lib/libcrypto/LPdir_win.c b/src/lib/libcrypto/LPdir_win.c
new file mode 100644
index 0000000000..09b475beed
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_win.c
@@ -0,0 +1,155 @@
1/* $LP: LPlib/source/LPdir_win.c,v 1.10 2004/08/26 13:36:05 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27#include <windows.h>
28#include <tchar.h>
29#ifndef LPDIR_H
30#include "LPdir.h"
31#endif
32
33/* We're most likely overcautious here, but let's reserve for
34 broken WinCE headers and explicitly opt for UNICODE call.
35 Keep in mind that our WinCE builds are compiled with -DUNICODE
36 [as well as -D_UNICODE]. */
37#if defined(LP_SYS_WINCE) && !defined(FindFirstFile)
38# define FindFirstFile FindFirstFileW
39#endif
40#if defined(LP_SYS_WINCE) && !defined(FindFirstFile)
41# define FindNextFile FindNextFileW
42#endif
43
44#ifndef NAME_MAX
45#define NAME_MAX 255
46#endif
47
48struct LP_dir_context_st
49{
50 WIN32_FIND_DATA ctx;
51 HANDLE handle;
52 char entry_name[NAME_MAX+1];
53};
54
55const char *LP_find_file(LP_DIR_CTX **ctx, const char *directory)
56{
57 struct dirent *direntry = NULL;
58
59 if (ctx == NULL || directory == NULL)
60 {
61 errno = EINVAL;
62 return 0;
63 }
64
65 errno = 0;
66 if (*ctx == NULL)
67 {
68 *ctx = (LP_DIR_CTX *)malloc(sizeof(LP_DIR_CTX));
69 if (*ctx == NULL)
70 {
71 errno = ENOMEM;
72 return 0;
73 }
74 memset(*ctx, '\0', sizeof(LP_DIR_CTX));
75
76 if (sizeof(TCHAR) != sizeof(char))
77 {
78 TCHAR *wdir = NULL;
79 /* len_0 denotes string length *with* trailing 0 */
80 size_t index = 0,len_0 = strlen(directory) + 1;
81
82 wdir = (TCHAR *)malloc(len_0 * sizeof(TCHAR));
83 if (wdir == NULL)
84 {
85 free(*ctx);
86 *ctx = NULL;
87 errno = ENOMEM;
88 return 0;
89 }
90
91#ifdef LP_MULTIBYTE_AVAILABLE
92 if (!MultiByteToWideChar(CP_ACP, 0, directory, len_0, (WCHAR *)wdir, len_0))
93#endif
94 for (index = 0; index < len_0; index++)
95 wdir[index] = (TCHAR)directory[index];
96
97 (*ctx)->handle = FindFirstFile(wdir, &(*ctx)->ctx);
98
99 free(wdir);
100 }
101 else
102 (*ctx)->handle = FindFirstFile((TCHAR *)directory, &(*ctx)->ctx);
103
104 if ((*ctx)->handle == INVALID_HANDLE_VALUE)
105 {
106 free(*ctx);
107 *ctx = NULL;
108 errno = EINVAL;
109 return 0;
110 }
111 }
112 else
113 {
114 if (FindNextFile((*ctx)->handle, &(*ctx)->ctx) == FALSE)
115 {
116 return 0;
117 }
118 }
119
120 if (sizeof(TCHAR) != sizeof(char))
121 {
122 TCHAR *wdir = (*ctx)->ctx.cFileName;
123 size_t index, len_0 = 0;
124
125 while (wdir[len_0] && len_0 < (sizeof((*ctx)->entry_name) - 1)) len_0++;
126 len_0++;
127
128#ifdef LP_MULTIBYTE_AVAILABLE
129 if (!WideCharToMultiByte(CP_ACP, 0, (WCHAR *)wdir, len_0, (*ctx)->entry_name,
130 sizeof((*ctx)->entry_name), NULL, 0))
131#endif
132 for (index = 0; index < len_0; index++)
133 (*ctx)->entry_name[index] = (char)wdir[index];
134 }
135 else
136 strncpy((*ctx)->entry_name, (const char *)(*ctx)->ctx.cFileName,
137 sizeof((*ctx)->entry_name)-1);
138
139 (*ctx)->entry_name[sizeof((*ctx)->entry_name)-1] = '\0';
140
141 return (*ctx)->entry_name;
142}
143
144int LP_find_file_end(LP_DIR_CTX **ctx)
145{
146 if (ctx != NULL && *ctx != NULL)
147 {
148 FindClose((*ctx)->handle);
149 free(*ctx);
150 *ctx = NULL;
151 return 1;
152 }
153 errno = EINVAL;
154 return 0;
155}
diff --git a/src/lib/libcrypto/LPdir_win32.c b/src/lib/libcrypto/LPdir_win32.c
new file mode 100644
index 0000000000..e39872da52
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_win32.c
@@ -0,0 +1,30 @@
1/* $LP: LPlib/source/LPdir_win32.c,v 1.3 2004/08/26 13:36:05 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#define LP_SYS_WIN32
29#define LP_MULTIBYTE_AVAILABLE
30#include "LPdir_win.c"
diff --git a/src/lib/libcrypto/LPdir_wince.c b/src/lib/libcrypto/LPdir_wince.c
new file mode 100644
index 0000000000..ab0e1e6f4f
--- /dev/null
+++ b/src/lib/libcrypto/LPdir_wince.c
@@ -0,0 +1,31 @@
1/* $LP: LPlib/source/LPdir_wince.c,v 1.3 2004/08/26 13:36:05 _cvs_levitte Exp $ */
2/*
3 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28#define LP_SYS_WINCE
29/* We might want to define LP_MULTIBYTE_AVAILABLE here. It's currently
30 under investigation what the exact conditions would be */
31#include "LPdir_win.c"
diff --git a/src/lib/libcrypto/Makefile.ssl b/src/lib/libcrypto/Makefile.ssl
new file mode 100644
index 0000000000..b9951a4600
--- /dev/null
+++ b/src/lib/libcrypto/Makefile.ssl
@@ -0,0 +1,218 @@
1#
2# SSLeay/crypto/Makefile
3#
4
5DIR= crypto
6TOP= ..
7CC= cc
8INCLUDE= -I. -I$(TOP) -I../include
9INCLUDES= -I.. -I../.. -I../../include
10CFLAG= -g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP= /usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18RM= rm -f
19AR= ar r
20
21PEX_LIBS=
22EX_LIBS=
23
24CFLAGS= $(INCLUDE) $(CFLAG)
25
26
27LIBS=
28
29SDIRS= md2 md5 sha mdc2 hmac ripemd \
30 des rc2 rc4 rc5 idea bf cast \
31 bn ec rsa dsa dh dso engine aes \
32 buffer bio stack lhash rand err objects \
33 evp asn1 pem x509 x509v3 conf txt_db pkcs7 pkcs12 comp ocsp ui krb5
34
35GENERAL=Makefile README crypto-lib.com install.com
36
37LIB= $(TOP)/libcrypto.a
38SHARED_LIB= libcrypto$(SHLIB_EXT)
39LIBSRC= cryptlib.c mem.c mem_clr.c mem_dbg.c cversion.c ex_data.c tmdiff.c cpt_err.c ebcdic.c uid.c o_time.c
40LIBOBJ= cryptlib.o mem.o mem_clr.o mem_dbg.o cversion.o ex_data.o tmdiff.o cpt_err.o ebcdic.o uid.o o_time.o
41
42SRC= $(LIBSRC)
43
44EXHEADER= crypto.h tmdiff.h opensslv.h opensslconf.h ebcdic.h symhacks.h \
45 ossl_typ.h
46HEADER= cryptlib.h buildinf.h md32_common.h o_time.h $(EXHEADER)
47
48ALL= $(GENERAL) $(SRC) $(HEADER)
49
50top:
51 @(cd ..; $(MAKE) DIRS=$(DIR) all)
52
53all: shared
54
55buildinf.h: ../Makefile.ssl
56 ( echo "#ifndef MK1MF_BUILD"; \
57 echo ' /* auto-generated by crypto/Makefile.ssl for crypto/cversion.c */'; \
58 echo ' #define CFLAGS "$(CC) $(CFLAG)"'; \
59 echo ' #define PLATFORM "$(PLATFORM)"'; \
60 echo " #define DATE \"`LC_ALL=C LC_TIME=C date`\""; \
61 echo '#endif' ) >buildinf.h
62
63testapps:
64 if echo ${SDIRS} | fgrep ' des '; \
65 then cd des && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' des; fi
66 cd pkcs7 && $(MAKE) CC='$(CC)' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' BN_ASM='${BN_ASM}' DES_ENC='${DES_ENC}' SHA1_ASM_OBJ='${SHA1_ASM_OBJ}' MD5_ASM_OBJ='${MD5_ASM_OBJ}' RMD160_ASM_OBJ='${RMD160_ASM_OBJ}' BF_ENC='${BF_ENC}' CAST_ENC='${CAST_ENC}' RC4_ENC='${RC4_ENC}' RC5_ENC='${RC5_ENC}' AR='${AR}' PROCESSOR='${PROCESSOR}' PERL='${PERL}' RANLIB='${RANLIB}' testapps
67
68subdirs:
69 @for i in $(SDIRS) ;\
70 do \
71 (cd $$i && echo "making all in crypto/$$i..." && \
72 $(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; \
73 done;
74
75files:
76 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
77 @for i in $(SDIRS) ;\
78 do \
79 (cd $$i && echo "making 'files' in crypto/$$i..." && \
80 $(MAKE) PERL='${PERL}' files ); \
81 done;
82
83links:
84 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
85 @$(PERL) $(TOP)/util/mklink.pl ../include/openssl $(EXHEADER)
86 @$(PERL) $(TOP)/util/mklink.pl ../test $(TEST)
87 @$(PERL) $(TOP)/util/mklink.pl ../apps $(APPS)
88 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
89 @for i in $(SDIRS); do \
90 (cd $$i && echo "making links in crypto/$$i..." && \
91 $(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 ); \
92 done;
93
94lib: $(LIBOBJ)
95 $(AR) $(LIB) $(LIBOBJ)
96 $(RANLIB) $(LIB) || echo Never mind.
97 @touch lib
98
99shared: buildinf.h lib subdirs
100 if [ -n "$(SHARED_LIBS)" ]; then \
101 (cd ..; $(MAKE) $(SHARED_LIB)); \
102 fi
103
104libs:
105 @for i in $(SDIRS) ;\
106 do \
107 (cd $$i && echo "making libs in crypto/$$i..." && \
108 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' lib ); \
109 done;
110
111tests:
112 @for i in $(SDIRS) ;\
113 do \
114 (cd $$i && echo "making tests in crypto/$$i..." && \
115 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' AR='${AR}' tests ); \
116 done;
117
118install:
119 @for i in $(EXHEADER) ;\
120 do \
121 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
122 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
123 done;
124 @for i in $(SDIRS) ;\
125 do \
126 (cd $$i && echo "making install in crypto/$$i..." && \
127 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALL_PREFIX='${INSTALL_PREFIX}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' install ); \
128 done;
129
130lint:
131 @for i in $(SDIRS) ;\
132 do \
133 (cd $$i && echo "making lint in crypto/$$i..." && \
134 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' lint ); \
135 done;
136
137depend:
138 if [ ! -f buildinf.h ]; then touch buildinf.h; fi # fake buildinf.h if it does not exist
139 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDE) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
140 if [ ! -s buildinf.h ]; then rm buildinf.h; fi
141 @for i in $(SDIRS) ;\
142 do \
143 (cd $$i && echo "making depend in crypto/$$i..." && \
144 $(MAKE) MAKEFILE='${MAKEFILE}' INCLUDES='${INCLUDES}' CFLAG='${CFLAG}' DEPFLAG='${DEPFLAG}' MAKEDEPPROG='${MAKEDEPPROG}' KRB5_INCLUDES='${KRB5_INCLUDES}' PERL='${PERL}' depend ); \
145 done;
146
147clean:
148 rm -f buildinf.h *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
149 @for i in $(SDIRS) ;\
150 do \
151 (cd $$i && echo "making clean in crypto/$$i..." && \
152 $(MAKE) CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' clean ); \
153 done;
154
155dclean:
156 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
157 mv -f Makefile.new $(MAKEFILE)
158 @for i in $(SDIRS) ;\
159 do \
160 (cd $$i && echo "making dclean in crypto/$$i..." && \
161 $(MAKE) PERL='${PERL}' CC='$(CC)' CFLAG='${CFLAG}' INSTALLTOP='${INSTALLTOP}' PEX_LIBS='${PEX_LIBS}' EX_LIBS='${EX_LIBS}' dclean ); \
162 done;
163
164# DO NOT DELETE THIS LINE -- make depend depends on it.
165
166cpt_err.o: ../include/openssl/bio.h ../include/openssl/crypto.h
167cpt_err.o: ../include/openssl/e_os2.h ../include/openssl/err.h
168cpt_err.o: ../include/openssl/lhash.h ../include/openssl/opensslconf.h
169cpt_err.o: ../include/openssl/opensslv.h ../include/openssl/safestack.h
170cpt_err.o: ../include/openssl/stack.h ../include/openssl/symhacks.h cpt_err.c
171cryptlib.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
172cryptlib.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
173cryptlib.o: ../include/openssl/err.h ../include/openssl/lhash.h
174cryptlib.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
175cryptlib.o: ../include/openssl/safestack.h ../include/openssl/stack.h
176cryptlib.o: ../include/openssl/symhacks.h cryptlib.c cryptlib.h
177cversion.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
178cversion.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
179cversion.o: ../include/openssl/err.h ../include/openssl/lhash.h
180cversion.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
181cversion.o: ../include/openssl/safestack.h ../include/openssl/stack.h
182cversion.o: ../include/openssl/symhacks.h buildinf.h cryptlib.h cversion.c
183ebcdic.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h ebcdic.c
184ex_data.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
185ex_data.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
186ex_data.o: ../include/openssl/err.h ../include/openssl/lhash.h
187ex_data.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
188ex_data.o: ../include/openssl/safestack.h ../include/openssl/stack.h
189ex_data.o: ../include/openssl/symhacks.h cryptlib.h ex_data.c
190mem.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
191mem.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
192mem.o: ../include/openssl/err.h ../include/openssl/lhash.h
193mem.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
194mem.o: ../include/openssl/safestack.h ../include/openssl/stack.h
195mem.o: ../include/openssl/symhacks.h cryptlib.h mem.c
196mem_clr.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
197mem_clr.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
198mem_clr.o: ../include/openssl/safestack.h ../include/openssl/stack.h
199mem_clr.o: ../include/openssl/symhacks.h mem_clr.c
200mem_dbg.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
201mem_dbg.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
202mem_dbg.o: ../include/openssl/err.h ../include/openssl/lhash.h
203mem_dbg.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
204mem_dbg.o: ../include/openssl/safestack.h ../include/openssl/stack.h
205mem_dbg.o: ../include/openssl/symhacks.h cryptlib.h mem_dbg.c
206o_time.o: ../include/openssl/e_os2.h ../include/openssl/opensslconf.h o_time.c
207o_time.o: o_time.h
208tmdiff.o: ../e_os.h ../include/openssl/bio.h ../include/openssl/buffer.h
209tmdiff.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
210tmdiff.o: ../include/openssl/err.h ../include/openssl/lhash.h
211tmdiff.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
212tmdiff.o: ../include/openssl/safestack.h ../include/openssl/stack.h
213tmdiff.o: ../include/openssl/symhacks.h ../include/openssl/tmdiff.h cryptlib.h
214tmdiff.o: tmdiff.c
215uid.o: ../include/openssl/crypto.h ../include/openssl/e_os2.h
216uid.o: ../include/openssl/opensslconf.h ../include/openssl/opensslv.h
217uid.o: ../include/openssl/safestack.h ../include/openssl/stack.h
218uid.o: ../include/openssl/symhacks.h uid.c
diff --git a/src/lib/libcrypto/acss/acss.h b/src/lib/libcrypto/acss/acss.h
new file mode 100644
index 0000000000..c2d3550796
--- /dev/null
+++ b/src/lib/libcrypto/acss/acss.h
@@ -0,0 +1,47 @@
1/* $OpenBSD: acss.h,v 1.4 2005/04/25 13:20:52 miod Exp $ */
2/*
3 * Copyright (c) 2004 The OpenBSD project
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef _ACSS_H_
19#define _ACSS_H_
20
21#ifdef OPENSSL_NO_ACSS
22#error acss is disabled.
23#endif
24
25/* 40bit key */
26#define ACSS_KEYSIZE 5
27
28/* modes of acss */
29#define ACSS_MODE0 0
30#define ACSS_MODE1 1
31#define ACSS_MODE2 2
32#define ACSS_MODE3 3
33
34typedef struct acss_key_st {
35 unsigned int lfsr17; /* current state of lfsrs */
36 unsigned int lfsr25;
37 unsigned int lfsrsum;
38 unsigned char seed[ACSS_KEYSIZE];
39 unsigned char data[ACSS_KEYSIZE];
40 int encrypt;
41 int mode;
42} ACSS_KEY;
43
44void acss_setkey(ACSS_KEY *, const unsigned char *, int, int);
45void acss(ACSS_KEY *, unsigned long, const unsigned char *, unsigned char *);
46
47#endif /* ifndef _ACSS_H_ */
diff --git a/src/lib/libcrypto/acss/acss_enc.c b/src/lib/libcrypto/acss/acss_enc.c
new file mode 100644
index 0000000000..829830bc54
--- /dev/null
+++ b/src/lib/libcrypto/acss/acss_enc.c
@@ -0,0 +1,177 @@
1/* $OpenBSD: acss_enc.c,v 1.4 2004/02/13 10:05:44 hshoexer Exp $ */
2/*
3 * Copyright (c) 2004 The OpenBSD project
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/acss.h>
19
20/* decryption sbox */
21static unsigned char sboxdec[] = {
22 0x33, 0x73, 0x3b, 0x26, 0x63, 0x23, 0x6b, 0x76,
23 0x3e, 0x7e, 0x36, 0x2b, 0x6e, 0x2e, 0x66, 0x7b,
24 0xd3, 0x93, 0xdb, 0x06, 0x43, 0x03, 0x4b, 0x96,
25 0xde, 0x9e, 0xd6, 0x0b, 0x4e, 0x0e, 0x46, 0x9b,
26 0x57, 0x17, 0x5f, 0x82, 0xc7, 0x87, 0xcf, 0x12,
27 0x5a, 0x1a, 0x52, 0x8f, 0xca, 0x8a, 0xc2, 0x1f,
28 0xd9, 0x99, 0xd1, 0x00, 0x49, 0x09, 0x41, 0x90,
29 0xd8, 0x98, 0xd0, 0x01, 0x48, 0x08, 0x40, 0x91,
30 0x3d, 0x7d, 0x35, 0x24, 0x6d, 0x2d, 0x65, 0x74,
31 0x3c, 0x7c, 0x34, 0x25, 0x6c, 0x2c, 0x64, 0x75,
32 0xdd, 0x9d, 0xd5, 0x04, 0x4d, 0x0d, 0x45, 0x94,
33 0xdc, 0x9c, 0xd4, 0x05, 0x4c, 0x0c, 0x44, 0x95,
34 0x59, 0x19, 0x51, 0x80, 0xc9, 0x89, 0xc1, 0x10,
35 0x58, 0x18, 0x50, 0x81, 0xc8, 0x88, 0xc0, 0x11,
36 0xd7, 0x97, 0xdf, 0x02, 0x47, 0x07, 0x4f, 0x92,
37 0xda, 0x9a, 0xd2, 0x0f, 0x4a, 0x0a, 0x42, 0x9f,
38 0x53, 0x13, 0x5b, 0x86, 0xc3, 0x83, 0xcb, 0x16,
39 0x5e, 0x1e, 0x56, 0x8b, 0xce, 0x8e, 0xc6, 0x1b,
40 0xb3, 0xf3, 0xbb, 0xa6, 0xe3, 0xa3, 0xeb, 0xf6,
41 0xbe, 0xfe, 0xb6, 0xab, 0xee, 0xae, 0xe6, 0xfb,
42 0x37, 0x77, 0x3f, 0x22, 0x67, 0x27, 0x6f, 0x72,
43 0x3a, 0x7a, 0x32, 0x2f, 0x6a, 0x2a, 0x62, 0x7f,
44 0xb9, 0xf9, 0xb1, 0xa0, 0xe9, 0xa9, 0xe1, 0xf0,
45 0xb8, 0xf8, 0xb0, 0xa1, 0xe8, 0xa8, 0xe0, 0xf1,
46 0x5d, 0x1d, 0x55, 0x84, 0xcd, 0x8d, 0xc5, 0x14,
47 0x5c, 0x1c, 0x54, 0x85, 0xcc, 0x8c, 0xc4, 0x15,
48 0xbd, 0xfd, 0xb5, 0xa4, 0xed, 0xad, 0xe5, 0xf4,
49 0xbc, 0xfc, 0xb4, 0xa5, 0xec, 0xac, 0xe4, 0xf5,
50 0x39, 0x79, 0x31, 0x20, 0x69, 0x29, 0x61, 0x70,
51 0x38, 0x78, 0x30, 0x21, 0x68, 0x28, 0x60, 0x71,
52 0xb7, 0xf7, 0xbf, 0xa2, 0xe7, 0xa7, 0xef, 0xf2,
53 0xba, 0xfa, 0xb2, 0xaf, 0xea, 0xaa, 0xe2, 0xff
54};
55
56/* encryption sbox */
57static unsigned char sboxenc[] = {
58 0x33, 0x3b, 0x73, 0x15, 0x53, 0x5b, 0x13, 0x75,
59 0x3d, 0x35, 0x7d, 0x1b, 0x5d, 0x55, 0x1d, 0x7b,
60 0x67, 0x6f, 0x27, 0x81, 0xc7, 0xcf, 0x87, 0x21,
61 0x69, 0x61, 0x29, 0x8f, 0xc9, 0xc1, 0x89, 0x2f,
62 0xe3, 0xeb, 0xa3, 0x05, 0x43, 0x4b, 0x03, 0xa5,
63 0xed, 0xe5, 0xad, 0x0b, 0x4d, 0x45, 0x0d, 0xab,
64 0xea, 0xe2, 0xaa, 0x00, 0x4a, 0x42, 0x0a, 0xa0,
65 0xe8, 0xe0, 0xa8, 0x02, 0x48, 0x40, 0x08, 0xa2,
66 0x3e, 0x36, 0x7e, 0x14, 0x5e, 0x56, 0x1e, 0x74,
67 0x3c, 0x34, 0x7c, 0x16, 0x5c, 0x54, 0x1c, 0x76,
68 0x6a, 0x62, 0x2a, 0x80, 0xca, 0xc2, 0x8a, 0x20,
69 0x68, 0x60, 0x28, 0x82, 0xc8, 0xc0, 0x88, 0x22,
70 0xee, 0xe6, 0xae, 0x04, 0x4e, 0x46, 0x0e, 0xa4,
71 0xec, 0xe4, 0xac, 0x06, 0x4c, 0x44, 0x0c, 0xa6,
72 0xe7, 0xef, 0xa7, 0x01, 0x47, 0x4f, 0x07, 0xa1,
73 0xe9, 0xe1, 0xa9, 0x0f, 0x49, 0x41, 0x09, 0xaf,
74 0x63, 0x6b, 0x23, 0x85, 0xc3, 0xcb, 0x83, 0x25,
75 0x6d, 0x65, 0x2d, 0x8b, 0xcd, 0xc5, 0x8d, 0x2b,
76 0x37, 0x3f, 0x77, 0x11, 0x57, 0x5f, 0x17, 0x71,
77 0x39, 0x31, 0x79, 0x1f, 0x59, 0x51, 0x19, 0x7f,
78 0xb3, 0xbb, 0xf3, 0x95, 0xd3, 0xdb, 0x93, 0xf5,
79 0xbd, 0xb5, 0xfd, 0x9b, 0xdd, 0xd5, 0x9d, 0xfb,
80 0xba, 0xb2, 0xfa, 0x90, 0xda, 0xd2, 0x9a, 0xf0,
81 0xb8, 0xb0, 0xf8, 0x92, 0xd8, 0xd0, 0x98, 0xf2,
82 0x6e, 0x66, 0x2e, 0x84, 0xce, 0xc6, 0x8e, 0x24,
83 0x6c, 0x64, 0x2c, 0x86, 0xcc, 0xc4, 0x8c, 0x26,
84 0x3a, 0x32, 0x7a, 0x10, 0x5a, 0x52, 0x1a, 0x70,
85 0x38, 0x30, 0x78, 0x12, 0x58, 0x50, 0x18, 0x72,
86 0xbe, 0xb6, 0xfe, 0x94, 0xde, 0xd6, 0x9e, 0xf4,
87 0xbc, 0xb4, 0xfc, 0x96, 0xdc, 0xd4, 0x9c, 0xf6,
88 0xb7, 0xbf, 0xf7, 0x91, 0xd7, 0xdf, 0x97, 0xf1,
89 0xb9, 0xb1, 0xf9, 0x9f, 0xd9, 0xd1, 0x99, 0xff
90};
91
92/*
93 * Two linear feedback shift registers are used:
94 *
95 * lfsr17: polynomial of degree 17, primitive modulo 2 (listed in Schneier)
96 * x^15 + x + 1
97 * lfsr25: polynomial of degree 25, not know if primitive modulo 2
98 * x^13 + x^5 + x^4 + x + 1
99 *
100 * Output bits are discarded, instead the feedback bits are added to produce
101 * the cipher stream. Depending on the mode, feedback bytes may be inverted
102 * bit-wise before addition.
103 *
104 * The lfsrs are seeded with bytes from the raw key:
105 *
106 * lfsr17: byte 0[0:7] at bit 9
107 * byte 1[0:7] at bit 0
108 *
109 * lfsr25: byte 2[0:4] at bit 16
110 * byte 2[5:7] at bit 22
111 * byte 3[0:7] at bit 8
112 * byte 4[0:7] at bit 0
113 *
114 * To prevent 0 cycles, 1's are inject at bit 8 in lfrs17 and bit 21 in
115 * lfsr25.
116 *
117 */
118
119void
120acss(ACSS_KEY *key, unsigned long len, const unsigned char *in,
121 unsigned char *out)
122{
123 unsigned long i;
124 unsigned long lfsr17tmp, lfsr25tmp, lfsrsumtmp;
125
126 lfsrsumtmp = lfsr17tmp = lfsr25tmp = 0;
127
128 /* keystream is sum of lfsrs */
129 for (i = 0; i < len; i++) {
130 lfsr17tmp = key->lfsr17 ^ (key->lfsr17 >> 14);
131 key->lfsr17 = (key->lfsr17 >> 8)
132 ^ (lfsr17tmp << 9)
133 ^ (lfsr17tmp << 12)
134 ^ (lfsr17tmp << 15);
135 key->lfsr17 &= 0x1ffff; /* 17 bit LFSR */
136
137 lfsr25tmp = key->lfsr25
138 ^ (key->lfsr25 >> 3)
139 ^ (key->lfsr25 >> 4)
140 ^ (key->lfsr25 >> 12);
141 key->lfsr25 = (key->lfsr25 >> 8) ^ (lfsr25tmp << 17);
142 key->lfsr25 &= 0x1ffffff; /* 25 bit LFSR */
143
144 lfsrsumtmp = key->lfsrsum;
145
146 /* addition */
147 switch (key->mode) {
148 case ACSS_MODE3:
149 key->lfsrsum = 0xff & ~(key->lfsr17 >> 9);
150 key->lfsrsum += 0xff & ~(key->lfsr25 >> 17);
151 break;
152 case ACSS_MODE2:
153 key->lfsrsum = key->lfsr17 >> 9;
154 key->lfsrsum += 0xff & ~(key->lfsr25 >> 17);
155 break;
156 case ACSS_MODE1:
157 key->lfsrsum = 0xff & ~(key->lfsr17 >> 9);
158 key->lfsrsum += key->lfsr25 >> 17;
159 break;
160 case ACSS_MODE0:
161 default:
162 key->lfsrsum = key->lfsr17 >> 9;
163 key->lfsrsum += key->lfsr25 >> 17;
164 break;
165 }
166 key->lfsrsum += (lfsrsumtmp >> 8);
167
168 if (in == (unsigned char *)0)
169 /* generate only a keystream */
170 out[i] = key->lfsrsum & 0xff;
171 else if (key->encrypt) {
172 out[i] = sboxenc[(in[i] ^ key->lfsrsum) & 0xff];
173 } else {
174 out[i] = (sboxdec[in[i]] ^ key->lfsrsum) & 0xff;
175 }
176 }
177}
diff --git a/src/lib/libcrypto/acss/acss_skey.c b/src/lib/libcrypto/acss/acss_skey.c
new file mode 100644
index 0000000000..08e5685fcf
--- /dev/null
+++ b/src/lib/libcrypto/acss/acss_skey.c
@@ -0,0 +1,86 @@
1/* $OpenBSD: acss_skey.c,v 1.2 2004/01/23 19:23:33 hshoexer Exp $ */
2/*
3 * Copyright (c) 2004 The OpenBSD project
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <openssl/acss.h>
19
20static unsigned char reverse[] = {
21 0x00, 0x80, 0x40, 0xc0, 0x20, 0xa0, 0x60, 0xe0,
22 0x10, 0x90, 0x50, 0xd0, 0x30, 0xb0, 0x70, 0xf0,
23 0x08, 0x88, 0x48, 0xc8, 0x28, 0xa8, 0x68, 0xe8,
24 0x18, 0x98, 0x58, 0xd8, 0x38, 0xb8, 0x78, 0xf8,
25 0x04, 0x84, 0x44, 0xc4, 0x24, 0xa4, 0x64, 0xe4,
26 0x14, 0x94, 0x54, 0xd4, 0x34, 0xb4, 0x74, 0xf4,
27 0x0c, 0x8c, 0x4c, 0xcc, 0x2c, 0xac, 0x6c, 0xec,
28 0x1c, 0x9c, 0x5c, 0xdc, 0x3c, 0xbc, 0x7c, 0xfc,
29 0x02, 0x82, 0x42, 0xc2, 0x22, 0xa2, 0x62, 0xe2,
30 0x12, 0x92, 0x52, 0xd2, 0x32, 0xb2, 0x72, 0xf2,
31 0x0a, 0x8a, 0x4a, 0xca, 0x2a, 0xaa, 0x6a, 0xea,
32 0x1a, 0x9a, 0x5a, 0xda, 0x3a, 0xba, 0x7a, 0xfa,
33 0x06, 0x86, 0x46, 0xc6, 0x26, 0xa6, 0x66, 0xe6,
34 0x16, 0x96, 0x56, 0xd6, 0x36, 0xb6, 0x76, 0xf6,
35 0x0e, 0x8e, 0x4e, 0xce, 0x2e, 0xae, 0x6e, 0xee,
36 0x1e, 0x9e, 0x5e, 0xde, 0x3e, 0xbe, 0x7e, 0xfe,
37 0x01, 0x81, 0x41, 0xc1, 0x21, 0xa1, 0x61, 0xe1,
38 0x11, 0x91, 0x51, 0xd1, 0x31, 0xb1, 0x71, 0xf1,
39 0x09, 0x89, 0x49, 0xc9, 0x29, 0xa9, 0x69, 0xe9,
40 0x19, 0x99, 0x59, 0xd9, 0x39, 0xb9, 0x79, 0xf9,
41 0x05, 0x85, 0x45, 0xc5, 0x25, 0xa5, 0x65, 0xe5,
42 0x15, 0x95, 0x55, 0xd5, 0x35, 0xb5, 0x75, 0xf5,
43 0x0d, 0x8d, 0x4d, 0xcd, 0x2d, 0xad, 0x6d, 0xed,
44 0x1d, 0x9d, 0x5d, 0xdd, 0x3d, 0xbd, 0x7d, 0xfd,
45 0x03, 0x83, 0x43, 0xc3, 0x23, 0xa3, 0x63, 0xe3,
46 0x13, 0x93, 0x53, 0xd3, 0x33, 0xb3, 0x73, 0xf3,
47 0x0b, 0x8b, 0x4b, 0xcb, 0x2b, 0xab, 0x6b, 0xeb,
48 0x1b, 0x9b, 0x5b, 0xdb, 0x3b, 0xbb, 0x7b, 0xfb,
49 0x07, 0x87, 0x47, 0xc7, 0x27, 0xa7, 0x67, 0xe7,
50 0x17, 0x97, 0x57, 0xd7, 0x37, 0xb7, 0x77, 0xf7,
51 0x0f, 0x8f, 0x4f, 0xcf, 0x2f, 0xaf, 0x6f, 0xef,
52 0x1f, 0x9f, 0x5f, 0xdf, 0x3f, 0xbf, 0x7f, 0xff
53};
54
55static void
56acss_seed(ACSS_KEY *key)
57{
58 int i;
59
60 for (i = 0; i < ACSS_KEYSIZE; i++)
61 key->seed[i] = reverse[key->data[i]];
62
63 /* seed lfsrs */
64 key->lfsr17 = key->seed[1]
65 | (key->seed[0] << 9)
66 | (1 << 8); /* inject 1 at bit 9 */
67 key->lfsr25 = key->seed[4]
68 | (key->seed[3] << 8)
69 | ((key->seed[2] & 0x1f) << 16)
70 | ((key->seed[2] & 0xe0) << 17)
71 | (1 << 21); /* inject 1 at bit 22 */
72
73 key->lfsrsum = 0;
74}
75
76void
77acss_setkey(ACSS_KEY *key, const unsigned char *data, int enc, int mode)
78{
79 memcpy(key->data, data, sizeof(key->data));
80
81 if (enc != -1)
82 key->encrypt = enc;
83 key->mode = mode;
84
85 acss_seed(key);
86}
diff --git a/src/lib/libcrypto/aes/Makefile b/src/lib/libcrypto/aes/Makefile
new file mode 100644
index 0000000000..22c7203dbb
--- /dev/null
+++ b/src/lib/libcrypto/aes/Makefile
@@ -0,0 +1,130 @@
1#
2# crypto/aes/Makefile
3#
4
5DIR= aes
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14AES_ASM_OBJ=aes_core.o aes_cbc.o
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21#TEST=aestest.c
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=aes_core.c aes_misc.c aes_ecb.c aes_cbc.c aes_cfb.c aes_ofb.c \
27 aes_ctr.c aes_ige.c aes_wrap.c
28LIBOBJ=aes_misc.o aes_ecb.o aes_cfb.o aes_ofb.o aes_ctr.o aes_ige.o aes_wrap.o \
29 $(AES_ASM_OBJ)
30
31SRC= $(LIBSRC)
32
33EXHEADER= aes.h
34HEADER= aes_locl.h $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48$(LIBOBJ): $(LIBSRC)
49
50aes-ia64.s: asm/aes-ia64.S
51 $(CC) $(CFLAGS) -E asm/aes-ia64.S > $@
52
53ax86-elf.s: asm/aes-586.pl ../perlasm/x86asm.pl
54 (cd asm; $(PERL) aes-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
55ax86-cof.s: asm/aes-586.pl ../perlasm/x86asm.pl
56 (cd asm; $(PERL) aes-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
57ax86-out.s: asm/aes-586.pl ../perlasm/x86asm.pl
58 (cd asm; $(PERL) aes-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
59
60aes-x86_64.s: asm/aes-x86_64.pl
61 $(PERL) asm/aes-x86_64.pl $@
62
63files:
64 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
65
66links:
67 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
68 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
69 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
70
71install:
72 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
73 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
74 do \
75 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
76 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
77 done;
78
79tags:
80 ctags $(SRC)
81
82tests:
83
84lint:
85 lint -DLINT $(INCLUDES) $(SRC)>fluff
86
87depend:
88 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
89 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
90
91dclean:
92 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
93 mv -f Makefile.new $(MAKEFILE)
94
95clean:
96 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
97
98# DO NOT DELETE THIS LINE -- make depend depends on it.
99
100aes_cbc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
101aes_cbc.o: ../../include/openssl/opensslconf.h aes_cbc.c aes_locl.h
102aes_cfb.o: ../../e_os.h ../../include/openssl/aes.h
103aes_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
104aes_cfb.o: aes_cfb.c aes_locl.h
105aes_core.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
106aes_core.o: ../../include/openssl/opensslconf.h aes_core.c aes_locl.h
107aes_ctr.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
108aes_ctr.o: ../../include/openssl/opensslconf.h aes_ctr.c aes_locl.h
109aes_ecb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
110aes_ecb.o: ../../include/openssl/opensslconf.h aes_ecb.c aes_locl.h
111aes_ige.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/bio.h
112aes_ige.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
113aes_ige.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
114aes_ige.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
115aes_ige.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
116aes_ige.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
117aes_ige.o: ../../include/openssl/symhacks.h ../cryptlib.h aes_ige.c aes_locl.h
118aes_misc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
119aes_misc.o: ../../include/openssl/opensslconf.h
120aes_misc.o: ../../include/openssl/opensslv.h aes_locl.h aes_misc.c
121aes_ofb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
122aes_ofb.o: ../../include/openssl/opensslconf.h aes_locl.h aes_ofb.c
123aes_wrap.o: ../../e_os.h ../../include/openssl/aes.h
124aes_wrap.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
125aes_wrap.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
126aes_wrap.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
127aes_wrap.o: ../../include/openssl/opensslconf.h
128aes_wrap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
129aes_wrap.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
130aes_wrap.o: ../../include/openssl/symhacks.h ../cryptlib.h aes_wrap.c
diff --git a/src/lib/libcrypto/aes/Makefile.ssl b/src/lib/libcrypto/aes/Makefile.ssl
new file mode 100644
index 0000000000..f353aeb697
--- /dev/null
+++ b/src/lib/libcrypto/aes/Makefile.ssl
@@ -0,0 +1,103 @@
1#
2# crypto/aes/Makefile
3#
4
5DIR= aes
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP= /usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20# CFLAGS= -mpentiumpro $(INCLUDES) $(CFLAG) -O3 -fexpensive-optimizations -funroll-loops -fforce-addr
21CFLAGS= $(INCLUDES) $(CFLAG)
22
23GENERAL=Makefile
24#TEST=aestest.c
25TEST=
26APPS=
27
28LIB=$(TOP)/libcrypto.a
29LIBSRC=aes_core.c aes_misc.c aes_ecb.c aes_cbc.c aes_cfb.c aes_ofb.c aes_ctr.c
30LIBOBJ=aes_core.o aes_misc.o aes_ecb.o aes_cbc.o aes_cfb.o aes_ofb.o aes_ctr.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= aes.h
35HEADER= aes_locl.h $(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) || echo Never mind.
47 @touch lib
48
49$(LIBOBJ): $(LIBSRC)
50
51files:
52 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
53
54links:
55 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
56 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
57 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
58 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
59
60install: installs
61
62installs:
63 @for i in $(EXHEADER) ; \
64 do \
65 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
66 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
67 done;
68
69tags:
70 ctags $(SRC)
71
72tests:
73
74lint:
75 lint -DLINT $(INCLUDES) $(SRC)>fluff
76
77depend:
78 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
79
80dclean:
81 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
82 mv -f Makefile.new $(MAKEFILE)
83
84clean:
85 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
86
87# DO NOT DELETE THIS LINE -- make depend depends on it.
88
89aes_cbc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
90aes_cbc.o: ../../include/openssl/opensslconf.h aes_cbc.c aes_locl.h
91aes_cfb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
92aes_cfb.o: ../../include/openssl/opensslconf.h aes_cfb.c aes_locl.h
93aes_core.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
94aes_core.o: ../../include/openssl/opensslconf.h aes_core.c aes_locl.h
95aes_ctr.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
96aes_ctr.o: ../../include/openssl/opensslconf.h aes_ctr.c aes_locl.h
97aes_ecb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
98aes_ecb.o: ../../include/openssl/opensslconf.h aes_ecb.c aes_locl.h
99aes_misc.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
100aes_misc.o: ../../include/openssl/opensslconf.h
101aes_misc.o: ../../include/openssl/opensslv.h aes_locl.h aes_misc.c
102aes_ofb.o: ../../include/openssl/aes.h ../../include/openssl/e_os2.h
103aes_ofb.o: ../../include/openssl/opensslconf.h aes_locl.h aes_ofb.c
diff --git a/src/lib/libcrypto/aes/aes.h b/src/lib/libcrypto/aes/aes.h
index baf0222d49..8a3ea0b883 100644
--- a/src/lib/libcrypto/aes/aes.h
+++ b/src/lib/libcrypto/aes/aes.h
@@ -52,7 +52,7 @@
52#ifndef HEADER_AES_H 52#ifndef HEADER_AES_H
53#define HEADER_AES_H 53#define HEADER_AES_H
54 54
55#include <openssl/opensslconf.h> 55#include <openssl/e_os2.h>
56 56
57#ifdef OPENSSL_NO_AES 57#ifdef OPENSSL_NO_AES
58#error AES is disabled. 58#error AES is disabled.
@@ -66,17 +66,17 @@
66#define AES_MAXNR 14 66#define AES_MAXNR 14
67#define AES_BLOCK_SIZE 16 67#define AES_BLOCK_SIZE 16
68 68
69#if defined(OPENSSL_FIPS)
70#define FIPS_AES_SIZE_T int
71#endif
72
69#ifdef __cplusplus 73#ifdef __cplusplus
70extern "C" { 74extern "C" {
71#endif 75#endif
72 76
73/* This should be a hidden type, but EVP requires that the size be known */ 77/* This should be a hidden type, but EVP requires that the size be known */
74struct aes_key_st { 78struct aes_key_st {
75#ifdef AES_LONG
76 unsigned long rd_key[4 *(AES_MAXNR + 1)]; 79 unsigned long rd_key[4 *(AES_MAXNR + 1)];
77#else
78 unsigned int rd_key[4 *(AES_MAXNR + 1)];
79#endif
80 int rounds; 80 int rounds;
81}; 81};
82typedef struct aes_key_st AES_KEY; 82typedef struct aes_key_st AES_KEY;
@@ -119,23 +119,6 @@ void AES_ctr128_encrypt(const unsigned char *in, unsigned char *out,
119 unsigned char ecount_buf[AES_BLOCK_SIZE], 119 unsigned char ecount_buf[AES_BLOCK_SIZE],
120 unsigned int *num); 120 unsigned int *num);
121 121
122/* For IGE, see also http://www.links.org/files/openssl-ige.pdf */
123/* NB: the IV is _two_ blocks long */
124void AES_ige_encrypt(const unsigned char *in, unsigned char *out,
125 const unsigned long length, const AES_KEY *key,
126 unsigned char *ivec, const int enc);
127/* NB: the IV is _four_ blocks long */
128void AES_bi_ige_encrypt(const unsigned char *in, unsigned char *out,
129 const unsigned long length, const AES_KEY *key,
130 const AES_KEY *key2, const unsigned char *ivec,
131 const int enc);
132
133int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
134 unsigned char *out,
135 const unsigned char *in, unsigned int inlen);
136int AES_unwrap_key(AES_KEY *key, const unsigned char *iv,
137 unsigned char *out,
138 const unsigned char *in, unsigned int inlen);
139 122
140#ifdef __cplusplus 123#ifdef __cplusplus
141} 124}
diff --git a/src/lib/libcrypto/aes/aes_cbc.c b/src/lib/libcrypto/aes/aes_cbc.c
index d2ba6bcdb4..373864cd4b 100644
--- a/src/lib/libcrypto/aes/aes_cbc.c
+++ b/src/lib/libcrypto/aes/aes_cbc.c
@@ -59,6 +59,7 @@
59#include <openssl/aes.h> 59#include <openssl/aes.h>
60#include "aes_locl.h" 60#include "aes_locl.h"
61 61
62#if !defined(OPENSSL_FIPS_AES_ASM)
62void AES_cbc_encrypt(const unsigned char *in, unsigned char *out, 63void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
63 const unsigned long length, const AES_KEY *key, 64 const unsigned long length, const AES_KEY *key,
64 unsigned char *ivec, const int enc) { 65 unsigned char *ivec, const int enc) {
@@ -129,3 +130,4 @@ void AES_cbc_encrypt(const unsigned char *in, unsigned char *out,
129 } 130 }
130 } 131 }
131} 132}
133#endif
diff --git a/src/lib/libcrypto/aes/aes_core.c b/src/lib/libcrypto/aes/aes_core.c
index 3a80e18b0a..ed566a8123 100644
--- a/src/lib/libcrypto/aes/aes_core.c
+++ b/src/lib/libcrypto/aes/aes_core.c
@@ -37,19 +37,23 @@
37 37
38#include <stdlib.h> 38#include <stdlib.h>
39#include <openssl/aes.h> 39#include <openssl/aes.h>
40#include <openssl/fips.h>
40#include "aes_locl.h" 41#include "aes_locl.h"
41 42
43#ifndef OPENSSL_FIPS
44
42/* 45/*
43Te0[x] = S [x].[02, 01, 01, 03]; 46Te0[x] = S [x].[02, 01, 01, 03];
44Te1[x] = S [x].[03, 02, 01, 01]; 47Te1[x] = S [x].[03, 02, 01, 01];
45Te2[x] = S [x].[01, 03, 02, 01]; 48Te2[x] = S [x].[01, 03, 02, 01];
46Te3[x] = S [x].[01, 01, 03, 02]; 49Te3[x] = S [x].[01, 01, 03, 02];
50Te4[x] = S [x].[01, 01, 01, 01];
47 51
48Td0[x] = Si[x].[0e, 09, 0d, 0b]; 52Td0[x] = Si[x].[0e, 09, 0d, 0b];
49Td1[x] = Si[x].[0b, 0e, 09, 0d]; 53Td1[x] = Si[x].[0b, 0e, 09, 0d];
50Td2[x] = Si[x].[0d, 0b, 0e, 09]; 54Td2[x] = Si[x].[0d, 0b, 0e, 09];
51Td3[x] = Si[x].[09, 0d, 0b, 0e]; 55Td3[x] = Si[x].[09, 0d, 0b, 0e];
52Td4[x] = Si[x].[01]; 56Td4[x] = Si[x].[01, 01, 01, 01];
53*/ 57*/
54 58
55static const u32 Te0[256] = { 59static const u32 Te0[256] = {
@@ -251,6 +255,7 @@ static const u32 Te2[256] = {
251 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U, 255 0xb0cb7bb0U, 0x54fca854U, 0xbbd66dbbU, 0x163a2c16U,
252}; 256};
253static const u32 Te3[256] = { 257static const u32 Te3[256] = {
258
254 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U, 259 0x6363a5c6U, 0x7c7c84f8U, 0x777799eeU, 0x7b7b8df6U,
255 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U, 260 0xf2f20dffU, 0x6b6bbdd6U, 0x6f6fb1deU, 0xc5c55491U,
256 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U, 261 0x30305060U, 0x01010302U, 0x6767a9ceU, 0x2b2b7d56U,
@@ -316,7 +321,72 @@ static const u32 Te3[256] = {
316 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU, 321 0x4141c382U, 0x9999b029U, 0x2d2d775aU, 0x0f0f111eU,
317 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU, 322 0xb0b0cb7bU, 0x5454fca8U, 0xbbbbd66dU, 0x16163a2cU,
318}; 323};
319 324static const u32 Te4[256] = {
325 0x63636363U, 0x7c7c7c7cU, 0x77777777U, 0x7b7b7b7bU,
326 0xf2f2f2f2U, 0x6b6b6b6bU, 0x6f6f6f6fU, 0xc5c5c5c5U,
327 0x30303030U, 0x01010101U, 0x67676767U, 0x2b2b2b2bU,
328 0xfefefefeU, 0xd7d7d7d7U, 0xababababU, 0x76767676U,
329 0xcacacacaU, 0x82828282U, 0xc9c9c9c9U, 0x7d7d7d7dU,
330 0xfafafafaU, 0x59595959U, 0x47474747U, 0xf0f0f0f0U,
331 0xadadadadU, 0xd4d4d4d4U, 0xa2a2a2a2U, 0xafafafafU,
332 0x9c9c9c9cU, 0xa4a4a4a4U, 0x72727272U, 0xc0c0c0c0U,
333 0xb7b7b7b7U, 0xfdfdfdfdU, 0x93939393U, 0x26262626U,
334 0x36363636U, 0x3f3f3f3fU, 0xf7f7f7f7U, 0xccccccccU,
335 0x34343434U, 0xa5a5a5a5U, 0xe5e5e5e5U, 0xf1f1f1f1U,
336 0x71717171U, 0xd8d8d8d8U, 0x31313131U, 0x15151515U,
337 0x04040404U, 0xc7c7c7c7U, 0x23232323U, 0xc3c3c3c3U,
338 0x18181818U, 0x96969696U, 0x05050505U, 0x9a9a9a9aU,
339 0x07070707U, 0x12121212U, 0x80808080U, 0xe2e2e2e2U,
340 0xebebebebU, 0x27272727U, 0xb2b2b2b2U, 0x75757575U,
341 0x09090909U, 0x83838383U, 0x2c2c2c2cU, 0x1a1a1a1aU,
342 0x1b1b1b1bU, 0x6e6e6e6eU, 0x5a5a5a5aU, 0xa0a0a0a0U,
343 0x52525252U, 0x3b3b3b3bU, 0xd6d6d6d6U, 0xb3b3b3b3U,
344 0x29292929U, 0xe3e3e3e3U, 0x2f2f2f2fU, 0x84848484U,
345 0x53535353U, 0xd1d1d1d1U, 0x00000000U, 0xededededU,
346 0x20202020U, 0xfcfcfcfcU, 0xb1b1b1b1U, 0x5b5b5b5bU,
347 0x6a6a6a6aU, 0xcbcbcbcbU, 0xbebebebeU, 0x39393939U,
348 0x4a4a4a4aU, 0x4c4c4c4cU, 0x58585858U, 0xcfcfcfcfU,
349 0xd0d0d0d0U, 0xefefefefU, 0xaaaaaaaaU, 0xfbfbfbfbU,
350 0x43434343U, 0x4d4d4d4dU, 0x33333333U, 0x85858585U,
351 0x45454545U, 0xf9f9f9f9U, 0x02020202U, 0x7f7f7f7fU,
352 0x50505050U, 0x3c3c3c3cU, 0x9f9f9f9fU, 0xa8a8a8a8U,
353 0x51515151U, 0xa3a3a3a3U, 0x40404040U, 0x8f8f8f8fU,
354 0x92929292U, 0x9d9d9d9dU, 0x38383838U, 0xf5f5f5f5U,
355 0xbcbcbcbcU, 0xb6b6b6b6U, 0xdadadadaU, 0x21212121U,
356 0x10101010U, 0xffffffffU, 0xf3f3f3f3U, 0xd2d2d2d2U,
357 0xcdcdcdcdU, 0x0c0c0c0cU, 0x13131313U, 0xececececU,
358 0x5f5f5f5fU, 0x97979797U, 0x44444444U, 0x17171717U,
359 0xc4c4c4c4U, 0xa7a7a7a7U, 0x7e7e7e7eU, 0x3d3d3d3dU,
360 0x64646464U, 0x5d5d5d5dU, 0x19191919U, 0x73737373U,
361 0x60606060U, 0x81818181U, 0x4f4f4f4fU, 0xdcdcdcdcU,
362 0x22222222U, 0x2a2a2a2aU, 0x90909090U, 0x88888888U,
363 0x46464646U, 0xeeeeeeeeU, 0xb8b8b8b8U, 0x14141414U,
364 0xdedededeU, 0x5e5e5e5eU, 0x0b0b0b0bU, 0xdbdbdbdbU,
365 0xe0e0e0e0U, 0x32323232U, 0x3a3a3a3aU, 0x0a0a0a0aU,
366 0x49494949U, 0x06060606U, 0x24242424U, 0x5c5c5c5cU,
367 0xc2c2c2c2U, 0xd3d3d3d3U, 0xacacacacU, 0x62626262U,
368 0x91919191U, 0x95959595U, 0xe4e4e4e4U, 0x79797979U,
369 0xe7e7e7e7U, 0xc8c8c8c8U, 0x37373737U, 0x6d6d6d6dU,
370 0x8d8d8d8dU, 0xd5d5d5d5U, 0x4e4e4e4eU, 0xa9a9a9a9U,
371 0x6c6c6c6cU, 0x56565656U, 0xf4f4f4f4U, 0xeaeaeaeaU,
372 0x65656565U, 0x7a7a7a7aU, 0xaeaeaeaeU, 0x08080808U,
373 0xbabababaU, 0x78787878U, 0x25252525U, 0x2e2e2e2eU,
374 0x1c1c1c1cU, 0xa6a6a6a6U, 0xb4b4b4b4U, 0xc6c6c6c6U,
375 0xe8e8e8e8U, 0xddddddddU, 0x74747474U, 0x1f1f1f1fU,
376 0x4b4b4b4bU, 0xbdbdbdbdU, 0x8b8b8b8bU, 0x8a8a8a8aU,
377 0x70707070U, 0x3e3e3e3eU, 0xb5b5b5b5U, 0x66666666U,
378 0x48484848U, 0x03030303U, 0xf6f6f6f6U, 0x0e0e0e0eU,
379 0x61616161U, 0x35353535U, 0x57575757U, 0xb9b9b9b9U,
380 0x86868686U, 0xc1c1c1c1U, 0x1d1d1d1dU, 0x9e9e9e9eU,
381 0xe1e1e1e1U, 0xf8f8f8f8U, 0x98989898U, 0x11111111U,
382 0x69696969U, 0xd9d9d9d9U, 0x8e8e8e8eU, 0x94949494U,
383 0x9b9b9b9bU, 0x1e1e1e1eU, 0x87878787U, 0xe9e9e9e9U,
384 0xcecececeU, 0x55555555U, 0x28282828U, 0xdfdfdfdfU,
385 0x8c8c8c8cU, 0xa1a1a1a1U, 0x89898989U, 0x0d0d0d0dU,
386 0xbfbfbfbfU, 0xe6e6e6e6U, 0x42424242U, 0x68686868U,
387 0x41414141U, 0x99999999U, 0x2d2d2d2dU, 0x0f0f0f0fU,
388 0xb0b0b0b0U, 0x54545454U, 0xbbbbbbbbU, 0x16161616U,
389};
320static const u32 Td0[256] = { 390static const u32 Td0[256] = {
321 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U, 391 0x51f4a750U, 0x7e416553U, 0x1a17a4c3U, 0x3a275e96U,
322 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U, 392 0x3bab6bcbU, 0x1f9d45f1U, 0xacfa58abU, 0x4be30393U,
@@ -470,6 +540,7 @@ static const u32 Td2[256] = {
470 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U, 540 0xf4cd65daU, 0xbed50605U, 0x621fd134U, 0xfe8ac4a6U,
471 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U, 541 0x539d342eU, 0x55a0a2f3U, 0xe132058aU, 0xeb75a4f6U,
472 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU, 542 0xec390b83U, 0xefaa4060U, 0x9f065e71U, 0x1051bd6eU,
543
473 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U, 544 0x8af93e21U, 0x063d96ddU, 0x05aedd3eU, 0xbd464de6U,
474 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U, 545 0x8db59154U, 0x5d0571c4U, 0xd46f0406U, 0x15ff6050U,
475 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U, 546 0xfb241998U, 0xe997d6bdU, 0x43cc8940U, 0x9e7767d9U,
@@ -581,39 +652,71 @@ static const u32 Td3[256] = {
581 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U, 652 0xa8017139U, 0x0cb3de08U, 0xb4e49cd8U, 0x56c19064U,
582 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U, 653 0xcb84617bU, 0x32b670d5U, 0x6c5c7448U, 0xb85742d0U,
583}; 654};
584static const u8 Td4[256] = { 655static const u32 Td4[256] = {
585 0x52U, 0x09U, 0x6aU, 0xd5U, 0x30U, 0x36U, 0xa5U, 0x38U, 656 0x52525252U, 0x09090909U, 0x6a6a6a6aU, 0xd5d5d5d5U,
586 0xbfU, 0x40U, 0xa3U, 0x9eU, 0x81U, 0xf3U, 0xd7U, 0xfbU, 657 0x30303030U, 0x36363636U, 0xa5a5a5a5U, 0x38383838U,
587 0x7cU, 0xe3U, 0x39U, 0x82U, 0x9bU, 0x2fU, 0xffU, 0x87U, 658 0xbfbfbfbfU, 0x40404040U, 0xa3a3a3a3U, 0x9e9e9e9eU,
588 0x34U, 0x8eU, 0x43U, 0x44U, 0xc4U, 0xdeU, 0xe9U, 0xcbU, 659 0x81818181U, 0xf3f3f3f3U, 0xd7d7d7d7U, 0xfbfbfbfbU,
589 0x54U, 0x7bU, 0x94U, 0x32U, 0xa6U, 0xc2U, 0x23U, 0x3dU, 660 0x7c7c7c7cU, 0xe3e3e3e3U, 0x39393939U, 0x82828282U,
590 0xeeU, 0x4cU, 0x95U, 0x0bU, 0x42U, 0xfaU, 0xc3U, 0x4eU, 661 0x9b9b9b9bU, 0x2f2f2f2fU, 0xffffffffU, 0x87878787U,
591 0x08U, 0x2eU, 0xa1U, 0x66U, 0x28U, 0xd9U, 0x24U, 0xb2U, 662 0x34343434U, 0x8e8e8e8eU, 0x43434343U, 0x44444444U,
592 0x76U, 0x5bU, 0xa2U, 0x49U, 0x6dU, 0x8bU, 0xd1U, 0x25U, 663 0xc4c4c4c4U, 0xdedededeU, 0xe9e9e9e9U, 0xcbcbcbcbU,
593 0x72U, 0xf8U, 0xf6U, 0x64U, 0x86U, 0x68U, 0x98U, 0x16U, 664 0x54545454U, 0x7b7b7b7bU, 0x94949494U, 0x32323232U,
594 0xd4U, 0xa4U, 0x5cU, 0xccU, 0x5dU, 0x65U, 0xb6U, 0x92U, 665 0xa6a6a6a6U, 0xc2c2c2c2U, 0x23232323U, 0x3d3d3d3dU,
595 0x6cU, 0x70U, 0x48U, 0x50U, 0xfdU, 0xedU, 0xb9U, 0xdaU, 666 0xeeeeeeeeU, 0x4c4c4c4cU, 0x95959595U, 0x0b0b0b0bU,
596 0x5eU, 0x15U, 0x46U, 0x57U, 0xa7U, 0x8dU, 0x9dU, 0x84U, 667 0x42424242U, 0xfafafafaU, 0xc3c3c3c3U, 0x4e4e4e4eU,
597 0x90U, 0xd8U, 0xabU, 0x00U, 0x8cU, 0xbcU, 0xd3U, 0x0aU, 668 0x08080808U, 0x2e2e2e2eU, 0xa1a1a1a1U, 0x66666666U,
598 0xf7U, 0xe4U, 0x58U, 0x05U, 0xb8U, 0xb3U, 0x45U, 0x06U, 669 0x28282828U, 0xd9d9d9d9U, 0x24242424U, 0xb2b2b2b2U,
599 0xd0U, 0x2cU, 0x1eU, 0x8fU, 0xcaU, 0x3fU, 0x0fU, 0x02U, 670 0x76767676U, 0x5b5b5b5bU, 0xa2a2a2a2U, 0x49494949U,
600 0xc1U, 0xafU, 0xbdU, 0x03U, 0x01U, 0x13U, 0x8aU, 0x6bU, 671 0x6d6d6d6dU, 0x8b8b8b8bU, 0xd1d1d1d1U, 0x25252525U,
601 0x3aU, 0x91U, 0x11U, 0x41U, 0x4fU, 0x67U, 0xdcU, 0xeaU, 672 0x72727272U, 0xf8f8f8f8U, 0xf6f6f6f6U, 0x64646464U,
602 0x97U, 0xf2U, 0xcfU, 0xceU, 0xf0U, 0xb4U, 0xe6U, 0x73U, 673 0x86868686U, 0x68686868U, 0x98989898U, 0x16161616U,
603 0x96U, 0xacU, 0x74U, 0x22U, 0xe7U, 0xadU, 0x35U, 0x85U, 674 0xd4d4d4d4U, 0xa4a4a4a4U, 0x5c5c5c5cU, 0xccccccccU,
604 0xe2U, 0xf9U, 0x37U, 0xe8U, 0x1cU, 0x75U, 0xdfU, 0x6eU, 675 0x5d5d5d5dU, 0x65656565U, 0xb6b6b6b6U, 0x92929292U,
605 0x47U, 0xf1U, 0x1aU, 0x71U, 0x1dU, 0x29U, 0xc5U, 0x89U, 676 0x6c6c6c6cU, 0x70707070U, 0x48484848U, 0x50505050U,
606 0x6fU, 0xb7U, 0x62U, 0x0eU, 0xaaU, 0x18U, 0xbeU, 0x1bU, 677 0xfdfdfdfdU, 0xededededU, 0xb9b9b9b9U, 0xdadadadaU,
607 0xfcU, 0x56U, 0x3eU, 0x4bU, 0xc6U, 0xd2U, 0x79U, 0x20U, 678 0x5e5e5e5eU, 0x15151515U, 0x46464646U, 0x57575757U,
608 0x9aU, 0xdbU, 0xc0U, 0xfeU, 0x78U, 0xcdU, 0x5aU, 0xf4U, 679 0xa7a7a7a7U, 0x8d8d8d8dU, 0x9d9d9d9dU, 0x84848484U,
609 0x1fU, 0xddU, 0xa8U, 0x33U, 0x88U, 0x07U, 0xc7U, 0x31U, 680 0x90909090U, 0xd8d8d8d8U, 0xababababU, 0x00000000U,
610 0xb1U, 0x12U, 0x10U, 0x59U, 0x27U, 0x80U, 0xecU, 0x5fU, 681 0x8c8c8c8cU, 0xbcbcbcbcU, 0xd3d3d3d3U, 0x0a0a0a0aU,
611 0x60U, 0x51U, 0x7fU, 0xa9U, 0x19U, 0xb5U, 0x4aU, 0x0dU, 682 0xf7f7f7f7U, 0xe4e4e4e4U, 0x58585858U, 0x05050505U,
612 0x2dU, 0xe5U, 0x7aU, 0x9fU, 0x93U, 0xc9U, 0x9cU, 0xefU, 683 0xb8b8b8b8U, 0xb3b3b3b3U, 0x45454545U, 0x06060606U,
613 0xa0U, 0xe0U, 0x3bU, 0x4dU, 0xaeU, 0x2aU, 0xf5U, 0xb0U, 684 0xd0d0d0d0U, 0x2c2c2c2cU, 0x1e1e1e1eU, 0x8f8f8f8fU,
614 0xc8U, 0xebU, 0xbbU, 0x3cU, 0x83U, 0x53U, 0x99U, 0x61U, 685 0xcacacacaU, 0x3f3f3f3fU, 0x0f0f0f0fU, 0x02020202U,
615 0x17U, 0x2bU, 0x04U, 0x7eU, 0xbaU, 0x77U, 0xd6U, 0x26U, 686 0xc1c1c1c1U, 0xafafafafU, 0xbdbdbdbdU, 0x03030303U,
616 0xe1U, 0x69U, 0x14U, 0x63U, 0x55U, 0x21U, 0x0cU, 0x7dU, 687 0x01010101U, 0x13131313U, 0x8a8a8a8aU, 0x6b6b6b6bU,
688 0x3a3a3a3aU, 0x91919191U, 0x11111111U, 0x41414141U,
689 0x4f4f4f4fU, 0x67676767U, 0xdcdcdcdcU, 0xeaeaeaeaU,
690 0x97979797U, 0xf2f2f2f2U, 0xcfcfcfcfU, 0xcecececeU,
691 0xf0f0f0f0U, 0xb4b4b4b4U, 0xe6e6e6e6U, 0x73737373U,
692 0x96969696U, 0xacacacacU, 0x74747474U, 0x22222222U,
693 0xe7e7e7e7U, 0xadadadadU, 0x35353535U, 0x85858585U,
694 0xe2e2e2e2U, 0xf9f9f9f9U, 0x37373737U, 0xe8e8e8e8U,
695 0x1c1c1c1cU, 0x75757575U, 0xdfdfdfdfU, 0x6e6e6e6eU,
696 0x47474747U, 0xf1f1f1f1U, 0x1a1a1a1aU, 0x71717171U,
697 0x1d1d1d1dU, 0x29292929U, 0xc5c5c5c5U, 0x89898989U,
698 0x6f6f6f6fU, 0xb7b7b7b7U, 0x62626262U, 0x0e0e0e0eU,
699 0xaaaaaaaaU, 0x18181818U, 0xbebebebeU, 0x1b1b1b1bU,
700 0xfcfcfcfcU, 0x56565656U, 0x3e3e3e3eU, 0x4b4b4b4bU,
701 0xc6c6c6c6U, 0xd2d2d2d2U, 0x79797979U, 0x20202020U,
702 0x9a9a9a9aU, 0xdbdbdbdbU, 0xc0c0c0c0U, 0xfefefefeU,
703 0x78787878U, 0xcdcdcdcdU, 0x5a5a5a5aU, 0xf4f4f4f4U,
704 0x1f1f1f1fU, 0xddddddddU, 0xa8a8a8a8U, 0x33333333U,
705 0x88888888U, 0x07070707U, 0xc7c7c7c7U, 0x31313131U,
706 0xb1b1b1b1U, 0x12121212U, 0x10101010U, 0x59595959U,
707 0x27272727U, 0x80808080U, 0xececececU, 0x5f5f5f5fU,
708 0x60606060U, 0x51515151U, 0x7f7f7f7fU, 0xa9a9a9a9U,
709 0x19191919U, 0xb5b5b5b5U, 0x4a4a4a4aU, 0x0d0d0d0dU,
710 0x2d2d2d2dU, 0xe5e5e5e5U, 0x7a7a7a7aU, 0x9f9f9f9fU,
711 0x93939393U, 0xc9c9c9c9U, 0x9c9c9c9cU, 0xefefefefU,
712 0xa0a0a0a0U, 0xe0e0e0e0U, 0x3b3b3b3bU, 0x4d4d4d4dU,
713 0xaeaeaeaeU, 0x2a2a2a2aU, 0xf5f5f5f5U, 0xb0b0b0b0U,
714 0xc8c8c8c8U, 0xebebebebU, 0xbbbbbbbbU, 0x3c3c3c3cU,
715 0x83838383U, 0x53535353U, 0x99999999U, 0x61616161U,
716 0x17171717U, 0x2b2b2b2bU, 0x04040404U, 0x7e7e7e7eU,
717 0xbabababaU, 0x77777777U, 0xd6d6d6d6U, 0x26262626U,
718 0xe1e1e1e1U, 0x69696969U, 0x14141414U, 0x63636363U,
719 0x55555555U, 0x21212121U, 0x0c0c0c0cU, 0x7d7d7d7dU,
617}; 720};
618static const u32 rcon[] = { 721static const u32 rcon[] = {
619 0x01000000, 0x02000000, 0x04000000, 0x08000000, 722 0x01000000, 0x02000000, 0x04000000, 0x08000000,
@@ -653,10 +756,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
653 while (1) { 756 while (1) {
654 temp = rk[3]; 757 temp = rk[3];
655 rk[4] = rk[0] ^ 758 rk[4] = rk[0] ^
656 (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ 759 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
657 (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ 760 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
658 (Te0[(temp ) & 0xff] & 0x0000ff00) ^ 761 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
659 (Te1[(temp >> 24) ] & 0x000000ff) ^ 762 (Te4[(temp >> 24) ] & 0x000000ff) ^
660 rcon[i]; 763 rcon[i];
661 rk[5] = rk[1] ^ rk[4]; 764 rk[5] = rk[1] ^ rk[4];
662 rk[6] = rk[2] ^ rk[5]; 765 rk[6] = rk[2] ^ rk[5];
@@ -673,10 +776,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
673 while (1) { 776 while (1) {
674 temp = rk[ 5]; 777 temp = rk[ 5];
675 rk[ 6] = rk[ 0] ^ 778 rk[ 6] = rk[ 0] ^
676 (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ 779 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
677 (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ 780 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
678 (Te0[(temp ) & 0xff] & 0x0000ff00) ^ 781 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
679 (Te1[(temp >> 24) ] & 0x000000ff) ^ 782 (Te4[(temp >> 24) ] & 0x000000ff) ^
680 rcon[i]; 783 rcon[i];
681 rk[ 7] = rk[ 1] ^ rk[ 6]; 784 rk[ 7] = rk[ 1] ^ rk[ 6];
682 rk[ 8] = rk[ 2] ^ rk[ 7]; 785 rk[ 8] = rk[ 2] ^ rk[ 7];
@@ -695,10 +798,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
695 while (1) { 798 while (1) {
696 temp = rk[ 7]; 799 temp = rk[ 7];
697 rk[ 8] = rk[ 0] ^ 800 rk[ 8] = rk[ 0] ^
698 (Te2[(temp >> 16) & 0xff] & 0xff000000) ^ 801 (Te4[(temp >> 16) & 0xff] & 0xff000000) ^
699 (Te3[(temp >> 8) & 0xff] & 0x00ff0000) ^ 802 (Te4[(temp >> 8) & 0xff] & 0x00ff0000) ^
700 (Te0[(temp ) & 0xff] & 0x0000ff00) ^ 803 (Te4[(temp ) & 0xff] & 0x0000ff00) ^
701 (Te1[(temp >> 24) ] & 0x000000ff) ^ 804 (Te4[(temp >> 24) ] & 0x000000ff) ^
702 rcon[i]; 805 rcon[i];
703 rk[ 9] = rk[ 1] ^ rk[ 8]; 806 rk[ 9] = rk[ 1] ^ rk[ 8];
704 rk[10] = rk[ 2] ^ rk[ 9]; 807 rk[10] = rk[ 2] ^ rk[ 9];
@@ -708,10 +811,10 @@ int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
708 } 811 }
709 temp = rk[11]; 812 temp = rk[11];
710 rk[12] = rk[ 4] ^ 813 rk[12] = rk[ 4] ^
711 (Te2[(temp >> 24) ] & 0xff000000) ^ 814 (Te4[(temp >> 24) ] & 0xff000000) ^
712 (Te3[(temp >> 16) & 0xff] & 0x00ff0000) ^ 815 (Te4[(temp >> 16) & 0xff] & 0x00ff0000) ^
713 (Te0[(temp >> 8) & 0xff] & 0x0000ff00) ^ 816 (Te4[(temp >> 8) & 0xff] & 0x0000ff00) ^
714 (Te1[(temp ) & 0xff] & 0x000000ff); 817 (Te4[(temp ) & 0xff] & 0x000000ff);
715 rk[13] = rk[ 5] ^ rk[12]; 818 rk[13] = rk[ 5] ^ rk[12];
716 rk[14] = rk[ 6] ^ rk[13]; 819 rk[14] = rk[ 6] ^ rk[13];
717 rk[15] = rk[ 7] ^ rk[14]; 820 rk[15] = rk[ 7] ^ rk[14];
@@ -750,30 +853,29 @@ int AES_set_decrypt_key(const unsigned char *userKey, const int bits,
750 for (i = 1; i < (key->rounds); i++) { 853 for (i = 1; i < (key->rounds); i++) {
751 rk += 4; 854 rk += 4;
752 rk[0] = 855 rk[0] =
753 Td0[Te1[(rk[0] >> 24) ] & 0xff] ^ 856 Td0[Te4[(rk[0] >> 24) ] & 0xff] ^
754 Td1[Te1[(rk[0] >> 16) & 0xff] & 0xff] ^ 857 Td1[Te4[(rk[0] >> 16) & 0xff] & 0xff] ^
755 Td2[Te1[(rk[0] >> 8) & 0xff] & 0xff] ^ 858 Td2[Te4[(rk[0] >> 8) & 0xff] & 0xff] ^
756 Td3[Te1[(rk[0] ) & 0xff] & 0xff]; 859 Td3[Te4[(rk[0] ) & 0xff] & 0xff];
757 rk[1] = 860 rk[1] =
758 Td0[Te1[(rk[1] >> 24) ] & 0xff] ^ 861 Td0[Te4[(rk[1] >> 24) ] & 0xff] ^
759 Td1[Te1[(rk[1] >> 16) & 0xff] & 0xff] ^ 862 Td1[Te4[(rk[1] >> 16) & 0xff] & 0xff] ^
760 Td2[Te1[(rk[1] >> 8) & 0xff] & 0xff] ^ 863 Td2[Te4[(rk[1] >> 8) & 0xff] & 0xff] ^
761 Td3[Te1[(rk[1] ) & 0xff] & 0xff]; 864 Td3[Te4[(rk[1] ) & 0xff] & 0xff];
762 rk[2] = 865 rk[2] =
763 Td0[Te1[(rk[2] >> 24) ] & 0xff] ^ 866 Td0[Te4[(rk[2] >> 24) ] & 0xff] ^
764 Td1[Te1[(rk[2] >> 16) & 0xff] & 0xff] ^ 867 Td1[Te4[(rk[2] >> 16) & 0xff] & 0xff] ^
765 Td2[Te1[(rk[2] >> 8) & 0xff] & 0xff] ^ 868 Td2[Te4[(rk[2] >> 8) & 0xff] & 0xff] ^
766 Td3[Te1[(rk[2] ) & 0xff] & 0xff]; 869 Td3[Te4[(rk[2] ) & 0xff] & 0xff];
767 rk[3] = 870 rk[3] =
768 Td0[Te1[(rk[3] >> 24) ] & 0xff] ^ 871 Td0[Te4[(rk[3] >> 24) ] & 0xff] ^
769 Td1[Te1[(rk[3] >> 16) & 0xff] & 0xff] ^ 872 Td1[Te4[(rk[3] >> 16) & 0xff] & 0xff] ^
770 Td2[Te1[(rk[3] >> 8) & 0xff] & 0xff] ^ 873 Td2[Te4[(rk[3] >> 8) & 0xff] & 0xff] ^
771 Td3[Te1[(rk[3] ) & 0xff] & 0xff]; 874 Td3[Te4[(rk[3] ) & 0xff] & 0xff];
772 } 875 }
773 return 0; 876 return 0;
774} 877}
775 878
776#ifndef AES_ASM
777/* 879/*
778 * Encrypt a single block 880 * Encrypt a single block
779 * in and out can overlap 881 * in and out can overlap
@@ -936,31 +1038,31 @@ void AES_encrypt(const unsigned char *in, unsigned char *out,
936 * map cipher state to byte array block: 1038 * map cipher state to byte array block:
937 */ 1039 */
938 s0 = 1040 s0 =
939 (Te2[(t0 >> 24) ] & 0xff000000) ^ 1041 (Te4[(t0 >> 24) ] & 0xff000000) ^
940 (Te3[(t1 >> 16) & 0xff] & 0x00ff0000) ^ 1042 (Te4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
941 (Te0[(t2 >> 8) & 0xff] & 0x0000ff00) ^ 1043 (Te4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
942 (Te1[(t3 ) & 0xff] & 0x000000ff) ^ 1044 (Te4[(t3 ) & 0xff] & 0x000000ff) ^
943 rk[0]; 1045 rk[0];
944 PUTU32(out , s0); 1046 PUTU32(out , s0);
945 s1 = 1047 s1 =
946 (Te2[(t1 >> 24) ] & 0xff000000) ^ 1048 (Te4[(t1 >> 24) ] & 0xff000000) ^
947 (Te3[(t2 >> 16) & 0xff] & 0x00ff0000) ^ 1049 (Te4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
948 (Te0[(t3 >> 8) & 0xff] & 0x0000ff00) ^ 1050 (Te4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
949 (Te1[(t0 ) & 0xff] & 0x000000ff) ^ 1051 (Te4[(t0 ) & 0xff] & 0x000000ff) ^
950 rk[1]; 1052 rk[1];
951 PUTU32(out + 4, s1); 1053 PUTU32(out + 4, s1);
952 s2 = 1054 s2 =
953 (Te2[(t2 >> 24) ] & 0xff000000) ^ 1055 (Te4[(t2 >> 24) ] & 0xff000000) ^
954 (Te3[(t3 >> 16) & 0xff] & 0x00ff0000) ^ 1056 (Te4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
955 (Te0[(t0 >> 8) & 0xff] & 0x0000ff00) ^ 1057 (Te4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
956 (Te1[(t1 ) & 0xff] & 0x000000ff) ^ 1058 (Te4[(t1 ) & 0xff] & 0x000000ff) ^
957 rk[2]; 1059 rk[2];
958 PUTU32(out + 8, s2); 1060 PUTU32(out + 8, s2);
959 s3 = 1061 s3 =
960 (Te2[(t3 >> 24) ] & 0xff000000) ^ 1062 (Te4[(t3 >> 24) ] & 0xff000000) ^
961 (Te3[(t0 >> 16) & 0xff] & 0x00ff0000) ^ 1063 (Te4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
962 (Te0[(t1 >> 8) & 0xff] & 0x0000ff00) ^ 1064 (Te4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
963 (Te1[(t2 ) & 0xff] & 0x000000ff) ^ 1065 (Te4[(t2 ) & 0xff] & 0x000000ff) ^
964 rk[3]; 1066 rk[3];
965 PUTU32(out + 12, s3); 1067 PUTU32(out + 12, s3);
966} 1068}
@@ -1127,33 +1229,33 @@ void AES_decrypt(const unsigned char *in, unsigned char *out,
1127 * map cipher state to byte array block: 1229 * map cipher state to byte array block:
1128 */ 1230 */
1129 s0 = 1231 s0 =
1130 (Td4[(t0 >> 24) ] << 24) ^ 1232 (Td4[(t0 >> 24) ] & 0xff000000) ^
1131 (Td4[(t3 >> 16) & 0xff] << 16) ^ 1233 (Td4[(t3 >> 16) & 0xff] & 0x00ff0000) ^
1132 (Td4[(t2 >> 8) & 0xff] << 8) ^ 1234 (Td4[(t2 >> 8) & 0xff] & 0x0000ff00) ^
1133 (Td4[(t1 ) & 0xff]) ^ 1235 (Td4[(t1 ) & 0xff] & 0x000000ff) ^
1134 rk[0]; 1236 rk[0];
1135 PUTU32(out , s0); 1237 PUTU32(out , s0);
1136 s1 = 1238 s1 =
1137 (Td4[(t1 >> 24) ] << 24) ^ 1239 (Td4[(t1 >> 24) ] & 0xff000000) ^
1138 (Td4[(t0 >> 16) & 0xff] << 16) ^ 1240 (Td4[(t0 >> 16) & 0xff] & 0x00ff0000) ^
1139 (Td4[(t3 >> 8) & 0xff] << 8) ^ 1241 (Td4[(t3 >> 8) & 0xff] & 0x0000ff00) ^
1140 (Td4[(t2 ) & 0xff]) ^ 1242 (Td4[(t2 ) & 0xff] & 0x000000ff) ^
1141 rk[1]; 1243 rk[1];
1142 PUTU32(out + 4, s1); 1244 PUTU32(out + 4, s1);
1143 s2 = 1245 s2 =
1144 (Td4[(t2 >> 24) ] << 24) ^ 1246 (Td4[(t2 >> 24) ] & 0xff000000) ^
1145 (Td4[(t1 >> 16) & 0xff] << 16) ^ 1247 (Td4[(t1 >> 16) & 0xff] & 0x00ff0000) ^
1146 (Td4[(t0 >> 8) & 0xff] << 8) ^ 1248 (Td4[(t0 >> 8) & 0xff] & 0x0000ff00) ^
1147 (Td4[(t3 ) & 0xff]) ^ 1249 (Td4[(t3 ) & 0xff] & 0x000000ff) ^
1148 rk[2]; 1250 rk[2];
1149 PUTU32(out + 8, s2); 1251 PUTU32(out + 8, s2);
1150 s3 = 1252 s3 =
1151 (Td4[(t3 >> 24) ] << 24) ^ 1253 (Td4[(t3 >> 24) ] & 0xff000000) ^
1152 (Td4[(t2 >> 16) & 0xff] << 16) ^ 1254 (Td4[(t2 >> 16) & 0xff] & 0x00ff0000) ^
1153 (Td4[(t1 >> 8) & 0xff] << 8) ^ 1255 (Td4[(t1 >> 8) & 0xff] & 0x0000ff00) ^
1154 (Td4[(t0 ) & 0xff]) ^ 1256 (Td4[(t0 ) & 0xff] & 0x000000ff) ^
1155 rk[3]; 1257 rk[3];
1156 PUTU32(out + 12, s3); 1258 PUTU32(out + 12, s3);
1157} 1259}
1158 1260
1159#endif /* AES_ASM */ 1261#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/aes/aes_locl.h b/src/lib/libcrypto/aes/aes_locl.h
index 054b442d41..4184729e34 100644
--- a/src/lib/libcrypto/aes/aes_locl.h
+++ b/src/lib/libcrypto/aes/aes_locl.h
@@ -62,7 +62,7 @@
62#include <stdlib.h> 62#include <stdlib.h>
63#include <string.h> 63#include <string.h>
64 64
65#if defined(_MSC_VER) && (defined(_M_IX86) || defined(_M_AMD64) || defined(_M_X64)) 65#if defined(_MSC_VER) && !defined(_M_IA64) && !defined(OPENSSL_SYS_WINCE)
66# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) 66# define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00)
67# define GETU32(p) SWAP(*((u32 *)(p))) 67# define GETU32(p) SWAP(*((u32 *)(p)))
68# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } 68# define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); }
@@ -71,11 +71,7 @@
71# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); } 71# define PUTU32(ct, st) { (ct)[0] = (u8)((st) >> 24); (ct)[1] = (u8)((st) >> 16); (ct)[2] = (u8)((st) >> 8); (ct)[3] = (u8)(st); }
72#endif 72#endif
73 73
74#ifdef AES_LONG
75typedef unsigned long u32; 74typedef unsigned long u32;
76#else
77typedef unsigned int u32;
78#endif
79typedef unsigned short u16; 75typedef unsigned short u16;
80typedef unsigned char u8; 76typedef unsigned char u8;
81 77
diff --git a/src/lib/libcrypto/aes/aes_misc.c b/src/lib/libcrypto/aes/aes_misc.c
index 4fead1b4c7..090def25d5 100644
--- a/src/lib/libcrypto/aes/aes_misc.c
+++ b/src/lib/libcrypto/aes/aes_misc.c
@@ -53,7 +53,7 @@
53#include <openssl/aes.h> 53#include <openssl/aes.h>
54#include "aes_locl.h" 54#include "aes_locl.h"
55 55
56const char AES_version[]="AES" OPENSSL_VERSION_PTEXT; 56const char *AES_version="AES" OPENSSL_VERSION_PTEXT;
57 57
58const char *AES_options(void) { 58const char *AES_options(void) {
59#ifdef FULL_UNROLL 59#ifdef FULL_UNROLL
diff --git a/src/lib/libcrypto/aes/asm/aes-586.pl b/src/lib/libcrypto/aes/asm/aes-586.pl
index 89fa261794..688fda21ff 100644
--- a/src/lib/libcrypto/aes/asm/aes-586.pl
+++ b/src/lib/libcrypto/aes/asm/aes-586.pl
@@ -6,7 +6,7 @@
6# forms are granted according to the OpenSSL license. 6# forms are granted according to the OpenSSL license.
7# ==================================================================== 7# ====================================================================
8# 8#
9# Version 3.6. 9# Version 2.0.
10# 10#
11# You might fail to appreciate this module performance from the first 11# You might fail to appreciate this module performance from the first
12# try. If compared to "vanilla" linux-ia32-icc target, i.e. considered 12# try. If compared to "vanilla" linux-ia32-icc target, i.e. considered
@@ -46,68 +46,43 @@
46# Instruction Level Parallelism, and it indeed resulted in up to 15% 46# Instruction Level Parallelism, and it indeed resulted in up to 15%
47# better performance on most recent µ-archs... 47# better performance on most recent µ-archs...
48# 48#
49# Third version adds AES_cbc_encrypt implementation, which resulted in 49# Current ECB performance numbers for 128-bit key in cycles per byte
50# up to 40% performance imrovement of CBC benchmark results. 40% was 50# [measure commonly used by AES benchmarkers] are:
51# observed on P4 core, where "overall" imrovement coefficient, i.e. if
52# compared to PIC generated by GCC and in CBC mode, was observed to be
53# as large as 4x:-) CBC performance is virtually identical to ECB now
54# and on some platforms even better, e.g. 17.6 "small" cycles/byte on
55# Opteron, because certain function prologues and epilogues are
56# effectively taken out of the loop...
57#
58# Version 3.2 implements compressed tables and prefetch of these tables
59# in CBC[!] mode. Former means that 3/4 of table references are now
60# misaligned, which unfortunately has negative impact on elder IA-32
61# implementations, Pentium suffered 30% penalty, PIII - 10%.
62#
63# Version 3.3 avoids L1 cache aliasing between stack frame and
64# S-boxes, and 3.4 - L1 cache aliasing even between key schedule. The
65# latter is achieved by copying the key schedule to controlled place in
66# stack. This unfortunately has rather strong impact on small block CBC
67# performance, ~2x deterioration on 16-byte block if compared to 3.3.
68#
69# Version 3.5 checks if there is L1 cache aliasing between user-supplied
70# key schedule and S-boxes and abstains from copying the former if
71# there is no. This allows end-user to consciously retain small block
72# performance by aligning key schedule in specific manner.
73#
74# Version 3.6 compresses Td4 to 256 bytes and prefetches it in ECB.
75#
76# Current ECB performance numbers for 128-bit key in CPU cycles per
77# processed byte [measure commonly used by AES benchmarkers] are:
78# 51#
79# small footprint fully unrolled 52# small footprint fully unrolled
80# P4 24 22 53# P4[-3] 23[24] 22[23]
81# AMD K8 20 19 54# AMD K8 19 18
82# PIII 25 23 55# PIII 26(*) 23
83# Pentium 81 78 56# Pentium 63(*) 52
57#
58# (*) Performance difference between small footprint code and fully
59# unrolled in more commonly used CBC mode is not as big, 7% for
60# PIII and 15% for Pentium, which I consider tolerable.
84 61
85push(@INC,"perlasm","../../perlasm"); 62push(@INC,"perlasm","../../perlasm");
86require "x86asm.pl"; 63require "x86asm.pl";
87 64
88&asm_init($ARGV[0],"aes-586.pl",$ARGV[$#ARGV] eq "386"); 65&asm_init($ARGV[0],"aes-586.pl",$ARGV[$#ARGV] eq "386");
89 66
67$small_footprint=1; # $small_footprint=1 code is ~5% slower [on
68 # recent µ-archs], but ~5 times smaller!
69 # I favor compact code, because it minimizes
70 # cache contention...
71$vertical_spin=0; # shift "verticaly" defaults to 0, because of
72 # its proof-of-concept status, see below...
73
90$s0="eax"; 74$s0="eax";
91$s1="ebx"; 75$s1="ebx";
92$s2="ecx"; 76$s2="ecx";
93$s3="edx"; 77$s3="edx";
94$key="edi"; 78$key="esi";
95$acc="esi"; 79$acc="edi";
96
97$compromise=0; # $compromise=128 abstains from copying key
98 # schedule to stack when encrypting inputs
99 # shorter than 128 bytes at the cost of
100 # risksing aliasing with S-boxes. In return
101 # you get way better, up to +70%, small block
102 # performance.
103$small_footprint=1; # $small_footprint=1 code is ~5% slower [on
104 # recent µ-archs], but ~5 times smaller!
105 # I favor compact code to minimize cache
106 # contention and in hope to "collect" 5% back
107 # in real-life applications...
108$vertical_spin=0; # shift "verticaly" defaults to 0, because of
109 # its proof-of-concept status...
110 80
81if ($vertical_spin) {
82 # I need high parts of volatile registers to be accessible...
83 $s1="esi"; $key="ebx";
84 $s2="edi"; $acc="ecx";
85}
111# Note that there is no decvert(), as well as last encryption round is 86# Note that there is no decvert(), as well as last encryption round is
112# performed with "horizontal" shifts. This is because this "vertical" 87# performed with "horizontal" shifts. This is because this "vertical"
113# implementation [one which groups shifts on a given $s[i] to form a 88# implementation [one which groups shifts on a given $s[i] to form a
@@ -123,55 +98,55 @@ sub encvert()
123 my $v0 = $acc, $v1 = $key; 98 my $v0 = $acc, $v1 = $key;
124 99
125 &mov ($v0,$s[3]); # copy s3 100 &mov ($v0,$s[3]); # copy s3
126 &mov (&DWP(4,"esp"),$s[2]); # save s2 101 &mov (&DWP(0,"esp"),$s[2]); # save s2
127 &mov ($v1,$s[0]); # copy s0 102 &mov ($v1,$s[0]); # copy s0
128 &mov (&DWP(8,"esp"),$s[1]); # save s1 103 &mov (&DWP(4,"esp"),$s[1]); # save s1
129 104
130 &movz ($s[2],&HB($s[0])); 105 &movz ($s[2],&HB($s[0]));
131 &and ($s[0],0xFF); 106 &and ($s[0],0xFF);
132 &mov ($s[0],&DWP(0,$te,$s[0],8)); # s0>>0 107 &mov ($s[0],&DWP(1024*0,$te,$s[0],4)); # s0>>0
133 &shr ($v1,16); 108 &shr ($v1,16);
134 &mov ($s[3],&DWP(3,$te,$s[2],8)); # s0>>8 109 &mov ($s[3],&DWP(1024*1,$te,$s[2],4)); # s0>>8
135 &movz ($s[1],&HB($v1)); 110 &movz ($s[1],&HB($v1));
136 &and ($v1,0xFF); 111 &and ($v1,0xFF);
137 &mov ($s[2],&DWP(2,$te,$v1,8)); # s0>>16 112 &mov ($s[2],&DWP(1024*2,$te,$v1,4)); # s0>>16
138 &mov ($v1,$v0); 113 &mov ($v1,$v0);
139 &mov ($s[1],&DWP(1,$te,$s[1],8)); # s0>>24 114 &mov ($s[1],&DWP(1024*3,$te,$s[1],4)); # s0>>24
140 115
141 &and ($v0,0xFF); 116 &and ($v0,0xFF);
142 &xor ($s[3],&DWP(0,$te,$v0,8)); # s3>>0 117 &xor ($s[3],&DWP(1024*0,$te,$v0,4)); # s3>>0
143 &movz ($v0,&HB($v1)); 118 &movz ($v0,&HB($v1));
144 &shr ($v1,16); 119 &shr ($v1,16);
145 &xor ($s[2],&DWP(3,$te,$v0,8)); # s3>>8 120 &xor ($s[2],&DWP(1024*1,$te,$v0,4)); # s3>>8
146 &movz ($v0,&HB($v1)); 121 &movz ($v0,&HB($v1));
147 &and ($v1,0xFF); 122 &and ($v1,0xFF);
148 &xor ($s[1],&DWP(2,$te,$v1,8)); # s3>>16 123 &xor ($s[1],&DWP(1024*2,$te,$v1,4)); # s3>>16
149 &mov ($v1,&DWP(4,"esp")); # restore s2 124 &mov ($v1,&DWP(0,"esp")); # restore s2
150 &xor ($s[0],&DWP(1,$te,$v0,8)); # s3>>24 125 &xor ($s[0],&DWP(1024*3,$te,$v0,4)); # s3>>24
151 126
152 &mov ($v0,$v1); 127 &mov ($v0,$v1);
153 &and ($v1,0xFF); 128 &and ($v1,0xFF);
154 &xor ($s[2],&DWP(0,$te,$v1,8)); # s2>>0 129 &xor ($s[2],&DWP(1024*0,$te,$v1,4)); # s2>>0
155 &movz ($v1,&HB($v0)); 130 &movz ($v1,&HB($v0));
156 &shr ($v0,16); 131 &shr ($v0,16);
157 &xor ($s[1],&DWP(3,$te,$v1,8)); # s2>>8 132 &xor ($s[1],&DWP(1024*1,$te,$v1,4)); # s2>>8
158 &movz ($v1,&HB($v0)); 133 &movz ($v1,&HB($v0));
159 &and ($v0,0xFF); 134 &and ($v0,0xFF);
160 &xor ($s[0],&DWP(2,$te,$v0,8)); # s2>>16 135 &xor ($s[0],&DWP(1024*2,$te,$v0,4)); # s2>>16
161 &mov ($v0,&DWP(8,"esp")); # restore s1 136 &mov ($v0,&DWP(4,"esp")); # restore s1
162 &xor ($s[3],&DWP(1,$te,$v1,8)); # s2>>24 137 &xor ($s[3],&DWP(1024*3,$te,$v1,4)); # s2>>24
163 138
164 &mov ($v1,$v0); 139 &mov ($v1,$v0);
165 &and ($v0,0xFF); 140 &and ($v0,0xFF);
166 &xor ($s[1],&DWP(0,$te,$v0,8)); # s1>>0 141 &xor ($s[1],&DWP(1024*0,$te,$v0,4)); # s1>>0
167 &movz ($v0,&HB($v1)); 142 &movz ($v0,&HB($v1));
168 &shr ($v1,16); 143 &shr ($v1,16);
169 &xor ($s[0],&DWP(3,$te,$v0,8)); # s1>>8 144 &xor ($s[0],&DWP(1024*1,$te,$v0,4)); # s1>>8
170 &movz ($v0,&HB($v1)); 145 &movz ($v0,&HB($v1));
171 &and ($v1,0xFF); 146 &and ($v1,0xFF);
172 &xor ($s[3],&DWP(2,$te,$v1,8)); # s1>>16 147 &xor ($s[3],&DWP(1024*2,$te,$v1,4)); # s1>>16
173 &mov ($key,&DWP(12,"esp")); # reincarnate v1 as key 148 &mov ($key,&DWP(12,"esp")); # reincarnate v1 as key
174 &xor ($s[2],&DWP(1,$te,$v0,8)); # s1>>24 149 &xor ($s[2],&DWP(1024*3,$te,$v0,4)); # s1>>24
175} 150}
176 151
177sub encstep() 152sub encstep()
@@ -185,25 +160,25 @@ sub encstep()
185 &and ($out,0xFF); } 160 &and ($out,0xFF); }
186 if ($i==1) { &shr ($s[0],16); }#%ebx[1] 161 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
187 if ($i==2) { &shr ($s[0],24); }#%ecx[2] 162 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
188 &mov ($out,&DWP(0,$te,$out,8)); 163 &mov ($out,&DWP(1024*0,$te,$out,4));
189 164
190 if ($i==3) { $tmp=$s[1]; }##%eax 165 if ($i==3) { $tmp=$s[1]; }##%eax
191 &movz ($tmp,&HB($s[1])); 166 &movz ($tmp,&HB($s[1]));
192 &xor ($out,&DWP(3,$te,$tmp,8)); 167 &xor ($out,&DWP(1024*1,$te,$tmp,4));
193 168
194 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(4,"esp")); }##%ebx 169 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
195 else { &mov ($tmp,$s[2]); 170 else { &mov ($tmp,$s[2]);
196 &shr ($tmp,16); } 171 &shr ($tmp,16); }
197 if ($i==2) { &and ($s[1],0xFF); }#%edx[2] 172 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
198 &and ($tmp,0xFF); 173 &and ($tmp,0xFF);
199 &xor ($out,&DWP(2,$te,$tmp,8)); 174 &xor ($out,&DWP(1024*2,$te,$tmp,4));
200 175
201 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }##%ecx 176 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
202 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2] 177 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
203 else { &mov ($tmp,$s[3]); 178 else { &mov ($tmp,$s[3]);
204 &shr ($tmp,24) } 179 &shr ($tmp,24) }
205 &xor ($out,&DWP(1,$te,$tmp,8)); 180 &xor ($out,&DWP(1024*3,$te,$tmp,4));
206 if ($i<2) { &mov (&DWP(4+4*$i,"esp"),$out); } 181 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
207 if ($i==3) { &mov ($s[3],$acc); } 182 if ($i==3) { &mov ($s[3],$acc); }
208 &comment(); 183 &comment();
209} 184}
@@ -218,49 +193,60 @@ sub enclast()
218 &and ($out,0xFF); 193 &and ($out,0xFF);
219 if ($i==1) { &shr ($s[0],16); }#%ebx[1] 194 if ($i==1) { &shr ($s[0],16); }#%ebx[1]
220 if ($i==2) { &shr ($s[0],24); }#%ecx[2] 195 if ($i==2) { &shr ($s[0],24); }#%ecx[2]
221 &mov ($out,&DWP(2,$te,$out,8)); 196 &mov ($out,&DWP(1024*0,$te,$out,4));
222 &and ($out,0x000000ff); 197 &and ($out,0x000000ff);
223 198
224 if ($i==3) { $tmp=$s[1]; }##%eax 199 if ($i==3) { $tmp=$s[1]; }##%eax
225 &movz ($tmp,&HB($s[1])); 200 &movz ($tmp,&HB($s[1]));
226 &mov ($tmp,&DWP(0,$te,$tmp,8)); 201 &mov ($tmp,&DWP(0,$te,$tmp,4));
227 &and ($tmp,0x0000ff00); 202 &and ($tmp,0x0000ff00);
228 &xor ($out,$tmp); 203 &xor ($out,$tmp);
229 204
230 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(4,"esp")); }##%ebx 205 if ($i==3) { $tmp=$s[2]; &mov ($s[1],&DWP(0,"esp")); }##%ebx
231 else { mov ($tmp,$s[2]); 206 else { mov ($tmp,$s[2]);
232 &shr ($tmp,16); } 207 &shr ($tmp,16); }
233 if ($i==2) { &and ($s[1],0xFF); }#%edx[2] 208 if ($i==2) { &and ($s[1],0xFF); }#%edx[2]
234 &and ($tmp,0xFF); 209 &and ($tmp,0xFF);
235 &mov ($tmp,&DWP(0,$te,$tmp,8)); 210 &mov ($tmp,&DWP(0,$te,$tmp,4));
236 &and ($tmp,0x00ff0000); 211 &and ($tmp,0x00ff0000);
237 &xor ($out,$tmp); 212 &xor ($out,$tmp);
238 213
239 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); }##%ecx 214 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }##%ecx
240 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2] 215 elsif($i==2){ &movz ($tmp,&HB($s[3])); }#%ebx[2]
241 else { &mov ($tmp,$s[3]); 216 else { &mov ($tmp,$s[3]);
242 &shr ($tmp,24); } 217 &shr ($tmp,24); }
243 &mov ($tmp,&DWP(2,$te,$tmp,8)); 218 &mov ($tmp,&DWP(0,$te,$tmp,4));
244 &and ($tmp,0xff000000); 219 &and ($tmp,0xff000000);
245 &xor ($out,$tmp); 220 &xor ($out,$tmp);
246 if ($i<2) { &mov (&DWP(4+4*$i,"esp"),$out); } 221 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
247 if ($i==3) { &mov ($s[3],$acc); } 222 if ($i==3) { &mov ($s[3],$acc); }
248} 223}
249 224
250sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } } 225# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
251
252&public_label("AES_Te"); 226&public_label("AES_Te");
253&function_begin_B("_x86_AES_encrypt"); 227&function_begin("AES_encrypt");
254 if ($vertical_spin) { 228 &mov ($acc,&wparam(0)); # load inp
255 # I need high parts of volatile registers to be accessible... 229 &mov ($key,&wparam(2)); # load key
256 &exch ($s1="edi",$key="ebx"); 230
257 &mov ($s2="esi",$acc="ecx"); 231 &call (&label("pic_point")); # make it PIC!
258 } 232 &set_label("pic_point");
233 &blindpop("ebp");
234 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
235
236 # allocate aligned stack frame
237 &mov ($s0,"esp");
238 &sub ("esp",20);
239 &and ("esp",-16);
259 240
260 # note that caller is expected to allocate stack frame for me!
261 &mov (&DWP(12,"esp"),$key); # save key 241 &mov (&DWP(12,"esp"),$key); # save key
242 &mov (&DWP(16,"esp"),$s0); # save %esp
262 243
263 &xor ($s0,&DWP(0,$key)); # xor with key 244 &mov ($s0,&DWP(0,$acc)); # load input data
245 &mov ($s1,&DWP(4,$acc));
246 &mov ($s2,&DWP(8,$acc));
247 &mov ($s3,&DWP(12,$acc));
248
249 &xor ($s0,&DWP(0,$key));
264 &xor ($s1,&DWP(4,$key)); 250 &xor ($s1,&DWP(4,$key));
265 &xor ($s2,&DWP(8,$key)); 251 &xor ($s2,&DWP(8,$key));
266 &xor ($s3,&DWP(12,$key)); 252 &xor ($s3,&DWP(12,$key));
@@ -270,7 +256,7 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
270 if ($small_footprint) { 256 if ($small_footprint) {
271 &lea ($acc,&DWP(-2,$acc,$acc)); 257 &lea ($acc,&DWP(-2,$acc,$acc));
272 &lea ($acc,&DWP(0,$key,$acc,8)); 258 &lea ($acc,&DWP(0,$key,$acc,8));
273 &mov (&DWP(16,"esp"),$acc); # end of key schedule 259 &mov (&DWP(8,"esp"),$acc); # end of key schedule
274 &align (4); 260 &align (4);
275 &set_label("loop"); 261 &set_label("loop");
276 if ($vertical_spin) { 262 if ($vertical_spin) {
@@ -281,12 +267,12 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
281 &encstep(2,"ebp",$s2,$s3,$s0,$s1); 267 &encstep(2,"ebp",$s2,$s3,$s0,$s1);
282 &encstep(3,"ebp",$s3,$s0,$s1,$s2); 268 &encstep(3,"ebp",$s3,$s0,$s1,$s2);
283 } 269 }
284 &add ($key,16); # advance rd_key 270 &add ($key,16); # advance rd_key
285 &xor ($s0,&DWP(0,$key)); 271 &xor ($s0,&DWP(0,$key));
286 &xor ($s1,&DWP(4,$key)); 272 &xor ($s1,&DWP(4,$key));
287 &xor ($s2,&DWP(8,$key)); 273 &xor ($s2,&DWP(8,$key));
288 &xor ($s3,&DWP(12,$key)); 274 &xor ($s3,&DWP(12,$key));
289 &cmp ($key,&DWP(16,"esp")); 275 &cmp ($key,&DWP(8,"esp"));
290 &mov (&DWP(12,"esp"),$key); 276 &mov (&DWP(12,"esp"),$key);
291 &jb (&label("loop")); 277 &jb (&label("loop"));
292 } 278 }
@@ -312,7 +298,7 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
312 &xor ($s3,&DWP(16*$i+12,$key)); 298 &xor ($s3,&DWP(16*$i+12,$key));
313 } 299 }
314 &add ($key,32); 300 &add ($key,32);
315 &mov (&DWP(12,"esp"),$key); # advance rd_key 301 &mov (&DWP(12,"esp"),$key); # advance rd_key
316 &set_label("12rounds"); 302 &set_label("12rounds");
317 for ($i=1;$i<3;$i++) { 303 for ($i=1;$i<3;$i++) {
318 if ($vertical_spin) { 304 if ($vertical_spin) {
@@ -329,7 +315,7 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
329 &xor ($s3,&DWP(16*$i+12,$key)); 315 &xor ($s3,&DWP(16*$i+12,$key));
330 } 316 }
331 &add ($key,32); 317 &add ($key,32);
332 &mov (&DWP(12,"esp"),$key); # advance rd_key 318 &mov (&DWP(12,"esp"),$key); # advance rd_key
333 &set_label("10rounds"); 319 &set_label("10rounds");
334 for ($i=1;$i<10;$i++) { 320 for ($i=1;$i<10;$i++) {
335 if ($vertical_spin) { 321 if ($vertical_spin) {
@@ -347,130 +333,376 @@ sub _data_word() { my $i; while(defined($i=shift)) { &data_word($i,$i); } }
347 } 333 }
348 } 334 }
349 335
336 &add ("ebp",4*1024); # skip to Te4
350 if ($vertical_spin) { 337 if ($vertical_spin) {
351 # "reincarnate" some registers for "horizontal" spin... 338 # "reincarnate" some registers for "horizontal" spin...
352 &mov ($s1="ebx",$key="edi"); 339 &mov ($s1="ebx",$key="esi");
353 &mov ($s2="ecx",$acc="esi"); 340 &mov ($s2="ecx",$acc="edi");
354 } 341 }
355 &enclast(0,"ebp",$s0,$s1,$s2,$s3); 342 &enclast(0,"ebp",$s0,$s1,$s2,$s3);
356 &enclast(1,"ebp",$s1,$s2,$s3,$s0); 343 &enclast(1,"ebp",$s1,$s2,$s3,$s0);
357 &enclast(2,"ebp",$s2,$s3,$s0,$s1); 344 &enclast(2,"ebp",$s2,$s3,$s0,$s1);
358 &enclast(3,"ebp",$s3,$s0,$s1,$s2); 345 &enclast(3,"ebp",$s3,$s0,$s1,$s2);
359 346
347 &mov ("esp",&DWP(16,"esp")); # restore %esp
360 &add ($key,$small_footprint?16:160); 348 &add ($key,$small_footprint?16:160);
361 &xor ($s0,&DWP(0,$key)); 349 &xor ($s0,&DWP(0,$key));
362 &xor ($s1,&DWP(4,$key)); 350 &xor ($s1,&DWP(4,$key));
363 &xor ($s2,&DWP(8,$key)); 351 &xor ($s2,&DWP(8,$key));
364 &xor ($s3,&DWP(12,$key)); 352 &xor ($s3,&DWP(12,$key));
365 353
366 &ret ();
367
368&set_label("AES_Te",64); # Yes! I keep it in the code segment!
369 &_data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
370 &_data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
371 &_data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
372 &_data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
373 &_data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
374 &_data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
375 &_data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
376 &_data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
377 &_data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
378 &_data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
379 &_data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
380 &_data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
381 &_data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
382 &_data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
383 &_data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
384 &_data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
385 &_data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
386 &_data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
387 &_data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
388 &_data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
389 &_data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
390 &_data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
391 &_data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
392 &_data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
393 &_data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
394 &_data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
395 &_data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
396 &_data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
397 &_data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
398 &_data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
399 &_data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
400 &_data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
401 &_data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
402 &_data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
403 &_data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
404 &_data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
405 &_data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
406 &_data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
407 &_data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
408 &_data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
409 &_data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
410 &_data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
411 &_data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
412 &_data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
413 &_data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
414 &_data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
415 &_data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
416 &_data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
417 &_data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
418 &_data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
419 &_data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
420 &_data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
421 &_data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
422 &_data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
423 &_data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
424 &_data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
425 &_data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
426 &_data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
427 &_data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
428 &_data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
429 &_data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
430 &_data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
431 &_data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
432 &_data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
433#rcon:
434 &data_word(0x00000001, 0x00000002, 0x00000004, 0x00000008);
435 &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080);
436 &data_word(0x0000001b, 0x00000036, 0, 0, 0, 0, 0, 0);
437&function_end_B("_x86_AES_encrypt");
438
439# void AES_encrypt (const void *inp,void *out,const AES_KEY *key);
440&public_label("AES_Te");
441&function_begin("AES_encrypt");
442 &mov ($acc,&wparam(0)); # load inp
443 &mov ($key,&wparam(2)); # load key
444
445 &mov ($s0,"esp");
446 &sub ("esp",24);
447 &and ("esp",-64);
448 &add ("esp",4);
449 &mov (&DWP(16,"esp"),$s0);
450
451 &call (&label("pic_point")); # make it PIC!
452 &set_label("pic_point");
453 &blindpop("ebp");
454 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
455
456 &mov ($s0,&DWP(0,$acc)); # load input data
457 &mov ($s1,&DWP(4,$acc));
458 &mov ($s2,&DWP(8,$acc));
459 &mov ($s3,&DWP(12,$acc));
460
461 &call ("_x86_AES_encrypt");
462
463 &mov ("esp",&DWP(16,"esp"));
464
465 &mov ($acc,&wparam(1)); # load out 354 &mov ($acc,&wparam(1)); # load out
466 &mov (&DWP(0,$acc),$s0); # write output data 355 &mov (&DWP(0,$acc),$s0); # write output data
467 &mov (&DWP(4,$acc),$s1); 356 &mov (&DWP(4,$acc),$s1);
468 &mov (&DWP(8,$acc),$s2); 357 &mov (&DWP(8,$acc),$s2);
469 &mov (&DWP(12,$acc),$s3); 358 &mov (&DWP(12,$acc),$s3);
470&function_end("AES_encrypt"); 359
360 &pop ("edi");
361 &pop ("esi");
362 &pop ("ebx");
363 &pop ("ebp");
364 &ret ();
365
366&set_label("AES_Te",64); # Yes! I keep it in the code segment!
367 &data_word(0xa56363c6, 0x847c7cf8, 0x997777ee, 0x8d7b7bf6);
368 &data_word(0x0df2f2ff, 0xbd6b6bd6, 0xb16f6fde, 0x54c5c591);
369 &data_word(0x50303060, 0x03010102, 0xa96767ce, 0x7d2b2b56);
370 &data_word(0x19fefee7, 0x62d7d7b5, 0xe6abab4d, 0x9a7676ec);
371 &data_word(0x45caca8f, 0x9d82821f, 0x40c9c989, 0x877d7dfa);
372 &data_word(0x15fafaef, 0xeb5959b2, 0xc947478e, 0x0bf0f0fb);
373 &data_word(0xecadad41, 0x67d4d4b3, 0xfda2a25f, 0xeaafaf45);
374 &data_word(0xbf9c9c23, 0xf7a4a453, 0x967272e4, 0x5bc0c09b);
375 &data_word(0xc2b7b775, 0x1cfdfde1, 0xae93933d, 0x6a26264c);
376 &data_word(0x5a36366c, 0x413f3f7e, 0x02f7f7f5, 0x4fcccc83);
377 &data_word(0x5c343468, 0xf4a5a551, 0x34e5e5d1, 0x08f1f1f9);
378 &data_word(0x937171e2, 0x73d8d8ab, 0x53313162, 0x3f15152a);
379 &data_word(0x0c040408, 0x52c7c795, 0x65232346, 0x5ec3c39d);
380 &data_word(0x28181830, 0xa1969637, 0x0f05050a, 0xb59a9a2f);
381 &data_word(0x0907070e, 0x36121224, 0x9b80801b, 0x3de2e2df);
382 &data_word(0x26ebebcd, 0x6927274e, 0xcdb2b27f, 0x9f7575ea);
383 &data_word(0x1b090912, 0x9e83831d, 0x742c2c58, 0x2e1a1a34);
384 &data_word(0x2d1b1b36, 0xb26e6edc, 0xee5a5ab4, 0xfba0a05b);
385 &data_word(0xf65252a4, 0x4d3b3b76, 0x61d6d6b7, 0xceb3b37d);
386 &data_word(0x7b292952, 0x3ee3e3dd, 0x712f2f5e, 0x97848413);
387 &data_word(0xf55353a6, 0x68d1d1b9, 0x00000000, 0x2cededc1);
388 &data_word(0x60202040, 0x1ffcfce3, 0xc8b1b179, 0xed5b5bb6);
389 &data_word(0xbe6a6ad4, 0x46cbcb8d, 0xd9bebe67, 0x4b393972);
390 &data_word(0xde4a4a94, 0xd44c4c98, 0xe85858b0, 0x4acfcf85);
391 &data_word(0x6bd0d0bb, 0x2aefefc5, 0xe5aaaa4f, 0x16fbfbed);
392 &data_word(0xc5434386, 0xd74d4d9a, 0x55333366, 0x94858511);
393 &data_word(0xcf45458a, 0x10f9f9e9, 0x06020204, 0x817f7ffe);
394 &data_word(0xf05050a0, 0x443c3c78, 0xba9f9f25, 0xe3a8a84b);
395 &data_word(0xf35151a2, 0xfea3a35d, 0xc0404080, 0x8a8f8f05);
396 &data_word(0xad92923f, 0xbc9d9d21, 0x48383870, 0x04f5f5f1);
397 &data_word(0xdfbcbc63, 0xc1b6b677, 0x75dadaaf, 0x63212142);
398 &data_word(0x30101020, 0x1affffe5, 0x0ef3f3fd, 0x6dd2d2bf);
399 &data_word(0x4ccdcd81, 0x140c0c18, 0x35131326, 0x2fececc3);
400 &data_word(0xe15f5fbe, 0xa2979735, 0xcc444488, 0x3917172e);
401 &data_word(0x57c4c493, 0xf2a7a755, 0x827e7efc, 0x473d3d7a);
402 &data_word(0xac6464c8, 0xe75d5dba, 0x2b191932, 0x957373e6);
403 &data_word(0xa06060c0, 0x98818119, 0xd14f4f9e, 0x7fdcdca3);
404 &data_word(0x66222244, 0x7e2a2a54, 0xab90903b, 0x8388880b);
405 &data_word(0xca46468c, 0x29eeeec7, 0xd3b8b86b, 0x3c141428);
406 &data_word(0x79dedea7, 0xe25e5ebc, 0x1d0b0b16, 0x76dbdbad);
407 &data_word(0x3be0e0db, 0x56323264, 0x4e3a3a74, 0x1e0a0a14);
408 &data_word(0xdb494992, 0x0a06060c, 0x6c242448, 0xe45c5cb8);
409 &data_word(0x5dc2c29f, 0x6ed3d3bd, 0xefacac43, 0xa66262c4);
410 &data_word(0xa8919139, 0xa4959531, 0x37e4e4d3, 0x8b7979f2);
411 &data_word(0x32e7e7d5, 0x43c8c88b, 0x5937376e, 0xb76d6dda);
412 &data_word(0x8c8d8d01, 0x64d5d5b1, 0xd24e4e9c, 0xe0a9a949);
413 &data_word(0xb46c6cd8, 0xfa5656ac, 0x07f4f4f3, 0x25eaeacf);
414 &data_word(0xaf6565ca, 0x8e7a7af4, 0xe9aeae47, 0x18080810);
415 &data_word(0xd5baba6f, 0x887878f0, 0x6f25254a, 0x722e2e5c);
416 &data_word(0x241c1c38, 0xf1a6a657, 0xc7b4b473, 0x51c6c697);
417 &data_word(0x23e8e8cb, 0x7cdddda1, 0x9c7474e8, 0x211f1f3e);
418 &data_word(0xdd4b4b96, 0xdcbdbd61, 0x868b8b0d, 0x858a8a0f);
419 &data_word(0x907070e0, 0x423e3e7c, 0xc4b5b571, 0xaa6666cc);
420 &data_word(0xd8484890, 0x05030306, 0x01f6f6f7, 0x120e0e1c);
421 &data_word(0xa36161c2, 0x5f35356a, 0xf95757ae, 0xd0b9b969);
422 &data_word(0x91868617, 0x58c1c199, 0x271d1d3a, 0xb99e9e27);
423 &data_word(0x38e1e1d9, 0x13f8f8eb, 0xb398982b, 0x33111122);
424 &data_word(0xbb6969d2, 0x70d9d9a9, 0x898e8e07, 0xa7949433);
425 &data_word(0xb69b9b2d, 0x221e1e3c, 0x92878715, 0x20e9e9c9);
426 &data_word(0x49cece87, 0xff5555aa, 0x78282850, 0x7adfdfa5);
427 &data_word(0x8f8c8c03, 0xf8a1a159, 0x80898909, 0x170d0d1a);
428 &data_word(0xdabfbf65, 0x31e6e6d7, 0xc6424284, 0xb86868d0);
429 &data_word(0xc3414182, 0xb0999929, 0x772d2d5a, 0x110f0f1e);
430 &data_word(0xcbb0b07b, 0xfc5454a8, 0xd6bbbb6d, 0x3a16162c);
431#Te1:
432 &data_word(0x6363c6a5, 0x7c7cf884, 0x7777ee99, 0x7b7bf68d);
433 &data_word(0xf2f2ff0d, 0x6b6bd6bd, 0x6f6fdeb1, 0xc5c59154);
434 &data_word(0x30306050, 0x01010203, 0x6767cea9, 0x2b2b567d);
435 &data_word(0xfefee719, 0xd7d7b562, 0xabab4de6, 0x7676ec9a);
436 &data_word(0xcaca8f45, 0x82821f9d, 0xc9c98940, 0x7d7dfa87);
437 &data_word(0xfafaef15, 0x5959b2eb, 0x47478ec9, 0xf0f0fb0b);
438 &data_word(0xadad41ec, 0xd4d4b367, 0xa2a25ffd, 0xafaf45ea);
439 &data_word(0x9c9c23bf, 0xa4a453f7, 0x7272e496, 0xc0c09b5b);
440 &data_word(0xb7b775c2, 0xfdfde11c, 0x93933dae, 0x26264c6a);
441 &data_word(0x36366c5a, 0x3f3f7e41, 0xf7f7f502, 0xcccc834f);
442 &data_word(0x3434685c, 0xa5a551f4, 0xe5e5d134, 0xf1f1f908);
443 &data_word(0x7171e293, 0xd8d8ab73, 0x31316253, 0x15152a3f);
444 &data_word(0x0404080c, 0xc7c79552, 0x23234665, 0xc3c39d5e);
445 &data_word(0x18183028, 0x969637a1, 0x05050a0f, 0x9a9a2fb5);
446 &data_word(0x07070e09, 0x12122436, 0x80801b9b, 0xe2e2df3d);
447 &data_word(0xebebcd26, 0x27274e69, 0xb2b27fcd, 0x7575ea9f);
448 &data_word(0x0909121b, 0x83831d9e, 0x2c2c5874, 0x1a1a342e);
449 &data_word(0x1b1b362d, 0x6e6edcb2, 0x5a5ab4ee, 0xa0a05bfb);
450 &data_word(0x5252a4f6, 0x3b3b764d, 0xd6d6b761, 0xb3b37dce);
451 &data_word(0x2929527b, 0xe3e3dd3e, 0x2f2f5e71, 0x84841397);
452 &data_word(0x5353a6f5, 0xd1d1b968, 0x00000000, 0xededc12c);
453 &data_word(0x20204060, 0xfcfce31f, 0xb1b179c8, 0x5b5bb6ed);
454 &data_word(0x6a6ad4be, 0xcbcb8d46, 0xbebe67d9, 0x3939724b);
455 &data_word(0x4a4a94de, 0x4c4c98d4, 0x5858b0e8, 0xcfcf854a);
456 &data_word(0xd0d0bb6b, 0xefefc52a, 0xaaaa4fe5, 0xfbfbed16);
457 &data_word(0x434386c5, 0x4d4d9ad7, 0x33336655, 0x85851194);
458 &data_word(0x45458acf, 0xf9f9e910, 0x02020406, 0x7f7ffe81);
459 &data_word(0x5050a0f0, 0x3c3c7844, 0x9f9f25ba, 0xa8a84be3);
460 &data_word(0x5151a2f3, 0xa3a35dfe, 0x404080c0, 0x8f8f058a);
461 &data_word(0x92923fad, 0x9d9d21bc, 0x38387048, 0xf5f5f104);
462 &data_word(0xbcbc63df, 0xb6b677c1, 0xdadaaf75, 0x21214263);
463 &data_word(0x10102030, 0xffffe51a, 0xf3f3fd0e, 0xd2d2bf6d);
464 &data_word(0xcdcd814c, 0x0c0c1814, 0x13132635, 0xececc32f);
465 &data_word(0x5f5fbee1, 0x979735a2, 0x444488cc, 0x17172e39);
466 &data_word(0xc4c49357, 0xa7a755f2, 0x7e7efc82, 0x3d3d7a47);
467 &data_word(0x6464c8ac, 0x5d5dbae7, 0x1919322b, 0x7373e695);
468 &data_word(0x6060c0a0, 0x81811998, 0x4f4f9ed1, 0xdcdca37f);
469 &data_word(0x22224466, 0x2a2a547e, 0x90903bab, 0x88880b83);
470 &data_word(0x46468cca, 0xeeeec729, 0xb8b86bd3, 0x1414283c);
471 &data_word(0xdedea779, 0x5e5ebce2, 0x0b0b161d, 0xdbdbad76);
472 &data_word(0xe0e0db3b, 0x32326456, 0x3a3a744e, 0x0a0a141e);
473 &data_word(0x494992db, 0x06060c0a, 0x2424486c, 0x5c5cb8e4);
474 &data_word(0xc2c29f5d, 0xd3d3bd6e, 0xacac43ef, 0x6262c4a6);
475 &data_word(0x919139a8, 0x959531a4, 0xe4e4d337, 0x7979f28b);
476 &data_word(0xe7e7d532, 0xc8c88b43, 0x37376e59, 0x6d6ddab7);
477 &data_word(0x8d8d018c, 0xd5d5b164, 0x4e4e9cd2, 0xa9a949e0);
478 &data_word(0x6c6cd8b4, 0x5656acfa, 0xf4f4f307, 0xeaeacf25);
479 &data_word(0x6565caaf, 0x7a7af48e, 0xaeae47e9, 0x08081018);
480 &data_word(0xbaba6fd5, 0x7878f088, 0x25254a6f, 0x2e2e5c72);
481 &data_word(0x1c1c3824, 0xa6a657f1, 0xb4b473c7, 0xc6c69751);
482 &data_word(0xe8e8cb23, 0xdddda17c, 0x7474e89c, 0x1f1f3e21);
483 &data_word(0x4b4b96dd, 0xbdbd61dc, 0x8b8b0d86, 0x8a8a0f85);
484 &data_word(0x7070e090, 0x3e3e7c42, 0xb5b571c4, 0x6666ccaa);
485 &data_word(0x484890d8, 0x03030605, 0xf6f6f701, 0x0e0e1c12);
486 &data_word(0x6161c2a3, 0x35356a5f, 0x5757aef9, 0xb9b969d0);
487 &data_word(0x86861791, 0xc1c19958, 0x1d1d3a27, 0x9e9e27b9);
488 &data_word(0xe1e1d938, 0xf8f8eb13, 0x98982bb3, 0x11112233);
489 &data_word(0x6969d2bb, 0xd9d9a970, 0x8e8e0789, 0x949433a7);
490 &data_word(0x9b9b2db6, 0x1e1e3c22, 0x87871592, 0xe9e9c920);
491 &data_word(0xcece8749, 0x5555aaff, 0x28285078, 0xdfdfa57a);
492 &data_word(0x8c8c038f, 0xa1a159f8, 0x89890980, 0x0d0d1a17);
493 &data_word(0xbfbf65da, 0xe6e6d731, 0x424284c6, 0x6868d0b8);
494 &data_word(0x414182c3, 0x999929b0, 0x2d2d5a77, 0x0f0f1e11);
495 &data_word(0xb0b07bcb, 0x5454a8fc, 0xbbbb6dd6, 0x16162c3a);
496#Te2:
497 &data_word(0x63c6a563, 0x7cf8847c, 0x77ee9977, 0x7bf68d7b);
498 &data_word(0xf2ff0df2, 0x6bd6bd6b, 0x6fdeb16f, 0xc59154c5);
499 &data_word(0x30605030, 0x01020301, 0x67cea967, 0x2b567d2b);
500 &data_word(0xfee719fe, 0xd7b562d7, 0xab4de6ab, 0x76ec9a76);
501 &data_word(0xca8f45ca, 0x821f9d82, 0xc98940c9, 0x7dfa877d);
502 &data_word(0xfaef15fa, 0x59b2eb59, 0x478ec947, 0xf0fb0bf0);
503 &data_word(0xad41ecad, 0xd4b367d4, 0xa25ffda2, 0xaf45eaaf);
504 &data_word(0x9c23bf9c, 0xa453f7a4, 0x72e49672, 0xc09b5bc0);
505 &data_word(0xb775c2b7, 0xfde11cfd, 0x933dae93, 0x264c6a26);
506 &data_word(0x366c5a36, 0x3f7e413f, 0xf7f502f7, 0xcc834fcc);
507 &data_word(0x34685c34, 0xa551f4a5, 0xe5d134e5, 0xf1f908f1);
508 &data_word(0x71e29371, 0xd8ab73d8, 0x31625331, 0x152a3f15);
509 &data_word(0x04080c04, 0xc79552c7, 0x23466523, 0xc39d5ec3);
510 &data_word(0x18302818, 0x9637a196, 0x050a0f05, 0x9a2fb59a);
511 &data_word(0x070e0907, 0x12243612, 0x801b9b80, 0xe2df3de2);
512 &data_word(0xebcd26eb, 0x274e6927, 0xb27fcdb2, 0x75ea9f75);
513 &data_word(0x09121b09, 0x831d9e83, 0x2c58742c, 0x1a342e1a);
514 &data_word(0x1b362d1b, 0x6edcb26e, 0x5ab4ee5a, 0xa05bfba0);
515 &data_word(0x52a4f652, 0x3b764d3b, 0xd6b761d6, 0xb37dceb3);
516 &data_word(0x29527b29, 0xe3dd3ee3, 0x2f5e712f, 0x84139784);
517 &data_word(0x53a6f553, 0xd1b968d1, 0x00000000, 0xedc12ced);
518 &data_word(0x20406020, 0xfce31ffc, 0xb179c8b1, 0x5bb6ed5b);
519 &data_word(0x6ad4be6a, 0xcb8d46cb, 0xbe67d9be, 0x39724b39);
520 &data_word(0x4a94de4a, 0x4c98d44c, 0x58b0e858, 0xcf854acf);
521 &data_word(0xd0bb6bd0, 0xefc52aef, 0xaa4fe5aa, 0xfbed16fb);
522 &data_word(0x4386c543, 0x4d9ad74d, 0x33665533, 0x85119485);
523 &data_word(0x458acf45, 0xf9e910f9, 0x02040602, 0x7ffe817f);
524 &data_word(0x50a0f050, 0x3c78443c, 0x9f25ba9f, 0xa84be3a8);
525 &data_word(0x51a2f351, 0xa35dfea3, 0x4080c040, 0x8f058a8f);
526 &data_word(0x923fad92, 0x9d21bc9d, 0x38704838, 0xf5f104f5);
527 &data_word(0xbc63dfbc, 0xb677c1b6, 0xdaaf75da, 0x21426321);
528 &data_word(0x10203010, 0xffe51aff, 0xf3fd0ef3, 0xd2bf6dd2);
529 &data_word(0xcd814ccd, 0x0c18140c, 0x13263513, 0xecc32fec);
530 &data_word(0x5fbee15f, 0x9735a297, 0x4488cc44, 0x172e3917);
531 &data_word(0xc49357c4, 0xa755f2a7, 0x7efc827e, 0x3d7a473d);
532 &data_word(0x64c8ac64, 0x5dbae75d, 0x19322b19, 0x73e69573);
533 &data_word(0x60c0a060, 0x81199881, 0x4f9ed14f, 0xdca37fdc);
534 &data_word(0x22446622, 0x2a547e2a, 0x903bab90, 0x880b8388);
535 &data_word(0x468cca46, 0xeec729ee, 0xb86bd3b8, 0x14283c14);
536 &data_word(0xdea779de, 0x5ebce25e, 0x0b161d0b, 0xdbad76db);
537 &data_word(0xe0db3be0, 0x32645632, 0x3a744e3a, 0x0a141e0a);
538 &data_word(0x4992db49, 0x060c0a06, 0x24486c24, 0x5cb8e45c);
539 &data_word(0xc29f5dc2, 0xd3bd6ed3, 0xac43efac, 0x62c4a662);
540 &data_word(0x9139a891, 0x9531a495, 0xe4d337e4, 0x79f28b79);
541 &data_word(0xe7d532e7, 0xc88b43c8, 0x376e5937, 0x6ddab76d);
542 &data_word(0x8d018c8d, 0xd5b164d5, 0x4e9cd24e, 0xa949e0a9);
543 &data_word(0x6cd8b46c, 0x56acfa56, 0xf4f307f4, 0xeacf25ea);
544 &data_word(0x65caaf65, 0x7af48e7a, 0xae47e9ae, 0x08101808);
545 &data_word(0xba6fd5ba, 0x78f08878, 0x254a6f25, 0x2e5c722e);
546 &data_word(0x1c38241c, 0xa657f1a6, 0xb473c7b4, 0xc69751c6);
547 &data_word(0xe8cb23e8, 0xdda17cdd, 0x74e89c74, 0x1f3e211f);
548 &data_word(0x4b96dd4b, 0xbd61dcbd, 0x8b0d868b, 0x8a0f858a);
549 &data_word(0x70e09070, 0x3e7c423e, 0xb571c4b5, 0x66ccaa66);
550 &data_word(0x4890d848, 0x03060503, 0xf6f701f6, 0x0e1c120e);
551 &data_word(0x61c2a361, 0x356a5f35, 0x57aef957, 0xb969d0b9);
552 &data_word(0x86179186, 0xc19958c1, 0x1d3a271d, 0x9e27b99e);
553 &data_word(0xe1d938e1, 0xf8eb13f8, 0x982bb398, 0x11223311);
554 &data_word(0x69d2bb69, 0xd9a970d9, 0x8e07898e, 0x9433a794);
555 &data_word(0x9b2db69b, 0x1e3c221e, 0x87159287, 0xe9c920e9);
556 &data_word(0xce8749ce, 0x55aaff55, 0x28507828, 0xdfa57adf);
557 &data_word(0x8c038f8c, 0xa159f8a1, 0x89098089, 0x0d1a170d);
558 &data_word(0xbf65dabf, 0xe6d731e6, 0x4284c642, 0x68d0b868);
559 &data_word(0x4182c341, 0x9929b099, 0x2d5a772d, 0x0f1e110f);
560 &data_word(0xb07bcbb0, 0x54a8fc54, 0xbb6dd6bb, 0x162c3a16);
561#Te3:
562 &data_word(0xc6a56363, 0xf8847c7c, 0xee997777, 0xf68d7b7b);
563 &data_word(0xff0df2f2, 0xd6bd6b6b, 0xdeb16f6f, 0x9154c5c5);
564 &data_word(0x60503030, 0x02030101, 0xcea96767, 0x567d2b2b);
565 &data_word(0xe719fefe, 0xb562d7d7, 0x4de6abab, 0xec9a7676);
566 &data_word(0x8f45caca, 0x1f9d8282, 0x8940c9c9, 0xfa877d7d);
567 &data_word(0xef15fafa, 0xb2eb5959, 0x8ec94747, 0xfb0bf0f0);
568 &data_word(0x41ecadad, 0xb367d4d4, 0x5ffda2a2, 0x45eaafaf);
569 &data_word(0x23bf9c9c, 0x53f7a4a4, 0xe4967272, 0x9b5bc0c0);
570 &data_word(0x75c2b7b7, 0xe11cfdfd, 0x3dae9393, 0x4c6a2626);
571 &data_word(0x6c5a3636, 0x7e413f3f, 0xf502f7f7, 0x834fcccc);
572 &data_word(0x685c3434, 0x51f4a5a5, 0xd134e5e5, 0xf908f1f1);
573 &data_word(0xe2937171, 0xab73d8d8, 0x62533131, 0x2a3f1515);
574 &data_word(0x080c0404, 0x9552c7c7, 0x46652323, 0x9d5ec3c3);
575 &data_word(0x30281818, 0x37a19696, 0x0a0f0505, 0x2fb59a9a);
576 &data_word(0x0e090707, 0x24361212, 0x1b9b8080, 0xdf3de2e2);
577 &data_word(0xcd26ebeb, 0x4e692727, 0x7fcdb2b2, 0xea9f7575);
578 &data_word(0x121b0909, 0x1d9e8383, 0x58742c2c, 0x342e1a1a);
579 &data_word(0x362d1b1b, 0xdcb26e6e, 0xb4ee5a5a, 0x5bfba0a0);
580 &data_word(0xa4f65252, 0x764d3b3b, 0xb761d6d6, 0x7dceb3b3);
581 &data_word(0x527b2929, 0xdd3ee3e3, 0x5e712f2f, 0x13978484);
582 &data_word(0xa6f55353, 0xb968d1d1, 0x00000000, 0xc12ceded);
583 &data_word(0x40602020, 0xe31ffcfc, 0x79c8b1b1, 0xb6ed5b5b);
584 &data_word(0xd4be6a6a, 0x8d46cbcb, 0x67d9bebe, 0x724b3939);
585 &data_word(0x94de4a4a, 0x98d44c4c, 0xb0e85858, 0x854acfcf);
586 &data_word(0xbb6bd0d0, 0xc52aefef, 0x4fe5aaaa, 0xed16fbfb);
587 &data_word(0x86c54343, 0x9ad74d4d, 0x66553333, 0x11948585);
588 &data_word(0x8acf4545, 0xe910f9f9, 0x04060202, 0xfe817f7f);
589 &data_word(0xa0f05050, 0x78443c3c, 0x25ba9f9f, 0x4be3a8a8);
590 &data_word(0xa2f35151, 0x5dfea3a3, 0x80c04040, 0x058a8f8f);
591 &data_word(0x3fad9292, 0x21bc9d9d, 0x70483838, 0xf104f5f5);
592 &data_word(0x63dfbcbc, 0x77c1b6b6, 0xaf75dada, 0x42632121);
593 &data_word(0x20301010, 0xe51affff, 0xfd0ef3f3, 0xbf6dd2d2);
594 &data_word(0x814ccdcd, 0x18140c0c, 0x26351313, 0xc32fecec);
595 &data_word(0xbee15f5f, 0x35a29797, 0x88cc4444, 0x2e391717);
596 &data_word(0x9357c4c4, 0x55f2a7a7, 0xfc827e7e, 0x7a473d3d);
597 &data_word(0xc8ac6464, 0xbae75d5d, 0x322b1919, 0xe6957373);
598 &data_word(0xc0a06060, 0x19988181, 0x9ed14f4f, 0xa37fdcdc);
599 &data_word(0x44662222, 0x547e2a2a, 0x3bab9090, 0x0b838888);
600 &data_word(0x8cca4646, 0xc729eeee, 0x6bd3b8b8, 0x283c1414);
601 &data_word(0xa779dede, 0xbce25e5e, 0x161d0b0b, 0xad76dbdb);
602 &data_word(0xdb3be0e0, 0x64563232, 0x744e3a3a, 0x141e0a0a);
603 &data_word(0x92db4949, 0x0c0a0606, 0x486c2424, 0xb8e45c5c);
604 &data_word(0x9f5dc2c2, 0xbd6ed3d3, 0x43efacac, 0xc4a66262);
605 &data_word(0x39a89191, 0x31a49595, 0xd337e4e4, 0xf28b7979);
606 &data_word(0xd532e7e7, 0x8b43c8c8, 0x6e593737, 0xdab76d6d);
607 &data_word(0x018c8d8d, 0xb164d5d5, 0x9cd24e4e, 0x49e0a9a9);
608 &data_word(0xd8b46c6c, 0xacfa5656, 0xf307f4f4, 0xcf25eaea);
609 &data_word(0xcaaf6565, 0xf48e7a7a, 0x47e9aeae, 0x10180808);
610 &data_word(0x6fd5baba, 0xf0887878, 0x4a6f2525, 0x5c722e2e);
611 &data_word(0x38241c1c, 0x57f1a6a6, 0x73c7b4b4, 0x9751c6c6);
612 &data_word(0xcb23e8e8, 0xa17cdddd, 0xe89c7474, 0x3e211f1f);
613 &data_word(0x96dd4b4b, 0x61dcbdbd, 0x0d868b8b, 0x0f858a8a);
614 &data_word(0xe0907070, 0x7c423e3e, 0x71c4b5b5, 0xccaa6666);
615 &data_word(0x90d84848, 0x06050303, 0xf701f6f6, 0x1c120e0e);
616 &data_word(0xc2a36161, 0x6a5f3535, 0xaef95757, 0x69d0b9b9);
617 &data_word(0x17918686, 0x9958c1c1, 0x3a271d1d, 0x27b99e9e);
618 &data_word(0xd938e1e1, 0xeb13f8f8, 0x2bb39898, 0x22331111);
619 &data_word(0xd2bb6969, 0xa970d9d9, 0x07898e8e, 0x33a79494);
620 &data_word(0x2db69b9b, 0x3c221e1e, 0x15928787, 0xc920e9e9);
621 &data_word(0x8749cece, 0xaaff5555, 0x50782828, 0xa57adfdf);
622 &data_word(0x038f8c8c, 0x59f8a1a1, 0x09808989, 0x1a170d0d);
623 &data_word(0x65dabfbf, 0xd731e6e6, 0x84c64242, 0xd0b86868);
624 &data_word(0x82c34141, 0x29b09999, 0x5a772d2d, 0x1e110f0f);
625 &data_word(0x7bcbb0b0, 0xa8fc5454, 0x6dd6bbbb, 0x2c3a1616);
626#Te4:
627 &data_word(0x63636363, 0x7c7c7c7c, 0x77777777, 0x7b7b7b7b);
628 &data_word(0xf2f2f2f2, 0x6b6b6b6b, 0x6f6f6f6f, 0xc5c5c5c5);
629 &data_word(0x30303030, 0x01010101, 0x67676767, 0x2b2b2b2b);
630 &data_word(0xfefefefe, 0xd7d7d7d7, 0xabababab, 0x76767676);
631 &data_word(0xcacacaca, 0x82828282, 0xc9c9c9c9, 0x7d7d7d7d);
632 &data_word(0xfafafafa, 0x59595959, 0x47474747, 0xf0f0f0f0);
633 &data_word(0xadadadad, 0xd4d4d4d4, 0xa2a2a2a2, 0xafafafaf);
634 &data_word(0x9c9c9c9c, 0xa4a4a4a4, 0x72727272, 0xc0c0c0c0);
635 &data_word(0xb7b7b7b7, 0xfdfdfdfd, 0x93939393, 0x26262626);
636 &data_word(0x36363636, 0x3f3f3f3f, 0xf7f7f7f7, 0xcccccccc);
637 &data_word(0x34343434, 0xa5a5a5a5, 0xe5e5e5e5, 0xf1f1f1f1);
638 &data_word(0x71717171, 0xd8d8d8d8, 0x31313131, 0x15151515);
639 &data_word(0x04040404, 0xc7c7c7c7, 0x23232323, 0xc3c3c3c3);
640 &data_word(0x18181818, 0x96969696, 0x05050505, 0x9a9a9a9a);
641 &data_word(0x07070707, 0x12121212, 0x80808080, 0xe2e2e2e2);
642 &data_word(0xebebebeb, 0x27272727, 0xb2b2b2b2, 0x75757575);
643 &data_word(0x09090909, 0x83838383, 0x2c2c2c2c, 0x1a1a1a1a);
644 &data_word(0x1b1b1b1b, 0x6e6e6e6e, 0x5a5a5a5a, 0xa0a0a0a0);
645 &data_word(0x52525252, 0x3b3b3b3b, 0xd6d6d6d6, 0xb3b3b3b3);
646 &data_word(0x29292929, 0xe3e3e3e3, 0x2f2f2f2f, 0x84848484);
647 &data_word(0x53535353, 0xd1d1d1d1, 0x00000000, 0xedededed);
648 &data_word(0x20202020, 0xfcfcfcfc, 0xb1b1b1b1, 0x5b5b5b5b);
649 &data_word(0x6a6a6a6a, 0xcbcbcbcb, 0xbebebebe, 0x39393939);
650 &data_word(0x4a4a4a4a, 0x4c4c4c4c, 0x58585858, 0xcfcfcfcf);
651 &data_word(0xd0d0d0d0, 0xefefefef, 0xaaaaaaaa, 0xfbfbfbfb);
652 &data_word(0x43434343, 0x4d4d4d4d, 0x33333333, 0x85858585);
653 &data_word(0x45454545, 0xf9f9f9f9, 0x02020202, 0x7f7f7f7f);
654 &data_word(0x50505050, 0x3c3c3c3c, 0x9f9f9f9f, 0xa8a8a8a8);
655 &data_word(0x51515151, 0xa3a3a3a3, 0x40404040, 0x8f8f8f8f);
656 &data_word(0x92929292, 0x9d9d9d9d, 0x38383838, 0xf5f5f5f5);
657 &data_word(0xbcbcbcbc, 0xb6b6b6b6, 0xdadadada, 0x21212121);
658 &data_word(0x10101010, 0xffffffff, 0xf3f3f3f3, 0xd2d2d2d2);
659 &data_word(0xcdcdcdcd, 0x0c0c0c0c, 0x13131313, 0xecececec);
660 &data_word(0x5f5f5f5f, 0x97979797, 0x44444444, 0x17171717);
661 &data_word(0xc4c4c4c4, 0xa7a7a7a7, 0x7e7e7e7e, 0x3d3d3d3d);
662 &data_word(0x64646464, 0x5d5d5d5d, 0x19191919, 0x73737373);
663 &data_word(0x60606060, 0x81818181, 0x4f4f4f4f, 0xdcdcdcdc);
664 &data_word(0x22222222, 0x2a2a2a2a, 0x90909090, 0x88888888);
665 &data_word(0x46464646, 0xeeeeeeee, 0xb8b8b8b8, 0x14141414);
666 &data_word(0xdededede, 0x5e5e5e5e, 0x0b0b0b0b, 0xdbdbdbdb);
667 &data_word(0xe0e0e0e0, 0x32323232, 0x3a3a3a3a, 0x0a0a0a0a);
668 &data_word(0x49494949, 0x06060606, 0x24242424, 0x5c5c5c5c);
669 &data_word(0xc2c2c2c2, 0xd3d3d3d3, 0xacacacac, 0x62626262);
670 &data_word(0x91919191, 0x95959595, 0xe4e4e4e4, 0x79797979);
671 &data_word(0xe7e7e7e7, 0xc8c8c8c8, 0x37373737, 0x6d6d6d6d);
672 &data_word(0x8d8d8d8d, 0xd5d5d5d5, 0x4e4e4e4e, 0xa9a9a9a9);
673 &data_word(0x6c6c6c6c, 0x56565656, 0xf4f4f4f4, 0xeaeaeaea);
674 &data_word(0x65656565, 0x7a7a7a7a, 0xaeaeaeae, 0x08080808);
675 &data_word(0xbabababa, 0x78787878, 0x25252525, 0x2e2e2e2e);
676 &data_word(0x1c1c1c1c, 0xa6a6a6a6, 0xb4b4b4b4, 0xc6c6c6c6);
677 &data_word(0xe8e8e8e8, 0xdddddddd, 0x74747474, 0x1f1f1f1f);
678 &data_word(0x4b4b4b4b, 0xbdbdbdbd, 0x8b8b8b8b, 0x8a8a8a8a);
679 &data_word(0x70707070, 0x3e3e3e3e, 0xb5b5b5b5, 0x66666666);
680 &data_word(0x48484848, 0x03030303, 0xf6f6f6f6, 0x0e0e0e0e);
681 &data_word(0x61616161, 0x35353535, 0x57575757, 0xb9b9b9b9);
682 &data_word(0x86868686, 0xc1c1c1c1, 0x1d1d1d1d, 0x9e9e9e9e);
683 &data_word(0xe1e1e1e1, 0xf8f8f8f8, 0x98989898, 0x11111111);
684 &data_word(0x69696969, 0xd9d9d9d9, 0x8e8e8e8e, 0x94949494);
685 &data_word(0x9b9b9b9b, 0x1e1e1e1e, 0x87878787, 0xe9e9e9e9);
686 &data_word(0xcececece, 0x55555555, 0x28282828, 0xdfdfdfdf);
687 &data_word(0x8c8c8c8c, 0xa1a1a1a1, 0x89898989, 0x0d0d0d0d);
688 &data_word(0xbfbfbfbf, 0xe6e6e6e6, 0x42424242, 0x68686868);
689 &data_word(0x41414141, 0x99999999, 0x2d2d2d2d, 0x0f0f0f0f);
690 &data_word(0xb0b0b0b0, 0x54545454, 0xbbbbbbbb, 0x16161616);
691#rcon:
692 &data_word(0x00000001, 0x00000002, 0x00000004, 0x00000008);
693 &data_word(0x00000010, 0x00000020, 0x00000040, 0x00000080);
694 &data_word(0x0000001b, 0x00000036);
695&function_end_B("AES_encrypt");
471 696
472#------------------------------------------------------------------# 697#------------------------------------------------------------------#
473 698
699$s0="eax";
700$s1="ebx";
701$s2="ecx";
702$s3="edx";
703$key="edi";
704$acc="esi";
705
474sub decstep() 706sub decstep()
475{ my ($i,$td,@s) = @_; 707{ my ($i,$td,@s) = @_;
476 my $tmp = $key; 708 my $tmp = $key;
@@ -483,24 +715,24 @@ sub decstep()
483 if($i==3) { &mov ($key,&DWP(12,"esp")); } 715 if($i==3) { &mov ($key,&DWP(12,"esp")); }
484 else { &mov ($out,$s[0]); } 716 else { &mov ($out,$s[0]); }
485 &and ($out,0xFF); 717 &and ($out,0xFF);
486 &mov ($out,&DWP(0,$td,$out,8)); 718 &mov ($out,&DWP(1024*0,$td,$out,4));
487 719
488 if ($i==3) { $tmp=$s[1]; } 720 if ($i==3) { $tmp=$s[1]; }
489 &movz ($tmp,&HB($s[1])); 721 &movz ($tmp,&HB($s[1]));
490 &xor ($out,&DWP(3,$td,$tmp,8)); 722 &xor ($out,&DWP(1024*1,$td,$tmp,4));
491 723
492 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); } 724 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
493 else { &mov ($tmp,$s[2]); } 725 else { &mov ($tmp,$s[2]); }
494 &shr ($tmp,16); 726 &shr ($tmp,16);
495 &and ($tmp,0xFF); 727 &and ($tmp,0xFF);
496 &xor ($out,&DWP(2,$td,$tmp,8)); 728 &xor ($out,&DWP(1024*2,$td,$tmp,4));
497 729
498 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); } 730 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
499 else { &mov ($tmp,$s[3]); } 731 else { &mov ($tmp,$s[3]); }
500 &shr ($tmp,24); 732 &shr ($tmp,24);
501 &xor ($out,&DWP(1,$td,$tmp,8)); 733 &xor ($out,&DWP(1024*3,$td,$tmp,4));
502 if ($i<2) { &mov (&DWP(4+4*$i,"esp"),$out); } 734 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
503 if ($i==3) { &mov ($s[3],&DWP(4,"esp")); } 735 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
504 &comment(); 736 &comment();
505} 737}
506 738
@@ -512,38 +744,58 @@ sub declast()
512 if($i==3) { &mov ($key,&DWP(12,"esp")); } 744 if($i==3) { &mov ($key,&DWP(12,"esp")); }
513 else { &mov ($out,$s[0]); } 745 else { &mov ($out,$s[0]); }
514 &and ($out,0xFF); 746 &and ($out,0xFF);
515 &movz ($out,&BP(2048,$td,$out,1)); 747 &mov ($out,&DWP(0,$td,$out,4));
748 &and ($out,0x000000ff);
516 749
517 if ($i==3) { $tmp=$s[1]; } 750 if ($i==3) { $tmp=$s[1]; }
518 &movz ($tmp,&HB($s[1])); 751 &movz ($tmp,&HB($s[1]));
519 &movz ($tmp,&BP(2048,$td,$tmp,1)); 752 &mov ($tmp,&DWP(0,$td,$tmp,4));
520 &shl ($tmp,8); 753 &and ($tmp,0x0000ff00);
521 &xor ($out,$tmp); 754 &xor ($out,$tmp);
522 755
523 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); } 756 if ($i==3) { $tmp=$s[2]; &mov ($s[1],$acc); }
524 else { mov ($tmp,$s[2]); } 757 else { mov ($tmp,$s[2]); }
525 &shr ($tmp,16); 758 &shr ($tmp,16);
526 &and ($tmp,0xFF); 759 &and ($tmp,0xFF);
527 &movz ($tmp,&BP(2048,$td,$tmp,1)); 760 &mov ($tmp,&DWP(0,$td,$tmp,4));
528 &shl ($tmp,16); 761 &and ($tmp,0x00ff0000);
529 &xor ($out,$tmp); 762 &xor ($out,$tmp);
530 763
531 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(8,"esp")); } 764 if ($i==3) { $tmp=$s[3]; &mov ($s[2],&DWP(4,"esp")); }
532 else { &mov ($tmp,$s[3]); } 765 else { &mov ($tmp,$s[3]); }
533 &shr ($tmp,24); 766 &shr ($tmp,24);
534 &movz ($tmp,&BP(2048,$td,$tmp,1)); 767 &mov ($tmp,&DWP(0,$td,$tmp,4));
535 &shl ($tmp,24); 768 &and ($tmp,0xff000000);
536 &xor ($out,$tmp); 769 &xor ($out,$tmp);
537 if ($i<2) { &mov (&DWP(4+4*$i,"esp"),$out); } 770 if ($i<2) { &mov (&DWP(4*$i,"esp"),$out); }
538 if ($i==3) { &mov ($s[3],&DWP(4,"esp")); } 771 if ($i==3) { &mov ($s[3],&DWP(0,"esp")); }
539} 772}
540 773
774# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
541&public_label("AES_Td"); 775&public_label("AES_Td");
542&function_begin_B("_x86_AES_decrypt"); 776&function_begin("AES_decrypt");
543 # note that caller is expected to allocate stack frame for me! 777 &mov ($acc,&wparam(0)); # load inp
778 &mov ($key,&wparam(2)); # load key
779
780 &call (&label("pic_point")); # make it PIC!
781 &set_label("pic_point");
782 &blindpop("ebp");
783 &lea ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
784
785 # allocate aligned stack frame
786 &mov ($s0,"esp");
787 &sub ("esp",20);
788 &and ("esp",-16);
789
544 &mov (&DWP(12,"esp"),$key); # save key 790 &mov (&DWP(12,"esp"),$key); # save key
791 &mov (&DWP(16,"esp"),$s0); # save %esp
792
793 &mov ($s0,&DWP(0,$acc)); # load input data
794 &mov ($s1,&DWP(4,$acc));
795 &mov ($s2,&DWP(8,$acc));
796 &mov ($s3,&DWP(12,$acc));
545 797
546 &xor ($s0,&DWP(0,$key)); # xor with key 798 &xor ($s0,&DWP(0,$key));
547 &xor ($s1,&DWP(4,$key)); 799 &xor ($s1,&DWP(4,$key));
548 &xor ($s2,&DWP(8,$key)); 800 &xor ($s2,&DWP(8,$key));
549 &xor ($s3,&DWP(12,$key)); 801 &xor ($s3,&DWP(12,$key));
@@ -553,19 +805,19 @@ sub declast()
553 if ($small_footprint) { 805 if ($small_footprint) {
554 &lea ($acc,&DWP(-2,$acc,$acc)); 806 &lea ($acc,&DWP(-2,$acc,$acc));
555 &lea ($acc,&DWP(0,$key,$acc,8)); 807 &lea ($acc,&DWP(0,$key,$acc,8));
556 &mov (&DWP(16,"esp"),$acc); # end of key schedule 808 &mov (&DWP(8,"esp"),$acc); # end of key schedule
557 &align (4); 809 &align (4);
558 &set_label("loop"); 810 &set_label("loop");
559 &decstep(0,"ebp",$s0,$s3,$s2,$s1); 811 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
560 &decstep(1,"ebp",$s1,$s0,$s3,$s2); 812 &decstep(1,"ebp",$s1,$s0,$s3,$s2);
561 &decstep(2,"ebp",$s2,$s1,$s0,$s3); 813 &decstep(2,"ebp",$s2,$s1,$s0,$s3);
562 &decstep(3,"ebp",$s3,$s2,$s1,$s0); 814 &decstep(3,"ebp",$s3,$s2,$s1,$s0);
563 &add ($key,16); # advance rd_key 815 &add ($key,16); # advance rd_key
564 &xor ($s0,&DWP(0,$key)); 816 &xor ($s0,&DWP(0,$key));
565 &xor ($s1,&DWP(4,$key)); 817 &xor ($s1,&DWP(4,$key));
566 &xor ($s2,&DWP(8,$key)); 818 &xor ($s2,&DWP(8,$key));
567 &xor ($s3,&DWP(12,$key)); 819 &xor ($s3,&DWP(12,$key));
568 &cmp ($key,&DWP(16,"esp")); 820 &cmp ($key,&DWP(8,"esp"));
569 &mov (&DWP(12,"esp"),$key); 821 &mov (&DWP(12,"esp"),$key);
570 &jb (&label("loop")); 822 &jb (&label("loop"));
571 } 823 }
@@ -587,7 +839,7 @@ sub declast()
587 &xor ($s3,&DWP(16*$i+12,$key)); 839 &xor ($s3,&DWP(16*$i+12,$key));
588 } 840 }
589 &add ($key,32); 841 &add ($key,32);
590 &mov (&DWP(12,"esp"),$key); # advance rd_key 842 &mov (&DWP(12,"esp"),$key); # advance rd_key
591 &set_label("12rounds"); 843 &set_label("12rounds");
592 for ($i=1;$i<3;$i++) { 844 for ($i=1;$i<3;$i++) {
593 &decstep(0,"ebp",$s0,$s3,$s2,$s1); 845 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
@@ -600,7 +852,7 @@ sub declast()
600 &xor ($s3,&DWP(16*$i+12,$key)); 852 &xor ($s3,&DWP(16*$i+12,$key));
601 } 853 }
602 &add ($key,32); 854 &add ($key,32);
603 &mov (&DWP(12,"esp"),$key); # advance rd_key 855 &mov (&DWP(12,"esp"),$key); # advance rd_key
604 &set_label("10rounds"); 856 &set_label("10rounds");
605 for ($i=1;$i<10;$i++) { 857 for ($i=1;$i<10;$i++) {
606 &decstep(0,"ebp",$s0,$s3,$s2,$s1); 858 &decstep(0,"ebp",$s0,$s3,$s2,$s1);
@@ -614,627 +866,382 @@ sub declast()
614 } 866 }
615 } 867 }
616 868
869 &add ("ebp",4*1024); # skip to Te4
617 &declast(0,"ebp",$s0,$s3,$s2,$s1); 870 &declast(0,"ebp",$s0,$s3,$s2,$s1);
618 &declast(1,"ebp",$s1,$s0,$s3,$s2); 871 &declast(1,"ebp",$s1,$s0,$s3,$s2);
619 &declast(2,"ebp",$s2,$s1,$s0,$s3); 872 &declast(2,"ebp",$s2,$s1,$s0,$s3);
620 &declast(3,"ebp",$s3,$s2,$s1,$s0); 873 &declast(3,"ebp",$s3,$s2,$s1,$s0);
621 874
875 &mov ("esp",&DWP(16,"esp")); # restore %esp
622 &add ($key,$small_footprint?16:160); 876 &add ($key,$small_footprint?16:160);
623 &xor ($s0,&DWP(0,$key)); 877 &xor ($s0,&DWP(0,$key));
624 &xor ($s1,&DWP(4,$key)); 878 &xor ($s1,&DWP(4,$key));
625 &xor ($s2,&DWP(8,$key)); 879 &xor ($s2,&DWP(8,$key));
626 &xor ($s3,&DWP(12,$key)); 880 &xor ($s3,&DWP(12,$key));
627 881
628 &ret (); 882 &mov ($key,&wparam(1)); # load out
629 883 &mov (&DWP(0,$key),$s0); # write output data
630&set_label("AES_Td",64); # Yes! I keep it in the code segment!
631 &_data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
632 &_data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
633 &_data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
634 &_data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
635 &_data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
636 &_data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
637 &_data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
638 &_data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
639 &_data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
640 &_data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
641 &_data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
642 &_data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
643 &_data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
644 &_data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
645 &_data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
646 &_data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
647 &_data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
648 &_data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
649 &_data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
650 &_data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
651 &_data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
652 &_data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
653 &_data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
654 &_data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
655 &_data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
656 &_data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
657 &_data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
658 &_data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
659 &_data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
660 &_data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
661 &_data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
662 &_data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
663 &_data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
664 &_data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
665 &_data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
666 &_data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
667 &_data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
668 &_data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
669 &_data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
670 &_data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
671 &_data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
672 &_data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
673 &_data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
674 &_data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
675 &_data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
676 &_data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
677 &_data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
678 &_data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
679 &_data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
680 &_data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
681 &_data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
682 &_data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
683 &_data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
684 &_data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
685 &_data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
686 &_data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
687 &_data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
688 &_data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
689 &_data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
690 &_data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
691 &_data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
692 &_data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
693 &_data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
694 &_data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
695#Td4:
696 &data_byte(0x52, 0x09, 0x6a, 0xd5, 0x30, 0x36, 0xa5, 0x38);
697 &data_byte(0xbf, 0x40, 0xa3, 0x9e, 0x81, 0xf3, 0xd7, 0xfb);
698 &data_byte(0x7c, 0xe3, 0x39, 0x82, 0x9b, 0x2f, 0xff, 0x87);
699 &data_byte(0x34, 0x8e, 0x43, 0x44, 0xc4, 0xde, 0xe9, 0xcb);
700 &data_byte(0x54, 0x7b, 0x94, 0x32, 0xa6, 0xc2, 0x23, 0x3d);
701 &data_byte(0xee, 0x4c, 0x95, 0x0b, 0x42, 0xfa, 0xc3, 0x4e);
702 &data_byte(0x08, 0x2e, 0xa1, 0x66, 0x28, 0xd9, 0x24, 0xb2);
703 &data_byte(0x76, 0x5b, 0xa2, 0x49, 0x6d, 0x8b, 0xd1, 0x25);
704 &data_byte(0x72, 0xf8, 0xf6, 0x64, 0x86, 0x68, 0x98, 0x16);
705 &data_byte(0xd4, 0xa4, 0x5c, 0xcc, 0x5d, 0x65, 0xb6, 0x92);
706 &data_byte(0x6c, 0x70, 0x48, 0x50, 0xfd, 0xed, 0xb9, 0xda);
707 &data_byte(0x5e, 0x15, 0x46, 0x57, 0xa7, 0x8d, 0x9d, 0x84);
708 &data_byte(0x90, 0xd8, 0xab, 0x00, 0x8c, 0xbc, 0xd3, 0x0a);
709 &data_byte(0xf7, 0xe4, 0x58, 0x05, 0xb8, 0xb3, 0x45, 0x06);
710 &data_byte(0xd0, 0x2c, 0x1e, 0x8f, 0xca, 0x3f, 0x0f, 0x02);
711 &data_byte(0xc1, 0xaf, 0xbd, 0x03, 0x01, 0x13, 0x8a, 0x6b);
712 &data_byte(0x3a, 0x91, 0x11, 0x41, 0x4f, 0x67, 0xdc, 0xea);
713 &data_byte(0x97, 0xf2, 0xcf, 0xce, 0xf0, 0xb4, 0xe6, 0x73);
714 &data_byte(0x96, 0xac, 0x74, 0x22, 0xe7, 0xad, 0x35, 0x85);
715 &data_byte(0xe2, 0xf9, 0x37, 0xe8, 0x1c, 0x75, 0xdf, 0x6e);
716 &data_byte(0x47, 0xf1, 0x1a, 0x71, 0x1d, 0x29, 0xc5, 0x89);
717 &data_byte(0x6f, 0xb7, 0x62, 0x0e, 0xaa, 0x18, 0xbe, 0x1b);
718 &data_byte(0xfc, 0x56, 0x3e, 0x4b, 0xc6, 0xd2, 0x79, 0x20);
719 &data_byte(0x9a, 0xdb, 0xc0, 0xfe, 0x78, 0xcd, 0x5a, 0xf4);
720 &data_byte(0x1f, 0xdd, 0xa8, 0x33, 0x88, 0x07, 0xc7, 0x31);
721 &data_byte(0xb1, 0x12, 0x10, 0x59, 0x27, 0x80, 0xec, 0x5f);
722 &data_byte(0x60, 0x51, 0x7f, 0xa9, 0x19, 0xb5, 0x4a, 0x0d);
723 &data_byte(0x2d, 0xe5, 0x7a, 0x9f, 0x93, 0xc9, 0x9c, 0xef);
724 &data_byte(0xa0, 0xe0, 0x3b, 0x4d, 0xae, 0x2a, 0xf5, 0xb0);
725 &data_byte(0xc8, 0xeb, 0xbb, 0x3c, 0x83, 0x53, 0x99, 0x61);
726 &data_byte(0x17, 0x2b, 0x04, 0x7e, 0xba, 0x77, 0xd6, 0x26);
727 &data_byte(0xe1, 0x69, 0x14, 0x63, 0x55, 0x21, 0x0c, 0x7d);
728&function_end_B("_x86_AES_decrypt");
729
730# void AES_decrypt (const void *inp,void *out,const AES_KEY *key);
731&public_label("AES_Td");
732&function_begin("AES_decrypt");
733 &mov ($acc,&wparam(0)); # load inp
734 &mov ($key,&wparam(2)); # load key
735
736 &mov ($s0,"esp");
737 &sub ("esp",24);
738 &and ("esp",-64);
739 &add ("esp",4);
740 &mov (&DWP(16,"esp"),$s0);
741
742 &call (&label("pic_point")); # make it PIC!
743 &set_label("pic_point");
744 &blindpop("ebp");
745 &lea ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
746
747 # prefetch Td4
748 &lea ("ebp",&DWP(2048+128,"ebp"));
749 &mov ($s0,&DWP(0-128,"ebp"));
750 &mov ($s1,&DWP(32-128,"ebp"));
751 &mov ($s2,&DWP(64-128,"ebp"));
752 &mov ($s3,&DWP(96-128,"ebp"));
753 &mov ($s0,&DWP(128-128,"ebp"));
754 &mov ($s1,&DWP(160-128,"ebp"));
755 &mov ($s2,&DWP(192-128,"ebp"));
756 &mov ($s3,&DWP(224-128,"ebp"));
757 &lea ("ebp",&DWP(-2048-128,"ebp"));
758
759 &mov ($s0,&DWP(0,$acc)); # load input data
760 &mov ($s1,&DWP(4,$acc));
761 &mov ($s2,&DWP(8,$acc));
762 &mov ($s3,&DWP(12,$acc));
763
764 &call ("_x86_AES_decrypt");
765
766 &mov ("esp",&DWP(16,"esp"));
767
768 &mov ($acc,&wparam(1)); # load out
769 &mov (&DWP(0,$acc),$s0); # write output data
770 &mov (&DWP(4,$acc),$s1);
771 &mov (&DWP(8,$acc),$s2);
772 &mov (&DWP(12,$acc),$s3);
773&function_end("AES_decrypt");
774
775# void AES_cbc_encrypt (const void char *inp, unsigned char *out,
776# size_t length, const AES_KEY *key,
777# unsigned char *ivp,const int enc);
778{
779# stack frame layout
780# -4(%esp) 0(%esp) return address
781# 0(%esp) 4(%esp) tmp1
782# 4(%esp) 8(%esp) tmp2
783# 8(%esp) 12(%esp) key
784# 12(%esp) 16(%esp) end of key schedule
785my $_esp=&DWP(16,"esp"); #saved %esp
786my $_inp=&DWP(20,"esp"); #copy of wparam(0)
787my $_out=&DWP(24,"esp"); #copy of wparam(1)
788my $_len=&DWP(28,"esp"); #copy of wparam(2)
789my $_key=&DWP(32,"esp"); #copy of wparam(3)
790my $_ivp=&DWP(36,"esp"); #copy of wparam(4)
791my $_tmp=&DWP(40,"esp"); #volatile variable
792my $ivec=&DWP(44,"esp"); #ivec[16]
793my $aes_key=&DWP(60,"esp"); #copy of aes_key
794my $mark=&DWP(60+240,"esp"); #copy of aes_key->rounds
795
796&public_label("AES_Te");
797&public_label("AES_Td");
798&function_begin("AES_cbc_encrypt");
799 &mov ($s2 eq "ecx"? $s2 : "",&wparam(2)); # load len
800 &cmp ($s2,0);
801 &je (&label("enc_out"));
802
803 &call (&label("pic_point")); # make it PIC!
804 &set_label("pic_point");
805 &blindpop("ebp");
806
807 &pushf ();
808 &cld ();
809
810 &cmp (&wparam(5),0);
811 &je (&label("DECRYPT"));
812
813 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
814
815 # allocate aligned stack frame...
816 &lea ($key,&DWP(-64-244,"esp"));
817 &and ($key,-64);
818
819 # ... and make sure it doesn't alias with AES_Te modulo 4096
820 &mov ($s0,"ebp");
821 &lea ($s1,&DWP(2048,"ebp"));
822 &mov ($s3,$key);
823 &and ($s0,0xfff); # s = %ebp&0xfff
824 &and ($s1,0xfff); # e = (%ebp+2048)&0xfff
825 &and ($s3,0xfff); # p = %esp&0xfff
826
827 &cmp ($s3,$s1); # if (p>=e) %esp =- (p-e);
828 &jb (&label("te_break_out"));
829 &sub ($s3,$s1);
830 &sub ($key,$s3);
831 &jmp (&label("te_ok"));
832 &set_label("te_break_out"); # else %esp -= (p-s)&0xfff + framesz;
833 &sub ($s3,$s0);
834 &and ($s3,0xfff);
835 &add ($s3,64+256);
836 &sub ($key,$s3);
837 &align (4);
838 &set_label("te_ok");
839
840 &mov ($s0,&wparam(0)); # load inp
841 &mov ($s1,&wparam(1)); # load out
842 &mov ($s3,&wparam(3)); # load key
843 &mov ($acc,&wparam(4)); # load ivp
844
845 &exch ("esp",$key);
846 &add ("esp",4); # reserve for return address!
847 &mov ($_esp,$key); # save %esp
848
849 &mov ($_inp,$s0); # save copy of inp
850 &mov ($_out,$s1); # save copy of out
851 &mov ($_len,$s2); # save copy of len
852 &mov ($_key,$s3); # save copy of key
853 &mov ($_ivp,$acc); # save copy of ivp
854
855 &mov ($mark,0); # copy of aes_key->rounds = 0;
856 if ($compromise) {
857 &cmp ($s2,$compromise);
858 &jb (&label("skip_ecopy"));
859 }
860 # do we copy key schedule to stack?
861 &mov ($s1 eq "ebx" ? $s1 : "",$s3);
862 &mov ($s2 eq "ecx" ? $s2 : "",244/4);
863 &sub ($s1,"ebp");
864 &mov ("esi",$s3);
865 &and ($s1,0xfff);
866 &lea ("edi",$aes_key);
867 &cmp ($s1,2048);
868 &jb (&label("do_ecopy"));
869 &cmp ($s1,4096-244);
870 &jb (&label("skip_ecopy"));
871 &align (4);
872 &set_label("do_ecopy");
873 &mov ($_key,"edi");
874 &data_word(0xA5F3F689); # rep movsd
875 &set_label("skip_ecopy");
876
877 &mov ($acc,$s0);
878 &mov ($key,16);
879 &align (4);
880 &set_label("prefetch_te");
881 &mov ($s0,&DWP(0,"ebp"));
882 &mov ($s1,&DWP(32,"ebp"));
883 &mov ($s2,&DWP(64,"ebp"));
884 &mov ($s3,&DWP(96,"ebp"));
885 &lea ("ebp",&DWP(128,"ebp"));
886 &dec ($key);
887 &jnz (&label("prefetch_te"));
888 &sub ("ebp",2048);
889
890 &mov ($s2,$_len);
891 &mov ($key,$_ivp);
892 &test ($s2,0xFFFFFFF0);
893 &jz (&label("enc_tail")); # short input...
894
895 &mov ($s0,&DWP(0,$key)); # load iv
896 &mov ($s1,&DWP(4,$key));
897
898 &align (4);
899 &set_label("enc_loop");
900 &mov ($s2,&DWP(8,$key));
901 &mov ($s3,&DWP(12,$key));
902
903 &xor ($s0,&DWP(0,$acc)); # xor input data
904 &xor ($s1,&DWP(4,$acc));
905 &xor ($s2,&DWP(8,$acc));
906 &xor ($s3,&DWP(12,$acc));
907
908 &mov ($key,$_key); # load key
909 &call ("_x86_AES_encrypt");
910
911 &mov ($acc,$_inp); # load inp
912 &mov ($key,$_out); # load out
913
914 &mov (&DWP(0,$key),$s0); # save output data
915 &mov (&DWP(4,$key),$s1);
916 &mov (&DWP(8,$key),$s2);
917 &mov (&DWP(12,$key),$s3);
918
919 &mov ($s2,$_len); # load len
920
921 &lea ($acc,&DWP(16,$acc));
922 &mov ($_inp,$acc); # save inp
923
924 &lea ($s3,&DWP(16,$key));
925 &mov ($_out,$s3); # save out
926
927 &sub ($s2,16);
928 &test ($s2,0xFFFFFFF0);
929 &mov ($_len,$s2); # save len
930 &jnz (&label("enc_loop"));
931 &test ($s2,15);
932 &jnz (&label("enc_tail"));
933 &mov ($acc,$_ivp); # load ivp
934 &mov ($s2,&DWP(8,$key)); # restore last dwords
935 &mov ($s3,&DWP(12,$key));
936 &mov (&DWP(0,$acc),$s0); # save ivec
937 &mov (&DWP(4,$acc),$s1);
938 &mov (&DWP(8,$acc),$s2);
939 &mov (&DWP(12,$acc),$s3);
940
941 &cmp ($mark,0); # was the key schedule copied?
942 &mov ("edi",$_key);
943 &je (&label("skip_ezero"));
944 # zero copy of key schedule
945 &mov ("ecx",240/4);
946 &xor ("eax","eax");
947 &align (4);
948 &data_word(0xABF3F689); # rep stosd
949 &set_label("skip_ezero")
950 &mov ("esp",$_esp);
951 &popf ();
952 &set_label("enc_out");
953 &function_end_A();
954 &pushf (); # kludge, never executed
955
956 &align (4);
957 &set_label("enc_tail");
958 &push ($key eq "edi" ? $key : ""); # push ivp
959 &mov ($key,$_out); # load out
960 &mov ($s1,16);
961 &sub ($s1,$s2);
962 &cmp ($key,$acc); # compare with inp
963 &je (&label("enc_in_place"));
964 &align (4);
965 &data_word(0xA4F3F689); # rep movsb # copy input
966 &jmp (&label("enc_skip_in_place"));
967 &set_label("enc_in_place");
968 &lea ($key,&DWP(0,$key,$s2));
969 &set_label("enc_skip_in_place");
970 &mov ($s2,$s1);
971 &xor ($s0,$s0);
972 &align (4);
973 &data_word(0xAAF3F689); # rep stosb # zero tail
974 &pop ($key); # pop ivp
975
976 &mov ($acc,$_out); # output as input
977 &mov ($s0,&DWP(0,$key));
978 &mov ($s1,&DWP(4,$key));
979 &mov ($_len,16); # len=16
980 &jmp (&label("enc_loop")); # one more spin...
981
982#----------------------------- DECRYPT -----------------------------#
983&align (4);
984&set_label("DECRYPT");
985 &lea ("ebp",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
986
987 # allocate aligned stack frame...
988 &lea ($key,&DWP(-64-244,"esp"));
989 &and ($key,-64);
990
991 # ... and make sure it doesn't alias with AES_Td modulo 4096
992 &mov ($s0,"ebp");
993 &lea ($s1,&DWP(2048+256,"ebp"));
994 &mov ($s3,$key);
995 &and ($s0,0xfff); # s = %ebp&0xfff
996 &and ($s1,0xfff); # e = (%ebp+2048+256)&0xfff
997 &and ($s3,0xfff); # p = %esp&0xfff
998
999 &cmp ($s3,$s1); # if (p>=e) %esp =- (p-e);
1000 &jb (&label("td_break_out"));
1001 &sub ($s3,$s1);
1002 &sub ($key,$s3);
1003 &jmp (&label("td_ok"));
1004 &set_label("td_break_out"); # else %esp -= (p-s)&0xfff + framesz;
1005 &sub ($s3,$s0);
1006 &and ($s3,0xfff);
1007 &add ($s3,64+256);
1008 &sub ($key,$s3);
1009 &align (4);
1010 &set_label("td_ok");
1011
1012 &mov ($s0,&wparam(0)); # load inp
1013 &mov ($s1,&wparam(1)); # load out
1014 &mov ($s3,&wparam(3)); # load key
1015 &mov ($acc,&wparam(4)); # load ivp
1016
1017 &exch ("esp",$key);
1018 &add ("esp",4); # reserve for return address!
1019 &mov ($_esp,$key); # save %esp
1020
1021 &mov ($_inp,$s0); # save copy of inp
1022 &mov ($_out,$s1); # save copy of out
1023 &mov ($_len,$s2); # save copy of len
1024 &mov ($_key,$s3); # save copy of key
1025 &mov ($_ivp,$acc); # save copy of ivp
1026
1027 &mov ($mark,0); # copy of aes_key->rounds = 0;
1028 if ($compromise) {
1029 &cmp ($s2,$compromise);
1030 &jb (&label("skip_dcopy"));
1031 }
1032 # do we copy key schedule to stack?
1033 &mov ($s1 eq "ebx" ? $s1 : "",$s3);
1034 &mov ($s2 eq "ecx" ? $s2 : "",244/4);
1035 &sub ($s1,"ebp");
1036 &mov ("esi",$s3);
1037 &and ($s1,0xfff);
1038 &lea ("edi",$aes_key);
1039 &cmp ($s1,2048+256);
1040 &jb (&label("do_dcopy"));
1041 &cmp ($s1,4096-244);
1042 &jb (&label("skip_dcopy"));
1043 &align (4);
1044 &set_label("do_dcopy");
1045 &mov ($_key,"edi");
1046 &data_word(0xA5F3F689); # rep movsd
1047 &set_label("skip_dcopy");
1048
1049 &mov ($acc,$s0);
1050 &mov ($key,18);
1051 &align (4);
1052 &set_label("prefetch_td");
1053 &mov ($s0,&DWP(0,"ebp"));
1054 &mov ($s1,&DWP(32,"ebp"));
1055 &mov ($s2,&DWP(64,"ebp"));
1056 &mov ($s3,&DWP(96,"ebp"));
1057 &lea ("ebp",&DWP(128,"ebp"));
1058 &dec ($key);
1059 &jnz (&label("prefetch_td"));
1060 &sub ("ebp",2048+256);
1061
1062 &cmp ($acc,$_out);
1063 &je (&label("dec_in_place")); # in-place processing...
1064
1065 &mov ($key,$_ivp); # load ivp
1066 &mov ($_tmp,$key);
1067
1068 &align (4);
1069 &set_label("dec_loop");
1070 &mov ($s0,&DWP(0,$acc)); # read input
1071 &mov ($s1,&DWP(4,$acc));
1072 &mov ($s2,&DWP(8,$acc));
1073 &mov ($s3,&DWP(12,$acc));
1074
1075 &mov ($key,$_key); # load key
1076 &call ("_x86_AES_decrypt");
1077
1078 &mov ($key,$_tmp); # load ivp
1079 &mov ($acc,$_len); # load len
1080 &xor ($s0,&DWP(0,$key)); # xor iv
1081 &xor ($s1,&DWP(4,$key));
1082 &xor ($s2,&DWP(8,$key));
1083 &xor ($s3,&DWP(12,$key));
1084
1085 &sub ($acc,16);
1086 &jc (&label("dec_partial"));
1087 &mov ($_len,$acc); # save len
1088 &mov ($acc,$_inp); # load inp
1089 &mov ($key,$_out); # load out
1090
1091 &mov (&DWP(0,$key),$s0); # write output
1092 &mov (&DWP(4,$key),$s1);
1093 &mov (&DWP(8,$key),$s2);
1094 &mov (&DWP(12,$key),$s3);
1095
1096 &mov ($_tmp,$acc); # save ivp
1097 &lea ($acc,&DWP(16,$acc));
1098 &mov ($_inp,$acc); # save inp
1099
1100 &lea ($key,&DWP(16,$key));
1101 &mov ($_out,$key); # save out
1102
1103 &jnz (&label("dec_loop"));
1104 &mov ($key,$_tmp); # load temp ivp
1105 &set_label("dec_end");
1106 &mov ($acc,$_ivp); # load user ivp
1107 &mov ($s0,&DWP(0,$key)); # load iv
1108 &mov ($s1,&DWP(4,$key));
1109 &mov ($s2,&DWP(8,$key));
1110 &mov ($s3,&DWP(12,$key));
1111 &mov (&DWP(0,$acc),$s0); # copy back to user
1112 &mov (&DWP(4,$acc),$s1);
1113 &mov (&DWP(8,$acc),$s2);
1114 &mov (&DWP(12,$acc),$s3);
1115 &jmp (&label("dec_out"));
1116
1117 &align (4);
1118 &set_label("dec_partial");
1119 &lea ($key,$ivec);
1120 &mov (&DWP(0,$key),$s0); # dump output to stack
1121 &mov (&DWP(4,$key),$s1); 884 &mov (&DWP(4,$key),$s1);
1122 &mov (&DWP(8,$key),$s2); 885 &mov (&DWP(8,$key),$s2);
1123 &mov (&DWP(12,$key),$s3); 886 &mov (&DWP(12,$key),$s3);
1124 &lea ($s2 eq "ecx" ? $s2 : "",&DWP(16,$acc));
1125 &mov ($acc eq "esi" ? $acc : "",$key);
1126 &mov ($key eq "edi" ? $key : "",$_out); # load out
1127 &data_word(0xA4F3F689); # rep movsb # copy output
1128 &mov ($key,$_inp); # use inp as temp ivp
1129 &jmp (&label("dec_end"));
1130
1131 &align (4);
1132 &set_label("dec_in_place");
1133 &set_label("dec_in_place_loop");
1134 &lea ($key,$ivec);
1135 &mov ($s0,&DWP(0,$acc)); # read input
1136 &mov ($s1,&DWP(4,$acc));
1137 &mov ($s2,&DWP(8,$acc));
1138 &mov ($s3,&DWP(12,$acc));
1139
1140 &mov (&DWP(0,$key),$s0); # copy to temp
1141 &mov (&DWP(4,$key),$s1);
1142 &mov (&DWP(8,$key),$s2);
1143 &mov (&DWP(12,$key),$s3);
1144
1145 &mov ($key,$_key); # load key
1146 &call ("_x86_AES_decrypt");
1147
1148 &mov ($key,$_ivp); # load ivp
1149 &mov ($acc,$_out); # load out
1150 &xor ($s0,&DWP(0,$key)); # xor iv
1151 &xor ($s1,&DWP(4,$key));
1152 &xor ($s2,&DWP(8,$key));
1153 &xor ($s3,&DWP(12,$key));
1154 887
1155 &mov (&DWP(0,$acc),$s0); # write output 888 &pop ("edi");
1156 &mov (&DWP(4,$acc),$s1); 889 &pop ("esi");
1157 &mov (&DWP(8,$acc),$s2); 890 &pop ("ebx");
1158 &mov (&DWP(12,$acc),$s3); 891 &pop ("ebp");
1159 892 &ret ();
1160 &lea ($acc,&DWP(16,$acc));
1161 &mov ($_out,$acc); # save out
1162
1163 &lea ($acc,$ivec);
1164 &mov ($s0,&DWP(0,$acc)); # read temp
1165 &mov ($s1,&DWP(4,$acc));
1166 &mov ($s2,&DWP(8,$acc));
1167 &mov ($s3,&DWP(12,$acc));
1168
1169 &mov (&DWP(0,$key),$s0); # copy iv
1170 &mov (&DWP(4,$key),$s1);
1171 &mov (&DWP(8,$key),$s2);
1172 &mov (&DWP(12,$key),$s3);
1173
1174 &mov ($acc,$_inp); # load inp
1175
1176 &lea ($acc,&DWP(16,$acc));
1177 &mov ($_inp,$acc); # save inp
1178
1179 &mov ($s2,$_len); # load len
1180 &sub ($s2,16);
1181 &jc (&label("dec_in_place_partial"));
1182 &mov ($_len,$s2); # save len
1183 &jnz (&label("dec_in_place_loop"));
1184 &jmp (&label("dec_out"));
1185
1186 &align (4);
1187 &set_label("dec_in_place_partial");
1188 # one can argue if this is actually required...
1189 &mov ($key eq "edi" ? $key : "",$_out);
1190 &lea ($acc eq "esi" ? $acc : "",$ivec);
1191 &lea ($key,&DWP(0,$key,$s2));
1192 &lea ($acc,&DWP(16,$acc,$s2));
1193 &neg ($s2 eq "ecx" ? $s2 : "");
1194 &data_word(0xA4F3F689); # rep movsb # restore tail
1195
1196 &align (4);
1197 &set_label("dec_out");
1198 &cmp ($mark,0); # was the key schedule copied?
1199 &mov ("edi",$_key);
1200 &je (&label("skip_dzero"));
1201 # zero copy of key schedule
1202 &mov ("ecx",240/4);
1203 &xor ("eax","eax");
1204 &align (4);
1205 &data_word(0xABF3F689); # rep stosd
1206 &set_label("skip_dzero")
1207 &mov ("esp",$_esp);
1208 &popf ();
1209&function_end("AES_cbc_encrypt");
1210}
1211 893
1212#------------------------------------------------------------------# 894&set_label("AES_Td",64); # Yes! I keep it in the code segment!
895 &data_word(0x50a7f451, 0x5365417e, 0xc3a4171a, 0x965e273a);
896 &data_word(0xcb6bab3b, 0xf1459d1f, 0xab58faac, 0x9303e34b);
897 &data_word(0x55fa3020, 0xf66d76ad, 0x9176cc88, 0x254c02f5);
898 &data_word(0xfcd7e54f, 0xd7cb2ac5, 0x80443526, 0x8fa362b5);
899 &data_word(0x495ab1de, 0x671bba25, 0x980eea45, 0xe1c0fe5d);
900 &data_word(0x02752fc3, 0x12f04c81, 0xa397468d, 0xc6f9d36b);
901 &data_word(0xe75f8f03, 0x959c9215, 0xeb7a6dbf, 0xda595295);
902 &data_word(0x2d83bed4, 0xd3217458, 0x2969e049, 0x44c8c98e);
903 &data_word(0x6a89c275, 0x78798ef4, 0x6b3e5899, 0xdd71b927);
904 &data_word(0xb64fe1be, 0x17ad88f0, 0x66ac20c9, 0xb43ace7d);
905 &data_word(0x184adf63, 0x82311ae5, 0x60335197, 0x457f5362);
906 &data_word(0xe07764b1, 0x84ae6bbb, 0x1ca081fe, 0x942b08f9);
907 &data_word(0x58684870, 0x19fd458f, 0x876cde94, 0xb7f87b52);
908 &data_word(0x23d373ab, 0xe2024b72, 0x578f1fe3, 0x2aab5566);
909 &data_word(0x0728ebb2, 0x03c2b52f, 0x9a7bc586, 0xa50837d3);
910 &data_word(0xf2872830, 0xb2a5bf23, 0xba6a0302, 0x5c8216ed);
911 &data_word(0x2b1ccf8a, 0x92b479a7, 0xf0f207f3, 0xa1e2694e);
912 &data_word(0xcdf4da65, 0xd5be0506, 0x1f6234d1, 0x8afea6c4);
913 &data_word(0x9d532e34, 0xa055f3a2, 0x32e18a05, 0x75ebf6a4);
914 &data_word(0x39ec830b, 0xaaef6040, 0x069f715e, 0x51106ebd);
915 &data_word(0xf98a213e, 0x3d06dd96, 0xae053edd, 0x46bde64d);
916 &data_word(0xb58d5491, 0x055dc471, 0x6fd40604, 0xff155060);
917 &data_word(0x24fb9819, 0x97e9bdd6, 0xcc434089, 0x779ed967);
918 &data_word(0xbd42e8b0, 0x888b8907, 0x385b19e7, 0xdbeec879);
919 &data_word(0x470a7ca1, 0xe90f427c, 0xc91e84f8, 0x00000000);
920 &data_word(0x83868009, 0x48ed2b32, 0xac70111e, 0x4e725a6c);
921 &data_word(0xfbff0efd, 0x5638850f, 0x1ed5ae3d, 0x27392d36);
922 &data_word(0x64d90f0a, 0x21a65c68, 0xd1545b9b, 0x3a2e3624);
923 &data_word(0xb1670a0c, 0x0fe75793, 0xd296eeb4, 0x9e919b1b);
924 &data_word(0x4fc5c080, 0xa220dc61, 0x694b775a, 0x161a121c);
925 &data_word(0x0aba93e2, 0xe52aa0c0, 0x43e0223c, 0x1d171b12);
926 &data_word(0x0b0d090e, 0xadc78bf2, 0xb9a8b62d, 0xc8a91e14);
927 &data_word(0x8519f157, 0x4c0775af, 0xbbdd99ee, 0xfd607fa3);
928 &data_word(0x9f2601f7, 0xbcf5725c, 0xc53b6644, 0x347efb5b);
929 &data_word(0x7629438b, 0xdcc623cb, 0x68fcedb6, 0x63f1e4b8);
930 &data_word(0xcadc31d7, 0x10856342, 0x40229713, 0x2011c684);
931 &data_word(0x7d244a85, 0xf83dbbd2, 0x1132f9ae, 0x6da129c7);
932 &data_word(0x4b2f9e1d, 0xf330b2dc, 0xec52860d, 0xd0e3c177);
933 &data_word(0x6c16b32b, 0x99b970a9, 0xfa489411, 0x2264e947);
934 &data_word(0xc48cfca8, 0x1a3ff0a0, 0xd82c7d56, 0xef903322);
935 &data_word(0xc74e4987, 0xc1d138d9, 0xfea2ca8c, 0x360bd498);
936 &data_word(0xcf81f5a6, 0x28de7aa5, 0x268eb7da, 0xa4bfad3f);
937 &data_word(0xe49d3a2c, 0x0d927850, 0x9bcc5f6a, 0x62467e54);
938 &data_word(0xc2138df6, 0xe8b8d890, 0x5ef7392e, 0xf5afc382);
939 &data_word(0xbe805d9f, 0x7c93d069, 0xa92dd56f, 0xb31225cf);
940 &data_word(0x3b99acc8, 0xa77d1810, 0x6e639ce8, 0x7bbb3bdb);
941 &data_word(0x097826cd, 0xf418596e, 0x01b79aec, 0xa89a4f83);
942 &data_word(0x656e95e6, 0x7ee6ffaa, 0x08cfbc21, 0xe6e815ef);
943 &data_word(0xd99be7ba, 0xce366f4a, 0xd4099fea, 0xd67cb029);
944 &data_word(0xafb2a431, 0x31233f2a, 0x3094a5c6, 0xc066a235);
945 &data_word(0x37bc4e74, 0xa6ca82fc, 0xb0d090e0, 0x15d8a733);
946 &data_word(0x4a9804f1, 0xf7daec41, 0x0e50cd7f, 0x2ff69117);
947 &data_word(0x8dd64d76, 0x4db0ef43, 0x544daacc, 0xdf0496e4);
948 &data_word(0xe3b5d19e, 0x1b886a4c, 0xb81f2cc1, 0x7f516546);
949 &data_word(0x04ea5e9d, 0x5d358c01, 0x737487fa, 0x2e410bfb);
950 &data_word(0x5a1d67b3, 0x52d2db92, 0x335610e9, 0x1347d66d);
951 &data_word(0x8c61d79a, 0x7a0ca137, 0x8e14f859, 0x893c13eb);
952 &data_word(0xee27a9ce, 0x35c961b7, 0xede51ce1, 0x3cb1477a);
953 &data_word(0x59dfd29c, 0x3f73f255, 0x79ce1418, 0xbf37c773);
954 &data_word(0xeacdf753, 0x5baafd5f, 0x146f3ddf, 0x86db4478);
955 &data_word(0x81f3afca, 0x3ec468b9, 0x2c342438, 0x5f40a3c2);
956 &data_word(0x72c31d16, 0x0c25e2bc, 0x8b493c28, 0x41950dff);
957 &data_word(0x7101a839, 0xdeb30c08, 0x9ce4b4d8, 0x90c15664);
958 &data_word(0x6184cb7b, 0x70b632d5, 0x745c6c48, 0x4257b8d0);
959#Td1:
960 &data_word(0xa7f45150, 0x65417e53, 0xa4171ac3, 0x5e273a96);
961 &data_word(0x6bab3bcb, 0x459d1ff1, 0x58faacab, 0x03e34b93);
962 &data_word(0xfa302055, 0x6d76adf6, 0x76cc8891, 0x4c02f525);
963 &data_word(0xd7e54ffc, 0xcb2ac5d7, 0x44352680, 0xa362b58f);
964 &data_word(0x5ab1de49, 0x1bba2567, 0x0eea4598, 0xc0fe5de1);
965 &data_word(0x752fc302, 0xf04c8112, 0x97468da3, 0xf9d36bc6);
966 &data_word(0x5f8f03e7, 0x9c921595, 0x7a6dbfeb, 0x595295da);
967 &data_word(0x83bed42d, 0x217458d3, 0x69e04929, 0xc8c98e44);
968 &data_word(0x89c2756a, 0x798ef478, 0x3e58996b, 0x71b927dd);
969 &data_word(0x4fe1beb6, 0xad88f017, 0xac20c966, 0x3ace7db4);
970 &data_word(0x4adf6318, 0x311ae582, 0x33519760, 0x7f536245);
971 &data_word(0x7764b1e0, 0xae6bbb84, 0xa081fe1c, 0x2b08f994);
972 &data_word(0x68487058, 0xfd458f19, 0x6cde9487, 0xf87b52b7);
973 &data_word(0xd373ab23, 0x024b72e2, 0x8f1fe357, 0xab55662a);
974 &data_word(0x28ebb207, 0xc2b52f03, 0x7bc5869a, 0x0837d3a5);
975 &data_word(0x872830f2, 0xa5bf23b2, 0x6a0302ba, 0x8216ed5c);
976 &data_word(0x1ccf8a2b, 0xb479a792, 0xf207f3f0, 0xe2694ea1);
977 &data_word(0xf4da65cd, 0xbe0506d5, 0x6234d11f, 0xfea6c48a);
978 &data_word(0x532e349d, 0x55f3a2a0, 0xe18a0532, 0xebf6a475);
979 &data_word(0xec830b39, 0xef6040aa, 0x9f715e06, 0x106ebd51);
980 &data_word(0x8a213ef9, 0x06dd963d, 0x053eddae, 0xbde64d46);
981 &data_word(0x8d5491b5, 0x5dc47105, 0xd406046f, 0x155060ff);
982 &data_word(0xfb981924, 0xe9bdd697, 0x434089cc, 0x9ed96777);
983 &data_word(0x42e8b0bd, 0x8b890788, 0x5b19e738, 0xeec879db);
984 &data_word(0x0a7ca147, 0x0f427ce9, 0x1e84f8c9, 0x00000000);
985 &data_word(0x86800983, 0xed2b3248, 0x70111eac, 0x725a6c4e);
986 &data_word(0xff0efdfb, 0x38850f56, 0xd5ae3d1e, 0x392d3627);
987 &data_word(0xd90f0a64, 0xa65c6821, 0x545b9bd1, 0x2e36243a);
988 &data_word(0x670a0cb1, 0xe757930f, 0x96eeb4d2, 0x919b1b9e);
989 &data_word(0xc5c0804f, 0x20dc61a2, 0x4b775a69, 0x1a121c16);
990 &data_word(0xba93e20a, 0x2aa0c0e5, 0xe0223c43, 0x171b121d);
991 &data_word(0x0d090e0b, 0xc78bf2ad, 0xa8b62db9, 0xa91e14c8);
992 &data_word(0x19f15785, 0x0775af4c, 0xdd99eebb, 0x607fa3fd);
993 &data_word(0x2601f79f, 0xf5725cbc, 0x3b6644c5, 0x7efb5b34);
994 &data_word(0x29438b76, 0xc623cbdc, 0xfcedb668, 0xf1e4b863);
995 &data_word(0xdc31d7ca, 0x85634210, 0x22971340, 0x11c68420);
996 &data_word(0x244a857d, 0x3dbbd2f8, 0x32f9ae11, 0xa129c76d);
997 &data_word(0x2f9e1d4b, 0x30b2dcf3, 0x52860dec, 0xe3c177d0);
998 &data_word(0x16b32b6c, 0xb970a999, 0x489411fa, 0x64e94722);
999 &data_word(0x8cfca8c4, 0x3ff0a01a, 0x2c7d56d8, 0x903322ef);
1000 &data_word(0x4e4987c7, 0xd138d9c1, 0xa2ca8cfe, 0x0bd49836);
1001 &data_word(0x81f5a6cf, 0xde7aa528, 0x8eb7da26, 0xbfad3fa4);
1002 &data_word(0x9d3a2ce4, 0x9278500d, 0xcc5f6a9b, 0x467e5462);
1003 &data_word(0x138df6c2, 0xb8d890e8, 0xf7392e5e, 0xafc382f5);
1004 &data_word(0x805d9fbe, 0x93d0697c, 0x2dd56fa9, 0x1225cfb3);
1005 &data_word(0x99acc83b, 0x7d1810a7, 0x639ce86e, 0xbb3bdb7b);
1006 &data_word(0x7826cd09, 0x18596ef4, 0xb79aec01, 0x9a4f83a8);
1007 &data_word(0x6e95e665, 0xe6ffaa7e, 0xcfbc2108, 0xe815efe6);
1008 &data_word(0x9be7bad9, 0x366f4ace, 0x099fead4, 0x7cb029d6);
1009 &data_word(0xb2a431af, 0x233f2a31, 0x94a5c630, 0x66a235c0);
1010 &data_word(0xbc4e7437, 0xca82fca6, 0xd090e0b0, 0xd8a73315);
1011 &data_word(0x9804f14a, 0xdaec41f7, 0x50cd7f0e, 0xf691172f);
1012 &data_word(0xd64d768d, 0xb0ef434d, 0x4daacc54, 0x0496e4df);
1013 &data_word(0xb5d19ee3, 0x886a4c1b, 0x1f2cc1b8, 0x5165467f);
1014 &data_word(0xea5e9d04, 0x358c015d, 0x7487fa73, 0x410bfb2e);
1015 &data_word(0x1d67b35a, 0xd2db9252, 0x5610e933, 0x47d66d13);
1016 &data_word(0x61d79a8c, 0x0ca1377a, 0x14f8598e, 0x3c13eb89);
1017 &data_word(0x27a9ceee, 0xc961b735, 0xe51ce1ed, 0xb1477a3c);
1018 &data_word(0xdfd29c59, 0x73f2553f, 0xce141879, 0x37c773bf);
1019 &data_word(0xcdf753ea, 0xaafd5f5b, 0x6f3ddf14, 0xdb447886);
1020 &data_word(0xf3afca81, 0xc468b93e, 0x3424382c, 0x40a3c25f);
1021 &data_word(0xc31d1672, 0x25e2bc0c, 0x493c288b, 0x950dff41);
1022 &data_word(0x01a83971, 0xb30c08de, 0xe4b4d89c, 0xc1566490);
1023 &data_word(0x84cb7b61, 0xb632d570, 0x5c6c4874, 0x57b8d042);
1024#Td2:
1025 &data_word(0xf45150a7, 0x417e5365, 0x171ac3a4, 0x273a965e);
1026 &data_word(0xab3bcb6b, 0x9d1ff145, 0xfaacab58, 0xe34b9303);
1027 &data_word(0x302055fa, 0x76adf66d, 0xcc889176, 0x02f5254c);
1028 &data_word(0xe54ffcd7, 0x2ac5d7cb, 0x35268044, 0x62b58fa3);
1029 &data_word(0xb1de495a, 0xba25671b, 0xea45980e, 0xfe5de1c0);
1030 &data_word(0x2fc30275, 0x4c8112f0, 0x468da397, 0xd36bc6f9);
1031 &data_word(0x8f03e75f, 0x9215959c, 0x6dbfeb7a, 0x5295da59);
1032 &data_word(0xbed42d83, 0x7458d321, 0xe0492969, 0xc98e44c8);
1033 &data_word(0xc2756a89, 0x8ef47879, 0x58996b3e, 0xb927dd71);
1034 &data_word(0xe1beb64f, 0x88f017ad, 0x20c966ac, 0xce7db43a);
1035 &data_word(0xdf63184a, 0x1ae58231, 0x51976033, 0x5362457f);
1036 &data_word(0x64b1e077, 0x6bbb84ae, 0x81fe1ca0, 0x08f9942b);
1037 &data_word(0x48705868, 0x458f19fd, 0xde94876c, 0x7b52b7f8);
1038 &data_word(0x73ab23d3, 0x4b72e202, 0x1fe3578f, 0x55662aab);
1039 &data_word(0xebb20728, 0xb52f03c2, 0xc5869a7b, 0x37d3a508);
1040 &data_word(0x2830f287, 0xbf23b2a5, 0x0302ba6a, 0x16ed5c82);
1041 &data_word(0xcf8a2b1c, 0x79a792b4, 0x07f3f0f2, 0x694ea1e2);
1042 &data_word(0xda65cdf4, 0x0506d5be, 0x34d11f62, 0xa6c48afe);
1043 &data_word(0x2e349d53, 0xf3a2a055, 0x8a0532e1, 0xf6a475eb);
1044 &data_word(0x830b39ec, 0x6040aaef, 0x715e069f, 0x6ebd5110);
1045 &data_word(0x213ef98a, 0xdd963d06, 0x3eddae05, 0xe64d46bd);
1046 &data_word(0x5491b58d, 0xc471055d, 0x06046fd4, 0x5060ff15);
1047 &data_word(0x981924fb, 0xbdd697e9, 0x4089cc43, 0xd967779e);
1048 &data_word(0xe8b0bd42, 0x8907888b, 0x19e7385b, 0xc879dbee);
1049 &data_word(0x7ca1470a, 0x427ce90f, 0x84f8c91e, 0x00000000);
1050 &data_word(0x80098386, 0x2b3248ed, 0x111eac70, 0x5a6c4e72);
1051 &data_word(0x0efdfbff, 0x850f5638, 0xae3d1ed5, 0x2d362739);
1052 &data_word(0x0f0a64d9, 0x5c6821a6, 0x5b9bd154, 0x36243a2e);
1053 &data_word(0x0a0cb167, 0x57930fe7, 0xeeb4d296, 0x9b1b9e91);
1054 &data_word(0xc0804fc5, 0xdc61a220, 0x775a694b, 0x121c161a);
1055 &data_word(0x93e20aba, 0xa0c0e52a, 0x223c43e0, 0x1b121d17);
1056 &data_word(0x090e0b0d, 0x8bf2adc7, 0xb62db9a8, 0x1e14c8a9);
1057 &data_word(0xf1578519, 0x75af4c07, 0x99eebbdd, 0x7fa3fd60);
1058 &data_word(0x01f79f26, 0x725cbcf5, 0x6644c53b, 0xfb5b347e);
1059 &data_word(0x438b7629, 0x23cbdcc6, 0xedb668fc, 0xe4b863f1);
1060 &data_word(0x31d7cadc, 0x63421085, 0x97134022, 0xc6842011);
1061 &data_word(0x4a857d24, 0xbbd2f83d, 0xf9ae1132, 0x29c76da1);
1062 &data_word(0x9e1d4b2f, 0xb2dcf330, 0x860dec52, 0xc177d0e3);
1063 &data_word(0xb32b6c16, 0x70a999b9, 0x9411fa48, 0xe9472264);
1064 &data_word(0xfca8c48c, 0xf0a01a3f, 0x7d56d82c, 0x3322ef90);
1065 &data_word(0x4987c74e, 0x38d9c1d1, 0xca8cfea2, 0xd498360b);
1066 &data_word(0xf5a6cf81, 0x7aa528de, 0xb7da268e, 0xad3fa4bf);
1067 &data_word(0x3a2ce49d, 0x78500d92, 0x5f6a9bcc, 0x7e546246);
1068 &data_word(0x8df6c213, 0xd890e8b8, 0x392e5ef7, 0xc382f5af);
1069 &data_word(0x5d9fbe80, 0xd0697c93, 0xd56fa92d, 0x25cfb312);
1070 &data_word(0xacc83b99, 0x1810a77d, 0x9ce86e63, 0x3bdb7bbb);
1071 &data_word(0x26cd0978, 0x596ef418, 0x9aec01b7, 0x4f83a89a);
1072 &data_word(0x95e6656e, 0xffaa7ee6, 0xbc2108cf, 0x15efe6e8);
1073 &data_word(0xe7bad99b, 0x6f4ace36, 0x9fead409, 0xb029d67c);
1074 &data_word(0xa431afb2, 0x3f2a3123, 0xa5c63094, 0xa235c066);
1075 &data_word(0x4e7437bc, 0x82fca6ca, 0x90e0b0d0, 0xa73315d8);
1076 &data_word(0x04f14a98, 0xec41f7da, 0xcd7f0e50, 0x91172ff6);
1077 &data_word(0x4d768dd6, 0xef434db0, 0xaacc544d, 0x96e4df04);
1078 &data_word(0xd19ee3b5, 0x6a4c1b88, 0x2cc1b81f, 0x65467f51);
1079 &data_word(0x5e9d04ea, 0x8c015d35, 0x87fa7374, 0x0bfb2e41);
1080 &data_word(0x67b35a1d, 0xdb9252d2, 0x10e93356, 0xd66d1347);
1081 &data_word(0xd79a8c61, 0xa1377a0c, 0xf8598e14, 0x13eb893c);
1082 &data_word(0xa9ceee27, 0x61b735c9, 0x1ce1ede5, 0x477a3cb1);
1083 &data_word(0xd29c59df, 0xf2553f73, 0x141879ce, 0xc773bf37);
1084 &data_word(0xf753eacd, 0xfd5f5baa, 0x3ddf146f, 0x447886db);
1085 &data_word(0xafca81f3, 0x68b93ec4, 0x24382c34, 0xa3c25f40);
1086 &data_word(0x1d1672c3, 0xe2bc0c25, 0x3c288b49, 0x0dff4195);
1087 &data_word(0xa8397101, 0x0c08deb3, 0xb4d89ce4, 0x566490c1);
1088 &data_word(0xcb7b6184, 0x32d570b6, 0x6c48745c, 0xb8d04257);
1089#Td3:
1090 &data_word(0x5150a7f4, 0x7e536541, 0x1ac3a417, 0x3a965e27);
1091 &data_word(0x3bcb6bab, 0x1ff1459d, 0xacab58fa, 0x4b9303e3);
1092 &data_word(0x2055fa30, 0xadf66d76, 0x889176cc, 0xf5254c02);
1093 &data_word(0x4ffcd7e5, 0xc5d7cb2a, 0x26804435, 0xb58fa362);
1094 &data_word(0xde495ab1, 0x25671bba, 0x45980eea, 0x5de1c0fe);
1095 &data_word(0xc302752f, 0x8112f04c, 0x8da39746, 0x6bc6f9d3);
1096 &data_word(0x03e75f8f, 0x15959c92, 0xbfeb7a6d, 0x95da5952);
1097 &data_word(0xd42d83be, 0x58d32174, 0x492969e0, 0x8e44c8c9);
1098 &data_word(0x756a89c2, 0xf478798e, 0x996b3e58, 0x27dd71b9);
1099 &data_word(0xbeb64fe1, 0xf017ad88, 0xc966ac20, 0x7db43ace);
1100 &data_word(0x63184adf, 0xe582311a, 0x97603351, 0x62457f53);
1101 &data_word(0xb1e07764, 0xbb84ae6b, 0xfe1ca081, 0xf9942b08);
1102 &data_word(0x70586848, 0x8f19fd45, 0x94876cde, 0x52b7f87b);
1103 &data_word(0xab23d373, 0x72e2024b, 0xe3578f1f, 0x662aab55);
1104 &data_word(0xb20728eb, 0x2f03c2b5, 0x869a7bc5, 0xd3a50837);
1105 &data_word(0x30f28728, 0x23b2a5bf, 0x02ba6a03, 0xed5c8216);
1106 &data_word(0x8a2b1ccf, 0xa792b479, 0xf3f0f207, 0x4ea1e269);
1107 &data_word(0x65cdf4da, 0x06d5be05, 0xd11f6234, 0xc48afea6);
1108 &data_word(0x349d532e, 0xa2a055f3, 0x0532e18a, 0xa475ebf6);
1109 &data_word(0x0b39ec83, 0x40aaef60, 0x5e069f71, 0xbd51106e);
1110 &data_word(0x3ef98a21, 0x963d06dd, 0xddae053e, 0x4d46bde6);
1111 &data_word(0x91b58d54, 0x71055dc4, 0x046fd406, 0x60ff1550);
1112 &data_word(0x1924fb98, 0xd697e9bd, 0x89cc4340, 0x67779ed9);
1113 &data_word(0xb0bd42e8, 0x07888b89, 0xe7385b19, 0x79dbeec8);
1114 &data_word(0xa1470a7c, 0x7ce90f42, 0xf8c91e84, 0x00000000);
1115 &data_word(0x09838680, 0x3248ed2b, 0x1eac7011, 0x6c4e725a);
1116 &data_word(0xfdfbff0e, 0x0f563885, 0x3d1ed5ae, 0x3627392d);
1117 &data_word(0x0a64d90f, 0x6821a65c, 0x9bd1545b, 0x243a2e36);
1118 &data_word(0x0cb1670a, 0x930fe757, 0xb4d296ee, 0x1b9e919b);
1119 &data_word(0x804fc5c0, 0x61a220dc, 0x5a694b77, 0x1c161a12);
1120 &data_word(0xe20aba93, 0xc0e52aa0, 0x3c43e022, 0x121d171b);
1121 &data_word(0x0e0b0d09, 0xf2adc78b, 0x2db9a8b6, 0x14c8a91e);
1122 &data_word(0x578519f1, 0xaf4c0775, 0xeebbdd99, 0xa3fd607f);
1123 &data_word(0xf79f2601, 0x5cbcf572, 0x44c53b66, 0x5b347efb);
1124 &data_word(0x8b762943, 0xcbdcc623, 0xb668fced, 0xb863f1e4);
1125 &data_word(0xd7cadc31, 0x42108563, 0x13402297, 0x842011c6);
1126 &data_word(0x857d244a, 0xd2f83dbb, 0xae1132f9, 0xc76da129);
1127 &data_word(0x1d4b2f9e, 0xdcf330b2, 0x0dec5286, 0x77d0e3c1);
1128 &data_word(0x2b6c16b3, 0xa999b970, 0x11fa4894, 0x472264e9);
1129 &data_word(0xa8c48cfc, 0xa01a3ff0, 0x56d82c7d, 0x22ef9033);
1130 &data_word(0x87c74e49, 0xd9c1d138, 0x8cfea2ca, 0x98360bd4);
1131 &data_word(0xa6cf81f5, 0xa528de7a, 0xda268eb7, 0x3fa4bfad);
1132 &data_word(0x2ce49d3a, 0x500d9278, 0x6a9bcc5f, 0x5462467e);
1133 &data_word(0xf6c2138d, 0x90e8b8d8, 0x2e5ef739, 0x82f5afc3);
1134 &data_word(0x9fbe805d, 0x697c93d0, 0x6fa92dd5, 0xcfb31225);
1135 &data_word(0xc83b99ac, 0x10a77d18, 0xe86e639c, 0xdb7bbb3b);
1136 &data_word(0xcd097826, 0x6ef41859, 0xec01b79a, 0x83a89a4f);
1137 &data_word(0xe6656e95, 0xaa7ee6ff, 0x2108cfbc, 0xefe6e815);
1138 &data_word(0xbad99be7, 0x4ace366f, 0xead4099f, 0x29d67cb0);
1139 &data_word(0x31afb2a4, 0x2a31233f, 0xc63094a5, 0x35c066a2);
1140 &data_word(0x7437bc4e, 0xfca6ca82, 0xe0b0d090, 0x3315d8a7);
1141 &data_word(0xf14a9804, 0x41f7daec, 0x7f0e50cd, 0x172ff691);
1142 &data_word(0x768dd64d, 0x434db0ef, 0xcc544daa, 0xe4df0496);
1143 &data_word(0x9ee3b5d1, 0x4c1b886a, 0xc1b81f2c, 0x467f5165);
1144 &data_word(0x9d04ea5e, 0x015d358c, 0xfa737487, 0xfb2e410b);
1145 &data_word(0xb35a1d67, 0x9252d2db, 0xe9335610, 0x6d1347d6);
1146 &data_word(0x9a8c61d7, 0x377a0ca1, 0x598e14f8, 0xeb893c13);
1147 &data_word(0xceee27a9, 0xb735c961, 0xe1ede51c, 0x7a3cb147);
1148 &data_word(0x9c59dfd2, 0x553f73f2, 0x1879ce14, 0x73bf37c7);
1149 &data_word(0x53eacdf7, 0x5f5baafd, 0xdf146f3d, 0x7886db44);
1150 &data_word(0xca81f3af, 0xb93ec468, 0x382c3424, 0xc25f40a3);
1151 &data_word(0x1672c31d, 0xbc0c25e2, 0x288b493c, 0xff41950d);
1152 &data_word(0x397101a8, 0x08deb30c, 0xd89ce4b4, 0x6490c156);
1153 &data_word(0x7b6184cb, 0xd570b632, 0x48745c6c, 0xd04257b8);
1154#Td4:
1155 &data_word(0x52525252, 0x09090909, 0x6a6a6a6a, 0xd5d5d5d5);
1156 &data_word(0x30303030, 0x36363636, 0xa5a5a5a5, 0x38383838);
1157 &data_word(0xbfbfbfbf, 0x40404040, 0xa3a3a3a3, 0x9e9e9e9e);
1158 &data_word(0x81818181, 0xf3f3f3f3, 0xd7d7d7d7, 0xfbfbfbfb);
1159 &data_word(0x7c7c7c7c, 0xe3e3e3e3, 0x39393939, 0x82828282);
1160 &data_word(0x9b9b9b9b, 0x2f2f2f2f, 0xffffffff, 0x87878787);
1161 &data_word(0x34343434, 0x8e8e8e8e, 0x43434343, 0x44444444);
1162 &data_word(0xc4c4c4c4, 0xdededede, 0xe9e9e9e9, 0xcbcbcbcb);
1163 &data_word(0x54545454, 0x7b7b7b7b, 0x94949494, 0x32323232);
1164 &data_word(0xa6a6a6a6, 0xc2c2c2c2, 0x23232323, 0x3d3d3d3d);
1165 &data_word(0xeeeeeeee, 0x4c4c4c4c, 0x95959595, 0x0b0b0b0b);
1166 &data_word(0x42424242, 0xfafafafa, 0xc3c3c3c3, 0x4e4e4e4e);
1167 &data_word(0x08080808, 0x2e2e2e2e, 0xa1a1a1a1, 0x66666666);
1168 &data_word(0x28282828, 0xd9d9d9d9, 0x24242424, 0xb2b2b2b2);
1169 &data_word(0x76767676, 0x5b5b5b5b, 0xa2a2a2a2, 0x49494949);
1170 &data_word(0x6d6d6d6d, 0x8b8b8b8b, 0xd1d1d1d1, 0x25252525);
1171 &data_word(0x72727272, 0xf8f8f8f8, 0xf6f6f6f6, 0x64646464);
1172 &data_word(0x86868686, 0x68686868, 0x98989898, 0x16161616);
1173 &data_word(0xd4d4d4d4, 0xa4a4a4a4, 0x5c5c5c5c, 0xcccccccc);
1174 &data_word(0x5d5d5d5d, 0x65656565, 0xb6b6b6b6, 0x92929292);
1175 &data_word(0x6c6c6c6c, 0x70707070, 0x48484848, 0x50505050);
1176 &data_word(0xfdfdfdfd, 0xedededed, 0xb9b9b9b9, 0xdadadada);
1177 &data_word(0x5e5e5e5e, 0x15151515, 0x46464646, 0x57575757);
1178 &data_word(0xa7a7a7a7, 0x8d8d8d8d, 0x9d9d9d9d, 0x84848484);
1179 &data_word(0x90909090, 0xd8d8d8d8, 0xabababab, 0x00000000);
1180 &data_word(0x8c8c8c8c, 0xbcbcbcbc, 0xd3d3d3d3, 0x0a0a0a0a);
1181 &data_word(0xf7f7f7f7, 0xe4e4e4e4, 0x58585858, 0x05050505);
1182 &data_word(0xb8b8b8b8, 0xb3b3b3b3, 0x45454545, 0x06060606);
1183 &data_word(0xd0d0d0d0, 0x2c2c2c2c, 0x1e1e1e1e, 0x8f8f8f8f);
1184 &data_word(0xcacacaca, 0x3f3f3f3f, 0x0f0f0f0f, 0x02020202);
1185 &data_word(0xc1c1c1c1, 0xafafafaf, 0xbdbdbdbd, 0x03030303);
1186 &data_word(0x01010101, 0x13131313, 0x8a8a8a8a, 0x6b6b6b6b);
1187 &data_word(0x3a3a3a3a, 0x91919191, 0x11111111, 0x41414141);
1188 &data_word(0x4f4f4f4f, 0x67676767, 0xdcdcdcdc, 0xeaeaeaea);
1189 &data_word(0x97979797, 0xf2f2f2f2, 0xcfcfcfcf, 0xcececece);
1190 &data_word(0xf0f0f0f0, 0xb4b4b4b4, 0xe6e6e6e6, 0x73737373);
1191 &data_word(0x96969696, 0xacacacac, 0x74747474, 0x22222222);
1192 &data_word(0xe7e7e7e7, 0xadadadad, 0x35353535, 0x85858585);
1193 &data_word(0xe2e2e2e2, 0xf9f9f9f9, 0x37373737, 0xe8e8e8e8);
1194 &data_word(0x1c1c1c1c, 0x75757575, 0xdfdfdfdf, 0x6e6e6e6e);
1195 &data_word(0x47474747, 0xf1f1f1f1, 0x1a1a1a1a, 0x71717171);
1196 &data_word(0x1d1d1d1d, 0x29292929, 0xc5c5c5c5, 0x89898989);
1197 &data_word(0x6f6f6f6f, 0xb7b7b7b7, 0x62626262, 0x0e0e0e0e);
1198 &data_word(0xaaaaaaaa, 0x18181818, 0xbebebebe, 0x1b1b1b1b);
1199 &data_word(0xfcfcfcfc, 0x56565656, 0x3e3e3e3e, 0x4b4b4b4b);
1200 &data_word(0xc6c6c6c6, 0xd2d2d2d2, 0x79797979, 0x20202020);
1201 &data_word(0x9a9a9a9a, 0xdbdbdbdb, 0xc0c0c0c0, 0xfefefefe);
1202 &data_word(0x78787878, 0xcdcdcdcd, 0x5a5a5a5a, 0xf4f4f4f4);
1203 &data_word(0x1f1f1f1f, 0xdddddddd, 0xa8a8a8a8, 0x33333333);
1204 &data_word(0x88888888, 0x07070707, 0xc7c7c7c7, 0x31313131);
1205 &data_word(0xb1b1b1b1, 0x12121212, 0x10101010, 0x59595959);
1206 &data_word(0x27272727, 0x80808080, 0xecececec, 0x5f5f5f5f);
1207 &data_word(0x60606060, 0x51515151, 0x7f7f7f7f, 0xa9a9a9a9);
1208 &data_word(0x19191919, 0xb5b5b5b5, 0x4a4a4a4a, 0x0d0d0d0d);
1209 &data_word(0x2d2d2d2d, 0xe5e5e5e5, 0x7a7a7a7a, 0x9f9f9f9f);
1210 &data_word(0x93939393, 0xc9c9c9c9, 0x9c9c9c9c, 0xefefefef);
1211 &data_word(0xa0a0a0a0, 0xe0e0e0e0, 0x3b3b3b3b, 0x4d4d4d4d);
1212 &data_word(0xaeaeaeae, 0x2a2a2a2a, 0xf5f5f5f5, 0xb0b0b0b0);
1213 &data_word(0xc8c8c8c8, 0xebebebeb, 0xbbbbbbbb, 0x3c3c3c3c);
1214 &data_word(0x83838383, 0x53535353, 0x99999999, 0x61616161);
1215 &data_word(0x17171717, 0x2b2b2b2b, 0x04040404, 0x7e7e7e7e);
1216 &data_word(0xbabababa, 0x77777777, 0xd6d6d6d6, 0x26262626);
1217 &data_word(0xe1e1e1e1, 0x69696969, 0x14141414, 0x63636363);
1218 &data_word(0x55555555, 0x21212121, 0x0c0c0c0c, 0x7d7d7d7d);
1219&function_end_B("AES_decrypt");
1213 1220
1214sub enckey() 1221sub enckey()
1215{ 1222{
1216 &movz ("esi",&LB("edx")); # rk[i]>>0 1223 &movz ("esi",&LB("edx")); # rk[i]>>0
1217 &mov ("ebx",&DWP(2,"ebp","esi",8)); 1224 &mov ("ebx",&DWP(0,"ebp","esi",4));
1218 &movz ("esi",&HB("edx")); # rk[i]>>8 1225 &movz ("esi",&HB("edx")); # rk[i]>>8
1219 &and ("ebx",0xFF000000); 1226 &and ("ebx",0xFF000000);
1220 &xor ("eax","ebx"); 1227 &xor ("eax","ebx");
1221 1228
1222 &mov ("ebx",&DWP(2,"ebp","esi",8)); 1229 &mov ("ebx",&DWP(0,"ebp","esi",4));
1223 &shr ("edx",16); 1230 &shr ("edx",16);
1224 &and ("ebx",0x000000FF); 1231 &and ("ebx",0x000000FF);
1225 &movz ("esi",&LB("edx")); # rk[i]>>16 1232 &movz ("esi",&LB("edx")); # rk[i]>>16
1226 &xor ("eax","ebx"); 1233 &xor ("eax","ebx");
1227 1234
1228 &mov ("ebx",&DWP(0,"ebp","esi",8)); 1235 &mov ("ebx",&DWP(0,"ebp","esi",4));
1229 &movz ("esi",&HB("edx")); # rk[i]>>24 1236 &movz ("esi",&HB("edx")); # rk[i]>>24
1230 &and ("ebx",0x0000FF00); 1237 &and ("ebx",0x0000FF00);
1231 &xor ("eax","ebx"); 1238 &xor ("eax","ebx");
1232 1239
1233 &mov ("ebx",&DWP(0,"ebp","esi",8)); 1240 &mov ("ebx",&DWP(0,"ebp","esi",4));
1234 &and ("ebx",0x00FF0000); 1241 &and ("ebx",0x00FF0000);
1235 &xor ("eax","ebx"); 1242 &xor ("eax","ebx");
1236 1243
1237 &xor ("eax",&DWP(2048,"ebp","ecx",4)); # rcon 1244 &xor ("eax",&DWP(1024,"ebp","ecx",4)); # rcon
1238} 1245}
1239 1246
1240# int AES_set_encrypt_key(const unsigned char *userKey, const int bits, 1247# int AES_set_encrypt_key(const unsigned char *userKey, const int bits,
@@ -1253,6 +1260,7 @@ sub enckey()
1253 &set_label("pic_point"); 1260 &set_label("pic_point");
1254 &blindpop("ebp"); 1261 &blindpop("ebp");
1255 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp")); 1262 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1263 &add ("ebp",1024*4); # skip to Te4
1256 1264
1257 &mov ("ecx",&wparam(1)); # number of bits in key 1265 &mov ("ecx",&wparam(1)); # number of bits in key
1258 &cmp ("ecx",128); 1266 &cmp ("ecx",128);
@@ -1393,23 +1401,23 @@ sub enckey()
1393 &mov ("edx","eax"); 1401 &mov ("edx","eax");
1394 &mov ("eax",&DWP(16,"edi")); # rk[4] 1402 &mov ("eax",&DWP(16,"edi")); # rk[4]
1395 &movz ("esi",&LB("edx")); # rk[11]>>0 1403 &movz ("esi",&LB("edx")); # rk[11]>>0
1396 &mov ("ebx",&DWP(2,"ebp","esi",8)); 1404 &mov ("ebx",&DWP(0,"ebp","esi",4));
1397 &movz ("esi",&HB("edx")); # rk[11]>>8 1405 &movz ("esi",&HB("edx")); # rk[11]>>8
1398 &and ("ebx",0x000000FF); 1406 &and ("ebx",0x000000FF);
1399 &xor ("eax","ebx"); 1407 &xor ("eax","ebx");
1400 1408
1401 &mov ("ebx",&DWP(0,"ebp","esi",8)); 1409 &mov ("ebx",&DWP(0,"ebp","esi",4));
1402 &shr ("edx",16); 1410 &shr ("edx",16);
1403 &and ("ebx",0x0000FF00); 1411 &and ("ebx",0x0000FF00);
1404 &movz ("esi",&LB("edx")); # rk[11]>>16 1412 &movz ("esi",&LB("edx")); # rk[11]>>16
1405 &xor ("eax","ebx"); 1413 &xor ("eax","ebx");
1406 1414
1407 &mov ("ebx",&DWP(0,"ebp","esi",8)); 1415 &mov ("ebx",&DWP(0,"ebp","esi",4));
1408 &movz ("esi",&HB("edx")); # rk[11]>>24 1416 &movz ("esi",&HB("edx")); # rk[11]>>24
1409 &and ("ebx",0x00FF0000); 1417 &and ("ebx",0x00FF0000);
1410 &xor ("eax","ebx"); 1418 &xor ("eax","ebx");
1411 1419
1412 &mov ("ebx",&DWP(2,"ebp","esi",8)); 1420 &mov ("ebx",&DWP(0,"ebp","esi",4));
1413 &and ("ebx",0xFF000000); 1421 &and ("ebx",0xFF000000);
1414 &xor ("eax","ebx"); 1422 &xor ("eax","ebx");
1415 1423
@@ -1435,23 +1443,23 @@ sub enckey()
1435&function_end("AES_set_encrypt_key"); 1443&function_end("AES_set_encrypt_key");
1436 1444
1437sub deckey() 1445sub deckey()
1438{ my ($i,$ptr,$te,$td) = @_; 1446{ my ($i,$ptr,$te4,$td) = @_;
1439 1447
1440 &mov ("eax",&DWP($i,$ptr)); 1448 &mov ("eax",&DWP($i,$ptr));
1441 &mov ("edx","eax"); 1449 &mov ("edx","eax");
1442 &movz ("ebx",&HB("eax")); 1450 &movz ("ebx",&HB("eax"));
1443 &shr ("edx",16); 1451 &shr ("edx",16);
1444 &and ("eax",0xFF); 1452 &and ("eax",0xFF);
1445 &movz ("eax",&BP(2,$te,"eax",8)); 1453 &movz ("eax",&BP(0,$te4,"eax",4));
1446 &movz ("ebx",&BP(2,$te,"ebx",8)); 1454 &movz ("ebx",&BP(0,$te4,"ebx",4));
1447 &mov ("eax",&DWP(0,$td,"eax",8)); 1455 &mov ("eax",&DWP(1024*0,$td,"eax",4));
1448 &xor ("eax",&DWP(3,$td,"ebx",8)); 1456 &xor ("eax",&DWP(1024*1,$td,"ebx",4));
1449 &movz ("ebx",&HB("edx")); 1457 &movz ("ebx",&HB("edx"));
1450 &and ("edx",0xFF); 1458 &and ("edx",0xFF);
1451 &movz ("edx",&BP(2,$te,"edx",8)); 1459 &movz ("edx",&BP(0,$te4,"edx",4));
1452 &movz ("ebx",&BP(2,$te,"ebx",8)); 1460 &movz ("ebx",&BP(0,$te4,"ebx",4));
1453 &xor ("eax",&DWP(2,$td,"edx",8)); 1461 &xor ("eax",&DWP(1024*2,$td,"edx",4));
1454 &xor ("eax",&DWP(1,$td,"ebx",8)); 1462 &xor ("eax",&DWP(1024*3,$td,"ebx",4));
1455 &mov (&DWP($i,$ptr),"eax"); 1463 &mov (&DWP($i,$ptr),"eax");
1456} 1464}
1457 1465
@@ -1512,6 +1520,7 @@ sub deckey()
1512 blindpop("ebp"); 1520 blindpop("ebp");
1513 &lea ("edi",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp")); 1521 &lea ("edi",&DWP(&label("AES_Td")."-".&label("pic_point"),"ebp"));
1514 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp")); 1522 &lea ("ebp",&DWP(&label("AES_Te")."-".&label("pic_point"),"ebp"));
1523 &add ("ebp",1024*4); # skip to Te4
1515 1524
1516 &mov ("esi",&wparam(2)); 1525 &mov ("esi",&wparam(2));
1517 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds 1526 &mov ("ecx",&DWP(240,"esi")); # pull number of rounds
diff --git a/src/lib/libcrypto/asn1/Makefile b/src/lib/libcrypto/asn1/Makefile
new file mode 100644
index 0000000000..63066899d0
--- /dev/null
+++ b/src/lib/libcrypto/asn1/Makefile
@@ -0,0 +1,885 @@
1#
2# OpenSSL/crypto/asn1/Makefile
3#
4
5DIR= asn1
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile README
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
21 a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \
22 a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \
23 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c \
24 x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
25 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
26 t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
27 tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
28 f_int.c f_string.c n_pkey.c \
29 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c asn_mime.c \
30 asn1_gen.c asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
31 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
32LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
33 a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \
34 a_enum.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o a_strex.o \
35 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o x_bignum.o \
36 x_long.o x_name.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \
37 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
38 t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
39 tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \
40 f_int.o f_string.o n_pkey.o \
41 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o asn_mime.o \
42 asn1_gen.o asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
43 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o
44
45SRC= $(LIBSRC)
46
47EXHEADER= asn1.h asn1_mac.h asn1t.h
48HEADER= $(EXHEADER)
49
50ALL= $(GENERAL) $(SRC) $(HEADER)
51
52top:
53 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
54
55test: test.c
56 cc -g -I../../include -c test.c
57 cc -g -I../../include -o test test.o -L../.. -lcrypto
58
59pk: pk.c
60 cc -g -I../../include -c pk.c
61 cc -g -I../../include -o pk pk.o -L../.. -lcrypto
62
63all: lib
64
65lib: $(LIBOBJ)
66 $(AR) $(LIB) $(LIBOBJ)
67 $(RANLIB) $(LIB) || echo Never mind.
68 @touch lib
69
70files:
71 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
72
73links:
74 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
75 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
76 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
77
78install:
79 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
80 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
81 do \
82 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
83 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
84 done;
85
86tags:
87 ctags $(SRC)
88
89tests:
90
91lint:
92 lint -DLINT $(INCLUDES) $(SRC)>fluff
93
94depend:
95 @[ -n "$(MAKEDEPEND)" ] # should be set by top Makefile...
96 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
97
98dclean:
99 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
100 mv -f Makefile.new $(MAKEFILE)
101
102clean:
103 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
104
105
106# DO NOT DELETE THIS LINE -- make depend depends on it.
107
108a_bitstr.o: ../../e_os.h ../../include/openssl/asn1.h
109a_bitstr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
110a_bitstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
111a_bitstr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
112a_bitstr.o: ../../include/openssl/opensslconf.h
113a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114a_bitstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
115a_bitstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bitstr.c
116a_bool.o: ../../e_os.h ../../include/openssl/asn1.h
117a_bool.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
118a_bool.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
119a_bool.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
120a_bool.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
121a_bool.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122a_bool.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123a_bool.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bool.c
124a_bytes.o: ../../e_os.h ../../include/openssl/asn1.h
125a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
126a_bytes.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
127a_bytes.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
128a_bytes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
129a_bytes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
130a_bytes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
131a_bytes.o: ../cryptlib.h a_bytes.c
132a_d2i_fp.o: ../../e_os.h ../../include/openssl/asn1.h
133a_d2i_fp.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
134a_d2i_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
135a_d2i_fp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
136a_d2i_fp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
137a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
138a_d2i_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
139a_d2i_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_d2i_fp.c
140a_digest.o: ../../e_os.h ../../include/openssl/asn1.h
141a_digest.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
142a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
143a_digest.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
144a_digest.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
145a_digest.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
146a_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
147a_digest.o: ../../include/openssl/opensslconf.h
148a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149a_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
150a_digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151a_digest.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
152a_digest.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_digest.c
153a_dup.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
154a_dup.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
155a_dup.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
156a_dup.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
157a_dup.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
158a_dup.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
159a_dup.o: ../../include/openssl/symhacks.h ../cryptlib.h a_dup.c
160a_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
161a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
162a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
163a_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
164a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
165a_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
166a_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
167a_enum.o: ../cryptlib.h a_enum.c
168a_gentm.o: ../../e_os.h ../../include/openssl/asn1.h
169a_gentm.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
170a_gentm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
171a_gentm.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
172a_gentm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
173a_gentm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
174a_gentm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
175a_gentm.o: ../cryptlib.h ../o_time.h a_gentm.c
176a_hdr.o: ../../e_os.h ../../include/openssl/asn1.h
177a_hdr.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
178a_hdr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
179a_hdr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
180a_hdr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
181a_hdr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
182a_hdr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
183a_hdr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_hdr.c
184a_i2d_fp.o: ../../e_os.h ../../include/openssl/asn1.h
185a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
186a_i2d_fp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
187a_i2d_fp.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
188a_i2d_fp.o: ../../include/openssl/opensslconf.h
189a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
190a_i2d_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
191a_i2d_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_i2d_fp.c
192a_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
193a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
194a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
195a_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
196a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
197a_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
198a_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
199a_int.o: ../cryptlib.h a_int.c
200a_mbstr.o: ../../e_os.h ../../include/openssl/asn1.h
201a_mbstr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
202a_mbstr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
203a_mbstr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
204a_mbstr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
205a_mbstr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
206a_mbstr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
207a_mbstr.o: ../cryptlib.h a_mbstr.c
208a_meth.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
209a_meth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
210a_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
211a_meth.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
212a_meth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
213a_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
214a_meth.o: ../../include/openssl/symhacks.h ../cryptlib.h a_meth.c
215a_object.o: ../../e_os.h ../../include/openssl/asn1.h
216a_object.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
217a_object.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
218a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
219a_object.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
220a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
221a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
222a_object.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
223a_object.o: ../../include/openssl/symhacks.h ../cryptlib.h a_object.c
224a_octet.o: ../../e_os.h ../../include/openssl/asn1.h
225a_octet.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
226a_octet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
227a_octet.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
228a_octet.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
229a_octet.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
230a_octet.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
231a_octet.o: ../cryptlib.h a_octet.c
232a_print.o: ../../e_os.h ../../include/openssl/asn1.h
233a_print.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
234a_print.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
235a_print.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
236a_print.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
237a_print.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
238a_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
239a_print.o: ../cryptlib.h a_print.c
240a_set.o: ../../e_os.h ../../include/openssl/asn1.h
241a_set.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
242a_set.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
243a_set.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
244a_set.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
245a_set.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
246a_set.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
247a_set.o: ../../include/openssl/symhacks.h ../cryptlib.h a_set.c
248a_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
249a_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
250a_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
251a_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
252a_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
253a_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
254a_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
255a_sign.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
256a_sign.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
257a_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
258a_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
259a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
260a_sign.o: ../cryptlib.h a_sign.c
261a_strex.o: ../../e_os.h ../../include/openssl/asn1.h
262a_strex.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
263a_strex.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
264a_strex.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
265a_strex.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
266a_strex.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
267a_strex.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
268a_strex.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
269a_strex.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
270a_strex.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
271a_strex.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
272a_strex.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
273a_strex.o: ../cryptlib.h a_strex.c charmap.h
274a_strnid.o: ../../e_os.h ../../include/openssl/asn1.h
275a_strnid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
276a_strnid.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
277a_strnid.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
278a_strnid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
279a_strnid.o: ../../include/openssl/opensslconf.h
280a_strnid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
281a_strnid.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
282a_strnid.o: ../../include/openssl/symhacks.h ../cryptlib.h a_strnid.c
283a_time.o: ../../e_os.h ../../include/openssl/asn1.h
284a_time.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
285a_time.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
286a_time.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
287a_time.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
288a_time.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
289a_time.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
290a_time.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_time.c
291a_type.o: ../../e_os.h ../../include/openssl/asn1.h
292a_type.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
293a_type.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
294a_type.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
295a_type.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
296a_type.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
297a_type.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
298a_type.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
299a_type.o: ../../include/openssl/symhacks.h ../cryptlib.h a_type.c
300a_utctm.o: ../../e_os.h ../../include/openssl/asn1.h
301a_utctm.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
302a_utctm.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
303a_utctm.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
304a_utctm.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
305a_utctm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
306a_utctm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
307a_utctm.o: ../cryptlib.h ../o_time.h a_utctm.c
308a_utf8.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
309a_utf8.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
310a_utf8.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
311a_utf8.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
312a_utf8.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
313a_utf8.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
314a_utf8.o: ../../include/openssl/symhacks.h ../cryptlib.h a_utf8.c
315a_verify.o: ../../e_os.h ../../include/openssl/asn1.h
316a_verify.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
317a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
318a_verify.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
319a_verify.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
320a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
321a_verify.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
322a_verify.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
323a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
324a_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
325a_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
326a_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
327a_verify.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_verify.c
328asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
329asn1_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
330asn1_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
331asn1_err.o: ../../include/openssl/opensslconf.h
332asn1_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
333asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
334asn1_err.o: ../../include/openssl/symhacks.h asn1_err.c
335asn1_gen.o: ../../e_os.h ../../include/openssl/asn1.h
336asn1_gen.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
337asn1_gen.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
338asn1_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
339asn1_gen.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
340asn1_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
341asn1_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
342asn1_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
343asn1_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
344asn1_gen.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
345asn1_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
346asn1_gen.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
347asn1_gen.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
348asn1_gen.o: ../cryptlib.h asn1_gen.c
349asn1_lib.o: ../../e_os.h ../../include/openssl/asn1.h
350asn1_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
351asn1_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
352asn1_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
353asn1_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
354asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
355asn1_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
356asn1_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_lib.c
357asn1_par.o: ../../e_os.h ../../include/openssl/asn1.h
358asn1_par.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
359asn1_par.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
360asn1_par.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
361asn1_par.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
362asn1_par.o: ../../include/openssl/opensslconf.h
363asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
364asn1_par.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
365asn1_par.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_par.c
366asn_mime.o: ../../e_os.h ../../include/openssl/asn1.h
367asn_mime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
368asn_mime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
369asn_mime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
370asn_mime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
371asn_mime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
372asn_mime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
373asn_mime.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
374asn_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
375asn_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
376asn_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
377asn_mime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
378asn_mime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
379asn_mime.o: ../cryptlib.h asn_mime.c
380asn_moid.o: ../../e_os.h ../../include/openssl/asn1.h
381asn_moid.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
382asn_moid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
383asn_moid.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
384asn_moid.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
385asn_moid.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
386asn_moid.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
387asn_moid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
388asn_moid.o: ../../include/openssl/opensslconf.h
389asn_moid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
390asn_moid.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
391asn_moid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
392asn_moid.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
393asn_moid.o: ../../include/openssl/x509_vfy.h ../cryptlib.h asn_moid.c
394asn_pack.o: ../../e_os.h ../../include/openssl/asn1.h
395asn_pack.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
396asn_pack.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
397asn_pack.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
398asn_pack.o: ../../include/openssl/opensslconf.h
399asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
400asn_pack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
401asn_pack.o: ../../include/openssl/symhacks.h ../cryptlib.h asn_pack.c
402d2i_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
403d2i_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
404d2i_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
405d2i_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
406d2i_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
407d2i_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
408d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
409d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
410d2i_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
411d2i_pr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
412d2i_pr.o: ../cryptlib.h d2i_pr.c
413d2i_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
414d2i_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
415d2i_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
416d2i_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
417d2i_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
418d2i_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
419d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
420d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
421d2i_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
422d2i_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
423d2i_pu.o: ../cryptlib.h d2i_pu.c
424evp_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
425evp_asn1.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
426evp_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
427evp_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
428evp_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
429evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
430evp_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
431evp_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_asn1.c
432f_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
433f_enum.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
434f_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
435f_enum.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
436f_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
437f_enum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
438f_enum.o: ../../include/openssl/symhacks.h ../cryptlib.h f_enum.c
439f_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
440f_int.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
441f_int.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
442f_int.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
443f_int.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
444f_int.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
445f_int.o: ../../include/openssl/symhacks.h ../cryptlib.h f_int.c
446f_string.o: ../../e_os.h ../../include/openssl/asn1.h
447f_string.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
448f_string.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
449f_string.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
450f_string.o: ../../include/openssl/opensslconf.h
451f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
452f_string.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
453f_string.o: ../../include/openssl/symhacks.h ../cryptlib.h f_string.c
454i2d_pr.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
455i2d_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
456i2d_pr.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
457i2d_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
458i2d_pr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
459i2d_pr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
460i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
461i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
462i2d_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
463i2d_pr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
464i2d_pr.o: ../cryptlib.h i2d_pr.c
465i2d_pu.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
466i2d_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
467i2d_pu.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
468i2d_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
469i2d_pu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
470i2d_pu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
471i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
472i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
473i2d_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
474i2d_pu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
475i2d_pu.o: ../cryptlib.h i2d_pu.c
476n_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
477n_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/asn1t.h
478n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
479n_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
480n_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
481n_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
482n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
483n_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
484n_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
485n_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
486n_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
487n_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
488n_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
489n_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h n_pkey.c
490nsseq.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
491nsseq.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
492nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
493nsseq.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
494nsseq.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
495nsseq.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
496nsseq.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
497nsseq.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
498nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
499nsseq.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
500nsseq.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
501nsseq.o: ../../include/openssl/x509_vfy.h nsseq.c
502p5_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
503p5_pbe.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
504p5_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
505p5_pbe.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
506p5_pbe.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
507p5_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
508p5_pbe.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
509p5_pbe.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
510p5_pbe.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
511p5_pbe.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
512p5_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
513p5_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
514p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
515p5_pbe.o: ../cryptlib.h p5_pbe.c
516p5_pbev2.o: ../../e_os.h ../../include/openssl/asn1.h
517p5_pbev2.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
518p5_pbev2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
519p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
520p5_pbev2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
521p5_pbev2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
522p5_pbev2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
523p5_pbev2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
524p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
525p5_pbev2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
526p5_pbev2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
527p5_pbev2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
528p5_pbev2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
529p5_pbev2.o: ../cryptlib.h p5_pbev2.c
530p8_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
531p8_pkey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
532p8_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
533p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
534p8_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
535p8_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
536p8_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
537p8_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
538p8_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
539p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
540p8_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
541p8_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
542p8_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p8_pkey.c
543t_bitst.o: ../../e_os.h ../../include/openssl/asn1.h
544t_bitst.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
545t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
546t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
547t_bitst.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
548t_bitst.o: ../../include/openssl/err.h ../../include/openssl/evp.h
549t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
550t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
551t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
552t_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
553t_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
554t_bitst.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
555t_bitst.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
556t_bitst.o: ../cryptlib.h t_bitst.c
557t_crl.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
558t_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
559t_crl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
560t_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
561t_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
562t_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
563t_crl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
564t_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
565t_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
566t_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
567t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
568t_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
569t_crl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
570t_crl.o: ../cryptlib.h t_crl.c
571t_pkey.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
572t_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
573t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
574t_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
575t_pkey.o: ../../include/openssl/ec.h ../../include/openssl/err.h
576t_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
577t_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
578t_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
579t_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
580t_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
581t_pkey.o: ../cryptlib.h t_pkey.c
582t_req.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
583t_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
584t_req.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
585t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
586t_req.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
587t_req.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
588t_req.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
589t_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
590t_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
591t_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
592t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
593t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
594t_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
595t_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
596t_req.o: ../cryptlib.h t_req.c
597t_spki.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
598t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
599t_spki.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
600t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
601t_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
602t_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
603t_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
604t_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
605t_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
606t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
607t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
608t_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
609t_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
610t_spki.o: ../cryptlib.h t_spki.c
611t_x509.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
612t_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
613t_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
614t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
615t_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
616t_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
617t_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
618t_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
619t_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
620t_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
621t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
622t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
623t_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
624t_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
625t_x509.o: ../cryptlib.h t_x509.c
626t_x509a.o: ../../e_os.h ../../include/openssl/asn1.h
627t_x509a.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
628t_x509a.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
629t_x509a.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
630t_x509a.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
631t_x509a.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
632t_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
633t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
634t_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
635t_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
636t_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
637t_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
638t_x509a.o: ../cryptlib.h t_x509a.c
639tasn_dec.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
640tasn_dec.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
641tasn_dec.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
642tasn_dec.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
643tasn_dec.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
644tasn_dec.o: ../../include/openssl/opensslconf.h
645tasn_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
646tasn_dec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
647tasn_dec.o: ../../include/openssl/symhacks.h tasn_dec.c
648tasn_enc.o: ../../e_os.h ../../include/openssl/asn1.h
649tasn_enc.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
650tasn_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
651tasn_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
652tasn_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
653tasn_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
654tasn_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
655tasn_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
656tasn_enc.o: ../../include/openssl/symhacks.h ../cryptlib.h tasn_enc.c
657tasn_fre.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
658tasn_fre.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
659tasn_fre.o: ../../include/openssl/e_os2.h ../../include/openssl/obj_mac.h
660tasn_fre.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
661tasn_fre.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
662tasn_fre.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
663tasn_fre.o: ../../include/openssl/symhacks.h tasn_fre.c
664tasn_new.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
665tasn_new.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
666tasn_new.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
667tasn_new.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
668tasn_new.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
669tasn_new.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
670tasn_new.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
671tasn_new.o: ../../include/openssl/symhacks.h tasn_new.c
672tasn_typ.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
673tasn_typ.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
674tasn_typ.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
675tasn_typ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
676tasn_typ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
677tasn_typ.o: ../../include/openssl/symhacks.h tasn_typ.c
678tasn_utl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
679tasn_utl.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
680tasn_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
681tasn_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
682tasn_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
683tasn_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
684tasn_utl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
685tasn_utl.o: ../../include/openssl/symhacks.h tasn_utl.c
686x_algor.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
687x_algor.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
688x_algor.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
689x_algor.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
690x_algor.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
691x_algor.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
692x_algor.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
693x_algor.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
694x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
695x_algor.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
696x_algor.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
697x_algor.o: ../../include/openssl/x509_vfy.h x_algor.c
698x_attrib.o: ../../e_os.h ../../include/openssl/asn1.h
699x_attrib.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
700x_attrib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
701x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
702x_attrib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
703x_attrib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
704x_attrib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
705x_attrib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
706x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
707x_attrib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
708x_attrib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
709x_attrib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
710x_attrib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_attrib.c
711x_bignum.o: ../../e_os.h ../../include/openssl/asn1.h
712x_bignum.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
713x_bignum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
714x_bignum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
715x_bignum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
716x_bignum.o: ../../include/openssl/opensslconf.h
717x_bignum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
718x_bignum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
719x_bignum.o: ../../include/openssl/symhacks.h ../cryptlib.h x_bignum.c
720x_crl.o: ../../e_os.h ../../include/openssl/asn1.h
721x_crl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
722x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
723x_crl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
724x_crl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
725x_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
726x_crl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
727x_crl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
728x_crl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
729x_crl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
730x_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
731x_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
732x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_crl.c
733x_exten.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
734x_exten.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
735x_exten.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
736x_exten.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
737x_exten.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
738x_exten.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
739x_exten.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
740x_exten.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
741x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
742x_exten.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
743x_exten.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
744x_exten.o: ../../include/openssl/x509_vfy.h x_exten.c
745x_info.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
746x_info.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
747x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
748x_info.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
749x_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
750x_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
751x_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
752x_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
753x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
754x_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
755x_info.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
756x_info.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_info.c
757x_long.o: ../../e_os.h ../../include/openssl/asn1.h
758x_long.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
759x_long.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
760x_long.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
761x_long.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
762x_long.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
763x_long.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
764x_long.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
765x_long.o: ../cryptlib.h x_long.c
766x_name.o: ../../e_os.h ../../include/openssl/asn1.h
767x_name.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
768x_name.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
769x_name.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
770x_name.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
771x_name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
772x_name.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
773x_name.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
774x_name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
775x_name.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
776x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
777x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
778x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_name.c
779x_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
780x_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
781x_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
782x_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
783x_pkey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
784x_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
785x_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
786x_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
787x_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
788x_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
789x_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
790x_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
791x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_pkey.c
792x_pubkey.o: ../../e_os.h ../../include/openssl/asn1.h
793x_pubkey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
794x_pubkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
795x_pubkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
796x_pubkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
797x_pubkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
798x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
799x_pubkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
800x_pubkey.o: ../../include/openssl/opensslconf.h
801x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
802x_pubkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
803x_pubkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
804x_pubkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
805x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
806x_pubkey.o: ../cryptlib.h x_pubkey.c
807x_req.o: ../../e_os.h ../../include/openssl/asn1.h
808x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
809x_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
810x_req.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
811x_req.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
812x_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
813x_req.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
814x_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
815x_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
816x_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
817x_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
818x_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
819x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_req.c
820x_sig.o: ../../e_os.h ../../include/openssl/asn1.h
821x_sig.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
822x_sig.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
823x_sig.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
824x_sig.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
825x_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h
826x_sig.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
827x_sig.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
828x_sig.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
829x_sig.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
830x_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
831x_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
832x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_sig.c
833x_spki.o: ../../e_os.h ../../include/openssl/asn1.h
834x_spki.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
835x_spki.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
836x_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
837x_spki.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
838x_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
839x_spki.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
840x_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
841x_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
842x_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
843x_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
844x_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
845x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_spki.c
846x_val.o: ../../e_os.h ../../include/openssl/asn1.h
847x_val.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
848x_val.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
849x_val.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
850x_val.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
851x_val.o: ../../include/openssl/err.h ../../include/openssl/evp.h
852x_val.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
853x_val.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
854x_val.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
855x_val.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
856x_val.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
857x_val.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
858x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_val.c
859x_x509.o: ../../e_os.h ../../include/openssl/asn1.h
860x_x509.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
861x_x509.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
862x_x509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
863x_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
864x_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
865x_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
866x_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
867x_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
868x_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
869x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
870x_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
871x_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
872x_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h x_x509.c
873x_x509a.o: ../../e_os.h ../../include/openssl/asn1.h
874x_x509a.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
875x_x509a.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
876x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
877x_x509a.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
878x_x509a.o: ../../include/openssl/err.h ../../include/openssl/evp.h
879x_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
880x_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
881x_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
882x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
883x_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
884x_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
885x_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_x509a.c
diff --git a/src/lib/libcrypto/asn1/Makefile.ssl b/src/lib/libcrypto/asn1/Makefile.ssl
new file mode 100644
index 0000000000..cb45194d48
--- /dev/null
+++ b/src/lib/libcrypto/asn1/Makefile.ssl
@@ -0,0 +1,1152 @@
1#
2# SSLeay/crypto/asn1/Makefile
3#
4
5DIR= asn1
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= a_object.c a_bitstr.c a_utctm.c a_gentm.c a_time.c a_int.c a_octet.c \
27 a_print.c a_type.c a_set.c a_dup.c a_d2i_fp.c a_i2d_fp.c \
28 a_enum.c a_utf8.c a_sign.c a_digest.c a_verify.c a_mbstr.c a_strex.c \
29 x_algor.c x_val.c x_pubkey.c x_sig.c x_req.c x_attrib.c x_bignum.c \
30 x_long.c x_name.c x_x509.c x_x509a.c x_crl.c x_info.c x_spki.c nsseq.c \
31 d2i_pu.c d2i_pr.c i2d_pu.c i2d_pr.c\
32 t_req.c t_x509.c t_x509a.c t_crl.c t_pkey.c t_spki.c t_bitst.c \
33 tasn_new.c tasn_fre.c tasn_enc.c tasn_dec.c tasn_utl.c tasn_typ.c \
34 f_int.c f_string.c n_pkey.c \
35 f_enum.c a_hdr.c x_pkey.c a_bool.c x_exten.c \
36 asn1_par.c asn1_lib.c asn1_err.c a_meth.c a_bytes.c a_strnid.c \
37 evp_asn1.c asn_pack.c p5_pbe.c p5_pbev2.c p8_pkey.c asn_moid.c
38LIBOBJ= a_object.o a_bitstr.o a_utctm.o a_gentm.o a_time.o a_int.o a_octet.o \
39 a_print.o a_type.o a_set.o a_dup.o a_d2i_fp.o a_i2d_fp.o \
40 a_enum.o a_utf8.o a_sign.o a_digest.o a_verify.o a_mbstr.o a_strex.o \
41 x_algor.o x_val.o x_pubkey.o x_sig.o x_req.o x_attrib.o x_bignum.o \
42 x_long.o x_name.o x_x509.o x_x509a.o x_crl.o x_info.o x_spki.o nsseq.o \
43 d2i_pu.o d2i_pr.o i2d_pu.o i2d_pr.o \
44 t_req.o t_x509.o t_x509a.o t_crl.o t_pkey.o t_spki.o t_bitst.o \
45 tasn_new.o tasn_fre.o tasn_enc.o tasn_dec.o tasn_utl.o tasn_typ.o \
46 f_int.o f_string.o n_pkey.o \
47 f_enum.o a_hdr.o x_pkey.o a_bool.o x_exten.o \
48 asn1_par.o asn1_lib.o asn1_err.o a_meth.o a_bytes.o a_strnid.o \
49 evp_asn1.o asn_pack.o p5_pbe.o p5_pbev2.o p8_pkey.o asn_moid.o
50
51SRC= $(LIBSRC)
52
53EXHEADER= asn1.h asn1_mac.h asn1t.h
54HEADER= $(EXHEADER)
55
56ALL= $(GENERAL) $(SRC) $(HEADER)
57
58top:
59 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
60
61test: test.c
62 cc -g -I../../include -c test.c
63 cc -g -I../../include -o test test.o -L../.. -lcrypto
64
65pk: pk.c
66 cc -g -I../../include -c pk.c
67 cc -g -I../../include -o pk pk.o -L../.. -lcrypto
68
69all: lib
70
71lib: $(LIBOBJ)
72 $(AR) $(LIB) $(LIBOBJ)
73 $(RANLIB) $(LIB) || echo Never mind.
74 @touch lib
75
76files:
77 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
78
79links:
80 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
81 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
82 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
83 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
84
85install:
86 @for i in $(EXHEADER) ; \
87 do \
88 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
89 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
90 done;
91
92tags:
93 ctags $(SRC)
94
95tests:
96
97lint:
98 lint -DLINT $(INCLUDES) $(SRC)>fluff
99
100depend:
101 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
102
103dclean:
104 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
105 mv -f Makefile.new $(MAKEFILE)
106
107clean:
108 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
109
110
111# DO NOT DELETE THIS LINE -- make depend depends on it.
112
113a_bitstr.o: ../../e_os.h ../../include/openssl/asn1.h
114a_bitstr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
115a_bitstr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
116a_bitstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
117a_bitstr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
118a_bitstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
119a_bitstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
120a_bitstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bitstr.c
121a_bool.o: ../../e_os.h ../../include/openssl/asn1.h
122a_bool.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
123a_bool.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
124a_bool.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
125a_bool.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
126a_bool.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
127a_bool.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
128a_bool.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
129a_bool.o: ../cryptlib.h a_bool.c
130a_bytes.o: ../../e_os.h ../../include/openssl/asn1.h
131a_bytes.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
132a_bytes.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
133a_bytes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
134a_bytes.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
135a_bytes.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
136a_bytes.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
137a_bytes.o: ../../include/openssl/symhacks.h ../cryptlib.h a_bytes.c
138a_d2i_fp.o: ../../e_os.h ../../include/openssl/asn1.h
139a_d2i_fp.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
140a_d2i_fp.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
141a_d2i_fp.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
142a_d2i_fp.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
143a_d2i_fp.o: ../../include/openssl/opensslconf.h
144a_d2i_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
145a_d2i_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
146a_d2i_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_d2i_fp.c
147a_digest.o: ../../e_os.h ../../include/openssl/aes.h
148a_digest.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
149a_digest.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
150a_digest.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
151a_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
152a_digest.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
153a_digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
154a_digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
155a_digest.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
156a_digest.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
157a_digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
158a_digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
159a_digest.o: ../../include/openssl/opensslconf.h
160a_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
161a_digest.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
162a_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
163a_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
164a_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
165a_digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
166a_digest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
167a_digest.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
168a_digest.o: ../cryptlib.h a_digest.c
169a_dup.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
170a_dup.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
171a_dup.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
172a_dup.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
173a_dup.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
174a_dup.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
175a_dup.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176a_dup.o: ../cryptlib.h a_dup.c
177a_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
178a_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
179a_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
180a_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
181a_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
182a_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
183a_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
184a_enum.o: ../cryptlib.h a_enum.c
185a_gentm.o: ../../e_os.h ../../include/openssl/asn1.h
186a_gentm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
187a_gentm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
188a_gentm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
189a_gentm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
190a_gentm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
191a_gentm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
192a_gentm.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_gentm.c
193a_hdr.o: ../../e_os.h ../../include/openssl/asn1.h
194a_hdr.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
195a_hdr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
196a_hdr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
197a_hdr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
198a_hdr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
199a_hdr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
200a_hdr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
201a_hdr.o: ../cryptlib.h a_hdr.c
202a_i2d_fp.o: ../../e_os.h ../../include/openssl/asn1.h
203a_i2d_fp.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
204a_i2d_fp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205a_i2d_fp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
206a_i2d_fp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
207a_i2d_fp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
208a_i2d_fp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
209a_i2d_fp.o: ../../include/openssl/symhacks.h ../cryptlib.h a_i2d_fp.c
210a_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
211a_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
212a_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
213a_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
214a_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215a_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
216a_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217a_int.o: ../cryptlib.h a_int.c
218a_mbstr.o: ../../e_os.h ../../include/openssl/asn1.h
219a_mbstr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
220a_mbstr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
221a_mbstr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
222a_mbstr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
223a_mbstr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
224a_mbstr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
225a_mbstr.o: ../../include/openssl/symhacks.h ../cryptlib.h a_mbstr.c
226a_meth.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
227a_meth.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
228a_meth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
229a_meth.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
230a_meth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
231a_meth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
232a_meth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
233a_meth.o: ../cryptlib.h a_meth.c
234a_object.o: ../../e_os.h ../../include/openssl/asn1.h
235a_object.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
236a_object.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
237a_object.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
238a_object.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
239a_object.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
240a_object.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
241a_object.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
242a_object.o: ../../include/openssl/symhacks.h ../cryptlib.h a_object.c
243a_octet.o: ../../e_os.h ../../include/openssl/asn1.h
244a_octet.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
245a_octet.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
246a_octet.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
247a_octet.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
248a_octet.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
249a_octet.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
250a_octet.o: ../../include/openssl/symhacks.h ../cryptlib.h a_octet.c
251a_print.o: ../../e_os.h ../../include/openssl/asn1.h
252a_print.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
253a_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
254a_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
255a_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
256a_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
257a_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
258a_print.o: ../../include/openssl/symhacks.h ../cryptlib.h a_print.c
259a_set.o: ../../e_os.h ../../include/openssl/asn1.h
260a_set.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
261a_set.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
262a_set.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
263a_set.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
264a_set.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
265a_set.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
266a_set.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
267a_set.o: ../cryptlib.h a_set.c
268a_sign.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
269a_sign.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
270a_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
271a_sign.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
272a_sign.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
273a_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
274a_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
275a_sign.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
276a_sign.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
277a_sign.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
278a_sign.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
279a_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
280a_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
281a_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
282a_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
283a_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
284a_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
285a_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
286a_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
287a_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
288a_sign.o: ../cryptlib.h a_sign.c
289a_strex.o: ../../e_os.h ../../include/openssl/aes.h
290a_strex.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
291a_strex.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
292a_strex.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
293a_strex.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
294a_strex.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
295a_strex.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
296a_strex.o: ../../include/openssl/err.h ../../include/openssl/evp.h
297a_strex.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
298a_strex.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
299a_strex.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
300a_strex.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
301a_strex.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
302a_strex.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
303a_strex.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
304a_strex.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
305a_strex.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
306a_strex.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
307a_strex.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
308a_strex.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
309a_strex.o: ../../include/openssl/x509_vfy.h ../cryptlib.h a_strex.c charmap.h
310a_strnid.o: ../../e_os.h ../../include/openssl/asn1.h
311a_strnid.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
312a_strnid.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
313a_strnid.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
314a_strnid.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
315a_strnid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
316a_strnid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
317a_strnid.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
318a_strnid.o: ../../include/openssl/symhacks.h ../cryptlib.h a_strnid.c
319a_time.o: ../../e_os.h ../../include/openssl/asn1.h
320a_time.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
321a_time.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
322a_time.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
323a_time.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
324a_time.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
325a_time.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
326a_time.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
327a_time.o: ../cryptlib.h ../o_time.h a_time.c
328a_type.o: ../../e_os.h ../../include/openssl/asn1.h
329a_type.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
330a_type.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
331a_type.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
332a_type.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
333a_type.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
334a_type.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
335a_type.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
336a_type.o: ../cryptlib.h a_type.c
337a_utctm.o: ../../e_os.h ../../include/openssl/asn1.h
338a_utctm.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
339a_utctm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
340a_utctm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
341a_utctm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
342a_utctm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
343a_utctm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
344a_utctm.o: ../../include/openssl/symhacks.h ../cryptlib.h ../o_time.h a_utctm.c
345a_utf8.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
346a_utf8.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
347a_utf8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
348a_utf8.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
349a_utf8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
350a_utf8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
351a_utf8.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
352a_utf8.o: ../cryptlib.h a_utf8.c
353a_verify.o: ../../e_os.h ../../include/openssl/aes.h
354a_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
355a_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
356a_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
357a_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
358a_verify.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
359a_verify.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
360a_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
361a_verify.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
362a_verify.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
363a_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
364a_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
365a_verify.o: ../../include/openssl/opensslconf.h
366a_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
367a_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
368a_verify.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
369a_verify.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
370a_verify.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
371a_verify.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
372a_verify.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
373a_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
374a_verify.o: ../cryptlib.h a_verify.c
375asn1_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
376asn1_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
377asn1_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
378asn1_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
379asn1_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
380asn1_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
381asn1_err.o: ../../include/openssl/symhacks.h asn1_err.c
382asn1_lib.o: ../../e_os.h ../../include/openssl/asn1.h
383asn1_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
384asn1_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
385asn1_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
386asn1_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
387asn1_lib.o: ../../include/openssl/opensslconf.h
388asn1_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
389asn1_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
390asn1_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_lib.c
391asn1_par.o: ../../e_os.h ../../include/openssl/asn1.h
392asn1_par.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
393asn1_par.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
394asn1_par.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
395asn1_par.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
396asn1_par.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
397asn1_par.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
398asn1_par.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
399asn1_par.o: ../../include/openssl/symhacks.h ../cryptlib.h asn1_par.c
400asn_moid.o: ../../e_os.h ../../include/openssl/aes.h
401asn_moid.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
402asn_moid.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
403asn_moid.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
404asn_moid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
405asn_moid.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
406asn_moid.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
407asn_moid.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
408asn_moid.o: ../../include/openssl/err.h ../../include/openssl/evp.h
409asn_moid.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
410asn_moid.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
411asn_moid.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
412asn_moid.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
413asn_moid.o: ../../include/openssl/opensslconf.h
414asn_moid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
415asn_moid.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
416asn_moid.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
417asn_moid.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
418asn_moid.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
419asn_moid.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
420asn_moid.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
421asn_moid.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
422asn_moid.o: ../cryptlib.h asn_moid.c
423asn_pack.o: ../../e_os.h ../../include/openssl/asn1.h
424asn_pack.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
425asn_pack.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
426asn_pack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
427asn_pack.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
428asn_pack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
429asn_pack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
430asn_pack.o: ../../include/openssl/symhacks.h ../cryptlib.h asn_pack.c
431d2i_pr.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
432d2i_pr.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
433d2i_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
434d2i_pr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
435d2i_pr.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
436d2i_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
437d2i_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
438d2i_pr.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
439d2i_pr.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
440d2i_pr.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
441d2i_pr.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
442d2i_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
443d2i_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
444d2i_pr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
445d2i_pr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
446d2i_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
447d2i_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
448d2i_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
449d2i_pr.o: ../../include/openssl/ui_compat.h ../cryptlib.h d2i_pr.c
450d2i_pu.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
451d2i_pu.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
452d2i_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
453d2i_pu.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
454d2i_pu.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
455d2i_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
456d2i_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
457d2i_pu.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
458d2i_pu.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
459d2i_pu.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
460d2i_pu.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
461d2i_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
462d2i_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
463d2i_pu.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
464d2i_pu.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
465d2i_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
466d2i_pu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
467d2i_pu.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
468d2i_pu.o: ../../include/openssl/ui_compat.h ../cryptlib.h d2i_pu.c
469evp_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
470evp_asn1.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
471evp_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
472evp_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
473evp_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
474evp_asn1.o: ../../include/openssl/opensslconf.h
475evp_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
476evp_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
477evp_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_asn1.c
478f_enum.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
479f_enum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
480f_enum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
481f_enum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
482f_enum.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
483f_enum.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
484f_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
485f_enum.o: ../cryptlib.h f_enum.c
486f_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
487f_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
488f_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
489f_int.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
490f_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
491f_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
492f_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
493f_int.o: ../cryptlib.h f_int.c
494f_string.o: ../../e_os.h ../../include/openssl/asn1.h
495f_string.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
496f_string.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
497f_string.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
498f_string.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
499f_string.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
500f_string.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
501f_string.o: ../../include/openssl/symhacks.h ../cryptlib.h f_string.c
502i2d_pr.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
503i2d_pr.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
504i2d_pr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
505i2d_pr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
506i2d_pr.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
507i2d_pr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
508i2d_pr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
509i2d_pr.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
510i2d_pr.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
511i2d_pr.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
512i2d_pr.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
513i2d_pr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
514i2d_pr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
515i2d_pr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
516i2d_pr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
517i2d_pr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
518i2d_pr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
519i2d_pr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
520i2d_pr.o: ../../include/openssl/ui_compat.h ../cryptlib.h i2d_pr.c
521i2d_pu.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
522i2d_pu.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
523i2d_pu.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
524i2d_pu.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
525i2d_pu.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
526i2d_pu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
527i2d_pu.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
528i2d_pu.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
529i2d_pu.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
530i2d_pu.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
531i2d_pu.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
532i2d_pu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
533i2d_pu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
534i2d_pu.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
535i2d_pu.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
536i2d_pu.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
537i2d_pu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
538i2d_pu.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
539i2d_pu.o: ../../include/openssl/ui_compat.h ../cryptlib.h i2d_pu.c
540n_pkey.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
541n_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/asn1t.h
542n_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
543n_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
544n_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
545n_pkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
546n_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
547n_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
548n_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
549n_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
550n_pkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
551n_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
552n_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
553n_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
554n_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
555n_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
556n_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
557n_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
558n_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
559n_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
560n_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
561n_pkey.o: ../cryptlib.h n_pkey.c
562nsseq.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
563nsseq.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
564nsseq.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
565nsseq.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
566nsseq.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
567nsseq.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
568nsseq.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
569nsseq.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
570nsseq.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
571nsseq.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
572nsseq.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
573nsseq.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
574nsseq.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
575nsseq.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
576nsseq.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
577nsseq.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
578nsseq.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
579nsseq.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
580nsseq.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
581nsseq.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h nsseq.c
582p5_pbe.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
583p5_pbe.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
584p5_pbe.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
585p5_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
586p5_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
587p5_pbe.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
588p5_pbe.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
589p5_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
590p5_pbe.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
591p5_pbe.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
592p5_pbe.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
593p5_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
594p5_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
595p5_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
596p5_pbe.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
597p5_pbe.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
598p5_pbe.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
599p5_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
600p5_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
601p5_pbe.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
602p5_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
603p5_pbe.o: ../cryptlib.h p5_pbe.c
604p5_pbev2.o: ../../e_os.h ../../include/openssl/aes.h
605p5_pbev2.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
606p5_pbev2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
607p5_pbev2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
608p5_pbev2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
609p5_pbev2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
610p5_pbev2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
611p5_pbev2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
612p5_pbev2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
613p5_pbev2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
614p5_pbev2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
615p5_pbev2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
616p5_pbev2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
617p5_pbev2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
618p5_pbev2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
619p5_pbev2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
620p5_pbev2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
621p5_pbev2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
622p5_pbev2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
623p5_pbev2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
624p5_pbev2.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
625p5_pbev2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_pbev2.c
626p8_pkey.o: ../../e_os.h ../../include/openssl/aes.h
627p8_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
628p8_pkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
629p8_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
630p8_pkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
631p8_pkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
632p8_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
633p8_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
634p8_pkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
635p8_pkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
636p8_pkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
637p8_pkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
638p8_pkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
639p8_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
640p8_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
641p8_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
642p8_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
643p8_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
644p8_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
645p8_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
646p8_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
647p8_pkey.o: ../cryptlib.h p8_pkey.c
648t_bitst.o: ../../e_os.h ../../include/openssl/aes.h
649t_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
650t_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
651t_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
652t_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
653t_bitst.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
654t_bitst.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
655t_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
656t_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
657t_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
658t_bitst.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
659t_bitst.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
660t_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
661t_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
662t_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
663t_bitst.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
664t_bitst.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
665t_bitst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
666t_bitst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
667t_bitst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
668t_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
669t_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h t_bitst.c
670t_crl.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
671t_crl.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
672t_crl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
673t_crl.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
674t_crl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
675t_crl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
676t_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
677t_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
678t_crl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
679t_crl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
680t_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
681t_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
682t_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
683t_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
684t_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
685t_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
686t_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
687t_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
688t_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
689t_crl.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
690t_crl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
691t_crl.o: ../cryptlib.h t_crl.c
692t_pkey.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
693t_pkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
694t_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
695t_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
696t_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
697t_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
698t_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
699t_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
700t_pkey.o: ../../include/openssl/symhacks.h ../cryptlib.h t_pkey.c
701t_req.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
702t_req.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
703t_req.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
704t_req.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
705t_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
706t_req.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
707t_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
708t_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
709t_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
710t_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
711t_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
712t_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
713t_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
714t_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
715t_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
716t_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
717t_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
718t_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
719t_req.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
720t_req.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
721t_req.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
722t_req.o: ../cryptlib.h t_req.c
723t_spki.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
724t_spki.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
725t_spki.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
726t_spki.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
727t_spki.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
728t_spki.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
729t_spki.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
730t_spki.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
731t_spki.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
732t_spki.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
733t_spki.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
734t_spki.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
735t_spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
736t_spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
737t_spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
738t_spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
739t_spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
740t_spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
741t_spki.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
742t_spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
743t_spki.o: ../cryptlib.h t_spki.c
744t_x509.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
745t_x509.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
746t_x509.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
747t_x509.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
748t_x509.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
749t_x509.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
750t_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
751t_x509.o: ../../include/openssl/err.h ../../include/openssl/evp.h
752t_x509.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
753t_x509.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
754t_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
755t_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
756t_x509.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
757t_x509.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
758t_x509.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
759t_x509.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
760t_x509.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
761t_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
762t_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
763t_x509.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
764t_x509.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
765t_x509.o: ../cryptlib.h t_x509.c
766t_x509a.o: ../../e_os.h ../../include/openssl/aes.h
767t_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
768t_x509a.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
769t_x509a.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
770t_x509a.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
771t_x509a.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
772t_x509a.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
773t_x509a.o: ../../include/openssl/err.h ../../include/openssl/evp.h
774t_x509a.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
775t_x509a.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
776t_x509a.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
777t_x509a.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
778t_x509a.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
779t_x509a.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
780t_x509a.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
781t_x509a.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
782t_x509a.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
783t_x509a.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
784t_x509a.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
785t_x509a.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
786t_x509a.o: ../../include/openssl/x509_vfy.h ../cryptlib.h t_x509a.c
787tasn_dec.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
788tasn_dec.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
789tasn_dec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
790tasn_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
791tasn_dec.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
792tasn_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
793tasn_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
794tasn_dec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
795tasn_dec.o: ../../include/openssl/symhacks.h tasn_dec.c
796tasn_enc.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
797tasn_enc.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
798tasn_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
799tasn_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
800tasn_enc.o: ../../include/openssl/opensslconf.h
801tasn_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
802tasn_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
803tasn_enc.o: ../../include/openssl/symhacks.h tasn_enc.c
804tasn_fre.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
805tasn_fre.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
806tasn_fre.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
807tasn_fre.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
808tasn_fre.o: ../../include/openssl/opensslconf.h
809tasn_fre.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
810tasn_fre.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
811tasn_fre.o: ../../include/openssl/symhacks.h tasn_fre.c
812tasn_new.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
813tasn_new.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
814tasn_new.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
815tasn_new.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
816tasn_new.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
817tasn_new.o: ../../include/openssl/opensslconf.h
818tasn_new.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
819tasn_new.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
820tasn_new.o: ../../include/openssl/symhacks.h tasn_new.c
821tasn_typ.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
822tasn_typ.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
823tasn_typ.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
824tasn_typ.o: ../../include/openssl/opensslconf.h
825tasn_typ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
826tasn_typ.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
827tasn_typ.o: ../../include/openssl/symhacks.h tasn_typ.c
828tasn_utl.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
829tasn_utl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
830tasn_utl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
831tasn_utl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
832tasn_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
833tasn_utl.o: ../../include/openssl/opensslconf.h
834tasn_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
835tasn_utl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
836tasn_utl.o: ../../include/openssl/symhacks.h tasn_utl.c
837x_algor.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
838x_algor.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
839x_algor.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
840x_algor.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
841x_algor.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
842x_algor.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
843x_algor.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
844x_algor.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
845x_algor.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
846x_algor.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
847x_algor.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
848x_algor.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
849x_algor.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
850x_algor.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
851x_algor.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
852x_algor.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
853x_algor.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
854x_algor.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
855x_algor.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
856x_algor.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
857x_algor.o: x_algor.c
858x_attrib.o: ../../e_os.h ../../include/openssl/aes.h
859x_attrib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
860x_attrib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
861x_attrib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
862x_attrib.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
863x_attrib.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
864x_attrib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
865x_attrib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
866x_attrib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
867x_attrib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
868x_attrib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
869x_attrib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
870x_attrib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
871x_attrib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
872x_attrib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
873x_attrib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
874x_attrib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
875x_attrib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
876x_attrib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
877x_attrib.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
878x_attrib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
879x_attrib.o: ../cryptlib.h x_attrib.c
880x_bignum.o: ../../e_os.h ../../include/openssl/asn1.h
881x_bignum.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
882x_bignum.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
883x_bignum.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
884x_bignum.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
885x_bignum.o: ../../include/openssl/opensslconf.h
886x_bignum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
887x_bignum.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
888x_bignum.o: ../../include/openssl/symhacks.h ../cryptlib.h x_bignum.c
889x_crl.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
890x_crl.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
891x_crl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
892x_crl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
893x_crl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
894x_crl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
895x_crl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
896x_crl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
897x_crl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
898x_crl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
899x_crl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
900x_crl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
901x_crl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
902x_crl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
903x_crl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
904x_crl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
905x_crl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
906x_crl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
907x_crl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
908x_crl.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
909x_crl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_crl.c
910x_exten.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
911x_exten.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
912x_exten.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
913x_exten.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
914x_exten.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
915x_exten.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
916x_exten.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
917x_exten.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
918x_exten.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
919x_exten.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
920x_exten.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
921x_exten.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
922x_exten.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
923x_exten.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
924x_exten.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
925x_exten.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
926x_exten.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
927x_exten.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
928x_exten.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
929x_exten.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
930x_exten.o: x_exten.c
931x_info.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
932x_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
933x_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
934x_info.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
935x_info.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
936x_info.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
937x_info.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
938x_info.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
939x_info.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
940x_info.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
941x_info.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
942x_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
943x_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
944x_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
945x_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
946x_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
947x_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
948x_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
949x_info.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
950x_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
951x_info.o: ../cryptlib.h x_info.c
952x_long.o: ../../e_os.h ../../include/openssl/asn1.h
953x_long.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
954x_long.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
955x_long.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
956x_long.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
957x_long.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
958x_long.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
959x_long.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
960x_long.o: ../cryptlib.h x_long.c
961x_name.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
962x_name.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
963x_name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
964x_name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
965x_name.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
966x_name.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
967x_name.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
968x_name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
969x_name.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
970x_name.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
971x_name.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
972x_name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
973x_name.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
974x_name.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
975x_name.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
976x_name.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
977x_name.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
978x_name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
979x_name.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
980x_name.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
981x_name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_name.c
982x_pkey.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
983x_pkey.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
984x_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
985x_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
986x_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
987x_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
988x_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
989x_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
990x_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
991x_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
992x_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
993x_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
994x_pkey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
995x_pkey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
996x_pkey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
997x_pkey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
998x_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
999x_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1000x_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1001x_pkey.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1002x_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_pkey.c
1003x_pubkey.o: ../../e_os.h ../../include/openssl/aes.h
1004x_pubkey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
1005x_pubkey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1006x_pubkey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1007x_pubkey.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1008x_pubkey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1009x_pubkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1010x_pubkey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1011x_pubkey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1012x_pubkey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1013x_pubkey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1014x_pubkey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1015x_pubkey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1016x_pubkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1017x_pubkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1018x_pubkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1019x_pubkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1020x_pubkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1021x_pubkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1022x_pubkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1023x_pubkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1024x_pubkey.o: ../cryptlib.h x_pubkey.c
1025x_req.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1026x_req.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1027x_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1028x_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1029x_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1030x_req.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1031x_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1032x_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1033x_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1034x_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1035x_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1036x_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1037x_req.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1038x_req.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1039x_req.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1040x_req.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1041x_req.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1042x_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1043x_req.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1044x_req.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1045x_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_req.c
1046x_sig.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1047x_sig.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1048x_sig.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1049x_sig.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1050x_sig.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1051x_sig.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1052x_sig.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1053x_sig.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1054x_sig.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1055x_sig.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1056x_sig.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1057x_sig.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1058x_sig.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1059x_sig.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1060x_sig.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1061x_sig.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1062x_sig.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1063x_sig.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1064x_sig.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1065x_sig.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1066x_sig.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_sig.c
1067x_spki.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1068x_spki.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1069x_spki.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1070x_spki.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1071x_spki.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1072x_spki.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1073x_spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1074x_spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1075x_spki.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1076x_spki.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1077x_spki.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1078x_spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1079x_spki.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1080x_spki.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1081x_spki.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1082x_spki.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1083x_spki.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1084x_spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1085x_spki.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1086x_spki.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1087x_spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_spki.c
1088x_val.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1089x_val.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1090x_val.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1091x_val.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1092x_val.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1093x_val.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1094x_val.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1095x_val.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1096x_val.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1097x_val.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1098x_val.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1099x_val.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1100x_val.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
1101x_val.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
1102x_val.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1103x_val.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1104x_val.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1105x_val.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1106x_val.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1107x_val.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1108x_val.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_val.c
1109x_x509.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1110x_x509.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
1111x_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1112x_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1113x_x509.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
1114x_x509.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1115x_x509.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1116x_x509.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1117x_x509.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1118x_x509.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1119x_x509.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1120x_x509.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1121x_x509.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1122x_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1123x_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1124x_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1125x_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1126x_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1127x_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1128x_x509.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1129x_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1130x_x509.o: ../../include/openssl/x509v3.h ../cryptlib.h x_x509.c
1131x_x509a.o: ../../e_os.h ../../include/openssl/aes.h
1132x_x509a.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
1133x_x509a.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1134x_x509a.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1135x_x509a.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1136x_x509a.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1137x_x509a.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1138x_x509a.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1139x_x509a.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1140x_x509a.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1141x_x509a.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1142x_x509a.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1143x_x509a.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1144x_x509a.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1145x_x509a.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1146x_x509a.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1147x_x509a.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1148x_x509a.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1149x_x509a.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1150x_x509a.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1151x_x509a.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1152x_x509a.o: ../cryptlib.h x_x509a.c
diff --git a/src/lib/libcrypto/asn1/a_bitstr.c b/src/lib/libcrypto/asn1/a_bitstr.c
index 0fb9ce0c2a..b81bf4fc81 100644
--- a/src/lib/libcrypto/asn1/a_bitstr.c
+++ b/src/lib/libcrypto/asn1/a_bitstr.c
@@ -113,12 +113,11 @@ int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a, unsigned char **pp)
113 return(ret); 113 return(ret);
114 } 114 }
115 115
116ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, 116ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a, unsigned char **pp,
117 const unsigned char **pp, long len) 117 long len)
118 { 118 {
119 ASN1_BIT_STRING *ret=NULL; 119 ASN1_BIT_STRING *ret=NULL;
120 const unsigned char *p; 120 unsigned char *p,*s;
121 unsigned char *s;
122 int i; 121 int i;
123 122
124 if (len < 1) 123 if (len < 1)
@@ -165,7 +164,7 @@ ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,
165 *pp=p; 164 *pp=p;
166 return(ret); 165 return(ret);
167err: 166err:
168 ASN1err(ASN1_F_C2I_ASN1_BIT_STRING,i); 167 ASN1err(ASN1_F_D2I_ASN1_BIT_STRING,i);
169 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 168 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
170 M_ASN1_BIT_STRING_free(ret); 169 M_ASN1_BIT_STRING_free(ret);
171 return(NULL); 170 return(NULL);
@@ -183,11 +182,9 @@ int ASN1_BIT_STRING_set_bit(ASN1_BIT_STRING *a, int n, int value)
183 iv= ~v; 182 iv= ~v;
184 if (!value) v=0; 183 if (!value) v=0;
185 184
186 if (a == NULL)
187 return 0;
188
189 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */ 185 a->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); /* clear, set on write */
190 186
187 if (a == NULL) return(0);
191 if ((a->length < (w+1)) || (a->data == NULL)) 188 if ((a->length < (w+1)) || (a->data == NULL))
192 { 189 {
193 if (!value) return(1); /* Don't need to set */ 190 if (!value) return(1); /* Don't need to set */
diff --git a/src/lib/libcrypto/asn1/a_bool.c b/src/lib/libcrypto/asn1/a_bool.c
index 331acdf053..24333ea4d5 100644
--- a/src/lib/libcrypto/asn1/a_bool.c
+++ b/src/lib/libcrypto/asn1/a_bool.c
@@ -75,10 +75,10 @@ int i2d_ASN1_BOOLEAN(int a, unsigned char **pp)
75 return(r); 75 return(r);
76 } 76 }
77 77
78int d2i_ASN1_BOOLEAN(int *a, const unsigned char **pp, long length) 78int d2i_ASN1_BOOLEAN(int *a, unsigned char **pp, long length)
79 { 79 {
80 int ret= -1; 80 int ret= -1;
81 const unsigned char *p; 81 unsigned char *p;
82 long len; 82 long len;
83 int inf,tag,xclass; 83 int inf,tag,xclass;
84 int i=0; 84 int i=0;
diff --git a/src/lib/libcrypto/asn1/a_bytes.c b/src/lib/libcrypto/asn1/a_bytes.c
index 8d13f9c931..2407f7c87a 100644
--- a/src/lib/libcrypto/asn1/a_bytes.c
+++ b/src/lib/libcrypto/asn1/a_bytes.c
@@ -60,15 +60,14 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62 62
63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c); 63static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c);
64/* type is a 'bitmap' of acceptable string types. 64/* type is a 'bitmap' of acceptable string types.
65 */ 65 */
66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp, 66ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, unsigned char **pp,
67 long length, int type) 67 long length, int type)
68 { 68 {
69 ASN1_STRING *ret=NULL; 69 ASN1_STRING *ret=NULL;
70 const unsigned char *p; 70 unsigned char *p,*s;
71 unsigned char *s;
72 long len; 71 long len;
73 int inf,tag,xclass; 72 int inf,tag,xclass;
74 int i=0; 73 int i=0;
@@ -79,7 +78,7 @@ ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a, const unsigned char **pp,
79 78
80 if (tag >= 32) 79 if (tag >= 32)
81 { 80 {
82 i=ASN1_R_TAG_VALUE_TOO_HIGH;; 81 i=ASN1_R_TAG_VALUE_TOO_HIGH;
83 goto err; 82 goto err;
84 } 83 }
85 if (!(ASN1_tag2bit(tag) & type)) 84 if (!(ASN1_tag2bit(tag) & type))
@@ -154,12 +153,11 @@ int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass)
154 return(r); 153 return(r);
155 } 154 }
156 155
157ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, 156ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp, long length,
158 long length, int Ptag, int Pclass) 157 int Ptag, int Pclass)
159 { 158 {
160 ASN1_STRING *ret=NULL; 159 ASN1_STRING *ret=NULL;
161 const unsigned char *p; 160 unsigned char *p,*s;
162 unsigned char *s;
163 long len; 161 long len;
164 int inf,tag,xclass; 162 int inf,tag,xclass;
165 int i=0; 163 int i=0;
@@ -187,7 +185,7 @@ ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp,
187 185
188 if (inf & V_ASN1_CONSTRUCTED) 186 if (inf & V_ASN1_CONSTRUCTED)
189 { 187 {
190 ASN1_const_CTX c; 188 ASN1_CTX c;
191 189
192 c.pp=pp; 190 c.pp=pp;
193 c.p=p; 191 c.p=p;
@@ -249,7 +247,7 @@ err:
249 * them into the one structure that is then returned */ 247 * them into the one structure that is then returned */
250/* There have been a few bug fixes for this function from 248/* There have been a few bug fixes for this function from
251 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */ 249 * Paul Keogh <paul.keogh@sse.ie>, many thanks to him */
252static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c) 250static int asn1_collate_primitive(ASN1_STRING *a, ASN1_CTX *c)
253 { 251 {
254 ASN1_STRING *os=NULL; 252 ASN1_STRING *os=NULL;
255 BUF_MEM b; 253 BUF_MEM b;
@@ -270,7 +268,7 @@ static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
270 { 268 {
271 if (c->inf & 1) 269 if (c->inf & 1)
272 { 270 {
273 c->eos=ASN1_const_check_infinite_end(&c->p, 271 c->eos=ASN1_check_infinite_end(&c->p,
274 (long)(c->max-c->p)); 272 (long)(c->max-c->p));
275 if (c->eos) break; 273 if (c->eos) break;
276 } 274 }
@@ -298,7 +296,7 @@ static int asn1_collate_primitive(ASN1_STRING *a, ASN1_const_CTX *c)
298 num+=os->length; 296 num+=os->length;
299 } 297 }
300 298
301 if (!asn1_const_Finish(c)) goto err; 299 if (!asn1_Finish(c)) goto err;
302 300
303 a->length=num; 301 a->length=num;
304 if (a->data != NULL) OPENSSL_free(a->data); 302 if (a->data != NULL) OPENSSL_free(a->data);
diff --git a/src/lib/libcrypto/asn1/a_d2i_fp.c b/src/lib/libcrypto/asn1/a_d2i_fp.c
index ece40bc4c0..b67b75e7c2 100644
--- a/src/lib/libcrypto/asn1/a_d2i_fp.c
+++ b/src/lib/libcrypto/asn1/a_d2i_fp.c
@@ -66,10 +66,11 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb);
66#ifndef NO_OLD_ASN1 66#ifndef NO_OLD_ASN1
67#ifndef OPENSSL_NO_FP_API 67#ifndef OPENSSL_NO_FP_API
68 68
69void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x) 69char *ASN1_d2i_fp(char *(*xnew)(), char *(*d2i)(), FILE *in,
70 unsigned char **x)
70 { 71 {
71 BIO *b; 72 BIO *b;
72 void *ret; 73 char *ret;
73 74
74 if ((b=BIO_new(BIO_s_file())) == NULL) 75 if ((b=BIO_new(BIO_s_file())) == NULL)
75 { 76 {
@@ -83,11 +84,12 @@ void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x)
83 } 84 }
84#endif 85#endif
85 86
86void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x) 87char *ASN1_d2i_bio(char *(*xnew)(), char *(*d2i)(), BIO *in,
88 unsigned char **x)
87 { 89 {
88 BUF_MEM *b = NULL; 90 BUF_MEM *b = NULL;
89 const unsigned char *p; 91 unsigned char *p;
90 void *ret=NULL; 92 char *ret=NULL;
91 int len; 93 int len;
92 94
93 len = asn1_d2i_read_bio(in, &b); 95 len = asn1_d2i_read_bio(in, &b);
@@ -105,14 +107,14 @@ err:
105void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x) 107void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x)
106 { 108 {
107 BUF_MEM *b = NULL; 109 BUF_MEM *b = NULL;
108 const unsigned char *p; 110 unsigned char *p;
109 void *ret=NULL; 111 void *ret=NULL;
110 int len; 112 int len;
111 113
112 len = asn1_d2i_read_bio(in, &b); 114 len = asn1_d2i_read_bio(in, &b);
113 if(len < 0) goto err; 115 if(len < 0) goto err;
114 116
115 p=(const unsigned char *)b->data; 117 p=(unsigned char *)b->data;
116 ret=ASN1_item_d2i(x,&p,len, it); 118 ret=ASN1_item_d2i(x,&p,len, it);
117err: 119err:
118 if (b != NULL) BUF_MEM_free(b); 120 if (b != NULL) BUF_MEM_free(b);
@@ -127,7 +129,7 @@ void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x)
127 129
128 if ((b=BIO_new(BIO_s_file())) == NULL) 130 if ((b=BIO_new(BIO_s_file())) == NULL)
129 { 131 {
130 ASN1err(ASN1_F_ASN1_ITEM_D2I_FP,ERR_R_BUF_LIB); 132 ASN1err(ASN1_F_ASN1_D2I_FP,ERR_R_BUF_LIB);
131 return(NULL); 133 return(NULL);
132 } 134 }
133 BIO_set_fp(b,in,BIO_NOCLOSE); 135 BIO_set_fp(b,in,BIO_NOCLOSE);
@@ -144,7 +146,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
144 unsigned char *p; 146 unsigned char *p;
145 int i; 147 int i;
146 int ret=-1; 148 int ret=-1;
147 ASN1_const_CTX c; 149 ASN1_CTX c;
148 int want=HEADER_SIZE; 150 int want=HEADER_SIZE;
149 int eos=0; 151 int eos=0;
150#if defined(__GNUC__) && defined(__ia64) 152#if defined(__GNUC__) && defined(__ia64)
@@ -158,7 +160,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
158 b=BUF_MEM_new(); 160 b=BUF_MEM_new();
159 if (b == NULL) 161 if (b == NULL)
160 { 162 {
161 ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); 163 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
162 return -1; 164 return -1;
163 } 165 }
164 166
@@ -171,13 +173,13 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
171 173
172 if (!BUF_MEM_grow_clean(b,len+want)) 174 if (!BUF_MEM_grow_clean(b,len+want))
173 { 175 {
174 ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); 176 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
175 goto err; 177 goto err;
176 } 178 }
177 i=BIO_read(in,&(b->data[len]),want); 179 i=BIO_read(in,&(b->data[len]),want);
178 if ((i < 0) && ((len-off) == 0)) 180 if ((i < 0) && ((len-off) == 0))
179 { 181 {
180 ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ASN1_R_NOT_ENOUGH_DATA); 182 ASN1err(ASN1_F_ASN1_D2I_BIO,ASN1_R_NOT_ENOUGH_DATA);
181 goto err; 183 goto err;
182 } 184 }
183 if (i > 0) 185 if (i > 0)
@@ -197,7 +199,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
197 if (e != ASN1_R_TOO_LONG) 199 if (e != ASN1_R_TOO_LONG)
198 goto err; 200 goto err;
199 else 201 else
200 ERR_clear_error(); /* clear error */ 202 ERR_get_error(); /* clear error */
201 } 203 }
202 i=c.p-p;/* header length */ 204 i=c.p-p;/* header length */
203 off+=i; /* end of data */ 205 off+=i; /* end of data */
@@ -226,7 +228,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
226 want-=(len-off); 228 want-=(len-off);
227 if (!BUF_MEM_grow_clean(b,len+want)) 229 if (!BUF_MEM_grow_clean(b,len+want))
228 { 230 {
229 ASN1err(ASN1_F_ASN1_D2I_READ_BIO,ERR_R_MALLOC_FAILURE); 231 ASN1err(ASN1_F_ASN1_D2I_BIO,ERR_R_MALLOC_FAILURE);
230 goto err; 232 goto err;
231 } 233 }
232 while (want > 0) 234 while (want > 0)
@@ -234,7 +236,7 @@ static int asn1_d2i_read_bio(BIO *in, BUF_MEM **pb)
234 i=BIO_read(in,&(b->data[len]),want); 236 i=BIO_read(in,&(b->data[len]),want);
235 if (i <= 0) 237 if (i <= 0)
236 { 238 {
237 ASN1err(ASN1_F_ASN1_D2I_READ_BIO, 239 ASN1err(ASN1_F_ASN1_D2I_BIO,
238 ASN1_R_NOT_ENOUGH_DATA); 240 ASN1_R_NOT_ENOUGH_DATA);
239 goto err; 241 goto err;
240 } 242 }
diff --git a/src/lib/libcrypto/asn1/a_digest.c b/src/lib/libcrypto/asn1/a_digest.c
index d00d9e22b1..7182e9fa5d 100644
--- a/src/lib/libcrypto/asn1/a_digest.c
+++ b/src/lib/libcrypto/asn1/a_digest.c
@@ -72,7 +72,7 @@
72 72
73#ifndef NO_ASN1_OLD 73#ifndef NO_ASN1_OLD
74 74
75int ASN1_digest(i2d_of_void *i2d, const EVP_MD *type, char *data, 75int ASN1_digest(int (*i2d)(), const EVP_MD *type, char *data,
76 unsigned char *md, unsigned int *len) 76 unsigned char *md, unsigned int *len)
77 { 77 {
78 int i; 78 int i;
diff --git a/src/lib/libcrypto/asn1/a_dup.c b/src/lib/libcrypto/asn1/a_dup.c
index 199d50f521..58a017884c 100644
--- a/src/lib/libcrypto/asn1/a_dup.c
+++ b/src/lib/libcrypto/asn1/a_dup.c
@@ -62,23 +62,22 @@
62 62
63#ifndef NO_OLD_ASN1 63#ifndef NO_OLD_ASN1
64 64
65void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x) 65char *ASN1_dup(int (*i2d)(), char *(*d2i)(), char *x)
66 { 66 {
67 unsigned char *b,*p; 67 unsigned char *b,*p;
68 const unsigned char *p2; 68 long i;
69 int i;
70 char *ret; 69 char *ret;
71 70
72 if (x == NULL) return(NULL); 71 if (x == NULL) return(NULL);
73 72
74 i=i2d(x,NULL); 73 i=(long)i2d(x,NULL);
75 b=OPENSSL_malloc(i+10); 74 b=(unsigned char *)OPENSSL_malloc((unsigned int)i+10);
76 if (b == NULL) 75 if (b == NULL)
77 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } 76 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
78 p= b; 77 p= b;
79 i=i2d(x,&p); 78 i=i2d(x,&p);
80 p2= b; 79 p= b;
81 ret=d2i(NULL,&p2,i); 80 ret=d2i(NULL,&p,i);
82 OPENSSL_free(b); 81 OPENSSL_free(b);
83 return(ret); 82 return(ret);
84 } 83 }
@@ -92,8 +91,7 @@ void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x)
92 91
93void *ASN1_item_dup(const ASN1_ITEM *it, void *x) 92void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
94 { 93 {
95 unsigned char *b = NULL; 94 unsigned char *b = NULL, *p;
96 const unsigned char *p;
97 long i; 95 long i;
98 void *ret; 96 void *ret;
99 97
@@ -101,7 +99,7 @@ void *ASN1_item_dup(const ASN1_ITEM *it, void *x)
101 99
102 i=ASN1_item_i2d(x,&b,it); 100 i=ASN1_item_i2d(x,&b,it);
103 if (b == NULL) 101 if (b == NULL)
104 { ASN1err(ASN1_F_ASN1_ITEM_DUP,ERR_R_MALLOC_FAILURE); return(NULL); } 102 { ASN1err(ASN1_F_ASN1_DUP,ERR_R_MALLOC_FAILURE); return(NULL); }
105 p= b; 103 p= b;
106 ret=ASN1_item_d2i(NULL,&p,i, it); 104 ret=ASN1_item_d2i(NULL,&p,i, it);
107 OPENSSL_free(b); 105 OPENSSL_free(b);
diff --git a/src/lib/libcrypto/asn1/a_enum.c b/src/lib/libcrypto/asn1/a_enum.c
index fe9aa13b9c..03ede68d1c 100644
--- a/src/lib/libcrypto/asn1/a_enum.c
+++ b/src/lib/libcrypto/asn1/a_enum.c
@@ -59,7 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h>
63 62
64/* 63/*
65 * Code for ENUMERATED type: identical to INTEGER apart from a different tag. 64 * Code for ENUMERATED type: identical to INTEGER apart from a different tag.
@@ -68,13 +67,12 @@
68 67
69int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v) 68int ASN1_ENUMERATED_set(ASN1_ENUMERATED *a, long v)
70 { 69 {
71 int j,k; 70 int i,j,k;
72 unsigned int i;
73 unsigned char buf[sizeof(long)+1]; 71 unsigned char buf[sizeof(long)+1];
74 long d; 72 long d;
75 73
76 a->type=V_ASN1_ENUMERATED; 74 a->type=V_ASN1_ENUMERATED;
77 if (a->length < (int)(sizeof(long)+1)) 75 if (a->length < (sizeof(long)+1))
78 { 76 {
79 if (a->data != NULL) 77 if (a->data != NULL)
80 OPENSSL_free(a->data); 78 OPENSSL_free(a->data);
@@ -118,7 +116,7 @@ long ASN1_ENUMERATED_get(ASN1_ENUMERATED *a)
118 else if (i != V_ASN1_ENUMERATED) 116 else if (i != V_ASN1_ENUMERATED)
119 return -1; 117 return -1;
120 118
121 if (a->length > (int)sizeof(long)) 119 if (a->length > sizeof(long))
122 { 120 {
123 /* hmm... a bit ugly */ 121 /* hmm... a bit ugly */
124 return(0xffffffffL); 122 return(0xffffffffL);
@@ -149,7 +147,7 @@ ASN1_ENUMERATED *BN_to_ASN1_ENUMERATED(BIGNUM *bn, ASN1_ENUMERATED *ai)
149 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR); 147 ASN1err(ASN1_F_BN_TO_ASN1_ENUMERATED,ERR_R_NESTED_ASN1_ERROR);
150 goto err; 148 goto err;
151 } 149 }
152 if(BN_is_negative(bn)) ret->type = V_ASN1_NEG_ENUMERATED; 150 if(bn->neg) ret->type = V_ASN1_NEG_ENUMERATED;
153 else ret->type=V_ASN1_ENUMERATED; 151 else ret->type=V_ASN1_ENUMERATED;
154 j=BN_num_bits(bn); 152 j=BN_num_bits(bn);
155 len=((j == 0)?0:((j/8)+1)); 153 len=((j == 0)?0:((j/8)+1));
@@ -177,6 +175,6 @@ BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai, BIGNUM *bn)
177 175
178 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 176 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
179 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB); 177 ASN1err(ASN1_F_ASN1_ENUMERATED_TO_BN,ASN1_R_BN_LIB);
180 else if(ai->type == V_ASN1_NEG_ENUMERATED) BN_set_negative(ret,1); 178 else if(ai->type == V_ASN1_NEG_ENUMERATED) ret->neg = 1;
181 return(ret); 179 return(ret);
182 } 180 }
diff --git a/src/lib/libcrypto/asn1/a_gentm.c b/src/lib/libcrypto/asn1/a_gentm.c
new file mode 100644
index 0000000000..0dfd576211
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_gentm.c
@@ -0,0 +1,246 @@
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 "o_time.h"
65#include <openssl/asn1.h>
66
67#if 0
68
69int i2d_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME *a, unsigned char **pp)
70 {
71#ifdef CHARSET_EBCDIC
72 /* KLUDGE! We convert to ascii before writing DER */
73 int len;
74 char tmp[24];
75 ASN1_STRING tmpstr = *(ASN1_STRING *)a;
76
77 len = tmpstr.length;
78 ebcdic2ascii(tmp, tmpstr.data, (len >= sizeof tmp) ? sizeof tmp : len);
79 tmpstr.data = tmp;
80
81 a = (ASN1_GENERALIZEDTIME *) &tmpstr;
82#endif
83 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
84 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL));
85 }
86
87
88ASN1_GENERALIZEDTIME *d2i_ASN1_GENERALIZEDTIME(ASN1_GENERALIZEDTIME **a,
89 unsigned char **pp, long length)
90 {
91 ASN1_GENERALIZEDTIME *ret=NULL;
92
93 ret=(ASN1_GENERALIZEDTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
94 V_ASN1_GENERALIZEDTIME,V_ASN1_UNIVERSAL);
95 if (ret == NULL)
96 {
97 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ERR_R_NESTED_ASN1_ERROR);
98 return(NULL);
99 }
100#ifdef CHARSET_EBCDIC
101 ascii2ebcdic(ret->data, ret->data, ret->length);
102#endif
103 if (!ASN1_GENERALIZEDTIME_check(ret))
104 {
105 ASN1err(ASN1_F_D2I_ASN1_GENERALIZEDTIME,ASN1_R_INVALID_TIME_FORMAT);
106 goto err;
107 }
108
109 return(ret);
110err:
111 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
112 M_ASN1_GENERALIZEDTIME_free(ret);
113 return(NULL);
114 }
115
116#endif
117
118int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *d)
119 {
120 static int min[9]={ 0, 0, 1, 1, 0, 0, 0, 0, 0};
121 static int max[9]={99, 99,12,31,23,59,59,12,59};
122 char *a;
123 int n,i,l,o;
124
125 if (d->type != V_ASN1_GENERALIZEDTIME) return(0);
126 l=d->length;
127 a=(char *)d->data;
128 o=0;
129 /* GENERALIZEDTIME is similar to UTCTIME except the year is
130 * represented as YYYY. This stuff treats everything as a two digit
131 * field so make first two fields 00 to 99
132 */
133 if (l < 13) goto err;
134 for (i=0; i<7; i++)
135 {
136 if ((i == 6) && ((a[o] == 'Z') ||
137 (a[o] == '+') || (a[o] == '-')))
138 { i++; break; }
139 if ((a[o] < '0') || (a[o] > '9')) goto err;
140 n= a[o]-'0';
141 if (++o > l) goto err;
142
143 if ((a[o] < '0') || (a[o] > '9')) goto err;
144 n=(n*10)+ a[o]-'0';
145 if (++o > l) goto err;
146
147 if ((n < min[i]) || (n > max[i])) goto err;
148 }
149 /* Optional fractional seconds: decimal point followed by one
150 * or more digits.
151 */
152 if (a[o] == '.')
153 {
154 if (++o > l) goto err;
155 i = o;
156 while ((a[o] >= '0') && (a[o] <= '9') && (o <= l))
157 o++;
158 /* Must have at least one digit after decimal point */
159 if (i == o) goto err;
160 }
161
162 if (a[o] == 'Z')
163 o++;
164 else if ((a[o] == '+') || (a[o] == '-'))
165 {
166 o++;
167 if (o+4 > l) goto err;
168 for (i=7; i<9; i++)
169 {
170 if ((a[o] < '0') || (a[o] > '9')) goto err;
171 n= a[o]-'0';
172 o++;
173 if ((a[o] < '0') || (a[o] > '9')) goto err;
174 n=(n*10)+ a[o]-'0';
175 if ((n < min[i]) || (n > max[i])) goto err;
176 o++;
177 }
178 }
179 return(o == l);
180err:
181 return(0);
182 }
183
184int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str)
185 {
186 ASN1_GENERALIZEDTIME t;
187
188 t.type=V_ASN1_GENERALIZEDTIME;
189 t.length=strlen(str);
190 t.data=(unsigned char *)str;
191 if (ASN1_GENERALIZEDTIME_check(&t))
192 {
193 if (s != NULL)
194 {
195 if (!ASN1_STRING_set((ASN1_STRING *)s,
196 (unsigned char *)str,t.length))
197 return 0;
198 s->type=V_ASN1_GENERALIZEDTIME;
199 }
200 return(1);
201 }
202 else
203 return(0);
204 }
205
206ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,
207 time_t t)
208 {
209 char *p;
210 struct tm *ts;
211 struct tm data;
212 size_t len = 20;
213
214 if (s == NULL)
215 s=M_ASN1_GENERALIZEDTIME_new();
216 if (s == NULL)
217 return(NULL);
218
219 ts=OPENSSL_gmtime(&t, &data);
220 if (ts == NULL)
221 return(NULL);
222
223 p=(char *)s->data;
224 if ((p == NULL) || ((size_t)s->length < len))
225 {
226 p=OPENSSL_malloc(len);
227 if (p == NULL)
228 {
229 ASN1err(ASN1_F_ASN1_GENERALIZEDTIME_SET,
230 ERR_R_MALLOC_FAILURE);
231 return(NULL);
232 }
233 if (s->data != NULL)
234 OPENSSL_free(s->data);
235 s->data=(unsigned char *)p;
236 }
237
238 BIO_snprintf(p,len,"%04d%02d%02d%02d%02d%02dZ",ts->tm_year + 1900,
239 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
240 s->length=strlen(p);
241 s->type=V_ASN1_GENERALIZEDTIME;
242#ifdef CHARSET_EBCDIC_not
243 ebcdic2ascii(s->data, s->data, s->length);
244#endif
245 return(s);
246 }
diff --git a/src/lib/libcrypto/asn1/a_hdr.c b/src/lib/libcrypto/asn1/a_hdr.c
new file mode 100644
index 0000000000..b1aad81f77
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_hdr.c
@@ -0,0 +1,119 @@
1/* crypto/asn1/a_hdr.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/asn1.h>
63
64int i2d_ASN1_HEADER(ASN1_HEADER *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->header, i2d_ASN1_OCTET_STRING);
69 M_ASN1_I2D_len(a->data, a->meth->i2d);
70
71 M_ASN1_I2D_seq_total();
72
73 M_ASN1_I2D_put(a->header, i2d_ASN1_OCTET_STRING);
74 M_ASN1_I2D_put(a->data, a->meth->i2d);
75
76 M_ASN1_I2D_finish();
77 }
78
79ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a, unsigned char **pp,
80 long length)
81 {
82 M_ASN1_D2I_vars(a,ASN1_HEADER *,ASN1_HEADER_new);
83
84 M_ASN1_D2I_Init();
85 M_ASN1_D2I_start_sequence();
86 M_ASN1_D2I_get(ret->header,d2i_ASN1_OCTET_STRING);
87 if (ret->meth != NULL)
88 {
89 M_ASN1_D2I_get(ret->data,ret->meth->d2i);
90 }
91 else
92 {
93 if (a != NULL) (*a)=ret;
94 return(ret);
95 }
96 M_ASN1_D2I_Finish(a,ASN1_HEADER_free,ASN1_F_D2I_ASN1_HEADER);
97 }
98
99ASN1_HEADER *ASN1_HEADER_new(void)
100 {
101 ASN1_HEADER *ret=NULL;
102 ASN1_CTX c;
103
104 M_ASN1_New_Malloc(ret,ASN1_HEADER);
105 M_ASN1_New(ret->header,M_ASN1_OCTET_STRING_new);
106 ret->meth=NULL;
107 ret->data=NULL;
108 return(ret);
109 M_ASN1_New_Error(ASN1_F_ASN1_HEADER_NEW);
110 }
111
112void ASN1_HEADER_free(ASN1_HEADER *a)
113 {
114 if (a == NULL) return;
115 M_ASN1_OCTET_STRING_free(a->header);
116 if (a->meth != NULL)
117 a->meth->destroy(a->data);
118 OPENSSL_free(a);
119 }
diff --git a/src/lib/libcrypto/asn1/a_i2d_fp.c b/src/lib/libcrypto/asn1/a_i2d_fp.c
index a3ad76d356..f4f1b73ebe 100644
--- a/src/lib/libcrypto/asn1/a_i2d_fp.c
+++ b/src/lib/libcrypto/asn1/a_i2d_fp.c
@@ -64,7 +64,7 @@
64#ifndef NO_OLD_ASN1 64#ifndef NO_OLD_ASN1
65 65
66#ifndef OPENSSL_NO_FP_API 66#ifndef OPENSSL_NO_FP_API
67int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x) 67int ASN1_i2d_fp(int (*i2d)(), FILE *out, unsigned char *x)
68 { 68 {
69 BIO *b; 69 BIO *b;
70 int ret; 70 int ret;
@@ -81,7 +81,7 @@ int ASN1_i2d_fp(i2d_of_void *i2d, FILE *out, void *x)
81 } 81 }
82#endif 82#endif
83 83
84int ASN1_i2d_bio(i2d_of_void *i2d, BIO *out, unsigned char *x) 84int ASN1_i2d_bio(int (*i2d)(), BIO *out, unsigned char *x)
85 { 85 {
86 char *b; 86 char *b;
87 unsigned char *p; 87 unsigned char *p;
@@ -124,7 +124,7 @@ int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x)
124 124
125 if ((b=BIO_new(BIO_s_file())) == NULL) 125 if ((b=BIO_new(BIO_s_file())) == NULL)
126 { 126 {
127 ASN1err(ASN1_F_ASN1_ITEM_I2D_FP,ERR_R_BUF_LIB); 127 ASN1err(ASN1_F_ASN1_I2D_FP,ERR_R_BUF_LIB);
128 return(0); 128 return(0);
129 } 129 }
130 BIO_set_fp(b,out,BIO_NOCLOSE); 130 BIO_set_fp(b,out,BIO_NOCLOSE);
@@ -142,7 +142,7 @@ int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x)
142 n = ASN1_item_i2d(x, &b, it); 142 n = ASN1_item_i2d(x, &b, it);
143 if (b == NULL) 143 if (b == NULL)
144 { 144 {
145 ASN1err(ASN1_F_ASN1_ITEM_I2D_BIO,ERR_R_MALLOC_FAILURE); 145 ASN1err(ASN1_F_ASN1_I2D_BIO,ERR_R_MALLOC_FAILURE);
146 return(0); 146 return(0);
147 } 147 }
148 148
diff --git a/src/lib/libcrypto/asn1/a_int.c b/src/lib/libcrypto/asn1/a_int.c
index f8d198efb1..21cc64bb23 100644
--- a/src/lib/libcrypto/asn1/a_int.c
+++ b/src/lib/libcrypto/asn1/a_int.c
@@ -59,7 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1.h> 61#include <openssl/asn1.h>
62#include <openssl/bn.h>
63 62
64ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x) 63ASN1_INTEGER *ASN1_INTEGER_dup(ASN1_INTEGER *x)
65{ return M_ASN1_INTEGER_dup(x);} 64{ return M_ASN1_INTEGER_dup(x);}
@@ -175,12 +174,11 @@ int i2c_ASN1_INTEGER(ASN1_INTEGER *a, unsigned char **pp)
175 174
176/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */ 175/* Convert just ASN1 INTEGER content octets to ASN1_INTEGER structure */
177 176
178ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp, 177ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, unsigned char **pp,
179 long len) 178 long len)
180 { 179 {
181 ASN1_INTEGER *ret=NULL; 180 ASN1_INTEGER *ret=NULL;
182 const unsigned char *p, *pend; 181 unsigned char *p,*to,*s, *pend;
183 unsigned char *to,*s;
184 int i; 182 int i;
185 183
186 if ((a == NULL) || ((*a) == NULL)) 184 if ((a == NULL) || ((*a) == NULL))
@@ -256,7 +254,7 @@ ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a, const unsigned char **pp,
256 *pp=pend; 254 *pp=pend;
257 return(ret); 255 return(ret);
258err: 256err:
259 ASN1err(ASN1_F_C2I_ASN1_INTEGER,i); 257 ASN1err(ASN1_F_D2I_ASN1_INTEGER,i);
260 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 258 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
261 M_ASN1_INTEGER_free(ret); 259 M_ASN1_INTEGER_free(ret);
262 return(NULL); 260 return(NULL);
@@ -268,12 +266,11 @@ err:
268 * with its MSB set as negative (it doesn't add a padding zero). 266 * with its MSB set as negative (it doesn't add a padding zero).
269 */ 267 */
270 268
271ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, const unsigned char **pp, 269ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a, unsigned char **pp,
272 long length) 270 long length)
273 { 271 {
274 ASN1_INTEGER *ret=NULL; 272 ASN1_INTEGER *ret=NULL;
275 const unsigned char *p; 273 unsigned char *p,*to,*s;
276 unsigned char *to,*s;
277 long len; 274 long len;
278 int inf,tag,xclass; 275 int inf,tag,xclass;
279 int i; 276 int i;
@@ -335,13 +332,12 @@ err:
335 332
336int ASN1_INTEGER_set(ASN1_INTEGER *a, long v) 333int ASN1_INTEGER_set(ASN1_INTEGER *a, long v)
337 { 334 {
338 int j,k; 335 int i,j,k;
339 unsigned int i;
340 unsigned char buf[sizeof(long)+1]; 336 unsigned char buf[sizeof(long)+1];
341 long d; 337 long d;
342 338
343 a->type=V_ASN1_INTEGER; 339 a->type=V_ASN1_INTEGER;
344 if (a->length < (int)(sizeof(long)+1)) 340 if (a->length < (sizeof(long)+1))
345 { 341 {
346 if (a->data != NULL) 342 if (a->data != NULL)
347 OPENSSL_free(a->data); 343 OPENSSL_free(a->data);
@@ -385,7 +381,7 @@ long ASN1_INTEGER_get(ASN1_INTEGER *a)
385 else if (i != V_ASN1_INTEGER) 381 else if (i != V_ASN1_INTEGER)
386 return -1; 382 return -1;
387 383
388 if (a->length > (int)sizeof(long)) 384 if (a->length > sizeof(long))
389 { 385 {
390 /* hmm... a bit ugly */ 386 /* hmm... a bit ugly */
391 return(0xffffffffL); 387 return(0xffffffffL);
@@ -416,8 +412,7 @@ ASN1_INTEGER *BN_to_ASN1_INTEGER(BIGNUM *bn, ASN1_INTEGER *ai)
416 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR); 412 ASN1err(ASN1_F_BN_TO_ASN1_INTEGER,ERR_R_NESTED_ASN1_ERROR);
417 goto err; 413 goto err;
418 } 414 }
419 if (BN_is_negative(bn)) 415 if(bn->neg) ret->type = V_ASN1_NEG_INTEGER;
420 ret->type = V_ASN1_NEG_INTEGER;
421 else ret->type=V_ASN1_INTEGER; 416 else ret->type=V_ASN1_INTEGER;
422 j=BN_num_bits(bn); 417 j=BN_num_bits(bn);
423 len=((j == 0)?0:((j/8)+1)); 418 len=((j == 0)?0:((j/8)+1));
@@ -450,8 +445,7 @@ BIGNUM *ASN1_INTEGER_to_BN(ASN1_INTEGER *ai, BIGNUM *bn)
450 445
451 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL) 446 if ((ret=BN_bin2bn(ai->data,ai->length,bn)) == NULL)
452 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB); 447 ASN1err(ASN1_F_ASN1_INTEGER_TO_BN,ASN1_R_BN_LIB);
453 else if(ai->type == V_ASN1_NEG_INTEGER) 448 else if(ai->type == V_ASN1_NEG_INTEGER) ret->neg = 1;
454 BN_set_negative(ret, 1);
455 return(ret); 449 return(ret);
456 } 450 }
457 451
diff --git a/src/lib/libcrypto/asn1/a_mbstr.c b/src/lib/libcrypto/asn1/a_mbstr.c
index 2d4800a22a..208b3ec395 100644
--- a/src/lib/libcrypto/asn1/a_mbstr.c
+++ b/src/lib/libcrypto/asn1/a_mbstr.c
@@ -107,7 +107,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
107 107
108 case MBSTRING_BMP: 108 case MBSTRING_BMP:
109 if(len & 1) { 109 if(len & 1) {
110 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 110 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
111 ASN1_R_INVALID_BMPSTRING_LENGTH); 111 ASN1_R_INVALID_BMPSTRING_LENGTH);
112 return -1; 112 return -1;
113 } 113 }
@@ -116,7 +116,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
116 116
117 case MBSTRING_UNIV: 117 case MBSTRING_UNIV:
118 if(len & 3) { 118 if(len & 3) {
119 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 119 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH); 120 ASN1_R_INVALID_UNIVERSALSTRING_LENGTH);
121 return -1; 121 return -1;
122 } 122 }
@@ -128,7 +128,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
128 /* This counts the characters and does utf8 syntax checking */ 128 /* This counts the characters and does utf8 syntax checking */
129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar); 129 ret = traverse_string(in, len, MBSTRING_UTF8, in_utf8, &nchar);
130 if(ret < 0) { 130 if(ret < 0) {
131 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 131 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
132 ASN1_R_INVALID_UTF8STRING); 132 ASN1_R_INVALID_UTF8STRING);
133 return -1; 133 return -1;
134 } 134 }
@@ -139,19 +139,19 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
139 break; 139 break;
140 140
141 default: 141 default:
142 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_UNKNOWN_FORMAT); 142 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_UNKNOWN_FORMAT);
143 return -1; 143 return -1;
144 } 144 }
145 145
146 if((minsize > 0) && (nchar < minsize)) { 146 if((minsize > 0) && (nchar < minsize)) {
147 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_SHORT); 147 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_SHORT);
148 BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize); 148 BIO_snprintf(strbuf, sizeof strbuf, "%ld", minsize);
149 ERR_add_error_data(2, "minsize=", strbuf); 149 ERR_add_error_data(2, "minsize=", strbuf);
150 return -1; 150 return -1;
151 } 151 }
152 152
153 if((maxsize > 0) && (nchar > maxsize)) { 153 if((maxsize > 0) && (nchar > maxsize)) {
154 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_STRING_TOO_LONG); 154 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_STRING_TOO_LONG);
155 BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize); 155 BIO_snprintf(strbuf, sizeof strbuf, "%ld", maxsize);
156 ERR_add_error_data(2, "maxsize=", strbuf); 156 ERR_add_error_data(2, "maxsize=", strbuf);
157 return -1; 157 return -1;
@@ -159,7 +159,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
159 159
160 /* Now work out minimal type (if any) */ 160 /* Now work out minimal type (if any) */
161 if(traverse_string(in, len, inform, type_str, &mask) < 0) { 161 if(traverse_string(in, len, inform, type_str, &mask) < 0) {
162 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, ASN1_R_ILLEGAL_CHARACTERS); 162 ASN1err(ASN1_F_ASN1_MBSTRING_COPY, ASN1_R_ILLEGAL_CHARACTERS);
163 return -1; 163 return -1;
164 } 164 }
165 165
@@ -193,7 +193,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
193 free_out = 1; 193 free_out = 1;
194 dest = ASN1_STRING_type_new(str_type); 194 dest = ASN1_STRING_type_new(str_type);
195 if(!dest) { 195 if(!dest) {
196 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY, 196 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,
197 ERR_R_MALLOC_FAILURE); 197 ERR_R_MALLOC_FAILURE);
198 return -1; 198 return -1;
199 } 199 }
@@ -202,7 +202,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
202 /* If both the same type just copy across */ 202 /* If both the same type just copy across */
203 if(inform == outform) { 203 if(inform == outform) {
204 if(!ASN1_STRING_set(dest, in, len)) { 204 if(!ASN1_STRING_set(dest, in, len)) {
205 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 205 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
206 return -1; 206 return -1;
207 } 207 }
208 return str_type; 208 return str_type;
@@ -233,7 +233,7 @@ int ASN1_mbstring_ncopy(ASN1_STRING **out, const unsigned char *in, int len,
233 } 233 }
234 if(!(p = OPENSSL_malloc(outlen + 1))) { 234 if(!(p = OPENSSL_malloc(outlen + 1))) {
235 if(free_out) ASN1_STRING_free(dest); 235 if(free_out) ASN1_STRING_free(dest);
236 ASN1err(ASN1_F_ASN1_MBSTRING_NCOPY,ERR_R_MALLOC_FAILURE); 236 ASN1err(ASN1_F_ASN1_MBSTRING_COPY,ERR_R_MALLOC_FAILURE);
237 return -1; 237 return -1;
238 } 238 }
239 dest->length = outlen; 239 dest->length = outlen;
diff --git a/src/lib/libcrypto/asn1/a_meth.c b/src/lib/libcrypto/asn1/a_meth.c
new file mode 100644
index 0000000000..63158e9cab
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_meth.c
@@ -0,0 +1,84 @@
1/* crypto/asn1/a_meth.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/buffer.h>
62#include <openssl/asn1.h>
63
64static ASN1_METHOD ia5string_meth={
65 (int (*)()) i2d_ASN1_IA5STRING,
66 (char *(*)()) d2i_ASN1_IA5STRING,
67 (char *(*)()) ASN1_STRING_new,
68 (void (*)()) ASN1_STRING_free};
69
70static ASN1_METHOD bit_string_meth={
71 (int (*)()) i2d_ASN1_BIT_STRING,
72 (char *(*)()) d2i_ASN1_BIT_STRING,
73 (char *(*)()) ASN1_STRING_new,
74 (void (*)()) ASN1_STRING_free};
75
76ASN1_METHOD *ASN1_IA5STRING_asn1_meth(void)
77 {
78 return(&ia5string_meth);
79 }
80
81ASN1_METHOD *ASN1_BIT_STRING_asn1_meth(void)
82 {
83 return(&bit_string_meth);
84 }
diff --git a/src/lib/libcrypto/asn1/a_object.c b/src/lib/libcrypto/asn1/a_object.c
index dc980421d0..0a8e6c287c 100644
--- a/src/lib/libcrypto/asn1/a_object.c
+++ b/src/lib/libcrypto/asn1/a_object.c
@@ -57,12 +57,10 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <limits.h>
61#include "cryptlib.h" 60#include "cryptlib.h"
62#include <openssl/buffer.h> 61#include <openssl/buffer.h>
63#include <openssl/asn1.h> 62#include <openssl/asn1.h>
64#include <openssl/objects.h> 63#include <openssl/objects.h>
65#include <openssl/bn.h>
66 64
67int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp) 65int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
68 { 66 {
@@ -85,12 +83,10 @@ int i2d_ASN1_OBJECT(ASN1_OBJECT *a, unsigned char **pp)
85 83
86int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num) 84int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
87 { 85 {
88 int i,first,len=0,c, use_bn; 86 int i,first,len=0,c;
89 char ftmp[24], *tmp = ftmp; 87 char tmp[24];
90 int tmpsize = sizeof ftmp;
91 const char *p; 88 const char *p;
92 unsigned long l; 89 unsigned long l;
93 BIGNUM *bl = NULL;
94 90
95 if (num == 0) 91 if (num == 0)
96 return(0); 92 return(0);
@@ -102,7 +98,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
102 num--; 98 num--;
103 if ((c >= '0') && (c <= '2')) 99 if ((c >= '0') && (c <= '2'))
104 { 100 {
105 first= c-'0'; 101 first=(c-'0')*40;
106 } 102 }
107 else 103 else
108 { 104 {
@@ -126,7 +122,6 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
126 goto err; 122 goto err;
127 } 123 }
128 l=0; 124 l=0;
129 use_bn = 0;
130 for (;;) 125 for (;;)
131 { 126 {
132 if (num <= 0) break; 127 if (num <= 0) break;
@@ -139,22 +134,7 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
139 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT); 134 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_INVALID_DIGIT);
140 goto err; 135 goto err;
141 } 136 }
142 if (!use_bn && l > (ULONG_MAX / 10L)) 137 l=l*10L+(long)(c-'0');
143 {
144 use_bn = 1;
145 if (!bl)
146 bl = BN_new();
147 if (!bl || !BN_set_word(bl, l))
148 goto err;
149 }
150 if (use_bn)
151 {
152 if (!BN_mul_word(bl, 10L)
153 || !BN_add_word(bl, c-'0'))
154 goto err;
155 }
156 else
157 l=l*10L+(long)(c-'0');
158 } 138 }
159 if (len == 0) 139 if (len == 0)
160 { 140 {
@@ -163,42 +143,14 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
163 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE); 143 ASN1err(ASN1_F_A2D_ASN1_OBJECT,ASN1_R_SECOND_NUMBER_TOO_LARGE);
164 goto err; 144 goto err;
165 } 145 }
166 if (use_bn) 146 l+=(long)first;
167 {
168 if (!BN_add_word(bl, first * 40))
169 goto err;
170 }
171 else
172 l+=(long)first*40;
173 } 147 }
174 i=0; 148 i=0;
175 if (use_bn) 149 for (;;)
176 {
177 int blsize;
178 blsize = BN_num_bits(bl);
179 blsize = (blsize + 6)/7;
180 if (blsize > tmpsize)
181 {
182 if (tmp != ftmp)
183 OPENSSL_free(tmp);
184 tmpsize = blsize + 32;
185 tmp = OPENSSL_malloc(tmpsize);
186 if (!tmp)
187 goto err;
188 }
189 while(blsize--)
190 tmp[i++] = (unsigned char)BN_div_word(bl, 0x80L);
191 }
192 else
193 { 150 {
194 151 tmp[i++]=(unsigned char)l&0x7f;
195 for (;;) 152 l>>=7L;
196 { 153 if (l == 0L) break;
197 tmp[i++]=(unsigned char)l&0x7f;
198 l>>=7L;
199 if (l == 0L) break;
200 }
201
202 } 154 }
203 if (out != NULL) 155 if (out != NULL)
204 { 156 {
@@ -214,16 +166,8 @@ int a2d_ASN1_OBJECT(unsigned char *out, int olen, const char *buf, int num)
214 else 166 else
215 len+=i; 167 len+=i;
216 } 168 }
217 if (tmp != ftmp)
218 OPENSSL_free(tmp);
219 if (bl)
220 BN_free(bl);
221 return(len); 169 return(len);
222err: 170err:
223 if (tmp != ftmp)
224 OPENSSL_free(tmp);
225 if (bl)
226 BN_free(bl);
227 return(0); 171 return(0);
228 } 172 }
229 173
@@ -234,31 +178,21 @@ int i2t_ASN1_OBJECT(char *buf, int buf_len, ASN1_OBJECT *a)
234 178
235int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a) 179int i2a_ASN1_OBJECT(BIO *bp, ASN1_OBJECT *a)
236 { 180 {
237 char buf[80], *p = buf; 181 char buf[80];
238 int i; 182 int i;
239 183
240 if ((a == NULL) || (a->data == NULL)) 184 if ((a == NULL) || (a->data == NULL))
241 return(BIO_write(bp,"NULL",4)); 185 return(BIO_write(bp,"NULL",4));
242 i=i2t_ASN1_OBJECT(buf,sizeof buf,a); 186 i=i2t_ASN1_OBJECT(buf,sizeof buf,a);
243 if (i > (int)(sizeof(buf) - 1)) 187 if (i > sizeof buf) i=sizeof buf;
244 { 188 BIO_write(bp,buf,i);
245 p = OPENSSL_malloc(i + 1);
246 if (!p)
247 return -1;
248 i2t_ASN1_OBJECT(p,i + 1,a);
249 }
250 if (i <= 0)
251 return BIO_write(bp, "<INVALID>", 9);
252 BIO_write(bp,p,i);
253 if (p != buf)
254 OPENSSL_free(p);
255 return(i); 189 return(i);
256 } 190 }
257 191
258ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 192ASN1_OBJECT *d2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
259 long length) 193 long length)
260{ 194{
261 const unsigned char *p; 195 unsigned char *p;
262 long len; 196 long len;
263 int tag,xclass; 197 int tag,xclass;
264 int inf,i; 198 int inf,i;
@@ -285,11 +219,11 @@ err:
285 ASN1_OBJECT_free(ret); 219 ASN1_OBJECT_free(ret);
286 return(NULL); 220 return(NULL);
287} 221}
288ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp, 222ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, unsigned char **pp,
289 long len) 223 long len)
290 { 224 {
291 ASN1_OBJECT *ret=NULL; 225 ASN1_OBJECT *ret=NULL;
292 const unsigned char *p; 226 unsigned char *p;
293 int i; 227 int i;
294 228
295 /* only the ASN1_OBJECTs from the 'table' will have values 229 /* only the ASN1_OBJECTs from the 'table' will have values
@@ -321,7 +255,7 @@ ASN1_OBJECT *c2i_ASN1_OBJECT(ASN1_OBJECT **a, const unsigned char **pp,
321 *pp=p; 255 *pp=p;
322 return(ret); 256 return(ret);
323err: 257err:
324 ASN1err(ASN1_F_C2I_ASN1_OBJECT,i); 258 ASN1err(ASN1_F_D2I_ASN1_OBJECT,i);
325 if ((ret != NULL) && ((a == NULL) || (*a != ret))) 259 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
326 ASN1_OBJECT_free(ret); 260 ASN1_OBJECT_free(ret);
327 return(NULL); 261 return(NULL);
diff --git a/src/lib/libcrypto/asn1/a_octet.c b/src/lib/libcrypto/asn1/a_octet.c
index 24fd0f8e5a..9690bae0f1 100644
--- a/src/lib/libcrypto/asn1/a_octet.c
+++ b/src/lib/libcrypto/asn1/a_octet.c
@@ -66,6 +66,6 @@ ASN1_OCTET_STRING *ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *x)
66int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b) 66int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b)
67{ return M_ASN1_OCTET_STRING_cmp(a, b); } 67{ return M_ASN1_OCTET_STRING_cmp(a, b); }
68 68
69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, const unsigned char *d, int len) 69int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *x, unsigned char *d, int len)
70{ return M_ASN1_OCTET_STRING_set(x, d, len); } 70{ return M_ASN1_OCTET_STRING_set(x, d, len); }
71 71
diff --git a/src/lib/libcrypto/asn1/a_set.c b/src/lib/libcrypto/asn1/a_set.c
index 958558c204..e24061c545 100644
--- a/src/lib/libcrypto/asn1/a_set.c
+++ b/src/lib/libcrypto/asn1/a_set.c
@@ -85,8 +85,8 @@ static int SetBlobCmp(const void *elem1, const void *elem2 )
85 } 85 }
86 86
87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */ 87/* int is_set: if TRUE, then sort the contents (i.e. it isn't a SEQUENCE) */
88int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag, 88int i2d_ASN1_SET(STACK *a, unsigned char **pp, int (*func)(), int ex_tag,
89 int ex_class, int is_set) 89 int ex_class, int is_set)
90 { 90 {
91 int ret=0,r; 91 int ret=0,r;
92 int i; 92 int i;
@@ -97,7 +97,7 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
97 97
98 if (a == NULL) return(0); 98 if (a == NULL) return(0);
99 for (i=sk_num(a)-1; i>=0; i--) 99 for (i=sk_num(a)-1; i>=0; i--)
100 ret+=i2d(sk_value(a,i),NULL); 100 ret+=func(sk_value(a,i),NULL);
101 r=ASN1_object_size(1,ret,ex_tag); 101 r=ASN1_object_size(1,ret,ex_tag);
102 if (pp == NULL) return(r); 102 if (pp == NULL) return(r);
103 103
@@ -111,7 +111,7 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
111 if(!is_set || (sk_num(a) < 2)) 111 if(!is_set || (sk_num(a) < 2))
112 { 112 {
113 for (i=0; i<sk_num(a); i++) 113 for (i=0; i<sk_num(a); i++)
114 i2d(sk_value(a,i),&p); 114 func(sk_value(a,i),&p);
115 115
116 *pp=p; 116 *pp=p;
117 return(r); 117 return(r);
@@ -129,7 +129,7 @@ int i2d_ASN1_SET(STACK *a, unsigned char **pp, i2d_of_void *i2d, int ex_tag,
129 for (i=0; i<sk_num(a); i++) 129 for (i=0; i<sk_num(a); i++)
130 { 130 {
131 rgSetBlob[i].pbData = p; /* catch each set encode blob */ 131 rgSetBlob[i].pbData = p; /* catch each set encode blob */
132 i2d(sk_value(a,i),&p); 132 func(sk_value(a,i),&p);
133 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this 133 rgSetBlob[i].cbData = p - rgSetBlob[i].pbData; /* Length of this
134SetBlob 134SetBlob
135*/ 135*/
@@ -162,11 +162,10 @@ SetBlob
162 return(r); 162 return(r);
163 } 163 }
164 164
165STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, 165STACK *d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
166 d2i_of_void *d2i, void (*free_func)(void *), int ex_tag, 166 char *(*func)(), void (*free_func)(void *), int ex_tag, int ex_class)
167 int ex_class)
168 { 167 {
169 ASN1_const_CTX c; 168 ASN1_CTX c;
170 STACK *ret=NULL; 169 STACK *ret=NULL;
171 170
172 if ((a == NULL) || ((*a) == NULL)) 171 if ((a == NULL) || ((*a) == NULL))
@@ -211,9 +210,7 @@ STACK *d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length,
211 char *s; 210 char *s;
212 211
213 if (M_ASN1_D2I_end_sequence()) break; 212 if (M_ASN1_D2I_end_sequence()) break;
214 /* XXX: This was called with 4 arguments, incorrectly, it seems 213 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL)
215 if ((s=func(NULL,&c.p,c.slen,c.max-c.p)) == NULL) */
216 if ((s=d2i(NULL,&c.p,c.slen)) == NULL)
217 { 214 {
218 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT); 215 ASN1err(ASN1_F_D2I_ASN1_SET,ASN1_R_ERROR_PARSING_SET_ELEMENT);
219 asn1_add_error(*pp,(int)(c.q- *pp)); 216 asn1_add_error(*pp,(int)(c.q- *pp));
diff --git a/src/lib/libcrypto/asn1/a_sign.c b/src/lib/libcrypto/asn1/a_sign.c
index 1081950518..52ce7e3974 100644
--- a/src/lib/libcrypto/asn1/a_sign.c
+++ b/src/lib/libcrypto/asn1/a_sign.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ==================================================================== 58/* ====================================================================
59 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 * 60 *
61 * Redistribution and use in source and binary forms, with or without 61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions 62 * modification, are permitted provided that the following conditions
@@ -126,9 +126,9 @@
126 126
127#ifndef NO_ASN1_OLD 127#ifndef NO_ASN1_OLD
128 128
129int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, X509_ALGOR *algor2, 129int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
130 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey, 130 ASN1_BIT_STRING *signature, char *data, EVP_PKEY *pkey,
131 const EVP_MD *type) 131 const EVP_MD *type)
132 { 132 {
133 EVP_MD_CTX ctx; 133 EVP_MD_CTX ctx;
134 unsigned char *p,*buf_in=NULL,*buf_out=NULL; 134 unsigned char *p,*buf_in=NULL,*buf_out=NULL;
@@ -229,11 +229,10 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
229 else 229 else
230 a=algor2; 230 a=algor2;
231 if (a == NULL) continue; 231 if (a == NULL) continue;
232 if (type->pkey_type == NID_dsaWithSHA1 || 232 if (type->pkey_type == NID_dsaWithSHA1)
233 type->pkey_type == NID_ecdsa_with_SHA1)
234 { 233 {
235 /* special case: RFC 3279 tells us to omit 'parameters' 234 /* special case: RFC 2459 tells us to omit 'parameters'
236 * with id-dsa-with-sha1 and ecdsa-with-SHA1 */ 235 * with id-dsa-with-sha1 */
237 ASN1_TYPE_free(a->parameter); 236 ASN1_TYPE_free(a->parameter);
238 a->parameter = NULL; 237 a->parameter = NULL;
239 } 238 }
@@ -248,12 +247,12 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
248 a->algorithm=OBJ_nid2obj(type->pkey_type); 247 a->algorithm=OBJ_nid2obj(type->pkey_type);
249 if (a->algorithm == NULL) 248 if (a->algorithm == NULL)
250 { 249 {
251 ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE); 250 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_UNKNOWN_OBJECT_TYPE);
252 goto err; 251 goto err;
253 } 252 }
254 if (a->algorithm->length == 0) 253 if (a->algorithm->length == 0)
255 { 254 {
256 ASN1err(ASN1_F_ASN1_ITEM_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD); 255 ASN1err(ASN1_F_ASN1_SIGN,ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD);
257 goto err; 256 goto err;
258 } 257 }
259 } 258 }
@@ -263,7 +262,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
263 if ((buf_in == NULL) || (buf_out == NULL)) 262 if ((buf_in == NULL) || (buf_out == NULL))
264 { 263 {
265 outl=0; 264 outl=0;
266 ASN1err(ASN1_F_ASN1_ITEM_SIGN,ERR_R_MALLOC_FAILURE); 265 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_MALLOC_FAILURE);
267 goto err; 266 goto err;
268 } 267 }
269 268
@@ -273,7 +272,7 @@ int ASN1_item_sign(const ASN1_ITEM *it, X509_ALGOR *algor1, X509_ALGOR *algor2,
273 (unsigned int *)&outl,pkey)) 272 (unsigned int *)&outl,pkey))
274 { 273 {
275 outl=0; 274 outl=0;
276 ASN1err(ASN1_F_ASN1_ITEM_SIGN,ERR_R_EVP_LIB); 275 ASN1err(ASN1_F_ASN1_SIGN,ERR_R_EVP_LIB);
277 goto err; 276 goto err;
278 } 277 }
279 if (signature->data != NULL) OPENSSL_free(signature->data); 278 if (signature->data != NULL) OPENSSL_free(signature->data);
diff --git a/src/lib/libcrypto/asn1/a_strex.c b/src/lib/libcrypto/asn1/a_strex.c
index c2dbb6f9a5..a07122ba47 100644
--- a/src/lib/libcrypto/asn1/a_strex.c
+++ b/src/lib/libcrypto/asn1/a_strex.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -58,12 +58,12 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/crypto.h> 61#include <openssl/crypto.h>
63#include <openssl/x509.h> 62#include <openssl/x509.h>
64#include <openssl/asn1.h> 63#include <openssl/asn1.h>
65 64
66#include "charmap.h" 65#include "charmap.h"
66#include "cryptlib.h"
67 67
68/* ASN1_STRING_print_ex() and X509_NAME_print_ex(). 68/* ASN1_STRING_print_ex() and X509_NAME_print_ex().
69 * Enhanced string and name printing routines handling 69 * Enhanced string and name printing routines handling
@@ -170,7 +170,7 @@ static int do_buf(unsigned char *buf, int buflen,
170 q = buf + buflen; 170 q = buf + buflen;
171 outlen = 0; 171 outlen = 0;
172 while(p != q) { 172 while(p != q) {
173 if(p == buf && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_FIRST_ESC_2253; 173 if(p == buf) orflags = CHARTYPE_FIRST_ESC_2253;
174 else orflags = 0; 174 else orflags = 0;
175 switch(type & BUF_TYPE_WIDTH_MASK) { 175 switch(type & BUF_TYPE_WIDTH_MASK) {
176 case 4: 176 case 4:
@@ -194,10 +194,8 @@ static int do_buf(unsigned char *buf, int buflen,
194 if(i < 0) return -1; /* Invalid UTF8String */ 194 if(i < 0) return -1; /* Invalid UTF8String */
195 p += i; 195 p += i;
196 break; 196 break;
197 default:
198 return -1; /* invalid width */
199 } 197 }
200 if (p == q && flags & ASN1_STRFLGS_ESC_2253) orflags = CHARTYPE_LAST_ESC_2253; 198 if (p == q) orflags = CHARTYPE_LAST_ESC_2253;
201 if(type & BUF_TYPE_CONVUTF8) { 199 if(type & BUF_TYPE_CONVUTF8) {
202 unsigned char utfbuf[6]; 200 unsigned char utfbuf[6];
203 int utflen; 201 int utflen;
@@ -225,7 +223,7 @@ static int do_buf(unsigned char *buf, int buflen,
225 223
226static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen) 224static int do_hex_dump(char_io *io_ch, void *arg, unsigned char *buf, int buflen)
227{ 225{
228 static const char hexdig[] = "0123456789ABCDEF"; 226 const static char hexdig[] = "0123456789ABCDEF";
229 unsigned char *p, *q; 227 unsigned char *p, *q;
230 char hextmp[2]; 228 char hextmp[2];
231 if(arg) { 229 if(arg) {
@@ -281,7 +279,7 @@ static int do_dump(unsigned long lflags, char_io *io_ch, void *arg, ASN1_STRING
281 * otherwise it is the number of bytes per character 279 * otherwise it is the number of bytes per character
282 */ 280 */
283 281
284static const signed char tag2nbyte[] = { 282const static signed char tag2nbyte[] = {
285 -1, -1, -1, -1, -1, /* 0-4 */ 283 -1, -1, -1, -1, -1, /* 0-4 */
286 -1, -1, -1, -1, -1, /* 5-9 */ 284 -1, -1, -1, -1, -1, /* 5-9 */
287 -1, -1, 0, -1, /* 10-13 */ 285 -1, -1, 0, -1, /* 10-13 */
@@ -358,13 +356,12 @@ static int do_print_ex(char_io *io_ch, void *arg, unsigned long lflags, ASN1_STR
358 } 356 }
359 357
360 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL); 358 len = do_buf(str->data, str->length, type, flags, &quotes, io_ch, NULL);
361 if(len < 0) return -1; 359 if(outlen < 0) return -1;
362 outlen += len; 360 outlen += len;
363 if(quotes) outlen += 2; 361 if(quotes) outlen += 2;
364 if(!arg) return outlen; 362 if(!arg) return outlen;
365 if(quotes && !io_ch(arg, "\"", 1)) return -1; 363 if(quotes && !io_ch(arg, "\"", 1)) return -1;
366 if(do_buf(str->data, str->length, type, flags, NULL, io_ch, arg) < 0) 364 do_buf(str->data, str->length, type, flags, NULL, io_ch, arg);
367 return -1;
368 if(quotes && !io_ch(arg, "\"", 1)) return -1; 365 if(quotes && !io_ch(arg, "\"", 1)) return -1;
369 return outlen; 366 return outlen;
370} 367}
@@ -516,7 +513,7 @@ int X509_NAME_print_ex(BIO *out, X509_NAME *nm, int indent, unsigned long flags)
516 return do_name_ex(send_bio_chars, out, nm, indent, flags); 513 return do_name_ex(send_bio_chars, out, nm, indent, flags);
517} 514}
518 515
519#ifndef OPENSSL_NO_FP_API 516
520int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags) 517int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long flags)
521{ 518{
522 if(flags == XN_FLAG_COMPAT) 519 if(flags == XN_FLAG_COMPAT)
@@ -531,19 +528,17 @@ int X509_NAME_print_ex_fp(FILE *fp, X509_NAME *nm, int indent, unsigned long fla
531 } 528 }
532 return do_name_ex(send_fp_chars, fp, nm, indent, flags); 529 return do_name_ex(send_fp_chars, fp, nm, indent, flags);
533} 530}
534#endif
535 531
536int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags) 532int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags)
537{ 533{
538 return do_print_ex(send_bio_chars, out, flags, str); 534 return do_print_ex(send_bio_chars, out, flags, str);
539} 535}
540 536
541#ifndef OPENSSL_NO_FP_API 537
542int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags) 538int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags)
543{ 539{
544 return do_print_ex(send_fp_chars, fp, flags, str); 540 return do_print_ex(send_fp_chars, fp, flags, str);
545} 541}
546#endif
547 542
548/* Utility function: convert any string type to UTF8, returns number of bytes 543/* Utility function: convert any string type to UTF8, returns number of bytes
549 * in output string or a negative error code 544 * in output string or a negative error code
@@ -558,7 +553,12 @@ int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in)
558 if((type < 0) || (type > 30)) return -1; 553 if((type < 0) || (type > 30)) return -1;
559 mbflag = tag2nbyte[type]; 554 mbflag = tag2nbyte[type];
560 if(mbflag == -1) return -1; 555 if(mbflag == -1) return -1;
561 mbflag |= MBSTRING_FLAG; 556 if (mbflag == 0)
557 mbflag = MBSTRING_UTF8;
558 else if (mbflag == 4)
559 mbflag = MBSTRING_UNIV;
560 else
561 mbflag |= MBSTRING_FLAG;
562 stmp.data = NULL; 562 stmp.data = NULL;
563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING); 563 ret = ASN1_mbstring_copy(&str, in->data, in->length, mbflag, B_ASN1_UTF8STRING);
564 if(ret < 0) return ret; 564 if(ret < 0) return ret;
diff --git a/src/lib/libcrypto/asn1/a_type.c b/src/lib/libcrypto/asn1/a_type.c
index 36beceacdb..2292d49b93 100644
--- a/src/lib/libcrypto/asn1/a_type.c
+++ b/src/lib/libcrypto/asn1/a_type.c
@@ -57,9 +57,8 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1t.h> 60#include <openssl/asn1t.h>
62#include <openssl/objects.h> 61#include "cryptlib.h"
63 62
64int ASN1_TYPE_get(ASN1_TYPE *a) 63int ASN1_TYPE_get(ASN1_TYPE *a)
65 { 64 {
@@ -80,31 +79,6 @@ void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value)
80 a->value.ptr=value; 79 a->value.ptr=value;
81 } 80 }
82 81
83int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value)
84 {
85 if (!value || (type == V_ASN1_BOOLEAN))
86 {
87 void *p = (void *)value;
88 ASN1_TYPE_set(a, type, p);
89 }
90 else if (type == V_ASN1_OBJECT)
91 {
92 ASN1_OBJECT *odup;
93 odup = OBJ_dup(value);
94 if (!odup)
95 return 0;
96 ASN1_TYPE_set(a, type, odup);
97 }
98 else
99 {
100 ASN1_STRING *sdup;
101 sdup = ASN1_STRING_dup((ASN1_STRING *)value);
102 if (!sdup)
103 return 0;
104 ASN1_TYPE_set(a, type, sdup);
105 }
106 return 1;
107 }
108 82
109IMPLEMENT_STACK_OF(ASN1_TYPE) 83IMPLEMENT_STACK_OF(ASN1_TYPE)
110IMPLEMENT_ASN1_SET_OF(ASN1_TYPE) 84IMPLEMENT_ASN1_SET_OF(ASN1_TYPE)
diff --git a/src/lib/libcrypto/asn1/a_utctm.c b/src/lib/libcrypto/asn1/a_utctm.c
new file mode 100644
index 0000000000..7b25fed331
--- /dev/null
+++ b/src/lib/libcrypto/asn1/a_utctm.c
@@ -0,0 +1,303 @@
1/* crypto/asn1/a_utctm.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <time.h>
61#include "cryptlib.h"
62#include "o_time.h"
63#include <openssl/asn1.h>
64
65#if 0
66int i2d_ASN1_UTCTIME(ASN1_UTCTIME *a, unsigned char **pp)
67 {
68#ifndef CHARSET_EBCDIC
69 return(i2d_ASN1_bytes((ASN1_STRING *)a,pp,
70 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL));
71#else
72 /* KLUDGE! We convert to ascii before writing DER */
73 int len;
74 char tmp[24];
75 ASN1_STRING x = *(ASN1_STRING *)a;
76
77 len = x.length;
78 ebcdic2ascii(tmp, x.data, (len >= sizeof tmp) ? sizeof tmp : len);
79 x.data = tmp;
80 return i2d_ASN1_bytes(&x, pp, V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
81#endif
82 }
83
84
85ASN1_UTCTIME *d2i_ASN1_UTCTIME(ASN1_UTCTIME **a, unsigned char **pp,
86 long length)
87 {
88 ASN1_UTCTIME *ret=NULL;
89
90 ret=(ASN1_UTCTIME *)d2i_ASN1_bytes((ASN1_STRING **)a,pp,length,
91 V_ASN1_UTCTIME,V_ASN1_UNIVERSAL);
92 if (ret == NULL)
93 {
94 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,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_UTCTIME_check(ret))
101 {
102 ASN1err(ASN1_F_D2I_ASN1_UTCTIME,ASN1_R_INVALID_TIME_FORMAT);
103 goto err;
104 }
105
106 return(ret);
107err:
108 if ((ret != NULL) && ((a == NULL) || (*a != ret)))
109 M_ASN1_UTCTIME_free(ret);
110 return(NULL);
111 }
112
113#endif
114
115int ASN1_UTCTIME_check(ASN1_UTCTIME *d)
116 {
117 static int min[8]={ 0, 1, 1, 0, 0, 0, 0, 0};
118 static int max[8]={99,12,31,23,59,59,12,59};
119 char *a;
120 int n,i,l,o;
121
122 if (d->type != V_ASN1_UTCTIME) return(0);
123 l=d->length;
124 a=(char *)d->data;
125 o=0;
126
127 if (l < 11) goto err;
128 for (i=0; i<6; i++)
129 {
130 if ((i == 5) && ((a[o] == 'Z') ||
131 (a[o] == '+') || (a[o] == '-')))
132 { i++; break; }
133 if ((a[o] < '0') || (a[o] > '9')) goto err;
134 n= a[o]-'0';
135 if (++o > l) goto err;
136
137 if ((a[o] < '0') || (a[o] > '9')) goto err;
138 n=(n*10)+ a[o]-'0';
139 if (++o > l) goto err;
140
141 if ((n < min[i]) || (n > max[i])) goto err;
142 }
143 if (a[o] == 'Z')
144 o++;
145 else if ((a[o] == '+') || (a[o] == '-'))
146 {
147 o++;
148 if (o+4 > l) goto err;
149 for (i=6; i<8; i++)
150 {
151 if ((a[o] < '0') || (a[o] > '9')) goto err;
152 n= a[o]-'0';
153 o++;
154 if ((a[o] < '0') || (a[o] > '9')) goto err;
155 n=(n*10)+ a[o]-'0';
156 if ((n < min[i]) || (n > max[i])) goto err;
157 o++;
158 }
159 }
160 return(o == l);
161err:
162 return(0);
163 }
164
165int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str)
166 {
167 ASN1_UTCTIME t;
168
169 t.type=V_ASN1_UTCTIME;
170 t.length=strlen(str);
171 t.data=(unsigned char *)str;
172 if (ASN1_UTCTIME_check(&t))
173 {
174 if (s != NULL)
175 {
176 if (!ASN1_STRING_set((ASN1_STRING *)s,
177 (unsigned char *)str,t.length))
178 return 0;
179 s->type = V_ASN1_UTCTIME;
180 }
181 return(1);
182 }
183 else
184 return(0);
185 }
186
187ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s, time_t t)
188 {
189 char *p;
190 struct tm *ts;
191 struct tm data;
192 size_t len = 20;
193
194 if (s == NULL)
195 s=M_ASN1_UTCTIME_new();
196 if (s == NULL)
197 return(NULL);
198
199 ts=OPENSSL_gmtime(&t, &data);
200 if (ts == NULL)
201 return(NULL);
202
203 p=(char *)s->data;
204 if ((p == NULL) || ((size_t)s->length < len))
205 {
206 p=OPENSSL_malloc(len);
207 if (p == NULL)
208 {
209 ASN1err(ASN1_F_ASN1_UTCTIME_SET,ERR_R_MALLOC_FAILURE);
210 return(NULL);
211 }
212 if (s->data != NULL)
213 OPENSSL_free(s->data);
214 s->data=(unsigned char *)p;
215 }
216
217 BIO_snprintf(p,len,"%02d%02d%02d%02d%02d%02dZ",ts->tm_year%100,
218 ts->tm_mon+1,ts->tm_mday,ts->tm_hour,ts->tm_min,ts->tm_sec);
219 s->length=strlen(p);
220 s->type=V_ASN1_UTCTIME;
221#ifdef CHARSET_EBCDIC_not
222 ebcdic2ascii(s->data, s->data, s->length);
223#endif
224 return(s);
225 }
226
227
228int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t)
229 {
230 struct tm *tm;
231 struct tm data;
232 int offset;
233 int year;
234
235#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
236
237 if (s->data[12] == 'Z')
238 offset=0;
239 else
240 {
241 offset = g2(s->data+13)*60+g2(s->data+15);
242 if (s->data[12] == '-')
243 offset = -offset;
244 }
245
246 t -= offset*60; /* FIXME: may overflow in extreme cases */
247
248 tm = OPENSSL_gmtime(&t, &data);
249
250#define return_cmp(a,b) if ((a)<(b)) return -1; else if ((a)>(b)) return 1
251 year = g2(s->data);
252 if (year < 50)
253 year += 100;
254 return_cmp(year, tm->tm_year);
255 return_cmp(g2(s->data+2) - 1, tm->tm_mon);
256 return_cmp(g2(s->data+4), tm->tm_mday);
257 return_cmp(g2(s->data+6), tm->tm_hour);
258 return_cmp(g2(s->data+8), tm->tm_min);
259 return_cmp(g2(s->data+10), tm->tm_sec);
260#undef g2
261#undef return_cmp
262
263 return 0;
264 }
265
266
267#if 0
268time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s)
269 {
270 struct tm tm;
271 int offset;
272
273 memset(&tm,'\0',sizeof tm);
274
275#define g2(p) (((p)[0]-'0')*10+(p)[1]-'0')
276 tm.tm_year=g2(s->data);
277 if(tm.tm_year < 50)
278 tm.tm_year+=100;
279 tm.tm_mon=g2(s->data+2)-1;
280 tm.tm_mday=g2(s->data+4);
281 tm.tm_hour=g2(s->data+6);
282 tm.tm_min=g2(s->data+8);
283 tm.tm_sec=g2(s->data+10);
284 if(s->data[12] == 'Z')
285 offset=0;
286 else
287 {
288 offset=g2(s->data+13)*60+g2(s->data+15);
289 if(s->data[12] == '-')
290 offset= -offset;
291 }
292#undef g2
293
294 return mktime(&tm)-offset*60; /* FIXME: mktime assumes the current timezone
295 * instead of UTC, and unless we rewrite OpenSSL
296 * in Lisp we cannot locally change the timezone
297 * without possibly interfering with other parts
298 * of the program. timegm, which uses UTC, is
299 * non-standard.
300 * Also time_t is inappropriate for general
301 * UTC times because it may a 32 bit type. */
302 }
303#endif
diff --git a/src/lib/libcrypto/asn1/a_verify.c b/src/lib/libcrypto/asn1/a_verify.c
index fdce6e4380..18ef0acf00 100644
--- a/src/lib/libcrypto/asn1/a_verify.c
+++ b/src/lib/libcrypto/asn1/a_verify.c
@@ -73,8 +73,8 @@
73 73
74#ifndef NO_ASN1_OLD 74#ifndef NO_ASN1_OLD
75 75
76int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *a, ASN1_BIT_STRING *signature, 76int ASN1_verify(int (*i2d)(), X509_ALGOR *a, ASN1_BIT_STRING *signature,
77 char *data, EVP_PKEY *pkey) 77 char *data, EVP_PKEY *pkey)
78 { 78 {
79 EVP_MD_CTX ctx; 79 EVP_MD_CTX ctx;
80 const EVP_MD *type; 80 const EVP_MD *type;
@@ -138,13 +138,13 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
138 type=EVP_get_digestbyname(OBJ_nid2sn(i)); 138 type=EVP_get_digestbyname(OBJ_nid2sn(i));
139 if (type == NULL) 139 if (type == NULL)
140 { 140 {
141 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM); 141 ASN1err(ASN1_F_ASN1_VERIFY,ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM);
142 goto err; 142 goto err;
143 } 143 }
144 144
145 if (!EVP_VerifyInit_ex(&ctx,type, NULL)) 145 if (!EVP_VerifyInit_ex(&ctx,type, NULL))
146 { 146 {
147 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); 147 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
148 ret=0; 148 ret=0;
149 goto err; 149 goto err;
150 } 150 }
@@ -153,7 +153,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
153 153
154 if (buf_in == NULL) 154 if (buf_in == NULL)
155 { 155 {
156 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_MALLOC_FAILURE); 156 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_MALLOC_FAILURE);
157 goto err; 157 goto err;
158 } 158 }
159 159
@@ -165,7 +165,7 @@ int ASN1_item_verify(const ASN1_ITEM *it, X509_ALGOR *a, ASN1_BIT_STRING *signat
165 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data, 165 if (EVP_VerifyFinal(&ctx,(unsigned char *)signature->data,
166 (unsigned int)signature->length,pkey) <= 0) 166 (unsigned int)signature->length,pkey) <= 0)
167 { 167 {
168 ASN1err(ASN1_F_ASN1_ITEM_VERIFY,ERR_R_EVP_LIB); 168 ASN1err(ASN1_F_ASN1_VERIFY,ERR_R_EVP_LIB);
169 ret=0; 169 ret=0;
170 goto err; 170 goto err;
171 } 171 }
diff --git a/src/lib/libcrypto/asn1/asn1.h b/src/lib/libcrypto/asn1/asn1.h
index 424cd348bb..0184b475a7 100644
--- a/src/lib/libcrypto/asn1/asn1.h
+++ b/src/lib/libcrypto/asn1/asn1.h
@@ -60,19 +60,17 @@
60#define HEADER_ASN1_H 60#define HEADER_ASN1_H
61 61
62#include <time.h> 62#include <time.h>
63#include <openssl/e_os2.h>
64#ifndef OPENSSL_NO_BIO 63#ifndef OPENSSL_NO_BIO
65#include <openssl/bio.h> 64#include <openssl/bio.h>
66#endif 65#endif
66#include <openssl/e_os2.h>
67#include <openssl/bn.h>
67#include <openssl/stack.h> 68#include <openssl/stack.h>
68#include <openssl/safestack.h> 69#include <openssl/safestack.h>
69 70
70#include <openssl/symhacks.h> 71#include <openssl/symhacks.h>
71 72
72#include <openssl/ossl_typ.h> 73#include <openssl/ossl_typ.h>
73#ifndef OPENSSL_NO_DEPRECATED
74#include <openssl/bn.h>
75#endif
76 74
77#ifdef OPENSSL_BUILD_SHLIBCRYPTO 75#ifdef OPENSSL_BUILD_SHLIBCRYPTO
78# undef OPENSSL_EXTERN 76# undef OPENSSL_EXTERN
@@ -149,29 +147,19 @@ extern "C" {
149#define B_ASN1_UTF8STRING 0x2000 147#define B_ASN1_UTF8STRING 0x2000
150#define B_ASN1_UTCTIME 0x4000 148#define B_ASN1_UTCTIME 0x4000
151#define B_ASN1_GENERALIZEDTIME 0x8000 149#define B_ASN1_GENERALIZEDTIME 0x8000
152#define B_ASN1_SEQUENCE 0x10000
153 150
154/* For use with ASN1_mbstring_copy() */ 151/* For use with ASN1_mbstring_copy() */
155#define MBSTRING_FLAG 0x1000 152#define MBSTRING_FLAG 0x1000
156#define MBSTRING_UTF8 (MBSTRING_FLAG)
157#define MBSTRING_ASC (MBSTRING_FLAG|1) 153#define MBSTRING_ASC (MBSTRING_FLAG|1)
158#define MBSTRING_BMP (MBSTRING_FLAG|2) 154#define MBSTRING_BMP (MBSTRING_FLAG|2)
159#define MBSTRING_UNIV (MBSTRING_FLAG|4) 155#define MBSTRING_UNIV (MBSTRING_FLAG|3)
160 156#define MBSTRING_UTF8 (MBSTRING_FLAG|4)
161#define SMIME_OLDMIME 0x400
162#define SMIME_CRLFEOL 0x800
163#define SMIME_STREAM 0x1000
164 157
165struct X509_algor_st; 158struct X509_algor_st;
166DECLARE_STACK_OF(X509_ALGOR)
167 159
168#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */ 160#define DECLARE_ASN1_SET_OF(type) /* filled in by mkstack.pl */
169#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */ 161#define IMPLEMENT_ASN1_SET_OF(type) /* nothing, no longer needed */
170 162
171/* We MUST make sure that, except for constness, asn1_ctx_st and
172 asn1_const_ctx are exactly the same. Fortunately, as soon as
173 the old ASN1 parsing macros are gone, we can throw this away
174 as well... */
175typedef struct asn1_ctx_st 163typedef struct asn1_ctx_st
176 { 164 {
177 unsigned char *p;/* work char pointer */ 165 unsigned char *p;/* work char pointer */
@@ -187,21 +175,6 @@ typedef struct asn1_ctx_st
187 int line; /* used in error processing */ 175 int line; /* used in error processing */
188 } ASN1_CTX; 176 } ASN1_CTX;
189 177
190typedef struct asn1_const_ctx_st
191 {
192 const unsigned char *p;/* work char pointer */
193 int eos; /* end of sequence read for indefinite encoding */
194 int error; /* error code to use when returning an error */
195 int inf; /* constructed if 0x20, indefinite is 0x21 */
196 int tag; /* tag from last 'get object' */
197 int xclass; /* class from last 'get object' */
198 long slen; /* length of last 'get object' */
199 const unsigned char *max; /* largest value of p allowed */
200 const unsigned char *q;/* temporary variable */
201 const unsigned char **pp;/* variable */
202 int line; /* used in error processing */
203 } ASN1_const_CTX;
204
205/* These are used internally in the ASN1_OBJECT to keep track of 178/* These are used internally in the ASN1_OBJECT to keep track of
206 * whether the names and data need to be free()ed */ 179 * whether the names and data need to be free()ed */
207#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */ 180#define ASN1_OBJECT_FLAG_DYNAMIC 0x01 /* internal use */
@@ -218,18 +191,6 @@ typedef struct asn1_object_st
218 } ASN1_OBJECT; 191 } ASN1_OBJECT;
219 192
220#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */ 193#define ASN1_STRING_FLAG_BITS_LEFT 0x08 /* Set if 0x07 has bits left value */
221/* This indicates that the ASN1_STRING is not a real value but just a place
222 * holder for the location where indefinite length constructed data should
223 * be inserted in the memory buffer
224 */
225#define ASN1_STRING_FLAG_NDEF 0x010
226
227/* This flag is used by the CMS code to indicate that a string is not
228 * complete and is a place holder for content when it had all been
229 * accessed. The flag will be reset when content has been written to it.
230 */
231#define ASN1_STRING_FLAG_CONT 0x020
232
233/* This is the base type that holds just about everything :-) */ 194/* This is the base type that holds just about everything :-) */
234typedef struct asn1_string_st 195typedef struct asn1_string_st
235 { 196 {
@@ -298,19 +259,18 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
298 259
299#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type) 260#define DECLARE_ASN1_FUNCTIONS(type) DECLARE_ASN1_FUNCTIONS_name(type, type)
300 261
301#define DECLARE_ASN1_ALLOC_FUNCTIONS(type) \
302 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, type)
303
304#define DECLARE_ASN1_FUNCTIONS_name(type, name) \ 262#define DECLARE_ASN1_FUNCTIONS_name(type, name) \
305 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ 263 type *name##_new(void); \
264 void name##_free(type *a); \
306 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) 265 DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name)
307 266
308#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \ 267#define DECLARE_ASN1_FUNCTIONS_fname(type, itname, name) \
309 DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \ 268 type *name##_new(void); \
269 void name##_free(type *a); \
310 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) 270 DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name)
311 271
312#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \ 272#define DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) \
313 type *d2i_##name(type **a, const unsigned char **in, long len); \ 273 type *d2i_##name(type **a, unsigned char **in, long len); \
314 int i2d_##name(type *a, unsigned char **out); \ 274 int i2d_##name(type *a, unsigned char **out); \
315 DECLARE_ASN1_ITEM(itname) 275 DECLARE_ASN1_ITEM(itname)
316 276
@@ -319,37 +279,10 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
319 int i2d_##name(const type *a, unsigned char **out); \ 279 int i2d_##name(const type *a, unsigned char **out); \
320 DECLARE_ASN1_ITEM(name) 280 DECLARE_ASN1_ITEM(name)
321 281
322#define DECLARE_ASN1_NDEF_FUNCTION(name) \
323 int i2d_##name##_NDEF(name *a, unsigned char **out);
324
325#define DECLARE_ASN1_FUNCTIONS_const(name) \ 282#define DECLARE_ASN1_FUNCTIONS_const(name) \
326 DECLARE_ASN1_ALLOC_FUNCTIONS(name) \ 283 name *name##_new(void); \
327 DECLARE_ASN1_ENCODE_FUNCTIONS_const(name, name) 284 void name##_free(name *a);
328 285
329#define DECLARE_ASN1_ALLOC_FUNCTIONS_name(type, name) \
330 type *name##_new(void); \
331 void name##_free(type *a);
332
333#define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
334#define I2D_OF(type) int (*)(type *,unsigned char **)
335#define I2D_OF_const(type) int (*)(const type *,unsigned char **)
336
337#define CHECKED_D2I_OF(type, d2i) \
338 ((d2i_of_void*) (1 ? d2i : ((D2I_OF(type))0)))
339#define CHECKED_I2D_OF(type, i2d) \
340 ((i2d_of_void*) (1 ? i2d : ((I2D_OF(type))0)))
341#define CHECKED_NEW_OF(type, xnew) \
342 ((void *(*)(void)) (1 ? xnew : ((type *(*)(void))0)))
343#define CHECKED_PTR_OF(type, p) \
344 ((void*) (1 ? p : (type*)0))
345#define CHECKED_PPTR_OF(type, p) \
346 ((void**) (1 ? p : (type**)0))
347
348#define TYPEDEF_D2I_OF(type) typedef type *d2i_of_##type(type **,const unsigned char **,long)
349#define TYPEDEF_I2D_OF(type) typedef int i2d_of_##type(type *,unsigned char **)
350#define TYPEDEF_D2I2D_OF(type) TYPEDEF_D2I_OF(type); TYPEDEF_I2D_OF(type)
351
352TYPEDEF_D2I2D_OF(void);
353 286
354/* The following macros and typedefs allow an ASN1_ITEM 287/* The following macros and typedefs allow an ASN1_ITEM
355 * to be embedded in a structure and referenced. Since 288 * to be embedded in a structure and referenced. Since
@@ -534,7 +467,6 @@ typedef struct asn1_type_st
534 * contain the set or sequence bytes */ 467 * contain the set or sequence bytes */
535 ASN1_STRING * set; 468 ASN1_STRING * set;
536 ASN1_STRING * sequence; 469 ASN1_STRING * sequence;
537 ASN1_VALUE * asn1_value;
538 } value; 470 } value;
539 } ASN1_TYPE; 471 } ASN1_TYPE;
540 472
@@ -543,17 +475,17 @@ DECLARE_ASN1_SET_OF(ASN1_TYPE)
543 475
544typedef struct asn1_method_st 476typedef struct asn1_method_st
545 { 477 {
546 i2d_of_void *i2d; 478 int (*i2d)();
547 d2i_of_void *d2i; 479 char *(*d2i)();
548 void *(*create)(void); 480 char *(*create)();
549 void (*destroy)(void *); 481 void (*destroy)();
550 } ASN1_METHOD; 482 } ASN1_METHOD;
551 483
552/* This is used when parsing some Netscape objects */ 484/* This is used when parsing some Netscape objects */
553typedef struct asn1_header_st 485typedef struct asn1_header_st
554 { 486 {
555 ASN1_OCTET_STRING *header; 487 ASN1_OCTET_STRING *header;
556 void *data; 488 char *data;
557 ASN1_METHOD *meth; 489 ASN1_METHOD *meth;
558 } ASN1_HEADER; 490 } ASN1_HEADER;
559 491
@@ -619,7 +551,6 @@ typedef struct BIT_STRING_BITNAME_st {
619 B_ASN1_UNIVERSALSTRING|\ 551 B_ASN1_UNIVERSALSTRING|\
620 B_ASN1_BMPSTRING|\ 552 B_ASN1_BMPSTRING|\
621 B_ASN1_UTF8STRING|\ 553 B_ASN1_UTF8STRING|\
622 B_ASN1_SEQUENCE|\
623 B_ASN1_UNKNOWN 554 B_ASN1_UNKNOWN
624 555
625#define B_ASN1_DIRECTORYSTRING \ 556#define B_ASN1_DIRECTORYSTRING \
@@ -765,14 +696,13 @@ DECLARE_ASN1_FUNCTIONS_fname(ASN1_TYPE, ASN1_ANY, ASN1_TYPE)
765 696
766int ASN1_TYPE_get(ASN1_TYPE *a); 697int ASN1_TYPE_get(ASN1_TYPE *a);
767void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value); 698void ASN1_TYPE_set(ASN1_TYPE *a, int type, void *value);
768int ASN1_TYPE_set1(ASN1_TYPE *a, int type, const void *value);
769 699
770ASN1_OBJECT * ASN1_OBJECT_new(void ); 700ASN1_OBJECT * ASN1_OBJECT_new(void );
771void ASN1_OBJECT_free(ASN1_OBJECT *a); 701void ASN1_OBJECT_free(ASN1_OBJECT *a);
772int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp); 702int i2d_ASN1_OBJECT(ASN1_OBJECT *a,unsigned char **pp);
773ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, 703ASN1_OBJECT * c2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
774 long length); 704 long length);
775ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,const unsigned char **pp, 705ASN1_OBJECT * d2i_ASN1_OBJECT(ASN1_OBJECT **a,unsigned char **pp,
776 long length); 706 long length);
777 707
778DECLARE_ASN1_ITEM(ASN1_OBJECT) 708DECLARE_ASN1_ITEM(ASN1_OBJECT)
@@ -788,7 +718,6 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b);
788 /* Since this is used to store all sorts of things, via macros, for now, make 718 /* Since this is used to store all sorts of things, via macros, for now, make
789 its data void * */ 719 its data void * */
790int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len); 720int ASN1_STRING_set(ASN1_STRING *str, const void *data, int len);
791void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len);
792int ASN1_STRING_length(ASN1_STRING *x); 721int ASN1_STRING_length(ASN1_STRING *x);
793void ASN1_STRING_length_set(ASN1_STRING *x, int n); 722void ASN1_STRING_length_set(ASN1_STRING *x, int n);
794int ASN1_STRING_type(ASN1_STRING *x); 723int ASN1_STRING_type(ASN1_STRING *x);
@@ -796,7 +725,7 @@ unsigned char * ASN1_STRING_data(ASN1_STRING *x);
796 725
797DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING) 726DECLARE_ASN1_FUNCTIONS(ASN1_BIT_STRING)
798int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp); 727int i2c_ASN1_BIT_STRING(ASN1_BIT_STRING *a,unsigned char **pp);
799ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,const unsigned char **pp, 728ASN1_BIT_STRING *c2i_ASN1_BIT_STRING(ASN1_BIT_STRING **a,unsigned char **pp,
800 long length); 729 long length);
801int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d, 730int ASN1_BIT_STRING_set(ASN1_BIT_STRING *a, unsigned char *d,
802 int length ); 731 int length );
@@ -812,13 +741,13 @@ int ASN1_BIT_STRING_set_asc(ASN1_BIT_STRING *bs, char *name, int value,
812 BIT_STRING_BITNAME *tbl); 741 BIT_STRING_BITNAME *tbl);
813 742
814int i2d_ASN1_BOOLEAN(int a,unsigned char **pp); 743int i2d_ASN1_BOOLEAN(int a,unsigned char **pp);
815int d2i_ASN1_BOOLEAN(int *a,const unsigned char **pp,long length); 744int d2i_ASN1_BOOLEAN(int *a,unsigned char **pp,long length);
816 745
817DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER) 746DECLARE_ASN1_FUNCTIONS(ASN1_INTEGER)
818int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp); 747int i2c_ASN1_INTEGER(ASN1_INTEGER *a,unsigned char **pp);
819ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,const unsigned char **pp, 748ASN1_INTEGER *c2i_ASN1_INTEGER(ASN1_INTEGER **a,unsigned char **pp,
820 long length); 749 long length);
821ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,const unsigned char **pp, 750ASN1_INTEGER *d2i_ASN1_UINTEGER(ASN1_INTEGER **a,unsigned char **pp,
822 long length); 751 long length);
823ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x); 752ASN1_INTEGER * ASN1_INTEGER_dup(ASN1_INTEGER *x);
824int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y); 753int ASN1_INTEGER_cmp(ASN1_INTEGER *x, ASN1_INTEGER *y);
@@ -827,7 +756,7 @@ DECLARE_ASN1_FUNCTIONS(ASN1_ENUMERATED)
827 756
828int ASN1_UTCTIME_check(ASN1_UTCTIME *a); 757int ASN1_UTCTIME_check(ASN1_UTCTIME *a);
829ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t); 758ASN1_UTCTIME *ASN1_UTCTIME_set(ASN1_UTCTIME *s,time_t t);
830int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, const char *str); 759int ASN1_UTCTIME_set_string(ASN1_UTCTIME *s, char *str);
831int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t); 760int ASN1_UTCTIME_cmp_time_t(const ASN1_UTCTIME *s, time_t t);
832#if 0 761#if 0
833time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s); 762time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
@@ -835,12 +764,12 @@ time_t ASN1_UTCTIME_get(const ASN1_UTCTIME *s);
835 764
836int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a); 765int ASN1_GENERALIZEDTIME_check(ASN1_GENERALIZEDTIME *a);
837ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t); 766ASN1_GENERALIZEDTIME *ASN1_GENERALIZEDTIME_set(ASN1_GENERALIZEDTIME *s,time_t t);
838int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, const char *str); 767int ASN1_GENERALIZEDTIME_set_string(ASN1_GENERALIZEDTIME *s, char *str);
839 768
840DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING) 769DECLARE_ASN1_FUNCTIONS(ASN1_OCTET_STRING)
841ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a); 770ASN1_OCTET_STRING * ASN1_OCTET_STRING_dup(ASN1_OCTET_STRING *a);
842int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b); 771int ASN1_OCTET_STRING_cmp(ASN1_OCTET_STRING *a, ASN1_OCTET_STRING *b);
843int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, const unsigned char *data, int len); 772int ASN1_OCTET_STRING_set(ASN1_OCTET_STRING *str, unsigned char *data, int len);
844 773
845DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING) 774DECLARE_ASN1_FUNCTIONS(ASN1_VISIBLESTRING)
846DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING) 775DECLARE_ASN1_FUNCTIONS(ASN1_UNIVERSALSTRING)
@@ -863,17 +792,15 @@ DECLARE_ASN1_FUNCTIONS(ASN1_UTCTIME)
863DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME) 792DECLARE_ASN1_FUNCTIONS(ASN1_GENERALIZEDTIME)
864DECLARE_ASN1_FUNCTIONS(ASN1_TIME) 793DECLARE_ASN1_FUNCTIONS(ASN1_TIME)
865 794
866DECLARE_ASN1_ITEM(ASN1_OCTET_STRING_NDEF)
867
868ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t); 795ASN1_TIME *ASN1_TIME_set(ASN1_TIME *s,time_t t);
869int ASN1_TIME_check(ASN1_TIME *t); 796int ASN1_TIME_check(ASN1_TIME *t);
870ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out); 797ASN1_GENERALIZEDTIME *ASN1_TIME_to_generalizedtime(ASN1_TIME *t, ASN1_GENERALIZEDTIME **out);
871 798
872int i2d_ASN1_SET(STACK *a, unsigned char **pp, 799int i2d_ASN1_SET(STACK *a, unsigned char **pp,
873 i2d_of_void *i2d, int ex_tag, int ex_class, int is_set); 800 int (*func)(), int ex_tag, int ex_class, int is_set);
874STACK * d2i_ASN1_SET(STACK **a, const unsigned char **pp, long length, 801STACK * d2i_ASN1_SET(STACK **a, unsigned char **pp, long length,
875 d2i_of_void *d2i, void (*free_func)(void *), 802 char *(*func)(), void (*free_func)(void *),
876 int ex_tag, int ex_class); 803 int ex_tag, int ex_class);
877 804
878#ifndef OPENSSL_NO_BIO 805#ifndef OPENSSL_NO_BIO
879int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a); 806int i2a_ASN1_INTEGER(BIO *bp, ASN1_INTEGER *a);
@@ -905,70 +832,33 @@ BIGNUM *ASN1_ENUMERATED_to_BN(ASN1_ENUMERATED *ai,BIGNUM *bn);
905int ASN1_PRINTABLE_type(const unsigned char *s, int max); 832int ASN1_PRINTABLE_type(const unsigned char *s, int max);
906 833
907int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass); 834int i2d_ASN1_bytes(ASN1_STRING *a, unsigned char **pp, int tag, int xclass);
908ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, const unsigned char **pp, 835ASN1_STRING *d2i_ASN1_bytes(ASN1_STRING **a, unsigned char **pp,
909 long length, int Ptag, int Pclass); 836 long length, int Ptag, int Pclass);
910unsigned long ASN1_tag2bit(int tag); 837unsigned long ASN1_tag2bit(int tag);
911/* type is one or more of the B_ASN1_ values. */ 838/* type is one or more of the B_ASN1_ values. */
912ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,const unsigned char **pp, 839ASN1_STRING *d2i_ASN1_type_bytes(ASN1_STRING **a,unsigned char **pp,
913 long length,int type); 840 long length,int type);
914 841
915/* PARSING */ 842/* PARSING */
916int asn1_Finish(ASN1_CTX *c); 843int asn1_Finish(ASN1_CTX *c);
917int asn1_const_Finish(ASN1_const_CTX *c);
918 844
919/* SPECIALS */ 845/* SPECIALS */
920int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag, 846int ASN1_get_object(unsigned char **pp, long *plength, int *ptag,
921 int *pclass, long omax); 847 int *pclass, long omax);
922int ASN1_check_infinite_end(unsigned char **p,long len); 848int ASN1_check_infinite_end(unsigned char **p,long len);
923int ASN1_const_check_infinite_end(const unsigned char **p,long len);
924void ASN1_put_object(unsigned char **pp, int constructed, int length, 849void ASN1_put_object(unsigned char **pp, int constructed, int length,
925 int tag, int xclass); 850 int tag, int xclass);
926int ASN1_put_eoc(unsigned char **pp);
927int ASN1_object_size(int constructed, int length, int tag); 851int ASN1_object_size(int constructed, int length, int tag);
928 852
929/* Used to implement other functions */ 853/* Used to implement other functions */
930void *ASN1_dup(i2d_of_void *i2d, d2i_of_void *d2i, char *x); 854char *ASN1_dup(int (*i2d)(),char *(*d2i)(),char *x);
931
932#define ASN1_dup_of(type,i2d,d2i,x) \
933 ((type*)ASN1_dup(CHECKED_I2D_OF(type, i2d), \
934 CHECKED_D2I_OF(type, d2i), \
935 CHECKED_PTR_OF(type, x)))
936
937#define ASN1_dup_of_const(type,i2d,d2i,x) \
938 ((type*)ASN1_dup(CHECKED_I2D_OF(const type, i2d), \
939 CHECKED_D2I_OF(type, d2i), \
940 CHECKED_PTR_OF(const type, x)))
941 855
942void *ASN1_item_dup(const ASN1_ITEM *it, void *x); 856void *ASN1_item_dup(const ASN1_ITEM *it, void *x);
943 857
944/* ASN1 alloc/free macros for when a type is only used internally */
945
946#define M_ASN1_new_of(type) (type *)ASN1_item_new(ASN1_ITEM_rptr(type))
947#define M_ASN1_free_of(x, type) \
948 ASN1_item_free(CHECKED_PTR_OF(type, x), ASN1_ITEM_rptr(type))
949
950#ifndef OPENSSL_NO_FP_API 858#ifndef OPENSSL_NO_FP_API
951void *ASN1_d2i_fp(void *(*xnew)(void), d2i_of_void *d2i, FILE *in, void **x); 859char *ASN1_d2i_fp(char *(*xnew)(),char *(*d2i)(),FILE *fp,unsigned char **x);
952
953#define ASN1_d2i_fp_of(type,xnew,d2i,in,x) \
954 ((type*)ASN1_d2i_fp(CHECKED_NEW_OF(type, xnew), \
955 CHECKED_D2I_OF(type, d2i), \
956 in, \
957 CHECKED_PPTR_OF(type, x)))
958
959void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x); 860void *ASN1_item_d2i_fp(const ASN1_ITEM *it, FILE *in, void *x);
960int ASN1_i2d_fp(i2d_of_void *i2d,FILE *out,void *x); 861int ASN1_i2d_fp(int (*i2d)(),FILE *out,unsigned char *x);
961
962#define ASN1_i2d_fp_of(type,i2d,out,x) \
963 (ASN1_i2d_fp(CHECKED_I2D_OF(type, i2d), \
964 out, \
965 CHECKED_PTR_OF(type, x)))
966
967#define ASN1_i2d_fp_of_const(type,i2d,out,x) \
968 (ASN1_i2d_fp(CHECKED_I2D_OF(const type, i2d), \
969 out, \
970 CHECKED_PTR_OF(const type, x)))
971
972int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x); 862int ASN1_item_i2d_fp(const ASN1_ITEM *it, FILE *out, void *x);
973int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags); 863int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
974#endif 864#endif
@@ -976,41 +866,23 @@ int ASN1_STRING_print_ex_fp(FILE *fp, ASN1_STRING *str, unsigned long flags);
976int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in); 866int ASN1_STRING_to_UTF8(unsigned char **out, ASN1_STRING *in);
977 867
978#ifndef OPENSSL_NO_BIO 868#ifndef OPENSSL_NO_BIO
979void *ASN1_d2i_bio(void *(*xnew)(void), d2i_of_void *d2i, BIO *in, void **x); 869char *ASN1_d2i_bio(char *(*xnew)(),char *(*d2i)(),BIO *bp,unsigned char **x);
980
981#define ASN1_d2i_bio_of(type,xnew,d2i,in,x) \
982 ((type*)ASN1_d2i_bio( CHECKED_NEW_OF(type, xnew), \
983 CHECKED_D2I_OF(type, d2i), \
984 in, \
985 CHECKED_PPTR_OF(type, x)))
986
987void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x); 870void *ASN1_item_d2i_bio(const ASN1_ITEM *it, BIO *in, void *x);
988int ASN1_i2d_bio(i2d_of_void *i2d,BIO *out, unsigned char *x); 871int ASN1_i2d_bio(int (*i2d)(),BIO *out,unsigned char *x);
989
990#define ASN1_i2d_bio_of(type,i2d,out,x) \
991 (ASN1_i2d_bio(CHECKED_I2D_OF(type, i2d), \
992 out, \
993 CHECKED_PTR_OF(type, x)))
994
995#define ASN1_i2d_bio_of_const(type,i2d,out,x) \
996 (ASN1_i2d_bio(CHECKED_I2D_OF(const type, i2d), \
997 out, \
998 CHECKED_PTR_OF(const type, x)))
999
1000int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x); 872int ASN1_item_i2d_bio(const ASN1_ITEM *it, BIO *out, void *x);
1001int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a); 873int ASN1_UTCTIME_print(BIO *fp,ASN1_UTCTIME *a);
1002int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a); 874int ASN1_GENERALIZEDTIME_print(BIO *fp,ASN1_GENERALIZEDTIME *a);
1003int ASN1_TIME_print(BIO *fp,ASN1_TIME *a); 875int ASN1_TIME_print(BIO *fp,ASN1_TIME *a);
1004int ASN1_STRING_print(BIO *bp,ASN1_STRING *v); 876int ASN1_STRING_print(BIO *bp,ASN1_STRING *v);
1005int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags); 877int ASN1_STRING_print_ex(BIO *out, ASN1_STRING *str, unsigned long flags);
1006int ASN1_parse(BIO *bp,const unsigned char *pp,long len,int indent); 878int ASN1_parse(BIO *bp,unsigned char *pp,long len,int indent);
1007int ASN1_parse_dump(BIO *bp,const unsigned char *pp,long len,int indent,int dump); 879int ASN1_parse_dump(BIO *bp,unsigned char *pp,long len,int indent,int dump);
1008#endif 880#endif
1009const char *ASN1_tag2str(int tag); 881const char *ASN1_tag2str(int tag);
1010 882
1011/* Used to load and write netscape format cert/key */ 883/* Used to load and write netscape format cert/key */
1012int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp); 884int i2d_ASN1_HEADER(ASN1_HEADER *a,unsigned char **pp);
1013ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,const unsigned char **pp, long length); 885ASN1_HEADER *d2i_ASN1_HEADER(ASN1_HEADER **a,unsigned char **pp, long length);
1014ASN1_HEADER *ASN1_HEADER_new(void ); 886ASN1_HEADER *ASN1_HEADER_new(void );
1015void ASN1_HEADER_free(ASN1_HEADER *a); 887void ASN1_HEADER_free(ASN1_HEADER *a);
1016 888
@@ -1031,20 +903,13 @@ int ASN1_TYPE_set_int_octetstring(ASN1_TYPE *a, long num,
1031int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num, 903int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a,long *num,
1032 unsigned char *data, int max_len); 904 unsigned char *data, int max_len);
1033 905
1034STACK *ASN1_seq_unpack(const unsigned char *buf, int len, 906STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
1035 d2i_of_void *d2i, void (*free_func)(void *)); 907 void (*free_func)(void *) );
1036unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, 908unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
1037 unsigned char **buf, int *len ); 909 int *len );
1038void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i); 910void *ASN1_unpack_string(ASN1_STRING *oct, char *(*d2i)());
1039void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it); 911void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it);
1040ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, 912ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_OCTET_STRING **oct);
1041 ASN1_OCTET_STRING **oct);
1042
1043#define ASN1_pack_string_of(type,obj,i2d,oct) \
1044 (ASN1_pack_string(CHECKED_PTR_OF(type, obj), \
1045 CHECKED_I2D_OF(type, i2d), \
1046 oct))
1047
1048ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct); 913ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_OCTET_STRING **oct);
1049 914
1050void ASN1_STRING_set_default_mask(unsigned long mask); 915void ASN1_STRING_set_default_mask(unsigned long mask);
@@ -1067,25 +932,11 @@ void ASN1_STRING_TABLE_cleanup(void);
1067/* Old API compatible functions */ 932/* Old API compatible functions */
1068ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it); 933ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it);
1069void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it); 934void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it);
1070ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it); 935ASN1_VALUE * ASN1_item_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it);
1071int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it); 936int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1072int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it);
1073 937
1074void ASN1_add_oid_module(void); 938void ASN1_add_oid_module(void);
1075 939
1076ASN1_TYPE *ASN1_generate_nconf(char *str, CONF *nconf);
1077ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
1078
1079typedef int asn1_output_data_fn(BIO *out, BIO *data, ASN1_VALUE *val, int flags,
1080 const ASN1_ITEM *it);
1081
1082int int_smime_write_ASN1(BIO *bio, ASN1_VALUE *val, BIO *data, int flags,
1083 int ctype_nid, int econt_nid,
1084 STACK_OF(X509_ALGOR) *mdalgs,
1085 asn1_output_data_fn *data_fn,
1086 const ASN1_ITEM *it);
1087ASN1_VALUE *SMIME_read_ASN1(BIO *bio, BIO **bcont, const ASN1_ITEM *it);
1088
1089/* BEGIN ERROR CODES */ 940/* BEGIN ERROR CODES */
1090/* The following lines are auto generated by the script mkerr.pl. Any changes 941/* The following lines are auto generated by the script mkerr.pl. Any changes
1091 * made after this point may be overwritten when the script is next run. 942 * made after this point may be overwritten when the script is next run.
@@ -1099,70 +950,49 @@ void ERR_load_ASN1_strings(void);
1099#define ASN1_F_A2I_ASN1_ENUMERATED 101 950#define ASN1_F_A2I_ASN1_ENUMERATED 101
1100#define ASN1_F_A2I_ASN1_INTEGER 102 951#define ASN1_F_A2I_ASN1_INTEGER 102
1101#define ASN1_F_A2I_ASN1_STRING 103 952#define ASN1_F_A2I_ASN1_STRING 103
1102#define ASN1_F_APPEND_EXP 176 953#define ASN1_F_ASN1_BIT_STRING_SET_BIT 176
1103#define ASN1_F_ASN1_BIT_STRING_SET_BIT 183
1104#define ASN1_F_ASN1_CB 177
1105#define ASN1_F_ASN1_CHECK_TLEN 104 954#define ASN1_F_ASN1_CHECK_TLEN 104
1106#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105 955#define ASN1_F_ASN1_COLLATE_PRIMITIVE 105
1107#define ASN1_F_ASN1_COLLECT 106 956#define ASN1_F_ASN1_COLLECT 106
957#define ASN1_F_ASN1_D2I_BIO 107
1108#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108 958#define ASN1_F_ASN1_D2I_EX_PRIMITIVE 108
1109#define ASN1_F_ASN1_D2I_FP 109 959#define ASN1_F_ASN1_D2I_FP 109
1110#define ASN1_F_ASN1_D2I_READ_BIO 107 960#define ASN1_F_ASN1_DIGEST 177
1111#define ASN1_F_ASN1_DIGEST 184
1112#define ASN1_F_ASN1_DO_ADB 110 961#define ASN1_F_ASN1_DO_ADB 110
1113#define ASN1_F_ASN1_DUP 111 962#define ASN1_F_ASN1_DUP 111
1114#define ASN1_F_ASN1_ENUMERATED_SET 112 963#define ASN1_F_ASN1_ENUMERATED_SET 112
1115#define ASN1_F_ASN1_ENUMERATED_TO_BN 113 964#define ASN1_F_ASN1_ENUMERATED_TO_BN 113
1116#define ASN1_F_ASN1_EX_C2I 204 965#define ASN1_F_ASN1_FIND_END 182
1117#define ASN1_F_ASN1_FIND_END 190 966#define ASN1_F_ASN1_GENERALIZEDTIME_SET 178
1118#define ASN1_F_ASN1_GENERALIZEDTIME_SET 185
1119#define ASN1_F_ASN1_GENERATE_V3 178
1120#define ASN1_F_ASN1_GET_OBJECT 114 967#define ASN1_F_ASN1_GET_OBJECT 114
1121#define ASN1_F_ASN1_HEADER_NEW 115 968#define ASN1_F_ASN1_HEADER_NEW 115
1122#define ASN1_F_ASN1_I2D_BIO 116 969#define ASN1_F_ASN1_I2D_BIO 116
1123#define ASN1_F_ASN1_I2D_FP 117 970#define ASN1_F_ASN1_I2D_FP 117
1124#define ASN1_F_ASN1_INTEGER_SET 118 971#define ASN1_F_ASN1_INTEGER_SET 118
1125#define ASN1_F_ASN1_INTEGER_TO_BN 119 972#define ASN1_F_ASN1_INTEGER_TO_BN 119
1126#define ASN1_F_ASN1_ITEM_D2I_FP 206
1127#define ASN1_F_ASN1_ITEM_DUP 191
1128#define ASN1_F_ASN1_ITEM_EX_COMBINE_NEW 121
1129#define ASN1_F_ASN1_ITEM_EX_D2I 120 973#define ASN1_F_ASN1_ITEM_EX_D2I 120
1130#define ASN1_F_ASN1_ITEM_I2D_BIO 192 974#define ASN1_F_ASN1_ITEM_NEW 121
1131#define ASN1_F_ASN1_ITEM_I2D_FP 193 975#define ASN1_F_ASN1_MBSTRING_COPY 122
1132#define ASN1_F_ASN1_ITEM_PACK 198
1133#define ASN1_F_ASN1_ITEM_SIGN 195
1134#define ASN1_F_ASN1_ITEM_UNPACK 199
1135#define ASN1_F_ASN1_ITEM_VERIFY 197
1136#define ASN1_F_ASN1_MBSTRING_NCOPY 122
1137#define ASN1_F_ASN1_OBJECT_NEW 123 976#define ASN1_F_ASN1_OBJECT_NEW 123
1138#define ASN1_F_ASN1_OUTPUT_DATA 207
1139#define ASN1_F_ASN1_PACK_STRING 124 977#define ASN1_F_ASN1_PACK_STRING 124
1140#define ASN1_F_ASN1_PCTX_NEW 205 978#define ASN1_F_ASN1_PBE_SET 125
1141#define ASN1_F_ASN1_PKCS5_PBE_SET 125
1142#define ASN1_F_ASN1_SEQ_PACK 126 979#define ASN1_F_ASN1_SEQ_PACK 126
1143#define ASN1_F_ASN1_SEQ_UNPACK 127 980#define ASN1_F_ASN1_SEQ_UNPACK 127
1144#define ASN1_F_ASN1_SIGN 128 981#define ASN1_F_ASN1_SIGN 128
1145#define ASN1_F_ASN1_STR2TYPE 179 982#define ASN1_F_ASN1_STRING_SET 179
1146#define ASN1_F_ASN1_STRING_SET 186
1147#define ASN1_F_ASN1_STRING_TABLE_ADD 129 983#define ASN1_F_ASN1_STRING_TABLE_ADD 129
1148#define ASN1_F_ASN1_STRING_TYPE_NEW 130 984#define ASN1_F_ASN1_STRING_TYPE_NEW 130
985#define ASN1_F_ASN1_TEMPLATE_D2I 131
1149#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132 986#define ASN1_F_ASN1_TEMPLATE_EX_D2I 132
1150#define ASN1_F_ASN1_TEMPLATE_NEW 133 987#define ASN1_F_ASN1_TEMPLATE_NEW 133
1151#define ASN1_F_ASN1_TEMPLATE_NOEXP_D2I 131
1152#define ASN1_F_ASN1_TIME_SET 175 988#define ASN1_F_ASN1_TIME_SET 175
1153#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134 989#define ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING 134
1154#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135 990#define ASN1_F_ASN1_TYPE_GET_OCTETSTRING 135
1155#define ASN1_F_ASN1_UNPACK_STRING 136 991#define ASN1_F_ASN1_UNPACK_STRING 136
1156#define ASN1_F_ASN1_UTCTIME_SET 187 992#define ASN1_F_ASN1_UTCTIME_SET 180
1157#define ASN1_F_ASN1_VERIFY 137 993#define ASN1_F_ASN1_VERIFY 137
1158#define ASN1_F_B64_READ_ASN1 208
1159#define ASN1_F_B64_WRITE_ASN1 209
1160#define ASN1_F_BITSTR_CB 180
1161#define ASN1_F_BN_TO_ASN1_ENUMERATED 138 994#define ASN1_F_BN_TO_ASN1_ENUMERATED 138
1162#define ASN1_F_BN_TO_ASN1_INTEGER 139 995#define ASN1_F_BN_TO_ASN1_INTEGER 139
1163#define ASN1_F_C2I_ASN1_BIT_STRING 189
1164#define ASN1_F_C2I_ASN1_INTEGER 194
1165#define ASN1_F_C2I_ASN1_OBJECT 196
1166#define ASN1_F_COLLECT_DATA 140 996#define ASN1_F_COLLECT_DATA 140
1167#define ASN1_F_D2I_ASN1_BIT_STRING 141 997#define ASN1_F_D2I_ASN1_BIT_STRING 141
1168#define ASN1_F_D2I_ASN1_BOOLEAN 142 998#define ASN1_F_D2I_ASN1_BOOLEAN 142
@@ -1179,39 +1009,29 @@ void ERR_load_ASN1_strings(void);
1179#define ASN1_F_D2I_NETSCAPE_RSA_2 153 1009#define ASN1_F_D2I_NETSCAPE_RSA_2 153
1180#define ASN1_F_D2I_PRIVATEKEY 154 1010#define ASN1_F_D2I_PRIVATEKEY 154
1181#define ASN1_F_D2I_PUBLICKEY 155 1011#define ASN1_F_D2I_PUBLICKEY 155
1182#define ASN1_F_D2I_RSA_NET 200
1183#define ASN1_F_D2I_RSA_NET_2 201
1184#define ASN1_F_D2I_X509 156 1012#define ASN1_F_D2I_X509 156
1185#define ASN1_F_D2I_X509_CINF 157 1013#define ASN1_F_D2I_X509_CINF 157
1014#define ASN1_F_D2I_X509_NAME 158
1186#define ASN1_F_D2I_X509_PKEY 159 1015#define ASN1_F_D2I_X509_PKEY 159
1187#define ASN1_F_I2D_ASN1_SET 188 1016#define ASN1_F_I2D_ASN1_SET 181
1188#define ASN1_F_I2D_ASN1_TIME 160 1017#define ASN1_F_I2D_ASN1_TIME 160
1189#define ASN1_F_I2D_DSA_PUBKEY 161 1018#define ASN1_F_I2D_DSA_PUBKEY 161
1190#define ASN1_F_I2D_EC_PUBKEY 181 1019#define ASN1_F_I2D_NETSCAPE_RSA 162
1191#define ASN1_F_I2D_PRIVATEKEY 163 1020#define ASN1_F_I2D_PRIVATEKEY 163
1192#define ASN1_F_I2D_PUBLICKEY 164 1021#define ASN1_F_I2D_PUBLICKEY 164
1193#define ASN1_F_I2D_RSA_NET 162
1194#define ASN1_F_I2D_RSA_PUBKEY 165 1022#define ASN1_F_I2D_RSA_PUBKEY 165
1195#define ASN1_F_LONG_C2I 166 1023#define ASN1_F_LONG_C2I 166
1196#define ASN1_F_OID_MODULE_INIT 174 1024#define ASN1_F_OID_MODULE_INIT 174
1197#define ASN1_F_PARSE_TAGGING 182
1198#define ASN1_F_PKCS5_PBE2_SET 167 1025#define ASN1_F_PKCS5_PBE2_SET 167
1199#define ASN1_F_PKCS5_PBE_SET 202
1200#define ASN1_F_SMIME_READ_ASN1 210
1201#define ASN1_F_SMIME_TEXT 211
1202#define ASN1_F_X509_CINF_NEW 168 1026#define ASN1_F_X509_CINF_NEW 168
1203#define ASN1_F_X509_CRL_ADD0_REVOKED 169 1027#define ASN1_F_X509_CRL_ADD0_REVOKED 169
1204#define ASN1_F_X509_INFO_NEW 170 1028#define ASN1_F_X509_INFO_NEW 170
1205#define ASN1_F_X509_NAME_ENCODE 203 1029#define ASN1_F_X509_NAME_NEW 171
1206#define ASN1_F_X509_NAME_EX_D2I 158
1207#define ASN1_F_X509_NAME_EX_NEW 171
1208#define ASN1_F_X509_NEW 172 1030#define ASN1_F_X509_NEW 172
1209#define ASN1_F_X509_PKEY_NEW 173 1031#define ASN1_F_X509_PKEY_NEW 173
1210 1032
1211/* Reason codes. */ 1033/* Reason codes. */
1212#define ASN1_R_ADDING_OBJECT 171 1034#define ASN1_R_ADDING_OBJECT 171
1213#define ASN1_R_ASN1_PARSE_ERROR 198
1214#define ASN1_R_ASN1_SIG_PARSE_ERROR 199
1215#define ASN1_R_AUX_ERROR 100 1035#define ASN1_R_AUX_ERROR 100
1216#define ASN1_R_BAD_CLASS 101 1036#define ASN1_R_BAD_CLASS 101
1217#define ASN1_R_BAD_OBJECT_HEADER 102 1037#define ASN1_R_BAD_OBJECT_HEADER 102
@@ -1224,7 +1044,6 @@ void ERR_load_ASN1_strings(void);
1224#define ASN1_R_DATA_IS_WRONG 109 1044#define ASN1_R_DATA_IS_WRONG 109
1225#define ASN1_R_DECODE_ERROR 110 1045#define ASN1_R_DECODE_ERROR 110
1226#define ASN1_R_DECODING_ERROR 111 1046#define ASN1_R_DECODING_ERROR 111
1227#define ASN1_R_DEPTH_EXCEEDED 174
1228#define ASN1_R_ENCODE_ERROR 112 1047#define ASN1_R_ENCODE_ERROR 112
1229#define ASN1_R_ERROR_GETTING_TIME 173 1048#define ASN1_R_ERROR_GETTING_TIME 173
1230#define ASN1_R_ERROR_LOADING_SECTION 172 1049#define ASN1_R_ERROR_LOADING_SECTION 172
@@ -1239,68 +1058,39 @@ void ERR_load_ASN1_strings(void);
1239#define ASN1_R_FIELD_MISSING 121 1058#define ASN1_R_FIELD_MISSING 121
1240#define ASN1_R_FIRST_NUM_TOO_LARGE 122 1059#define ASN1_R_FIRST_NUM_TOO_LARGE 122
1241#define ASN1_R_HEADER_TOO_LONG 123 1060#define ASN1_R_HEADER_TOO_LONG 123
1242#define ASN1_R_ILLEGAL_BITSTRING_FORMAT 175
1243#define ASN1_R_ILLEGAL_BOOLEAN 176
1244#define ASN1_R_ILLEGAL_CHARACTERS 124 1061#define ASN1_R_ILLEGAL_CHARACTERS 124
1245#define ASN1_R_ILLEGAL_FORMAT 177
1246#define ASN1_R_ILLEGAL_HEX 178
1247#define ASN1_R_ILLEGAL_IMPLICIT_TAG 179
1248#define ASN1_R_ILLEGAL_INTEGER 180
1249#define ASN1_R_ILLEGAL_NESTED_TAGGING 181
1250#define ASN1_R_ILLEGAL_NULL 125 1062#define ASN1_R_ILLEGAL_NULL 125
1251#define ASN1_R_ILLEGAL_NULL_VALUE 182
1252#define ASN1_R_ILLEGAL_OBJECT 183
1253#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126 1063#define ASN1_R_ILLEGAL_OPTIONAL_ANY 126
1254#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170 1064#define ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE 170
1255#define ASN1_R_ILLEGAL_TAGGED_ANY 127 1065#define ASN1_R_ILLEGAL_TAGGED_ANY 127
1256#define ASN1_R_ILLEGAL_TIME_VALUE 184
1257#define ASN1_R_INTEGER_NOT_ASCII_FORMAT 185
1258#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128 1066#define ASN1_R_INTEGER_TOO_LARGE_FOR_LONG 128
1259#define ASN1_R_INVALID_BMPSTRING_LENGTH 129 1067#define ASN1_R_INVALID_BMPSTRING_LENGTH 129
1260#define ASN1_R_INVALID_DIGIT 130 1068#define ASN1_R_INVALID_DIGIT 130
1261#define ASN1_R_INVALID_MIME_TYPE 200
1262#define ASN1_R_INVALID_MODIFIER 186
1263#define ASN1_R_INVALID_NUMBER 187
1264#define ASN1_R_INVALID_SEPARATOR 131 1069#define ASN1_R_INVALID_SEPARATOR 131
1265#define ASN1_R_INVALID_TIME_FORMAT 132 1070#define ASN1_R_INVALID_TIME_FORMAT 132
1266#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133 1071#define ASN1_R_INVALID_UNIVERSALSTRING_LENGTH 133
1267#define ASN1_R_INVALID_UTF8STRING 134 1072#define ASN1_R_INVALID_UTF8STRING 134
1268#define ASN1_R_IV_TOO_LARGE 135 1073#define ASN1_R_IV_TOO_LARGE 135
1269#define ASN1_R_LENGTH_ERROR 136 1074#define ASN1_R_LENGTH_ERROR 136
1270#define ASN1_R_LIST_ERROR 188
1271#define ASN1_R_MIME_NO_CONTENT_TYPE 201
1272#define ASN1_R_MIME_PARSE_ERROR 202
1273#define ASN1_R_MIME_SIG_PARSE_ERROR 203
1274#define ASN1_R_MISSING_EOC 137 1075#define ASN1_R_MISSING_EOC 137
1275#define ASN1_R_MISSING_SECOND_NUMBER 138 1076#define ASN1_R_MISSING_SECOND_NUMBER 138
1276#define ASN1_R_MISSING_VALUE 189
1277#define ASN1_R_MSTRING_NOT_UNIVERSAL 139 1077#define ASN1_R_MSTRING_NOT_UNIVERSAL 139
1278#define ASN1_R_MSTRING_WRONG_TAG 140 1078#define ASN1_R_MSTRING_WRONG_TAG 140
1279#define ASN1_R_NESTED_ASN1_STRING 197 1079#define ASN1_R_NESTED_ASN1_STRING 174
1280#define ASN1_R_NON_HEX_CHARACTERS 141 1080#define ASN1_R_NON_HEX_CHARACTERS 141
1281#define ASN1_R_NOT_ASCII_FORMAT 190
1282#define ASN1_R_NOT_ENOUGH_DATA 142 1081#define ASN1_R_NOT_ENOUGH_DATA 142
1283#define ASN1_R_NO_CONTENT_TYPE 204
1284#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143 1082#define ASN1_R_NO_MATCHING_CHOICE_TYPE 143
1285#define ASN1_R_NO_MULTIPART_BODY_FAILURE 205
1286#define ASN1_R_NO_MULTIPART_BOUNDARY 206
1287#define ASN1_R_NO_SIG_CONTENT_TYPE 207
1288#define ASN1_R_NULL_IS_WRONG_LENGTH 144 1083#define ASN1_R_NULL_IS_WRONG_LENGTH 144
1289#define ASN1_R_OBJECT_NOT_ASCII_FORMAT 191
1290#define ASN1_R_ODD_NUMBER_OF_CHARS 145 1084#define ASN1_R_ODD_NUMBER_OF_CHARS 145
1291#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146 1085#define ASN1_R_PRIVATE_KEY_HEADER_MISSING 146
1292#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147 1086#define ASN1_R_SECOND_NUMBER_TOO_LARGE 147
1293#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148 1087#define ASN1_R_SEQUENCE_LENGTH_MISMATCH 148
1294#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149 1088#define ASN1_R_SEQUENCE_NOT_CONSTRUCTED 149
1295#define ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG 192
1296#define ASN1_R_SHORT_LINE 150 1089#define ASN1_R_SHORT_LINE 150
1297#define ASN1_R_SIG_INVALID_MIME_TYPE 208
1298#define ASN1_R_STREAMING_NOT_SUPPORTED 209
1299#define ASN1_R_STRING_TOO_LONG 151 1090#define ASN1_R_STRING_TOO_LONG 151
1300#define ASN1_R_STRING_TOO_SHORT 152 1091#define ASN1_R_STRING_TOO_SHORT 152
1301#define ASN1_R_TAG_VALUE_TOO_HIGH 153 1092#define ASN1_R_TAG_VALUE_TOO_HIGH 153
1302#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154 1093#define ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD 154
1303#define ASN1_R_TIME_NOT_ASCII_FORMAT 193
1304#define ASN1_R_TOO_LONG 155 1094#define ASN1_R_TOO_LONG 155
1305#define ASN1_R_TYPE_NOT_CONSTRUCTED 156 1095#define ASN1_R_TYPE_NOT_CONSTRUCTED 156
1306#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157 1096#define ASN1_R_UNABLE_TO_DECODE_RSA_KEY 157
@@ -1310,13 +1100,10 @@ void ERR_load_ASN1_strings(void);
1310#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161 1100#define ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM 161
1311#define ASN1_R_UNKNOWN_OBJECT_TYPE 162 1101#define ASN1_R_UNKNOWN_OBJECT_TYPE 162
1312#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163 1102#define ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE 163
1313#define ASN1_R_UNKNOWN_TAG 194
1314#define ASN1_R_UNKOWN_FORMAT 195
1315#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164 1103#define ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE 164
1316#define ASN1_R_UNSUPPORTED_CIPHER 165 1104#define ASN1_R_UNSUPPORTED_CIPHER 165
1317#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166 1105#define ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM 166
1318#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167 1106#define ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE 167
1319#define ASN1_R_UNSUPPORTED_TYPE 196
1320#define ASN1_R_WRONG_TAG 168 1107#define ASN1_R_WRONG_TAG 168
1321#define ASN1_R_WRONG_TYPE 169 1108#define ASN1_R_WRONG_TYPE 169
1322 1109
diff --git a/src/lib/libcrypto/asn1/asn1_err.c b/src/lib/libcrypto/asn1/asn1_err.c
index f8a3e2e6cd..315d0a0807 100644
--- a/src/lib/libcrypto/asn1/asn1_err.c
+++ b/src/lib/libcrypto/asn1/asn1_err.c
@@ -1,6 +1,6 @@
1/* crypto/asn1/asn1_err.c */ 1/* crypto/asn1/asn1_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -74,70 +74,49 @@ static ERR_STRING_DATA ASN1_str_functs[]=
74{ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"}, 74{ERR_FUNC(ASN1_F_A2I_ASN1_ENUMERATED), "a2i_ASN1_ENUMERATED"},
75{ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"}, 75{ERR_FUNC(ASN1_F_A2I_ASN1_INTEGER), "a2i_ASN1_INTEGER"},
76{ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"}, 76{ERR_FUNC(ASN1_F_A2I_ASN1_STRING), "a2i_ASN1_STRING"},
77{ERR_FUNC(ASN1_F_APPEND_EXP), "APPEND_EXP"},
78{ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"}, 77{ERR_FUNC(ASN1_F_ASN1_BIT_STRING_SET_BIT), "ASN1_BIT_STRING_set_bit"},
79{ERR_FUNC(ASN1_F_ASN1_CB), "ASN1_CB"},
80{ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"}, 78{ERR_FUNC(ASN1_F_ASN1_CHECK_TLEN), "ASN1_CHECK_TLEN"},
81{ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"}, 79{ERR_FUNC(ASN1_F_ASN1_COLLATE_PRIMITIVE), "ASN1_COLLATE_PRIMITIVE"},
82{ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"}, 80{ERR_FUNC(ASN1_F_ASN1_COLLECT), "ASN1_COLLECT"},
81{ERR_FUNC(ASN1_F_ASN1_D2I_BIO), "ASN1_d2i_bio"},
83{ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"}, 82{ERR_FUNC(ASN1_F_ASN1_D2I_EX_PRIMITIVE), "ASN1_D2I_EX_PRIMITIVE"},
84{ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"}, 83{ERR_FUNC(ASN1_F_ASN1_D2I_FP), "ASN1_d2i_fp"},
85{ERR_FUNC(ASN1_F_ASN1_D2I_READ_BIO), "ASN1_D2I_READ_BIO"},
86{ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"}, 84{ERR_FUNC(ASN1_F_ASN1_DIGEST), "ASN1_digest"},
87{ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"}, 85{ERR_FUNC(ASN1_F_ASN1_DO_ADB), "ASN1_DO_ADB"},
88{ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"}, 86{ERR_FUNC(ASN1_F_ASN1_DUP), "ASN1_dup"},
89{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"}, 87{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_SET), "ASN1_ENUMERATED_set"},
90{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"}, 88{ERR_FUNC(ASN1_F_ASN1_ENUMERATED_TO_BN), "ASN1_ENUMERATED_to_BN"},
91{ERR_FUNC(ASN1_F_ASN1_EX_C2I), "ASN1_EX_C2I"},
92{ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"}, 89{ERR_FUNC(ASN1_F_ASN1_FIND_END), "ASN1_FIND_END"},
93{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"}, 90{ERR_FUNC(ASN1_F_ASN1_GENERALIZEDTIME_SET), "ASN1_GENERALIZEDTIME_set"},
94{ERR_FUNC(ASN1_F_ASN1_GENERATE_V3), "ASN1_generate_v3"},
95{ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"}, 91{ERR_FUNC(ASN1_F_ASN1_GET_OBJECT), "ASN1_get_object"},
96{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_new"}, 92{ERR_FUNC(ASN1_F_ASN1_HEADER_NEW), "ASN1_HEADER_new"},
97{ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"}, 93{ERR_FUNC(ASN1_F_ASN1_I2D_BIO), "ASN1_i2d_bio"},
98{ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"}, 94{ERR_FUNC(ASN1_F_ASN1_I2D_FP), "ASN1_i2d_fp"},
99{ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"}, 95{ERR_FUNC(ASN1_F_ASN1_INTEGER_SET), "ASN1_INTEGER_set"},
100{ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"}, 96{ERR_FUNC(ASN1_F_ASN1_INTEGER_TO_BN), "ASN1_INTEGER_to_BN"},
101{ERR_FUNC(ASN1_F_ASN1_ITEM_D2I_FP), "ASN1_item_d2i_fp"},
102{ERR_FUNC(ASN1_F_ASN1_ITEM_DUP), "ASN1_item_dup"},
103{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW), "ASN1_ITEM_EX_COMBINE_NEW"},
104{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"}, 97{ERR_FUNC(ASN1_F_ASN1_ITEM_EX_D2I), "ASN1_ITEM_EX_D2I"},
105{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_BIO), "ASN1_item_i2d_bio"}, 98{ERR_FUNC(ASN1_F_ASN1_ITEM_NEW), "ASN1_item_new"},
106{ERR_FUNC(ASN1_F_ASN1_ITEM_I2D_FP), "ASN1_item_i2d_fp"}, 99{ERR_FUNC(ASN1_F_ASN1_MBSTRING_COPY), "ASN1_mbstring_copy"},
107{ERR_FUNC(ASN1_F_ASN1_ITEM_PACK), "ASN1_item_pack"},
108{ERR_FUNC(ASN1_F_ASN1_ITEM_SIGN), "ASN1_item_sign"},
109{ERR_FUNC(ASN1_F_ASN1_ITEM_UNPACK), "ASN1_item_unpack"},
110{ERR_FUNC(ASN1_F_ASN1_ITEM_VERIFY), "ASN1_item_verify"},
111{ERR_FUNC(ASN1_F_ASN1_MBSTRING_NCOPY), "ASN1_mbstring_ncopy"},
112{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"}, 100{ERR_FUNC(ASN1_F_ASN1_OBJECT_NEW), "ASN1_OBJECT_new"},
113{ERR_FUNC(ASN1_F_ASN1_OUTPUT_DATA), "ASN1_OUTPUT_DATA"},
114{ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"}, 101{ERR_FUNC(ASN1_F_ASN1_PACK_STRING), "ASN1_pack_string"},
115{ERR_FUNC(ASN1_F_ASN1_PCTX_NEW), "ASN1_PCTX_NEW"}, 102{ERR_FUNC(ASN1_F_ASN1_PBE_SET), "ASN1_PBE_SET"},
116{ERR_FUNC(ASN1_F_ASN1_PKCS5_PBE_SET), "ASN1_PKCS5_PBE_SET"},
117{ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"}, 103{ERR_FUNC(ASN1_F_ASN1_SEQ_PACK), "ASN1_seq_pack"},
118{ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"}, 104{ERR_FUNC(ASN1_F_ASN1_SEQ_UNPACK), "ASN1_seq_unpack"},
119{ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"}, 105{ERR_FUNC(ASN1_F_ASN1_SIGN), "ASN1_sign"},
120{ERR_FUNC(ASN1_F_ASN1_STR2TYPE), "ASN1_STR2TYPE"},
121{ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"}, 106{ERR_FUNC(ASN1_F_ASN1_STRING_SET), "ASN1_STRING_set"},
122{ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"}, 107{ERR_FUNC(ASN1_F_ASN1_STRING_TABLE_ADD), "ASN1_STRING_TABLE_add"},
123{ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"}, 108{ERR_FUNC(ASN1_F_ASN1_STRING_TYPE_NEW), "ASN1_STRING_type_new"},
109{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_D2I), "ASN1_TEMPLATE_D2I"},
124{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"}, 110{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_EX_D2I), "ASN1_TEMPLATE_EX_D2I"},
125{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"}, 111{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NEW), "ASN1_TEMPLATE_NEW"},
126{ERR_FUNC(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I), "ASN1_TEMPLATE_NOEXP_D2I"},
127{ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"}, 112{ERR_FUNC(ASN1_F_ASN1_TIME_SET), "ASN1_TIME_set"},
128{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), "ASN1_TYPE_get_int_octetstring"}, 113{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_INT_OCTETSTRING), "ASN1_TYPE_get_int_octetstring"},
129{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"}, 114{ERR_FUNC(ASN1_F_ASN1_TYPE_GET_OCTETSTRING), "ASN1_TYPE_get_octetstring"},
130{ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"}, 115{ERR_FUNC(ASN1_F_ASN1_UNPACK_STRING), "ASN1_unpack_string"},
131{ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"}, 116{ERR_FUNC(ASN1_F_ASN1_UTCTIME_SET), "ASN1_UTCTIME_set"},
132{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"}, 117{ERR_FUNC(ASN1_F_ASN1_VERIFY), "ASN1_verify"},
133{ERR_FUNC(ASN1_F_B64_READ_ASN1), "B64_READ_ASN1"},
134{ERR_FUNC(ASN1_F_B64_WRITE_ASN1), "B64_WRITE_ASN1"},
135{ERR_FUNC(ASN1_F_BITSTR_CB), "BITSTR_CB"},
136{ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"}, 118{ERR_FUNC(ASN1_F_BN_TO_ASN1_ENUMERATED), "BN_to_ASN1_ENUMERATED"},
137{ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"}, 119{ERR_FUNC(ASN1_F_BN_TO_ASN1_INTEGER), "BN_to_ASN1_INTEGER"},
138{ERR_FUNC(ASN1_F_C2I_ASN1_BIT_STRING), "c2i_ASN1_BIT_STRING"},
139{ERR_FUNC(ASN1_F_C2I_ASN1_INTEGER), "c2i_ASN1_INTEGER"},
140{ERR_FUNC(ASN1_F_C2I_ASN1_OBJECT), "c2i_ASN1_OBJECT"},
141{ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"}, 120{ERR_FUNC(ASN1_F_COLLECT_DATA), "COLLECT_DATA"},
142{ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"}, 121{ERR_FUNC(ASN1_F_D2I_ASN1_BIT_STRING), "D2I_ASN1_BIT_STRING"},
143{ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"}, 122{ERR_FUNC(ASN1_F_D2I_ASN1_BOOLEAN), "d2i_ASN1_BOOLEAN"},
@@ -154,32 +133,24 @@ static ERR_STRING_DATA ASN1_str_functs[]=
154{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"}, 133{ERR_FUNC(ASN1_F_D2I_NETSCAPE_RSA_2), "D2I_NETSCAPE_RSA_2"},
155{ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"}, 134{ERR_FUNC(ASN1_F_D2I_PRIVATEKEY), "d2i_PrivateKey"},
156{ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"}, 135{ERR_FUNC(ASN1_F_D2I_PUBLICKEY), "d2i_PublicKey"},
157{ERR_FUNC(ASN1_F_D2I_RSA_NET), "d2i_RSA_NET"},
158{ERR_FUNC(ASN1_F_D2I_RSA_NET_2), "D2I_RSA_NET_2"},
159{ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"}, 136{ERR_FUNC(ASN1_F_D2I_X509), "D2I_X509"},
160{ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"}, 137{ERR_FUNC(ASN1_F_D2I_X509_CINF), "D2I_X509_CINF"},
138{ERR_FUNC(ASN1_F_D2I_X509_NAME), "D2I_X509_NAME"},
161{ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"}, 139{ERR_FUNC(ASN1_F_D2I_X509_PKEY), "d2i_X509_PKEY"},
162{ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"}, 140{ERR_FUNC(ASN1_F_I2D_ASN1_SET), "i2d_ASN1_SET"},
163{ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"}, 141{ERR_FUNC(ASN1_F_I2D_ASN1_TIME), "I2D_ASN1_TIME"},
164{ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"}, 142{ERR_FUNC(ASN1_F_I2D_DSA_PUBKEY), "i2d_DSA_PUBKEY"},
165{ERR_FUNC(ASN1_F_I2D_EC_PUBKEY), "i2d_EC_PUBKEY"}, 143{ERR_FUNC(ASN1_F_I2D_NETSCAPE_RSA), "i2d_Netscape_RSA"},
166{ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"}, 144{ERR_FUNC(ASN1_F_I2D_PRIVATEKEY), "i2d_PrivateKey"},
167{ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"}, 145{ERR_FUNC(ASN1_F_I2D_PUBLICKEY), "i2d_PublicKey"},
168{ERR_FUNC(ASN1_F_I2D_RSA_NET), "i2d_RSA_NET"},
169{ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"}, 146{ERR_FUNC(ASN1_F_I2D_RSA_PUBKEY), "i2d_RSA_PUBKEY"},
170{ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"}, 147{ERR_FUNC(ASN1_F_LONG_C2I), "LONG_C2I"},
171{ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"}, 148{ERR_FUNC(ASN1_F_OID_MODULE_INIT), "OID_MODULE_INIT"},
172{ERR_FUNC(ASN1_F_PARSE_TAGGING), "PARSE_TAGGING"},
173{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET), "PKCS5_pbe2_set"}, 149{ERR_FUNC(ASN1_F_PKCS5_PBE2_SET), "PKCS5_pbe2_set"},
174{ERR_FUNC(ASN1_F_PKCS5_PBE_SET), "PKCS5_pbe_set"},
175{ERR_FUNC(ASN1_F_SMIME_READ_ASN1), "SMIME_read_ASN1"},
176{ERR_FUNC(ASN1_F_SMIME_TEXT), "SMIME_text"},
177{ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"}, 150{ERR_FUNC(ASN1_F_X509_CINF_NEW), "X509_CINF_NEW"},
178{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"}, 151{ERR_FUNC(ASN1_F_X509_CRL_ADD0_REVOKED), "X509_CRL_add0_revoked"},
179{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"}, 152{ERR_FUNC(ASN1_F_X509_INFO_NEW), "X509_INFO_new"},
180{ERR_FUNC(ASN1_F_X509_NAME_ENCODE), "X509_NAME_ENCODE"}, 153{ERR_FUNC(ASN1_F_X509_NAME_NEW), "X509_NAME_NEW"},
181{ERR_FUNC(ASN1_F_X509_NAME_EX_D2I), "X509_NAME_EX_D2I"},
182{ERR_FUNC(ASN1_F_X509_NAME_EX_NEW), "X509_NAME_EX_NEW"},
183{ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"}, 154{ERR_FUNC(ASN1_F_X509_NEW), "X509_NEW"},
184{ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"}, 155{ERR_FUNC(ASN1_F_X509_PKEY_NEW), "X509_PKEY_new"},
185{0,NULL} 156{0,NULL}
@@ -188,8 +159,6 @@ static ERR_STRING_DATA ASN1_str_functs[]=
188static ERR_STRING_DATA ASN1_str_reasons[]= 159static ERR_STRING_DATA ASN1_str_reasons[]=
189 { 160 {
190{ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"}, 161{ERR_REASON(ASN1_R_ADDING_OBJECT) ,"adding object"},
191{ERR_REASON(ASN1_R_ASN1_PARSE_ERROR) ,"asn1 parse error"},
192{ERR_REASON(ASN1_R_ASN1_SIG_PARSE_ERROR) ,"asn1 sig parse error"},
193{ERR_REASON(ASN1_R_AUX_ERROR) ,"aux error"}, 162{ERR_REASON(ASN1_R_AUX_ERROR) ,"aux error"},
194{ERR_REASON(ASN1_R_BAD_CLASS) ,"bad class"}, 163{ERR_REASON(ASN1_R_BAD_CLASS) ,"bad class"},
195{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) ,"bad object header"}, 164{ERR_REASON(ASN1_R_BAD_OBJECT_HEADER) ,"bad object header"},
@@ -202,7 +171,6 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
202{ERR_REASON(ASN1_R_DATA_IS_WRONG) ,"data is wrong"}, 171{ERR_REASON(ASN1_R_DATA_IS_WRONG) ,"data is wrong"},
203{ERR_REASON(ASN1_R_DECODE_ERROR) ,"decode error"}, 172{ERR_REASON(ASN1_R_DECODE_ERROR) ,"decode error"},
204{ERR_REASON(ASN1_R_DECODING_ERROR) ,"decoding error"}, 173{ERR_REASON(ASN1_R_DECODING_ERROR) ,"decoding error"},
205{ERR_REASON(ASN1_R_DEPTH_EXCEEDED) ,"depth exceeded"},
206{ERR_REASON(ASN1_R_ENCODE_ERROR) ,"encode error"}, 174{ERR_REASON(ASN1_R_ENCODE_ERROR) ,"encode error"},
207{ERR_REASON(ASN1_R_ERROR_GETTING_TIME) ,"error getting time"}, 175{ERR_REASON(ASN1_R_ERROR_GETTING_TIME) ,"error getting time"},
208{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),"error loading section"}, 176{ERR_REASON(ASN1_R_ERROR_LOADING_SECTION),"error loading section"},
@@ -217,68 +185,39 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
217{ERR_REASON(ASN1_R_FIELD_MISSING) ,"field missing"}, 185{ERR_REASON(ASN1_R_FIELD_MISSING) ,"field missing"},
218{ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE) ,"first num too large"}, 186{ERR_REASON(ASN1_R_FIRST_NUM_TOO_LARGE) ,"first num too large"},
219{ERR_REASON(ASN1_R_HEADER_TOO_LONG) ,"header too long"}, 187{ERR_REASON(ASN1_R_HEADER_TOO_LONG) ,"header too long"},
220{ERR_REASON(ASN1_R_ILLEGAL_BITSTRING_FORMAT),"illegal bitstring format"},
221{ERR_REASON(ASN1_R_ILLEGAL_BOOLEAN) ,"illegal boolean"},
222{ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS) ,"illegal characters"}, 188{ERR_REASON(ASN1_R_ILLEGAL_CHARACTERS) ,"illegal characters"},
223{ERR_REASON(ASN1_R_ILLEGAL_FORMAT) ,"illegal format"},
224{ERR_REASON(ASN1_R_ILLEGAL_HEX) ,"illegal hex"},
225{ERR_REASON(ASN1_R_ILLEGAL_IMPLICIT_TAG) ,"illegal implicit tag"},
226{ERR_REASON(ASN1_R_ILLEGAL_INTEGER) ,"illegal integer"},
227{ERR_REASON(ASN1_R_ILLEGAL_NESTED_TAGGING),"illegal nested tagging"},
228{ERR_REASON(ASN1_R_ILLEGAL_NULL) ,"illegal null"}, 189{ERR_REASON(ASN1_R_ILLEGAL_NULL) ,"illegal null"},
229{ERR_REASON(ASN1_R_ILLEGAL_NULL_VALUE) ,"illegal null value"},
230{ERR_REASON(ASN1_R_ILLEGAL_OBJECT) ,"illegal object"},
231{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY) ,"illegal optional any"}, 190{ERR_REASON(ASN1_R_ILLEGAL_OPTIONAL_ANY) ,"illegal optional any"},
232{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),"illegal options on item template"}, 191{ERR_REASON(ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE),"illegal options on item template"},
233{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY) ,"illegal tagged any"}, 192{ERR_REASON(ASN1_R_ILLEGAL_TAGGED_ANY) ,"illegal tagged any"},
234{ERR_REASON(ASN1_R_ILLEGAL_TIME_VALUE) ,"illegal time value"},
235{ERR_REASON(ASN1_R_INTEGER_NOT_ASCII_FORMAT),"integer not ascii format"},
236{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"}, 193{ERR_REASON(ASN1_R_INTEGER_TOO_LARGE_FOR_LONG),"integer too large for long"},
237{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"}, 194{ERR_REASON(ASN1_R_INVALID_BMPSTRING_LENGTH),"invalid bmpstring length"},
238{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"}, 195{ERR_REASON(ASN1_R_INVALID_DIGIT) ,"invalid digit"},
239{ERR_REASON(ASN1_R_INVALID_MIME_TYPE) ,"invalid mime type"},
240{ERR_REASON(ASN1_R_INVALID_MODIFIER) ,"invalid modifier"},
241{ERR_REASON(ASN1_R_INVALID_NUMBER) ,"invalid number"},
242{ERR_REASON(ASN1_R_INVALID_SEPARATOR) ,"invalid separator"}, 196{ERR_REASON(ASN1_R_INVALID_SEPARATOR) ,"invalid separator"},
243{ERR_REASON(ASN1_R_INVALID_TIME_FORMAT) ,"invalid time format"}, 197{ERR_REASON(ASN1_R_INVALID_TIME_FORMAT) ,"invalid time format"},
244{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),"invalid universalstring length"}, 198{ERR_REASON(ASN1_R_INVALID_UNIVERSALSTRING_LENGTH),"invalid universalstring length"},
245{ERR_REASON(ASN1_R_INVALID_UTF8STRING) ,"invalid utf8string"}, 199{ERR_REASON(ASN1_R_INVALID_UTF8STRING) ,"invalid utf8string"},
246{ERR_REASON(ASN1_R_IV_TOO_LARGE) ,"iv too large"}, 200{ERR_REASON(ASN1_R_IV_TOO_LARGE) ,"iv too large"},
247{ERR_REASON(ASN1_R_LENGTH_ERROR) ,"length error"}, 201{ERR_REASON(ASN1_R_LENGTH_ERROR) ,"length error"},
248{ERR_REASON(ASN1_R_LIST_ERROR) ,"list error"},
249{ERR_REASON(ASN1_R_MIME_NO_CONTENT_TYPE) ,"mime no content type"},
250{ERR_REASON(ASN1_R_MIME_PARSE_ERROR) ,"mime parse error"},
251{ERR_REASON(ASN1_R_MIME_SIG_PARSE_ERROR) ,"mime sig parse error"},
252{ERR_REASON(ASN1_R_MISSING_EOC) ,"missing eoc"}, 202{ERR_REASON(ASN1_R_MISSING_EOC) ,"missing eoc"},
253{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER),"missing second number"}, 203{ERR_REASON(ASN1_R_MISSING_SECOND_NUMBER),"missing second number"},
254{ERR_REASON(ASN1_R_MISSING_VALUE) ,"missing value"},
255{ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL),"mstring not universal"}, 204{ERR_REASON(ASN1_R_MSTRING_NOT_UNIVERSAL),"mstring not universal"},
256{ERR_REASON(ASN1_R_MSTRING_WRONG_TAG) ,"mstring wrong tag"}, 205{ERR_REASON(ASN1_R_MSTRING_WRONG_TAG) ,"mstring wrong tag"},
257{ERR_REASON(ASN1_R_NESTED_ASN1_STRING) ,"nested asn1 string"}, 206{ERR_REASON(ASN1_R_NESTED_ASN1_STRING) ,"nested asn1 string"},
258{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) ,"non hex characters"}, 207{ERR_REASON(ASN1_R_NON_HEX_CHARACTERS) ,"non hex characters"},
259{ERR_REASON(ASN1_R_NOT_ASCII_FORMAT) ,"not ascii format"},
260{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) ,"not enough data"}, 208{ERR_REASON(ASN1_R_NOT_ENOUGH_DATA) ,"not enough data"},
261{ERR_REASON(ASN1_R_NO_CONTENT_TYPE) ,"no content type"},
262{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"}, 209{ERR_REASON(ASN1_R_NO_MATCHING_CHOICE_TYPE),"no matching choice type"},
263{ERR_REASON(ASN1_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
264{ERR_REASON(ASN1_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
265{ERR_REASON(ASN1_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
266{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) ,"null is wrong length"}, 210{ERR_REASON(ASN1_R_NULL_IS_WRONG_LENGTH) ,"null is wrong length"},
267{ERR_REASON(ASN1_R_OBJECT_NOT_ASCII_FORMAT),"object not ascii format"},
268{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) ,"odd number of chars"}, 211{ERR_REASON(ASN1_R_ODD_NUMBER_OF_CHARS) ,"odd number of chars"},
269{ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING),"private key header missing"}, 212{ERR_REASON(ASN1_R_PRIVATE_KEY_HEADER_MISSING),"private key header missing"},
270{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE),"second number too large"}, 213{ERR_REASON(ASN1_R_SECOND_NUMBER_TOO_LARGE),"second number too large"},
271{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH),"sequence length mismatch"}, 214{ERR_REASON(ASN1_R_SEQUENCE_LENGTH_MISMATCH),"sequence length mismatch"},
272{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED),"sequence not constructed"}, 215{ERR_REASON(ASN1_R_SEQUENCE_NOT_CONSTRUCTED),"sequence not constructed"},
273{ERR_REASON(ASN1_R_SEQUENCE_OR_SET_NEEDS_CONFIG),"sequence or set needs config"},
274{ERR_REASON(ASN1_R_SHORT_LINE) ,"short line"}, 216{ERR_REASON(ASN1_R_SHORT_LINE) ,"short line"},
275{ERR_REASON(ASN1_R_SIG_INVALID_MIME_TYPE),"sig invalid mime type"},
276{ERR_REASON(ASN1_R_STREAMING_NOT_SUPPORTED),"streaming not supported"},
277{ERR_REASON(ASN1_R_STRING_TOO_LONG) ,"string too long"}, 217{ERR_REASON(ASN1_R_STRING_TOO_LONG) ,"string too long"},
278{ERR_REASON(ASN1_R_STRING_TOO_SHORT) ,"string too short"}, 218{ERR_REASON(ASN1_R_STRING_TOO_SHORT) ,"string too short"},
279{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) ,"tag value too high"}, 219{ERR_REASON(ASN1_R_TAG_VALUE_TOO_HIGH) ,"tag value too high"},
280{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"}, 220{ERR_REASON(ASN1_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"},
281{ERR_REASON(ASN1_R_TIME_NOT_ASCII_FORMAT),"time not ascii format"},
282{ERR_REASON(ASN1_R_TOO_LONG) ,"too long"}, 221{ERR_REASON(ASN1_R_TOO_LONG) ,"too long"},
283{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) ,"type not constructed"}, 222{ERR_REASON(ASN1_R_TYPE_NOT_CONSTRUCTED) ,"type not constructed"},
284{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY),"unable to decode rsa key"}, 223{ERR_REASON(ASN1_R_UNABLE_TO_DECODE_RSA_KEY),"unable to decode rsa key"},
@@ -288,13 +227,10 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
288{ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),"unknown message digest algorithm"}, 227{ERR_REASON(ASN1_R_UNKNOWN_MESSAGE_DIGEST_ALGORITHM),"unknown message digest algorithm"},
289{ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE) ,"unknown object type"}, 228{ERR_REASON(ASN1_R_UNKNOWN_OBJECT_TYPE) ,"unknown object type"},
290{ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),"unknown public key type"}, 229{ERR_REASON(ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE),"unknown public key type"},
291{ERR_REASON(ASN1_R_UNKNOWN_TAG) ,"unknown tag"},
292{ERR_REASON(ASN1_R_UNKOWN_FORMAT) ,"unkown format"},
293{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),"unsupported any defined by type"}, 230{ERR_REASON(ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE),"unsupported any defined by type"},
294{ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"}, 231{ERR_REASON(ASN1_R_UNSUPPORTED_CIPHER) ,"unsupported cipher"},
295{ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),"unsupported encryption algorithm"}, 232{ERR_REASON(ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM),"unsupported encryption algorithm"},
296{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),"unsupported public key type"}, 233{ERR_REASON(ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE),"unsupported public key type"},
297{ERR_REASON(ASN1_R_UNSUPPORTED_TYPE) ,"unsupported type"},
298{ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"}, 234{ERR_REASON(ASN1_R_WRONG_TAG) ,"wrong tag"},
299{ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"}, 235{ERR_REASON(ASN1_R_WRONG_TYPE) ,"wrong type"},
300{0,NULL} 236{0,NULL}
@@ -304,12 +240,15 @@ static ERR_STRING_DATA ASN1_str_reasons[]=
304 240
305void ERR_load_ASN1_strings(void) 241void ERR_load_ASN1_strings(void)
306 { 242 {
307#ifndef OPENSSL_NO_ERR 243 static int init=1;
308 244
309 if (ERR_func_error_string(ASN1_str_functs[0].error) == NULL) 245 if (init)
310 { 246 {
247 init=0;
248#ifndef OPENSSL_NO_ERR
311 ERR_load_strings(0,ASN1_str_functs); 249 ERR_load_strings(0,ASN1_str_functs);
312 ERR_load_strings(0,ASN1_str_reasons); 250 ERR_load_strings(0,ASN1_str_reasons);
313 }
314#endif 251#endif
252
253 }
315 } 254 }
diff --git a/src/lib/libcrypto/asn1/asn1_lib.c b/src/lib/libcrypto/asn1/asn1_lib.c
index 5af559ef8d..97b9b35f4b 100644
--- a/src/lib/libcrypto/asn1/asn1_lib.c
+++ b/src/lib/libcrypto/asn1/asn1_lib.c
@@ -62,11 +62,11 @@
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#include <openssl/asn1_mac.h> 63#include <openssl/asn1_mac.h>
64 64
65static int asn1_get_length(const unsigned char **pp,int *inf,long *rl,int max); 65static int asn1_get_length(unsigned char **pp,int *inf,long *rl,int max);
66static void asn1_put_length(unsigned char **pp, int length); 66static void asn1_put_length(unsigned char **pp, int length);
67const char ASN1_version[]="ASN.1" OPENSSL_VERSION_PTEXT; 67const char *ASN1_version="ASN.1" OPENSSL_VERSION_PTEXT;
68 68
69static int _asn1_check_infinite_end(const unsigned char **p, long len) 69int ASN1_check_infinite_end(unsigned char **p, long len)
70 { 70 {
71 /* If there is 0 or 1 byte left, the length check should pick 71 /* If there is 0 or 1 byte left, the length check should pick
72 * things up */ 72 * things up */
@@ -80,23 +80,13 @@ static int _asn1_check_infinite_end(const unsigned char **p, long len)
80 return(0); 80 return(0);
81 } 81 }
82 82
83int ASN1_check_infinite_end(unsigned char **p, long len)
84 {
85 return _asn1_check_infinite_end((const unsigned char **)p, len);
86 }
87 83
88int ASN1_const_check_infinite_end(const unsigned char **p, long len) 84int ASN1_get_object(unsigned char **pp, long *plength, int *ptag, int *pclass,
89 { 85 long omax)
90 return _asn1_check_infinite_end(p, len);
91 }
92
93
94int ASN1_get_object(const unsigned char **pp, long *plength, int *ptag,
95 int *pclass, long omax)
96 { 86 {
97 int i,ret; 87 int i,ret;
98 long l; 88 long l;
99 const unsigned char *p= *pp; 89 unsigned char *p= *pp;
100 int tag,xclass,inf; 90 int tag,xclass,inf;
101 long max=omax; 91 long max=omax;
102 92
@@ -151,11 +141,11 @@ err:
151 return(0x80); 141 return(0x80);
152 } 142 }
153 143
154static int asn1_get_length(const unsigned char **pp, int *inf, long *rl, int max) 144static int asn1_get_length(unsigned char **pp, int *inf, long *rl, int max)
155 { 145 {
156 const unsigned char *p= *pp; 146 unsigned char *p= *pp;
157 unsigned long ret=0; 147 unsigned long ret=0;
158 unsigned int i; 148 int i;
159 149
160 if (max-- < 1) return(0); 150 if (max-- < 1) return(0);
161 if (*p == 0x80) 151 if (*p == 0x80)
@@ -215,22 +205,13 @@ void ASN1_put_object(unsigned char **pp, int constructed, int length, int tag,
215 } 205 }
216 p += ttag; 206 p += ttag;
217 } 207 }
218 if (constructed == 2) 208 if ((constructed == 2) && (length == 0))
219 *(p++)=0x80; 209 *(p++)=0x80; /* der_put_length would output 0 instead */
220 else 210 else
221 asn1_put_length(&p,length); 211 asn1_put_length(&p,length);
222 *pp=p; 212 *pp=p;
223 } 213 }
224 214
225int ASN1_put_eoc(unsigned char **pp)
226 {
227 unsigned char *p = *pp;
228 *p++ = 0;
229 *p++ = 0;
230 *pp = p;
231 return 2;
232 }
233
234static void asn1_put_length(unsigned char **pp, int length) 215static void asn1_put_length(unsigned char **pp, int length)
235 { 216 {
236 unsigned char *p= *pp; 217 unsigned char *p= *pp;
@@ -268,8 +249,8 @@ int ASN1_object_size(int constructed, int length, int tag)
268 ret++; 249 ret++;
269 } 250 }
270 } 251 }
271 if (constructed == 2) 252 if ((length == 0) && (constructed == 2))
272 return ret + 3; 253 ret+=2;
273 ret++; 254 ret++;
274 if (length > 127) 255 if (length > 127)
275 { 256 {
@@ -282,11 +263,11 @@ int ASN1_object_size(int constructed, int length, int tag)
282 return(ret); 263 return(ret);
283 } 264 }
284 265
285static int _asn1_Finish(ASN1_const_CTX *c) 266int asn1_Finish(ASN1_CTX *c)
286 { 267 {
287 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos)) 268 if ((c->inf == (1|V_ASN1_CONSTRUCTED)) && (!c->eos))
288 { 269 {
289 if (!ASN1_const_check_infinite_end(&c->p,c->slen)) 270 if (!ASN1_check_infinite_end(&c->p,c->slen))
290 { 271 {
291 c->error=ERR_R_MISSING_ASN1_EOS; 272 c->error=ERR_R_MISSING_ASN1_EOS;
292 return(0); 273 return(0);
@@ -301,19 +282,9 @@ static int _asn1_Finish(ASN1_const_CTX *c)
301 return(1); 282 return(1);
302 } 283 }
303 284
304int asn1_Finish(ASN1_CTX *c) 285int asn1_GetSequence(ASN1_CTX *c, long *length)
305 {
306 return _asn1_Finish((ASN1_const_CTX *)c);
307 }
308
309int asn1_const_Finish(ASN1_const_CTX *c)
310 { 286 {
311 return _asn1_Finish(c); 287 unsigned char *q;
312 }
313
314int asn1_GetSequence(ASN1_const_CTX *c, long *length)
315 {
316 const unsigned char *q;
317 288
318 q=c->p; 289 q=c->p;
319 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass), 290 c->inf=ASN1_get_object(&(c->p),&(c->slen),&(c->tag),&(c->xclass),
@@ -393,14 +364,6 @@ int ASN1_STRING_set(ASN1_STRING *str, const void *_data, int len)
393 return(1); 364 return(1);
394 } 365 }
395 366
396void ASN1_STRING_set0(ASN1_STRING *str, void *data, int len)
397 {
398 if (str->data)
399 OPENSSL_free(str->data);
400 str->data = data;
401 str->length = len;
402 }
403
404ASN1_STRING *ASN1_STRING_new(void) 367ASN1_STRING *ASN1_STRING_new(void)
405 { 368 {
406 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING)); 369 return(ASN1_STRING_type_new(V_ASN1_OCTET_STRING));
@@ -448,7 +411,7 @@ int ASN1_STRING_cmp(ASN1_STRING *a, ASN1_STRING *b)
448 return(i); 411 return(i);
449 } 412 }
450 413
451void asn1_add_error(const unsigned char *address, int offset) 414void asn1_add_error(unsigned char *address, int offset)
452 { 415 {
453 char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1]; 416 char buf1[DECIMAL_SIZE(address)+1],buf2[DECIMAL_SIZE(offset)+1];
454 417
diff --git a/src/lib/libcrypto/asn1/asn1_mac.h b/src/lib/libcrypto/asn1/asn1_mac.h
index d958ca60d9..a48649ceeb 100644
--- a/src/lib/libcrypto/asn1/asn1_mac.h
+++ b/src/lib/libcrypto/asn1/asn1_mac.h
@@ -73,11 +73,11 @@ extern "C" {
73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line)) 73 ERR_PUT_error(ASN1_MAC_ERR_LIB,(f),(r),__FILE__,(line))
74 74
75#define M_ASN1_D2I_vars(a,type,func) \ 75#define M_ASN1_D2I_vars(a,type,func) \
76 ASN1_const_CTX c; \ 76 ASN1_CTX c; \
77 type ret=NULL; \ 77 type ret=NULL; \
78 \ 78 \
79 c.pp=(const unsigned char **)pp; \ 79 c.pp=(unsigned char **)pp; \
80 c.q= *(const unsigned char **)pp; \ 80 c.q= *(unsigned char **)pp; \
81 c.error=ERR_R_NESTED_ASN1_ERROR; \ 81 c.error=ERR_R_NESTED_ASN1_ERROR; \
82 if ((a == NULL) || ((*a) == NULL)) \ 82 if ((a == NULL) || ((*a) == NULL)) \
83 { if ((ret=(type)func()) == NULL) \ 83 { if ((ret=(type)func()) == NULL) \
@@ -85,13 +85,13 @@ extern "C" {
85 else ret=(*a); 85 else ret=(*a);
86 86
87#define M_ASN1_D2I_Init() \ 87#define M_ASN1_D2I_Init() \
88 c.p= *(const unsigned char **)pp; \ 88 c.p= *(unsigned char **)pp; \
89 c.max=(length == 0)?0:(c.p+length); 89 c.max=(length == 0)?0:(c.p+length);
90 90
91#define M_ASN1_D2I_Finish_2(a) \ 91#define M_ASN1_D2I_Finish_2(a) \
92 if (!asn1_const_Finish(&c)) \ 92 if (!asn1_Finish(&c)) \
93 { c.line=__LINE__; goto err; } \ 93 { c.line=__LINE__; goto err; } \
94 *(const unsigned char **)pp=c.p; \ 94 *(unsigned char **)pp=c.p; \
95 if (a != NULL) (*a)=ret; \ 95 if (a != NULL) (*a)=ret; \
96 return(ret); 96 return(ret);
97 97
@@ -99,7 +99,7 @@ extern "C" {
99 M_ASN1_D2I_Finish_2(a); \ 99 M_ASN1_D2I_Finish_2(a); \
100err:\ 100err:\
101 ASN1_MAC_H_err((e),c.error,c.line); \ 101 ASN1_MAC_H_err((e),c.error,c.line); \
102 asn1_add_error(*(const unsigned char **)pp,(int)(c.q- *pp)); \ 102 asn1_add_error(*(unsigned char **)pp,(int)(c.q- *pp)); \
103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \ 103 if ((ret != NULL) && ((a == NULL) || (*a != ret))) func(ret); \
104 return(NULL) 104 return(NULL)
105 105
@@ -123,22 +123,15 @@ err:\
123 123
124#define M_ASN1_D2I_end_sequence() \ 124#define M_ASN1_D2I_end_sequence() \
125 (((c.inf&1) == 0)?(c.slen <= 0): \ 125 (((c.inf&1) == 0)?(c.slen <= 0): \
126 (c.eos=ASN1_const_check_infinite_end(&c.p,c.slen))) 126 (c.eos=ASN1_check_infinite_end(&c.p,c.slen)))
127 127
128/* Don't use this with d2i_ASN1_BOOLEAN() */ 128/* Don't use this with d2i_ASN1_BOOLEAN() */
129#define M_ASN1_D2I_get(b, func) \ 129#define M_ASN1_D2I_get(b,func) \
130 c.q=c.p; \ 130 c.q=c.p; \
131 if (func(&(b),&c.p,c.slen) == NULL) \ 131 if (func(&(b),&c.p,c.slen) == NULL) \
132 {c.line=__LINE__; goto err; } \ 132 {c.line=__LINE__; goto err; } \
133 c.slen-=(c.p-c.q); 133 c.slen-=(c.p-c.q);
134 134
135/* Don't use this with d2i_ASN1_BOOLEAN() */
136#define M_ASN1_D2I_get_x(type,b,func) \
137 c.q=c.p; \
138 if (((D2I_OF(type))func)(&(b),&c.p,c.slen) == NULL) \
139 {c.line=__LINE__; goto err; } \
140 c.slen-=(c.p-c.q);
141
142/* use this instead () */ 135/* use this instead () */
143#define M_ASN1_D2I_get_int(b,func) \ 136#define M_ASN1_D2I_get_int(b,func) \
144 c.q=c.p; \ 137 c.q=c.p; \
@@ -285,7 +278,7 @@ err:\
285 { c.line=__LINE__; goto err; } \ 278 { c.line=__LINE__; goto err; } \
286 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \ 279 if (Tinf == (V_ASN1_CONSTRUCTED+1)) { \
287 Tlen = c.slen - (c.p - c.q); \ 280 Tlen = c.slen - (c.p - c.q); \
288 if(!ASN1_const_check_infinite_end(&c.p, Tlen)) \ 281 if(!ASN1_check_infinite_end(&c.p, Tlen)) \
289 { c.error=ERR_R_MISSING_ASN1_EOS; \ 282 { c.error=ERR_R_MISSING_ASN1_EOS; \
290 c.line=__LINE__; goto err; } \ 283 c.line=__LINE__; goto err; } \
291 }\ 284 }\
@@ -360,12 +353,8 @@ err:\
360 return(NULL) 353 return(NULL)
361 354
362 355
363/* BIG UGLY WARNING! This is so damn ugly I wanna puke. Unfortunately, 356#define M_ASN1_next (*c.p)
364 some macros that use ASN1_const_CTX still insist on writing in the input 357#define M_ASN1_next_prev (*c.q)
365 stream. ARGH! ARGH! ARGH! Let's get rid of this macro package.
366 Please? -- Richard Levitte */
367#define M_ASN1_next (*((unsigned char *)(c.p)))
368#define M_ASN1_next_prev (*((unsigned char *)(c.q)))
369 358
370/*************************************************/ 359/*************************************************/
371 360
@@ -562,8 +551,8 @@ err:\
562#define M_ASN1_I2D_finish() *pp=p; \ 551#define M_ASN1_I2D_finish() *pp=p; \
563 return(r); 552 return(r);
564 553
565int asn1_GetSequence(ASN1_const_CTX *c, long *length); 554int asn1_GetSequence(ASN1_CTX *c, long *length);
566void asn1_add_error(const unsigned char *address,int offset); 555void asn1_add_error(unsigned char *address,int offset);
567#ifdef __cplusplus 556#ifdef __cplusplus
568} 557}
569#endif 558#endif
diff --git a/src/lib/libcrypto/asn1/asn1_par.c b/src/lib/libcrypto/asn1/asn1_par.c
index 501b62a4b1..676d434f03 100644
--- a/src/lib/libcrypto/asn1/asn1_par.c
+++ b/src/lib/libcrypto/asn1/asn1_par.c
@@ -64,7 +64,7 @@
64 64
65static 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,
66 int indent); 66 int indent);
67static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, 67static int asn1_parse2(BIO *bp, unsigned char **pp, long length,
68 int offset, int depth, int indent, int dump); 68 int offset, int depth, int indent, int dump);
69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed, 69static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
70 int indent) 70 int indent)
@@ -88,10 +88,7 @@ static int asn1_print_info(BIO *bp, int tag, int xclass, int constructed,
88 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag); 88 BIO_snprintf(str,sizeof str,"cont [ %d ]",tag);
89 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION) 89 else if ((xclass & V_ASN1_APPLICATION) == V_ASN1_APPLICATION)
90 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag); 90 BIO_snprintf(str,sizeof str,"appl [ %d ]",tag);
91 else if (tag > 30) 91 else p = ASN1_tag2str(tag);
92 BIO_snprintf(str,sizeof str,"<ASN1 %d>",tag);
93 else
94 p = ASN1_tag2str(tag);
95 92
96 if (p2 != NULL) 93 if (p2 != NULL)
97 { 94 {
@@ -106,20 +103,20 @@ err:
106 return(0); 103 return(0);
107 } 104 }
108 105
109int ASN1_parse(BIO *bp, const unsigned char *pp, long len, int indent) 106int ASN1_parse(BIO *bp, unsigned char *pp, long len, int indent)
110 { 107 {
111 return(asn1_parse2(bp,&pp,len,0,0,indent,0)); 108 return(asn1_parse2(bp,&pp,len,0,0,indent,0));
112 } 109 }
113 110
114int ASN1_parse_dump(BIO *bp, const unsigned char *pp, long len, int indent, int dump) 111int ASN1_parse_dump(BIO *bp, unsigned char *pp, long len, int indent, int dump)
115 { 112 {
116 return(asn1_parse2(bp,&pp,len,0,0,indent,dump)); 113 return(asn1_parse2(bp,&pp,len,0,0,indent,dump));
117 } 114 }
118 115
119static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offset, 116static int asn1_parse2(BIO *bp, unsigned char **pp, long length, int offset,
120 int depth, int indent, int dump) 117 int depth, int indent, int dump)
121 { 118 {
122 const unsigned char *p,*ep,*tot,*op,*opp; 119 unsigned char *p,*ep,*tot,*op,*opp;
123 long len; 120 long len;
124 int tag,xclass,ret=0; 121 int tag,xclass,ret=0;
125 int nl,hl,j,r; 122 int nl,hl,j,r;
@@ -218,7 +215,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
218 { 215 {
219 if (BIO_write(bp,":",1) <= 0) goto end; 216 if (BIO_write(bp,":",1) <= 0) goto end;
220 if ((len > 0) && 217 if ((len > 0) &&
221 BIO_write(bp,(const char *)p,(int)len) 218 BIO_write(bp,(char *)p,(int)len)
222 != (int)len) 219 != (int)len)
223 goto end; 220 goto end;
224 } 221 }
@@ -259,11 +256,9 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
259 256
260 opp=op; 257 opp=op;
261 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl); 258 os=d2i_ASN1_OCTET_STRING(NULL,&opp,len+hl);
262 if (os != NULL && os->length > 0) 259 if (os != NULL)
263 { 260 {
264 opp = os->data; 261 opp=os->data;
265 /* testing whether the octet string is
266 * printable */
267 for (i=0; i<os->length; i++) 262 for (i=0; i<os->length; i++)
268 { 263 {
269 if (( (opp[i] < ' ') && 264 if (( (opp[i] < ' ') &&
@@ -276,47 +271,28 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
276 break; 271 break;
277 } 272 }
278 } 273 }
279 if (printable) 274 if (printable && (os->length > 0))
280 /* printable string */
281 { 275 {
282 if (BIO_write(bp,":",1) <= 0) 276 if (BIO_write(bp,":",1) <= 0)
283 goto end; 277 goto end;
284 if (BIO_write(bp,(const char *)opp, 278 if (BIO_write(bp,(char *)opp,
285 os->length) <= 0) 279 os->length) <= 0)
286 goto end; 280 goto end;
287 } 281 }
288 else if (!dump) 282 if (!printable && (os->length > 0)
289 /* not printable => print octet string 283 && dump)
290 * as hex dump */
291 {
292 if (BIO_write(bp,"[HEX DUMP]:",11) <= 0)
293 goto end;
294 for (i=0; i<os->length; i++)
295 {
296 if (BIO_printf(bp,"%02X"
297 , opp[i]) <= 0)
298 goto end;
299 }
300 }
301 else
302 /* print the normal dump */
303 { 284 {
304 if (!nl) 285 if (!nl)
305 { 286 {
306 if (BIO_write(bp,"\n",1) <= 0) 287 if (BIO_write(bp,"\n",1) <= 0)
307 goto end; 288 goto end;
308 } 289 }
309 if (BIO_dump_indent(bp, 290 if (BIO_dump_indent(bp,(char *)opp,
310 (const char *)opp, 291 ((dump == -1 || dump > os->length)?os->length:dump),
311 ((dump == -1 || dump >
312 os->length)?os->length:dump),
313 dump_indent) <= 0) 292 dump_indent) <= 0)
314 goto end; 293 goto end;
315 nl=1; 294 nl=1;
316 } 295 }
317 }
318 if (os != NULL)
319 {
320 M_ASN1_OCTET_STRING_free(os); 296 M_ASN1_OCTET_STRING_free(os);
321 os=NULL; 297 os=NULL;
322 } 298 }
@@ -392,7 +368,7 @@ static int asn1_parse2(BIO *bp, const unsigned char **pp, long length, int offse
392 if (BIO_write(bp,"\n",1) <= 0) 368 if (BIO_write(bp,"\n",1) <= 0)
393 goto end; 369 goto end;
394 } 370 }
395 if (BIO_dump_indent(bp,(const char *)p, 371 if (BIO_dump_indent(bp,(char *)p,
396 ((dump == -1 || dump > len)?len:dump), 372 ((dump == -1 || dump > len)?len:dump),
397 dump_indent) <= 0) 373 dump_indent) <= 0)
398 goto end; 374 goto end;
@@ -422,7 +398,7 @@ end:
422 398
423const char *ASN1_tag2str(int tag) 399const char *ASN1_tag2str(int tag)
424{ 400{
425 static const char *tag2str[] = { 401 const static char *tag2str[] = {
426 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */ 402 "EOC", "BOOLEAN", "INTEGER", "BIT STRING", "OCTET STRING", /* 0-4 */
427 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */ 403 "NULL", "OBJECT", "OBJECT DESCRIPTOR", "EXTERNAL", "REAL", /* 5-9 */
428 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */ 404 "ENUMERATED", "<ASN1 11>", "UTF8STRING", "<ASN1 13>", /* 10-13 */
diff --git a/src/lib/libcrypto/asn1/asn1t.h b/src/lib/libcrypto/asn1/asn1t.h
index bf315e65ed..ed372f8554 100644
--- a/src/lib/libcrypto/asn1/asn1t.h
+++ b/src/lib/libcrypto/asn1/asn1t.h
@@ -99,7 +99,7 @@ extern "C" {
99#define ASN1_ITEM_start(itname) \ 99#define ASN1_ITEM_start(itname) \
100 const ASN1_ITEM * itname##_it(void) \ 100 const ASN1_ITEM * itname##_it(void) \
101 { \ 101 { \
102 static const ASN1_ITEM local_it = { 102 static const ASN1_ITEM local_it = { \
103 103
104#define ASN1_ITEM_end(itname) \ 104#define ASN1_ITEM_end(itname) \
105 }; \ 105 }; \
@@ -112,7 +112,7 @@ extern "C" {
112/* Macros to aid ASN1 template writing */ 112/* Macros to aid ASN1 template writing */
113 113
114#define ASN1_ITEM_TEMPLATE(tname) \ 114#define ASN1_ITEM_TEMPLATE(tname) \
115 static const ASN1_TEMPLATE tname##_item_tt 115 const static ASN1_TEMPLATE tname##_item_tt
116 116
117#define ASN1_ITEM_TEMPLATE_END(tname) \ 117#define ASN1_ITEM_TEMPLATE_END(tname) \
118 ;\ 118 ;\
@@ -150,7 +150,7 @@ extern "C" {
150 */ 150 */
151 151
152#define ASN1_SEQUENCE(tname) \ 152#define ASN1_SEQUENCE(tname) \
153 static const ASN1_TEMPLATE tname##_seq_tt[] 153 const static ASN1_TEMPLATE tname##_seq_tt[]
154 154
155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname) 155#define ASN1_SEQUENCE_END(stname) ASN1_SEQUENCE_END_name(stname, stname)
156 156
@@ -166,40 +166,22 @@ extern "C" {
166 #stname \ 166 #stname \
167 ASN1_ITEM_end(tname) 167 ASN1_ITEM_end(tname)
168 168
169#define ASN1_NDEF_SEQUENCE(tname) \
170 ASN1_SEQUENCE(tname)
171
172#define ASN1_NDEF_SEQUENCE_cb(tname, cb) \
173 ASN1_SEQUENCE_cb(tname, cb)
174
175#define ASN1_SEQUENCE_cb(tname, cb) \ 169#define ASN1_SEQUENCE_cb(tname, cb) \
176 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 170 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
177 ASN1_SEQUENCE(tname) 171 ASN1_SEQUENCE(tname)
178 172
179#define ASN1_BROKEN_SEQUENCE(tname) \ 173#define ASN1_BROKEN_SEQUENCE(tname) \
180 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \ 174 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_BROKEN, 0, 0, 0, 0}; \
181 ASN1_SEQUENCE(tname) 175 ASN1_SEQUENCE(tname)
182 176
183#define ASN1_SEQUENCE_ref(tname, cb, lck) \ 177#define ASN1_SEQUENCE_ref(tname, cb, lck) \
184 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \ 178 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_REFCOUNT, offsetof(tname, references), lck, cb, 0}; \
185 ASN1_SEQUENCE(tname) 179 ASN1_SEQUENCE(tname)
186 180
187#define ASN1_SEQUENCE_enc(tname, enc, cb) \ 181#define ASN1_SEQUENCE_enc(tname, enc, cb) \
188 static const ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \ 182 const static ASN1_AUX tname##_aux = {NULL, ASN1_AFLG_ENCODING, 0, 0, cb, offsetof(tname, enc)}; \
189 ASN1_SEQUENCE(tname) 183 ASN1_SEQUENCE(tname)
190 184
191#define ASN1_NDEF_SEQUENCE_END(tname) \
192 ;\
193 ASN1_ITEM_start(tname) \
194 ASN1_ITYPE_NDEF_SEQUENCE,\
195 V_ASN1_SEQUENCE,\
196 tname##_seq_tt,\
197 sizeof(tname##_seq_tt) / sizeof(ASN1_TEMPLATE),\
198 NULL,\
199 sizeof(tname),\
200 #tname \
201 ASN1_ITEM_end(tname)
202
203#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname) 185#define ASN1_BROKEN_SEQUENCE_END(stname) ASN1_SEQUENCE_END_ref(stname, stname)
204 186
205#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname) 187#define ASN1_SEQUENCE_END_enc(stname, tname) ASN1_SEQUENCE_END_ref(stname, tname)
@@ -242,10 +224,10 @@ extern "C" {
242 */ 224 */
243 225
244#define ASN1_CHOICE(tname) \ 226#define ASN1_CHOICE(tname) \
245 static const ASN1_TEMPLATE tname##_ch_tt[] 227 const static ASN1_TEMPLATE tname##_ch_tt[]
246 228
247#define ASN1_CHOICE_cb(tname, cb) \ 229#define ASN1_CHOICE_cb(tname, cb) \
248 static const ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \ 230 const static ASN1_AUX tname##_aux = {NULL, 0, 0, 0, cb, 0}; \
249 ASN1_CHOICE(tname) 231 ASN1_CHOICE(tname)
250 232
251#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname) 233#define ASN1_CHOICE_END(stname) ASN1_CHOICE_END_name(stname, stname)
@@ -371,24 +353,16 @@ extern "C" {
371#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \ 353#define ASN1_EXP_SEQUENCE_OF_OPT(stname, field, type, tag) \
372 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL) 354 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_SEQUENCE_OF|ASN1_TFLG_OPTIONAL)
373 355
374/* EXPLICIT using indefinite length constructed form */
375#define ASN1_NDEF_EXP(stname, field, type, tag) \
376 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_NDEF)
377
378/* EXPLICIT OPTIONAL using indefinite length constructed form */
379#define ASN1_NDEF_EXP_OPT(stname, field, type, tag) \
380 ASN1_EXP_EX(stname, field, type, tag, ASN1_TFLG_OPTIONAL|ASN1_TFLG_NDEF)
381
382/* Macros for the ASN1_ADB structure */ 356/* Macros for the ASN1_ADB structure */
383 357
384#define ASN1_ADB(name) \ 358#define ASN1_ADB(name) \
385 static const ASN1_ADB_TABLE name##_adbtbl[] 359 const static ASN1_ADB_TABLE name##_adbtbl[]
386 360
387#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION 361#ifndef OPENSSL_EXPORT_VAR_AS_FUNCTION
388 362
389#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ 363#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
390 ;\ 364 ;\
391 static const ASN1_ADB name##_adb = {\ 365 const static ASN1_ADB name##_adb = {\
392 flags,\ 366 flags,\
393 offsetof(name, field),\ 367 offsetof(name, field),\
394 app_table,\ 368 app_table,\
@@ -402,9 +376,9 @@ extern "C" {
402 376
403#define ASN1_ADB_END(name, flags, field, app_table, def, none) \ 377#define ASN1_ADB_END(name, flags, field, app_table, def, none) \
404 ;\ 378 ;\
405 static const ASN1_ITEM *name##_adb(void) \ 379 const static ASN1_ITEM *name##_adb(void) \
406 { \ 380 { \
407 static const ASN1_ADB internal_adb = \ 381 const static ASN1_ADB internal_adb = \
408 {\ 382 {\
409 flags,\ 383 flags,\
410 offsetof(name, field),\ 384 offsetof(name, field),\
@@ -423,7 +397,7 @@ extern "C" {
423#define ADB_ENTRY(val, template) {val, template} 397#define ADB_ENTRY(val, template) {val, template}
424 398
425#define ASN1_ADB_TEMPLATE(name) \ 399#define ASN1_ADB_TEMPLATE(name) \
426 static const ASN1_TEMPLATE name##_tt 400 const static ASN1_TEMPLATE name##_tt
427 401
428/* This is the ASN1 template structure that defines 402/* This is the ASN1 template structure that defines
429 * a wrapper round the actual type. It determines the 403 * a wrapper round the actual type. It determines the
@@ -436,7 +410,7 @@ unsigned long flags; /* Various flags */
436long tag; /* tag, not used if no tagging */ 410long tag; /* tag, not used if no tagging */
437unsigned long offset; /* Offset of this field in structure */ 411unsigned long offset; /* Offset of this field in structure */
438#ifndef NO_ASN1_FIELD_NAMES 412#ifndef NO_ASN1_FIELD_NAMES
439const char *field_name; /* Field name */ 413char *field_name; /* Field name */
440#endif 414#endif
441ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */ 415ASN1_ITEM_EXP *item; /* Relevant ASN1_ITEM or ASN1_ADB */
442}; 416};
@@ -544,13 +518,6 @@ struct ASN1_ADB_TABLE_st {
544 518
545#define ASN1_TFLG_COMBINE (0x1<<10) 519#define ASN1_TFLG_COMBINE (0x1<<10)
546 520
547/* This flag when present in a SEQUENCE OF, SET OF
548 * or EXPLICIT causes indefinite length constructed
549 * encoding to be used if required.
550 */
551
552#define ASN1_TFLG_NDEF (0x1<<11)
553
554/* This is the actual ASN1 item itself */ 521/* This is the actual ASN1 item itself */
555 522
556struct ASN1_ITEM_st { 523struct ASN1_ITEM_st {
@@ -603,25 +570,19 @@ const char *sname; /* Structure name */
603 * has a special meaning, it is used as a mask 570 * has a special meaning, it is used as a mask
604 * of acceptable types using the B_ASN1 constants. 571 * of acceptable types using the B_ASN1 constants.
605 * 572 *
606 * NDEF_SEQUENCE is the same as SEQUENCE except
607 * that it will use indefinite length constructed
608 * encoding if requested.
609 *
610 */ 573 */
611 574
612#define ASN1_ITYPE_PRIMITIVE 0x0 575#define ASN1_ITYPE_PRIMITIVE 0x0
613
614#define ASN1_ITYPE_SEQUENCE 0x1
615 576
616#define ASN1_ITYPE_CHOICE 0x2 577#define ASN1_ITYPE_SEQUENCE 0x1
617 578
618#define ASN1_ITYPE_COMPAT 0x3 579#define ASN1_ITYPE_CHOICE 0x2
619 580
620#define ASN1_ITYPE_EXTERN 0x4 581#define ASN1_ITYPE_COMPAT 0x3
621 582
622#define ASN1_ITYPE_MSTRING 0x5 583#define ASN1_ITYPE_EXTERN 0x4
623 584
624#define ASN1_ITYPE_NDEF_SEQUENCE 0x6 585#define ASN1_ITYPE_MSTRING 0x5
625 586
626/* Cache for ASN1 tag and length, so we 587/* Cache for ASN1 tag and length, so we
627 * don't keep re-reading it for things 588 * don't keep re-reading it for things
@@ -641,10 +602,10 @@ struct ASN1_TLC_st{
641 602
642typedef ASN1_VALUE * ASN1_new_func(void); 603typedef ASN1_VALUE * ASN1_new_func(void);
643typedef void ASN1_free_func(ASN1_VALUE *a); 604typedef void ASN1_free_func(ASN1_VALUE *a);
644typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, const unsigned char ** in, long length); 605typedef ASN1_VALUE * ASN1_d2i_func(ASN1_VALUE **a, unsigned char ** in, long length);
645typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in); 606typedef int ASN1_i2d_func(ASN1_VALUE * a, unsigned char **in);
646 607
647typedef int ASN1_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, 608typedef int ASN1_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
648 int tag, int aclass, char opt, ASN1_TLC *ctx); 609 int tag, int aclass, char opt, ASN1_TLC *ctx);
649 610
650typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 611typedef int ASN1_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
@@ -652,7 +613,7 @@ typedef int ASN1_ex_new_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
652typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it); 613typedef void ASN1_ex_free_func(ASN1_VALUE **pval, const ASN1_ITEM *it);
653 614
654typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 615typedef int ASN1_primitive_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
655typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 616typedef int ASN1_primitive_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
656 617
657typedef struct ASN1_COMPAT_FUNCS_st { 618typedef struct ASN1_COMPAT_FUNCS_st {
658 ASN1_new_func *asn1_new; 619 ASN1_new_func *asn1_new;
@@ -782,9 +743,6 @@ typedef struct ASN1_AUX_st {
782#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \ 743#define IMPLEMENT_ASN1_FUNCTIONS_ENCODE_name(stname, itname) \
783 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname) 744 IMPLEMENT_ASN1_FUNCTIONS_ENCODE_fname(stname, itname, itname)
784 745
785#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS(stname) \
786 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, stname, stname)
787
788#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \ 746#define IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) \
789 stname *fname##_new(void) \ 747 stname *fname##_new(void) \
790 { \ 748 { \
@@ -800,7 +758,7 @@ typedef struct ASN1_AUX_st {
800 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname) 758 IMPLEMENT_ASN1_ALLOC_FUNCTIONS_fname(stname, itname, fname)
801 759
802#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \ 760#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(stname, itname, fname) \
803 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ 761 stname *d2i_##fname(stname **a, unsigned char **in, long len) \
804 { \ 762 { \
805 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ 763 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\
806 } \ 764 } \
@@ -809,19 +767,13 @@ typedef struct ASN1_AUX_st {
809 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\ 767 return ASN1_item_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(itname));\
810 } 768 }
811 769
812#define IMPLEMENT_ASN1_NDEF_FUNCTION(stname) \
813 int i2d_##stname##_NDEF(stname *a, unsigned char **out) \
814 { \
815 return ASN1_item_ndef_i2d((ASN1_VALUE *)a, out, ASN1_ITEM_rptr(stname));\
816 }
817
818/* This includes evil casts to remove const: they will go away when full 770/* This includes evil casts to remove const: they will go away when full
819 * ASN1 constification is done. 771 * ASN1 constification is done.
820 */ 772 */
821#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \ 773#define IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(stname, itname, fname) \
822 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \ 774 stname *d2i_##fname(stname **a, const unsigned char **in, long len) \
823 { \ 775 { \
824 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, ASN1_ITEM_rptr(itname));\ 776 return (stname *)ASN1_item_d2i((ASN1_VALUE **)a, (unsigned char **)in, len, ASN1_ITEM_rptr(itname));\
825 } \ 777 } \
826 int i2d_##fname(const stname *a, unsigned char **out) \ 778 int i2d_##fname(const stname *a, unsigned char **out) \
827 { \ 779 { \
@@ -846,6 +798,7 @@ typedef struct ASN1_AUX_st {
846DECLARE_ASN1_ITEM(ASN1_BOOLEAN) 798DECLARE_ASN1_ITEM(ASN1_BOOLEAN)
847DECLARE_ASN1_ITEM(ASN1_TBOOLEAN) 799DECLARE_ASN1_ITEM(ASN1_TBOOLEAN)
848DECLARE_ASN1_ITEM(ASN1_FBOOLEAN) 800DECLARE_ASN1_ITEM(ASN1_FBOOLEAN)
801DECLARE_ASN1_ITEM(ASN1_ANY)
849DECLARE_ASN1_ITEM(ASN1_SEQUENCE) 802DECLARE_ASN1_ITEM(ASN1_SEQUENCE)
850DECLARE_ASN1_ITEM(CBIGNUM) 803DECLARE_ASN1_ITEM(CBIGNUM)
851DECLARE_ASN1_ITEM(BIGNUM) 804DECLARE_ASN1_ITEM(BIGNUM)
@@ -862,8 +815,8 @@ int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
862int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it); 815int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
863 816
864void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); 817void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
865int ASN1_template_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_TEMPLATE *tt); 818int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt);
866int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, const ASN1_ITEM *it, 819int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
867 int tag, int aclass, char opt, ASN1_TLC *ctx); 820 int tag, int aclass, char opt, ASN1_TLC *ctx);
868 821
869int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 822int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
@@ -871,7 +824,7 @@ int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLAT
871void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 824void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
872 825
873int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 826int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
874int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 827int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
875 828
876int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it); 829int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it);
877int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it); 830int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it);
@@ -885,7 +838,7 @@ int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it);
885void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it); 838void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it);
886void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 839void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
887int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it); 840int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it);
888int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, const ASN1_ITEM *it); 841int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it);
889 842
890#ifdef __cplusplus 843#ifdef __cplusplus
891} 844}
diff --git a/src/lib/libcrypto/asn1/asn_moid.c b/src/lib/libcrypto/asn1/asn_moid.c
index 9132350f10..edb44c988f 100644
--- a/src/lib/libcrypto/asn1/asn_moid.c
+++ b/src/lib/libcrypto/asn1/asn_moid.c
@@ -3,7 +3,7 @@
3 * project 2001. 3 * project 2001.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2001-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -57,7 +57,6 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h>
61#include <openssl/crypto.h> 60#include <openssl/crypto.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include <openssl/conf.h> 62#include <openssl/conf.h>
@@ -66,8 +65,6 @@
66 65
67/* Simple ASN1 OID module: add all objects in a given section */ 66/* Simple ASN1 OID module: add all objects in a given section */
68 67
69static int do_create(char *value, char *name);
70
71static int oid_module_init(CONF_IMODULE *md, const CONF *cnf) 68static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
72 { 69 {
73 int i; 70 int i;
@@ -83,7 +80,7 @@ static int oid_module_init(CONF_IMODULE *md, const CONF *cnf)
83 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++) 80 for(i = 0; i < sk_CONF_VALUE_num(sktmp); i++)
84 { 81 {
85 oval = sk_CONF_VALUE_value(sktmp, i); 82 oval = sk_CONF_VALUE_value(sktmp, i);
86 if(!do_create(oval->value, oval->name)) 83 if(OBJ_create(oval->value, oval->name, oval->name) == NID_undef)
87 { 84 {
88 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT); 85 ASN1err(ASN1_F_OID_MODULE_INIT, ASN1_R_ADDING_OBJECT);
89 return 0; 86 return 0;
@@ -101,60 +98,3 @@ void ASN1_add_oid_module(void)
101 { 98 {
102 CONF_module_add("oid_section", oid_module_init, oid_module_finish); 99 CONF_module_add("oid_section", oid_module_init, oid_module_finish);
103 } 100 }
104
105/* Create an OID based on a name value pair. Accept two formats.
106 * shortname = 1.2.3.4
107 * shortname = some long name, 1.2.3.4
108 */
109
110
111static int do_create(char *value, char *name)
112 {
113 int nid;
114 ASN1_OBJECT *oid;
115 char *ln, *ostr, *p, *lntmp;
116 p = strrchr(value, ',');
117 if (!p)
118 {
119 ln = name;
120 ostr = value;
121 }
122 else
123 {
124 ln = NULL;
125 ostr = p + 1;
126 if (!*ostr)
127 return 0;
128 while(isspace((unsigned char)*ostr)) ostr++;
129 }
130
131 nid = OBJ_create(ostr, name, ln);
132
133 if (nid == NID_undef)
134 return 0;
135
136 if (p)
137 {
138 ln = value;
139 while(isspace((unsigned char)*ln)) ln++;
140 p--;
141 while(isspace((unsigned char)*p))
142 {
143 if (p == ln)
144 return 0;
145 p--;
146 }
147 p++;
148 lntmp = OPENSSL_malloc((p - ln) + 1);
149 if (lntmp == NULL)
150 return 0;
151 memcpy(lntmp, ln, p - ln);
152 lntmp[p - ln] = 0;
153 oid = OBJ_nid2obj(nid);
154 oid->ln = lntmp;
155 }
156
157 return 1;
158 }
159
160
diff --git a/src/lib/libcrypto/asn1/asn_pack.c b/src/lib/libcrypto/asn1/asn_pack.c
index e8b671b7b5..e6051db2dc 100644
--- a/src/lib/libcrypto/asn1/asn_pack.c
+++ b/src/lib/libcrypto/asn1/asn_pack.c
@@ -66,11 +66,11 @@
66 66
67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */ 67/* Turn an ASN1 encoded SEQUENCE OF into a STACK of structures */
68 68
69STACK *ASN1_seq_unpack(const unsigned char *buf, int len, 69STACK *ASN1_seq_unpack(unsigned char *buf, int len, char *(*d2i)(),
70 d2i_of_void *d2i,void (*free_func)(void *)) 70 void (*free_func)(void *))
71{ 71{
72 STACK *sk; 72 STACK *sk;
73 const unsigned char *pbuf; 73 unsigned char *pbuf;
74 pbuf = buf; 74 pbuf = buf;
75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func, 75 if (!(sk = d2i_ASN1_SET(NULL, &pbuf, len, d2i, free_func,
76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL))) 76 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL)))
@@ -82,8 +82,8 @@ STACK *ASN1_seq_unpack(const unsigned char *buf, int len,
82 * OPENSSL_malloc'ed buffer 82 * OPENSSL_malloc'ed buffer
83 */ 83 */
84 84
85unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d, 85unsigned char *ASN1_seq_pack(STACK *safes, int (*i2d)(), unsigned char **buf,
86 unsigned char **buf, int *len) 86 int *len)
87{ 87{
88 int safelen; 88 int safelen;
89 unsigned char *safe, *p; 89 unsigned char *safe, *p;
@@ -106,9 +106,9 @@ unsigned char *ASN1_seq_pack(STACK *safes, i2d_of_void *i2d,
106 106
107/* Extract an ASN1 object from an ASN1_STRING */ 107/* Extract an ASN1 object from an ASN1_STRING */
108 108
109void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i) 109void *ASN1_unpack_string (ASN1_STRING *oct, char *(*d2i)())
110{ 110{
111 const unsigned char *p; 111 unsigned char *p;
112 char *ret; 112 char *ret;
113 113
114 p = oct->data; 114 p = oct->data;
@@ -119,7 +119,7 @@ void *ASN1_unpack_string(ASN1_STRING *oct, d2i_of_void *d2i)
119 119
120/* Pack an ASN1 object into an ASN1_STRING */ 120/* Pack an ASN1 object into an ASN1_STRING */
121 121
122ASN1_STRING *ASN1_pack_string(void *obj, i2d_of_void *i2d, ASN1_STRING **oct) 122ASN1_STRING *ASN1_pack_string(void *obj, int (*i2d)(), ASN1_STRING **oct)
123{ 123{
124 unsigned char *p; 124 unsigned char *p;
125 ASN1_STRING *octmp; 125 ASN1_STRING *octmp;
@@ -155,7 +155,7 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
155 155
156 if (!oct || !*oct) { 156 if (!oct || !*oct) {
157 if (!(octmp = ASN1_STRING_new ())) { 157 if (!(octmp = ASN1_STRING_new ())) {
158 ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE); 158 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
159 return NULL; 159 return NULL;
160 } 160 }
161 if (oct) *oct = octmp; 161 if (oct) *oct = octmp;
@@ -167,11 +167,11 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
167 } 167 }
168 168
169 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) { 169 if (!(octmp->length = ASN1_item_i2d(obj, &octmp->data, it))) {
170 ASN1err(ASN1_F_ASN1_ITEM_PACK,ASN1_R_ENCODE_ERROR); 170 ASN1err(ASN1_F_ASN1_PACK_STRING,ASN1_R_ENCODE_ERROR);
171 return NULL; 171 return NULL;
172 } 172 }
173 if (!octmp->data) { 173 if (!octmp->data) {
174 ASN1err(ASN1_F_ASN1_ITEM_PACK,ERR_R_MALLOC_FAILURE); 174 ASN1err(ASN1_F_ASN1_PACK_STRING,ERR_R_MALLOC_FAILURE);
175 return NULL; 175 return NULL;
176 } 176 }
177 return octmp; 177 return octmp;
@@ -181,11 +181,11 @@ ASN1_STRING *ASN1_item_pack(void *obj, const ASN1_ITEM *it, ASN1_STRING **oct)
181 181
182void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it) 182void *ASN1_item_unpack(ASN1_STRING *oct, const ASN1_ITEM *it)
183{ 183{
184 const unsigned char *p; 184 unsigned char *p;
185 void *ret; 185 void *ret;
186 186
187 p = oct->data; 187 p = oct->data;
188 if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it))) 188 if(!(ret = ASN1_item_d2i(NULL, &p, oct->length, it)))
189 ASN1err(ASN1_F_ASN1_ITEM_UNPACK,ASN1_R_DECODE_ERROR); 189 ASN1err(ASN1_F_ASN1_UNPACK_STRING,ASN1_R_DECODE_ERROR);
190 return ret; 190 return ret;
191} 191}
diff --git a/src/lib/libcrypto/asn1/d2i_pr.c b/src/lib/libcrypto/asn1/d2i_pr.c
index 207ccda5ac..2e7d96af90 100644
--- a/src/lib/libcrypto/asn1/d2i_pr.c
+++ b/src/lib/libcrypto/asn1/d2i_pr.c
@@ -68,11 +68,8 @@
68#ifndef OPENSSL_NO_DSA 68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h> 69#include <openssl/dsa.h>
70#endif 70#endif
71#ifndef OPENSSL_NO_EC
72#include <openssl/ec.h>
73#endif
74 71
75EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, 72EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, unsigned char **pp,
76 long length) 73 long length)
77 { 74 {
78 EVP_PKEY *ret; 75 EVP_PKEY *ret;
@@ -111,16 +108,6 @@ EVP_PKEY *d2i_PrivateKey(int type, EVP_PKEY **a, const unsigned char **pp,
111 } 108 }
112 break; 109 break;
113#endif 110#endif
114#ifndef OPENSSL_NO_EC
115 case EVP_PKEY_EC:
116 if ((ret->pkey.ec = d2i_ECPrivateKey(NULL,
117 (const unsigned char **)pp, length)) == NULL)
118 {
119 ASN1err(ASN1_F_D2I_PRIVATEKEY, ERR_R_ASN1_LIB);
120 goto err;
121 }
122 break;
123#endif
124 default: 111 default:
125 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 112 ASN1err(ASN1_F_D2I_PRIVATEKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
126 goto err; 113 goto err;
@@ -135,11 +122,11 @@ err:
135 122
136/* This works like d2i_PrivateKey() except it automatically works out the type */ 123/* This works like d2i_PrivateKey() except it automatically works out the type */
137 124
138EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, 125EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
139 long length) 126 long length)
140{ 127{
141 STACK_OF(ASN1_TYPE) *inkey; 128 STACK_OF(ASN1_TYPE) *inkey;
142 const unsigned char *p; 129 unsigned char *p;
143 int keytype; 130 int keytype;
144 p = *pp; 131 p = *pp;
145 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE): 132 /* Dirty trick: read in the ASN1 data into a STACK_OF(ASN1_TYPE):
@@ -151,10 +138,7 @@ EVP_PKEY *d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp,
151 /* Since we only need to discern "traditional format" RSA and DSA 138 /* Since we only need to discern "traditional format" RSA and DSA
152 * keys we can just count the elements. 139 * keys we can just count the elements.
153 */ 140 */
154 if(sk_ASN1_TYPE_num(inkey) == 6) 141 if(sk_ASN1_TYPE_num(inkey) == 6) keytype = EVP_PKEY_DSA;
155 keytype = EVP_PKEY_DSA;
156 else if (sk_ASN1_TYPE_num(inkey) == 4)
157 keytype = EVP_PKEY_EC;
158 else keytype = EVP_PKEY_RSA; 142 else keytype = EVP_PKEY_RSA;
159 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free); 143 sk_ASN1_TYPE_pop_free(inkey, ASN1_TYPE_free);
160 return d2i_PrivateKey(keytype, a, pp, length); 144 return d2i_PrivateKey(keytype, a, pp, length);
diff --git a/src/lib/libcrypto/asn1/d2i_pu.c b/src/lib/libcrypto/asn1/d2i_pu.c
index 3694f51a8c..71f2eb361b 100644
--- a/src/lib/libcrypto/asn1/d2i_pu.c
+++ b/src/lib/libcrypto/asn1/d2i_pu.c
@@ -68,11 +68,8 @@
68#ifndef OPENSSL_NO_DSA 68#ifndef OPENSSL_NO_DSA
69#include <openssl/dsa.h> 69#include <openssl/dsa.h>
70#endif 70#endif
71#ifndef OPENSSL_NO_EC
72#include <openssl/ec.h>
73#endif
74 71
75EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp, 72EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, unsigned char **pp,
76 long length) 73 long length)
77 { 74 {
78 EVP_PKEY *ret; 75 EVP_PKEY *ret;
@@ -103,24 +100,14 @@ EVP_PKEY *d2i_PublicKey(int type, EVP_PKEY **a, const unsigned char **pp,
103#endif 100#endif
104#ifndef OPENSSL_NO_DSA 101#ifndef OPENSSL_NO_DSA
105 case EVP_PKEY_DSA: 102 case EVP_PKEY_DSA:
106 if (!d2i_DSAPublicKey(&(ret->pkey.dsa), 103 if ((ret->pkey.dsa=d2i_DSAPublicKey(NULL,
107 (const unsigned char **)pp,length)) /* TMP UGLY CAST */ 104 (const unsigned char **)pp,length)) == NULL) /* TMP UGLY CAST */
108 { 105 {
109 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB); 106 ASN1err(ASN1_F_D2I_PUBLICKEY,ERR_R_ASN1_LIB);
110 goto err; 107 goto err;
111 } 108 }
112 break; 109 break;
113#endif 110#endif
114#ifndef OPENSSL_NO_EC
115 case EVP_PKEY_EC:
116 if (!o2i_ECPublicKey(&(ret->pkey.ec),
117 (const unsigned char **)pp, length))
118 {
119 ASN1err(ASN1_F_D2I_PUBLICKEY, ERR_R_ASN1_LIB);
120 goto err;
121 }
122 break;
123#endif
124 default: 111 default:
125 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE); 112 ASN1err(ASN1_F_D2I_PUBLICKEY,ASN1_R_UNKNOWN_PUBLIC_KEY_TYPE);
126 goto err; 113 goto err;
diff --git a/src/lib/libcrypto/asn1/evp_asn1.c b/src/lib/libcrypto/asn1/evp_asn1.c
index f3d9804860..f92ce6cb5d 100644
--- a/src/lib/libcrypto/asn1/evp_asn1.c
+++ b/src/lib/libcrypto/asn1/evp_asn1.c
@@ -141,9 +141,9 @@ int ASN1_TYPE_get_int_octetstring(ASN1_TYPE *a, long *num, unsigned char *data,
141 int ret= -1,n; 141 int ret= -1,n;
142 ASN1_INTEGER *ai=NULL; 142 ASN1_INTEGER *ai=NULL;
143 ASN1_OCTET_STRING *os=NULL; 143 ASN1_OCTET_STRING *os=NULL;
144 const unsigned char *p; 144 unsigned char *p;
145 long length; 145 long length;
146 ASN1_const_CTX c; 146 ASN1_CTX c;
147 147
148 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL)) 148 if ((a->type != V_ASN1_SEQUENCE) || (a->value.sequence == NULL))
149 { 149 {
diff --git a/src/lib/libcrypto/asn1/f.c b/src/lib/libcrypto/asn1/f.c
new file mode 100644
index 0000000000..82bccdfd51
--- /dev/null
+++ b/src/lib/libcrypto/asn1/f.c
@@ -0,0 +1,80 @@
1/* crypto/asn1/f.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be 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 <openssl/asn1.h>
60#include <openssl/err.h>
61
62main()
63 {
64 ASN1_TYPE *at;
65 char buf[512];
66 int n;
67 long l;
68
69 at=ASN1_TYPE_new();
70
71 n=ASN1_TYPE_set_int_octetstring(at,98736,"01234567",8);
72 printf("%d\n",n);
73 n=ASN1_TYPE_get_int_octetstring(at,&l,buf,8);
74 buf[8]='\0';
75 printf("%ld %d %d\n",l,n,buf[8]);
76 buf[8]='\0';
77 printf("%s\n",buf);
78 ERR_load_crypto_strings();
79 ERR_print_errors_fp(stderr);
80 }
diff --git a/src/lib/libcrypto/asn1/i2d_pr.c b/src/lib/libcrypto/asn1/i2d_pr.c
index 0be52c5b76..1e951ae01d 100644
--- a/src/lib/libcrypto/asn1/i2d_pr.c
+++ b/src/lib/libcrypto/asn1/i2d_pr.c
@@ -67,9 +67,6 @@
67#ifndef OPENSSL_NO_DSA 67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h> 68#include <openssl/dsa.h>
69#endif 69#endif
70#ifndef OPENSSL_NO_EC
71#include <openssl/ec.h>
72#endif
73 70
74int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp) 71int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
75 { 72 {
@@ -86,12 +83,6 @@ int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp)
86 return(i2d_DSAPrivateKey(a->pkey.dsa,pp)); 83 return(i2d_DSAPrivateKey(a->pkey.dsa,pp));
87 } 84 }
88#endif 85#endif
89#ifndef OPENSSL_NO_EC
90 if (a->type == EVP_PKEY_EC)
91 {
92 return(i2d_ECPrivateKey(a->pkey.ec, pp));
93 }
94#endif
95 86
96 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); 87 ASN1err(ASN1_F_I2D_PRIVATEKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
97 return(-1); 88 return(-1);
diff --git a/src/lib/libcrypto/asn1/i2d_pu.c b/src/lib/libcrypto/asn1/i2d_pu.c
index 34286dbd35..013d19bbf4 100644
--- a/src/lib/libcrypto/asn1/i2d_pu.c
+++ b/src/lib/libcrypto/asn1/i2d_pu.c
@@ -67,9 +67,6 @@
67#ifndef OPENSSL_NO_DSA 67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h> 68#include <openssl/dsa.h>
69#endif 69#endif
70#ifndef OPENSSL_NO_EC
71#include <openssl/ec.h>
72#endif
73 70
74int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp) 71int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
75 { 72 {
@@ -83,10 +80,6 @@ int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp)
83 case EVP_PKEY_DSA: 80 case EVP_PKEY_DSA:
84 return(i2d_DSAPublicKey(a->pkey.dsa,pp)); 81 return(i2d_DSAPublicKey(a->pkey.dsa,pp));
85#endif 82#endif
86#ifndef OPENSSL_NO_EC
87 case EVP_PKEY_EC:
88 return(i2o_ECPublicKey(a->pkey.ec, pp));
89#endif
90 default: 83 default:
91 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE); 84 ASN1err(ASN1_F_I2D_PUBLICKEY,ASN1_R_UNSUPPORTED_PUBLIC_KEY_TYPE);
92 return(-1); 85 return(-1);
diff --git a/src/lib/libcrypto/asn1/n_pkey.c b/src/lib/libcrypto/asn1/n_pkey.c
index 60bc437938..766b51c538 100644
--- a/src/lib/libcrypto/asn1/n_pkey.c
+++ b/src/lib/libcrypto/asn1/n_pkey.c
@@ -56,9 +56,9 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#ifndef OPENSSL_NO_RSA
62#include <openssl/rsa.h> 62#include <openssl/rsa.h>
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
@@ -107,20 +107,14 @@ DECLARE_ASN1_ENCODE_FUNCTIONS_const(NETSCAPE_PKEY,NETSCAPE_PKEY)
107IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY) 107IMPLEMENT_ASN1_FUNCTIONS_const(NETSCAPE_PKEY)
108 108
109static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, 109static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
110 int (*cb)(char *buf, int len, const char *prompt, 110 int (*cb)(), int sgckey);
111 int verify),
112 int sgckey);
113 111
114int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, 112int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)())
115 int (*cb)(char *buf, int len, const char *prompt,
116 int verify))
117{ 113{
118 return i2d_RSA_NET(a, pp, cb, 0); 114 return i2d_RSA_NET(a, pp, cb, 0);
119} 115}
120 116
121int i2d_RSA_NET(const RSA *a, unsigned char **pp, 117int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey)
122 int (*cb)(char *buf, int len, const char *prompt, int verify),
123 int sgckey)
124 { 118 {
125 int i, j, ret = 0; 119 int i, j, ret = 0;
126 int rsalen, pkeylen, olen; 120 int rsalen, pkeylen, olen;
@@ -170,7 +164,7 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
170 /* Since its RC4 encrypted length is actual length */ 164 /* Since its RC4 encrypted length is actual length */
171 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL) 165 if ((zz=(unsigned char *)OPENSSL_malloc(rsalen)) == NULL)
172 { 166 {
173 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 167 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
174 goto err; 168 goto err;
175 } 169 }
176 170
@@ -180,13 +174,13 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
180 174
181 if ((zz=OPENSSL_malloc(pkeylen)) == NULL) 175 if ((zz=OPENSSL_malloc(pkeylen)) == NULL)
182 { 176 {
183 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 177 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
184 goto err; 178 goto err;
185 } 179 }
186 180
187 if (!ASN1_STRING_set(enckey->os, "private-key", -1)) 181 if (!ASN1_STRING_set(enckey->os, "private-key", -1))
188 { 182 {
189 ASN1err(ASN1_F_I2D_RSA_NET,ERR_R_MALLOC_FAILURE); 183 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ERR_R_MALLOC_FAILURE);
190 goto err; 184 goto err;
191 } 185 }
192 enckey->enckey->digest->data = zz; 186 enckey->enckey->digest->data = zz;
@@ -197,10 +191,10 @@ int i2d_RSA_NET(const RSA *a, unsigned char **pp,
197 191
198 if (cb == NULL) 192 if (cb == NULL)
199 cb=EVP_read_pw_string; 193 cb=EVP_read_pw_string;
200 i=cb((char *)buf,256,"Enter Private Key password:",1); 194 i=cb(buf,256,"Enter Private Key password:",1);
201 if (i != 0) 195 if (i != 0)
202 { 196 {
203 ASN1err(ASN1_F_I2D_RSA_NET,ASN1_R_BAD_PASSWORD_READ); 197 ASN1err(ASN1_F_I2D_NETSCAPE_RSA,ASN1_R_BAD_PASSWORD_READ);
204 goto err; 198 goto err;
205 } 199 }
206 i = strlen((char *)buf); 200 i = strlen((char *)buf);
@@ -230,16 +224,12 @@ err:
230 } 224 }
231 225
232 226
233RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, 227RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)())
234 int (*cb)(char *buf, int len, const char *prompt,
235 int verify))
236{ 228{
237 return d2i_RSA_NET(a, pp, length, cb, 0); 229 return d2i_RSA_NET(a, pp, length, cb, 0);
238} 230}
239 231
240RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, 232RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey)
241 int (*cb)(char *buf, int len, const char *prompt, int verify),
242 int sgckey)
243 { 233 {
244 RSA *ret=NULL; 234 RSA *ret=NULL;
245 const unsigned char *p, *kp; 235 const unsigned char *p, *kp;
@@ -249,20 +239,20 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
249 239
250 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length); 240 enckey = d2i_NETSCAPE_ENCRYPTED_PKEY(NULL, &p, length);
251 if(!enckey) { 241 if(!enckey) {
252 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_DECODING_ERROR); 242 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_DECODING_ERROR);
253 return NULL; 243 return NULL;
254 } 244 }
255 245
256 if ((enckey->os->length != 11) || (strncmp("private-key", 246 if ((enckey->os->length != 11) || (strncmp("private-key",
257 (char *)enckey->os->data,11) != 0)) 247 (char *)enckey->os->data,11) != 0))
258 { 248 {
259 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_PRIVATE_KEY_HEADER_MISSING); 249 ASN1err(ASN1_F_D2I_NETSCAPE_RSA,ASN1_R_PRIVATE_KEY_HEADER_MISSING);
260 NETSCAPE_ENCRYPTED_PKEY_free(enckey); 250 NETSCAPE_ENCRYPTED_PKEY_free(enckey);
261 return NULL; 251 return NULL;
262 } 252 }
263 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4) 253 if (OBJ_obj2nid(enckey->enckey->algor->algorithm) != NID_rc4)
264 { 254 {
265 ASN1err(ASN1_F_D2I_RSA_NET,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM); 255 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNSUPPORTED_ENCRYPTION_ALGORITHM);
266 goto err; 256 goto err;
267 } 257 }
268 kp = enckey->enckey->digest->data; 258 kp = enckey->enckey->digest->data;
@@ -279,8 +269,7 @@ RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
279 } 269 }
280 270
281static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os, 271static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
282 int (*cb)(char *buf, int len, const char *prompt, 272 int (*cb)(), int sgckey)
283 int verify), int sgckey)
284 { 273 {
285 NETSCAPE_PKEY *pkey=NULL; 274 NETSCAPE_PKEY *pkey=NULL;
286 RSA *ret=NULL; 275 RSA *ret=NULL;
@@ -290,10 +279,10 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
290 unsigned char key[EVP_MAX_KEY_LENGTH]; 279 unsigned char key[EVP_MAX_KEY_LENGTH];
291 EVP_CIPHER_CTX ctx; 280 EVP_CIPHER_CTX ctx;
292 281
293 i=cb((char *)buf,256,"Enter Private Key password:",0); 282 i=cb(buf,256,"Enter Private Key password:",0);
294 if (i != 0) 283 if (i != 0)
295 { 284 {
296 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_BAD_PASSWORD_READ); 285 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_BAD_PASSWORD_READ);
297 goto err; 286 goto err;
298 } 287 }
299 288
@@ -318,14 +307,14 @@ static RSA *d2i_RSA_NET_2(RSA **a, ASN1_OCTET_STRING *os,
318 307
319 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL) 308 if ((pkey=d2i_NETSCAPE_PKEY(NULL,&zz,os->length)) == NULL)
320 { 309 {
321 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY); 310 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_PRIVATE_KEY);
322 goto err; 311 goto err;
323 } 312 }
324 313
325 zz=pkey->private_key->data; 314 zz=pkey->private_key->data;
326 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL) 315 if ((ret=d2i_RSAPrivateKey(a,&zz,pkey->private_key->length)) == NULL)
327 { 316 {
328 ASN1err(ASN1_F_D2I_RSA_NET_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY); 317 ASN1err(ASN1_F_D2I_NETSCAPE_RSA_2,ASN1_R_UNABLE_TO_DECODE_RSA_KEY);
329 goto err; 318 goto err;
330 } 319 }
331err: 320err:
diff --git a/src/lib/libcrypto/asn1/p5_pbe.c b/src/lib/libcrypto/asn1/p5_pbe.c
index da91170094..ec788267e0 100644
--- a/src/lib/libcrypto/asn1/p5_pbe.c
+++ b/src/lib/libcrypto/asn1/p5_pbe.c
@@ -82,17 +82,17 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
82 ASN1_TYPE *astype=NULL; 82 ASN1_TYPE *astype=NULL;
83 83
84 if (!(pbe = PBEPARAM_new ())) { 84 if (!(pbe = PBEPARAM_new ())) {
85 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); 85 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
86 goto err; 86 goto err;
87 } 87 }
88 if(iter <= 0) iter = PKCS5_DEFAULT_ITER; 88 if(iter <= 0) iter = PKCS5_DEFAULT_ITER;
89 if (!ASN1_INTEGER_set(pbe->iter, iter)) { 89 if (!ASN1_INTEGER_set(pbe->iter, iter)) {
90 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); 90 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
91 goto err; 91 goto err;
92 } 92 }
93 if (!saltlen) saltlen = PKCS5_SALT_LEN; 93 if (!saltlen) saltlen = PKCS5_SALT_LEN;
94 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) { 94 if (!(pbe->salt->data = OPENSSL_malloc (saltlen))) {
95 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); 95 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
96 goto err; 96 goto err;
97 } 97 }
98 pbe->salt->length = saltlen; 98 pbe->salt->length = saltlen;
@@ -101,14 +101,13 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
101 goto err; 101 goto err;
102 102
103 if (!(astype = ASN1_TYPE_new())) { 103 if (!(astype = ASN1_TYPE_new())) {
104 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); 104 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
105 goto err; 105 goto err;
106 } 106 }
107 107
108 astype->type = V_ASN1_SEQUENCE; 108 astype->type = V_ASN1_SEQUENCE;
109 if(!ASN1_pack_string_of(PBEPARAM, pbe, i2d_PBEPARAM, 109 if(!ASN1_pack_string(pbe, i2d_PBEPARAM, &astype->value.sequence)) {
110 &astype->value.sequence)) { 110 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
111 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE);
112 goto err; 111 goto err;
113 } 112 }
114 PBEPARAM_free (pbe); 113 PBEPARAM_free (pbe);
@@ -116,7 +115,7 @@ X509_ALGOR *PKCS5_pbe_set(int alg, int iter, unsigned char *salt,
116 115
117 al = OBJ_nid2obj(alg); /* never need to free al */ 116 al = OBJ_nid2obj(alg); /* never need to free al */
118 if (!(algor = X509_ALGOR_new())) { 117 if (!(algor = X509_ALGOR_new())) {
119 ASN1err(ASN1_F_PKCS5_PBE_SET,ERR_R_MALLOC_FAILURE); 118 ASN1err(ASN1_F_ASN1_PBE_SET,ERR_R_MALLOC_FAILURE);
120 goto err; 119 goto err;
121 } 120 }
122 ASN1_OBJECT_free(algor->algorithm); 121 ASN1_OBJECT_free(algor->algorithm);
diff --git a/src/lib/libcrypto/asn1/p5_pbev2.c b/src/lib/libcrypto/asn1/p5_pbev2.c
index c834a38ddf..e0dc0ec4ee 100644
--- a/src/lib/libcrypto/asn1/p5_pbev2.c
+++ b/src/lib/libcrypto/asn1/p5_pbev2.c
@@ -115,7 +115,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
115 /* Create random IV */ 115 /* Create random IV */
116 if (EVP_CIPHER_iv_length(cipher) && 116 if (EVP_CIPHER_iv_length(cipher) &&
117 RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0) 117 RAND_pseudo_bytes(iv, EVP_CIPHER_iv_length(cipher)) < 0)
118 goto err; 118 goto err;
119 119
120 EVP_CIPHER_CTX_init(&ctx); 120 EVP_CIPHER_CTX_init(&ctx);
121 121
@@ -164,7 +164,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
164 164
165 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr; 165 if(!(pbe2->keyfunc->parameter = ASN1_TYPE_new())) goto merr;
166 166
167 if(!ASN1_pack_string_of(PBKDF2PARAM, kdf, i2d_PBKDF2PARAM, 167 if(!ASN1_pack_string(kdf, i2d_PBKDF2PARAM,
168 &pbe2->keyfunc->parameter->value.sequence)) goto merr; 168 &pbe2->keyfunc->parameter->value.sequence)) goto merr;
169 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE; 169 pbe2->keyfunc->parameter->type = V_ASN1_SEQUENCE;
170 170
@@ -180,7 +180,7 @@ X509_ALGOR *PKCS5_pbe2_set(const EVP_CIPHER *cipher, int iter,
180 180
181 /* Encode PBE2PARAM into parameter */ 181 /* Encode PBE2PARAM into parameter */
182 182
183 if(!ASN1_pack_string_of(PBE2PARAM, pbe2, i2d_PBE2PARAM, 183 if(!ASN1_pack_string(pbe2, i2d_PBE2PARAM,
184 &ret->parameter->value.sequence)) goto merr; 184 &ret->parameter->value.sequence)) goto merr;
185 ret->parameter->type = V_ASN1_SEQUENCE; 185 ret->parameter->type = V_ASN1_SEQUENCE;
186 186
diff --git a/src/lib/libcrypto/asn1/p8_key.c b/src/lib/libcrypto/asn1/p8_key.c
new file mode 100644
index 0000000000..3a31248e14
--- /dev/null
+++ b/src/lib/libcrypto/asn1/p8_key.c
@@ -0,0 +1,131 @@
1/* crypto/asn1/p8_key.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/objects.h>
63
64int i2d_X509_KEY(X509 *a, unsigned char **pp)
65 {
66 M_ASN1_I2D_vars(a);
67
68 M_ASN1_I2D_len(a->cert_info, i2d_X509_CINF);
69 M_ASN1_I2D_len(a->sig_alg, i2d_X509_ALGOR);
70 M_ASN1_I2D_len(a->signature, i2d_ASN1_BIT_STRING);
71
72 M_ASN1_I2D_seq_total();
73
74 M_ASN1_I2D_put(a->cert_info, i2d_X509_CINF);
75 M_ASN1_I2D_put(a->sig_alg, i2d_X509_ALGOR);
76 M_ASN1_I2D_put(a->signature, i2d_ASN1_BIT_STRING);
77
78 M_ASN1_I2D_finish();
79 }
80
81X509 *d2i_X509_KEY(X509 **a, unsigned char **pp, long length)
82 {
83 M_ASN1_D2I_vars(a,X509 *,X509_new);
84
85 M_ASN1_D2I_Init();
86 M_ASN1_D2I_start_sequence();
87 M_ASN1_D2I_get(ret->cert_info,d2i_X509_CINF);
88 M_ASN1_D2I_get(ret->sig_alg,d2i_X509_ALGOR);
89 M_ASN1_D2I_get(ret->signature,d2i_ASN1_BIT_STRING);
90 M_ASN1_D2I_Finish(a,X509_free,ASN1_F_D2I_X509);
91 }
92
93X509 *X509_KEY_new(void)
94 {
95 X509_KEY *ret=NULL;
96
97 M_ASN1_New_OPENSSL_malloc(ret,X509_KEY);
98 ret->references=1;
99 ret->type=NID
100 M_ASN1_New(ret->cert_info,X509_CINF_new);
101 M_ASN1_New(ret->sig_alg,X509_ALGOR_new);
102 M_ASN1_New(ret->signature,ASN1_BIT_STRING_new);
103 return(ret);
104 M_ASN1_New_Error(ASN1_F_X509_NEW);
105 }
106
107void X509_KEY_free(X509 *a)
108 {
109 int i;
110
111 if (a == NULL) return;
112
113 i=CRYPTO_add_lock(&a->references,-1,CRYPTO_LOCK_X509_KEY);
114#ifdef REF_PRINT
115 REF_PRINT("X509_KEY",a);
116#endif
117 if (i > 0) return;
118#ifdef REF_CHECK
119 if (i < 0)
120 {
121 fprintf(stderr,"X509_KEY_free, bad reference count\n");
122 abort();
123 }
124#endif
125
126 X509_CINF_free(a->cert_info);
127 X509_ALGOR_free(a->sig_alg);
128 ASN1_BIT_STRING_free(a->signature);
129 OPENSSL_free(a);
130 }
131
diff --git a/src/lib/libcrypto/asn1/t_crl.c b/src/lib/libcrypto/asn1/t_crl.c
index 929b3e5904..757c148df8 100644
--- a/src/lib/libcrypto/asn1/t_crl.c
+++ b/src/lib/libcrypto/asn1/t_crl.c
@@ -72,7 +72,7 @@ int X509_CRL_print_fp(FILE *fp, X509_CRL *x)
72 72
73 if ((b=BIO_new(BIO_s_file())) == NULL) 73 if ((b=BIO_new(BIO_s_file())) == NULL)
74 { 74 {
75 X509err(X509_F_X509_CRL_PRINT_FP,ERR_R_BUF_LIB); 75 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
76 return(0); 76 return(0);
77 } 77 }
78 BIO_set_fp(b,fp,BIO_NOCLOSE); 78 BIO_set_fp(b,fp,BIO_NOCLOSE);
@@ -121,7 +121,7 @@ int X509_CRL_print(BIO *out, X509_CRL *x)
121 r = sk_X509_REVOKED_value(rev, i); 121 r = sk_X509_REVOKED_value(rev, i);
122 BIO_printf(out," Serial Number: "); 122 BIO_printf(out," Serial Number: ");
123 i2a_ASN1_INTEGER(out,r->serialNumber); 123 i2a_ASN1_INTEGER(out,r->serialNumber);
124 BIO_printf(out,"\n Revocation Date: "); 124 BIO_printf(out,"\n Revocation Date: ","");
125 ASN1_TIME_print(out,r->revocationDate); 125 ASN1_TIME_print(out,r->revocationDate);
126 BIO_printf(out,"\n"); 126 BIO_printf(out,"\n");
127 X509V3_extensions_print(out, "CRL entry extensions", 127 X509V3_extensions_print(out, "CRL entry extensions",
diff --git a/src/lib/libcrypto/asn1/t_pkey.c b/src/lib/libcrypto/asn1/t_pkey.c
index afb95d6712..d15006e654 100644
--- a/src/lib/libcrypto/asn1/t_pkey.c
+++ b/src/lib/libcrypto/asn1/t_pkey.c
@@ -55,15 +55,9 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Binary polynomial ECC support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
64#include <stdio.h> 59#include <stdio.h>
65#include "cryptlib.h" 60#include "cryptlib.h"
66#include <openssl/objects.h>
67#include <openssl/buffer.h> 61#include <openssl/buffer.h>
68#include <openssl/bn.h> 62#include <openssl/bn.h>
69#ifndef OPENSSL_NO_RSA 63#ifndef OPENSSL_NO_RSA
@@ -75,33 +69,26 @@
75#ifndef OPENSSL_NO_DSA 69#ifndef OPENSSL_NO_DSA
76#include <openssl/dsa.h> 70#include <openssl/dsa.h>
77#endif 71#endif
78#ifndef OPENSSL_NO_EC
79#include <openssl/ec.h>
80#endif
81 72
82static int print(BIO *fp,const char *str, const BIGNUM *num, 73static int print(BIO *fp,const char *str,BIGNUM *num,
83 unsigned char *buf,int off); 74 unsigned char *buf,int off);
84#ifndef OPENSSL_NO_EC
85static int print_bin(BIO *fp, const char *str, const unsigned char *num,
86 size_t len, int off);
87#endif
88#ifndef OPENSSL_NO_RSA 75#ifndef OPENSSL_NO_RSA
89#ifndef OPENSSL_NO_FP_API 76#ifndef OPENSSL_NO_FP_API
90int RSA_print_fp(FILE *fp, const RSA *x, int off) 77int RSA_print_fp(FILE *fp, const RSA *x, int off)
91 { 78 {
92 BIO *b; 79 BIO *b;
93 int ret; 80 int ret;
94 81
95 if ((b=BIO_new(BIO_s_file())) == NULL) 82 if ((b=BIO_new(BIO_s_file())) == NULL)
96 { 83 {
97 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB); 84 RSAerr(RSA_F_RSA_PRINT_FP,ERR_R_BUF_LIB);
98 return(0); 85 return(0);
99 } 86 }
100 BIO_set_fp(b,fp,BIO_NOCLOSE); 87 BIO_set_fp(b,fp,BIO_NOCLOSE);
101 ret=RSA_print(b,x,off); 88 ret=RSA_print(b,x,off);
102 BIO_free(b); 89 BIO_free(b);
103 return(ret); 90 return(ret);
104 } 91 }
105#endif 92#endif
106 93
107int RSA_print(BIO *bp, const RSA *x, int off) 94int RSA_print(BIO *bp, const RSA *x, int off)
@@ -109,7 +96,7 @@ int RSA_print(BIO *bp, const RSA *x, int off)
109 char str[128]; 96 char str[128];
110 const char *s; 97 const char *s;
111 unsigned char *m=NULL; 98 unsigned char *m=NULL;
112 int ret=0, mod_len = 0; 99 int ret=0;
113 size_t buf_len=0, i; 100 size_t buf_len=0, i;
114 101
115 if (x->n) 102 if (x->n)
@@ -143,37 +130,27 @@ int RSA_print(BIO *bp, const RSA *x, int off)
143 goto err; 130 goto err;
144 } 131 }
145 132
146 if (x->n != NULL)
147 mod_len = BN_num_bits(x->n);
148
149 if (x->d != NULL) 133 if (x->d != NULL)
150 { 134 {
151 if(!BIO_indent(bp,off,128)) 135 if(!BIO_indent(bp,off,128))
152 goto err; 136 goto err;
153 if (BIO_printf(bp,"Private-Key: (%d bit)\n", mod_len) 137 if (BIO_printf(bp,"Private-Key: (%d bit)\n",BN_num_bits(x->n))
154 <= 0) goto err; 138 <= 0) goto err;
155 } 139 }
156 140
157 if (x->d == NULL) 141 if (x->d == NULL)
158 BIO_snprintf(str,sizeof str,"Modulus (%d bit):", mod_len); 142 BIO_snprintf(str,sizeof str,"Modulus (%d bit):",BN_num_bits(x->n));
159 else 143 else
160 BUF_strlcpy(str,"modulus:",sizeof str); 144 BUF_strlcpy(str,"modulus:",sizeof str);
161 if (!print(bp,str,x->n,m,off)) goto err; 145 if (!print(bp,str,x->n,m,off)) goto err;
162 s=(x->d == NULL)?"Exponent:":"publicExponent:"; 146 s=(x->d == NULL)?"Exponent:":"publicExponent:";
163 if ((x->e != NULL) && !print(bp,s,x->e,m,off)) 147 if (!print(bp,s,x->e,m,off)) goto err;
164 goto err; 148 if (!print(bp,"privateExponent:",x->d,m,off)) goto err;
165 if ((x->d != NULL) && !print(bp,"privateExponent:",x->d,m,off)) 149 if (!print(bp,"prime1:",x->p,m,off)) goto err;
166 goto err; 150 if (!print(bp,"prime2:",x->q,m,off)) goto err;
167 if ((x->p != NULL) && !print(bp,"prime1:",x->p,m,off)) 151 if (!print(bp,"exponent1:",x->dmp1,m,off)) goto err;
168 goto err; 152 if (!print(bp,"exponent2:",x->dmq1,m,off)) goto err;
169 if ((x->q != NULL) && !print(bp,"prime2:",x->q,m,off)) 153 if (!print(bp,"coefficient:",x->iqmp,m,off)) goto err;
170 goto err;
171 if ((x->dmp1 != NULL) && !print(bp,"exponent1:",x->dmp1,m,off))
172 goto err;
173 if ((x->dmq1 != NULL) && !print(bp,"exponent2:",x->dmq1,m,off))
174 goto err;
175 if ((x->iqmp != NULL) && !print(bp,"coefficient:",x->iqmp,m,off))
176 goto err;
177 ret=1; 154 ret=1;
178err: 155err:
179 if (m != NULL) OPENSSL_free(m); 156 if (m != NULL) OPENSSL_free(m);
@@ -208,11 +185,6 @@ int DSA_print(BIO *bp, const DSA *x, int off)
208 185
209 if (x->p) 186 if (x->p)
210 buf_len = (size_t)BN_num_bytes(x->p); 187 buf_len = (size_t)BN_num_bytes(x->p);
211 else
212 {
213 DSAerr(DSA_F_DSA_PRINT,DSA_R_MISSING_PARAMETERS);
214 goto err;
215 }
216 if (x->q) 188 if (x->q)
217 if (buf_len < (i = (size_t)BN_num_bytes(x->q))) 189 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
218 buf_len = i; 190 buf_len = i;
@@ -255,334 +227,16 @@ err:
255 } 227 }
256#endif /* !OPENSSL_NO_DSA */ 228#endif /* !OPENSSL_NO_DSA */
257 229
258#ifndef OPENSSL_NO_EC 230static int print(BIO *bp, const char *number, BIGNUM *num, unsigned char *buf,
259#ifndef OPENSSL_NO_FP_API
260int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off)
261 {
262 BIO *b;
263 int ret;
264
265 if ((b=BIO_new(BIO_s_file())) == NULL)
266 {
267 ECerr(EC_F_ECPKPARAMETERS_PRINT_FP,ERR_R_BUF_LIB);
268 return(0);
269 }
270 BIO_set_fp(b, fp, BIO_NOCLOSE);
271 ret = ECPKParameters_print(b, x, off);
272 BIO_free(b);
273 return(ret);
274 }
275
276int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off)
277 {
278 BIO *b;
279 int ret;
280
281 if ((b=BIO_new(BIO_s_file())) == NULL)
282 {
283 ECerr(EC_F_EC_KEY_PRINT_FP, ERR_R_BIO_LIB);
284 return(0);
285 }
286 BIO_set_fp(b, fp, BIO_NOCLOSE);
287 ret = EC_KEY_print(b, x, off);
288 BIO_free(b);
289 return(ret);
290 }
291#endif
292
293int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off)
294 {
295 unsigned char *buffer=NULL;
296 size_t buf_len=0, i;
297 int ret=0, reason=ERR_R_BIO_LIB;
298 BN_CTX *ctx=NULL;
299 const EC_POINT *point=NULL;
300 BIGNUM *p=NULL, *a=NULL, *b=NULL, *gen=NULL,
301 *order=NULL, *cofactor=NULL;
302 const unsigned char *seed;
303 size_t seed_len=0;
304
305 static const char *gen_compressed = "Generator (compressed):";
306 static const char *gen_uncompressed = "Generator (uncompressed):";
307 static const char *gen_hybrid = "Generator (hybrid):";
308
309 if (!x)
310 {
311 reason = ERR_R_PASSED_NULL_PARAMETER;
312 goto err;
313 }
314
315 if (EC_GROUP_get_asn1_flag(x))
316 {
317 /* the curve parameter are given by an asn1 OID */
318 int nid;
319
320 if (!BIO_indent(bp, off, 128))
321 goto err;
322
323 nid = EC_GROUP_get_curve_name(x);
324 if (nid == 0)
325 goto err;
326
327 if (BIO_printf(bp, "ASN1 OID: %s", OBJ_nid2sn(nid)) <= 0)
328 goto err;
329 if (BIO_printf(bp, "\n") <= 0)
330 goto err;
331 }
332 else
333 {
334 /* explicit parameters */
335 int is_char_two = 0;
336 point_conversion_form_t form;
337 int tmp_nid = EC_METHOD_get_field_type(EC_GROUP_method_of(x));
338
339 if (tmp_nid == NID_X9_62_characteristic_two_field)
340 is_char_two = 1;
341
342 if ((p = BN_new()) == NULL || (a = BN_new()) == NULL ||
343 (b = BN_new()) == NULL || (order = BN_new()) == NULL ||
344 (cofactor = BN_new()) == NULL)
345 {
346 reason = ERR_R_MALLOC_FAILURE;
347 goto err;
348 }
349
350 if (is_char_two)
351 {
352 if (!EC_GROUP_get_curve_GF2m(x, p, a, b, ctx))
353 {
354 reason = ERR_R_EC_LIB;
355 goto err;
356 }
357 }
358 else /* prime field */
359 {
360 if (!EC_GROUP_get_curve_GFp(x, p, a, b, ctx))
361 {
362 reason = ERR_R_EC_LIB;
363 goto err;
364 }
365 }
366
367 if ((point = EC_GROUP_get0_generator(x)) == NULL)
368 {
369 reason = ERR_R_EC_LIB;
370 goto err;
371 }
372 if (!EC_GROUP_get_order(x, order, NULL) ||
373 !EC_GROUP_get_cofactor(x, cofactor, NULL))
374 {
375 reason = ERR_R_EC_LIB;
376 goto err;
377 }
378
379 form = EC_GROUP_get_point_conversion_form(x);
380
381 if ((gen = EC_POINT_point2bn(x, point,
382 form, NULL, ctx)) == NULL)
383 {
384 reason = ERR_R_EC_LIB;
385 goto err;
386 }
387
388 buf_len = (size_t)BN_num_bytes(p);
389 if (buf_len < (i = (size_t)BN_num_bytes(a)))
390 buf_len = i;
391 if (buf_len < (i = (size_t)BN_num_bytes(b)))
392 buf_len = i;
393 if (buf_len < (i = (size_t)BN_num_bytes(gen)))
394 buf_len = i;
395 if (buf_len < (i = (size_t)BN_num_bytes(order)))
396 buf_len = i;
397 if (buf_len < (i = (size_t)BN_num_bytes(cofactor)))
398 buf_len = i;
399
400 if ((seed = EC_GROUP_get0_seed(x)) != NULL)
401 seed_len = EC_GROUP_get_seed_len(x);
402
403 buf_len += 10;
404 if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
405 {
406 reason = ERR_R_MALLOC_FAILURE;
407 goto err;
408 }
409
410 if (!BIO_indent(bp, off, 128))
411 goto err;
412
413 /* print the 'short name' of the field type */
414 if (BIO_printf(bp, "Field Type: %s\n", OBJ_nid2sn(tmp_nid))
415 <= 0)
416 goto err;
417
418 if (is_char_two)
419 {
420 /* print the 'short name' of the base type OID */
421 int basis_type = EC_GROUP_get_basis_type(x);
422 if (basis_type == 0)
423 goto err;
424
425 if (!BIO_indent(bp, off, 128))
426 goto err;
427
428 if (BIO_printf(bp, "Basis Type: %s\n",
429 OBJ_nid2sn(basis_type)) <= 0)
430 goto err;
431
432 /* print the polynomial */
433 if ((p != NULL) && !print(bp, "Polynomial:", p, buffer,
434 off))
435 goto err;
436 }
437 else
438 {
439 if ((p != NULL) && !print(bp, "Prime:", p, buffer,off))
440 goto err;
441 }
442 if ((a != NULL) && !print(bp, "A: ", a, buffer, off))
443 goto err;
444 if ((b != NULL) && !print(bp, "B: ", b, buffer, off))
445 goto err;
446 if (form == POINT_CONVERSION_COMPRESSED)
447 {
448 if ((gen != NULL) && !print(bp, gen_compressed, gen,
449 buffer, off))
450 goto err;
451 }
452 else if (form == POINT_CONVERSION_UNCOMPRESSED)
453 {
454 if ((gen != NULL) && !print(bp, gen_uncompressed, gen,
455 buffer, off))
456 goto err;
457 }
458 else /* form == POINT_CONVERSION_HYBRID */
459 {
460 if ((gen != NULL) && !print(bp, gen_hybrid, gen,
461 buffer, off))
462 goto err;
463 }
464 if ((order != NULL) && !print(bp, "Order: ", order,
465 buffer, off)) goto err;
466 if ((cofactor != NULL) && !print(bp, "Cofactor: ", cofactor,
467 buffer, off)) goto err;
468 if (seed && !print_bin(bp, "Seed:", seed, seed_len, off))
469 goto err;
470 }
471 ret=1;
472err:
473 if (!ret)
474 ECerr(EC_F_ECPKPARAMETERS_PRINT, reason);
475 if (p)
476 BN_free(p);
477 if (a)
478 BN_free(a);
479 if (b)
480 BN_free(b);
481 if (gen)
482 BN_free(gen);
483 if (order)
484 BN_free(order);
485 if (cofactor)
486 BN_free(cofactor);
487 if (ctx)
488 BN_CTX_free(ctx);
489 if (buffer != NULL)
490 OPENSSL_free(buffer);
491 return(ret);
492 }
493
494int EC_KEY_print(BIO *bp, const EC_KEY *x, int off)
495 {
496 unsigned char *buffer=NULL;
497 size_t buf_len=0, i;
498 int ret=0, reason=ERR_R_BIO_LIB;
499 BIGNUM *pub_key=NULL, *order=NULL;
500 BN_CTX *ctx=NULL;
501 const EC_GROUP *group;
502 const EC_POINT *public_key;
503 const BIGNUM *priv_key;
504
505 if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
506 {
507 reason = ERR_R_PASSED_NULL_PARAMETER;
508 goto err;
509 }
510
511 public_key = EC_KEY_get0_public_key(x);
512 if ((pub_key = EC_POINT_point2bn(group, public_key,
513 EC_KEY_get_conv_form(x), NULL, ctx)) == NULL)
514 {
515 reason = ERR_R_EC_LIB;
516 goto err;
517 }
518
519 buf_len = (size_t)BN_num_bytes(pub_key);
520 priv_key = EC_KEY_get0_private_key(x);
521 if (priv_key != NULL)
522 {
523 if ((i = (size_t)BN_num_bytes(priv_key)) > buf_len)
524 buf_len = i;
525 }
526
527 buf_len += 10;
528 if ((buffer = OPENSSL_malloc(buf_len)) == NULL)
529 {
530 reason = ERR_R_MALLOC_FAILURE;
531 goto err;
532 }
533
534 if (priv_key != NULL)
535 {
536 if (!BIO_indent(bp, off, 128))
537 goto err;
538 if ((order = BN_new()) == NULL)
539 goto err;
540 if (!EC_GROUP_get_order(group, order, NULL))
541 goto err;
542 if (BIO_printf(bp, "Private-Key: (%d bit)\n",
543 BN_num_bits(order)) <= 0) goto err;
544 }
545
546 if ((priv_key != NULL) && !print(bp, "priv:", priv_key,
547 buffer, off))
548 goto err;
549 if ((pub_key != NULL) && !print(bp, "pub: ", pub_key,
550 buffer, off))
551 goto err;
552 if (!ECPKParameters_print(bp, group, off))
553 goto err;
554 ret=1;
555err:
556 if (!ret)
557 ECerr(EC_F_EC_KEY_PRINT, reason);
558 if (pub_key)
559 BN_free(pub_key);
560 if (order)
561 BN_free(order);
562 if (ctx)
563 BN_CTX_free(ctx);
564 if (buffer != NULL)
565 OPENSSL_free(buffer);
566 return(ret);
567 }
568#endif /* OPENSSL_NO_EC */
569
570static int print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *buf,
571 int off) 231 int off)
572 { 232 {
573 int n,i; 233 int n,i;
574 const char *neg; 234 const char *neg;
575 235
576 if (num == NULL) return(1); 236 if (num == NULL) return(1);
577 neg = (BN_is_negative(num))?"-":""; 237 neg=(num->neg)?"-":"";
578 if(!BIO_indent(bp,off,128)) 238 if(!BIO_indent(bp,off,128))
579 return 0; 239 return 0;
580 if (BN_is_zero(num))
581 {
582 if (BIO_printf(bp, "%s 0\n", number) <= 0)
583 return 0;
584 return 1;
585 }
586 240
587 if (BN_num_bytes(num) <= BN_BYTES) 241 if (BN_num_bytes(num) <= BN_BYTES)
588 { 242 {
@@ -618,63 +272,23 @@ static int print(BIO *bp, const char *number, const BIGNUM *num, unsigned char *
618 return(1); 272 return(1);
619 } 273 }
620 274
621#ifndef OPENSSL_NO_EC
622static int print_bin(BIO *fp, const char *name, const unsigned char *buf,
623 size_t len, int off)
624 {
625 size_t i;
626 char str[128];
627
628 if (buf == NULL)
629 return 1;
630 if (off)
631 {
632 if (off > 128)
633 off=128;
634 memset(str,' ',off);
635 if (BIO_write(fp, str, off) <= 0)
636 return 0;
637 }
638
639 if (BIO_printf(fp,"%s", name) <= 0)
640 return 0;
641
642 for (i=0; i<len; i++)
643 {
644 if ((i%15) == 0)
645 {
646 str[0]='\n';
647 memset(&(str[1]),' ',off+4);
648 if (BIO_write(fp, str, off+1+4) <= 0)
649 return 0;
650 }
651 if (BIO_printf(fp,"%02x%s",buf[i],((i+1) == len)?"":":") <= 0)
652 return 0;
653 }
654 if (BIO_write(fp,"\n",1) <= 0)
655 return 0;
656
657 return 1;
658 }
659#endif
660
661#ifndef OPENSSL_NO_DH 275#ifndef OPENSSL_NO_DH
662#ifndef OPENSSL_NO_FP_API 276#ifndef OPENSSL_NO_FP_API
663int DHparams_print_fp(FILE *fp, const DH *x) 277int DHparams_print_fp(FILE *fp, const DH *x)
664 { 278 {
665 BIO *b; 279 BIO *b;
666 int ret; 280 int ret;
667 281
668 if ((b=BIO_new(BIO_s_file())) == NULL) 282 if ((b=BIO_new(BIO_s_file())) == NULL)
669 { 283 {
670 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB); 284 DHerr(DH_F_DHPARAMS_PRINT_FP,ERR_R_BUF_LIB);
671 return(0); 285 return(0);
672 } 286 }
673 BIO_set_fp(b,fp,BIO_NOCLOSE); 287 BIO_set_fp(b,fp,BIO_NOCLOSE);
674 ret=DHparams_print(b, x); 288 ret=DHparams_print(b, x);
675 BIO_free(b); 289 BIO_free(b);
676 return(ret); 290 return(ret);
677 } 291 }
678#endif 292#endif
679 293
680int DHparams_print(BIO *bp, const DH *x) 294int DHparams_print(BIO *bp, const DH *x)
@@ -685,11 +299,6 @@ int DHparams_print(BIO *bp, const DH *x)
685 299
686 if (x->p) 300 if (x->p)
687 buf_len = (size_t)BN_num_bytes(x->p); 301 buf_len = (size_t)BN_num_bytes(x->p);
688 else
689 {
690 reason = ERR_R_PASSED_NULL_PARAMETER;
691 goto err;
692 }
693 if (x->g) 302 if (x->g)
694 if (buf_len < (i = (size_t)BN_num_bytes(x->g))) 303 if (buf_len < (i = (size_t)BN_num_bytes(x->g)))
695 buf_len = i; 304 buf_len = i;
@@ -724,35 +333,30 @@ err:
724#ifndef OPENSSL_NO_DSA 333#ifndef OPENSSL_NO_DSA
725#ifndef OPENSSL_NO_FP_API 334#ifndef OPENSSL_NO_FP_API
726int DSAparams_print_fp(FILE *fp, const DSA *x) 335int DSAparams_print_fp(FILE *fp, const DSA *x)
727 { 336 {
728 BIO *b; 337 BIO *b;
729 int ret; 338 int ret;
730 339
731 if ((b=BIO_new(BIO_s_file())) == NULL) 340 if ((b=BIO_new(BIO_s_file())) == NULL)
732 { 341 {
733 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB); 342 DSAerr(DSA_F_DSAPARAMS_PRINT_FP,ERR_R_BUF_LIB);
734 return(0); 343 return(0);
735 } 344 }
736 BIO_set_fp(b,fp,BIO_NOCLOSE); 345 BIO_set_fp(b,fp,BIO_NOCLOSE);
737 ret=DSAparams_print(b, x); 346 ret=DSAparams_print(b, x);
738 BIO_free(b); 347 BIO_free(b);
739 return(ret); 348 return(ret);
740 } 349 }
741#endif 350#endif
742 351
743int DSAparams_print(BIO *bp, const DSA *x) 352int DSAparams_print(BIO *bp, const DSA *x)
744 { 353 {
745 unsigned char *m=NULL; 354 unsigned char *m=NULL;
746 int ret=0; 355 int reason=ERR_R_BUF_LIB,ret=0;
747 size_t buf_len=0,i; 356 size_t buf_len=0,i;
748 357
749 if (x->p) 358 if (x->p)
750 buf_len = (size_t)BN_num_bytes(x->p); 359 buf_len = (size_t)BN_num_bytes(x->p);
751 else
752 {
753 DSAerr(DSA_F_DSAPARAMS_PRINT,DSA_R_MISSING_PARAMETERS);
754 goto err;
755 }
756 if (x->q) 360 if (x->q)
757 if (buf_len < (i = (size_t)BN_num_bytes(x->q))) 361 if (buf_len < (i = (size_t)BN_num_bytes(x->q)))
758 buf_len = i; 362 buf_len = i;
@@ -762,7 +366,7 @@ int DSAparams_print(BIO *bp, const DSA *x)
762 m=(unsigned char *)OPENSSL_malloc(buf_len+10); 366 m=(unsigned char *)OPENSSL_malloc(buf_len+10);
763 if (m == NULL) 367 if (m == NULL)
764 { 368 {
765 DSAerr(DSA_F_DSAPARAMS_PRINT,ERR_R_MALLOC_FAILURE); 369 reason=ERR_R_MALLOC_FAILURE;
766 goto err; 370 goto err;
767 } 371 }
768 372
@@ -770,70 +374,14 @@ int DSAparams_print(BIO *bp, const DSA *x)
770 BN_num_bits(x->p)) <= 0) 374 BN_num_bits(x->p)) <= 0)
771 goto err; 375 goto err;
772 if (!print(bp,"p:",x->p,m,4)) goto err; 376 if (!print(bp,"p:",x->p,m,4)) goto err;
773 if ((x->q != NULL) && !print(bp,"q:",x->q,m,4)) goto err; 377 if (!print(bp,"q:",x->q,m,4)) goto err;
774 if ((x->g != NULL) && !print(bp,"g:",x->g,m,4)) goto err; 378 if (!print(bp,"g:",x->g,m,4)) goto err;
775 ret=1; 379 ret=1;
776err: 380err:
777 if (m != NULL) OPENSSL_free(m); 381 if (m != NULL) OPENSSL_free(m);
382 DSAerr(DSA_F_DSAPARAMS_PRINT,reason);
778 return(ret); 383 return(ret);
779 } 384 }
780 385
781#endif /* !OPENSSL_NO_DSA */ 386#endif /* !OPENSSL_NO_DSA */
782 387
783#ifndef OPENSSL_NO_EC
784#ifndef OPENSSL_NO_FP_API
785int ECParameters_print_fp(FILE *fp, const EC_KEY *x)
786 {
787 BIO *b;
788 int ret;
789
790 if ((b=BIO_new(BIO_s_file())) == NULL)
791 {
792 ECerr(EC_F_ECPARAMETERS_PRINT_FP, ERR_R_BIO_LIB);
793 return(0);
794 }
795 BIO_set_fp(b, fp, BIO_NOCLOSE);
796 ret = ECParameters_print(b, x);
797 BIO_free(b);
798 return(ret);
799 }
800#endif
801
802int ECParameters_print(BIO *bp, const EC_KEY *x)
803 {
804 int reason=ERR_R_EC_LIB, ret=0;
805 BIGNUM *order=NULL;
806 const EC_GROUP *group;
807
808 if (x == NULL || (group = EC_KEY_get0_group(x)) == NULL)
809 {
810 reason = ERR_R_PASSED_NULL_PARAMETER;;
811 goto err;
812 }
813
814 if ((order = BN_new()) == NULL)
815 {
816 reason = ERR_R_MALLOC_FAILURE;
817 goto err;
818 }
819
820 if (!EC_GROUP_get_order(group, order, NULL))
821 {
822 reason = ERR_R_EC_LIB;
823 goto err;
824 }
825
826 if (BIO_printf(bp, "ECDSA-Parameters: (%d bit)\n",
827 BN_num_bits(order)) <= 0)
828 goto err;
829 if (!ECPKParameters_print(bp, group, 4))
830 goto err;
831 ret=1;
832err:
833 if (order)
834 BN_free(order);
835 ECerr(EC_F_ECPARAMETERS_PRINT, reason);
836 return(ret);
837 }
838
839#endif
diff --git a/src/lib/libcrypto/asn1/t_req.c b/src/lib/libcrypto/asn1/t_req.c
index 5557e06584..740cee80c0 100644
--- a/src/lib/libcrypto/asn1/t_req.c
+++ b/src/lib/libcrypto/asn1/t_req.c
@@ -63,12 +63,6 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66#ifndef OPENSSL_NO_RSA
67#include <openssl/rsa.h>
68#endif
69#ifndef OPENSSL_NO_DSA
70#include <openssl/dsa.h>
71#endif
72 66
73#ifndef OPENSSL_NO_FP_API 67#ifndef OPENSSL_NO_FP_API
74int X509_REQ_print_fp(FILE *fp, X509_REQ *x) 68int X509_REQ_print_fp(FILE *fp, X509_REQ *x)
@@ -166,14 +160,6 @@ int X509_REQ_print_ex(BIO *bp, X509_REQ *x, unsigned long nmflags, unsigned long
166 } 160 }
167 else 161 else
168#endif 162#endif
169#ifndef OPENSSL_NO_EC
170 if (pkey->type == EVP_PKEY_EC)
171 {
172 BIO_printf(bp, "%12sEC Public Key: \n","");
173 EC_KEY_print(bp, pkey->pkey.ec, 16);
174 }
175 else
176#endif
177 BIO_printf(bp,"%12sUnknown Public Key:\n",""); 163 BIO_printf(bp,"%12sUnknown Public Key:\n","");
178 164
179 EVP_PKEY_free(pkey); 165 EVP_PKEY_free(pkey);
@@ -244,7 +230,7 @@ get_next:
244 } 230 }
245 } 231 }
246 } 232 }
247 if(!(cflag & X509_FLAG_NO_EXTENSIONS)) 233 if(!(cflag & X509_FLAG_NO_ATTRIBUTES))
248 { 234 {
249 exts = X509_REQ_get_extensions(x); 235 exts = X509_REQ_get_extensions(x);
250 if(exts) 236 if(exts)
@@ -260,9 +246,9 @@ get_next:
260 obj=X509_EXTENSION_get_object(ex); 246 obj=X509_EXTENSION_get_object(ex);
261 i2a_ASN1_OBJECT(bp,obj); 247 i2a_ASN1_OBJECT(bp,obj);
262 j=X509_EXTENSION_get_critical(ex); 248 j=X509_EXTENSION_get_critical(ex);
263 if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) 249 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
264 goto err; 250 goto err;
265 if(!X509V3_EXT_print(bp, ex, cflag, 16)) 251 if(!X509V3_EXT_print(bp, ex, 0, 16))
266 { 252 {
267 BIO_printf(bp, "%16s", ""); 253 BIO_printf(bp, "%16s", "");
268 M_ASN1_OCTET_STRING_print(bp,ex->value); 254 M_ASN1_OCTET_STRING_print(bp,ex->value);
@@ -280,7 +266,7 @@ get_next:
280 266
281 return(1); 267 return(1);
282err: 268err:
283 X509err(X509_F_X509_REQ_PRINT_EX,ERR_R_BUF_LIB); 269 X509err(X509_F_X509_REQ_PRINT,ERR_R_BUF_LIB);
284 return(0); 270 return(0);
285 } 271 }
286 272
diff --git a/src/lib/libcrypto/asn1/t_spki.c b/src/lib/libcrypto/asn1/t_spki.c
index c2a5797dd8..5abfbc815e 100644
--- a/src/lib/libcrypto/asn1/t_spki.c
+++ b/src/lib/libcrypto/asn1/t_spki.c
@@ -60,13 +60,6 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/x509.h> 61#include <openssl/x509.h>
62#include <openssl/asn1.h> 62#include <openssl/asn1.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DSA
67#include <openssl/dsa.h>
68#endif
69#include <openssl/bn.h>
70 63
71/* Print out an SPKI */ 64/* Print out an SPKI */
72 65
@@ -100,15 +93,6 @@ int NETSCAPE_SPKI_print(BIO *out, NETSCAPE_SPKI *spki)
100 } 93 }
101 else 94 else
102#endif 95#endif
103#ifndef OPENSSL_NO_EC
104 if (pkey->type == EVP_PKEY_EC)
105 {
106 BIO_printf(out, " EC Public Key:\n");
107 EC_KEY_print(out, pkey->pkey.ec,2);
108 }
109 else
110#endif
111
112 BIO_printf(out," Unknown Public Key:\n"); 96 BIO_printf(out," Unknown Public Key:\n");
113 EVP_PKEY_free(pkey); 97 EVP_PKEY_free(pkey);
114 } 98 }
diff --git a/src/lib/libcrypto/asn1/t_x509.c b/src/lib/libcrypto/asn1/t_x509.c
index eb776b7b3b..30f68561b7 100644
--- a/src/lib/libcrypto/asn1/t_x509.c
+++ b/src/lib/libcrypto/asn1/t_x509.c
@@ -66,9 +66,6 @@
66#ifndef OPENSSL_NO_DSA 66#ifndef OPENSSL_NO_DSA
67#include <openssl/dsa.h> 67#include <openssl/dsa.h>
68#endif 68#endif
69#ifndef OPENSSL_NO_EC
70#include <openssl/ec.h>
71#endif
72#include <openssl/objects.h> 69#include <openssl/objects.h>
73#include <openssl/x509.h> 70#include <openssl/x509.h>
74#include <openssl/x509v3.h> 71#include <openssl/x509v3.h>
@@ -86,7 +83,7 @@ int X509_print_ex_fp(FILE *fp, X509 *x, unsigned long nmflag, unsigned long cfla
86 83
87 if ((b=BIO_new(BIO_s_file())) == NULL) 84 if ((b=BIO_new(BIO_s_file())) == NULL)
88 { 85 {
89 X509err(X509_F_X509_PRINT_EX_FP,ERR_R_BUF_LIB); 86 X509err(X509_F_X509_PRINT_FP,ERR_R_BUF_LIB);
90 return(0); 87 return(0);
91 } 88 }
92 BIO_set_fp(b,fp,BIO_NOCLOSE); 89 BIO_set_fp(b,fp,BIO_NOCLOSE);
@@ -232,14 +229,6 @@ int X509_print_ex(BIO *bp, X509 *x, unsigned long nmflags, unsigned long cflag)
232 } 229 }
233 else 230 else
234#endif 231#endif
235#ifndef OPENSSL_NO_EC
236 if (pkey->type == EVP_PKEY_EC)
237 {
238 BIO_printf(bp, "%12sEC Public Key:\n","");
239 EC_KEY_print(bp, pkey->pkey.ec, 16);
240 }
241 else
242#endif
243 BIO_printf(bp,"%12sUnknown Public Key:\n",""); 232 BIO_printf(bp,"%12sUnknown Public Key:\n","");
244 233
245 EVP_PKEY_free(pkey); 234 EVP_PKEY_free(pkey);
@@ -332,7 +321,7 @@ int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
332int ASN1_STRING_print(BIO *bp, ASN1_STRING *v) 321int ASN1_STRING_print(BIO *bp, ASN1_STRING *v)
333 { 322 {
334 int i,n; 323 int i,n;
335 char buf[80],*p;; 324 char buf[80],*p;
336 325
337 if (v == NULL) return(0); 326 if (v == NULL) return(0);
338 n=0; 327 n=0;
@@ -445,18 +434,19 @@ err:
445int X509_NAME_print(BIO *bp, X509_NAME *name, int obase) 434int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
446 { 435 {
447 char *s,*c,*b; 436 char *s,*c,*b;
448 int ret=0,l,i; 437 int ret=0,l,ll,i,first=1;
449 438
450 l=80-2-obase; 439 ll=80-2-obase;
451 440
452 b=X509_NAME_oneline(name,NULL,0); 441 b=s=X509_NAME_oneline(name,NULL,0);
453 if (!*b) 442 if (!*s)
454 { 443 {
455 OPENSSL_free(b); 444 OPENSSL_free(b);
456 return 1; 445 return 1;
457 } 446 }
458 s=b+1; /* skip the first slash */ 447 s++; /* skip the first slash */
459 448
449 l=ll;
460 c=s; 450 c=s;
461 for (;;) 451 for (;;)
462 { 452 {
@@ -478,9 +468,20 @@ int X509_NAME_print(BIO *bp, X509_NAME *name, int obase)
478 (*s == '\0')) 468 (*s == '\0'))
479#endif 469#endif
480 { 470 {
471 if ((l <= 0) && !first)
472 {
473 first=0;
474 if (BIO_write(bp,"\n",1) != 1) goto err;
475 for (i=0; i<obase; i++)
476 {
477 if (BIO_write(bp," ",1) != 1) goto err;
478 }
479 l=ll;
480 }
481 i=s-c; 481 i=s-c;
482 if (BIO_write(bp,c,i) != i) goto err; 482 if (BIO_write(bp,c,i) != i) goto err;
483 c=s+1; /* skip following slash */ 483 c+=i;
484 c++;
484 if (*s != '\0') 485 if (*s != '\0')
485 { 486 {
486 if (BIO_write(bp,", ",2) != 2) goto err; 487 if (BIO_write(bp,", ",2) != 2) goto err;
diff --git a/src/lib/libcrypto/asn1/tasn_dec.c b/src/lib/libcrypto/asn1/tasn_dec.c
index 0ee406231e..b7e916ef36 100644
--- a/src/lib/libcrypto/asn1/tasn_dec.c
+++ b/src/lib/libcrypto/asn1/tasn_dec.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -65,40 +65,24 @@
65#include <openssl/buffer.h> 65#include <openssl/buffer.h>
66#include <openssl/err.h> 66#include <openssl/err.h>
67 67
68static int asn1_check_eoc(const unsigned char **in, long len); 68static int asn1_check_eoc(unsigned char **in, long len);
69static int asn1_find_end(const unsigned char **in, long len, char inf); 69static int asn1_find_end(unsigned char **in, long len, char inf);
70 70static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass);
71static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, 71static int collect_data(BUF_MEM *buf, unsigned char **p, long plen);
72 char inf, int tag, int aclass); 72static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
73 73 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx);
74static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen); 74static int asn1_template_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
75 75static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx);
76static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, 76static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long len,
77 char *inf, char *cst, 77 const ASN1_ITEM *it, int tag, int aclass, char opt, ASN1_TLC *ctx);
78 const unsigned char **in, long len,
79 int exptag, int expclass, char opt,
80 ASN1_TLC *ctx);
81
82static int asn1_template_ex_d2i(ASN1_VALUE **pval,
83 const unsigned char **in, long len,
84 const ASN1_TEMPLATE *tt, char opt,
85 ASN1_TLC *ctx);
86static int asn1_template_noexp_d2i(ASN1_VALUE **val,
87 const unsigned char **in, long len,
88 const ASN1_TEMPLATE *tt, char opt,
89 ASN1_TLC *ctx);
90static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
91 const unsigned char **in, long len,
92 const ASN1_ITEM *it,
93 int tag, int aclass, char opt, ASN1_TLC *ctx);
94 78
95/* Table to convert tags to bit values, used for MSTRING type */ 79/* Table to convert tags to bit values, used for MSTRING type */
96static const unsigned long tag2bit[32] = { 80static unsigned long tag2bit[32]={
970, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */ 810, 0, 0, B_ASN1_BIT_STRING, /* tags 0 - 3 */
98B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */ 82B_ASN1_OCTET_STRING, 0, 0, B_ASN1_UNKNOWN,/* tags 4- 7 */
99B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */ 83B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN, B_ASN1_UNKNOWN,/* tags 8-11 */
100B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */ 84B_ASN1_UTF8STRING,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,B_ASN1_UNKNOWN,/* tags 12-15 */
101B_ASN1_SEQUENCE,0,B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */ 850, 0, B_ASN1_NUMERICSTRING,B_ASN1_PRINTABLESTRING, /* tags 16-19 */
102B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */ 86B_ASN1_T61STRING,B_ASN1_VIDEOTEXSTRING,B_ASN1_IA5STRING, /* tags 20-22 */
103B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */ 87B_ASN1_UTCTIME, B_ASN1_GENERALIZEDTIME, /* tags 23-24 */
104B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */ 88B_ASN1_GRAPHICSTRING,B_ASN1_ISO64STRING,B_ASN1_GENERALSTRING, /* tags 25-27 */
@@ -106,14 +90,14 @@ B_ASN1_UNIVERSALSTRING,B_ASN1_UNKNOWN,B_ASN1_BMPSTRING,B_ASN1_UNKNOWN, /* tags 2
106 }; 90 };
107 91
108unsigned long ASN1_tag2bit(int tag) 92unsigned long ASN1_tag2bit(int tag)
109 { 93{
110 if ((tag < 0) || (tag > 30)) return 0; 94 if((tag < 0) || (tag > 30)) return 0;
111 return tag2bit[tag]; 95 return tag2bit[tag];
112 } 96}
113 97
114/* Macro to initialize and invalidate the cache */ 98/* Macro to initialize and invalidate the cache */
115 99
116#define asn1_tlc_clear(c) if (c) (c)->valid = 0 100#define asn1_tlc_clear(c) if(c) (c)->valid = 0
117 101
118/* Decode an ASN1 item, this currently behaves just 102/* Decode an ASN1 item, this currently behaves just
119 * like a standard 'd2i' function. 'in' points to 103 * like a standard 'd2i' function. 'in' points to
@@ -123,147 +107,113 @@ unsigned long ASN1_tag2bit(int tag)
123 * case. 107 * case.
124 */ 108 */
125 109
126ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, 110ASN1_VALUE *ASN1_item_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it)
127 const unsigned char **in, long len, const ASN1_ITEM *it) 111{
128 {
129 ASN1_TLC c; 112 ASN1_TLC c;
130 ASN1_VALUE *ptmpval = NULL; 113 ASN1_VALUE *ptmpval = NULL;
131 if (!pval) 114 if(!pval) pval = &ptmpval;
132 pval = &ptmpval; 115 asn1_tlc_clear(&c);
133 c.valid = 0; 116 if(ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
134 if (ASN1_item_ex_d2i(pval, in, len, it, -1, 0, 0, &c) > 0)
135 return *pval; 117 return *pval;
136 return NULL; 118 return NULL;
137 } 119}
138 120
139int ASN1_template_d2i(ASN1_VALUE **pval, 121int ASN1_template_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_TEMPLATE *tt)
140 const unsigned char **in, long len, const ASN1_TEMPLATE *tt) 122{
141 {
142 ASN1_TLC c; 123 ASN1_TLC c;
143 c.valid = 0; 124 asn1_tlc_clear(&c);
144 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c); 125 return asn1_template_ex_d2i(pval, in, len, tt, 0, &c);
145 } 126}
146 127
147 128
148/* Decode an item, taking care of IMPLICIT tagging, if any. 129/* Decode an item, taking care of IMPLICIT tagging, if any.
149 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL 130 * If 'opt' set and tag mismatch return -1 to handle OPTIONAL
150 */ 131 */
151 132
152int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len, 133int ASN1_item_ex_d2i(ASN1_VALUE **pval, unsigned char **in, long len, const ASN1_ITEM *it,
153 const ASN1_ITEM *it, 134 int tag, int aclass, char opt, ASN1_TLC *ctx)
154 int tag, int aclass, char opt, ASN1_TLC *ctx) 135{
155 {
156 const ASN1_TEMPLATE *tt, *errtt = NULL; 136 const ASN1_TEMPLATE *tt, *errtt = NULL;
157 const ASN1_COMPAT_FUNCS *cf; 137 const ASN1_COMPAT_FUNCS *cf;
158 const ASN1_EXTERN_FUNCS *ef; 138 const ASN1_EXTERN_FUNCS *ef;
159 const ASN1_AUX *aux = it->funcs; 139 const ASN1_AUX *aux = it->funcs;
160 ASN1_aux_cb *asn1_cb; 140 ASN1_aux_cb *asn1_cb;
161 const unsigned char *p = NULL, *q; 141 unsigned char *p, *q, imphack = 0, oclass;
162 unsigned char *wp=NULL; /* BIG FAT WARNING! BREAKS CONST WHERE USED */
163 unsigned char imphack = 0, oclass;
164 char seq_eoc, seq_nolen, cst, isopt; 142 char seq_eoc, seq_nolen, cst, isopt;
165 long tmplen; 143 long tmplen;
166 int i; 144 int i;
167 int otag; 145 int otag;
168 int ret = 0; 146 int ret = 0;
169 ASN1_VALUE *pchval, **pchptr, *ptmpval; 147 ASN1_VALUE *pchval, **pchptr, *ptmpval;
170 if (!pval) 148 if(!pval) return 0;
171 return 0; 149 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
172 if (aux && aux->asn1_cb)
173 asn1_cb = aux->asn1_cb;
174 else asn1_cb = 0; 150 else asn1_cb = 0;
175 151
176 switch(it->itype) 152 switch(it->itype) {
177 { 153
178 case ASN1_ITYPE_PRIMITIVE: 154 case ASN1_ITYPE_PRIMITIVE:
179 if (it->templates) 155 if(it->templates) {
180 { 156 /* tagging or OPTIONAL is currently illegal on an item template
181 /* tagging or OPTIONAL is currently illegal on an item 157 * because the flags can't get passed down. In practice this isn't
182 * template because the flags can't get passed down. 158 * a problem: we include the relevant flags from the item template
183 * In practice this isn't a problem: we include the 159 * in the template itself.
184 * relevant flags from the item template in the
185 * template itself.
186 */ 160 */
187 if ((tag != -1) || opt) 161 if ((tag != -1) || opt) {
188 { 162 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
189 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
190 ASN1_R_ILLEGAL_OPTIONS_ON_ITEM_TEMPLATE);
191 goto err; 163 goto err;
192 } 164 }
193 return asn1_template_ex_d2i(pval, in, len, 165 return asn1_template_ex_d2i(pval, in, len, it->templates, opt, ctx);
194 it->templates, opt, ctx);
195 } 166 }
196 return asn1_d2i_ex_primitive(pval, in, len, it, 167 return asn1_d2i_ex_primitive(pval, in, len, it, tag, aclass, opt, ctx);
197 tag, aclass, opt, ctx);
198 break; 168 break;
199 169
200 case ASN1_ITYPE_MSTRING: 170 case ASN1_ITYPE_MSTRING:
201 p = *in; 171 p = *in;
202 /* Just read in tag and class */ 172 /* Just read in tag and class */
203 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, 173 ret = asn1_check_tlen(NULL, &otag, &oclass, NULL, NULL, &p, len, -1, 0, 1, ctx);
204 &p, len, -1, 0, 1, ctx); 174 if(!ret) {
205 if (!ret) 175 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
206 {
207 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
208 ERR_R_NESTED_ASN1_ERROR);
209 goto err; 176 goto err;
210 } 177 }
211
212 /* Must be UNIVERSAL class */ 178 /* Must be UNIVERSAL class */
213 if (oclass != V_ASN1_UNIVERSAL) 179 if(oclass != V_ASN1_UNIVERSAL) {
214 {
215 /* If OPTIONAL, assume this is OK */ 180 /* If OPTIONAL, assume this is OK */
216 if (opt) return -1; 181 if(opt) return -1;
217 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 182 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_NOT_UNIVERSAL);
218 ASN1_R_MSTRING_NOT_UNIVERSAL);
219 goto err; 183 goto err;
220 } 184 }
221 /* Check tag matches bit map */ 185 /* Check tag matches bit map */
222 if (!(ASN1_tag2bit(otag) & it->utype)) 186 if(!(ASN1_tag2bit(otag) & it->utype)) {
223 {
224 /* If OPTIONAL, assume this is OK */ 187 /* If OPTIONAL, assume this is OK */
225 if (opt) 188 if(opt) return -1;
226 return -1; 189 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MSTRING_WRONG_TAG);
227 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
228 ASN1_R_MSTRING_WRONG_TAG);
229 goto err; 190 goto err;
230 } 191 }
231 return asn1_d2i_ex_primitive(pval, in, len, 192 return asn1_d2i_ex_primitive(pval, in, len, it, otag, 0, 0, ctx);
232 it, otag, 0, 0, ctx);
233 193
234 case ASN1_ITYPE_EXTERN: 194 case ASN1_ITYPE_EXTERN:
235 /* Use new style d2i */ 195 /* Use new style d2i */
236 ef = it->funcs; 196 ef = it->funcs;
237 return ef->asn1_ex_d2i(pval, in, len, 197 return ef->asn1_ex_d2i(pval, in, len, it, tag, aclass, opt, ctx);
238 it, tag, aclass, opt, ctx);
239 198
240 case ASN1_ITYPE_COMPAT: 199 case ASN1_ITYPE_COMPAT:
241 /* we must resort to old style evil hackery */ 200 /* we must resort to old style evil hackery */
242 cf = it->funcs; 201 cf = it->funcs;
243 202
244 /* If OPTIONAL see if it is there */ 203 /* If OPTIONAL see if it is there */
245 if (opt) 204 if(opt) {
246 {
247 int exptag; 205 int exptag;
248 p = *in; 206 p = *in;
249 if (tag == -1) 207 if(tag == -1) exptag = it->utype;
250 exptag = it->utype;
251 else exptag = tag; 208 else exptag = tag;
252 /* Don't care about anything other than presence 209 /* Don't care about anything other than presence of expected tag */
253 * of expected tag */ 210 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, &p, len, exptag, aclass, 1, ctx);
254 211 if(!ret) {
255 ret = asn1_check_tlen(NULL, NULL, NULL, NULL, NULL, 212 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
256 &p, len, exptag, aclass, 1, ctx);
257 if (!ret)
258 {
259 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
260 ERR_R_NESTED_ASN1_ERROR);
261 goto err; 213 goto err;
262 }
263 if (ret == -1)
264 return -1;
265 } 214 }
266 215 if(ret == -1) return -1;
216 }
267 /* This is the old style evil hack IMPLICIT handling: 217 /* This is the old style evil hack IMPLICIT handling:
268 * since the underlying code is expecting a tag and 218 * since the underlying code is expecting a tag and
269 * class other than the one present we change the 219 * class other than the one present we change the
@@ -279,332 +229,245 @@ int ASN1_item_ex_d2i(ASN1_VALUE **pval, const unsigned char **in, long len,
279 * buffer. 229 * buffer.
280 */ 230 */
281 231
282 if (tag != -1) 232 if(tag != -1) {
283 { 233 p = *in;
284 wp = *(unsigned char **)in; 234 imphack = *p;
285 imphack = *wp; 235 *p = (unsigned char)((*p & V_ASN1_CONSTRUCTED) | it->utype);
286 if (p == NULL) 236 }
287 {
288 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
289 ERR_R_NESTED_ASN1_ERROR);
290 goto err;
291 }
292 *wp = (unsigned char)((*p & V_ASN1_CONSTRUCTED)
293 | it->utype);
294 }
295 237
296 ptmpval = cf->asn1_d2i(pval, in, len); 238 ptmpval = cf->asn1_d2i(pval, in, len);
297 239
298 if (tag != -1) 240 if(tag != -1) *p = imphack;
299 *wp = imphack;
300
301 if (ptmpval)
302 return 1;
303 241
242 if(ptmpval) return 1;
304 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR); 243 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
305 goto err; 244 goto err;
306 245
307 246
308 case ASN1_ITYPE_CHOICE: 247 case ASN1_ITYPE_CHOICE:
309 if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) 248 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
310 goto auxerr; 249 goto auxerr;
311 250
312 /* Allocate structure */ 251 /* Allocate structure */
313 if (!*pval && !ASN1_item_ex_new(pval, it)) 252 if(!*pval) {
314 { 253 if(!ASN1_item_ex_new(pval, it)) {
315 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 254 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
316 ERR_R_NESTED_ASN1_ERROR); 255 goto err;
317 goto err;
318 } 256 }
257 }
319 /* CHOICE type, try each possibility in turn */ 258 /* CHOICE type, try each possibility in turn */
320 pchval = NULL; 259 pchval = NULL;
321 p = *in; 260 p = *in;
322 for (i = 0, tt=it->templates; i < it->tcount; i++, tt++) 261 for(i = 0, tt=it->templates; i < it->tcount; i++, tt++) {
323 {
324 pchptr = asn1_get_field_ptr(pval, tt); 262 pchptr = asn1_get_field_ptr(pval, tt);
325 /* We mark field as OPTIONAL so its absence 263 /* We mark field as OPTIONAL so its absence
326 * can be recognised. 264 * can be recognised.
327 */ 265 */
328 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx); 266 ret = asn1_template_ex_d2i(pchptr, &p, len, tt, 1, ctx);
329 /* If field not present, try the next one */ 267 /* If field not present, try the next one */
330 if (ret == -1) 268 if(ret == -1) continue;
331 continue;
332 /* If positive return, read OK, break loop */ 269 /* If positive return, read OK, break loop */
333 if (ret > 0) 270 if(ret > 0) break;
334 break;
335 /* Otherwise must be an ASN1 parsing error */ 271 /* Otherwise must be an ASN1 parsing error */
336 errtt = tt; 272 errtt = tt;
337 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 273 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
338 ERR_R_NESTED_ASN1_ERROR);
339 goto err; 274 goto err;
340 } 275 }
341
342 /* Did we fall off the end without reading anything? */ 276 /* Did we fall off the end without reading anything? */
343 if (i == it->tcount) 277 if(i == it->tcount) {
344 {
345 /* If OPTIONAL, this is OK */ 278 /* If OPTIONAL, this is OK */
346 if (opt) 279 if(opt) {
347 {
348 /* Free and zero it */ 280 /* Free and zero it */
349 ASN1_item_ex_free(pval, it); 281 ASN1_item_ex_free(pval, it);
350 return -1; 282 return -1;
351 }
352 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
353 ASN1_R_NO_MATCHING_CHOICE_TYPE);
354 goto err;
355 } 283 }
356 284 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_NO_MATCHING_CHOICE_TYPE);
285 goto err;
286 }
357 asn1_set_choice_selector(pval, i, it); 287 asn1_set_choice_selector(pval, i, it);
358 *in = p; 288 *in = p;
359 if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) 289 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
360 goto auxerr; 290 goto auxerr;
361 return 1; 291 return 1;
362 292
363 case ASN1_ITYPE_NDEF_SEQUENCE:
364 case ASN1_ITYPE_SEQUENCE: 293 case ASN1_ITYPE_SEQUENCE:
365 p = *in; 294 p = *in;
366 tmplen = len; 295 tmplen = len;
367 296
368 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ 297 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
369 if (tag == -1) 298 if(tag == -1) {
370 {
371 tag = V_ASN1_SEQUENCE; 299 tag = V_ASN1_SEQUENCE;
372 aclass = V_ASN1_UNIVERSAL; 300 aclass = V_ASN1_UNIVERSAL;
373 } 301 }
374 /* Get SEQUENCE length and update len, p */ 302 /* Get SEQUENCE length and update len, p */
375 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, 303 ret = asn1_check_tlen(&len, NULL, NULL, &seq_eoc, &cst, &p, len, tag, aclass, opt, ctx);
376 &p, len, tag, aclass, opt, ctx); 304 if(!ret) {
377 if (!ret) 305 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
378 {
379 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
380 ERR_R_NESTED_ASN1_ERROR);
381 goto err; 306 goto err;
382 } 307 } else if(ret == -1) return -1;
383 else if (ret == -1) 308 if(aux && (aux->flags & ASN1_AFLG_BROKEN)) {
384 return -1;
385 if (aux && (aux->flags & ASN1_AFLG_BROKEN))
386 {
387 len = tmplen - (p - *in); 309 len = tmplen - (p - *in);
388 seq_nolen = 1; 310 seq_nolen = 1;
389 } 311 } else seq_nolen = seq_eoc; /* If indefinite we don't do a length check */
390 /* If indefinite we don't do a length check */ 312 if(!cst) {
391 else seq_nolen = seq_eoc; 313 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
392 if (!cst)
393 {
394 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
395 ASN1_R_SEQUENCE_NOT_CONSTRUCTED);
396 goto err; 314 goto err;
397 } 315 }
398 316
399 if (!*pval && !ASN1_item_ex_new(pval, it)) 317 if(!*pval) {
400 { 318 if(!ASN1_item_ex_new(pval, it)) {
401 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 319 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
402 ERR_R_NESTED_ASN1_ERROR); 320 goto err;
403 goto err;
404 } 321 }
405 322 }
406 if (asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it)) 323 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_PRE, pval, it))
407 goto auxerr; 324 goto auxerr;
408 325
409 /* Get each field entry */ 326 /* Get each field entry */
410 for (i = 0, tt = it->templates; i < it->tcount; i++, tt++) 327 for(i = 0, tt = it->templates; i < it->tcount; i++, tt++) {
411 {
412 const ASN1_TEMPLATE *seqtt; 328 const ASN1_TEMPLATE *seqtt;
413 ASN1_VALUE **pseqval; 329 ASN1_VALUE **pseqval;
414 seqtt = asn1_do_adb(pval, tt, 1); 330 seqtt = asn1_do_adb(pval, tt, 1);
415 if (!seqtt) 331 if(!seqtt) goto err;
416 goto err;
417 pseqval = asn1_get_field_ptr(pval, seqtt); 332 pseqval = asn1_get_field_ptr(pval, seqtt);
418 /* Have we ran out of data? */ 333 /* Have we ran out of data? */
419 if (!len) 334 if(!len) break;
420 break;
421 q = p; 335 q = p;
422 if (asn1_check_eoc(&p, len)) 336 if(asn1_check_eoc(&p, len)) {
423 { 337 if(!seq_eoc) {
424 if (!seq_eoc) 338 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_UNEXPECTED_EOC);
425 {
426 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
427 ASN1_R_UNEXPECTED_EOC);
428 goto err; 339 goto err;
429 } 340 }
430 len -= p - q; 341 len -= p - q;
431 seq_eoc = 0; 342 seq_eoc = 0;
432 q = p; 343 q = p;
433 break; 344 break;
434 } 345 }
435 /* This determines the OPTIONAL flag value. The field 346 /* This determines the OPTIONAL flag value. The field cannot
436 * cannot be omitted if it is the last of a SEQUENCE 347 * be omitted if it is the last of a SEQUENCE and there is
437 * and there is still data to be read. This isn't 348 * still data to be read. This isn't strictly necessary but
438 * strictly necessary but it increases efficiency in 349 * it increases efficiency in some cases.
439 * some cases.
440 */ 350 */
441 if (i == (it->tcount - 1)) 351 if(i == (it->tcount - 1)) isopt = 0;
442 isopt = 0;
443 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL); 352 else isopt = (char)(seqtt->flags & ASN1_TFLG_OPTIONAL);
444 /* attempt to read in field, allowing each to be 353 /* attempt to read in field, allowing each to be OPTIONAL */
445 * OPTIONAL */ 354 ret = asn1_template_ex_d2i(pseqval, &p, len, seqtt, isopt, ctx);
446 355 if(!ret) {
447 ret = asn1_template_ex_d2i(pseqval, &p, len,
448 seqtt, isopt, ctx);
449 if (!ret)
450 {
451 errtt = seqtt; 356 errtt = seqtt;
452 goto err; 357 goto err;
453 } 358 } else if(ret == -1) {
454 else if (ret == -1) 359 /* OPTIONAL component absent. Free and zero the field
455 {
456 /* OPTIONAL component absent.
457 * Free and zero the field.
458 */ 360 */
459 ASN1_template_free(pseqval, seqtt); 361 ASN1_template_free(pseqval, seqtt);
460 continue; 362 continue;
461 } 363 }
462 /* Update length */ 364 /* Update length */
463 len -= p - q; 365 len -= p - q;
464 } 366 }
465
466 /* Check for EOC if expecting one */ 367 /* Check for EOC if expecting one */
467 if (seq_eoc && !asn1_check_eoc(&p, len)) 368 if(seq_eoc && !asn1_check_eoc(&p, len)) {
468 {
469 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC); 369 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_MISSING_EOC);
470 goto err; 370 goto err;
471 } 371 }
472 /* Check all data read */ 372 /* Check all data read */
473 if (!seq_nolen && len) 373 if(!seq_nolen && len) {
474 { 374 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_SEQUENCE_LENGTH_MISMATCH);
475 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I,
476 ASN1_R_SEQUENCE_LENGTH_MISMATCH);
477 goto err; 375 goto err;
478 } 376 }
479 377
480 /* If we get here we've got no more data in the SEQUENCE, 378 /* If we get here we've got no more data in the SEQUENCE,
481 * however we may not have read all fields so check all 379 * however we may not have read all fields so check all
482 * remaining are OPTIONAL and clear any that are. 380 * remaining are OPTIONAL and clear any that are.
483 */ 381 */
484 for (; i < it->tcount; tt++, i++) 382 for(; i < it->tcount; tt++, i++) {
485 {
486 const ASN1_TEMPLATE *seqtt; 383 const ASN1_TEMPLATE *seqtt;
487 seqtt = asn1_do_adb(pval, tt, 1); 384 seqtt = asn1_do_adb(pval, tt, 1);
488 if (!seqtt) 385 if(!seqtt) goto err;
489 goto err; 386 if(seqtt->flags & ASN1_TFLG_OPTIONAL) {
490 if (seqtt->flags & ASN1_TFLG_OPTIONAL)
491 {
492 ASN1_VALUE **pseqval; 387 ASN1_VALUE **pseqval;
493 pseqval = asn1_get_field_ptr(pval, seqtt); 388 pseqval = asn1_get_field_ptr(pval, seqtt);
494 ASN1_template_free(pseqval, seqtt); 389 ASN1_template_free(pseqval, seqtt);
495 } 390 } else {
496 else
497 {
498 errtt = seqtt; 391 errtt = seqtt;
499 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, 392 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_FIELD_MISSING);
500 ASN1_R_FIELD_MISSING);
501 goto err; 393 goto err;
502 }
503 } 394 }
395 }
504 /* Save encoding */ 396 /* Save encoding */
505 if (!asn1_enc_save(pval, *in, p - *in, it)) 397 if(!asn1_enc_save(pval, *in, p - *in, it)) goto auxerr;
506 goto auxerr;
507 *in = p; 398 *in = p;
508 if (asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it)) 399 if(asn1_cb && !asn1_cb(ASN1_OP_D2I_POST, pval, it))
509 goto auxerr; 400 goto auxerr;
510 return 1; 401 return 1;
511 402
512 default: 403 default:
513 return 0; 404 return 0;
514 } 405 }
515 auxerr: 406 auxerr:
516 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR); 407 ASN1err(ASN1_F_ASN1_ITEM_EX_D2I, ASN1_R_AUX_ERROR);
517 err: 408 err:
518 ASN1_item_ex_free(pval, it); 409 ASN1_item_ex_free(pval, it);
519 if (errtt) 410 if(errtt) ERR_add_error_data(4, "Field=", errtt->field_name, ", Type=", it->sname);
520 ERR_add_error_data(4, "Field=", errtt->field_name, 411 else ERR_add_error_data(2, "Type=", it->sname);
521 ", Type=", it->sname);
522 else
523 ERR_add_error_data(2, "Type=", it->sname);
524 return 0; 412 return 0;
525 } 413}
526 414
527/* Templates are handled with two separate functions. 415/* Templates are handled with two separate functions. One handles any EXPLICIT tag and the other handles the
528 * One handles any EXPLICIT tag and the other handles the rest. 416 * rest.
529 */ 417 */
530 418
531static int asn1_template_ex_d2i(ASN1_VALUE **val, 419static int asn1_template_ex_d2i(ASN1_VALUE **val, unsigned char **in, long inlen, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
532 const unsigned char **in, long inlen, 420{
533 const ASN1_TEMPLATE *tt, char opt,
534 ASN1_TLC *ctx)
535 {
536 int flags, aclass; 421 int flags, aclass;
537 int ret; 422 int ret;
538 long len; 423 long len;
539 const unsigned char *p, *q; 424 unsigned char *p, *q;
540 char exp_eoc; 425 char exp_eoc;
541 if (!val) 426 if(!val) return 0;
542 return 0;
543 flags = tt->flags; 427 flags = tt->flags;
544 aclass = flags & ASN1_TFLG_TAG_CLASS; 428 aclass = flags & ASN1_TFLG_TAG_CLASS;
545 429
546 p = *in; 430 p = *in;
547 431
548 /* Check if EXPLICIT tag expected */ 432 /* Check if EXPLICIT tag expected */
549 if (flags & ASN1_TFLG_EXPTAG) 433 if(flags & ASN1_TFLG_EXPTAG) {
550 {
551 char cst; 434 char cst;
552 /* Need to work out amount of data available to the inner 435 /* Need to work out amount of data available to the inner content and where it
553 * content and where it starts: so read in EXPLICIT header to 436 * starts: so read in EXPLICIT header to get the info.
554 * get the info.
555 */ 437 */
556 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, 438 ret = asn1_check_tlen(&len, NULL, NULL, &exp_eoc, &cst, &p, inlen, tt->tag, aclass, opt, ctx);
557 &p, inlen, tt->tag, aclass, opt, ctx);
558 q = p; 439 q = p;
559 if (!ret) 440 if(!ret) {
560 { 441 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
561 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
562 ERR_R_NESTED_ASN1_ERROR);
563 return 0; 442 return 0;
564 } 443 } else if(ret == -1) return -1;
565 else if (ret == -1) 444 if(!cst) {
566 return -1; 445 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
567 if (!cst)
568 {
569 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
570 ASN1_R_EXPLICIT_TAG_NOT_CONSTRUCTED);
571 return 0; 446 return 0;
572 } 447 }
573 /* We've found the field so it can't be OPTIONAL now */ 448 /* We've found the field so it can't be OPTIONAL now */
574 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx); 449 ret = asn1_template_noexp_d2i(val, &p, len, tt, 0, ctx);
575 if (!ret) 450 if(!ret) {
576 { 451 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
577 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
578 ERR_R_NESTED_ASN1_ERROR);
579 return 0; 452 return 0;
580 } 453 }
581 /* We read the field in OK so update length */ 454 /* We read the field in OK so update length */
582 len -= p - q; 455 len -= p - q;
583 if (exp_eoc) 456 if(exp_eoc) {
584 {
585 /* If NDEF we must have an EOC here */ 457 /* If NDEF we must have an EOC here */
586 if (!asn1_check_eoc(&p, len)) 458 if(!asn1_check_eoc(&p, len)) {
587 { 459 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
588 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
589 ASN1_R_MISSING_EOC);
590 goto err; 460 goto err;
591 }
592 } 461 }
593 else 462 } else {
594 { 463 /* Otherwise we must hit the EXPLICIT tag end or its an error */
595 /* Otherwise we must hit the EXPLICIT tag end or its 464 if(len) {
596 * an error */ 465 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_EXPLICIT_LENGTH_MISMATCH);
597 if (len)
598 {
599 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I,
600 ASN1_R_EXPLICIT_LENGTH_MISMATCH);
601 goto err; 466 goto err;
602 }
603 } 467 }
604 } 468 }
605 else 469 } else
606 return asn1_template_noexp_d2i(val, in, inlen, 470 return asn1_template_noexp_d2i(val, in, inlen, tt, opt, ctx);
607 tt, opt, ctx);
608 471
609 *in = p; 472 *in = p;
610 return 1; 473 return 1;
@@ -613,145 +476,98 @@ static int asn1_template_ex_d2i(ASN1_VALUE **val,
613 ASN1_template_free(val, tt); 476 ASN1_template_free(val, tt);
614 *val = NULL; 477 *val = NULL;
615 return 0; 478 return 0;
616 } 479}
617 480
618static int asn1_template_noexp_d2i(ASN1_VALUE **val, 481static int asn1_template_noexp_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_TEMPLATE *tt, char opt, ASN1_TLC *ctx)
619 const unsigned char **in, long len, 482{
620 const ASN1_TEMPLATE *tt, char opt,
621 ASN1_TLC *ctx)
622 {
623 int flags, aclass; 483 int flags, aclass;
624 int ret; 484 int ret;
625 const unsigned char *p, *q; 485 unsigned char *p, *q;
626 if (!val) 486 if(!val) return 0;
627 return 0;
628 flags = tt->flags; 487 flags = tt->flags;
629 aclass = flags & ASN1_TFLG_TAG_CLASS; 488 aclass = flags & ASN1_TFLG_TAG_CLASS;
630 489
631 p = *in; 490 p = *in;
632 q = p; 491 q = p;
633 492
634 if (flags & ASN1_TFLG_SK_MASK) 493 if(flags & ASN1_TFLG_SK_MASK) {
635 {
636 /* SET OF, SEQUENCE OF */ 494 /* SET OF, SEQUENCE OF */
637 int sktag, skaclass; 495 int sktag, skaclass;
638 char sk_eoc; 496 char sk_eoc;
639 /* First work out expected inner tag value */ 497 /* First work out expected inner tag value */
640 if (flags & ASN1_TFLG_IMPTAG) 498 if(flags & ASN1_TFLG_IMPTAG) {
641 {
642 sktag = tt->tag; 499 sktag = tt->tag;
643 skaclass = aclass; 500 skaclass = aclass;
644 } 501 } else {
645 else
646 {
647 skaclass = V_ASN1_UNIVERSAL; 502 skaclass = V_ASN1_UNIVERSAL;
648 if (flags & ASN1_TFLG_SET_OF) 503 if(flags & ASN1_TFLG_SET_OF) sktag = V_ASN1_SET;
649 sktag = V_ASN1_SET; 504 else sktag = V_ASN1_SEQUENCE;
650 else 505 }
651 sktag = V_ASN1_SEQUENCE;
652 }
653 /* Get the tag */ 506 /* Get the tag */
654 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, 507 ret = asn1_check_tlen(&len, NULL, NULL, &sk_eoc, NULL, &p, len, sktag, skaclass, opt, ctx);
655 &p, len, sktag, skaclass, opt, ctx); 508 if(!ret) {
656 if (!ret) 509 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_NESTED_ASN1_ERROR);
657 {
658 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
659 ERR_R_NESTED_ASN1_ERROR);
660 return 0; 510 return 0;
661 } 511 } else if(ret == -1) return -1;
662 else if (ret == -1) 512 if(!*val) *val = (ASN1_VALUE *)sk_new_null();
663 return -1; 513 else {
664 if (!*val)
665 *val = (ASN1_VALUE *)sk_new_null();
666 else
667 {
668 /* We've got a valid STACK: free up any items present */ 514 /* We've got a valid STACK: free up any items present */
669 STACK *sktmp = (STACK *)*val; 515 STACK *sktmp = (STACK *)*val;
670 ASN1_VALUE *vtmp; 516 ASN1_VALUE *vtmp;
671 while(sk_num(sktmp) > 0) 517 while(sk_num(sktmp) > 0) {
672 {
673 vtmp = (ASN1_VALUE *)sk_pop(sktmp); 518 vtmp = (ASN1_VALUE *)sk_pop(sktmp);
674 ASN1_item_ex_free(&vtmp, 519 ASN1_item_ex_free(&vtmp, ASN1_ITEM_ptr(tt->item));
675 ASN1_ITEM_ptr(tt->item));
676 }
677 } 520 }
521 }
678 522
679 if (!*val) 523 if(!*val) {
680 { 524 ASN1err(ASN1_F_ASN1_TEMPLATE_EX_D2I, ERR_R_MALLOC_FAILURE);
681 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
682 ERR_R_MALLOC_FAILURE);
683 goto err; 525 goto err;
684 } 526 }
685
686 /* Read as many items as we can */ 527 /* Read as many items as we can */
687 while(len > 0) 528 while(len > 0) {
688 {
689 ASN1_VALUE *skfield; 529 ASN1_VALUE *skfield;
690 q = p; 530 q = p;
691 /* See if EOC found */ 531 /* See if EOC found */
692 if (asn1_check_eoc(&p, len)) 532 if(asn1_check_eoc(&p, len)) {
693 { 533 if(!sk_eoc) {
694 if (!sk_eoc) 534 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_UNEXPECTED_EOC);
695 {
696 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
697 ASN1_R_UNEXPECTED_EOC);
698 goto err; 535 goto err;
699 } 536 }
700 len -= p - q; 537 len -= p - q;
701 sk_eoc = 0; 538 sk_eoc = 0;
702 break; 539 break;
703 } 540 }
704 skfield = NULL; 541 skfield = NULL;
705 if (!ASN1_item_ex_d2i(&skfield, &p, len, 542 if(!ASN1_item_ex_d2i(&skfield, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, 0, ctx)) {
706 ASN1_ITEM_ptr(tt->item), 543 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
707 -1, 0, 0, ctx))
708 {
709 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
710 ERR_R_NESTED_ASN1_ERROR);
711 goto err; 544 goto err;
712 } 545 }
713 len -= p - q; 546 len -= p - q;
714 if (!sk_push((STACK *)*val, (char *)skfield)) 547 if(!sk_push((STACK *)*val, (char *)skfield)) {
715 { 548 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_MALLOC_FAILURE);
716 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
717 ERR_R_MALLOC_FAILURE);
718 goto err; 549 goto err;
719 }
720 } 550 }
721 if (sk_eoc) 551 }
722 { 552 if(sk_eoc) {
723 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I, ASN1_R_MISSING_EOC); 553 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ASN1_R_MISSING_EOC);
724 goto err; 554 goto err;
725 }
726 } 555 }
727 else if (flags & ASN1_TFLG_IMPTAG) 556 } else if(flags & ASN1_TFLG_IMPTAG) {
728 {
729 /* IMPLICIT tagging */ 557 /* IMPLICIT tagging */
730 ret = ASN1_item_ex_d2i(val, &p, len, 558 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx);
731 ASN1_ITEM_ptr(tt->item), tt->tag, aclass, opt, ctx); 559 if(!ret) {
732 if (!ret) 560 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
733 {
734 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
735 ERR_R_NESTED_ASN1_ERROR);
736 goto err; 561 goto err;
737 } 562 } else if(ret == -1) return -1;
738 else if (ret == -1) 563 } else {
739 return -1;
740 }
741 else
742 {
743 /* Nothing special */ 564 /* Nothing special */
744 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), 565 ret = ASN1_item_ex_d2i(val, &p, len, ASN1_ITEM_ptr(tt->item), -1, 0, opt, ctx);
745 -1, 0, opt, ctx); 566 if(!ret) {
746 if (!ret) 567 ASN1err(ASN1_F_ASN1_TEMPLATE_D2I, ERR_R_NESTED_ASN1_ERROR);
747 {
748 ASN1err(ASN1_F_ASN1_TEMPLATE_NOEXP_D2I,
749 ERR_R_NESTED_ASN1_ERROR);
750 goto err; 568 goto err;
751 } 569 } else if(ret == -1) return -1;
752 else if (ret == -1) 570 }
753 return -1;
754 }
755 571
756 *in = p; 572 *in = p;
757 return 1; 573 return 1;
@@ -760,115 +576,85 @@ static int asn1_template_noexp_d2i(ASN1_VALUE **val,
760 ASN1_template_free(val, tt); 576 ASN1_template_free(val, tt);
761 *val = NULL; 577 *val = NULL;
762 return 0; 578 return 0;
763 } 579}
764 580
765static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, 581static int asn1_d2i_ex_primitive(ASN1_VALUE **pval, unsigned char **in, long inlen,
766 const unsigned char **in, long inlen, 582 const ASN1_ITEM *it,
767 const ASN1_ITEM *it, 583 int tag, int aclass, char opt, ASN1_TLC *ctx)
768 int tag, int aclass, char opt, ASN1_TLC *ctx) 584{
769 {
770 int ret = 0, utype; 585 int ret = 0, utype;
771 long plen; 586 long plen;
772 char cst, inf, free_cont = 0; 587 char cst, inf, free_cont = 0;
773 const unsigned char *p; 588 unsigned char *p;
774 BUF_MEM buf; 589 BUF_MEM buf;
775 const unsigned char *cont = NULL; 590 unsigned char *cont = NULL;
776 long len; 591 long len;
777 if (!pval) 592 if(!pval) {
778 {
779 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL); 593 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_NULL);
780 return 0; /* Should never happen */ 594 return 0; /* Should never happen */
781 } 595 }
782 596
783 if (it->itype == ASN1_ITYPE_MSTRING) 597 if(it->itype == ASN1_ITYPE_MSTRING) {
784 {
785 utype = tag; 598 utype = tag;
786 tag = -1; 599 tag = -1;
787 } 600 } else utype = it->utype;
788 else
789 utype = it->utype;
790 601
791 if (utype == V_ASN1_ANY) 602 if(utype == V_ASN1_ANY) {
792 {
793 /* If type is ANY need to figure out type from tag */ 603 /* If type is ANY need to figure out type from tag */
794 unsigned char oclass; 604 unsigned char oclass;
795 if (tag >= 0) 605 if(tag >= 0) {
796 { 606 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_TAGGED_ANY);
797 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
798 ASN1_R_ILLEGAL_TAGGED_ANY);
799 return 0; 607 return 0;
800 } 608 }
801 if (opt) 609 if(opt) {
802 { 610 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_ILLEGAL_OPTIONAL_ANY);
803 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
804 ASN1_R_ILLEGAL_OPTIONAL_ANY);
805 return 0; 611 return 0;
806 } 612 }
807 p = *in; 613 p = *in;
808 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, 614 ret = asn1_check_tlen(NULL, &utype, &oclass, NULL, NULL, &p, inlen, -1, 0, 0, ctx);
809 &p, inlen, -1, 0, 0, ctx); 615 if(!ret) {
810 if (!ret) 616 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
811 {
812 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
813 ERR_R_NESTED_ASN1_ERROR);
814 return 0; 617 return 0;
815 }
816 if (oclass != V_ASN1_UNIVERSAL)
817 utype = V_ASN1_OTHER;
818 } 618 }
819 if (tag == -1) 619 if(oclass != V_ASN1_UNIVERSAL) utype = V_ASN1_OTHER;
820 { 620 }
621 if(tag == -1) {
821 tag = utype; 622 tag = utype;
822 aclass = V_ASN1_UNIVERSAL; 623 aclass = V_ASN1_UNIVERSAL;
823 } 624 }
824 p = *in; 625 p = *in;
825 /* Check header */ 626 /* Check header */
826 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, 627 ret = asn1_check_tlen(&plen, NULL, NULL, &inf, &cst, &p, inlen, tag, aclass, opt, ctx);
827 &p, inlen, tag, aclass, opt, ctx); 628 if(!ret) {
828 if (!ret)
829 {
830 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR); 629 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_NESTED_ASN1_ERROR);
831 return 0; 630 return 0;
832 } 631 } else if(ret == -1) return -1;
833 else if (ret == -1) 632
834 return -1; 633 ret = 0;
835 ret = 0;
836 /* SEQUENCE, SET and "OTHER" are left in encoded form */ 634 /* SEQUENCE, SET and "OTHER" are left in encoded form */
837 if ((utype == V_ASN1_SEQUENCE) 635 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) {
838 || (utype == V_ASN1_SET) || (utype == V_ASN1_OTHER)) 636 /* Clear context cache for type OTHER because the auto clear when
839 { 637 * we have a exact match wont work
840 /* Clear context cache for type OTHER because the auto clear
841 * when we have a exact match wont work
842 */ 638 */
843 if (utype == V_ASN1_OTHER) 639 if(utype == V_ASN1_OTHER) {
844 {
845 asn1_tlc_clear(ctx); 640 asn1_tlc_clear(ctx);
846 }
847 /* SEQUENCE and SET must be constructed */ 641 /* SEQUENCE and SET must be constructed */
848 else if (!cst) 642 } else if(!cst) {
849 { 643 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_TYPE_NOT_CONSTRUCTED);
850 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
851 ASN1_R_TYPE_NOT_CONSTRUCTED);
852 return 0; 644 return 0;
853 } 645 }
854 646
855 cont = *in; 647 cont = *in;
856 /* If indefinite length constructed find the real end */ 648 /* If indefinite length constructed find the real end */
857 if (inf) 649 if(inf) {
858 { 650 if(!asn1_find_end(&p, plen, inf)) goto err;
859 if (!asn1_find_end(&p, plen, inf))
860 goto err;
861 len = p - cont; 651 len = p - cont;
862 } 652 } else {
863 else
864 {
865 len = p - cont + plen; 653 len = p - cont + plen;
866 p += plen; 654 p += plen;
867 buf.data = NULL; 655 buf.data = NULL;
868 }
869 } 656 }
870 else if (cst) 657 } else if(cst) {
871 {
872 buf.length = 0; 658 buf.length = 0;
873 buf.max = 0; 659 buf.max = 0;
874 buf.data = NULL; 660 buf.data = NULL;
@@ -878,46 +664,36 @@ static int asn1_d2i_ex_primitive(ASN1_VALUE **pval,
878 * internally irrespective of the type. So instead just check 664 * internally irrespective of the type. So instead just check
879 * for UNIVERSAL class and ignore the tag. 665 * for UNIVERSAL class and ignore the tag.
880 */ 666 */
881 if (!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) 667 if(!asn1_collect(&buf, &p, plen, inf, -1, V_ASN1_UNIVERSAL)) goto err;
882 {
883 free_cont = 1;
884 goto err;
885 }
886 len = buf.length; 668 len = buf.length;
887 /* Append a final null to string */ 669 /* Append a final null to string */
888 if (!BUF_MEM_grow_clean(&buf, len + 1)) 670 if(!BUF_MEM_grow_clean(&buf, len + 1)) {
889 { 671 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
890 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE,
891 ERR_R_MALLOC_FAILURE);
892 return 0; 672 return 0;
893 } 673 }
894 buf.data[len] = 0; 674 buf.data[len] = 0;
895 cont = (const unsigned char *)buf.data; 675 cont = (unsigned char *)buf.data;
896 free_cont = 1; 676 free_cont = 1;
897 } 677 } else {
898 else
899 {
900 cont = p; 678 cont = p;
901 len = plen; 679 len = plen;
902 p += plen; 680 p += plen;
903 } 681 }
904 682
905 /* We now have content length and type: translate into a structure */ 683 /* We now have content length and type: translate into a structure */
906 if (!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) 684 if(!asn1_ex_c2i(pval, cont, len, utype, &free_cont, it)) goto err;
907 goto err;
908 685
909 *in = p; 686 *in = p;
910 ret = 1; 687 ret = 1;
911 err: 688 err:
912 if (free_cont && buf.data) OPENSSL_free(buf.data); 689 if(free_cont && buf.data) OPENSSL_free(buf.data);
913 return ret; 690 return ret;
914 } 691}
915 692
916/* Translate ASN1 content octets into a structure */ 693/* Translate ASN1 content octets into a structure */
917 694
918int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 695int asn1_ex_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
919 int utype, char *free_cont, const ASN1_ITEM *it) 696{
920 {
921 ASN1_VALUE **opval = NULL; 697 ASN1_VALUE **opval = NULL;
922 ASN1_STRING *stmp; 698 ASN1_STRING *stmp;
923 ASN1_TYPE *typ = NULL; 699 ASN1_TYPE *typ = NULL;
@@ -925,62 +701,43 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
925 const ASN1_PRIMITIVE_FUNCS *pf; 701 const ASN1_PRIMITIVE_FUNCS *pf;
926 ASN1_INTEGER **tint; 702 ASN1_INTEGER **tint;
927 pf = it->funcs; 703 pf = it->funcs;
928 704 if(pf && pf->prim_c2i) return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
929 if (pf && pf->prim_c2i)
930 return pf->prim_c2i(pval, cont, len, utype, free_cont, it);
931 /* If ANY type clear type and set pointer to internal value */ 705 /* If ANY type clear type and set pointer to internal value */
932 if (it->utype == V_ASN1_ANY) 706 if(it->utype == V_ASN1_ANY) {
933 { 707 if(!*pval) {
934 if (!*pval)
935 {
936 typ = ASN1_TYPE_new(); 708 typ = ASN1_TYPE_new();
937 if (typ == NULL)
938 goto err;
939 *pval = (ASN1_VALUE *)typ; 709 *pval = (ASN1_VALUE *)typ;
940 } 710 } else typ = (ASN1_TYPE *)*pval;
941 else 711 if(utype != typ->type) ASN1_TYPE_set(typ, utype, NULL);
942 typ = (ASN1_TYPE *)*pval;
943
944 if (utype != typ->type)
945 ASN1_TYPE_set(typ, utype, NULL);
946 opval = pval; 712 opval = pval;
947 pval = &typ->value.asn1_value; 713 pval = (ASN1_VALUE **)&typ->value.ptr;
948 } 714 }
949 switch(utype) 715 switch(utype) {
950 {
951 case V_ASN1_OBJECT: 716 case V_ASN1_OBJECT:
952 if (!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) 717 if(!c2i_ASN1_OBJECT((ASN1_OBJECT **)pval, &cont, len)) goto err;
953 goto err;
954 break; 718 break;
955 719
956 case V_ASN1_NULL: 720 case V_ASN1_NULL:
957 if (len) 721 if(len) {
958 { 722 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_NULL_IS_WRONG_LENGTH);
959 ASN1err(ASN1_F_ASN1_EX_C2I,
960 ASN1_R_NULL_IS_WRONG_LENGTH);
961 goto err; 723 goto err;
962 } 724 }
963 *pval = (ASN1_VALUE *)1; 725 *pval = (ASN1_VALUE *)1;
964 break; 726 break;
965 727
966 case V_ASN1_BOOLEAN: 728 case V_ASN1_BOOLEAN:
967 if (len != 1) 729 if(len != 1) {
968 { 730 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
969 ASN1err(ASN1_F_ASN1_EX_C2I,
970 ASN1_R_BOOLEAN_IS_WRONG_LENGTH);
971 goto err; 731 goto err;
972 } 732 } else {
973 else
974 {
975 ASN1_BOOLEAN *tbool; 733 ASN1_BOOLEAN *tbool;
976 tbool = (ASN1_BOOLEAN *)pval; 734 tbool = (ASN1_BOOLEAN *)pval;
977 *tbool = *cont; 735 *tbool = *cont;
978 } 736 }
979 break; 737 break;
980 738
981 case V_ASN1_BIT_STRING: 739 case V_ASN1_BIT_STRING:
982 if (!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) 740 if(!c2i_ASN1_BIT_STRING((ASN1_BIT_STRING **)pval, &cont, len)) goto err;
983 goto err;
984 break; 741 break;
985 742
986 case V_ASN1_INTEGER: 743 case V_ASN1_INTEGER:
@@ -988,8 +745,7 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
988 case V_ASN1_ENUMERATED: 745 case V_ASN1_ENUMERATED:
989 case V_ASN1_NEG_ENUMERATED: 746 case V_ASN1_NEG_ENUMERATED:
990 tint = (ASN1_INTEGER **)pval; 747 tint = (ASN1_INTEGER **)pval;
991 if (!c2i_ASN1_INTEGER(tint, &cont, len)) 748 if(!c2i_ASN1_INTEGER(tint, &cont, len)) goto err;
992 goto err;
993 /* Fixup type to match the expected form */ 749 /* Fixup type to match the expected form */
994 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG); 750 (*tint)->type = utype | ((*tint)->type & V_ASN1_NEG);
995 break; 751 break;
@@ -1013,59 +769,46 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
1013 case V_ASN1_SEQUENCE: 769 case V_ASN1_SEQUENCE:
1014 default: 770 default:
1015 /* All based on ASN1_STRING and handled the same */ 771 /* All based on ASN1_STRING and handled the same */
1016 if (!*pval) 772 if(!*pval) {
1017 {
1018 stmp = ASN1_STRING_type_new(utype); 773 stmp = ASN1_STRING_type_new(utype);
1019 if (!stmp) 774 if(!stmp) {
1020 { 775 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
1021 ASN1err(ASN1_F_ASN1_EX_C2I,
1022 ERR_R_MALLOC_FAILURE);
1023 goto err; 776 goto err;
1024 }
1025 *pval = (ASN1_VALUE *)stmp;
1026 } 777 }
1027 else 778 *pval = (ASN1_VALUE *)stmp;
1028 { 779 } else {
1029 stmp = (ASN1_STRING *)*pval; 780 stmp = (ASN1_STRING *)*pval;
1030 stmp->type = utype; 781 stmp->type = utype;
1031 } 782 }
1032 /* If we've already allocated a buffer use it */ 783 /* If we've already allocated a buffer use it */
1033 if (*free_cont) 784 if(*free_cont) {
1034 { 785 if(stmp->data) OPENSSL_free(stmp->data);
1035 if (stmp->data) 786 stmp->data = cont;
1036 OPENSSL_free(stmp->data);
1037 stmp->data = (unsigned char *)cont; /* UGLY CAST! RL */
1038 stmp->length = len; 787 stmp->length = len;
1039 *free_cont = 0; 788 *free_cont = 0;
1040 } 789 } else {
1041 else 790 if(!ASN1_STRING_set(stmp, cont, len)) {
1042 { 791 ASN1err(ASN1_F_ASN1_D2I_EX_PRIMITIVE, ERR_R_MALLOC_FAILURE);
1043 if (!ASN1_STRING_set(stmp, cont, len))
1044 {
1045 ASN1err(ASN1_F_ASN1_EX_C2I,
1046 ERR_R_MALLOC_FAILURE);
1047 ASN1_STRING_free(stmp); 792 ASN1_STRING_free(stmp);
1048 *pval = NULL; 793 *pval = NULL;
1049 goto err; 794 goto err;
1050 }
1051 } 795 }
1052 break;
1053 } 796 }
797 break;
798 }
1054 /* If ASN1_ANY and NULL type fix up value */ 799 /* If ASN1_ANY and NULL type fix up value */
1055 if (typ && (utype == V_ASN1_NULL)) 800 if(typ && utype==V_ASN1_NULL) typ->value.ptr = NULL;
1056 typ->value.ptr = NULL;
1057 801
1058 ret = 1; 802 ret = 1;
1059 err: 803 err:
1060 if (!ret) 804 if(!ret)
1061 { 805 {
1062 ASN1_TYPE_free(typ); 806 ASN1_TYPE_free(typ);
1063 if (opval) 807 if (opval)
1064 *opval = NULL; 808 *opval = NULL;
1065 } 809 }
1066 return ret; 810 return ret;
1067 } 811}
1068
1069 812
1070/* This function finds the end of an ASN1 structure when passed its maximum 813/* This function finds the end of an ASN1 structure when passed its maximum
1071 * length, whether it is indefinite length and a pointer to the content. 814 * length, whether it is indefinite length and a pointer to the content.
@@ -1073,11 +816,11 @@ int asn1_ex_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len,
1073 * recurse on each indefinite length header. 816 * recurse on each indefinite length header.
1074 */ 817 */
1075 818
1076static int asn1_find_end(const unsigned char **in, long len, char inf) 819static int asn1_find_end(unsigned char **in, long len, char inf)
1077 { 820 {
1078 int expected_eoc; 821 int expected_eoc;
1079 long plen; 822 long plen;
1080 const unsigned char *p = *in, *q; 823 unsigned char *p = *in, *q;
1081 /* If not indefinite length constructed just add length */ 824 /* If not indefinite length constructed just add length */
1082 if (inf == 0) 825 if (inf == 0)
1083 { 826 {
@@ -1087,7 +830,7 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
1087 expected_eoc = 1; 830 expected_eoc = 1;
1088 /* Indefinite length constructed form. Find the end when enough EOCs 831 /* Indefinite length constructed form. Find the end when enough EOCs
1089 * are found. If more indefinite length constructed headers 832 * are found. If more indefinite length constructed headers
1090 * are encountered increment the expected eoc count otherwise just 833 * are encountered increment the expected eoc count otherwise justi
1091 * skip to the end of the data. 834 * skip to the end of the data.
1092 */ 835 */
1093 while (len > 0) 836 while (len > 0)
@@ -1122,55 +865,38 @@ static int asn1_find_end(const unsigned char **in, long len, char inf)
1122 *in = p; 865 *in = p;
1123 return 1; 866 return 1;
1124 } 867 }
868
1125/* This function collects the asn1 data from a constructred string 869/* This function collects the asn1 data from a constructred string
1126 * type into a buffer. The values of 'in' and 'len' should refer 870 * type into a buffer. The values of 'in' and 'len' should refer
1127 * to the contents of the constructed type and 'inf' should be set 871 * to the contents of the constructed type and 'inf' should be set
1128 * if it is indefinite length. 872 * if it is indefinite length.
1129 */ 873 */
1130 874
1131static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len, 875static int asn1_collect(BUF_MEM *buf, unsigned char **in, long len, char inf, int tag, int aclass)
1132 char inf, int tag, int aclass) 876{
1133 { 877 unsigned char *p, *q;
1134 const unsigned char *p, *q;
1135 long plen; 878 long plen;
1136 char cst, ininf; 879 char cst, ininf;
1137 p = *in; 880 p = *in;
1138 inf &= 1; 881 inf &= 1;
1139 /* If no buffer and not indefinite length constructed just pass over 882 while(len > 0) {
1140 * the encoded data */
1141 if (!buf && !inf)
1142 {
1143 *in += len;
1144 return 1;
1145 }
1146 while(len > 0)
1147 {
1148 q = p; 883 q = p;
1149 /* Check for EOC */ 884 /* Check for EOC */
1150 if (asn1_check_eoc(&p, len)) 885 if(asn1_check_eoc(&p, len)) {
1151 { 886 /* EOC is illegal outside indefinite length constructed form */
1152 /* EOC is illegal outside indefinite length 887 if(!inf) {
1153 * constructed form */ 888 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_UNEXPECTED_EOC);
1154 if (!inf)
1155 {
1156 ASN1err(ASN1_F_ASN1_COLLECT,
1157 ASN1_R_UNEXPECTED_EOC);
1158 return 0; 889 return 0;
1159 } 890 }
1160 inf = 0; 891 inf = 0;
1161 break; 892 break;
1162 } 893 }
1163 894 if(!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p, len, tag, aclass, 0, NULL)) {
1164 if (!asn1_check_tlen(&plen, NULL, NULL, &ininf, &cst, &p,
1165 len, tag, aclass, 0, NULL))
1166 {
1167 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR); 895 ASN1err(ASN1_F_ASN1_COLLECT, ERR_R_NESTED_ASN1_ERROR);
1168 return 0; 896 return 0;
1169 } 897 }
1170
1171 /* If indefinite length constructed update max length */ 898 /* If indefinite length constructed update max length */
1172 if (cst) 899 if(cst) {
1173 {
1174#ifdef OPENSSL_ALLOW_NESTED_ASN1_STRINGS 900#ifdef OPENSSL_ALLOW_NESTED_ASN1_STRINGS
1175 if (!asn1_collect(buf, &p, plen, ininf, tag, aclass)) 901 if (!asn1_collect(buf, &p, plen, ininf, tag, aclass))
1176 return 0; 902 return 0;
@@ -1178,51 +904,47 @@ static int asn1_collect(BUF_MEM *buf, const unsigned char **in, long len,
1178 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING); 904 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_NESTED_ASN1_STRING);
1179 return 0; 905 return 0;
1180#endif 906#endif
1181 } 907 } else {
1182 else if (plen && !collect_data(buf, &p, plen)) 908 if(plen && !collect_data(buf, &p, plen)) return 0;
1183 return 0;
1184 len -= p - q;
1185 } 909 }
1186 if (inf) 910 len -= p - q;
1187 { 911 }
912 if(inf) {
1188 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC); 913 ASN1err(ASN1_F_ASN1_COLLECT, ASN1_R_MISSING_EOC);
1189 return 0; 914 return 0;
1190 } 915 }
1191 *in = p; 916 *in = p;
1192 return 1; 917 return 1;
1193 } 918}
1194 919
1195static int collect_data(BUF_MEM *buf, const unsigned char **p, long plen) 920static int collect_data(BUF_MEM *buf, unsigned char **p, long plen)
1196 { 921{
1197 int len; 922 int len;
1198 if (buf) 923 if(buf) {
1199 { 924 len = buf->length;
1200 len = buf->length; 925 if(!BUF_MEM_grow_clean(buf, len + plen)) {
1201 if (!BUF_MEM_grow_clean(buf, len + plen)) 926 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
1202 { 927 return 0;
1203 ASN1err(ASN1_F_COLLECT_DATA, ERR_R_MALLOC_FAILURE);
1204 return 0;
1205 } 928 }
1206 memcpy(buf->data + len, *p, plen); 929 memcpy(buf->data + len, *p, plen);
1207 } 930 }
1208 *p += plen; 931 *p += plen;
1209 return 1; 932 return 1;
1210 } 933}
1211 934
1212/* Check for ASN1 EOC and swallow it if found */ 935/* Check for ASN1 EOC and swallow it if found */
1213 936
1214static int asn1_check_eoc(const unsigned char **in, long len) 937static int asn1_check_eoc(unsigned char **in, long len)
1215 { 938{
1216 const unsigned char *p; 939 unsigned char *p;
1217 if (len < 2) return 0; 940 if(len < 2) return 0;
1218 p = *in; 941 p = *in;
1219 if (!p[0] && !p[1]) 942 if(!p[0] && !p[1]) {
1220 {
1221 *in += 2; 943 *in += 2;
1222 return 1; 944 return 1;
1223 }
1224 return 0;
1225 } 945 }
946 return 0;
947}
1226 948
1227/* Check an ASN1 tag and length: a bit like ASN1_get_object 949/* Check an ASN1 tag and length: a bit like ASN1_get_object
1228 * but it sets the length for indefinite length constructed 950 * but it sets the length for indefinite length constructed
@@ -1231,32 +953,25 @@ static int asn1_check_eoc(const unsigned char **in, long len)
1231 * header length just read. 953 * header length just read.
1232 */ 954 */
1233 955
1234static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, 956static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass, char *inf, char *cst,
1235 char *inf, char *cst, 957 unsigned char **in, long len, int exptag, int expclass, char opt, ASN1_TLC *ctx)
1236 const unsigned char **in, long len, 958{
1237 int exptag, int expclass, char opt,
1238 ASN1_TLC *ctx)
1239 {
1240 int i; 959 int i;
1241 int ptag, pclass; 960 int ptag, pclass;
1242 long plen; 961 long plen;
1243 const unsigned char *p, *q; 962 unsigned char *p, *q;
1244 p = *in; 963 p = *in;
1245 q = p; 964 q = p;
1246 965
1247 if (ctx && ctx->valid) 966 if(ctx && ctx->valid) {
1248 {
1249 i = ctx->ret; 967 i = ctx->ret;
1250 plen = ctx->plen; 968 plen = ctx->plen;
1251 pclass = ctx->pclass; 969 pclass = ctx->pclass;
1252 ptag = ctx->ptag; 970 ptag = ctx->ptag;
1253 p += ctx->hdrlen; 971 p += ctx->hdrlen;
1254 } 972 } else {
1255 else
1256 {
1257 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len); 973 i = ASN1_get_object(&p, &plen, &ptag, &pclass, len);
1258 if (ctx) 974 if(ctx) {
1259 {
1260 ctx->ret = i; 975 ctx->ret = i;
1261 ctx->plen = plen; 976 ctx->plen = plen;
1262 ctx->pclass = pclass; 977 ctx->pclass = pclass;
@@ -1266,57 +981,43 @@ static int asn1_check_tlen(long *olen, int *otag, unsigned char *oclass,
1266 /* If definite length, and no error, length + 981 /* If definite length, and no error, length +
1267 * header can't exceed total amount of data available. 982 * header can't exceed total amount of data available.
1268 */ 983 */
1269 if (!(i & 0x81) && ((plen + ctx->hdrlen) > len)) 984 if(!(i & 0x81) && ((plen + ctx->hdrlen) > len)) {
1270 { 985 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_TOO_LONG);
1271 ASN1err(ASN1_F_ASN1_CHECK_TLEN,
1272 ASN1_R_TOO_LONG);
1273 asn1_tlc_clear(ctx); 986 asn1_tlc_clear(ctx);
1274 return 0; 987 return 0;
1275 }
1276 } 988 }
1277 } 989 }
990 }
1278 991
1279 if (i & 0x80) 992 if(i & 0x80) {
1280 {
1281 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER); 993 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_BAD_OBJECT_HEADER);
1282 asn1_tlc_clear(ctx); 994 asn1_tlc_clear(ctx);
1283 return 0; 995 return 0;
1284 } 996 }
1285 if (exptag >= 0) 997 if(exptag >= 0) {
1286 { 998 if((exptag != ptag) || (expclass != pclass)) {
1287 if ((exptag != ptag) || (expclass != pclass)) 999 /* If type is OPTIONAL, not an error, but indicate missing
1288 { 1000 * type.
1289 /* If type is OPTIONAL, not an error:
1290 * indicate missing type.
1291 */ 1001 */
1292 if (opt) return -1; 1002 if(opt) return -1;
1293 asn1_tlc_clear(ctx); 1003 asn1_tlc_clear(ctx);
1294 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG); 1004 ASN1err(ASN1_F_ASN1_CHECK_TLEN, ASN1_R_WRONG_TAG);
1295 return 0; 1005 return 0;
1296 }
1297 /* We have a tag and class match:
1298 * assume we are going to do something with it */
1299 asn1_tlc_clear(ctx);
1300 } 1006 }
1007 /* We have a tag and class match, so assume we are going to do something with it */
1008 asn1_tlc_clear(ctx);
1009 }
1301 1010
1302 if (i & 1) 1011 if(i & 1) plen = len - (p - q);
1303 plen = len - (p - q);
1304
1305 if (inf)
1306 *inf = i & 1;
1307
1308 if (cst)
1309 *cst = i & V_ASN1_CONSTRUCTED;
1310 1012
1311 if (olen) 1013 if(inf) *inf = i & 1;
1312 *olen = plen;
1313 1014
1314 if (oclass) 1015 if(cst) *cst = i & V_ASN1_CONSTRUCTED;
1315 *oclass = pclass;
1316 1016
1317 if (otag) 1017 if(olen) *olen = plen;
1318 *otag = ptag; 1018 if(oclass) *oclass = pclass;
1019 if(otag) *otag = ptag;
1319 1020
1320 *in = p; 1021 *in = p;
1321 return 1; 1022 return 1;
1322 } 1023}
diff --git a/src/lib/libcrypto/asn1/tasn_enc.c b/src/lib/libcrypto/asn1/tasn_enc.c
index be19b36acd..c675c3c832 100644
--- a/src/lib/libcrypto/asn1/tasn_enc.c
+++ b/src/lib/libcrypto/asn1/tasn_enc.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -59,119 +59,88 @@
59 59
60#include <stddef.h> 60#include <stddef.h>
61#include <string.h> 61#include <string.h>
62#include "cryptlib.h"
63#include <openssl/asn1.h> 62#include <openssl/asn1.h>
64#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66 65
67static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, 66static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
68 const ASN1_ITEM *it, 67static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *seq, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int isset);
69 int tag, int aclass);
70static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out,
71 int skcontlen, const ASN1_ITEM *item,
72 int do_sort, int iclass);
73static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
74 const ASN1_TEMPLATE *tt,
75 int tag, int aclass);
76static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out,
77 const ASN1_ITEM *it, int flags);
78
79/* Top level i2d equivalents: the 'ndef' variant instructs the encoder
80 * to use indefinite length constructed encoding, where appropriate
81 */
82
83int ASN1_item_ndef_i2d(ASN1_VALUE *val, unsigned char **out,
84 const ASN1_ITEM *it)
85 {
86 return asn1_item_flags_i2d(val, out, it, ASN1_TFLG_NDEF);
87 }
88
89int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
90 {
91 return asn1_item_flags_i2d(val, out, it, 0);
92 }
93 68
94/* Encode an ASN1 item, this is use by the 69/* Encode an ASN1 item, this is compatible with the
95 * standard 'i2d' function. 'out' points to 70 * standard 'i2d' function. 'out' points to
96 * a buffer to output the data to. 71 * a buffer to output the data to, in future we will
72 * have more advanced versions that can output data
73 * a piece at a time and this will simply be a special
74 * case.
97 * 75 *
98 * The new i2d has one additional feature. If the output 76 * The new i2d has one additional feature. If the output
99 * buffer is NULL (i.e. *out == NULL) then a buffer is 77 * buffer is NULL (i.e. *out == NULL) then a buffer is
100 * allocated and populated with the encoding. 78 * allocated and populated with the encoding.
101 */ 79 */
102 80
103static int asn1_item_flags_i2d(ASN1_VALUE *val, unsigned char **out, 81
104 const ASN1_ITEM *it, int flags) 82int ASN1_item_i2d(ASN1_VALUE *val, unsigned char **out, const ASN1_ITEM *it)
105 { 83{
106 if (out && !*out) 84 if(out && !*out) {
107 {
108 unsigned char *p, *buf; 85 unsigned char *p, *buf;
109 int len; 86 int len;
110 len = ASN1_item_ex_i2d(&val, NULL, it, -1, flags); 87 len = ASN1_item_ex_i2d(&val, NULL, it, -1, 0);
111 if (len <= 0) 88 if(len <= 0) return len;
112 return len;
113 buf = OPENSSL_malloc(len); 89 buf = OPENSSL_malloc(len);
114 if (!buf) 90 if(!buf) return -1;
115 return -1;
116 p = buf; 91 p = buf;
117 ASN1_item_ex_i2d(&val, &p, it, -1, flags); 92 ASN1_item_ex_i2d(&val, &p, it, -1, 0);
118 *out = buf; 93 *out = buf;
119 return len; 94 return len;
120 }
121
122 return ASN1_item_ex_i2d(&val, out, it, -1, flags);
123 } 95 }
96
97 return ASN1_item_ex_i2d(&val, out, it, -1, 0);
98}
124 99
125/* Encode an item, taking care of IMPLICIT tagging (if any). 100/* Encode an item, taking care of IMPLICIT tagging (if any).
126 * This function performs the normal item handling: it can be 101 * This function performs the normal item handling: it can be
127 * used in external types. 102 * used in external types.
128 */ 103 */
129 104
130int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, 105int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
131 const ASN1_ITEM *it, int tag, int aclass) 106{
132 {
133 const ASN1_TEMPLATE *tt = NULL; 107 const ASN1_TEMPLATE *tt = NULL;
134 unsigned char *p = NULL; 108 unsigned char *p = NULL;
135 int i, seqcontlen, seqlen, ndef = 1; 109 int i, seqcontlen, seqlen;
110 ASN1_STRING *strtmp;
136 const ASN1_COMPAT_FUNCS *cf; 111 const ASN1_COMPAT_FUNCS *cf;
137 const ASN1_EXTERN_FUNCS *ef; 112 const ASN1_EXTERN_FUNCS *ef;
138 const ASN1_AUX *aux = it->funcs; 113 const ASN1_AUX *aux = it->funcs;
139 ASN1_aux_cb *asn1_cb = 0; 114 ASN1_aux_cb *asn1_cb;
140 115 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return 0;
141 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) 116 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
142 return 0; 117 else asn1_cb = 0;
143 118
144 if (aux && aux->asn1_cb) 119 switch(it->itype) {
145 asn1_cb = aux->asn1_cb;
146
147 switch(it->itype)
148 {
149 120
150 case ASN1_ITYPE_PRIMITIVE: 121 case ASN1_ITYPE_PRIMITIVE:
151 if (it->templates) 122 if(it->templates)
152 return asn1_template_ex_i2d(pval, out, it->templates, 123 return ASN1_template_i2d(pval, out, it->templates);
153 tag, aclass);
154 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass); 124 return asn1_i2d_ex_primitive(pval, out, it, tag, aclass);
155 break; 125 break;
156 126
157 case ASN1_ITYPE_MSTRING: 127 case ASN1_ITYPE_MSTRING:
158 return asn1_i2d_ex_primitive(pval, out, it, -1, aclass); 128 strtmp = (ASN1_STRING *)*pval;
129 return asn1_i2d_ex_primitive(pval, out, it, -1, 0);
159 130
160 case ASN1_ITYPE_CHOICE: 131 case ASN1_ITYPE_CHOICE:
161 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it)) 132 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
162 return 0; 133 return 0;
163 i = asn1_get_choice_selector(pval, it); 134 i = asn1_get_choice_selector(pval, it);
164 if ((i >= 0) && (i < it->tcount)) 135 if((i >= 0) && (i < it->tcount)) {
165 {
166 ASN1_VALUE **pchval; 136 ASN1_VALUE **pchval;
167 const ASN1_TEMPLATE *chtt; 137 const ASN1_TEMPLATE *chtt;
168 chtt = it->templates + i; 138 chtt = it->templates + i;
169 pchval = asn1_get_field_ptr(pval, chtt); 139 pchval = asn1_get_field_ptr(pval, chtt);
170 return asn1_template_ex_i2d(pchval, out, chtt, 140 return ASN1_template_i2d(pchval, out, chtt);
171 -1, aclass); 141 }
172 }
173 /* Fixme: error condition if selector out of range */ 142 /* Fixme: error condition if selector out of range */
174 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it)) 143 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
175 return 0; 144 return 0;
176 break; 145 break;
177 146
@@ -183,236 +152,136 @@ int ASN1_item_ex_i2d(ASN1_VALUE **pval, unsigned char **out,
183 case ASN1_ITYPE_COMPAT: 152 case ASN1_ITYPE_COMPAT:
184 /* old style hackery... */ 153 /* old style hackery... */
185 cf = it->funcs; 154 cf = it->funcs;
186 if (out) 155 if(out) p = *out;
187 p = *out;
188 i = cf->asn1_i2d(*pval, out); 156 i = cf->asn1_i2d(*pval, out);
189 /* Fixup for IMPLICIT tag: note this messes up for tags > 30, 157 /* Fixup for IMPLICIT tag: note this messes up for tags > 30,
190 * but so did the old code. Tags > 30 are very rare anyway. 158 * but so did the old code. Tags > 30 are very rare anyway.
191 */ 159 */
192 if (out && (tag != -1)) 160 if(out && (tag != -1))
193 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED); 161 *p = aclass | tag | (*p & V_ASN1_CONSTRUCTED);
194 return i; 162 return i;
195 163
196 case ASN1_ITYPE_NDEF_SEQUENCE:
197 /* Use indefinite length constructed if requested */
198 if (aclass & ASN1_TFLG_NDEF) ndef = 2;
199 /* fall through */
200
201 case ASN1_ITYPE_SEQUENCE: 164 case ASN1_ITYPE_SEQUENCE:
202 i = asn1_enc_restore(&seqcontlen, out, pval, it); 165 i = asn1_enc_restore(&seqcontlen, out, pval, it);
203 /* An error occurred */ 166 /* An error occurred */
204 if (i < 0) 167 if(i < 0) return 0;
205 return 0;
206 /* We have a valid cached encoding... */ 168 /* We have a valid cached encoding... */
207 if (i > 0) 169 if(i > 0) return seqcontlen;
208 return seqcontlen;
209 /* Otherwise carry on */ 170 /* Otherwise carry on */
210 seqcontlen = 0; 171 seqcontlen = 0;
211 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */ 172 /* If no IMPLICIT tagging set to SEQUENCE, UNIVERSAL */
212 if (tag == -1) 173 if(tag == -1) {
213 {
214 tag = V_ASN1_SEQUENCE; 174 tag = V_ASN1_SEQUENCE;
215 /* Retain any other flags in aclass */ 175 aclass = V_ASN1_UNIVERSAL;
216 aclass = (aclass & ~ASN1_TFLG_TAG_CLASS) 176 }
217 | V_ASN1_UNIVERSAL; 177 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
218 }
219 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_PRE, pval, it))
220 return 0; 178 return 0;
221 /* First work out sequence content length */ 179 /* First work out sequence content length */
222 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) 180 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
223 {
224 const ASN1_TEMPLATE *seqtt; 181 const ASN1_TEMPLATE *seqtt;
225 ASN1_VALUE **pseqval; 182 ASN1_VALUE **pseqval;
226 seqtt = asn1_do_adb(pval, tt, 1); 183 seqtt = asn1_do_adb(pval, tt, 1);
227 if (!seqtt) 184 if(!seqtt) return 0;
228 return 0;
229 pseqval = asn1_get_field_ptr(pval, seqtt); 185 pseqval = asn1_get_field_ptr(pval, seqtt);
230 /* FIXME: check for errors in enhanced version */ 186 /* FIXME: check for errors in enhanced version */
231 seqcontlen += asn1_template_ex_i2d(pseqval, NULL, seqtt, 187 /* FIXME: special handling of indefinite length encoding */
232 -1, aclass); 188 seqcontlen += ASN1_template_i2d(pseqval, NULL, seqtt);
233 } 189 }
234 190 seqlen = ASN1_object_size(1, seqcontlen, tag);
235 seqlen = ASN1_object_size(ndef, seqcontlen, tag); 191 if(!out) return seqlen;
236 if (!out)
237 return seqlen;
238 /* Output SEQUENCE header */ 192 /* Output SEQUENCE header */
239 ASN1_put_object(out, ndef, seqcontlen, tag, aclass); 193 ASN1_put_object(out, 1, seqcontlen, tag, aclass);
240 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) 194 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
241 {
242 const ASN1_TEMPLATE *seqtt; 195 const ASN1_TEMPLATE *seqtt;
243 ASN1_VALUE **pseqval; 196 ASN1_VALUE **pseqval;
244 seqtt = asn1_do_adb(pval, tt, 1); 197 seqtt = asn1_do_adb(pval, tt, 1);
245 if (!seqtt) 198 if(!seqtt) return 0;
246 return 0;
247 pseqval = asn1_get_field_ptr(pval, seqtt); 199 pseqval = asn1_get_field_ptr(pval, seqtt);
248 /* FIXME: check for errors in enhanced version */ 200 /* FIXME: check for errors in enhanced version */
249 asn1_template_ex_i2d(pseqval, out, seqtt, -1, aclass); 201 ASN1_template_i2d(pseqval, out, seqtt);
250 } 202 }
251 if (ndef == 2) 203 if(asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
252 ASN1_put_eoc(out);
253 if (asn1_cb && !asn1_cb(ASN1_OP_I2D_POST, pval, it))
254 return 0; 204 return 0;
255 return seqlen; 205 return seqlen;
256 206
257 default: 207 default:
258 return 0; 208 return 0;
259
260 }
261 return 0;
262 }
263
264int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out,
265 const ASN1_TEMPLATE *tt)
266 {
267 return asn1_template_ex_i2d(pval, out, tt, -1, 0);
268 } 209 }
210 return 0;
211}
269 212
270static int asn1_template_ex_i2d(ASN1_VALUE **pval, unsigned char **out, 213int ASN1_template_i2d(ASN1_VALUE **pval, unsigned char **out, const ASN1_TEMPLATE *tt)
271 const ASN1_TEMPLATE *tt, int tag, int iclass) 214{
272 { 215 int i, ret, flags, aclass;
273 int i, ret, flags, ttag, tclass, ndef;
274 flags = tt->flags; 216 flags = tt->flags;
275 /* Work out tag and class to use: tagging may come 217 aclass = flags & ASN1_TFLG_TAG_CLASS;
276 * either from the template or the arguments, not both 218 if(flags & ASN1_TFLG_SK_MASK) {
277 * because this would create ambiguity. Additionally
278 * the iclass argument may contain some additional flags
279 * which should be noted and passed down to other levels.
280 */
281 if (flags & ASN1_TFLG_TAG_MASK)
282 {
283 /* Error if argument and template tagging */
284 if (tag != -1)
285 /* FIXME: error code here */
286 return -1;
287 /* Get tagging from template */
288 ttag = tt->tag;
289 tclass = flags & ASN1_TFLG_TAG_CLASS;
290 }
291 else if (tag != -1)
292 {
293 /* No template tagging, get from arguments */
294 ttag = tag;
295 tclass = iclass & ASN1_TFLG_TAG_CLASS;
296 }
297 else
298 {
299 ttag = -1;
300 tclass = 0;
301 }
302 /*
303 * Remove any class mask from iflag.
304 */
305 iclass &= ~ASN1_TFLG_TAG_CLASS;
306
307 /* At this point 'ttag' contains the outer tag to use,
308 * 'tclass' is the class and iclass is any flags passed
309 * to this function.
310 */
311
312 /* if template and arguments require ndef, use it */
313 if ((flags & ASN1_TFLG_NDEF) && (iclass & ASN1_TFLG_NDEF))
314 ndef = 2;
315 else ndef = 1;
316
317 if (flags & ASN1_TFLG_SK_MASK)
318 {
319 /* SET OF, SEQUENCE OF */ 219 /* SET OF, SEQUENCE OF */
320 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; 220 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
321 int isset, sktag, skaclass; 221 int isset, sktag, skaclass;
322 int skcontlen, sklen; 222 int skcontlen, sklen;
323 ASN1_VALUE *skitem; 223 ASN1_VALUE *skitem;
324 224 if(!*pval) return 0;
325 if (!*pval) 225 if(flags & ASN1_TFLG_SET_OF) {
326 return 0;
327
328 if (flags & ASN1_TFLG_SET_OF)
329 {
330 isset = 1; 226 isset = 1;
331 /* 2 means we reorder */ 227 /* 2 means we reorder */
332 if (flags & ASN1_TFLG_SEQUENCE_OF) 228 if(flags & ASN1_TFLG_SEQUENCE_OF) isset = 2;
333 isset = 2; 229 } else isset = 0;
334 } 230 /* First work out inner tag value */
335 else isset = 0; 231 if(flags & ASN1_TFLG_IMPTAG) {
336 232 sktag = tt->tag;
337 /* Work out inner tag value: if EXPLICIT 233 skaclass = aclass;
338 * or no tagging use underlying type. 234 } else {
339 */
340 if ((ttag != -1) && !(flags & ASN1_TFLG_EXPTAG))
341 {
342 sktag = ttag;
343 skaclass = tclass;
344 }
345 else
346 {
347 skaclass = V_ASN1_UNIVERSAL; 235 skaclass = V_ASN1_UNIVERSAL;
348 if (isset) 236 if(isset) sktag = V_ASN1_SET;
349 sktag = V_ASN1_SET;
350 else sktag = V_ASN1_SEQUENCE; 237 else sktag = V_ASN1_SEQUENCE;
351 } 238 }
352 239 /* Now work out length of items */
353 /* Determine total length of items */
354 skcontlen = 0; 240 skcontlen = 0;
355 for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) 241 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
356 {
357 skitem = sk_ASN1_VALUE_value(sk, i); 242 skitem = sk_ASN1_VALUE_value(sk, i);
358 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, 243 skcontlen += ASN1_item_ex_i2d(&skitem, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
359 ASN1_ITEM_ptr(tt->item), 244 }
360 -1, iclass); 245 sklen = ASN1_object_size(1, skcontlen, sktag);
361 }
362 sklen = ASN1_object_size(ndef, skcontlen, sktag);
363 /* If EXPLICIT need length of surrounding tag */ 246 /* If EXPLICIT need length of surrounding tag */
364 if (flags & ASN1_TFLG_EXPTAG) 247 if(flags & ASN1_TFLG_EXPTAG)
365 ret = ASN1_object_size(ndef, sklen, ttag); 248 ret = ASN1_object_size(1, sklen, tt->tag);
366 else ret = sklen; 249 else ret = sklen;
367 250
368 if (!out) 251 if(!out) return ret;
369 return ret;
370 252
371 /* Now encode this lot... */ 253 /* Now encode this lot... */
372 /* EXPLICIT tag */ 254 /* EXPLICIT tag */
373 if (flags & ASN1_TFLG_EXPTAG) 255 if(flags & ASN1_TFLG_EXPTAG)
374 ASN1_put_object(out, ndef, sklen, ttag, tclass); 256 ASN1_put_object(out, 1, sklen, tt->tag, aclass);
375 /* SET or SEQUENCE and IMPLICIT tag */ 257 /* SET or SEQUENCE and IMPLICIT tag */
376 ASN1_put_object(out, ndef, skcontlen, sktag, skaclass); 258 ASN1_put_object(out, 1, skcontlen, sktag, skaclass);
377 /* And the stuff itself */ 259 /* And finally the stuff itself */
378 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), 260 asn1_set_seq_out(sk, out, skcontlen, ASN1_ITEM_ptr(tt->item), isset);
379 isset, iclass);
380 if (ndef == 2)
381 {
382 ASN1_put_eoc(out);
383 if (flags & ASN1_TFLG_EXPTAG)
384 ASN1_put_eoc(out);
385 }
386 261
387 return ret; 262 return ret;
388 } 263 }
389 264
390 if (flags & ASN1_TFLG_EXPTAG) 265 if(flags & ASN1_TFLG_EXPTAG) {
391 {
392 /* EXPLICIT tagging */ 266 /* EXPLICIT tagging */
393 /* Find length of tagged item */ 267 /* Find length of tagged item */
394 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), 268 i = ASN1_item_ex_i2d(pval, NULL, ASN1_ITEM_ptr(tt->item), -1, 0);
395 -1, iclass); 269 if(!i) return 0;
396 if (!i)
397 return 0;
398 /* Find length of EXPLICIT tag */ 270 /* Find length of EXPLICIT tag */
399 ret = ASN1_object_size(ndef, i, ttag); 271 ret = ASN1_object_size(1, i, tt->tag);
400 if (out) 272 if(out) {
401 {
402 /* Output tag and item */ 273 /* Output tag and item */
403 ASN1_put_object(out, ndef, i, ttag, tclass); 274 ASN1_put_object(out, 1, i, tt->tag, aclass);
404 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), 275 ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
405 -1, iclass);
406 if (ndef == 2)
407 ASN1_put_eoc(out);
408 }
409 return ret;
410 } 276 }
411 277 return ret;
412 /* Either normal or IMPLICIT tagging: combine class and flags */ 278 }
413 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), 279 if(flags & ASN1_TFLG_IMPTAG) {
414 ttag, tclass | iclass); 280 /* IMPLICIT tagging */
415 281 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), tt->tag, aclass);
282 }
283 /* Nothing special: treat as normal */
284 return ASN1_item_ex_i2d(pval, out, ASN1_ITEM_ptr(tt->item), -1, 0);
416} 285}
417 286
418/* Temporary structure used to hold DER encoding of items for SET OF */ 287/* Temporary structure used to hold DER encoding of items for SET OF */
@@ -424,90 +293,72 @@ typedef struct {
424} DER_ENC; 293} DER_ENC;
425 294
426static int der_cmp(const void *a, const void *b) 295static int der_cmp(const void *a, const void *b)
427 { 296{
428 const DER_ENC *d1 = a, *d2 = b; 297 const DER_ENC *d1 = a, *d2 = b;
429 int cmplen, i; 298 int cmplen, i;
430 cmplen = (d1->length < d2->length) ? d1->length : d2->length; 299 cmplen = (d1->length < d2->length) ? d1->length : d2->length;
431 i = memcmp(d1->data, d2->data, cmplen); 300 i = memcmp(d1->data, d2->data, cmplen);
432 if (i) 301 if(i) return i;
433 return i;
434 return d1->length - d2->length; 302 return d1->length - d2->length;
435 } 303}
436 304
437/* Output the content octets of SET OF or SEQUENCE OF */ 305/* Output the content octets of SET OF or SEQUENCE OF */
438 306
439static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, 307static int asn1_set_seq_out(STACK_OF(ASN1_VALUE) *sk, unsigned char **out, int skcontlen, const ASN1_ITEM *item, int do_sort)
440 int skcontlen, const ASN1_ITEM *item, 308{
441 int do_sort, int iclass)
442 {
443 int i; 309 int i;
444 ASN1_VALUE *skitem; 310 ASN1_VALUE *skitem;
445 unsigned char *tmpdat = NULL, *p = NULL; 311 unsigned char *tmpdat = NULL, *p = NULL;
446 DER_ENC *derlst = NULL, *tder; 312 DER_ENC *derlst = NULL, *tder;
447 if (do_sort) 313 if(do_sort) {
448 {
449 /* Don't need to sort less than 2 items */ 314 /* Don't need to sort less than 2 items */
450 if (sk_ASN1_VALUE_num(sk) < 2) 315 if(sk_ASN1_VALUE_num(sk) < 2) do_sort = 0;
451 do_sort = 0; 316 else {
452 else 317 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk) * sizeof(*derlst));
453 {
454 derlst = OPENSSL_malloc(sk_ASN1_VALUE_num(sk)
455 * sizeof(*derlst));
456 tmpdat = OPENSSL_malloc(skcontlen); 318 tmpdat = OPENSSL_malloc(skcontlen);
457 if (!derlst || !tmpdat) 319 if(!derlst || !tmpdat) return 0;
458 return 0;
459 }
460 } 320 }
321 }
461 /* If not sorting just output each item */ 322 /* If not sorting just output each item */
462 if (!do_sort) 323 if(!do_sort) {
463 { 324 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
464 for (i = 0; i < sk_ASN1_VALUE_num(sk); i++)
465 {
466 skitem = sk_ASN1_VALUE_value(sk, i); 325 skitem = sk_ASN1_VALUE_value(sk, i);
467 ASN1_item_ex_i2d(&skitem, out, item, -1, iclass); 326 ASN1_item_i2d(skitem, out, item);
468 }
469 return 1;
470 } 327 }
328 return 1;
329 }
471 p = tmpdat; 330 p = tmpdat;
472
473 /* Doing sort: build up a list of each member's DER encoding */ 331 /* Doing sort: build up a list of each member's DER encoding */
474 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) 332 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
475 {
476 skitem = sk_ASN1_VALUE_value(sk, i); 333 skitem = sk_ASN1_VALUE_value(sk, i);
477 tder->data = p; 334 tder->data = p;
478 tder->length = ASN1_item_ex_i2d(&skitem, &p, item, -1, iclass); 335 tder->length = ASN1_item_i2d(skitem, &p, item);
479 tder->field = skitem; 336 tder->field = skitem;
480 } 337 }
481
482 /* Now sort them */ 338 /* Now sort them */
483 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp); 339 qsort(derlst, sk_ASN1_VALUE_num(sk), sizeof(*derlst), der_cmp);
484 /* Output sorted DER encoding */ 340 /* Output sorted DER encoding */
485 p = *out; 341 p = *out;
486 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) 342 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++) {
487 {
488 memcpy(p, tder->data, tder->length); 343 memcpy(p, tder->data, tder->length);
489 p += tder->length; 344 p += tder->length;
490 } 345 }
491 *out = p; 346 *out = p;
492 /* If do_sort is 2 then reorder the STACK */ 347 /* If do_sort is 2 then reorder the STACK */
493 if (do_sort == 2) 348 if(do_sort == 2) {
494 { 349 for(i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); i++, tder++)
495 for (i = 0, tder = derlst; i < sk_ASN1_VALUE_num(sk); 350 sk_ASN1_VALUE_set(sk, i, tder->field);
496 i++, tder++) 351 }
497 (void)sk_ASN1_VALUE_set(sk, i, tder->field);
498 }
499 OPENSSL_free(derlst); 352 OPENSSL_free(derlst);
500 OPENSSL_free(tmpdat); 353 OPENSSL_free(tmpdat);
501 return 1; 354 return 1;
502 } 355}
503 356
504static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, 357static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass)
505 const ASN1_ITEM *it, int tag, int aclass) 358{
506 {
507 int len; 359 int len;
508 int utype; 360 int utype;
509 int usetag; 361 int usetag;
510 int ndef = 0;
511 362
512 utype = it->utype; 363 utype = it->utype;
513 364
@@ -523,48 +374,33 @@ static int asn1_i2d_ex_primitive(ASN1_VALUE **pval, unsigned char **out,
523 * because the call to asn1_ex_i2c() could change 374 * because the call to asn1_ex_i2c() could change
524 * utype. 375 * utype.
525 */ 376 */
526 if ((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) || 377 if((utype == V_ASN1_SEQUENCE) || (utype == V_ASN1_SET) ||
527 (utype == V_ASN1_OTHER)) 378 (utype == V_ASN1_OTHER))
528 usetag = 0; 379 usetag = 0;
529 else usetag = 1; 380 else usetag = 1;
530 381
531 /* -1 means omit type */ 382 /* -1 means omit type */
532 383
533 if (len == -1) 384 if(len == -1) return 0;
534 return 0;
535
536 /* -2 return is special meaning use ndef */
537 if (len == -2)
538 {
539 ndef = 2;
540 len = 0;
541 }
542 385
543 /* If not implicitly tagged get tag from underlying type */ 386 /* If not implicitly tagged get tag from underlying type */
544 if (tag == -1) tag = utype; 387 if(tag == -1) tag = utype;
545 388
546 /* Output tag+length followed by content octets */ 389 /* Output tag+length followed by content octets */
547 if (out) 390 if(out) {
548 { 391 if(usetag) ASN1_put_object(out, 0, len, tag, aclass);
549 if (usetag)
550 ASN1_put_object(out, ndef, len, tag, aclass);
551 asn1_ex_i2c(pval, *out, &utype, it); 392 asn1_ex_i2c(pval, *out, &utype, it);
552 if (ndef) 393 *out += len;
553 ASN1_put_eoc(out); 394 }
554 else
555 *out += len;
556 }
557 395
558 if (usetag) 396 if(usetag) return ASN1_object_size(0, len, tag);
559 return ASN1_object_size(ndef, len, tag);
560 return len; 397 return len;
561 } 398}
562 399
563/* Produce content octets from a structure */ 400/* Produce content octets from a structure */
564 401
565int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, 402int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype, const ASN1_ITEM *it)
566 const ASN1_ITEM *it) 403{
567 {
568 ASN1_BOOLEAN *tbool = NULL; 404 ASN1_BOOLEAN *tbool = NULL;
569 ASN1_STRING *strtmp; 405 ASN1_STRING *strtmp;
570 ASN1_OBJECT *otmp; 406 ASN1_OBJECT *otmp;
@@ -573,36 +409,28 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
573 int len; 409 int len;
574 const ASN1_PRIMITIVE_FUNCS *pf; 410 const ASN1_PRIMITIVE_FUNCS *pf;
575 pf = it->funcs; 411 pf = it->funcs;
576 if (pf && pf->prim_i2c) 412 if(pf && pf->prim_i2c) return pf->prim_i2c(pval, cout, putype, it);
577 return pf->prim_i2c(pval, cout, putype, it);
578 413
579 /* Should type be omitted? */ 414 /* Should type be omitted? */
580 if ((it->itype != ASN1_ITYPE_PRIMITIVE) 415 if((it->itype != ASN1_ITYPE_PRIMITIVE) || (it->utype != V_ASN1_BOOLEAN)) {
581 || (it->utype != V_ASN1_BOOLEAN)) 416 if(!*pval) return -1;
582 { 417 }
583 if (!*pval) return -1;
584 }
585 418
586 if (it->itype == ASN1_ITYPE_MSTRING) 419 if(it->itype == ASN1_ITYPE_MSTRING) {
587 {
588 /* If MSTRING type set the underlying type */ 420 /* If MSTRING type set the underlying type */
589 strtmp = (ASN1_STRING *)*pval; 421 strtmp = (ASN1_STRING *)*pval;
590 utype = strtmp->type; 422 utype = strtmp->type;
591 *putype = utype; 423 *putype = utype;
592 } 424 } else if(it->utype == V_ASN1_ANY) {
593 else if (it->utype == V_ASN1_ANY)
594 {
595 /* If ANY set type and pointer to value */ 425 /* If ANY set type and pointer to value */
596 ASN1_TYPE *typ; 426 ASN1_TYPE *typ;
597 typ = (ASN1_TYPE *)*pval; 427 typ = (ASN1_TYPE *)*pval;
598 utype = typ->type; 428 utype = typ->type;
599 *putype = utype; 429 *putype = utype;
600 pval = &typ->value.asn1_value; 430 pval = (ASN1_VALUE **)&typ->value.ptr;
601 } 431 } else utype = *putype;
602 else utype = *putype;
603 432
604 switch(utype) 433 switch(utype) {
605 {
606 case V_ASN1_OBJECT: 434 case V_ASN1_OBJECT:
607 otmp = (ASN1_OBJECT *)*pval; 435 otmp = (ASN1_OBJECT *)*pval;
608 cont = otmp->data; 436 cont = otmp->data;
@@ -616,15 +444,12 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
616 444
617 case V_ASN1_BOOLEAN: 445 case V_ASN1_BOOLEAN:
618 tbool = (ASN1_BOOLEAN *)pval; 446 tbool = (ASN1_BOOLEAN *)pval;
619 if (*tbool == -1) 447 if(*tbool == -1) return -1;
620 return -1;
621 if (it->utype != V_ASN1_ANY) 448 if (it->utype != V_ASN1_ANY)
622 { 449 {
623 /* Default handling if value == size field then omit */ 450 /* Default handling if value == size field then omit */
624 if (*tbool && (it->size > 0)) 451 if(*tbool && (it->size > 0)) return -1;
625 return -1; 452 if(!*tbool && !it->size) return -1;
626 if (!*tbool && !it->size)
627 return -1;
628 } 453 }
629 c = (unsigned char)*tbool; 454 c = (unsigned char)*tbool;
630 cont = &c; 455 cont = &c;
@@ -632,8 +457,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
632 break; 457 break;
633 458
634 case V_ASN1_BIT_STRING: 459 case V_ASN1_BIT_STRING:
635 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, 460 return i2c_ASN1_BIT_STRING((ASN1_BIT_STRING *)*pval, cout ? &cout : NULL);
636 cout ? &cout : NULL);
637 break; 461 break;
638 462
639 case V_ASN1_INTEGER: 463 case V_ASN1_INTEGER:
@@ -643,8 +467,7 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
643 /* These are all have the same content format 467 /* These are all have the same content format
644 * as ASN1_INTEGER 468 * as ASN1_INTEGER
645 */ 469 */
646 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, 470 return i2c_ASN1_INTEGER((ASN1_INTEGER *)*pval, cout ? &cout : NULL);
647 cout ? &cout : NULL);
648 break; 471 break;
649 472
650 case V_ASN1_OCTET_STRING: 473 case V_ASN1_OCTET_STRING:
@@ -666,25 +489,12 @@ int asn1_ex_i2c(ASN1_VALUE **pval, unsigned char *cout, int *putype,
666 default: 489 default:
667 /* All based on ASN1_STRING and handled the same */ 490 /* All based on ASN1_STRING and handled the same */
668 strtmp = (ASN1_STRING *)*pval; 491 strtmp = (ASN1_STRING *)*pval;
669 /* Special handling for NDEF */
670 if ((it->size == ASN1_TFLG_NDEF)
671 && (strtmp->flags & ASN1_STRING_FLAG_NDEF))
672 {
673 if (cout)
674 {
675 strtmp->data = cout;
676 strtmp->length = 0;
677 }
678 /* Special return code */
679 return -2;
680 }
681 cont = strtmp->data; 492 cont = strtmp->data;
682 len = strtmp->length; 493 len = strtmp->length;
683 494
684 break; 495 break;
685 496
686 }
687 if (cout && len)
688 memcpy(cout, cont, len);
689 return len;
690 } 497 }
498 if(cout && len) memcpy(cout, cont, len);
499 return len;
500}
diff --git a/src/lib/libcrypto/asn1/tasn_fre.c b/src/lib/libcrypto/asn1/tasn_fre.c
index bb7c1e2af4..2dd844159e 100644
--- a/src/lib/libcrypto/asn1/tasn_fre.c
+++ b/src/lib/libcrypto/asn1/tasn_fre.c
@@ -67,40 +67,33 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
67/* Free up an ASN1 structure */ 67/* Free up an ASN1 structure */
68 68
69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it) 69void ASN1_item_free(ASN1_VALUE *val, const ASN1_ITEM *it)
70 { 70{
71 asn1_item_combine_free(&val, it, 0); 71 asn1_item_combine_free(&val, it, 0);
72 } 72}
73 73
74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 74void ASN1_item_ex_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
75 { 75{
76 asn1_item_combine_free(pval, it, 0); 76 asn1_item_combine_free(pval, it, 0);
77 } 77}
78 78
79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine) 79static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
80 { 80{
81 const ASN1_TEMPLATE *tt = NULL, *seqtt; 81 const ASN1_TEMPLATE *tt = NULL, *seqtt;
82 const ASN1_EXTERN_FUNCS *ef; 82 const ASN1_EXTERN_FUNCS *ef;
83 const ASN1_COMPAT_FUNCS *cf; 83 const ASN1_COMPAT_FUNCS *cf;
84 const ASN1_AUX *aux = it->funcs; 84 const ASN1_AUX *aux = it->funcs;
85 ASN1_aux_cb *asn1_cb; 85 ASN1_aux_cb *asn1_cb;
86 int i; 86 int i;
87 if (!pval) 87 if(!pval) return;
88 return; 88 if((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) return;
89 if ((it->itype != ASN1_ITYPE_PRIMITIVE) && !*pval) 89 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
90 return; 90 else asn1_cb = 0;
91 if (aux && aux->asn1_cb)
92 asn1_cb = aux->asn1_cb;
93 else
94 asn1_cb = 0;
95 91
96 switch(it->itype) 92 switch(it->itype) {
97 {
98 93
99 case ASN1_ITYPE_PRIMITIVE: 94 case ASN1_ITYPE_PRIMITIVE:
100 if (it->templates) 95 if(it->templates) ASN1_template_free(pval, it->templates);
101 ASN1_template_free(pval, it->templates); 96 else ASN1_primitive_free(pval, it);
102 else
103 ASN1_primitive_free(pval, it);
104 break; 97 break;
105 98
106 case ASN1_ITYPE_MSTRING: 99 case ASN1_ITYPE_MSTRING:
@@ -108,51 +101,41 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
108 break; 101 break;
109 102
110 case ASN1_ITYPE_CHOICE: 103 case ASN1_ITYPE_CHOICE:
111 if (asn1_cb) 104 if(asn1_cb) {
112 {
113 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); 105 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
114 if (i == 2) 106 if(i == 2) return;
115 return; 107 }
116 }
117 i = asn1_get_choice_selector(pval, it); 108 i = asn1_get_choice_selector(pval, it);
118 if ((i >= 0) && (i < it->tcount)) 109 if(asn1_cb) asn1_cb(ASN1_OP_FREE_PRE, pval, it);
119 { 110 if((i >= 0) && (i < it->tcount)) {
120 ASN1_VALUE **pchval; 111 ASN1_VALUE **pchval;
121 tt = it->templates + i; 112 tt = it->templates + i;
122 pchval = asn1_get_field_ptr(pval, tt); 113 pchval = asn1_get_field_ptr(pval, tt);
123 ASN1_template_free(pchval, tt); 114 ASN1_template_free(pchval, tt);
124 } 115 }
125 if (asn1_cb) 116 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
126 asn1_cb(ASN1_OP_FREE_POST, pval, it); 117 if(!combine) {
127 if (!combine)
128 {
129 OPENSSL_free(*pval); 118 OPENSSL_free(*pval);
130 *pval = NULL; 119 *pval = NULL;
131 } 120 }
132 break; 121 break;
133 122
134 case ASN1_ITYPE_COMPAT: 123 case ASN1_ITYPE_COMPAT:
135 cf = it->funcs; 124 cf = it->funcs;
136 if (cf && cf->asn1_free) 125 if(cf && cf->asn1_free) cf->asn1_free(*pval);
137 cf->asn1_free(*pval);
138 break; 126 break;
139 127
140 case ASN1_ITYPE_EXTERN: 128 case ASN1_ITYPE_EXTERN:
141 ef = it->funcs; 129 ef = it->funcs;
142 if (ef && ef->asn1_ex_free) 130 if(ef && ef->asn1_ex_free) ef->asn1_ex_free(pval, it);
143 ef->asn1_ex_free(pval, it);
144 break; 131 break;
145 132
146 case ASN1_ITYPE_NDEF_SEQUENCE:
147 case ASN1_ITYPE_SEQUENCE: 133 case ASN1_ITYPE_SEQUENCE:
148 if (asn1_do_lock(pval, -1, it) > 0) 134 if(asn1_do_lock(pval, -1, it) > 0) return;
149 return; 135 if(asn1_cb) {
150 if (asn1_cb)
151 {
152 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it); 136 i = asn1_cb(ASN1_OP_FREE_PRE, pval, it);
153 if (i == 2) 137 if(i == 2) return;
154 return; 138 }
155 }
156 asn1_enc_free(pval, it); 139 asn1_enc_free(pval, it);
157 /* If we free up as normal we will invalidate any 140 /* If we free up as normal we will invalidate any
158 * ANY DEFINED BY field and we wont be able to 141 * ANY DEFINED BY field and we wont be able to
@@ -160,84 +143,64 @@ static void asn1_item_combine_free(ASN1_VALUE **pval, const ASN1_ITEM *it, int c
160 * free up in reverse order. 143 * free up in reverse order.
161 */ 144 */
162 tt = it->templates + it->tcount - 1; 145 tt = it->templates + it->tcount - 1;
163 for (i = 0; i < it->tcount; tt--, i++) 146 for(i = 0; i < it->tcount; tt--, i++) {
164 {
165 ASN1_VALUE **pseqval; 147 ASN1_VALUE **pseqval;
166 seqtt = asn1_do_adb(pval, tt, 0); 148 seqtt = asn1_do_adb(pval, tt, 0);
167 if (!seqtt) 149 if(!seqtt) continue;
168 continue;
169 pseqval = asn1_get_field_ptr(pval, seqtt); 150 pseqval = asn1_get_field_ptr(pval, seqtt);
170 ASN1_template_free(pseqval, seqtt); 151 ASN1_template_free(pseqval, seqtt);
171 } 152 }
172 if (asn1_cb) 153 if(asn1_cb) asn1_cb(ASN1_OP_FREE_POST, pval, it);
173 asn1_cb(ASN1_OP_FREE_POST, pval, it); 154 if(!combine) {
174 if (!combine)
175 {
176 OPENSSL_free(*pval); 155 OPENSSL_free(*pval);
177 *pval = NULL; 156 *pval = NULL;
178 }
179 break;
180 } 157 }
158 break;
181 } 159 }
160}
182 161
183void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 162void ASN1_template_free(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
184 { 163{
185 int i; 164 int i;
186 if (tt->flags & ASN1_TFLG_SK_MASK) 165 if(tt->flags & ASN1_TFLG_SK_MASK) {
187 {
188 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval; 166 STACK_OF(ASN1_VALUE) *sk = (STACK_OF(ASN1_VALUE) *)*pval;
189 for (i = 0; i < sk_ASN1_VALUE_num(sk); i++) 167 for(i = 0; i < sk_ASN1_VALUE_num(sk); i++) {
190 {
191 ASN1_VALUE *vtmp; 168 ASN1_VALUE *vtmp;
192 vtmp = sk_ASN1_VALUE_value(sk, i); 169 vtmp = sk_ASN1_VALUE_value(sk, i);
193 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 170 asn1_item_combine_free(&vtmp, ASN1_ITEM_ptr(tt->item), 0);
194 0); 171 }
195 }
196 sk_ASN1_VALUE_free(sk); 172 sk_ASN1_VALUE_free(sk);
197 *pval = NULL; 173 *pval = NULL;
198 } 174 } else asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
199 else
200 asn1_item_combine_free(pval, ASN1_ITEM_ptr(tt->item),
201 tt->flags & ASN1_TFLG_COMBINE); 175 tt->flags & ASN1_TFLG_COMBINE);
202 } 176}
203 177
204void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 178void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
205 { 179{
206 int utype; 180 int utype;
207 if (it) 181 if(it) {
208 {
209 const ASN1_PRIMITIVE_FUNCS *pf; 182 const ASN1_PRIMITIVE_FUNCS *pf;
210 pf = it->funcs; 183 pf = it->funcs;
211 if (pf && pf->prim_free) 184 if(pf && pf->prim_free) {
212 {
213 pf->prim_free(pval, it); 185 pf->prim_free(pval, it);
214 return; 186 return;
215 }
216 } 187 }
188 }
217 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */ 189 /* Special case: if 'it' is NULL free contents of ASN1_TYPE */
218 if (!it) 190 if(!it) {
219 {
220 ASN1_TYPE *typ = (ASN1_TYPE *)*pval; 191 ASN1_TYPE *typ = (ASN1_TYPE *)*pval;
221 utype = typ->type; 192 utype = typ->type;
222 pval = &typ->value.asn1_value; 193 pval = (ASN1_VALUE **)&typ->value.ptr;
223 if (!*pval) 194 if(!*pval) return;
224 return; 195 } else if(it->itype == ASN1_ITYPE_MSTRING) {
225 }
226 else if (it->itype == ASN1_ITYPE_MSTRING)
227 {
228 utype = -1; 196 utype = -1;
229 if (!*pval) 197 if(!*pval) return;
230 return; 198 } else {
231 }
232 else
233 {
234 utype = it->utype; 199 utype = it->utype;
235 if ((utype != V_ASN1_BOOLEAN) && !*pval) 200 if((utype != V_ASN1_BOOLEAN) && !*pval) return;
236 return; 201 }
237 }
238 202
239 switch(utype) 203 switch(utype) {
240 {
241 case V_ASN1_OBJECT: 204 case V_ASN1_OBJECT:
242 ASN1_OBJECT_free((ASN1_OBJECT *)*pval); 205 ASN1_OBJECT_free((ASN1_OBJECT *)*pval);
243 break; 206 break;
@@ -261,6 +224,6 @@ void ASN1_primitive_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
261 ASN1_STRING_free((ASN1_STRING *)*pval); 224 ASN1_STRING_free((ASN1_STRING *)*pval);
262 *pval = NULL; 225 *pval = NULL;
263 break; 226 break;
264 }
265 *pval = NULL;
266 } 227 }
228 *pval = NULL;
229}
diff --git a/src/lib/libcrypto/asn1/tasn_new.c b/src/lib/libcrypto/asn1/tasn_new.c
index 531dad365c..a0e3db574f 100644
--- a/src/lib/libcrypto/asn1/tasn_new.c
+++ b/src/lib/libcrypto/asn1/tasn_new.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -64,30 +64,27 @@
64#include <openssl/asn1t.h> 64#include <openssl/asn1t.h>
65#include <string.h> 65#include <string.h>
66 66
67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, 67static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine);
68 int combine);
69static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 68static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
70static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt); 69static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt);
71void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it); 70void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it);
72 71
73ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it) 72ASN1_VALUE *ASN1_item_new(const ASN1_ITEM *it)
74 { 73{
75 ASN1_VALUE *ret = NULL; 74 ASN1_VALUE *ret = NULL;
76 if (ASN1_item_ex_new(&ret, it) > 0) 75 if(ASN1_item_ex_new(&ret, it) > 0) return ret;
77 return ret;
78 return NULL; 76 return NULL;
79 } 77}
80 78
81/* Allocate an ASN1 structure */ 79/* Allocate an ASN1 structure */
82 80
83int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 81int ASN1_item_ex_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
84 { 82{
85 return asn1_item_ex_combine_new(pval, it, 0); 83 return asn1_item_ex_combine_new(pval, it, 0);
86 } 84}
87 85
88static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, 86static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it, int combine)
89 int combine) 87{
90 {
91 const ASN1_TEMPLATE *tt = NULL; 88 const ASN1_TEMPLATE *tt = NULL;
92 const ASN1_COMPAT_FUNCS *cf; 89 const ASN1_COMPAT_FUNCS *cf;
93 const ASN1_EXTERN_FUNCS *ef; 90 const ASN1_EXTERN_FUNCS *ef;
@@ -95,155 +92,133 @@ static int asn1_item_ex_combine_new(ASN1_VALUE **pval, const ASN1_ITEM *it,
95 ASN1_aux_cb *asn1_cb; 92 ASN1_aux_cb *asn1_cb;
96 ASN1_VALUE **pseqval; 93 ASN1_VALUE **pseqval;
97 int i; 94 int i;
98 if (aux && aux->asn1_cb) 95 if(aux && aux->asn1_cb) asn1_cb = aux->asn1_cb;
99 asn1_cb = aux->asn1_cb; 96 else asn1_cb = 0;
100 else
101 asn1_cb = 0;
102 97
103 if (!combine) *pval = NULL; 98 if(!combine) *pval = NULL;
104 99
105#ifdef CRYPTO_MDEBUG 100#ifdef CRYPTO_MDEBUG
106 if (it->sname) 101 if(it->sname) CRYPTO_push_info(it->sname);
107 CRYPTO_push_info(it->sname);
108#endif 102#endif
109 103
110 switch(it->itype) 104 switch(it->itype) {
111 {
112 105
113 case ASN1_ITYPE_EXTERN: 106 case ASN1_ITYPE_EXTERN:
114 ef = it->funcs; 107 ef = it->funcs;
115 if (ef && ef->asn1_ex_new) 108 if(ef && ef->asn1_ex_new) {
116 { 109 if(!ef->asn1_ex_new(pval, it))
117 if (!ef->asn1_ex_new(pval, it))
118 goto memerr; 110 goto memerr;
119 } 111 }
120 break; 112 break;
121 113
122 case ASN1_ITYPE_COMPAT: 114 case ASN1_ITYPE_COMPAT:
123 cf = it->funcs; 115 cf = it->funcs;
124 if (cf && cf->asn1_new) { 116 if(cf && cf->asn1_new) {
125 *pval = cf->asn1_new(); 117 *pval = cf->asn1_new();
126 if (!*pval) 118 if(!*pval) goto memerr;
127 goto memerr;
128 } 119 }
129 break; 120 break;
130 121
131 case ASN1_ITYPE_PRIMITIVE: 122 case ASN1_ITYPE_PRIMITIVE:
132 if (it->templates) 123 if(it->templates) {
133 { 124 if(!ASN1_template_new(pval, it->templates))
134 if (!ASN1_template_new(pval, it->templates))
135 goto memerr; 125 goto memerr;
136 } 126 } else {
137 else if (!ASN1_primitive_new(pval, it)) 127 if(!ASN1_primitive_new(pval, it))
138 goto memerr; 128 goto memerr;
129 }
139 break; 130 break;
140 131
141 case ASN1_ITYPE_MSTRING: 132 case ASN1_ITYPE_MSTRING:
142 if (!ASN1_primitive_new(pval, it)) 133 if(!ASN1_primitive_new(pval, it))
143 goto memerr; 134 goto memerr;
144 break; 135 break;
145 136
146 case ASN1_ITYPE_CHOICE: 137 case ASN1_ITYPE_CHOICE:
147 if (asn1_cb) 138 if(asn1_cb) {
148 {
149 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); 139 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
150 if (!i) 140 if(!i) goto auxerr;
151 goto auxerr; 141 if(i==2) {
152 if (i==2)
153 {
154#ifdef CRYPTO_MDEBUG 142#ifdef CRYPTO_MDEBUG
155 if (it->sname) 143 if(it->sname) CRYPTO_pop_info();
156 CRYPTO_pop_info();
157#endif 144#endif
158 return 1; 145 return 1;
159 }
160 } 146 }
161 if (!combine) 147 }
162 { 148 if(!combine) {
163 *pval = OPENSSL_malloc(it->size); 149 *pval = OPENSSL_malloc(it->size);
164 if (!*pval) 150 if(!*pval) goto memerr;
165 goto memerr;
166 memset(*pval, 0, it->size); 151 memset(*pval, 0, it->size);
167 } 152 }
168 asn1_set_choice_selector(pval, -1, it); 153 asn1_set_choice_selector(pval, -1, it);
169 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it)) 154 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
170 goto auxerr; 155 goto auxerr;
171 break; 156 break;
172 157
173 case ASN1_ITYPE_NDEF_SEQUENCE:
174 case ASN1_ITYPE_SEQUENCE: 158 case ASN1_ITYPE_SEQUENCE:
175 if (asn1_cb) 159 if(asn1_cb) {
176 {
177 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it); 160 i = asn1_cb(ASN1_OP_NEW_PRE, pval, it);
178 if (!i) 161 if(!i) goto auxerr;
179 goto auxerr; 162 if(i==2) {
180 if (i==2)
181 {
182#ifdef CRYPTO_MDEBUG 163#ifdef CRYPTO_MDEBUG
183 if (it->sname) 164 if(it->sname) CRYPTO_pop_info();
184 CRYPTO_pop_info();
185#endif 165#endif
186 return 1; 166 return 1;
187 }
188 } 167 }
189 if (!combine) 168 }
190 { 169 if(!combine) {
191 *pval = OPENSSL_malloc(it->size); 170 *pval = OPENSSL_malloc(it->size);
192 if (!*pval) 171 if(!*pval) goto memerr;
193 goto memerr;
194 memset(*pval, 0, it->size); 172 memset(*pval, 0, it->size);
195 asn1_do_lock(pval, 0, it); 173 asn1_do_lock(pval, 0, it);
196 asn1_enc_init(pval, it); 174 asn1_enc_init(pval, it);
197 } 175 }
198 for (i = 0, tt = it->templates; i < it->tcount; tt++, i++) 176 for(i = 0, tt = it->templates; i < it->tcount; tt++, i++) {
199 {
200 pseqval = asn1_get_field_ptr(pval, tt); 177 pseqval = asn1_get_field_ptr(pval, tt);
201 if (!ASN1_template_new(pseqval, tt)) 178 if(!ASN1_template_new(pseqval, tt)) goto memerr;
202 goto memerr; 179 }
203 } 180 if(asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
204 if (asn1_cb && !asn1_cb(ASN1_OP_NEW_POST, pval, it))
205 goto auxerr; 181 goto auxerr;
206 break; 182 break;
207 } 183 }
208#ifdef CRYPTO_MDEBUG 184#ifdef CRYPTO_MDEBUG
209 if (it->sname) CRYPTO_pop_info(); 185 if(it->sname) CRYPTO_pop_info();
210#endif 186#endif
211 return 1; 187 return 1;
212 188
213 memerr: 189 memerr:
214 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ERR_R_MALLOC_FAILURE); 190 ASN1err(ASN1_F_ASN1_ITEM_NEW, ERR_R_MALLOC_FAILURE);
215#ifdef CRYPTO_MDEBUG 191#ifdef CRYPTO_MDEBUG
216 if (it->sname) CRYPTO_pop_info(); 192 if(it->sname) CRYPTO_pop_info();
217#endif 193#endif
218 return 0; 194 return 0;
219 195
220 auxerr: 196 auxerr:
221 ASN1err(ASN1_F_ASN1_ITEM_EX_COMBINE_NEW, ASN1_R_AUX_ERROR); 197 ASN1err(ASN1_F_ASN1_ITEM_NEW, ASN1_R_AUX_ERROR);
222 ASN1_item_ex_free(pval, it); 198 ASN1_item_ex_free(pval, it);
223#ifdef CRYPTO_MDEBUG 199#ifdef CRYPTO_MDEBUG
224 if (it->sname) CRYPTO_pop_info(); 200 if(it->sname) CRYPTO_pop_info();
225#endif 201#endif
226 return 0; 202 return 0;
227 203
228 } 204}
229 205
230static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 206static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
231 { 207{
232 const ASN1_EXTERN_FUNCS *ef; 208 const ASN1_EXTERN_FUNCS *ef;
233 209
234 switch(it->itype) 210 switch(it->itype) {
235 {
236 211
237 case ASN1_ITYPE_EXTERN: 212 case ASN1_ITYPE_EXTERN:
238 ef = it->funcs; 213 ef = it->funcs;
239 if (ef && ef->asn1_ex_clear) 214 if(ef && ef->asn1_ex_clear)
240 ef->asn1_ex_clear(pval, it); 215 ef->asn1_ex_clear(pval, it);
241 else *pval = NULL; 216 else *pval = NULL;
242 break; 217 break;
243 218
244 219
245 case ASN1_ITYPE_PRIMITIVE: 220 case ASN1_ITYPE_PRIMITIVE:
246 if (it->templates) 221 if(it->templates)
247 asn1_template_clear(pval, it->templates); 222 asn1_template_clear(pval, it->templates);
248 else 223 else
249 asn1_primitive_clear(pval, it); 224 asn1_primitive_clear(pval, it);
@@ -256,90 +231,75 @@ static void asn1_item_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
256 case ASN1_ITYPE_COMPAT: 231 case ASN1_ITYPE_COMPAT:
257 case ASN1_ITYPE_CHOICE: 232 case ASN1_ITYPE_CHOICE:
258 case ASN1_ITYPE_SEQUENCE: 233 case ASN1_ITYPE_SEQUENCE:
259 case ASN1_ITYPE_NDEF_SEQUENCE:
260 *pval = NULL; 234 *pval = NULL;
261 break; 235 break;
262 }
263 } 236 }
237}
264 238
265 239
266int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 240int ASN1_template_new(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
267 { 241{
268 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item); 242 const ASN1_ITEM *it = ASN1_ITEM_ptr(tt->item);
269 int ret; 243 int ret;
270 if (tt->flags & ASN1_TFLG_OPTIONAL) 244 if(tt->flags & ASN1_TFLG_OPTIONAL) {
271 {
272 asn1_template_clear(pval, tt); 245 asn1_template_clear(pval, tt);
273 return 1; 246 return 1;
274 } 247 }
275 /* If ANY DEFINED BY nothing to do */ 248 /* If ANY DEFINED BY nothing to do */
276 249
277 if (tt->flags & ASN1_TFLG_ADB_MASK) 250 if(tt->flags & ASN1_TFLG_ADB_MASK) {
278 {
279 *pval = NULL; 251 *pval = NULL;
280 return 1; 252 return 1;
281 } 253 }
282#ifdef CRYPTO_MDEBUG 254#ifdef CRYPTO_MDEBUG
283 if (tt->field_name) 255 if(tt->field_name) CRYPTO_push_info(tt->field_name);
284 CRYPTO_push_info(tt->field_name);
285#endif 256#endif
286 /* If SET OF or SEQUENCE OF, its a STACK */ 257 /* If SET OF or SEQUENCE OF, its a STACK */
287 if (tt->flags & ASN1_TFLG_SK_MASK) 258 if(tt->flags & ASN1_TFLG_SK_MASK) {
288 {
289 STACK_OF(ASN1_VALUE) *skval; 259 STACK_OF(ASN1_VALUE) *skval;
290 skval = sk_ASN1_VALUE_new_null(); 260 skval = sk_ASN1_VALUE_new_null();
291 if (!skval) 261 if(!skval) {
292 {
293 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE); 262 ASN1err(ASN1_F_ASN1_TEMPLATE_NEW, ERR_R_MALLOC_FAILURE);
294 ret = 0; 263 ret = 0;
295 goto done; 264 goto done;
296 } 265 }
297 *pval = (ASN1_VALUE *)skval; 266 *pval = (ASN1_VALUE *)skval;
298 ret = 1; 267 ret = 1;
299 goto done; 268 goto done;
300 } 269 }
301 /* Otherwise pass it back to the item routine */ 270 /* Otherwise pass it back to the item routine */
302 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE); 271 ret = asn1_item_ex_combine_new(pval, it, tt->flags & ASN1_TFLG_COMBINE);
303 done: 272 done:
304#ifdef CRYPTO_MDEBUG 273#ifdef CRYPTO_MDEBUG
305 if (it->sname) 274 if(it->sname) CRYPTO_pop_info();
306 CRYPTO_pop_info();
307#endif 275#endif
308 return ret; 276 return ret;
309 } 277}
310 278
311static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 279static void asn1_template_clear(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
312 { 280{
313 /* If ADB or STACK just NULL the field */ 281 /* If ADB or STACK just NULL the field */
314 if (tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK)) 282 if(tt->flags & (ASN1_TFLG_ADB_MASK|ASN1_TFLG_SK_MASK))
315 *pval = NULL; 283 *pval = NULL;
316 else 284 else
317 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item)); 285 asn1_item_clear(pval, ASN1_ITEM_ptr(tt->item));
318 } 286}
319 287
320 288
321/* NB: could probably combine most of the real XXX_new() behaviour and junk 289/* NB: could probably combine most of the real XXX_new() behaviour and junk all the old
322 * all the old functions. 290 * functions.
323 */ 291 */
324 292
325int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it) 293int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
326 { 294{
327 ASN1_TYPE *typ; 295 ASN1_TYPE *typ;
328 int utype; 296 int utype;
329 297 const ASN1_PRIMITIVE_FUNCS *pf;
330 if (it && it->funcs) 298 pf = it->funcs;
331 { 299 if(pf && pf->prim_new) return pf->prim_new(pval, it);
332 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 300 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
333 if (pf->prim_new) 301 else utype = it->utype;
334 return pf->prim_new(pval, it); 302 switch(utype) {
335 }
336
337 if (!it || (it->itype == ASN1_ITYPE_MSTRING))
338 utype = -1;
339 else
340 utype = it->utype;
341 switch(utype)
342 {
343 case V_ASN1_OBJECT: 303 case V_ASN1_OBJECT:
344 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef); 304 *pval = (ASN1_VALUE *)OBJ_nid2obj(NID_undef);
345 return 1; 305 return 1;
@@ -357,8 +317,7 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
357 317
358 case V_ASN1_ANY: 318 case V_ASN1_ANY:
359 typ = OPENSSL_malloc(sizeof(ASN1_TYPE)); 319 typ = OPENSSL_malloc(sizeof(ASN1_TYPE));
360 if (!typ) 320 if(!typ) return 0;
361 return 0;
362 typ->value.ptr = NULL; 321 typ->value.ptr = NULL;
363 typ->type = -1; 322 typ->type = -1;
364 *pval = (ASN1_VALUE *)typ; 323 *pval = (ASN1_VALUE *)typ;
@@ -367,29 +326,26 @@ int ASN1_primitive_new(ASN1_VALUE **pval, const ASN1_ITEM *it)
367 default: 326 default:
368 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype); 327 *pval = (ASN1_VALUE *)ASN1_STRING_type_new(utype);
369 break; 328 break;
370 }
371 if (*pval)
372 return 1;
373 return 0;
374 } 329 }
330 if(*pval) return 1;
331 return 0;
332}
375 333
376void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it) 334void asn1_primitive_clear(ASN1_VALUE **pval, const ASN1_ITEM *it)
377 { 335{
378 int utype; 336 int utype;
379 if (it && it->funcs) 337 const ASN1_PRIMITIVE_FUNCS *pf;
380 { 338 pf = it->funcs;
381 const ASN1_PRIMITIVE_FUNCS *pf = it->funcs; 339 if(pf) {
382 if (pf->prim_clear) 340 if(pf->prim_clear)
383 pf->prim_clear(pval, it); 341 pf->prim_clear(pval, it);
384 else 342 else
385 *pval = NULL; 343 *pval = NULL;
386 return; 344 return;
387 } 345 }
388 if (!it || (it->itype == ASN1_ITYPE_MSTRING)) 346 if(!it || (it->itype == ASN1_ITYPE_MSTRING)) utype = -1;
389 utype = -1; 347 else utype = it->utype;
390 else 348 if(utype == V_ASN1_BOOLEAN)
391 utype = it->utype;
392 if (utype == V_ASN1_BOOLEAN)
393 *(ASN1_BOOLEAN *)pval = it->size; 349 *(ASN1_BOOLEAN *)pval = it->size;
394 else *pval = NULL; 350 else *pval = NULL;
395 } 351}
diff --git a/src/lib/libcrypto/asn1/tasn_typ.c b/src/lib/libcrypto/asn1/tasn_typ.c
index 6f17f1bec7..804d2eeba2 100644
--- a/src/lib/libcrypto/asn1/tasn_typ.c
+++ b/src/lib/libcrypto/asn1/tasn_typ.c
@@ -131,7 +131,3 @@ IMPLEMENT_ASN1_FUNCTIONS_name(ASN1_STRING, DIRECTORYSTRING)
131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1) 131IMPLEMENT_ASN1_TYPE_ex(ASN1_BOOLEAN, ASN1_BOOLEAN, -1)
132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1) 132IMPLEMENT_ASN1_TYPE_ex(ASN1_TBOOLEAN, ASN1_BOOLEAN, 1)
133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0) 133IMPLEMENT_ASN1_TYPE_ex(ASN1_FBOOLEAN, ASN1_BOOLEAN, 0)
134
135/* Special, OCTET STRING with indefinite length constructed support */
136
137IMPLEMENT_ASN1_TYPE_ex(ASN1_OCTET_STRING_NDEF, ASN1_OCTET_STRING, ASN1_TFLG_NDEF)
diff --git a/src/lib/libcrypto/asn1/tasn_utl.c b/src/lib/libcrypto/asn1/tasn_utl.c
index 34d520b180..8996ce8c13 100644
--- a/src/lib/libcrypto/asn1/tasn_utl.c
+++ b/src/lib/libcrypto/asn1/tasn_utl.c
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2000-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -74,23 +74,23 @@
74 */ 74 */
75 75
76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it) 76int asn1_get_choice_selector(ASN1_VALUE **pval, const ASN1_ITEM *it)
77 { 77{
78 int *sel = offset2ptr(*pval, it->utype); 78 int *sel = offset2ptr(*pval, it->utype);
79 return *sel; 79 return *sel;
80 } 80}
81 81
82/* Given an ASN1_ITEM CHOICE type set 82/* Given an ASN1_ITEM CHOICE type set
83 * the selector value, return old value. 83 * the selector value, return old value.
84 */ 84 */
85 85
86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it) 86int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
87 { 87{
88 int *sel, ret; 88 int *sel, ret;
89 sel = offset2ptr(*pval, it->utype); 89 sel = offset2ptr(*pval, it->utype);
90 ret = *sel; 90 ret = *sel;
91 *sel = value; 91 *sel = value;
92 return ret; 92 return ret;
93 } 93}
94 94
95/* Do reference counting. The value 'op' decides what to do. 95/* Do reference counting. The value 'op' decides what to do.
96 * if it is +1 then the count is incremented. If op is 0 count is 96 * if it is +1 then the count is incremented. If op is 0 count is
@@ -99,134 +99,114 @@ int asn1_set_choice_selector(ASN1_VALUE **pval, int value, const ASN1_ITEM *it)
99 */ 99 */
100 100
101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it) 101int asn1_do_lock(ASN1_VALUE **pval, int op, const ASN1_ITEM *it)
102 { 102{
103 const ASN1_AUX *aux; 103 const ASN1_AUX *aux;
104 int *lck, ret; 104 int *lck, ret;
105 if ((it->itype != ASN1_ITYPE_SEQUENCE) 105 if(it->itype != ASN1_ITYPE_SEQUENCE) return 0;
106 && (it->itype != ASN1_ITYPE_NDEF_SEQUENCE))
107 return 0;
108 aux = it->funcs; 106 aux = it->funcs;
109 if (!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) 107 if(!aux || !(aux->flags & ASN1_AFLG_REFCOUNT)) return 0;
110 return 0;
111 lck = offset2ptr(*pval, aux->ref_offset); 108 lck = offset2ptr(*pval, aux->ref_offset);
112 if (op == 0) 109 if(op == 0) {
113 {
114 *lck = 1; 110 *lck = 1;
115 return 1; 111 return 1;
116 } 112 }
117 ret = CRYPTO_add(lck, op, aux->ref_lock); 113 ret = CRYPTO_add(lck, op, aux->ref_lock);
118#ifdef REF_PRINT 114#ifdef REF_PRINT
119 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck); 115 fprintf(stderr, "%s: Reference Count: %d\n", it->sname, *lck);
120#endif 116#endif
121#ifdef REF_CHECK 117#ifdef REF_CHECK
122 if (ret < 0) 118 if(ret < 0)
123 fprintf(stderr, "%s, bad reference count\n", it->sname); 119 fprintf(stderr, "%s, bad reference count\n", it->sname);
124#endif 120#endif
125 return ret; 121 return ret;
126 } 122}
127 123
128static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it) 124static ASN1_ENCODING *asn1_get_enc_ptr(ASN1_VALUE **pval, const ASN1_ITEM *it)
129 { 125{
130 const ASN1_AUX *aux; 126 const ASN1_AUX *aux;
131 if (!pval || !*pval) 127 if(!pval || !*pval) return NULL;
132 return NULL;
133 aux = it->funcs; 128 aux = it->funcs;
134 if (!aux || !(aux->flags & ASN1_AFLG_ENCODING)) 129 if(!aux || !(aux->flags & ASN1_AFLG_ENCODING)) return NULL;
135 return NULL;
136 return offset2ptr(*pval, aux->enc_offset); 130 return offset2ptr(*pval, aux->enc_offset);
137 } 131}
138 132
139void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it) 133void asn1_enc_init(ASN1_VALUE **pval, const ASN1_ITEM *it)
140 { 134{
141 ASN1_ENCODING *enc; 135 ASN1_ENCODING *enc;
142 enc = asn1_get_enc_ptr(pval, it); 136 enc = asn1_get_enc_ptr(pval, it);
143 if (enc) 137 if(enc) {
144 {
145 enc->enc = NULL; 138 enc->enc = NULL;
146 enc->len = 0; 139 enc->len = 0;
147 enc->modified = 1; 140 enc->modified = 1;
148 }
149 } 141 }
142}
150 143
151void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it) 144void asn1_enc_free(ASN1_VALUE **pval, const ASN1_ITEM *it)
152 { 145{
153 ASN1_ENCODING *enc; 146 ASN1_ENCODING *enc;
154 enc = asn1_get_enc_ptr(pval, it); 147 enc = asn1_get_enc_ptr(pval, it);
155 if (enc) 148 if(enc) {
156 { 149 if(enc->enc) OPENSSL_free(enc->enc);
157 if (enc->enc)
158 OPENSSL_free(enc->enc);
159 enc->enc = NULL; 150 enc->enc = NULL;
160 enc->len = 0; 151 enc->len = 0;
161 enc->modified = 1; 152 enc->modified = 1;
162 }
163 } 153 }
154}
164 155
165int asn1_enc_save(ASN1_VALUE **pval, const unsigned char *in, int inlen, 156int asn1_enc_save(ASN1_VALUE **pval, unsigned char *in, int inlen, const ASN1_ITEM *it)
166 const ASN1_ITEM *it) 157{
167 {
168 ASN1_ENCODING *enc; 158 ASN1_ENCODING *enc;
169 enc = asn1_get_enc_ptr(pval, it); 159 enc = asn1_get_enc_ptr(pval, it);
170 if (!enc) 160 if(!enc) return 1;
171 return 1;
172 161
173 if (enc->enc) 162 if(enc->enc) OPENSSL_free(enc->enc);
174 OPENSSL_free(enc->enc);
175 enc->enc = OPENSSL_malloc(inlen); 163 enc->enc = OPENSSL_malloc(inlen);
176 if (!enc->enc) 164 if(!enc->enc) return 0;
177 return 0;
178 memcpy(enc->enc, in, inlen); 165 memcpy(enc->enc, in, inlen);
179 enc->len = inlen; 166 enc->len = inlen;
180 enc->modified = 0; 167 enc->modified = 0;
181 168
182 return 1; 169 return 1;
183 } 170}
184 171
185int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, 172int asn1_enc_restore(int *len, unsigned char **out, ASN1_VALUE **pval, const ASN1_ITEM *it)
186 const ASN1_ITEM *it) 173{
187 {
188 ASN1_ENCODING *enc; 174 ASN1_ENCODING *enc;
189 enc = asn1_get_enc_ptr(pval, it); 175 enc = asn1_get_enc_ptr(pval, it);
190 if (!enc || enc->modified) 176 if(!enc || enc->modified) return 0;
191 return 0; 177 if(out) {
192 if (out)
193 {
194 memcpy(*out, enc->enc, enc->len); 178 memcpy(*out, enc->enc, enc->len);
195 *out += enc->len; 179 *out += enc->len;
196 }
197 if (len)
198 *len = enc->len;
199 return 1;
200 } 180 }
181 if(len) *len = enc->len;
182 return 1;
183}
201 184
202/* Given an ASN1_TEMPLATE get a pointer to a field */ 185/* Given an ASN1_TEMPLATE get a pointer to a field */
203ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt) 186ASN1_VALUE ** asn1_get_field_ptr(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt)
204 { 187{
205 ASN1_VALUE **pvaltmp; 188 ASN1_VALUE **pvaltmp;
206 if (tt->flags & ASN1_TFLG_COMBINE) 189 if(tt->flags & ASN1_TFLG_COMBINE) return pval;
207 return pval;
208 pvaltmp = offset2ptr(*pval, tt->offset); 190 pvaltmp = offset2ptr(*pval, tt->offset);
209 /* NOTE for BOOLEAN types the field is just a plain 191 /* NOTE for BOOLEAN types the field is just a plain
210 * int so we can't return int **, so settle for 192 * int so we can't return int **, so settle for
211 * (int *). 193 * (int *).
212 */ 194 */
213 return pvaltmp; 195 return pvaltmp;
214 } 196}
215 197
216/* Handle ANY DEFINED BY template, find the selector, look up 198/* Handle ANY DEFINED BY template, find the selector, look up
217 * the relevant ASN1_TEMPLATE in the table and return it. 199 * the relevant ASN1_TEMPLATE in the table and return it.
218 */ 200 */
219 201
220const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, 202const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt, int nullerr)
221 int nullerr) 203{
222 {
223 const ASN1_ADB *adb; 204 const ASN1_ADB *adb;
224 const ASN1_ADB_TABLE *atbl; 205 const ASN1_ADB_TABLE *atbl;
225 long selector; 206 long selector;
226 ASN1_VALUE **sfld; 207 ASN1_VALUE **sfld;
227 int i; 208 int i;
228 if (!(tt->flags & ASN1_TFLG_ADB_MASK)) 209 if(!(tt->flags & ASN1_TFLG_ADB_MASK)) return tt;
229 return tt;
230 210
231 /* Else ANY DEFINED BY ... get the table */ 211 /* Else ANY DEFINED BY ... get the table */
232 adb = ASN1_ADB_ptr(tt->item); 212 adb = ASN1_ADB_ptr(tt->item);
@@ -235,18 +215,16 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
235 sfld = offset2ptr(*pval, adb->offset); 215 sfld = offset2ptr(*pval, adb->offset);
236 216
237 /* Check if NULL */ 217 /* Check if NULL */
238 if (!sfld) 218 if(!sfld) {
239 { 219 if(!adb->null_tt) goto err;
240 if (!adb->null_tt)
241 goto err;
242 return adb->null_tt; 220 return adb->null_tt;
243 } 221 }
244 222
245 /* Convert type to a long: 223 /* Convert type to a long:
246 * NB: don't check for NID_undef here because it 224 * NB: don't check for NID_undef here because it
247 * might be a legitimate value in the table 225 * might be a legitimate value in the table
248 */ 226 */
249 if (tt->flags & ASN1_TFLG_ADB_OID) 227 if(tt->flags & ASN1_TFLG_ADB_OID)
250 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld); 228 selector = OBJ_obj2nid((ASN1_OBJECT *)*sfld);
251 else 229 else
252 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld); 230 selector = ASN1_INTEGER_get((ASN1_INTEGER *)*sfld);
@@ -259,21 +237,17 @@ const ASN1_TEMPLATE *asn1_do_adb(ASN1_VALUE **pval, const ASN1_TEMPLATE *tt,
259 * linear search. 237 * linear search.
260 */ 238 */
261 239
262 for (atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++) 240 for(atbl = adb->tbl, i = 0; i < adb->tblcount; i++, atbl++)
263 if (atbl->value == selector) 241 if(atbl->value == selector) return &atbl->tt;
264 return &atbl->tt;
265 242
266 /* FIXME: need to search application table too */ 243 /* FIXME: need to search application table too */
267 244
268 /* No match, return default type */ 245 /* No match, return default type */
269 if (!adb->default_tt) 246 if(!adb->default_tt) goto err;
270 goto err;
271 return adb->default_tt; 247 return adb->default_tt;
272 248
273 err: 249 err:
274 /* FIXME: should log the value or OID of unsupported type */ 250 /* FIXME: should log the value or OID of unsupported type */
275 if (nullerr) 251 if(nullerr) ASN1err(ASN1_F_ASN1_DO_ADB, ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
276 ASN1err(ASN1_F_ASN1_DO_ADB,
277 ASN1_R_UNSUPPORTED_ANY_DEFINED_BY_TYPE);
278 return NULL; 252 return NULL;
279 } 253}
diff --git a/src/lib/libcrypto/asn1/x_algor.c b/src/lib/libcrypto/asn1/x_algor.c
index 33533aba86..00b9ea54a1 100644
--- a/src/lib/libcrypto/asn1/x_algor.c
+++ b/src/lib/libcrypto/asn1/x_algor.c
@@ -66,65 +66,8 @@ ASN1_SEQUENCE(X509_ALGOR) = {
66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY) 66 ASN1_OPT(X509_ALGOR, parameter, ASN1_ANY)
67} ASN1_SEQUENCE_END(X509_ALGOR) 67} ASN1_SEQUENCE_END(X509_ALGOR)
68 68
69ASN1_ITEM_TEMPLATE(X509_ALGORS) =
70 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, algorithms, X509_ALGOR)
71ASN1_ITEM_TEMPLATE_END(X509_ALGORS)
72
73IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR) 69IMPLEMENT_ASN1_FUNCTIONS(X509_ALGOR)
74IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_ALGORS, X509_ALGORS, X509_ALGORS)
75IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR) 70IMPLEMENT_ASN1_DUP_FUNCTION(X509_ALGOR)
76 71
77IMPLEMENT_STACK_OF(X509_ALGOR) 72IMPLEMENT_STACK_OF(X509_ALGOR)
78IMPLEMENT_ASN1_SET_OF(X509_ALGOR) 73IMPLEMENT_ASN1_SET_OF(X509_ALGOR)
79
80int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval)
81 {
82 if (!alg)
83 return 0;
84 if (ptype != V_ASN1_UNDEF)
85 {
86 if (alg->parameter == NULL)
87 alg->parameter = ASN1_TYPE_new();
88 if (alg->parameter == NULL)
89 return 0;
90 }
91 if (alg)
92 {
93 if (alg->algorithm)
94 ASN1_OBJECT_free(alg->algorithm);
95 alg->algorithm = aobj;
96 }
97 if (ptype == 0)
98 return 1;
99 if (ptype == V_ASN1_UNDEF)
100 {
101 if (alg->parameter)
102 {
103 ASN1_TYPE_free(alg->parameter);
104 alg->parameter = NULL;
105 }
106 }
107 else
108 ASN1_TYPE_set(alg->parameter, ptype, pval);
109 return 1;
110 }
111
112void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
113 X509_ALGOR *algor)
114 {
115 if (paobj)
116 *paobj = algor->algorithm;
117 if (pptype)
118 {
119 if (algor->parameter == NULL)
120 {
121 *pptype = V_ASN1_UNDEF;
122 return;
123 }
124 else
125 *pptype = algor->parameter->type;
126 if (ppval)
127 *ppval = algor->parameter->value.ptr;
128 }
129 }
130
diff --git a/src/lib/libcrypto/asn1/x_bignum.c b/src/lib/libcrypto/asn1/x_bignum.c
index 869c05d931..848c7a0877 100644
--- a/src/lib/libcrypto/asn1/x_bignum.c
+++ b/src/lib/libcrypto/asn1/x_bignum.c
@@ -59,7 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/bn.h>
63 62
64/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a 63/* Custom primitive type for BIGNUM handling. This reads in an ASN1_INTEGER as a
65 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all 64 * BIGNUM directly. Currently it ignores the sign which isn't a problem since all
@@ -73,7 +72,7 @@ static int bn_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
73static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 72static void bn_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
74 73
75static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 74static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
76static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 75static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
77 76
78static ASN1_PRIMITIVE_FUNCS bignum_pf = { 77static ASN1_PRIMITIVE_FUNCS bignum_pf = {
79 NULL, 0, 78 NULL, 0,
@@ -123,8 +122,7 @@ static int bn_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN
123 return pad + BN_num_bytes(bn); 122 return pad + BN_num_bytes(bn);
124} 123}
125 124
126static int bn_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 125static int bn_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
127 int utype, char *free_cont, const ASN1_ITEM *it)
128{ 126{
129 BIGNUM *bn; 127 BIGNUM *bn;
130 if(!*pval) bn_new(pval, it); 128 if(!*pval) bn_new(pval, it);
diff --git a/src/lib/libcrypto/asn1/x_cinf.c b/src/lib/libcrypto/asn1/x_cinf.c
new file mode 100644
index 0000000000..339a110eef
--- /dev/null
+++ b/src/lib/libcrypto/asn1/x_cinf.c
@@ -0,0 +1,201 @@
1/* crypto/asn1/x_cinf.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/asn1_mac.h>
62#include <openssl/x509.h>
63
64int i2d_X509_CINF(X509_CINF *a, unsigned char **pp)
65 {
66 int v1=0,v2=0;
67 M_ASN1_I2D_vars(a);
68
69 M_ASN1_I2D_len_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1);
70 M_ASN1_I2D_len(a->serialNumber, i2d_ASN1_INTEGER);
71 M_ASN1_I2D_len(a->signature, i2d_X509_ALGOR);
72 M_ASN1_I2D_len(a->issuer, i2d_X509_NAME);
73 M_ASN1_I2D_len(a->validity, i2d_X509_VAL);
74 M_ASN1_I2D_len(a->subject, i2d_X509_NAME);
75 M_ASN1_I2D_len(a->key, i2d_X509_PUBKEY);
76 M_ASN1_I2D_len_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING);
77 M_ASN1_I2D_len_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING);
78 M_ASN1_I2D_len_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
79 i2d_X509_EXTENSION,3,
80 V_ASN1_SEQUENCE,v2);
81
82 M_ASN1_I2D_seq_total();
83
84 M_ASN1_I2D_put_EXP_opt(a->version,i2d_ASN1_INTEGER,0,v1);
85 M_ASN1_I2D_put(a->serialNumber, i2d_ASN1_INTEGER);
86 M_ASN1_I2D_put(a->signature, i2d_X509_ALGOR);
87 M_ASN1_I2D_put(a->issuer, i2d_X509_NAME);
88 M_ASN1_I2D_put(a->validity, i2d_X509_VAL);
89 M_ASN1_I2D_put(a->subject, i2d_X509_NAME);
90 M_ASN1_I2D_put(a->key, i2d_X509_PUBKEY);
91 M_ASN1_I2D_put_IMP_opt(a->issuerUID, i2d_ASN1_BIT_STRING,1);
92 M_ASN1_I2D_put_IMP_opt(a->subjectUID, i2d_ASN1_BIT_STRING,2);
93 M_ASN1_I2D_put_EXP_SEQUENCE_opt_type(X509_EXTENSION,a->extensions,
94 i2d_X509_EXTENSION,3,
95 V_ASN1_SEQUENCE,v2);
96
97 M_ASN1_I2D_finish();
98 }
99
100X509_CINF *d2i_X509_CINF(X509_CINF **a, unsigned char **pp, long length)
101 {
102 int ver=0;
103 M_ASN1_D2I_vars(a,X509_CINF *,X509_CINF_new);
104
105 M_ASN1_D2I_Init();
106 M_ASN1_D2I_start_sequence();
107 /* we have the optional version field */
108 if (M_ASN1_next == (V_ASN1_CONTEXT_SPECIFIC | V_ASN1_CONSTRUCTED | 0))
109 {
110 M_ASN1_D2I_get_EXP_opt(ret->version,d2i_ASN1_INTEGER,0);
111 if (ret->version->data != NULL)
112 ver=ret->version->data[0];
113 }
114 else
115 {
116 if (ret->version != NULL)
117 {
118 M_ASN1_INTEGER_free(ret->version);
119 ret->version=NULL;
120 }
121 }
122 M_ASN1_D2I_get(ret->serialNumber,d2i_ASN1_INTEGER);
123 M_ASN1_D2I_get(ret->signature,d2i_X509_ALGOR);
124 M_ASN1_D2I_get(ret->issuer,d2i_X509_NAME);
125 M_ASN1_D2I_get(ret->validity,d2i_X509_VAL);
126 M_ASN1_D2I_get(ret->subject,d2i_X509_NAME);
127 M_ASN1_D2I_get(ret->key,d2i_X509_PUBKEY);
128 if (ver >= 1) /* version 2 extensions */
129 {
130 if (ret->issuerUID != NULL)
131 {
132 M_ASN1_BIT_STRING_free(ret->issuerUID);
133 ret->issuerUID=NULL;
134 }
135 if (ret->subjectUID != NULL)
136 {
137 M_ASN1_BIT_STRING_free(ret->subjectUID);
138 ret->subjectUID=NULL;
139 }
140 M_ASN1_D2I_get_IMP_opt(ret->issuerUID,d2i_ASN1_BIT_STRING, 1,
141 V_ASN1_BIT_STRING);
142 M_ASN1_D2I_get_IMP_opt(ret->subjectUID,d2i_ASN1_BIT_STRING, 2,
143 V_ASN1_BIT_STRING);
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
151 if (ver >= 2) /* version 3 extensions */
152#endif
153 {
154 if (ret->extensions != NULL)
155 while (sk_X509_EXTENSION_num(ret->extensions))
156 X509_EXTENSION_free(
157 sk_X509_EXTENSION_pop(ret->extensions));
158 M_ASN1_D2I_get_EXP_set_opt_type(X509_EXTENSION,ret->extensions,
159 d2i_X509_EXTENSION,
160 X509_EXTENSION_free,3,
161 V_ASN1_SEQUENCE);
162 }
163 M_ASN1_D2I_Finish(a,X509_CINF_free,ASN1_F_D2I_X509_CINF);
164 }
165
166X509_CINF *X509_CINF_new(void)
167 {
168 X509_CINF *ret=NULL;
169 ASN1_CTX c;
170
171 M_ASN1_New_Malloc(ret,X509_CINF);
172 ret->version=NULL;
173 M_ASN1_New(ret->serialNumber,M_ASN1_INTEGER_new);
174 M_ASN1_New(ret->signature,X509_ALGOR_new);
175 M_ASN1_New(ret->issuer,X509_NAME_new);
176 M_ASN1_New(ret->validity,X509_VAL_new);
177 M_ASN1_New(ret->subject,X509_NAME_new);
178 M_ASN1_New(ret->key,X509_PUBKEY_new);
179 ret->issuerUID=NULL;
180 ret->subjectUID=NULL;
181 ret->extensions=NULL;
182 return(ret);
183 M_ASN1_New_Error(ASN1_F_X509_CINF_NEW);
184 }
185
186void X509_CINF_free(X509_CINF *a)
187 {
188 if (a == NULL) return;
189 M_ASN1_INTEGER_free(a->version);
190 M_ASN1_INTEGER_free(a->serialNumber);
191 X509_ALGOR_free(a->signature);
192 X509_NAME_free(a->issuer);
193 X509_VAL_free(a->validity);
194 X509_NAME_free(a->subject);
195 X509_PUBKEY_free(a->key);
196 M_ASN1_BIT_STRING_free(a->issuerUID);
197 M_ASN1_BIT_STRING_free(a->subjectUID);
198 sk_X509_EXTENSION_pop_free(a->extensions,X509_EXTENSION_free);
199 OPENSSL_free(a);
200 }
201
diff --git a/src/lib/libcrypto/asn1/x_crl.c b/src/lib/libcrypto/asn1/x_crl.c
index 70d56a67f2..b99f8fc522 100644
--- a/src/lib/libcrypto/asn1/x_crl.c
+++ b/src/lib/libcrypto/asn1/x_crl.c
@@ -84,7 +84,7 @@ static int crl_inf_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
84 * would affect the output of X509_CRL_print(). 84 * would affect the output of X509_CRL_print().
85 */ 85 */
86 case ASN1_OP_D2I_POST: 86 case ASN1_OP_D2I_POST:
87 (void)sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp); 87 sk_X509_REVOKED_set_cmp_func(a->revoked,X509_REVOKED_cmp);
88 break; 88 break;
89 } 89 }
90 return 1; 90 return 1;
diff --git a/src/lib/libcrypto/asn1/x_exten.c b/src/lib/libcrypto/asn1/x_exten.c
index 1732e66712..702421b6c8 100644
--- a/src/lib/libcrypto/asn1/x_exten.c
+++ b/src/lib/libcrypto/asn1/x_exten.c
@@ -67,10 +67,5 @@ ASN1_SEQUENCE(X509_EXTENSION) = {
67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING) 67 ASN1_SIMPLE(X509_EXTENSION, value, ASN1_OCTET_STRING)
68} ASN1_SEQUENCE_END(X509_EXTENSION) 68} ASN1_SEQUENCE_END(X509_EXTENSION)
69 69
70ASN1_ITEM_TEMPLATE(X509_EXTENSIONS) =
71 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0, Extension, X509_EXTENSION)
72ASN1_ITEM_TEMPLATE_END(X509_EXTENSIONS)
73
74IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION) 70IMPLEMENT_ASN1_FUNCTIONS(X509_EXTENSION)
75IMPLEMENT_ASN1_ENCODE_FUNCTIONS_fname(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
76IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION) 71IMPLEMENT_ASN1_DUP_FUNCTION(X509_EXTENSION)
diff --git a/src/lib/libcrypto/asn1/x_long.c b/src/lib/libcrypto/asn1/x_long.c
index 0db233cb95..c5f25956cb 100644
--- a/src/lib/libcrypto/asn1/x_long.c
+++ b/src/lib/libcrypto/asn1/x_long.c
@@ -59,7 +59,6 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/bn.h>
63 62
64/* Custom primitive type for long handling. This converts between an ASN1_INTEGER 63/* Custom primitive type for long handling. This converts between an ASN1_INTEGER
65 * and a long directly. 64 * and a long directly.
@@ -70,7 +69,7 @@ static int long_new(ASN1_VALUE **pval, const ASN1_ITEM *it);
70static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it); 69static void long_free(ASN1_VALUE **pval, const ASN1_ITEM *it);
71 70
72static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it); 71static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const ASN1_ITEM *it);
73static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it); 72static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it);
74 73
75static ASN1_PRIMITIVE_FUNCS long_pf = { 74static ASN1_PRIMITIVE_FUNCS long_pf = {
76 NULL, 0, 75 NULL, 0,
@@ -137,14 +136,13 @@ static int long_i2c(ASN1_VALUE **pval, unsigned char *cont, int *putype, const A
137 return clen + pad; 136 return clen + pad;
138} 137}
139 138
140static int long_c2i(ASN1_VALUE **pval, const unsigned char *cont, int len, 139static int long_c2i(ASN1_VALUE **pval, unsigned char *cont, int len, int utype, char *free_cont, const ASN1_ITEM *it)
141 int utype, char *free_cont, const ASN1_ITEM *it)
142{ 140{
143 int neg, i; 141 int neg, i;
144 long ltmp; 142 long ltmp;
145 unsigned long utmp = 0; 143 unsigned long utmp = 0;
146 char *cp = (char *)pval; 144 char *cp = (char *)pval;
147 if(len > (int)sizeof(long)) { 145 if(len > sizeof(long)) {
148 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG); 146 ASN1err(ASN1_F_LONG_C2I, ASN1_R_INTEGER_TOO_LARGE_FOR_LONG);
149 return 0; 147 return 0;
150 } 148 }
diff --git a/src/lib/libcrypto/asn1/x_name.c b/src/lib/libcrypto/asn1/x_name.c
index 04380abc3f..31f3377b64 100644
--- a/src/lib/libcrypto/asn1/x_name.c
+++ b/src/lib/libcrypto/asn1/x_name.c
@@ -61,7 +61,7 @@
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63 63
64static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, 64static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
65 int tag, int aclass, char opt, ASN1_TLC *ctx); 65 int tag, int aclass, char opt, ASN1_TLC *ctx);
66 66
67static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass); 67static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_ITEM *it, int tag, int aclass);
@@ -123,7 +123,7 @@ static int x509_name_ex_new(ASN1_VALUE **val, const ASN1_ITEM *it)
123 return 1; 123 return 1;
124 124
125 memerr: 125 memerr:
126 ASN1err(ASN1_F_X509_NAME_EX_NEW, ERR_R_MALLOC_FAILURE); 126 ASN1err(ASN1_F_X509_NAME_NEW, ERR_R_MALLOC_FAILURE);
127 if (ret) 127 if (ret)
128 { 128 {
129 if (ret->entries) 129 if (ret->entries)
@@ -156,48 +156,48 @@ static void sk_internal_free(void *a)
156 sk_free(a); 156 sk_free(a);
157} 157}
158 158
159static int x509_name_ex_d2i(ASN1_VALUE **val, const unsigned char **in, long len, const ASN1_ITEM *it, 159static int x509_name_ex_d2i(ASN1_VALUE **val, unsigned char **in, long len, const ASN1_ITEM *it,
160 int tag, int aclass, char opt, ASN1_TLC *ctx) 160 int tag, int aclass, char opt, ASN1_TLC *ctx)
161{ 161{
162 const unsigned char *p = *in, *q; 162 unsigned char *p = *in, *q;
163 union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; 163 STACK *intname = NULL, **intname_pp = &intname;
164 union { X509_NAME *x; ASN1_VALUE *a; } nm = {NULL};
165 int i, j, ret; 164 int i, j, ret;
165 X509_NAME *nm = NULL, **nm_pp = &nm;
166 STACK_OF(X509_NAME_ENTRY) *entries; 166 STACK_OF(X509_NAME_ENTRY) *entries;
167 X509_NAME_ENTRY *entry; 167 X509_NAME_ENTRY *entry;
168 q = p; 168 q = p;
169 169
170 /* Get internal representation of Name */ 170 /* Get internal representation of Name */
171 ret = ASN1_item_ex_d2i(&intname.a, 171 ret = ASN1_item_ex_d2i((ASN1_VALUE **)intname_pp,
172 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL), 172 &p, len, ASN1_ITEM_rptr(X509_NAME_INTERNAL),
173 tag, aclass, opt, ctx); 173 tag, aclass, opt, ctx);
174 174
175 if(ret <= 0) return ret; 175 if(ret <= 0) return ret;
176 176
177 if(*val) x509_name_ex_free(val, NULL); 177 if(*val) x509_name_ex_free(val, NULL);
178 if(!x509_name_ex_new(&nm.a, NULL)) goto err; 178 if(!x509_name_ex_new((ASN1_VALUE **)nm_pp, NULL)) goto err;
179 /* We've decoded it: now cache encoding */ 179 /* We've decoded it: now cache encoding */
180 if(!BUF_MEM_grow(nm.x->bytes, p - q)) goto err; 180 if(!BUF_MEM_grow(nm->bytes, p - q)) goto err;
181 memcpy(nm.x->bytes->data, q, p - q); 181 memcpy(nm->bytes->data, q, p - q);
182 182
183 /* Convert internal representation to X509_NAME structure */ 183 /* Convert internal representation to X509_NAME structure */
184 for(i = 0; i < sk_num(intname.s); i++) { 184 for(i = 0; i < sk_num(intname); i++) {
185 entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname.s, i); 185 entries = (STACK_OF(X509_NAME_ENTRY) *)sk_value(intname, i);
186 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) { 186 for(j = 0; j < sk_X509_NAME_ENTRY_num(entries); j++) {
187 entry = sk_X509_NAME_ENTRY_value(entries, j); 187 entry = sk_X509_NAME_ENTRY_value(entries, j);
188 entry->set = i; 188 entry->set = i;
189 if(!sk_X509_NAME_ENTRY_push(nm.x->entries, entry)) 189 if(!sk_X509_NAME_ENTRY_push(nm->entries, entry))
190 goto err; 190 goto err;
191 } 191 }
192 sk_X509_NAME_ENTRY_free(entries); 192 sk_X509_NAME_ENTRY_free(entries);
193 } 193 }
194 sk_free(intname.s); 194 sk_free(intname);
195 nm.x->modified = 0; 195 nm->modified = 0;
196 *val = nm.a; 196 *val = (ASN1_VALUE *)nm;
197 *in = p; 197 *in = p;
198 return ret; 198 return ret;
199 err: 199 err:
200 ASN1err(ASN1_F_X509_NAME_EX_D2I, ERR_R_NESTED_ASN1_ERROR); 200 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_NESTED_ASN1_ERROR);
201 return 0; 201 return 0;
202} 202}
203 203
@@ -219,36 +219,36 @@ static int x509_name_ex_i2d(ASN1_VALUE **val, unsigned char **out, const ASN1_IT
219 219
220static int x509_name_encode(X509_NAME *a) 220static int x509_name_encode(X509_NAME *a)
221{ 221{
222 union { STACK *s; ASN1_VALUE *a; } intname = {NULL}; 222 STACK *intname = NULL, **intname_pp = &intname;
223 int len; 223 int len;
224 unsigned char *p; 224 unsigned char *p;
225 STACK_OF(X509_NAME_ENTRY) *entries = NULL; 225 STACK_OF(X509_NAME_ENTRY) *entries = NULL;
226 X509_NAME_ENTRY *entry; 226 X509_NAME_ENTRY *entry;
227 int i, set = -1; 227 int i, set = -1;
228 intname.s = sk_new_null(); 228 intname = sk_new_null();
229 if(!intname.s) goto memerr; 229 if(!intname) goto memerr;
230 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) { 230 for(i = 0; i < sk_X509_NAME_ENTRY_num(a->entries); i++) {
231 entry = sk_X509_NAME_ENTRY_value(a->entries, i); 231 entry = sk_X509_NAME_ENTRY_value(a->entries, i);
232 if(entry->set != set) { 232 if(entry->set != set) {
233 entries = sk_X509_NAME_ENTRY_new_null(); 233 entries = sk_X509_NAME_ENTRY_new_null();
234 if(!entries) goto memerr; 234 if(!entries) goto memerr;
235 if(!sk_push(intname.s, (char *)entries)) goto memerr; 235 if(!sk_push(intname, (char *)entries)) goto memerr;
236 set = entry->set; 236 set = entry->set;
237 } 237 }
238 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr; 238 if(!sk_X509_NAME_ENTRY_push(entries, entry)) goto memerr;
239 } 239 }
240 len = ASN1_item_ex_i2d(&intname.a, NULL, 240 len = ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp, NULL,
241 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 241 ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
242 if (!BUF_MEM_grow(a->bytes,len)) goto memerr; 242 if (!BUF_MEM_grow(a->bytes,len)) goto memerr;
243 p=(unsigned char *)a->bytes->data; 243 p=(unsigned char *)a->bytes->data;
244 ASN1_item_ex_i2d(&intname.a, 244 ASN1_item_ex_i2d((ASN1_VALUE **)intname_pp,
245 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1); 245 &p, ASN1_ITEM_rptr(X509_NAME_INTERNAL), -1, -1);
246 sk_pop_free(intname.s, sk_internal_free); 246 sk_pop_free(intname, sk_internal_free);
247 a->modified = 0; 247 a->modified = 0;
248 return len; 248 return len;
249 memerr: 249 memerr:
250 sk_pop_free(intname.s, sk_internal_free); 250 sk_pop_free(intname, sk_internal_free);
251 ASN1err(ASN1_F_X509_NAME_ENCODE, ERR_R_MALLOC_FAILURE); 251 ASN1err(ASN1_F_D2I_X509_NAME, ERR_R_MALLOC_FAILURE);
252 return -1; 252 return -1;
253} 253}
254 254
diff --git a/src/lib/libcrypto/asn1/x_pkey.c b/src/lib/libcrypto/asn1/x_pkey.c
index 8453618426..f1c6221ac3 100644
--- a/src/lib/libcrypto/asn1/x_pkey.c
+++ b/src/lib/libcrypto/asn1/x_pkey.c
@@ -69,15 +69,15 @@ int i2d_X509_PKEY(X509_PKEY *a, unsigned char **pp)
69 return(0); 69 return(0);
70 } 70 }
71 71
72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, const unsigned char **pp, long length) 72X509_PKEY *d2i_X509_PKEY(X509_PKEY **a, unsigned char **pp, long length)
73 { 73 {
74 int i; 74 int i;
75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new); 75 M_ASN1_D2I_vars(a,X509_PKEY *,X509_PKEY_new);
76 76
77 M_ASN1_D2I_Init(); 77 M_ASN1_D2I_Init();
78 M_ASN1_D2I_start_sequence(); 78 M_ASN1_D2I_start_sequence();
79 M_ASN1_D2I_get_x(X509_ALGOR,ret->enc_algor,d2i_X509_ALGOR); 79 M_ASN1_D2I_get(ret->enc_algor,d2i_X509_ALGOR);
80 M_ASN1_D2I_get_x(ASN1_OCTET_STRING,ret->enc_pkey,d2i_ASN1_OCTET_STRING); 80 M_ASN1_D2I_get(ret->enc_pkey,d2i_ASN1_OCTET_STRING);
81 81
82 ret->cipher.cipher=EVP_get_cipherbyname( 82 ret->cipher.cipher=EVP_get_cipherbyname(
83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm))); 83 OBJ_nid2ln(OBJ_obj2nid(ret->enc_algor->algorithm)));
diff --git a/src/lib/libcrypto/asn1/x_pubkey.c b/src/lib/libcrypto/asn1/x_pubkey.c
index 91c2756116..7d6d71af88 100644
--- a/src/lib/libcrypto/asn1/x_pubkey.c
+++ b/src/lib/libcrypto/asn1/x_pubkey.c
@@ -60,23 +60,16 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/asn1t.h> 61#include <openssl/asn1t.h>
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63#ifndef OPENSSL_NO_RSA
64#include <openssl/rsa.h>
65#endif
66#ifndef OPENSSL_NO_DSA
67#include <openssl/dsa.h>
68#endif
69 63
70/* Minor tweak to operation: free up EVP_PKEY */ 64/* Minor tweak to operation: free up EVP_PKEY */
71static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 65static int pubkey_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
72 { 66{
73 if (operation == ASN1_OP_FREE_POST) 67 if(operation == ASN1_OP_FREE_POST) {
74 {
75 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval; 68 X509_PUBKEY *pubkey = (X509_PUBKEY *)*pval;
76 EVP_PKEY_free(pubkey->pkey); 69 EVP_PKEY_free(pubkey->pkey);
77 }
78 return 1;
79 } 70 }
71 return 1;
72}
80 73
81ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = { 74ASN1_SEQUENCE_cb(X509_PUBKEY, pubkey_cb) = {
82 ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR), 75 ASN1_SIMPLE(X509_PUBKEY, algor, X509_ALGOR),
@@ -118,12 +111,13 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
118 a->parameter->type=V_ASN1_NULL; 111 a->parameter->type=V_ASN1_NULL;
119 } 112 }
120 } 113 }
114 else
121#ifndef OPENSSL_NO_DSA 115#ifndef OPENSSL_NO_DSA
122 else if (pkey->type == EVP_PKEY_DSA) 116 if (pkey->type == EVP_PKEY_DSA)
123 { 117 {
124 unsigned char *pp; 118 unsigned char *pp;
125 DSA *dsa; 119 DSA *dsa;
126 120
127 dsa=pkey->pkey.dsa; 121 dsa=pkey->pkey.dsa;
128 dsa->write_params=0; 122 dsa->write_params=0;
129 ASN1_TYPE_free(a->parameter); 123 ASN1_TYPE_free(a->parameter);
@@ -157,64 +151,8 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
157 } 151 }
158 OPENSSL_free(p); 152 OPENSSL_free(p);
159 } 153 }
154 else
160#endif 155#endif
161#ifndef OPENSSL_NO_EC
162 else if (pkey->type == EVP_PKEY_EC)
163 {
164 int nid=0;
165 unsigned char *pp;
166 EC_KEY *ec_key;
167 const EC_GROUP *group;
168
169 ec_key = pkey->pkey.ec;
170 ASN1_TYPE_free(a->parameter);
171
172 if ((a->parameter = ASN1_TYPE_new()) == NULL)
173 {
174 X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
175 goto err;
176 }
177
178 group = EC_KEY_get0_group(ec_key);
179 if (EC_GROUP_get_asn1_flag(group)
180 && (nid = EC_GROUP_get_curve_name(group)))
181 {
182 /* just set the OID */
183 a->parameter->type = V_ASN1_OBJECT;
184 a->parameter->value.object = OBJ_nid2obj(nid);
185 }
186 else /* explicit parameters */
187 {
188 if ((i = i2d_ECParameters(ec_key, NULL)) == 0)
189 {
190 X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
191 goto err;
192 }
193 if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
194 {
195 X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE);
196 goto err;
197 }
198 pp = p;
199 if (!i2d_ECParameters(ec_key, &pp))
200 {
201 X509err(X509_F_X509_PUBKEY_SET, ERR_R_EC_LIB);
202 OPENSSL_free(p);
203 goto err;
204 }
205 a->parameter->type = V_ASN1_SEQUENCE;
206 if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL)
207 {
208 X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
209 OPENSSL_free(p);
210 goto err;
211 }
212 ASN1_STRING_set(a->parameter->value.sequence, p, i);
213 OPENSSL_free(p);
214 }
215 }
216#endif
217 else if (1)
218 { 156 {
219 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM); 157 X509err(X509_F_X509_PUBKEY_SET,X509_R_UNSUPPORTED_ALGORITHM);
220 goto err; 158 goto err;
@@ -233,7 +171,7 @@ int X509_PUBKEY_set(X509_PUBKEY **x, EVP_PKEY *pkey)
233 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE); 171 X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
234 goto err; 172 goto err;
235 } 173 }
236 /* Set number of unused bits to zero */ 174 /* Set number of unused bits to zero */
237 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07); 175 pk->public_key->flags&= ~(ASN1_STRING_FLAG_BITS_LEFT|0x07);
238 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT; 176 pk->public_key->flags|=ASN1_STRING_FLAG_BITS_LEFT;
239 177
@@ -260,8 +198,8 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
260 EVP_PKEY *ret=NULL; 198 EVP_PKEY *ret=NULL;
261 long j; 199 long j;
262 int type; 200 int type;
263 const unsigned char *p; 201 unsigned char *p;
264#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA) 202#ifndef OPENSSL_NO_DSA
265 const unsigned char *cp; 203 const unsigned char *cp;
266 X509_ALGOR *a; 204 X509_ALGOR *a;
267#endif 205#endif
@@ -269,106 +207,40 @@ EVP_PKEY *X509_PUBKEY_get(X509_PUBKEY *key)
269 if (key == NULL) goto err; 207 if (key == NULL) goto err;
270 208
271 if (key->pkey != NULL) 209 if (key->pkey != NULL)
272 { 210 {
273 CRYPTO_add(&key->pkey->references, 1, CRYPTO_LOCK_EVP_PKEY); 211 CRYPTO_add(&key->pkey->references,1,CRYPTO_LOCK_EVP_PKEY);
274 return(key->pkey); 212 return(key->pkey);
275 } 213 }
276 214
277 if (key->public_key == NULL) goto err; 215 if (key->public_key == NULL) goto err;
278 216
279 type=OBJ_obj2nid(key->algor->algorithm); 217 type=OBJ_obj2nid(key->algor->algorithm);
280 if ((ret = EVP_PKEY_new()) == NULL) 218 p=key->public_key->data;
219 j=key->public_key->length;
220 if ((ret=d2i_PublicKey(type,NULL,&p,(long)j)) == NULL)
281 { 221 {
282 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE); 222 X509err(X509_F_X509_PUBKEY_GET,X509_R_ERR_ASN1_LIB);
283 goto err; 223 goto err;
284 } 224 }
285 ret->type = EVP_PKEY_type(type); 225 ret->save_parameters=0;
286
287 /* the parameters must be extracted before the public key (ECDSA!) */
288
289#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_ECDSA)
290 a=key->algor;
291#endif
292 226
293 if (0)
294 ;
295#ifndef OPENSSL_NO_DSA 227#ifndef OPENSSL_NO_DSA
296 else if (ret->type == EVP_PKEY_DSA) 228 a=key->algor;
229 if (ret->type == EVP_PKEY_DSA)
297 { 230 {
298 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE)) 231 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
299 { 232 {
300 if ((ret->pkey.dsa = DSA_new()) == NULL)
301 {
302 X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
303 goto err;
304 }
305 ret->pkey.dsa->write_params=0; 233 ret->pkey.dsa->write_params=0;
306 cp=p=a->parameter->value.sequence->data; 234 cp=p=a->parameter->value.sequence->data;
307 j=a->parameter->value.sequence->length; 235 j=a->parameter->value.sequence->length;
308 if (!d2i_DSAparams(&ret->pkey.dsa, &cp, (long)j)) 236 if (!d2i_DSAparams(&ret->pkey.dsa,&cp,(long)j))
309 goto err; 237 goto err;
310 } 238 }
311 ret->save_parameters=1; 239 ret->save_parameters=1;
312 } 240 }
313#endif 241#endif
314#ifndef OPENSSL_NO_EC 242 key->pkey=ret;
315 else if (ret->type == EVP_PKEY_EC) 243 CRYPTO_add(&ret->references,1,CRYPTO_LOCK_EVP_PKEY);
316 {
317 if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
318 {
319 /* type == V_ASN1_SEQUENCE => we have explicit parameters
320 * (e.g. parameters in the X9_62_EC_PARAMETERS-structure )
321 */
322 if ((ret->pkey.ec= EC_KEY_new()) == NULL)
323 {
324 X509err(X509_F_X509_PUBKEY_GET,
325 ERR_R_MALLOC_FAILURE);
326 goto err;
327 }
328 cp = p = a->parameter->value.sequence->data;
329 j = a->parameter->value.sequence->length;
330 if (!d2i_ECParameters(&ret->pkey.ec, &cp, (long)j))
331 {
332 X509err(X509_F_X509_PUBKEY_GET, ERR_R_EC_LIB);
333 goto err;
334 }
335 }
336 else if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))
337 {
338 /* type == V_ASN1_OBJECT => the parameters are given
339 * by an asn1 OID
340 */
341 EC_KEY *ec_key;
342 EC_GROUP *group;
343
344 if (ret->pkey.ec == NULL)
345 ret->pkey.ec = EC_KEY_new();
346 ec_key = ret->pkey.ec;
347 if (ec_key == NULL)
348 goto err;
349 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object));
350 if (group == NULL)
351 goto err;
352 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
353 if (EC_KEY_set_group(ec_key, group) == 0)
354 goto err;
355 EC_GROUP_free(group);
356 }
357 /* the case implicitlyCA is currently not implemented */
358 ret->save_parameters = 1;
359 }
360#endif
361
362 p=key->public_key->data;
363 j=key->public_key->length;
364 if (!d2i_PublicKey(type, &ret, &p, (long)j))
365 {
366 X509err(X509_F_X509_PUBKEY_GET, X509_R_ERR_ASN1_LIB);
367 goto err;
368 }
369
370 key->pkey = ret;
371 CRYPTO_add(&ret->references, 1, CRYPTO_LOCK_EVP_PKEY);
372 return(ret); 244 return(ret);
373err: 245err:
374 if (ret != NULL) 246 if (ret != NULL)
@@ -380,9 +252,9 @@ err:
380 * and encode or decode as X509_PUBKEY 252 * and encode or decode as X509_PUBKEY
381 */ 253 */
382 254
383EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp, 255EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, unsigned char **pp,
384 long length) 256 long length)
385 { 257{
386 X509_PUBKEY *xpk; 258 X509_PUBKEY *xpk;
387 EVP_PKEY *pktmp; 259 EVP_PKEY *pktmp;
388 xpk = d2i_X509_PUBKEY(NULL, pp, length); 260 xpk = d2i_X509_PUBKEY(NULL, pp, length);
@@ -390,16 +262,15 @@ EVP_PKEY *d2i_PUBKEY(EVP_PKEY **a, const unsigned char **pp,
390 pktmp = X509_PUBKEY_get(xpk); 262 pktmp = X509_PUBKEY_get(xpk);
391 X509_PUBKEY_free(xpk); 263 X509_PUBKEY_free(xpk);
392 if(!pktmp) return NULL; 264 if(!pktmp) return NULL;
393 if(a) 265 if(a) {
394 {
395 EVP_PKEY_free(*a); 266 EVP_PKEY_free(*a);
396 *a = pktmp; 267 *a = pktmp;
397 }
398 return pktmp;
399 } 268 }
269 return pktmp;
270}
400 271
401int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp) 272int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
402 { 273{
403 X509_PUBKEY *xpk=NULL; 274 X509_PUBKEY *xpk=NULL;
404 int ret; 275 int ret;
405 if(!a) return 0; 276 if(!a) return 0;
@@ -407,125 +278,83 @@ int i2d_PUBKEY(EVP_PKEY *a, unsigned char **pp)
407 ret = i2d_X509_PUBKEY(xpk, pp); 278 ret = i2d_X509_PUBKEY(xpk, pp);
408 X509_PUBKEY_free(xpk); 279 X509_PUBKEY_free(xpk);
409 return ret; 280 return ret;
410 } 281}
411 282
412/* The following are equivalents but which return RSA and DSA 283/* The following are equivalents but which return RSA and DSA
413 * keys 284 * keys
414 */ 285 */
415#ifndef OPENSSL_NO_RSA 286#ifndef OPENSSL_NO_RSA
416RSA *d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, 287RSA *d2i_RSA_PUBKEY(RSA **a, unsigned char **pp,
417 long length) 288 long length)
418 { 289{
419 EVP_PKEY *pkey; 290 EVP_PKEY *pkey;
420 RSA *key; 291 RSA *key;
421 const unsigned char *q; 292 unsigned char *q;
422 q = *pp; 293 q = *pp;
423 pkey = d2i_PUBKEY(NULL, &q, length); 294 pkey = d2i_PUBKEY(NULL, &q, length);
424 if (!pkey) return NULL; 295 if(!pkey) return NULL;
425 key = EVP_PKEY_get1_RSA(pkey); 296 key = EVP_PKEY_get1_RSA(pkey);
426 EVP_PKEY_free(pkey); 297 EVP_PKEY_free(pkey);
427 if (!key) return NULL; 298 if(!key) return NULL;
428 *pp = q; 299 *pp = q;
429 if (a) 300 if(a) {
430 {
431 RSA_free(*a); 301 RSA_free(*a);
432 *a = key; 302 *a = key;
433 }
434 return key;
435 } 303 }
304 return key;
305}
436 306
437int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp) 307int i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
438 { 308{
439 EVP_PKEY *pktmp; 309 EVP_PKEY *pktmp;
440 int ret; 310 int ret;
441 if (!a) return 0; 311 if(!a) return 0;
442 pktmp = EVP_PKEY_new(); 312 pktmp = EVP_PKEY_new();
443 if (!pktmp) 313 if(!pktmp) {
444 {
445 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE); 314 ASN1err(ASN1_F_I2D_RSA_PUBKEY, ERR_R_MALLOC_FAILURE);
446 return 0; 315 return 0;
447 } 316 }
448 EVP_PKEY_set1_RSA(pktmp, a); 317 EVP_PKEY_set1_RSA(pktmp, a);
449 ret = i2d_PUBKEY(pktmp, pp); 318 ret = i2d_PUBKEY(pktmp, pp);
450 EVP_PKEY_free(pktmp); 319 EVP_PKEY_free(pktmp);
451 return ret; 320 return ret;
452 } 321}
453#endif 322#endif
454 323
455#ifndef OPENSSL_NO_DSA 324#ifndef OPENSSL_NO_DSA
456DSA *d2i_DSA_PUBKEY(DSA **a, const unsigned char **pp, 325DSA *d2i_DSA_PUBKEY(DSA **a, unsigned char **pp,
457 long length) 326 long length)
458 { 327{
459 EVP_PKEY *pkey; 328 EVP_PKEY *pkey;
460 DSA *key; 329 DSA *key;
461 const unsigned char *q; 330 unsigned char *q;
462 q = *pp; 331 q = *pp;
463 pkey = d2i_PUBKEY(NULL, &q, length); 332 pkey = d2i_PUBKEY(NULL, &q, length);
464 if (!pkey) return NULL; 333 if(!pkey) return NULL;
465 key = EVP_PKEY_get1_DSA(pkey); 334 key = EVP_PKEY_get1_DSA(pkey);
466 EVP_PKEY_free(pkey); 335 EVP_PKEY_free(pkey);
467 if (!key) return NULL; 336 if(!key) return NULL;
468 *pp = q; 337 *pp = q;
469 if (a) 338 if(a) {
470 {
471 DSA_free(*a); 339 DSA_free(*a);
472 *a = key; 340 *a = key;
473 }
474 return key;
475 } 341 }
342 return key;
343}
476 344
477int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp) 345int i2d_DSA_PUBKEY(DSA *a, unsigned char **pp)
478 { 346{
479 EVP_PKEY *pktmp; 347 EVP_PKEY *pktmp;
480 int ret; 348 int ret;
481 if(!a) return 0; 349 if(!a) return 0;
482 pktmp = EVP_PKEY_new(); 350 pktmp = EVP_PKEY_new();
483 if(!pktmp) 351 if(!pktmp) {
484 {
485 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE); 352 ASN1err(ASN1_F_I2D_DSA_PUBKEY, ERR_R_MALLOC_FAILURE);
486 return 0; 353 return 0;
487 } 354 }
488 EVP_PKEY_set1_DSA(pktmp, a); 355 EVP_PKEY_set1_DSA(pktmp, a);
489 ret = i2d_PUBKEY(pktmp, pp); 356 ret = i2d_PUBKEY(pktmp, pp);
490 EVP_PKEY_free(pktmp); 357 EVP_PKEY_free(pktmp);
491 return ret; 358 return ret;
492 } 359}
493#endif
494
495#ifndef OPENSSL_NO_EC
496EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length)
497 {
498 EVP_PKEY *pkey;
499 EC_KEY *key;
500 const unsigned char *q;
501 q = *pp;
502 pkey = d2i_PUBKEY(NULL, &q, length);
503 if (!pkey) return(NULL);
504 key = EVP_PKEY_get1_EC_KEY(pkey);
505 EVP_PKEY_free(pkey);
506 if (!key) return(NULL);
507 *pp = q;
508 if (a)
509 {
510 EC_KEY_free(*a);
511 *a = key;
512 }
513 return(key);
514 }
515
516int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
517 {
518 EVP_PKEY *pktmp;
519 int ret;
520 if (!a) return(0);
521 if ((pktmp = EVP_PKEY_new()) == NULL)
522 {
523 ASN1err(ASN1_F_I2D_EC_PUBKEY, ERR_R_MALLOC_FAILURE);
524 return(0);
525 }
526 EVP_PKEY_set1_EC_KEY(pktmp, a);
527 ret = i2d_PUBKEY(pktmp, pp);
528 EVP_PKEY_free(pktmp);
529 return(ret);
530 }
531#endif 360#endif
diff --git a/src/lib/libcrypto/asn1/x_req.c b/src/lib/libcrypto/asn1/x_req.c
index 59ca8ce329..b3f18ebc12 100644
--- a/src/lib/libcrypto/asn1/x_req.c
+++ b/src/lib/libcrypto/asn1/x_req.c
@@ -102,7 +102,7 @@ ASN1_SEQUENCE_enc(X509_REQ_INFO, enc, rinf_cb) = {
102 102
103IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO) 103IMPLEMENT_ASN1_FUNCTIONS(X509_REQ_INFO)
104 104
105ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_REQ) = { 105ASN1_SEQUENCE_ref(X509_REQ, 0, CRYPTO_LOCK_X509_INFO) = {
106 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO), 106 ASN1_SIMPLE(X509_REQ, req_info, X509_REQ_INFO),
107 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR), 107 ASN1_SIMPLE(X509_REQ, sig_alg, X509_ALGOR),
108 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING) 108 ASN1_SIMPLE(X509_REQ, signature, ASN1_BIT_STRING)
diff --git a/src/lib/libcrypto/asn1/x_x509.c b/src/lib/libcrypto/asn1/x_x509.c
index e118696625..b50167ce43 100644
--- a/src/lib/libcrypto/asn1/x_x509.c
+++ b/src/lib/libcrypto/asn1/x_x509.c
@@ -79,8 +79,6 @@ ASN1_SEQUENCE(X509_CINF) = {
79IMPLEMENT_ASN1_FUNCTIONS(X509_CINF) 79IMPLEMENT_ASN1_FUNCTIONS(X509_CINF)
80/* X509 top level structure needs a bit of customisation */ 80/* X509 top level structure needs a bit of customisation */
81 81
82extern void policy_cache_free(X509_POLICY_CACHE *cache);
83
84static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it) 82static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
85{ 83{
86 X509 *ret = (X509 *)*pval; 84 X509 *ret = (X509 *)*pval;
@@ -94,10 +92,6 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
94 ret->ex_pathlen = -1; 92 ret->ex_pathlen = -1;
95 ret->skid = NULL; 93 ret->skid = NULL;
96 ret->akid = NULL; 94 ret->akid = NULL;
97#ifndef OPENSSL_NO_RFC3779
98 ret->rfc3779_addr = NULL;
99 ret->rfc3779_asid = NULL;
100#endif
101 ret->aux = NULL; 95 ret->aux = NULL;
102 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data); 96 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509, ret, &ret->ex_data);
103 break; 97 break;
@@ -112,11 +106,6 @@ static int x509_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it)
112 X509_CERT_AUX_free(ret->aux); 106 X509_CERT_AUX_free(ret->aux);
113 ASN1_OCTET_STRING_free(ret->skid); 107 ASN1_OCTET_STRING_free(ret->skid);
114 AUTHORITY_KEYID_free(ret->akid); 108 AUTHORITY_KEYID_free(ret->akid);
115 policy_cache_free(ret->policy_cache);
116#ifndef OPENSSL_NO_RFC3779
117 sk_IPAddressFamily_pop_free(ret->rfc3779_addr, IPAddressFamily_free);
118 ASIdentifiers_free(ret->rfc3779_asid);
119#endif
120 109
121 if (ret->name != NULL) OPENSSL_free(ret->name); 110 if (ret->name != NULL) OPENSSL_free(ret->name);
122 break; 111 break;
@@ -136,13 +125,11 @@ ASN1_SEQUENCE_ref(X509, x509_cb, CRYPTO_LOCK_X509) = {
136IMPLEMENT_ASN1_FUNCTIONS(X509) 125IMPLEMENT_ASN1_FUNCTIONS(X509)
137IMPLEMENT_ASN1_DUP_FUNCTION(X509) 126IMPLEMENT_ASN1_DUP_FUNCTION(X509)
138 127
139static ASN1_METHOD meth= 128static ASN1_METHOD meth={
140 { 129 (int (*)()) i2d_X509,
141 (I2D_OF(void)) i2d_X509, 130 (char *(*)())d2i_X509,
142 (D2I_OF(void)) d2i_X509, 131 (char *(*)())X509_new,
143 (void *(*)(void))X509_new, 132 (void (*)()) X509_free};
144 (void (*)(void *)) X509_free
145 };
146 133
147ASN1_METHOD *X509_asn1_meth(void) 134ASN1_METHOD *X509_asn1_meth(void)
148 { 135 {
@@ -174,9 +161,9 @@ void *X509_get_ex_data(X509 *r, int idx)
174 * 161 *
175 */ 162 */
176 163
177X509 *d2i_X509_AUX(X509 **a, const unsigned char **pp, long length) 164X509 *d2i_X509_AUX(X509 **a, unsigned char **pp, long length)
178{ 165{
179 const unsigned char *q; 166 unsigned char *q;
180 X509 *ret; 167 X509 *ret;
181 /* Save start position */ 168 /* Save start position */
182 q = *pp; 169 q = *pp;
diff --git a/src/lib/libcrypto/asn1/x_x509a.c b/src/lib/libcrypto/asn1/x_x509a.c
index 13db5fd03f..f244768b7e 100644
--- a/src/lib/libcrypto/asn1/x_x509a.c
+++ b/src/lib/libcrypto/asn1/x_x509a.c
@@ -91,14 +91,6 @@ static X509_CERT_AUX *aux_get(X509 *x)
91int X509_alias_set1(X509 *x, unsigned char *name, int len) 91int X509_alias_set1(X509 *x, unsigned char *name, int len)
92{ 92{
93 X509_CERT_AUX *aux; 93 X509_CERT_AUX *aux;
94 if (!name)
95 {
96 if (!x || !x->aux || !x->aux->alias)
97 return 1;
98 ASN1_UTF8STRING_free(x->aux->alias);
99 x->aux->alias = NULL;
100 return 1;
101 }
102 if(!(aux = aux_get(x))) return 0; 94 if(!(aux = aux_get(x))) return 0;
103 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0; 95 if(!aux->alias && !(aux->alias = ASN1_UTF8STRING_new())) return 0;
104 return ASN1_STRING_set(aux->alias, name, len); 96 return ASN1_STRING_set(aux->alias, name, len);
@@ -107,14 +99,6 @@ int X509_alias_set1(X509 *x, unsigned char *name, int len)
107int X509_keyid_set1(X509 *x, unsigned char *id, int len) 99int X509_keyid_set1(X509 *x, unsigned char *id, int len)
108{ 100{
109 X509_CERT_AUX *aux; 101 X509_CERT_AUX *aux;
110 if (!id)
111 {
112 if (!x || !x->aux || !x->aux->keyid)
113 return 1;
114 ASN1_OCTET_STRING_free(x->aux->keyid);
115 x->aux->keyid = NULL;
116 return 1;
117 }
118 if(!(aux = aux_get(x))) return 0; 102 if(!(aux = aux_get(x))) return 0;
119 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0; 103 if(!aux->keyid && !(aux->keyid = ASN1_OCTET_STRING_new())) return 0;
120 return ASN1_STRING_set(aux->keyid, id, len); 104 return ASN1_STRING_set(aux->keyid, id, len);
@@ -127,13 +111,6 @@ unsigned char *X509_alias_get0(X509 *x, int *len)
127 return x->aux->alias->data; 111 return x->aux->alias->data;
128} 112}
129 113
130unsigned char *X509_keyid_get0(X509 *x, int *len)
131{
132 if(!x->aux || !x->aux->keyid) return NULL;
133 if(len) *len = x->aux->keyid->length;
134 return x->aux->keyid->data;
135}
136
137int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj) 114int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj)
138{ 115{
139 X509_CERT_AUX *aux; 116 X509_CERT_AUX *aux;
@@ -172,9 +149,3 @@ void X509_reject_clear(X509 *x)
172 } 149 }
173} 150}
174 151
175ASN1_SEQUENCE(X509_CERT_PAIR) = {
176 ASN1_EXP_OPT(X509_CERT_PAIR, forward, X509, 0),
177 ASN1_EXP_OPT(X509_CERT_PAIR, reverse, X509, 1)
178} ASN1_SEQUENCE_END(X509_CERT_PAIR)
179
180IMPLEMENT_ASN1_FUNCTIONS(X509_CERT_PAIR)
diff --git a/src/lib/libcrypto/bf/Makefile b/src/lib/libcrypto/bf/Makefile
new file mode 100644
index 0000000000..8441954a8d
--- /dev/null
+++ b/src/lib/libcrypto/bf/Makefile
@@ -0,0 +1,107 @@
1#
2# OpenSSL/crypto/blowfish/Makefile
3#
4
5DIR= bf
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14BF_ENC= bf_enc.o
15# or use
16#DES_ENC= bx86-elf.o
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG)
20AFLAGS= $(ASFLAGS)
21
22GENERAL=Makefile
23TEST=bftest.c
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c
28LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= blowfish.h
33HEADER= bf_pi.h bf_locl.h $(EXHEADER)
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47# ELF
48bx86-elf.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
49 (cd asm; $(PERL) bf-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
50# COFF
51bx86-cof.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
52 (cd asm; $(PERL) bf-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
53# a.out
54bx86-out.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
55 (cd asm; $(PERL) bf-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
56
57files:
58 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
59
60links:
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65# We need to use force because 'install' matches 'INSTALL' on case
66# insensitive systems
67FRC.install:
68install: FRC.install
69 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
70 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
71 do \
72 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
73 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
74 done;
75
76tags:
77 ctags $(SRC)
78
79tests:
80
81lint:
82 lint -DLINT $(INCLUDES) $(SRC)>fluff
83
84depend:
85 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
86 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
87
88dclean:
89 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
90 mv -f Makefile.new $(MAKEFILE)
91
92clean:
93 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
94
95# DO NOT DELETE THIS LINE -- make depend depends on it.
96
97bf_cfb64.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
98bf_cfb64.o: ../../include/openssl/opensslconf.h bf_cfb64.c bf_locl.h
99bf_ecb.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
100bf_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101bf_ecb.o: bf_ecb.c bf_locl.h
102bf_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
103bf_enc.o: ../../include/openssl/opensslconf.h bf_enc.c bf_locl.h
104bf_ofb64.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
105bf_ofb64.o: ../../include/openssl/opensslconf.h bf_locl.h bf_ofb64.c
106bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
107bf_skey.o: ../../include/openssl/opensslconf.h bf_locl.h bf_pi.h bf_skey.c
diff --git a/src/lib/libcrypto/bf/Makefile.ssl b/src/lib/libcrypto/bf/Makefile.ssl
new file mode 100644
index 0000000000..be3ad77a05
--- /dev/null
+++ b/src/lib/libcrypto/bf/Makefile.ssl
@@ -0,0 +1,115 @@
1#
2# SSLeay/crypto/blowfish/Makefile
3#
4
5DIR= bf
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20BF_ENC= bf_enc.o
21# or use
22#DES_ENC= bx86-elf.o
23
24CFLAGS= $(INCLUDES) $(CFLAG)
25ASFLAGS= $(INCLUDES) $(ASFLAG)
26
27GENERAL=Makefile
28TEST=bftest.c
29APPS=
30
31LIB=$(TOP)/libcrypto.a
32LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c
33LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o
34
35SRC= $(LIBSRC)
36
37EXHEADER= blowfish.h
38HEADER= bf_pi.h bf_locl.h $(EXHEADER)
39
40ALL= $(GENERAL) $(SRC) $(HEADER)
41
42top:
43 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
44
45all: lib
46
47lib: $(LIBOBJ)
48 $(AR) $(LIB) $(LIBOBJ)
49 $(RANLIB) $(LIB) || echo Never mind.
50 @touch lib
51
52# elf
53asm/bx86-elf.s: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
54 (cd asm; $(PERL) bf-586.pl elf $(CFLAGS) $(PROCESSOR) > bx86-elf.s)
55
56# a.out
57asm/bx86-out.o: asm/bx86unix.cpp
58 $(CPP) -DOUT asm/bx86unix.cpp | as -o asm/bx86-out.o
59
60# bsdi
61asm/bx86bsdi.o: asm/bx86unix.cpp
62 $(CPP) -DBSDI asm/bx86unix.cpp | sed 's/ :/:/' | as -o asm/bx86bsdi.o
63
64asm/bx86unix.cpp: asm/bf-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
65 (cd asm; $(PERL) bf-586.pl cpp $(PROCESSOR) >bx86unix.cpp)
66
67files:
68 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69
70links:
71 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
72 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
73 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
74 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75
76install: installs
77
78installs:
79 @for i in $(EXHEADER) ; \
80 do \
81 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
82 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
83 done;
84
85tags:
86 ctags $(SRC)
87
88tests:
89
90lint:
91 lint -DLINT $(INCLUDES) $(SRC)>fluff
92
93depend:
94 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
95
96dclean:
97 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
98 mv -f Makefile.new $(MAKEFILE)
99
100clean:
101 rm -f asm/bx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
102
103# DO NOT DELETE THIS LINE -- make depend depends on it.
104
105bf_cfb64.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
106bf_cfb64.o: ../../include/openssl/opensslconf.h bf_cfb64.c bf_locl.h
107bf_ecb.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
108bf_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
109bf_ecb.o: bf_ecb.c bf_locl.h
110bf_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
111bf_enc.o: ../../include/openssl/opensslconf.h bf_enc.c bf_locl.h
112bf_ofb64.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
113bf_ofb64.o: ../../include/openssl/opensslconf.h bf_locl.h bf_ofb64.c
114bf_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/e_os2.h
115bf_skey.o: ../../include/openssl/opensslconf.h bf_locl.h bf_pi.h bf_skey.c
diff --git a/src/lib/libcrypto/bf/asm/bf-586.pl b/src/lib/libcrypto/bf/asm/bf-586.pl
index b556642c94..b5a4760d09 100644
--- a/src/lib/libcrypto/bf/asm/bf-586.pl
+++ b/src/lib/libcrypto/bf/asm/bf-586.pl
@@ -18,7 +18,7 @@ $tmp4="edx";
18 18
19&BF_encrypt("BF_encrypt",1); 19&BF_encrypt("BF_encrypt",1);
20&BF_encrypt("BF_decrypt",0); 20&BF_encrypt("BF_decrypt",0);
21&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1); 21&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1) unless $main'openbsd;
22&asm_finish(); 22&asm_finish();
23 23
24sub BF_encrypt 24sub BF_encrypt
diff --git a/src/lib/libcrypto/bf/asm/bf-686.pl b/src/lib/libcrypto/bf/asm/bf-686.pl
new file mode 100644
index 0000000000..8e4c25f598
--- /dev/null
+++ b/src/lib/libcrypto/bf/asm/bf-686.pl
@@ -0,0 +1,127 @@
1#!/usr/local/bin/perl
2
3push(@INC,"perlasm","../../perlasm");
4require "x86asm.pl";
5require "cbc.pl";
6
7&asm_init($ARGV[0],"bf-686.pl");
8
9$BF_ROUNDS=16;
10$BF_OFF=($BF_ROUNDS+2)*4;
11$L="ecx";
12$R="edx";
13$P="edi";
14$tot="esi";
15$tmp1="eax";
16$tmp2="ebx";
17$tmp3="ebp";
18
19&des_encrypt("BF_encrypt",1);
20&des_encrypt("BF_decrypt",0);
21&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
22
23&asm_finish();
24
25&file_end();
26
27sub des_encrypt
28 {
29 local($name,$enc)=@_;
30
31 &function_begin($name,"");
32
33 &comment("");
34 &comment("Load the 2 words");
35 &mov("eax",&wparam(0));
36 &mov($L,&DWP(0,"eax","",0));
37 &mov($R,&DWP(4,"eax","",0));
38
39 &comment("");
40 &comment("P pointer, s and enc flag");
41 &mov($P,&wparam(1));
42
43 &xor( $tmp1, $tmp1);
44 &xor( $tmp2, $tmp2);
45
46 # encrypting part
47
48 if ($enc)
49 {
50 &xor($L,&DWP(0,$P,"",0));
51 for ($i=0; $i<$BF_ROUNDS; $i+=2)
52 {
53 &comment("");
54 &comment("Round $i");
55 &BF_ENCRYPT($i+1,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
56
57 &comment("");
58 &comment("Round ".sprintf("%d",$i+1));
59 &BF_ENCRYPT($i+2,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
60 }
61 &xor($R,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
62
63 &mov("eax",&wparam(0));
64 &mov(&DWP(0,"eax","",0),$R);
65 &mov(&DWP(4,"eax","",0),$L);
66 &function_end_A($name);
67 }
68 else
69 {
70 &xor($L,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
71 for ($i=$BF_ROUNDS; $i>0; $i-=2)
72 {
73 &comment("");
74 &comment("Round $i");
75 &BF_ENCRYPT($i,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
76 &comment("");
77 &comment("Round ".sprintf("%d",$i-1));
78 &BF_ENCRYPT($i-1,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
79 }
80 &xor($R,&DWP(0,$P,"",0));
81
82 &mov("eax",&wparam(0));
83 &mov(&DWP(0,"eax","",0),$R);
84 &mov(&DWP(4,"eax","",0),$L);
85 &function_end_A($name);
86 }
87
88 &function_end_B($name);
89 }
90
91sub BF_ENCRYPT
92 {
93 local($i,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3)=@_;
94
95 &rotr( $R, 16);
96 &mov( $tot, &DWP(&n2a($i*4),$P,"",0));
97
98 &movb( &LB($tmp1), &HB($R));
99 &movb( &LB($tmp2), &LB($R));
100
101 &rotr( $R, 16);
102 &xor( $L, $tot);
103
104 &mov( $tot, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
105 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
106
107 &movb( &LB($tmp1), &HB($R));
108 &movb( &LB($tmp2), &LB($R));
109
110 &add( $tot, $tmp3);
111 &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp1,4)); # delay
112
113 &xor( $tot, $tmp1);
114 &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp2,4));
115
116 &add( $tot, $tmp3);
117 &xor( $tmp1, $tmp1);
118
119 &xor( $L, $tot);
120 # delay
121 }
122
123sub n2a
124 {
125 sprintf("%d",$_[0]);
126 }
127
diff --git a/src/lib/libcrypto/bf/asm/readme b/src/lib/libcrypto/bf/asm/readme
new file mode 100644
index 0000000000..2385fa3812
--- /dev/null
+++ b/src/lib/libcrypto/bf/asm/readme
@@ -0,0 +1,10 @@
1There are blowfish assembler generation scripts.
2bf-586.pl version is for the pentium and
3bf-686.pl is my original version, which is faster on the pentium pro.
4
5When using a bf-586.pl, the pentium pro/II is %8 slower than using
6bf-686.pl. When using a bf-686.pl, the pentium is %16 slower
7than bf-586.pl
8
9So the default is bf-586.pl
10
diff --git a/src/lib/libcrypto/bf/bf_ecb.c b/src/lib/libcrypto/bf/bf_ecb.c
index 1607cefa32..341991636f 100644
--- a/src/lib/libcrypto/bf/bf_ecb.c
+++ b/src/lib/libcrypto/bf/bf_ecb.c
@@ -65,7 +65,7 @@
65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993) 65 * CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
66 */ 66 */
67 67
68const char BF_version[]="Blowfish" OPENSSL_VERSION_PTEXT; 68const char *BF_version="Blowfish" OPENSSL_VERSION_PTEXT;
69 69
70const char *BF_options(void) 70const char *BF_options(void)
71 { 71 {
diff --git a/src/lib/libcrypto/bf/bf_enc.c b/src/lib/libcrypto/bf/bf_enc.c
index 2d21d09f42..b380acf959 100644
--- a/src/lib/libcrypto/bf/bf_enc.c
+++ b/src/lib/libcrypto/bf/bf_enc.c
@@ -73,7 +73,7 @@ void BF_encrypt(BF_LONG *data, const BF_KEY *key)
73 { 73 {
74#ifndef BF_PTR2 74#ifndef BF_PTR2
75 register BF_LONG l,r; 75 register BF_LONG l,r;
76 register const BF_LONG *p,*s; 76 const register BF_LONG *p,*s;
77 77
78 p=key->P; 78 p=key->P;
79 s= &(key->S[0]); 79 s= &(key->S[0]);
@@ -150,7 +150,7 @@ void BF_decrypt(BF_LONG *data, const BF_KEY *key)
150 { 150 {
151#ifndef BF_PTR2 151#ifndef BF_PTR2
152 register BF_LONG l,r; 152 register BF_LONG l,r;
153 register const BF_LONG *p,*s; 153 const register BF_LONG *p,*s;
154 154
155 p=key->P; 155 p=key->P;
156 s= &(key->S[0]); 156 s= &(key->S[0]);
diff --git a/src/lib/libcrypto/bf/bf_opts.c b/src/lib/libcrypto/bf/bf_opts.c
new file mode 100644
index 0000000000..171dada2ca
--- /dev/null
+++ b/src/lib/libcrypto/bf/bf_opts.c
@@ -0,0 +1,328 @@
1/* crypto/bf/bf_opts.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* define 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. */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/blowfish.h>
100
101#define BF_DEFAULT_OPTIONS
102
103#undef BF_ENC
104#define BF_encrypt BF_encrypt_normal
105#undef HEADER_BF_LOCL_H
106#include "bf_enc.c"
107
108#define BF_PTR
109#undef BF_PTR2
110#undef BF_ENC
111#undef BF_encrypt
112#define BF_encrypt BF_encrypt_ptr
113#undef HEADER_BF_LOCL_H
114#include "bf_enc.c"
115
116#undef BF_PTR
117#define BF_PTR2
118#undef BF_ENC
119#undef BF_encrypt
120#define BF_encrypt BF_encrypt_ptr2
121#undef HEADER_BF_LOCL_H
122#include "bf_enc.c"
123
124/* The following if from times(3) man page. It may need to be changed */
125#ifndef HZ
126# ifndef CLK_TCK
127# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
128# define HZ 100.0
129# else /* _BSD_CLK_TCK_ */
130# define HZ ((double)_BSD_CLK_TCK_)
131# endif
132# else /* CLK_TCK */
133# define HZ ((double)CLK_TCK)
134# endif
135#endif
136
137#define BUFSIZE ((long)1024)
138long run=0;
139
140double Time_F(int s);
141#ifdef SIGALRM
142#if defined(__STDC__) || defined(sgi)
143#define SIGRETTYPE void
144#else
145#define SIGRETTYPE int
146#endif
147
148SIGRETTYPE sig_done(int sig);
149SIGRETTYPE sig_done(int sig)
150 {
151 signal(SIGALRM,sig_done);
152 run=0;
153#ifdef LINT
154 sig=sig;
155#endif
156 }
157#endif
158
159#define START 0
160#define STOP 1
161
162double Time_F(int s)
163 {
164 double ret;
165#ifdef TIMES
166 static struct tms tstart,tend;
167
168 if (s == START)
169 {
170 times(&tstart);
171 return(0);
172 }
173 else
174 {
175 times(&tend);
176 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
177 return((ret == 0.0)?1e-6:ret);
178 }
179#else /* !times() */
180 static struct timeb tstart,tend;
181 long i;
182
183 if (s == START)
184 {
185 ftime(&tstart);
186 return(0);
187 }
188 else
189 {
190 ftime(&tend);
191 i=(long)tend.millitm-(long)tstart.millitm;
192 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
193 return((ret == 0.0)?1e-6:ret);
194 }
195#endif
196 }
197
198#ifdef SIGALRM
199#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
200#else
201#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
202#endif
203
204#define time_it(func,name,index) \
205 print_name(name); \
206 Time_F(START); \
207 for (count=0,run=1; COND(cb); count+=4) \
208 { \
209 unsigned long d[2]; \
210 func(d,&sch); \
211 func(d,&sch); \
212 func(d,&sch); \
213 func(d,&sch); \
214 } \
215 tm[index]=Time_F(STOP); \
216 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
217 tm[index]=((double)COUNT(cb))/tm[index];
218
219#define print_it(name,index) \
220 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
221 tm[index]*8,1.0e6/tm[index]);
222
223int main(int argc, char **argv)
224 {
225 long count;
226 static unsigned char buf[BUFSIZE];
227 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
228 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
229 BF_KEY sch;
230 double d,tm[16],max=0;
231 int rank[16];
232 char *str[16];
233 int max_idx=0,i,num=0,j;
234#ifndef SIGALARM
235 long ca,cb,cc,cd,ce;
236#endif
237
238 for (i=0; i<12; i++)
239 {
240 tm[i]=0.0;
241 rank[i]=0;
242 }
243
244#ifndef TIMES
245 fprintf(stderr,"To get the most accurate results, try to run this\n");
246 fprintf(stderr,"program when this computer is idle.\n");
247#endif
248
249 BF_set_key(&sch,16,key);
250
251#ifndef SIGALRM
252 fprintf(stderr,"First we calculate the approximate speed ...\n");
253 count=10;
254 do {
255 long i;
256 unsigned long data[2];
257
258 count*=2;
259 Time_F(START);
260 for (i=count; i; i--)
261 BF_encrypt(data,&sch);
262 d=Time_F(STOP);
263 } while (d < 3.0);
264 ca=count;
265 cb=count*3;
266 cc=count*3*8/BUFSIZE+1;
267 cd=count*8/BUFSIZE+1;
268
269 ce=count/20+1;
270#define COND(d) (count != (d))
271#define COUNT(d) (d)
272#else
273#define COND(c) (run)
274#define COUNT(d) (count)
275 signal(SIGALRM,sig_done);
276 alarm(10);
277#endif
278
279 time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0);
280 time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1);
281 time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2);
282 num+=3;
283
284 str[0]="<nothing>";
285 print_it("BF_encrypt_normal ",0);
286 max=tm[0];
287 max_idx=0;
288 str[1]="ptr ";
289 print_it("BF_encrypt_ptr ",1);
290 if (max < tm[1]) { max=tm[1]; max_idx=1; }
291 str[2]="ptr2 ";
292 print_it("BF_encrypt_ptr2 ",2);
293 if (max < tm[2]) { max=tm[2]; max_idx=2; }
294
295 printf("options BF ecb/s\n");
296 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
297 d=tm[max_idx];
298 tm[max_idx]= -2.0;
299 max= -1.0;
300 for (;;)
301 {
302 for (i=0; i<3; i++)
303 {
304 if (max < tm[i]) { max=tm[i]; j=i; }
305 }
306 if (max < 0.0) break;
307 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
308 tm[j]= -2.0;
309 max= -1.0;
310 }
311
312 switch (max_idx)
313 {
314 case 0:
315 printf("-DBF_DEFAULT_OPTIONS\n");
316 break;
317 case 1:
318 printf("-DBF_PTR\n");
319 break;
320 case 2:
321 printf("-DBF_PTR2\n");
322 break;
323 }
324 exit(0);
325#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
326 return(0);
327#endif
328 }
diff --git a/src/lib/libcrypto/bf/bf_skey.c b/src/lib/libcrypto/bf/bf_skey.c
index 3673cdee6e..1931aba83f 100644
--- a/src/lib/libcrypto/bf/bf_skey.c
+++ b/src/lib/libcrypto/bf/bf_skey.c
@@ -58,11 +58,13 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <string.h> 60#include <string.h>
61#include <openssl/crypto.h>
61#include <openssl/blowfish.h> 62#include <openssl/blowfish.h>
63#include <openssl/fips.h>
62#include "bf_locl.h" 64#include "bf_locl.h"
63#include "bf_pi.h" 65#include "bf_pi.h"
64 66
65void BF_set_key(BF_KEY *key, int len, const unsigned char *data) 67FIPS_NON_FIPS_VCIPHER_Init(BF)
66 { 68 {
67 int i; 69 int i;
68 BF_LONG *p,ri,in[2]; 70 BF_LONG *p,ri,in[2];
diff --git a/src/lib/libcrypto/bf/bfs.cpp b/src/lib/libcrypto/bf/bfs.cpp
new file mode 100644
index 0000000000..d74c457760
--- /dev/null
+++ b/src/lib/libcrypto/bf/bfs.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/blowfish.h>
36
37void main(int argc,char *argv[])
38 {
39 BF_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 BF_encrypt(&data[0],&key);
49 GetTSC(s1);
50 BF_encrypt(&data[0],&key);
51 BF_encrypt(&data[0],&key);
52 BF_encrypt(&data[0],&key);
53 GetTSC(e1);
54 GetTSC(s2);
55 BF_encrypt(&data[0],&key);
56 BF_encrypt(&data[0],&key);
57 BF_encrypt(&data[0],&key);
58 BF_encrypt(&data[0],&key);
59 GetTSC(e2);
60 BF_encrypt(&data[0],&key);
61 }
62
63 printf("blowfish %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/bf/bfspeed.c b/src/lib/libcrypto/bf/bfspeed.c
new file mode 100644
index 0000000000..f346af64f3
--- /dev/null
+++ b/src/lib/libcrypto/bf/bfspeed.c
@@ -0,0 +1,274 @@
1/* crypto/bf/bfspeed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
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 */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/blowfish.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103#ifndef CLK_TCK
104#define HZ 100.0
105#else /* CLK_TCK */
106#define HZ ((double)CLK_TCK)
107#endif
108#endif
109
110#define BUFSIZE ((long)1024)
111long run=0;
112
113double Time_F(int s);
114#ifdef SIGALRM
115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
116#define SIGRETTYPE void
117#else
118#define SIGRETTYPE int
119#endif
120
121SIGRETTYPE sig_done(int sig);
122SIGRETTYPE sig_done(int sig)
123 {
124 signal(SIGALRM,sig_done);
125 run=0;
126#ifdef LINT
127 sig=sig;
128#endif
129 }
130#endif
131
132#define START 0
133#define STOP 1
134
135double Time_F(int s)
136 {
137 double ret;
138#ifdef TIMES
139 static struct tms tstart,tend;
140
141 if (s == START)
142 {
143 times(&tstart);
144 return(0);
145 }
146 else
147 {
148 times(&tend);
149 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
150 return((ret == 0.0)?1e-6:ret);
151 }
152#else /* !times() */
153 static struct timeb tstart,tend;
154 long i;
155
156 if (s == START)
157 {
158 ftime(&tstart);
159 return(0);
160 }
161 else
162 {
163 ftime(&tend);
164 i=(long)tend.millitm-(long)tstart.millitm;
165 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
166 return((ret == 0.0)?1e-6:ret);
167 }
168#endif
169 }
170
171int main(int argc, char **argv)
172 {
173 long count;
174 static unsigned char buf[BUFSIZE];
175 static unsigned char key[] ={
176 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
177 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
178 };
179 BF_KEY sch;
180 double a,b,c,d;
181#ifndef SIGALRM
182 long ca,cb,cc;
183#endif
184
185#ifndef TIMES
186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n");
188#endif
189
190#ifndef SIGALRM
191 printf("First we calculate the approximate speed ...\n");
192 BF_set_key(&sch,16,key);
193 count=10;
194 do {
195 long i;
196 BF_LONG data[2];
197
198 count*=2;
199 Time_F(START);
200 for (i=count; i; i--)
201 BF_encrypt(data,&sch);
202 d=Time_F(STOP);
203 } while (d < 3.0);
204 ca=count/512;
205 cb=count;
206 cc=count*8/BUFSIZE+1;
207 printf("Doing BF_set_key %ld times\n",ca);
208#define COND(d) (count != (d))
209#define COUNT(d) (d)
210#else
211#define COND(c) (run)
212#define COUNT(d) (count)
213 signal(SIGALRM,sig_done);
214 printf("Doing BF_set_key for 10 seconds\n");
215 alarm(10);
216#endif
217
218 Time_F(START);
219 for (count=0,run=1; COND(ca); count+=4)
220 {
221 BF_set_key(&sch,16,key);
222 BF_set_key(&sch,16,key);
223 BF_set_key(&sch,16,key);
224 BF_set_key(&sch,16,key);
225 }
226 d=Time_F(STOP);
227 printf("%ld BF_set_key's in %.2f seconds\n",count,d);
228 a=((double)COUNT(ca))/d;
229
230#ifdef SIGALRM
231 printf("Doing BF_encrypt's for 10 seconds\n");
232 alarm(10);
233#else
234 printf("Doing BF_encrypt %ld times\n",cb);
235#endif
236 Time_F(START);
237 for (count=0,run=1; COND(cb); count+=4)
238 {
239 BF_LONG data[2];
240
241 BF_encrypt(data,&sch);
242 BF_encrypt(data,&sch);
243 BF_encrypt(data,&sch);
244 BF_encrypt(data,&sch);
245 }
246 d=Time_F(STOP);
247 printf("%ld BF_encrypt's in %.2f second\n",count,d);
248 b=((double)COUNT(cb)*8)/d;
249
250#ifdef SIGALRM
251 printf("Doing BF_cbc_encrypt on %ld byte blocks for 10 seconds\n",
252 BUFSIZE);
253 alarm(10);
254#else
255 printf("Doing BF_cbc_encrypt %ld times on %ld byte blocks\n",cc,
256 BUFSIZE);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cc); count++)
260 BF_cbc_encrypt(buf,buf,BUFSIZE,&sch,
261 &(key[0]),BF_ENCRYPT);
262 d=Time_F(STOP);
263 printf("%ld BF_cbc_encrypt's of %ld byte blocks in %.2f second\n",
264 count,BUFSIZE,d);
265 c=((double)COUNT(cc)*BUFSIZE)/d;
266
267 printf("Blowfish set_key per sec = %12.3f (%9.3fuS)\n",a,1.0e6/a);
268 printf("Blowfish raw ecb bytes per sec = %12.3f (%9.3fuS)\n",b,8.0e6/b);
269 printf("Blowfish cbc bytes per sec = %12.3f (%9.3fuS)\n",c,8.0e6/c);
270 exit(0);
271#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
272 return(0);
273#endif
274 }
diff --git a/src/lib/libcrypto/bf/bftest.c b/src/lib/libcrypto/bf/bftest.c
new file mode 100644
index 0000000000..24d526b14b
--- /dev/null
+++ b/src/lib/libcrypto/bf/bftest.c
@@ -0,0 +1,536 @@
1/* crypto/bf/bftest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. 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 has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65
66#include "../e_os.h"
67
68#ifdef OPENSSL_NO_BF
69int main(int argc, char *argv[])
70{
71 printf("No BF support\n");
72 return(0);
73}
74#else
75#include <openssl/blowfish.h>
76
77#ifdef CHARSET_EBCDIC
78#include <openssl/ebcdic.h>
79#endif
80
81static char *bf_key[2]={
82 "abcdefghijklmnopqrstuvwxyz",
83 "Who is John Galt?"
84 };
85
86/* big endian */
87static BF_LONG bf_plain[2][2]={
88 {0x424c4f57L,0x46495348L},
89 {0xfedcba98L,0x76543210L}
90 };
91
92static BF_LONG bf_cipher[2][2]={
93 {0x324ed0feL,0xf413a203L},
94 {0xcc91732bL,0x8022f684L}
95 };
96/************/
97
98/* Lets use the DES test vectors :-) */
99#define NUM_TESTS 34
100static unsigned char ecb_data[NUM_TESTS][8]={
101 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
102 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
103 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
104 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
105 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
106 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
107 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
108 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
109 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
110 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
111 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
112 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
113 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
114 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
115 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
116 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
117 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
118 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
119 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
120 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
121 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
122 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
123 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
124 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
125 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
126 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
127 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
128 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
129 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
130 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
131 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
132 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
133 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
134 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
135
136static unsigned char plain_data[NUM_TESTS][8]={
137 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
138 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
139 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
140 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
141 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
142 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
143 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
144 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
145 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
146 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
147 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
148 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
149 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
150 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
151 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
152 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
153 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
154 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
155 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
156 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
157 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
158 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
159 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
160 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
161 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
162 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
163 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
164 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
165 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
166 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
167 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
168 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
169 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
170 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
171
172static unsigned char cipher_data[NUM_TESTS][8]={
173 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
174 {0x51,0x86,0x6F,0xD5,0xB8,0x5E,0xCB,0x8A},
175 {0x7D,0x85,0x6F,0x9A,0x61,0x30,0x63,0xF2},
176 {0x24,0x66,0xDD,0x87,0x8B,0x96,0x3C,0x9D},
177 {0x61,0xF9,0xC3,0x80,0x22,0x81,0xB0,0x96},
178 {0x7D,0x0C,0xC6,0x30,0xAF,0xDA,0x1E,0xC7},
179 {0x4E,0xF9,0x97,0x45,0x61,0x98,0xDD,0x78},
180 {0x0A,0xCE,0xAB,0x0F,0xC6,0xA0,0xA2,0x8D},
181 {0x59,0xC6,0x82,0x45,0xEB,0x05,0x28,0x2B},
182 {0xB1,0xB8,0xCC,0x0B,0x25,0x0F,0x09,0xA0},
183 {0x17,0x30,0xE5,0x77,0x8B,0xEA,0x1D,0xA4},
184 {0xA2,0x5E,0x78,0x56,0xCF,0x26,0x51,0xEB},
185 {0x35,0x38,0x82,0xB1,0x09,0xCE,0x8F,0x1A},
186 {0x48,0xF4,0xD0,0x88,0x4C,0x37,0x99,0x18},
187 {0x43,0x21,0x93,0xB7,0x89,0x51,0xFC,0x98},
188 {0x13,0xF0,0x41,0x54,0xD6,0x9D,0x1A,0xE5},
189 {0x2E,0xED,0xDA,0x93,0xFF,0xD3,0x9C,0x79},
190 {0xD8,0x87,0xE0,0x39,0x3C,0x2D,0xA6,0xE3},
191 {0x5F,0x99,0xD0,0x4F,0x5B,0x16,0x39,0x69},
192 {0x4A,0x05,0x7A,0x3B,0x24,0xD3,0x97,0x7B},
193 {0x45,0x20,0x31,0xC1,0xE4,0xFA,0xDA,0x8E},
194 {0x75,0x55,0xAE,0x39,0xF5,0x9B,0x87,0xBD},
195 {0x53,0xC5,0x5F,0x9C,0xB4,0x9F,0xC0,0x19},
196 {0x7A,0x8E,0x7B,0xFA,0x93,0x7E,0x89,0xA3},
197 {0xCF,0x9C,0x5D,0x7A,0x49,0x86,0xAD,0xB5},
198 {0xD1,0xAB,0xB2,0x90,0x65,0x8B,0xC7,0x78},
199 {0x55,0xCB,0x37,0x74,0xD1,0x3E,0xF2,0x01},
200 {0xFA,0x34,0xEC,0x48,0x47,0xB2,0x68,0xB2},
201 {0xA7,0x90,0x79,0x51,0x08,0xEA,0x3C,0xAE},
202 {0xC3,0x9E,0x07,0x2D,0x9F,0xAC,0x63,0x1D},
203 {0x01,0x49,0x33,0xE0,0xCD,0xAF,0xF6,0xE4},
204 {0xF2,0x1E,0x9A,0x77,0xB7,0x1C,0x49,0xBC},
205 {0x24,0x59,0x46,0x88,0x57,0x54,0x36,0x9A},
206 {0x6B,0x5C,0x5A,0x9C,0x5D,0x9E,0x0A,0x5A},
207 };
208
209static unsigned char cbc_key [16]={
210 0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,
211 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
212static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
213static char cbc_data[40]="7654321 Now is the time for ";
214static unsigned char cbc_ok[32]={
215 0x6B,0x77,0xB4,0xD6,0x30,0x06,0xDE,0xE6,
216 0x05,0xB1,0x56,0xE2,0x74,0x03,0x97,0x93,
217 0x58,0xDE,0xB9,0xE7,0x15,0x46,0x16,0xD9,
218 0x59,0xF1,0x65,0x2B,0xD5,0xFF,0x92,0xCC};
219
220static unsigned char cfb64_ok[]={
221 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
222 0xF2,0x6E,0xCF,0x6D,0x2E,0xB9,0xE7,0x6E,
223 0x3D,0xA3,0xDE,0x04,0xD1,0x51,0x72,0x00,
224 0x51,0x9D,0x57,0xA6,0xC3};
225
226static unsigned char ofb64_ok[]={
227 0xE7,0x32,0x14,0xA2,0x82,0x21,0x39,0xCA,
228 0x62,0xB3,0x43,0xCC,0x5B,0x65,0x58,0x73,
229 0x10,0xDD,0x90,0x8D,0x0C,0x24,0x1B,0x22,
230 0x63,0xC2,0xCF,0x80,0xDA};
231
232#define KEY_TEST_NUM 25
233static unsigned char key_test[KEY_TEST_NUM]={
234 0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87,
235 0x78,0x69,0x5a,0x4b,0x3c,0x2d,0x1e,0x0f,
236 0x00,0x11,0x22,0x33,0x44,0x55,0x66,0x77,
237 0x88};
238
239static unsigned char key_data[8]=
240 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10};
241
242static unsigned char key_out[KEY_TEST_NUM][8]={
243 {0xF9,0xAD,0x59,0x7C,0x49,0xDB,0x00,0x5E},
244 {0xE9,0x1D,0x21,0xC1,0xD9,0x61,0xA6,0xD6},
245 {0xE9,0xC2,0xB7,0x0A,0x1B,0xC6,0x5C,0xF3},
246 {0xBE,0x1E,0x63,0x94,0x08,0x64,0x0F,0x05},
247 {0xB3,0x9E,0x44,0x48,0x1B,0xDB,0x1E,0x6E},
248 {0x94,0x57,0xAA,0x83,0xB1,0x92,0x8C,0x0D},
249 {0x8B,0xB7,0x70,0x32,0xF9,0x60,0x62,0x9D},
250 {0xE8,0x7A,0x24,0x4E,0x2C,0xC8,0x5E,0x82},
251 {0x15,0x75,0x0E,0x7A,0x4F,0x4E,0xC5,0x77},
252 {0x12,0x2B,0xA7,0x0B,0x3A,0xB6,0x4A,0xE0},
253 {0x3A,0x83,0x3C,0x9A,0xFF,0xC5,0x37,0xF6},
254 {0x94,0x09,0xDA,0x87,0xA9,0x0F,0x6B,0xF2},
255 {0x88,0x4F,0x80,0x62,0x50,0x60,0xB8,0xB4},
256 {0x1F,0x85,0x03,0x1C,0x19,0xE1,0x19,0x68},
257 {0x79,0xD9,0x37,0x3A,0x71,0x4C,0xA3,0x4F},
258 {0x93,0x14,0x28,0x87,0xEE,0x3B,0xE1,0x5C},
259 {0x03,0x42,0x9E,0x83,0x8C,0xE2,0xD1,0x4B},
260 {0xA4,0x29,0x9E,0x27,0x46,0x9F,0xF6,0x7B},
261 {0xAF,0xD5,0xAE,0xD1,0xC1,0xBC,0x96,0xA8},
262 {0x10,0x85,0x1C,0x0E,0x38,0x58,0xDA,0x9F},
263 {0xE6,0xF5,0x1E,0xD7,0x9B,0x9D,0xB2,0x1F},
264 {0x64,0xA6,0xE1,0x4A,0xFD,0x36,0xB4,0x6F},
265 {0x80,0xC7,0xD7,0xD4,0x5A,0x54,0x79,0xAD},
266 {0x05,0x04,0x4B,0x62,0xFA,0x52,0xD0,0x80},
267 };
268
269static int test(void );
270static int print_test_data(void );
271int main(int argc, char *argv[])
272 {
273 int ret;
274
275 if (argc > 1)
276 ret=print_test_data();
277 else
278 ret=test();
279
280 EXIT(ret);
281 return(0);
282 }
283
284static int print_test_data(void)
285 {
286 unsigned int i,j;
287
288 printf("ecb test data\n");
289 printf("key bytes\t\tclear bytes\t\tcipher bytes\n");
290 for (i=0; i<NUM_TESTS; i++)
291 {
292 for (j=0; j<8; j++)
293 printf("%02X",ecb_data[i][j]);
294 printf("\t");
295 for (j=0; j<8; j++)
296 printf("%02X",plain_data[i][j]);
297 printf("\t");
298 for (j=0; j<8; j++)
299 printf("%02X",cipher_data[i][j]);
300 printf("\n");
301 }
302
303 printf("set_key test data\n");
304 printf("data[8]= ");
305 for (j=0; j<8; j++)
306 printf("%02X",key_data[j]);
307 printf("\n");
308 for (i=0; i<KEY_TEST_NUM-1; i++)
309 {
310 printf("c=");
311 for (j=0; j<8; j++)
312 printf("%02X",key_out[i][j]);
313 printf(" k[%2u]=",i+1);
314 for (j=0; j<i+1; j++)
315 printf("%02X",key_test[j]);
316 printf("\n");
317 }
318
319 printf("\nchaining mode test data\n");
320 printf("key[16] = ");
321 for (j=0; j<16; j++)
322 printf("%02X",cbc_key[j]);
323 printf("\niv[8] = ");
324 for (j=0; j<8; j++)
325 printf("%02X",cbc_iv[j]);
326 printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data);
327 printf("\ndata[%d] = ",(int)strlen(cbc_data)+1);
328 for (j=0; j<strlen(cbc_data)+1; j++)
329 printf("%02X",cbc_data[j]);
330 printf("\n");
331 printf("cbc cipher text\n");
332 printf("cipher[%d]= ",32);
333 for (j=0; j<32; j++)
334 printf("%02X",cbc_ok[j]);
335 printf("\n");
336
337 printf("cfb64 cipher text\n");
338 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
339 for (j=0; j<strlen(cbc_data)+1; j++)
340 printf("%02X",cfb64_ok[j]);
341 printf("\n");
342
343 printf("ofb64 cipher text\n");
344 printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
345 for (j=0; j<strlen(cbc_data)+1; j++)
346 printf("%02X",ofb64_ok[j]);
347 printf("\n");
348 return(0);
349 }
350
351static int test(void)
352 {
353 unsigned char cbc_in[40],cbc_out[40],iv[8];
354 int i,n,err=0;
355 BF_KEY key;
356 BF_LONG data[2];
357 unsigned char out[8];
358 BF_LONG len;
359
360#ifdef CHARSET_EBCDIC
361 ebcdic2ascii(cbc_data, cbc_data, strlen(cbc_data));
362#endif
363
364 printf("testing blowfish in raw ecb mode\n");
365 for (n=0; n<2; n++)
366 {
367#ifdef CHARSET_EBCDIC
368 ebcdic2ascii(bf_key[n], bf_key[n], strlen(bf_key[n]));
369#endif
370 BF_set_key(&key,strlen(bf_key[n]),(unsigned char *)bf_key[n]);
371
372 data[0]=bf_plain[n][0];
373 data[1]=bf_plain[n][1];
374 BF_encrypt(data,&key);
375 if (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)
376 {
377 printf("BF_encrypt error encrypting\n");
378 printf("got :");
379 for (i=0; i<2; i++)
380 printf("%08lX ",(unsigned long)data[i]);
381 printf("\n");
382 printf("expected:");
383 for (i=0; i<2; i++)
384 printf("%08lX ",(unsigned long)bf_cipher[n][i]);
385 err=1;
386 printf("\n");
387 }
388
389 BF_decrypt(&(data[0]),&key);
390 if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)
391 {
392 printf("BF_encrypt error decrypting\n");
393 printf("got :");
394 for (i=0; i<2; i++)
395 printf("%08lX ",(unsigned long)data[i]);
396 printf("\n");
397 printf("expected:");
398 for (i=0; i<2; i++)
399 printf("%08lX ",(unsigned long)bf_plain[n][i]);
400 printf("\n");
401 err=1;
402 }
403 }
404
405 printf("testing blowfish in ecb mode\n");
406
407 for (n=0; n<NUM_TESTS; n++)
408 {
409 BF_set_key(&key,8,ecb_data[n]);
410
411 BF_ecb_encrypt(&(plain_data[n][0]),out,&key,BF_ENCRYPT);
412 if (memcmp(&(cipher_data[n][0]),out,8) != 0)
413 {
414 printf("BF_ecb_encrypt blowfish error encrypting\n");
415 printf("got :");
416 for (i=0; i<8; i++)
417 printf("%02X ",out[i]);
418 printf("\n");
419 printf("expected:");
420 for (i=0; i<8; i++)
421 printf("%02X ",cipher_data[n][i]);
422 err=1;
423 printf("\n");
424 }
425
426 BF_ecb_encrypt(out,out,&key,BF_DECRYPT);
427 if (memcmp(&(plain_data[n][0]),out,8) != 0)
428 {
429 printf("BF_ecb_encrypt error decrypting\n");
430 printf("got :");
431 for (i=0; i<8; i++)
432 printf("%02X ",out[i]);
433 printf("\n");
434 printf("expected:");
435 for (i=0; i<8; i++)
436 printf("%02X ",plain_data[n][i]);
437 printf("\n");
438 err=1;
439 }
440 }
441
442 printf("testing blowfish set_key\n");
443 for (n=1; n<KEY_TEST_NUM; n++)
444 {
445 BF_set_key(&key,n,key_test);
446 BF_ecb_encrypt(key_data,out,&key,BF_ENCRYPT);
447 /* mips-sgi-irix6.5-gcc vv -mabi=64 bug workaround */
448 if (memcmp(out,&(key_out[i=n-1][0]),8) != 0)
449 {
450 printf("blowfish setkey error\n");
451 err=1;
452 }
453 }
454
455 printf("testing blowfish in cbc mode\n");
456 len=strlen(cbc_data)+1;
457
458 BF_set_key(&key,16,cbc_key);
459 memset(cbc_in,0,sizeof cbc_in);
460 memset(cbc_out,0,sizeof cbc_out);
461 memcpy(iv,cbc_iv,sizeof iv);
462 BF_cbc_encrypt((unsigned char *)cbc_data,cbc_out,len,
463 &key,iv,BF_ENCRYPT);
464 if (memcmp(cbc_out,cbc_ok,32) != 0)
465 {
466 err=1;
467 printf("BF_cbc_encrypt encrypt error\n");
468 for (i=0; i<32; i++) printf("0x%02X,",cbc_out[i]);
469 }
470 memcpy(iv,cbc_iv,8);
471 BF_cbc_encrypt(cbc_out,cbc_in,len,
472 &key,iv,BF_DECRYPT);
473 if (memcmp(cbc_in,cbc_data,strlen(cbc_data)+1) != 0)
474 {
475 printf("BF_cbc_encrypt decrypt error\n");
476 err=1;
477 }
478
479 printf("testing blowfish in cfb64 mode\n");
480
481 BF_set_key(&key,16,cbc_key);
482 memset(cbc_in,0,40);
483 memset(cbc_out,0,40);
484 memcpy(iv,cbc_iv,8);
485 n=0;
486 BF_cfb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,
487 &key,iv,&n,BF_ENCRYPT);
488 BF_cfb64_encrypt((unsigned char *)&(cbc_data[13]),&(cbc_out[13]),len-13,
489 &key,iv,&n,BF_ENCRYPT);
490 if (memcmp(cbc_out,cfb64_ok,(int)len) != 0)
491 {
492 err=1;
493 printf("BF_cfb64_encrypt encrypt error\n");
494 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
495 }
496 n=0;
497 memcpy(iv,cbc_iv,8);
498 BF_cfb64_encrypt(cbc_out,cbc_in,17,
499 &key,iv,&n,BF_DECRYPT);
500 BF_cfb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,
501 &key,iv,&n,BF_DECRYPT);
502 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
503 {
504 printf("BF_cfb64_encrypt decrypt error\n");
505 err=1;
506 }
507
508 printf("testing blowfish in ofb64\n");
509
510 BF_set_key(&key,16,cbc_key);
511 memset(cbc_in,0,40);
512 memset(cbc_out,0,40);
513 memcpy(iv,cbc_iv,8);
514 n=0;
515 BF_ofb64_encrypt((unsigned char *)cbc_data,cbc_out,(long)13,&key,iv,&n);
516 BF_ofb64_encrypt((unsigned char *)&(cbc_data[13]),
517 &(cbc_out[13]),len-13,&key,iv,&n);
518 if (memcmp(cbc_out,ofb64_ok,(int)len) != 0)
519 {
520 err=1;
521 printf("BF_ofb64_encrypt encrypt error\n");
522 for (i=0; i<(int)len; i++) printf("0x%02X,",cbc_out[i]);
523 }
524 n=0;
525 memcpy(iv,cbc_iv,8);
526 BF_ofb64_encrypt(cbc_out,cbc_in,17,&key,iv,&n);
527 BF_ofb64_encrypt(&(cbc_out[17]),&(cbc_in[17]),len-17,&key,iv,&n);
528 if (memcmp(cbc_in,cbc_data,(int)len) != 0)
529 {
530 printf("BF_ofb64_encrypt decrypt error\n");
531 err=1;
532 }
533
534 return(err);
535 }
536#endif
diff --git a/src/lib/libcrypto/bf/blowfish.h b/src/lib/libcrypto/bf/blowfish.h
index cd49e85ab2..b4d8774961 100644
--- a/src/lib/libcrypto/bf/blowfish.h
+++ b/src/lib/libcrypto/bf/blowfish.h
@@ -104,7 +104,10 @@ typedef struct bf_key_st
104 BF_LONG S[4*256]; 104 BF_LONG S[4*256];
105 } BF_KEY; 105 } BF_KEY;
106 106
107 107
108#ifdef OPENSSL_FIPS
109void private_BF_set_key(BF_KEY *key, int len, const unsigned char *data);
110#endif
108void BF_set_key(BF_KEY *key, int len, const unsigned char *data); 111void BF_set_key(BF_KEY *key, int len, const unsigned char *data);
109 112
110void BF_encrypt(BF_LONG *data,const BF_KEY *key); 113void BF_encrypt(BF_LONG *data,const BF_KEY *key);
diff --git a/src/lib/libcrypto/bio/Makefile b/src/lib/libcrypto/bio/Makefile
new file mode 100644
index 0000000000..1ef6c2fb9f
--- /dev/null
+++ b/src/lib/libcrypto/bio/Makefile
@@ -0,0 +1,221 @@
1#
2# OpenSSL/crypto/bio/Makefile
3#
4
5DIR= bio
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= bio_lib.c bio_cb.c bio_err.c \
21 bss_mem.c bss_null.c bss_fd.c \
22 bss_file.c bss_sock.c bss_conn.c \
23 bf_null.c bf_buff.c b_print.c b_dump.c \
24 b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c \
25 bss_dgram.c
26# bf_lbuf.c
27LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
28 bss_mem.o bss_null.o bss_fd.o \
29 bss_file.o bss_sock.o bss_conn.o \
30 bf_null.o bf_buff.o b_print.o b_dump.o \
31 b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o \
32 bss_dgram.o
33# bf_lbuf.o
34
35SRC= $(LIBSRC)
36
37EXHEADER= bio.h
38HEADER= bio_lcl.h $(EXHEADER)
39
40ALL= $(GENERAL) $(SRC) $(HEADER)
41
42top:
43 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
44
45all: lib
46
47lib: $(LIBOBJ)
48 $(AR) $(LIB) $(LIBOBJ)
49 $(RANLIB) $(LIB) || echo Never mind.
50 @touch lib
51
52files:
53 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
54
55links:
56 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
57 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
58 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
59
60install:
61 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
62 @headerlist="$(EXHEADER)"; for i in $$headerlist; \
63 do \
64 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
65 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
66 done;
67
68tags:
69 ctags $(SRC)
70
71tests:
72
73lint:
74 lint -DLINT $(INCLUDES) $(SRC)>fluff
75
76depend:
77 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
78 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
79
80dclean:
81 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
82 mv -f Makefile.new $(MAKEFILE)
83
84clean:
85 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
86
87# DO NOT DELETE THIS LINE -- make depend depends on it.
88
89b_dump.o: ../../e_os.h ../../include/openssl/bio.h
90b_dump.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
91b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
92b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
93b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
94b_dump.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
95b_dump.o: ../../include/openssl/symhacks.h ../cryptlib.h b_dump.c bio_lcl.h
96b_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
97b_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
98b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
99b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
100b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101b_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
102b_print.o: ../../include/openssl/symhacks.h ../cryptlib.h b_print.c
103b_sock.o: ../../e_os.h ../../include/openssl/bio.h
104b_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
105b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
106b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
107b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
108b_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
109b_sock.o: ../../include/openssl/symhacks.h ../cryptlib.h b_sock.c
110bf_buff.o: ../../e_os.h ../../include/openssl/bio.h
111bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
112bf_buff.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
113bf_buff.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
114bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
115bf_buff.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116bf_buff.o: ../../include/openssl/symhacks.h ../cryptlib.h bf_buff.c
117bf_nbio.o: ../../e_os.h ../../include/openssl/bio.h
118bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
119bf_nbio.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
120bf_nbio.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
121bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
123bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
124bf_nbio.o: ../cryptlib.h bf_nbio.c
125bf_null.o: ../../e_os.h ../../include/openssl/bio.h
126bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
127bf_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
128bf_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
129bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130bf_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
131bf_null.o: ../../include/openssl/symhacks.h ../cryptlib.h bf_null.c
132bio_cb.o: ../../e_os.h ../../include/openssl/bio.h
133bio_cb.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
134bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
135bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
136bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
137bio_cb.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
138bio_cb.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_cb.c
139bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
140bio_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
141bio_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
142bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
143bio_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
144bio_err.o: ../../include/openssl/symhacks.h bio_err.c
145bio_lib.o: ../../e_os.h ../../include/openssl/bio.h
146bio_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
147bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
148bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
149bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
150bio_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
151bio_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lib.c
152bss_acpt.o: ../../e_os.h ../../include/openssl/bio.h
153bss_acpt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
154bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
155bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
156bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
157bss_acpt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158bss_acpt.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_acpt.c
159bss_bio.o: ../../e_os.h ../../include/openssl/bio.h
160bss_bio.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
161bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
162bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
163bss_bio.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
164bss_bio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
165bss_bio.o: bss_bio.c
166bss_conn.o: ../../e_os.h ../../include/openssl/bio.h
167bss_conn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
168bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
169bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
170bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
171bss_conn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
172bss_conn.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_conn.c
173bss_dgram.o: ../../e_os.h ../../include/openssl/bio.h
174bss_dgram.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
175bss_dgram.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
176bss_dgram.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
177bss_dgram.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
178bss_dgram.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
179bss_dgram.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_dgram.c
180bss_fd.o: ../../e_os.h ../../include/openssl/bio.h
181bss_fd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
182bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
183bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
184bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
185bss_fd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
186bss_fd.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lcl.h bss_fd.c
187bss_file.o: ../../e_os.h ../../include/openssl/bio.h
188bss_file.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
189bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
190bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
191bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
192bss_file.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
193bss_file.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_lcl.h bss_file.c
194bss_log.o: ../../e_os.h ../../include/openssl/bio.h
195bss_log.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
196bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
197bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
198bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
199bss_log.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
200bss_log.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_log.c
201bss_mem.o: ../../e_os.h ../../include/openssl/bio.h
202bss_mem.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
203bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
204bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
205bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
206bss_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
207bss_mem.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_mem.c
208bss_null.o: ../../e_os.h ../../include/openssl/bio.h
209bss_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
210bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
211bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
212bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
213bss_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
214bss_null.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_null.c
215bss_sock.o: ../../e_os.h ../../include/openssl/bio.h
216bss_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
217bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
218bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
219bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
220bss_sock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
221bss_sock.o: ../../include/openssl/symhacks.h ../cryptlib.h bss_sock.c
diff --git a/src/lib/libcrypto/bio/Makefile.ssl b/src/lib/libcrypto/bio/Makefile.ssl
new file mode 100644
index 0000000000..d0b9e297b0
--- /dev/null
+++ b/src/lib/libcrypto/bio/Makefile.ssl
@@ -0,0 +1,216 @@
1#
2# SSLeay/crypto/bio/Makefile
3#
4
5DIR= bio
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= bio_lib.c bio_cb.c bio_err.c \
27 bss_mem.c bss_null.c bss_fd.c \
28 bss_file.c bss_sock.c bss_conn.c \
29 bf_null.c bf_buff.c b_print.c b_dump.c \
30 b_sock.c bss_acpt.c bf_nbio.c bss_log.c bss_bio.c
31# bf_lbuf.c
32LIBOBJ= bio_lib.o bio_cb.o bio_err.o \
33 bss_mem.o bss_null.o bss_fd.o \
34 bss_file.o bss_sock.o bss_conn.o \
35 bf_null.o bf_buff.o b_print.o b_dump.o \
36 b_sock.o bss_acpt.o bf_nbio.o bss_log.o bss_bio.o
37# bf_lbuf.o
38
39SRC= $(LIBSRC)
40
41EXHEADER= bio.h
42HEADER= bss_file.c $(EXHEADER)
43
44ALL= $(GENERAL) $(SRC) $(HEADER)
45
46top:
47 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
48
49all: lib
50
51lib: $(LIBOBJ)
52 $(AR) $(LIB) $(LIBOBJ)
53 $(RANLIB) $(LIB) || echo Never mind.
54 @touch lib
55
56files:
57 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
58
59links:
60 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65install:
66 @for i in $(EXHEADER); \
67 do \
68 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
69 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
70 done;
71
72tags:
73 ctags $(SRC)
74
75tests:
76
77lint:
78 lint -DLINT $(INCLUDES) $(SRC)>fluff
79
80depend:
81 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
82
83dclean:
84 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
85 mv -f Makefile.new $(MAKEFILE)
86
87clean:
88 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
89
90# DO NOT DELETE THIS LINE -- make depend depends on it.
91
92b_dump.o: ../../e_os.h ../../include/openssl/bio.h
93b_dump.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
94b_dump.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
95b_dump.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
96b_dump.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
97b_dump.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98b_dump.o: ../cryptlib.h b_dump.c
99b_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
100b_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101b_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102b_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
103b_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
104b_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
105b_print.o: ../cryptlib.h b_print.c
106b_sock.o: ../../e_os.h ../../include/openssl/bio.h
107b_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
108b_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
109b_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
110b_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
111b_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
112b_sock.o: ../cryptlib.h b_sock.c
113bf_buff.o: ../../e_os.h ../../include/openssl/bio.h
114bf_buff.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
115bf_buff.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
116bf_buff.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
117bf_buff.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
118bf_buff.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119bf_buff.o: ../cryptlib.h bf_buff.c
120bf_nbio.o: ../../e_os.h ../../include/openssl/bio.h
121bf_nbio.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
122bf_nbio.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
123bf_nbio.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
124bf_nbio.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
125bf_nbio.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
126bf_nbio.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
127bf_nbio.o: ../cryptlib.h bf_nbio.c
128bf_null.o: ../../e_os.h ../../include/openssl/bio.h
129bf_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
130bf_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
131bf_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
132bf_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
133bf_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
134bf_null.o: ../cryptlib.h bf_null.c
135bio_cb.o: ../../e_os.h ../../include/openssl/bio.h
136bio_cb.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
137bio_cb.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
138bio_cb.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
139bio_cb.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
140bio_cb.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
141bio_cb.o: ../cryptlib.h bio_cb.c
142bio_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
143bio_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
144bio_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
145bio_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
146bio_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
147bio_err.o: bio_err.c
148bio_lib.o: ../../e_os.h ../../include/openssl/bio.h
149bio_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
150bio_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
151bio_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
152bio_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
153bio_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
154bio_lib.o: ../cryptlib.h bio_lib.c
155bss_acpt.o: ../../e_os.h ../../include/openssl/bio.h
156bss_acpt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
157bss_acpt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
158bss_acpt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
159bss_acpt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
160bss_acpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
161bss_acpt.o: ../cryptlib.h bss_acpt.c
162bss_bio.o: ../../e_os.h ../../include/openssl/bio.h
163bss_bio.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
164bss_bio.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
165bss_bio.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
166bss_bio.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
167bss_bio.o: ../../include/openssl/symhacks.h bss_bio.c
168bss_conn.o: ../../e_os.h ../../include/openssl/bio.h
169bss_conn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
170bss_conn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
171bss_conn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
172bss_conn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
173bss_conn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
174bss_conn.o: ../cryptlib.h bss_conn.c
175bss_fd.o: ../../e_os.h ../../include/openssl/bio.h
176bss_fd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
177bss_fd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
178bss_fd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
179bss_fd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
180bss_fd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
181bss_fd.o: ../cryptlib.h bss_fd.c
182bss_file.o: ../../e_os.h ../../include/openssl/bio.h
183bss_file.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
184bss_file.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
185bss_file.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
186bss_file.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
187bss_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
188bss_file.o: ../cryptlib.h bss_file.c
189bss_log.o: ../../e_os.h ../../include/openssl/bio.h
190bss_log.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
191bss_log.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
192bss_log.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
193bss_log.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
194bss_log.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
195bss_log.o: ../cryptlib.h bss_log.c
196bss_mem.o: ../../e_os.h ../../include/openssl/bio.h
197bss_mem.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
198bss_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
199bss_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
200bss_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
201bss_mem.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
202bss_mem.o: ../cryptlib.h bss_mem.c
203bss_null.o: ../../e_os.h ../../include/openssl/bio.h
204bss_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205bss_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
206bss_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
207bss_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
208bss_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
209bss_null.o: ../cryptlib.h bss_null.c
210bss_sock.o: ../../e_os.h ../../include/openssl/bio.h
211bss_sock.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
212bss_sock.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
213bss_sock.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
214bss_sock.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
215bss_sock.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
216bss_sock.o: ../cryptlib.h bss_sock.c
diff --git a/src/lib/libcrypto/bio/b_dump.c b/src/lib/libcrypto/bio/b_dump.c
index c80ecc4295..f671e722fa 100644
--- a/src/lib/libcrypto/bio/b_dump.c
+++ b/src/lib/libcrypto/bio/b_dump.c
@@ -62,32 +62,30 @@
62 62
63#include <stdio.h> 63#include <stdio.h>
64#include "cryptlib.h" 64#include "cryptlib.h"
65#include "bio_lcl.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#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4)) 69#define DUMP_WIDTH_LESS_INDENT(i) (DUMP_WIDTH-((i-(i>6?6:i)+3)/4))
70 70
71int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u), 71int BIO_dump(BIO *bio, const char *s, int len)
72 void *u, const char *s, int len)
73 { 72 {
74 return BIO_dump_indent_cb(cb, u, s, len, 0); 73 return BIO_dump_indent(bio, s, len, 0);
75 } 74 }
76 75
77int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u), 76int BIO_dump_indent(BIO *bio, const char *s, int len, int indent)
78 void *u, const char *s, int len, int indent)
79 { 77 {
80 int ret=0; 78 int ret=0;
81 char buf[288+1],tmp[20],str[128+1]; 79 char buf[288+1],tmp[20],str[128+1];
82 int i,j,rows,trc; 80 int i,j,rows,trunc;
83 unsigned char ch; 81 unsigned char ch;
84 int dump_width; 82 int dump_width;
85 83
86 trc=0; 84 trunc=0;
87 85
88#ifdef TRUNCATE 86#ifdef TRUNCATE
89 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--) 87 for(; (len > 0) && ((s[len-1] == ' ') || (s[len-1] == '\0')); len--)
90 trc++; 88 trunc++;
91#endif 89#endif
92 90
93 if (indent < 0) 91 if (indent < 0)
@@ -98,7 +96,7 @@ int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
98 memset(str,' ',indent); 96 memset(str,' ',indent);
99 } 97 }
100 str[indent]='\0'; 98 str[indent]='\0';
101 99
102 dump_width=DUMP_WIDTH_LESS_INDENT(indent); 100 dump_width=DUMP_WIDTH_LESS_INDENT(indent);
103 rows=(len/dump_width); 101 rows=(len/dump_width);
104 if ((rows*dump_width)<len) 102 if ((rows*dump_width)<len)
@@ -119,7 +117,7 @@ int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
119 { 117 {
120 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; 118 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
121 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch, 119 BIO_snprintf(tmp,sizeof tmp,"%02x%c",ch,
122 j==7?'-':' '); 120 j==7?'-':' ');
123 BUF_strlcat(buf,tmp,sizeof buf); 121 BUF_strlcat(buf,tmp,sizeof buf);
124 } 122 }
125 } 123 }
@@ -131,57 +129,28 @@ int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
131 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff; 129 ch=((unsigned char)*(s+i*dump_width+j)) & 0xff;
132#ifndef CHARSET_EBCDIC 130#ifndef CHARSET_EBCDIC
133 BIO_snprintf(tmp,sizeof tmp,"%c", 131 BIO_snprintf(tmp,sizeof tmp,"%c",
134 ((ch>=' ')&&(ch<='~'))?ch:'.'); 132 ((ch>=' ')&&(ch<='~'))?ch:'.');
135#else 133#else
136 BIO_snprintf(tmp,sizeof tmp,"%c", 134 BIO_snprintf(tmp,sizeof tmp,"%c",
137 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~'])) 135 ((ch>=os_toascii[' '])&&(ch<=os_toascii['~']))
138 ? os_toebcdic[ch] 136 ? os_toebcdic[ch]
139 : '.'); 137 : '.');
140#endif 138#endif
141 BUF_strlcat(buf,tmp,sizeof buf); 139 BUF_strlcat(buf,tmp,sizeof buf);
142 } 140 }
143 BUF_strlcat(buf,"\n",sizeof buf); 141 BUF_strlcat(buf,"\n",sizeof buf);
144 /* if this is the last call then update the ddt_dump thing so 142 /* if this is the last call then update the ddt_dump thing so that
145 * that we will move the selection point in the debug window 143 * we will move the selection point in the debug window
146 */ 144 */
147 ret+=cb((void *)buf,strlen(buf),u); 145 ret+=BIO_write(bio,(char *)buf,strlen(buf));
148 } 146 }
149#ifdef TRUNCATE 147#ifdef TRUNCATE
150 if (trc > 0) 148 if (trunc > 0)
151 { 149 {
152 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str, 150 BIO_snprintf(buf,sizeof buf,"%s%04x - <SPACES/NULS>\n",str,
153 len+trc); 151 len+trunc);
154 ret+=cb((void *)buf,strlen(buf),u); 152 ret+=BIO_write(bio,(char *)buf,strlen(buf));
155 } 153 }
156#endif 154#endif
157 return(ret); 155 return(ret);
158 } 156 }
159
160#ifndef OPENSSL_NO_FP_API
161static int write_fp(const void *data, size_t len, void *fp)
162 {
163 return UP_fwrite(data, len, 1, fp);
164 }
165int BIO_dump_fp(FILE *fp, const char *s, int len)
166 {
167 return BIO_dump_cb(write_fp, fp, s, len);
168 }
169int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent)
170 {
171 return BIO_dump_indent_cb(write_fp, fp, s, len, indent);
172 }
173#endif
174
175static int write_bio(const void *data, size_t len, void *bp)
176 {
177 return BIO_write((BIO *)bp, (const char *)data, len);
178 }
179int BIO_dump(BIO *bp, const char *s, int len)
180 {
181 return BIO_dump_cb(write_bio, bp, s, len);
182 }
183int BIO_dump_indent(BIO *bp, const char *s, int len, int indent)
184 {
185 return BIO_dump_indent_cb(write_bio, bp, s, len, indent);
186 }
187
diff --git a/src/lib/libcrypto/bio/b_print.c b/src/lib/libcrypto/bio/b_print.c
index 3a87b0ec0b..f2bd91d5a0 100644
--- a/src/lib/libcrypto/bio/b_print.c
+++ b/src/lib/libcrypto/bio/b_print.c
@@ -79,7 +79,7 @@
79#include <openssl/bn.h> /* To get BN_LLONG properly defined */ 79#include <openssl/bn.h> /* To get BN_LLONG properly defined */
80#include <openssl/bio.h> 80#include <openssl/bio.h>
81 81
82#if defined(BN_LLONG) || defined(SIXTY_FOUR_BIT) 82#ifdef BN_LLONG
83# ifndef HAVE_LONG_LONG 83# ifndef HAVE_LONG_LONG
84# define HAVE_LONG_LONG 1 84# define HAVE_LONG_LONG 1
85# endif 85# endif
@@ -117,7 +117,7 @@
117 117
118#if HAVE_LONG_LONG 118#if HAVE_LONG_LONG
119# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__) 119# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
120# define LLONG __int64 120# define LLONG _int64
121# else 121# else
122# define LLONG long long 122# define LLONG long long
123# endif 123# endif
@@ -482,7 +482,7 @@ fmtint(
482 int flags) 482 int flags)
483{ 483{
484 int signvalue = 0; 484 int signvalue = 0;
485 const char *prefix = ""; 485 char *prefix = "";
486 unsigned LLONG uvalue; 486 unsigned LLONG uvalue;
487 char convert[DECIMAL_SIZE(value)+3]; 487 char convert[DECIMAL_SIZE(value)+3];
488 int place = 0; 488 int place = 0;
@@ -513,8 +513,8 @@ fmtint(
513 (caps ? "0123456789ABCDEF" : "0123456789abcdef") 513 (caps ? "0123456789ABCDEF" : "0123456789abcdef")
514 [uvalue % (unsigned) base]; 514 [uvalue % (unsigned) base];
515 uvalue = (uvalue / (unsigned) base); 515 uvalue = (uvalue / (unsigned) base);
516 } while (uvalue && (place < (int)sizeof(convert))); 516 } while (uvalue && (place < sizeof convert));
517 if (place == sizeof(convert)) 517 if (place == sizeof convert)
518 place--; 518 place--;
519 convert[place] = 0; 519 convert[place] = 0;
520 520
@@ -619,7 +619,6 @@ fmtfp(
619 int caps = 0; 619 int caps = 0;
620 long intpart; 620 long intpart;
621 long fracpart; 621 long fracpart;
622 long max10;
623 622
624 if (max < 0) 623 if (max < 0)
625 max = 6; 624 max = 6;
@@ -640,12 +639,11 @@ fmtfp(
640 639
641 /* we "cheat" by converting the fractional part to integer by 640 /* we "cheat" by converting the fractional part to integer by
642 multiplying by a factor of 10 */ 641 multiplying by a factor of 10 */
643 max10 = roundv(pow_10(max)); 642 fracpart = roundv((pow_10(max)) * (ufvalue - intpart));
644 fracpart = roundv(pow_10(max) * (ufvalue - intpart));
645 643
646 if (fracpart >= max10) { 644 if (fracpart >= (long)pow_10(max)) {
647 intpart++; 645 intpart++;
648 fracpart -= max10; 646 fracpart -= (long)pow_10(max);
649 } 647 }
650 648
651 /* convert integer part */ 649 /* convert integer part */
@@ -654,7 +652,7 @@ fmtfp(
654 (caps ? "0123456789ABCDEF" 652 (caps ? "0123456789ABCDEF"
655 : "0123456789abcdef")[intpart % 10]; 653 : "0123456789abcdef")[intpart % 10];
656 intpart = (intpart / 10); 654 intpart = (intpart / 10);
657 } while (intpart && (iplace < (int)sizeof(iconvert))); 655 } while (intpart && (iplace < sizeof iconvert));
658 if (iplace == sizeof iconvert) 656 if (iplace == sizeof iconvert)
659 iplace--; 657 iplace--;
660 iconvert[iplace] = 0; 658 iconvert[iplace] = 0;
@@ -808,6 +806,7 @@ int BIO_vprintf (BIO *bio, const char *format, va_list args)
808 } 806 }
809 807
810/* As snprintf is not available everywhere, we provide our own implementation. 808/* As snprintf is not available everywhere, we provide our own implementation.
809 * In case of overflow or error, this returns -1.
811 * This function has nothing to do with BIOs, but it's closely related 810 * This function has nothing to do with BIOs, but it's closely related
812 * to BIO_printf, and we need *some* name prefix ... 811 * to BIO_printf, and we need *some* name prefix ...
813 * (XXX the function should be renamed, but to what?) */ 812 * (XXX the function should be renamed, but to what?) */
@@ -832,10 +831,10 @@ int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
832 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args); 831 _dopr(&buf, NULL, &n, &retlen, &truncated, format, args);
833 832
834 if (truncated) 833 if (truncated)
835 /* In case of truncation, return -1 like traditional snprintf. 834 /* In case of truncation, return -1 unlike traditional snprintf.
836 * (Current drafts for ISO/IEC 9899 say snprintf should return 835 * (Current drafts for ISO/IEC 9899 say snprintf should return
837 * the number of characters that would have been written, 836 * the number of characters that would have been written,
838 * had the buffer been large enough.) */ 837 * had the buffer been large enough, as it did historically.) */
839 return -1; 838 return -1;
840 else 839 else
841 return (retlen <= INT_MAX) ? (int)retlen : -1; 840 return (retlen <= INT_MAX) ? (int)retlen : -1;
diff --git a/src/lib/libcrypto/bio/b_sock.c b/src/lib/libcrypto/bio/b_sock.c
index ead477d8a2..c851298d1e 100644
--- a/src/lib/libcrypto/bio/b_sock.c
+++ b/src/lib/libcrypto/bio/b_sock.c
@@ -56,21 +56,14 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SOCK
60
59#include <stdio.h> 61#include <stdio.h>
60#include <stdlib.h> 62#include <stdlib.h>
61#include <errno.h> 63#include <errno.h>
62#define USE_SOCKETS 64#define USE_SOCKETS
63#include "cryptlib.h" 65#include "cryptlib.h"
64#include <openssl/bio.h> 66#include <openssl/bio.h>
65#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_BSDSOCK)
66#include <netdb.h>
67#if defined(NETWARE_CLIB)
68#include <sys/ioctl.h>
69NETDB_DEFINE_CONTEXT
70#endif
71#endif
72
73#ifndef OPENSSL_NO_SOCK
74 67
75#ifdef OPENSSL_SYS_WIN16 68#ifdef OPENSSL_SYS_WIN16
76#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 69#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
@@ -86,7 +79,7 @@ NETDB_DEFINE_CONTEXT
86#define MAX_LISTEN 32 79#define MAX_LISTEN 32
87#endif 80#endif
88 81
89#if defined(OPENSSL_SYS_WINDOWS) || (defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)) 82#ifdef OPENSSL_SYS_WINDOWS
90static int wsa_init_done=0; 83static int wsa_init_done=0;
91#endif 84#endif
92 85
@@ -182,11 +175,11 @@ int BIO_get_port(const char *str, unsigned short *port_ptr)
182 /* Note: under VMS with SOCKETSHR, it seems like the first 175 /* Note: under VMS with SOCKETSHR, it seems like the first
183 * parameter is 'char *', instead of 'const char *' 176 * parameter is 'char *', instead of 'const char *'
184 */ 177 */
178 s=getservbyname(
185#ifndef CONST_STRICT 179#ifndef CONST_STRICT
186 s=getservbyname((char *)str,"tcp"); 180 (char *)
187#else
188 s=getservbyname(str,"tcp");
189#endif 181#endif
182 str,"tcp");
190 if(s != NULL) 183 if(s != NULL)
191 *port_ptr=ntohs((unsigned short)s->s_port); 184 *port_ptr=ntohs((unsigned short)s->s_port);
192 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME); 185 CRYPTO_w_unlock(CRYPTO_LOCK_GETSERVBYNAME);
@@ -364,11 +357,7 @@ struct hostent *BIO_gethostbyname(const char *name)
364#if 1 357#if 1
365 /* Caching gethostbyname() results forever is wrong, 358 /* Caching gethostbyname() results forever is wrong,
366 * so we have to let the true gethostbyname() worry about this */ 359 * so we have to let the true gethostbyname() worry about this */
367#if (defined(NETWARE_BSDSOCK) && !defined(__NOVELL_LIBC__))
368 return gethostbyname((char*)name);
369#else
370 return gethostbyname(name); 360 return gethostbyname(name);
371#endif
372#else 361#else
373 struct hostent *ret; 362 struct hostent *ret;
374 int i,lowi=0,j; 363 int i,lowi=0,j;
@@ -408,11 +397,11 @@ struct hostent *BIO_gethostbyname(const char *name)
408 /* Note: under VMS with SOCKETSHR, it seems like the first 397 /* Note: under VMS with SOCKETSHR, it seems like the first
409 * parameter is 'char *', instead of 'const char *' 398 * parameter is 'char *', instead of 'const char *'
410 */ 399 */
400 ret=gethostbyname(
411# ifndef CONST_STRICT 401# ifndef CONST_STRICT
412 ret=gethostbyname((char *)name); 402 (char *)
413# else
414 ret=gethostbyname(name);
415# endif 403# endif
404 name);
416 405
417 if (ret == NULL) 406 if (ret == NULL)
418 goto end; 407 goto end;
@@ -464,6 +453,9 @@ int BIO_sock_init(void)
464 { 453 {
465 int err; 454 int err;
466 455
456#ifdef SIGINT
457 signal(SIGINT,(void (*)(int))BIO_sock_cleanup);
458#endif
467 wsa_init_done=1; 459 wsa_init_done=1;
468 memset(&wsa_state,0,sizeof(wsa_state)); 460 memset(&wsa_state,0,sizeof(wsa_state));
469 if (WSAStartup(0x0101,&wsa_state)!=0) 461 if (WSAStartup(0x0101,&wsa_state)!=0)
@@ -481,26 +473,6 @@ int BIO_sock_init(void)
481 if (sock_init()) 473 if (sock_init())
482 return (-1); 474 return (-1);
483#endif 475#endif
484
485#if defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
486 WORD wVerReq;
487 WSADATA wsaData;
488 int err;
489
490 if (!wsa_init_done)
491 {
492 wsa_init_done=1;
493 wVerReq = MAKEWORD( 2, 0 );
494 err = WSAStartup(wVerReq,&wsaData);
495 if (err != 0)
496 {
497 SYSerr(SYS_F_WSASTARTUP,err);
498 BIOerr(BIO_F_BIO_SOCK_INIT,BIO_R_WSASTARTUP);
499 return(-1);
500 }
501 }
502#endif
503
504 return(1); 476 return(1);
505 } 477 }
506 478
@@ -511,16 +483,10 @@ void BIO_sock_cleanup(void)
511 { 483 {
512 wsa_init_done=0; 484 wsa_init_done=0;
513#ifndef OPENSSL_SYS_WINCE 485#ifndef OPENSSL_SYS_WINCE
514 WSACancelBlockingCall(); /* Winsock 1.1 specific */ 486 WSACancelBlockingCall();
515#endif 487#endif
516 WSACleanup(); 488 WSACleanup();
517 } 489 }
518#elif defined(OPENSSL_SYS_NETWARE) && !defined(NETWARE_BSDSOCK)
519 if (wsa_init_done)
520 {
521 wsa_init_done=0;
522 WSACleanup();
523 }
524#endif 490#endif
525 } 491 }
526 492
diff --git a/src/lib/libcrypto/bio/bf_nbio.c b/src/lib/libcrypto/bio/bf_nbio.c
index c72a23c2e1..1ce2bfacc0 100644
--- a/src/lib/libcrypto/bio/bf_nbio.c
+++ b/src/lib/libcrypto/bio/bf_nbio.c
@@ -127,7 +127,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
127 { 127 {
128 NBIO_TEST *nt; 128 NBIO_TEST *nt;
129 int ret=0; 129 int ret=0;
130#if 1 130#if 0
131 int num; 131 int num;
132 unsigned char n; 132 unsigned char n;
133#endif 133#endif
@@ -137,7 +137,7 @@ static int nbiof_read(BIO *b, char *out, int outl)
137 nt=(NBIO_TEST *)b->ptr; 137 nt=(NBIO_TEST *)b->ptr;
138 138
139 BIO_clear_retry_flags(b); 139 BIO_clear_retry_flags(b);
140#if 1 140#if 0
141 RAND_pseudo_bytes(&n,1); 141 RAND_pseudo_bytes(&n,1);
142 num=(n&0x07); 142 num=(n&0x07);
143 143
diff --git a/src/lib/libcrypto/bio/bio.h b/src/lib/libcrypto/bio/bio.h
index cecb6a7207..2eb703830f 100644
--- a/src/lib/libcrypto/bio/bio.h
+++ b/src/lib/libcrypto/bio/bio.h
@@ -59,14 +59,13 @@
59#ifndef HEADER_BIO_H 59#ifndef HEADER_BIO_H
60#define HEADER_BIO_H 60#define HEADER_BIO_H
61 61
62#include <openssl/e_os2.h>
63
64#ifndef OPENSSL_NO_FP_API 62#ifndef OPENSSL_NO_FP_API
65# include <stdio.h> 63# include <stdio.h>
66#endif 64#endif
67#include <stdarg.h> 65#include <stdarg.h>
68 66
69#include <openssl/crypto.h> 67#include <openssl/crypto.h>
68#include <openssl/e_os2.h>
70 69
71#ifdef __cplusplus 70#ifdef __cplusplus
72extern "C" { 71extern "C" {
@@ -94,8 +93,6 @@ extern "C" {
94#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */ 93#define BIO_TYPE_BER (18|0x0200) /* BER -> bin filter */
95#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */ 94#define BIO_TYPE_BIO (19|0x0400) /* (half a) BIO pair */
96#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */ 95#define BIO_TYPE_LINEBUFFER (20|0x0200) /* filter */
97#define BIO_TYPE_DGRAM (21|0x0400|0x0100)
98#define BIO_TYPE_COMP (23|0x0200) /* filter */
99 96
100#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */ 97#define BIO_TYPE_DESCRIPTOR 0x0100 /* socket, fd, connect or accept */
101#define BIO_TYPE_FILTER 0x0200 98#define BIO_TYPE_FILTER 0x0200
@@ -127,38 +124,6 @@ extern "C" {
127 124
128#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */ 125#define BIO_CTRL_SET_FILENAME 30 /* BIO_s_file special */
129 126
130/* dgram BIO stuff */
131#define BIO_CTRL_DGRAM_CONNECT 31 /* BIO dgram special */
132#define BIO_CTRL_DGRAM_SET_CONNECTED 32 /* allow for an externally
133 * connected socket to be
134 * passed in */
135#define BIO_CTRL_DGRAM_SET_RECV_TIMEOUT 33 /* setsockopt, essentially */
136#define BIO_CTRL_DGRAM_GET_RECV_TIMEOUT 34 /* getsockopt, essentially */
137#define BIO_CTRL_DGRAM_SET_SEND_TIMEOUT 35 /* setsockopt, essentially */
138#define BIO_CTRL_DGRAM_GET_SEND_TIMEOUT 36 /* getsockopt, essentially */
139
140#define BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP 37 /* flag whether the last */
141#define BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP 38 /* I/O operation tiemd out */
142
143/* #ifdef IP_MTU_DISCOVER */
144#define BIO_CTRL_DGRAM_MTU_DISCOVER 39 /* set DF bit on egress packets */
145/* #endif */
146
147#define BIO_CTRL_DGRAM_QUERY_MTU 40 /* as kernel for current MTU */
148#define BIO_CTRL_DGRAM_GET_MTU 41 /* get cached value for MTU */
149#define BIO_CTRL_DGRAM_SET_MTU 42 /* set cached value for
150 * MTU. want to use this
151 * if asking the kernel
152 * fails */
153
154#define BIO_CTRL_DGRAM_MTU_EXCEEDED 43 /* check whether the MTU
155 * was exceed in the
156 * previous write
157 * operation */
158
159#define BIO_CTRL_DGRAM_SET_PEER 44 /* Destination for the data */
160
161
162/* modifiers */ 127/* modifiers */
163#define BIO_FP_READ 0x02 128#define BIO_FP_READ 0x02
164#define BIO_FP_WRITE 0x04 129#define BIO_FP_WRITE 0x04
@@ -170,11 +135,6 @@ extern "C" {
170#define BIO_FLAGS_IO_SPECIAL 0x04 135#define BIO_FLAGS_IO_SPECIAL 0x04
171#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL) 136#define BIO_FLAGS_RWS (BIO_FLAGS_READ|BIO_FLAGS_WRITE|BIO_FLAGS_IO_SPECIAL)
172#define BIO_FLAGS_SHOULD_RETRY 0x08 137#define BIO_FLAGS_SHOULD_RETRY 0x08
173#ifndef BIO_FLAGS_UPLINK
174/* "UPLINK" flag denotes file descriptors provided by application.
175 It defaults to 0, as most platforms don't require UPLINK interface. */
176#define BIO_FLAGS_UPLINK 0
177#endif
178 138
179/* Used in BIO_gethostbyname() */ 139/* Used in BIO_gethostbyname() */
180#define BIO_GHBN_CTRL_HITS 1 140#define BIO_GHBN_CTRL_HITS 1
@@ -197,32 +157,28 @@ extern "C" {
197 */ 157 */
198#define BIO_FLAGS_MEM_RDONLY 0x200 158#define BIO_FLAGS_MEM_RDONLY 0x200
199 159
200typedef struct bio_st BIO; 160#define BIO_set_flags(b,f) ((b)->flags|=(f))
201 161#define BIO_get_flags(b) ((b)->flags)
202void BIO_set_flags(BIO *b, int flags);
203int BIO_test_flags(const BIO *b, int flags);
204void BIO_clear_flags(BIO *b, int flags);
205
206#define BIO_get_flags(b) BIO_test_flags(b, ~(0x0))
207#define BIO_set_retry_special(b) \ 162#define BIO_set_retry_special(b) \
208 BIO_set_flags(b, (BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY)) 163 ((b)->flags|=(BIO_FLAGS_IO_SPECIAL|BIO_FLAGS_SHOULD_RETRY))
209#define BIO_set_retry_read(b) \ 164#define BIO_set_retry_read(b) \
210 BIO_set_flags(b, (BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY)) 165 ((b)->flags|=(BIO_FLAGS_READ|BIO_FLAGS_SHOULD_RETRY))
211#define BIO_set_retry_write(b) \ 166#define BIO_set_retry_write(b) \
212 BIO_set_flags(b, (BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY)) 167 ((b)->flags|=(BIO_FLAGS_WRITE|BIO_FLAGS_SHOULD_RETRY))
213 168
214/* These are normally used internally in BIOs */ 169/* These are normally used internally in BIOs */
170#define BIO_clear_flags(b,f) ((b)->flags&= ~(f))
215#define BIO_clear_retry_flags(b) \ 171#define BIO_clear_retry_flags(b) \
216 BIO_clear_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 172 ((b)->flags&= ~(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
217#define BIO_get_retry_flags(b) \ 173#define BIO_get_retry_flags(b) \
218 BIO_test_flags(b, (BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY)) 174 ((b)->flags&(BIO_FLAGS_RWS|BIO_FLAGS_SHOULD_RETRY))
219 175
220/* These should be used by the application to tell why we should retry */ 176/* These should be used by the application to tell why we should retry */
221#define BIO_should_read(a) BIO_test_flags(a, BIO_FLAGS_READ) 177#define BIO_should_read(a) ((a)->flags & BIO_FLAGS_READ)
222#define BIO_should_write(a) BIO_test_flags(a, BIO_FLAGS_WRITE) 178#define BIO_should_write(a) ((a)->flags & BIO_FLAGS_WRITE)
223#define BIO_should_io_special(a) BIO_test_flags(a, BIO_FLAGS_IO_SPECIAL) 179#define BIO_should_io_special(a) ((a)->flags & BIO_FLAGS_IO_SPECIAL)
224#define BIO_retry_type(a) BIO_test_flags(a, BIO_FLAGS_RWS) 180#define BIO_retry_type(a) ((a)->flags & BIO_FLAGS_RWS)
225#define BIO_should_retry(a) BIO_test_flags(a, BIO_FLAGS_SHOULD_RETRY) 181#define BIO_should_retry(a) ((a)->flags & BIO_FLAGS_SHOULD_RETRY)
226 182
227/* The next three are used in conjunction with the 183/* The next three are used in conjunction with the
228 * BIO_should_io_special() condition. After this returns true, 184 * BIO_should_io_special() condition. After this returns true,
@@ -251,14 +207,14 @@ void BIO_clear_flags(BIO *b, int flags);
251#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN)) 207#define BIO_cb_pre(a) (!((a)&BIO_CB_RETURN))
252#define BIO_cb_post(a) ((a)&BIO_CB_RETURN) 208#define BIO_cb_post(a) ((a)&BIO_CB_RETURN)
253 209
254long (*BIO_get_callback(const BIO *b)) (struct bio_st *,int,const char *,int, long,long); 210#define BIO_set_callback(b,cb) ((b)->callback=(cb))
255void BIO_set_callback(BIO *b, 211#define BIO_set_callback_arg(b,arg) ((b)->cb_arg=(char *)(arg))
256 long (*callback)(struct bio_st *,int,const char *,int, long,long)); 212#define BIO_get_callback_arg(b) ((b)->cb_arg)
257char *BIO_get_callback_arg(const BIO *b); 213#define BIO_get_callback(b) ((b)->callback)
258void BIO_set_callback_arg(BIO *b, char *arg); 214#define BIO_method_name(b) ((b)->method->name)
215#define BIO_method_type(b) ((b)->method->type)
259 216
260const char * BIO_method_name(const BIO *b); 217typedef struct bio_st BIO;
261int BIO_method_type(const BIO *b);
262 218
263typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long); 219typedef void bio_info_cb(struct bio_st *, int, const char *, int, long, long);
264 220
@@ -532,18 +488,6 @@ size_t BIO_ctrl_get_write_guarantee(BIO *b);
532size_t BIO_ctrl_get_read_request(BIO *b); 488size_t BIO_ctrl_get_read_request(BIO *b);
533int BIO_ctrl_reset_read_request(BIO *b); 489int BIO_ctrl_reset_read_request(BIO *b);
534 490
535/* ctrl macros for dgram */
536#define BIO_ctrl_dgram_connect(b,peer) \
537 (int)BIO_ctrl(b,BIO_CTRL_DGRAM_CONNECT,0, (char *)peer)
538#define BIO_ctrl_set_connected(b, state, peer) \
539 (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_CONNECTED, state, (char *)peer)
540#define BIO_dgram_recv_timedout(b) \
541 (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_RECV_TIMER_EXP, 0, NULL)
542#define BIO_dgram_send_timedout(b) \
543 (int)BIO_ctrl(b, BIO_CTRL_DGRAM_GET_SEND_TIMER_EXP, 0, NULL)
544#define BIO_dgram_set_peer(b,peer) \
545 (int)BIO_ctrl(b, BIO_CTRL_DGRAM_SET_PEER, 0, (char *)peer)
546
547/* These two aren't currently implemented */ 491/* These two aren't currently implemented */
548/* int BIO_get_ex_num(BIO *bio); */ 492/* int BIO_get_ex_num(BIO *bio); */
549/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */ 493/* void BIO_set_ex_free_func(BIO *bio,int idx,void (*cb)()); */
@@ -623,28 +567,15 @@ BIO_METHOD *BIO_f_buffer(void);
623BIO_METHOD *BIO_f_linebuffer(void); 567BIO_METHOD *BIO_f_linebuffer(void);
624#endif 568#endif
625BIO_METHOD *BIO_f_nbio_test(void); 569BIO_METHOD *BIO_f_nbio_test(void);
626#ifndef OPENSSL_NO_DGRAM
627BIO_METHOD *BIO_s_datagram(void);
628#endif
629
630/* BIO_METHOD *BIO_f_ber(void); */ 570/* BIO_METHOD *BIO_f_ber(void); */
631 571
632int BIO_sock_should_retry(int i); 572int BIO_sock_should_retry(int i);
633int BIO_sock_non_fatal_error(int error); 573int BIO_sock_non_fatal_error(int error);
634int BIO_dgram_non_fatal_error(int error);
635
636int BIO_fd_should_retry(int i); 574int BIO_fd_should_retry(int i);
637int BIO_fd_non_fatal_error(int error); 575int BIO_fd_non_fatal_error(int error);
638int BIO_dump_cb(int (*cb)(const void *data, size_t len, void *u),
639 void *u, const char *s, int len);
640int BIO_dump_indent_cb(int (*cb)(const void *data, size_t len, void *u),
641 void *u, const char *s, int len, int indent);
642int BIO_dump(BIO *b,const char *bytes,int len); 576int BIO_dump(BIO *b,const char *bytes,int len);
643int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent); 577int BIO_dump_indent(BIO *b,const char *bytes,int len,int indent);
644#ifndef OPENSSL_NO_FP_API 578
645int BIO_dump_fp(FILE *fp, const char *s, int len);
646int BIO_dump_indent_fp(FILE *fp, const char *s, int len, int indent);
647#endif
648struct hostent *BIO_gethostbyname(const char *name); 579struct hostent *BIO_gethostbyname(const char *name);
649/* We might want a thread-safe interface too: 580/* We might want a thread-safe interface too:
650 * struct hostent *BIO_gethostbyname_r(const char *name, 581 * struct hostent *BIO_gethostbyname_r(const char *name,
@@ -666,7 +597,6 @@ void BIO_sock_cleanup(void);
666int BIO_set_tcp_ndelay(int sock,int turn_on); 597int BIO_set_tcp_ndelay(int sock,int turn_on);
667 598
668BIO *BIO_new_socket(int sock, int close_flag); 599BIO *BIO_new_socket(int sock, int close_flag);
669BIO *BIO_new_dgram(int fd, int close_flag);
670BIO *BIO_new_fd(int fd, int close_flag); 600BIO *BIO_new_fd(int fd, int close_flag);
671BIO *BIO_new_connect(char *host_port); 601BIO *BIO_new_connect(char *host_port);
672BIO *BIO_new_accept(char *host_port); 602BIO *BIO_new_accept(char *host_port);
@@ -682,20 +612,10 @@ void BIO_copy_next_retry(BIO *b);
682 612
683/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/ 613/*long BIO_ghbn_ctrl(int cmd,int iarg,char *parg);*/
684 614
685#ifdef __GNUC__ 615int BIO_printf(BIO *bio, const char *format, ...);
686# define __bio_h__attr__ __attribute__ 616int BIO_vprintf(BIO *bio, const char *format, va_list args);
687#else 617int BIO_snprintf(char *buf, size_t n, const char *format, ...);
688# define __bio_h__attr__(x) 618int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args);
689#endif
690int BIO_printf(BIO *bio, const char *format, ...)
691 __bio_h__attr__((__format__(__printf__,2,3)));
692int BIO_vprintf(BIO *bio, const char *format, va_list args)
693 __bio_h__attr__((__format__(__printf__,2,0)));
694int BIO_snprintf(char *buf, size_t n, const char *format, ...)
695 __bio_h__attr__((__format__(__printf__,3,4)));
696int BIO_vsnprintf(char *buf, size_t n, const char *format, va_list args)
697 __bio_h__attr__((__format__(__printf__,3,0)));
698#undef __bio_h__attr__
699 619
700/* BEGIN ERROR CODES */ 620/* BEGIN ERROR CODES */
701/* The following lines are auto generated by the script mkerr.pl. Any changes 621/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -709,7 +629,6 @@ void ERR_load_BIO_strings(void);
709#define BIO_F_ACPT_STATE 100 629#define BIO_F_ACPT_STATE 100
710#define BIO_F_BIO_ACCEPT 101 630#define BIO_F_BIO_ACCEPT 101
711#define BIO_F_BIO_BER_GET_HEADER 102 631#define BIO_F_BIO_BER_GET_HEADER 102
712#define BIO_F_BIO_CALLBACK_CTRL 131
713#define BIO_F_BIO_CTRL 103 632#define BIO_F_BIO_CTRL 103
714#define BIO_F_BIO_GETHOSTBYNAME 120 633#define BIO_F_BIO_GETHOSTBYNAME 120
715#define BIO_F_BIO_GETS 104 634#define BIO_F_BIO_GETS 104
diff --git a/src/lib/libcrypto/bio/bio_err.c b/src/lib/libcrypto/bio/bio_err.c
index 6603f1c74d..8859a58ae4 100644
--- a/src/lib/libcrypto/bio/bio_err.c
+++ b/src/lib/libcrypto/bio/bio_err.c
@@ -73,7 +73,6 @@ static ERR_STRING_DATA BIO_str_functs[]=
73{ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"}, 73{ERR_FUNC(BIO_F_ACPT_STATE), "ACPT_STATE"},
74{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"}, 74{ERR_FUNC(BIO_F_BIO_ACCEPT), "BIO_accept"},
75{ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"}, 75{ERR_FUNC(BIO_F_BIO_BER_GET_HEADER), "BIO_BER_GET_HEADER"},
76{ERR_FUNC(BIO_F_BIO_CALLBACK_CTRL), "BIO_callback_ctrl"},
77{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"}, 76{ERR_FUNC(BIO_F_BIO_CTRL), "BIO_ctrl"},
78{ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"}, 77{ERR_FUNC(BIO_F_BIO_GETHOSTBYNAME), "BIO_gethostbyname"},
79{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"}, 78{ERR_FUNC(BIO_F_BIO_GETS), "BIO_gets"},
@@ -143,12 +142,15 @@ static ERR_STRING_DATA BIO_str_reasons[]=
143 142
144void ERR_load_BIO_strings(void) 143void ERR_load_BIO_strings(void)
145 { 144 {
146#ifndef OPENSSL_NO_ERR 145 static int init=1;
147 146
148 if (ERR_func_error_string(BIO_str_functs[0].error) == NULL) 147 if (init)
149 { 148 {
149 init=0;
150#ifndef OPENSSL_NO_ERR
150 ERR_load_strings(0,BIO_str_functs); 151 ERR_load_strings(0,BIO_str_functs);
151 ERR_load_strings(0,BIO_str_reasons); 152 ERR_load_strings(0,BIO_str_reasons);
152 }
153#endif 153#endif
154
155 }
154 } 156 }
diff --git a/src/lib/libcrypto/bio/bio_lcl.h b/src/lib/libcrypto/bio/bio_lcl.h
new file mode 100644
index 0000000000..dba2919d43
--- /dev/null
+++ b/src/lib/libcrypto/bio/bio_lcl.h
@@ -0,0 +1,28 @@
1#include <openssl/bio.h>
2
3#if BIO_FLAGS_UPLINK==0
4/* Shortcut UPLINK calls on most platforms... */
5#define UP_stdin stdin
6#define UP_stdout stdout
7#define UP_stderr stderr
8#define UP_fprintf fprintf
9#define UP_fgets fgets
10#define UP_fread fread
11#define UP_fwrite fwrite
12#undef UP_fsetmod
13#define UP_feof feof
14#define UP_fclose fclose
15
16#define UP_fopen fopen
17#define UP_fseek fseek
18#define UP_ftell ftell
19#define UP_fflush fflush
20#define UP_ferror ferror
21#define UP_fileno fileno
22
23#define UP_open open
24#define UP_read read
25#define UP_write write
26#define UP_lseek lseek
27#define UP_close close
28#endif
diff --git a/src/lib/libcrypto/bio/bio_lib.c b/src/lib/libcrypto/bio/bio_lib.c
index 3f52ae953c..692c8fb5c6 100644
--- a/src/lib/libcrypto/bio/bio_lib.c
+++ b/src/lib/libcrypto/bio/bio_lib.c
@@ -141,56 +141,10 @@ int BIO_free(BIO *a)
141void BIO_vfree(BIO *a) 141void BIO_vfree(BIO *a)
142 { BIO_free(a); } 142 { BIO_free(a); }
143 143
144void BIO_clear_flags(BIO *b, int flags)
145 {
146 b->flags &= ~flags;
147 }
148
149int BIO_test_flags(const BIO *b, int flags)
150 {
151 return (b->flags & flags);
152 }
153
154void BIO_set_flags(BIO *b, int flags)
155 {
156 b->flags |= flags;
157 }
158
159long (*BIO_get_callback(const BIO *b))(struct bio_st *,int,const char *,int, long,long)
160 {
161 return b->callback;
162 }
163
164void BIO_set_callback(BIO *b, long (*cb)(struct bio_st *,int,const char *,int, long,long))
165 {
166 b->callback = cb;
167 }
168
169void BIO_set_callback_arg(BIO *b, char *arg)
170 {
171 b->cb_arg = arg;
172 }
173
174char * BIO_get_callback_arg(const BIO *b)
175 {
176 return b->cb_arg;
177 }
178
179const char * BIO_method_name(const BIO *b)
180 {
181 return b->method->name;
182 }
183
184int BIO_method_type(const BIO *b)
185 {
186 return b->method->type;
187 }
188
189
190int BIO_read(BIO *b, void *out, int outl) 144int BIO_read(BIO *b, void *out, int outl)
191 { 145 {
192 int i; 146 int i;
193 long (*cb)(BIO *,int,const char *,int,long,long); 147 long (*cb)();
194 148
195 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL)) 149 if ((b == NULL) || (b->method == NULL) || (b->method->bread == NULL))
196 { 150 {
@@ -222,7 +176,7 @@ int BIO_read(BIO *b, void *out, int outl)
222int BIO_write(BIO *b, const void *in, int inl) 176int BIO_write(BIO *b, const void *in, int inl)
223 { 177 {
224 int i; 178 int i;
225 long (*cb)(BIO *,int,const char *,int,long,long); 179 long (*cb)();
226 180
227 if (b == NULL) 181 if (b == NULL)
228 return(0); 182 return(0);
@@ -257,7 +211,7 @@ int BIO_write(BIO *b, const void *in, int inl)
257int BIO_puts(BIO *b, const char *in) 211int BIO_puts(BIO *b, const char *in)
258 { 212 {
259 int i; 213 int i;
260 long (*cb)(BIO *,int,const char *,int,long,long); 214 long (*cb)();
261 215
262 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL)) 216 if ((b == NULL) || (b->method == NULL) || (b->method->bputs == NULL))
263 { 217 {
@@ -290,7 +244,7 @@ int BIO_puts(BIO *b, const char *in)
290int BIO_gets(BIO *b, char *in, int inl) 244int BIO_gets(BIO *b, char *in, int inl)
291 { 245 {
292 int i; 246 int i;
293 long (*cb)(BIO *,int,const char *,int,long,long); 247 long (*cb)();
294 248
295 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL)) 249 if ((b == NULL) || (b->method == NULL) || (b->method->bgets == NULL))
296 { 250 {
@@ -351,7 +305,7 @@ char *BIO_ptr_ctrl(BIO *b, int cmd, long larg)
351long BIO_ctrl(BIO *b, int cmd, long larg, void *parg) 305long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
352 { 306 {
353 long ret; 307 long ret;
354 long (*cb)(BIO *,int,const char *,int,long,long); 308 long (*cb)();
355 309
356 if (b == NULL) return(0); 310 if (b == NULL) return(0);
357 311
@@ -378,13 +332,13 @@ long BIO_ctrl(BIO *b, int cmd, long larg, void *parg)
378long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long)) 332long BIO_callback_ctrl(BIO *b, int cmd, void (*fp)(struct bio_st *, int, const char *, int, long, long))
379 { 333 {
380 long ret; 334 long ret;
381 long (*cb)(BIO *,int,const char *,int,long,long); 335 long (*cb)();
382 336
383 if (b == NULL) return(0); 337 if (b == NULL) return(0);
384 338
385 if ((b->method == NULL) || (b->method->callback_ctrl == NULL)) 339 if ((b->method == NULL) || (b->method->callback_ctrl == NULL))
386 { 340 {
387 BIOerr(BIO_F_BIO_CALLBACK_CTRL,BIO_R_UNSUPPORTED_METHOD); 341 BIOerr(BIO_F_BIO_CTRL,BIO_R_UNSUPPORTED_METHOD);
388 return(-2); 342 return(-2);
389 } 343 }
390 344
diff --git a/src/lib/libcrypto/bio/bss_acpt.c b/src/lib/libcrypto/bio/bss_acpt.c
index d090b7272f..8ea1db158b 100644
--- a/src/lib/libcrypto/bio/bss_acpt.c
+++ b/src/lib/libcrypto/bio/bss_acpt.c
@@ -56,14 +56,14 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SOCK
60
59#include <stdio.h> 61#include <stdio.h>
60#include <errno.h> 62#include <errno.h>
61#define USE_SOCKETS 63#define USE_SOCKETS
62#include "cryptlib.h" 64#include "cryptlib.h"
63#include <openssl/bio.h> 65#include <openssl/bio.h>
64 66
65#ifndef OPENSSL_NO_SOCK
66
67#ifdef OPENSSL_SYS_WIN16 67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else 69#else
diff --git a/src/lib/libcrypto/bio/bss_conn.c b/src/lib/libcrypto/bio/bss_conn.c
index c14727855b..216780ed5e 100644
--- a/src/lib/libcrypto/bio/bss_conn.c
+++ b/src/lib/libcrypto/bio/bss_conn.c
@@ -56,14 +56,14 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SOCK
60
59#include <stdio.h> 61#include <stdio.h>
60#include <errno.h> 62#include <errno.h>
61#define USE_SOCKETS 63#define USE_SOCKETS
62#include "cryptlib.h" 64#include "cryptlib.h"
63#include <openssl/bio.h> 65#include <openssl/bio.h>
64 66
65#ifndef OPENSSL_NO_SOCK
66
67#ifdef OPENSSL_SYS_WIN16 67#ifdef OPENSSL_SYS_WIN16
68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */ 68#define SOCKET_PROTOCOL 0 /* more microsoft stupidity */
69#else 69#else
@@ -130,7 +130,7 @@ static int conn_state(BIO *b, BIO_CONNECT *c)
130 int ret= -1,i; 130 int ret= -1,i;
131 unsigned long l; 131 unsigned long l;
132 char *p,*q; 132 char *p,*q;
133 int (*cb)(const BIO *,int,int)=NULL; 133 int (*cb)()=NULL;
134 134
135 if (c->info_callback != NULL) 135 if (c->info_callback != NULL)
136 cb=c->info_callback; 136 cb=c->info_callback;
@@ -590,9 +590,9 @@ static long conn_ctrl(BIO *b, int cmd, long num, void *ptr)
590 break; 590 break;
591 case BIO_CTRL_GET_CALLBACK: 591 case BIO_CTRL_GET_CALLBACK:
592 { 592 {
593 int (**fptr)(const BIO *bio,int state,int xret); 593 int (**fptr)();
594 594
595 fptr=(int (**)(const BIO *bio,int state,int xret))ptr; 595 fptr=(int (**)())ptr;
596 *fptr=data->info_callback; 596 *fptr=data->info_callback;
597 } 597 }
598 break; 598 break;
diff --git a/src/lib/libcrypto/bio/bss_fd.c b/src/lib/libcrypto/bio/bss_fd.c
index 4c229bf641..5e3e187de6 100644
--- a/src/lib/libcrypto/bio/bss_fd.c
+++ b/src/lib/libcrypto/bio/bss_fd.c
@@ -60,19 +60,7 @@
60#include <errno.h> 60#include <errno.h>
61#define USE_SOCKETS 61#define USE_SOCKETS
62#include "cryptlib.h" 62#include "cryptlib.h"
63/* 63#include <openssl/bio.h>
64 * As for unconditional usage of "UPLINK" interface in this module.
65 * Trouble is that unlike Unix file descriptors [which are indexes
66 * in kernel-side per-process table], corresponding descriptors on
67 * platforms which require "UPLINK" interface seem to be indexes
68 * in a user-land, non-global table. Well, in fact they are indexes
69 * in stdio _iob[], and recall that _iob[] was the very reason why
70 * "UPLINK" interface was introduced in first place. But one way on
71 * another. Neither libcrypto or libssl use this BIO meaning that
72 * file descriptors can only be provided by application. Therefore
73 * "UPLINK" calls are due...
74 */
75#include "bio_lcl.h"
76 64
77static int fd_write(BIO *h, const char *buf, int num); 65static int fd_write(BIO *h, const char *buf, int num);
78static int fd_read(BIO *h, char *buf, int size); 66static int fd_read(BIO *h, char *buf, int size);
@@ -112,9 +100,9 @@ BIO *BIO_new_fd(int fd,int close_flag)
112static int fd_new(BIO *bi) 100static int fd_new(BIO *bi)
113 { 101 {
114 bi->init=0; 102 bi->init=0;
115 bi->num=-1; 103 bi->num=0;
116 bi->ptr=NULL; 104 bi->ptr=NULL;
117 bi->flags=BIO_FLAGS_UPLINK; /* essentially redundant */ 105 bi->flags=0;
118 return(1); 106 return(1);
119 } 107 }
120 108
@@ -125,10 +113,10 @@ static int fd_free(BIO *a)
125 { 113 {
126 if (a->init) 114 if (a->init)
127 { 115 {
128 UP_close(a->num); 116 close(a->num);
129 } 117 }
130 a->init=0; 118 a->init=0;
131 a->flags=BIO_FLAGS_UPLINK; 119 a->flags=0;
132 } 120 }
133 return(1); 121 return(1);
134 } 122 }
@@ -140,7 +128,7 @@ static int fd_read(BIO *b, char *out,int outl)
140 if (out != NULL) 128 if (out != NULL)
141 { 129 {
142 clear_sys_error(); 130 clear_sys_error();
143 ret=UP_read(b->num,out,outl); 131 ret=read(b->num,out,outl);
144 BIO_clear_retry_flags(b); 132 BIO_clear_retry_flags(b);
145 if (ret <= 0) 133 if (ret <= 0)
146 { 134 {
@@ -155,7 +143,7 @@ static int fd_write(BIO *b, const char *in, int inl)
155 { 143 {
156 int ret; 144 int ret;
157 clear_sys_error(); 145 clear_sys_error();
158 ret=UP_write(b->num,in,inl); 146 ret=write(b->num,in,inl);
159 BIO_clear_retry_flags(b); 147 BIO_clear_retry_flags(b);
160 if (ret <= 0) 148 if (ret <= 0)
161 { 149 {
@@ -175,11 +163,11 @@ static long fd_ctrl(BIO *b, int cmd, long num, void *ptr)
175 case BIO_CTRL_RESET: 163 case BIO_CTRL_RESET:
176 num=0; 164 num=0;
177 case BIO_C_FILE_SEEK: 165 case BIO_C_FILE_SEEK:
178 ret=(long)UP_lseek(b->num,num,0); 166 ret=(long)lseek(b->num,num,0);
179 break; 167 break;
180 case BIO_C_FILE_TELL: 168 case BIO_C_FILE_TELL:
181 case BIO_CTRL_INFO: 169 case BIO_CTRL_INFO:
182 ret=(long)UP_lseek(b->num,0,1); 170 ret=(long)lseek(b->num,0,1);
183 break; 171 break;
184 case BIO_C_SET_FD: 172 case BIO_C_SET_FD:
185 fd_free(b); 173 fd_free(b);
diff --git a/src/lib/libcrypto/bio/bss_file.c b/src/lib/libcrypto/bio/bss_file.c
index 4df9927c43..58fade9f29 100644
--- a/src/lib/libcrypto/bio/bss_file.c
+++ b/src/lib/libcrypto/bio/bss_file.c
@@ -65,34 +65,12 @@
65#ifndef HEADER_BSS_FILE_C 65#ifndef HEADER_BSS_FILE_C
66#define HEADER_BSS_FILE_C 66#define HEADER_BSS_FILE_C
67 67
68#if defined(__linux) || defined(__sun) || defined(__hpux)
69/* Following definition aliases fopen to fopen64 on above mentioned
70 * platforms. This makes it possible to open and sequentially access
71 * files larger than 2GB from 32-bit application. It does not allow to
72 * traverse them beyond 2GB with fseek/ftell, but on the other hand *no*
73 * 32-bit platform permits that, not with fseek/ftell. Not to mention
74 * that breaking 2GB limit for seeking would require surgery to *our*
75 * API. But sequential access suffices for practical cases when you
76 * can run into large files, such as fingerprinting, so we can let API
77 * alone. For reference, the list of 32-bit platforms which allow for
78 * sequential access of large files without extra "magic" comprise *BSD,
79 * Darwin, IRIX...
80 */
81#ifndef _FILE_OFFSET_BITS
82#define _FILE_OFFSET_BITS 64
83#endif
84#endif
85
86#include <stdio.h> 68#include <stdio.h>
87#include <errno.h> 69#include <errno.h>
88#include "cryptlib.h" 70#include "cryptlib.h"
89#include "bio_lcl.h" 71#include <openssl/bio.h>
90#include <openssl/err.h> 72#include <openssl/err.h>
91 73
92#if defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
93#include <nwfileio.h>
94#endif
95
96#if !defined(OPENSSL_NO_STDIO) 74#if !defined(OPENSSL_NO_STDIO)
97 75
98static int MS_CALLBACK file_write(BIO *h, const char *buf, int num); 76static int MS_CALLBACK file_write(BIO *h, const char *buf, int num);
@@ -132,12 +110,8 @@ BIO *BIO_new_file(const char *filename, const char *mode)
132 return(NULL); 110 return(NULL);
133 } 111 }
134 if ((ret=BIO_new(BIO_s_file_internal())) == NULL) 112 if ((ret=BIO_new(BIO_s_file_internal())) == NULL)
135 {
136 fclose(file);
137 return(NULL); 113 return(NULL);
138 }
139 114
140 BIO_clear_flags(ret,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
141 BIO_set_fp(ret,file,BIO_CLOSE); 115 BIO_set_fp(ret,file,BIO_CLOSE);
142 return(ret); 116 return(ret);
143 } 117 }
@@ -149,7 +123,6 @@ BIO *BIO_new_fp(FILE *stream, int close_flag)
149 if ((ret=BIO_new(BIO_s_file())) == NULL) 123 if ((ret=BIO_new(BIO_s_file())) == NULL)
150 return(NULL); 124 return(NULL);
151 125
152 BIO_set_flags(ret,BIO_FLAGS_UPLINK); /* redundant, left for documentation puposes */
153 BIO_set_fp(ret,stream,close_flag); 126 BIO_set_fp(ret,stream,close_flag);
154 return(ret); 127 return(ret);
155 } 128 }
@@ -164,7 +137,6 @@ static int MS_CALLBACK file_new(BIO *bi)
164 bi->init=0; 137 bi->init=0;
165 bi->num=0; 138 bi->num=0;
166 bi->ptr=NULL; 139 bi->ptr=NULL;
167 bi->flags=BIO_FLAGS_UPLINK; /* default to UPLINK */
168 return(1); 140 return(1);
169 } 141 }
170 142
@@ -175,12 +147,8 @@ static int MS_CALLBACK file_free(BIO *a)
175 { 147 {
176 if ((a->init) && (a->ptr != NULL)) 148 if ((a->init) && (a->ptr != NULL))
177 { 149 {
178 if (a->flags&BIO_FLAGS_UPLINK) 150 fclose((FILE *)a->ptr);
179 UP_fclose (a->ptr);
180 else
181 fclose (a->ptr);
182 a->ptr=NULL; 151 a->ptr=NULL;
183 a->flags=BIO_FLAGS_UPLINK;
184 } 152 }
185 a->init=0; 153 a->init=0;
186 } 154 }
@@ -193,11 +161,8 @@ static int MS_CALLBACK file_read(BIO *b, char *out, int outl)
193 161
194 if (b->init && (out != NULL)) 162 if (b->init && (out != NULL))
195 { 163 {
196 if (b->flags&BIO_FLAGS_UPLINK) 164 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
197 ret=UP_fread(out,1,(int)outl,b->ptr); 165 if(ret == 0 && ferror((FILE *)b->ptr))
198 else
199 ret=fread(out,1,(int)outl,(FILE *)b->ptr);
200 if(ret == 0 && (b->flags&BIO_FLAGS_UPLINK)?UP_ferror((FILE *)b->ptr):ferror((FILE *)b->ptr))
201 { 166 {
202 SYSerr(SYS_F_FREAD,get_last_sys_error()); 167 SYSerr(SYS_F_FREAD,get_last_sys_error());
203 BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB); 168 BIOerr(BIO_F_FILE_READ,ERR_R_SYS_LIB);
@@ -213,11 +178,7 @@ static int MS_CALLBACK file_write(BIO *b, const char *in, int inl)
213 178
214 if (b->init && (in != NULL)) 179 if (b->init && (in != NULL))
215 { 180 {
216 if (b->flags&BIO_FLAGS_UPLINK) 181 if (fwrite(in,(int)inl,1,(FILE *)b->ptr))
217 ret=UP_fwrite(in,(int)inl,1,b->ptr);
218 else
219 ret=fwrite(in,(int)inl,1,(FILE *)b->ptr);
220 if (ret)
221 ret=inl; 182 ret=inl;
222 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */ 183 /* ret=fwrite(in,1,(int)inl,(FILE *)b->ptr); */
223 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented 184 /* according to Tim Hudson <tjh@cryptsoft.com>, the commented
@@ -238,45 +199,20 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
238 { 199 {
239 case BIO_C_FILE_SEEK: 200 case BIO_C_FILE_SEEK:
240 case BIO_CTRL_RESET: 201 case BIO_CTRL_RESET:
241 if (b->flags&BIO_FLAGS_UPLINK) 202 ret=(long)fseek(fp,num,SEEK_SET);
242 ret=(long)UP_fseek(b->ptr,num,0);
243 else
244 ret=(long)fseek(fp,num,0);
245 break; 203 break;
246 case BIO_CTRL_EOF: 204 case BIO_CTRL_EOF:
247 if (b->flags&BIO_FLAGS_UPLINK) 205 ret=(long)feof(fp);
248 ret=(long)UP_feof(fp);
249 else
250 ret=(long)feof(fp);
251 break; 206 break;
252 case BIO_C_FILE_TELL: 207 case BIO_C_FILE_TELL:
253 case BIO_CTRL_INFO: 208 case BIO_CTRL_INFO:
254 if (b->flags&BIO_FLAGS_UPLINK) 209 ret=ftell(fp);
255 ret=UP_ftell(b->ptr);
256 else
257 ret=ftell(fp);
258 break; 210 break;
259 case BIO_C_SET_FILE_PTR: 211 case BIO_C_SET_FILE_PTR:
260 file_free(b); 212 file_free(b);
261 b->shutdown=(int)num&BIO_CLOSE; 213 b->shutdown=(int)num&BIO_CLOSE;
262 b->ptr=ptr; 214 b->ptr=(char *)ptr;
263 b->init=1; 215 b->init=1;
264#if BIO_FLAGS_UPLINK!=0
265#if defined(__MINGW32__) && defined(__MSVCRT__) && !defined(_IOB_ENTRIES)
266#define _IOB_ENTRIES 20
267#endif
268#if defined(_IOB_ENTRIES)
269 /* Safety net to catch purely internal BIO_set_fp calls */
270 if ((size_t)ptr >= (size_t)stdin &&
271 (size_t)ptr < (size_t)(stdin+_IOB_ENTRIES))
272 BIO_clear_flags(b,BIO_FLAGS_UPLINK);
273#endif
274#endif
275#ifdef UP_fsetmode
276 if (b->flags&BIO_FLAGS_UPLINK)
277 UP_fsetmode(b->ptr,num&BIO_FP_TEXT?'t':'b');
278 else
279#endif
280 { 216 {
281#if defined(OPENSSL_SYS_WINDOWS) 217#if defined(OPENSSL_SYS_WINDOWS)
282 int fd = fileno((FILE*)ptr); 218 int fd = fileno((FILE*)ptr);
@@ -284,14 +220,6 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
284 _setmode(fd,_O_TEXT); 220 _setmode(fd,_O_TEXT);
285 else 221 else
286 _setmode(fd,_O_BINARY); 222 _setmode(fd,_O_BINARY);
287#elif defined(OPENSSL_SYS_NETWARE) && defined(NETWARE_CLIB)
288 int fd = fileno((FILE*)ptr);
289 /* Under CLib there are differences in file modes
290 */
291 if (num & BIO_FP_TEXT)
292 setmode(fd,O_TEXT);
293 else
294 setmode(fd,O_BINARY);
295#elif defined(OPENSSL_SYS_MSDOS) 223#elif defined(OPENSSL_SYS_MSDOS)
296 int fd = fileno((FILE*)ptr); 224 int fd = fileno((FILE*)ptr);
297 /* Set correct text/binary mode */ 225 /* Set correct text/binary mode */
@@ -344,12 +272,6 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
344 else 272 else
345 strcat(p,"t"); 273 strcat(p,"t");
346#endif 274#endif
347#if defined(OPENSSL_SYS_NETWARE)
348 if (!(num & BIO_FP_TEXT))
349 strcat(p,"b");
350 else
351 strcat(p,"t");
352#endif
353 fp=fopen(ptr,p); 275 fp=fopen(ptr,p);
354 if (fp == NULL) 276 if (fp == NULL)
355 { 277 {
@@ -359,9 +281,8 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
359 ret=0; 281 ret=0;
360 break; 282 break;
361 } 283 }
362 b->ptr=fp; 284 b->ptr=(char *)fp;
363 b->init=1; 285 b->init=1;
364 BIO_clear_flags(b,BIO_FLAGS_UPLINK); /* we did fopen -> we disengage UPLINK */
365 break; 286 break;
366 case BIO_C_GET_FILE_PTR: 287 case BIO_C_GET_FILE_PTR:
367 /* the ptr parameter is actually a FILE ** in this case. */ 288 /* the ptr parameter is actually a FILE ** in this case. */
@@ -378,10 +299,7 @@ static long MS_CALLBACK file_ctrl(BIO *b, int cmd, long num, void *ptr)
378 b->shutdown=(int)num; 299 b->shutdown=(int)num;
379 break; 300 break;
380 case BIO_CTRL_FLUSH: 301 case BIO_CTRL_FLUSH:
381 if (b->flags&BIO_FLAGS_UPLINK) 302 fflush((FILE *)b->ptr);
382 UP_fflush(b->ptr);
383 else
384 fflush((FILE *)b->ptr);
385 break; 303 break;
386 case BIO_CTRL_DUP: 304 case BIO_CTRL_DUP:
387 ret=1; 305 ret=1;
@@ -403,10 +321,7 @@ static int MS_CALLBACK file_gets(BIO *bp, char *buf, int size)
403 int ret=0; 321 int ret=0;
404 322
405 buf[0]='\0'; 323 buf[0]='\0';
406 if (bp->flags&BIO_FLAGS_UPLINK) 324 fgets(buf,size,(FILE *)bp->ptr);
407 UP_fgets(buf,size,bp->ptr);
408 else
409 fgets(buf,size,(FILE *)bp->ptr);
410 if (buf[0] != '\0') 325 if (buf[0] != '\0')
411 ret=strlen(buf); 326 ret=strlen(buf);
412 return(ret); 327 return(ret);
diff --git a/src/lib/libcrypto/bio/bss_log.c b/src/lib/libcrypto/bio/bss_log.c
index 6360dbc820..1eb678cac0 100644
--- a/src/lib/libcrypto/bio/bss_log.c
+++ b/src/lib/libcrypto/bio/bss_log.c
@@ -78,8 +78,6 @@
78# include <starlet.h> 78# include <starlet.h>
79#elif defined(__ultrix) 79#elif defined(__ultrix)
80# include <sys/syslog.h> 80# include <sys/syslog.h>
81#elif defined(OPENSSL_SYS_NETWARE)
82# define NO_SYSLOG
83#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG) 81#elif (!defined(MSDOS) || defined(WATT32)) && !defined(OPENSSL_SYS_VXWORKS) && !defined(NO_SYSLOG)
84# include <syslog.h> 82# include <syslog.h>
85#endif 83#endif
diff --git a/src/lib/libcrypto/bio/bss_rtcp.c b/src/lib/libcrypto/bio/bss_rtcp.c
new file mode 100644
index 0000000000..7dae485564
--- /dev/null
+++ b/src/lib/libcrypto/bio/bss_rtcp.c
@@ -0,0 +1,294 @@
1/* crypto/bio/bss_rtcp.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Written by David L. Jones <jonesd@kcgl1.eng.ohio-state.edu>
60 * Date: 22-JUL-1996
61 * Revised: 25-SEP-1997 Update for 0.8.1, BIO_CTRL_SET -> BIO_C_SET_FD
62 */
63/* VMS */
64#include <stdio.h>
65#include <stdlib.h>
66#include <string.h>
67#include <errno.h>
68#include "cryptlib.h"
69#include <openssl/bio.h>
70
71#include <iodef.h> /* VMS IO$_ definitions */
72#include <starlet.h>
73
74typedef unsigned short io_channel;
75/*************************************************************************/
76struct io_status { short status, count; long flags; };
77
78struct rpc_msg { /* Should have member alignment inhibited */
79 char channel; /* 'A'-app data. 'R'-remote client 'G'-global */
80 char function; /* 'G'-get, 'P'-put, 'C'-confirm, 'X'-close */
81 unsigned short int length; /* Amount of data returned or max to return */
82 char data[4092]; /* variable data */
83};
84#define RPC_HDR_SIZE (sizeof(struct rpc_msg) - 4092)
85
86struct rpc_ctx {
87 int filled, pos;
88 struct rpc_msg msg;
89};
90
91static int rtcp_write(BIO *h,const char *buf,int num);
92static int rtcp_read(BIO *h,char *buf,int size);
93static int rtcp_puts(BIO *h,const char *str);
94static int rtcp_gets(BIO *h,char *str,int size);
95static long rtcp_ctrl(BIO *h,int cmd,long arg1,void *arg2);
96static int rtcp_new(BIO *h);
97static int rtcp_free(BIO *data);
98
99static BIO_METHOD rtcp_method=
100 {
101 BIO_TYPE_FD,
102 "RTCP",
103 rtcp_write,
104 rtcp_read,
105 rtcp_puts,
106 rtcp_gets,
107 rtcp_ctrl,
108 rtcp_new,
109 rtcp_free,
110 NULL,
111 };
112
113BIO_METHOD *BIO_s_rtcp(void)
114 {
115 return(&rtcp_method);
116 }
117/*****************************************************************************/
118/* Decnet I/O routines.
119 */
120
121#ifdef __DECC
122#pragma message save
123#pragma message disable DOLLARID
124#endif
125
126static int get ( io_channel chan, char *buffer, int maxlen, int *length )
127{
128 int status;
129 struct io_status iosb;
130 status = sys$qiow ( 0, chan, IO$_READVBLK, &iosb, 0, 0,
131 buffer, maxlen, 0, 0, 0, 0 );
132 if ( (status&1) == 1 ) status = iosb.status;
133 if ( (status&1) == 1 ) *length = iosb.count;
134 return status;
135}
136
137static int put ( io_channel chan, char *buffer, int length )
138{
139 int status;
140 struct io_status iosb;
141 status = sys$qiow ( 0, chan, IO$_WRITEVBLK, &iosb, 0, 0,
142 buffer, length, 0, 0, 0, 0 );
143 if ( (status&1) == 1 ) status = iosb.status;
144 return status;
145}
146
147#ifdef __DECC
148#pragma message restore
149#endif
150
151/***************************************************************************/
152
153static int rtcp_new(BIO *bi)
154{
155 struct rpc_ctx *ctx;
156 bi->init=1;
157 bi->num=0;
158 bi->flags = 0;
159 bi->ptr=OPENSSL_malloc(sizeof(struct rpc_ctx));
160 ctx = (struct rpc_ctx *) bi->ptr;
161 ctx->filled = 0;
162 ctx->pos = 0;
163 return(1);
164}
165
166static int rtcp_free(BIO *a)
167{
168 if (a == NULL) return(0);
169 if ( a->ptr ) OPENSSL_free ( a->ptr );
170 a->ptr = NULL;
171 return(1);
172}
173
174static int rtcp_read(BIO *b, char *out, int outl)
175{
176 int status, length;
177 struct rpc_ctx *ctx;
178 /*
179 * read data, return existing.
180 */
181 ctx = (struct rpc_ctx *) b->ptr;
182 if ( ctx->pos < ctx->filled ) {
183 length = ctx->filled - ctx->pos;
184 if ( length > outl ) length = outl;
185 memmove ( out, &ctx->msg.data[ctx->pos], length );
186 ctx->pos += length;
187 return length;
188 }
189 /*
190 * Requst more data from R channel.
191 */
192 ctx->msg.channel = 'R';
193 ctx->msg.function = 'G';
194 ctx->msg.length = sizeof(ctx->msg.data);
195 status = put ( b->num, (char *) &ctx->msg, RPC_HDR_SIZE );
196 if ( (status&1) == 0 ) {
197 return -1;
198 }
199 /*
200 * Read.
201 */
202 ctx->pos = ctx->filled = 0;
203 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
204 if ( (status&1) == 0 ) length = -1;
205 if ( ctx->msg.channel != 'R' || ctx->msg.function != 'C' ) {
206 length = -1;
207 }
208 ctx->filled = length - RPC_HDR_SIZE;
209
210 if ( ctx->pos < ctx->filled ) {
211 length = ctx->filled - ctx->pos;
212 if ( length > outl ) length = outl;
213 memmove ( out, ctx->msg.data, length );
214 ctx->pos += length;
215 return length;
216 }
217
218 return length;
219}
220
221static int rtcp_write(BIO *b, const char *in, int inl)
222{
223 int status, i, segment, length;
224 struct rpc_ctx *ctx;
225 /*
226 * Output data, send in chunks no larger that sizeof(ctx->msg.data).
227 */
228 ctx = (struct rpc_ctx *) b->ptr;
229 for ( i = 0; i < inl; i += segment ) {
230 segment = inl - i;
231 if ( segment > sizeof(ctx->msg.data) ) segment = sizeof(ctx->msg.data);
232 ctx->msg.channel = 'R';
233 ctx->msg.function = 'P';
234 ctx->msg.length = segment;
235 memmove ( ctx->msg.data, &in[i], segment );
236 status = put ( b->num, (char *) &ctx->msg, segment + RPC_HDR_SIZE );
237 if ((status&1) == 0 ) { i = -1; break; }
238
239 status = get ( b->num, (char *) &ctx->msg, sizeof(ctx->msg), &length );
240 if ( ((status&1) == 0) || (length < RPC_HDR_SIZE) ) { i = -1; break; }
241 if ( (ctx->msg.channel != 'R') || (ctx->msg.function != 'C') ) {
242 printf("unexpected response when confirming put %c %c\n",
243 ctx->msg.channel, ctx->msg.function );
244
245 }
246 }
247 return(i);
248}
249
250static long rtcp_ctrl(BIO *b, int cmd, long num, void *ptr)
251 {
252 long ret=1;
253
254 switch (cmd)
255 {
256 case BIO_CTRL_RESET:
257 case BIO_CTRL_EOF:
258 ret = 1;
259 break;
260 case BIO_C_SET_FD:
261 b->num = num;
262 ret = 1;
263 break;
264 case BIO_CTRL_SET_CLOSE:
265 case BIO_CTRL_FLUSH:
266 case BIO_CTRL_DUP:
267 ret=1;
268 break;
269 case BIO_CTRL_GET_CLOSE:
270 case BIO_CTRL_INFO:
271 case BIO_CTRL_GET:
272 case BIO_CTRL_PENDING:
273 case BIO_CTRL_WPENDING:
274 default:
275 ret=0;
276 break;
277 }
278 return(ret);
279 }
280
281static int rtcp_gets(BIO *bp, char *buf, int size)
282 {
283 return(0);
284 }
285
286static int rtcp_puts(BIO *bp, const char *str)
287{
288 int length;
289 if (str == NULL) return(0);
290 length = strlen ( str );
291 if ( length == 0 ) return (0);
292 return rtcp_write ( bp,str, length );
293}
294
diff --git a/src/lib/libcrypto/bio/bss_sock.c b/src/lib/libcrypto/bio/bss_sock.c
index 472dd75821..2c1c405ec7 100644
--- a/src/lib/libcrypto/bio/bss_sock.c
+++ b/src/lib/libcrypto/bio/bss_sock.c
@@ -56,6 +56,8 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SOCK
60
59#include <stdio.h> 61#include <stdio.h>
60#include <errno.h> 62#include <errno.h>
61#define USE_SOCKETS 63#define USE_SOCKETS
@@ -246,7 +248,7 @@ int BIO_sock_non_fatal_error(int err)
246 { 248 {
247 switch (err) 249 switch (err)
248 { 250 {
249#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_NETWARE) 251#if defined(OPENSSL_SYS_WINDOWS)
250# if defined(WSAEWOULDBLOCK) 252# if defined(WSAEWOULDBLOCK)
251 case WSAEWOULDBLOCK: 253 case WSAEWOULDBLOCK:
252# endif 254# endif
@@ -277,7 +279,7 @@ int BIO_sock_non_fatal_error(int err)
277#endif 279#endif
278 280
279#ifdef EAGAIN 281#ifdef EAGAIN
280# if EWOULDBLOCK != EAGAIN 282#if EWOULDBLOCK != EAGAIN
281 case EAGAIN: 283 case EAGAIN:
282# endif 284# endif
283#endif 285#endif
@@ -300,3 +302,4 @@ int BIO_sock_non_fatal_error(int err)
300 } 302 }
301 return(0); 303 return(0);
302 } 304 }
305#endif
diff --git a/src/lib/libcrypto/bn/Makefile b/src/lib/libcrypto/bn/Makefile
new file mode 100644
index 0000000000..e97c751390
--- /dev/null
+++ b/src/lib/libcrypto/bn/Makefile
@@ -0,0 +1,351 @@
1#
2# OpenSSL/crypto/bn/Makefile
3#
4
5DIR= bn
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES= -I.. -I$(TOP) -I../../include
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14BN_ASM= bn_asm.o
15# or use
16#BN_ASM= bn86-elf.o
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG)
20AFLAGS= $(ASFLAGS)
21
22GENERAL=Makefile
23TEST=bntest.c exptest.c
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
28 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
29 bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
30 bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c bn_gf2m.c bn_nist.c \
31 bn_depr.c bn_const.c
32
33LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
34 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
35 bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
36 bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o bn_gf2m.o bn_nist.o \
37 bn_depr.o bn_const.o
38
39SRC= $(LIBSRC)
40
41EXHEADER= bn.h
42HEADER= bn_lcl.h bn_prime.h $(EXHEADER)
43
44ALL= $(GENERAL) $(SRC) $(HEADER)
45
46top:
47 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
48
49all: lib
50
51bn_prime.h: bn_prime.pl
52 $(PERL) bn_prime.pl >bn_prime.h
53
54divtest: divtest.c ../../libcrypto.a
55 cc -I../../include divtest.c -o divtest ../../libcrypto.a
56
57bnbug: bnbug.c ../../libcrypto.a top
58 cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a
59
60lib: $(LIBOBJ)
61 $(AR) $(LIB) $(LIBOBJ)
62 $(RANLIB) $(LIB) || echo Never mind.
63 @touch lib
64
65# ELF
66bn86-elf.s: asm/bn-586.pl ../perlasm/x86asm.pl
67 (cd asm; $(PERL) bn-586.pl elf $(CFLAGS) > ../$@)
68co86-elf.s: asm/co-586.pl ../perlasm/x86asm.pl
69 (cd asm; $(PERL) co-586.pl elf $(CFLAGS) > ../$@)
70mo86-elf.s: asm/mo-586.pl ../perlasm/x86asm.pl
71 (cd asm; $(PERL) mo-586.pl elf $(CFLAGS) > ../$@)
72# COFF
73bn86-cof.s: asm/bn-586.pl ../perlasm/x86asm.pl
74 (cd asm; $(PERL) bn-586.pl coff $(CFLAGS) > ../$@)
75co86-cof.s: asm/co-586.pl ../perlasm/x86asm.pl
76 (cd asm; $(PERL) co-586.pl coff $(CFLAGS) > ../$@)
77mo86-cof.s: asm/mo-586.pl ../perlasm/x86asm.pl
78 (cd asm; $(PERL) mo-586.pl coff $(CFLAGS) > ../$@)
79# a.out
80bn86-out.s: asm/bn-586.pl ../perlasm/x86asm.pl
81 (cd asm; $(PERL) bn-586.pl a.out $(CFLAGS) > ../$@)
82co86-out.s: asm/co-586.pl ../perlasm/x86asm.pl
83 (cd asm; $(PERL) co-586.pl a.out $(CFLAGS) > ../$@)
84mo86-out.s: asm/mo-586.pl ../perlasm/x86asm.pl
85 (cd asm; $(PERL) mo-586.pl a.out $(CFLAGS) > ../$@)
86
87sparcv8.o: asm/sparcv8.S
88 $(CC) $(CFLAGS) -c asm/sparcv8.S
89sparcv8plus.o: asm/sparcv8plus.S
90 $(CC) $(CFLAGS) -c asm/sparcv8plus.S
91
92bn-mips3.o: asm/mips3.s
93 @if [ "$(CC)" = "gcc" ]; then \
94 ABI=`expr "$(CFLAGS)" : ".*-mabi=\([n3264]*\)"` && \
95 as -$$ABI -O -o $@ asm/mips3.s; \
96 else $(CC) -c $(CFLAGS) -o $@ asm/mips3.s; fi
97
98x86_64-gcc.o: asm/x86_64-gcc.c
99 $(CC) $(CFLAGS) -c -o $@ asm/x86_64-gcc.c
100x86_64-mont.s: asm/x86_64-mont.pl
101 $(PERL) asm/x86_64-mont.pl $@
102
103bn-ia64.s: asm/ia64.S
104 $(CC) $(CFLAGS) -E asm/ia64.S > $@
105
106# GNU assembler fails to compile PA-RISC2 modules, insist on calling
107# vendor assembler...
108pa-risc2W.o: asm/pa-risc2W.s
109 /usr/ccs/bin/as -o pa-risc2W.o asm/pa-risc2W.s
110pa-risc2.o: asm/pa-risc2.s
111 /usr/ccs/bin/as -o pa-risc2.o asm/pa-risc2.s
112
113# ppc - AIX, Linux, MacOS X...
114linux_ppc32.s: asm/ppc.pl; $(PERL) $< $@
115linux_ppc64.s: asm/ppc.pl; $(PERL) $< $@
116aix_ppc32.s: asm/ppc.pl; $(PERL) asm/ppc.pl $@
117aix_ppc64.s: asm/ppc.pl; $(PERL) asm/ppc.pl $@
118osx_ppc32.s: asm/ppc.pl; $(PERL) $< $@
119
120files:
121 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
122
123links:
124 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
125 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
126 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
127
128install:
129 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
130 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
131 do \
132 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
133 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
134 done;
135
136exptest:
137 rm -f exptest
138 gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a
139
140div:
141 rm -f a.out
142 gcc -I.. -g div.c ../../libcrypto.a
143
144tags:
145 ctags $(SRC)
146
147tests:
148
149lint:
150 lint -DLINT $(INCLUDES) $(SRC)>fluff
151
152depend:
153 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
154 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
155
156dclean:
157 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
158 mv -f Makefile.new $(MAKEFILE)
159
160clean:
161 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
162
163# DO NOT DELETE THIS LINE -- make depend depends on it.
164
165bn_add.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
166bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
167bn_add.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
168bn_add.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
169bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
170bn_add.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
171bn_add.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_add.c bn_lcl.h
172bn_asm.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
173bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
174bn_asm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
175bn_asm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
176bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
177bn_asm.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
178bn_asm.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_asm.c bn_lcl.h
179bn_blind.o: ../../e_os.h ../../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_os2.h ../../include/openssl/err.h
182bn_blind.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
183bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
184bn_blind.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
185bn_blind.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_blind.c bn_lcl.h
186bn_const.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
187bn_const.o: ../../include/openssl/ossl_typ.h bn.h bn_const.c
188bn_ctx.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
189bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
190bn_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
191bn_ctx.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
192bn_ctx.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
193bn_ctx.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
194bn_ctx.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_ctx.c bn_lcl.h
195bn_depr.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
196bn_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
197bn_depr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
198bn_depr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
199bn_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
200bn_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
201bn_depr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
202bn_depr.o: ../cryptlib.h bn_depr.c bn_lcl.h
203bn_div.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
204bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205bn_div.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
206bn_div.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
207bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
208bn_div.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
209bn_div.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_div.c bn_lcl.h
210bn_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
211bn_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
212bn_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
213bn_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
214bn_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
215bn_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
216bn_err.o: bn_err.c
217bn_exp.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
218bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
219bn_exp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
220bn_exp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
221bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
222bn_exp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
223bn_exp.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_exp.c bn_lcl.h
224bn_exp2.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
225bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
226bn_exp2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
227bn_exp2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
228bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
229bn_exp2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
230bn_exp2.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_exp2.c bn_lcl.h
231bn_gcd.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
232bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
233bn_gcd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
234bn_gcd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
235bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
236bn_gcd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
237bn_gcd.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_gcd.c bn_lcl.h
238bn_gf2m.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
239bn_gf2m.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
240bn_gf2m.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
241bn_gf2m.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
242bn_gf2m.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
243bn_gf2m.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
244bn_gf2m.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_gf2m.c bn_lcl.h
245bn_kron.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
246bn_kron.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
247bn_kron.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
248bn_kron.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
249bn_kron.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
250bn_kron.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
251bn_kron.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_kron.c bn_lcl.h
252bn_lib.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
253bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
254bn_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
255bn_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
256bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
257bn_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
258bn_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_lib.c
259bn_mod.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
260bn_mod.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
261bn_mod.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
262bn_mod.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
263bn_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
264bn_mod.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
265bn_mod.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_mod.c
266bn_mont.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
267bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
268bn_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
269bn_mont.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
270bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
271bn_mont.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
272bn_mont.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_mont.c
273bn_mpi.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
274bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
275bn_mpi.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
276bn_mpi.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
277bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
278bn_mpi.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
279bn_mpi.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_mpi.c
280bn_mul.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
281bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
282bn_mul.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
283bn_mul.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
284bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
285bn_mul.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
286bn_mul.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_mul.c
287bn_nist.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
288bn_nist.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
289bn_nist.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
290bn_nist.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
291bn_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
292bn_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
293bn_nist.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_nist.c
294bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
295bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
296bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
297bn_prime.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
298bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
299bn_prime.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
300bn_prime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
301bn_prime.o: ../cryptlib.h bn_lcl.h bn_prime.c bn_prime.h
302bn_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
303bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
304bn_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
305bn_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
306bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
307bn_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
308bn_print.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_print.c
309bn_rand.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
310bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
311bn_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
312bn_rand.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
313bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
314bn_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
315bn_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
316bn_rand.o: ../cryptlib.h bn_lcl.h bn_rand.c
317bn_recp.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
318bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
319bn_recp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
320bn_recp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
321bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
322bn_recp.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
323bn_recp.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_recp.c
324bn_shift.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
325bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
326bn_shift.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
327bn_shift.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
328bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
329bn_shift.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
330bn_shift.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_shift.c
331bn_sqr.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
332bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
333bn_sqr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
334bn_sqr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
335bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
336bn_sqr.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
337bn_sqr.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_sqr.c
338bn_sqrt.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
339bn_sqrt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
340bn_sqrt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
341bn_sqrt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
342bn_sqrt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
343bn_sqrt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
344bn_sqrt.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_sqrt.c
345bn_word.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
346bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
347bn_word.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
348bn_word.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
349bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
350bn_word.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
351bn_word.o: ../../include/openssl/symhacks.h ../cryptlib.h bn_lcl.h bn_word.c
diff --git a/src/lib/libcrypto/bn/Makefile.ssl b/src/lib/libcrypto/bn/Makefile.ssl
new file mode 100644
index 0000000000..50892ef44c
--- /dev/null
+++ b/src/lib/libcrypto/bn/Makefile.ssl
@@ -0,0 +1,326 @@
1#
2# SSLeay/crypto/bn/Makefile
3#
4
5DIR= bn
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES= -I.. -I$(TOP) -I../../include
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20BN_ASM= bn_asm.o
21# or use
22#BN_ASM= bn86-elf.o
23
24CFLAGS= $(INCLUDES) $(CFLAG)
25ASFLAGS= $(INCLUDES) $(ASFLAG)
26
27GENERAL=Makefile
28TEST=bntest.c exptest.c
29APPS=
30
31LIB=$(TOP)/libcrypto.a
32LIBSRC= bn_add.c bn_div.c bn_exp.c bn_lib.c bn_ctx.c bn_mul.c bn_mod.c \
33 bn_print.c bn_rand.c bn_shift.c bn_word.c bn_blind.c \
34 bn_kron.c bn_sqrt.c bn_gcd.c bn_prime.c bn_err.c bn_sqr.c bn_asm.c \
35 bn_recp.c bn_mont.c bn_mpi.c bn_exp2.c
36
37LIBOBJ= bn_add.o bn_div.o bn_exp.o bn_lib.o bn_ctx.o bn_mul.o bn_mod.o \
38 bn_print.o bn_rand.o bn_shift.o bn_word.o bn_blind.o \
39 bn_kron.o bn_sqrt.o bn_gcd.o bn_prime.o bn_err.o bn_sqr.o $(BN_ASM) \
40 bn_recp.o bn_mont.o bn_mpi.o bn_exp2.o
41
42SRC= $(LIBSRC)
43
44EXHEADER= bn.h
45HEADER= bn_lcl.h bn_prime.h $(EXHEADER)
46
47ALL= $(GENERAL) $(SRC) $(HEADER)
48
49top:
50 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
51
52all: lib
53
54bn_prime.h: bn_prime.pl
55 $(PERL) bn_prime.pl >bn_prime.h
56
57divtest: divtest.c ../../libcrypto.a
58 cc -I../../include divtest.c -o divtest ../../libcrypto.a
59
60bnbug: bnbug.c ../../libcrypto.a top
61 cc -g -I../../include bnbug.c -o bnbug ../../libcrypto.a
62
63lib: $(LIBOBJ)
64 $(AR) $(LIB) $(LIBOBJ)
65 $(RANLIB) $(LIB) || echo Never mind.
66 @touch lib
67
68# elf
69asm/bn86-elf.s: asm/bn-586.pl ../perlasm/x86asm.pl
70 (cd asm; $(PERL) bn-586.pl elf $(CFLAGS) > bn86-elf.s)
71
72asm/co86-elf.s: asm/co-586.pl ../perlasm/x86asm.pl
73 (cd asm; $(PERL) co-586.pl elf $(CFLAGS) > co86-elf.s)
74
75# a.out
76asm/bn86-out.o: asm/bn86unix.cpp
77 $(CPP) -DOUT asm/bn86unix.cpp | as -o asm/bn86-out.o
78
79asm/co86-out.o: asm/co86unix.cpp
80 $(CPP) -DOUT asm/co86unix.cpp | as -o asm/co86-out.o
81
82# bsdi
83asm/bn86bsdi.o: asm/bn86unix.cpp
84 $(CPP) -DBSDI asm/bn86unix.cpp | sed 's/ :/:/' | as -o asm/bn86bsdi.o
85
86asm/co86bsdi.o: asm/co86unix.cpp
87 $(CPP) -DBSDI asm/co86unix.cpp | sed 's/ :/:/' | as -o asm/co86bsdi.o
88
89asm/bn86unix.cpp: asm/bn-586.pl ../perlasm/x86asm.pl
90 (cd asm; $(PERL) bn-586.pl cpp >bn86unix.cpp )
91
92asm/co86unix.cpp: asm/co-586.pl ../perlasm/x86asm.pl
93 (cd asm; $(PERL) co-586.pl cpp >co86unix.cpp )
94
95asm/sparcv8.o: asm/sparcv8.S
96
97asm/sparcv8plus.o: asm/sparcv8plus.S
98
99# Old GNU assembler doesn't understand V9 instructions, so we
100# hire /usr/ccs/bin/as to do the job. Note that option is called
101# *-gcc27, but even gcc 2>=8 users may experience similar problem
102# if they didn't bother to upgrade GNU assembler. Such users should
103# not choose this option, but be adviced to *remove* GNU assembler
104# or upgrade it.
105asm/sparcv8plus-gcc27.o: asm/sparcv8plus.S
106 $(CC) $(ASFLAGS) -E asm/sparcv8plus.S | \
107 /usr/ccs/bin/as -xarch=v8plus - -o asm/sparcv8plus-gcc27.o
108
109
110asm/ia64.o: asm/ia64.S
111
112# Some compiler drivers (most notably HP-UX and Intel C++) don't
113# understand .S extension:-( I wish I could pipe output from cc -E,
114# but it's too compiler driver/ABI dependent to cover with a single
115# rule... <appro@fy.chalmers.se>
116asm/ia64-cpp.o: asm/ia64.S
117 $(CC) $(ASFLAGS) -E asm/ia64.S > /tmp/ia64.$$$$.s && \
118 $(CC) $(ASFLAGS) -c -o asm/ia64-cpp.o /tmp/ia64.$$$$.s; \
119 rm -f /tmp/ia64.$$$$.s
120
121asm/x86_64-gcc.o: asm/x86_64-gcc.c
122
123asm/pa-risc2W.o: asm/pa-risc2W.s
124 /usr/ccs/bin/as -o asm/pa-rics2W.o asm/pa-risc2W.s
125
126files:
127 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
128
129links:
130 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
131 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
132 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
133 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
134
135install:
136 @for i in $(EXHEADER) ; \
137 do \
138 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
139 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
140 done;
141
142exptest:
143 rm -f exptest
144 gcc -I../../include -g2 -ggdb -o exptest exptest.c ../../libcrypto.a
145
146div:
147 rm -f a.out
148 gcc -I.. -g div.c ../../libcrypto.a
149
150tags:
151 ctags $(SRC)
152
153tests:
154
155lint:
156 lint -DLINT $(INCLUDES) $(SRC)>fluff
157
158depend:
159 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
160
161dclean:
162 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
163 mv -f Makefile.new $(MAKEFILE)
164
165clean:
166 rm -f asm/co86unix.cpp asm/bn86unix.cpp asm/*-elf.* *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff bn_asm.s
167
168# DO NOT DELETE THIS LINE -- make depend depends on it.
169
170bn_add.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
171bn_add.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
172bn_add.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
173bn_add.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
174bn_add.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
175bn_add.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176bn_add.o: ../cryptlib.h bn_add.c bn_lcl.h
177bn_asm.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
178bn_asm.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
179bn_asm.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
180bn_asm.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
181bn_asm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
182bn_asm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
183bn_asm.o: ../cryptlib.h bn_asm.c bn_lcl.h
184bn_blind.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
185bn_blind.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
186bn_blind.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
187bn_blind.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
188bn_blind.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
189bn_blind.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
190bn_blind.o: ../cryptlib.h bn_blind.c bn_lcl.h
191bn_ctx.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
192bn_ctx.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
193bn_ctx.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
194bn_ctx.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
195bn_ctx.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
196bn_ctx.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
197bn_ctx.o: ../cryptlib.h bn_ctx.c bn_lcl.h
198bn_div.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
199bn_div.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
200bn_div.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
201bn_div.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
202bn_div.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
203bn_div.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
204bn_div.o: ../cryptlib.h bn_div.c bn_lcl.h
205bn_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
206bn_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
207bn_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
208bn_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
209bn_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
210bn_err.o: ../../include/openssl/symhacks.h bn_err.c
211bn_exp.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
212bn_exp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
213bn_exp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
214bn_exp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
215bn_exp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
216bn_exp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217bn_exp.o: ../cryptlib.h bn_exp.c bn_lcl.h
218bn_exp2.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
219bn_exp2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
220bn_exp2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
221bn_exp2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
222bn_exp2.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
223bn_exp2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
224bn_exp2.o: ../cryptlib.h bn_exp2.c bn_lcl.h
225bn_gcd.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
226bn_gcd.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
227bn_gcd.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
228bn_gcd.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
229bn_gcd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
230bn_gcd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
231bn_gcd.o: ../cryptlib.h bn_gcd.c bn_lcl.h
232bn_kron.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
233bn_kron.o: ../../include/openssl/opensslconf.h bn_kron.c bn_lcl.h
234bn_lib.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
235bn_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
236bn_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
237bn_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
238bn_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
239bn_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
240bn_lib.o: ../cryptlib.h bn_lcl.h bn_lib.c
241bn_mod.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
242bn_mod.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
243bn_mod.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
244bn_mod.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
245bn_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
246bn_mod.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247bn_mod.o: ../cryptlib.h bn_lcl.h bn_mod.c
248bn_mont.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
249bn_mont.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
250bn_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
251bn_mont.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
252bn_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
253bn_mont.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
254bn_mont.o: ../cryptlib.h bn_lcl.h bn_mont.c
255bn_mpi.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
256bn_mpi.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
257bn_mpi.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
258bn_mpi.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
259bn_mpi.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
260bn_mpi.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
261bn_mpi.o: ../cryptlib.h bn_lcl.h bn_mpi.c
262bn_mul.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
263bn_mul.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
264bn_mul.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
265bn_mul.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
266bn_mul.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
267bn_mul.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
268bn_mul.o: ../cryptlib.h bn_lcl.h bn_mul.c
269bn_prime.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
270bn_prime.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
271bn_prime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
272bn_prime.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
273bn_prime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
274bn_prime.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
275bn_prime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
276bn_prime.o: ../cryptlib.h bn_lcl.h bn_prime.c bn_prime.h
277bn_print.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
278bn_print.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
279bn_print.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
280bn_print.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
281bn_print.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
282bn_print.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
283bn_print.o: ../cryptlib.h bn_lcl.h bn_print.c
284bn_rand.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
285bn_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
286bn_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
287bn_rand.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
288bn_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
289bn_rand.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
290bn_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
291bn_rand.o: ../cryptlib.h bn_lcl.h bn_rand.c
292bn_recp.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
293bn_recp.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
294bn_recp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
295bn_recp.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
296bn_recp.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
297bn_recp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
298bn_recp.o: ../cryptlib.h bn_lcl.h bn_recp.c
299bn_shift.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
300bn_shift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
301bn_shift.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
302bn_shift.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
303bn_shift.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
304bn_shift.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
305bn_shift.o: ../cryptlib.h bn_lcl.h bn_shift.c
306bn_sqr.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
307bn_sqr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
308bn_sqr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
309bn_sqr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
310bn_sqr.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
311bn_sqr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
312bn_sqr.o: ../cryptlib.h bn_lcl.h bn_sqr.c
313bn_sqrt.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
314bn_sqrt.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
315bn_sqrt.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
316bn_sqrt.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
317bn_sqrt.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
318bn_sqrt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
319bn_sqrt.o: ../cryptlib.h bn_lcl.h bn_sqrt.c
320bn_word.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
321bn_word.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
322bn_word.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
323bn_word.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
324bn_word.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
325bn_word.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
326bn_word.o: ../cryptlib.h bn_lcl.h bn_word.c
diff --git a/src/lib/libcrypto/bn/asm/README b/src/lib/libcrypto/bn/asm/README
new file mode 100644
index 0000000000..b0f3a68a06
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/README
@@ -0,0 +1,27 @@
1<OBSOLETE>
2
3All assember in this directory are just version of the file
4crypto/bn/bn_asm.c.
5
6Quite a few of these files are just the assember output from gcc since on
7quite a few machines they are 2 times faster than the system compiler.
8
9For the x86, I have hand written assember because of the bad job all
10compilers seem to do on it. This normally gives a 2 time speed up in the RSA
11routines.
12
13For the DEC alpha, I also hand wrote the assember (except the division which
14is just the output from the C compiler pasted on the end of the file).
15On the 2 alpha C compilers I had access to, it was not possible to do
1664b x 64b -> 128b calculations (both long and the long long data types
17were 64 bits). So the hand assember gives access to the 128 bit result and
18a 2 times speedup :-).
19
20There are 3 versions of assember for the HP PA-RISC.
21
22pa-risc.s is the origional one which works fine and generated using gcc :-)
23
24pa-risc2W.s and pa-risc2.s are 64 and 32-bit PA-RISC 2.0 implementations
25by Chris Ruemmler from HP (with some help from the HP C compiler).
26
27</OBSOLETE>
diff --git a/src/lib/libcrypto/bn/asm/alpha.s b/src/lib/libcrypto/bn/asm/alpha.s
new file mode 100644
index 0000000000..555ff0b92d
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.s
@@ -0,0 +1,3199 @@
1 # DEC Alpha assember
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
4 # bn_div_words.
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"
12 .set noat
13gcc2_compiled.:
14__gnu_compiled_c:
15 .text
16 .align 3
17 .globl bn_mul_add_words
18 .ent bn_mul_add_words
19bn_mul_add_words:
20bn_mul_add_words..ng:
21 .frame $30,0,$26,0
22 .prologue 0
23 .align 5
24 subq $18,4,$18
25 bis $31,$31,$0
26 blt $18,$43 # if we are -1, -2, -3 or -4 goto tail code
27 ldq $20,0($17) # 1 1
28 ldq $1,0($16) # 1 1
29 .align 3
30$42:
31 mulq $20,$19,$5 # 1 2 1 ######
32 ldq $21,8($17) # 2 1
33 ldq $2,8($16) # 2 1
34 umulh $20,$19,$20 # 1 2 ######
35 ldq $27,16($17) # 3 1
36 ldq $3,16($16) # 3 1
37 mulq $21,$19,$6 # 2 2 1 ######
38 ldq $28,24($17) # 4 1
39 addq $1,$5,$1 # 1 2 2
40 ldq $4,24($16) # 4 1
41 umulh $21,$19,$21 # 2 2 ######
42 cmpult $1,$5,$22 # 1 2 3 1
43 addq $20,$22,$20 # 1 3 1
44 addq $1,$0,$1 # 1 2 3 1
45 mulq $27,$19,$7 # 3 2 1 ######
46 cmpult $1,$0,$0 # 1 2 3 2
47 addq $2,$6,$2 # 2 2 2
48 addq $20,$0,$0 # 1 3 2
49 cmpult $2,$6,$23 # 2 2 3 1
50 addq $21,$23,$21 # 2 3 1
51 umulh $27,$19,$27 # 3 2 ######
52 addq $2,$0,$2 # 2 2 3 1
53 cmpult $2,$0,$0 # 2 2 3 2
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
77
78 ldq $20,0($17) # 1 1
79 ldq $1,0($16) # 1 1
80
81 br $42
82
83 .align 4
84$45:
85 ldq $20,0($17) # 4 1
86 ldq $1,0($16) # 4 1
87 mulq $20,$19,$5 # 4 2 1
88 subq $18,1,$18
89 addq $16,8,$16
90 addq $17,8,$17
91 umulh $20,$19,$20 # 4 2
92 addq $1,$5,$1 # 4 2 2
93 cmpult $1,$5,$22 # 4 2 3 1
94 addq $20,$22,$20 # 4 3 1
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
101
102 .align 4
103$43:
104 addq $18,4,$18
105 bgt $18,$45 # goto tail code
106 ret $31,($26),1 # else exit
107
108 .end bn_mul_add_words
109 .align 3
110 .globl bn_mul_words
111 .ent bn_mul_words
112bn_mul_words:
113bn_mul_words..ng:
114 .frame $30,0,$26,0
115 .prologue 0
116 .align 5
117 subq $18,4,$18
118 bis $31,$31,$0
119 blt $18,$143 # if we are -1, -2, -3 or -4 goto tail code
120 ldq $20,0($17) # 1 1
121 .align 3
122$142:
123
124 mulq $20,$19,$5 # 1 2 1 #####
125 ldq $21,8($17) # 2 1
126 ldq $27,16($17) # 3 1
127 umulh $20,$19,$20 # 1 2 #####
128 ldq $28,24($17) # 4 1
129 mulq $21,$19,$6 # 2 2 1 #####
130 addq $5,$0,$5 # 1 2 3 1
131 subq $18,4,$18
132 cmpult $5,$0,$0 # 1 2 3 2
133 umulh $21,$19,$21 # 2 2 #####
134 addq $20,$0,$0 # 1 3 2
135 addq $17,32,$17
136 addq $6,$0,$6 # 2 2 3 1
137 mulq $27,$19,$7 # 3 2 1 #####
138 cmpult $6,$0,$0 # 2 2 3 2
139 addq $21,$0,$0 # 2 3 2
140 addq $16,32,$16
141 umulh $27,$19,$27 # 3 2 #####
142 stq $5,-32($16) # 1 2 4
143 mulq $28,$19,$8 # 4 2 1 #####
144 addq $7,$0,$7 # 3 2 3 1
145 stq $6,-24($16) # 2 2 4
146 cmpult $7,$0,$0 # 3 2 3 2
147 umulh $28,$19,$28 # 4 2 #####
148 addq $27,$0,$0 # 3 3 2
149 stq $7,-16($16) # 3 2 4
150 addq $8,$0,$8 # 4 2 3 1
151 cmpult $8,$0,$0 # 4 2 3 2
152
153 addq $28,$0,$0 # 4 3 2
154
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
185 .end bn_mul_words
186 .align 3
187 .globl bn_sqr_words
188 .ent bn_sqr_words
189bn_sqr_words:
190bn_sqr_words..ng:
191 .frame $30,0,$26,0
192 .prologue 0
193
194 subq $18,4,$18
195 blt $18,$543 # if we are -1, -2, -3 or -4 goto tail code
196 ldq $20,0($17) # 1 1
197 .align 3
198$542:
199 mulq $20,$20,$5 ######
200 ldq $21,8($17) # 1 1
201 subq $18,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]
217
218 addq $16,64,$16
219 addq $17,32,$17
220 stq $8,-16($16) # r[0]
221 stq $4,-8($16) # r[1]
222
223 blt $18,$543
224 ldq $20,0($17) # 1 1
225 br $542
226
227$442:
228 ldq $20,0($17) # a[0]
229 mulq $20,$20,$5 # a[0]*w low part r2
230 addq $16,16,$16
231 addq $17,8,$17
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
239
240 .align 4
241$543:
242 addq $18,4,$18
243 bgt $18,$442 # goto tail code
244 ret $31,($26),1 # else exit
245 .end bn_sqr_words
246
247 .align 3
248 .globl bn_add_words
249 .ent bn_add_words
250bn_add_words:
251bn_add_words..ng:
252 .frame $30,0,$26,0
253 .prologue 0
254
255 subq $19,4,$19
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
261$901:
262 addq $1,$5,$1 # r=a+b;
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++
296
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
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++
315
316 bgt $19,$945
317 ret $31,($26),1 # else exit
318
319$900:
320 addq $19,4,$19
321 bgt $19,$945 # goto tail code
322 ret $31,($26),1 # else exit
323 .end bn_add_words
324
325 #
326 # What follows was taken directly from the C compiler with a few
327 # hacks to redo the lables.
328 #
329.text
330 .align 3
331 .globl bn_div_words
332 .ent bn_div_words
333bn_div_words:
334 ldgp $29,0($27)
335bn_div_words..ng:
336 lda $30,-48($30)
337 .frame $30,48,$26,0
338 stq $26,0($30)
339 stq $9,8($30)
340 stq $10,16($30)
341 stq $11,24($30)
342 stq $12,32($30)
343 stq $13,40($30)
344 .mask 0x4003e00,-48
345 .prologue 1
346 bis $16,$16,$9
347 bis $17,$17,$10
348 bis $18,$18,$11
349 bis $31,$31,$13
350 bis $31,2,$12
351 bne $11,$119
352 lda $0,-1
353 br $31,$136
354 .align 4
355$119:
356 bis $11,$11,$16
357 jsr $26,BN_num_bits_word
358 ldgp $29,0($26)
359 subq $0,64,$1
360 beq $1,$120
361 bis $31,1,$1
362 sll $1,$0,$1
363 cmpule $9,$1,$1
364 bne $1,$120
365 # lda $16,_IO_stderr_
366 # lda $17,$C32
367 # bis $0,$0,$18
368 # jsr $26,fprintf
369 # ldgp $29,0($26)
370 jsr $26,abort
371 ldgp $29,0($26)
372 .align 4
373$120:
374 bis $31,64,$3
375 cmpult $9,$11,$2
376 subq $3,$0,$1
377 addl $1,$31,$0
378 subq $9,$11,$1
379 cmoveq $2,$1,$9
380 beq $0,$122
381 zapnot $0,15,$2
382 subq $3,$0,$1
383 sll $11,$2,$11
384 sll $9,$2,$3
385 srl $10,$1,$1
386 sll $10,$2,$10
387 bis $3,$1,$9
388$122:
389 srl $11,32,$5
390 zapnot $11,15,$6
391 lda $7,-1
392 .align 5
393$123:
394 srl $9,32,$1
395 subq $1,$5,$1
396 bne $1,$126
397 zapnot $7,15,$27
398 br $31,$127
399 .align 4
400$126:
401 bis $9,$9,$24
402 bis $5,$5,$25
403 divqu $24,$25,$27
404$127:
405 srl $10,32,$4
406 .align 5
407$128:
408 mulq $27,$5,$1
409 subq $9,$1,$3
410 zapnot $3,240,$1
411 bne $1,$129
412 mulq $6,$27,$2
413 sll $3,32,$1
414 addq $1,$4,$1
415 cmpule $2,$1,$2
416 bne $2,$129
417 subq $27,1,$27
418 br $31,$128
419 .align 4
420$129:
421 mulq $27,$6,$1
422 mulq $27,$5,$4
423 srl $1,32,$3
424 sll $1,32,$1
425 addq $4,$3,$4
426 cmpult $10,$1,$2
427 subq $10,$1,$10
428 addq $2,$4,$2
429 cmpult $9,$2,$1
430 bis $2,$2,$4
431 beq $1,$134
432 addq $9,$11,$9
433 subq $27,1,$27
434$134:
435 subl $12,1,$12
436 subq $9,$4,$9
437 beq $12,$124
438 sll $27,32,$13
439 sll $9,32,$2
440 srl $10,32,$1
441 sll $10,32,$10
442 bis $2,$1,$9
443 br $31,$123
444 .align 4
445$124:
446 bis $13,$27,$0
447$136:
448 ldq $26,0($30)
449 ldq $9,8($30)
450 ldq $10,16($30)
451 ldq $11,24($30)
452 ldq $12,32($30)
453 ldq $13,40($30)
454 addq $30,48,$30
455 ret $31,($26),1
456 .end bn_div_words
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
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 ldq $1, 0($17)
698 ldq $2, 0($18)
699 zapnot $1, 15, $7
700 srl $2, 32, $8
701 mulq $8, $7, $22
702 srl $1, 32, $6
703 zapnot $2, 15, $5
704 mulq $5, $6, $4
705 mulq $7, $5, $24
706 addq $22, $4, $22
707 cmpult $22, $4, $1
708 mulq $6, $8, $3
709 beq $1, $173
710 bis $31, 1, $1
711 sll $1, 32, $1
712 addq $3, $1, $3
713$173:
714 sll $22, 32, $4
715 addq $24, $4, $24
716 stq $24, 0($16)
717 ldq $2, 0($17)
718 ldq $1, 8($18)
719 zapnot $2, 15, $7
720 srl $1, 32, $8
721 mulq $8, $7, $25
722 zapnot $1, 15, $5
723 mulq $7, $5, $0
724 srl $2, 32, $6
725 mulq $5, $6, $23
726 mulq $6, $8, $6
727 srl $22, 32, $1
728 cmpult $24, $4, $2
729 addq $3, $1, $3
730 addq $2, $3, $22
731 addq $25, $23, $25
732 cmpult $25, $23, $1
733 bis $31, 1, $2
734 beq $1, $177
735 sll $2, 32, $1
736 addq $6, $1, $6
737$177:
738 sll $25, 32, $23
739 ldq $1, 0($18)
740 addq $0, $23, $0
741 bis $0, $0, $7
742 ldq $3, 8($17)
743 addq $22, $7, $22
744 srl $1, 32, $8
745 cmpult $22, $7, $4
746 zapnot $3, 15, $7
747 mulq $8, $7, $28
748 zapnot $1, 15, $5
749 mulq $7, $5, $21
750 srl $25, 32, $1
751 cmpult $0, $23, $2
752 addq $6, $1, $6
753 addq $2, $6, $6
754 addq $4, $6, $24
755 srl $3, 32, $6
756 mulq $5, $6, $2
757 mulq $6, $8, $6
758 addq $28, $2, $28
759 cmpult $28, $2, $1
760 bis $31, 1, $2
761 beq $1, $181
762 sll $2, 32, $1
763 addq $6, $1, $6
764$181:
765 sll $28, 32, $2
766 addq $21, $2, $21
767 bis $21, $21, $7
768 addq $22, $7, $22
769 stq $22, 8($16)
770 ldq $3, 16($17)
771 ldq $1, 0($18)
772 cmpult $22, $7, $4
773 zapnot $3, 15, $7
774 srl $1, 32, $8
775 mulq $8, $7, $22
776 zapnot $1, 15, $5
777 mulq $7, $5, $20
778 srl $28, 32, $1
779 cmpult $21, $2, $2
780 addq $6, $1, $6
781 addq $2, $6, $6
782 addq $4, $6, $6
783 addq $24, $6, $24
784 cmpult $24, $6, $23
785 srl $3, 32, $6
786 mulq $5, $6, $2
787 mulq $6, $8, $6
788 addq $22, $2, $22
789 cmpult $22, $2, $1
790 bis $31, 1, $2
791 beq $1, $185
792 sll $2, 32, $1
793 addq $6, $1, $6
794$185:
795 sll $22, 32, $2
796 ldq $1, 8($18)
797 addq $20, $2, $20
798 bis $20, $20, $7
799 ldq $4, 8($17)
800 addq $24, $7, $24
801 srl $1, 32, $8
802 cmpult $24, $7, $3
803 zapnot $4, 15, $7
804 mulq $8, $7, $25
805 zapnot $1, 15, $5
806 mulq $7, $5, $0
807 srl $22, 32, $1
808 cmpult $20, $2, $2
809 addq $6, $1, $6
810 addq $2, $6, $6
811 addq $3, $6, $6
812 addq $23, $6, $23
813 cmpult $23, $6, $22
814 srl $4, 32, $6
815 mulq $5, $6, $5
816 bis $31, 1, $21
817 addq $25, $5, $25
818 cmpult $25, $5, $1
819 mulq $6, $8, $6
820 beq $1, $189
821 sll $21, 32, $1
822 addq $6, $1, $6
823$189:
824 sll $25, 32, $5
825 ldq $2, 16($18)
826 addq $0, $5, $0
827 bis $0, $0, $7
828 ldq $4, 0($17)
829 addq $24, $7, $24
830 srl $2, 32, $8
831 cmpult $24, $7, $3
832 zapnot $4, 15, $7
833 mulq $8, $7, $28
834 srl $25, 32, $1
835 addq $6, $1, $6
836 cmpult $0, $5, $1
837 zapnot $2, 15, $5
838 addq $1, $6, $6
839 addq $3, $6, $6
840 addq $23, $6, $23
841 cmpult $23, $6, $1
842 srl $4, 32, $6
843 mulq $5, $6, $25
844 mulq $7, $5, $2
845 addq $1, $22, $22
846 addq $28, $25, $28
847 cmpult $28, $25, $1
848 mulq $6, $8, $6
849 beq $1, $193
850 sll $21, 32, $1
851 addq $6, $1, $6
852$193:
853 sll $28, 32, $25
854 addq $2, $25, $2
855 bis $2, $2, $7
856 addq $24, $7, $24
857 stq $24, 16($16)
858 ldq $4, 0($17)
859 ldq $5, 24($18)
860 cmpult $24, $7, $3
861 zapnot $4, 15, $7
862 srl $5, 32, $8
863 mulq $8, $7, $0
864 srl $28, 32, $1
865 cmpult $2, $25, $2
866 addq $6, $1, $6
867 addq $2, $6, $6
868 addq $3, $6, $6
869 addq $23, $6, $23
870 cmpult $23, $6, $1
871 srl $4, 32, $6
872 zapnot $5, 15, $5
873 mulq $5, $6, $24
874 mulq $7, $5, $2
875 addq $1, $22, $22
876 addq $0, $24, $0
877 cmpult $0, $24, $1
878 mulq $6, $8, $6
879 beq $1, $197
880 sll $21, 32, $1
881 addq $6, $1, $6
882$197:
883 sll $0, 32, $24
884 ldq $1, 16($18)
885 addq $2, $24, $2
886 bis $2, $2, $7
887 ldq $4, 8($17)
888 addq $23, $7, $23
889 srl $1, 32, $8
890 cmpult $23, $7, $3
891 zapnot $4, 15, $7
892 mulq $8, $7, $25
893 zapnot $1, 15, $5
894 mulq $7, $5, $21
895 srl $0, 32, $1
896 cmpult $2, $24, $2
897 addq $6, $1, $6
898 addq $2, $6, $6
899 addq $3, $6, $6
900 addq $22, $6, $22
901 cmpult $22, $6, $24
902 srl $4, 32, $6
903 mulq $5, $6, $5
904 bis $31, 1, $20
905 addq $25, $5, $25
906 cmpult $25, $5, $1
907 mulq $6, $8, $6
908 beq $1, $201
909 sll $20, 32, $1
910 addq $6, $1, $6
911$201:
912 sll $25, 32, $5
913 ldq $2, 8($18)
914 addq $21, $5, $21
915 bis $21, $21, $7
916 ldq $4, 16($17)
917 addq $23, $7, $23
918 srl $2, 32, $8
919 cmpult $23, $7, $3
920 zapnot $4, 15, $7
921 mulq $8, $7, $28
922 srl $25, 32, $1
923 addq $6, $1, $6
924 cmpult $21, $5, $1
925 zapnot $2, 15, $5
926 addq $1, $6, $6
927 addq $3, $6, $6
928 addq $22, $6, $22
929 cmpult $22, $6, $1
930 srl $4, 32, $6
931 mulq $5, $6, $25
932 mulq $7, $5, $5
933 addq $1, $24, $24
934 addq $28, $25, $28
935 cmpult $28, $25, $1
936 mulq $6, $8, $6
937 beq $1, $205
938 sll $20, 32, $1
939 addq $6, $1, $6
940$205:
941 sll $28, 32, $25
942 ldq $2, 0($18)
943 addq $5, $25, $5
944 bis $5, $5, $7
945 ldq $4, 24($17)
946 addq $23, $7, $23
947 srl $2, 32, $8
948 cmpult $23, $7, $3
949 zapnot $4, 15, $7
950 mulq $8, $7, $0
951 srl $28, 32, $1
952 addq $6, $1, $6
953 cmpult $5, $25, $1
954 zapnot $2, 15, $5
955 addq $1, $6, $6
956 addq $3, $6, $6
957 addq $22, $6, $22
958 cmpult $22, $6, $1
959 srl $4, 32, $6
960 mulq $5, $6, $25
961 mulq $7, $5, $2
962 addq $1, $24, $24
963 addq $0, $25, $0
964 cmpult $0, $25, $1
965 mulq $6, $8, $6
966 beq $1, $209
967 sll $20, 32, $1
968 addq $6, $1, $6
969$209:
970 sll $0, 32, $25
971 addq $2, $25, $2
972 bis $2, $2, $7
973 addq $23, $7, $23
974 stq $23, 24($16)
975 ldq $4, 32($17)
976 ldq $5, 0($18)
977 cmpult $23, $7, $3
978 zapnot $4, 15, $7
979 srl $5, 32, $8
980 mulq $8, $7, $28
981 srl $0, 32, $1
982 cmpult $2, $25, $2
983 addq $6, $1, $6
984 addq $2, $6, $6
985 addq $3, $6, $6
986 addq $22, $6, $22
987 cmpult $22, $6, $1
988 srl $4, 32, $6
989 zapnot $5, 15, $5
990 mulq $5, $6, $23
991 mulq $7, $5, $2
992 addq $1, $24, $24
993 addq $28, $23, $28
994 cmpult $28, $23, $1
995 mulq $6, $8, $6
996 beq $1, $213
997 sll $20, 32, $1
998 addq $6, $1, $6
999$213:
1000 sll $28, 32, $23
1001 ldq $1, 8($18)
1002 addq $2, $23, $2
1003 bis $2, $2, $7
1004 ldq $4, 24($17)
1005 addq $22, $7, $22
1006 srl $1, 32, $8
1007 cmpult $22, $7, $3
1008 zapnot $4, 15, $7
1009 mulq $8, $7, $25
1010 zapnot $1, 15, $5
1011 mulq $7, $5, $0
1012 srl $28, 32, $1
1013 cmpult $2, $23, $2
1014 addq $6, $1, $6
1015 addq $2, $6, $6
1016 addq $3, $6, $6
1017 addq $24, $6, $24
1018 cmpult $24, $6, $23
1019 srl $4, 32, $6
1020 mulq $5, $6, $5
1021 bis $31, 1, $21
1022 addq $25, $5, $25
1023 cmpult $25, $5, $1
1024 mulq $6, $8, $6
1025 beq $1, $217
1026 sll $21, 32, $1
1027 addq $6, $1, $6
1028$217:
1029 sll $25, 32, $5
1030 ldq $2, 16($18)
1031 addq $0, $5, $0
1032 bis $0, $0, $7
1033 ldq $4, 16($17)
1034 addq $22, $7, $22
1035 srl $2, 32, $8
1036 cmpult $22, $7, $3
1037 zapnot $4, 15, $7
1038 mulq $8, $7, $28
1039 srl $25, 32, $1
1040 addq $6, $1, $6
1041 cmpult $0, $5, $1
1042 zapnot $2, 15, $5
1043 addq $1, $6, $6
1044 addq $3, $6, $6
1045 addq $24, $6, $24
1046 cmpult $24, $6, $1
1047 srl $4, 32, $6
1048 mulq $5, $6, $25
1049 mulq $7, $5, $5
1050 addq $1, $23, $23
1051 addq $28, $25, $28
1052 cmpult $28, $25, $1
1053 mulq $6, $8, $6
1054 beq $1, $221
1055 sll $21, 32, $1
1056 addq $6, $1, $6
1057$221:
1058 sll $28, 32, $25
1059 ldq $2, 24($18)
1060 addq $5, $25, $5
1061 bis $5, $5, $7
1062 ldq $4, 8($17)
1063 addq $22, $7, $22
1064 srl $2, 32, $8
1065 cmpult $22, $7, $3
1066 zapnot $4, 15, $7
1067 mulq $8, $7, $0
1068 srl $28, 32, $1
1069 addq $6, $1, $6
1070 cmpult $5, $25, $1
1071 zapnot $2, 15, $5
1072 addq $1, $6, $6
1073 addq $3, $6, $6
1074 addq $24, $6, $24
1075 cmpult $24, $6, $1
1076 srl $4, 32, $6
1077 mulq $5, $6, $25
1078 mulq $7, $5, $5
1079 addq $1, $23, $23
1080 addq $0, $25, $0
1081 cmpult $0, $25, $1
1082 mulq $6, $8, $6
1083 beq $1, $225
1084 sll $21, 32, $1
1085 addq $6, $1, $6
1086$225:
1087 sll $0, 32, $25
1088 ldq $2, 32($18)
1089 addq $5, $25, $5
1090 bis $5, $5, $7
1091 ldq $4, 0($17)
1092 addq $22, $7, $22
1093 srl $2, 32, $8
1094 cmpult $22, $7, $3
1095 zapnot $4, 15, $7
1096 mulq $8, $7, $28
1097 srl $0, 32, $1
1098 addq $6, $1, $6
1099 cmpult $5, $25, $1
1100 zapnot $2, 15, $5
1101 addq $1, $6, $6
1102 addq $3, $6, $6
1103 addq $24, $6, $24
1104 cmpult $24, $6, $1
1105 srl $4, 32, $6
1106 mulq $5, $6, $25
1107 mulq $7, $5, $2
1108 addq $1, $23, $23
1109 addq $28, $25, $28
1110 cmpult $28, $25, $1
1111 mulq $6, $8, $6
1112 beq $1, $229
1113 sll $21, 32, $1
1114 addq $6, $1, $6
1115$229:
1116 sll $28, 32, $25
1117 addq $2, $25, $2
1118 bis $2, $2, $7
1119 addq $22, $7, $22
1120 stq $22, 32($16)
1121 ldq $4, 0($17)
1122 ldq $5, 40($18)
1123 cmpult $22, $7, $3
1124 zapnot $4, 15, $7
1125 srl $5, 32, $8
1126 mulq $8, $7, $0
1127 srl $28, 32, $1
1128 cmpult $2, $25, $2
1129 addq $6, $1, $6
1130 addq $2, $6, $6
1131 addq $3, $6, $6
1132 addq $24, $6, $24
1133 cmpult $24, $6, $1
1134 srl $4, 32, $6
1135 zapnot $5, 15, $5
1136 mulq $5, $6, $22
1137 mulq $7, $5, $2
1138 addq $1, $23, $23
1139 addq $0, $22, $0
1140 cmpult $0, $22, $1
1141 mulq $6, $8, $6
1142 beq $1, $233
1143 sll $21, 32, $1
1144 addq $6, $1, $6
1145$233:
1146 sll $0, 32, $22
1147 ldq $1, 32($18)
1148 addq $2, $22, $2
1149 bis $2, $2, $7
1150 ldq $4, 8($17)
1151 addq $24, $7, $24
1152 srl $1, 32, $8
1153 cmpult $24, $7, $3
1154 zapnot $4, 15, $7
1155 mulq $8, $7, $25
1156 zapnot $1, 15, $5
1157 mulq $7, $5, $21
1158 srl $0, 32, $1
1159 cmpult $2, $22, $2
1160 addq $6, $1, $6
1161 addq $2, $6, $6
1162 addq $3, $6, $6
1163 addq $23, $6, $23
1164 cmpult $23, $6, $22
1165 srl $4, 32, $6
1166 mulq $5, $6, $5
1167 bis $31, 1, $20
1168 addq $25, $5, $25
1169 cmpult $25, $5, $1
1170 mulq $6, $8, $6
1171 beq $1, $237
1172 sll $20, 32, $1
1173 addq $6, $1, $6
1174$237:
1175 sll $25, 32, $5
1176 ldq $2, 24($18)
1177 addq $21, $5, $21
1178 bis $21, $21, $7
1179 ldq $4, 16($17)
1180 addq $24, $7, $24
1181 srl $2, 32, $8
1182 cmpult $24, $7, $3
1183 zapnot $4, 15, $7
1184 mulq $8, $7, $28
1185 srl $25, 32, $1
1186 addq $6, $1, $6
1187 cmpult $21, $5, $1
1188 zapnot $2, 15, $5
1189 addq $1, $6, $6
1190 addq $3, $6, $6
1191 addq $23, $6, $23
1192 cmpult $23, $6, $1
1193 srl $4, 32, $6
1194 mulq $5, $6, $25
1195 mulq $7, $5, $5
1196 addq $1, $22, $22
1197 addq $28, $25, $28
1198 cmpult $28, $25, $1
1199 mulq $6, $8, $6
1200 beq $1, $241
1201 sll $20, 32, $1
1202 addq $6, $1, $6
1203$241:
1204 sll $28, 32, $25
1205 ldq $2, 16($18)
1206 addq $5, $25, $5
1207 bis $5, $5, $7
1208 ldq $4, 24($17)
1209 addq $24, $7, $24
1210 srl $2, 32, $8
1211 cmpult $24, $7, $3
1212 zapnot $4, 15, $7
1213 mulq $8, $7, $0
1214 srl $28, 32, $1
1215 addq $6, $1, $6
1216 cmpult $5, $25, $1
1217 zapnot $2, 15, $5
1218 addq $1, $6, $6
1219 addq $3, $6, $6
1220 addq $23, $6, $23
1221 cmpult $23, $6, $1
1222 srl $4, 32, $6
1223 mulq $5, $6, $25
1224 mulq $7, $5, $5
1225 addq $1, $22, $22
1226 addq $0, $25, $0
1227 cmpult $0, $25, $1
1228 mulq $6, $8, $6
1229 beq $1, $245
1230 sll $20, 32, $1
1231 addq $6, $1, $6
1232$245:
1233 sll $0, 32, $25
1234 ldq $2, 8($18)
1235 addq $5, $25, $5
1236 bis $5, $5, $7
1237 ldq $4, 32($17)
1238 addq $24, $7, $24
1239 srl $2, 32, $8
1240 cmpult $24, $7, $3
1241 zapnot $4, 15, $7
1242 mulq $8, $7, $28
1243 srl $0, 32, $1
1244 addq $6, $1, $6
1245 cmpult $5, $25, $1
1246 zapnot $2, 15, $5
1247 addq $1, $6, $6
1248 addq $3, $6, $6
1249 addq $23, $6, $23
1250 cmpult $23, $6, $1
1251 srl $4, 32, $6
1252 mulq $5, $6, $25
1253 mulq $7, $5, $5
1254 addq $1, $22, $22
1255 addq $28, $25, $28
1256 cmpult $28, $25, $1
1257 mulq $6, $8, $6
1258 beq $1, $249
1259 sll $20, 32, $1
1260 addq $6, $1, $6
1261$249:
1262 sll $28, 32, $25
1263 ldq $2, 0($18)
1264 addq $5, $25, $5
1265 bis $5, $5, $7
1266 ldq $4, 40($17)
1267 addq $24, $7, $24
1268 srl $2, 32, $8
1269 cmpult $24, $7, $3
1270 zapnot $4, 15, $7
1271 mulq $8, $7, $0
1272 srl $28, 32, $1
1273 addq $6, $1, $6
1274 cmpult $5, $25, $1
1275 zapnot $2, 15, $5
1276 addq $1, $6, $6
1277 addq $3, $6, $6
1278 addq $23, $6, $23
1279 cmpult $23, $6, $1
1280 srl $4, 32, $6
1281 mulq $5, $6, $25
1282 mulq $7, $5, $2
1283 addq $1, $22, $22
1284 addq $0, $25, $0
1285 cmpult $0, $25, $1
1286 mulq $6, $8, $6
1287 beq $1, $253
1288 sll $20, 32, $1
1289 addq $6, $1, $6
1290$253:
1291 sll $0, 32, $25
1292 addq $2, $25, $2
1293 bis $2, $2, $7
1294 addq $24, $7, $24
1295 stq $24, 40($16)
1296 ldq $4, 48($17)
1297 ldq $5, 0($18)
1298 cmpult $24, $7, $3
1299 zapnot $4, 15, $7
1300 srl $5, 32, $8
1301 mulq $8, $7, $28
1302 srl $0, 32, $1
1303 cmpult $2, $25, $2
1304 addq $6, $1, $6
1305 addq $2, $6, $6
1306 addq $3, $6, $6
1307 addq $23, $6, $23
1308 cmpult $23, $6, $1
1309 srl $4, 32, $6
1310 zapnot $5, 15, $5
1311 mulq $5, $6, $24
1312 mulq $7, $5, $2
1313 addq $1, $22, $22
1314 addq $28, $24, $28
1315 cmpult $28, $24, $1
1316 mulq $6, $8, $6
1317 beq $1, $257
1318 sll $20, 32, $1
1319 addq $6, $1, $6
1320$257:
1321 sll $28, 32, $24
1322 ldq $1, 8($18)
1323 addq $2, $24, $2
1324 bis $2, $2, $7
1325 ldq $4, 40($17)
1326 addq $23, $7, $23
1327 srl $1, 32, $8
1328 cmpult $23, $7, $3
1329 zapnot $4, 15, $7
1330 mulq $8, $7, $25
1331 zapnot $1, 15, $5
1332 mulq $7, $5, $0
1333 srl $28, 32, $1
1334 cmpult $2, $24, $2
1335 addq $6, $1, $6
1336 addq $2, $6, $6
1337 addq $3, $6, $6
1338 addq $22, $6, $22
1339 cmpult $22, $6, $24
1340 srl $4, 32, $6
1341 mulq $5, $6, $5
1342 bis $31, 1, $21
1343 addq $25, $5, $25
1344 cmpult $25, $5, $1
1345 mulq $6, $8, $6
1346 beq $1, $261
1347 sll $21, 32, $1
1348 addq $6, $1, $6
1349$261:
1350 sll $25, 32, $5
1351 ldq $2, 16($18)
1352 addq $0, $5, $0
1353 bis $0, $0, $7
1354 ldq $4, 32($17)
1355 addq $23, $7, $23
1356 srl $2, 32, $8
1357 cmpult $23, $7, $3
1358 zapnot $4, 15, $7
1359 mulq $8, $7, $28
1360 srl $25, 32, $1
1361 addq $6, $1, $6
1362 cmpult $0, $5, $1
1363 zapnot $2, 15, $5
1364 addq $1, $6, $6
1365 addq $3, $6, $6
1366 addq $22, $6, $22
1367 cmpult $22, $6, $1
1368 srl $4, 32, $6
1369 mulq $5, $6, $25
1370 mulq $7, $5, $5
1371 addq $1, $24, $24
1372 addq $28, $25, $28
1373 cmpult $28, $25, $1
1374 mulq $6, $8, $6
1375 beq $1, $265
1376 sll $21, 32, $1
1377 addq $6, $1, $6
1378$265:
1379 sll $28, 32, $25
1380 ldq $2, 24($18)
1381 addq $5, $25, $5
1382 bis $5, $5, $7
1383 ldq $4, 24($17)
1384 addq $23, $7, $23
1385 srl $2, 32, $8
1386 cmpult $23, $7, $3
1387 zapnot $4, 15, $7
1388 mulq $8, $7, $0
1389 srl $28, 32, $1
1390 addq $6, $1, $6
1391 cmpult $5, $25, $1
1392 zapnot $2, 15, $5
1393 addq $1, $6, $6
1394 addq $3, $6, $6
1395 addq $22, $6, $22
1396 cmpult $22, $6, $1
1397 srl $4, 32, $6
1398 mulq $5, $6, $25
1399 mulq $7, $5, $5
1400 addq $1, $24, $24
1401 addq $0, $25, $0
1402 cmpult $0, $25, $1
1403 mulq $6, $8, $6
1404 beq $1, $269
1405 sll $21, 32, $1
1406 addq $6, $1, $6
1407$269:
1408 sll $0, 32, $25
1409 ldq $2, 32($18)
1410 addq $5, $25, $5
1411 bis $5, $5, $7
1412 ldq $4, 16($17)
1413 addq $23, $7, $23
1414 srl $2, 32, $8
1415 cmpult $23, $7, $3
1416 zapnot $4, 15, $7
1417 mulq $8, $7, $28
1418 srl $0, 32, $1
1419 addq $6, $1, $6
1420 cmpult $5, $25, $1
1421 zapnot $2, 15, $5
1422 addq $1, $6, $6
1423 addq $3, $6, $6
1424 addq $22, $6, $22
1425 cmpult $22, $6, $1
1426 srl $4, 32, $6
1427 mulq $5, $6, $25
1428 mulq $7, $5, $5
1429 addq $1, $24, $24
1430 addq $28, $25, $28
1431 cmpult $28, $25, $1
1432 mulq $6, $8, $6
1433 beq $1, $273
1434 sll $21, 32, $1
1435 addq $6, $1, $6
1436$273:
1437 sll $28, 32, $25
1438 ldq $2, 40($18)
1439 addq $5, $25, $5
1440 bis $5, $5, $7
1441 ldq $4, 8($17)
1442 addq $23, $7, $23
1443 srl $2, 32, $8
1444 cmpult $23, $7, $3
1445 zapnot $4, 15, $7
1446 mulq $8, $7, $0
1447 srl $28, 32, $1
1448 addq $6, $1, $6
1449 cmpult $5, $25, $1
1450 zapnot $2, 15, $5
1451 addq $1, $6, $6
1452 addq $3, $6, $6
1453 addq $22, $6, $22
1454 cmpult $22, $6, $1
1455 srl $4, 32, $6
1456 mulq $5, $6, $25
1457 mulq $7, $5, $5
1458 addq $1, $24, $24
1459 addq $0, $25, $0
1460 cmpult $0, $25, $1
1461 mulq $6, $8, $6
1462 beq $1, $277
1463 sll $21, 32, $1
1464 addq $6, $1, $6
1465$277:
1466 sll $0, 32, $25
1467 ldq $2, 48($18)
1468 addq $5, $25, $5
1469 bis $5, $5, $7
1470 ldq $4, 0($17)
1471 addq $23, $7, $23
1472 srl $2, 32, $8
1473 cmpult $23, $7, $3
1474 zapnot $4, 15, $7
1475 mulq $8, $7, $28
1476 srl $0, 32, $1
1477 addq $6, $1, $6
1478 cmpult $5, $25, $1
1479 zapnot $2, 15, $5
1480 addq $1, $6, $6
1481 addq $3, $6, $6
1482 addq $22, $6, $22
1483 cmpult $22, $6, $1
1484 srl $4, 32, $6
1485 mulq $5, $6, $25
1486 mulq $7, $5, $2
1487 addq $1, $24, $24
1488 addq $28, $25, $28
1489 cmpult $28, $25, $1
1490 mulq $6, $8, $6
1491 beq $1, $281
1492 sll $21, 32, $1
1493 addq $6, $1, $6
1494$281:
1495 sll $28, 32, $25
1496 addq $2, $25, $2
1497 bis $2, $2, $7
1498 addq $23, $7, $23
1499 stq $23, 48($16)
1500 ldq $4, 0($17)
1501 ldq $5, 56($18)
1502 cmpult $23, $7, $3
1503 zapnot $4, 15, $7
1504 srl $5, 32, $8
1505 mulq $8, $7, $0
1506 srl $28, 32, $1
1507 cmpult $2, $25, $2
1508 addq $6, $1, $6
1509 addq $2, $6, $6
1510 addq $3, $6, $6
1511 addq $22, $6, $22
1512 cmpult $22, $6, $1
1513 srl $4, 32, $6
1514 zapnot $5, 15, $5
1515 mulq $5, $6, $23
1516 mulq $7, $5, $2
1517 addq $1, $24, $24
1518 addq $0, $23, $0
1519 cmpult $0, $23, $1
1520 mulq $6, $8, $6
1521 beq $1, $285
1522 sll $21, 32, $1
1523 addq $6, $1, $6
1524$285:
1525 sll $0, 32, $23
1526 ldq $1, 48($18)
1527 addq $2, $23, $2
1528 bis $2, $2, $7
1529 ldq $4, 8($17)
1530 addq $22, $7, $22
1531 srl $1, 32, $8
1532 cmpult $22, $7, $3
1533 zapnot $4, 15, $7
1534 mulq $8, $7, $25
1535 zapnot $1, 15, $5
1536 mulq $7, $5, $21
1537 srl $0, 32, $1
1538 cmpult $2, $23, $2
1539 addq $6, $1, $6
1540 addq $2, $6, $6
1541 addq $3, $6, $6
1542 addq $24, $6, $24
1543 cmpult $24, $6, $23
1544 srl $4, 32, $6
1545 mulq $5, $6, $5
1546 bis $31, 1, $20
1547 addq $25, $5, $25
1548 cmpult $25, $5, $1
1549 mulq $6, $8, $6
1550 beq $1, $289
1551 sll $20, 32, $1
1552 addq $6, $1, $6
1553$289:
1554 sll $25, 32, $5
1555 ldq $2, 40($18)
1556 addq $21, $5, $21
1557 bis $21, $21, $7
1558 ldq $4, 16($17)
1559 addq $22, $7, $22
1560 srl $2, 32, $8
1561 cmpult $22, $7, $3
1562 zapnot $4, 15, $7
1563 mulq $8, $7, $28
1564 srl $25, 32, $1
1565 addq $6, $1, $6
1566 cmpult $21, $5, $1
1567 zapnot $2, 15, $5
1568 addq $1, $6, $6
1569 addq $3, $6, $6
1570 addq $24, $6, $24
1571 cmpult $24, $6, $1
1572 srl $4, 32, $6
1573 mulq $5, $6, $25
1574 mulq $7, $5, $5
1575 addq $1, $23, $23
1576 addq $28, $25, $28
1577 cmpult $28, $25, $1
1578 mulq $6, $8, $6
1579 beq $1, $293
1580 sll $20, 32, $1
1581 addq $6, $1, $6
1582$293:
1583 sll $28, 32, $25
1584 ldq $2, 32($18)
1585 addq $5, $25, $5
1586 bis $5, $5, $7
1587 ldq $4, 24($17)
1588 addq $22, $7, $22
1589 srl $2, 32, $8
1590 cmpult $22, $7, $3
1591 zapnot $4, 15, $7
1592 mulq $8, $7, $0
1593 srl $28, 32, $1
1594 addq $6, $1, $6
1595 cmpult $5, $25, $1
1596 zapnot $2, 15, $5
1597 addq $1, $6, $6
1598 addq $3, $6, $6
1599 addq $24, $6, $24
1600 cmpult $24, $6, $1
1601 srl $4, 32, $6
1602 mulq $5, $6, $25
1603 mulq $7, $5, $5
1604 addq $1, $23, $23
1605 addq $0, $25, $0
1606 cmpult $0, $25, $1
1607 mulq $6, $8, $6
1608 beq $1, $297
1609 sll $20, 32, $1
1610 addq $6, $1, $6
1611$297:
1612 sll $0, 32, $25
1613 ldq $2, 24($18)
1614 addq $5, $25, $5
1615 bis $5, $5, $7
1616 ldq $4, 32($17)
1617 addq $22, $7, $22
1618 srl $2, 32, $8
1619 cmpult $22, $7, $3
1620 zapnot $4, 15, $7
1621 mulq $8, $7, $28
1622 srl $0, 32, $1
1623 addq $6, $1, $6
1624 cmpult $5, $25, $1
1625 zapnot $2, 15, $5
1626 addq $1, $6, $6
1627 addq $3, $6, $6
1628 addq $24, $6, $24
1629 cmpult $24, $6, $1
1630 srl $4, 32, $6
1631 mulq $5, $6, $25
1632 mulq $7, $5, $5
1633 addq $1, $23, $23
1634 addq $28, $25, $28
1635 cmpult $28, $25, $1
1636 mulq $6, $8, $6
1637 beq $1, $301
1638 sll $20, 32, $1
1639 addq $6, $1, $6
1640$301:
1641 sll $28, 32, $25
1642 ldq $2, 16($18)
1643 addq $5, $25, $5
1644 bis $5, $5, $7
1645 ldq $4, 40($17)
1646 addq $22, $7, $22
1647 srl $2, 32, $8
1648 cmpult $22, $7, $3
1649 zapnot $4, 15, $7
1650 mulq $8, $7, $0
1651 srl $28, 32, $1
1652 addq $6, $1, $6
1653 cmpult $5, $25, $1
1654 zapnot $2, 15, $5
1655 addq $1, $6, $6
1656 addq $3, $6, $6
1657 addq $24, $6, $24
1658 cmpult $24, $6, $1
1659 srl $4, 32, $6
1660 mulq $5, $6, $25
1661 mulq $7, $5, $5
1662 addq $1, $23, $23
1663 addq $0, $25, $0
1664 cmpult $0, $25, $1
1665 mulq $6, $8, $6
1666 beq $1, $305
1667 sll $20, 32, $1
1668 addq $6, $1, $6
1669$305:
1670 sll $0, 32, $25
1671 ldq $2, 8($18)
1672 addq $5, $25, $5
1673 bis $5, $5, $7
1674 ldq $4, 48($17)
1675 addq $22, $7, $22
1676 srl $2, 32, $8
1677 cmpult $22, $7, $3
1678 zapnot $4, 15, $7
1679 mulq $8, $7, $28
1680 srl $0, 32, $1
1681 addq $6, $1, $6
1682 cmpult $5, $25, $1
1683 zapnot $2, 15, $5
1684 addq $1, $6, $6
1685 addq $3, $6, $6
1686 addq $24, $6, $24
1687 cmpult $24, $6, $1
1688 srl $4, 32, $6
1689 mulq $5, $6, $25
1690 mulq $7, $5, $5
1691 addq $1, $23, $23
1692 addq $28, $25, $28
1693 cmpult $28, $25, $1
1694 mulq $6, $8, $6
1695 beq $1, $309
1696 sll $20, 32, $1
1697 addq $6, $1, $6
1698$309:
1699 sll $28, 32, $25
1700 ldq $2, 0($18)
1701 addq $5, $25, $5
1702 bis $5, $5, $7
1703 ldq $4, 56($17)
1704 addq $22, $7, $22
1705 srl $2, 32, $8
1706 cmpult $22, $7, $3
1707 zapnot $4, 15, $7
1708 mulq $8, $7, $0
1709 srl $28, 32, $1
1710 addq $6, $1, $6
1711 cmpult $5, $25, $1
1712 zapnot $2, 15, $5
1713 addq $1, $6, $6
1714 addq $3, $6, $6
1715 addq $24, $6, $24
1716 cmpult $24, $6, $1
1717 srl $4, 32, $6
1718 mulq $5, $6, $25
1719 mulq $7, $5, $2
1720 addq $1, $23, $23
1721 addq $0, $25, $0
1722 cmpult $0, $25, $1
1723 mulq $6, $8, $6
1724 beq $1, $313
1725 sll $20, 32, $1
1726 addq $6, $1, $6
1727$313:
1728 sll $0, 32, $25
1729 addq $2, $25, $2
1730 bis $2, $2, $7
1731 addq $22, $7, $22
1732 stq $22, 56($16)
1733 ldq $4, 56($17)
1734 ldq $5, 8($18)
1735 cmpult $22, $7, $3
1736 zapnot $4, 15, $7
1737 srl $5, 32, $8
1738 mulq $8, $7, $28
1739 srl $0, 32, $1
1740 cmpult $2, $25, $2
1741 addq $6, $1, $6
1742 addq $2, $6, $6
1743 addq $3, $6, $6
1744 addq $24, $6, $24
1745 cmpult $24, $6, $1
1746 srl $4, 32, $6
1747 zapnot $5, 15, $5
1748 mulq $5, $6, $22
1749 mulq $7, $5, $2
1750 addq $1, $23, $23
1751 addq $28, $22, $28
1752 cmpult $28, $22, $1
1753 mulq $6, $8, $6
1754 beq $1, $317
1755 sll $20, 32, $1
1756 addq $6, $1, $6
1757$317:
1758 sll $28, 32, $22
1759 ldq $1, 16($18)
1760 addq $2, $22, $2
1761 bis $2, $2, $7
1762 ldq $4, 48($17)
1763 addq $24, $7, $24
1764 srl $1, 32, $8
1765 cmpult $24, $7, $3
1766 zapnot $4, 15, $7
1767 mulq $8, $7, $25
1768 zapnot $1, 15, $5
1769 mulq $7, $5, $0
1770 srl $28, 32, $1
1771 cmpult $2, $22, $2
1772 addq $6, $1, $6
1773 addq $2, $6, $6
1774 addq $3, $6, $6
1775 addq $23, $6, $23
1776 cmpult $23, $6, $22
1777 srl $4, 32, $6
1778 mulq $5, $6, $5
1779 bis $31, 1, $21
1780 addq $25, $5, $25
1781 cmpult $25, $5, $1
1782 mulq $6, $8, $6
1783 beq $1, $321
1784 sll $21, 32, $1
1785 addq $6, $1, $6
1786$321:
1787 sll $25, 32, $5
1788 ldq $2, 24($18)
1789 addq $0, $5, $0
1790 bis $0, $0, $7
1791 ldq $4, 40($17)
1792 addq $24, $7, $24
1793 srl $2, 32, $8
1794 cmpult $24, $7, $3
1795 zapnot $4, 15, $7
1796 mulq $8, $7, $28
1797 srl $25, 32, $1
1798 addq $6, $1, $6
1799 cmpult $0, $5, $1
1800 zapnot $2, 15, $5
1801 addq $1, $6, $6
1802 addq $3, $6, $6
1803 addq $23, $6, $23
1804 cmpult $23, $6, $1
1805 srl $4, 32, $6
1806 mulq $5, $6, $25
1807 mulq $7, $5, $5
1808 addq $1, $22, $22
1809 addq $28, $25, $28
1810 cmpult $28, $25, $1
1811 mulq $6, $8, $6
1812 beq $1, $325
1813 sll $21, 32, $1
1814 addq $6, $1, $6
1815$325:
1816 sll $28, 32, $25
1817 ldq $2, 32($18)
1818 addq $5, $25, $5
1819 bis $5, $5, $7
1820 ldq $4, 32($17)
1821 addq $24, $7, $24
1822 srl $2, 32, $8
1823 cmpult $24, $7, $3
1824 zapnot $4, 15, $7
1825 mulq $8, $7, $0
1826 srl $28, 32, $1
1827 addq $6, $1, $6
1828 cmpult $5, $25, $1
1829 zapnot $2, 15, $5
1830 addq $1, $6, $6
1831 addq $3, $6, $6
1832 addq $23, $6, $23
1833 cmpult $23, $6, $1
1834 srl $4, 32, $6
1835 mulq $5, $6, $25
1836 mulq $7, $5, $5
1837 addq $1, $22, $22
1838 addq $0, $25, $0
1839 cmpult $0, $25, $1
1840 mulq $6, $8, $6
1841 beq $1, $329
1842 sll $21, 32, $1
1843 addq $6, $1, $6
1844$329:
1845 sll $0, 32, $25
1846 ldq $2, 40($18)
1847 addq $5, $25, $5
1848 bis $5, $5, $7
1849 ldq $4, 24($17)
1850 addq $24, $7, $24
1851 srl $2, 32, $8
1852 cmpult $24, $7, $3
1853 zapnot $4, 15, $7
1854 mulq $8, $7, $28
1855 srl $0, 32, $1
1856 addq $6, $1, $6
1857 cmpult $5, $25, $1
1858 zapnot $2, 15, $5
1859 addq $1, $6, $6
1860 addq $3, $6, $6
1861 addq $23, $6, $23
1862 cmpult $23, $6, $1
1863 srl $4, 32, $6
1864 mulq $5, $6, $25
1865 mulq $7, $5, $5
1866 addq $1, $22, $22
1867 addq $28, $25, $28
1868 cmpult $28, $25, $1
1869 mulq $6, $8, $6
1870 beq $1, $333
1871 sll $21, 32, $1
1872 addq $6, $1, $6
1873$333:
1874 sll $28, 32, $25
1875 ldq $2, 48($18)
1876 addq $5, $25, $5
1877 bis $5, $5, $7
1878 ldq $4, 16($17)
1879 addq $24, $7, $24
1880 srl $2, 32, $8
1881 cmpult $24, $7, $3
1882 zapnot $4, 15, $7
1883 mulq $8, $7, $0
1884 srl $28, 32, $1
1885 addq $6, $1, $6
1886 cmpult $5, $25, $1
1887 zapnot $2, 15, $5
1888 addq $1, $6, $6
1889 addq $3, $6, $6
1890 addq $23, $6, $23
1891 cmpult $23, $6, $1
1892 srl $4, 32, $6
1893 mulq $5, $6, $25
1894 mulq $7, $5, $5
1895 addq $1, $22, $22
1896 addq $0, $25, $0
1897 cmpult $0, $25, $1
1898 mulq $6, $8, $6
1899 beq $1, $337
1900 sll $21, 32, $1
1901 addq $6, $1, $6
1902$337:
1903 sll $0, 32, $25
1904 ldq $2, 56($18)
1905 addq $5, $25, $5
1906 bis $5, $5, $7
1907 ldq $4, 8($17)
1908 addq $24, $7, $24
1909 srl $2, 32, $8
1910 cmpult $24, $7, $3
1911 zapnot $4, 15, $7
1912 mulq $8, $7, $28
1913 srl $0, 32, $1
1914 addq $6, $1, $6
1915 cmpult $5, $25, $1
1916 zapnot $2, 15, $5
1917 addq $1, $6, $6
1918 addq $3, $6, $6
1919 addq $23, $6, $23
1920 cmpult $23, $6, $1
1921 srl $4, 32, $6
1922 mulq $5, $6, $25
1923 mulq $7, $5, $2
1924 addq $1, $22, $22
1925 addq $28, $25, $28
1926 cmpult $28, $25, $1
1927 mulq $6, $8, $6
1928 beq $1, $341
1929 sll $21, 32, $1
1930 addq $6, $1, $6
1931$341:
1932 sll $28, 32, $25
1933 addq $2, $25, $2
1934 bis $2, $2, $7
1935 addq $24, $7, $24
1936 stq $24, 64($16)
1937 ldq $4, 16($17)
1938 ldq $5, 56($18)
1939 cmpult $24, $7, $3
1940 zapnot $4, 15, $7
1941 srl $5, 32, $8
1942 mulq $8, $7, $0
1943 srl $28, 32, $1
1944 cmpult $2, $25, $2
1945 addq $6, $1, $6
1946 addq $2, $6, $6
1947 addq $3, $6, $6
1948 addq $23, $6, $23
1949 cmpult $23, $6, $1
1950 srl $4, 32, $6
1951 zapnot $5, 15, $5
1952 mulq $5, $6, $24
1953 mulq $7, $5, $2
1954 addq $1, $22, $22
1955 addq $0, $24, $0
1956 cmpult $0, $24, $1
1957 mulq $6, $8, $6
1958 beq $1, $345
1959 sll $21, 32, $1
1960 addq $6, $1, $6
1961$345:
1962 sll $0, 32, $24
1963 ldq $1, 48($18)
1964 addq $2, $24, $2
1965 bis $2, $2, $7
1966 ldq $4, 24($17)
1967 addq $23, $7, $23
1968 srl $1, 32, $8
1969 cmpult $23, $7, $3
1970 zapnot $4, 15, $7
1971 mulq $8, $7, $25
1972 zapnot $1, 15, $5
1973 mulq $7, $5, $21
1974 srl $0, 32, $1
1975 cmpult $2, $24, $2
1976 addq $6, $1, $6
1977 addq $2, $6, $6
1978 addq $3, $6, $6
1979 addq $22, $6, $22
1980 cmpult $22, $6, $24
1981 srl $4, 32, $6
1982 mulq $5, $6, $5
1983 bis $31, 1, $20
1984 addq $25, $5, $25
1985 cmpult $25, $5, $1
1986 mulq $6, $8, $6
1987 beq $1, $349
1988 sll $20, 32, $1
1989 addq $6, $1, $6
1990$349:
1991 sll $25, 32, $5
1992 ldq $2, 40($18)
1993 addq $21, $5, $21
1994 bis $21, $21, $7
1995 ldq $4, 32($17)
1996 addq $23, $7, $23
1997 srl $2, 32, $8
1998 cmpult $23, $7, $3
1999 zapnot $4, 15, $7
2000 mulq $8, $7, $28
2001 srl $25, 32, $1
2002 addq $6, $1, $6
2003 cmpult $21, $5, $1
2004 zapnot $2, 15, $5
2005 addq $1, $6, $6
2006 addq $3, $6, $6
2007 addq $22, $6, $22
2008 cmpult $22, $6, $1
2009 srl $4, 32, $6
2010 mulq $5, $6, $25
2011 mulq $7, $5, $5
2012 addq $1, $24, $24
2013 addq $28, $25, $28
2014 cmpult $28, $25, $1
2015 mulq $6, $8, $6
2016 beq $1, $353
2017 sll $20, 32, $1
2018 addq $6, $1, $6
2019$353:
2020 sll $28, 32, $25
2021 ldq $2, 32($18)
2022 addq $5, $25, $5
2023 bis $5, $5, $7
2024 ldq $4, 40($17)
2025 addq $23, $7, $23
2026 srl $2, 32, $8
2027 cmpult $23, $7, $3
2028 zapnot $4, 15, $7
2029 mulq $8, $7, $0
2030 srl $28, 32, $1
2031 addq $6, $1, $6
2032 cmpult $5, $25, $1
2033 zapnot $2, 15, $5
2034 addq $1, $6, $6
2035 addq $3, $6, $6
2036 addq $22, $6, $22
2037 cmpult $22, $6, $1
2038 srl $4, 32, $6
2039 mulq $5, $6, $25
2040 mulq $7, $5, $5
2041 addq $1, $24, $24
2042 addq $0, $25, $0
2043 cmpult $0, $25, $1
2044 mulq $6, $8, $6
2045 beq $1, $357
2046 sll $20, 32, $1
2047 addq $6, $1, $6
2048$357:
2049 sll $0, 32, $25
2050 ldq $2, 24($18)
2051 addq $5, $25, $5
2052 bis $5, $5, $7
2053 ldq $4, 48($17)
2054 addq $23, $7, $23
2055 srl $2, 32, $8
2056 cmpult $23, $7, $3
2057 zapnot $4, 15, $7
2058 mulq $8, $7, $28
2059 srl $0, 32, $1
2060 addq $6, $1, $6
2061 cmpult $5, $25, $1
2062 zapnot $2, 15, $5
2063 addq $1, $6, $6
2064 addq $3, $6, $6
2065 addq $22, $6, $22
2066 cmpult $22, $6, $1
2067 srl $4, 32, $6
2068 mulq $5, $6, $25
2069 mulq $7, $5, $5
2070 addq $1, $24, $24
2071 addq $28, $25, $28
2072 cmpult $28, $25, $1
2073 mulq $6, $8, $6
2074 beq $1, $361
2075 sll $20, 32, $1
2076 addq $6, $1, $6
2077$361:
2078 sll $28, 32, $25
2079 ldq $2, 16($18)
2080 addq $5, $25, $5
2081 bis $5, $5, $7
2082 ldq $4, 56($17)
2083 addq $23, $7, $23
2084 srl $2, 32, $8
2085 cmpult $23, $7, $3
2086 zapnot $4, 15, $7
2087 mulq $8, $7, $0
2088 srl $28, 32, $1
2089 addq $6, $1, $6
2090 cmpult $5, $25, $1
2091 zapnot $2, 15, $5
2092 addq $1, $6, $6
2093 addq $3, $6, $6
2094 addq $22, $6, $22
2095 cmpult $22, $6, $1
2096 srl $4, 32, $6
2097 mulq $5, $6, $25
2098 mulq $7, $5, $2
2099 addq $1, $24, $24
2100 addq $0, $25, $0
2101 cmpult $0, $25, $1
2102 mulq $6, $8, $6
2103 beq $1, $365
2104 sll $20, 32, $1
2105 addq $6, $1, $6
2106$365:
2107 sll $0, 32, $25
2108 addq $2, $25, $2
2109 bis $2, $2, $7
2110 addq $23, $7, $23
2111 stq $23, 72($16)
2112 ldq $4, 56($17)
2113 ldq $5, 24($18)
2114 cmpult $23, $7, $3
2115 zapnot $4, 15, $7
2116 srl $5, 32, $8
2117 mulq $8, $7, $28
2118 srl $0, 32, $1
2119 cmpult $2, $25, $2
2120 addq $6, $1, $6
2121 addq $2, $6, $6
2122 addq $3, $6, $6
2123 addq $22, $6, $22
2124 cmpult $22, $6, $1
2125 srl $4, 32, $6
2126 zapnot $5, 15, $5
2127 mulq $5, $6, $23
2128 mulq $7, $5, $2
2129 addq $1, $24, $24
2130 addq $28, $23, $28
2131 cmpult $28, $23, $1
2132 mulq $6, $8, $6
2133 beq $1, $369
2134 sll $20, 32, $1
2135 addq $6, $1, $6
2136$369:
2137 sll $28, 32, $23
2138 ldq $1, 32($18)
2139 addq $2, $23, $2
2140 bis $2, $2, $7
2141 ldq $4, 48($17)
2142 addq $22, $7, $22
2143 srl $1, 32, $8
2144 cmpult $22, $7, $3
2145 zapnot $4, 15, $7
2146 mulq $8, $7, $25
2147 zapnot $1, 15, $5
2148 mulq $7, $5, $0
2149 srl $28, 32, $1
2150 cmpult $2, $23, $2
2151 addq $6, $1, $6
2152 addq $2, $6, $6
2153 addq $3, $6, $6
2154 addq $24, $6, $24
2155 cmpult $24, $6, $23
2156 srl $4, 32, $6
2157 mulq $5, $6, $5
2158 bis $31, 1, $21
2159 addq $25, $5, $25
2160 cmpult $25, $5, $1
2161 mulq $6, $8, $6
2162 beq $1, $373
2163 sll $21, 32, $1
2164 addq $6, $1, $6
2165$373:
2166 sll $25, 32, $5
2167 ldq $2, 40($18)
2168 addq $0, $5, $0
2169 bis $0, $0, $7
2170 ldq $4, 40($17)
2171 addq $22, $7, $22
2172 srl $2, 32, $8
2173 cmpult $22, $7, $3
2174 zapnot $4, 15, $7
2175 mulq $8, $7, $28
2176 srl $25, 32, $1
2177 addq $6, $1, $6
2178 cmpult $0, $5, $1
2179 zapnot $2, 15, $5
2180 addq $1, $6, $6
2181 addq $3, $6, $6
2182 addq $24, $6, $24
2183 cmpult $24, $6, $1
2184 srl $4, 32, $6
2185 mulq $5, $6, $25
2186 mulq $7, $5, $5
2187 addq $1, $23, $23
2188 addq $28, $25, $28
2189 cmpult $28, $25, $1
2190 mulq $6, $8, $6
2191 beq $1, $377
2192 sll $21, 32, $1
2193 addq $6, $1, $6
2194$377:
2195 sll $28, 32, $25
2196 ldq $2, 48($18)
2197 addq $5, $25, $5
2198 bis $5, $5, $7
2199 ldq $4, 32($17)
2200 addq $22, $7, $22
2201 srl $2, 32, $8
2202 cmpult $22, $7, $3
2203 zapnot $4, 15, $7
2204 mulq $8, $7, $0
2205 srl $28, 32, $1
2206 addq $6, $1, $6
2207 cmpult $5, $25, $1
2208 zapnot $2, 15, $5
2209 addq $1, $6, $6
2210 addq $3, $6, $6
2211 addq $24, $6, $24
2212 cmpult $24, $6, $1
2213 srl $4, 32, $6
2214 mulq $5, $6, $25
2215 mulq $7, $5, $5
2216 addq $1, $23, $23
2217 addq $0, $25, $0
2218 cmpult $0, $25, $1
2219 mulq $6, $8, $6
2220 beq $1, $381
2221 sll $21, 32, $1
2222 addq $6, $1, $6
2223$381:
2224 sll $0, 32, $25
2225 ldq $2, 56($18)
2226 addq $5, $25, $5
2227 bis $5, $5, $7
2228 ldq $4, 24($17)
2229 addq $22, $7, $22
2230 srl $2, 32, $8
2231 cmpult $22, $7, $3
2232 zapnot $4, 15, $7
2233 mulq $8, $7, $28
2234 srl $0, 32, $1
2235 addq $6, $1, $6
2236 cmpult $5, $25, $1
2237 zapnot $2, 15, $5
2238 addq $1, $6, $6
2239 addq $3, $6, $6
2240 addq $24, $6, $24
2241 cmpult $24, $6, $1
2242 srl $4, 32, $6
2243 mulq $5, $6, $25
2244 mulq $7, $5, $2
2245 addq $1, $23, $23
2246 addq $28, $25, $28
2247 cmpult $28, $25, $1
2248 mulq $6, $8, $6
2249 beq $1, $385
2250 sll $21, 32, $1
2251 addq $6, $1, $6
2252$385:
2253 sll $28, 32, $25
2254 addq $2, $25, $2
2255 bis $2, $2, $7
2256 addq $22, $7, $22
2257 stq $22, 80($16)
2258 ldq $4, 32($17)
2259 ldq $5, 56($18)
2260 cmpult $22, $7, $3
2261 zapnot $4, 15, $7
2262 srl $5, 32, $8
2263 mulq $8, $7, $0
2264 srl $28, 32, $1
2265 cmpult $2, $25, $2
2266 addq $6, $1, $6
2267 addq $2, $6, $6
2268 addq $3, $6, $6
2269 addq $24, $6, $24
2270 cmpult $24, $6, $1
2271 srl $4, 32, $6
2272 zapnot $5, 15, $5
2273 mulq $5, $6, $22
2274 mulq $7, $5, $2
2275 addq $1, $23, $23
2276 addq $0, $22, $0
2277 cmpult $0, $22, $1
2278 mulq $6, $8, $6
2279 beq $1, $389
2280 sll $21, 32, $1
2281 addq $6, $1, $6
2282$389:
2283 sll $0, 32, $22
2284 ldq $1, 48($18)
2285 addq $2, $22, $2
2286 bis $2, $2, $7
2287 ldq $4, 40($17)
2288 addq $24, $7, $24
2289 srl $1, 32, $8
2290 cmpult $24, $7, $3
2291 zapnot $4, 15, $7
2292 mulq $8, $7, $25
2293 zapnot $1, 15, $5
2294 mulq $7, $5, $21
2295 srl $0, 32, $1
2296 cmpult $2, $22, $2
2297 addq $6, $1, $6
2298 addq $2, $6, $6
2299 addq $3, $6, $6
2300 addq $23, $6, $23
2301 cmpult $23, $6, $22
2302 srl $4, 32, $6
2303 mulq $5, $6, $5
2304 bis $31, 1, $20
2305 addq $25, $5, $25
2306 cmpult $25, $5, $1
2307 mulq $6, $8, $6
2308 beq $1, $393
2309 sll $20, 32, $1
2310 addq $6, $1, $6
2311$393:
2312 sll $25, 32, $5
2313 ldq $2, 40($18)
2314 addq $21, $5, $21
2315 bis $21, $21, $7
2316 ldq $4, 48($17)
2317 addq $24, $7, $24
2318 srl $2, 32, $8
2319 cmpult $24, $7, $3
2320 zapnot $4, 15, $7
2321 mulq $8, $7, $28
2322 srl $25, 32, $1
2323 addq $6, $1, $6
2324 cmpult $21, $5, $1
2325 zapnot $2, 15, $5
2326 addq $1, $6, $6
2327 addq $3, $6, $6
2328 addq $23, $6, $23
2329 cmpult $23, $6, $1
2330 srl $4, 32, $6
2331 mulq $5, $6, $25
2332 mulq $7, $5, $5
2333 addq $1, $22, $22
2334 addq $28, $25, $28
2335 cmpult $28, $25, $1
2336 mulq $6, $8, $6
2337 beq $1, $397
2338 sll $20, 32, $1
2339 addq $6, $1, $6
2340$397:
2341 sll $28, 32, $25
2342 ldq $2, 32($18)
2343 addq $5, $25, $5
2344 bis $5, $5, $7
2345 ldq $4, 56($17)
2346 addq $24, $7, $24
2347 srl $2, 32, $8
2348 cmpult $24, $7, $3
2349 zapnot $4, 15, $7
2350 mulq $8, $7, $21
2351 srl $28, 32, $1
2352 addq $6, $1, $6
2353 cmpult $5, $25, $1
2354 zapnot $2, 15, $5
2355 addq $1, $6, $6
2356 addq $3, $6, $6
2357 addq $23, $6, $23
2358 cmpult $23, $6, $1
2359 srl $4, 32, $6
2360 mulq $5, $6, $25
2361 mulq $7, $5, $2
2362 addq $1, $22, $22
2363 addq $21, $25, $21
2364 cmpult $21, $25, $1
2365 mulq $6, $8, $6
2366 beq $1, $401
2367 sll $20, 32, $1
2368 addq $6, $1, $6
2369$401:
2370 sll $21, 32, $25
2371 addq $2, $25, $2
2372 bis $2, $2, $7
2373 addq $24, $7, $24
2374 stq $24, 88($16)
2375 ldq $4, 56($17)
2376 ldq $5, 40($18)
2377 cmpult $24, $7, $3
2378 zapnot $4, 15, $7
2379 srl $5, 32, $8
2380 mulq $8, $7, $0
2381 srl $21, 32, $1
2382 cmpult $2, $25, $2
2383 addq $6, $1, $6
2384 addq $2, $6, $6
2385 addq $3, $6, $6
2386 addq $23, $6, $23
2387 cmpult $23, $6, $1
2388 srl $4, 32, $6
2389 zapnot $5, 15, $5
2390 mulq $5, $6, $24
2391 mulq $7, $5, $5
2392 addq $1, $22, $22
2393 addq $0, $24, $0
2394 cmpult $0, $24, $1
2395 mulq $6, $8, $6
2396 beq $1, $405
2397 sll $20, 32, $1
2398 addq $6, $1, $6
2399$405:
2400 sll $0, 32, $24
2401 ldq $2, 48($18)
2402 addq $5, $24, $5
2403 bis $5, $5, $7
2404 ldq $4, 48($17)
2405 addq $23, $7, $23
2406 srl $2, 32, $8
2407 cmpult $23, $7, $3
2408 zapnot $4, 15, $7
2409 mulq $8, $7, $28
2410 srl $0, 32, $1
2411 addq $6, $1, $6
2412 cmpult $5, $24, $1
2413 zapnot $2, 15, $5
2414 addq $1, $6, $6
2415 addq $3, $6, $6
2416 addq $22, $6, $22
2417 cmpult $22, $6, $24
2418 srl $4, 32, $6
2419 mulq $5, $6, $25
2420 mulq $7, $5, $5
2421 addq $28, $25, $28
2422 cmpult $28, $25, $1
2423 mulq $6, $8, $6
2424 beq $1, $409
2425 sll $20, 32, $1
2426 addq $6, $1, $6
2427$409:
2428 sll $28, 32, $25
2429 ldq $2, 56($18)
2430 addq $5, $25, $5
2431 bis $5, $5, $7
2432 ldq $4, 40($17)
2433 addq $23, $7, $23
2434 srl $2, 32, $8
2435 cmpult $23, $7, $3
2436 zapnot $4, 15, $7
2437 mulq $8, $7, $0
2438 srl $28, 32, $1
2439 addq $6, $1, $6
2440 cmpult $5, $25, $1
2441 zapnot $2, 15, $5
2442 addq $1, $6, $6
2443 addq $3, $6, $6
2444 addq $22, $6, $22
2445 cmpult $22, $6, $1
2446 srl $4, 32, $6
2447 mulq $5, $6, $25
2448 mulq $7, $5, $2
2449 addq $1, $24, $24
2450 addq $0, $25, $0
2451 cmpult $0, $25, $1
2452 mulq $6, $8, $6
2453 beq $1, $413
2454 sll $20, 32, $1
2455 addq $6, $1, $6
2456$413:
2457 sll $0, 32, $25
2458 addq $2, $25, $2
2459 bis $2, $2, $7
2460 addq $23, $7, $23
2461 stq $23, 96($16)
2462 ldq $4, 48($17)
2463 ldq $5, 56($18)
2464 cmpult $23, $7, $3
2465 zapnot $4, 15, $7
2466 srl $5, 32, $8
2467 mulq $8, $7, $28
2468 srl $0, 32, $1
2469 cmpult $2, $25, $2
2470 addq $6, $1, $6
2471 addq $2, $6, $6
2472 addq $3, $6, $6
2473 addq $22, $6, $22
2474 cmpult $22, $6, $1
2475 srl $4, 32, $6
2476 zapnot $5, 15, $5
2477 mulq $5, $6, $23
2478 mulq $7, $5, $5
2479 addq $1, $24, $24
2480 addq $28, $23, $28
2481 cmpult $28, $23, $1
2482 mulq $6, $8, $6
2483 beq $1, $417
2484 sll $20, 32, $1
2485 addq $6, $1, $6
2486$417:
2487 sll $28, 32, $23
2488 ldq $2, 48($18)
2489 addq $5, $23, $5
2490 bis $5, $5, $7
2491 ldq $4, 56($17)
2492 addq $22, $7, $22
2493 srl $2, 32, $8
2494 cmpult $22, $7, $3
2495 zapnot $4, 15, $7
2496 mulq $8, $7, $0
2497 srl $28, 32, $1
2498 addq $6, $1, $6
2499 cmpult $5, $23, $1
2500 zapnot $2, 15, $5
2501 addq $1, $6, $6
2502 addq $3, $6, $6
2503 addq $24, $6, $24
2504 cmpult $24, $6, $23
2505 srl $4, 32, $6
2506 mulq $5, $6, $25
2507 mulq $7, $5, $2
2508 addq $0, $25, $0
2509 cmpult $0, $25, $1
2510 mulq $6, $8, $6
2511 beq $1, $421
2512 sll $20, 32, $1
2513 addq $6, $1, $6
2514$421:
2515 sll $0, 32, $25
2516 addq $2, $25, $2
2517 bis $2, $2, $7
2518 addq $22, $7, $22
2519 stq $22, 104($16)
2520 ldq $4, 56($17)
2521 ldq $5, 56($18)
2522 cmpult $22, $7, $3
2523 zapnot $4, 15, $7
2524 srl $5, 32, $8
2525 mulq $8, $7, $28
2526 srl $0, 32, $1
2527 cmpult $2, $25, $2
2528 addq $6, $1, $6
2529 addq $2, $6, $6
2530 addq $3, $6, $6
2531 addq $24, $6, $24
2532 cmpult $24, $6, $1
2533 srl $4, 32, $6
2534 zapnot $5, 15, $5
2535 mulq $5, $6, $22
2536 mulq $7, $5, $2
2537 addq $1, $23, $23
2538 addq $28, $22, $28
2539 cmpult $28, $22, $1
2540 mulq $6, $8, $3
2541 beq $1, $425
2542 sll $20, 32, $1
2543 addq $3, $1, $3
2544$425:
2545 sll $28, 32, $22
2546 srl $28, 32, $1
2547 addq $2, $22, $2
2548 addq $3, $1, $3
2549 bis $2, $2, $7
2550 addq $24, $7, $24
2551 cmpult $7, $22, $1
2552 cmpult $24, $7, $2
2553 addq $1, $3, $6
2554 addq $2, $6, $6
2555 stq $24, 112($16)
2556 addq $23, $6, $23
2557 stq $23, 120($16)
2558 ret $31, ($26), 1
2559 .end bn_mul_comba8
2560 .text
2561 .align 3
2562 .globl bn_sqr_comba4
2563 .ent bn_sqr_comba4
2564bn_sqr_comba4:
2565bn_sqr_comba4..ng:
2566 .frame $30,0,$26,0
2567 .prologue 0
2568
2569 ldq $0, 0($17)
2570 ldq $1, 8($17)
2571 ldq $2, 16($17)
2572 ldq $3, 24($17)
2573 bis $31, $31, $6
2574 mulq $0, $0, $4
2575 umulh $0, $0, $5
2576 stq $4, 0($16)
2577 bis $31, $31, $4
2578 mulq $0, $1, $7
2579 umulh $0, $1, $8
2580 cmplt $7, $31, $22
2581 cmplt $8, $31, $23
2582 addq $7, $7, $7
2583 addq $8, $8, $8
2584 addq $8, $22, $8
2585 addq $4, $23, $4
2586 addq $5, $7, $5
2587 addq $6, $8, $6
2588 cmpult $5, $7, $24
2589 cmpult $6, $8, $25
2590 addq $6, $24, $6
2591 addq $4, $25, $4
2592 stq $5, 8($16)
2593 bis $31, $31, $5
2594 mulq $1, $1, $27
2595 umulh $1, $1, $28
2596 addq $6, $27, $6
2597 addq $4, $28, $4
2598 cmpult $6, $27, $21
2599 cmpult $4, $28, $20
2600 addq $4, $21, $4
2601 addq $5, $20, $5
2602 mulq $2, $0, $19
2603 umulh $2, $0, $18
2604 cmplt $19, $31, $17
2605 cmplt $18, $31, $22
2606 addq $19, $19, $19
2607 addq $18, $18, $18
2608 addq $18, $17, $18
2609 addq $5, $22, $5
2610 addq $6, $19, $6
2611 addq $4, $18, $4
2612 cmpult $6, $19, $23
2613 cmpult $4, $18, $7
2614 addq $4, $23, $4
2615 addq $5, $7, $5
2616 stq $6, 16($16)
2617 bis $31, $31, $6
2618 mulq $3, $0, $8
2619 umulh $3, $0, $24
2620 cmplt $8, $31, $25
2621 cmplt $24, $31, $27
2622 addq $8, $8, $8
2623 addq $24, $24, $24
2624 addq $24, $25, $24
2625 addq $6, $27, $6
2626 addq $4, $8, $4
2627 addq $5, $24, $5
2628 cmpult $4, $8, $28
2629 cmpult $5, $24, $21
2630 addq $5, $28, $5
2631 addq $6, $21, $6
2632 mulq $2, $1, $20
2633 umulh $2, $1, $17
2634 cmplt $20, $31, $22
2635 cmplt $17, $31, $19
2636 addq $20, $20, $20
2637 addq $17, $17, $17
2638 addq $17, $22, $17
2639 addq $6, $19, $6
2640 addq $4, $20, $4
2641 addq $5, $17, $5
2642 cmpult $4, $20, $18
2643 cmpult $5, $17, $23
2644 addq $5, $18, $5
2645 addq $6, $23, $6
2646 stq $4, 24($16)
2647 bis $31, $31, $4
2648 mulq $2, $2, $7
2649 umulh $2, $2, $25
2650 addq $5, $7, $5
2651 addq $6, $25, $6
2652 cmpult $5, $7, $27
2653 cmpult $6, $25, $8
2654 addq $6, $27, $6
2655 addq $4, $8, $4
2656 mulq $3, $1, $24
2657 umulh $3, $1, $28
2658 cmplt $24, $31, $21
2659 cmplt $28, $31, $22
2660 addq $24, $24, $24
2661 addq $28, $28, $28
2662 addq $28, $21, $28
2663 addq $4, $22, $4
2664 addq $5, $24, $5
2665 addq $6, $28, $6
2666 cmpult $5, $24, $19
2667 cmpult $6, $28, $20
2668 addq $6, $19, $6
2669 addq $4, $20, $4
2670 stq $5, 32($16)
2671 bis $31, $31, $5
2672 mulq $3, $2, $17
2673 umulh $3, $2, $18
2674 cmplt $17, $31, $23
2675 cmplt $18, $31, $7
2676 addq $17, $17, $17
2677 addq $18, $18, $18
2678 addq $18, $23, $18
2679 addq $5, $7, $5
2680 addq $6, $17, $6
2681 addq $4, $18, $4
2682 cmpult $6, $17, $25
2683 cmpult $4, $18, $27
2684 addq $4, $25, $4
2685 addq $5, $27, $5
2686 stq $6, 40($16)
2687 bis $31, $31, $6
2688 mulq $3, $3, $8
2689 umulh $3, $3, $21
2690 addq $4, $8, $4
2691 addq $5, $21, $5
2692 cmpult $4, $8, $22
2693 cmpult $5, $21, $24
2694 addq $5, $22, $5
2695 addq $6, $24, $6
2696 stq $4, 48($16)
2697 stq $5, 56($16)
2698 ret $31,($26),1
2699 .end bn_sqr_comba4
2700 .text
2701 .align 3
2702 .globl bn_sqr_comba8
2703 .ent bn_sqr_comba8
2704bn_sqr_comba8:
2705bn_sqr_comba8..ng:
2706 .frame $30,0,$26,0
2707 .prologue 0
2708
2709 ldq $0, 0($17)
2710 ldq $1, 8($17)
2711 ldq $2, 16($17)
2712 ldq $3, 24($17)
2713 ldq $4, 32($17)
2714 ldq $5, 40($17)
2715 ldq $6, 48($17)
2716 ldq $7, 56($17)
2717 bis $31, $31, $23
2718 mulq $0, $0, $8
2719 umulh $0, $0, $22
2720 stq $8, 0($16)
2721 bis $31, $31, $8
2722 mulq $1, $0, $24
2723 umulh $1, $0, $25
2724 cmplt $24, $31, $27
2725 cmplt $25, $31, $28
2726 addq $24, $24, $24
2727 addq $25, $25, $25
2728 addq $25, $27, $25
2729 addq $8, $28, $8
2730 addq $22, $24, $22
2731 addq $23, $25, $23
2732 cmpult $22, $24, $21
2733 cmpult $23, $25, $20
2734 addq $23, $21, $23
2735 addq $8, $20, $8
2736 stq $22, 8($16)
2737 bis $31, $31, $22
2738 mulq $1, $1, $19
2739 umulh $1, $1, $18
2740 addq $23, $19, $23
2741 addq $8, $18, $8
2742 cmpult $23, $19, $17
2743 cmpult $8, $18, $27
2744 addq $8, $17, $8
2745 addq $22, $27, $22
2746 mulq $2, $0, $28
2747 umulh $2, $0, $24
2748 cmplt $28, $31, $25
2749 cmplt $24, $31, $21
2750 addq $28, $28, $28
2751 addq $24, $24, $24
2752 addq $24, $25, $24
2753 addq $22, $21, $22
2754 addq $23, $28, $23
2755 addq $8, $24, $8
2756 cmpult $23, $28, $20
2757 cmpult $8, $24, $19
2758 addq $8, $20, $8
2759 addq $22, $19, $22
2760 stq $23, 16($16)
2761 bis $31, $31, $23
2762 mulq $2, $1, $18
2763 umulh $2, $1, $17
2764 cmplt $18, $31, $27
2765 cmplt $17, $31, $25
2766 addq $18, $18, $18
2767 addq $17, $17, $17
2768 addq $17, $27, $17
2769 addq $23, $25, $23
2770 addq $8, $18, $8
2771 addq $22, $17, $22
2772 cmpult $8, $18, $21
2773 cmpult $22, $17, $28
2774 addq $22, $21, $22
2775 addq $23, $28, $23
2776 mulq $3, $0, $24
2777 umulh $3, $0, $20
2778 cmplt $24, $31, $19
2779 cmplt $20, $31, $27
2780 addq $24, $24, $24
2781 addq $20, $20, $20
2782 addq $20, $19, $20
2783 addq $23, $27, $23
2784 addq $8, $24, $8
2785 addq $22, $20, $22
2786 cmpult $8, $24, $25
2787 cmpult $22, $20, $18
2788 addq $22, $25, $22
2789 addq $23, $18, $23
2790 stq $8, 24($16)
2791 bis $31, $31, $8
2792 mulq $2, $2, $17
2793 umulh $2, $2, $21
2794 addq $22, $17, $22
2795 addq $23, $21, $23
2796 cmpult $22, $17, $28
2797 cmpult $23, $21, $19
2798 addq $23, $28, $23
2799 addq $8, $19, $8
2800 mulq $3, $1, $27
2801 umulh $3, $1, $24
2802 cmplt $27, $31, $20
2803 cmplt $24, $31, $25
2804 addq $27, $27, $27
2805 addq $24, $24, $24
2806 addq $24, $20, $24
2807 addq $8, $25, $8
2808 addq $22, $27, $22
2809 addq $23, $24, $23
2810 cmpult $22, $27, $18
2811 cmpult $23, $24, $17
2812 addq $23, $18, $23
2813 addq $8, $17, $8
2814 mulq $4, $0, $21
2815 umulh $4, $0, $28
2816 cmplt $21, $31, $19
2817 cmplt $28, $31, $20
2818 addq $21, $21, $21
2819 addq $28, $28, $28
2820 addq $28, $19, $28
2821 addq $8, $20, $8
2822 addq $22, $21, $22
2823 addq $23, $28, $23
2824 cmpult $22, $21, $25
2825 cmpult $23, $28, $27
2826 addq $23, $25, $23
2827 addq $8, $27, $8
2828 stq $22, 32($16)
2829 bis $31, $31, $22
2830 mulq $3, $2, $24
2831 umulh $3, $2, $18
2832 cmplt $24, $31, $17
2833 cmplt $18, $31, $19
2834 addq $24, $24, $24
2835 addq $18, $18, $18
2836 addq $18, $17, $18
2837 addq $22, $19, $22
2838 addq $23, $24, $23
2839 addq $8, $18, $8
2840 cmpult $23, $24, $20
2841 cmpult $8, $18, $21
2842 addq $8, $20, $8
2843 addq $22, $21, $22
2844 mulq $4, $1, $28
2845 umulh $4, $1, $25
2846 cmplt $28, $31, $27
2847 cmplt $25, $31, $17
2848 addq $28, $28, $28
2849 addq $25, $25, $25
2850 addq $25, $27, $25
2851 addq $22, $17, $22
2852 addq $23, $28, $23
2853 addq $8, $25, $8
2854 cmpult $23, $28, $19
2855 cmpult $8, $25, $24
2856 addq $8, $19, $8
2857 addq $22, $24, $22
2858 mulq $5, $0, $18
2859 umulh $5, $0, $20
2860 cmplt $18, $31, $21
2861 cmplt $20, $31, $27
2862 addq $18, $18, $18
2863 addq $20, $20, $20
2864 addq $20, $21, $20
2865 addq $22, $27, $22
2866 addq $23, $18, $23
2867 addq $8, $20, $8
2868 cmpult $23, $18, $17
2869 cmpult $8, $20, $28
2870 addq $8, $17, $8
2871 addq $22, $28, $22
2872 stq $23, 40($16)
2873 bis $31, $31, $23
2874 mulq $3, $3, $25
2875 umulh $3, $3, $19
2876 addq $8, $25, $8
2877 addq $22, $19, $22
2878 cmpult $8, $25, $24
2879 cmpult $22, $19, $21
2880 addq $22, $24, $22
2881 addq $23, $21, $23
2882 mulq $4, $2, $27
2883 umulh $4, $2, $18
2884 cmplt $27, $31, $20
2885 cmplt $18, $31, $17
2886 addq $27, $27, $27
2887 addq $18, $18, $18
2888 addq $18, $20, $18
2889 addq $23, $17, $23
2890 addq $8, $27, $8
2891 addq $22, $18, $22
2892 cmpult $8, $27, $28
2893 cmpult $22, $18, $25
2894 addq $22, $28, $22
2895 addq $23, $25, $23
2896 mulq $5, $1, $19
2897 umulh $5, $1, $24
2898 cmplt $19, $31, $21
2899 cmplt $24, $31, $20
2900 addq $19, $19, $19
2901 addq $24, $24, $24
2902 addq $24, $21, $24
2903 addq $23, $20, $23
2904 addq $8, $19, $8
2905 addq $22, $24, $22
2906 cmpult $8, $19, $17
2907 cmpult $22, $24, $27
2908 addq $22, $17, $22
2909 addq $23, $27, $23
2910 mulq $6, $0, $18
2911 umulh $6, $0, $28
2912 cmplt $18, $31, $25
2913 cmplt $28, $31, $21
2914 addq $18, $18, $18
2915 addq $28, $28, $28
2916 addq $28, $25, $28
2917 addq $23, $21, $23
2918 addq $8, $18, $8
2919 addq $22, $28, $22
2920 cmpult $8, $18, $20
2921 cmpult $22, $28, $19
2922 addq $22, $20, $22
2923 addq $23, $19, $23
2924 stq $8, 48($16)
2925 bis $31, $31, $8
2926 mulq $4, $3, $24
2927 umulh $4, $3, $17
2928 cmplt $24, $31, $27
2929 cmplt $17, $31, $25
2930 addq $24, $24, $24
2931 addq $17, $17, $17
2932 addq $17, $27, $17
2933 addq $8, $25, $8
2934 addq $22, $24, $22
2935 addq $23, $17, $23
2936 cmpult $22, $24, $21
2937 cmpult $23, $17, $18
2938 addq $23, $21, $23
2939 addq $8, $18, $8
2940 mulq $5, $2, $28
2941 umulh $5, $2, $20
2942 cmplt $28, $31, $19
2943 cmplt $20, $31, $27
2944 addq $28, $28, $28
2945 addq $20, $20, $20
2946 addq $20, $19, $20
2947 addq $8, $27, $8
2948 addq $22, $28, $22
2949 addq $23, $20, $23
2950 cmpult $22, $28, $25
2951 cmpult $23, $20, $24
2952 addq $23, $25, $23
2953 addq $8, $24, $8
2954 mulq $6, $1, $17
2955 umulh $6, $1, $21
2956 cmplt $17, $31, $18
2957 cmplt $21, $31, $19
2958 addq $17, $17, $17
2959 addq $21, $21, $21
2960 addq $21, $18, $21
2961 addq $8, $19, $8
2962 addq $22, $17, $22
2963 addq $23, $21, $23
2964 cmpult $22, $17, $27
2965 cmpult $23, $21, $28
2966 addq $23, $27, $23
2967 addq $8, $28, $8
2968 mulq $7, $0, $20
2969 umulh $7, $0, $25
2970 cmplt $20, $31, $24
2971 cmplt $25, $31, $18
2972 addq $20, $20, $20
2973 addq $25, $25, $25
2974 addq $25, $24, $25
2975 addq $8, $18, $8
2976 addq $22, $20, $22
2977 addq $23, $25, $23
2978 cmpult $22, $20, $19
2979 cmpult $23, $25, $17
2980 addq $23, $19, $23
2981 addq $8, $17, $8
2982 stq $22, 56($16)
2983 bis $31, $31, $22
2984 mulq $4, $4, $21
2985 umulh $4, $4, $27
2986 addq $23, $21, $23
2987 addq $8, $27, $8
2988 cmpult $23, $21, $28
2989 cmpult $8, $27, $24
2990 addq $8, $28, $8
2991 addq $22, $24, $22
2992 mulq $5, $3, $18
2993 umulh $5, $3, $20
2994 cmplt $18, $31, $25
2995 cmplt $20, $31, $19
2996 addq $18, $18, $18
2997 addq $20, $20, $20
2998 addq $20, $25, $20
2999 addq $22, $19, $22
3000 addq $23, $18, $23
3001 addq $8, $20, $8
3002 cmpult $23, $18, $17
3003 cmpult $8, $20, $21
3004 addq $8, $17, $8
3005 addq $22, $21, $22
3006 mulq $6, $2, $27
3007 umulh $6, $2, $28
3008 cmplt $27, $31, $24
3009 cmplt $28, $31, $25
3010 addq $27, $27, $27
3011 addq $28, $28, $28
3012 addq $28, $24, $28
3013 addq $22, $25, $22
3014 addq $23, $27, $23
3015 addq $8, $28, $8
3016 cmpult $23, $27, $19
3017 cmpult $8, $28, $18
3018 addq $8, $19, $8
3019 addq $22, $18, $22
3020 mulq $7, $1, $20
3021 umulh $7, $1, $17
3022 cmplt $20, $31, $21
3023 cmplt $17, $31, $24
3024 addq $20, $20, $20
3025 addq $17, $17, $17
3026 addq $17, $21, $17
3027 addq $22, $24, $22
3028 addq $23, $20, $23
3029 addq $8, $17, $8
3030 cmpult $23, $20, $25
3031 cmpult $8, $17, $27
3032 addq $8, $25, $8
3033 addq $22, $27, $22
3034 stq $23, 64($16)
3035 bis $31, $31, $23
3036 mulq $5, $4, $28
3037 umulh $5, $4, $19
3038 cmplt $28, $31, $18
3039 cmplt $19, $31, $21
3040 addq $28, $28, $28
3041 addq $19, $19, $19
3042 addq $19, $18, $19
3043 addq $23, $21, $23
3044 addq $8, $28, $8
3045 addq $22, $19, $22
3046 cmpult $8, $28, $24
3047 cmpult $22, $19, $20
3048 addq $22, $24, $22
3049 addq $23, $20, $23
3050 mulq $6, $3, $17
3051 umulh $6, $3, $25
3052 cmplt $17, $31, $27
3053 cmplt $25, $31, $18
3054 addq $17, $17, $17
3055 addq $25, $25, $25
3056 addq $25, $27, $25
3057 addq $23, $18, $23
3058 addq $8, $17, $8
3059 addq $22, $25, $22
3060 cmpult $8, $17, $21
3061 cmpult $22, $25, $28
3062 addq $22, $21, $22
3063 addq $23, $28, $23
3064 mulq $7, $2, $19
3065 umulh $7, $2, $24
3066 cmplt $19, $31, $20
3067 cmplt $24, $31, $27
3068 addq $19, $19, $19
3069 addq $24, $24, $24
3070 addq $24, $20, $24
3071 addq $23, $27, $23
3072 addq $8, $19, $8
3073 addq $22, $24, $22
3074 cmpult $8, $19, $18
3075 cmpult $22, $24, $17
3076 addq $22, $18, $22
3077 addq $23, $17, $23
3078 stq $8, 72($16)
3079 bis $31, $31, $8
3080 mulq $5, $5, $25
3081 umulh $5, $5, $21
3082 addq $22, $25, $22
3083 addq $23, $21, $23
3084 cmpult $22, $25, $28
3085 cmpult $23, $21, $20
3086 addq $23, $28, $23
3087 addq $8, $20, $8
3088 mulq $6, $4, $27
3089 umulh $6, $4, $19
3090 cmplt $27, $31, $24
3091 cmplt $19, $31, $18
3092 addq $27, $27, $27
3093 addq $19, $19, $19
3094 addq $19, $24, $19
3095 addq $8, $18, $8
3096 addq $22, $27, $22
3097 addq $23, $19, $23
3098 cmpult $22, $27, $17
3099 cmpult $23, $19, $25
3100 addq $23, $17, $23
3101 addq $8, $25, $8
3102 mulq $7, $3, $21
3103 umulh $7, $3, $28
3104 cmplt $21, $31, $20
3105 cmplt $28, $31, $24
3106 addq $21, $21, $21
3107 addq $28, $28, $28
3108 addq $28, $20, $28
3109 addq $8, $24, $8
3110 addq $22, $21, $22
3111 addq $23, $28, $23
3112 cmpult $22, $21, $18
3113 cmpult $23, $28, $27
3114 addq $23, $18, $23
3115 addq $8, $27, $8
3116 stq $22, 80($16)
3117 bis $31, $31, $22
3118 mulq $6, $5, $19
3119 umulh $6, $5, $17
3120 cmplt $19, $31, $25
3121 cmplt $17, $31, $20
3122 addq $19, $19, $19
3123 addq $17, $17, $17
3124 addq $17, $25, $17
3125 addq $22, $20, $22
3126 addq $23, $19, $23
3127 addq $8, $17, $8
3128 cmpult $23, $19, $24
3129 cmpult $8, $17, $21
3130 addq $8, $24, $8
3131 addq $22, $21, $22
3132 mulq $7, $4, $28
3133 umulh $7, $4, $18
3134 cmplt $28, $31, $27
3135 cmplt $18, $31, $25
3136 addq $28, $28, $28
3137 addq $18, $18, $18
3138 addq $18, $27, $18
3139 addq $22, $25, $22
3140 addq $23, $28, $23
3141 addq $8, $18, $8
3142 cmpult $23, $28, $20
3143 cmpult $8, $18, $19
3144 addq $8, $20, $8
3145 addq $22, $19, $22
3146 stq $23, 88($16)
3147 bis $31, $31, $23
3148 mulq $6, $6, $17
3149 umulh $6, $6, $24
3150 addq $8, $17, $8
3151 addq $22, $24, $22
3152 cmpult $8, $17, $21
3153 cmpult $22, $24, $27
3154 addq $22, $21, $22
3155 addq $23, $27, $23
3156 mulq $7, $5, $25
3157 umulh $7, $5, $28
3158 cmplt $25, $31, $18
3159 cmplt $28, $31, $20
3160 addq $25, $25, $25
3161 addq $28, $28, $28
3162 addq $28, $18, $28
3163 addq $23, $20, $23
3164 addq $8, $25, $8
3165 addq $22, $28, $22
3166 cmpult $8, $25, $19
3167 cmpult $22, $28, $17
3168 addq $22, $19, $22
3169 addq $23, $17, $23
3170 stq $8, 96($16)
3171 bis $31, $31, $8
3172 mulq $7, $6, $24
3173 umulh $7, $6, $21
3174 cmplt $24, $31, $27
3175 cmplt $21, $31, $18
3176 addq $24, $24, $24
3177 addq $21, $21, $21
3178 addq $21, $27, $21
3179 addq $8, $18, $8
3180 addq $22, $24, $22
3181 addq $23, $21, $23
3182 cmpult $22, $24, $20
3183 cmpult $23, $21, $25
3184 addq $23, $20, $23
3185 addq $8, $25, $8
3186 stq $22, 104($16)
3187 bis $31, $31, $22
3188 mulq $7, $7, $28
3189 umulh $7, $7, $19
3190 addq $23, $28, $23
3191 addq $8, $19, $8
3192 cmpult $23, $28, $17
3193 cmpult $8, $19, $27
3194 addq $8, $17, $8
3195 addq $22, $27, $22
3196 stq $23, 112($16)
3197 stq $8, 120($16)
3198 ret $31,($26),1
3199 .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/alpha.works/add.pl b/src/lib/libcrypto/bn/asm/alpha.works/add.pl
new file mode 100644
index 0000000000..4dc76e6b69
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/add.pl
@@ -0,0 +1,119 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$b0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($b0,&QWPw(0,$bp));
28
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84##################################################
85 # Do the last 0..3 words
86
87 ($t0,$o0)=&NR(2);
88 &set_label("last_loop");
89
90 &ld($a0,&QWPw(0,$ap)); # get a
91 &ld($b0,&QWPw(0,$bp)); # get b
92
93 &add($a0,$b0,$o0);
94 &cmpult($o0,$b0,$t0); # will we borrow?
95 &add($o0,$cc,$o0); # will we borrow?
96 &cmpult($o0,$cc,$cc); # will we borrow?
97 &add($cc,$t0,$cc); # add the borrows
98 &st($o0,&QWPw(0,$rp)); # save
99
100 &add($ap,$QWS,$ap);
101 &add($bp,$QWS,$bp);
102 &add($rp,$QWS,$rp);
103 &sub($count,1,$count);
104 &bgt($count,&label("last_loop"));
105 &function_end_A($name);
106
107######################################################
108 &set_label("finish");
109 &add($count,4,$count);
110 &bgt($count,&label("last_loop"));
111
112 &FR($o0,$t0,$a0,$b0);
113 &set_label("end");
114 &function_end($name);
115
116 &fin_pool;
117 }
118
1191;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/div.pl b/src/lib/libcrypto/bn/asm/alpha.works/div.pl
new file mode 100644
index 0000000000..7ec144377f
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div64
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div64
15 .ent bn_div64
16bn_div64:
17 ldgp $29,0($27)
18bn_div64..ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div64
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul.pl
new file mode 100644
index 0000000000..b182bae452
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &mul($a0,$word,($l0)=&NR(1));
93 &add($ap,$QWS,$ap);
94 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
95 &add($l0,$cc,$l0);
96 &add($rp,$QWS,$rp);
97 &sub($count,1,$count);
98 &cmpult($l0,$cc,$cc);
99 &st($l0,&QWPw(-1,$rp)); &FR($l0);
100 &add($h0,$cc,$cc); &FR($h0);
101
102 &bgt($count,&label("last_loop"));
103 &function_end_A($name);
104
105######################################################
106 &set_label("finish");
107 &add($count,4,$count);
108 &bgt($count,&label("last_loop"));
109
110 &set_label("end");
111 &function_end($name);
112
113 &fin_pool;
114 }
115
1161;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl
new file mode 100644
index 0000000000..e37f6315fb
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_add.pl
@@ -0,0 +1,120 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &br(&label("finish"));
23 &blt($count,&label("finish"));
24
25 ($a0,$r0)=&NR(2);
26 &ld($a0,&QWPw(0,$ap));
27 &ld($r0,&QWPw(0,$rp));
28
29$a=<<'EOF';
30##########################################################
31 &set_label("loop");
32
33 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
34 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
35 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
36 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
37 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
38 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
39
40 ($o0,$t0)=&NR(2);
41 &add($a0,$b0,$o0);
42 &cmpult($o0,$b0,$t0);
43 &add($o0,$cc,$o0);
44 &cmpult($o0,$cc,$cc);
45 &add($cc,$t0,$cc); &FR($t0);
46
47 ($t1,$o1)=&NR(2);
48
49 &add($a1,$b1,$o1); &FR($a1);
50 &cmpult($o1,$b1,$t1); &FR($b1);
51 &add($o1,$cc,$o1);
52 &cmpult($o1,$cc,$cc);
53 &add($cc,$t1,$cc); &FR($t1);
54
55 ($t2,$o2)=&NR(2);
56
57 &add($a2,$b2,$o2); &FR($a2);
58 &cmpult($o2,$b2,$t2); &FR($b2);
59 &add($o2,$cc,$o2);
60 &cmpult($o2,$cc,$cc);
61 &add($cc,$t2,$cc); &FR($t2);
62
63 ($t3,$o3)=&NR(2);
64
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &cmpult($o3,$cc,$cc);
69 &add($cc,$t3,$cc); &FR($t3);
70
71 &st($o0,&QWPw(0,$rp)); &FR($o0);
72 &st($o1,&QWPw(0,$rp)); &FR($o1);
73 &st($o2,&QWPw(0,$rp)); &FR($o2);
74 &st($o3,&QWPw(0,$rp)); &FR($o3);
75
76 &sub($count,4,$count); # count-=4
77 &add($ap,4*$QWS,$ap); # count+=4
78 &add($bp,4*$QWS,$bp); # count+=4
79 &add($rp,4*$QWS,$rp); # count+=4
80
81 &blt($count,&label("finish"));
82 &ld($a0,&QWPw(0,$ap));
83 &ld($b0,&QWPw(0,$bp));
84 &br(&label("loop"));
85EOF
86##################################################
87 # Do the last 0..3 words
88
89 &set_label("last_loop");
90
91 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
92 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
93 &mul($a0,$word,($l0)=&NR(1));
94 &sub($count,1,$count);
95 &add($ap,$QWS,$ap);
96 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
97 &add($r0,$l0,$r0);
98 &add($rp,$QWS,$rp);
99 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
100 &add($r0,$cc,$r0);
101 &add($h0,$t0,$h0); &FR($t0);
102 &cmpult($r0,$cc,$cc);
103 &st($r0,&QWPw(-1,$rp)); &FR($r0);
104 &add($h0,$cc,$cc); &FR($h0);
105
106 &bgt($count,&label("last_loop"));
107 &function_end_A($name);
108
109######################################################
110 &set_label("finish");
111 &add($count,4,$count);
112 &bgt($count,&label("last_loop"));
113
114 &set_label("end");
115 &function_end($name);
116
117 &fin_pool;
118 }
119
1201;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl
new file mode 100644
index 0000000000..5efd201281
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.pl
@@ -0,0 +1,213 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$b,($l1)=&NR(1));
10 &muh($a,$b,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
13 &add($t1,$h1,$h1); &FR($t1);
14 &add($c1,$h1,$c1);
15 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub bn_mul_comba4
20 {
21 local($name)=@_;
22 local(@a,@b,$r,$c0,$c1,$c2);
23
24 $cnt=1;
25 &init_pool(3);
26
27 $rp=&wparam(0);
28 $ap=&wparam(1);
29 $bp=&wparam(2);
30
31 &function_begin($name,"");
32
33 &comment("");
34
35 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
36 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
37 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
38 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
39 &mul($a[0],$b[0],($r00)=&NR(1));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &muh($a[0],$b[0],($r01)=&NR(1));
43 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
44 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
45 &mul($a[0],$b[1],($r02)=&NR(1));
46
47 ($R,$H1,$H2)=&NR(3);
48
49 &st($r00,&QWPw(0,$rp)); &FR($r00);
50
51 &mov("zero",$R);
52 &mul($a[1],$b[0],($r03)=&NR(1));
53
54 &mov("zero",$H1);
55 &mov("zero",$H0);
56 &add($R,$r01,$R);
57 &muh($a[0],$b[1],($r04)=&NR(1));
58 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
59 &add($R,$r02,$R);
60 &add($H1,$t01,$H1) &FR($t01);
61 &muh($a[1],$b[0],($r05)=&NR(1));
62 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
63 &add($R,$r03,$R);
64 &add($H2,$t02,$H2) &FR($t02);
65 &mul($a[0],$b[2],($r06)=&NR(1));
66 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
67 &add($H1,$t03,$H1) &FR($t03);
68 &st($R,&QWPw(1,$rp));
69 &add($H1,$H2,$R);
70
71 &mov("zero",$H1);
72 &add($R,$r04,$R);
73 &mov("zero",$H2);
74 &mul($a[1],$b[1],($r07)=&NR(1));
75 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
76 &add($R,$r05,$R);
77 &add($H1,$t04,$H1) &FR($t04);
78 &mul($a[2],$b[0],($r08)=&NR(1));
79 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
80 &add($R,$r01,$R);
81 &add($H2,$t05,$H2) &FR($t05);
82 &muh($a[0],$b[2],($r09)=&NR(1));
83 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
84 &add($R,$r07,$R);
85 &add($H1,$t06,$H1) &FR($t06);
86 &muh($a[1],$b[1],($r10)=&NR(1));
87 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
88 &add($R,$r08,$R);
89 &add($H2,$t07,$H2) &FR($t07);
90 &muh($a[2],$b[0],($r11)=&NR(1));
91 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
92 &add($H1,$t08,$H1) &FR($t08);
93 &st($R,&QWPw(2,$rp));
94 &add($H1,$H2,$R);
95
96 &mov("zero",$H1);
97 &add($R,$r09,$R);
98 &mov("zero",$H2);
99 &mul($a[0],$b[3],($r12)=&NR(1));
100 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
101 &add($R,$r10,$R);
102 &add($H1,$t09,$H1) &FR($t09);
103 &mul($a[1],$b[2],($r13)=&NR(1));
104 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
105 &add($R,$r11,$R);
106 &add($H1,$t10,$H1) &FR($t10);
107 &mul($a[2],$b[1],($r14)=&NR(1));
108 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
109 &add($R,$r12,$R);
110 &add($H1,$t11,$H1) &FR($t11);
111 &mul($a[3],$b[0],($r15)=&NR(1));
112 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
113 &add($R,$r13,$R);
114 &add($H1,$t12,$H1) &FR($t12);
115 &muh($a[0],$b[3],($r16)=&NR(1));
116 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
117 &add($R,$r14,$R);
118 &add($H1,$t13,$H1) &FR($t13);
119 &muh($a[1],$b[2],($r17)=&NR(1));
120 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
121 &add($R,$r15,$R);
122 &add($H1,$t14,$H1) &FR($t14);
123 &muh($a[2],$b[1],($r18)=&NR(1));
124 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
125 &add($H1,$t15,$H1) &FR($t15);
126 &st($R,&QWPw(3,$rp));
127 &add($H1,$H2,$R);
128
129 &mov("zero",$H1);
130 &add($R,$r16,$R);
131 &mov("zero",$H2);
132 &muh($a[3],$b[0],($r19)=&NR(1));
133 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
134 &add($R,$r17,$R);
135 &add($H1,$t16,$H1) &FR($t16);
136 &mul($a[1],$b[3],($r20)=&NR(1));
137 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
138 &add($R,$r18,$R);
139 &add($H1,$t17,$H1) &FR($t17);
140 &mul($a[2],$b[2],($r21)=&NR(1));
141 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
142 &add($R,$r19,$R);
143 &add($H1,$t18,$H1) &FR($t18);
144 &mul($a[3],$b[1],($r22)=&NR(1));
145 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
146 &add($R,$r20,$R);
147 &add($H1,$t19,$H1) &FR($t19);
148 &muh($a[1],$b[3],($r23)=&NR(1));
149 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
150 &add($R,$r21,$R);
151 &add($H1,$t20,$H1) &FR($t20);
152 &muh($a[2],$b[2],($r24)=&NR(1));
153 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
154 &add($R,$r22,$R);
155 &add($H1,$t21,$H1) &FR($t21);
156 &muh($a[3],$b[1],($r25)=&NR(1));
157 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
158 &add($H1,$t22,$H1) &FR($t22);
159 &st($R,&QWPw(4,$rp));
160 &add($H1,$H2,$R);
161
162 &mov("zero",$H1);
163 &add($R,$r23,$R);
164 &mov("zero",$H2);
165 &mul($a[2],$b[3],($r26)=&NR(1));
166 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
167 &add($R,$r24,$R);
168 &add($H1,$t23,$H1) &FR($t23);
169 &mul($a[3],$b[2],($r27)=&NR(1));
170 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
171 &add($R,$r25,$R);
172 &add($H1,$t24,$H1) &FR($t24);
173 &muh($a[2],$b[3],($r28)=&NR(1));
174 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
175 &add($R,$r26,$R);
176 &add($H1,$t25,$H1) &FR($t25);
177 &muh($a[3],$b[2],($r29)=&NR(1));
178 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
179 &add($R,$r27,$R);
180 &add($H1,$t26,$H1) &FR($t26);
181 &mul($a[3],$b[3],($r30)=&NR(1));
182 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
183 &add($H1,$t27,$H1) &FR($t27);
184 &st($R,&QWPw(5,$rp));
185 &add($H1,$H2,$R);
186
187 &mov("zero",$H1);
188 &add($R,$r28,$R);
189 &mov("zero",$H2);
190 &muh($a[3],$b[3],($r31)=&NR(1));
191 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
192 &add($R,$r29,$R);
193 &add($H1,$t28,$H1) &FR($t28);
194 ############
195 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
196 &add($R,$r30,$R);
197 &add($H1,$t29,$H1) &FR($t29);
198 ############
199 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
200 &add($H1,$t30,$H1) &FR($t30);
201 &st($R,&QWPw(6,$rp));
202 &add($H1,$H2,$R);
203
204 &add($R,$r31,$R); &FR($r31);
205 &st($R,&QWPw(7,$rp));
206
207 &FR($R,$H1,$H2);
208 &function_end($name);
209
210 &fin_pool;
211 }
212
2131;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libcrypto/bn/asm/alpha.works/sub.pl b/src/lib/libcrypto/bn/asm/alpha.works/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha.works/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libcrypto/bn/asm/alpha/add.pl b/src/lib/libcrypto/bn/asm/alpha/add.pl
new file mode 100644
index 0000000000..13bf516428
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/add.pl
@@ -0,0 +1,118 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25
26##########################################################
27 &set_label("loop");
28
29 &ld(($a0)=&NR(1),&QWPw(0,$ap));
30 &ld(($b0)=&NR(1),&QWPw(0,$bp));
31 &ld(($a1)=&NR(1),&QWPw(1,$ap));
32 &ld(($b1)=&NR(1),&QWPw(1,$bp));
33
34 ($o0,$t0)=&NR(2);
35 &add($a0,$b0,$o0);
36 &ld(($a2)=&NR(1),&QWPw(2,$ap));
37 &cmpult($o0,$b0,$t0);
38 &add($o0,$cc,$o0);
39 &cmpult($o0,$cc,$cc);
40 &ld(($b2)=&NR(1),&QWPw(2,$bp));
41 &add($cc,$t0,$cc); &FR($t0);
42
43 ($t1,$o1)=&NR(2);
44
45 &add($a1,$b1,$o1); &FR($a1);
46 &cmpult($o1,$b1,$t1); &FR($b1);
47 &add($o1,$cc,$o1);
48 &cmpult($o1,$cc,$cc);
49 &ld(($a3)=&NR(1),&QWPw(3,$ap));
50 &add($cc,$t1,$cc); &FR($t1);
51
52 ($t2,$o2)=&NR(2);
53
54 &add($a2,$b2,$o2); &FR($a2);
55 &cmpult($o2,$b2,$t2); &FR($b2);
56 &add($o2,$cc,$o2);
57 &cmpult($o2,$cc,$cc);
58 &ld(($b3)=&NR(1),&QWPw(3,$bp));
59 &st($o0,&QWPw(0,$rp)); &FR($o0);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &st($o1,&QWPw(0,$rp)); &FR($o1);
65 &add($a3,$b3,$o3); &FR($a3);
66 &cmpult($o3,$b3,$t3); &FR($b3);
67 &add($o3,$cc,$o3);
68 &st($o2,&QWPw(0,$rp)); &FR($o2);
69 &cmpult($o3,$cc,$cc);
70 &st($o3,&QWPw(0,$rp)); &FR($o3);
71 &add($cc,$t3,$cc); &FR($t3);
72
73
74 &sub($count,4,$count); # count-=4
75 &add($ap,4*$QWS,$ap); # count+=4
76 &add($bp,4*$QWS,$bp); # count+=4
77 &add($rp,4*$QWS,$rp); # count+=4
78
79 ###
80 &bge($count,&label("loop"));
81 ###
82 &br(&label("finish"));
83##################################################
84 # Do the last 0..3 words
85
86 ($t0,$o0)=&NR(2);
87 &set_label("last_loop");
88
89 &ld($a0,&QWPw(0,$ap)); # get a
90 &ld($b0,&QWPw(0,$bp)); # get b
91 &add($ap,$QWS,$ap);
92 &add($bp,$QWS,$bp);
93 &add($a0,$b0,$o0);
94 &sub($count,1,$count);
95 &cmpult($o0,$b0,$t0); # will we borrow?
96 &add($o0,$cc,$o0); # will we borrow?
97 &cmpult($o0,$cc,$cc); # will we borrow?
98 &add($rp,$QWS,$rp);
99 &st($o0,&QWPw(-1,$rp)); # save
100 &add($cc,$t0,$cc); # add the borrows
101
102 ###
103 &bgt($count,&label("last_loop"));
104 &function_end_A($name);
105
106######################################################
107 &set_label("finish");
108 &add($count,4,$count);
109 &bgt($count,&label("last_loop"));
110
111 &FR($o0,$t0,$a0,$b0);
112 &set_label("end");
113 &function_end($name);
114
115 &fin_pool;
116 }
117
1181;
diff --git a/src/lib/libcrypto/bn/asm/alpha/div.pl b/src/lib/libcrypto/bn/asm/alpha/div.pl
new file mode 100644
index 0000000000..e9e680897a
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/div.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2
3sub bn_div_words
4 {
5 local($data)=<<'EOF';
6 #
7 # What follows was taken directly from the C compiler with a few
8 # hacks to redo the lables.
9 #
10.text
11 .set noreorder
12 .set volatile
13 .align 3
14 .globl bn_div_words
15 .ent bn_div_words
16bn_div_words
17 ldgp $29,0($27)
18bn_div_words.ng:
19 lda $30,-48($30)
20 .frame $30,48,$26,0
21 stq $26,0($30)
22 stq $9,8($30)
23 stq $10,16($30)
24 stq $11,24($30)
25 stq $12,32($30)
26 stq $13,40($30)
27 .mask 0x4003e00,-48
28 .prologue 1
29 bis $16,$16,$9
30 bis $17,$17,$10
31 bis $18,$18,$11
32 bis $31,$31,$13
33 bis $31,2,$12
34 bne $11,$9119
35 lda $0,-1
36 br $31,$9136
37 .align 4
38$9119:
39 bis $11,$11,$16
40 jsr $26,BN_num_bits_word
41 ldgp $29,0($26)
42 subq $0,64,$1
43 beq $1,$9120
44 bis $31,1,$1
45 sll $1,$0,$1
46 cmpule $9,$1,$1
47 bne $1,$9120
48 # lda $16,_IO_stderr_
49 # lda $17,$C32
50 # bis $0,$0,$18
51 # jsr $26,fprintf
52 # ldgp $29,0($26)
53 jsr $26,abort
54 ldgp $29,0($26)
55 .align 4
56$9120:
57 bis $31,64,$3
58 cmpult $9,$11,$2
59 subq $3,$0,$1
60 addl $1,$31,$0
61 subq $9,$11,$1
62 cmoveq $2,$1,$9
63 beq $0,$9122
64 zapnot $0,15,$2
65 subq $3,$0,$1
66 sll $11,$2,$11
67 sll $9,$2,$3
68 srl $10,$1,$1
69 sll $10,$2,$10
70 bis $3,$1,$9
71$9122:
72 srl $11,32,$5
73 zapnot $11,15,$6
74 lda $7,-1
75 .align 5
76$9123:
77 srl $9,32,$1
78 subq $1,$5,$1
79 bne $1,$9126
80 zapnot $7,15,$27
81 br $31,$9127
82 .align 4
83$9126:
84 bis $9,$9,$24
85 bis $5,$5,$25
86 divqu $24,$25,$27
87$9127:
88 srl $10,32,$4
89 .align 5
90$9128:
91 mulq $27,$5,$1
92 subq $9,$1,$3
93 zapnot $3,240,$1
94 bne $1,$9129
95 mulq $6,$27,$2
96 sll $3,32,$1
97 addq $1,$4,$1
98 cmpule $2,$1,$2
99 bne $2,$9129
100 subq $27,1,$27
101 br $31,$9128
102 .align 4
103$9129:
104 mulq $27,$6,$1
105 mulq $27,$5,$4
106 srl $1,32,$3
107 sll $1,32,$1
108 addq $4,$3,$4
109 cmpult $10,$1,$2
110 subq $10,$1,$10
111 addq $2,$4,$2
112 cmpult $9,$2,$1
113 bis $2,$2,$4
114 beq $1,$9134
115 addq $9,$11,$9
116 subq $27,1,$27
117$9134:
118 subl $12,1,$12
119 subq $9,$4,$9
120 beq $12,$9124
121 sll $27,32,$13
122 sll $9,32,$2
123 srl $10,32,$1
124 sll $10,32,$10
125 bis $2,$1,$9
126 br $31,$9123
127 .align 4
128$9124:
129 bis $13,$27,$0
130$9136:
131 ldq $26,0($30)
132 ldq $9,8($30)
133 ldq $10,16($30)
134 ldq $11,24($30)
135 ldq $12,32($30)
136 ldq $13,40($30)
137 addq $30,48,$30
138 ret $31,($26),1
139 .end bn_div_words
140EOF
141 &asm_add($data);
142 }
143
1441;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul.pl b/src/lib/libcrypto/bn/asm/alpha/mul.pl
new file mode 100644
index 0000000000..76c926566c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul.pl
@@ -0,0 +1,104 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
26
27 &set_label("loop");
28
29 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
30 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
31
32 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
33 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
34 ### wait 8
35 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
36 ### wait 8
37 &muh($a1,$word,($h1)=&NR(1)); &FR($a1);
38 &add($l0,$cc,$l0); ### wait 8
39 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
40 &cmpult($l0,$cc,$cc); ### wait 8
41 &muh($a2,$word,($h2)=&NR(1)); &FR($a2);
42 &add($h0,$cc,$cc); &FR($h0); ### wait 8
43 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
44 &add($l1,$cc,$l1); ### wait 8
45 &st($l0,&QWPw(0,$rp)); &FR($l0);
46 &cmpult($l1,$cc,$cc); ### wait 8
47 &muh($a3,$word,($h3)=&NR(1)); &FR($a3);
48 &add($h1,$cc,$cc); &FR($h1);
49 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
50 &add($l2,$cc,$l2);
51 &st($l1,&QWPw(1,$rp)); &FR($l1);
52 &cmpult($l2,$cc,$cc);
53 &add($h2,$cc,$cc); &FR($h2);
54 &sub($count,4,$count); # count-=4
55 &st($l2,&QWPw(2,$rp)); &FR($l2);
56 &add($l3,$cc,$l3);
57 &cmpult($l3,$cc,$cc);
58 &add($bp,4*$QWS,$bp); # count+=4
59 &add($h3,$cc,$cc); &FR($h3);
60 &add($ap,4*$QWS,$ap); # count+=4
61 &st($l3,&QWPw(3,$rp)); &FR($l3);
62 &add($rp,4*$QWS,$rp); # count+=4
63 ###
64 &blt($count,&label("finish"));
65 ($a0)=&NR(1); &ld($a0,&QWPw(0,$ap));
66 &br(&label("finish"));
67##################################################
68
69##################################################
70 # Do the last 0..3 words
71
72 &set_label("last_loop");
73
74 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
75 ###
76 ###
77 ###
78 &muh($a0,$word,($h0)=&NR(1));
79 ### Wait 8 for next mul issue
80 &mul($a0,$word,($l0)=&NR(1)); &FR($a0)
81 &add($ap,$QWS,$ap);
82 ### Loose 12 until result is available
83 &add($rp,$QWS,$rp);
84 &sub($count,1,$count);
85 &add($l0,$cc,$l0);
86 ###
87 &st($l0,&QWPw(-1,$rp)); &FR($l0);
88 &cmpult($l0,$cc,$cc);
89 &add($h0,$cc,$cc); &FR($h0);
90 &bgt($count,&label("last_loop"));
91 &function_end_A($name);
92
93######################################################
94 &set_label("finish");
95 &add($count,4,$count);
96 &bgt($count,&label("last_loop"));
97
98 &set_label("end");
99 &function_end($name);
100
101 &fin_pool;
102 }
103
1041;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_add.pl b/src/lib/libcrypto/bn/asm/alpha/mul_add.pl
new file mode 100644
index 0000000000..0d6df69bc4
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_add.pl
@@ -0,0 +1,123 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_add_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15 $word=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 ###
23 &blt($count,&label("finish"));
24
25 &ld(($a0)=&NR(1),&QWPw(0,$ap));
26
27$a=<<'EOF';
28##########################################################
29 &set_label("loop");
30
31 &ld(($r0)=&NR(1),&QWPw(0,$rp));
32 &ld(($a1)=&NR(1),&QWPw(1,$ap));
33 &muh($a0,$word,($h0)=&NR(1));
34 &ld(($r1)=&NR(1),&QWPw(1,$rp));
35 &ld(($a2)=&NR(1),&QWPw(2,$ap));
36 ###
37 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
38 &ld(($r2)=&NR(1),&QWPw(2,$rp));
39 &muh($a1,$word,($h1)=&NR(1));
40 &ld(($a3)=&NR(1),&QWPw(3,$ap));
41 &mul($a1,$word,($l1)=&NR(1)); &FR($a1);
42 &ld(($r3)=&NR(1),&QWPw(3,$rp));
43 &add($r0,$l0,$r0);
44 &add($r1,$l1,$r1);
45 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
46 &cmpult($r1,$l1,($t1)=&NR(1)); &FR($l1);
47 &muh($a2,$word,($h2)=&NR(1));
48 &add($r0,$cc,$r0);
49 &add($h0,$t0,$h0); &FR($t0);
50 &cmpult($r0,$cc,$cc);
51 &add($h1,$t1,$h1); &FR($t1);
52 &add($h0,$cc,$cc); &FR($h0);
53 &mul($a2,$word,($l2)=&NR(1)); &FR($a2);
54 &add($r1,$cc,$r1);
55 &cmpult($r1,$cc,$cc);
56 &add($r2,$l2,$r2);
57 &add($h1,$cc,$cc); &FR($h1);
58 &cmpult($r2,$l2,($t2)=&NR(1)); &FR($l2);
59 &muh($a3,$word,($h3)=&NR(1));
60 &add($r2,$cc,$r2);
61 &st($r0,&QWPw(0,$rp)); &FR($r0);
62 &add($h2,$t2,$h2); &FR($t2);
63 &st($r1,&QWPw(1,$rp)); &FR($r1);
64 &cmpult($r2,$cc,$cc);
65 &mul($a3,$word,($l3)=&NR(1)); &FR($a3);
66 &add($h2,$cc,$cc); &FR($h2);
67 &st($r2,&QWPw(2,$rp)); &FR($r2);
68 &sub($count,4,$count); # count-=4
69 &add($rp,4*$QWS,$rp); # count+=4
70 &add($r3,$l3,$r3);
71 &add($ap,4*$QWS,$ap); # count+=4
72 &cmpult($r3,$l3,($t3)=&NR(1)); &FR($l3);
73 &add($r3,$cc,$r3);
74 &add($h3,$t3,$h3); &FR($t3);
75 &cmpult($r3,$cc,$cc);
76 &st($r3,&QWPw(-1,$rp)); &FR($r3);
77 &add($h3,$cc,$cc); &FR($h3);
78
79 ###
80 &blt($count,&label("finish"));
81 &ld(($a0)=&NR(1),&QWPw(0,$ap));
82 &br(&label("loop"));
83EOF
84##################################################
85 # Do the last 0..3 words
86
87 &set_label("last_loop");
88
89 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
90 &ld(($r0)=&NR(1),&QWPw(0,$rp)); # get b
91 ###
92 ###
93 &muh($a0,$word,($h0)=&NR(1)); &FR($a0);
94 ### wait 8
95 &mul($a0,$word,($l0)=&NR(1)); &FR($a0);
96 &add($rp,$QWS,$rp);
97 &add($ap,$QWS,$ap);
98 &sub($count,1,$count);
99 ### wait 3 until l0 is available
100 &add($r0,$l0,$r0);
101 ###
102 &cmpult($r0,$l0,($t0)=&NR(1)); &FR($l0);
103 &add($r0,$cc,$r0);
104 &add($h0,$t0,$h0); &FR($t0);
105 &cmpult($r0,$cc,$cc);
106 &add($h0,$cc,$cc); &FR($h0);
107
108 &st($r0,&QWPw(-1,$rp)); &FR($r0);
109 &bgt($count,&label("last_loop"));
110 &function_end_A($name);
111
112######################################################
113 &set_label("finish");
114 &add($count,4,$count);
115 &bgt($count,&label("last_loop"));
116
117 &set_label("end");
118 &function_end($name);
119
120 &fin_pool;
121 }
122
1231;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl
new file mode 100644
index 0000000000..9cc876ded4
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c4.pl
@@ -0,0 +1,215 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4# upto
5
6sub mul_add_c
7 {
8 local($a,$b,$c0,$c1,$c2)=@_;
9 local($l1,$h1,$t1,$t2);
10
11 &mul($a,$b,($l1)=&NR(1));
12 &muh($a,$b,($h1)=&NR(1));
13 &add($c0,$l1,$c0);
14 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
15 &add($t1,$h1,$h1); &FR($t1);
16 &add($c1,$h1,$c1);
17 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
18 &add($c2,$t2,$c2); &FR($t2);
19 }
20
21sub bn_mul_comba4
22 {
23 local($name)=@_;
24 local(@a,@b,$r,$c0,$c1,$c2);
25
26 $cnt=1;
27 &init_pool(3);
28
29 $rp=&wparam(0);
30 $ap=&wparam(1);
31 $bp=&wparam(2);
32
33 &function_begin($name,"");
34
35 &comment("");
36
37 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
38 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
39 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
40 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
41 &mul($a[0],$b[0],($r00)=&NR(1));
42 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
43 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
44 &muh($a[0],$b[0],($r01)=&NR(1));
45 &FR($ap); &ld(($a[3])=&NR(1),&QWPw(3,$ap));
46 &FR($bp); &ld(($b[3])=&NR(1),&QWPw(3,$bp));
47 &mul($a[0],$b[1],($r02)=&NR(1));
48
49 ($R,$H1,$H2)=&NR(3);
50
51 &st($r00,&QWPw(0,$rp)); &FR($r00);
52
53 &mov("zero",$R);
54 &mul($a[1],$b[0],($r03)=&NR(1));
55
56 &mov("zero",$H1);
57 &mov("zero",$H0);
58 &add($R,$r01,$R);
59 &muh($a[0],$b[1],($r04)=&NR(1));
60 &cmpult($R,$r01,($t01)=&NR(1)); &FR($r01);
61 &add($R,$r02,$R);
62 &add($H1,$t01,$H1) &FR($t01);
63 &muh($a[1],$b[0],($r05)=&NR(1));
64 &cmpult($R,$r02,($t02)=&NR(1)); &FR($r02);
65 &add($R,$r03,$R);
66 &add($H2,$t02,$H2) &FR($t02);
67 &mul($a[0],$b[2],($r06)=&NR(1));
68 &cmpult($R,$r03,($t03)=&NR(1)); &FR($r03);
69 &add($H1,$t03,$H1) &FR($t03);
70 &st($R,&QWPw(1,$rp));
71 &add($H1,$H2,$R);
72
73 &mov("zero",$H1);
74 &add($R,$r04,$R);
75 &mov("zero",$H2);
76 &mul($a[1],$b[1],($r07)=&NR(1));
77 &cmpult($R,$r04,($t04)=&NR(1)); &FR($r04);
78 &add($R,$r05,$R);
79 &add($H1,$t04,$H1) &FR($t04);
80 &mul($a[2],$b[0],($r08)=&NR(1));
81 &cmpult($R,$r05,($t05)=&NR(1)); &FR($r05);
82 &add($R,$r01,$R);
83 &add($H2,$t05,$H2) &FR($t05);
84 &muh($a[0],$b[2],($r09)=&NR(1));
85 &cmpult($R,$r06,($t06)=&NR(1)); &FR($r06);
86 &add($R,$r07,$R);
87 &add($H1,$t06,$H1) &FR($t06);
88 &muh($a[1],$b[1],($r10)=&NR(1));
89 &cmpult($R,$r07,($t07)=&NR(1)); &FR($r07);
90 &add($R,$r08,$R);
91 &add($H2,$t07,$H2) &FR($t07);
92 &muh($a[2],$b[0],($r11)=&NR(1));
93 &cmpult($R,$r08,($t08)=&NR(1)); &FR($r08);
94 &add($H1,$t08,$H1) &FR($t08);
95 &st($R,&QWPw(2,$rp));
96 &add($H1,$H2,$R);
97
98 &mov("zero",$H1);
99 &add($R,$r09,$R);
100 &mov("zero",$H2);
101 &mul($a[0],$b[3],($r12)=&NR(1));
102 &cmpult($R,$r09,($t09)=&NR(1)); &FR($r09);
103 &add($R,$r10,$R);
104 &add($H1,$t09,$H1) &FR($t09);
105 &mul($a[1],$b[2],($r13)=&NR(1));
106 &cmpult($R,$r10,($t10)=&NR(1)); &FR($r10);
107 &add($R,$r11,$R);
108 &add($H1,$t10,$H1) &FR($t10);
109 &mul($a[2],$b[1],($r14)=&NR(1));
110 &cmpult($R,$r11,($t11)=&NR(1)); &FR($r11);
111 &add($R,$r12,$R);
112 &add($H1,$t11,$H1) &FR($t11);
113 &mul($a[3],$b[0],($r15)=&NR(1));
114 &cmpult($R,$r12,($t12)=&NR(1)); &FR($r12);
115 &add($R,$r13,$R);
116 &add($H1,$t12,$H1) &FR($t12);
117 &muh($a[0],$b[3],($r16)=&NR(1));
118 &cmpult($R,$r13,($t13)=&NR(1)); &FR($r13);
119 &add($R,$r14,$R);
120 &add($H1,$t13,$H1) &FR($t13);
121 &muh($a[1],$b[2],($r17)=&NR(1));
122 &cmpult($R,$r14,($t14)=&NR(1)); &FR($r14);
123 &add($R,$r15,$R);
124 &add($H1,$t14,$H1) &FR($t14);
125 &muh($a[2],$b[1],($r18)=&NR(1));
126 &cmpult($R,$r15,($t15)=&NR(1)); &FR($r15);
127 &add($H1,$t15,$H1) &FR($t15);
128 &st($R,&QWPw(3,$rp));
129 &add($H1,$H2,$R);
130
131 &mov("zero",$H1);
132 &add($R,$r16,$R);
133 &mov("zero",$H2);
134 &muh($a[3],$b[0],($r19)=&NR(1));
135 &cmpult($R,$r16,($t16)=&NR(1)); &FR($r16);
136 &add($R,$r17,$R);
137 &add($H1,$t16,$H1) &FR($t16);
138 &mul($a[1],$b[3],($r20)=&NR(1));
139 &cmpult($R,$r17,($t17)=&NR(1)); &FR($r17);
140 &add($R,$r18,$R);
141 &add($H1,$t17,$H1) &FR($t17);
142 &mul($a[2],$b[2],($r21)=&NR(1));
143 &cmpult($R,$r18,($t18)=&NR(1)); &FR($r18);
144 &add($R,$r19,$R);
145 &add($H1,$t18,$H1) &FR($t18);
146 &mul($a[3],$b[1],($r22)=&NR(1));
147 &cmpult($R,$r19,($t19)=&NR(1)); &FR($r19);
148 &add($R,$r20,$R);
149 &add($H1,$t19,$H1) &FR($t19);
150 &muh($a[1],$b[3],($r23)=&NR(1));
151 &cmpult($R,$r20,($t20)=&NR(1)); &FR($r20);
152 &add($R,$r21,$R);
153 &add($H1,$t20,$H1) &FR($t20);
154 &muh($a[2],$b[2],($r24)=&NR(1));
155 &cmpult($R,$r21,($t21)=&NR(1)); &FR($r21);
156 &add($R,$r22,$R);
157 &add($H1,$t21,$H1) &FR($t21);
158 &muh($a[3],$b[1],($r25)=&NR(1));
159 &cmpult($R,$r22,($t22)=&NR(1)); &FR($r22);
160 &add($H1,$t22,$H1) &FR($t22);
161 &st($R,&QWPw(4,$rp));
162 &add($H1,$H2,$R);
163
164 &mov("zero",$H1);
165 &add($R,$r23,$R);
166 &mov("zero",$H2);
167 &mul($a[2],$b[3],($r26)=&NR(1));
168 &cmpult($R,$r23,($t23)=&NR(1)); &FR($r23);
169 &add($R,$r24,$R);
170 &add($H1,$t23,$H1) &FR($t23);
171 &mul($a[3],$b[2],($r27)=&NR(1));
172 &cmpult($R,$r24,($t24)=&NR(1)); &FR($r24);
173 &add($R,$r25,$R);
174 &add($H1,$t24,$H1) &FR($t24);
175 &muh($a[2],$b[3],($r28)=&NR(1));
176 &cmpult($R,$r25,($t25)=&NR(1)); &FR($r25);
177 &add($R,$r26,$R);
178 &add($H1,$t25,$H1) &FR($t25);
179 &muh($a[3],$b[2],($r29)=&NR(1));
180 &cmpult($R,$r26,($t26)=&NR(1)); &FR($r26);
181 &add($R,$r27,$R);
182 &add($H1,$t26,$H1) &FR($t26);
183 &mul($a[3],$b[3],($r30)=&NR(1));
184 &cmpult($R,$r27,($t27)=&NR(1)); &FR($r27);
185 &add($H1,$t27,$H1) &FR($t27);
186 &st($R,&QWPw(5,$rp));
187 &add($H1,$H2,$R);
188
189 &mov("zero",$H1);
190 &add($R,$r28,$R);
191 &mov("zero",$H2);
192 &muh($a[3],$b[3],($r31)=&NR(1));
193 &cmpult($R,$r28,($t28)=&NR(1)); &FR($r28);
194 &add($R,$r29,$R);
195 &add($H1,$t28,$H1) &FR($t28);
196 ############
197 &cmpult($R,$r29,($t29)=&NR(1)); &FR($r29);
198 &add($R,$r30,$R);
199 &add($H1,$t29,$H1) &FR($t29);
200 ############
201 &cmpult($R,$r30,($t30)=&NR(1)); &FR($r30);
202 &add($H1,$t30,$H1) &FR($t30);
203 &st($R,&QWPw(6,$rp));
204 &add($H1,$H2,$R);
205
206 &add($R,$r31,$R); &FR($r31);
207 &st($R,&QWPw(7,$rp));
208
209 &FR($R,$H1,$H2);
210 &function_end($name);
211
212 &fin_pool;
213 }
214
2151;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl
new file mode 100644
index 0000000000..79d86dd25c
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c4.works.pl
@@ -0,0 +1,98 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub mul_add_c
5 {
6 local($a,$b,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9print STDERR "count=$cnt\n"; $cnt++;
10 &mul($a,$b,($l1)=&NR(1));
11 &muh($a,$b,($h1)=&NR(1));
12 &add($c0,$l1,$c0);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &add($t1,$h1,$h1); &FR($t1);
15 &add($c1,$h1,$c1);
16 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
17 &add($c2,$t2,$c2); &FR($t2);
18 }
19
20sub bn_mul_comba4
21 {
22 local($name)=@_;
23 local(@a,@b,$r,$c0,$c1,$c2);
24
25 $cnt=1;
26 &init_pool(3);
27
28 $rp=&wparam(0);
29 $ap=&wparam(1);
30 $bp=&wparam(2);
31
32 &function_begin($name,"");
33
34 &comment("");
35
36 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
37 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
38 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
39 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
40 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
41 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
42 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
43 &ld(($b[3])=&NR(1),&QWPw(3,$bp)); &FR($bp);
44
45 ($c0,$c1,$c2)=&NR(3);
46 &mov("zero",$c2);
47 &mul($a[0],$b[0],$c0);
48 &muh($a[0],$b[0],$c1);
49 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR($c0);
50 ($c0,$c1,$c2)=($c1,$c2,$c0);
51 &mov("zero",$c2);
52
53 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
54 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
55 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR($c0);
56 ($c0,$c1,$c2)=($c1,$c2,$c0);
57 &mov("zero",$c2);
58
59 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
60 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
61 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
62 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR($c0);
63 ($c0,$c1,$c2)=($c1,$c2,$c0);
64 &mov("zero",$c2);
65
66 &mul_add_c($a[0],$b[3],$c0,$c1,$c2); &FR($a[0]);
67 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
68 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
69 &mul_add_c($a[3],$b[0],$c0,$c1,$c2); &FR($b[0]);
70 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR($c0);
71 ($c0,$c1,$c2)=($c1,$c2,$c0);
72 &mov("zero",$c2);
73
74 &mul_add_c($a[1],$b[3],$c0,$c1,$c2); &FR($a[1]);
75 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
76 &mul_add_c($a[3],$b[1],$c0,$c1,$c2); &FR($b[1]);
77 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR($c0);
78 ($c0,$c1,$c2)=($c1,$c2,$c0);
79 &mov("zero",$c2);
80
81 &mul_add_c($a[2],$b[3],$c0,$c1,$c2); &FR($a[2]);
82 &mul_add_c($a[3],$b[2],$c0,$c1,$c2); &FR($b[2]);
83 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR($c0);
84 ($c0,$c1,$c2)=($c1,$c2,$c0);
85 &mov("zero",$c2);
86
87 &mul_add_c($a[3],$b[3],$c0,$c1,$c2); &FR($a[3],$b[3]);
88 &st($c0,&QWPw(6,$rp));
89 &st($c1,&QWPw(7,$rp));
90
91 &FR($c0,$c1,$c2);
92
93 &function_end($name);
94
95 &fin_pool;
96 }
97
981;
diff --git a/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl b/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl
new file mode 100644
index 0000000000..525ca7494b
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/mul_c8.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_mul_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(3);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19
20 &stack_push(2);
21 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
22 &ld(($b[0])=&NR(1),&QWPw(0,$bp));
23 &st($reg_s0,&swtmp(0)); &FR($reg_s0);
24 &st($reg_s1,&swtmp(1)); &FR($reg_s1);
25 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
26 &ld(($b[1])=&NR(1),&QWPw(1,$bp));
27 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
28 &ld(($b[2])=&NR(1),&QWPw(2,$bp));
29 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
30 &ld(($b[3])=&NR(1),&QWPw(3,$bp));
31 &ld(($a[4])=&NR(1),&QWPw(1,$ap));
32 &ld(($b[4])=&NR(1),&QWPw(1,$bp));
33 &ld(($a[5])=&NR(1),&QWPw(1,$ap));
34 &ld(($b[5])=&NR(1),&QWPw(1,$bp));
35 &ld(($a[6])=&NR(1),&QWPw(1,$ap));
36 &ld(($b[6])=&NR(1),&QWPw(1,$bp));
37 &ld(($a[7])=&NR(1),&QWPw(1,$ap)); &FR($ap);
38 &ld(($b[7])=&NR(1),&QWPw(1,$bp)); &FR($bp);
39
40 ($c0,$c1,$c2)=&NR(3);
41 &mov("zero",$c2);
42 &mul($a[0],$b[0],$c0);
43 &muh($a[0],$b[0],$c1);
44 &st($c0,&QWPw(0,$rp)); &FR($c0); ($c0)=&NR(1);
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &mul_add_c($a[0],$b[1],$c0,$c1,$c2);
49 &mul_add_c($a[1],$b[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(1,$rp)); &FR($c0); ($c0)=&NR(1);
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &mul_add_c($a[0],$b[2],$c0,$c1,$c2);
55 &mul_add_c($a[1],$b[1],$c0,$c1,$c2);
56 &mul_add_c($a[2],$b[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(2,$rp)); &FR($c0); ($c0)=&NR(1);
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &mul_add_c($a[0],$b[3],$c0,$c1,$c2);
62 &mul_add_c($a[1],$b[2],$c0,$c1,$c2);
63 &mul_add_c($a[2],$b[1],$c0,$c1,$c2);
64 &mul_add_c($a[3],$b[0],$c0,$c1,$c2);
65 &st($c0,&QWPw(3,$rp)); &FR($c0); ($c0)=&NR(1);
66 ($c0,$c1,$c2)=($c1,$c2,$c0);
67 &mov("zero",$c2);
68
69 &mul_add_c($a[0],$b[4],$c0,$c1,$c2);
70 &mul_add_c($a[1],$b[3],$c0,$c1,$c2);
71 &mul_add_c($a[2],$b[2],$c0,$c1,$c2);
72 &mul_add_c($a[3],$b[1],$c0,$c1,$c2);
73 &mul_add_c($a[4],$b[0],$c0,$c1,$c2);
74 &st($c0,&QWPw(4,$rp)); &FR($c0); ($c0)=&NR(1);
75 ($c0,$c1,$c2)=($c1,$c2,$c0);
76 &mov("zero",$c2);
77
78 &mul_add_c($a[0],$b[5],$c0,$c1,$c2);
79 &mul_add_c($a[1],$b[4],$c0,$c1,$c2);
80 &mul_add_c($a[2],$b[3],$c0,$c1,$c2);
81 &mul_add_c($a[3],$b[2],$c0,$c1,$c2);
82 &mul_add_c($a[4],$b[1],$c0,$c1,$c2);
83 &mul_add_c($a[5],$b[0],$c0,$c1,$c2);
84 &st($c0,&QWPw(5,$rp)); &FR($c0); ($c0)=&NR(1);
85 ($c0,$c1,$c2)=($c1,$c2,$c0);
86 &mov("zero",$c2);
87
88 &mul_add_c($a[0],$b[6],$c0,$c1,$c2);
89 &mul_add_c($a[1],$b[5],$c0,$c1,$c2);
90 &mul_add_c($a[2],$b[4],$c0,$c1,$c2);
91 &mul_add_c($a[3],$b[3],$c0,$c1,$c2);
92 &mul_add_c($a[4],$b[2],$c0,$c1,$c2);
93 &mul_add_c($a[5],$b[1],$c0,$c1,$c2);
94 &mul_add_c($a[6],$b[0],$c0,$c1,$c2);
95 &st($c0,&QWPw(6,$rp)); &FR($c0); ($c0)=&NR(1);
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &mul_add_c($a[0],$b[7],$c0,$c1,$c2); &FR($a[0]);
100 &mul_add_c($a[1],$b[6],$c0,$c1,$c2);
101 &mul_add_c($a[2],$b[5],$c0,$c1,$c2);
102 &mul_add_c($a[3],$b[4],$c0,$c1,$c2);
103 &mul_add_c($a[4],$b[3],$c0,$c1,$c2);
104 &mul_add_c($a[5],$b[2],$c0,$c1,$c2);
105 &mul_add_c($a[6],$b[1],$c0,$c1,$c2);
106 &mul_add_c($a[7],$b[0],$c0,$c1,$c2); &FR($b[0]);
107 &st($c0,&QWPw(7,$rp)); &FR($c0); ($c0)=&NR(1);
108 ($c0,$c1,$c2)=($c1,$c2,$c0);
109 &mov("zero",$c2);
110
111 &mul_add_c($a[1],$b[7],$c0,$c1,$c2); &FR($a[1]);
112 &mul_add_c($a[2],$b[6],$c0,$c1,$c2);
113 &mul_add_c($a[3],$b[5],$c0,$c1,$c2);
114 &mul_add_c($a[4],$b[4],$c0,$c1,$c2);
115 &mul_add_c($a[5],$b[3],$c0,$c1,$c2);
116 &mul_add_c($a[6],$b[2],$c0,$c1,$c2);
117 &mul_add_c($a[7],$b[1],$c0,$c1,$c2); &FR($b[1]);
118 &st($c0,&QWPw(8,$rp)); &FR($c0); ($c0)=&NR(1);
119 ($c0,$c1,$c2)=($c1,$c2,$c0);
120 &mov("zero",$c2);
121
122 &mul_add_c($a[2],$b[7],$c0,$c1,$c2); &FR($a[2]);
123 &mul_add_c($a[3],$b[6],$c0,$c1,$c2);
124 &mul_add_c($a[4],$b[5],$c0,$c1,$c2);
125 &mul_add_c($a[5],$b[4],$c0,$c1,$c2);
126 &mul_add_c($a[6],$b[3],$c0,$c1,$c2);
127 &mul_add_c($a[7],$b[2],$c0,$c1,$c2); &FR($b[2]);
128 &st($c0,&QWPw(9,$rp)); &FR($c0); ($c0)=&NR(1);
129 ($c0,$c1,$c2)=($c1,$c2,$c0);
130 &mov("zero",$c2);
131
132 &mul_add_c($a[3],$b[7],$c0,$c1,$c2); &FR($a[3]);
133 &mul_add_c($a[4],$b[6],$c0,$c1,$c2);
134 &mul_add_c($a[5],$b[5],$c0,$c1,$c2);
135 &mul_add_c($a[6],$b[4],$c0,$c1,$c2);
136 &mul_add_c($a[7],$b[3],$c0,$c1,$c2); &FR($b[3]);
137 &st($c0,&QWPw(10,$rp)); &FR($c0); ($c0)=&NR(1);
138 ($c0,$c1,$c2)=($c1,$c2,$c0);
139 &mov("zero",$c2);
140
141 &mul_add_c($a[4],$b[7],$c0,$c1,$c2); &FR($a[4]);
142 &mul_add_c($a[5],$b[6],$c0,$c1,$c2);
143 &mul_add_c($a[6],$b[5],$c0,$c1,$c2);
144 &mul_add_c($a[7],$b[4],$c0,$c1,$c2); &FR($b[4]);
145 &st($c0,&QWPw(11,$rp)); &FR($c0); ($c0)=&NR(1);
146 ($c0,$c1,$c2)=($c1,$c2,$c0);
147 &mov("zero",$c2);
148
149 &mul_add_c($a[5],$b[7],$c0,$c1,$c2); &FR($a[5]);
150 &mul_add_c($a[6],$b[6],$c0,$c1,$c2);
151 &mul_add_c($a[7],$b[5],$c0,$c1,$c2); &FR($b[5]);
152 &st($c0,&QWPw(12,$rp)); &FR($c0); ($c0)=&NR(1);
153 ($c0,$c1,$c2)=($c1,$c2,$c0);
154 &mov("zero",$c2);
155
156 &mul_add_c($a[6],$b[7],$c0,$c1,$c2); &FR($a[6]);
157 &mul_add_c($a[7],$b[6],$c0,$c1,$c2); &FR($b[6]);
158 &st($c0,&QWPw(13,$rp)); &FR($c0); ($c0)=&NR(1);
159 ($c0,$c1,$c2)=($c1,$c2,$c0);
160 &mov("zero",$c2);
161
162 &mul_add_c($a[7],$b[7],$c0,$c1,$c2); &FR($a[7],$b[7]);
163 &st($c0,&QWPw(14,$rp));
164 &st($c1,&QWPw(15,$rp));
165
166 &FR($c0,$c1,$c2);
167
168 &ld($reg_s0,&swtmp(0));
169 &ld($reg_s1,&swtmp(1));
170 &stack_pop(2);
171
172 &function_end($name);
173
174 &fin_pool;
175 }
176
1771;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr.pl b/src/lib/libcrypto/bn/asm/alpha/sqr.pl
new file mode 100644
index 0000000000..a55b696906
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr.pl
@@ -0,0 +1,113 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r,$couny);
8
9 &init_pool(3);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $count=&wparam(2);
15
16 &function_begin($name,"");
17
18 &comment("");
19 &sub($count,4,$count);
20 &mov("zero",$cc);
21 &br(&label("finish"));
22 &blt($count,&label("finish"));
23
24 ($a0,$r0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($r0,&QWPw(0,$rp));
27
28$a=<<'EOF';
29##########################################################
30 &set_label("loop");
31
32 ($a1)=&NR(1); &ld($a1,&QWPw(1,$ap));
33 ($b1)=&NR(1); &ld($b1,&QWPw(1,$bp));
34 ($a2)=&NR(1); &ld($a2,&QWPw(2,$ap));
35 ($b2)=&NR(1); &ld($b2,&QWPw(2,$bp));
36 ($a3)=&NR(1); &ld($a3,&QWPw(3,$ap));
37 ($b3)=&NR(1); &ld($b3,&QWPw(3,$bp));
38
39 ($o0,$t0)=&NR(2);
40 &add($a0,$b0,$o0);
41 &cmpult($o0,$b0,$t0);
42 &add($o0,$cc,$o0);
43 &cmpult($o0,$cc,$cc);
44 &add($cc,$t0,$cc); &FR($t0);
45
46 ($t1,$o1)=&NR(2);
47
48 &add($a1,$b1,$o1); &FR($a1);
49 &cmpult($o1,$b1,$t1); &FR($b1);
50 &add($o1,$cc,$o1);
51 &cmpult($o1,$cc,$cc);
52 &add($cc,$t1,$cc); &FR($t1);
53
54 ($t2,$o2)=&NR(2);
55
56 &add($a2,$b2,$o2); &FR($a2);
57 &cmpult($o2,$b2,$t2); &FR($b2);
58 &add($o2,$cc,$o2);
59 &cmpult($o2,$cc,$cc);
60 &add($cc,$t2,$cc); &FR($t2);
61
62 ($t3,$o3)=&NR(2);
63
64 &add($a3,$b3,$o3); &FR($a3);
65 &cmpult($o3,$b3,$t3); &FR($b3);
66 &add($o3,$cc,$o3);
67 &cmpult($o3,$cc,$cc);
68 &add($cc,$t3,$cc); &FR($t3);
69
70 &st($o0,&QWPw(0,$rp)); &FR($o0);
71 &st($o1,&QWPw(0,$rp)); &FR($o1);
72 &st($o2,&QWPw(0,$rp)); &FR($o2);
73 &st($o3,&QWPw(0,$rp)); &FR($o3);
74
75 &sub($count,4,$count); # count-=4
76 &add($ap,4*$QWS,$ap); # count+=4
77 &add($bp,4*$QWS,$bp); # count+=4
78 &add($rp,4*$QWS,$rp); # count+=4
79
80 &blt($count,&label("finish"));
81 &ld($a0,&QWPw(0,$ap));
82 &ld($b0,&QWPw(0,$bp));
83 &br(&label("loop"));
84EOF
85##################################################
86 # Do the last 0..3 words
87
88 &set_label("last_loop");
89
90 &ld(($a0)=&NR(1),&QWPw(0,$ap)); # get a
91 &mul($a0,$a0,($l0)=&NR(1));
92 &add($ap,$QWS,$ap);
93 &add($rp,2*$QWS,$rp);
94 &sub($count,1,$count);
95 &muh($a0,$a0,($h0)=&NR(1)); &FR($a0);
96 &st($l0,&QWPw(-2,$rp)); &FR($l0);
97 &st($h0,&QWPw(-1,$rp)); &FR($h0);
98
99 &bgt($count,&label("last_loop"));
100 &function_end_A($name);
101
102######################################################
103 &set_label("finish");
104 &add($count,4,$count);
105 &bgt($count,&label("last_loop"));
106
107 &set_label("end");
108 &function_end($name);
109
110 &fin_pool;
111 }
112
1131;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl
new file mode 100644
index 0000000000..bf33f5b503
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr_c4.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub sqr_add_c
5 {
6 local($a,$c0,$c1,$c2)=@_;
7 local($l1,$h1,$t1,$t2);
8
9 &mul($a,$a,($l1)=&NR(1));
10 &muh($a,$a,($h1)=&NR(1));
11 &add($c0,$l1,$c0);
12 &add($c1,$h1,$c1);
13 &cmpult($c0,$l1,($t1)=&NR(1)); &FR($l1);
14 &cmpult($c1,$h1,($t2)=&NR(1)); &FR($h1);
15 &add($c1,$t1,$c1); &FR($t1);
16 &add($c2,$t2,$c2); &FR($t2);
17 }
18
19sub sqr_add_c2
20 {
21 local($a,$b,$c0,$c1,$c2)=@_;
22 local($l1,$h1,$t1,$t2);
23
24 &mul($a,$b,($l1)=&NR(1));
25 &muh($a,$b,($h1)=&NR(1));
26 &cmplt($l1,"zero",($lc1)=&NR(1));
27 &cmplt($h1,"zero",($hc1)=&NR(1));
28 &add($l1,$l1,$l1);
29 &add($h1,$h1,$h1);
30 &add($h1,$lc1,$h1); &FR($lc1);
31 &add($c2,$hc1,$c2); &FR($hc1);
32
33 &add($c0,$l1,$c0);
34 &add($c1,$h1,$c1);
35 &cmpult($c0,$l1,($lc1)=&NR(1)); &FR($l1);
36 &cmpult($c1,$h1,($hc1)=&NR(1)); &FR($h1);
37
38 &add($c1,$lc1,$c1); &FR($lc1);
39 &add($c2,$hc1,$c2); &FR($hc1);
40 }
41
42
43sub bn_sqr_comba4
44 {
45 local($name)=@_;
46 local(@a,@b,$r,$c0,$c1,$c2);
47
48 $cnt=1;
49 &init_pool(2);
50
51 $rp=&wparam(0);
52 $ap=&wparam(1);
53
54 &function_begin($name,"");
55
56 &comment("");
57
58 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
59 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
60 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
61 &ld(($a[3])=&NR(1),&QWPw(3,$ap)); &FR($ap);
62
63 ($c0,$c1,$c2)=&NR(3);
64
65 &mov("zero",$c2);
66 &mul($a[0],$a[0],$c0);
67 &muh($a[0],$a[0],$c1);
68 &st($c0,&QWPw(0,$rp));
69 ($c0,$c1,$c2)=($c1,$c2,$c0);
70 &mov("zero",$c2);
71
72 &sqr_add_c2($a[0],$a[1],$c0,$c1,$c2);
73 &st($c0,&QWPw(1,$rp));
74 ($c0,$c1,$c2)=($c1,$c2,$c0);
75 &mov("zero",$c2);
76
77 &sqr_add_c($a[1],$c0,$c1,$c2);
78 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
79 &st($c0,&QWPw(2,$rp));
80 ($c0,$c1,$c2)=($c1,$c2,$c0);
81 &mov("zero",$c2);
82
83 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
84 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
85 &st($c0,&QWPw(3,$rp));
86 ($c0,$c1,$c2)=($c1,$c2,$c0);
87 &mov("zero",$c2);
88
89 &sqr_add_c($a[2],$c0,$c1,$c2);
90 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
91 &st($c0,&QWPw(4,$rp));
92 ($c0,$c1,$c2)=($c1,$c2,$c0);
93 &mov("zero",$c2);
94
95 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
96 &st($c0,&QWPw(5,$rp));
97 ($c0,$c1,$c2)=($c1,$c2,$c0);
98 &mov("zero",$c2);
99
100 &sqr_add_c($a[3],$c0,$c1,$c2);
101 &st($c0,&QWPw(6,$rp));
102 &st($c1,&QWPw(7,$rp));
103
104 &function_end($name);
105
106 &fin_pool;
107 }
108
1091;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl b/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl
new file mode 100644
index 0000000000..b4afe085f1
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sqr_c8.pl
@@ -0,0 +1,132 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sqr_comba8
5 {
6 local($name)=@_;
7 local(@a,@b,$r,$c0,$c1,$c2);
8
9 $cnt=1;
10 &init_pool(2);
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14
15 &function_begin($name,"");
16
17 &comment("");
18
19 &ld(($a[0])=&NR(1),&QWPw(0,$ap));
20 &ld(($a[1])=&NR(1),&QWPw(1,$ap));
21 &ld(($a[2])=&NR(1),&QWPw(2,$ap));
22 &ld(($a[3])=&NR(1),&QWPw(3,$ap));
23 &ld(($a[4])=&NR(1),&QWPw(4,$ap));
24 &ld(($a[5])=&NR(1),&QWPw(5,$ap));
25 &ld(($a[6])=&NR(1),&QWPw(6,$ap));
26 &ld(($a[7])=&NR(1),&QWPw(7,$ap)); &FR($ap);
27
28 ($c0,$c1,$c2)=&NR(3);
29
30 &mov("zero",$c2);
31 &mul($a[0],$a[0],$c0);
32 &muh($a[0],$a[0],$c1);
33 &st($c0,&QWPw(0,$rp));
34 ($c0,$c1,$c2)=($c1,$c2,$c0);
35 &mov("zero",$c2);
36
37 &sqr_add_c2($a[1],$a[0],$c0,$c1,$c2);
38 &st($c0,&QWPw(1,$rp));
39 ($c0,$c1,$c2)=($c1,$c2,$c0);
40 &mov("zero",$c2);
41
42 &sqr_add_c($a[1],$c0,$c1,$c2);
43 &sqr_add_c2($a[2],$a[0],$c0,$c1,$c2);
44 &st($c0,&QWPw(2,$rp));
45 ($c0,$c1,$c2)=($c1,$c2,$c0);
46 &mov("zero",$c2);
47
48 &sqr_add_c2($a[2],$a[1],$c0,$c1,$c2);
49 &sqr_add_c2($a[3],$a[0],$c0,$c1,$c2);
50 &st($c0,&QWPw(3,$rp));
51 ($c0,$c1,$c2)=($c1,$c2,$c0);
52 &mov("zero",$c2);
53
54 &sqr_add_c($a[2],$c0,$c1,$c2);
55 &sqr_add_c2($a[3],$a[1],$c0,$c1,$c2);
56 &sqr_add_c2($a[4],$a[0],$c0,$c1,$c2);
57 &st($c0,&QWPw(4,$rp));
58 ($c0,$c1,$c2)=($c1,$c2,$c0);
59 &mov("zero",$c2);
60
61 &sqr_add_c2($a[3],$a[2],$c0,$c1,$c2);
62 &sqr_add_c2($a[4],$a[1],$c0,$c1,$c2);
63 &sqr_add_c2($a[5],$a[0],$c0,$c1,$c2);
64 &st($c0,&QWPw(5,$rp));
65 ($c0,$c1,$c2)=($c1,$c2,$c0);
66 &mov("zero",$c2);
67
68 &sqr_add_c($a[3],$c0,$c1,$c2);
69 &sqr_add_c2($a[4],$a[2],$c0,$c1,$c2);
70 &sqr_add_c2($a[5],$a[1],$c0,$c1,$c2);
71 &sqr_add_c2($a[6],$a[0],$c0,$c1,$c2);
72 &st($c0,&QWPw(6,$rp));
73 ($c0,$c1,$c2)=($c1,$c2,$c0);
74 &mov("zero",$c2);
75
76 &sqr_add_c2($a[4],$a[3],$c0,$c1,$c2);
77 &sqr_add_c2($a[5],$a[2],$c0,$c1,$c2);
78 &sqr_add_c2($a[6],$a[1],$c0,$c1,$c2);
79 &sqr_add_c2($a[7],$a[0],$c0,$c1,$c2);
80 &st($c0,&QWPw(7,$rp));
81 ($c0,$c1,$c2)=($c1,$c2,$c0);
82 &mov("zero",$c2);
83
84 &sqr_add_c($a[4],$c0,$c1,$c2);
85 &sqr_add_c2($a[5],$a[3],$c0,$c1,$c2);
86 &sqr_add_c2($a[6],$a[2],$c0,$c1,$c2);
87 &sqr_add_c2($a[7],$a[1],$c0,$c1,$c2);
88 &st($c0,&QWPw(8,$rp));
89 ($c0,$c1,$c2)=($c1,$c2,$c0);
90 &mov("zero",$c2);
91
92 &sqr_add_c2($a[5],$a[4],$c0,$c1,$c2);
93 &sqr_add_c2($a[6],$a[3],$c0,$c1,$c2);
94 &sqr_add_c2($a[7],$a[2],$c0,$c1,$c2);
95 &st($c0,&QWPw(9,$rp));
96 ($c0,$c1,$c2)=($c1,$c2,$c0);
97 &mov("zero",$c2);
98
99 &sqr_add_c($a[5],$c0,$c1,$c2);
100 &sqr_add_c2($a[6],$a[4],$c0,$c1,$c2);
101 &sqr_add_c2($a[7],$a[3],$c0,$c1,$c2);
102 &st($c0,&QWPw(10,$rp));
103 ($c0,$c1,$c2)=($c1,$c2,$c0);
104 &mov("zero",$c2);
105
106 &sqr_add_c2($a[6],$a[5],$c0,$c1,$c2);
107 &sqr_add_c2($a[7],$a[4],$c0,$c1,$c2);
108 &st($c0,&QWPw(11,$rp));
109 ($c0,$c1,$c2)=($c1,$c2,$c0);
110 &mov("zero",$c2);
111
112 &sqr_add_c($a[6],$c0,$c1,$c2);
113 &sqr_add_c2($a[7],$a[5],$c0,$c1,$c2);
114 &st($c0,&QWPw(12,$rp));
115 ($c0,$c1,$c2)=($c1,$c2,$c0);
116 &mov("zero",$c2);
117
118 &sqr_add_c2($a[7],$a[6],$c0,$c1,$c2);
119 &st($c0,&QWPw(13,$rp));
120 ($c0,$c1,$c2)=($c1,$c2,$c0);
121 &mov("zero",$c2);
122
123 &sqr_add_c($a[7],$c0,$c1,$c2);
124 &st($c0,&QWPw(14,$rp));
125 &st($c1,&QWPw(15,$rp));
126
127 &function_end($name);
128
129 &fin_pool;
130 }
131
1321;
diff --git a/src/lib/libcrypto/bn/asm/alpha/sub.pl b/src/lib/libcrypto/bn/asm/alpha/sub.pl
new file mode 100644
index 0000000000..d998da5c21
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/alpha/sub.pl
@@ -0,0 +1,108 @@
1#!/usr/local/bin/perl
2# alpha assember
3
4sub bn_sub_words
5 {
6 local($name)=@_;
7 local($cc,$a,$b,$r);
8
9 &init_pool(4);
10 ($cc)=GR("r0");
11
12 $rp=&wparam(0);
13 $ap=&wparam(1);
14 $bp=&wparam(2);
15 $count=&wparam(3);
16
17 &function_begin($name,"");
18
19 &comment("");
20 &sub($count,4,$count);
21 &mov("zero",$cc);
22 &blt($count,&label("finish"));
23
24 ($a0,$b0)=&NR(2);
25 &ld($a0,&QWPw(0,$ap));
26 &ld($b0,&QWPw(0,$bp));
27
28##########################################################
29 &set_label("loop");
30
31 ($a1,$tmp,$b1,$a2,$b2,$a3,$b3,$o0)=&NR(8);
32 &ld($a1,&QWPw(1,$ap));
33 &cmpult($a0,$b0,$tmp); # will we borrow?
34 &ld($b1,&QWPw(1,$bp));
35 &sub($a0,$b0,$a0); # do the subtract
36 &ld($a2,&QWPw(2,$ap));
37 &cmpult($a0,$cc,$b0); # will we borrow?
38 &ld($b2,&QWPw(2,$bp));
39 &sub($a0,$cc,$o0); # will we borrow?
40 &ld($a3,&QWPw(3,$ap));
41 &add($b0,$tmp,$cc); ($t1,$o1)=&NR(2); &FR($tmp);
42
43 &cmpult($a1,$b1,$t1); # will we borrow?
44 &sub($a1,$b1,$a1); # do the subtract
45 &ld($b3,&QWPw(3,$bp));
46 &cmpult($a1,$cc,$b1); # will we borrow?
47 &sub($a1,$cc,$o1); # will we borrow?
48 &add($b1,$t1,$cc); ($tmp,$o2)=&NR(2); &FR($t1,$a1,$b1);
49
50 &cmpult($a2,$b2,$tmp); # will we borrow?
51 &sub($a2,$b2,$a2); # do the subtract
52 &st($o0,&QWPw(0,$rp)); &FR($o0); # save
53 &cmpult($a2,$cc,$b2); # will we borrow?
54 &sub($a2,$cc,$o2); # will we borrow?
55 &add($b2,$tmp,$cc); ($t3,$o3)=&NR(2); &FR($tmp,$a2,$b2);
56
57 &cmpult($a3,$b3,$t3); # will we borrow?
58 &sub($a3,$b3,$a3); # do the subtract
59 &st($o1,&QWPw(1,$rp)); &FR($o1);
60 &cmpult($a3,$cc,$b3); # will we borrow?
61 &sub($a3,$cc,$o3); # will we borrow?
62 &add($b3,$t3,$cc); &FR($t3,$a3,$b3);
63
64 &st($o2,&QWPw(2,$rp)); &FR($o2);
65 &sub($count,4,$count); # count-=4
66 &st($o3,&QWPw(3,$rp)); &FR($o3);
67 &add($ap,4*$QWS,$ap); # count+=4
68 &add($bp,4*$QWS,$bp); # count+=4
69 &add($rp,4*$QWS,$rp); # count+=4
70
71 &blt($count,&label("finish"));
72 &ld($a0,&QWPw(0,$ap));
73 &ld($b0,&QWPw(0,$bp));
74 &br(&label("loop"));
75##################################################
76 # Do the last 0..3 words
77
78 &set_label("last_loop");
79
80 &ld($a0,&QWPw(0,$ap)); # get a
81 &ld($b0,&QWPw(0,$bp)); # get b
82 &cmpult($a0,$b0,$tmp); # will we borrow?
83 &sub($a0,$b0,$a0); # do the subtract
84 &cmpult($a0,$cc,$b0); # will we borrow?
85 &sub($a0,$cc,$a0); # will we borrow?
86 &st($a0,&QWPw(0,$rp)); # save
87 &add($b0,$tmp,$cc); # add the borrows
88
89 &add($ap,$QWS,$ap);
90 &add($bp,$QWS,$bp);
91 &add($rp,$QWS,$rp);
92 &sub($count,1,$count);
93 &bgt($count,&label("last_loop"));
94 &function_end_A($name);
95
96######################################################
97 &set_label("finish");
98 &add($count,4,$count);
99 &bgt($count,&label("last_loop"));
100
101 &FR($a0,$b0);
102 &set_label("end");
103 &function_end($name);
104
105 &fin_pool;
106 }
107
1081;
diff --git a/src/lib/libcrypto/bn/asm/bn-586.pl b/src/lib/libcrypto/bn/asm/bn-586.pl
index 26c2685a72..c4de4a2bee 100644
--- a/src/lib/libcrypto/bn/asm/bn-586.pl
+++ b/src/lib/libcrypto/bn/asm/bn-586.pl
@@ -5,18 +5,13 @@ require "x86asm.pl";
5 5
6&asm_init($ARGV[0],$0); 6&asm_init($ARGV[0],$0);
7 7
8$sse2=0;
9for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
10
11&external_label("OPENSSL_ia32cap_P") if ($sse2);
12
13&bn_mul_add_words("bn_mul_add_words"); 8&bn_mul_add_words("bn_mul_add_words");
14&bn_mul_words("bn_mul_words"); 9&bn_mul_words("bn_mul_words");
15&bn_sqr_words("bn_sqr_words"); 10&bn_sqr_words("bn_sqr_words");
16&bn_div_words("bn_div_words"); 11&bn_div_words("bn_div_words");
17&bn_add_words("bn_add_words"); 12&bn_add_words("bn_add_words");
18&bn_sub_words("bn_sub_words"); 13&bn_sub_words("bn_sub_words");
19&bn_sub_part_words("bn_sub_part_words"); 14#&bn_sub_part_words("bn_sub_part_words");
20 15
21&asm_finish(); 16&asm_finish();
22 17
@@ -24,7 +19,7 @@ sub bn_mul_add_words
24 { 19 {
25 local($name)=@_; 20 local($name)=@_;
26 21
27 &function_begin($name,$sse2?"EXTRN\t_OPENSSL_ia32cap_P:DWORD":""); 22 &function_begin($name,"");
28 23
29 &comment(""); 24 &comment("");
30 $Low="eax"; 25 $Low="eax";
@@ -47,83 +42,6 @@ sub bn_mul_add_words
47 42
48 &jz(&label("maw_finish")); 43 &jz(&label("maw_finish"));
49 44
50 if ($sse2) {
51 &picmeup("eax","OPENSSL_ia32cap_P");
52 &bt(&DWP(0,"eax"),26);
53 &jnc(&label("maw_loop"));
54
55 &movd("mm0",$w); # mm0 = w
56 &pxor("mm1","mm1"); # mm1 = carry_in
57
58 &set_label("maw_sse2_loop",0);
59 &movd("mm3",&DWP(0,$r,"",0)); # mm3 = r[0]
60 &paddq("mm1","mm3"); # mm1 = carry_in + r[0]
61 &movd("mm2",&DWP(0,$a,"",0)); # mm2 = a[0]
62 &pmuludq("mm2","mm0"); # mm2 = w*a[0]
63 &movd("mm4",&DWP(4,$a,"",0)); # mm4 = a[1]
64 &pmuludq("mm4","mm0"); # mm4 = w*a[1]
65 &movd("mm6",&DWP(8,$a,"",0)); # mm6 = a[2]
66 &pmuludq("mm6","mm0"); # mm6 = w*a[2]
67 &movd("mm7",&DWP(12,$a,"",0)); # mm7 = a[3]
68 &pmuludq("mm7","mm0"); # mm7 = w*a[3]
69 &paddq("mm1","mm2"); # mm1 = carry_in + r[0] + w*a[0]
70 &movd("mm3",&DWP(4,$r,"",0)); # mm3 = r[1]
71 &paddq("mm3","mm4"); # mm3 = r[1] + w*a[1]
72 &movd("mm5",&DWP(8,$r,"",0)); # mm5 = r[2]
73 &paddq("mm5","mm6"); # mm5 = r[2] + w*a[2]
74 &movd("mm4",&DWP(12,$r,"",0)); # mm4 = r[3]
75 &paddq("mm7","mm4"); # mm7 = r[3] + w*a[3]
76 &movd(&DWP(0,$r,"",0),"mm1");
77 &movd("mm2",&DWP(16,$a,"",0)); # mm2 = a[4]
78 &pmuludq("mm2","mm0"); # mm2 = w*a[4]
79 &psrlq("mm1",32); # mm1 = carry0
80 &movd("mm4",&DWP(20,$a,"",0)); # mm4 = a[5]
81 &pmuludq("mm4","mm0"); # mm4 = w*a[5]
82 &paddq("mm1","mm3"); # mm1 = carry0 + r[1] + w*a[1]
83 &movd("mm6",&DWP(24,$a,"",0)); # mm6 = a[6]
84 &pmuludq("mm6","mm0"); # mm6 = w*a[6]
85 &movd(&DWP(4,$r,"",0),"mm1");
86 &psrlq("mm1",32); # mm1 = carry1
87 &movd("mm3",&DWP(28,$a,"",0)); # mm3 = a[7]
88 &add($a,32);
89 &pmuludq("mm3","mm0"); # mm3 = w*a[7]
90 &paddq("mm1","mm5"); # mm1 = carry1 + r[2] + w*a[2]
91 &movd("mm5",&DWP(16,$r,"",0)); # mm5 = r[4]
92 &paddq("mm2","mm5"); # mm2 = r[4] + w*a[4]
93 &movd(&DWP(8,$r,"",0),"mm1");
94 &psrlq("mm1",32); # mm1 = carry2
95 &paddq("mm1","mm7"); # mm1 = carry2 + r[3] + w*a[3]
96 &movd("mm5",&DWP(20,$r,"",0)); # mm5 = r[5]
97 &paddq("mm4","mm5"); # mm4 = r[5] + w*a[5]
98 &movd(&DWP(12,$r,"",0),"mm1");
99 &psrlq("mm1",32); # mm1 = carry3
100 &paddq("mm1","mm2"); # mm1 = carry3 + r[4] + w*a[4]
101 &movd("mm5",&DWP(24,$r,"",0)); # mm5 = r[6]
102 &paddq("mm6","mm5"); # mm6 = r[6] + w*a[6]
103 &movd(&DWP(16,$r,"",0),"mm1");
104 &psrlq("mm1",32); # mm1 = carry4
105 &paddq("mm1","mm4"); # mm1 = carry4 + r[5] + w*a[5]
106 &movd("mm5",&DWP(28,$r,"",0)); # mm5 = r[7]
107 &paddq("mm3","mm5"); # mm3 = r[7] + w*a[7]
108 &movd(&DWP(20,$r,"",0),"mm1");
109 &psrlq("mm1",32); # mm1 = carry5
110 &paddq("mm1","mm6"); # mm1 = carry5 + r[6] + w*a[6]
111 &movd(&DWP(24,$r,"",0),"mm1");
112 &psrlq("mm1",32); # mm1 = carry6
113 &paddq("mm1","mm3"); # mm1 = carry6 + r[7] + w*a[7]
114 &movd(&DWP(28,$r,"",0),"mm1");
115 &add($r,32);
116 &psrlq("mm1",32); # mm1 = carry_out
117
118 &sub("ecx",8);
119 &jnz(&label("maw_sse2_loop"));
120
121 &movd($c,"mm1"); # c = carry_out
122 &emms();
123
124 &jmp(&label("maw_finish"));
125 }
126
127 &set_label("maw_loop",0); 45 &set_label("maw_loop",0);
128 46
129 &mov(&swtmp(0),"ecx"); # 47 &mov(&swtmp(0),"ecx"); #
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/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-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/ia64.S b/src/lib/libcrypto/bn/asm/ia64.S
index 951abc53ea..7b82b820e6 100644
--- a/src/lib/libcrypto/bn/asm/ia64.S
+++ b/src/lib/libcrypto/bn/asm/ia64.S
@@ -171,21 +171,21 @@
171.skip 32 // makes the loop body aligned at 64-byte boundary 171.skip 32 // makes the loop body aligned at 64-byte boundary
172bn_add_words: 172bn_add_words:
173 .prologue 173 .prologue
174 .fframe 0
174 .save ar.pfs,r2 175 .save ar.pfs,r2
175{ .mii; alloc r2=ar.pfs,4,12,0,16 176{ .mii; alloc r2=ar.pfs,4,12,0,16
176 cmp4.le p6,p0=r35,r0 };; 177 cmp4.le p6,p0=r35,r0 };;
177{ .mfb; mov r8=r0 // return value 178{ .mfb; mov r8=r0 // return value
178(p6) br.ret.spnt.many b0 };; 179(p6) br.ret.spnt.many b0 };;
179 180
180{ .mib; sub r10=r35,r0,1
181 .save ar.lc,r3 181 .save ar.lc,r3
182{ .mib; sub r10=r35,r0,1
182 mov r3=ar.lc 183 mov r3=ar.lc
183 brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16 184 brp.loop.imp .L_bn_add_words_ctop,.L_bn_add_words_cend-16
184 } 185 }
186 .body
185{ .mib; ADDP r14=0,r32 // rp 187{ .mib; ADDP r14=0,r32 // rp
186 .save pr,r9
187 mov r9=pr };; 188 mov r9=pr };;
188 .body
189{ .mii; ADDP r15=0,r33 // ap 189{ .mii; ADDP r15=0,r33 // ap
190 mov ar.lc=r10 190 mov ar.lc=r10
191 mov ar.ec=6 } 191 mov ar.ec=6 }
@@ -224,21 +224,21 @@ bn_add_words:
224.skip 32 // makes the loop body aligned at 64-byte boundary 224.skip 32 // makes the loop body aligned at 64-byte boundary
225bn_sub_words: 225bn_sub_words:
226 .prologue 226 .prologue
227 .fframe 0
227 .save ar.pfs,r2 228 .save ar.pfs,r2
228{ .mii; alloc r2=ar.pfs,4,12,0,16 229{ .mii; alloc r2=ar.pfs,4,12,0,16
229 cmp4.le p6,p0=r35,r0 };; 230 cmp4.le p6,p0=r35,r0 };;
230{ .mfb; mov r8=r0 // return value 231{ .mfb; mov r8=r0 // return value
231(p6) br.ret.spnt.many b0 };; 232(p6) br.ret.spnt.many b0 };;
232 233
233{ .mib; sub r10=r35,r0,1
234 .save ar.lc,r3 234 .save ar.lc,r3
235{ .mib; sub r10=r35,r0,1
235 mov r3=ar.lc 236 mov r3=ar.lc
236 brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16 237 brp.loop.imp .L_bn_sub_words_ctop,.L_bn_sub_words_cend-16
237 } 238 }
239 .body
238{ .mib; ADDP r14=0,r32 // rp 240{ .mib; ADDP r14=0,r32 // rp
239 .save pr,r9
240 mov r9=pr };; 241 mov r9=pr };;
241 .body
242{ .mii; ADDP r15=0,r33 // ap 242{ .mii; ADDP r15=0,r33 // ap
243 mov ar.lc=r10 243 mov ar.lc=r10
244 mov ar.ec=6 } 244 mov ar.ec=6 }
@@ -283,6 +283,7 @@ bn_sub_words:
283.skip 32 // makes the loop body aligned at 64-byte boundary 283.skip 32 // makes the loop body aligned at 64-byte boundary
284bn_mul_words: 284bn_mul_words:
285 .prologue 285 .prologue
286 .fframe 0
286 .save ar.pfs,r2 287 .save ar.pfs,r2
287#ifdef XMA_TEMPTATION 288#ifdef XMA_TEMPTATION
288{ .mfi; alloc r2=ar.pfs,4,0,0,0 };; 289{ .mfi; alloc r2=ar.pfs,4,0,0,0 };;
@@ -293,10 +294,9 @@ bn_mul_words:
293 cmp4.le p6,p0=r34,r0 294 cmp4.le p6,p0=r34,r0
294(p6) br.ret.spnt.many b0 };; 295(p6) br.ret.spnt.many b0 };;
295 296
296{ .mii; sub r10=r34,r0,1
297 .save ar.lc,r3 297 .save ar.lc,r3
298{ .mii; sub r10=r34,r0,1
298 mov r3=ar.lc 299 mov r3=ar.lc
299 .save pr,r9
300 mov r9=pr };; 300 mov r9=pr };;
301 301
302 .body 302 .body
@@ -397,21 +397,22 @@ bn_mul_words:
397.skip 48 // makes the loop body aligned at 64-byte boundary 397.skip 48 // makes the loop body aligned at 64-byte boundary
398bn_mul_add_words: 398bn_mul_add_words:
399 .prologue 399 .prologue
400 .fframe 0
400 .save ar.pfs,r2 401 .save ar.pfs,r2
402 .save ar.lc,r3
403 .save pr,r9
401{ .mmi; alloc r2=ar.pfs,4,4,0,8 404{ .mmi; alloc r2=ar.pfs,4,4,0,8
402 cmp4.le p6,p0=r34,r0 405 cmp4.le p6,p0=r34,r0
403 .save ar.lc,r3
404 mov r3=ar.lc };; 406 mov r3=ar.lc };;
405{ .mib; mov r8=r0 // return value 407{ .mib; mov r8=r0 // return value
406 sub r10=r34,r0,1 408 sub r10=r34,r0,1
407(p6) br.ret.spnt.many b0 };; 409(p6) br.ret.spnt.many b0 };;
408 410
411 .body
409{ .mib; setf.sig f8=r35 // w 412{ .mib; setf.sig f8=r35 // w
410 .save pr,r9
411 mov r9=pr 413 mov r9=pr
412 brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16 414 brp.loop.imp .L_bn_mul_add_words_ctop,.L_bn_mul_add_words_cend-16
413 } 415 }
414 .body
415{ .mmi; ADDP r14=0,r32 // rp 416{ .mmi; ADDP r14=0,r32 // rp
416 ADDP r15=0,r33 // ap 417 ADDP r15=0,r33 // ap
417 mov ar.lc=r10 } 418 mov ar.lc=r10 }
@@ -465,6 +466,7 @@ bn_mul_add_words:
465.skip 32 // makes the loop body aligned at 64-byte boundary 466.skip 32 // makes the loop body aligned at 64-byte boundary
466bn_sqr_words: 467bn_sqr_words:
467 .prologue 468 .prologue
469 .fframe 0
468 .save ar.pfs,r2 470 .save ar.pfs,r2
469{ .mii; alloc r2=ar.pfs,3,0,0,0 471{ .mii; alloc r2=ar.pfs,3,0,0,0
470 sxt4 r34=r34 };; 472 sxt4 r34=r34 };;
@@ -474,10 +476,9 @@ bn_sqr_words:
474 nop.f 0x0 476 nop.f 0x0
475(p6) br.ret.spnt.many b0 };; 477(p6) br.ret.spnt.many b0 };;
476 478
477{ .mii; sub r10=r34,r0,1
478 .save ar.lc,r3 479 .save ar.lc,r3
480{ .mii; sub r10=r34,r0,1
479 mov r3=ar.lc 481 mov r3=ar.lc
480 .save pr,r9
481 mov r9=pr };; 482 mov r9=pr };;
482 483
483 .body 484 .body
@@ -544,6 +545,7 @@ bn_sqr_words:
544.align 64 545.align 64
545bn_sqr_comba8: 546bn_sqr_comba8:
546 .prologue 547 .prologue
548 .fframe 0
547 .save ar.pfs,r2 549 .save ar.pfs,r2
548#if defined(_HPUX_SOURCE) && !defined(_LP64) 550#if defined(_HPUX_SOURCE) && !defined(_LP64)
549{ .mii; alloc r2=ar.pfs,2,1,0,0 551{ .mii; alloc r2=ar.pfs,2,1,0,0
@@ -615,6 +617,7 @@ bn_sqr_comba8:
615.align 64 617.align 64
616bn_mul_comba8: 618bn_mul_comba8:
617 .prologue 619 .prologue
620 .fframe 0
618 .save ar.pfs,r2 621 .save ar.pfs,r2
619#if defined(_HPUX_SOURCE) && !defined(_LP64) 622#if defined(_HPUX_SOURCE) && !defined(_LP64)
620{ .mii; alloc r2=ar.pfs,3,0,0,0 623{ .mii; alloc r2=ar.pfs,3,0,0,0
@@ -1172,6 +1175,7 @@ bn_mul_comba8:
1172.align 64 1175.align 64
1173bn_sqr_comba4: 1176bn_sqr_comba4:
1174 .prologue 1177 .prologue
1178 .fframe 0
1175 .save ar.pfs,r2 1179 .save ar.pfs,r2
1176#if defined(_HPUX_SOURCE) && !defined(_LP64) 1180#if defined(_HPUX_SOURCE) && !defined(_LP64)
1177{ .mii; alloc r2=ar.pfs,2,1,0,0 1181{ .mii; alloc r2=ar.pfs,2,1,0,0
@@ -1204,6 +1208,7 @@ bn_sqr_comba4:
1204.align 64 1208.align 64
1205bn_mul_comba4: 1209bn_mul_comba4:
1206 .prologue 1210 .prologue
1211 .fframe 0
1207 .save ar.pfs,r2 1212 .save ar.pfs,r2
1208#if defined(_HPUX_SOURCE) && !defined(_LP64) 1213#if defined(_HPUX_SOURCE) && !defined(_LP64)
1209{ .mii; alloc r2=ar.pfs,3,0,0,0 1214{ .mii; alloc r2=ar.pfs,3,0,0,0
@@ -1406,11 +1411,11 @@ equ=p24
1406.align 64 1411.align 64
1407bn_div_words: 1412bn_div_words:
1408 .prologue 1413 .prologue
1414 .fframe 0
1409 .save ar.pfs,r2 1415 .save ar.pfs,r2
1410{ .mii; alloc r2=ar.pfs,3,5,0,8
1411 .save b0,r3 1416 .save b0,r3
1417{ .mii; alloc r2=ar.pfs,3,5,0,8
1412 mov r3=b0 1418 mov r3=b0
1413 .save pr,r10
1414 mov r10=pr };; 1419 mov r10=pr };;
1415{ .mmb; cmp.eq p6,p0=r34,r0 1420{ .mmb; cmp.eq p6,p0=r34,r0
1416 mov r8=-1 1421 mov r8=-1
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..dca4105c7d
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/mips3.s
@@ -0,0 +1,2201 @@
1.rdata
2.asciiz "mips3.s, Version 1.1"
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 subu a3,4
399 ld t1,8(a1)
400 and AT,a3,MINUS4
401 ld t2,16(a1)
402 PTR_ADD a2,32
403 ld t3,24(a1)
404 PTR_ADD a0,32
405 ld ta1,-24(a2)
406 PTR_ADD a1,32
407 ld ta2,-16(a2)
408 ld ta3,-8(a2)
409 daddu ta0,t0
410 sltu t8,ta0,t0
411 daddu t0,ta0,v0
412 sltu v0,t0,ta0
413 sd t0,-32(a0)
414 daddu v0,t8
415
416 daddu ta1,t1
417 sltu t9,ta1,t1
418 daddu t1,ta1,v0
419 sltu v0,t1,ta1
420 sd t1,-24(a0)
421 daddu v0,t9
422
423 daddu ta2,t2
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 subu a3,4
499 ld t1,8(a1)
500 and AT,a3,MINUS4
501 ld t2,16(a1)
502 PTR_ADD a2,32
503 ld t3,24(a1)
504 PTR_ADD a0,32
505 ld ta1,-24(a2)
506 PTR_ADD a1,32
507 ld ta2,-16(a2)
508 ld ta3,-8(a2)
509 sltu t8,t0,ta0
510 dsubu t0,ta0
511 dsubu ta0,t0,v0
512 sd ta0,-32(a0)
513 MOVNZ (t0,v0,t8)
514
515 sltu t9,t1,ta1
516 dsubu t1,ta1
517 dsubu ta1,t1,v0
518 sd ta1,-24(a0)
519 MOVNZ (t1,v0,t9)
520
521
522 sltu t8,t2,ta2
523 dsubu t2,ta2
524 dsubu ta2,t2,v0
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_3_words)
579 .set reorder
580 move a3,a0 /* we know that bn_div_words doesn't
581 * touch a3, ta2, ta3 and preserves a2
582 * so that we can save two arguments
583 * and return address in registers
584 * instead of stack:-)
585 */
586 ld a0,(a3)
587 move ta2,a1
588 ld a1,-8(a3)
589 bne a0,a2,.L_bn_div_3_words_proceed
590 li v0,-1
591 jr ra
592.L_bn_div_3_words_proceed:
593 move ta3,ra
594 bal bn_div_words
595 move ra,ta3
596 dmultu ta2,v0
597 ld t2,-16(a3)
598 move ta0,zero
599 mfhi t1
600 mflo t0
601 sltu t8,t1,v1
602.L_bn_div_3_words_inner_loop:
603 bnez t8,.L_bn_div_3_words_inner_loop_done
604 sgeu AT,t2,t0
605 seq t9,t1,v1
606 and AT,t9
607 sltu t3,t0,ta2
608 daddu v1,a2
609 dsubu t1,t3
610 dsubu t0,ta2
611 sltu t8,t1,v1
612 sltu ta0,v1,a2
613 or t8,ta0
614 .set noreorder
615 beqzl AT,.L_bn_div_3_words_inner_loop
616 dsubu v0,1
617 .set reorder
618.L_bn_div_3_words_inner_loop_done:
619 jr ra
620END(bn_div_3_words)
621
622.align 5
623LEAF(bn_div_words)
624 .set noreorder
625 bnezl a2,.L_bn_div_words_proceed
626 move v1,zero
627 jr ra
628 li v0,-1 /* I'd rather signal div-by-zero
629 * which can be done with 'break 7' */
630
631.L_bn_div_words_proceed:
632 bltz a2,.L_bn_div_words_body
633 move t9,v1
634 dsll a2,1
635 bgtz a2,.-4
636 addu t9,1
637
638 .set reorder
639 negu t1,t9
640 li t2,-1
641 dsll t2,t1
642 and t2,a0
643 dsrl AT,a1,t1
644 .set noreorder
645 bnezl t2,.+8
646 break 6 /* signal overflow */
647 .set reorder
648 dsll a0,t9
649 dsll a1,t9
650 or a0,AT
651
652#define QT ta0
653#define HH ta1
654#define DH v1
655.L_bn_div_words_body:
656 dsrl DH,a2,32
657 sgeu AT,a0,a2
658 .set noreorder
659 bnezl AT,.+8
660 dsubu a0,a2
661 .set reorder
662
663 li QT,-1
664 dsrl HH,a0,32
665 dsrl QT,32 /* q=0xffffffff */
666 beq DH,HH,.L_bn_div_words_skip_div1
667 ddivu zero,a0,DH
668 mflo QT
669.L_bn_div_words_skip_div1:
670 dmultu a2,QT
671 dsll t3,a0,32
672 dsrl AT,a1,32
673 or t3,AT
674 mflo t0
675 mfhi t1
676.L_bn_div_words_inner_loop1:
677 sltu t2,t3,t0
678 seq t8,HH,t1
679 sltu AT,HH,t1
680 and t2,t8
681 sltu v0,t0,a2
682 or AT,t2
683 .set noreorder
684 beqz AT,.L_bn_div_words_inner_loop1_done
685 dsubu t1,v0
686 dsubu t0,a2
687 b .L_bn_div_words_inner_loop1
688 dsubu QT,1
689 .set reorder
690.L_bn_div_words_inner_loop1_done:
691
692 dsll a1,32
693 dsubu a0,t3,t0
694 dsll v0,QT,32
695
696 li QT,-1
697 dsrl HH,a0,32
698 dsrl QT,32 /* q=0xffffffff */
699 beq DH,HH,.L_bn_div_words_skip_div2
700 ddivu zero,a0,DH
701 mflo QT
702.L_bn_div_words_skip_div2:
703#undef DH
704 dmultu a2,QT
705 dsll t3,a0,32
706 dsrl AT,a1,32
707 or t3,AT
708 mflo t0
709 mfhi t1
710.L_bn_div_words_inner_loop2:
711 sltu t2,t3,t0
712 seq t8,HH,t1
713 sltu AT,HH,t1
714 and t2,t8
715 sltu v1,t0,a2
716 or AT,t2
717 .set noreorder
718 beqz AT,.L_bn_div_words_inner_loop2_done
719 dsubu t1,v1
720 dsubu t0,a2
721 b .L_bn_div_words_inner_loop2
722 dsubu QT,1
723 .set reorder
724.L_bn_div_words_inner_loop2_done:
725#undef HH
726
727 dsubu a0,t3,t0
728 or v0,QT
729 dsrl v1,a0,t9 /* v1 contains remainder if anybody wants it */
730 dsrl a2,t9 /* restore a2 */
731 jr ra
732#undef QT
733END(bn_div_words)
734
735#define a_0 t0
736#define a_1 t1
737#define a_2 t2
738#define a_3 t3
739#define b_0 ta0
740#define b_1 ta1
741#define b_2 ta2
742#define b_3 ta3
743
744#define a_4 s0
745#define a_5 s2
746#define a_6 s4
747#define a_7 a1 /* once we load a[7] we don't need a anymore */
748#define b_4 s1
749#define b_5 s3
750#define b_6 s5
751#define b_7 a2 /* once we load b[7] we don't need b anymore */
752
753#define t_1 t8
754#define t_2 t9
755
756#define c_1 v0
757#define c_2 v1
758#define c_3 a3
759
760#define FRAME_SIZE 48
761
762.align 5
763LEAF(bn_mul_comba8)
764 .set noreorder
765 PTR_SUB sp,FRAME_SIZE
766 .frame sp,64,ra
767 .set reorder
768 ld a_0,0(a1) /* If compiled with -mips3 option on
769 * R5000 box assembler barks on this
770 * line with "shouldn't have mult/div
771 * as last instruction in bb (R10K
772 * bug)" warning. If anybody out there
773 * has a clue about how to circumvent
774 * this do send me a note.
775 * <appro@fy.chalmers.se>
776 */
777 ld b_0,0(a2)
778 ld a_1,8(a1)
779 ld a_2,16(a1)
780 ld a_3,24(a1)
781 ld b_1,8(a2)
782 ld b_2,16(a2)
783 ld b_3,24(a2)
784 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
785 sd s0,0(sp)
786 sd s1,8(sp)
787 sd s2,16(sp)
788 sd s3,24(sp)
789 sd s4,32(sp)
790 sd s5,40(sp)
791 mflo c_1
792 mfhi c_2
793
794 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
795 ld a_4,32(a1)
796 ld a_5,40(a1)
797 ld a_6,48(a1)
798 ld a_7,56(a1)
799 ld b_4,32(a2)
800 ld b_5,40(a2)
801 mflo t_1
802 mfhi t_2
803 daddu c_2,t_1
804 sltu AT,c_2,t_1
805 daddu c_3,t_2,AT
806 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
807 ld b_6,48(a2)
808 ld b_7,56(a2)
809 sd c_1,0(a0) /* r[0]=c1; */
810 mflo t_1
811 mfhi t_2
812 daddu c_2,t_1
813 sltu AT,c_2,t_1
814 daddu t_2,AT
815 daddu c_3,t_2
816 sltu c_1,c_3,t_2
817 sd c_2,8(a0) /* r[1]=c2; */
818
819 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
820 mflo t_1
821 mfhi t_2
822 daddu c_3,t_1
823 sltu AT,c_3,t_1
824 daddu t_2,AT
825 daddu c_1,t_2
826 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
827 mflo t_1
828 mfhi t_2
829 daddu c_3,t_1
830 sltu AT,c_3,t_1
831 daddu t_2,AT
832 daddu c_1,t_2
833 sltu c_2,c_1,t_2
834 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
835 mflo t_1
836 mfhi t_2
837 daddu c_3,t_1
838 sltu AT,c_3,t_1
839 daddu t_2,AT
840 daddu c_1,t_2
841 sltu AT,c_1,t_2
842 daddu c_2,AT
843 sd c_3,16(a0) /* r[2]=c3; */
844
845 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
846 mflo t_1
847 mfhi t_2
848 daddu c_1,t_1
849 sltu AT,c_1,t_1
850 daddu t_2,AT
851 daddu c_2,t_2
852 sltu c_3,c_2,t_2
853 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
854 mflo t_1
855 mfhi t_2
856 daddu c_1,t_1
857 sltu AT,c_1,t_1
858 daddu t_2,AT
859 daddu c_2,t_2
860 sltu AT,c_2,t_2
861 daddu c_3,AT
862 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
863 mflo t_1
864 mfhi t_2
865 daddu c_1,t_1
866 sltu AT,c_1,t_1
867 daddu t_2,AT
868 daddu c_2,t_2
869 sltu AT,c_2,t_2
870 daddu c_3,AT
871 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
872 mflo t_1
873 mfhi t_2
874 daddu c_1,t_1
875 sltu AT,c_1,t_1
876 daddu t_2,AT
877 daddu c_2,t_2
878 sltu AT,c_2,t_2
879 daddu c_3,AT
880 sd c_1,24(a0) /* r[3]=c1; */
881
882 dmultu a_4,b_0 /* mul_add_c(a[4],b[0],c2,c3,c1); */
883 mflo t_1
884 mfhi t_2
885 daddu c_2,t_1
886 sltu AT,c_2,t_1
887 daddu t_2,AT
888 daddu c_3,t_2
889 sltu c_1,c_3,t_2
890 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
891 mflo t_1
892 mfhi t_2
893 daddu c_2,t_1
894 sltu AT,c_2,t_1
895 daddu t_2,AT
896 daddu c_3,t_2
897 sltu AT,c_3,t_2
898 daddu c_1,AT
899 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
900 mflo t_1
901 mfhi t_2
902 daddu c_2,t_1
903 sltu AT,c_2,t_1
904 daddu t_2,AT
905 daddu c_3,t_2
906 sltu AT,c_3,t_2
907 daddu c_1,AT
908 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
909 mflo t_1
910 mfhi t_2
911 daddu c_2,t_1
912 sltu AT,c_2,t_1
913 daddu t_2,AT
914 daddu c_3,t_2
915 sltu AT,c_3,t_2
916 daddu c_1,AT
917 dmultu a_0,b_4 /* mul_add_c(a[0],b[4],c2,c3,c1); */
918 mflo t_1
919 mfhi t_2
920 daddu c_2,t_1
921 sltu AT,c_2,t_1
922 daddu t_2,AT
923 daddu c_3,t_2
924 sltu AT,c_3,t_2
925 daddu c_1,AT
926 sd c_2,32(a0) /* r[4]=c2; */
927
928 dmultu a_0,b_5 /* mul_add_c(a[0],b[5],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_1,b_4 /* mul_add_c(a[1],b[4],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_2,b_3 /* mul_add_c(a[2],b[3],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_3,b_2 /* mul_add_c(a[3],b[2],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_4,b_1 /* mul_add_c(a[4],b[1],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 dmultu a_5,b_0 /* mul_add_c(a[5],b[0],c3,c1,c2); */
973 mflo t_1
974 mfhi t_2
975 daddu c_3,t_1
976 sltu AT,c_3,t_1
977 daddu t_2,AT
978 daddu c_1,t_2
979 sltu AT,c_1,t_2
980 daddu c_2,AT
981 sd c_3,40(a0) /* r[5]=c3; */
982
983 dmultu a_6,b_0 /* mul_add_c(a[6],b[0],c1,c2,c3); */
984 mflo t_1
985 mfhi t_2
986 daddu c_1,t_1
987 sltu AT,c_1,t_1
988 daddu t_2,AT
989 daddu c_2,t_2
990 sltu c_3,c_2,t_2
991 dmultu a_5,b_1 /* mul_add_c(a[5],b[1],c1,c2,c3); */
992 mflo t_1
993 mfhi t_2
994 daddu c_1,t_1
995 sltu AT,c_1,t_1
996 daddu t_2,AT
997 daddu c_2,t_2
998 sltu AT,c_2,t_2
999 daddu c_3,AT
1000 dmultu a_4,b_2 /* mul_add_c(a[4],b[2],c1,c2,c3); */
1001 mflo t_1
1002 mfhi t_2
1003 daddu c_1,t_1
1004 sltu AT,c_1,t_1
1005 daddu t_2,AT
1006 daddu c_2,t_2
1007 sltu AT,c_2,t_2
1008 daddu c_3,AT
1009 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1010 mflo t_1
1011 mfhi t_2
1012 daddu c_1,t_1
1013 sltu AT,c_1,t_1
1014 daddu t_2,AT
1015 daddu c_2,t_2
1016 sltu AT,c_2,t_2
1017 daddu c_3,AT
1018 dmultu a_2,b_4 /* mul_add_c(a[2],b[4],c1,c2,c3); */
1019 mflo t_1
1020 mfhi t_2
1021 daddu c_1,t_1
1022 sltu AT,c_1,t_1
1023 daddu t_2,AT
1024 daddu c_2,t_2
1025 sltu AT,c_2,t_2
1026 daddu c_3,AT
1027 dmultu a_1,b_5 /* mul_add_c(a[1],b[5],c1,c2,c3); */
1028 mflo t_1
1029 mfhi t_2
1030 daddu c_1,t_1
1031 sltu AT,c_1,t_1
1032 daddu t_2,AT
1033 daddu c_2,t_2
1034 sltu AT,c_2,t_2
1035 daddu c_3,AT
1036 dmultu a_0,b_6 /* mul_add_c(a[0],b[6],c1,c2,c3); */
1037 mflo t_1
1038 mfhi t_2
1039 daddu c_1,t_1
1040 sltu AT,c_1,t_1
1041 daddu t_2,AT
1042 daddu c_2,t_2
1043 sltu AT,c_2,t_2
1044 daddu c_3,AT
1045 sd c_1,48(a0) /* r[6]=c1; */
1046
1047 dmultu a_0,b_7 /* mul_add_c(a[0],b[7],c2,c3,c1); */
1048 mflo t_1
1049 mfhi t_2
1050 daddu c_2,t_1
1051 sltu AT,c_2,t_1
1052 daddu t_2,AT
1053 daddu c_3,t_2
1054 sltu c_1,c_3,t_2
1055 dmultu a_1,b_6 /* mul_add_c(a[1],b[6],c2,c3,c1); */
1056 mflo t_1
1057 mfhi t_2
1058 daddu c_2,t_1
1059 sltu AT,c_2,t_1
1060 daddu t_2,AT
1061 daddu c_3,t_2
1062 sltu AT,c_3,t_2
1063 daddu c_1,AT
1064 dmultu a_2,b_5 /* mul_add_c(a[2],b[5],c2,c3,c1); */
1065 mflo t_1
1066 mfhi t_2
1067 daddu c_2,t_1
1068 sltu AT,c_2,t_1
1069 daddu t_2,AT
1070 daddu c_3,t_2
1071 sltu AT,c_3,t_2
1072 daddu c_1,AT
1073 dmultu a_3,b_4 /* mul_add_c(a[3],b[4],c2,c3,c1); */
1074 mflo t_1
1075 mfhi t_2
1076 daddu c_2,t_1
1077 sltu AT,c_2,t_1
1078 daddu t_2,AT
1079 daddu c_3,t_2
1080 sltu AT,c_3,t_2
1081 daddu c_1,AT
1082 dmultu a_4,b_3 /* mul_add_c(a[4],b[3],c2,c3,c1); */
1083 mflo t_1
1084 mfhi t_2
1085 daddu c_2,t_1
1086 sltu AT,c_2,t_1
1087 daddu t_2,AT
1088 daddu c_3,t_2
1089 sltu AT,c_3,t_2
1090 daddu c_1,AT
1091 dmultu a_5,b_2 /* mul_add_c(a[5],b[2],c2,c3,c1); */
1092 mflo t_1
1093 mfhi t_2
1094 daddu c_2,t_1
1095 sltu AT,c_2,t_1
1096 daddu t_2,AT
1097 daddu c_3,t_2
1098 sltu AT,c_3,t_2
1099 daddu c_1,AT
1100 dmultu a_6,b_1 /* mul_add_c(a[6],b[1],c2,c3,c1); */
1101 mflo t_1
1102 mfhi t_2
1103 daddu c_2,t_1
1104 sltu AT,c_2,t_1
1105 daddu t_2,AT
1106 daddu c_3,t_2
1107 sltu AT,c_3,t_2
1108 daddu c_1,AT
1109 dmultu a_7,b_0 /* mul_add_c(a[7],b[0],c2,c3,c1); */
1110 mflo t_1
1111 mfhi t_2
1112 daddu c_2,t_1
1113 sltu AT,c_2,t_1
1114 daddu t_2,AT
1115 daddu c_3,t_2
1116 sltu AT,c_3,t_2
1117 daddu c_1,AT
1118 sd c_2,56(a0) /* r[7]=c2; */
1119
1120 dmultu a_7,b_1 /* mul_add_c(a[7],b[1],c3,c1,c2); */
1121 mflo t_1
1122 mfhi t_2
1123 daddu c_3,t_1
1124 sltu AT,c_3,t_1
1125 daddu t_2,AT
1126 daddu c_1,t_2
1127 sltu c_2,c_1,t_2
1128 dmultu a_6,b_2 /* mul_add_c(a[6],b[2],c3,c1,c2); */
1129 mflo t_1
1130 mfhi t_2
1131 daddu c_3,t_1
1132 sltu AT,c_3,t_1
1133 daddu t_2,AT
1134 daddu c_1,t_2
1135 sltu AT,c_1,t_2
1136 daddu c_2,AT
1137 dmultu a_5,b_3 /* mul_add_c(a[5],b[3],c3,c1,c2); */
1138 mflo t_1
1139 mfhi t_2
1140 daddu c_3,t_1
1141 sltu AT,c_3,t_1
1142 daddu t_2,AT
1143 daddu c_1,t_2
1144 sltu AT,c_1,t_2
1145 daddu c_2,AT
1146 dmultu a_4,b_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1147 mflo t_1
1148 mfhi t_2
1149 daddu c_3,t_1
1150 sltu AT,c_3,t_1
1151 daddu t_2,AT
1152 daddu c_1,t_2
1153 sltu AT,c_1,t_2
1154 daddu c_2,AT
1155 dmultu a_3,b_5 /* mul_add_c(a[3],b[5],c3,c1,c2); */
1156 mflo t_1
1157 mfhi t_2
1158 daddu c_3,t_1
1159 sltu AT,c_3,t_1
1160 daddu t_2,AT
1161 daddu c_1,t_2
1162 sltu AT,c_1,t_2
1163 daddu c_2,AT
1164 dmultu a_2,b_6 /* mul_add_c(a[2],b[6],c3,c1,c2); */
1165 mflo t_1
1166 mfhi t_2
1167 daddu c_3,t_1
1168 sltu AT,c_3,t_1
1169 daddu t_2,AT
1170 daddu c_1,t_2
1171 sltu AT,c_1,t_2
1172 daddu c_2,AT
1173 dmultu a_1,b_7 /* mul_add_c(a[1],b[7],c3,c1,c2); */
1174 mflo t_1
1175 mfhi t_2
1176 daddu c_3,t_1
1177 sltu AT,c_3,t_1
1178 daddu t_2,AT
1179 daddu c_1,t_2
1180 sltu AT,c_1,t_2
1181 daddu c_2,AT
1182 sd c_3,64(a0) /* r[8]=c3; */
1183
1184 dmultu a_2,b_7 /* mul_add_c(a[2],b[7],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 c_3,c_2,t_2
1192 dmultu a_3,b_6 /* mul_add_c(a[3],b[6],c1,c2,c3); */
1193 mflo t_1
1194 mfhi t_2
1195 daddu c_1,t_1
1196 sltu AT,c_1,t_1
1197 daddu t_2,AT
1198 daddu c_2,t_2
1199 sltu AT,c_2,t_2
1200 daddu c_3,AT
1201 dmultu a_4,b_5 /* mul_add_c(a[4],b[5],c1,c2,c3); */
1202 mflo t_1
1203 mfhi t_2
1204 daddu c_1,t_1
1205 sltu AT,c_1,t_1
1206 daddu t_2,AT
1207 daddu c_2,t_2
1208 sltu AT,c_2,t_2
1209 daddu c_3,AT
1210 dmultu a_5,b_4 /* mul_add_c(a[5],b[4],c1,c2,c3); */
1211 mflo t_1
1212 mfhi t_2
1213 daddu c_1,t_1
1214 sltu AT,c_1,t_1
1215 daddu t_2,AT
1216 daddu c_2,t_2
1217 sltu AT,c_2,t_2
1218 daddu c_3,AT
1219 dmultu a_6,b_3 /* mul_add_c(a[6],b[3],c1,c2,c3); */
1220 mflo t_1
1221 mfhi t_2
1222 daddu c_1,t_1
1223 sltu AT,c_1,t_1
1224 daddu t_2,AT
1225 daddu c_2,t_2
1226 sltu AT,c_2,t_2
1227 daddu c_3,AT
1228 dmultu a_7,b_2 /* mul_add_c(a[7],b[2],c1,c2,c3); */
1229 mflo t_1
1230 mfhi t_2
1231 daddu c_1,t_1
1232 sltu AT,c_1,t_1
1233 daddu t_2,AT
1234 daddu c_2,t_2
1235 sltu AT,c_2,t_2
1236 daddu c_3,AT
1237 sd c_1,72(a0) /* r[9]=c1; */
1238
1239 dmultu a_7,b_3 /* mul_add_c(a[7],b[3],c2,c3,c1); */
1240 mflo t_1
1241 mfhi t_2
1242 daddu c_2,t_1
1243 sltu AT,c_2,t_1
1244 daddu t_2,AT
1245 daddu c_3,t_2
1246 sltu c_1,c_3,t_2
1247 dmultu a_6,b_4 /* mul_add_c(a[6],b[4],c2,c3,c1); */
1248 mflo t_1
1249 mfhi t_2
1250 daddu c_2,t_1
1251 sltu AT,c_2,t_1
1252 daddu t_2,AT
1253 daddu c_3,t_2
1254 sltu AT,c_3,t_2
1255 daddu c_1,AT
1256 dmultu a_5,b_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1257 mflo t_1
1258 mfhi t_2
1259 daddu c_2,t_1
1260 sltu AT,c_2,t_1
1261 daddu t_2,AT
1262 daddu c_3,t_2
1263 sltu AT,c_3,t_2
1264 daddu c_1,AT
1265 dmultu a_4,b_6 /* mul_add_c(a[4],b[6],c2,c3,c1); */
1266 mflo t_1
1267 mfhi t_2
1268 daddu c_2,t_1
1269 sltu AT,c_2,t_1
1270 daddu t_2,AT
1271 daddu c_3,t_2
1272 sltu AT,c_3,t_2
1273 daddu c_1,AT
1274 dmultu a_3,b_7 /* mul_add_c(a[3],b[7],c2,c3,c1); */
1275 mflo t_1
1276 mfhi t_2
1277 daddu c_2,t_1
1278 sltu AT,c_2,t_1
1279 daddu t_2,AT
1280 daddu c_3,t_2
1281 sltu AT,c_3,t_2
1282 daddu c_1,AT
1283 sd c_2,80(a0) /* r[10]=c2; */
1284
1285 dmultu a_4,b_7 /* mul_add_c(a[4],b[7],c3,c1,c2); */
1286 mflo t_1
1287 mfhi t_2
1288 daddu c_3,t_1
1289 sltu AT,c_3,t_1
1290 daddu t_2,AT
1291 daddu c_1,t_2
1292 sltu c_2,c_1,t_2
1293 dmultu a_5,b_6 /* mul_add_c(a[5],b[6],c3,c1,c2); */
1294 mflo t_1
1295 mfhi t_2
1296 daddu c_3,t_1
1297 sltu AT,c_3,t_1
1298 daddu t_2,AT
1299 daddu c_1,t_2
1300 sltu AT,c_1,t_2
1301 daddu c_2,AT
1302 dmultu a_6,b_5 /* mul_add_c(a[6],b[5],c3,c1,c2); */
1303 mflo t_1
1304 mfhi t_2
1305 daddu c_3,t_1
1306 sltu AT,c_3,t_1
1307 daddu t_2,AT
1308 daddu c_1,t_2
1309 sltu AT,c_1,t_2
1310 daddu c_2,AT
1311 dmultu a_7,b_4 /* mul_add_c(a[7],b[4],c3,c1,c2); */
1312 mflo t_1
1313 mfhi t_2
1314 daddu c_3,t_1
1315 sltu AT,c_3,t_1
1316 daddu t_2,AT
1317 daddu c_1,t_2
1318 sltu AT,c_1,t_2
1319 daddu c_2,AT
1320 sd c_3,88(a0) /* r[11]=c3; */
1321
1322 dmultu a_7,b_5 /* mul_add_c(a[7],b[5],c1,c2,c3); */
1323 mflo t_1
1324 mfhi t_2
1325 daddu c_1,t_1
1326 sltu AT,c_1,t_1
1327 daddu t_2,AT
1328 daddu c_2,t_2
1329 sltu c_3,c_2,t_2
1330 dmultu a_6,b_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
1331 mflo t_1
1332 mfhi t_2
1333 daddu c_1,t_1
1334 sltu AT,c_1,t_1
1335 daddu t_2,AT
1336 daddu c_2,t_2
1337 sltu AT,c_2,t_2
1338 daddu c_3,AT
1339 dmultu a_5,b_7 /* mul_add_c(a[5],b[7],c1,c2,c3); */
1340 mflo t_1
1341 mfhi t_2
1342 daddu c_1,t_1
1343 sltu AT,c_1,t_1
1344 daddu t_2,AT
1345 daddu c_2,t_2
1346 sltu AT,c_2,t_2
1347 daddu c_3,AT
1348 sd c_1,96(a0) /* r[12]=c1; */
1349
1350 dmultu a_6,b_7 /* mul_add_c(a[6],b[7],c2,c3,c1); */
1351 mflo t_1
1352 mfhi t_2
1353 daddu c_2,t_1
1354 sltu AT,c_2,t_1
1355 daddu t_2,AT
1356 daddu c_3,t_2
1357 sltu c_1,c_3,t_2
1358 dmultu a_7,b_6 /* mul_add_c(a[7],b[6],c2,c3,c1); */
1359 mflo t_1
1360 mfhi t_2
1361 daddu c_2,t_1
1362 sltu AT,c_2,t_1
1363 daddu t_2,AT
1364 daddu c_3,t_2
1365 sltu AT,c_3,t_2
1366 daddu c_1,AT
1367 sd c_2,104(a0) /* r[13]=c2; */
1368
1369 dmultu a_7,b_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
1370 ld s0,0(sp)
1371 ld s1,8(sp)
1372 ld s2,16(sp)
1373 ld s3,24(sp)
1374 ld s4,32(sp)
1375 ld s5,40(sp)
1376 mflo t_1
1377 mfhi t_2
1378 daddu c_3,t_1
1379 sltu AT,c_3,t_1
1380 daddu t_2,AT
1381 daddu c_1,t_2
1382 sd c_3,112(a0) /* r[14]=c3; */
1383 sd c_1,120(a0) /* r[15]=c1; */
1384
1385 PTR_ADD sp,FRAME_SIZE
1386
1387 jr ra
1388END(bn_mul_comba8)
1389
1390.align 5
1391LEAF(bn_mul_comba4)
1392 .set reorder
1393 ld a_0,0(a1)
1394 ld b_0,0(a2)
1395 ld a_1,8(a1)
1396 ld a_2,16(a1)
1397 dmultu a_0,b_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1398 ld a_3,24(a1)
1399 ld b_1,8(a2)
1400 ld b_2,16(a2)
1401 ld b_3,24(a2)
1402 mflo c_1
1403 mfhi c_2
1404 sd c_1,0(a0)
1405
1406 dmultu a_0,b_1 /* mul_add_c(a[0],b[1],c2,c3,c1); */
1407 mflo t_1
1408 mfhi t_2
1409 daddu c_2,t_1
1410 sltu AT,c_2,t_1
1411 daddu c_3,t_2,AT
1412 dmultu a_1,b_0 /* mul_add_c(a[1],b[0],c2,c3,c1); */
1413 mflo t_1
1414 mfhi t_2
1415 daddu c_2,t_1
1416 sltu AT,c_2,t_1
1417 daddu t_2,AT
1418 daddu c_3,t_2
1419 sltu c_1,c_3,t_2
1420 sd c_2,8(a0)
1421
1422 dmultu a_2,b_0 /* mul_add_c(a[2],b[0],c3,c1,c2); */
1423 mflo t_1
1424 mfhi t_2
1425 daddu c_3,t_1
1426 sltu AT,c_3,t_1
1427 daddu t_2,AT
1428 daddu c_1,t_2
1429 dmultu a_1,b_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1430 mflo t_1
1431 mfhi t_2
1432 daddu c_3,t_1
1433 sltu AT,c_3,t_1
1434 daddu t_2,AT
1435 daddu c_1,t_2
1436 sltu c_2,c_1,t_2
1437 dmultu a_0,b_2 /* mul_add_c(a[0],b[2],c3,c1,c2); */
1438 mflo t_1
1439 mfhi t_2
1440 daddu c_3,t_1
1441 sltu AT,c_3,t_1
1442 daddu t_2,AT
1443 daddu c_1,t_2
1444 sltu AT,c_1,t_2
1445 daddu c_2,AT
1446 sd c_3,16(a0)
1447
1448 dmultu a_0,b_3 /* mul_add_c(a[0],b[3],c1,c2,c3); */
1449 mflo t_1
1450 mfhi t_2
1451 daddu c_1,t_1
1452 sltu AT,c_1,t_1
1453 daddu t_2,AT
1454 daddu c_2,t_2
1455 sltu c_3,c_2,t_2
1456 dmultu a_1,b_2 /* mul_add_c(a[1],b[2],c1,c2,c3); */
1457 mflo t_1
1458 mfhi t_2
1459 daddu c_1,t_1
1460 sltu AT,c_1,t_1
1461 daddu t_2,AT
1462 daddu c_2,t_2
1463 sltu AT,c_2,t_2
1464 daddu c_3,AT
1465 dmultu a_2,b_1 /* mul_add_c(a[2],b[1],c1,c2,c3); */
1466 mflo t_1
1467 mfhi t_2
1468 daddu c_1,t_1
1469 sltu AT,c_1,t_1
1470 daddu t_2,AT
1471 daddu c_2,t_2
1472 sltu AT,c_2,t_2
1473 daddu c_3,AT
1474 dmultu a_3,b_0 /* mul_add_c(a[3],b[0],c1,c2,c3); */
1475 mflo t_1
1476 mfhi t_2
1477 daddu c_1,t_1
1478 sltu AT,c_1,t_1
1479 daddu t_2,AT
1480 daddu c_2,t_2
1481 sltu AT,c_2,t_2
1482 daddu c_3,AT
1483 sd c_1,24(a0)
1484
1485 dmultu a_3,b_1 /* mul_add_c(a[3],b[1],c2,c3,c1); */
1486 mflo t_1
1487 mfhi t_2
1488 daddu c_2,t_1
1489 sltu AT,c_2,t_1
1490 daddu t_2,AT
1491 daddu c_3,t_2
1492 sltu c_1,c_3,t_2
1493 dmultu a_2,b_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1494 mflo t_1
1495 mfhi t_2
1496 daddu c_2,t_1
1497 sltu AT,c_2,t_1
1498 daddu t_2,AT
1499 daddu c_3,t_2
1500 sltu AT,c_3,t_2
1501 daddu c_1,AT
1502 dmultu a_1,b_3 /* mul_add_c(a[1],b[3],c2,c3,c1); */
1503 mflo t_1
1504 mfhi t_2
1505 daddu c_2,t_1
1506 sltu AT,c_2,t_1
1507 daddu t_2,AT
1508 daddu c_3,t_2
1509 sltu AT,c_3,t_2
1510 daddu c_1,AT
1511 sd c_2,32(a0)
1512
1513 dmultu a_2,b_3 /* mul_add_c(a[2],b[3],c3,c1,c2); */
1514 mflo t_1
1515 mfhi t_2
1516 daddu c_3,t_1
1517 sltu AT,c_3,t_1
1518 daddu t_2,AT
1519 daddu c_1,t_2
1520 sltu c_2,c_1,t_2
1521 dmultu a_3,b_2 /* mul_add_c(a[3],b[2],c3,c1,c2); */
1522 mflo t_1
1523 mfhi t_2
1524 daddu c_3,t_1
1525 sltu AT,c_3,t_1
1526 daddu t_2,AT
1527 daddu c_1,t_2
1528 sltu AT,c_1,t_2
1529 daddu c_2,AT
1530 sd c_3,40(a0)
1531
1532 dmultu a_3,b_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1533 mflo t_1
1534 mfhi t_2
1535 daddu c_1,t_1
1536 sltu AT,c_1,t_1
1537 daddu t_2,AT
1538 daddu c_2,t_2
1539 sd c_1,48(a0)
1540 sd c_2,56(a0)
1541
1542 jr ra
1543END(bn_mul_comba4)
1544
1545#undef a_4
1546#undef a_5
1547#undef a_6
1548#undef a_7
1549#define a_4 b_0
1550#define a_5 b_1
1551#define a_6 b_2
1552#define a_7 b_3
1553
1554.align 5
1555LEAF(bn_sqr_comba8)
1556 .set reorder
1557 ld a_0,0(a1)
1558 ld a_1,8(a1)
1559 ld a_2,16(a1)
1560 ld a_3,24(a1)
1561
1562 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
1563 ld a_4,32(a1)
1564 ld a_5,40(a1)
1565 ld a_6,48(a1)
1566 ld a_7,56(a1)
1567 mflo c_1
1568 mfhi c_2
1569 sd c_1,0(a0)
1570
1571 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
1572 mflo t_1
1573 mfhi t_2
1574 slt c_1,t_2,zero
1575 dsll t_2,1
1576 slt a2,t_1,zero
1577 daddu t_2,a2
1578 dsll t_1,1
1579 daddu c_2,t_1
1580 sltu AT,c_2,t_1
1581 daddu c_3,t_2,AT
1582 sd c_2,8(a0)
1583
1584 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
1585 mflo t_1
1586 mfhi t_2
1587 slt c_2,t_2,zero
1588 dsll t_2,1
1589 slt a2,t_1,zero
1590 daddu t_2,a2
1591 dsll t_1,1
1592 daddu c_3,t_1
1593 sltu AT,c_3,t_1
1594 daddu t_2,AT
1595 daddu c_1,t_2
1596 sltu AT,c_1,t_2
1597 daddu c_2,AT
1598 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
1599 mflo t_1
1600 mfhi t_2
1601 daddu c_3,t_1
1602 sltu AT,c_3,t_1
1603 daddu t_2,AT
1604 daddu c_1,t_2
1605 sltu AT,c_1,t_2
1606 daddu c_2,AT
1607 sd c_3,16(a0)
1608
1609 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
1610 mflo t_1
1611 mfhi t_2
1612 slt c_3,t_2,zero
1613 dsll t_2,1
1614 slt a2,t_1,zero
1615 daddu t_2,a2
1616 dsll t_1,1
1617 daddu c_1,t_1
1618 sltu AT,c_1,t_1
1619 daddu t_2,AT
1620 daddu c_2,t_2
1621 sltu AT,c_2,t_2
1622 daddu c_3,AT
1623 dmultu a_1,a_2 /* mul_add_c2(a[1],b[2],c1,c2,c3); */
1624 mflo t_1
1625 mfhi t_2
1626 slt AT,t_2,zero
1627 daddu c_3,AT
1628 dsll t_2,1
1629 slt a2,t_1,zero
1630 daddu t_2,a2
1631 dsll t_1,1
1632 daddu c_1,t_1
1633 sltu AT,c_1,t_1
1634 daddu t_2,AT
1635 daddu c_2,t_2
1636 sltu AT,c_2,t_2
1637 daddu c_3,AT
1638 sd c_1,24(a0)
1639
1640 dmultu a_4,a_0 /* mul_add_c2(a[4],b[0],c2,c3,c1); */
1641 mflo t_1
1642 mfhi t_2
1643 slt c_1,t_2,zero
1644 dsll t_2,1
1645 slt a2,t_1,zero
1646 daddu t_2,a2
1647 dsll t_1,1
1648 daddu c_2,t_1
1649 sltu AT,c_2,t_1
1650 daddu t_2,AT
1651 daddu c_3,t_2
1652 sltu AT,c_3,t_2
1653 daddu c_1,AT
1654 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
1655 mflo t_1
1656 mfhi t_2
1657 slt AT,t_2,zero
1658 daddu c_1,AT
1659 dsll t_2,1
1660 slt a2,t_1,zero
1661 daddu t_2,a2
1662 dsll t_1,1
1663 daddu c_2,t_1
1664 sltu AT,c_2,t_1
1665 daddu t_2,AT
1666 daddu c_3,t_2
1667 sltu AT,c_3,t_2
1668 daddu c_1,AT
1669 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
1670 mflo t_1
1671 mfhi t_2
1672 daddu c_2,t_1
1673 sltu AT,c_2,t_1
1674 daddu t_2,AT
1675 daddu c_3,t_2
1676 sltu AT,c_3,t_2
1677 daddu c_1,AT
1678 sd c_2,32(a0)
1679
1680 dmultu a_0,a_5 /* mul_add_c2(a[0],b[5],c3,c1,c2); */
1681 mflo t_1
1682 mfhi t_2
1683 slt c_2,t_2,zero
1684 dsll t_2,1
1685 slt a2,t_1,zero
1686 daddu t_2,a2
1687 dsll t_1,1
1688 daddu c_3,t_1
1689 sltu AT,c_3,t_1
1690 daddu t_2,AT
1691 daddu c_1,t_2
1692 sltu AT,c_1,t_2
1693 daddu c_2,AT
1694 dmultu a_1,a_4 /* mul_add_c2(a[1],b[4],c3,c1,c2); */
1695 mflo t_1
1696 mfhi t_2
1697 slt AT,t_2,zero
1698 daddu c_2,AT
1699 dsll t_2,1
1700 slt a2,t_1,zero
1701 daddu t_2,a2
1702 dsll t_1,1
1703 daddu c_3,t_1
1704 sltu AT,c_3,t_1
1705 daddu t_2,AT
1706 daddu c_1,t_2
1707 sltu AT,c_1,t_2
1708 daddu c_2,AT
1709 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
1710 mflo t_1
1711 mfhi t_2
1712 slt AT,t_2,zero
1713 daddu c_2,AT
1714 dsll t_2,1
1715 slt a2,t_1,zero
1716 daddu t_2,a2
1717 dsll t_1,1
1718 daddu c_3,t_1
1719 sltu AT,c_3,t_1
1720 daddu t_2,AT
1721 daddu c_1,t_2
1722 sltu AT,c_1,t_2
1723 daddu c_2,AT
1724 sd c_3,40(a0)
1725
1726 dmultu a_6,a_0 /* mul_add_c2(a[6],b[0],c1,c2,c3); */
1727 mflo t_1
1728 mfhi t_2
1729 slt c_3,t_2,zero
1730 dsll t_2,1
1731 slt a2,t_1,zero
1732 daddu t_2,a2
1733 dsll t_1,1
1734 daddu c_1,t_1
1735 sltu AT,c_1,t_1
1736 daddu t_2,AT
1737 daddu c_2,t_2
1738 sltu AT,c_2,t_2
1739 daddu c_3,AT
1740 dmultu a_5,a_1 /* mul_add_c2(a[5],b[1],c1,c2,c3); */
1741 mflo t_1
1742 mfhi t_2
1743 slt AT,t_2,zero
1744 daddu c_3,AT
1745 dsll t_2,1
1746 slt a2,t_1,zero
1747 daddu t_2,a2
1748 dsll t_1,1
1749 daddu c_1,t_1
1750 sltu AT,c_1,t_1
1751 daddu t_2,AT
1752 daddu c_2,t_2
1753 sltu AT,c_2,t_2
1754 daddu c_3,AT
1755 dmultu a_4,a_2 /* mul_add_c2(a[4],b[2],c1,c2,c3); */
1756 mflo t_1
1757 mfhi t_2
1758 slt AT,t_2,zero
1759 daddu c_3,AT
1760 dsll t_2,1
1761 slt a2,t_1,zero
1762 daddu t_2,a2
1763 dsll t_1,1
1764 daddu c_1,t_1
1765 sltu AT,c_1,t_1
1766 daddu t_2,AT
1767 daddu c_2,t_2
1768 sltu AT,c_2,t_2
1769 daddu c_3,AT
1770 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
1771 mflo t_1
1772 mfhi t_2
1773 daddu c_1,t_1
1774 sltu AT,c_1,t_1
1775 daddu t_2,AT
1776 daddu c_2,t_2
1777 sltu AT,c_2,t_2
1778 daddu c_3,AT
1779 sd c_1,48(a0)
1780
1781 dmultu a_0,a_7 /* mul_add_c2(a[0],b[7],c2,c3,c1); */
1782 mflo t_1
1783 mfhi t_2
1784 slt c_1,t_2,zero
1785 dsll t_2,1
1786 slt a2,t_1,zero
1787 daddu t_2,a2
1788 dsll t_1,1
1789 daddu c_2,t_1
1790 sltu AT,c_2,t_1
1791 daddu t_2,AT
1792 daddu c_3,t_2
1793 sltu AT,c_3,t_2
1794 daddu c_1,AT
1795 dmultu a_1,a_6 /* mul_add_c2(a[1],b[6],c2,c3,c1); */
1796 mflo t_1
1797 mfhi t_2
1798 slt AT,t_2,zero
1799 daddu c_1,AT
1800 dsll t_2,1
1801 slt a2,t_1,zero
1802 daddu t_2,a2
1803 dsll t_1,1
1804 daddu c_2,t_1
1805 sltu AT,c_2,t_1
1806 daddu t_2,AT
1807 daddu c_3,t_2
1808 sltu AT,c_3,t_2
1809 daddu c_1,AT
1810 dmultu a_2,a_5 /* mul_add_c2(a[2],b[5],c2,c3,c1); */
1811 mflo t_1
1812 mfhi t_2
1813 slt AT,t_2,zero
1814 daddu c_1,AT
1815 dsll t_2,1
1816 slt a2,t_1,zero
1817 daddu t_2,a2
1818 dsll t_1,1
1819 daddu c_2,t_1
1820 sltu AT,c_2,t_1
1821 daddu t_2,AT
1822 daddu c_3,t_2
1823 sltu AT,c_3,t_2
1824 daddu c_1,AT
1825 dmultu a_3,a_4 /* mul_add_c2(a[3],b[4],c2,c3,c1); */
1826 mflo t_1
1827 mfhi t_2
1828 slt AT,t_2,zero
1829 daddu c_1,AT
1830 dsll t_2,1
1831 slt a2,t_1,zero
1832 daddu t_2,a2
1833 dsll t_1,1
1834 daddu c_2,t_1
1835 sltu AT,c_2,t_1
1836 daddu t_2,AT
1837 daddu c_3,t_2
1838 sltu AT,c_3,t_2
1839 daddu c_1,AT
1840 sd c_2,56(a0)
1841
1842 dmultu a_7,a_1 /* mul_add_c2(a[7],b[1],c3,c1,c2); */
1843 mflo t_1
1844 mfhi t_2
1845 slt c_2,t_2,zero
1846 dsll t_2,1
1847 slt a2,t_1,zero
1848 daddu t_2,a2
1849 dsll t_1,1
1850 daddu c_3,t_1
1851 sltu AT,c_3,t_1
1852 daddu t_2,AT
1853 daddu c_1,t_2
1854 sltu AT,c_1,t_2
1855 daddu c_2,AT
1856 dmultu a_6,a_2 /* mul_add_c2(a[6],b[2],c3,c1,c2); */
1857 mflo t_1
1858 mfhi t_2
1859 slt AT,t_2,zero
1860 daddu c_2,AT
1861 dsll t_2,1
1862 slt a2,t_1,zero
1863 daddu t_2,a2
1864 dsll t_1,1
1865 daddu c_3,t_1
1866 sltu AT,c_3,t_1
1867 daddu t_2,AT
1868 daddu c_1,t_2
1869 sltu AT,c_1,t_2
1870 daddu c_2,AT
1871 dmultu a_5,a_3 /* mul_add_c2(a[5],b[3],c3,c1,c2); */
1872 mflo t_1
1873 mfhi t_2
1874 slt AT,t_2,zero
1875 daddu c_2,AT
1876 dsll t_2,1
1877 slt a2,t_1,zero
1878 daddu t_2,a2
1879 dsll t_1,1
1880 daddu c_3,t_1
1881 sltu AT,c_3,t_1
1882 daddu t_2,AT
1883 daddu c_1,t_2
1884 sltu AT,c_1,t_2
1885 daddu c_2,AT
1886 dmultu a_4,a_4 /* mul_add_c(a[4],b[4],c3,c1,c2); */
1887 mflo t_1
1888 mfhi t_2
1889 daddu c_3,t_1
1890 sltu AT,c_3,t_1
1891 daddu t_2,AT
1892 daddu c_1,t_2
1893 sltu AT,c_1,t_2
1894 daddu c_2,AT
1895 sd c_3,64(a0)
1896
1897 dmultu a_2,a_7 /* mul_add_c2(a[2],b[7],c1,c2,c3); */
1898 mflo t_1
1899 mfhi t_2
1900 slt c_3,t_2,zero
1901 dsll t_2,1
1902 slt a2,t_1,zero
1903 daddu t_2,a2
1904 dsll t_1,1
1905 daddu c_1,t_1
1906 sltu AT,c_1,t_1
1907 daddu t_2,AT
1908 daddu c_2,t_2
1909 sltu AT,c_2,t_2
1910 daddu c_3,AT
1911 dmultu a_3,a_6 /* mul_add_c2(a[3],b[6],c1,c2,c3); */
1912 mflo t_1
1913 mfhi t_2
1914 slt AT,t_2,zero
1915 daddu c_3,AT
1916 dsll t_2,1
1917 slt a2,t_1,zero
1918 daddu t_2,a2
1919 dsll t_1,1
1920 daddu c_1,t_1
1921 sltu AT,c_1,t_1
1922 daddu t_2,AT
1923 daddu c_2,t_2
1924 sltu AT,c_2,t_2
1925 daddu c_3,AT
1926 dmultu a_4,a_5 /* mul_add_c2(a[4],b[5],c1,c2,c3); */
1927 mflo t_1
1928 mfhi t_2
1929 slt AT,t_2,zero
1930 daddu c_3,AT
1931 dsll t_2,1
1932 slt a2,t_1,zero
1933 daddu t_2,a2
1934 dsll t_1,1
1935 daddu c_1,t_1
1936 sltu AT,c_1,t_1
1937 daddu t_2,AT
1938 daddu c_2,t_2
1939 sltu AT,c_2,t_2
1940 daddu c_3,AT
1941 sd c_1,72(a0)
1942
1943 dmultu a_7,a_3 /* mul_add_c2(a[7],b[3],c2,c3,c1); */
1944 mflo t_1
1945 mfhi t_2
1946 slt c_1,t_2,zero
1947 dsll t_2,1
1948 slt a2,t_1,zero
1949 daddu t_2,a2
1950 dsll t_1,1
1951 daddu c_2,t_1
1952 sltu AT,c_2,t_1
1953 daddu t_2,AT
1954 daddu c_3,t_2
1955 sltu AT,c_3,t_2
1956 daddu c_1,AT
1957 dmultu a_6,a_4 /* mul_add_c2(a[6],b[4],c2,c3,c1); */
1958 mflo t_1
1959 mfhi t_2
1960 slt AT,t_2,zero
1961 daddu c_1,AT
1962 dsll t_2,1
1963 slt a2,t_1,zero
1964 daddu t_2,a2
1965 dsll t_1,1
1966 daddu c_2,t_1
1967 sltu AT,c_2,t_1
1968 daddu t_2,AT
1969 daddu c_3,t_2
1970 sltu AT,c_3,t_2
1971 daddu c_1,AT
1972 dmultu a_5,a_5 /* mul_add_c(a[5],b[5],c2,c3,c1); */
1973 mflo t_1
1974 mfhi t_2
1975 daddu c_2,t_1
1976 sltu AT,c_2,t_1
1977 daddu t_2,AT
1978 daddu c_3,t_2
1979 sltu AT,c_3,t_2
1980 daddu c_1,AT
1981 sd c_2,80(a0)
1982
1983 dmultu a_4,a_7 /* mul_add_c2(a[4],b[7],c3,c1,c2); */
1984 mflo t_1
1985 mfhi t_2
1986 slt c_2,t_2,zero
1987 dsll t_2,1
1988 slt a2,t_1,zero
1989 daddu t_2,a2
1990 dsll t_1,1
1991 daddu c_3,t_1
1992 sltu AT,c_3,t_1
1993 daddu t_2,AT
1994 daddu c_1,t_2
1995 sltu AT,c_1,t_2
1996 daddu c_2,AT
1997 dmultu a_5,a_6 /* mul_add_c2(a[5],b[6],c3,c1,c2); */
1998 mflo t_1
1999 mfhi t_2
2000 slt AT,t_2,zero
2001 daddu c_2,AT
2002 dsll t_2,1
2003 slt a2,t_1,zero
2004 daddu t_2,a2
2005 dsll t_1,1
2006 daddu c_3,t_1
2007 sltu AT,c_3,t_1
2008 daddu t_2,AT
2009 daddu c_1,t_2
2010 sltu AT,c_1,t_2
2011 daddu c_2,AT
2012 sd c_3,88(a0)
2013
2014 dmultu a_7,a_5 /* mul_add_c2(a[7],b[5],c1,c2,c3); */
2015 mflo t_1
2016 mfhi t_2
2017 slt c_3,t_2,zero
2018 dsll t_2,1
2019 slt a2,t_1,zero
2020 daddu t_2,a2
2021 dsll t_1,1
2022 daddu c_1,t_1
2023 sltu AT,c_1,t_1
2024 daddu t_2,AT
2025 daddu c_2,t_2
2026 sltu AT,c_2,t_2
2027 daddu c_3,AT
2028 dmultu a_6,a_6 /* mul_add_c(a[6],b[6],c1,c2,c3); */
2029 mflo t_1
2030 mfhi t_2
2031 daddu c_1,t_1
2032 sltu AT,c_1,t_1
2033 daddu t_2,AT
2034 daddu c_2,t_2
2035 sltu AT,c_2,t_2
2036 daddu c_3,AT
2037 sd c_1,96(a0)
2038
2039 dmultu a_6,a_7 /* mul_add_c2(a[6],b[7],c2,c3,c1); */
2040 mflo t_1
2041 mfhi t_2
2042 slt c_1,t_2,zero
2043 dsll t_2,1
2044 slt a2,t_1,zero
2045 daddu t_2,a2
2046 dsll t_1,1
2047 daddu c_2,t_1
2048 sltu AT,c_2,t_1
2049 daddu t_2,AT
2050 daddu c_3,t_2
2051 sltu AT,c_3,t_2
2052 daddu c_1,AT
2053 sd c_2,104(a0)
2054
2055 dmultu a_7,a_7 /* mul_add_c(a[7],b[7],c3,c1,c2); */
2056 mflo t_1
2057 mfhi t_2
2058 daddu c_3,t_1
2059 sltu AT,c_3,t_1
2060 daddu t_2,AT
2061 daddu c_1,t_2
2062 sd c_3,112(a0)
2063 sd c_1,120(a0)
2064
2065 jr ra
2066END(bn_sqr_comba8)
2067
2068.align 5
2069LEAF(bn_sqr_comba4)
2070 .set reorder
2071 ld a_0,0(a1)
2072 ld a_1,8(a1)
2073 ld a_2,16(a1)
2074 ld a_3,24(a1)
2075 dmultu a_0,a_0 /* mul_add_c(a[0],b[0],c1,c2,c3); */
2076 mflo c_1
2077 mfhi c_2
2078 sd c_1,0(a0)
2079
2080 dmultu a_0,a_1 /* mul_add_c2(a[0],b[1],c2,c3,c1); */
2081 mflo t_1
2082 mfhi t_2
2083 slt c_1,t_2,zero
2084 dsll t_2,1
2085 slt a2,t_1,zero
2086 daddu t_2,a2
2087 dsll t_1,1
2088 daddu c_2,t_1
2089 sltu AT,c_2,t_1
2090 daddu c_3,t_2,AT
2091 sd c_2,8(a0)
2092
2093 dmultu a_2,a_0 /* mul_add_c2(a[2],b[0],c3,c1,c2); */
2094 mflo t_1
2095 mfhi t_2
2096 slt c_2,t_2,zero
2097 dsll t_2,1
2098 slt a2,t_1,zero
2099 daddu t_2,a2
2100 dsll t_1,1
2101 daddu c_3,t_1
2102 sltu AT,c_3,t_1
2103 daddu t_2,AT
2104 daddu c_1,t_2
2105 sltu AT,c_1,t_2
2106 daddu c_2,AT
2107 dmultu a_1,a_1 /* mul_add_c(a[1],b[1],c3,c1,c2); */
2108 mflo t_1
2109 mfhi t_2
2110 daddu c_3,t_1
2111 sltu AT,c_3,t_1
2112 daddu t_2,AT
2113 daddu c_1,t_2
2114 sltu AT,c_1,t_2
2115 daddu c_2,AT
2116 sd c_3,16(a0)
2117
2118 dmultu a_0,a_3 /* mul_add_c2(a[0],b[3],c1,c2,c3); */
2119 mflo t_1
2120 mfhi t_2
2121 slt c_3,t_2,zero
2122 dsll t_2,1
2123 slt a2,t_1,zero
2124 daddu t_2,a2
2125 dsll t_1,1
2126 daddu c_1,t_1
2127 sltu AT,c_1,t_1
2128 daddu t_2,AT
2129 daddu c_2,t_2
2130 sltu AT,c_2,t_2
2131 daddu c_3,AT
2132 dmultu a_1,a_2 /* mul_add_c(a2[1],b[2],c1,c2,c3); */
2133 mflo t_1
2134 mfhi t_2
2135 slt AT,t_2,zero
2136 daddu c_3,AT
2137 dsll t_2,1
2138 slt a2,t_1,zero
2139 daddu t_2,a2
2140 dsll t_1,1
2141 daddu c_1,t_1
2142 sltu AT,c_1,t_1
2143 daddu t_2,AT
2144 daddu c_2,t_2
2145 sltu AT,c_2,t_2
2146 daddu c_3,AT
2147 sd c_1,24(a0)
2148
2149 dmultu a_3,a_1 /* mul_add_c2(a[3],b[1],c2,c3,c1); */
2150 mflo t_1
2151 mfhi t_2
2152 slt c_1,t_2,zero
2153 dsll t_2,1
2154 slt a2,t_1,zero
2155 daddu t_2,a2
2156 dsll t_1,1
2157 daddu c_2,t_1
2158 sltu AT,c_2,t_1
2159 daddu t_2,AT
2160 daddu c_3,t_2
2161 sltu AT,c_3,t_2
2162 daddu c_1,AT
2163 dmultu a_2,a_2 /* mul_add_c(a[2],b[2],c2,c3,c1); */
2164 mflo t_1
2165 mfhi t_2
2166 daddu c_2,t_1
2167 sltu AT,c_2,t_1
2168 daddu t_2,AT
2169 daddu c_3,t_2
2170 sltu AT,c_3,t_2
2171 daddu c_1,AT
2172 sd c_2,32(a0)
2173
2174 dmultu a_2,a_3 /* mul_add_c2(a[2],b[3],c3,c1,c2); */
2175 mflo t_1
2176 mfhi t_2
2177 slt c_2,t_2,zero
2178 dsll t_2,1
2179 slt a2,t_1,zero
2180 daddu t_2,a2
2181 dsll t_1,1
2182 daddu c_3,t_1
2183 sltu AT,c_3,t_1
2184 daddu t_2,AT
2185 daddu c_1,t_2
2186 sltu AT,c_1,t_2
2187 daddu c_2,AT
2188 sd c_3,40(a0)
2189
2190 dmultu a_3,a_3 /* mul_add_c(a[3],b[3],c1,c2,c3); */
2191 mflo t_1
2192 mfhi t_2
2193 daddu c_1,t_1
2194 sltu AT,c_1,t_1
2195 daddu t_2,AT
2196 daddu c_2,t_2
2197 sd c_1,48(a0)
2198 sd c_2,56(a0)
2199
2200 jr ra
2201END(bn_sqr_comba4)
diff --git a/src/lib/libcrypto/bn/asm/mo-586.pl b/src/lib/libcrypto/bn/asm/mo-586.pl
new file mode 100644
index 0000000000..0982293094
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/mo-586.pl
@@ -0,0 +1,603 @@
1#!/usr/bin/env perl
2
3# This is crypto/bn/asm/x86-mont.pl (with asciz from crypto/perlasm/x86asm.pl)
4# from OpenSSL 0.9.9-dev
5
6sub ::asciz
7{ my @str=unpack("C*",shift);
8 push @str,0;
9 while ($#str>15) {
10 &data_byte(@str[0..15]);
11 foreach (0..15) { shift @str; }
12 }
13 &data_byte(@str) if (@str);
14}
15
16# ====================================================================
17# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
18# project. The module is, however, dual licensed under OpenSSL and
19# CRYPTOGAMS licenses depending on where you obtain it. For further
20# details see http://www.openssl.org/~appro/cryptogams/.
21# ====================================================================
22
23# October 2005
24#
25# This is a "teaser" code, as it can be improved in several ways...
26# First of all non-SSE2 path should be implemented (yes, for now it
27# performs Montgomery multiplication/convolution only on SSE2-capable
28# CPUs such as P4, others fall down to original code). Then inner loop
29# can be unrolled and modulo-scheduled to improve ILP and possibly
30# moved to 128-bit XMM register bank (though it would require input
31# rearrangement and/or increase bus bandwidth utilization). Dedicated
32# squaring procedure should give further performance improvement...
33# Yet, for being draft, the code improves rsa512 *sign* benchmark by
34# 110%(!), rsa1024 one - by 70% and rsa4096 - by 20%:-)
35
36# December 2006
37#
38# Modulo-scheduling SSE2 loops results in further 15-20% improvement.
39# Integer-only code [being equipped with dedicated squaring procedure]
40# gives ~40% on rsa512 sign benchmark...
41
42push(@INC,"perlasm","../../perlasm");
43require "x86asm.pl";
44
45&asm_init($ARGV[0],$0);
46
47$sse2=0;
48for (@ARGV) { $sse2=1 if (/-DOPENSSL_IA32_SSE2/); }
49
50&external_label("OPENSSL_ia32cap_P") if ($sse2);
51
52&function_begin("bn_mul_mont");
53
54$i="edx";
55$j="ecx";
56$ap="esi"; $tp="esi"; # overlapping variables!!!
57$rp="edi"; $bp="edi"; # overlapping variables!!!
58$np="ebp";
59$num="ebx";
60
61$_num=&DWP(4*0,"esp"); # stack top layout
62$_rp=&DWP(4*1,"esp");
63$_ap=&DWP(4*2,"esp");
64$_bp=&DWP(4*3,"esp");
65$_np=&DWP(4*4,"esp");
66$_n0=&DWP(4*5,"esp"); $_n0q=&QWP(4*5,"esp");
67$_sp=&DWP(4*6,"esp");
68$_bpend=&DWP(4*7,"esp");
69$frame=32; # size of above frame rounded up to 16n
70
71 &xor ("eax","eax");
72 &mov ("edi",&wparam(5)); # int num
73 &cmp ("edi",4);
74 &jl (&label("just_leave"));
75
76 &lea ("esi",&wparam(0)); # put aside pointer to argument block
77 &lea ("edx",&wparam(1)); # load ap
78 &mov ("ebp","esp"); # saved stack pointer!
79 &add ("edi",2); # extra two words on top of tp
80 &neg ("edi");
81 &lea ("esp",&DWP(-$frame,"esp","edi",4)); # alloca($frame+4*(num+2))
82 &neg ("edi");
83
84 # minimize cache contention by arraning 2K window between stack
85 # pointer and ap argument [np is also position sensitive vector,
86 # but it's assumed to be near ap, as it's allocated at ~same
87 # time].
88 &mov ("eax","esp");
89 &sub ("eax","edx");
90 &and ("eax",2047);
91 &sub ("esp","eax"); # this aligns sp and ap modulo 2048
92
93 &xor ("edx","esp");
94 &and ("edx",2048);
95 &xor ("edx",2048);
96 &sub ("esp","edx"); # this splits them apart modulo 4096
97
98 &and ("esp",-64); # align to cache line
99
100 ################################# load argument block...
101 &mov ("eax",&DWP(0*4,"esi"));# BN_ULONG *rp
102 &mov ("ebx",&DWP(1*4,"esi"));# const BN_ULONG *ap
103 &mov ("ecx",&DWP(2*4,"esi"));# const BN_ULONG *bp
104 &mov ("edx",&DWP(3*4,"esi"));# const BN_ULONG *np
105 &mov ("esi",&DWP(4*4,"esi"));# const BN_ULONG *n0
106 #&mov ("edi",&DWP(5*4,"esi"));# int num
107
108 &mov ("esi",&DWP(0,"esi")); # pull n0[0]
109 &mov ($_rp,"eax"); # ... save a copy of argument block
110 &mov ($_ap,"ebx");
111 &mov ($_bp,"ecx");
112 &mov ($_np,"edx");
113 &mov ($_n0,"esi");
114 &lea ($num,&DWP(-3,"edi")); # num=num-1 to assist modulo-scheduling
115 #&mov ($_num,$num); # redundant as $num is not reused
116 &mov ($_sp,"ebp"); # saved stack pointer!
117
118if($sse2) {
119$acc0="mm0"; # mmx register bank layout
120$acc1="mm1";
121$car0="mm2";
122$car1="mm3";
123$mul0="mm4";
124$mul1="mm5";
125$temp="mm6";
126$mask="mm7";
127
128 &picmeup("eax","OPENSSL_ia32cap_P");
129 &bt (&DWP(0,"eax"),26);
130 &jnc (&label("non_sse2"));
131
132 &mov ("eax",-1);
133 &movd ($mask,"eax"); # mask 32 lower bits
134
135 &mov ($ap,$_ap); # load input pointers
136 &mov ($bp,$_bp);
137 &mov ($np,$_np);
138
139 &xor ($i,$i); # i=0
140 &xor ($j,$j); # j=0
141
142 &movd ($mul0,&DWP(0,$bp)); # bp[0]
143 &movd ($mul1,&DWP(0,$ap)); # ap[0]
144 &movd ($car1,&DWP(0,$np)); # np[0]
145
146 &pmuludq($mul1,$mul0); # ap[0]*bp[0]
147 &movq ($car0,$mul1);
148 &movq ($acc0,$mul1); # I wish movd worked for
149 &pand ($acc0,$mask); # inter-register transfers
150
151 &pmuludq($mul1,$_n0q); # *=n0
152
153 &pmuludq($car1,$mul1); # "t[0]"*np[0]*n0
154 &paddq ($car1,$acc0);
155
156 &movd ($acc1,&DWP(4,$np)); # np[1]
157 &movd ($acc0,&DWP(4,$ap)); # ap[1]
158
159 &psrlq ($car0,32);
160 &psrlq ($car1,32);
161
162 &inc ($j); # j++
163&set_label("1st",16);
164 &pmuludq($acc0,$mul0); # ap[j]*bp[0]
165 &pmuludq($acc1,$mul1); # np[j]*m1
166 &paddq ($car0,$acc0); # +=c0
167 &paddq ($car1,$acc1); # +=c1
168
169 &movq ($acc0,$car0);
170 &pand ($acc0,$mask);
171 &movd ($acc1,&DWP(4,$np,$j,4)); # np[j+1]
172 &paddq ($car1,$acc0); # +=ap[j]*bp[0];
173 &movd ($acc0,&DWP(4,$ap,$j,4)); # ap[j+1]
174 &psrlq ($car0,32);
175 &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[j-1]=
176 &psrlq ($car1,32);
177
178 &lea ($j,&DWP(1,$j));
179 &cmp ($j,$num);
180 &jl (&label("1st"));
181
182 &pmuludq($acc0,$mul0); # ap[num-1]*bp[0]
183 &pmuludq($acc1,$mul1); # np[num-1]*m1
184 &paddq ($car0,$acc0); # +=c0
185 &paddq ($car1,$acc1); # +=c1
186
187 &movq ($acc0,$car0);
188 &pand ($acc0,$mask);
189 &paddq ($car1,$acc0); # +=ap[num-1]*bp[0];
190 &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[num-2]=
191
192 &psrlq ($car0,32);
193 &psrlq ($car1,32);
194
195 &paddq ($car1,$car0);
196 &movq (&QWP($frame,"esp",$num,4),$car1); # tp[num].tp[num-1]
197
198 &inc ($i); # i++
199&set_label("outer");
200 &xor ($j,$j); # j=0
201
202 &movd ($mul0,&DWP(0,$bp,$i,4)); # bp[i]
203 &movd ($mul1,&DWP(0,$ap)); # ap[0]
204 &movd ($temp,&DWP($frame,"esp")); # tp[0]
205 &movd ($car1,&DWP(0,$np)); # np[0]
206 &pmuludq($mul1,$mul0); # ap[0]*bp[i]
207
208 &paddq ($mul1,$temp); # +=tp[0]
209 &movq ($acc0,$mul1);
210 &movq ($car0,$mul1);
211 &pand ($acc0,$mask);
212
213 &pmuludq($mul1,$_n0q); # *=n0
214
215 &pmuludq($car1,$mul1);
216 &paddq ($car1,$acc0);
217
218 &movd ($temp,&DWP($frame+4,"esp")); # tp[1]
219 &movd ($acc1,&DWP(4,$np)); # np[1]
220 &movd ($acc0,&DWP(4,$ap)); # ap[1]
221
222 &psrlq ($car0,32);
223 &psrlq ($car1,32);
224 &paddq ($car0,$temp); # +=tp[1]
225
226 &inc ($j); # j++
227 &dec ($num);
228&set_label("inner");
229 &pmuludq($acc0,$mul0); # ap[j]*bp[i]
230 &pmuludq($acc1,$mul1); # np[j]*m1
231 &paddq ($car0,$acc0); # +=c0
232 &paddq ($car1,$acc1); # +=c1
233
234 &movq ($acc0,$car0);
235 &movd ($temp,&DWP($frame+4,"esp",$j,4));# tp[j+1]
236 &pand ($acc0,$mask);
237 &movd ($acc1,&DWP(4,$np,$j,4)); # np[j+1]
238 &paddq ($car1,$acc0); # +=ap[j]*bp[i]+tp[j]
239 &movd ($acc0,&DWP(4,$ap,$j,4)); # ap[j+1]
240 &psrlq ($car0,32);
241 &movd (&DWP($frame-4,"esp",$j,4),$car1);# tp[j-1]=
242 &psrlq ($car1,32);
243 &paddq ($car0,$temp); # +=tp[j+1]
244
245 &dec ($num);
246 &lea ($j,&DWP(1,$j)); # j++
247 &jnz (&label("inner"));
248
249 &mov ($num,$j);
250 &pmuludq($acc0,$mul0); # ap[num-1]*bp[i]
251 &pmuludq($acc1,$mul1); # np[num-1]*m1
252 &paddq ($car0,$acc0); # +=c0
253 &paddq ($car1,$acc1); # +=c1
254
255 &movq ($acc0,$car0);
256 &pand ($acc0,$mask);
257 &paddq ($car1,$acc0); # +=ap[num-1]*bp[i]+tp[num-1]
258 &movd (&DWP($frame-4,"esp",$j,4),$car1); # tp[num-2]=
259 &psrlq ($car0,32);
260 &psrlq ($car1,32);
261
262 &movd ($temp,&DWP($frame+4,"esp",$num,4)); # += tp[num]
263 &paddq ($car1,$car0);
264 &paddq ($car1,$temp);
265 &movq (&QWP($frame,"esp",$num,4),$car1); # tp[num].tp[num-1]
266
267 &lea ($i,&DWP(1,$i)); # i++
268 &cmp ($i,$num);
269 &jle (&label("outer"));
270
271 &emms (); # done with mmx bank
272 &jmp (&label("common_tail"));
273
274&set_label("non_sse2",16);
275}
276
277if (0) {
278 &mov ("esp",$_sp);
279 &xor ("eax","eax"); # signal "not fast enough [yet]"
280 &jmp (&label("just_leave"));
281 # While the below code provides competitive performance for
282 # all key lengthes on modern Intel cores, it's still more
283 # than 10% slower for 4096-bit key elsewhere:-( "Competitive"
284 # means compared to the original integer-only assembler.
285 # 512-bit RSA sign is better by ~40%, but that's about all
286 # one can say about all CPUs...
287} else {
288$inp="esi"; # integer path uses these registers differently
289$word="edi";
290$carry="ebp";
291
292 &mov ($inp,$_ap);
293 &lea ($carry,&DWP(1,$num));
294 &mov ($word,$_bp);
295 &xor ($j,$j); # j=0
296 &mov ("edx",$inp);
297 &and ($carry,1); # see if num is even
298 &sub ("edx",$word); # see if ap==bp
299 &lea ("eax",&DWP(4,$word,$num,4)); # &bp[num]
300 &or ($carry,"edx");
301 &mov ($word,&DWP(0,$word)); # bp[0]
302 &jz (&label("bn_sqr_mont"));
303 &mov ($_bpend,"eax");
304 &mov ("eax",&DWP(0,$inp));
305 &xor ("edx","edx");
306
307&set_label("mull",16);
308 &mov ($carry,"edx");
309 &mul ($word); # ap[j]*bp[0]
310 &add ($carry,"eax");
311 &lea ($j,&DWP(1,$j));
312 &adc ("edx",0);
313 &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j+1]
314 &cmp ($j,$num);
315 &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]=
316 &jl (&label("mull"));
317
318 &mov ($carry,"edx");
319 &mul ($word); # ap[num-1]*bp[0]
320 &mov ($word,$_n0);
321 &add ("eax",$carry);
322 &mov ($inp,$_np);
323 &adc ("edx",0);
324 &imul ($word,&DWP($frame,"esp")); # n0*tp[0]
325
326 &mov (&DWP($frame,"esp",$num,4),"eax"); # tp[num-1]=
327 &xor ($j,$j);
328 &mov (&DWP($frame+4,"esp",$num,4),"edx"); # tp[num]=
329 &mov (&DWP($frame+8,"esp",$num,4),$j); # tp[num+1]=
330
331 &mov ("eax",&DWP(0,$inp)); # np[0]
332 &mul ($word); # np[0]*m
333 &add ("eax",&DWP($frame,"esp")); # +=tp[0]
334 &mov ("eax",&DWP(4,$inp)); # np[1]
335 &adc ("edx",0);
336 &inc ($j);
337
338 &jmp (&label("2ndmadd"));
339
340&set_label("1stmadd",16);
341 &mov ($carry,"edx");
342 &mul ($word); # ap[j]*bp[i]
343 &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j]
344 &lea ($j,&DWP(1,$j));
345 &adc ("edx",0);
346 &add ($carry,"eax");
347 &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j+1]
348 &adc ("edx",0);
349 &cmp ($j,$num);
350 &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]=
351 &jl (&label("1stmadd"));
352
353 &mov ($carry,"edx");
354 &mul ($word); # ap[num-1]*bp[i]
355 &add ("eax",&DWP($frame,"esp",$num,4)); # +=tp[num-1]
356 &mov ($word,$_n0);
357 &adc ("edx",0);
358 &mov ($inp,$_np);
359 &add ($carry,"eax");
360 &adc ("edx",0);
361 &imul ($word,&DWP($frame,"esp")); # n0*tp[0]
362
363 &xor ($j,$j);
364 &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num]
365 &mov (&DWP($frame,"esp",$num,4),$carry); # tp[num-1]=
366 &adc ($j,0);
367 &mov ("eax",&DWP(0,$inp)); # np[0]
368 &mov (&DWP($frame+4,"esp",$num,4),"edx"); # tp[num]=
369 &mov (&DWP($frame+8,"esp",$num,4),$j); # tp[num+1]=
370
371 &mul ($word); # np[0]*m
372 &add ("eax",&DWP($frame,"esp")); # +=tp[0]
373 &mov ("eax",&DWP(4,$inp)); # np[1]
374 &adc ("edx",0);
375 &mov ($j,1);
376
377&set_label("2ndmadd",16);
378 &mov ($carry,"edx");
379 &mul ($word); # np[j]*m
380 &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j]
381 &lea ($j,&DWP(1,$j));
382 &adc ("edx",0);
383 &add ($carry,"eax");
384 &mov ("eax",&DWP(0,$inp,$j,4)); # np[j+1]
385 &adc ("edx",0);
386 &cmp ($j,$num);
387 &mov (&DWP($frame-8,"esp",$j,4),$carry); # tp[j-1]=
388 &jl (&label("2ndmadd"));
389
390 &mov ($carry,"edx");
391 &mul ($word); # np[j]*m
392 &add ($carry,&DWP($frame,"esp",$num,4)); # +=tp[num-1]
393 &adc ("edx",0);
394 &add ($carry,"eax");
395 &adc ("edx",0);
396 &mov (&DWP($frame-4,"esp",$num,4),$carry); # tp[num-2]=
397
398 &xor ("eax","eax");
399 &mov ($j,$_bp); # &bp[i]
400 &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num]
401 &adc ("eax",&DWP($frame+8,"esp",$num,4)); # +=tp[num+1]
402 &lea ($j,&DWP(4,$j));
403 &mov (&DWP($frame,"esp",$num,4),"edx"); # tp[num-1]=
404 &cmp ($j,$_bpend);
405 &mov (&DWP($frame+4,"esp",$num,4),"eax"); # tp[num]=
406 &je (&label("common_tail"));
407
408 &mov ($word,&DWP(0,$j)); # bp[i+1]
409 &mov ($inp,$_ap);
410 &mov ($_bp,$j); # &bp[++i]
411 &xor ($j,$j);
412 &xor ("edx","edx");
413 &mov ("eax",&DWP(0,$inp));
414 &jmp (&label("1stmadd"));
415
416&set_label("bn_sqr_mont",16);
417$sbit=$num;
418 &mov ($_num,$num);
419 &mov ($_bp,$j); # i=0
420
421 &mov ("eax",$word); # ap[0]
422 &mul ($word); # ap[0]*ap[0]
423 &mov (&DWP($frame,"esp"),"eax"); # tp[0]=
424 &mov ($sbit,"edx");
425 &shr ("edx",1);
426 &and ($sbit,1);
427 &inc ($j);
428&set_label("sqr",16);
429 &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j]
430 &mov ($carry,"edx");
431 &mul ($word); # ap[j]*ap[0]
432 &add ("eax",$carry);
433 &lea ($j,&DWP(1,$j));
434 &adc ("edx",0);
435 &lea ($carry,&DWP(0,$sbit,"eax",2));
436 &shr ("eax",31);
437 &cmp ($j,$_num);
438 &mov ($sbit,"eax");
439 &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]=
440 &jl (&label("sqr"));
441
442 &mov ("eax",&DWP(0,$inp,$j,4)); # ap[num-1]
443 &mov ($carry,"edx");
444 &mul ($word); # ap[num-1]*ap[0]
445 &add ("eax",$carry);
446 &mov ($word,$_n0);
447 &adc ("edx",0);
448 &mov ($inp,$_np);
449 &lea ($carry,&DWP(0,$sbit,"eax",2));
450 &imul ($word,&DWP($frame,"esp")); # n0*tp[0]
451 &shr ("eax",31);
452 &mov (&DWP($frame,"esp",$j,4),$carry); # tp[num-1]=
453
454 &lea ($carry,&DWP(0,"eax","edx",2));
455 &mov ("eax",&DWP(0,$inp)); # np[0]
456 &shr ("edx",31);
457 &mov (&DWP($frame+4,"esp",$j,4),$carry); # tp[num]=
458 &mov (&DWP($frame+8,"esp",$j,4),"edx"); # tp[num+1]=
459
460 &mul ($word); # np[0]*m
461 &add ("eax",&DWP($frame,"esp")); # +=tp[0]
462 &mov ($num,$j);
463 &adc ("edx",0);
464 &mov ("eax",&DWP(4,$inp)); # np[1]
465 &mov ($j,1);
466
467&set_label("3rdmadd",16);
468 &mov ($carry,"edx");
469 &mul ($word); # np[j]*m
470 &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j]
471 &adc ("edx",0);
472 &add ($carry,"eax");
473 &mov ("eax",&DWP(4,$inp,$j,4)); # np[j+1]
474 &adc ("edx",0);
475 &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j-1]=
476
477 &mov ($carry,"edx");
478 &mul ($word); # np[j+1]*m
479 &add ($carry,&DWP($frame+4,"esp",$j,4)); # +=tp[j+1]
480 &lea ($j,&DWP(2,$j));
481 &adc ("edx",0);
482 &add ($carry,"eax");
483 &mov ("eax",&DWP(0,$inp,$j,4)); # np[j+2]
484 &adc ("edx",0);
485 &cmp ($j,$num);
486 &mov (&DWP($frame-8,"esp",$j,4),$carry); # tp[j]=
487 &jl (&label("3rdmadd"));
488
489 &mov ($carry,"edx");
490 &mul ($word); # np[j]*m
491 &add ($carry,&DWP($frame,"esp",$num,4)); # +=tp[num-1]
492 &adc ("edx",0);
493 &add ($carry,"eax");
494 &adc ("edx",0);
495 &mov (&DWP($frame-4,"esp",$num,4),$carry); # tp[num-2]=
496
497 &mov ($j,$_bp); # i
498 &xor ("eax","eax");
499 &mov ($inp,$_ap);
500 &add ("edx",&DWP($frame+4,"esp",$num,4)); # carry+=tp[num]
501 &adc ("eax",&DWP($frame+8,"esp",$num,4)); # +=tp[num+1]
502 &mov (&DWP($frame,"esp",$num,4),"edx"); # tp[num-1]=
503 &cmp ($j,$num);
504 &mov (&DWP($frame+4,"esp",$num,4),"eax"); # tp[num]=
505 &je (&label("common_tail"));
506
507 &mov ($word,&DWP(4,$inp,$j,4)); # ap[i]
508 &lea ($j,&DWP(1,$j));
509 &mov ("eax",$word);
510 &mov ($_bp,$j); # ++i
511 &mul ($word); # ap[i]*ap[i]
512 &add ("eax",&DWP($frame,"esp",$j,4)); # +=tp[i]
513 &adc ("edx",0);
514 &mov (&DWP($frame,"esp",$j,4),"eax"); # tp[i]=
515 &xor ($carry,$carry);
516 &cmp ($j,$num);
517 &lea ($j,&DWP(1,$j));
518 &je (&label("sqrlast"));
519
520 &mov ($sbit,"edx"); # zaps $num
521 &shr ("edx",1);
522 &and ($sbit,1);
523&set_label("sqradd",16);
524 &mov ("eax",&DWP(0,$inp,$j,4)); # ap[j]
525 &mov ($carry,"edx");
526 &mul ($word); # ap[j]*ap[i]
527 &add ("eax",$carry);
528 &lea ($carry,&DWP(0,"eax","eax"));
529 &adc ("edx",0);
530 &shr ("eax",31);
531 &add ($carry,&DWP($frame,"esp",$j,4)); # +=tp[j]
532 &lea ($j,&DWP(1,$j));
533 &adc ("eax",0);
534 &add ($carry,$sbit);
535 &adc ("eax",0);
536 &cmp ($j,$_num);
537 &mov (&DWP($frame-4,"esp",$j,4),$carry); # tp[j]=
538 &mov ($sbit,"eax");
539 &jle (&label("sqradd"));
540
541 &mov ($carry,"edx");
542 &lea ("edx",&DWP(0,$sbit,"edx",2));
543 &shr ($carry,31);
544&set_label("sqrlast");
545 &mov ($word,$_n0);
546 &mov ($inp,$_np);
547 &imul ($word,&DWP($frame,"esp")); # n0*tp[0]
548
549 &add ("edx",&DWP($frame,"esp",$j,4)); # +=tp[num]
550 &mov ("eax",&DWP(0,$inp)); # np[0]
551 &adc ($carry,0);
552 &mov (&DWP($frame,"esp",$j,4),"edx"); # tp[num]=
553 &mov (&DWP($frame+4,"esp",$j,4),$carry); # tp[num+1]=
554
555 &mul ($word); # np[0]*m
556 &add ("eax",&DWP($frame,"esp")); # +=tp[0]
557 &lea ($num,&DWP(-1,$j));
558 &adc ("edx",0);
559 &mov ($j,1);
560 &mov ("eax",&DWP(4,$inp)); # np[1]
561
562 &jmp (&label("3rdmadd"));
563}
564
565&set_label("common_tail",16);
566 &mov ($np,$_np); # load modulus pointer
567 &mov ($rp,$_rp); # load result pointer
568 &lea ($tp,&DWP($frame,"esp")); # [$ap and $bp are zapped]
569
570 &mov ("eax",&DWP(0,$tp)); # tp[0]
571 &mov ($j,$num); # j=num-1
572 &xor ($i,$i); # i=0 and clear CF!
573
574&set_label("sub",16);
575 &sbb ("eax",&DWP(0,$np,$i,4));
576 &mov (&DWP(0,$rp,$i,4),"eax"); # rp[i]=tp[i]-np[i]
577 &dec ($j); # doesn't affect CF!
578 &mov ("eax",&DWP(4,$tp,$i,4)); # tp[i+1]
579 &lea ($i,&DWP(1,$i)); # i++
580 &jge (&label("sub"));
581
582 &sbb ("eax",0); # handle upmost overflow bit
583 &and ($tp,"eax");
584 &not ("eax");
585 &mov ($np,$rp);
586 &and ($np,"eax");
587 &or ($tp,$np); # tp=carry?tp:rp
588
589&set_label("copy",16); # copy or in-place refresh
590 &mov ("eax",&DWP(0,$tp,$num,4));
591 &mov (&DWP(0,$rp,$num,4),"eax"); # rp[i]=tp[i]
592 &mov (&DWP($frame,"esp",$num,4),$j); # zap temporary vector
593 &dec ($num);
594 &jge (&label("copy"));
595
596 &mov ("esp",$_sp); # pull saved stack pointer
597 &mov ("eax",1);
598&set_label("just_leave");
599&function_end("bn_mul_mont");
600
601&asciz("Montgomery Multiplication for x86, CRYPTOGAMS by <appro\@openssl.org>");
602
603&asm_finish();
diff --git a/src/lib/libcrypto/bn/asm/pa-risc.s b/src/lib/libcrypto/bn/asm/pa-risc.s
new file mode 100644
index 0000000000..775130a191
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/pa-risc.s
@@ -0,0 +1,710 @@
1 .SPACE $PRIVATE$
2 .SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
3 .SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
4 .SPACE $TEXT$
5 .SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
6 .SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
7 .IMPORT $global$,DATA
8 .IMPORT $$dyncall,MILLICODE
9; gcc_compiled.:
10 .SPACE $TEXT$
11 .SUBSPA $CODE$
12
13 .align 4
14 .EXPORT bn_mul_add_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
15bn_mul_add_words
16 .PROC
17 .CALLINFO FRAME=0,CALLS,SAVE_RP
18 .ENTRY
19 stw %r2,-20(0,%r30)
20 ldi 0,%r28
21 extru %r23,31,16,%r2
22 stw %r2,-16(0,%r30)
23 extru %r23,15,16,%r23
24 ldil L'65536,%r31
25 fldws -16(0,%r30),%fr11R
26 stw %r23,-16(0,%r30)
27 ldo 12(%r25),%r29
28 ldo 12(%r26),%r23
29 fldws -16(0,%r30),%fr11L
30L$0002
31 ldw 0(0,%r25),%r19
32 extru %r19,31,16,%r20
33 stw %r20,-16(0,%r30)
34 extru %r19,15,16,%r19
35 fldws -16(0,%r30),%fr22L
36 stw %r19,-16(0,%r30)
37 xmpyu %fr22L,%fr11R,%fr8
38 fldws -16(0,%r30),%fr22L
39 fstws %fr8R,-16(0,%r30)
40 xmpyu %fr11R,%fr22L,%fr10
41 ldw -16(0,%r30),%r2
42 stw %r20,-16(0,%r30)
43 xmpyu %fr22L,%fr11L,%fr9
44 fldws -16(0,%r30),%fr22L
45 fstws %fr10R,-16(0,%r30)
46 copy %r2,%r22
47 ldw -16(0,%r30),%r2
48 fstws %fr9R,-16(0,%r30)
49 xmpyu %fr11L,%fr22L,%fr8
50 copy %r2,%r19
51 ldw -16(0,%r30),%r2
52 fstws %fr8R,-16(0,%r30)
53 copy %r2,%r20
54 ldw -16(0,%r30),%r2
55 addl %r2,%r19,%r21
56 comclr,<<= %r19,%r21,0
57 addl %r20,%r31,%r20
58L$0005
59 extru %r21,15,16,%r19
60 addl %r20,%r19,%r20
61 zdep %r21,15,16,%r19
62 addl %r22,%r19,%r22
63 comclr,<<= %r19,%r22,0
64 addi,tr 1,%r20,%r19
65 copy %r20,%r19
66 addl %r22,%r28,%r20
67 comclr,<<= %r28,%r20,0
68 addi 1,%r19,%r19
69 ldw 0(0,%r26),%r28
70 addl %r20,%r28,%r20
71 comclr,<<= %r28,%r20,0
72 addi,tr 1,%r19,%r28
73 copy %r19,%r28
74 addib,= -1,%r24,L$0003
75 stw %r20,0(0,%r26)
76 ldw -8(0,%r29),%r19
77 extru %r19,31,16,%r20
78 stw %r20,-16(0,%r30)
79 extru %r19,15,16,%r19
80 fldws -16(0,%r30),%fr22L
81 stw %r19,-16(0,%r30)
82 xmpyu %fr22L,%fr11R,%fr8
83 fldws -16(0,%r30),%fr22L
84 fstws %fr8R,-16(0,%r30)
85 xmpyu %fr11R,%fr22L,%fr10
86 ldw -16(0,%r30),%r2
87 stw %r20,-16(0,%r30)
88 xmpyu %fr22L,%fr11L,%fr9
89 fldws -16(0,%r30),%fr22L
90 fstws %fr10R,-16(0,%r30)
91 copy %r2,%r22
92 ldw -16(0,%r30),%r2
93 fstws %fr9R,-16(0,%r30)
94 xmpyu %fr11L,%fr22L,%fr8
95 copy %r2,%r19
96 ldw -16(0,%r30),%r2
97 fstws %fr8R,-16(0,%r30)
98 copy %r2,%r20
99 ldw -16(0,%r30),%r2
100 addl %r2,%r19,%r21
101 comclr,<<= %r19,%r21,0
102 addl %r20,%r31,%r20
103L$0010
104 extru %r21,15,16,%r19
105 addl %r20,%r19,%r20
106 zdep %r21,15,16,%r19
107 addl %r22,%r19,%r22
108 comclr,<<= %r19,%r22,0
109 addi,tr 1,%r20,%r19
110 copy %r20,%r19
111 addl %r22,%r28,%r20
112 comclr,<<= %r28,%r20,0
113 addi 1,%r19,%r19
114 ldw -8(0,%r23),%r28
115 addl %r20,%r28,%r20
116 comclr,<<= %r28,%r20,0
117 addi,tr 1,%r19,%r28
118 copy %r19,%r28
119 addib,= -1,%r24,L$0003
120 stw %r20,-8(0,%r23)
121 ldw -4(0,%r29),%r19
122 extru %r19,31,16,%r20
123 stw %r20,-16(0,%r30)
124 extru %r19,15,16,%r19
125 fldws -16(0,%r30),%fr22L
126 stw %r19,-16(0,%r30)
127 xmpyu %fr22L,%fr11R,%fr8
128 fldws -16(0,%r30),%fr22L
129 fstws %fr8R,-16(0,%r30)
130 xmpyu %fr11R,%fr22L,%fr10
131 ldw -16(0,%r30),%r2
132 stw %r20,-16(0,%r30)
133 xmpyu %fr22L,%fr11L,%fr9
134 fldws -16(0,%r30),%fr22L
135 fstws %fr10R,-16(0,%r30)
136 copy %r2,%r22
137 ldw -16(0,%r30),%r2
138 fstws %fr9R,-16(0,%r30)
139 xmpyu %fr11L,%fr22L,%fr8
140 copy %r2,%r19
141 ldw -16(0,%r30),%r2
142 fstws %fr8R,-16(0,%r30)
143 copy %r2,%r20
144 ldw -16(0,%r30),%r2
145 addl %r2,%r19,%r21
146 comclr,<<= %r19,%r21,0
147 addl %r20,%r31,%r20
148L$0015
149 extru %r21,15,16,%r19
150 addl %r20,%r19,%r20
151 zdep %r21,15,16,%r19
152 addl %r22,%r19,%r22
153 comclr,<<= %r19,%r22,0
154 addi,tr 1,%r20,%r19
155 copy %r20,%r19
156 addl %r22,%r28,%r20
157 comclr,<<= %r28,%r20,0
158 addi 1,%r19,%r19
159 ldw -4(0,%r23),%r28
160 addl %r20,%r28,%r20
161 comclr,<<= %r28,%r20,0
162 addi,tr 1,%r19,%r28
163 copy %r19,%r28
164 addib,= -1,%r24,L$0003
165 stw %r20,-4(0,%r23)
166 ldw 0(0,%r29),%r19
167 extru %r19,31,16,%r20
168 stw %r20,-16(0,%r30)
169 extru %r19,15,16,%r19
170 fldws -16(0,%r30),%fr22L
171 stw %r19,-16(0,%r30)
172 xmpyu %fr22L,%fr11R,%fr8
173 fldws -16(0,%r30),%fr22L
174 fstws %fr8R,-16(0,%r30)
175 xmpyu %fr11R,%fr22L,%fr10
176 ldw -16(0,%r30),%r2
177 stw %r20,-16(0,%r30)
178 xmpyu %fr22L,%fr11L,%fr9
179 fldws -16(0,%r30),%fr22L
180 fstws %fr10R,-16(0,%r30)
181 copy %r2,%r22
182 ldw -16(0,%r30),%r2
183 fstws %fr9R,-16(0,%r30)
184 xmpyu %fr11L,%fr22L,%fr8
185 copy %r2,%r19
186 ldw -16(0,%r30),%r2
187 fstws %fr8R,-16(0,%r30)
188 copy %r2,%r20
189 ldw -16(0,%r30),%r2
190 addl %r2,%r19,%r21
191 comclr,<<= %r19,%r21,0
192 addl %r20,%r31,%r20
193L$0020
194 extru %r21,15,16,%r19
195 addl %r20,%r19,%r20
196 zdep %r21,15,16,%r19
197 addl %r22,%r19,%r22
198 comclr,<<= %r19,%r22,0
199 addi,tr 1,%r20,%r19
200 copy %r20,%r19
201 addl %r22,%r28,%r20
202 comclr,<<= %r28,%r20,0
203 addi 1,%r19,%r19
204 ldw 0(0,%r23),%r28
205 addl %r20,%r28,%r20
206 comclr,<<= %r28,%r20,0
207 addi,tr 1,%r19,%r28
208 copy %r19,%r28
209 addib,= -1,%r24,L$0003
210 stw %r20,0(0,%r23)
211 ldo 16(%r29),%r29
212 ldo 16(%r25),%r25
213 ldo 16(%r23),%r23
214 bl L$0002,0
215 ldo 16(%r26),%r26
216L$0003
217 ldw -20(0,%r30),%r2
218 bv,n 0(%r2)
219 .EXIT
220 .PROCEND
221 .align 4
222 .EXPORT bn_mul_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,ARGW3=GR,RTNVAL=GR
223bn_mul_words
224 .PROC
225 .CALLINFO FRAME=0,CALLS,SAVE_RP
226 .ENTRY
227 stw %r2,-20(0,%r30)
228 ldi 0,%r28
229 extru %r23,31,16,%r2
230 stw %r2,-16(0,%r30)
231 extru %r23,15,16,%r23
232 ldil L'65536,%r31
233 fldws -16(0,%r30),%fr11R
234 stw %r23,-16(0,%r30)
235 ldo 12(%r26),%r29
236 ldo 12(%r25),%r23
237 fldws -16(0,%r30),%fr11L
238L$0026
239 ldw 0(0,%r25),%r19
240 extru %r19,31,16,%r20
241 stw %r20,-16(0,%r30)
242 extru %r19,15,16,%r19
243 fldws -16(0,%r30),%fr22L
244 stw %r19,-16(0,%r30)
245 xmpyu %fr22L,%fr11R,%fr8
246 fldws -16(0,%r30),%fr22L
247 fstws %fr8R,-16(0,%r30)
248 xmpyu %fr11R,%fr22L,%fr10
249 ldw -16(0,%r30),%r2
250 stw %r20,-16(0,%r30)
251 xmpyu %fr22L,%fr11L,%fr9
252 fldws -16(0,%r30),%fr22L
253 fstws %fr10R,-16(0,%r30)
254 copy %r2,%r22
255 ldw -16(0,%r30),%r2
256 fstws %fr9R,-16(0,%r30)
257 xmpyu %fr11L,%fr22L,%fr8
258 copy %r2,%r19
259 ldw -16(0,%r30),%r2
260 fstws %fr8R,-16(0,%r30)
261 copy %r2,%r20
262 ldw -16(0,%r30),%r2
263 addl %r2,%r19,%r21
264 comclr,<<= %r19,%r21,0
265 addl %r20,%r31,%r20
266L$0029
267 extru %r21,15,16,%r19
268 addl %r20,%r19,%r20
269 zdep %r21,15,16,%r19
270 addl %r22,%r19,%r22
271 comclr,<<= %r19,%r22,0
272 addi,tr 1,%r20,%r19
273 copy %r20,%r19
274 addl %r22,%r28,%r20
275 comclr,<<= %r28,%r20,0
276 addi,tr 1,%r19,%r28
277 copy %r19,%r28
278 addib,= -1,%r24,L$0027
279 stw %r20,0(0,%r26)
280 ldw -8(0,%r23),%r19
281 extru %r19,31,16,%r20
282 stw %r20,-16(0,%r30)
283 extru %r19,15,16,%r19
284 fldws -16(0,%r30),%fr22L
285 stw %r19,-16(0,%r30)
286 xmpyu %fr22L,%fr11R,%fr8
287 fldws -16(0,%r30),%fr22L
288 fstws %fr8R,-16(0,%r30)
289 xmpyu %fr11R,%fr22L,%fr10
290 ldw -16(0,%r30),%r2
291 stw %r20,-16(0,%r30)
292 xmpyu %fr22L,%fr11L,%fr9
293 fldws -16(0,%r30),%fr22L
294 fstws %fr10R,-16(0,%r30)
295 copy %r2,%r22
296 ldw -16(0,%r30),%r2
297 fstws %fr9R,-16(0,%r30)
298 xmpyu %fr11L,%fr22L,%fr8
299 copy %r2,%r19
300 ldw -16(0,%r30),%r2
301 fstws %fr8R,-16(0,%r30)
302 copy %r2,%r20
303 ldw -16(0,%r30),%r2
304 addl %r2,%r19,%r21
305 comclr,<<= %r19,%r21,0
306 addl %r20,%r31,%r20
307L$0033
308 extru %r21,15,16,%r19
309 addl %r20,%r19,%r20
310 zdep %r21,15,16,%r19
311 addl %r22,%r19,%r22
312 comclr,<<= %r19,%r22,0
313 addi,tr 1,%r20,%r19
314 copy %r20,%r19
315 addl %r22,%r28,%r20
316 comclr,<<= %r28,%r20,0
317 addi,tr 1,%r19,%r28
318 copy %r19,%r28
319 addib,= -1,%r24,L$0027
320 stw %r20,-8(0,%r29)
321 ldw -4(0,%r23),%r19
322 extru %r19,31,16,%r20
323 stw %r20,-16(0,%r30)
324 extru %r19,15,16,%r19
325 fldws -16(0,%r30),%fr22L
326 stw %r19,-16(0,%r30)
327 xmpyu %fr22L,%fr11R,%fr8
328 fldws -16(0,%r30),%fr22L
329 fstws %fr8R,-16(0,%r30)
330 xmpyu %fr11R,%fr22L,%fr10
331 ldw -16(0,%r30),%r2
332 stw %r20,-16(0,%r30)
333 xmpyu %fr22L,%fr11L,%fr9
334 fldws -16(0,%r30),%fr22L
335 fstws %fr10R,-16(0,%r30)
336 copy %r2,%r22
337 ldw -16(0,%r30),%r2
338 fstws %fr9R,-16(0,%r30)
339 xmpyu %fr11L,%fr22L,%fr8
340 copy %r2,%r19
341 ldw -16(0,%r30),%r2
342 fstws %fr8R,-16(0,%r30)
343 copy %r2,%r20
344 ldw -16(0,%r30),%r2
345 addl %r2,%r19,%r21
346 comclr,<<= %r19,%r21,0
347 addl %r20,%r31,%r20
348L$0037
349 extru %r21,15,16,%r19
350 addl %r20,%r19,%r20
351 zdep %r21,15,16,%r19
352 addl %r22,%r19,%r22
353 comclr,<<= %r19,%r22,0
354 addi,tr 1,%r20,%r19
355 copy %r20,%r19
356 addl %r22,%r28,%r20
357 comclr,<<= %r28,%r20,0
358 addi,tr 1,%r19,%r28
359 copy %r19,%r28
360 addib,= -1,%r24,L$0027
361 stw %r20,-4(0,%r29)
362 ldw 0(0,%r23),%r19
363 extru %r19,31,16,%r20
364 stw %r20,-16(0,%r30)
365 extru %r19,15,16,%r19
366 fldws -16(0,%r30),%fr22L
367 stw %r19,-16(0,%r30)
368 xmpyu %fr22L,%fr11R,%fr8
369 fldws -16(0,%r30),%fr22L
370 fstws %fr8R,-16(0,%r30)
371 xmpyu %fr11R,%fr22L,%fr10
372 ldw -16(0,%r30),%r2
373 stw %r20,-16(0,%r30)
374 xmpyu %fr22L,%fr11L,%fr9
375 fldws -16(0,%r30),%fr22L
376 fstws %fr10R,-16(0,%r30)
377 copy %r2,%r22
378 ldw -16(0,%r30),%r2
379 fstws %fr9R,-16(0,%r30)
380 xmpyu %fr11L,%fr22L,%fr8
381 copy %r2,%r19
382 ldw -16(0,%r30),%r2
383 fstws %fr8R,-16(0,%r30)
384 copy %r2,%r20
385 ldw -16(0,%r30),%r2
386 addl %r2,%r19,%r21
387 comclr,<<= %r19,%r21,0
388 addl %r20,%r31,%r20
389L$0041
390 extru %r21,15,16,%r19
391 addl %r20,%r19,%r20
392 zdep %r21,15,16,%r19
393 addl %r22,%r19,%r22
394 comclr,<<= %r19,%r22,0
395 addi,tr 1,%r20,%r19
396 copy %r20,%r19
397 addl %r22,%r28,%r20
398 comclr,<<= %r28,%r20,0
399 addi,tr 1,%r19,%r28
400 copy %r19,%r28
401 addib,= -1,%r24,L$0027
402 stw %r20,0(0,%r29)
403 ldo 16(%r23),%r23
404 ldo 16(%r25),%r25
405 ldo 16(%r29),%r29
406 bl L$0026,0
407 ldo 16(%r26),%r26
408L$0027
409 ldw -20(0,%r30),%r2
410 bv,n 0(%r2)
411 .EXIT
412 .PROCEND
413 .align 4
414 .EXPORT bn_sqr_words,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR
415bn_sqr_words
416 .PROC
417 .CALLINFO FRAME=0,NO_CALLS
418 .ENTRY
419 ldo 28(%r26),%r23
420 ldo 12(%r25),%r28
421L$0046
422 ldw 0(0,%r25),%r21
423 extru %r21,31,16,%r22
424 stw %r22,-16(0,%r30)
425 extru %r21,15,16,%r21
426 fldws -16(0,%r30),%fr10L
427 stw %r21,-16(0,%r30)
428 fldws -16(0,%r30),%fr10R
429 xmpyu %fr10L,%fr10R,%fr8
430 fstws %fr8R,-16(0,%r30)
431 ldw -16(0,%r30),%r29
432 stw %r22,-16(0,%r30)
433 fldws -16(0,%r30),%fr10R
434 stw %r21,-16(0,%r30)
435 copy %r29,%r19
436 xmpyu %fr10L,%fr10R,%fr8
437 fldws -16(0,%r30),%fr10L
438 stw %r21,-16(0,%r30)
439 fldws -16(0,%r30),%fr10R
440 fstws %fr8R,-16(0,%r30)
441 extru %r19,16,17,%r20
442 zdep %r19,14,15,%r19
443 ldw -16(0,%r30),%r29
444 xmpyu %fr10L,%fr10R,%fr9
445 addl %r29,%r19,%r22
446 stw %r22,0(0,%r26)
447 fstws %fr9R,-16(0,%r30)
448 ldw -16(0,%r30),%r29
449 addl %r29,%r20,%r21
450 comclr,<<= %r19,%r22,0
451 addi 1,%r21,%r21
452 addib,= -1,%r24,L$0057
453 stw %r21,-24(0,%r23)
454 ldw -8(0,%r28),%r21
455 extru %r21,31,16,%r22
456 stw %r22,-16(0,%r30)
457 extru %r21,15,16,%r21
458 fldws -16(0,%r30),%fr10L
459 stw %r21,-16(0,%r30)
460 fldws -16(0,%r30),%fr10R
461 xmpyu %fr10L,%fr10R,%fr8
462 fstws %fr8R,-16(0,%r30)
463 ldw -16(0,%r30),%r29
464 stw %r22,-16(0,%r30)
465 fldws -16(0,%r30),%fr10R
466 stw %r21,-16(0,%r30)
467 copy %r29,%r19
468 xmpyu %fr10L,%fr10R,%fr8
469 fldws -16(0,%r30),%fr10L
470 stw %r21,-16(0,%r30)
471 fldws -16(0,%r30),%fr10R
472 fstws %fr8R,-16(0,%r30)
473 extru %r19,16,17,%r20
474 zdep %r19,14,15,%r19
475 ldw -16(0,%r30),%r29
476 xmpyu %fr10L,%fr10R,%fr9
477 addl %r29,%r19,%r22
478 stw %r22,-20(0,%r23)
479 fstws %fr9R,-16(0,%r30)
480 ldw -16(0,%r30),%r29
481 addl %r29,%r20,%r21
482 comclr,<<= %r19,%r22,0
483 addi 1,%r21,%r21
484 addib,= -1,%r24,L$0057
485 stw %r21,-16(0,%r23)
486 ldw -4(0,%r28),%r21
487 extru %r21,31,16,%r22
488 stw %r22,-16(0,%r30)
489 extru %r21,15,16,%r21
490 fldws -16(0,%r30),%fr10L
491 stw %r21,-16(0,%r30)
492 fldws -16(0,%r30),%fr10R
493 xmpyu %fr10L,%fr10R,%fr8
494 fstws %fr8R,-16(0,%r30)
495 ldw -16(0,%r30),%r29
496 stw %r22,-16(0,%r30)
497 fldws -16(0,%r30),%fr10R
498 stw %r21,-16(0,%r30)
499 copy %r29,%r19
500 xmpyu %fr10L,%fr10R,%fr8
501 fldws -16(0,%r30),%fr10L
502 stw %r21,-16(0,%r30)
503 fldws -16(0,%r30),%fr10R
504 fstws %fr8R,-16(0,%r30)
505 extru %r19,16,17,%r20
506 zdep %r19,14,15,%r19
507 ldw -16(0,%r30),%r29
508 xmpyu %fr10L,%fr10R,%fr9
509 addl %r29,%r19,%r22
510 stw %r22,-12(0,%r23)
511 fstws %fr9R,-16(0,%r30)
512 ldw -16(0,%r30),%r29
513 addl %r29,%r20,%r21
514 comclr,<<= %r19,%r22,0
515 addi 1,%r21,%r21
516 addib,= -1,%r24,L$0057
517 stw %r21,-8(0,%r23)
518 ldw 0(0,%r28),%r21
519 extru %r21,31,16,%r22
520 stw %r22,-16(0,%r30)
521 extru %r21,15,16,%r21
522 fldws -16(0,%r30),%fr10L
523 stw %r21,-16(0,%r30)
524 fldws -16(0,%r30),%fr10R
525 xmpyu %fr10L,%fr10R,%fr8
526 fstws %fr8R,-16(0,%r30)
527 ldw -16(0,%r30),%r29
528 stw %r22,-16(0,%r30)
529 fldws -16(0,%r30),%fr10R
530 stw %r21,-16(0,%r30)
531 copy %r29,%r19
532 xmpyu %fr10L,%fr10R,%fr8
533 fldws -16(0,%r30),%fr10L
534 stw %r21,-16(0,%r30)
535 fldws -16(0,%r30),%fr10R
536 fstws %fr8R,-16(0,%r30)
537 extru %r19,16,17,%r20
538 zdep %r19,14,15,%r19
539 ldw -16(0,%r30),%r29
540 xmpyu %fr10L,%fr10R,%fr9
541 addl %r29,%r19,%r22
542 stw %r22,-4(0,%r23)
543 fstws %fr9R,-16(0,%r30)
544 ldw -16(0,%r30),%r29
545 addl %r29,%r20,%r21
546 comclr,<<= %r19,%r22,0
547 addi 1,%r21,%r21
548 addib,= -1,%r24,L$0057
549 stw %r21,0(0,%r23)
550 ldo 16(%r28),%r28
551 ldo 16(%r25),%r25
552 ldo 32(%r23),%r23
553 bl L$0046,0
554 ldo 32(%r26),%r26
555L$0057
556 bv,n 0(%r2)
557 .EXIT
558 .PROCEND
559 .IMPORT BN_num_bits_word,CODE
560 .IMPORT fprintf,CODE
561 .IMPORT __iob,DATA
562 .SPACE $TEXT$
563 .SUBSPA $LIT$
564
565 .align 4
566L$C0000
567 .STRING "Division would overflow\x0a\x00"
568 .IMPORT abort,CODE
569 .SPACE $TEXT$
570 .SUBSPA $CODE$
571
572 .align 4
573 .EXPORT bn_div64,ENTRY,PRIV_LEV=3,ARGW0=GR,ARGW1=GR,ARGW2=GR,RTNVAL=GR
574bn_div64
575 .PROC
576 .CALLINFO FRAME=128,CALLS,SAVE_RP,ENTRY_GR=8
577 .ENTRY
578 stw %r2,-20(0,%r30)
579 stwm %r8,128(0,%r30)
580 stw %r7,-124(0,%r30)
581 stw %r4,-112(0,%r30)
582 stw %r3,-108(0,%r30)
583 copy %r26,%r3
584 copy %r25,%r4
585 stw %r6,-120(0,%r30)
586 ldi 0,%r7
587 stw %r5,-116(0,%r30)
588 movb,<> %r24,%r5,L$0059
589 ldi 2,%r6
590 bl L$0076,0
591 ldi -1,%r28
592L$0059
593 .CALL ARGW0=GR
594 bl BN_num_bits_word,%r2
595 copy %r5,%r26
596 ldi 32,%r19
597 comb,= %r19,%r28,L$0060
598 subi 31,%r28,%r19
599 mtsar %r19
600 zvdepi 1,32,%r19
601 comb,>>= %r19,%r3,L$0060
602 addil LR'__iob-$global$+32,%r27
603 ldo RR'__iob-$global$+32(%r1),%r26
604 ldil LR'L$C0000,%r25
605 .CALL ARGW0=GR,ARGW1=GR
606 bl fprintf,%r2
607 ldo RR'L$C0000(%r25),%r25
608 .CALL
609 bl abort,%r2
610 nop
611L$0060
612 comb,>> %r5,%r3,L$0061
613 subi 32,%r28,%r28
614 sub %r3,%r5,%r3
615L$0061
616 comib,= 0,%r28,L$0062
617 subi 31,%r28,%r19
618 mtsar %r19
619 zvdep %r5,32,%r5
620 zvdep %r3,32,%r21
621 subi 32,%r28,%r20
622 mtsar %r20
623 vshd 0,%r4,%r20
624 or %r21,%r20,%r3
625 mtsar %r19
626 zvdep %r4,32,%r4
627L$0062
628 extru %r5,15,16,%r23
629 extru %r5,31,16,%r28
630L$0063
631 extru %r3,15,16,%r19
632 comb,<> %r23,%r19,L$0066
633 copy %r3,%r26
634 bl L$0067,0
635 zdepi -1,31,16,%r29
636L$0066
637 .IMPORT $$divU,MILLICODE
638 bl $$divU,%r31
639 copy %r23,%r25
640L$0067
641 stw %r29,-16(0,%r30)
642 fldws -16(0,%r30),%fr10L
643 stw %r28,-16(0,%r30)
644 fldws -16(0,%r30),%fr10R
645 stw %r23,-16(0,%r30)
646 xmpyu %fr10L,%fr10R,%fr8
647 fldws -16(0,%r30),%fr10R
648 fstws %fr8R,-16(0,%r30)
649 xmpyu %fr10L,%fr10R,%fr9
650 ldw -16(0,%r30),%r8
651 fstws %fr9R,-16(0,%r30)
652 copy %r8,%r22
653 ldw -16(0,%r30),%r8
654 extru %r4,15,16,%r24
655 copy %r8,%r21
656L$0068
657 sub %r3,%r21,%r20
658 copy %r20,%r19
659 depi 0,31,16,%r19
660 comib,<> 0,%r19,L$0069
661 zdep %r20,15,16,%r19
662 addl %r19,%r24,%r19
663 comb,>>= %r19,%r22,L$0069
664 sub %r22,%r28,%r22
665 sub %r21,%r23,%r21
666 bl L$0068,0
667 ldo -1(%r29),%r29
668L$0069
669 stw %r29,-16(0,%r30)
670 fldws -16(0,%r30),%fr10L
671 stw %r28,-16(0,%r30)
672 fldws -16(0,%r30),%fr10R
673 xmpyu %fr10L,%fr10R,%fr8
674 fstws %fr8R,-16(0,%r30)
675 ldw -16(0,%r30),%r8
676 stw %r23,-16(0,%r30)
677 fldws -16(0,%r30),%fr10R
678 copy %r8,%r19
679 xmpyu %fr10L,%fr10R,%fr8
680 fstws %fr8R,-16(0,%r30)
681 extru %r19,15,16,%r20
682 ldw -16(0,%r30),%r8
683 zdep %r19,15,16,%r19
684 addl %r8,%r20,%r20
685 comclr,<<= %r19,%r4,0
686 addi 1,%r20,%r20
687 comb,<<= %r20,%r3,L$0074
688 sub %r4,%r19,%r4
689 addl %r3,%r5,%r3
690 ldo -1(%r29),%r29
691L$0074
692 addib,= -1,%r6,L$0064
693 sub %r3,%r20,%r3
694 zdep %r29,15,16,%r7
695 shd %r3,%r4,16,%r3
696 bl L$0063,0
697 zdep %r4,15,16,%r4
698L$0064
699 or %r7,%r29,%r28
700L$0076
701 ldw -148(0,%r30),%r2
702 ldw -124(0,%r30),%r7
703 ldw -120(0,%r30),%r6
704 ldw -116(0,%r30),%r5
705 ldw -112(0,%r30),%r4
706 ldw -108(0,%r30),%r3
707 bv 0(%r2)
708 ldwm -128(0,%r30),%r8
709 .EXIT
710 .PROCEND
diff --git a/src/lib/libcrypto/bn/asm/r3000.s b/src/lib/libcrypto/bn/asm/r3000.s
new file mode 100644
index 0000000000..e95269afa3
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/r3000.s
@@ -0,0 +1,646 @@
1 .file 1 "../bn_mulw.c"
2 .set nobopt
3 .option pic2
4
5 # GNU C 2.6.3 [AL 1.1, MM 40] SGI running IRIX 5.0 compiled by GNU C
6
7 # Cc1 defaults:
8 # -mabicalls
9
10 # Cc1 arguments (-G value = 0, Cpu = 3000, ISA = 1):
11 # -quiet -dumpbase -O2 -o
12
13gcc2_compiled.:
14__gnu_compiled_c:
15 .rdata
16
17 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
18 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x39,0x20
19 .byte 0x24,0x0
20
21 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
22 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x33,0x34,0x20
23 .byte 0x24,0x0
24
25 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
26 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x35,0x20,0x24
27 .byte 0x0
28
29 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
30 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
31 .byte 0x0
32
33 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
34 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x33,0x20
35 .byte 0x24,0x0
36
37 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
38 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x37,0x38,0x20
39 .byte 0x24,0x0
40
41 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
42 .byte 0x6e,0x3a,0x20,0x33,0x2e,0x37,0x30,0x20
43 .byte 0x24,0x0
44
45 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
46 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x32,0x20,0x24
47 .byte 0x0
48
49 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
50 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x34,0x20,0x24
51 .byte 0x0
52
53 .byte 0x24,0x52,0x65,0x76,0x69,0x73,0x69,0x6f
54 .byte 0x6e,0x3a,0x20,0x31,0x2e,0x38,0x20,0x24
55 .byte 0x0
56 .text
57 .align 2
58 .globl bn_mul_add_words
59 .ent bn_mul_add_words
60bn_mul_add_words:
61 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
62 .mask 0x00000000,0
63 .fmask 0x00000000,0
64 .set noreorder
65 .cpload $25
66 .set reorder
67 move $12,$4
68 move $14,$5
69 move $9,$6
70 move $13,$7
71 move $8,$0
72 addu $10,$12,12
73 addu $11,$14,12
74$L2:
75 lw $6,0($14)
76 #nop
77 multu $13,$6
78 mfhi $6
79 mflo $7
80 #nop
81 move $5,$8
82 move $4,$0
83 lw $3,0($12)
84 addu $9,$9,-1
85 move $2,$0
86 addu $7,$7,$3
87 sltu $8,$7,$3
88 addu $6,$6,$2
89 addu $6,$6,$8
90 addu $7,$7,$5
91 sltu $2,$7,$5
92 addu $6,$6,$4
93 addu $6,$6,$2
94 srl $3,$6,0
95 move $2,$0
96 move $8,$3
97 .set noreorder
98 .set nomacro
99 beq $9,$0,$L3
100 sw $7,0($12)
101 .set macro
102 .set reorder
103
104 lw $6,-8($11)
105 #nop
106 multu $13,$6
107 mfhi $6
108 mflo $7
109 #nop
110 move $5,$8
111 move $4,$0
112 lw $3,-8($10)
113 addu $9,$9,-1
114 move $2,$0
115 addu $7,$7,$3
116 sltu $8,$7,$3
117 addu $6,$6,$2
118 addu $6,$6,$8
119 addu $7,$7,$5
120 sltu $2,$7,$5
121 addu $6,$6,$4
122 addu $6,$6,$2
123 srl $3,$6,0
124 move $2,$0
125 move $8,$3
126 .set noreorder
127 .set nomacro
128 beq $9,$0,$L3
129 sw $7,-8($10)
130 .set macro
131 .set reorder
132
133 lw $6,-4($11)
134 #nop
135 multu $13,$6
136 mfhi $6
137 mflo $7
138 #nop
139 move $5,$8
140 move $4,$0
141 lw $3,-4($10)
142 addu $9,$9,-1
143 move $2,$0
144 addu $7,$7,$3
145 sltu $8,$7,$3
146 addu $6,$6,$2
147 addu $6,$6,$8
148 addu $7,$7,$5
149 sltu $2,$7,$5
150 addu $6,$6,$4
151 addu $6,$6,$2
152 srl $3,$6,0
153 move $2,$0
154 move $8,$3
155 .set noreorder
156 .set nomacro
157 beq $9,$0,$L3
158 sw $7,-4($10)
159 .set macro
160 .set reorder
161
162 lw $6,0($11)
163 #nop
164 multu $13,$6
165 mfhi $6
166 mflo $7
167 #nop
168 move $5,$8
169 move $4,$0
170 lw $3,0($10)
171 addu $9,$9,-1
172 move $2,$0
173 addu $7,$7,$3
174 sltu $8,$7,$3
175 addu $6,$6,$2
176 addu $6,$6,$8
177 addu $7,$7,$5
178 sltu $2,$7,$5
179 addu $6,$6,$4
180 addu $6,$6,$2
181 srl $3,$6,0
182 move $2,$0
183 move $8,$3
184 .set noreorder
185 .set nomacro
186 beq $9,$0,$L3
187 sw $7,0($10)
188 .set macro
189 .set reorder
190
191 addu $11,$11,16
192 addu $14,$14,16
193 addu $10,$10,16
194 .set noreorder
195 .set nomacro
196 j $L2
197 addu $12,$12,16
198 .set macro
199 .set reorder
200
201$L3:
202 .set noreorder
203 .set nomacro
204 j $31
205 move $2,$8
206 .set macro
207 .set reorder
208
209 .end bn_mul_add_words
210 .align 2
211 .globl bn_mul_words
212 .ent bn_mul_words
213bn_mul_words:
214 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
215 .mask 0x00000000,0
216 .fmask 0x00000000,0
217 .set noreorder
218 .cpload $25
219 .set reorder
220 move $11,$4
221 move $12,$5
222 move $8,$6
223 move $6,$0
224 addu $10,$11,12
225 addu $9,$12,12
226$L10:
227 lw $4,0($12)
228 #nop
229 multu $7,$4
230 mfhi $4
231 mflo $5
232 #nop
233 move $3,$6
234 move $2,$0
235 addu $8,$8,-1
236 addu $5,$5,$3
237 sltu $6,$5,$3
238 addu $4,$4,$2
239 addu $4,$4,$6
240 srl $3,$4,0
241 move $2,$0
242 move $6,$3
243 .set noreorder
244 .set nomacro
245 beq $8,$0,$L11
246 sw $5,0($11)
247 .set macro
248 .set reorder
249
250 lw $4,-8($9)
251 #nop
252 multu $7,$4
253 mfhi $4
254 mflo $5
255 #nop
256 move $3,$6
257 move $2,$0
258 addu $8,$8,-1
259 addu $5,$5,$3
260 sltu $6,$5,$3
261 addu $4,$4,$2
262 addu $4,$4,$6
263 srl $3,$4,0
264 move $2,$0
265 move $6,$3
266 .set noreorder
267 .set nomacro
268 beq $8,$0,$L11
269 sw $5,-8($10)
270 .set macro
271 .set reorder
272
273 lw $4,-4($9)
274 #nop
275 multu $7,$4
276 mfhi $4
277 mflo $5
278 #nop
279 move $3,$6
280 move $2,$0
281 addu $8,$8,-1
282 addu $5,$5,$3
283 sltu $6,$5,$3
284 addu $4,$4,$2
285 addu $4,$4,$6
286 srl $3,$4,0
287 move $2,$0
288 move $6,$3
289 .set noreorder
290 .set nomacro
291 beq $8,$0,$L11
292 sw $5,-4($10)
293 .set macro
294 .set reorder
295
296 lw $4,0($9)
297 #nop
298 multu $7,$4
299 mfhi $4
300 mflo $5
301 #nop
302 move $3,$6
303 move $2,$0
304 addu $8,$8,-1
305 addu $5,$5,$3
306 sltu $6,$5,$3
307 addu $4,$4,$2
308 addu $4,$4,$6
309 srl $3,$4,0
310 move $2,$0
311 move $6,$3
312 .set noreorder
313 .set nomacro
314 beq $8,$0,$L11
315 sw $5,0($10)
316 .set macro
317 .set reorder
318
319 addu $9,$9,16
320 addu $12,$12,16
321 addu $10,$10,16
322 .set noreorder
323 .set nomacro
324 j $L10
325 addu $11,$11,16
326 .set macro
327 .set reorder
328
329$L11:
330 .set noreorder
331 .set nomacro
332 j $31
333 move $2,$6
334 .set macro
335 .set reorder
336
337 .end bn_mul_words
338 .align 2
339 .globl bn_sqr_words
340 .ent bn_sqr_words
341bn_sqr_words:
342 .frame $sp,0,$31 # vars= 0, regs= 0/0, args= 0, extra= 0
343 .mask 0x00000000,0
344 .fmask 0x00000000,0
345 .set noreorder
346 .cpload $25
347 .set reorder
348 move $9,$4
349 addu $7,$9,28
350 addu $8,$5,12
351$L18:
352 lw $2,0($5)
353 #nop
354 multu $2,$2
355 mfhi $2
356 mflo $3
357 #nop
358 addu $6,$6,-1
359 sw $3,0($9)
360 srl $3,$2,0
361 move $2,$0
362 .set noreorder
363 .set nomacro
364 beq $6,$0,$L19
365 sw $3,-24($7)
366 .set macro
367 .set reorder
368
369 lw $2,-8($8)
370 #nop
371 multu $2,$2
372 mfhi $2
373 mflo $3
374 #nop
375 addu $6,$6,-1
376 sw $3,-20($7)
377 srl $3,$2,0
378 move $2,$0
379 .set noreorder
380 .set nomacro
381 beq $6,$0,$L19
382 sw $3,-16($7)
383 .set macro
384 .set reorder
385
386 lw $2,-4($8)
387 #nop
388 multu $2,$2
389 mfhi $2
390 mflo $3
391 #nop
392 addu $6,$6,-1
393 sw $3,-12($7)
394 srl $3,$2,0
395 move $2,$0
396 .set noreorder
397 .set nomacro
398 beq $6,$0,$L19
399 sw $3,-8($7)
400 .set macro
401 .set reorder
402
403 lw $2,0($8)
404 #nop
405 multu $2,$2
406 mfhi $2
407 mflo $3
408 #nop
409 addu $6,$6,-1
410 sw $3,-4($7)
411 srl $3,$2,0
412 move $2,$0
413 .set noreorder
414 .set nomacro
415 beq $6,$0,$L19
416 sw $3,0($7)
417 .set macro
418 .set reorder
419
420 addu $8,$8,16
421 addu $5,$5,16
422 addu $7,$7,32
423 .set noreorder
424 .set nomacro
425 j $L18
426 addu $9,$9,32
427 .set macro
428 .set reorder
429
430$L19:
431 j $31
432 .end bn_sqr_words
433 .rdata
434 .align 2
435$LC0:
436
437 .byte 0x44,0x69,0x76,0x69,0x73,0x69,0x6f,0x6e
438 .byte 0x20,0x77,0x6f,0x75,0x6c,0x64,0x20,0x6f
439 .byte 0x76,0x65,0x72,0x66,0x6c,0x6f,0x77,0xa
440 .byte 0x0
441 .text
442 .align 2
443 .globl bn_div64
444 .ent bn_div64
445bn_div64:
446 .frame $sp,56,$31 # vars= 0, regs= 7/0, args= 16, extra= 8
447 .mask 0x901f0000,-8
448 .fmask 0x00000000,0
449 .set noreorder
450 .cpload $25
451 .set reorder
452 subu $sp,$sp,56
453 .cprestore 16
454 sw $16,24($sp)
455 move $16,$4
456 sw $17,28($sp)
457 move $17,$5
458 sw $18,32($sp)
459 move $18,$6
460 sw $20,40($sp)
461 move $20,$0
462 sw $19,36($sp)
463 li $19,0x00000002 # 2
464 sw $31,48($sp)
465 .set noreorder
466 .set nomacro
467 bne $18,$0,$L26
468 sw $28,44($sp)
469 .set macro
470 .set reorder
471
472 .set noreorder
473 .set nomacro
474 j $L43
475 li $2,-1 # 0xffffffff
476 .set macro
477 .set reorder
478
479$L26:
480 move $4,$18
481 jal BN_num_bits_word
482 move $4,$2
483 li $2,0x00000020 # 32
484 .set noreorder
485 .set nomacro
486 beq $4,$2,$L27
487 li $2,0x00000001 # 1
488 .set macro
489 .set reorder
490
491 sll $2,$2,$4
492 sltu $2,$2,$16
493 .set noreorder
494 .set nomacro
495 beq $2,$0,$L44
496 li $5,0x00000020 # 32
497 .set macro
498 .set reorder
499
500 la $4,__iob+32
501 la $5,$LC0
502 jal fprintf
503 jal abort
504$L27:
505 li $5,0x00000020 # 32
506$L44:
507 sltu $2,$16,$18
508 .set noreorder
509 .set nomacro
510 bne $2,$0,$L28
511 subu $4,$5,$4
512 .set macro
513 .set reorder
514
515 subu $16,$16,$18
516$L28:
517 .set noreorder
518 .set nomacro
519 beq $4,$0,$L29
520 li $10,-65536 # 0xffff0000
521 .set macro
522 .set reorder
523
524 sll $18,$18,$4
525 sll $3,$16,$4
526 subu $2,$5,$4
527 srl $2,$17,$2
528 or $16,$3,$2
529 sll $17,$17,$4
530$L29:
531 srl $7,$18,16
532 andi $9,$18,0xffff
533$L30:
534 srl $2,$16,16
535 .set noreorder
536 .set nomacro
537 beq $2,$7,$L34
538 li $6,0x0000ffff # 65535
539 .set macro
540 .set reorder
541
542 divu $6,$16,$7
543$L34:
544 mult $6,$9
545 mflo $5
546 #nop
547 #nop
548 mult $6,$7
549 and $2,$17,$10
550 srl $8,$2,16
551 mflo $4
552$L35:
553 subu $3,$16,$4
554 and $2,$3,$10
555 .set noreorder
556 .set nomacro
557 bne $2,$0,$L36
558 sll $2,$3,16
559 .set macro
560 .set reorder
561
562 addu $2,$2,$8
563 sltu $2,$2,$5
564 .set noreorder
565 .set nomacro
566 beq $2,$0,$L36
567 subu $5,$5,$9
568 .set macro
569 .set reorder
570
571 subu $4,$4,$7
572 .set noreorder
573 .set nomacro
574 j $L35
575 addu $6,$6,-1
576 .set macro
577 .set reorder
578
579$L36:
580 mult $6,$7
581 mflo $5
582 #nop
583 #nop
584 mult $6,$9
585 mflo $4
586 #nop
587 #nop
588 srl $3,$4,16
589 sll $2,$4,16
590 and $4,$2,$10
591 sltu $2,$17,$4
592 .set noreorder
593 .set nomacro
594 beq $2,$0,$L40
595 addu $5,$5,$3
596 .set macro
597 .set reorder
598
599 addu $5,$5,1
600$L40:
601 sltu $2,$16,$5
602 .set noreorder
603 .set nomacro
604 beq $2,$0,$L41
605 subu $17,$17,$4
606 .set macro
607 .set reorder
608
609 addu $16,$16,$18
610 addu $6,$6,-1
611$L41:
612 addu $19,$19,-1
613 .set noreorder
614 .set nomacro
615 beq $19,$0,$L31
616 subu $16,$16,$5
617 .set macro
618 .set reorder
619
620 sll $20,$6,16
621 sll $3,$16,16
622 srl $2,$17,16
623 or $16,$3,$2
624 .set noreorder
625 .set nomacro
626 j $L30
627 sll $17,$17,16
628 .set macro
629 .set reorder
630
631$L31:
632 or $2,$20,$6
633$L43:
634 lw $31,48($sp)
635 lw $20,40($sp)
636 lw $19,36($sp)
637 lw $18,32($sp)
638 lw $17,28($sp)
639 lw $16,24($sp)
640 addu $sp,$sp,56
641 j $31
642 .end bn_div64
643
644 .globl abort .text
645 .globl fprintf .text
646 .globl BN_num_bits_word .text
diff --git a/src/lib/libcrypto/bn/asm/vms.mar b/src/lib/libcrypto/bn/asm/vms.mar
new file mode 100644
index 0000000000..aefab15cdb
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/vms.mar
@@ -0,0 +1,6440 @@
1 .title vax_bn_mul_add_words 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_words 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 vax_bn_div_words unsigned divide
166;
167; Richard Levitte 20-Nov-2000
168;
169; ULONG bn_div_words(ULONG h, ULONG l, ULONG d)
170; {
171; return ((ULONG)((((ULLONG)h)<<32)|l) / (ULLONG)d);
172; }
173;
174; Using EDIV would be very easy, if it didn't do signed calculations.
175; Any time any of the input numbers are signed, there are problems,
176; usually with integer overflow, at which point it returns useless
177; data (the quotient gets the value of l, and the remainder becomes 0).
178;
179; If it was just for the dividend, it would be very easy, just divide
180; it by 2 (unsigned), do the division, multiply the resulting quotient
181; and remainder by 2, add the bit that was dropped when dividing by 2
182; to the remainder, and do some adjustment so the remainder doesn't
183; end up larger than the divisor. For some cases when the divisor is
184; negative (from EDIV's point of view, i.e. when the highest bit is set),
185; dividing the dividend by 2 isn't enough, and since some operations
186; might generate integer overflows even when the dividend is divided by
187; 4 (when the high part of the shifted down dividend ends up being exactly
188; half of the divisor, the result is the quotient 0x80000000, which is
189; negative...) it needs to be divided by 8. Furthermore, the divisor needs
190; to be divided by 2 (unsigned) as well, to avoid more problems with the sign.
191; In this case, a little extra fiddling with the remainder is required.
192;
193; So, the simplest way to handle this is always to divide the dividend
194; by 8, and to divide the divisor by 2 if it's highest bit is set.
195; After EDIV has been used, the quotient gets multiplied by 8 if the
196; original divisor was positive, otherwise 4. The remainder, oddly
197; enough, is *always* multiplied by 8.
198; NOTE: in the case mentioned above, where the high part of the shifted
199; down dividend ends up being exactly half the shifted down divisor, we
200; end up with a 33 bit quotient. That's no problem however, it usually
201; means we have ended up with a too large remainder as well, and the
202; problem is fixed by the last part of the algorithm (next paragraph).
203;
204; The routine ends with comparing the resulting remainder with the
205; original divisor and if the remainder is larger, subtract the
206; original divisor from it, and increase the quotient by 1. This is
207; done until the remainder is smaller than the divisor.
208;
209; The complete algorithm looks like this:
210;
211; d' = d
212; l' = l & 7
213; [h,l] = [h,l] >> 3
214; [q,r] = floor([h,l] / d) # This is the EDIV operation
215; if (q < 0) q = -q # I doubt this is necessary any more
216;
217; r' = r >> 29
218; if (d' >= 0)
219; q' = q >> 29
220; q = q << 3
221; else
222; q' = q >> 30
223; q = q << 2
224; r = (r << 3) + l'
225;
226; if (d' < 0)
227; {
228; [r',r] = [r',r] - q
229; while ([r',r] < 0)
230; {
231; [r',r] = [r',r] + d
232; [q',q] = [q',q] - 1
233; }
234; }
235;
236; while ([r',r] >= d')
237; {
238; [r',r] = [r',r] - d'
239; [q',q] = [q',q] + 1
240; }
241;
242; return q
243
244h=4 ;(AP) h by value (input)
245l=8 ;(AP) l by value (input)
246d=12 ;(AP) d by value (input)
247
248;r2 = l, q
249;r3 = h, r
250;r4 = d
251;r5 = l'
252;r6 = r'
253;r7 = d'
254;r8 = q'
255
256 .psect code,nowrt
257
258.entry bn_div_words,^m<r2,r3,r4,r5,r6,r7,r8>
259 movl l(ap),r2
260 movl h(ap),r3
261 movl d(ap),r4
262
263 bicl3 #^XFFFFFFF8,r2,r5 ; l' = l & 7
264 bicl3 #^X00000007,r2,r2
265
266 bicl3 #^XFFFFFFF8,r3,r6
267 bicl3 #^X00000007,r3,r3
268
269 addl r6,r2
270
271 rotl #-3,r2,r2 ; l = l >> 3
272 rotl #-3,r3,r3 ; h = h >> 3
273
274 movl r4,r7 ; d' = d
275
276 movl #0,r6 ; r' = 0
277 movl #0,r8 ; q' = 0
278
279 tstl r4
280 beql 666$ ; Uh-oh, the divisor is 0...
281 bgtr 1$
282 rotl #-1,r4,r4 ; If d is negative, shift it right.
283 bicl2 #^X80000000,r4 ; Since d is then a large number, the
284 ; lowest bit is insignificant
285 ; (contradict that, and I'll fix the problem!)
2861$:
287 ediv r4,r2,r2,r3 ; Do the actual division
288
289 tstl r2
290 bgeq 3$
291 mnegl r2,r2 ; if q < 0, negate it
2923$:
293 tstl r7
294 blss 4$
295 rotl #3,r2,r2 ; q = q << 3
296 bicl3 #^XFFFFFFF8,r2,r8 ; q' gets the high bits from q
297 bicl3 #^X00000007,r2,r2
298 bsb 41$
2994$: ; else
300 rotl #2,r2,r2 ; q = q << 2
301 bicl3 #^XFFFFFFFC,r2,r8 ; q' gets the high bits from q
302 bicl3 #^X00000003,r2,r2
30341$:
304 rotl #3,r3,r3 ; r = r << 3
305 bicl3 #^XFFFFFFF8,r3,r6 ; r' gets the high bits from r
306 bicl3 #^X00000007,r3,r3
307 addl r5,r3 ; r = r + l'
308
309 tstl r7
310 bgeq 5$
311 bitl #1,r7
312 beql 5$ ; if d' < 0 && d' & 1
313 subl r2,r3 ; [r',r] = [r',r] - [q',q]
314 sbwc r8,r6
31545$:
316 bgeq 5$ ; while r < 0
317 decl r2 ; [q',q] = [q',q] - 1
318 sbwc #0,r8
319 addl r7,r3 ; [r',r] = [r',r] + d'
320 adwc #0,r6
321 brb 45$
322
323; The return points are placed in the middle to keep a short distance from
324; all the branch points
32542$:
326; movl r3,r1
327 movl r2,r0
328 ret
329666$:
330 movl #^XFFFFFFFF,r0
331 ret
332
3335$:
334 tstl r6
335 bneq 6$
336 cmpl r3,r7
337 blssu 42$ ; while [r',r] >= d'
3386$:
339 subl r7,r3 ; [r',r] = [r',r] - d'
340 sbwc #0,r6
341 incl r2 ; [q',q] = [q',q] + 1
342 adwc #0,r8
343 brb 5$
344
345 .title vax_bn_add_words unsigned add of two arrays
346;
347; Richard Levitte 20-Nov-2000
348;
349; ULONG bn_add_words(ULONG r[], ULONG a[], ULONG b[], int n) {
350; ULONG c = 0;
351; int i;
352; for (i = 0; i < n; i++) <c,r[i]> = a[i] + b[i] + c;
353; return(c);
354; }
355
356r=4 ;(AP) r by reference (output)
357a=8 ;(AP) a by reference (input)
358b=12 ;(AP) b by reference (input)
359n=16 ;(AP) n by value (input)
360
361
362 .psect code,nowrt
363
364.entry bn_add_words,^m<r2,r3,r4,r5,r6>
365
366 moval @r(ap),r2
367 moval @a(ap),r3
368 moval @b(ap),r4
369 movl n(ap),r5 ; assumed >0 by C code
370 clrl r0 ; c
371
372 tstl r5 ; carry = 0
373 bleq 666$
374
3750$:
376 movl (r3)+,r6 ; carry untouched
377 adwc (r4)+,r6 ; carry used and touched
378 movl r6,(r2)+ ; carry untouched
379 sobgtr r5,0$ ; carry untouched
380
381 adwc #0,r0
382666$:
383 ret
384
385 .title vax_bn_sub_words unsigned add of two arrays
386;
387; Richard Levitte 20-Nov-2000
388;
389; ULONG bn_sub_words(ULONG r[], ULONG a[], ULONG b[], int n) {
390; ULONG c = 0;
391; int i;
392; for (i = 0; i < n; i++) <c,r[i]> = a[i] - b[i] - c;
393; return(c);
394; }
395
396r=4 ;(AP) r by reference (output)
397a=8 ;(AP) a by reference (input)
398b=12 ;(AP) b by reference (input)
399n=16 ;(AP) n by value (input)
400
401
402 .psect code,nowrt
403
404.entry bn_sub_words,^m<r2,r3,r4,r5,r6>
405
406 moval @r(ap),r2
407 moval @a(ap),r3
408 moval @b(ap),r4
409 movl n(ap),r5 ; assumed >0 by C code
410 clrl r0 ; c
411
412 tstl r5 ; carry = 0
413 bleq 666$
414
4150$:
416 movl (r3)+,r6 ; carry untouched
417 sbwc (r4)+,r6 ; carry used and touched
418 movl r6,(r2)+ ; carry untouched
419 sobgtr r5,0$ ; carry untouched
420
421 adwc #0,r0
422666$:
423 ret
424
425
426;r=4 ;(AP)
427;a=8 ;(AP)
428;b=12 ;(AP)
429;n=16 ;(AP) n by value (input)
430
431 .psect code,nowrt
432
433.entry BN_MUL_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
434 movab -924(sp),sp
435 clrq r8
436
437 clrl r10
438
439 movl 8(ap),r6
440 movzwl 2(r6),r3
441 movl 12(ap),r7
442 bicl3 #-65536,(r7),r2
443 movzwl 2(r7),r0
444 bicl2 #-65536,r0
445 bicl3 #-65536,(r6),-12(fp)
446 bicl3 #-65536,r3,-16(fp)
447 mull3 r0,-12(fp),-4(fp)
448 mull2 r2,-12(fp)
449 mull3 r2,-16(fp),-8(fp)
450 mull2 r0,-16(fp)
451 addl3 -4(fp),-8(fp),r0
452 bicl3 #0,r0,-4(fp)
453 cmpl -4(fp),-8(fp)
454 bgequ noname.45
455 addl2 #65536,-16(fp)
456noname.45:
457 movzwl -2(fp),r0
458 bicl2 #-65536,r0
459 addl2 r0,-16(fp)
460 bicl3 #-65536,-4(fp),r0
461 ashl #16,r0,-8(fp)
462 addl3 -8(fp),-12(fp),r0
463 bicl3 #0,r0,-12(fp)
464 cmpl -12(fp),-8(fp)
465 bgequ noname.46
466 incl -16(fp)
467noname.46:
468 movl -12(fp),r1
469 movl -16(fp),r2
470 addl2 r1,r9
471 bicl2 #0,r9
472 cmpl r9,r1
473 bgequ noname.47
474 incl r2
475noname.47:
476 addl2 r2,r8
477 bicl2 #0,r8
478 cmpl r8,r2
479 bgequ noname.48
480 incl r10
481noname.48:
482
483 movl 4(ap),r11
484 movl r9,(r11)
485
486 clrl r9
487
488 movzwl 2(r6),r2
489 bicl3 #-65536,4(r7),r3
490 movzwl 6(r7),r0
491 bicl2 #-65536,r0
492 bicl3 #-65536,(r6),-28(fp)
493 bicl3 #-65536,r2,-32(fp)
494 mull3 r0,-28(fp),-20(fp)
495 mull2 r3,-28(fp)
496 mull3 r3,-32(fp),-24(fp)
497 mull2 r0,-32(fp)
498 addl3 -20(fp),-24(fp),r0
499 bicl3 #0,r0,-20(fp)
500 cmpl -20(fp),-24(fp)
501 bgequ noname.49
502 addl2 #65536,-32(fp)
503noname.49:
504 movzwl -18(fp),r0
505 bicl2 #-65536,r0
506 addl2 r0,-32(fp)
507 bicl3 #-65536,-20(fp),r0
508 ashl #16,r0,-24(fp)
509 addl3 -24(fp),-28(fp),r0
510 bicl3 #0,r0,-28(fp)
511 cmpl -28(fp),-24(fp)
512 bgequ noname.50
513 incl -32(fp)
514noname.50:
515 movl -28(fp),r1
516 movl -32(fp),r2
517 addl2 r1,r8
518 bicl2 #0,r8
519 cmpl r8,r1
520 bgequ noname.51
521 incl r2
522noname.51:
523 addl2 r2,r10
524 bicl2 #0,r10
525 cmpl r10,r2
526 bgequ noname.52
527 incl r9
528noname.52:
529
530 movzwl 6(r6),r2
531 bicl3 #-65536,(r7),r3
532 movzwl 2(r7),r0
533 bicl2 #-65536,r0
534 bicl3 #-65536,4(r6),-44(fp)
535 bicl3 #-65536,r2,-48(fp)
536 mull3 r0,-44(fp),-36(fp)
537 mull2 r3,-44(fp)
538 mull3 r3,-48(fp),-40(fp)
539 mull2 r0,-48(fp)
540 addl3 -36(fp),-40(fp),r0
541 bicl3 #0,r0,-36(fp)
542 cmpl -36(fp),-40(fp)
543 bgequ noname.53
544 addl2 #65536,-48(fp)
545noname.53:
546 movzwl -34(fp),r0
547 bicl2 #-65536,r0
548 addl2 r0,-48(fp)
549 bicl3 #-65536,-36(fp),r0
550 ashl #16,r0,-40(fp)
551 addl3 -40(fp),-44(fp),r0
552 bicl3 #0,r0,-44(fp)
553 cmpl -44(fp),-40(fp)
554 bgequ noname.54
555 incl -48(fp)
556noname.54:
557 movl -44(fp),r1
558 movl -48(fp),r2
559 addl2 r1,r8
560 bicl2 #0,r8
561 cmpl r8,r1
562 bgequ noname.55
563 incl r2
564noname.55:
565 addl2 r2,r10
566 bicl2 #0,r10
567 cmpl r10,r2
568 bgequ noname.56
569 incl r9
570noname.56:
571
572 movl r8,4(r11)
573
574 clrl r8
575
576 movzwl 10(r6),r2
577 bicl3 #-65536,(r7),r3
578 movzwl 2(r7),r0
579 bicl2 #-65536,r0
580 bicl3 #-65536,8(r6),-60(fp)
581 bicl3 #-65536,r2,-64(fp)
582 mull3 r0,-60(fp),-52(fp)
583 mull2 r3,-60(fp)
584 mull3 r3,-64(fp),-56(fp)
585 mull2 r0,-64(fp)
586 addl3 -52(fp),-56(fp),r0
587 bicl3 #0,r0,-52(fp)
588 cmpl -52(fp),-56(fp)
589 bgequ noname.57
590 addl2 #65536,-64(fp)
591noname.57:
592 movzwl -50(fp),r0
593 bicl2 #-65536,r0
594 addl2 r0,-64(fp)
595 bicl3 #-65536,-52(fp),r0
596 ashl #16,r0,-56(fp)
597 addl3 -56(fp),-60(fp),r0
598 bicl3 #0,r0,-60(fp)
599 cmpl -60(fp),-56(fp)
600 bgequ noname.58
601 incl -64(fp)
602noname.58:
603 movl -60(fp),r1
604 movl -64(fp),r2
605 addl2 r1,r10
606 bicl2 #0,r10
607 cmpl r10,r1
608 bgequ noname.59
609 incl r2
610noname.59:
611 addl2 r2,r9
612 bicl2 #0,r9
613 cmpl r9,r2
614 bgequ noname.60
615 incl r8
616noname.60:
617
618 movzwl 6(r6),r2
619 bicl3 #-65536,4(r7),r3
620 movzwl 6(r7),r0
621 bicl2 #-65536,r0
622 bicl3 #-65536,4(r6),-76(fp)
623 bicl3 #-65536,r2,-80(fp)
624 mull3 r0,-76(fp),-68(fp)
625 mull2 r3,-76(fp)
626 mull3 r3,-80(fp),-72(fp)
627 mull2 r0,-80(fp)
628 addl3 -68(fp),-72(fp),r0
629 bicl3 #0,r0,-68(fp)
630 cmpl -68(fp),-72(fp)
631 bgequ noname.61
632 addl2 #65536,-80(fp)
633noname.61:
634 movzwl -66(fp),r0
635 bicl2 #-65536,r0
636 addl2 r0,-80(fp)
637 bicl3 #-65536,-68(fp),r0
638 ashl #16,r0,-72(fp)
639 addl3 -72(fp),-76(fp),r0
640 bicl3 #0,r0,-76(fp)
641 cmpl -76(fp),-72(fp)
642 bgequ noname.62
643 incl -80(fp)
644noname.62:
645 movl -76(fp),r1
646 movl -80(fp),r2
647 addl2 r1,r10
648 bicl2 #0,r10
649 cmpl r10,r1
650 bgequ noname.63
651 incl r2
652noname.63:
653 addl2 r2,r9
654 bicl2 #0,r9
655 cmpl r9,r2
656 bgequ noname.64
657 incl r8
658noname.64:
659
660 movzwl 2(r6),r2
661 bicl3 #-65536,8(r7),r3
662 movzwl 10(r7),r0
663 bicl2 #-65536,r0
664 bicl3 #-65536,(r6),-92(fp)
665 bicl3 #-65536,r2,-96(fp)
666 mull3 r0,-92(fp),-84(fp)
667 mull2 r3,-92(fp)
668 mull3 r3,-96(fp),-88(fp)
669 mull2 r0,-96(fp)
670 addl3 -84(fp),-88(fp),r0
671 bicl3 #0,r0,-84(fp)
672 cmpl -84(fp),-88(fp)
673 bgequ noname.65
674 addl2 #65536,-96(fp)
675noname.65:
676 movzwl -82(fp),r0
677 bicl2 #-65536,r0
678 addl2 r0,-96(fp)
679 bicl3 #-65536,-84(fp),r0
680 ashl #16,r0,-88(fp)
681 addl3 -88(fp),-92(fp),r0
682 bicl3 #0,r0,-92(fp)
683 cmpl -92(fp),-88(fp)
684 bgequ noname.66
685 incl -96(fp)
686noname.66:
687 movl -92(fp),r1
688 movl -96(fp),r2
689 addl2 r1,r10
690 bicl2 #0,r10
691 cmpl r10,r1
692 bgequ noname.67
693 incl r2
694noname.67:
695 addl2 r2,r9
696 bicl2 #0,r9
697 cmpl r9,r2
698 bgequ noname.68
699 incl r8
700noname.68:
701
702 movl r10,8(r11)
703
704 clrl r10
705
706 movzwl 2(r6),r2
707 bicl3 #-65536,12(r7),r3
708 movzwl 14(r7),r0
709 bicl2 #-65536,r0
710 bicl3 #-65536,(r6),-108(fp)
711 bicl3 #-65536,r2,-112(fp)
712 mull3 r0,-108(fp),-100(fp)
713 mull2 r3,-108(fp)
714 mull3 r3,-112(fp),-104(fp)
715 mull2 r0,-112(fp)
716 addl3 -100(fp),-104(fp),r0
717 bicl3 #0,r0,-100(fp)
718 cmpl -100(fp),-104(fp)
719 bgequ noname.69
720 addl2 #65536,-112(fp)
721noname.69:
722 movzwl -98(fp),r0
723 bicl2 #-65536,r0
724 addl2 r0,-112(fp)
725 bicl3 #-65536,-100(fp),r0
726 ashl #16,r0,-104(fp)
727 addl3 -104(fp),-108(fp),r0
728 bicl3 #0,r0,-108(fp)
729 cmpl -108(fp),-104(fp)
730 bgequ noname.70
731 incl -112(fp)
732noname.70:
733 movl -108(fp),r1
734 movl -112(fp),r2
735 addl2 r1,r9
736 bicl2 #0,r9
737 cmpl r9,r1
738 bgequ noname.71
739 incl r2
740noname.71:
741 addl2 r2,r8
742 bicl2 #0,r8
743 cmpl r8,r2
744 bgequ noname.72
745 incl r10
746noname.72:
747
748 movzwl 6(r6),r2
749 bicl3 #-65536,8(r7),r3
750 movzwl 10(r7),r0
751 bicl2 #-65536,r0
752 bicl3 #-65536,4(r6),-124(fp)
753 bicl3 #-65536,r2,-128(fp)
754 mull3 r0,-124(fp),-116(fp)
755 mull2 r3,-124(fp)
756 mull3 r3,-128(fp),-120(fp)
757 mull2 r0,-128(fp)
758 addl3 -116(fp),-120(fp),r0
759 bicl3 #0,r0,-116(fp)
760 cmpl -116(fp),-120(fp)
761 bgequ noname.73
762 addl2 #65536,-128(fp)
763noname.73:
764 movzwl -114(fp),r0
765 bicl2 #-65536,r0
766 addl2 r0,-128(fp)
767 bicl3 #-65536,-116(fp),r0
768 ashl #16,r0,-120(fp)
769 addl3 -120(fp),-124(fp),r0
770 bicl3 #0,r0,-124(fp)
771 cmpl -124(fp),-120(fp)
772 bgequ noname.74
773 incl -128(fp)
774noname.74:
775 movl -124(fp),r1
776 movl -128(fp),r2
777 addl2 r1,r9
778 bicl2 #0,r9
779 cmpl r9,r1
780 bgequ noname.75
781 incl r2
782noname.75:
783 addl2 r2,r8
784 bicl2 #0,r8
785 cmpl r8,r2
786 bgequ noname.76
787 incl r10
788noname.76:
789
790 movzwl 10(r6),r2
791 bicl3 #-65536,4(r7),r3
792 movzwl 6(r7),r0
793 bicl2 #-65536,r0
794 bicl3 #-65536,8(r6),-140(fp)
795 bicl3 #-65536,r2,-144(fp)
796 mull3 r0,-140(fp),-132(fp)
797 mull2 r3,-140(fp)
798 mull3 r3,-144(fp),-136(fp)
799 mull2 r0,-144(fp)
800 addl3 -132(fp),-136(fp),r0
801 bicl3 #0,r0,-132(fp)
802 cmpl -132(fp),-136(fp)
803 bgequ noname.77
804 addl2 #65536,-144(fp)
805noname.77:
806 movzwl -130(fp),r0
807 bicl2 #-65536,r0
808 addl2 r0,-144(fp)
809 bicl3 #-65536,-132(fp),r0
810 ashl #16,r0,-136(fp)
811 addl3 -136(fp),-140(fp),r0
812 bicl3 #0,r0,-140(fp)
813 cmpl -140(fp),-136(fp)
814 bgequ noname.78
815 incl -144(fp)
816noname.78:
817 movl -140(fp),r1
818 movl -144(fp),r2
819 addl2 r1,r9
820 bicl2 #0,r9
821 cmpl r9,r1
822 bgequ noname.79
823 incl r2
824noname.79:
825 addl2 r2,r8
826 bicl2 #0,r8
827 cmpl r8,r2
828 bgequ noname.80
829 incl r10
830noname.80:
831
832 movzwl 14(r6),r2
833 bicl3 #-65536,(r7),r3
834 movzwl 2(r7),r0
835 bicl2 #-65536,r0
836 bicl3 #-65536,12(r6),-156(fp)
837 bicl3 #-65536,r2,-160(fp)
838 mull3 r0,-156(fp),-148(fp)
839 mull2 r3,-156(fp)
840 mull3 r3,-160(fp),-152(fp)
841 mull2 r0,-160(fp)
842 addl3 -148(fp),-152(fp),r0
843 bicl3 #0,r0,-148(fp)
844 cmpl -148(fp),-152(fp)
845 bgequ noname.81
846 addl2 #65536,-160(fp)
847noname.81:
848 movzwl -146(fp),r0
849 bicl2 #-65536,r0
850 addl2 r0,-160(fp)
851 bicl3 #-65536,-148(fp),r0
852 ashl #16,r0,-152(fp)
853 addl3 -152(fp),-156(fp),r0
854 bicl3 #0,r0,-156(fp)
855 cmpl -156(fp),-152(fp)
856 bgequ noname.82
857 incl -160(fp)
858noname.82:
859 movl -156(fp),r1
860 movl -160(fp),r2
861 addl2 r1,r9
862 bicl2 #0,r9
863 cmpl r9,r1
864 bgequ noname.83
865 incl r2
866noname.83:
867 addl2 r2,r8
868 bicl2 #0,r8
869 cmpl r8,r2
870 bgequ noname.84
871 incl r10
872noname.84:
873
874 movl r9,12(r11)
875
876 clrl r9
877
878 movzwl 18(r6),r2
879 bicl3 #-65536,(r7),r3
880 movzwl 2(r7),r0
881 bicl2 #-65536,r0
882 bicl3 #-65536,16(r6),-172(fp)
883 bicl3 #-65536,r2,-176(fp)
884 mull3 r0,-172(fp),-164(fp)
885 mull2 r3,-172(fp)
886 mull3 r3,-176(fp),-168(fp)
887 mull2 r0,-176(fp)
888 addl3 -164(fp),-168(fp),r0
889 bicl3 #0,r0,-164(fp)
890 cmpl -164(fp),-168(fp)
891 bgequ noname.85
892 addl2 #65536,-176(fp)
893noname.85:
894 movzwl -162(fp),r0
895 bicl2 #-65536,r0
896 addl2 r0,-176(fp)
897 bicl3 #-65536,-164(fp),r0
898 ashl #16,r0,-168(fp)
899 addl3 -168(fp),-172(fp),r0
900 bicl3 #0,r0,-172(fp)
901 cmpl -172(fp),-168(fp)
902 bgequ noname.86
903 incl -176(fp)
904noname.86:
905 movl -172(fp),r1
906 movl -176(fp),r2
907 addl2 r1,r8
908 bicl2 #0,r8
909 cmpl r8,r1
910 bgequ noname.87
911 incl r2
912noname.87:
913 addl2 r2,r10
914 bicl2 #0,r10
915 cmpl r10,r2
916 bgequ noname.88
917 incl r9
918noname.88:
919
920 movzwl 14(r6),r2
921 bicl3 #-65536,4(r7),r3
922 movzwl 6(r7),r0
923 bicl2 #-65536,r0
924 bicl3 #-65536,12(r6),-188(fp)
925 bicl3 #-65536,r2,-192(fp)
926 mull3 r0,-188(fp),-180(fp)
927 mull2 r3,-188(fp)
928 mull3 r3,-192(fp),-184(fp)
929 mull2 r0,-192(fp)
930 addl3 -180(fp),-184(fp),r0
931 bicl3 #0,r0,-180(fp)
932 cmpl -180(fp),-184(fp)
933 bgequ noname.89
934 addl2 #65536,-192(fp)
935noname.89:
936 movzwl -178(fp),r0
937 bicl2 #-65536,r0
938 addl2 r0,-192(fp)
939 bicl3 #-65536,-180(fp),r0
940 ashl #16,r0,-184(fp)
941 addl3 -184(fp),-188(fp),r0
942 bicl3 #0,r0,-188(fp)
943 cmpl -188(fp),-184(fp)
944 bgequ noname.90
945 incl -192(fp)
946noname.90:
947 movl -188(fp),r1
948 movl -192(fp),r2
949 addl2 r1,r8
950 bicl2 #0,r8
951 cmpl r8,r1
952 bgequ noname.91
953 incl r2
954noname.91:
955 addl2 r2,r10
956 bicl2 #0,r10
957 cmpl r10,r2
958 bgequ noname.92
959 incl r9
960noname.92:
961
962 movzwl 10(r6),r2
963 bicl3 #-65536,8(r7),r3
964 movzwl 10(r7),r0
965 bicl2 #-65536,r0
966 bicl3 #-65536,8(r6),-204(fp)
967 bicl3 #-65536,r2,-208(fp)
968 mull3 r0,-204(fp),-196(fp)
969 mull2 r3,-204(fp)
970 mull3 r3,-208(fp),-200(fp)
971 mull2 r0,-208(fp)
972 addl3 -196(fp),-200(fp),r0
973 bicl3 #0,r0,-196(fp)
974 cmpl -196(fp),-200(fp)
975 bgequ noname.93
976 addl2 #65536,-208(fp)
977noname.93:
978 movzwl -194(fp),r0
979 bicl2 #-65536,r0
980 addl2 r0,-208(fp)
981 bicl3 #-65536,-196(fp),r0
982 ashl #16,r0,-200(fp)
983 addl3 -200(fp),-204(fp),r0
984 bicl3 #0,r0,-204(fp)
985 cmpl -204(fp),-200(fp)
986 bgequ noname.94
987 incl -208(fp)
988noname.94:
989 movl -204(fp),r1
990 movl -208(fp),r2
991 addl2 r1,r8
992 bicl2 #0,r8
993 cmpl r8,r1
994 bgequ noname.95
995 incl r2
996noname.95:
997 addl2 r2,r10
998 bicl2 #0,r10
999 cmpl r10,r2
1000 bgequ noname.96
1001 incl r9
1002noname.96:
1003
1004 movzwl 6(r6),r2
1005 bicl3 #-65536,12(r7),r3
1006 movzwl 14(r7),r0
1007 bicl2 #-65536,r0
1008 bicl3 #-65536,4(r6),-220(fp)
1009 bicl3 #-65536,r2,-224(fp)
1010 mull3 r0,-220(fp),-212(fp)
1011 mull2 r3,-220(fp)
1012 mull3 r3,-224(fp),-216(fp)
1013 mull2 r0,-224(fp)
1014 addl3 -212(fp),-216(fp),r0
1015 bicl3 #0,r0,-212(fp)
1016 cmpl -212(fp),-216(fp)
1017 bgequ noname.97
1018 addl2 #65536,-224(fp)
1019noname.97:
1020 movzwl -210(fp),r0
1021 bicl2 #-65536,r0
1022 addl2 r0,-224(fp)
1023 bicl3 #-65536,-212(fp),r0
1024 ashl #16,r0,-216(fp)
1025 addl3 -216(fp),-220(fp),r0
1026 bicl3 #0,r0,-220(fp)
1027 cmpl -220(fp),-216(fp)
1028 bgequ noname.98
1029 incl -224(fp)
1030noname.98:
1031 movl -220(fp),r1
1032 movl -224(fp),r2
1033 addl2 r1,r8
1034 bicl2 #0,r8
1035 cmpl r8,r1
1036 bgequ noname.99
1037 incl r2
1038noname.99:
1039 addl2 r2,r10
1040 bicl2 #0,r10
1041 cmpl r10,r2
1042 bgequ noname.100
1043 incl r9
1044noname.100:
1045
1046 movzwl 2(r6),r2
1047 bicl3 #-65536,16(r7),r3
1048 movzwl 18(r7),r0
1049 bicl2 #-65536,r0
1050 bicl3 #-65536,(r6),-236(fp)
1051 bicl3 #-65536,r2,-240(fp)
1052 mull3 r0,-236(fp),-228(fp)
1053 mull2 r3,-236(fp)
1054 mull3 r3,-240(fp),-232(fp)
1055 mull2 r0,-240(fp)
1056 addl3 -228(fp),-232(fp),r0
1057 bicl3 #0,r0,-228(fp)
1058 cmpl -228(fp),-232(fp)
1059 bgequ noname.101
1060 addl2 #65536,-240(fp)
1061noname.101:
1062 movzwl -226(fp),r0
1063 bicl2 #-65536,r0
1064 addl2 r0,-240(fp)
1065 bicl3 #-65536,-228(fp),r0
1066 ashl #16,r0,-232(fp)
1067 addl3 -232(fp),-236(fp),r0
1068 bicl3 #0,r0,-236(fp)
1069 cmpl -236(fp),-232(fp)
1070 bgequ noname.102
1071 incl -240(fp)
1072noname.102:
1073 movl -236(fp),r1
1074 movl -240(fp),r2
1075 addl2 r1,r8
1076 bicl2 #0,r8
1077 cmpl r8,r1
1078 bgequ noname.103
1079 incl r2
1080noname.103:
1081 addl2 r2,r10
1082 bicl2 #0,r10
1083 cmpl r10,r2
1084 bgequ noname.104
1085 incl r9
1086noname.104:
1087
1088 movl r8,16(r11)
1089
1090 clrl r8
1091
1092 movzwl 2(r6),r2
1093 bicl3 #-65536,20(r7),r3
1094 movzwl 22(r7),r0
1095 bicl2 #-65536,r0
1096 bicl3 #-65536,(r6),-252(fp)
1097 bicl3 #-65536,r2,-256(fp)
1098 mull3 r0,-252(fp),-244(fp)
1099 mull2 r3,-252(fp)
1100 mull3 r3,-256(fp),-248(fp)
1101 mull2 r0,-256(fp)
1102 addl3 -244(fp),-248(fp),r0
1103 bicl3 #0,r0,-244(fp)
1104 cmpl -244(fp),-248(fp)
1105 bgequ noname.105
1106 addl2 #65536,-256(fp)
1107noname.105:
1108 movzwl -242(fp),r0
1109 bicl2 #-65536,r0
1110 addl2 r0,-256(fp)
1111 bicl3 #-65536,-244(fp),r0
1112 ashl #16,r0,-248(fp)
1113 addl3 -248(fp),-252(fp),r0
1114 bicl3 #0,r0,-252(fp)
1115 cmpl -252(fp),-248(fp)
1116 bgequ noname.106
1117 incl -256(fp)
1118noname.106:
1119 movl -252(fp),r1
1120 movl -256(fp),r2
1121 addl2 r1,r10
1122 bicl2 #0,r10
1123 cmpl r10,r1
1124 bgequ noname.107
1125 incl r2
1126noname.107:
1127 addl2 r2,r9
1128 bicl2 #0,r9
1129 cmpl r9,r2
1130 bgequ noname.108
1131 incl r8
1132noname.108:
1133
1134 movzwl 6(r6),r2
1135 bicl3 #-65536,16(r7),r3
1136 movzwl 18(r7),r0
1137 bicl2 #-65536,r0
1138 bicl3 #-65536,4(r6),-268(fp)
1139 bicl3 #-65536,r2,-272(fp)
1140 mull3 r0,-268(fp),-260(fp)
1141 mull2 r3,-268(fp)
1142 mull3 r3,-272(fp),-264(fp)
1143 mull2 r0,-272(fp)
1144 addl3 -260(fp),-264(fp),r0
1145 bicl3 #0,r0,-260(fp)
1146 cmpl -260(fp),-264(fp)
1147 bgequ noname.109
1148 addl2 #65536,-272(fp)
1149noname.109:
1150 movzwl -258(fp),r0
1151 bicl2 #-65536,r0
1152 addl2 r0,-272(fp)
1153 bicl3 #-65536,-260(fp),r0
1154 ashl #16,r0,-264(fp)
1155 addl3 -264(fp),-268(fp),r0
1156 bicl3 #0,r0,-268(fp)
1157 cmpl -268(fp),-264(fp)
1158 bgequ noname.110
1159 incl -272(fp)
1160noname.110:
1161 movl -268(fp),r1
1162 movl -272(fp),r2
1163 addl2 r1,r10
1164 bicl2 #0,r10
1165 cmpl r10,r1
1166 bgequ noname.111
1167 incl r2
1168noname.111:
1169 addl2 r2,r9
1170 bicl2 #0,r9
1171 cmpl r9,r2
1172 bgequ noname.112
1173 incl r8
1174noname.112:
1175
1176 movzwl 10(r6),r2
1177 bicl3 #-65536,12(r7),r3
1178 movzwl 14(r7),r0
1179 bicl2 #-65536,r0
1180 bicl3 #-65536,8(r6),-284(fp)
1181 bicl3 #-65536,r2,-288(fp)
1182 mull3 r0,-284(fp),-276(fp)
1183 mull2 r3,-284(fp)
1184 mull3 r3,-288(fp),-280(fp)
1185 mull2 r0,-288(fp)
1186 addl3 -276(fp),-280(fp),r0
1187 bicl3 #0,r0,-276(fp)
1188 cmpl -276(fp),-280(fp)
1189 bgequ noname.113
1190 addl2 #65536,-288(fp)
1191noname.113:
1192 movzwl -274(fp),r0
1193 bicl2 #-65536,r0
1194 addl2 r0,-288(fp)
1195 bicl3 #-65536,-276(fp),r0
1196 ashl #16,r0,-280(fp)
1197 addl3 -280(fp),-284(fp),r0
1198 bicl3 #0,r0,-284(fp)
1199 cmpl -284(fp),-280(fp)
1200 bgequ noname.114
1201 incl -288(fp)
1202noname.114:
1203 movl -284(fp),r1
1204 movl -288(fp),r2
1205 addl2 r1,r10
1206 bicl2 #0,r10
1207 cmpl r10,r1
1208 bgequ noname.115
1209 incl r2
1210noname.115:
1211 addl2 r2,r9
1212 bicl2 #0,r9
1213 cmpl r9,r2
1214 bgequ noname.116
1215 incl r8
1216noname.116:
1217
1218 movzwl 14(r6),r2
1219 bicl3 #-65536,8(r7),r3
1220 movzwl 10(r7),r0
1221 bicl2 #-65536,r0
1222 bicl3 #-65536,12(r6),-300(fp)
1223 bicl3 #-65536,r2,-304(fp)
1224 mull3 r0,-300(fp),-292(fp)
1225 mull2 r3,-300(fp)
1226 mull3 r3,-304(fp),-296(fp)
1227 mull2 r0,-304(fp)
1228 addl3 -292(fp),-296(fp),r0
1229 bicl3 #0,r0,-292(fp)
1230 cmpl -292(fp),-296(fp)
1231 bgequ noname.117
1232 addl2 #65536,-304(fp)
1233noname.117:
1234 movzwl -290(fp),r0
1235 bicl2 #-65536,r0
1236 addl2 r0,-304(fp)
1237 bicl3 #-65536,-292(fp),r0
1238 ashl #16,r0,-296(fp)
1239 addl3 -296(fp),-300(fp),r0
1240 bicl3 #0,r0,-300(fp)
1241 cmpl -300(fp),-296(fp)
1242 bgequ noname.118
1243 incl -304(fp)
1244noname.118:
1245 movl -300(fp),r1
1246 movl -304(fp),r2
1247 addl2 r1,r10
1248 bicl2 #0,r10
1249 cmpl r10,r1
1250 bgequ noname.119
1251 incl r2
1252noname.119:
1253 addl2 r2,r9
1254 bicl2 #0,r9
1255 cmpl r9,r2
1256 bgequ noname.120
1257 incl r8
1258noname.120:
1259
1260 movzwl 18(r6),r2
1261 bicl3 #-65536,4(r7),r3
1262 movzwl 6(r7),r0
1263 bicl2 #-65536,r0
1264 bicl3 #-65536,16(r6),-316(fp)
1265 bicl3 #-65536,r2,-320(fp)
1266 mull3 r0,-316(fp),-308(fp)
1267 mull2 r3,-316(fp)
1268 mull3 r3,-320(fp),-312(fp)
1269 mull2 r0,-320(fp)
1270 addl3 -308(fp),-312(fp),r0
1271 bicl3 #0,r0,-308(fp)
1272 cmpl -308(fp),-312(fp)
1273 bgequ noname.121
1274 addl2 #65536,-320(fp)
1275noname.121:
1276 movzwl -306(fp),r0
1277 bicl2 #-65536,r0
1278 addl2 r0,-320(fp)
1279 bicl3 #-65536,-308(fp),r0
1280 ashl #16,r0,-312(fp)
1281 addl3 -312(fp),-316(fp),r0
1282 bicl3 #0,r0,-316(fp)
1283 cmpl -316(fp),-312(fp)
1284 bgequ noname.122
1285 incl -320(fp)
1286noname.122:
1287 movl -316(fp),r1
1288 movl -320(fp),r2
1289 addl2 r1,r10
1290 bicl2 #0,r10
1291 cmpl r10,r1
1292 bgequ noname.123
1293 incl r2
1294
1295noname.123:
1296 addl2 r2,r9
1297 bicl2 #0,r9
1298 cmpl r9,r2
1299 bgequ noname.124
1300 incl r8
1301noname.124:
1302
1303 movzwl 22(r6),r2
1304 bicl3 #-65536,(r7),r3
1305 movzwl 2(r7),r0
1306 bicl2 #-65536,r0
1307 bicl3 #-65536,20(r6),-332(fp)
1308 bicl3 #-65536,r2,-336(fp)
1309 mull3 r0,-332(fp),-324(fp)
1310 mull2 r3,-332(fp)
1311 mull3 r3,-336(fp),-328(fp)
1312 mull2 r0,-336(fp)
1313 addl3 -324(fp),-328(fp),r0
1314 bicl3 #0,r0,-324(fp)
1315 cmpl -324(fp),-328(fp)
1316 bgequ noname.125
1317 addl2 #65536,-336(fp)
1318noname.125:
1319 movzwl -322(fp),r0
1320 bicl2 #-65536,r0
1321 addl2 r0,-336(fp)
1322 bicl3 #-65536,-324(fp),r0
1323 ashl #16,r0,-328(fp)
1324 addl3 -328(fp),-332(fp),r0
1325 bicl3 #0,r0,-332(fp)
1326 cmpl -332(fp),-328(fp)
1327 bgequ noname.126
1328 incl -336(fp)
1329noname.126:
1330 movl -332(fp),r1
1331 movl -336(fp),r2
1332 addl2 r1,r10
1333 bicl2 #0,r10
1334 cmpl r10,r1
1335 bgequ noname.127
1336 incl r2
1337noname.127:
1338 addl2 r2,r9
1339 bicl2 #0,r9
1340 cmpl r9,r2
1341 bgequ noname.128
1342 incl r8
1343noname.128:
1344
1345 movl r10,20(r11)
1346
1347 clrl r10
1348
1349 movzwl 26(r6),r2
1350 bicl3 #-65536,(r7),r3
1351 movzwl 2(r7),r0
1352 bicl2 #-65536,r0
1353 bicl3 #-65536,24(r6),-348(fp)
1354 bicl3 #-65536,r2,-352(fp)
1355 mull3 r0,-348(fp),-340(fp)
1356 mull2 r3,-348(fp)
1357 mull3 r3,-352(fp),-344(fp)
1358 mull2 r0,-352(fp)
1359 addl3 -340(fp),-344(fp),r0
1360 bicl3 #0,r0,-340(fp)
1361 cmpl -340(fp),-344(fp)
1362 bgequ noname.129
1363 addl2 #65536,-352(fp)
1364noname.129:
1365 movzwl -338(fp),r0
1366 bicl2 #-65536,r0
1367 addl2 r0,-352(fp)
1368 bicl3 #-65536,-340(fp),r0
1369 ashl #16,r0,-344(fp)
1370 addl3 -344(fp),-348(fp),r0
1371 bicl3 #0,r0,-348(fp)
1372 cmpl -348(fp),-344(fp)
1373 bgequ noname.130
1374 incl -352(fp)
1375noname.130:
1376 movl -348(fp),r1
1377 movl -352(fp),r2
1378 addl2 r1,r9
1379 bicl2 #0,r9
1380 cmpl r9,r1
1381 bgequ noname.131
1382 incl r2
1383noname.131:
1384 addl2 r2,r8
1385 bicl2 #0,r8
1386 cmpl r8,r2
1387 bgequ noname.132
1388 incl r10
1389noname.132:
1390
1391 movzwl 22(r6),r2
1392 bicl3 #-65536,4(r7),r3
1393 movzwl 6(r7),r0
1394 bicl2 #-65536,r0
1395 bicl3 #-65536,20(r6),-364(fp)
1396 bicl3 #-65536,r2,-368(fp)
1397 mull3 r0,-364(fp),-356(fp)
1398 mull2 r3,-364(fp)
1399 mull3 r3,-368(fp),-360(fp)
1400 mull2 r0,-368(fp)
1401 addl3 -356(fp),-360(fp),r0
1402 bicl3 #0,r0,-356(fp)
1403 cmpl -356(fp),-360(fp)
1404 bgequ noname.133
1405 addl2 #65536,-368(fp)
1406noname.133:
1407 movzwl -354(fp),r0
1408 bicl2 #-65536,r0
1409 addl2 r0,-368(fp)
1410 bicl3 #-65536,-356(fp),r0
1411 ashl #16,r0,-360(fp)
1412 addl3 -360(fp),-364(fp),r0
1413 bicl3 #0,r0,-364(fp)
1414 cmpl -364(fp),-360(fp)
1415 bgequ noname.134
1416 incl -368(fp)
1417noname.134:
1418 movl -364(fp),r1
1419 movl -368(fp),r2
1420 addl2 r1,r9
1421 bicl2 #0,r9
1422 cmpl r9,r1
1423 bgequ noname.135
1424 incl r2
1425noname.135:
1426 addl2 r2,r8
1427 bicl2 #0,r8
1428 cmpl r8,r2
1429 bgequ noname.136
1430 incl r10
1431noname.136:
1432
1433 movzwl 18(r6),r2
1434 bicl3 #-65536,8(r7),r3
1435 movzwl 10(r7),r0
1436 bicl2 #-65536,r0
1437 bicl3 #-65536,16(r6),-380(fp)
1438 bicl3 #-65536,r2,-384(fp)
1439 mull3 r0,-380(fp),-372(fp)
1440 mull2 r3,-380(fp)
1441 mull3 r3,-384(fp),-376(fp)
1442 mull2 r0,-384(fp)
1443 addl3 -372(fp),-376(fp),r0
1444 bicl3 #0,r0,-372(fp)
1445 cmpl -372(fp),-376(fp)
1446 bgequ noname.137
1447 addl2 #65536,-384(fp)
1448noname.137:
1449 movzwl -370(fp),r0
1450 bicl2 #-65536,r0
1451 addl2 r0,-384(fp)
1452 bicl3 #-65536,-372(fp),r0
1453 ashl #16,r0,-376(fp)
1454 addl3 -376(fp),-380(fp),r0
1455 bicl3 #0,r0,-380(fp)
1456 cmpl -380(fp),-376(fp)
1457 bgequ noname.138
1458 incl -384(fp)
1459noname.138:
1460 movl -380(fp),r1
1461 movl -384(fp),r2
1462 addl2 r1,r9
1463 bicl2 #0,r9
1464 cmpl r9,r1
1465 bgequ noname.139
1466 incl r2
1467noname.139:
1468 addl2 r2,r8
1469 bicl2 #0,r8
1470 cmpl r8,r2
1471 bgequ noname.140
1472 incl r10
1473noname.140:
1474
1475 movzwl 14(r6),r2
1476 bicl3 #-65536,12(r7),r3
1477 movzwl 14(r7),r0
1478 bicl2 #-65536,r0
1479 bicl3 #-65536,12(r6),-396(fp)
1480 bicl3 #-65536,r2,-400(fp)
1481 mull3 r0,-396(fp),-388(fp)
1482 mull2 r3,-396(fp)
1483 mull3 r3,-400(fp),-392(fp)
1484 mull2 r0,-400(fp)
1485 addl3 -388(fp),-392(fp),r0
1486 bicl3 #0,r0,-388(fp)
1487 cmpl -388(fp),-392(fp)
1488 bgequ noname.141
1489 addl2 #65536,-400(fp)
1490noname.141:
1491 movzwl -386(fp),r0
1492 bicl2 #-65536,r0
1493 addl2 r0,-400(fp)
1494 bicl3 #-65536,-388(fp),r0
1495 ashl #16,r0,-392(fp)
1496 addl3 -392(fp),-396(fp),r0
1497 bicl3 #0,r0,-396(fp)
1498 cmpl -396(fp),-392(fp)
1499 bgequ noname.142
1500 incl -400(fp)
1501noname.142:
1502 movl -396(fp),r1
1503 movl -400(fp),r2
1504 addl2 r1,r9
1505 bicl2 #0,r9
1506 cmpl r9,r1
1507 bgequ noname.143
1508 incl r2
1509noname.143:
1510 addl2 r2,r8
1511 bicl2 #0,r8
1512 cmpl r8,r2
1513 bgequ noname.144
1514 incl r10
1515noname.144:
1516
1517 movzwl 10(r6),r2
1518 bicl3 #-65536,16(r7),r3
1519 movzwl 18(r7),r0
1520 bicl2 #-65536,r0
1521 bicl3 #-65536,8(r6),-412(fp)
1522 bicl3 #-65536,r2,-416(fp)
1523 mull3 r0,-412(fp),-404(fp)
1524 mull2 r3,-412(fp)
1525 mull3 r3,-416(fp),-408(fp)
1526 mull2 r0,-416(fp)
1527 addl3 -404(fp),-408(fp),r0
1528 bicl3 #0,r0,-404(fp)
1529 cmpl -404(fp),-408(fp)
1530 bgequ noname.145
1531 addl2 #65536,-416(fp)
1532noname.145:
1533 movzwl -402(fp),r0
1534 bicl2 #-65536,r0
1535 addl2 r0,-416(fp)
1536 bicl3 #-65536,-404(fp),r0
1537 ashl #16,r0,-408(fp)
1538 addl3 -408(fp),-412(fp),r0
1539 bicl3 #0,r0,-412(fp)
1540 cmpl -412(fp),-408(fp)
1541 bgequ noname.146
1542 incl -416(fp)
1543noname.146:
1544 movl -412(fp),r1
1545 movl -416(fp),r2
1546 addl2 r1,r9
1547 bicl2 #0,r9
1548 cmpl r9,r1
1549 bgequ noname.147
1550 incl r2
1551noname.147:
1552 addl2 r2,r8
1553 bicl2 #0,r8
1554 cmpl r8,r2
1555 bgequ noname.148
1556 incl r10
1557noname.148:
1558
1559 movzwl 6(r6),r2
1560 bicl3 #-65536,20(r7),r3
1561 movzwl 22(r7),r0
1562 bicl2 #-65536,r0
1563 bicl3 #-65536,4(r6),-428(fp)
1564 bicl3 #-65536,r2,-432(fp)
1565 mull3 r0,-428(fp),-420(fp)
1566 mull2 r3,-428(fp)
1567 mull3 r3,-432(fp),-424(fp)
1568 mull2 r0,-432(fp)
1569 addl3 -420(fp),-424(fp),r0
1570 bicl3 #0,r0,-420(fp)
1571 cmpl -420(fp),-424(fp)
1572 bgequ noname.149
1573 addl2 #65536,-432(fp)
1574noname.149:
1575 movzwl -418(fp),r0
1576 bicl2 #-65536,r0
1577 addl2 r0,-432(fp)
1578 bicl3 #-65536,-420(fp),r0
1579 ashl #16,r0,-424(fp)
1580 addl3 -424(fp),-428(fp),r0
1581 bicl3 #0,r0,-428(fp)
1582 cmpl -428(fp),-424(fp)
1583 bgequ noname.150
1584 incl -432(fp)
1585noname.150:
1586 movl -428(fp),r1
1587 movl -432(fp),r2
1588 addl2 r1,r9
1589 bicl2 #0,r9
1590 cmpl r9,r1
1591 bgequ noname.151
1592 incl r2
1593noname.151:
1594 addl2 r2,r8
1595 bicl2 #0,r8
1596 cmpl r8,r2
1597 bgequ noname.152
1598 incl r10
1599noname.152:
1600
1601 movzwl 2(r6),r2
1602 bicl3 #-65536,24(r7),r3
1603 movzwl 26(r7),r0
1604 bicl2 #-65536,r0
1605 bicl3 #-65536,(r6),-444(fp)
1606 bicl3 #-65536,r2,-448(fp)
1607 mull3 r0,-444(fp),-436(fp)
1608 mull2 r3,-444(fp)
1609 mull3 r3,-448(fp),-440(fp)
1610 mull2 r0,-448(fp)
1611 addl3 -436(fp),-440(fp),r0
1612 bicl3 #0,r0,-436(fp)
1613 cmpl -436(fp),-440(fp)
1614 bgequ noname.153
1615 addl2 #65536,-448(fp)
1616noname.153:
1617 movzwl -434(fp),r0
1618 bicl2 #-65536,r0
1619 addl2 r0,-448(fp)
1620 bicl3 #-65536,-436(fp),r0
1621 ashl #16,r0,-440(fp)
1622 addl3 -440(fp),-444(fp),r0
1623 bicl3 #0,r0,-444(fp)
1624 cmpl -444(fp),-440(fp)
1625 bgequ noname.154
1626 incl -448(fp)
1627noname.154:
1628 movl -444(fp),r1
1629 movl -448(fp),r2
1630 addl2 r1,r9
1631 bicl2 #0,r9
1632 cmpl r9,r1
1633 bgequ noname.155
1634 incl r2
1635noname.155:
1636 addl2 r2,r8
1637 bicl2 #0,r8
1638 cmpl r8,r2
1639 bgequ noname.156
1640 incl r10
1641noname.156:
1642
1643 movl r9,24(r11)
1644
1645 clrl r9
1646
1647 movzwl 2(r6),r2
1648 bicl3 #-65536,28(r7),r3
1649 movzwl 30(r7),r0
1650 bicl2 #-65536,r0
1651 bicl3 #-65536,(r6),-460(fp)
1652 bicl3 #-65536,r2,-464(fp)
1653 mull3 r0,-460(fp),-452(fp)
1654 mull2 r3,-460(fp)
1655 mull3 r3,-464(fp),-456(fp)
1656 mull2 r0,-464(fp)
1657 addl3 -452(fp),-456(fp),r0
1658 bicl3 #0,r0,-452(fp)
1659 cmpl -452(fp),-456(fp)
1660 bgequ noname.157
1661 addl2 #65536,-464(fp)
1662noname.157:
1663 movzwl -450(fp),r0
1664 bicl2 #-65536,r0
1665 addl2 r0,-464(fp)
1666 bicl3 #-65536,-452(fp),r0
1667 ashl #16,r0,-456(fp)
1668 addl3 -456(fp),-460(fp),r0
1669 bicl3 #0,r0,-460(fp)
1670 cmpl -460(fp),-456(fp)
1671 bgequ noname.158
1672 incl -464(fp)
1673noname.158:
1674 movl -460(fp),r1
1675 movl -464(fp),r2
1676 addl2 r1,r8
1677 bicl2 #0,r8
1678 cmpl r8,r1
1679 bgequ noname.159
1680 incl r2
1681noname.159:
1682 addl2 r2,r10
1683 bicl2 #0,r10
1684 cmpl r10,r2
1685 bgequ noname.160
1686 incl r9
1687noname.160:
1688
1689 movzwl 6(r6),r2
1690 bicl3 #-65536,24(r7),r3
1691 movzwl 26(r7),r0
1692 bicl2 #-65536,r0
1693 bicl3 #-65536,4(r6),-476(fp)
1694 bicl3 #-65536,r2,-480(fp)
1695 mull3 r0,-476(fp),-468(fp)
1696 mull2 r3,-476(fp)
1697 mull3 r3,-480(fp),-472(fp)
1698 mull2 r0,-480(fp)
1699 addl3 -468(fp),-472(fp),r0
1700 bicl3 #0,r0,-468(fp)
1701 cmpl -468(fp),-472(fp)
1702 bgequ noname.161
1703 addl2 #65536,-480(fp)
1704noname.161:
1705 movzwl -466(fp),r0
1706 bicl2 #-65536,r0
1707 addl2 r0,-480(fp)
1708 bicl3 #-65536,-468(fp),r0
1709 ashl #16,r0,-472(fp)
1710 addl3 -472(fp),-476(fp),r0
1711 bicl3 #0,r0,-476(fp)
1712 cmpl -476(fp),-472(fp)
1713 bgequ noname.162
1714 incl -480(fp)
1715noname.162:
1716 movl -476(fp),r1
1717 movl -480(fp),r2
1718 addl2 r1,r8
1719 bicl2 #0,r8
1720 cmpl r8,r1
1721 bgequ noname.163
1722 incl r2
1723noname.163:
1724 addl2 r2,r10
1725 bicl2 #0,r10
1726 cmpl r10,r2
1727 bgequ noname.164
1728 incl r9
1729noname.164:
1730
1731 movzwl 10(r6),r2
1732 bicl3 #-65536,20(r7),r3
1733 movzwl 22(r7),r0
1734 bicl2 #-65536,r0
1735 bicl3 #-65536,8(r6),-492(fp)
1736 bicl3 #-65536,r2,-496(fp)
1737 mull3 r0,-492(fp),-484(fp)
1738 mull2 r3,-492(fp)
1739 mull3 r3,-496(fp),-488(fp)
1740 mull2 r0,-496(fp)
1741 addl3 -484(fp),-488(fp),r0
1742 bicl3 #0,r0,-484(fp)
1743 cmpl -484(fp),-488(fp)
1744 bgequ noname.165
1745 addl2 #65536,-496(fp)
1746noname.165:
1747 movzwl -482(fp),r0
1748 bicl2 #-65536,r0
1749 addl2 r0,-496(fp)
1750 bicl3 #-65536,-484(fp),r0
1751 ashl #16,r0,-488(fp)
1752 addl3 -488(fp),-492(fp),r0
1753 bicl3 #0,r0,-492(fp)
1754 cmpl -492(fp),-488(fp)
1755 bgequ noname.166
1756 incl -496(fp)
1757noname.166:
1758 movl -492(fp),r1
1759 movl -496(fp),r2
1760 addl2 r1,r8
1761 bicl2 #0,r8
1762 cmpl r8,r1
1763 bgequ noname.167
1764 incl r2
1765noname.167:
1766 addl2 r2,r10
1767 bicl2 #0,r10
1768 cmpl r10,r2
1769 bgequ noname.168
1770 incl r9
1771noname.168:
1772
1773 movzwl 14(r6),r2
1774 bicl3 #-65536,16(r7),r3
1775 movzwl 18(r7),r0
1776 bicl2 #-65536,r0
1777 bicl3 #-65536,12(r6),-508(fp)
1778 bicl3 #-65536,r2,-512(fp)
1779 mull3 r0,-508(fp),-500(fp)
1780 mull2 r3,-508(fp)
1781 mull3 r3,-512(fp),-504(fp)
1782 mull2 r0,-512(fp)
1783 addl3 -500(fp),-504(fp),r0
1784 bicl3 #0,r0,-500(fp)
1785 cmpl -500(fp),-504(fp)
1786 bgequ noname.169
1787 addl2 #65536,-512(fp)
1788noname.169:
1789 movzwl -498(fp),r0
1790 bicl2 #-65536,r0
1791 addl2 r0,-512(fp)
1792 bicl3 #-65536,-500(fp),r0
1793 ashl #16,r0,-504(fp)
1794 addl3 -504(fp),-508(fp),r0
1795 bicl3 #0,r0,-508(fp)
1796 cmpl -508(fp),-504(fp)
1797 bgequ noname.170
1798 incl -512(fp)
1799noname.170:
1800 movl -508(fp),r1
1801 movl -512(fp),r2
1802 addl2 r1,r8
1803 bicl2 #0,r8
1804 cmpl r8,r1
1805 bgequ noname.171
1806 incl r2
1807noname.171:
1808 addl2 r2,r10
1809 bicl2 #0,r10
1810 cmpl r10,r2
1811 bgequ noname.172
1812 incl r9
1813noname.172:
1814
1815 movzwl 18(r6),r2
1816 bicl3 #-65536,12(r7),r3
1817 movzwl 14(r7),r0
1818 bicl2 #-65536,r0
1819 bicl3 #-65536,16(r6),-524(fp)
1820 bicl3 #-65536,r2,-528(fp)
1821 mull3 r0,-524(fp),-516(fp)
1822 mull2 r3,-524(fp)
1823 mull3 r3,-528(fp),-520(fp)
1824 mull2 r0,-528(fp)
1825 addl3 -516(fp),-520(fp),r0
1826 bicl3 #0,r0,-516(fp)
1827 cmpl -516(fp),-520(fp)
1828 bgequ noname.173
1829 addl2 #65536,-528(fp)
1830noname.173:
1831 movzwl -514(fp),r0
1832 bicl2 #-65536,r0
1833 addl2 r0,-528(fp)
1834 bicl3 #-65536,-516(fp),r0
1835 ashl #16,r0,-520(fp)
1836 addl3 -520(fp),-524(fp),r0
1837 bicl3 #0,r0,-524(fp)
1838 cmpl -524(fp),-520(fp)
1839 bgequ noname.174
1840 incl -528(fp)
1841noname.174:
1842 movl -524(fp),r1
1843 movl -528(fp),r2
1844 addl2 r1,r8
1845 bicl2 #0,r8
1846 cmpl r8,r1
1847 bgequ noname.175
1848 incl r2
1849noname.175:
1850 addl2 r2,r10
1851 bicl2 #0,r10
1852 cmpl r10,r2
1853 bgequ noname.176
1854 incl r9
1855noname.176:
1856
1857 movzwl 22(r6),r2
1858 bicl3 #-65536,8(r7),r3
1859 movzwl 10(r7),r0
1860 bicl2 #-65536,r0
1861 bicl3 #-65536,20(r6),-540(fp)
1862 bicl3 #-65536,r2,-544(fp)
1863 mull3 r0,-540(fp),-532(fp)
1864 mull2 r3,-540(fp)
1865 mull3 r3,-544(fp),-536(fp)
1866 mull2 r0,-544(fp)
1867 addl3 -532(fp),-536(fp),r0
1868 bicl3 #0,r0,-532(fp)
1869 cmpl -532(fp),-536(fp)
1870 bgequ noname.177
1871 addl2 #65536,-544(fp)
1872noname.177:
1873 movzwl -530(fp),r0
1874 bicl2 #-65536,r0
1875 addl2 r0,-544(fp)
1876 bicl3 #-65536,-532(fp),r0
1877 ashl #16,r0,-536(fp)
1878 addl3 -536(fp),-540(fp),r0
1879 bicl3 #0,r0,-540(fp)
1880 cmpl -540(fp),-536(fp)
1881 bgequ noname.178
1882 incl -544(fp)
1883noname.178:
1884 movl -540(fp),r1
1885 movl -544(fp),r2
1886 addl2 r1,r8
1887 bicl2 #0,r8
1888 cmpl r8,r1
1889 bgequ noname.179
1890 incl r2
1891noname.179:
1892 addl2 r2,r10
1893 bicl2 #0,r10
1894 cmpl r10,r2
1895 bgequ noname.180
1896 incl r9
1897noname.180:
1898
1899 movzwl 26(r6),r2
1900 bicl3 #-65536,4(r7),r3
1901 movzwl 6(r7),r0
1902 bicl2 #-65536,r0
1903 bicl3 #-65536,24(r6),-556(fp)
1904 bicl3 #-65536,r2,-560(fp)
1905 mull3 r0,-556(fp),-548(fp)
1906 mull2 r3,-556(fp)
1907 mull3 r3,-560(fp),-552(fp)
1908 mull2 r0,-560(fp)
1909 addl3 -548(fp),-552(fp),r0
1910 bicl3 #0,r0,-548(fp)
1911 cmpl -548(fp),-552(fp)
1912 bgequ noname.181
1913 addl2 #65536,-560(fp)
1914noname.181:
1915 movzwl -546(fp),r0
1916 bicl2 #-65536,r0
1917 addl2 r0,-560(fp)
1918 bicl3 #-65536,-548(fp),r0
1919 ashl #16,r0,-552(fp)
1920 addl3 -552(fp),-556(fp),r0
1921 bicl3 #0,r0,-556(fp)
1922 cmpl -556(fp),-552(fp)
1923 bgequ noname.182
1924 incl -560(fp)
1925noname.182:
1926 movl -556(fp),r1
1927 movl -560(fp),r2
1928 addl2 r1,r8
1929 bicl2 #0,r8
1930 cmpl r8,r1
1931 bgequ noname.183
1932 incl r2
1933noname.183:
1934 addl2 r2,r10
1935 bicl2 #0,r10
1936 cmpl r10,r2
1937 bgequ noname.184
1938 incl r9
1939noname.184:
1940
1941 movzwl 30(r6),r2
1942 bicl3 #-65536,(r7),r3
1943 movzwl 2(r7),r0
1944 bicl2 #-65536,r0
1945 bicl3 #-65536,28(r6),-572(fp)
1946 bicl3 #-65536,r2,-576(fp)
1947 mull3 r0,-572(fp),-564(fp)
1948 mull2 r3,-572(fp)
1949 mull3 r3,-576(fp),-568(fp)
1950 mull2 r0,-576(fp)
1951 addl3 -564(fp),-568(fp),r0
1952 bicl3 #0,r0,-564(fp)
1953 cmpl -564(fp),-568(fp)
1954 bgequ noname.185
1955 addl2 #65536,-576(fp)
1956noname.185:
1957 movzwl -562(fp),r0
1958 bicl2 #-65536,r0
1959 addl2 r0,-576(fp)
1960 bicl3 #-65536,-564(fp),r0
1961 ashl #16,r0,-568(fp)
1962 addl3 -568(fp),-572(fp),r0
1963 bicl3 #0,r0,-572(fp)
1964 cmpl -572(fp),-568(fp)
1965 bgequ noname.186
1966 incl -576(fp)
1967noname.186:
1968 movl -572(fp),r1
1969 movl -576(fp),r2
1970 addl2 r1,r8
1971 bicl2 #0,r8
1972 cmpl r8,r1
1973 bgequ noname.187
1974 incl r2
1975noname.187:
1976 addl2 r2,r10
1977 bicl2 #0,r10
1978 cmpl r10,r2
1979 bgequ noname.188
1980 incl r9
1981noname.188:
1982
1983 movl r8,28(r11)
1984
1985 clrl r8
1986
1987 movzwl 30(r6),r2
1988 bicl3 #-65536,4(r7),r3
1989 movzwl 6(r7),r0
1990 bicl2 #-65536,r0
1991 bicl3 #-65536,28(r6),-588(fp)
1992 bicl3 #-65536,r2,-592(fp)
1993 mull3 r0,-588(fp),-580(fp)
1994 mull2 r3,-588(fp)
1995 mull3 r3,-592(fp),-584(fp)
1996 mull2 r0,-592(fp)
1997 addl3 -580(fp),-584(fp),r0
1998 bicl3 #0,r0,-580(fp)
1999 cmpl -580(fp),-584(fp)
2000 bgequ noname.189
2001 addl2 #65536,-592(fp)
2002noname.189:
2003 movzwl -578(fp),r0
2004 bicl2 #-65536,r0
2005 addl2 r0,-592(fp)
2006 bicl3 #-65536,-580(fp),r0
2007 ashl #16,r0,-584(fp)
2008 addl3 -584(fp),-588(fp),r0
2009 bicl3 #0,r0,-588(fp)
2010 cmpl -588(fp),-584(fp)
2011 bgequ noname.190
2012 incl -592(fp)
2013noname.190:
2014 movl -588(fp),r1
2015 movl -592(fp),r2
2016 addl2 r1,r10
2017 bicl2 #0,r10
2018 cmpl r10,r1
2019 bgequ noname.191
2020 incl r2
2021noname.191:
2022 addl2 r2,r9
2023 bicl2 #0,r9
2024 cmpl r9,r2
2025 bgequ noname.192
2026 incl r8
2027noname.192:
2028
2029 movzwl 26(r6),r2
2030 bicl3 #-65536,8(r7),r3
2031 movzwl 10(r7),r0
2032 bicl2 #-65536,r0
2033 bicl3 #-65536,24(r6),-604(fp)
2034 bicl3 #-65536,r2,-608(fp)
2035 mull3 r0,-604(fp),-596(fp)
2036 mull2 r3,-604(fp)
2037 mull3 r3,-608(fp),-600(fp)
2038 mull2 r0,-608(fp)
2039 addl3 -596(fp),-600(fp),r0
2040 bicl3 #0,r0,-596(fp)
2041 cmpl -596(fp),-600(fp)
2042 bgequ noname.193
2043 addl2 #65536,-608(fp)
2044noname.193:
2045 movzwl -594(fp),r0
2046 bicl2 #-65536,r0
2047 addl2 r0,-608(fp)
2048 bicl3 #-65536,-596(fp),r0
2049 ashl #16,r0,-600(fp)
2050 addl3 -600(fp),-604(fp),r0
2051 bicl3 #0,r0,-604(fp)
2052 cmpl -604(fp),-600(fp)
2053 bgequ noname.194
2054 incl -608(fp)
2055noname.194:
2056 movl -604(fp),r1
2057 movl -608(fp),r2
2058 addl2 r1,r10
2059 bicl2 #0,r10
2060 cmpl r10,r1
2061 bgequ noname.195
2062 incl r2
2063noname.195:
2064 addl2 r2,r9
2065 bicl2 #0,r9
2066 cmpl r9,r2
2067 bgequ noname.196
2068 incl r8
2069noname.196:
2070
2071 movzwl 22(r6),r2
2072 bicl3 #-65536,12(r7),r3
2073 movzwl 14(r7),r0
2074 bicl2 #-65536,r0
2075 bicl3 #-65536,20(r6),-620(fp)
2076 bicl3 #-65536,r2,-624(fp)
2077 mull3 r0,-620(fp),-612(fp)
2078 mull2 r3,-620(fp)
2079 mull3 r3,-624(fp),-616(fp)
2080 mull2 r0,-624(fp)
2081 addl3 -612(fp),-616(fp),r0
2082 bicl3 #0,r0,-612(fp)
2083 cmpl -612(fp),-616(fp)
2084 bgequ noname.197
2085 addl2 #65536,-624(fp)
2086noname.197:
2087 movzwl -610(fp),r0
2088 bicl2 #-65536,r0
2089 addl2 r0,-624(fp)
2090 bicl3 #-65536,-612(fp),r0
2091 ashl #16,r0,-616(fp)
2092 addl3 -616(fp),-620(fp),r0
2093 bicl3 #0,r0,-620(fp)
2094 cmpl -620(fp),-616(fp)
2095 bgequ noname.198
2096 incl -624(fp)
2097noname.198:
2098 movl -620(fp),r1
2099 movl -624(fp),r2
2100 addl2 r1,r10
2101 bicl2 #0,r10
2102 cmpl r10,r1
2103 bgequ noname.199
2104 incl r2
2105noname.199:
2106 addl2 r2,r9
2107 bicl2 #0,r9
2108 cmpl r9,r2
2109 bgequ noname.200
2110 incl r8
2111noname.200:
2112
2113 movzwl 18(r6),r2
2114 bicl3 #-65536,16(r7),r3
2115 movzwl 18(r7),r0
2116 bicl2 #-65536,r0
2117 bicl3 #-65536,16(r6),-636(fp)
2118 bicl3 #-65536,r2,-640(fp)
2119 mull3 r0,-636(fp),-628(fp)
2120 mull2 r3,-636(fp)
2121 mull3 r3,-640(fp),-632(fp)
2122 mull2 r0,-640(fp)
2123 addl3 -628(fp),-632(fp),r0
2124 bicl3 #0,r0,-628(fp)
2125 cmpl -628(fp),-632(fp)
2126 bgequ noname.201
2127 addl2 #65536,-640(fp)
2128noname.201:
2129 movzwl -626(fp),r0
2130 bicl2 #-65536,r0
2131 addl2 r0,-640(fp)
2132 bicl3 #-65536,-628(fp),r0
2133 ashl #16,r0,-632(fp)
2134 addl3 -632(fp),-636(fp),r0
2135 bicl3 #0,r0,-636(fp)
2136 cmpl -636(fp),-632(fp)
2137 bgequ noname.202
2138 incl -640(fp)
2139noname.202:
2140 movl -636(fp),r1
2141 movl -640(fp),r2
2142 addl2 r1,r10
2143 bicl2 #0,r10
2144 cmpl r10,r1
2145 bgequ noname.203
2146 incl r2
2147noname.203:
2148 addl2 r2,r9
2149 bicl2 #0,r9
2150 cmpl r9,r2
2151 bgequ noname.204
2152 incl r8
2153noname.204:
2154
2155 movzwl 14(r6),r2
2156 bicl3 #-65536,20(r7),r3
2157 movzwl 22(r7),r0
2158 bicl2 #-65536,r0
2159 bicl3 #-65536,12(r6),-652(fp)
2160 bicl3 #-65536,r2,-656(fp)
2161 mull3 r0,-652(fp),-644(fp)
2162 mull2 r3,-652(fp)
2163 mull3 r3,-656(fp),-648(fp)
2164 mull2 r0,-656(fp)
2165 addl3 -644(fp),-648(fp),r0
2166 bicl3 #0,r0,-644(fp)
2167 cmpl -644(fp),-648(fp)
2168 bgequ noname.205
2169 addl2 #65536,-656(fp)
2170noname.205:
2171 movzwl -642(fp),r0
2172 bicl2 #-65536,r0
2173 addl2 r0,-656(fp)
2174 bicl3 #-65536,-644(fp),r0
2175 ashl #16,r0,-648(fp)
2176 addl3 -648(fp),-652(fp),r0
2177 bicl3 #0,r0,-652(fp)
2178 cmpl -652(fp),-648(fp)
2179 bgequ noname.206
2180 incl -656(fp)
2181noname.206:
2182 movl -652(fp),r1
2183 movl -656(fp),r2
2184 addl2 r1,r10
2185 bicl2 #0,r10
2186 cmpl r10,r1
2187 bgequ noname.207
2188 incl r2
2189noname.207:
2190 addl2 r2,r9
2191 bicl2 #0,r9
2192 cmpl r9,r2
2193 bgequ noname.208
2194 incl r8
2195noname.208:
2196
2197 movzwl 10(r6),r2
2198 bicl3 #-65536,24(r7),r3
2199 movzwl 26(r7),r0
2200 bicl2 #-65536,r0
2201 bicl3 #-65536,8(r6),-668(fp)
2202 bicl3 #-65536,r2,-672(fp)
2203 mull3 r0,-668(fp),-660(fp)
2204 mull2 r3,-668(fp)
2205 mull3 r3,-672(fp),-664(fp)
2206 mull2 r0,-672(fp)
2207 addl3 -660(fp),-664(fp),r0
2208 bicl3 #0,r0,-660(fp)
2209 cmpl -660(fp),-664(fp)
2210 bgequ noname.209
2211 addl2 #65536,-672(fp)
2212noname.209:
2213 movzwl -658(fp),r0
2214 bicl2 #-65536,r0
2215 addl2 r0,-672(fp)
2216 bicl3 #-65536,-660(fp),r0
2217 ashl #16,r0,-664(fp)
2218 addl3 -664(fp),-668(fp),r0
2219 bicl3 #0,r0,-668(fp)
2220 cmpl -668(fp),-664(fp)
2221 bgequ noname.210
2222 incl -672(fp)
2223noname.210:
2224 movl -668(fp),r1
2225 movl -672(fp),r2
2226 addl2 r1,r10
2227 bicl2 #0,r10
2228 cmpl r10,r1
2229 bgequ noname.211
2230 incl r2
2231noname.211:
2232 addl2 r2,r9
2233 bicl2 #0,r9
2234 cmpl r9,r2
2235 bgequ noname.212
2236 incl r8
2237noname.212:
2238
2239 movzwl 6(r6),r2
2240 bicl3 #-65536,28(r7),r3
2241 movzwl 30(r7),r0
2242 bicl2 #-65536,r0
2243 bicl3 #-65536,4(r6),-684(fp)
2244 bicl3 #-65536,r2,-688(fp)
2245 mull3 r0,-684(fp),-676(fp)
2246 mull2 r3,-684(fp)
2247 mull3 r3,-688(fp),-680(fp)
2248 mull2 r0,-688(fp)
2249 addl3 -676(fp),-680(fp),r0
2250 bicl3 #0,r0,-676(fp)
2251 cmpl -676(fp),-680(fp)
2252 bgequ noname.213
2253 addl2 #65536,-688(fp)
2254noname.213:
2255 movzwl -674(fp),r0
2256 bicl2 #-65536,r0
2257 addl2 r0,-688(fp)
2258 bicl3 #-65536,-676(fp),r0
2259 ashl #16,r0,-680(fp)
2260 addl3 -680(fp),-684(fp),r0
2261 bicl3 #0,r0,-684(fp)
2262 cmpl -684(fp),-680(fp)
2263 bgequ noname.214
2264 incl -688(fp)
2265noname.214:
2266 movl -684(fp),r1
2267 movl -688(fp),r2
2268 addl2 r1,r10
2269 bicl2 #0,r10
2270 cmpl r10,r1
2271 bgequ noname.215
2272 incl r2
2273noname.215:
2274 addl2 r2,r9
2275 bicl2 #0,r9
2276 cmpl r9,r2
2277 bgequ noname.216
2278 incl r8
2279noname.216:
2280
2281 movl r10,32(r11)
2282
2283 clrl r10
2284
2285 movzwl 10(r6),r2
2286 bicl3 #-65536,28(r7),r3
2287 movzwl 30(r7),r0
2288 bicl2 #-65536,r0
2289 bicl3 #-65536,8(r6),-700(fp)
2290 bicl3 #-65536,r2,-704(fp)
2291 mull3 r0,-700(fp),-692(fp)
2292 mull2 r3,-700(fp)
2293 mull3 r3,-704(fp),-696(fp)
2294 mull2 r0,-704(fp)
2295 addl3 -692(fp),-696(fp),r0
2296 bicl3 #0,r0,-692(fp)
2297 cmpl -692(fp),-696(fp)
2298 bgequ noname.217
2299 addl2 #65536,-704(fp)
2300noname.217:
2301 movzwl -690(fp),r0
2302 bicl2 #-65536,r0
2303 addl2 r0,-704(fp)
2304 bicl3 #-65536,-692(fp),r0
2305 ashl #16,r0,-696(fp)
2306 addl3 -696(fp),-700(fp),r0
2307 bicl3 #0,r0,-700(fp)
2308 cmpl -700(fp),-696(fp)
2309 bgequ noname.218
2310 incl -704(fp)
2311noname.218:
2312 movl -700(fp),r1
2313 movl -704(fp),r2
2314 addl2 r1,r9
2315 bicl2 #0,r9
2316 cmpl r9,r1
2317 bgequ noname.219
2318 incl r2
2319noname.219:
2320 addl2 r2,r8
2321 bicl2 #0,r8
2322 cmpl r8,r2
2323 bgequ noname.220
2324 incl r10
2325noname.220:
2326
2327 movzwl 14(r6),r2
2328 bicl3 #-65536,24(r7),r3
2329 movzwl 26(r7),r0
2330 bicl2 #-65536,r0
2331 bicl3 #-65536,12(r6),-716(fp)
2332 bicl3 #-65536,r2,-720(fp)
2333 mull3 r0,-716(fp),-708(fp)
2334 mull2 r3,-716(fp)
2335 mull3 r3,-720(fp),-712(fp)
2336 mull2 r0,-720(fp)
2337 addl3 -708(fp),-712(fp),r0
2338 bicl3 #0,r0,-708(fp)
2339 cmpl -708(fp),-712(fp)
2340 bgequ noname.221
2341 addl2 #65536,-720(fp)
2342noname.221:
2343 movzwl -706(fp),r0
2344 bicl2 #-65536,r0
2345 addl2 r0,-720(fp)
2346 bicl3 #-65536,-708(fp),r0
2347 ashl #16,r0,-712(fp)
2348 addl3 -712(fp),-716(fp),r0
2349 bicl3 #0,r0,-716(fp)
2350 cmpl -716(fp),-712(fp)
2351 bgequ noname.222
2352 incl -720(fp)
2353noname.222:
2354 movl -716(fp),r1
2355 movl -720(fp),r2
2356 addl2 r1,r9
2357 bicl2 #0,r9
2358 cmpl r9,r1
2359 bgequ noname.223
2360 incl r2
2361noname.223:
2362 addl2 r2,r8
2363 bicl2 #0,r8
2364 cmpl r8,r2
2365 bgequ noname.224
2366 incl r10
2367noname.224:
2368
2369 movzwl 18(r6),r2
2370 bicl3 #-65536,20(r7),r3
2371 movzwl 22(r7),r0
2372 bicl2 #-65536,r0
2373 bicl3 #-65536,16(r6),-732(fp)
2374 bicl3 #-65536,r2,-736(fp)
2375 mull3 r0,-732(fp),-724(fp)
2376 mull2 r3,-732(fp)
2377 mull3 r3,-736(fp),-728(fp)
2378 mull2 r0,-736(fp)
2379 addl3 -724(fp),-728(fp),r0
2380 bicl3 #0,r0,-724(fp)
2381 cmpl -724(fp),-728(fp)
2382 bgequ noname.225
2383 addl2 #65536,-736(fp)
2384noname.225:
2385 movzwl -722(fp),r0
2386 bicl2 #-65536,r0
2387 addl2 r0,-736(fp)
2388 bicl3 #-65536,-724(fp),r0
2389 ashl #16,r0,-728(fp)
2390 addl3 -728(fp),-732(fp),r0
2391 bicl3 #0,r0,-732(fp)
2392 cmpl -732(fp),-728(fp)
2393 bgequ noname.226
2394 incl -736(fp)
2395noname.226:
2396 movl -732(fp),r1
2397 movl -736(fp),r2
2398 addl2 r1,r9
2399 bicl2 #0,r9
2400 cmpl r9,r1
2401 bgequ noname.227
2402 incl r2
2403noname.227:
2404 addl2 r2,r8
2405 bicl2 #0,r8
2406 cmpl r8,r2
2407 bgequ noname.228
2408 incl r10
2409noname.228:
2410
2411 movzwl 22(r6),r2
2412 bicl3 #-65536,16(r7),r3
2413 movzwl 18(r7),r0
2414 bicl2 #-65536,r0
2415 bicl3 #-65536,20(r6),-748(fp)
2416 bicl3 #-65536,r2,-752(fp)
2417 mull3 r0,-748(fp),-740(fp)
2418 mull2 r3,-748(fp)
2419 mull3 r3,-752(fp),-744(fp)
2420 mull2 r0,-752(fp)
2421 addl3 -740(fp),-744(fp),r0
2422 bicl3 #0,r0,-740(fp)
2423 cmpl -740(fp),-744(fp)
2424 bgequ noname.229
2425 addl2 #65536,-752(fp)
2426noname.229:
2427 movzwl -738(fp),r0
2428 bicl2 #-65536,r0
2429 addl2 r0,-752(fp)
2430 bicl3 #-65536,-740(fp),r0
2431 ashl #16,r0,-744(fp)
2432 addl3 -744(fp),-748(fp),r0
2433 bicl3 #0,r0,-748(fp)
2434 cmpl -748(fp),-744(fp)
2435 bgequ noname.230
2436 incl -752(fp)
2437noname.230:
2438 movl -748(fp),r1
2439 movl -752(fp),r2
2440 addl2 r1,r9
2441 bicl2 #0,r9
2442 cmpl r9,r1
2443 bgequ noname.231
2444 incl r2
2445noname.231:
2446 addl2 r2,r8
2447 bicl2 #0,r8
2448 cmpl r8,r2
2449 bgequ noname.232
2450 incl r10
2451noname.232:
2452
2453 movzwl 26(r6),r2
2454 bicl3 #-65536,12(r7),r3
2455 movzwl 14(r7),r0
2456 bicl2 #-65536,r0
2457 bicl3 #-65536,24(r6),-764(fp)
2458 bicl3 #-65536,r2,-768(fp)
2459 mull3 r0,-764(fp),-756(fp)
2460 mull2 r3,-764(fp)
2461 mull3 r3,-768(fp),-760(fp)
2462 mull2 r0,-768(fp)
2463 addl3 -756(fp),-760(fp),r0
2464 bicl3 #0,r0,-756(fp)
2465 cmpl -756(fp),-760(fp)
2466 bgequ noname.233
2467 addl2 #65536,-768(fp)
2468noname.233:
2469 movzwl -754(fp),r0
2470 bicl2 #-65536,r0
2471 addl2 r0,-768(fp)
2472 bicl3 #-65536,-756(fp),r0
2473 ashl #16,r0,-760(fp)
2474 addl3 -760(fp),-764(fp),r0
2475 bicl3 #0,r0,-764(fp)
2476 cmpl -764(fp),-760(fp)
2477 bgequ noname.234
2478 incl -768(fp)
2479noname.234:
2480 movl -764(fp),r1
2481 movl -768(fp),r2
2482 addl2 r1,r9
2483 bicl2 #0,r9
2484 cmpl r9,r1
2485 bgequ noname.235
2486 incl r2
2487noname.235:
2488 addl2 r2,r8
2489 bicl2 #0,r8
2490 cmpl r8,r2
2491 bgequ noname.236
2492 incl r10
2493noname.236:
2494
2495 bicl3 #-65536,28(r6),r3
2496 movzwl 30(r6),r1
2497 bicl2 #-65536,r1
2498 bicl3 #-65536,8(r7),r2
2499 movzwl 10(r7),r0
2500 bicl2 #-65536,r0
2501 movl r3,r5
2502 movl r1,r4
2503 mull3 r0,r5,-772(fp)
2504 mull2 r2,r5
2505 mull3 r2,r4,-776(fp)
2506 mull2 r0,r4
2507 addl3 -772(fp),-776(fp),r0
2508 bicl3 #0,r0,-772(fp)
2509 cmpl -772(fp),-776(fp)
2510 bgequ noname.237
2511 addl2 #65536,r4
2512noname.237:
2513 movzwl -770(fp),r0
2514 bicl2 #-65536,r0
2515 addl2 r0,r4
2516 bicl3 #-65536,-772(fp),r0
2517 ashl #16,r0,-776(fp)
2518 addl2 -776(fp),r5
2519 bicl2 #0,r5
2520 cmpl r5,-776(fp)
2521 bgequ noname.238
2522 incl r4
2523noname.238:
2524 movl r5,r1
2525 movl r4,r2
2526 addl2 r1,r9
2527 bicl2 #0,r9
2528 cmpl r9,r1
2529 bgequ noname.239
2530 incl r2
2531noname.239:
2532 addl2 r2,r8
2533 bicl2 #0,r8
2534 cmpl r8,r2
2535 bgequ noname.240
2536 incl r10
2537noname.240:
2538
2539 movl r9,36(r11)
2540
2541 clrl r9
2542
2543 bicl3 #-65536,28(r6),r3
2544 movzwl 30(r6),r1
2545 bicl2 #-65536,r1
2546 bicl3 #-65536,12(r7),r2
2547 movzwl 14(r7),r0
2548 bicl2 #-65536,r0
2549 movl r3,r5
2550 movl r1,r4
2551 mull3 r0,r5,-780(fp)
2552 mull2 r2,r5
2553 mull3 r2,r4,-784(fp)
2554 mull2 r0,r4
2555 addl3 -780(fp),-784(fp),r0
2556 bicl3 #0,r0,-780(fp)
2557 cmpl -780(fp),-784(fp)
2558 bgequ noname.241
2559 addl2 #65536,r4
2560noname.241:
2561 movzwl -778(fp),r0
2562 bicl2 #-65536,r0
2563 addl2 r0,r4
2564 bicl3 #-65536,-780(fp),r0
2565 ashl #16,r0,-784(fp)
2566 addl2 -784(fp),r5
2567 bicl2 #0,r5
2568 cmpl r5,-784(fp)
2569 bgequ noname.242
2570 incl r4
2571noname.242:
2572 movl r5,r1
2573 movl r4,r2
2574 addl2 r1,r8
2575 bicl2 #0,r8
2576 cmpl r8,r1
2577 bgequ noname.243
2578 incl r2
2579noname.243:
2580 addl2 r2,r10
2581 bicl2 #0,r10
2582 cmpl r10,r2
2583 bgequ noname.244
2584 incl r9
2585noname.244:
2586
2587 bicl3 #-65536,24(r6),r3
2588 movzwl 26(r6),r1
2589 bicl2 #-65536,r1
2590 bicl3 #-65536,16(r7),r2
2591 movzwl 18(r7),r0
2592 bicl2 #-65536,r0
2593 movl r3,r5
2594 movl r1,r4
2595 mull3 r0,r5,-788(fp)
2596 mull2 r2,r5
2597 mull3 r2,r4,-792(fp)
2598 mull2 r0,r4
2599 addl3 -788(fp),-792(fp),r0
2600 bicl3 #0,r0,-788(fp)
2601 cmpl -788(fp),-792(fp)
2602 bgequ noname.245
2603 addl2 #65536,r4
2604noname.245:
2605 movzwl -786(fp),r0
2606 bicl2 #-65536,r0
2607 addl2 r0,r4
2608 bicl3 #-65536,-788(fp),r0
2609 ashl #16,r0,-792(fp)
2610 addl2 -792(fp),r5
2611 bicl2 #0,r5
2612 cmpl r5,-792(fp)
2613 bgequ noname.246
2614 incl r4
2615noname.246:
2616 movl r5,r1
2617 movl r4,r2
2618 addl2 r1,r8
2619 bicl2 #0,r8
2620 cmpl r8,r1
2621 bgequ noname.247
2622 incl r2
2623noname.247:
2624 addl2 r2,r10
2625 bicl2 #0,r10
2626 cmpl r10,r2
2627 bgequ noname.248
2628 incl r9
2629noname.248:
2630
2631 bicl3 #-65536,20(r6),r3
2632 movzwl 22(r6),r1
2633 bicl2 #-65536,r1
2634 bicl3 #-65536,20(r7),r2
2635 movzwl 22(r7),r0
2636 bicl2 #-65536,r0
2637 movl r3,r5
2638 movl r1,r4
2639 mull3 r0,r5,-796(fp)
2640 mull2 r2,r5
2641 mull3 r2,r4,-800(fp)
2642 mull2 r0,r4
2643 addl3 -796(fp),-800(fp),r0
2644 bicl3 #0,r0,-796(fp)
2645 cmpl -796(fp),-800(fp)
2646 bgequ noname.249
2647 addl2 #65536,r4
2648noname.249:
2649 movzwl -794(fp),r0
2650 bicl2 #-65536,r0
2651 addl2 r0,r4
2652 bicl3 #-65536,-796(fp),r0
2653 ashl #16,r0,-800(fp)
2654 addl2 -800(fp),r5
2655 bicl2 #0,r5
2656 cmpl r5,-800(fp)
2657 bgequ noname.250
2658 incl r4
2659noname.250:
2660 movl r5,r1
2661 movl r4,r2
2662 addl2 r1,r8
2663 bicl2 #0,r8
2664 cmpl r8,r1
2665 bgequ noname.251
2666 incl r2
2667noname.251:
2668 addl2 r2,r10
2669 bicl2 #0,r10
2670 cmpl r10,r2
2671 bgequ noname.252
2672 incl r9
2673noname.252:
2674
2675 bicl3 #-65536,16(r6),r3
2676 movzwl 18(r6),r1
2677 bicl2 #-65536,r1
2678 bicl3 #-65536,24(r7),r2
2679 movzwl 26(r7),r0
2680 bicl2 #-65536,r0
2681 movl r3,r5
2682 movl r1,r4
2683 mull3 r0,r5,-804(fp)
2684 mull2 r2,r5
2685 mull3 r2,r4,-808(fp)
2686 mull2 r0,r4
2687 addl3 -804(fp),-808(fp),r0
2688 bicl3 #0,r0,-804(fp)
2689 cmpl -804(fp),-808(fp)
2690 bgequ noname.253
2691 addl2 #65536,r4
2692noname.253:
2693 movzwl -802(fp),r0
2694 bicl2 #-65536,r0
2695 addl2 r0,r4
2696 bicl3 #-65536,-804(fp),r0
2697 ashl #16,r0,-808(fp)
2698 addl2 -808(fp),r5
2699 bicl2 #0,r5
2700 cmpl r5,-808(fp)
2701 bgequ noname.254
2702 incl r4
2703noname.254:
2704 movl r5,r1
2705 movl r4,r2
2706 addl2 r1,r8
2707 bicl2 #0,r8
2708 cmpl r8,r1
2709 bgequ noname.255
2710 incl r2
2711noname.255:
2712 addl2 r2,r10
2713 bicl2 #0,r10
2714 cmpl r10,r2
2715 bgequ noname.256
2716 incl r9
2717noname.256:
2718
2719 bicl3 #-65536,12(r6),r3
2720 movzwl 14(r6),r1
2721 bicl2 #-65536,r1
2722 bicl3 #-65536,28(r7),r2
2723 movzwl 30(r7),r0
2724 bicl2 #-65536,r0
2725 movl r3,r5
2726 movl r1,r4
2727 mull3 r0,r5,-812(fp)
2728 mull2 r2,r5
2729 mull3 r2,r4,-816(fp)
2730 mull2 r0,r4
2731 addl3 -812(fp),-816(fp),r0
2732 bicl3 #0,r0,-812(fp)
2733 cmpl -812(fp),-816(fp)
2734 bgequ noname.257
2735 addl2 #65536,r4
2736noname.257:
2737 movzwl -810(fp),r0
2738 bicl2 #-65536,r0
2739 addl2 r0,r4
2740 bicl3 #-65536,-812(fp),r0
2741 ashl #16,r0,-816(fp)
2742 addl2 -816(fp),r5
2743 bicl2 #0,r5
2744 cmpl r5,-816(fp)
2745 bgequ noname.258
2746 incl r4
2747noname.258:
2748 movl r5,r1
2749 movl r4,r2
2750 addl2 r1,r8
2751 bicl2 #0,r8
2752 cmpl r8,r1
2753 bgequ noname.259
2754 incl r2
2755noname.259:
2756 addl2 r2,r10
2757 bicl2 #0,r10
2758 cmpl r10,r2
2759 bgequ noname.260
2760 incl r9
2761noname.260:
2762
2763 movl r8,40(r11)
2764
2765 clrl r8
2766
2767 bicl3 #-65536,16(r6),r3
2768 movzwl 18(r6),r2
2769 bicl3 #-65536,28(r7),r1
2770 movzwl 30(r7),r0
2771 bicl2 #-65536,r0
2772 movl r3,r4
2773 bicl3 #-65536,r2,-828(fp)
2774 mull3 r0,r4,-820(fp)
2775 mull2 r1,r4
2776 mull3 r1,-828(fp),-824(fp)
2777 mull2 r0,-828(fp)
2778 addl3 -820(fp),-824(fp),r0
2779 bicl3 #0,r0,-820(fp)
2780 cmpl -820(fp),-824(fp)
2781 bgequ noname.261
2782 addl2 #65536,-828(fp)
2783noname.261:
2784 movzwl -818(fp),r0
2785 bicl2 #-65536,r0
2786 addl2 r0,-828(fp)
2787 bicl3 #-65536,-820(fp),r0
2788 ashl #16,r0,-824(fp)
2789 addl2 -824(fp),r4
2790 bicl2 #0,r4
2791 cmpl r4,-824(fp)
2792 bgequ noname.262
2793 incl -828(fp)
2794noname.262:
2795 movl r4,r1
2796 movl -828(fp),r2
2797 addl2 r1,r10
2798 bicl2 #0,r10
2799 cmpl r10,r1
2800 bgequ noname.263
2801 incl r2
2802noname.263:
2803 addl2 r2,r9
2804 bicl2 #0,r9
2805 cmpl r9,r2
2806 bgequ noname.264
2807 incl r8
2808noname.264:
2809
2810 movzwl 22(r6),r2
2811 bicl3 #-65536,24(r7),r3
2812 movzwl 26(r7),r0
2813 bicl2 #-65536,r0
2814 bicl3 #-65536,20(r6),-840(fp)
2815 bicl3 #-65536,r2,-844(fp)
2816 mull3 r0,-840(fp),-832(fp)
2817 mull2 r3,-840(fp)
2818 mull3 r3,-844(fp),-836(fp)
2819 mull2 r0,-844(fp)
2820 addl3 -832(fp),-836(fp),r0
2821 bicl3 #0,r0,-832(fp)
2822 cmpl -832(fp),-836(fp)
2823 bgequ noname.265
2824 addl2 #65536,-844(fp)
2825noname.265:
2826 movzwl -830(fp),r0
2827 bicl2 #-65536,r0
2828 addl2 r0,-844(fp)
2829 bicl3 #-65536,-832(fp),r0
2830 ashl #16,r0,-836(fp)
2831 addl3 -836(fp),-840(fp),r0
2832 bicl3 #0,r0,-840(fp)
2833 cmpl -840(fp),-836(fp)
2834 bgequ noname.266
2835 incl -844(fp)
2836noname.266:
2837 movl -840(fp),r1
2838 movl -844(fp),r2
2839 addl2 r1,r10
2840 bicl2 #0,r10
2841 cmpl r10,r1
2842 bgequ noname.267
2843 incl r2
2844noname.267:
2845 addl2 r2,r9
2846 bicl2 #0,r9
2847 cmpl r9,r2
2848 bgequ noname.268
2849 incl r8
2850noname.268:
2851
2852 bicl3 #-65536,24(r6),r3
2853 movzwl 26(r6),r1
2854 bicl2 #-65536,r1
2855 bicl3 #-65536,20(r7),r2
2856 movzwl 22(r7),r0
2857 bicl2 #-65536,r0
2858 movl r3,r5
2859 movl r1,r4
2860 mull3 r0,r5,-848(fp)
2861 mull2 r2,r5
2862 mull3 r2,r4,-852(fp)
2863 mull2 r0,r4
2864 addl3 -848(fp),-852(fp),r0
2865 bicl3 #0,r0,-848(fp)
2866 cmpl -848(fp),-852(fp)
2867 bgequ noname.269
2868 addl2 #65536,r4
2869noname.269:
2870 movzwl -846(fp),r0
2871 bicl2 #-65536,r0
2872 addl2 r0,r4
2873 bicl3 #-65536,-848(fp),r0
2874 ashl #16,r0,-852(fp)
2875 addl2 -852(fp),r5
2876 bicl2 #0,r5
2877 cmpl r5,-852(fp)
2878 bgequ noname.270
2879 incl r4
2880noname.270:
2881 movl r5,r1
2882 movl r4,r2
2883 addl2 r1,r10
2884 bicl2 #0,r10
2885 cmpl r10,r1
2886 bgequ noname.271
2887 incl r2
2888noname.271:
2889 addl2 r2,r9
2890 bicl2 #0,r9
2891 cmpl r9,r2
2892 bgequ noname.272
2893 incl r8
2894noname.272:
2895
2896 bicl3 #-65536,28(r6),r3
2897 movzwl 30(r6),r1
2898 bicl2 #-65536,r1
2899 bicl3 #-65536,16(r7),r2
2900 movzwl 18(r7),r0
2901 bicl2 #-65536,r0
2902 movl r3,r5
2903 movl r1,r4
2904 mull3 r0,r5,-856(fp)
2905 mull2 r2,r5
2906 mull3 r2,r4,-860(fp)
2907 mull2 r0,r4
2908 addl3 -856(fp),-860(fp),r0
2909 bicl3 #0,r0,-856(fp)
2910 cmpl -856(fp),-860(fp)
2911 bgequ noname.273
2912 addl2 #65536,r4
2913noname.273:
2914 movzwl -854(fp),r0
2915 bicl2 #-65536,r0
2916 addl2 r0,r4
2917 bicl3 #-65536,-856(fp),r0
2918 ashl #16,r0,-860(fp)
2919 addl2 -860(fp),r5
2920 bicl2 #0,r5
2921 cmpl r5,-860(fp)
2922 bgequ noname.274
2923 incl r4
2924noname.274:
2925 movl r5,r1
2926 movl r4,r2
2927 addl2 r1,r10
2928 bicl2 #0,r10
2929 cmpl r10,r1
2930 bgequ noname.275
2931 incl r2
2932noname.275:
2933 addl2 r2,r9
2934 bicl2 #0,r9
2935 cmpl r9,r2
2936 bgequ noname.276
2937 incl r8
2938noname.276:
2939
2940 movl r10,44(r11)
2941
2942 clrl r10
2943
2944 bicl3 #-65536,28(r6),r3
2945 movzwl 30(r6),r1
2946 bicl2 #-65536,r1
2947 bicl3 #-65536,20(r7),r2
2948 movzwl 22(r7),r0
2949 bicl2 #-65536,r0
2950 movl r3,r5
2951 movl r1,r4
2952 mull3 r0,r5,-864(fp)
2953 mull2 r2,r5
2954 mull3 r2,r4,-868(fp)
2955 mull2 r0,r4
2956 addl3 -864(fp),-868(fp),r0
2957 bicl3 #0,r0,-864(fp)
2958 cmpl -864(fp),-868(fp)
2959 bgequ noname.277
2960 addl2 #65536,r4
2961noname.277:
2962 movzwl -862(fp),r0
2963 bicl2 #-65536,r0
2964 addl2 r0,r4
2965 bicl3 #-65536,-864(fp),r0
2966 ashl #16,r0,-868(fp)
2967 addl2 -868(fp),r5
2968 bicl2 #0,r5
2969 cmpl r5,-868(fp)
2970 bgequ noname.278
2971 incl r4
2972noname.278:
2973 movl r5,r1
2974 movl r4,r2
2975 addl2 r1,r9
2976 bicl2 #0,r9
2977 cmpl r9,r1
2978 bgequ noname.279
2979 incl r2
2980noname.279:
2981 addl2 r2,r8
2982 bicl2 #0,r8
2983 cmpl r8,r2
2984 bgequ noname.280
2985 incl r10
2986noname.280:
2987
2988 bicl3 #-65536,24(r6),r3
2989 movzwl 26(r6),r1
2990 bicl2 #-65536,r1
2991 bicl3 #-65536,24(r7),r2
2992 movzwl 26(r7),r0
2993 bicl2 #-65536,r0
2994 movl r3,r5
2995 movl r1,r4
2996 mull3 r0,r5,-872(fp)
2997 mull2 r2,r5
2998 mull3 r2,r4,-876(fp)
2999 mull2 r0,r4
3000 addl3 -872(fp),-876(fp),r0
3001 bicl3 #0,r0,-872(fp)
3002 cmpl -872(fp),-876(fp)
3003 bgequ noname.281
3004 addl2 #65536,r4
3005noname.281:
3006 movzwl -870(fp),r0
3007 bicl2 #-65536,r0
3008 addl2 r0,r4
3009 bicl3 #-65536,-872(fp),r0
3010 ashl #16,r0,-876(fp)
3011 addl2 -876(fp),r5
3012 bicl2 #0,r5
3013 cmpl r5,-876(fp)
3014 bgequ noname.282
3015 incl r4
3016noname.282:
3017 movl r5,r1
3018 movl r4,r2
3019 addl2 r1,r9
3020 bicl2 #0,r9
3021 cmpl r9,r1
3022 bgequ noname.283
3023 incl r2
3024noname.283:
3025 addl2 r2,r8
3026 bicl2 #0,r8
3027 cmpl r8,r2
3028 bgequ noname.284
3029 incl r10
3030noname.284:
3031
3032 bicl3 #-65536,20(r6),r3
3033 movzwl 22(r6),r1
3034 bicl2 #-65536,r1
3035 bicl3 #-65536,28(r7),r2
3036 movzwl 30(r7),r0
3037 bicl2 #-65536,r0
3038 movl r3,r5
3039 movl r1,r4
3040 mull3 r0,r5,-880(fp)
3041 mull2 r2,r5
3042 mull3 r2,r4,-884(fp)
3043 mull2 r0,r4
3044 addl3 -880(fp),-884(fp),r0
3045 bicl3 #0,r0,-880(fp)
3046 cmpl -880(fp),-884(fp)
3047 bgequ noname.285
3048 addl2 #65536,r4
3049noname.285:
3050 movzwl -878(fp),r0
3051 bicl2 #-65536,r0
3052 addl2 r0,r4
3053 bicl3 #-65536,-880(fp),r0
3054 ashl #16,r0,-884(fp)
3055 addl2 -884(fp),r5
3056 bicl2 #0,r5
3057 cmpl r5,-884(fp)
3058 bgequ noname.286
3059 incl r4
3060noname.286:
3061 movl r5,r1
3062 movl r4,r2
3063 addl2 r1,r9
3064 bicl2 #0,r9
3065 cmpl r9,r1
3066 bgequ noname.287
3067 incl r2
3068noname.287:
3069 addl2 r2,r8
3070 bicl2 #0,r8
3071 cmpl r8,r2
3072 bgequ noname.288
3073 incl r10
3074noname.288:
3075
3076 movl r9,48(r11)
3077
3078 clrl r9
3079
3080 bicl3 #-65536,24(r6),r3
3081 movzwl 26(r6),r1
3082 bicl2 #-65536,r1
3083 bicl3 #-65536,28(r7),r2
3084 movzwl 30(r7),r0
3085 bicl2 #-65536,r0
3086 movl r3,r5
3087 movl r1,r4
3088 mull3 r0,r5,-888(fp)
3089 mull2 r2,r5
3090 mull3 r2,r4,-892(fp)
3091 mull2 r0,r4
3092 addl3 -888(fp),-892(fp),r0
3093 bicl3 #0,r0,-888(fp)
3094 cmpl -888(fp),-892(fp)
3095 bgequ noname.289
3096 addl2 #65536,r4
3097noname.289:
3098 movzwl -886(fp),r0
3099 bicl2 #-65536,r0
3100 addl2 r0,r4
3101 bicl3 #-65536,-888(fp),r0
3102 ashl #16,r0,-892(fp)
3103 addl2 -892(fp),r5
3104 bicl2 #0,r5
3105 cmpl r5,-892(fp)
3106 bgequ noname.290
3107 incl r4
3108noname.290:
3109 movl r5,r1
3110 movl r4,r2
3111 addl2 r1,r8
3112 bicl2 #0,r8
3113 cmpl r8,r1
3114 bgequ noname.291
3115 incl r2
3116noname.291:
3117 addl2 r2,r10
3118 bicl2 #0,r10
3119 cmpl r10,r2
3120 bgequ noname.292
3121 incl r9
3122noname.292:
3123
3124 movzwl 30(r6),r2
3125 bicl3 #-65536,24(r7),r3
3126 movzwl 26(r7),r0
3127 bicl2 #-65536,r0
3128 bicl3 #-65536,28(r6),-904(fp)
3129 bicl3 #-65536,r2,-908(fp)
3130 mull3 r0,-904(fp),-896(fp)
3131 mull2 r3,-904(fp)
3132 mull3 r3,-908(fp),-900(fp)
3133 mull2 r0,-908(fp)
3134 addl3 -896(fp),-900(fp),r0
3135 bicl3 #0,r0,-896(fp)
3136 cmpl -896(fp),-900(fp)
3137 bgequ noname.293
3138 addl2 #65536,-908(fp)
3139noname.293:
3140 movzwl -894(fp),r0
3141 bicl2 #-65536,r0
3142 addl2 r0,-908(fp)
3143 bicl3 #-65536,-896(fp),r0
3144 ashl #16,r0,-900(fp)
3145 addl3 -900(fp),-904(fp),r0
3146 bicl3 #0,r0,-904(fp)
3147 cmpl -904(fp),-900(fp)
3148 bgequ noname.294
3149 incl -908(fp)
3150noname.294:
3151 movl -904(fp),r1
3152 movl -908(fp),r2
3153 addl2 r1,r8
3154 bicl2 #0,r8
3155 cmpl r8,r1
3156 bgequ noname.295
3157 incl r2
3158noname.295:
3159 addl2 r2,r10
3160 bicl2 #0,r10
3161 cmpl r10,r2
3162 bgequ noname.296
3163 incl r9
3164noname.296:
3165
3166 movl r8,52(r11)
3167
3168 clrl r8
3169
3170 movzwl 30(r6),r2
3171 bicl3 #-65536,28(r7),r3
3172 movzwl 30(r7),r0
3173 bicl2 #-65536,r0
3174 bicl3 #-65536,28(r6),-920(fp)
3175 bicl3 #-65536,r2,-924(fp)
3176 mull3 r0,-920(fp),-912(fp)
3177 mull2 r3,-920(fp)
3178 mull3 r3,-924(fp),-916(fp)
3179 mull2 r0,-924(fp)
3180 addl3 -912(fp),-916(fp),r0
3181 bicl3 #0,r0,-912(fp)
3182 cmpl -912(fp),-916(fp)
3183 bgequ noname.297
3184 addl2 #65536,-924(fp)
3185noname.297:
3186 movzwl -910(fp),r0
3187 bicl2 #-65536,r0
3188 addl2 r0,-924(fp)
3189 bicl3 #-65536,-912(fp),r0
3190 ashl #16,r0,-916(fp)
3191 addl3 -916(fp),-920(fp),r0
3192 bicl3 #0,r0,-920(fp)
3193 cmpl -920(fp),-916(fp)
3194 bgequ noname.298
3195 incl -924(fp)
3196noname.298:
3197 movl -920(fp),r1
3198 movl -924(fp),r2
3199 addl2 r1,r10
3200 bicl2 #0,r10
3201 cmpl r10,r1
3202 bgequ noname.299
3203 incl r2
3204noname.299:
3205 addl2 r2,r9
3206 bicl2 #0,r9
3207 cmpl r9,r2
3208 bgequ noname.300
3209 incl r8
3210noname.300:
3211
3212 movl r10,56(r11)
3213
3214 movl r9,60(r11)
3215
3216 ret
3217
3218
3219
3220;r=4 ;(AP)
3221;a=8 ;(AP)
3222;b=12 ;(AP)
3223;n=16 ;(AP) n by value (input)
3224
3225 .psect code,nowrt
3226
3227.entry BN_MUL_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10,r11>
3228 movab -156(sp),sp
3229
3230 clrq r9
3231
3232 clrl r8
3233
3234 movl 8(ap),r6
3235 bicl3 #-65536,(r6),r3
3236 movzwl 2(r6),r2
3237 bicl2 #-65536,r2
3238 movl 12(ap),r7
3239 bicl3 #-65536,(r7),r1
3240 movzwl 2(r7),r0
3241 bicl2 #-65536,r0
3242 movl r3,r5
3243 movl r2,r4
3244 mull3 r0,r5,-4(fp)
3245 mull2 r1,r5
3246 mull3 r1,r4,-8(fp)
3247 mull2 r0,r4
3248 addl3 -4(fp),-8(fp),r0
3249 bicl3 #0,r0,-4(fp)
3250 cmpl -4(fp),-8(fp)
3251 bgequ noname.303
3252 addl2 #65536,r4
3253noname.303:
3254 movzwl -2(fp),r0
3255 bicl2 #-65536,r0
3256 addl2 r0,r4
3257 bicl3 #-65536,-4(fp),r0
3258 ashl #16,r0,-8(fp)
3259 addl2 -8(fp),r5
3260 bicl2 #0,r5
3261 cmpl r5,-8(fp)
3262 bgequ noname.304
3263 incl r4
3264noname.304:
3265 movl r5,r1
3266 movl r4,r2
3267 addl2 r1,r10
3268 bicl2 #0,r10
3269 cmpl r10,r1
3270 bgequ noname.305
3271 incl r2
3272noname.305:
3273 addl2 r2,r9
3274 bicl2 #0,r9
3275 cmpl r9,r2
3276 bgequ noname.306
3277 incl r8
3278noname.306:
3279
3280 movl 4(ap),r11
3281 movl r10,(r11)
3282
3283 clrl r10
3284
3285 bicl3 #-65536,(r6),r3
3286 movzwl 2(r6),r1
3287 bicl2 #-65536,r1
3288 bicl3 #-65536,4(r7),r2
3289 movzwl 6(r7),r0
3290 bicl2 #-65536,r0
3291 movl r3,r5
3292 movl r1,r4
3293 mull3 r0,r5,-12(fp)
3294 mull2 r2,r5
3295 mull3 r2,r4,-16(fp)
3296 mull2 r0,r4
3297 addl3 -12(fp),-16(fp),r0
3298 bicl3 #0,r0,-12(fp)
3299 cmpl -12(fp),-16(fp)
3300 bgequ noname.307
3301 addl2 #65536,r4
3302noname.307:
3303 movzwl -10(fp),r0
3304 bicl2 #-65536,r0
3305 addl2 r0,r4
3306 bicl3 #-65536,-12(fp),r0
3307 ashl #16,r0,-16(fp)
3308 addl2 -16(fp),r5
3309 bicl2 #0,r5
3310 cmpl r5,-16(fp)
3311 bgequ noname.308
3312 incl r4
3313noname.308:
3314 movl r5,r1
3315 movl r4,r2
3316 addl2 r1,r9
3317 bicl2 #0,r9
3318 cmpl r9,r1
3319 bgequ noname.309
3320 incl r2
3321noname.309:
3322 addl2 r2,r8
3323 bicl2 #0,r8
3324 cmpl r8,r2
3325 bgequ noname.310
3326 incl r10
3327noname.310:
3328
3329 bicl3 #-65536,4(r6),r3
3330 movzwl 6(r6),r1
3331 bicl2 #-65536,r1
3332 bicl3 #-65536,(r7),r2
3333 movzwl 2(r7),r0
3334 bicl2 #-65536,r0
3335 movl r3,r5
3336 movl r1,r4
3337 mull3 r0,r5,-20(fp)
3338 mull2 r2,r5
3339 mull3 r2,r4,-24(fp)
3340 mull2 r0,r4
3341 addl3 -20(fp),-24(fp),r0
3342 bicl3 #0,r0,-20(fp)
3343 cmpl -20(fp),-24(fp)
3344 bgequ noname.311
3345 addl2 #65536,r4
3346noname.311:
3347 movzwl -18(fp),r0
3348 bicl2 #-65536,r0
3349 addl2 r0,r4
3350 bicl3 #-65536,-20(fp),r0
3351 ashl #16,r0,-24(fp)
3352 addl2 -24(fp),r5
3353 bicl2 #0,r5
3354 cmpl r5,-24(fp)
3355 bgequ noname.312
3356 incl r4
3357noname.312:
3358 movl r5,r1
3359 movl r4,r2
3360 addl2 r1,r9
3361 bicl2 #0,r9
3362 cmpl r9,r1
3363 bgequ noname.313
3364 incl r2
3365noname.313:
3366 addl2 r2,r8
3367 bicl2 #0,r8
3368 cmpl r8,r2
3369 bgequ noname.314
3370 incl r10
3371noname.314:
3372
3373 movl r9,4(r11)
3374
3375 clrl r9
3376
3377 bicl3 #-65536,8(r6),r3
3378 movzwl 10(r6),r1
3379 bicl2 #-65536,r1
3380 bicl3 #-65536,(r7),r2
3381 movzwl 2(r7),r0
3382 bicl2 #-65536,r0
3383 movl r3,r5
3384 movl r1,r4
3385 mull3 r0,r5,-28(fp)
3386 mull2 r2,r5
3387 mull3 r2,r4,-32(fp)
3388 mull2 r0,r4
3389 addl3 -28(fp),-32(fp),r0
3390 bicl3 #0,r0,-28(fp)
3391 cmpl -28(fp),-32(fp)
3392 bgequ noname.315
3393 addl2 #65536,r4
3394noname.315:
3395 movzwl -26(fp),r0
3396 bicl2 #-65536,r0
3397 addl2 r0,r4
3398 bicl3 #-65536,-28(fp),r0
3399 ashl #16,r0,-32(fp)
3400 addl2 -32(fp),r5
3401 bicl2 #0,r5
3402 cmpl r5,-32(fp)
3403 bgequ noname.316
3404 incl r4
3405noname.316:
3406 movl r5,r1
3407 movl r4,r2
3408 addl2 r1,r8
3409 bicl2 #0,r8
3410 cmpl r8,r1
3411 bgequ noname.317
3412 incl r2
3413noname.317:
3414 addl2 r2,r10
3415 bicl2 #0,r10
3416 cmpl r10,r2
3417 bgequ noname.318
3418 incl r9
3419noname.318:
3420
3421 bicl3 #-65536,4(r6),r3
3422 movzwl 6(r6),r1
3423 bicl2 #-65536,r1
3424 bicl3 #-65536,4(r7),r2
3425 movzwl 6(r7),r0
3426 bicl2 #-65536,r0
3427 movl r3,r5
3428 movl r1,r4
3429 mull3 r0,r5,-36(fp)
3430 mull2 r2,r5
3431 mull3 r2,r4,-40(fp)
3432 mull2 r0,r4
3433 addl3 -36(fp),-40(fp),r0
3434 bicl3 #0,r0,-36(fp)
3435 cmpl -36(fp),-40(fp)
3436 bgequ noname.319
3437 addl2 #65536,r4
3438noname.319:
3439 movzwl -34(fp),r0
3440 bicl2 #-65536,r0
3441 addl2 r0,r4
3442 bicl3 #-65536,-36(fp),r0
3443 ashl #16,r0,-40(fp)
3444 addl2 -40(fp),r5
3445 bicl2 #0,r5
3446 cmpl r5,-40(fp)
3447 bgequ noname.320
3448 incl r4
3449noname.320:
3450 movl r5,r1
3451 movl r4,r2
3452 addl2 r1,r8
3453 bicl2 #0,r8
3454 cmpl r8,r1
3455 bgequ noname.321
3456 incl r2
3457noname.321:
3458 addl2 r2,r10
3459 bicl2 #0,r10
3460 cmpl r10,r2
3461 bgequ noname.322
3462 incl r9
3463noname.322:
3464
3465 bicl3 #-65536,(r6),r3
3466 movzwl 2(r6),r1
3467 bicl2 #-65536,r1
3468 bicl3 #-65536,8(r7),r2
3469 movzwl 10(r7),r0
3470 bicl2 #-65536,r0
3471 movl r3,r5
3472 movl r1,r4
3473 mull3 r0,r5,-44(fp)
3474 mull2 r2,r5
3475 mull3 r2,r4,-48(fp)
3476 mull2 r0,r4
3477 addl3 -44(fp),-48(fp),r0
3478 bicl3 #0,r0,-44(fp)
3479 cmpl -44(fp),-48(fp)
3480 bgequ noname.323
3481 addl2 #65536,r4
3482noname.323:
3483 movzwl -42(fp),r0
3484 bicl2 #-65536,r0
3485 addl2 r0,r4
3486 bicl3 #-65536,-44(fp),r0
3487 ashl #16,r0,-48(fp)
3488 addl2 -48(fp),r5
3489 bicl2 #0,r5
3490 cmpl r5,-48(fp)
3491 bgequ noname.324
3492 incl r4
3493noname.324:
3494 movl r5,r1
3495 movl r4,r2
3496 addl2 r1,r8
3497 bicl2 #0,r8
3498 cmpl r8,r1
3499 bgequ noname.325
3500 incl r2
3501noname.325:
3502 addl2 r2,r10
3503 bicl2 #0,r10
3504 cmpl r10,r2
3505 bgequ noname.326
3506 incl r9
3507noname.326:
3508
3509 movl r8,8(r11)
3510
3511 clrl r8
3512
3513 bicl3 #-65536,(r6),r3
3514 movzwl 2(r6),r2
3515 bicl3 #-65536,12(r7),r1
3516 movzwl 14(r7),r0
3517 bicl2 #-65536,r0
3518 movl r3,r4
3519 bicl3 #-65536,r2,-60(fp)
3520 mull3 r0,r4,-52(fp)
3521 mull2 r1,r4
3522 mull3 r1,-60(fp),-56(fp)
3523 mull2 r0,-60(fp)
3524 addl3 -52(fp),-56(fp),r0
3525 bicl3 #0,r0,-52(fp)
3526 cmpl -52(fp),-56(fp)
3527 bgequ noname.327
3528 addl2 #65536,-60(fp)
3529noname.327:
3530 movzwl -50(fp),r0
3531 bicl2 #-65536,r0
3532 addl2 r0,-60(fp)
3533 bicl3 #-65536,-52(fp),r0
3534 ashl #16,r0,-56(fp)
3535 addl2 -56(fp),r4
3536 bicl2 #0,r4
3537 cmpl r4,-56(fp)
3538 bgequ noname.328
3539 incl -60(fp)
3540noname.328:
3541 movl r4,r1
3542 movl -60(fp),r2
3543 addl2 r1,r10
3544 bicl2 #0,r10
3545 cmpl r10,r1
3546 bgequ noname.329
3547 incl r2
3548noname.329:
3549 addl2 r2,r9
3550 bicl2 #0,r9
3551 cmpl r9,r2
3552 bgequ noname.330
3553 incl r8
3554noname.330:
3555
3556 movzwl 6(r6),r2
3557 bicl3 #-65536,8(r7),r3
3558 movzwl 10(r7),r0
3559 bicl2 #-65536,r0
3560 bicl3 #-65536,4(r6),-72(fp)
3561 bicl3 #-65536,r2,-76(fp)
3562 mull3 r0,-72(fp),-64(fp)
3563 mull2 r3,-72(fp)
3564 mull3 r3,-76(fp),-68(fp)
3565 mull2 r0,-76(fp)
3566 addl3 -64(fp),-68(fp),r0
3567 bicl3 #0,r0,-64(fp)
3568 cmpl -64(fp),-68(fp)
3569 bgequ noname.331
3570 addl2 #65536,-76(fp)
3571noname.331:
3572 movzwl -62(fp),r0
3573 bicl2 #-65536,r0
3574 addl2 r0,-76(fp)
3575 bicl3 #-65536,-64(fp),r0
3576 ashl #16,r0,-68(fp)
3577 addl3 -68(fp),-72(fp),r0
3578 bicl3 #0,r0,-72(fp)
3579 cmpl -72(fp),-68(fp)
3580 bgequ noname.332
3581 incl -76(fp)
3582noname.332:
3583 movl -72(fp),r1
3584 movl -76(fp),r2
3585 addl2 r1,r10
3586 bicl2 #0,r10
3587 cmpl r10,r1
3588 bgequ noname.333
3589 incl r2
3590noname.333:
3591 addl2 r2,r9
3592 bicl2 #0,r9
3593 cmpl r9,r2
3594 bgequ noname.334
3595 incl r8
3596noname.334:
3597
3598 bicl3 #-65536,8(r6),r3
3599 movzwl 10(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,-80(fp)
3607 mull2 r2,r5
3608 mull3 r2,r4,-84(fp)
3609 mull2 r0,r4
3610 addl3 -80(fp),-84(fp),r0
3611 bicl3 #0,r0,-80(fp)
3612 cmpl -80(fp),-84(fp)
3613 bgequ noname.335
3614 addl2 #65536,r4
3615noname.335:
3616 movzwl -78(fp),r0
3617 bicl2 #-65536,r0
3618 addl2 r0,r4
3619 bicl3 #-65536,-80(fp),r0
3620 ashl #16,r0,-84(fp)
3621 addl2 -84(fp),r5
3622 bicl2 #0,r5
3623 cmpl r5,-84(fp)
3624 bgequ noname.336
3625 incl r4
3626noname.336:
3627 movl r5,r1
3628 movl r4,r2
3629 addl2 r1,r10
3630 bicl2 #0,r10
3631 cmpl r10,r1
3632 bgequ noname.337
3633 incl r2
3634noname.337:
3635 addl2 r2,r9
3636 bicl2 #0,r9
3637 cmpl r9,r2
3638 bgequ noname.338
3639 incl r8
3640noname.338:
3641
3642 bicl3 #-65536,12(r6),r3
3643 movzwl 14(r6),r1
3644 bicl2 #-65536,r1
3645 bicl3 #-65536,(r7),r2
3646 movzwl 2(r7),r0
3647 bicl2 #-65536,r0
3648 movl r3,r5
3649 movl r1,r4
3650 mull3 r0,r5,-88(fp)
3651 mull2 r2,r5
3652 mull3 r2,r4,-92(fp)
3653 mull2 r0,r4
3654 addl3 -88(fp),-92(fp),r0
3655 bicl3 #0,r0,-88(fp)
3656 cmpl -88(fp),-92(fp)
3657 bgequ noname.339
3658 addl2 #65536,r4
3659noname.339:
3660 movzwl -86(fp),r0
3661 bicl2 #-65536,r0
3662 addl2 r0,r4
3663 bicl3 #-65536,-88(fp),r0
3664 ashl #16,r0,-92(fp)
3665 addl2 -92(fp),r5
3666 bicl2 #0,r5
3667 cmpl r5,-92(fp)
3668 bgequ noname.340
3669 incl r4
3670noname.340:
3671 movl r5,r1
3672 movl r4,r2
3673 addl2 r1,r10
3674 bicl2 #0,r10
3675 cmpl r10,r1
3676 bgequ noname.341
3677 incl r2
3678noname.341:
3679 addl2 r2,r9
3680 bicl2 #0,r9
3681 cmpl r9,r2
3682 bgequ noname.342
3683 incl r8
3684noname.342:
3685
3686 movl r10,12(r11)
3687
3688 clrl r10
3689
3690 bicl3 #-65536,12(r6),r3
3691 movzwl 14(r6),r1
3692 bicl2 #-65536,r1
3693 bicl3 #-65536,4(r7),r2
3694 movzwl 6(r7),r0
3695 bicl2 #-65536,r0
3696 movl r3,r5
3697 movl r1,r4
3698 mull3 r0,r5,-96(fp)
3699 mull2 r2,r5
3700 mull3 r2,r4,-100(fp)
3701 mull2 r0,r4
3702 addl3 -96(fp),-100(fp),r0
3703 bicl3 #0,r0,-96(fp)
3704 cmpl -96(fp),-100(fp)
3705 bgequ noname.343
3706 addl2 #65536,r4
3707noname.343:
3708 movzwl -94(fp),r0
3709 bicl2 #-65536,r0
3710 addl2 r0,r4
3711 bicl3 #-65536,-96(fp),r0
3712 ashl #16,r0,-100(fp)
3713 addl2 -100(fp),r5
3714 bicl2 #0,r5
3715 cmpl r5,-100(fp)
3716 bgequ noname.344
3717 incl r4
3718noname.344:
3719 movl r5,r1
3720 movl r4,r2
3721 addl2 r1,r9
3722 bicl2 #0,r9
3723 cmpl r9,r1
3724 bgequ noname.345
3725 incl r2
3726noname.345:
3727 addl2 r2,r8
3728 bicl2 #0,r8
3729 cmpl r8,r2
3730 bgequ noname.346
3731 incl r10
3732noname.346:
3733
3734 bicl3 #-65536,8(r6),r3
3735 movzwl 10(r6),r1
3736 bicl2 #-65536,r1
3737 bicl3 #-65536,8(r7),r2
3738 movzwl 10(r7),r0
3739 bicl2 #-65536,r0
3740 movl r3,r5
3741 movl r1,r4
3742 mull3 r0,r5,-104(fp)
3743 mull2 r2,r5
3744 mull3 r2,r4,-108(fp)
3745 mull2 r0,r4
3746 addl3 -104(fp),-108(fp),r0
3747 bicl3 #0,r0,-104(fp)
3748 cmpl -104(fp),-108(fp)
3749 bgequ noname.347
3750 addl2 #65536,r4
3751noname.347:
3752 movzwl -102(fp),r0
3753 bicl2 #-65536,r0
3754 addl2 r0,r4
3755 bicl3 #-65536,-104(fp),r0
3756 ashl #16,r0,-108(fp)
3757 addl2 -108(fp),r5
3758 bicl2 #0,r5
3759 cmpl r5,-108(fp)
3760 bgequ noname.348
3761 incl r4
3762noname.348:
3763 movl r5,r1
3764 movl r4,r2
3765 addl2 r1,r9
3766 bicl2 #0,r9
3767 cmpl r9,r1
3768 bgequ noname.349
3769 incl r2
3770noname.349:
3771 addl2 r2,r8
3772 bicl2 #0,r8
3773 cmpl r8,r2
3774 bgequ noname.350
3775 incl r10
3776noname.350:
3777
3778 bicl3 #-65536,4(r6),r3
3779 movzwl 6(r6),r1
3780 bicl2 #-65536,r1
3781 bicl3 #-65536,12(r7),r2
3782 movzwl 14(r7),r0
3783 bicl2 #-65536,r0
3784 movl r3,r5
3785 movl r1,r4
3786 mull3 r0,r5,-112(fp)
3787 mull2 r2,r5
3788 mull3 r2,r4,-116(fp)
3789 mull2 r0,r4
3790 addl3 -112(fp),-116(fp),r0
3791 bicl3 #0,r0,-112(fp)
3792 cmpl -112(fp),-116(fp)
3793 bgequ noname.351
3794 addl2 #65536,r4
3795noname.351:
3796 movzwl -110(fp),r0
3797 bicl2 #-65536,r0
3798 addl2 r0,r4
3799 bicl3 #-65536,-112(fp),r0
3800 ashl #16,r0,-116(fp)
3801 addl2 -116(fp),r5
3802 bicl2 #0,r5
3803 cmpl r5,-116(fp)
3804 bgequ noname.352
3805 incl r4
3806noname.352:
3807 movl r5,r1
3808 movl r4,r2
3809 addl2 r1,r9
3810 bicl2 #0,r9
3811 cmpl r9,r1
3812 bgequ noname.353
3813 incl r2
3814noname.353:
3815 addl2 r2,r8
3816 bicl2 #0,r8
3817 cmpl r8,r2
3818 bgequ noname.354
3819 incl r10
3820noname.354:
3821
3822 movl r9,16(r11)
3823
3824 clrl r9
3825
3826 bicl3 #-65536,8(r6),r3
3827 movzwl 10(r6),r1
3828 bicl2 #-65536,r1
3829 bicl3 #-65536,12(r7),r2
3830 movzwl 14(r7),r0
3831 bicl2 #-65536,r0
3832 movl r3,r5
3833 movl r1,r4
3834 mull3 r0,r5,-120(fp)
3835 mull2 r2,r5
3836 mull3 r2,r4,-124(fp)
3837 mull2 r0,r4
3838 addl3 -120(fp),-124(fp),r0
3839 bicl3 #0,r0,-120(fp)
3840 cmpl -120(fp),-124(fp)
3841 bgequ noname.355
3842 addl2 #65536,r4
3843noname.355:
3844 movzwl -118(fp),r0
3845 bicl2 #-65536,r0
3846 addl2 r0,r4
3847 bicl3 #-65536,-120(fp),r0
3848 ashl #16,r0,-124(fp)
3849 addl2 -124(fp),r5
3850 bicl2 #0,r5
3851 cmpl r5,-124(fp)
3852 bgequ noname.356
3853 incl r4
3854noname.356:
3855 movl r5,r1
3856 movl r4,r2
3857 addl2 r1,r8
3858 bicl2 #0,r8
3859 cmpl r8,r1
3860 bgequ noname.357
3861 incl r2
3862noname.357:
3863 addl2 r2,r10
3864 bicl2 #0,r10
3865 cmpl r10,r2
3866 bgequ noname.358
3867 incl r9
3868noname.358:
3869
3870 movzwl 14(r6),r2
3871 bicl3 #-65536,8(r7),r3
3872 movzwl 10(r7),r0
3873 bicl2 #-65536,r0
3874 bicl3 #-65536,12(r6),-136(fp)
3875 bicl3 #-65536,r2,-140(fp)
3876 mull3 r0,-136(fp),-128(fp)
3877 mull2 r3,-136(fp)
3878 mull3 r3,-140(fp),-132(fp)
3879 mull2 r0,-140(fp)
3880 addl3 -128(fp),-132(fp),r0
3881 bicl3 #0,r0,-128(fp)
3882 cmpl -128(fp),-132(fp)
3883 bgequ noname.359
3884 addl2 #65536,-140(fp)
3885noname.359:
3886 movzwl -126(fp),r0
3887 bicl2 #-65536,r0
3888 addl2 r0,-140(fp)
3889 bicl3 #-65536,-128(fp),r0
3890 ashl #16,r0,-132(fp)
3891 addl3 -132(fp),-136(fp),r0
3892 bicl3 #0,r0,-136(fp)
3893 cmpl -136(fp),-132(fp)
3894 bgequ noname.360
3895 incl -140(fp)
3896noname.360:
3897 movl -136(fp),r1
3898 movl -140(fp),r2
3899 addl2 r1,r8
3900 bicl2 #0,r8
3901 cmpl r8,r1
3902 bgequ noname.361
3903 incl r2
3904noname.361:
3905 addl2 r2,r10
3906 bicl2 #0,r10
3907 cmpl r10,r2
3908 bgequ noname.362
3909 incl r9
3910noname.362:
3911
3912 movl r8,20(r11)
3913
3914 clrl r8
3915
3916 movzwl 14(r6),r2
3917 bicl3 #-65536,12(r7),r3
3918 movzwl 14(r7),r0
3919 bicl2 #-65536,r0
3920 bicl3 #-65536,12(r6),-152(fp)
3921 bicl3 #-65536,r2,-156(fp)
3922 mull3 r0,-152(fp),-144(fp)
3923 mull2 r3,-152(fp)
3924 mull3 r3,-156(fp),-148(fp)
3925 mull2 r0,-156(fp)
3926 addl3 -144(fp),-148(fp),r0
3927 bicl3 #0,r0,-144(fp)
3928 cmpl -144(fp),-148(fp)
3929 bgequ noname.363
3930 addl2 #65536,-156(fp)
3931noname.363:
3932 movzwl -142(fp),r0
3933 bicl2 #-65536,r0
3934 addl2 r0,-156(fp)
3935 bicl3 #-65536,-144(fp),r0
3936 ashl #16,r0,-148(fp)
3937 addl3 -148(fp),-152(fp),r0
3938 bicl3 #0,r0,-152(fp)
3939 cmpl -152(fp),-148(fp)
3940 bgequ noname.364
3941 incl -156(fp)
3942noname.364:
3943 movl -152(fp),r1
3944 movl -156(fp),r2
3945 addl2 r1,r10
3946 bicl2 #0,r10
3947 cmpl r10,r1
3948 bgequ noname.365
3949 incl r2
3950noname.365:
3951 addl2 r2,r9
3952 bicl2 #0,r9
3953 cmpl r9,r2
3954 bgequ noname.366
3955 incl r8
3956noname.366:
3957
3958 movl r10,24(r11)
3959
3960 movl r9,28(r11)
3961
3962 ret
3963
3964
3965
3966;r=4 ;(AP)
3967;a=8 ;(AP)
3968;b=12 ;(AP)
3969;n=16 ;(AP) n by value (input)
3970
3971 .psect code,nowrt
3972
3973.entry BN_SQR_COMBA8,^m<r2,r3,r4,r5,r6,r7,r8,r9>
3974 movab -444(sp),sp
3975
3976 clrq r8
3977
3978 clrl r7
3979
3980 movl 8(ap),r4
3981 movl (r4),r3
3982 bicl3 #-65536,r3,-4(fp)
3983 extzv #16,#16,r3,r0
3984 bicl3 #-65536,r0,r3
3985 movl -4(fp),r0
3986 mull3 r0,r3,-8(fp)
3987 mull3 r0,r0,-4(fp)
3988 mull2 r3,r3
3989 bicl3 #32767,-8(fp),r0
3990 extzv #15,#17,r0,r0
3991 addl2 r0,r3
3992 bicl3 #-65536,-8(fp),r0
3993 ashl #17,r0,-8(fp)
3994 addl3 -4(fp),-8(fp),r0
3995 bicl3 #0,r0,-4(fp)
3996 cmpl -4(fp),-8(fp)
3997 bgequ noname.369
3998 incl r3
3999noname.369:
4000 movl -4(fp),r1
4001 movl r3,r2
4002 addl2 r1,r9
4003 bicl2 #0,r9
4004 cmpl r9,r1
4005 bgequ noname.370
4006 incl r2
4007noname.370:
4008 addl2 r2,r8
4009 bicl2 #0,r8
4010 cmpl r8,r2
4011 bgequ noname.371
4012 incl r7
4013noname.371:
4014
4015 movl r9,@4(ap)
4016
4017 clrl r9
4018
4019 movzwl 6(r4),r2
4020 bicl3 #-65536,(r4),r3
4021 movzwl 2(r4),r0
4022 bicl2 #-65536,r0
4023 bicl3 #-65536,4(r4),-20(fp)
4024 bicl3 #-65536,r2,-24(fp)
4025 mull3 r0,-20(fp),-12(fp)
4026 mull2 r3,-20(fp)
4027 mull3 r3,-24(fp),-16(fp)
4028 mull2 r0,-24(fp)
4029 addl3 -12(fp),-16(fp),r0
4030 bicl3 #0,r0,-12(fp)
4031 cmpl -12(fp),-16(fp)
4032 bgequ noname.372
4033 addl2 #65536,-24(fp)
4034noname.372:
4035 movzwl -10(fp),r0
4036 bicl2 #-65536,r0
4037 addl2 r0,-24(fp)
4038 bicl3 #-65536,-12(fp),r0
4039 ashl #16,r0,-16(fp)
4040 addl3 -16(fp),-20(fp),r0
4041 bicl3 #0,r0,-20(fp)
4042 cmpl -20(fp),-16(fp)
4043 bgequ noname.373
4044 incl -24(fp)
4045noname.373:
4046 movl -20(fp),r3
4047 movl -24(fp),r2
4048 bbc #31,r2,noname.374
4049 incl r9
4050noname.374:
4051 addl2 r2,r2
4052 bicl2 #0,r2
4053 bbc #31,r3,noname.375
4054 incl r2
4055noname.375:
4056 addl2 r3,r3
4057 bicl2 #0,r3
4058 addl2 r3,r8
4059 bicl2 #0,r8
4060 cmpl r8,r3
4061 bgequ noname.376
4062 incl r2
4063 bicl3 #0,r2,r0
4064 bneq noname.376
4065 incl r9
4066noname.376:
4067 addl2 r2,r7
4068 bicl2 #0,r7
4069 cmpl r7,r2
4070 bgequ noname.377
4071 incl r9
4072noname.377:
4073
4074 movl 4(ap),r0
4075 movl r8,4(r0)
4076
4077 clrl r8
4078
4079 movl 8(ap),r4
4080 movl 4(r4),r3
4081 bicl3 #-65536,r3,-28(fp)
4082 extzv #16,#16,r3,r0
4083 bicl3 #-65536,r0,r3
4084 movl -28(fp),r0
4085 mull3 r0,r3,-32(fp)
4086 mull3 r0,r0,-28(fp)
4087 mull2 r3,r3
4088 bicl3 #32767,-32(fp),r0
4089 extzv #15,#17,r0,r0
4090 addl2 r0,r3
4091 bicl3 #-65536,-32(fp),r0
4092 ashl #17,r0,-32(fp)
4093 addl3 -28(fp),-32(fp),r0
4094 bicl3 #0,r0,-28(fp)
4095 cmpl -28(fp),-32(fp)
4096 bgequ noname.378
4097 incl r3
4098noname.378:
4099 movl -28(fp),r1
4100 movl r3,r2
4101 addl2 r1,r7
4102 bicl2 #0,r7
4103 cmpl r7,r1
4104 bgequ noname.379
4105 incl r2
4106noname.379:
4107 addl2 r2,r9
4108 bicl2 #0,r9
4109 cmpl r9,r2
4110 bgequ noname.380
4111 incl r8
4112noname.380:
4113
4114 movzwl 10(r4),r2
4115 bicl3 #-65536,(r4),r3
4116 movzwl 2(r4),r0
4117 bicl2 #-65536,r0
4118 bicl3 #-65536,8(r4),-44(fp)
4119 bicl3 #-65536,r2,-48(fp)
4120 mull3 r0,-44(fp),-36(fp)
4121 mull2 r3,-44(fp)
4122 mull3 r3,-48(fp),-40(fp)
4123 mull2 r0,-48(fp)
4124 addl3 -36(fp),-40(fp),r0
4125 bicl3 #0,r0,-36(fp)
4126 cmpl -36(fp),-40(fp)
4127 bgequ noname.381
4128 addl2 #65536,-48(fp)
4129noname.381:
4130 movzwl -34(fp),r0
4131 bicl2 #-65536,r0
4132 addl2 r0,-48(fp)
4133 bicl3 #-65536,-36(fp),r0
4134 ashl #16,r0,-40(fp)
4135 addl3 -40(fp),-44(fp),r0
4136 bicl3 #0,r0,-44(fp)
4137 cmpl -44(fp),-40(fp)
4138 bgequ noname.382
4139 incl -48(fp)
4140noname.382:
4141 movl -44(fp),r3
4142 movl -48(fp),r2
4143 bbc #31,r2,noname.383
4144 incl r8
4145noname.383:
4146 addl2 r2,r2
4147 bicl2 #0,r2
4148 bbc #31,r3,noname.384
4149 incl r2
4150noname.384:
4151 addl2 r3,r3
4152 bicl2 #0,r3
4153 addl2 r3,r7
4154 bicl2 #0,r7
4155 cmpl r7,r3
4156 bgequ noname.385
4157 incl r2
4158 bicl3 #0,r2,r0
4159 bneq noname.385
4160 incl r8
4161noname.385:
4162 addl2 r2,r9
4163 bicl2 #0,r9
4164 cmpl r9,r2
4165 bgequ noname.386
4166 incl r8
4167noname.386:
4168
4169 movl 4(ap),r0
4170 movl r7,8(r0)
4171
4172 clrl r7
4173
4174 movl 8(ap),r0
4175 movzwl 14(r0),r2
4176 bicl3 #-65536,(r0),r3
4177 movzwl 2(r0),r1
4178 bicl2 #-65536,r1
4179 bicl3 #-65536,12(r0),-60(fp)
4180 bicl3 #-65536,r2,-64(fp)
4181 mull3 r1,-60(fp),-52(fp)
4182 mull2 r3,-60(fp)
4183 mull3 r3,-64(fp),-56(fp)
4184 mull2 r1,-64(fp)
4185 addl3 -52(fp),-56(fp),r0
4186 bicl3 #0,r0,-52(fp)
4187 cmpl -52(fp),-56(fp)
4188 bgequ noname.387
4189 addl2 #65536,-64(fp)
4190noname.387:
4191 movzwl -50(fp),r0
4192 bicl2 #-65536,r0
4193 addl2 r0,-64(fp)
4194 bicl3 #-65536,-52(fp),r0
4195 ashl #16,r0,-56(fp)
4196 addl3 -56(fp),-60(fp),r0
4197 bicl3 #0,r0,-60(fp)
4198 cmpl -60(fp),-56(fp)
4199 bgequ noname.388
4200 incl -64(fp)
4201noname.388:
4202 movl -60(fp),r3
4203 movl -64(fp),r2
4204 bbc #31,r2,noname.389
4205 incl r7
4206noname.389:
4207 addl2 r2,r2
4208 bicl2 #0,r2
4209 bbc #31,r3,noname.390
4210 incl r2
4211noname.390:
4212 addl2 r3,r3
4213 bicl2 #0,r3
4214 addl2 r3,r9
4215 bicl2 #0,r9
4216 cmpl r9,r3
4217 bgequ noname.391
4218 incl r2
4219 bicl3 #0,r2,r0
4220 bneq noname.391
4221 incl r7
4222noname.391:
4223 addl2 r2,r8
4224 bicl2 #0,r8
4225 cmpl r8,r2
4226 bgequ noname.392
4227 incl r7
4228noname.392:
4229
4230 movl 8(ap),r0
4231 movzwl 10(r0),r2
4232 bicl3 #-65536,4(r0),r3
4233 movzwl 6(r0),r1
4234 bicl2 #-65536,r1
4235 bicl3 #-65536,8(r0),-76(fp)
4236 bicl3 #-65536,r2,-80(fp)
4237 mull3 r1,-76(fp),-68(fp)
4238 mull2 r3,-76(fp)
4239 mull3 r3,-80(fp),-72(fp)
4240 mull2 r1,-80(fp)
4241 addl3 -68(fp),-72(fp),r0
4242 bicl3 #0,r0,-68(fp)
4243 cmpl -68(fp),-72(fp)
4244 bgequ noname.393
4245 addl2 #65536,-80(fp)
4246noname.393:
4247 movzwl -66(fp),r0
4248 bicl2 #-65536,r0
4249 addl2 r0,-80(fp)
4250 bicl3 #-65536,-68(fp),r0
4251 ashl #16,r0,-72(fp)
4252 addl3 -72(fp),-76(fp),r0
4253 bicl3 #0,r0,-76(fp)
4254 cmpl -76(fp),-72(fp)
4255 bgequ noname.394
4256 incl -80(fp)
4257noname.394:
4258 movl -76(fp),r3
4259 movl -80(fp),r2
4260 bbc #31,r2,noname.395
4261 incl r7
4262noname.395:
4263 addl2 r2,r2
4264 bicl2 #0,r2
4265 bbc #31,r3,noname.396
4266 incl r2
4267noname.396:
4268 addl2 r3,r3
4269 bicl2 #0,r3
4270 addl2 r3,r9
4271 bicl2 #0,r9
4272 cmpl r9,r3
4273 bgequ noname.397
4274 incl r2
4275 bicl3 #0,r2,r0
4276 bneq noname.397
4277 incl r7
4278noname.397:
4279 addl2 r2,r8
4280 bicl2 #0,r8
4281 cmpl r8,r2
4282 bgequ noname.398
4283 incl r7
4284noname.398:
4285
4286 movl 4(ap),r0
4287 movl r9,12(r0)
4288
4289 clrl r9
4290
4291 movl 8(ap),r2
4292 movl 8(r2),r4
4293 bicl3 #-65536,r4,-84(fp)
4294 extzv #16,#16,r4,r0
4295 bicl3 #-65536,r0,r4
4296 movl -84(fp),r0
4297 mull3 r0,r4,-88(fp)
4298 mull3 r0,r0,-84(fp)
4299 mull2 r4,r4
4300 bicl3 #32767,-88(fp),r0
4301 extzv #15,#17,r0,r0
4302 addl2 r0,r4
4303 bicl3 #-65536,-88(fp),r0
4304 ashl #17,r0,-88(fp)
4305 addl3 -84(fp),-88(fp),r0
4306 bicl3 #0,r0,-84(fp)
4307 cmpl -84(fp),-88(fp)
4308 bgequ noname.399
4309 incl r4
4310noname.399:
4311 movl -84(fp),r1
4312 movl r4,r3
4313 addl2 r1,r8
4314 bicl2 #0,r8
4315 cmpl r8,r1
4316 bgequ noname.400
4317 incl r3
4318noname.400:
4319 addl2 r3,r7
4320 bicl2 #0,r7
4321 cmpl r7,r3
4322 bgequ noname.401
4323 incl r9
4324noname.401:
4325
4326 movzwl 14(r2),r3
4327 bicl3 #-65536,4(r2),r1
4328 movzwl 6(r2),r0
4329 bicl2 #-65536,r0
4330 bicl3 #-65536,12(r2),-100(fp)
4331 bicl3 #-65536,r3,-104(fp)
4332 mull3 r0,-100(fp),-92(fp)
4333 mull2 r1,-100(fp)
4334 mull3 r1,-104(fp),-96(fp)
4335 mull2 r0,-104(fp)
4336 addl3 -92(fp),-96(fp),r0
4337 bicl3 #0,r0,-92(fp)
4338 cmpl -92(fp),-96(fp)
4339 bgequ noname.402
4340 addl2 #65536,-104(fp)
4341noname.402:
4342 movzwl -90(fp),r0
4343 bicl2 #-65536,r0
4344 addl2 r0,-104(fp)
4345 bicl3 #-65536,-92(fp),r0
4346 ashl #16,r0,-96(fp)
4347 addl3 -96(fp),-100(fp),r0
4348 bicl3 #0,r0,-100(fp)
4349 cmpl -100(fp),-96(fp)
4350 bgequ noname.403
4351 incl -104(fp)
4352noname.403:
4353 movl -100(fp),r3
4354 movl -104(fp),r2
4355 bbc #31,r2,noname.404
4356 incl r9
4357noname.404:
4358 addl2 r2,r2
4359 bicl2 #0,r2
4360 bbc #31,r3,noname.405
4361 incl r2
4362noname.405:
4363 addl2 r3,r3
4364 bicl2 #0,r3
4365 addl2 r3,r8
4366 bicl2 #0,r8
4367 cmpl r8,r3
4368 bgequ noname.406
4369 incl r2
4370 bicl3 #0,r2,r0
4371 bneq noname.406
4372 incl r9
4373noname.406:
4374 addl2 r2,r7
4375 bicl2 #0,r7
4376 cmpl r7,r2
4377 bgequ noname.407
4378 incl r9
4379noname.407:
4380
4381 movl 8(ap),r0
4382 movzwl 18(r0),r2
4383 bicl3 #-65536,(r0),r3
4384 movzwl 2(r0),r1
4385 bicl2 #-65536,r1
4386 bicl3 #-65536,16(r0),-116(fp)
4387 bicl3 #-65536,r2,-120(fp)
4388 mull3 r1,-116(fp),-108(fp)
4389 mull2 r3,-116(fp)
4390 mull3 r3,-120(fp),-112(fp)
4391 mull2 r1,-120(fp)
4392 addl3 -108(fp),-112(fp),r0
4393 bicl3 #0,r0,-108(fp)
4394 cmpl -108(fp),-112(fp)
4395 bgequ noname.408
4396 addl2 #65536,-120(fp)
4397noname.408:
4398 movzwl -106(fp),r0
4399 bicl2 #-65536,r0
4400 addl2 r0,-120(fp)
4401 bicl3 #-65536,-108(fp),r0
4402 ashl #16,r0,-112(fp)
4403 addl3 -112(fp),-116(fp),r0
4404 bicl3 #0,r0,-116(fp)
4405 cmpl -116(fp),-112(fp)
4406 bgequ noname.409
4407 incl -120(fp)
4408noname.409:
4409 movl -116(fp),r3
4410 movl -120(fp),r2
4411 bbc #31,r2,noname.410
4412 incl r9
4413noname.410:
4414 addl2 r2,r2
4415 bicl2 #0,r2
4416 bbc #31,r3,noname.411
4417 incl r2
4418noname.411:
4419 addl2 r3,r3
4420 bicl2 #0,r3
4421 addl2 r3,r8
4422 bicl2 #0,r8
4423 cmpl r8,r3
4424 bgequ noname.412
4425 incl r2
4426 bicl3 #0,r2,r0
4427 bneq noname.412
4428 incl r9
4429noname.412:
4430 addl2 r2,r7
4431 bicl2 #0,r7
4432 cmpl r7,r2
4433 bgequ noname.413
4434 incl r9
4435noname.413:
4436
4437 movl 4(ap),r0
4438 movl r8,16(r0)
4439
4440 clrl r8
4441
4442 movl 8(ap),r0
4443 movzwl 22(r0),r2
4444 bicl3 #-65536,(r0),r3
4445 movzwl 2(r0),r1
4446 bicl2 #-65536,r1
4447 bicl3 #-65536,20(r0),-132(fp)
4448 bicl3 #-65536,r2,-136(fp)
4449 mull3 r1,-132(fp),-124(fp)
4450 mull2 r3,-132(fp)
4451 mull3 r3,-136(fp),-128(fp)
4452 mull2 r1,-136(fp)
4453 addl3 -124(fp),-128(fp),r0
4454 bicl3 #0,r0,-124(fp)
4455 cmpl -124(fp),-128(fp)
4456 bgequ noname.414
4457 addl2 #65536,-136(fp)
4458noname.414:
4459 movzwl -122(fp),r0
4460 bicl2 #-65536,r0
4461 addl2 r0,-136(fp)
4462 bicl3 #-65536,-124(fp),r0
4463 ashl #16,r0,-128(fp)
4464 addl3 -128(fp),-132(fp),r0
4465 bicl3 #0,r0,-132(fp)
4466 cmpl -132(fp),-128(fp)
4467 bgequ noname.415
4468 incl -136(fp)
4469noname.415:
4470 movl -132(fp),r3
4471 movl -136(fp),r2
4472 bbc #31,r2,noname.416
4473 incl r8
4474noname.416:
4475 addl2 r2,r2
4476 bicl2 #0,r2
4477 bbc #31,r3,noname.417
4478 incl r2
4479noname.417:
4480 addl2 r3,r3
4481 bicl2 #0,r3
4482 addl2 r3,r7
4483 bicl2 #0,r7
4484 cmpl r7,r3
4485 bgequ noname.418
4486 incl r2
4487 bicl3 #0,r2,r0
4488 bneq noname.418
4489 incl r8
4490noname.418:
4491 addl2 r2,r9
4492 bicl2 #0,r9
4493 cmpl r9,r2
4494 bgequ noname.419
4495 incl r8
4496noname.419:
4497
4498 movl 8(ap),r0
4499 movzwl 18(r0),r2
4500 bicl3 #-65536,4(r0),r3
4501 movzwl 6(r0),r1
4502 bicl2 #-65536,r1
4503 bicl3 #-65536,16(r0),-148(fp)
4504 bicl3 #-65536,r2,-152(fp)
4505 mull3 r1,-148(fp),-140(fp)
4506 mull2 r3,-148(fp)
4507 mull3 r3,-152(fp),-144(fp)
4508 mull2 r1,-152(fp)
4509 addl3 -140(fp),-144(fp),r0
4510 bicl3 #0,r0,-140(fp)
4511 cmpl -140(fp),-144(fp)
4512 bgequ noname.420
4513 addl2 #65536,-152(fp)
4514noname.420:
4515 movzwl -138(fp),r0
4516 bicl2 #-65536,r0
4517 addl2 r0,-152(fp)
4518 bicl3 #-65536,-140(fp),r0
4519 ashl #16,r0,-144(fp)
4520 addl3 -144(fp),-148(fp),r0
4521 bicl3 #0,r0,-148(fp)
4522 cmpl -148(fp),-144(fp)
4523 bgequ noname.421
4524 incl -152(fp)
4525noname.421:
4526 movl -148(fp),r3
4527 movl -152(fp),r2
4528 bbc #31,r2,noname.422
4529 incl r8
4530noname.422:
4531 addl2 r2,r2
4532 bicl2 #0,r2
4533 bbc #31,r3,noname.423
4534 incl r2
4535noname.423:
4536 addl2 r3,r3
4537 bicl2 #0,r3
4538 addl2 r3,r7
4539 bicl2 #0,r7
4540 cmpl r7,r3
4541 bgequ noname.424
4542 incl r2
4543 bicl3 #0,r2,r0
4544 bneq noname.424
4545 incl r8
4546noname.424:
4547 addl2 r2,r9
4548 bicl2 #0,r9
4549 cmpl r9,r2
4550 bgequ noname.425
4551 incl r8
4552noname.425:
4553
4554 movl 8(ap),r0
4555 movzwl 14(r0),r2
4556 bicl3 #-65536,8(r0),r3
4557 movzwl 10(r0),r1
4558 bicl2 #-65536,r1
4559 bicl3 #-65536,12(r0),-164(fp)
4560 bicl3 #-65536,r2,-168(fp)
4561 mull3 r1,-164(fp),-156(fp)
4562 mull2 r3,-164(fp)
4563 mull3 r3,-168(fp),-160(fp)
4564 mull2 r1,-168(fp)
4565 addl3 -156(fp),-160(fp),r0
4566 bicl3 #0,r0,-156(fp)
4567 cmpl -156(fp),-160(fp)
4568 bgequ noname.426
4569 addl2 #65536,-168(fp)
4570noname.426:
4571 movzwl -154(fp),r0
4572 bicl2 #-65536,r0
4573 addl2 r0,-168(fp)
4574 bicl3 #-65536,-156(fp),r0
4575 ashl #16,r0,-160(fp)
4576 addl3 -160(fp),-164(fp),r0
4577 bicl3 #0,r0,-164(fp)
4578 cmpl -164(fp),-160(fp)
4579 bgequ noname.427
4580 incl -168(fp)
4581noname.427:
4582 movl -164(fp),r3
4583 movl -168(fp),r2
4584 bbc #31,r2,noname.428
4585 incl r8
4586noname.428:
4587 addl2 r2,r2
4588 bicl2 #0,r2
4589 bbc #31,r3,noname.429
4590 incl r2
4591noname.429:
4592 addl2 r3,r3
4593 bicl2 #0,r3
4594 addl2 r3,r7
4595 bicl2 #0,r7
4596 cmpl r7,r3
4597 bgequ noname.430
4598 incl r2
4599 bicl3 #0,r2,r0
4600 bneq noname.430
4601 incl r8
4602noname.430:
4603 addl2 r2,r9
4604 bicl2 #0,r9
4605 cmpl r9,r2
4606 bgequ noname.431
4607 incl r8
4608noname.431:
4609
4610 movl 4(ap),r0
4611 movl r7,20(r0)
4612
4613 clrl r7
4614
4615 movl 8(ap),r2
4616 movl 12(r2),r4
4617 bicl3 #-65536,r4,-172(fp)
4618 extzv #16,#16,r4,r0
4619 bicl3 #-65536,r0,r4
4620 movl -172(fp),r0
4621 mull3 r0,r4,-176(fp)
4622 mull3 r0,r0,-172(fp)
4623 mull2 r4,r4
4624 bicl3 #32767,-176(fp),r0
4625 extzv #15,#17,r0,r0
4626 addl2 r0,r4
4627 bicl3 #-65536,-176(fp),r0
4628 ashl #17,r0,-176(fp)
4629 addl3 -172(fp),-176(fp),r0
4630 bicl3 #0,r0,-172(fp)
4631 cmpl -172(fp),-176(fp)
4632 bgequ noname.432
4633 incl r4
4634noname.432:
4635 movl -172(fp),r1
4636 movl r4,r3
4637 addl2 r1,r9
4638 bicl2 #0,r9
4639 cmpl r9,r1
4640 bgequ noname.433
4641 incl r3
4642noname.433:
4643 addl2 r3,r8
4644 bicl2 #0,r8
4645 cmpl r8,r3
4646 bgequ noname.434
4647 incl r7
4648noname.434:
4649
4650 movzwl 18(r2),r3
4651 bicl3 #-65536,8(r2),r1
4652 movzwl 10(r2),r0
4653 bicl2 #-65536,r0
4654 bicl3 #-65536,16(r2),-188(fp)
4655 bicl3 #-65536,r3,-192(fp)
4656 mull3 r0,-188(fp),-180(fp)
4657 mull2 r1,-188(fp)
4658 mull3 r1,-192(fp),-184(fp)
4659 mull2 r0,-192(fp)
4660 addl3 -180(fp),-184(fp),r0
4661 bicl3 #0,r0,-180(fp)
4662 cmpl -180(fp),-184(fp)
4663 bgequ noname.435
4664 addl2 #65536,-192(fp)
4665noname.435:
4666 movzwl -178(fp),r0
4667 bicl2 #-65536,r0
4668 addl2 r0,-192(fp)
4669 bicl3 #-65536,-180(fp),r0
4670 ashl #16,r0,-184(fp)
4671 addl3 -184(fp),-188(fp),r0
4672 bicl3 #0,r0,-188(fp)
4673 cmpl -188(fp),-184(fp)
4674 bgequ noname.436
4675 incl -192(fp)
4676noname.436:
4677 movl -188(fp),r3
4678 movl -192(fp),r2
4679 bbc #31,r2,noname.437
4680 incl r7
4681noname.437:
4682 addl2 r2,r2
4683 bicl2 #0,r2
4684 bbc #31,r3,noname.438
4685 incl r2
4686noname.438:
4687 addl2 r3,r3
4688 bicl2 #0,r3
4689 addl2 r3,r9
4690 bicl2 #0,r9
4691 cmpl r9,r3
4692 bgequ noname.439
4693 incl r2
4694 bicl3 #0,r2,r0
4695 bneq noname.439
4696 incl r7
4697noname.439:
4698 addl2 r2,r8
4699 bicl2 #0,r8
4700 cmpl r8,r2
4701 bgequ noname.440
4702 incl r7
4703noname.440:
4704
4705 movl 8(ap),r0
4706 movzwl 22(r0),r2
4707 bicl3 #-65536,4(r0),r3
4708 movzwl 6(r0),r1
4709 bicl2 #-65536,r1
4710 bicl3 #-65536,20(r0),-204(fp)
4711 bicl3 #-65536,r2,-208(fp)
4712 mull3 r1,-204(fp),-196(fp)
4713 mull2 r3,-204(fp)
4714 mull3 r3,-208(fp),-200(fp)
4715 mull2 r1,-208(fp)
4716 addl3 -196(fp),-200(fp),r0
4717 bicl3 #0,r0,-196(fp)
4718 cmpl -196(fp),-200(fp)
4719 bgequ noname.441
4720 addl2 #65536,-208(fp)
4721noname.441:
4722 movzwl -194(fp),r0
4723 bicl2 #-65536,r0
4724 addl2 r0,-208(fp)
4725 bicl3 #-65536,-196(fp),r0
4726 ashl #16,r0,-200(fp)
4727 addl3 -200(fp),-204(fp),r0
4728 bicl3 #0,r0,-204(fp)
4729 cmpl -204(fp),-200(fp)
4730 bgequ noname.442
4731 incl -208(fp)
4732noname.442:
4733 movl -204(fp),r3
4734 movl -208(fp),r2
4735 bbc #31,r2,noname.443
4736 incl r7
4737noname.443:
4738 addl2 r2,r2
4739 bicl2 #0,r2
4740 bbc #31,r3,noname.444
4741 incl r2
4742noname.444:
4743 addl2 r3,r3
4744 bicl2 #0,r3
4745 addl2 r3,r9
4746 bicl2 #0,r9
4747 cmpl r9,r3
4748 bgequ noname.445
4749 incl r2
4750 bicl3 #0,r2,r0
4751 bneq noname.445
4752 incl r7
4753noname.445:
4754 addl2 r2,r8
4755 bicl2 #0,r8
4756 cmpl r8,r2
4757 bgequ noname.446
4758 incl r7
4759noname.446:
4760
4761 movl 8(ap),r0
4762 movzwl 26(r0),r2
4763 bicl3 #-65536,(r0),r3
4764 movzwl 2(r0),r1
4765 bicl2 #-65536,r1
4766 bicl3 #-65536,24(r0),-220(fp)
4767 bicl3 #-65536,r2,-224(fp)
4768 mull3 r1,-220(fp),-212(fp)
4769 mull2 r3,-220(fp)
4770 mull3 r3,-224(fp),-216(fp)
4771 mull2 r1,-224(fp)
4772 addl3 -212(fp),-216(fp),r0
4773 bicl3 #0,r0,-212(fp)
4774 cmpl -212(fp),-216(fp)
4775 bgequ noname.447
4776 addl2 #65536,-224(fp)
4777noname.447:
4778 movzwl -210(fp),r0
4779 bicl2 #-65536,r0
4780 addl2 r0,-224(fp)
4781 bicl3 #-65536,-212(fp),r0
4782 ashl #16,r0,-216(fp)
4783 addl3 -216(fp),-220(fp),r0
4784 bicl3 #0,r0,-220(fp)
4785 cmpl -220(fp),-216(fp)
4786 bgequ noname.448
4787 incl -224(fp)
4788noname.448:
4789 movl -220(fp),r3
4790 movl -224(fp),r2
4791 bbc #31,r2,noname.449
4792 incl r7
4793noname.449:
4794 addl2 r2,r2
4795 bicl2 #0,r2
4796 bbc #31,r3,noname.450
4797 incl r2
4798noname.450:
4799 addl2 r3,r3
4800 bicl2 #0,r3
4801 addl2 r3,r9
4802 bicl2 #0,r9
4803 cmpl r9,r3
4804 bgequ noname.451
4805 incl r2
4806 bicl3 #0,r2,r0
4807 bneq noname.451
4808 incl r7
4809noname.451:
4810 addl2 r2,r8
4811 bicl2 #0,r8
4812 cmpl r8,r2
4813 bgequ noname.452
4814 incl r7
4815noname.452:
4816
4817 movl 4(ap),r0
4818 movl r9,24(r0)
4819
4820 clrl r9
4821
4822 movl 8(ap),r0
4823 movzwl 30(r0),r2
4824 bicl3 #-65536,(r0),r3
4825 movzwl 2(r0),r1
4826 bicl2 #-65536,r1
4827 bicl3 #-65536,28(r0),-236(fp)
4828 bicl3 #-65536,r2,-240(fp)
4829 mull3 r1,-236(fp),-228(fp)
4830 mull2 r3,-236(fp)
4831 mull3 r3,-240(fp),-232(fp)
4832 mull2 r1,-240(fp)
4833 addl3 -228(fp),-232(fp),r0
4834 bicl3 #0,r0,-228(fp)
4835 cmpl -228(fp),-232(fp)
4836 bgequ noname.453
4837 addl2 #65536,-240(fp)
4838noname.453:
4839 movzwl -226(fp),r0
4840 bicl2 #-65536,r0
4841 addl2 r0,-240(fp)
4842 bicl3 #-65536,-228(fp),r0
4843 ashl #16,r0,-232(fp)
4844 addl3 -232(fp),-236(fp),r0
4845 bicl3 #0,r0,-236(fp)
4846 cmpl -236(fp),-232(fp)
4847 bgequ noname.454
4848 incl -240(fp)
4849noname.454:
4850 movl -236(fp),r3
4851 movl -240(fp),r2
4852 bbc #31,r2,noname.455
4853 incl r9
4854noname.455:
4855 addl2 r2,r2
4856 bicl2 #0,r2
4857 bbc #31,r3,noname.456
4858 incl r2
4859noname.456:
4860 addl2 r3,r3
4861 bicl2 #0,r3
4862 addl2 r3,r8
4863 bicl2 #0,r8
4864 cmpl r8,r3
4865 bgequ noname.457
4866 incl r2
4867 bicl3 #0,r2,r0
4868 bneq noname.457
4869 incl r9
4870noname.457:
4871 addl2 r2,r7
4872 bicl2 #0,r7
4873 cmpl r7,r2
4874 bgequ noname.458
4875 incl r9
4876noname.458:
4877
4878 movl 8(ap),r0
4879 movzwl 26(r0),r2
4880 bicl3 #-65536,4(r0),r3
4881 movzwl 6(r0),r1
4882 bicl2 #-65536,r1
4883 bicl3 #-65536,24(r0),-252(fp)
4884 bicl3 #-65536,r2,-256(fp)
4885 mull3 r1,-252(fp),-244(fp)
4886 mull2 r3,-252(fp)
4887 mull3 r3,-256(fp),-248(fp)
4888 mull2 r1,-256(fp)
4889 addl3 -244(fp),-248(fp),r0
4890 bicl3 #0,r0,-244(fp)
4891 cmpl -244(fp),-248(fp)
4892 bgequ noname.459
4893 addl2 #65536,-256(fp)
4894noname.459:
4895 movzwl -242(fp),r0
4896 bicl2 #-65536,r0
4897 addl2 r0,-256(fp)
4898 bicl3 #-65536,-244(fp),r0
4899 ashl #16,r0,-248(fp)
4900 addl3 -248(fp),-252(fp),r0
4901 bicl3 #0,r0,-252(fp)
4902 cmpl -252(fp),-248(fp)
4903 bgequ noname.460
4904 incl -256(fp)
4905noname.460:
4906 movl -252(fp),r3
4907 movl -256(fp),r2
4908 bbc #31,r2,noname.461
4909 incl r9
4910noname.461:
4911 addl2 r2,r2
4912 bicl2 #0,r2
4913 bbc #31,r3,noname.462
4914 incl r2
4915noname.462:
4916 addl2 r3,r3
4917 bicl2 #0,r3
4918 addl2 r3,r8
4919 bicl2 #0,r8
4920 cmpl r8,r3
4921 bgequ noname.463
4922 incl r2
4923 bicl3 #0,r2,r0
4924 bneq noname.463
4925 incl r9
4926noname.463:
4927 addl2 r2,r7
4928 bicl2 #0,r7
4929 cmpl r7,r2
4930 bgequ noname.464
4931 incl r9
4932noname.464:
4933
4934 movl 8(ap),r0
4935 movzwl 22(r0),r2
4936 bicl3 #-65536,8(r0),r3
4937 movzwl 10(r0),r1
4938 bicl2 #-65536,r1
4939 bicl3 #-65536,20(r0),-268(fp)
4940 bicl3 #-65536,r2,-272(fp)
4941 mull3 r1,-268(fp),-260(fp)
4942 mull2 r3,-268(fp)
4943 mull3 r3,-272(fp),-264(fp)
4944 mull2 r1,-272(fp)
4945 addl3 -260(fp),-264(fp),r0
4946 bicl3 #0,r0,-260(fp)
4947 cmpl -260(fp),-264(fp)
4948 bgequ noname.465
4949 addl2 #65536,-272(fp)
4950noname.465:
4951 movzwl -258(fp),r0
4952 bicl2 #-65536,r0
4953 addl2 r0,-272(fp)
4954 bicl3 #-65536,-260(fp),r0
4955 ashl #16,r0,-264(fp)
4956 addl3 -264(fp),-268(fp),r0
4957 bicl3 #0,r0,-268(fp)
4958 cmpl -268(fp),-264(fp)
4959 bgequ noname.466
4960 incl -272(fp)
4961noname.466:
4962 movl -268(fp),r3
4963 movl -272(fp),r2
4964 bbc #31,r2,noname.467
4965 incl r9
4966noname.467:
4967 addl2 r2,r2
4968 bicl2 #0,r2
4969 bbc #31,r3,noname.468
4970 incl r2
4971noname.468:
4972 addl2 r3,r3
4973 bicl2 #0,r3
4974 addl2 r3,r8
4975 bicl2 #0,r8
4976 cmpl r8,r3
4977 bgequ noname.469
4978 incl r2
4979 bicl3 #0,r2,r0
4980 bneq noname.469
4981 incl r9
4982noname.469:
4983 addl2 r2,r7
4984 bicl2 #0,r7
4985 cmpl r7,r2
4986 bgequ noname.470
4987 incl r9
4988noname.470:
4989
4990 movl 8(ap),r0
4991 movzwl 18(r0),r2
4992 bicl3 #-65536,12(r0),r3
4993 movzwl 14(r0),r1
4994 bicl2 #-65536,r1
4995 bicl3 #-65536,16(r0),-284(fp)
4996 bicl3 #-65536,r2,-288(fp)
4997 mull3 r1,-284(fp),-276(fp)
4998 mull2 r3,-284(fp)
4999 mull3 r3,-288(fp),-280(fp)
5000 mull2 r1,-288(fp)
5001 addl3 -276(fp),-280(fp),r0
5002 bicl3 #0,r0,-276(fp)
5003 cmpl -276(fp),-280(fp)
5004 bgequ noname.471
5005 addl2 #65536,-288(fp)
5006noname.471:
5007 movzwl -274(fp),r0
5008 bicl2 #-65536,r0
5009 addl2 r0,-288(fp)
5010 bicl3 #-65536,-276(fp),r0
5011 ashl #16,r0,-280(fp)
5012 addl3 -280(fp),-284(fp),r0
5013 bicl3 #0,r0,-284(fp)
5014 cmpl -284(fp),-280(fp)
5015 bgequ noname.472
5016 incl -288(fp)
5017noname.472:
5018 movl -284(fp),r3
5019 movl -288(fp),r2
5020 bbc #31,r2,noname.473
5021 incl r9
5022noname.473:
5023 addl2 r2,r2
5024 bicl2 #0,r2
5025 bbc #31,r3,noname.474
5026 incl r2
5027noname.474:
5028 addl2 r3,r3
5029 bicl2 #0,r3
5030 addl2 r3,r8
5031 bicl2 #0,r8
5032 cmpl r8,r3
5033 bgequ noname.475
5034 incl r2
5035 bicl3 #0,r2,r0
5036 bneq noname.475
5037 incl r9
5038noname.475:
5039 addl2 r2,r7
5040 bicl2 #0,r7
5041 cmpl r7,r2
5042 bgequ noname.476
5043 incl r9
5044noname.476:
5045
5046 movl 4(ap),r0
5047 movl r8,28(r0)
5048
5049 clrl r8
5050
5051 movl 8(ap),r3
5052 movl 16(r3),r4
5053 bicl3 #-65536,r4,r5
5054 extzv #16,#16,r4,r0
5055 bicl3 #-65536,r0,r4
5056 mull3 r5,r4,-292(fp)
5057 mull2 r5,r5
5058 mull2 r4,r4
5059 bicl3 #32767,-292(fp),r0
5060 extzv #15,#17,r0,r0
5061 addl2 r0,r4
5062 bicl3 #-65536,-292(fp),r0
5063 ashl #17,r0,-292(fp)
5064 addl2 -292(fp),r5
5065 bicl2 #0,r5
5066 cmpl r5,-292(fp)
5067 bgequ noname.477
5068 incl r4
5069noname.477:
5070 movl r5,r1
5071 movl r4,r2
5072 addl2 r1,r7
5073 bicl2 #0,r7
5074 cmpl r7,r1
5075 bgequ noname.478
5076 incl r2
5077noname.478:
5078 addl2 r2,r9
5079 bicl2 #0,r9
5080 cmpl r9,r2
5081 bgequ noname.479
5082 incl r8
5083noname.479:
5084
5085 bicl3 #-65536,20(r3),r4
5086 movzwl 22(r3),r1
5087 bicl2 #-65536,r1
5088 bicl3 #-65536,12(r3),r2
5089 movzwl 14(r3),r0
5090 bicl2 #-65536,r0
5091 movl r4,r6
5092 movl r1,r5
5093 mull3 r0,r6,-296(fp)
5094 mull2 r2,r6
5095 mull3 r2,r5,-300(fp)
5096 mull2 r0,r5
5097 addl3 -296(fp),-300(fp),r0
5098 bicl3 #0,r0,-296(fp)
5099 cmpl -296(fp),-300(fp)
5100 bgequ noname.480
5101 addl2 #65536,r5
5102noname.480:
5103 movzwl -294(fp),r0
5104 bicl2 #-65536,r0
5105 addl2 r0,r5
5106 bicl3 #-65536,-296(fp),r0
5107 ashl #16,r0,-300(fp)
5108 addl2 -300(fp),r6
5109 bicl2 #0,r6
5110 cmpl r6,-300(fp)
5111 bgequ noname.481
5112 incl r5
5113noname.481:
5114 movl r6,r3
5115 movl r5,r2
5116 bbc #31,r2,noname.482
5117 incl r8
5118noname.482:
5119 addl2 r2,r2
5120 bicl2 #0,r2
5121 bbc #31,r3,noname.483
5122 incl r2
5123noname.483:
5124 addl2 r3,r3
5125 bicl2 #0,r3
5126 addl2 r3,r7
5127 bicl2 #0,r7
5128 cmpl r7,r3
5129 bgequ noname.484
5130 incl r2
5131 bicl3 #0,r2,r0
5132 bneq noname.484
5133 incl r8
5134noname.484:
5135 addl2 r2,r9
5136 bicl2 #0,r9
5137 cmpl r9,r2
5138 bgequ noname.485
5139 incl r8
5140noname.485:
5141
5142 movl 8(ap),r0
5143 bicl3 #-65536,24(r0),r3
5144 movzwl 26(r0),r1
5145 bicl2 #-65536,r1
5146 bicl3 #-65536,8(r0),r2
5147 movzwl 10(r0),r0
5148 bicl2 #-65536,r0
5149 movl r3,r5
5150 movl r1,r4
5151 mull3 r0,r5,-304(fp)
5152 mull2 r2,r5
5153 mull3 r2,r4,-308(fp)
5154 mull2 r0,r4
5155 addl3 -304(fp),-308(fp),r0
5156 bicl3 #0,r0,-304(fp)
5157 cmpl -304(fp),-308(fp)
5158 bgequ noname.486
5159 addl2 #65536,r4
5160noname.486:
5161 movzwl -302(fp),r0
5162 bicl2 #-65536,r0
5163 addl2 r0,r4
5164 bicl3 #-65536,-304(fp),r0
5165 ashl #16,r0,-308(fp)
5166 addl2 -308(fp),r5
5167 bicl2 #0,r5
5168 cmpl r5,-308(fp)
5169 bgequ noname.487
5170 incl r4
5171noname.487:
5172 movl r5,r3
5173 movl r4,r2
5174 bbc #31,r2,noname.488
5175 incl r8
5176noname.488:
5177 addl2 r2,r2
5178 bicl2 #0,r2
5179 bbc #31,r3,noname.489
5180 incl r2
5181noname.489:
5182 addl2 r3,r3
5183 bicl2 #0,r3
5184 addl2 r3,r7
5185 bicl2 #0,r7
5186 cmpl r7,r3
5187 bgequ noname.490
5188 incl r2
5189 bicl3 #0,r2,r0
5190 bneq noname.490
5191 incl r8
5192noname.490:
5193 addl2 r2,r9
5194 bicl2 #0,r9
5195 cmpl r9,r2
5196 bgequ noname.491
5197 incl r8
5198noname.491:
5199
5200 movl 8(ap),r0
5201 bicl3 #-65536,28(r0),r3
5202 movzwl 30(r0),r1
5203 bicl2 #-65536,r1
5204 bicl3 #-65536,4(r0),r2
5205 movzwl 6(r0),r0
5206 bicl2 #-65536,r0
5207 movl r3,r5
5208 movl r1,r4
5209 mull3 r0,r5,-312(fp)
5210 mull2 r2,r5
5211 mull3 r2,r4,-316(fp)
5212 mull2 r0,r4
5213 addl3 -312(fp),-316(fp),r0
5214 bicl3 #0,r0,-312(fp)
5215 cmpl -312(fp),-316(fp)
5216 bgequ noname.492
5217 addl2 #65536,r4
5218noname.492:
5219 movzwl -310(fp),r0
5220 bicl2 #-65536,r0
5221 addl2 r0,r4
5222 bicl3 #-65536,-312(fp),r0
5223 ashl #16,r0,-316(fp)
5224 addl2 -316(fp),r5
5225 bicl2 #0,r5
5226 cmpl r5,-316(fp)
5227 bgequ noname.493
5228 incl r4
5229noname.493:
5230 movl r5,r3
5231 movl r4,r2
5232 bbc #31,r2,noname.494
5233 incl r8
5234noname.494:
5235 addl2 r2,r2
5236 bicl2 #0,r2
5237 bbc #31,r3,noname.495
5238 incl r2
5239noname.495:
5240 addl2 r3,r3
5241 bicl2 #0,r3
5242 addl2 r3,r7
5243 bicl2 #0,r7
5244 cmpl r7,r3
5245 bgequ noname.496
5246 incl r2
5247 bicl3 #0,r2,r0
5248 bneq noname.496
5249 incl r8
5250noname.496:
5251 addl2 r2,r9
5252 bicl2 #0,r9
5253 cmpl r9,r2
5254 bgequ noname.497
5255 incl r8
5256noname.497:
5257
5258 movl 4(ap),r0
5259 movl r7,32(r0)
5260
5261 clrl r7
5262
5263 movl 8(ap),r0
5264 bicl3 #-65536,28(r0),r3
5265 movzwl 30(r0),r2
5266 bicl3 #-65536,8(r0),r1
5267 movzwl 10(r0),r0
5268 bicl2 #-65536,r0
5269 movl r3,r4
5270 bicl3 #-65536,r2,-328(fp)
5271 mull3 r0,r4,-320(fp)
5272 mull2 r1,r4
5273 mull3 r1,-328(fp),-324(fp)
5274 mull2 r0,-328(fp)
5275 addl3 -320(fp),-324(fp),r0
5276 bicl3 #0,r0,-320(fp)
5277 cmpl -320(fp),-324(fp)
5278 bgequ noname.498
5279 addl2 #65536,-328(fp)
5280noname.498:
5281 movzwl -318(fp),r0
5282 bicl2 #-65536,r0
5283 addl2 r0,-328(fp)
5284 bicl3 #-65536,-320(fp),r0
5285 ashl #16,r0,-324(fp)
5286 addl2 -324(fp),r4
5287 bicl2 #0,r4
5288 cmpl r4,-324(fp)
5289 bgequ noname.499
5290 incl -328(fp)
5291noname.499:
5292 movl r4,r3
5293 movl -328(fp),r2
5294 bbc #31,r2,noname.500
5295 incl r7
5296noname.500:
5297 addl2 r2,r2
5298 bicl2 #0,r2
5299 bbc #31,r3,noname.501
5300 incl r2
5301noname.501:
5302 addl2 r3,r3
5303 bicl2 #0,r3
5304 addl2 r3,r9
5305 bicl2 #0,r9
5306 cmpl r9,r3
5307 bgequ noname.502
5308 incl r2
5309 bicl3 #0,r2,r0
5310 bneq noname.502
5311 incl r7
5312noname.502:
5313 addl2 r2,r8
5314 bicl2 #0,r8
5315 cmpl r8,r2
5316 bgequ noname.503
5317 incl r7
5318noname.503:
5319
5320 movl 8(ap),r0
5321 movzwl 26(r0),r2
5322 bicl3 #-65536,12(r0),r3
5323 movzwl 14(r0),r1
5324 bicl2 #-65536,r1
5325 bicl3 #-65536,24(r0),-340(fp)
5326 bicl3 #-65536,r2,-344(fp)
5327 mull3 r1,-340(fp),-332(fp)
5328 mull2 r3,-340(fp)
5329 mull3 r3,-344(fp),-336(fp)
5330 mull2 r1,-344(fp)
5331 addl3 -332(fp),-336(fp),r0
5332 bicl3 #0,r0,-332(fp)
5333 cmpl -332(fp),-336(fp)
5334 bgequ noname.504
5335 addl2 #65536,-344(fp)
5336noname.504:
5337 movzwl -330(fp),r0
5338 bicl2 #-65536,r0
5339 addl2 r0,-344(fp)
5340 bicl3 #-65536,-332(fp),r0
5341 ashl #16,r0,-336(fp)
5342 addl3 -336(fp),-340(fp),r0
5343 bicl3 #0,r0,-340(fp)
5344 cmpl -340(fp),-336(fp)
5345 bgequ noname.505
5346 incl -344(fp)
5347noname.505:
5348 movl -340(fp),r3
5349 movl -344(fp),r2
5350 bbc #31,r2,noname.506
5351 incl r7
5352noname.506:
5353 addl2 r2,r2
5354 bicl2 #0,r2
5355 bbc #31,r3,noname.507
5356 incl r2
5357noname.507:
5358 addl2 r3,r3
5359 bicl2 #0,r3
5360 addl2 r3,r9
5361 bicl2 #0,r9
5362 cmpl r9,r3
5363 bgequ noname.508
5364 incl r2
5365 bicl3 #0,r2,r0
5366 bneq noname.508
5367 incl r7
5368noname.508:
5369 addl2 r2,r8
5370 bicl2 #0,r8
5371 cmpl r8,r2
5372 bgequ noname.509
5373 incl r7
5374noname.509:
5375
5376 movl 8(ap),r0
5377 movzwl 22(r0),r2
5378 bicl3 #-65536,16(r0),r3
5379 movzwl 18(r0),r1
5380 bicl2 #-65536,r1
5381 bicl3 #-65536,20(r0),-356(fp)
5382 bicl3 #-65536,r2,-360(fp)
5383 mull3 r1,-356(fp),-348(fp)
5384 mull2 r3,-356(fp)
5385 mull3 r3,-360(fp),-352(fp)
5386 mull2 r1,-360(fp)
5387 addl3 -348(fp),-352(fp),r0
5388 bicl3 #0,r0,-348(fp)
5389 cmpl -348(fp),-352(fp)
5390 bgequ noname.510
5391 addl2 #65536,-360(fp)
5392noname.510:
5393 movzwl -346(fp),r0
5394 bicl2 #-65536,r0
5395 addl2 r0,-360(fp)
5396 bicl3 #-65536,-348(fp),r0
5397 ashl #16,r0,-352(fp)
5398 addl3 -352(fp),-356(fp),r0
5399 bicl3 #0,r0,-356(fp)
5400 cmpl -356(fp),-352(fp)
5401 bgequ noname.511
5402 incl -360(fp)
5403noname.511:
5404 movl -356(fp),r3
5405 movl -360(fp),r2
5406 bbc #31,r2,noname.512
5407 incl r7
5408noname.512:
5409 addl2 r2,r2
5410 bicl2 #0,r2
5411 bbc #31,r3,noname.513
5412 incl r2
5413noname.513:
5414 addl2 r3,r3
5415 bicl2 #0,r3
5416 addl2 r3,r9
5417 bicl2 #0,r9
5418 cmpl r9,r3
5419 bgequ noname.514
5420 incl r2
5421 bicl3 #0,r2,r0
5422 bneq noname.514
5423 incl r7
5424noname.514:
5425 addl2 r2,r8
5426 bicl2 #0,r8
5427 cmpl r8,r2
5428 bgequ noname.515
5429 incl r7
5430noname.515:
5431
5432 movl 4(ap),r0
5433 movl r9,36(r0)
5434
5435 clrl r9
5436
5437 movl 8(ap),r3
5438 movl 20(r3),r4
5439 bicl3 #-65536,r4,-364(fp)
5440 extzv #16,#16,r4,r0
5441 bicl3 #-65536,r0,r4
5442 movl -364(fp),r0
5443 mull3 r0,r4,-368(fp)
5444 mull3 r0,r0,-364(fp)
5445 mull2 r4,r4
5446 bicl3 #32767,-368(fp),r0
5447 extzv #15,#17,r0,r0
5448 addl2 r0,r4
5449 bicl3 #-65536,-368(fp),r0
5450 ashl #17,r0,-368(fp)
5451 addl3 -364(fp),-368(fp),r0
5452 bicl3 #0,r0,-364(fp)
5453 cmpl -364(fp),-368(fp)
5454 bgequ noname.516
5455 incl r4
5456noname.516:
5457 movl -364(fp),r1
5458 movl r4,r2
5459 addl2 r1,r8
5460 bicl2 #0,r8
5461 cmpl r8,r1
5462 bgequ noname.517
5463 incl r2
5464noname.517:
5465 addl2 r2,r7
5466 bicl2 #0,r7
5467 cmpl r7,r2
5468 bgequ noname.518
5469 incl r9
5470noname.518:
5471
5472 bicl3 #-65536,24(r3),r4
5473 movzwl 26(r3),r1
5474 bicl2 #-65536,r1
5475 bicl3 #-65536,16(r3),r2
5476 movzwl 18(r3),r0
5477 bicl2 #-65536,r0
5478 movl r4,r6
5479 movl r1,r5
5480 mull3 r0,r6,-372(fp)
5481 mull2 r2,r6
5482 mull3 r2,r5,-376(fp)
5483 mull2 r0,r5
5484 addl3 -372(fp),-376(fp),r0
5485 bicl3 #0,r0,-372(fp)
5486 cmpl -372(fp),-376(fp)
5487 bgequ noname.519
5488 addl2 #65536,r5
5489noname.519:
5490 movzwl -370(fp),r0
5491 bicl2 #-65536,r0
5492 addl2 r0,r5
5493 bicl3 #-65536,-372(fp),r0
5494 ashl #16,r0,-376(fp)
5495 addl2 -376(fp),r6
5496 bicl2 #0,r6
5497 cmpl r6,-376(fp)
5498 bgequ noname.520
5499 incl r5
5500noname.520:
5501 movl r6,r3
5502 movl r5,r2
5503 bbc #31,r2,noname.521
5504 incl r9
5505noname.521:
5506 addl2 r2,r2
5507 bicl2 #0,r2
5508 bbc #31,r3,noname.522
5509 incl r2
5510noname.522:
5511 addl2 r3,r3
5512 bicl2 #0,r3
5513 addl2 r3,r8
5514 bicl2 #0,r8
5515 cmpl r8,r3
5516 bgequ noname.523
5517 incl r2
5518 bicl3 #0,r2,r0
5519 bneq noname.523
5520 incl r9
5521noname.523:
5522 addl2 r2,r7
5523 bicl2 #0,r7
5524 cmpl r7,r2
5525 bgequ noname.524
5526 incl r9
5527noname.524:
5528
5529 movl 8(ap),r0
5530 bicl3 #-65536,28(r0),r3
5531 movzwl 30(r0),r1
5532 bicl2 #-65536,r1
5533 bicl3 #-65536,12(r0),r2
5534 movzwl 14(r0),r0
5535 bicl2 #-65536,r0
5536 movl r3,r5
5537 movl r1,r4
5538 mull3 r0,r5,-380(fp)
5539 mull2 r2,r5
5540 mull3 r2,r4,-384(fp)
5541 mull2 r0,r4
5542 addl3 -380(fp),-384(fp),r0
5543 bicl3 #0,r0,-380(fp)
5544 cmpl -380(fp),-384(fp)
5545 bgequ noname.525
5546 addl2 #65536,r4
5547noname.525:
5548 movzwl -378(fp),r0
5549 bicl2 #-65536,r0
5550 addl2 r0,r4
5551 bicl3 #-65536,-380(fp),r0
5552 ashl #16,r0,-384(fp)
5553 addl2 -384(fp),r5
5554 bicl2 #0,r5
5555 cmpl r5,-384(fp)
5556 bgequ noname.526
5557 incl r4
5558noname.526:
5559 movl r5,r3
5560 movl r4,r2
5561 bbc #31,r2,noname.527
5562 incl r9
5563noname.527:
5564 addl2 r2,r2
5565 bicl2 #0,r2
5566 bbc #31,r3,noname.528
5567 incl r2
5568noname.528:
5569 addl2 r3,r3
5570 bicl2 #0,r3
5571 addl2 r3,r8
5572 bicl2 #0,r8
5573 cmpl r8,r3
5574 bgequ noname.529
5575 incl r2
5576 bicl3 #0,r2,r0
5577 bneq noname.529
5578 incl r9
5579noname.529:
5580 addl2 r2,r7
5581 bicl2 #0,r7
5582 cmpl r7,r2
5583 bgequ noname.530
5584 incl r9
5585noname.530:
5586 movl 4(ap),r0
5587 movl r8,40(r0)
5588
5589 clrl r8
5590
5591 movl 8(ap),r0
5592 bicl3 #-65536,28(r0),r3
5593 movzwl 30(r0),r1
5594 bicl2 #-65536,r1
5595 bicl3 #-65536,16(r0),r2
5596 movzwl 18(r0),r0
5597 bicl2 #-65536,r0
5598 movl r3,r5
5599 movl r1,r4
5600 mull3 r0,r5,-388(fp)
5601 mull2 r2,r5
5602 mull3 r2,r4,-392(fp)
5603 mull2 r0,r4
5604 addl3 -388(fp),-392(fp),r0
5605 bicl3 #0,r0,-388(fp)
5606 cmpl -388(fp),-392(fp)
5607 bgequ noname.531
5608 addl2 #65536,r4
5609noname.531:
5610 movzwl -386(fp),r0
5611 bicl2 #-65536,r0
5612 addl2 r0,r4
5613 bicl3 #-65536,-388(fp),r0
5614 ashl #16,r0,-392(fp)
5615 addl2 -392(fp),r5
5616 bicl2 #0,r5
5617 cmpl r5,-392(fp)
5618 bgequ noname.532
5619 incl r4
5620noname.532:
5621 movl r5,r3
5622 movl r4,r2
5623 bbc #31,r2,noname.533
5624 incl r8
5625noname.533:
5626 addl2 r2,r2
5627 bicl2 #0,r2
5628 bbc #31,r3,noname.534
5629 incl r2
5630noname.534:
5631 addl2 r3,r3
5632 bicl2 #0,r3
5633 addl2 r3,r7
5634 bicl2 #0,r7
5635 cmpl r7,r3
5636 bgequ noname.535
5637 incl r2
5638 bicl3 #0,r2,r0
5639 bneq noname.535
5640 incl r8
5641noname.535:
5642 addl2 r2,r9
5643 bicl2 #0,r9
5644 cmpl r9,r2
5645 bgequ noname.536
5646 incl r8
5647noname.536:
5648
5649 movl 8(ap),r0
5650 bicl3 #-65536,24(r0),r3
5651 movzwl 26(r0),r1
5652 bicl2 #-65536,r1
5653 bicl3 #-65536,20(r0),r2
5654 movzwl 22(r0),r0
5655 bicl2 #-65536,r0
5656 movl r3,r5
5657 movl r1,r4
5658 mull3 r0,r5,-396(fp)
5659 mull2 r2,r5
5660 mull3 r2,r4,-400(fp)
5661 mull2 r0,r4
5662 addl3 -396(fp),-400(fp),r0
5663 bicl3 #0,r0,-396(fp)
5664 cmpl -396(fp),-400(fp)
5665 bgequ noname.537
5666 addl2 #65536,r4
5667noname.537:
5668 movzwl -394(fp),r0
5669 bicl2 #-65536,r0
5670 addl2 r0,r4
5671 bicl3 #-65536,-396(fp),r0
5672 ashl #16,r0,-400(fp)
5673 addl2 -400(fp),r5
5674 bicl2 #0,r5
5675 cmpl r5,-400(fp)
5676 bgequ noname.538
5677 incl r4
5678noname.538:
5679 movl r5,r3
5680 movl r4,r2
5681 bbc #31,r2,noname.539
5682 incl r8
5683noname.539:
5684 addl2 r2,r2
5685 bicl2 #0,r2
5686 bbc #31,r3,noname.540
5687 incl r2
5688noname.540:
5689 addl2 r3,r3
5690 bicl2 #0,r3
5691 addl2 r3,r7
5692 bicl2 #0,r7
5693 cmpl r7,r3
5694 bgequ noname.541
5695 incl r2
5696 bicl3 #0,r2,r0
5697 bneq noname.541
5698 incl r8
5699noname.541:
5700 addl2 r2,r9
5701 bicl2 #0,r9
5702 cmpl r9,r2
5703 bgequ noname.542
5704 incl r8
5705noname.542:
5706
5707 movl 4(ap),r0
5708 movl r7,44(r0)
5709
5710 clrl r7
5711
5712 movl 8(ap),r3
5713 movl 24(r3),r4
5714 bicl3 #-65536,r4,r5
5715 extzv #16,#16,r4,r0
5716 bicl3 #-65536,r0,r4
5717 mull3 r5,r4,-404(fp)
5718 mull2 r5,r5
5719 mull2 r4,r4
5720 bicl3 #32767,-404(fp),r0
5721 extzv #15,#17,r0,r0
5722 addl2 r0,r4
5723 bicl3 #-65536,-404(fp),r0
5724 ashl #17,r0,-404(fp)
5725 addl2 -404(fp),r5
5726 bicl2 #0,r5
5727 cmpl r5,-404(fp)
5728 bgequ noname.543
5729 incl r4
5730noname.543:
5731 movl r5,r1
5732 movl r4,r2
5733 addl2 r1,r9
5734 bicl2 #0,r9
5735 cmpl r9,r1
5736 bgequ noname.544
5737 incl r2
5738noname.544:
5739 addl2 r2,r8
5740 bicl2 #0,r8
5741 cmpl r8,r2
5742 bgequ noname.545
5743 incl r7
5744noname.545:
5745
5746 movzwl 30(r3),r2
5747 bicl3 #-65536,20(r3),r1
5748 movzwl 22(r3),r0
5749 bicl2 #-65536,r0
5750 bicl3 #-65536,28(r3),-416(fp)
5751 bicl3 #-65536,r2,-420(fp)
5752 mull3 r0,-416(fp),-408(fp)
5753 mull2 r1,-416(fp)
5754 mull3 r1,-420(fp),-412(fp)
5755 mull2 r0,-420(fp)
5756 addl3 -408(fp),-412(fp),r0
5757 bicl3 #0,r0,-408(fp)
5758 cmpl -408(fp),-412(fp)
5759 bgequ noname.546
5760 addl2 #65536,-420(fp)
5761noname.546:
5762 movzwl -406(fp),r0
5763 bicl2 #-65536,r0
5764 addl2 r0,-420(fp)
5765 bicl3 #-65536,-408(fp),r0
5766 ashl #16,r0,-412(fp)
5767 addl3 -412(fp),-416(fp),r0
5768 bicl3 #0,r0,-416(fp)
5769 cmpl -416(fp),-412(fp)
5770 bgequ noname.547
5771 incl -420(fp)
5772noname.547:
5773 movl -416(fp),r3
5774 movl -420(fp),r2
5775 bbc #31,r2,noname.548
5776 incl r7
5777noname.548:
5778 addl2 r2,r2
5779 bicl2 #0,r2
5780 bbc #31,r3,noname.549
5781 incl r2
5782noname.549:
5783 addl2 r3,r3
5784 bicl2 #0,r3
5785 addl2 r3,r9
5786 bicl2 #0,r9
5787 cmpl r9,r3
5788 bgequ noname.550
5789 incl r2
5790 bicl3 #0,r2,r0
5791 bneq noname.550
5792 incl r7
5793noname.550:
5794 addl2 r2,r8
5795 bicl2 #0,r8
5796 cmpl r8,r2
5797 bgequ noname.551
5798 incl r7
5799noname.551:
5800
5801 movl 4(ap),r0
5802 movl r9,48(r0)
5803
5804 clrl r9
5805
5806 movl 8(ap),r0
5807 movzwl 30(r0),r2
5808 bicl3 #-65536,24(r0),r3
5809 movzwl 26(r0),r1
5810 bicl2 #-65536,r1
5811 bicl3 #-65536,28(r0),-432(fp)
5812 bicl3 #-65536,r2,-436(fp)
5813 mull3 r1,-432(fp),-424(fp)
5814 mull2 r3,-432(fp)
5815 mull3 r3,-436(fp),-428(fp)
5816 mull2 r1,-436(fp)
5817 addl3 -424(fp),-428(fp),r0
5818 bicl3 #0,r0,-424(fp)
5819 cmpl -424(fp),-428(fp)
5820 bgequ noname.552
5821 addl2 #65536,-436(fp)
5822noname.552:
5823 movzwl -422(fp),r0
5824 bicl2 #-65536,r0
5825 addl2 r0,-436(fp)
5826 bicl3 #-65536,-424(fp),r0
5827 ashl #16,r0,-428(fp)
5828 addl3 -428(fp),-432(fp),r0
5829 bicl3 #0,r0,-432(fp)
5830 cmpl -432(fp),-428(fp)
5831 bgequ noname.553
5832 incl -436(fp)
5833noname.553:
5834 movl -432(fp),r3
5835 movl -436(fp),r2
5836 bbc #31,r2,noname.554
5837 incl r9
5838noname.554:
5839 addl2 r2,r2
5840 bicl2 #0,r2
5841 bbc #31,r3,noname.555
5842 incl r2
5843noname.555:
5844 addl2 r3,r3
5845 bicl2 #0,r3
5846 addl2 r3,r8
5847 bicl2 #0,r8
5848 cmpl r8,r3
5849 bgequ noname.556
5850 incl r2
5851 bicl3 #0,r2,r0
5852 bneq noname.556
5853 incl r9
5854noname.556:
5855 addl2 r2,r7
5856 bicl2 #0,r7
5857 cmpl r7,r2
5858 bgequ noname.557
5859 incl r9
5860noname.557:
5861
5862 movl 4(ap),r4
5863 movl r8,52(r4)
5864
5865 clrl r8
5866
5867 movl 8(ap),r0
5868 movl 28(r0),r3
5869 bicl3 #-65536,r3,-440(fp)
5870 extzv #16,#16,r3,r0
5871 bicl3 #-65536,r0,r3
5872 movl -440(fp),r0
5873 mull3 r0,r3,-444(fp)
5874 mull3 r0,r0,-440(fp)
5875 mull2 r3,r3
5876 bicl3 #32767,-444(fp),r0
5877 extzv #15,#17,r0,r0
5878 addl2 r0,r3
5879 bicl3 #-65536,-444(fp),r0
5880 ashl #17,r0,-444(fp)
5881 addl3 -440(fp),-444(fp),r0
5882 bicl3 #0,r0,-440(fp)
5883 cmpl -440(fp),-444(fp)
5884 bgequ noname.558
5885 incl r3
5886noname.558:
5887 movl -440(fp),r1
5888 movl r3,r2
5889 addl2 r1,r7
5890 bicl2 #0,r7
5891 cmpl r7,r1
5892 bgequ noname.559
5893 incl r2
5894noname.559:
5895 addl2 r2,r9
5896 bicl2 #0,r9
5897 cmpl r9,r2
5898 bgequ noname.560
5899 incl r8
5900noname.560:
5901
5902 movl r7,56(r4)
5903
5904 movl r9,60(r4)
5905
5906 ret
5907
5908
5909
5910;r=4 ;(AP)
5911;a=8 ;(AP)
5912;b=12 ;(AP)
5913;n=16 ;(AP) n by value (input)
5914
5915 .psect code,nowrt
5916
5917.entry BN_SQR_COMBA4,^m<r2,r3,r4,r5,r6,r7,r8,r9,r10>
5918 subl2 #44,sp
5919
5920 clrq r8
5921
5922 clrl r10
5923
5924 movl 8(ap),r5
5925 movl (r5),r3
5926 bicl3 #-65536,r3,r4
5927 extzv #16,#16,r3,r0
5928 bicl3 #-65536,r0,r3
5929 mull3 r4,r3,-4(fp)
5930 mull2 r4,r4
5931 mull2 r3,r3
5932 bicl3 #32767,-4(fp),r0
5933 extzv #15,#17,r0,r0
5934 addl2 r0,r3
5935 bicl3 #-65536,-4(fp),r0
5936 ashl #17,r0,-4(fp)
5937 addl2 -4(fp),r4
5938 bicl2 #0,r4
5939 cmpl r4,-4(fp)
5940 bgequ noname.563
5941 incl r3
5942noname.563:
5943 movl r4,r1
5944 movl r3,r2
5945 addl2 r1,r9
5946 bicl2 #0,r9
5947 cmpl r9,r1
5948 bgequ noname.564
5949 incl r2
5950noname.564:
5951 addl2 r2,r8
5952 bicl2 #0,r8
5953 cmpl r8,r2
5954 bgequ noname.565
5955 incl r10
5956noname.565:
5957
5958 movl r9,@4(ap)
5959
5960 clrl r9
5961
5962 bicl3 #-65536,4(r5),r3
5963 movzwl 6(r5),r1
5964 bicl2 #-65536,r1
5965 bicl3 #-65536,(r5),r2
5966 movzwl 2(r5),r0
5967 bicl2 #-65536,r0
5968 movl r3,r6
5969 movl r1,r4
5970 mull3 r0,r6,-8(fp)
5971 mull2 r2,r6
5972 mull2 r4,r2
5973 mull2 r0,r4
5974 addl3 -8(fp),r2,r0
5975 bicl3 #0,r0,-8(fp)
5976 cmpl -8(fp),r2
5977 bgequ noname.566
5978 addl2 #65536,r4
5979noname.566:
5980 movzwl -6(fp),r0
5981 bicl2 #-65536,r0
5982 addl2 r0,r4
5983 bicl3 #-65536,-8(fp),r0
5984 ashl #16,r0,r1
5985 addl2 r1,r6
5986 bicl2 #0,r6
5987 cmpl r6,r1
5988 bgequ noname.567
5989 incl r4
5990noname.567:
5991 movl r6,r3
5992 movl r4,r2
5993 bbc #31,r2,noname.568
5994 incl r9
5995noname.568:
5996 addl2 r2,r2
5997 bicl2 #0,r2
5998 bbc #31,r3,noname.569
5999 incl r2
6000noname.569:
6001 addl2 r3,r3
6002 bicl2 #0,r3
6003 addl2 r3,r8
6004 bicl2 #0,r8
6005 cmpl r8,r3
6006 bgequ noname.570
6007 incl r2
6008 bicl3 #0,r2,r0
6009 bneq noname.570
6010 incl r9
6011noname.570:
6012 addl2 r2,r10
6013 bicl2 #0,r10
6014 cmpl r10,r2
6015 bgequ noname.571
6016 incl r9
6017noname.571:
6018
6019 movl 4(ap),r0
6020 movl r8,4(r0)
6021
6022 clrl r8
6023
6024 movl 8(ap),r4
6025 movl 4(r4),r3
6026 bicl3 #-65536,r3,r5
6027 extzv #16,#16,r3,r0
6028 bicl3 #-65536,r0,r3
6029 mull3 r5,r3,r1
6030 mull2 r5,r5
6031 mull2 r3,r3
6032 bicl3 #32767,r1,r0
6033 extzv #15,#17,r0,r0
6034 addl2 r0,r3
6035 bicl2 #-65536,r1
6036 ashl #17,r1,r1
6037 addl2 r1,r5
6038 bicl2 #0,r5
6039 cmpl r5,r1
6040 bgequ noname.572
6041 incl r3
6042noname.572:
6043 movl r5,r1
6044 movl r3,r2
6045 addl2 r1,r10
6046 bicl2 #0,r10
6047 cmpl r10,r1
6048 bgequ noname.573
6049 incl r2
6050noname.573:
6051 addl2 r2,r9
6052 bicl2 #0,r9
6053 cmpl r9,r2
6054 bgequ noname.574
6055 incl r8
6056noname.574:
6057
6058 bicl3 #-65536,8(r4),r3
6059 movzwl 10(r4),r1
6060 bicl2 #-65536,r1
6061 bicl3 #-65536,(r4),r2
6062 movzwl 2(r4),r0
6063 bicl2 #-65536,r0
6064 movl r3,r6
6065 movl r1,r5
6066 mull3 r0,r6,r7
6067 mull2 r2,r6
6068 mull2 r5,r2
6069 mull2 r0,r5
6070 addl2 r2,r7
6071 bicl2 #0,r7
6072 cmpl r7,r2
6073 bgequ noname.575
6074 addl2 #65536,r5
6075noname.575:
6076 extzv #16,#16,r7,r0
6077 bicl2 #-65536,r0
6078 addl2 r0,r5
6079 bicl3 #-65536,r7,r0
6080 ashl #16,r0,r1
6081 addl2 r1,r6
6082 bicl2 #0,r6
6083 cmpl r6,r1
6084 bgequ noname.576
6085 incl r5
6086noname.576:
6087 movl r6,r3
6088 movl r5,r2
6089 bbc #31,r2,noname.577
6090 incl r8
6091noname.577:
6092 addl2 r2,r2
6093 bicl2 #0,r2
6094 bbc #31,r3,noname.578
6095 incl r2
6096noname.578:
6097 addl2 r3,r3
6098 bicl2 #0,r3
6099 addl2 r3,r10
6100 bicl2 #0,r10
6101 cmpl r10,r3
6102 bgequ noname.579
6103 incl r2
6104 bicl3 #0,r2,r0
6105 bneq noname.579
6106 incl r8
6107noname.579:
6108 addl2 r2,r9
6109 bicl2 #0,r9
6110 cmpl r9,r2
6111 bgequ noname.580
6112 incl r8
6113noname.580:
6114
6115 movl 4(ap),r0
6116 movl r10,8(r0)
6117
6118 clrl r10
6119
6120 movl 8(ap),r0
6121 bicl3 #-65536,12(r0),r3
6122 movzwl 14(r0),r1
6123 bicl2 #-65536,r1
6124 bicl3 #-65536,(r0),r2
6125 movzwl 2(r0),r0
6126 bicl2 #-65536,r0
6127 movl r3,r5
6128 movl r1,r4
6129 mull3 r0,r5,r6
6130 mull2 r2,r5
6131 mull3 r2,r4,-12(fp)
6132 mull2 r0,r4
6133 addl2 -12(fp),r6
6134 bicl2 #0,r6
6135 cmpl r6,-12(fp)
6136 bgequ noname.581
6137 addl2 #65536,r4
6138noname.581:
6139 extzv #16,#16,r6,r0
6140 bicl2 #-65536,r0
6141 addl2 r0,r4
6142 bicl3 #-65536,r6,r0
6143 ashl #16,r0,-12(fp)
6144 addl2 -12(fp),r5
6145 bicl2 #0,r5
6146 cmpl r5,-12(fp)
6147 bgequ noname.582
6148 incl r4
6149noname.582:
6150 movl r5,r3
6151 movl r4,r2
6152 bbc #31,r2,noname.583
6153 incl r10
6154noname.583:
6155 addl2 r2,r2
6156 bicl2 #0,r2
6157 bbc #31,r3,noname.584
6158 incl r2
6159noname.584:
6160 addl2 r3,r3
6161 bicl2 #0,r3
6162 addl2 r3,r9
6163 bicl2 #0,r9
6164 cmpl r9,r3
6165 bgequ noname.585
6166 incl r2
6167 bicl3 #0,r2,r0
6168 bneq noname.585
6169 incl r10
6170noname.585:
6171 addl2 r2,r8
6172 bicl2 #0,r8
6173 cmpl r8,r2
6174 bgequ noname.586
6175 incl r10
6176noname.586:
6177
6178 movl 8(ap),r0
6179 bicl3 #-65536,8(r0),r3
6180 movzwl 10(r0),r1
6181 bicl2 #-65536,r1
6182 bicl3 #-65536,4(r0),r2
6183 movzwl 6(r0),r0
6184 bicl2 #-65536,r0
6185 movl r3,r5
6186 movl r1,r4
6187 mull3 r0,r5,-16(fp)
6188 mull2 r2,r5
6189 mull3 r2,r4,-20(fp)
6190 mull2 r0,r4
6191 addl3 -16(fp),-20(fp),r0
6192 bicl3 #0,r0,-16(fp)
6193 cmpl -16(fp),-20(fp)
6194 bgequ noname.587
6195 addl2 #65536,r4
6196noname.587:
6197 movzwl -14(fp),r0
6198 bicl2 #-65536,r0
6199 addl2 r0,r4
6200 bicl3 #-65536,-16(fp),r0
6201 ashl #16,r0,-20(fp)
6202 addl2 -20(fp),r5
6203 bicl2 #0,r5
6204 cmpl r5,-20(fp)
6205 bgequ noname.588
6206 incl r4
6207noname.588:
6208 movl r5,r3
6209 movl r4,r2
6210 bbc #31,r2,noname.589
6211 incl r10
6212noname.589:
6213 addl2 r2,r2
6214 bicl2 #0,r2
6215 bbc #31,r3,noname.590
6216 incl r2
6217noname.590:
6218 addl2 r3,r3
6219 bicl2 #0,r3
6220 addl2 r3,r9
6221 bicl2 #0,r9
6222 cmpl r9,r3
6223 bgequ noname.591
6224 incl r2
6225 bicl3 #0,r2,r0
6226 bneq noname.591
6227 incl r10
6228noname.591:
6229 addl2 r2,r8
6230 bicl2 #0,r8
6231 cmpl r8,r2
6232 bgequ noname.592
6233 incl r10
6234noname.592:
6235 movl 4(ap),r0
6236 movl r9,12(r0)
6237
6238 clrl r9
6239
6240 movl 8(ap),r3
6241 movl 8(r3),r4
6242 bicl3 #-65536,r4,r5
6243 extzv #16,#16,r4,r0
6244 bicl3 #-65536,r0,r4
6245 mull3 r5,r4,-24(fp)
6246 mull2 r5,r5
6247 mull2 r4,r4
6248 bicl3 #32767,-24(fp),r0
6249 extzv #15,#17,r0,r0
6250 addl2 r0,r4
6251 bicl3 #-65536,-24(fp),r0
6252 ashl #17,r0,-24(fp)
6253 addl2 -24(fp),r5
6254 bicl2 #0,r5
6255 cmpl r5,-24(fp)
6256 bgequ noname.593
6257 incl r4
6258noname.593:
6259 movl r5,r1
6260 movl r4,r2
6261 addl2 r1,r8
6262 bicl2 #0,r8
6263 cmpl r8,r1
6264 bgequ noname.594
6265 incl r2
6266noname.594:
6267 addl2 r2,r10
6268 bicl2 #0,r10
6269 cmpl r10,r2
6270 bgequ noname.595
6271 incl r9
6272noname.595:
6273
6274 bicl3 #-65536,12(r3),r4
6275 movzwl 14(r3),r1
6276 bicl2 #-65536,r1
6277 bicl3 #-65536,4(r3),r2
6278 movzwl 6(r3),r0
6279 bicl2 #-65536,r0
6280 movl r4,r6
6281 movl r1,r5
6282 mull3 r0,r6,-28(fp)
6283 mull2 r2,r6
6284 mull3 r2,r5,-32(fp)
6285 mull2 r0,r5
6286 addl3 -28(fp),-32(fp),r0
6287 bicl3 #0,r0,-28(fp)
6288 cmpl -28(fp),-32(fp)
6289 bgequ noname.596
6290 addl2 #65536,r5
6291noname.596:
6292 movzwl -26(fp),r0
6293 bicl2 #-65536,r0
6294 addl2 r0,r5
6295 bicl3 #-65536,-28(fp),r0
6296 ashl #16,r0,-32(fp)
6297 addl2 -32(fp),r6
6298 bicl2 #0,r6
6299 cmpl r6,-32(fp)
6300 bgequ noname.597
6301 incl r5
6302noname.597:
6303 movl r6,r3
6304 movl r5,r2
6305 bbc #31,r2,noname.598
6306 incl r9
6307noname.598:
6308 addl2 r2,r2
6309 bicl2 #0,r2
6310 bbc #31,r3,noname.599
6311 incl r2
6312noname.599:
6313 addl2 r3,r3
6314 bicl2 #0,r3
6315 addl2 r3,r8
6316 bicl2 #0,r8
6317 cmpl r8,r3
6318 bgequ noname.600
6319 incl r2
6320 bicl3 #0,r2,r0
6321 bneq noname.600
6322 incl r9
6323noname.600:
6324 addl2 r2,r10
6325 bicl2 #0,r10
6326 cmpl r10,r2
6327 bgequ noname.601
6328 incl r9
6329noname.601:
6330
6331 movl 4(ap),r0
6332 movl r8,16(r0)
6333
6334 clrl r8
6335
6336 movl 8(ap),r0
6337 bicl3 #-65536,12(r0),r3
6338 movzwl 14(r0),r1
6339 bicl2 #-65536,r1
6340 bicl3 #-65536,8(r0),r2
6341 movzwl 10(r0),r0
6342 bicl2 #-65536,r0
6343 movl r3,r5
6344 movl r1,r4
6345 mull3 r0,r5,-36(fp)
6346 mull2 r2,r5
6347 mull3 r2,r4,-40(fp)
6348 mull2 r0,r4
6349 addl3 -36(fp),-40(fp),r0
6350 bicl3 #0,r0,-36(fp)
6351 cmpl -36(fp),-40(fp)
6352 bgequ noname.602
6353 addl2 #65536,r4
6354noname.602:
6355 movzwl -34(fp),r0
6356 bicl2 #-65536,r0
6357 addl2 r0,r4
6358 bicl3 #-65536,-36(fp),r0
6359 ashl #16,r0,-40(fp)
6360 addl2 -40(fp),r5
6361 bicl2 #0,r5
6362 cmpl r5,-40(fp)
6363 bgequ noname.603
6364 incl r4
6365noname.603:
6366 movl r5,r3
6367 movl r4,r2
6368 bbc #31,r2,noname.604
6369 incl r8
6370noname.604:
6371 addl2 r2,r2
6372 bicl2 #0,r2
6373 bbc #31,r3,noname.605
6374 incl r2
6375noname.605:
6376 addl2 r3,r3
6377 bicl2 #0,r3
6378 addl2 r3,r10
6379 bicl2 #0,r10
6380 cmpl r10,r3
6381 bgequ noname.606
6382 incl r2
6383 bicl3 #0,r2,r0
6384 bneq noname.606
6385 incl r8
6386noname.606:
6387 addl2 r2,r9
6388 bicl2 #0,r9
6389 cmpl r9,r2
6390 bgequ noname.607
6391 incl r8
6392noname.607:
6393
6394 movl 4(ap),r4
6395 movl r10,20(r4)
6396
6397 clrl r10
6398
6399 movl 8(ap),r0
6400 movl 12(r0),r3
6401 bicl3 #-65536,r3,r5
6402 extzv #16,#16,r3,r0
6403 bicl3 #-65536,r0,r3
6404 mull3 r5,r3,-44(fp)
6405 mull2 r5,r5
6406 mull2 r3,r3
6407 bicl3 #32767,-44(fp),r0
6408 extzv #15,#17,r0,r0
6409 addl2 r0,r3
6410 bicl3 #-65536,-44(fp),r0
6411 ashl #17,r0,-44(fp)
6412 addl2 -44(fp),r5
6413 bicl2 #0,r5
6414 cmpl r5,-44(fp)
6415 bgequ noname.608
6416 incl r3
6417noname.608:
6418 movl r5,r1
6419 movl r3,r2
6420 addl2 r1,r9
6421 bicl2 #0,r9
6422 cmpl r9,r1
6423 bgequ noname.609
6424 incl r2
6425noname.609:
6426 addl2 r2,r8
6427 bicl2 #0,r8
6428 cmpl r8,r2
6429 bgequ noname.610
6430 incl r10
6431noname.610:
6432
6433 movl r9,24(r4)
6434
6435 movl r8,28(r4)
6436
6437 ret
6438
6439; For now, the code below doesn't work, so I end this prematurely.
6440.end
diff --git a/src/lib/libcrypto/bn/asm/x86/f b/src/lib/libcrypto/bn/asm/x86/f
new file mode 100644
index 0000000000..22e4112224
--- /dev/null
+++ b/src/lib/libcrypto/bn/asm/x86/f
@@ -0,0 +1,3 @@
1#!/usr/local/bin/perl
2# x86 assember
3
diff --git a/src/lib/libcrypto/bn/bn.h b/src/lib/libcrypto/bn/bn.h
index 6d754d5547..1251521c54 100644
--- a/src/lib/libcrypto/bn/bn.h
+++ b/src/lib/libcrypto/bn/bn.h
@@ -55,19 +55,6 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the Eric Young open source
65 * license provided above.
66 *
67 * The binary polynomial arithmetic software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71 58
72#ifndef HEADER_BN_H 59#ifndef HEADER_BN_H
73#define HEADER_BN_H 60#define HEADER_BN_H
@@ -76,23 +63,14 @@
76#ifndef OPENSSL_NO_FP_API 63#ifndef OPENSSL_NO_FP_API
77#include <stdio.h> /* FILE */ 64#include <stdio.h> /* FILE */
78#endif 65#endif
79#include <openssl/ossl_typ.h>
80 66
81#ifdef __cplusplus 67#ifdef __cplusplus
82extern "C" { 68extern "C" {
83#endif 69#endif
84 70
85/* These preprocessor symbols control various aspects of the bignum headers and 71#ifdef OPENSSL_SYS_VMS
86 * library code. They're not defined by any "normal" configuration, as they are 72#undef BN_LLONG /* experimental, so far... */
87 * intended for development and testing purposes. NB: defining all three can be 73#endif
88 * useful for debugging application code as well as openssl itself.
89 *
90 * BN_DEBUG - turn on various debugging alterations to the bignum code
91 * BN_DEBUG_RAND - uses random poisoning of unused words to trip up
92 * mismanagement of bignum internals. You must also define BN_DEBUG.
93 */
94/* #define BN_DEBUG */
95/* #define BN_DEBUG_RAND */
96 74
97#define BN_MUL_COMBA 75#define BN_MUL_COMBA
98#define BN_SQR_COMBA 76#define BN_SQR_COMBA
@@ -165,12 +143,10 @@ extern "C" {
165#endif 143#endif
166 144
167#ifdef THIRTY_TWO_BIT 145#ifdef THIRTY_TWO_BIT
168#ifdef BN_LLONG 146#if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__)
169# if defined(OPENSSL_SYS_WIN32) && !defined(__GNUC__) 147#define BN_ULLONG unsigned _int64
170# define BN_ULLONG unsigned __int64 148#else
171# else 149#define BN_ULLONG unsigned long long
172# define BN_ULLONG unsigned long long
173# endif
174#endif 150#endif
175#define BN_ULONG unsigned long 151#define BN_ULONG unsigned long
176#define BN_LONG long 152#define BN_LONG long
@@ -243,23 +219,15 @@ extern "C" {
243 219
244#define BN_DEFAULT_BITS 1280 220#define BN_DEFAULT_BITS 1280
245 221
246#define BN_FLG_MALLOCED 0x01 222#ifdef BIGNUM
247#define BN_FLG_STATIC_DATA 0x02 223#undef BIGNUM
248#define BN_FLG_CONSTTIME 0x04 /* avoid leaking exponent information through timing,
249 * BN_mod_exp_mont() will call BN_mod_exp_mont_consttime,
250 * BN_div() will call BN_div_no_branch,
251 * BN_mod_inverse() will call BN_mod_inverse_no_branch.
252 */
253
254#ifndef OPENSSL_NO_DEPRECATED
255#define BN_FLG_EXP_CONSTTIME BN_FLG_CONSTTIME /* deprecated name for the flag */
256 /* avoid leaking exponent information through timings
257 * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */
258#endif 224#endif
259 225
260#ifndef OPENSSL_NO_DEPRECATED 226#define BN_FLG_MALLOCED 0x01
227#define BN_FLG_STATIC_DATA 0x02
228#define BN_FLG_EXP_CONSTTIME 0x04 /* avoid leaking exponent information through timings
229 * (BN_mod_exp_mont() will call BN_mod_exp_mont_consttime) */
261#define BN_FLG_FREE 0x8000 /* used for debuging */ 230#define BN_FLG_FREE 0x8000 /* used for debuging */
262#endif
263#define BN_set_flags(b,n) ((b)->flags|=(n)) 231#define BN_set_flags(b,n) ((b)->flags|=(n))
264#define BN_get_flags(b,n) ((b)->flags&(n)) 232#define BN_get_flags(b,n) ((b)->flags&(n))
265 233
@@ -274,18 +242,7 @@ extern "C" {
274 | BN_FLG_STATIC_DATA \ 242 | BN_FLG_STATIC_DATA \
275 | (n))) 243 | (n)))
276 244
277/* Already declared in ossl_typ.h */ 245typedef struct bignum_st
278#if 0
279typedef struct bignum_st BIGNUM;
280/* Used for temp variables (declaration hidden in bn_lcl.h) */
281typedef struct bignum_ctx BN_CTX;
282typedef struct bn_blinding_st BN_BLINDING;
283typedef struct bn_mont_ctx_st BN_MONT_CTX;
284typedef struct bn_recp_ctx_st BN_RECP_CTX;
285typedef struct bn_gencb_st BN_GENCB;
286#endif
287
288struct bignum_st
289 { 246 {
290 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */ 247 BN_ULONG *d; /* Pointer to an array of 'BN_BITS2' bit chunks. */
291 int top; /* Index of last used d +1. */ 248 int top; /* Index of last used d +1. */
@@ -293,64 +250,44 @@ struct bignum_st
293 int dmax; /* Size of the d array. */ 250 int dmax; /* Size of the d array. */
294 int neg; /* one if the number is negative */ 251 int neg; /* one if the number is negative */
295 int flags; 252 int flags;
296 }; 253 } BIGNUM;
254
255/* Used for temp variables (declaration hidden in bn_lcl.h) */
256typedef struct bignum_ctx BN_CTX;
257
258typedef struct bn_blinding_st
259 {
260 int init;
261 BIGNUM *A;
262 BIGNUM *Ai;
263 BIGNUM *mod; /* just a reference */
264 unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
265 * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
266 } BN_BLINDING;
297 267
298/* Used for montgomery multiplication */ 268/* Used for montgomery multiplication */
299struct bn_mont_ctx_st 269typedef struct bn_mont_ctx_st
300 { 270 {
301 int ri; /* number of bits in R */ 271 int ri; /* number of bits in R */
302 BIGNUM RR; /* used to convert to montgomery form */ 272 BIGNUM RR; /* used to convert to montgomery form */
303 BIGNUM N; /* The modulus */ 273 BIGNUM N; /* The modulus */
304 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1 274 BIGNUM Ni; /* R*(1/R mod N) - N*Ni = 1
305 * (Ni is only stored for bignum algorithm) */ 275 * (Ni is only stored for bignum algorithm) */
306#if 0
307 /* OpenSSL 0.9.9 preview: */
308 BN_ULONG n0[2];/* least significant word(s) of Ni */
309#else
310 BN_ULONG n0; /* least significant word of Ni */ 276 BN_ULONG n0; /* least significant word of Ni */
311#endif
312 int flags; 277 int flags;
313 }; 278 } BN_MONT_CTX;
314 279
315/* Used for reciprocal division/mod functions 280/* Used for reciprocal division/mod functions
316 * It cannot be shared between threads 281 * It cannot be shared between threads
317 */ 282 */
318struct bn_recp_ctx_st 283typedef struct bn_recp_ctx_st
319 { 284 {
320 BIGNUM N; /* the divisor */ 285 BIGNUM N; /* the divisor */
321 BIGNUM Nr; /* the reciprocal */ 286 BIGNUM Nr; /* the reciprocal */
322 int num_bits; 287 int num_bits;
323 int shift; 288 int shift;
324 int flags; 289 int flags;
325 }; 290 } BN_RECP_CTX;
326
327/* Used for slow "generation" functions. */
328struct bn_gencb_st
329 {
330 unsigned int ver; /* To handle binary (in)compatibility */
331 void *arg; /* callback-specific data */
332 union
333 {
334 /* if(ver==1) - handles old style callbacks */
335 void (*cb_1)(int, int, void *);
336 /* if(ver==2) - new callback style */
337 int (*cb_2)(int, int, BN_GENCB *);
338 } cb;
339 };
340/* Wrapper function to make using BN_GENCB easier, */
341int BN_GENCB_call(BN_GENCB *cb, int a, int b);
342/* Macro to populate a BN_GENCB structure with an "old"-style callback */
343#define BN_GENCB_set_old(gencb, callback, cb_arg) { \
344 BN_GENCB *tmp_gencb = (gencb); \
345 tmp_gencb->ver = 1; \
346 tmp_gencb->arg = (cb_arg); \
347 tmp_gencb->cb.cb_1 = (callback); }
348/* Macro to populate a BN_GENCB structure with a "new"-style callback */
349#define BN_GENCB_set(gencb, callback, cb_arg) { \
350 BN_GENCB *tmp_gencb = (gencb); \
351 tmp_gencb->ver = 2; \
352 tmp_gencb->arg = (cb_arg); \
353 tmp_gencb->cb.cb_2 = (callback); }
354 291
355#define BN_prime_checks 0 /* default: select number of iterations 292#define BN_prime_checks 0 /* default: select number of iterations
356 based on the size of the number */ 293 based on the size of the number */
@@ -375,33 +312,24 @@ int BN_GENCB_call(BN_GENCB *cb, int a, int b);
375 312
376#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8) 313#define BN_num_bytes(a) ((BN_num_bits(a)+7)/8)
377 314
378/* Note that BN_abs_is_word didn't work reliably for w == 0 until 0.9.8 */ 315/* Note that BN_abs_is_word does not work reliably for w == 0 */
379#define BN_abs_is_word(a,w) ((((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w))) || \ 316#define BN_abs_is_word(a,w) (((a)->top == 1) && ((a)->d[0] == (BN_ULONG)(w)))
380 (((w) == 0) && ((a)->top == 0))) 317#define BN_is_zero(a) (((a)->top == 0) || BN_abs_is_word(a,0))
381#define BN_is_zero(a) ((a)->top == 0)
382#define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg) 318#define BN_is_one(a) (BN_abs_is_word((a),1) && !(a)->neg)
383#define BN_is_word(a,w) (BN_abs_is_word((a),(w)) && (!(w) || !(a)->neg)) 319#define BN_is_word(a,w) ((w) ? BN_abs_is_word((a),(w)) && !(a)->neg : \
320 BN_is_zero((a)))
384#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1)) 321#define BN_is_odd(a) (((a)->top > 0) && ((a)->d[0] & 1))
385 322
386#define BN_one(a) (BN_set_word((a),1)) 323#define BN_one(a) (BN_set_word((a),1))
387#define BN_zero_ex(a) \
388 do { \
389 BIGNUM *_tmp_bn = (a); \
390 _tmp_bn->top = 0; \
391 _tmp_bn->neg = 0; \
392 } while(0)
393#ifdef OPENSSL_NO_DEPRECATED
394#define BN_zero(a) BN_zero_ex(a)
395#else
396#define BN_zero(a) (BN_set_word((a),0)) 324#define BN_zero(a) (BN_set_word((a),0))
397#endif 325
326/*#define BN_ascii2bn(a) BN_hex2bn(a) */
327/*#define BN_bn2ascii(a) BN_bn2hex(a) */
398 328
399const BIGNUM *BN_value_one(void); 329const BIGNUM *BN_value_one(void);
400char * BN_options(void); 330char * BN_options(void);
401BN_CTX *BN_CTX_new(void); 331BN_CTX *BN_CTX_new(void);
402#ifndef OPENSSL_NO_DEPRECATED
403void BN_CTX_init(BN_CTX *c); 332void BN_CTX_init(BN_CTX *c);
404#endif
405void BN_CTX_free(BN_CTX *c); 333void BN_CTX_free(BN_CTX *c);
406void BN_CTX_start(BN_CTX *ctx); 334void BN_CTX_start(BN_CTX *ctx);
407BIGNUM *BN_CTX_get(BN_CTX *ctx); 335BIGNUM *BN_CTX_get(BN_CTX *ctx);
@@ -427,16 +355,6 @@ int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
427int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 355int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
428int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx); 356int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
429int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx); 357int BN_sqr(BIGNUM *r, const BIGNUM *a,BN_CTX *ctx);
430/** BN_set_negative sets sign of a BIGNUM
431 * \param b pointer to the BIGNUM object
432 * \param n 0 if the BIGNUM b should be positive and a value != 0 otherwise
433 */
434void BN_set_negative(BIGNUM *b, int n);
435/** BN_is_negative returns 1 if the BIGNUM is negative
436 * \param a pointer to the BIGNUM object
437 * \return 1 if a < 0 and 0 otherwise
438 */
439#define BN_is_negative(a) ((a)->neg != 0)
440 358
441int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d, 359int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
442 BN_CTX *ctx); 360 BN_CTX *ctx);
@@ -510,9 +428,6 @@ BIGNUM *BN_mod_inverse(BIGNUM *ret,
510 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); 428 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
511BIGNUM *BN_mod_sqrt(BIGNUM *ret, 429BIGNUM *BN_mod_sqrt(BIGNUM *ret,
512 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx); 430 const BIGNUM *a, const BIGNUM *n,BN_CTX *ctx);
513
514/* Deprecated versions */
515#ifndef OPENSSL_NO_DEPRECATED
516BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe, 431BIGNUM *BN_generate_prime(BIGNUM *ret,int bits,int safe,
517 const BIGNUM *add, const BIGNUM *rem, 432 const BIGNUM *add, const BIGNUM *rem,
518 void (*callback)(int,int,void *),void *cb_arg); 433 void (*callback)(int,int,void *),void *cb_arg);
@@ -522,14 +437,19 @@ int BN_is_prime(const BIGNUM *p,int nchecks,
522int BN_is_prime_fasttest(const BIGNUM *p,int nchecks, 437int BN_is_prime_fasttest(const BIGNUM *p,int nchecks,
523 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg, 438 void (*callback)(int,int,void *),BN_CTX *ctx,void *cb_arg,
524 int do_trial_division); 439 int do_trial_division);
525#endif /* !defined(OPENSSL_NO_DEPRECATED) */
526 440
527/* Newer versions */ 441#ifdef OPENSSL_FIPS
528int BN_generate_prime_ex(BIGNUM *ret,int bits,int safe, const BIGNUM *add, 442int BN_X931_derive_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
529 const BIGNUM *rem, BN_GENCB *cb); 443 void (*cb)(int, int, void *), void *cb_arg,
530int BN_is_prime_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, BN_GENCB *cb); 444 const BIGNUM *Xp, const BIGNUM *Xp1, const BIGNUM *Xp2,
531int BN_is_prime_fasttest_ex(const BIGNUM *p,int nchecks, BN_CTX *ctx, 445 const BIGNUM *e, BN_CTX *ctx);
532 int do_trial_division, BN_GENCB *cb); 446int BN_X931_generate_Xpq(BIGNUM *Xp, BIGNUM *Xq, int nbits, BN_CTX *ctx);
447int BN_X931_generate_prime(BIGNUM *p, BIGNUM *p1, BIGNUM *p2,
448 BIGNUM *Xp1, BIGNUM *Xp2,
449 const BIGNUM *Xp,
450 const BIGNUM *e, BN_CTX *ctx,
451 void (*cb)(int, int, void *), void *cb_arg);
452#endif
533 453
534BN_MONT_CTX *BN_MONT_CTX_new(void ); 454BN_MONT_CTX *BN_MONT_CTX_new(void );
535void BN_MONT_CTX_init(BN_MONT_CTX *ctx); 455void BN_MONT_CTX_init(BN_MONT_CTX *ctx);
@@ -545,31 +465,14 @@ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to,BN_MONT_CTX *from);
545BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, 465BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
546 const BIGNUM *mod, BN_CTX *ctx); 466 const BIGNUM *mod, BN_CTX *ctx);
547 467
548/* BN_BLINDING flags */ 468BN_BLINDING *BN_BLINDING_new(BIGNUM *A,BIGNUM *Ai,BIGNUM *mod);
549#define BN_BLINDING_NO_UPDATE 0x00000001
550#define BN_BLINDING_NO_RECREATE 0x00000002
551
552BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod);
553void BN_BLINDING_free(BN_BLINDING *b); 469void BN_BLINDING_free(BN_BLINDING *b);
554int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx); 470int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
555int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); 471int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *r, BN_CTX *ctx);
556int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx); 472int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
557int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *); 473
558int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *);
559unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
560void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
561unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
562void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
563BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
564 const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx,
565 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
566 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
567 BN_MONT_CTX *m_ctx);
568
569#ifndef OPENSSL_NO_DEPRECATED
570void BN_set_params(int mul,int high,int low,int mont); 474void BN_set_params(int mul,int high,int low,int mont);
571int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */ 475int BN_get_params(int which); /* 0, mul, 1 high, 2 low, 3 mont */
572#endif
573 476
574void BN_RECP_CTX_init(BN_RECP_CTX *recp); 477void BN_RECP_CTX_init(BN_RECP_CTX *recp);
575BN_RECP_CTX *BN_RECP_CTX_new(void); 478BN_RECP_CTX *BN_RECP_CTX_new(void);
@@ -582,162 +485,15 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
582int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, 485int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
583 BN_RECP_CTX *recp, BN_CTX *ctx); 486 BN_RECP_CTX *recp, BN_CTX *ctx);
584 487
585/* Functions for arithmetic over binary polynomials represented by BIGNUMs.
586 *
587 * The BIGNUM::neg property of BIGNUMs representing binary polynomials is
588 * ignored.
589 *
590 * Note that input arguments are not const so that their bit arrays can
591 * be expanded to the appropriate size if needed.
592 */
593
594int BN_GF2m_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); /*r = a + b*/
595#define BN_GF2m_sub(r, a, b) BN_GF2m_add(r, a, b)
596int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p); /*r=a mod p*/
597int BN_GF2m_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
598 const BIGNUM *p, BN_CTX *ctx); /* r = (a * b) mod p */
599int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
600 BN_CTX *ctx); /* r = (a * a) mod p */
601int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *b, const BIGNUM *p,
602 BN_CTX *ctx); /* r = (1 / b) mod p */
603int BN_GF2m_mod_div(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
604 const BIGNUM *p, BN_CTX *ctx); /* r = (a / b) mod p */
605int BN_GF2m_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
606 const BIGNUM *p, BN_CTX *ctx); /* r = (a ^ b) mod p */
607int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
608 BN_CTX *ctx); /* r = sqrt(a) mod p */
609int BN_GF2m_mod_solve_quad(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
610 BN_CTX *ctx); /* r^2 + r = a mod p */
611#define BN_GF2m_cmp(a, b) BN_ucmp((a), (b))
612/* Some functions allow for representation of the irreducible polynomials
613 * as an unsigned int[], say p. The irreducible f(t) is then of the form:
614 * t^p[0] + t^p[1] + ... + t^p[k]
615 * where m = p[0] > p[1] > ... > p[k] = 0.
616 */
617int BN_GF2m_mod_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[]);
618 /* r = a mod p */
619int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
620 const unsigned int p[], BN_CTX *ctx); /* r = (a * b) mod p */
621int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const unsigned int p[],
622 BN_CTX *ctx); /* r = (a * a) mod p */
623int BN_GF2m_mod_inv_arr(BIGNUM *r, const BIGNUM *b, const unsigned int p[],
624 BN_CTX *ctx); /* r = (1 / b) mod p */
625int BN_GF2m_mod_div_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
626 const unsigned int p[], BN_CTX *ctx); /* r = (a / b) mod p */
627int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
628 const unsigned int p[], BN_CTX *ctx); /* r = (a ^ b) mod p */
629int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a,
630 const unsigned int p[], BN_CTX *ctx); /* r = sqrt(a) mod p */
631int BN_GF2m_mod_solve_quad_arr(BIGNUM *r, const BIGNUM *a,
632 const unsigned int p[], BN_CTX *ctx); /* r^2 + r = a mod p */
633int BN_GF2m_poly2arr(const BIGNUM *a, unsigned int p[], int max);
634int BN_GF2m_arr2poly(const unsigned int p[], BIGNUM *a);
635
636/* faster mod functions for the 'NIST primes'
637 * 0 <= a < p^2 */
638int BN_nist_mod_192(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
639int BN_nist_mod_224(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
640int BN_nist_mod_256(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
641int BN_nist_mod_384(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
642int BN_nist_mod_521(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx);
643
644const BIGNUM *BN_get0_nist_prime_192(void);
645const BIGNUM *BN_get0_nist_prime_224(void);
646const BIGNUM *BN_get0_nist_prime_256(void);
647const BIGNUM *BN_get0_nist_prime_384(void);
648const BIGNUM *BN_get0_nist_prime_521(void);
649
650/* library internal functions */ 488/* library internal functions */
651 489
652#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\ 490#define bn_expand(a,bits) ((((((bits+BN_BITS2-1))/BN_BITS2)) <= (a)->dmax)?\
653 (a):bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2)) 491 (a):bn_expand2((a),(bits)/BN_BITS2+1))
654#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words))) 492#define bn_wexpand(a,words) (((words) <= (a)->dmax)?(a):bn_expand2((a),(words)))
655BIGNUM *bn_expand2(BIGNUM *a, int words); 493BIGNUM *bn_expand2(BIGNUM *a, int words);
656#ifndef OPENSSL_NO_DEPRECATED 494BIGNUM *bn_dup_expand(const BIGNUM *a, int words);
657BIGNUM *bn_dup_expand(const BIGNUM *a, int words); /* unused */
658#endif
659
660/* Bignum consistency macros
661 * There is one "API" macro, bn_fix_top(), for stripping leading zeroes from
662 * bignum data after direct manipulations on the data. There is also an
663 * "internal" macro, bn_check_top(), for verifying that there are no leading
664 * zeroes. Unfortunately, some auditing is required due to the fact that
665 * bn_fix_top() has become an overabused duct-tape because bignum data is
666 * occasionally passed around in an inconsistent state. So the following
667 * changes have been made to sort this out;
668 * - bn_fix_top()s implementation has been moved to bn_correct_top()
669 * - if BN_DEBUG isn't defined, bn_fix_top() maps to bn_correct_top(), and
670 * bn_check_top() is as before.
671 * - if BN_DEBUG *is* defined;
672 * - bn_check_top() tries to pollute unused words even if the bignum 'top' is
673 * consistent. (ed: only if BN_DEBUG_RAND is defined)
674 * - bn_fix_top() maps to bn_check_top() rather than "fixing" anything.
675 * The idea is to have debug builds flag up inconsistent bignums when they
676 * occur. If that occurs in a bn_fix_top(), we examine the code in question; if
677 * the use of bn_fix_top() was appropriate (ie. it follows directly after code
678 * that manipulates the bignum) it is converted to bn_correct_top(), and if it
679 * was not appropriate, we convert it permanently to bn_check_top() and track
680 * down the cause of the bug. Eventually, no internal code should be using the
681 * bn_fix_top() macro. External applications and libraries should try this with
682 * their own code too, both in terms of building against the openssl headers
683 * with BN_DEBUG defined *and* linking with a version of OpenSSL built with it
684 * defined. This not only improves external code, it provides more test
685 * coverage for openssl's own code.
686 */
687
688#ifdef BN_DEBUG
689 495
690/* We only need assert() when debugging */ 496#define bn_fix_top(a) \
691#include <assert.h>
692
693#ifdef BN_DEBUG_RAND
694/* To avoid "make update" cvs wars due to BN_DEBUG, use some tricks */
695#ifndef RAND_pseudo_bytes
696int RAND_pseudo_bytes(unsigned char *buf,int num);
697#define BN_DEBUG_TRIX
698#endif
699#define bn_pollute(a) \
700 do { \
701 const BIGNUM *_bnum1 = (a); \
702 if(_bnum1->top < _bnum1->dmax) { \
703 unsigned char _tmp_char; \
704 /* We cast away const without the compiler knowing, any \
705 * *genuinely* constant variables that aren't mutable \
706 * wouldn't be constructed with top!=dmax. */ \
707 BN_ULONG *_not_const; \
708 memcpy(&_not_const, &_bnum1->d, sizeof(BN_ULONG*)); \
709 RAND_pseudo_bytes(&_tmp_char, 1); \
710 memset((unsigned char *)(_not_const + _bnum1->top), _tmp_char, \
711 (_bnum1->dmax - _bnum1->top) * sizeof(BN_ULONG)); \
712 } \
713 } while(0)
714#ifdef BN_DEBUG_TRIX
715#undef RAND_pseudo_bytes
716#endif
717#else
718#define bn_pollute(a)
719#endif
720#define bn_check_top(a) \
721 do { \
722 const BIGNUM *_bnum2 = (a); \
723 if (_bnum2 != NULL) { \
724 assert((_bnum2->top == 0) || \
725 (_bnum2->d[_bnum2->top - 1] != 0)); \
726 bn_pollute(_bnum2); \
727 } \
728 } while(0)
729
730#define bn_fix_top(a) bn_check_top(a)
731
732#else /* !BN_DEBUG */
733
734#define bn_pollute(a)
735#define bn_check_top(a)
736#define bn_fix_top(a) bn_correct_top(a)
737
738#endif
739
740#define bn_correct_top(a) \
741 { \ 497 { \
742 BN_ULONG *ftl; \ 498 BN_ULONG *ftl; \
743 if ((a)->top > 0) \ 499 if ((a)->top > 0) \
@@ -745,7 +501,6 @@ int RAND_pseudo_bytes(unsigned char *buf,int num);
745 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \ 501 for (ftl= &((a)->d[(a)->top-1]); (a)->top > 0; (a)->top--) \
746 if (*(ftl--)) break; \ 502 if (*(ftl--)) break; \
747 } \ 503 } \
748 bn_pollute(a); \
749 } 504 }
750 505
751BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w); 506BN_ULONG bn_mul_add_words(BN_ULONG *rp, const BN_ULONG *ap, int num, BN_ULONG w);
@@ -755,17 +510,15 @@ BN_ULONG bn_div_words(BN_ULONG h, BN_ULONG l, BN_ULONG d);
755BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); 510BN_ULONG bn_add_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
756BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num); 511BN_ULONG bn_sub_words(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,int num);
757 512
758/* Primes from RFC 2409 */ 513#ifdef BN_DEBUG
759BIGNUM *get_rfc2409_prime_768(BIGNUM *bn); 514void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n);
760BIGNUM *get_rfc2409_prime_1024(BIGNUM *bn); 515# define bn_print(a) {fprintf(stderr, #a "="); BN_print_fp(stderr,a); \
761 516 fprintf(stderr,"\n");}
762/* Primes from RFC 3526 */ 517# define bn_dump(a,n) bn_dump1(stderr,#a,a,n);
763BIGNUM *get_rfc3526_prime_1536(BIGNUM *bn); 518#else
764BIGNUM *get_rfc3526_prime_2048(BIGNUM *bn); 519# define bn_print(a)
765BIGNUM *get_rfc3526_prime_3072(BIGNUM *bn); 520# define bn_dump(a,b)
766BIGNUM *get_rfc3526_prime_4096(BIGNUM *bn); 521#endif
767BIGNUM *get_rfc3526_prime_6144(BIGNUM *bn);
768BIGNUM *get_rfc3526_prime_8192(BIGNUM *bn);
769 522
770int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom); 523int BN_bntest_rand(BIGNUM *rnd, int bits, int top,int bottom);
771 524
@@ -778,30 +531,18 @@ void ERR_load_BN_strings(void);
778/* Error codes for the BN functions. */ 531/* Error codes for the BN functions. */
779 532
780/* Function codes. */ 533/* Function codes. */
781#define BN_F_BNRAND 127 534#define BN_F_BN_BLINDING_CONVERT 100
782#define BN_F_BN_BLINDING_CONVERT_EX 100 535#define BN_F_BN_BLINDING_INVERT 101
783#define BN_F_BN_BLINDING_CREATE_PARAM 128
784#define BN_F_BN_BLINDING_INVERT_EX 101
785#define BN_F_BN_BLINDING_NEW 102 536#define BN_F_BN_BLINDING_NEW 102
786#define BN_F_BN_BLINDING_UPDATE 103 537#define BN_F_BN_BLINDING_UPDATE 103
787#define BN_F_BN_BN2DEC 104 538#define BN_F_BN_BN2DEC 104
788#define BN_F_BN_BN2HEX 105 539#define BN_F_BN_BN2HEX 105
789#define BN_F_BN_CTX_GET 116 540#define BN_F_BN_CTX_GET 116
790#define BN_F_BN_CTX_NEW 106 541#define BN_F_BN_CTX_NEW 106
791#define BN_F_BN_CTX_START 129
792#define BN_F_BN_DIV 107 542#define BN_F_BN_DIV 107
793#define BN_F_BN_DIV_NO_BRANCH 138
794#define BN_F_BN_DIV_RECP 130
795#define BN_F_BN_EXP 123 543#define BN_F_BN_EXP 123
796#define BN_F_BN_EXPAND2 108 544#define BN_F_BN_EXPAND2 108
797#define BN_F_BN_EXPAND_INTERNAL 120 545#define BN_F_BN_EXPAND_INTERNAL 120
798#define BN_F_BN_GF2M_MOD 131
799#define BN_F_BN_GF2M_MOD_EXP 132
800#define BN_F_BN_GF2M_MOD_MUL 133
801#define BN_F_BN_GF2M_MOD_SOLVE_QUAD 134
802#define BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR 135
803#define BN_F_BN_GF2M_MOD_SQR 136
804#define BN_F_BN_GF2M_MOD_SQRT 137
805#define BN_F_BN_MOD_EXP2_MONT 118 546#define BN_F_BN_MOD_EXP2_MONT 118
806#define BN_F_BN_MOD_EXP_MONT 109 547#define BN_F_BN_MOD_EXP_MONT 109
807#define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124 548#define BN_F_BN_MOD_EXP_MONT_CONSTTIME 124
@@ -809,7 +550,6 @@ void ERR_load_BN_strings(void);
809#define BN_F_BN_MOD_EXP_RECP 125 550#define BN_F_BN_MOD_EXP_RECP 125
810#define BN_F_BN_MOD_EXP_SIMPLE 126 551#define BN_F_BN_MOD_EXP_SIMPLE 126
811#define BN_F_BN_MOD_INVERSE 110 552#define BN_F_BN_MOD_INVERSE 110
812#define BN_F_BN_MOD_INVERSE_NO_BRANCH 139
813#define BN_F_BN_MOD_LSHIFT_QUICK 119 553#define BN_F_BN_MOD_LSHIFT_QUICK 119
814#define BN_F_BN_MOD_MUL_RECIPROCAL 111 554#define BN_F_BN_MOD_MUL_RECIPROCAL 111
815#define BN_F_BN_MOD_SQRT 121 555#define BN_F_BN_MOD_SQRT 121
@@ -833,7 +573,6 @@ void ERR_load_BN_strings(void);
833#define BN_R_NOT_A_SQUARE 111 573#define BN_R_NOT_A_SQUARE 111
834#define BN_R_NOT_INITIALIZED 107 574#define BN_R_NOT_INITIALIZED 107
835#define BN_R_NO_INVERSE 108 575#define BN_R_NO_INVERSE 108
836#define BN_R_NO_SOLUTION 116
837#define BN_R_P_IS_NOT_PRIME 112 576#define BN_R_P_IS_NOT_PRIME 112
838#define BN_R_TOO_MANY_ITERATIONS 113 577#define BN_R_TOO_MANY_ITERATIONS 113
839#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109 578#define BN_R_TOO_MANY_TEMPORARY_VARIABLES 109
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 9405163706..6cba07e9f6 100644
--- a/src/lib/libcrypto/bn/bn_add.c
+++ b/src/lib/libcrypto/bn/bn_add.c
@@ -64,7 +64,7 @@
64int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) 64int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
65 { 65 {
66 const BIGNUM *tmp; 66 const BIGNUM *tmp;
67 int a_neg = a->neg, ret; 67 int a_neg = a->neg;
68 68
69 bn_check_top(a); 69 bn_check_top(a);
70 bn_check_top(b); 70 bn_check_top(b);
@@ -95,17 +95,20 @@ int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
95 return(1); 95 return(1);
96 } 96 }
97 97
98 ret = BN_uadd(r,a,b); 98 if (!BN_uadd(r,a,b)) return(0);
99 r->neg = a_neg; 99 if (a_neg) /* both are neg */
100 bn_check_top(r); 100 r->neg=1;
101 return ret; 101 else
102 r->neg=0;
103 return(1);
102 } 104 }
103 105
104/* unsigned add of b to a */ 106/* unsigned add of b to a, r must be large enough */
105int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) 107int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
106 { 108 {
107 int max,min,dif; 109 register int i;
108 BN_ULONG *ap,*bp,*rp,carry,t1,t2; 110 int max,min;
111 BN_ULONG *ap,*bp,*rp,carry,t1;
109 const BIGNUM *tmp; 112 const BIGNUM *tmp;
110 113
111 bn_check_top(a); 114 bn_check_top(a);
@@ -113,12 +116,11 @@ int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
113 116
114 if (a->top < b->top) 117 if (a->top < b->top)
115 { tmp=a; a=b; b=tmp; } 118 { tmp=a; a=b; b=tmp; }
116 max = a->top; 119 max=a->top;
117 min = b->top; 120 min=b->top;
118 dif = max - min;
119 121
120 if (bn_wexpand(r,max+1) == NULL) 122 if (bn_wexpand(r,max+1) == NULL)
121 return 0; 123 return(0);
122 124
123 r->top=max; 125 r->top=max;
124 126
@@ -126,46 +128,46 @@ int BN_uadd(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
126 ap=a->d; 128 ap=a->d;
127 bp=b->d; 129 bp=b->d;
128 rp=r->d; 130 rp=r->d;
131 carry=0;
129 132
130 carry=bn_add_words(rp,ap,bp,min); 133 carry=bn_add_words(rp,ap,bp,min);
131 rp+=min; 134 rp+=min;
132 ap+=min; 135 ap+=min;
133 bp+=min; 136 bp+=min;
137 i=min;
134 138
135 if (carry) 139 if (carry)
136 { 140 {
137 while (dif) 141 while (i < max)
138 { 142 {
139 dif--; 143 i++;
140 t1 = *(ap++); 144 t1= *(ap++);
141 t2 = (t1+1) & BN_MASK2; 145 if ((*(rp++)=(t1+1)&BN_MASK2) >= t1)
142 *(rp++) = t2;
143 if (t2)
144 { 146 {
145 carry=0; 147 carry=0;
146 break; 148 break;
147 } 149 }
148 } 150 }
149 if (carry) 151 if ((i >= max) && carry)
150 { 152 {
151 /* carry != 0 => dif == 0 */ 153 *(rp++)=1;
152 *rp = 1;
153 r->top++; 154 r->top++;
154 } 155 }
155 } 156 }
156 if (dif && rp != ap) 157 if (rp != ap)
157 while (dif--) 158 {
158 /* copy remaining words if ap != rp */ 159 for (; i<max; i++)
159 *(rp++) = *(ap++); 160 *(rp++)= *(ap++);
161 }
162 /* memcpy(rp,ap,sizeof(*ap)*(max-i));*/
160 r->neg = 0; 163 r->neg = 0;
161 bn_check_top(r); 164 return(1);
162 return 1;
163 } 165 }
164 166
165/* unsigned subtraction of b from a, a must be larger than b. */ 167/* unsigned subtraction of b from a, a must be larger than b. */
166int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b) 168int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
167 { 169 {
168 int max,min,dif; 170 int max,min;
169 register BN_ULONG t1,t2,*ap,*bp,*rp; 171 register BN_ULONG t1,t2,*ap,*bp,*rp;
170 int i,carry; 172 int i,carry;
171#if defined(IRIX_CC_BUG) && !defined(LINT) 173#if defined(IRIX_CC_BUG) && !defined(LINT)
@@ -175,16 +177,14 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
175 bn_check_top(a); 177 bn_check_top(a);
176 bn_check_top(b); 178 bn_check_top(b);
177 179
178 max = a->top; 180 if (a->top < b->top) /* hmm... should not be happening */
179 min = b->top;
180 dif = max - min;
181
182 if (dif < 0) /* hmm... should not be happening */
183 { 181 {
184 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3); 182 BNerr(BN_F_BN_USUB,BN_R_ARG2_LT_ARG3);
185 return(0); 183 return(0);
186 } 184 }
187 185
186 max=a->top;
187 min=b->top;
188 if (bn_wexpand(r,max) == NULL) return(0); 188 if (bn_wexpand(r,max) == NULL) return(0);
189 189
190 ap=a->d; 190 ap=a->d;
@@ -193,7 +193,7 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
193 193
194#if 1 194#if 1
195 carry=0; 195 carry=0;
196 for (i = min; i != 0; i--) 196 for (i=0; i<min; i++)
197 { 197 {
198 t1= *(ap++); 198 t1= *(ap++);
199 t2= *(bp++); 199 t2= *(bp++);
@@ -217,20 +217,17 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
217 ap+=min; 217 ap+=min;
218 bp+=min; 218 bp+=min;
219 rp+=min; 219 rp+=min;
220 i=min;
220#endif 221#endif
221 if (carry) /* subtracted */ 222 if (carry) /* subtracted */
222 { 223 {
223 if (!dif) 224 while (i < max)
224 /* error: a < b */
225 return 0;
226 while (dif)
227 { 225 {
228 dif--; 226 i++;
229 t1 = *(ap++); 227 t1= *(ap++);
230 t2 = (t1-1)&BN_MASK2; 228 t2=(t1-1)&BN_MASK2;
231 *(rp++) = t2; 229 *(rp++)=t2;
232 if (t1) 230 if (t1 > t2) break;
233 break;
234 } 231 }
235 } 232 }
236#if 0 233#if 0
@@ -240,13 +237,13 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
240 { 237 {
241 for (;;) 238 for (;;)
242 { 239 {
243 if (!dif--) break; 240 if (i++ >= max) break;
244 rp[0]=ap[0]; 241 rp[0]=ap[0];
245 if (!dif--) break; 242 if (i++ >= max) break;
246 rp[1]=ap[1]; 243 rp[1]=ap[1];
247 if (!dif--) break; 244 if (i++ >= max) break;
248 rp[2]=ap[2]; 245 rp[2]=ap[2];
249 if (!dif--) break; 246 if (i++ >= max) break;
250 rp[3]=ap[3]; 247 rp[3]=ap[3];
251 rp+=4; 248 rp+=4;
252 ap+=4; 249 ap+=4;
@@ -256,7 +253,7 @@ int BN_usub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
256 253
257 r->top=max; 254 r->top=max;
258 r->neg=0; 255 r->neg=0;
259 bn_correct_top(r); 256 bn_fix_top(r);
260 return(1); 257 return(1);
261 } 258 }
262 259
@@ -307,7 +304,6 @@ int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b)
307 if (!BN_usub(r,a,b)) return(0); 304 if (!BN_usub(r,a,b)) return(0);
308 r->neg=0; 305 r->neg=0;
309 } 306 }
310 bn_check_top(r);
311 return(1); 307 return(1);
312 } 308 }
313 309
diff --git a/src/lib/libcrypto/bn/bn_asm.c b/src/lib/libcrypto/bn/bn_asm.c
index 99bc2de491..19978085b2 100644
--- a/src/lib/libcrypto/bn/bn_asm.c
+++ b/src/lib/libcrypto/bn/bn_asm.c
@@ -459,34 +459,6 @@ BN_ULONG bn_sub_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, int n)
459#define sqr_add_c2(a,i,j,c0,c1,c2) \ 459#define sqr_add_c2(a,i,j,c0,c1,c2) \
460 mul_add_c2((a)[i],(a)[j],c0,c1,c2) 460 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
461 461
462#elif defined(BN_UMULT_LOHI)
463
464#define mul_add_c(a,b,c0,c1,c2) { \
465 BN_ULONG ta=(a),tb=(b); \
466 BN_UMULT_LOHI(t1,t2,ta,tb); \
467 c0 += t1; t2 += (c0<t1)?1:0; \
468 c1 += t2; c2 += (c1<t2)?1:0; \
469 }
470
471#define mul_add_c2(a,b,c0,c1,c2) { \
472 BN_ULONG ta=(a),tb=(b),t0; \
473 BN_UMULT_LOHI(t0,t1,ta,tb); \
474 t2 = t1+t1; c2 += (t2<t1)?1:0; \
475 t1 = t0+t0; t2 += (t1<t0)?1:0; \
476 c0 += t1; t2 += (c0<t1)?1:0; \
477 c1 += t2; c2 += (c1<t2)?1:0; \
478 }
479
480#define sqr_add_c(a,i,c0,c1,c2) { \
481 BN_ULONG ta=(a)[i]; \
482 BN_UMULT_LOHI(t1,t2,ta,ta); \
483 c0 += t1; t2 += (c0<t1)?1:0; \
484 c1 += t2; c2 += (c1<t2)?1:0; \
485 }
486
487#define sqr_add_c2(a,i,j,c0,c1,c2) \
488 mul_add_c2((a)[i],(a)[j],c0,c1,c2)
489
490#elif defined(BN_UMULT_HIGH) 462#elif defined(BN_UMULT_HIGH)
491 463
492#define mul_add_c(a,b,c0,c1,c2) { \ 464#define mul_add_c(a,b,c0,c1,c2) { \
diff --git a/src/lib/libcrypto/bn/bn_blind.c b/src/lib/libcrypto/bn/bn_blind.c
index c11fb4ccc2..2d287e6d1b 100644
--- a/src/lib/libcrypto/bn/bn_blind.c
+++ b/src/lib/libcrypto/bn/bn_blind.c
@@ -1,57 +1,4 @@
1/* crypto/bn/bn_blind.c */ 1/* crypto/bn/bn_blind.c */
2/* ====================================================================
3 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved. 3 * All rights reserved.
57 * 4 *
@@ -113,28 +60,11 @@
113#include "cryptlib.h" 60#include "cryptlib.h"
114#include "bn_lcl.h" 61#include "bn_lcl.h"
115 62
116#define BN_BLINDING_COUNTER 32 63BN_BLINDING *BN_BLINDING_new(BIGNUM *A, BIGNUM *Ai, BIGNUM *mod)
117
118struct bn_blinding_st
119 {
120 BIGNUM *A;
121 BIGNUM *Ai;
122 BIGNUM *e;
123 BIGNUM *mod; /* just a reference */
124 unsigned long thread_id; /* added in OpenSSL 0.9.6j and 0.9.7b;
125 * used only by crypto/rsa/rsa_eay.c, rsa_lib.c */
126 unsigned int counter;
127 unsigned long flags;
128 BN_MONT_CTX *m_ctx;
129 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
130 const BIGNUM *m, BN_CTX *ctx,
131 BN_MONT_CTX *m_ctx);
132 };
133
134BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGNUM *mod)
135 { 64 {
136 BN_BLINDING *ret=NULL; 65 BN_BLINDING *ret=NULL;
137 66
67 bn_check_top(Ai);
138 bn_check_top(mod); 68 bn_check_top(mod);
139 69
140 if ((ret=(BN_BLINDING *)OPENSSL_malloc(sizeof(BN_BLINDING))) == NULL) 70 if ((ret=(BN_BLINDING *)OPENSSL_malloc(sizeof(BN_BLINDING))) == NULL)
@@ -143,21 +73,11 @@ BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai, /* const */ BIGN
143 return(NULL); 73 return(NULL);
144 } 74 }
145 memset(ret,0,sizeof(BN_BLINDING)); 75 memset(ret,0,sizeof(BN_BLINDING));
146 if (A != NULL) 76 if ((ret->A=BN_new()) == NULL) goto err;
147 { 77 if ((ret->Ai=BN_new()) == NULL) goto err;
148 if ((ret->A = BN_dup(A)) == NULL) goto err; 78 if (!BN_copy(ret->A,A)) goto err;
149 } 79 if (!BN_copy(ret->Ai,Ai)) goto err;
150 if (Ai != NULL) 80 ret->mod=mod;
151 {
152 if ((ret->Ai = BN_dup(Ai)) == NULL) goto err;
153 }
154
155 /* save a copy of mod in the BN_BLINDING structure */
156 if ((ret->mod = BN_dup(mod)) == NULL) goto err;
157 if (BN_get_flags(mod, BN_FLG_CONSTTIME) != 0)
158 BN_set_flags(ret->mod, BN_FLG_CONSTTIME);
159
160 ret->counter = BN_BLINDING_COUNTER;
161 return(ret); 81 return(ret);
162err: 82err:
163 if (ret != NULL) BN_BLINDING_free(ret); 83 if (ret != NULL) BN_BLINDING_free(ret);
@@ -171,8 +91,6 @@ void BN_BLINDING_free(BN_BLINDING *r)
171 91
172 if (r->A != NULL) BN_free(r->A ); 92 if (r->A != NULL) BN_free(r->A );
173 if (r->Ai != NULL) BN_free(r->Ai); 93 if (r->Ai != NULL) BN_free(r->Ai);
174 if (r->e != NULL) BN_free(r->e );
175 if (r->mod != NULL) BN_free(r->mod);
176 OPENSSL_free(r); 94 OPENSSL_free(r);
177 } 95 }
178 96
@@ -185,181 +103,42 @@ int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx)
185 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED); 103 BNerr(BN_F_BN_BLINDING_UPDATE,BN_R_NOT_INITIALIZED);
186 goto err; 104 goto err;
187 } 105 }
188 106
189 if (--(b->counter) == 0 && b->e != NULL && 107 if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
190 !(b->flags & BN_BLINDING_NO_RECREATE)) 108 if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
191 {
192 /* re-create blinding parameters */
193 if (!BN_BLINDING_create_param(b, NULL, NULL, ctx, NULL, NULL))
194 goto err;
195 }
196 else if (!(b->flags & BN_BLINDING_NO_UPDATE))
197 {
198 if (!BN_mod_mul(b->A,b->A,b->A,b->mod,ctx)) goto err;
199 if (!BN_mod_mul(b->Ai,b->Ai,b->Ai,b->mod,ctx)) goto err;
200 }
201 109
202 ret=1; 110 ret=1;
203err: 111err:
204 if (b->counter == 0)
205 b->counter = BN_BLINDING_COUNTER;
206 return(ret); 112 return(ret);
207 } 113 }
208 114
209int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) 115int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
210 { 116 {
211 return BN_BLINDING_convert_ex(n, NULL, b, ctx);
212 }
213
214int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
215 {
216 int ret = 1;
217
218 bn_check_top(n); 117 bn_check_top(n);
219 118
220 if ((b->A == NULL) || (b->Ai == NULL)) 119 if ((b->A == NULL) || (b->Ai == NULL))
221 { 120 {
222 BNerr(BN_F_BN_BLINDING_CONVERT_EX,BN_R_NOT_INITIALIZED); 121 BNerr(BN_F_BN_BLINDING_CONVERT,BN_R_NOT_INITIALIZED);
223 return(0); 122 return(0);
224 } 123 }
225 124 return(BN_mod_mul(n,n,b->A,b->mod,ctx));
226 if (r != NULL)
227 {
228 if (!BN_copy(r, b->Ai)) ret=0;
229 }
230
231 if (!BN_mod_mul(n,n,b->A,b->mod,ctx)) ret=0;
232
233 return ret;
234 } 125 }
235 126
236int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx) 127int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx)
237 { 128 {
238 return BN_BLINDING_invert_ex(n, NULL, b, ctx);
239 }
240
241int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b, BN_CTX *ctx)
242 {
243 int ret; 129 int ret;
244 130
245 bn_check_top(n); 131 bn_check_top(n);
246 if ((b->A == NULL) || (b->Ai == NULL)) 132 if ((b->A == NULL) || (b->Ai == NULL))
247 { 133 {
248 BNerr(BN_F_BN_BLINDING_INVERT_EX,BN_R_NOT_INITIALIZED); 134 BNerr(BN_F_BN_BLINDING_INVERT,BN_R_NOT_INITIALIZED);
249 return(0); 135 return(0);
250 } 136 }
251 137 if ((ret=BN_mod_mul(n,n,b->Ai,b->mod,ctx)) >= 0)
252 if (r != NULL)
253 ret = BN_mod_mul(n, n, r, b->mod, ctx);
254 else
255 ret = BN_mod_mul(n, n, b->Ai, b->mod, ctx);
256
257 if (ret >= 0)
258 { 138 {
259 if (!BN_BLINDING_update(b,ctx)) 139 if (!BN_BLINDING_update(b,ctx))
260 return(0); 140 return(0);
261 } 141 }
262 bn_check_top(n);
263 return(ret); 142 return(ret);
264 } 143 }
265 144
266unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *b)
267 {
268 return b->thread_id;
269 }
270
271void BN_BLINDING_set_thread_id(BN_BLINDING *b, unsigned long n)
272 {
273 b->thread_id = n;
274 }
275
276unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b)
277 {
278 return b->flags;
279 }
280
281void BN_BLINDING_set_flags(BN_BLINDING *b, unsigned long flags)
282 {
283 b->flags = flags;
284 }
285
286BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
287 const BIGNUM *e, /* const */ BIGNUM *m, BN_CTX *ctx,
288 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
289 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
290 BN_MONT_CTX *m_ctx)
291{
292 int retry_counter = 32;
293 BN_BLINDING *ret = NULL;
294
295 if (b == NULL)
296 ret = BN_BLINDING_new(NULL, NULL, m);
297 else
298 ret = b;
299
300 if (ret == NULL)
301 goto err;
302
303 if (ret->A == NULL && (ret->A = BN_new()) == NULL)
304 goto err;
305 if (ret->Ai == NULL && (ret->Ai = BN_new()) == NULL)
306 goto err;
307
308 if (e != NULL)
309 {
310 if (ret->e != NULL)
311 BN_free(ret->e);
312 ret->e = BN_dup(e);
313 }
314 if (ret->e == NULL)
315 goto err;
316
317 if (bn_mod_exp != NULL)
318 ret->bn_mod_exp = bn_mod_exp;
319 if (m_ctx != NULL)
320 ret->m_ctx = m_ctx;
321
322 do {
323 if (!BN_rand_range(ret->A, ret->mod)) goto err;
324 if (BN_mod_inverse(ret->Ai, ret->A, ret->mod, ctx) == NULL)
325 {
326 /* this should almost never happen for good RSA keys */
327 unsigned long error = ERR_peek_last_error();
328 if (ERR_GET_REASON(error) == BN_R_NO_INVERSE)
329 {
330 if (retry_counter-- == 0)
331 {
332 BNerr(BN_F_BN_BLINDING_CREATE_PARAM,
333 BN_R_TOO_MANY_ITERATIONS);
334 goto err;
335 }
336 ERR_clear_error();
337 }
338 else
339 goto err;
340 }
341 else
342 break;
343 } while (1);
344
345 if (ret->bn_mod_exp != NULL && ret->m_ctx != NULL)
346 {
347 if (!ret->bn_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx, ret->m_ctx))
348 goto err;
349 }
350 else
351 {
352 if (!BN_mod_exp(ret->A, ret->A, ret->e, ret->mod, ctx))
353 goto err;
354 }
355
356 return ret;
357err:
358 if (b == NULL && ret != NULL)
359 {
360 BN_BLINDING_free(ret);
361 ret = NULL;
362 }
363
364 return ret;
365}
diff --git a/src/lib/libcrypto/bn/bn_ctx.c b/src/lib/libcrypto/bn/bn_ctx.c
index b3452f1a91..7daf19eb84 100644
--- a/src/lib/libcrypto/bn/bn_ctx.c
+++ b/src/lib/libcrypto/bn/bn_ctx.c
@@ -1,7 +1,7 @@
1/* crypto/bn/bn_ctx.c */ 1/* crypto/bn/bn_ctx.c */
2/* Written by Ulf Moeller for the OpenSSL project. */ 2/* Written by Ulf Moeller for the OpenSSL project. */
3/* ==================================================================== 3/* ====================================================================
4 * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. 4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
@@ -54,10 +54,9 @@
54 * 54 *
55 */ 55 */
56 56
57#if !defined(BN_CTX_DEBUG) && !defined(BN_DEBUG) 57#ifndef BN_CTX_DEBUG
58#ifndef NDEBUG 58# undef NDEBUG /* avoid conflicting definitions */
59#define NDEBUG 59# define NDEBUG
60#endif
61#endif 60#endif
62 61
63#include <stdio.h> 62#include <stdio.h>
@@ -66,389 +65,91 @@
66#include "cryptlib.h" 65#include "cryptlib.h"
67#include "bn_lcl.h" 66#include "bn_lcl.h"
68 67
69/* TODO list
70 *
71 * 1. Check a bunch of "(words+1)" type hacks in various bignum functions and
72 * check they can be safely removed.
73 * - Check +1 and other ugliness in BN_from_montgomery()
74 *
75 * 2. Consider allowing a BN_new_ex() that, at least, lets you specify an
76 * appropriate 'block' size that will be honoured by bn_expand_internal() to
77 * prevent piddly little reallocations. OTOH, profiling bignum expansions in
78 * BN_CTX doesn't show this to be a big issue.
79 */
80
81/* How many bignums are in each "pool item"; */
82#define BN_CTX_POOL_SIZE 16
83/* The stack frame info is resizing, set a first-time expansion size; */
84#define BN_CTX_START_FRAMES 32
85
86/***********/
87/* BN_POOL */
88/***********/
89
90/* A bundle of bignums that can be linked with other bundles */
91typedef struct bignum_pool_item
92 {
93 /* The bignum values */
94 BIGNUM vals[BN_CTX_POOL_SIZE];
95 /* Linked-list admin */
96 struct bignum_pool_item *prev, *next;
97 } BN_POOL_ITEM;
98/* A linked-list of bignums grouped in bundles */
99typedef struct bignum_pool
100 {
101 /* Linked-list admin */
102 BN_POOL_ITEM *head, *current, *tail;
103 /* Stack depth and allocation size */
104 unsigned used, size;
105 } BN_POOL;
106static void BN_POOL_init(BN_POOL *);
107static void BN_POOL_finish(BN_POOL *);
108#ifndef OPENSSL_NO_DEPRECATED
109static void BN_POOL_reset(BN_POOL *);
110#endif
111static BIGNUM * BN_POOL_get(BN_POOL *);
112static void BN_POOL_release(BN_POOL *, unsigned int);
113
114/************/
115/* BN_STACK */
116/************/
117
118/* A wrapper to manage the "stack frames" */
119typedef struct bignum_ctx_stack
120 {
121 /* Array of indexes into the bignum stack */
122 unsigned int *indexes;
123 /* Number of stack frames, and the size of the allocated array */
124 unsigned int depth, size;
125 } BN_STACK;
126static void BN_STACK_init(BN_STACK *);
127static void BN_STACK_finish(BN_STACK *);
128#ifndef OPENSSL_NO_DEPRECATED
129static void BN_STACK_reset(BN_STACK *);
130#endif
131static int BN_STACK_push(BN_STACK *, unsigned int);
132static unsigned int BN_STACK_pop(BN_STACK *);
133
134/**********/
135/* BN_CTX */
136/**********/
137 68
138/* The opaque BN_CTX type */ 69BN_CTX *BN_CTX_new(void)
139struct bignum_ctx
140 { 70 {
141 /* The bignum bundles */ 71 BN_CTX *ret;
142 BN_POOL pool;
143 /* The "stack frames", if you will */
144 BN_STACK stack;
145 /* The number of bignums currently assigned */
146 unsigned int used;
147 /* Depth of stack overflow */
148 int err_stack;
149 /* Block "gets" until an "end" (compatibility behaviour) */
150 int too_many;
151 };
152 72
153/* Enable this to find BN_CTX bugs */ 73 ret=(BN_CTX *)OPENSSL_malloc(sizeof(BN_CTX));
154#ifdef BN_CTX_DEBUG 74 if (ret == NULL)
155static const char *ctxdbg_cur = NULL;
156static void ctxdbg(BN_CTX *ctx)
157 {
158 unsigned int bnidx = 0, fpidx = 0;
159 BN_POOL_ITEM *item = ctx->pool.head;
160 BN_STACK *stack = &ctx->stack;
161 fprintf(stderr,"(%08x): ", (unsigned int)ctx);
162 while(bnidx < ctx->used)
163 {
164 fprintf(stderr,"%02x ", item->vals[bnidx++ % BN_CTX_POOL_SIZE].dmax);
165 if(!(bnidx % BN_CTX_POOL_SIZE))
166 item = item->next;
167 }
168 fprintf(stderr,"\n");
169 bnidx = 0;
170 fprintf(stderr," : ");
171 while(fpidx < stack->depth)
172 { 75 {
173 while(bnidx++ < stack->indexes[fpidx]) 76 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
174 fprintf(stderr," "); 77 return(NULL);
175 fprintf(stderr,"^^ ");
176 bnidx++;
177 fpidx++;
178 } 78 }
179 fprintf(stderr,"\n"); 79
80 BN_CTX_init(ret);
81 ret->flags=BN_FLG_MALLOCED;
82 return(ret);
180 } 83 }
181#define CTXDBG_ENTRY(str, ctx) do { \
182 ctxdbg_cur = (str); \
183 fprintf(stderr,"Starting %s\n", ctxdbg_cur); \
184 ctxdbg(ctx); \
185 } while(0)
186#define CTXDBG_EXIT(ctx) do { \
187 fprintf(stderr,"Ending %s\n", ctxdbg_cur); \
188 ctxdbg(ctx); \
189 } while(0)
190#define CTXDBG_RET(ctx,ret)
191#else
192#define CTXDBG_ENTRY(str, ctx)
193#define CTXDBG_EXIT(ctx)
194#define CTXDBG_RET(ctx,ret)
195#endif
196 84
197/* This function is an evil legacy and should not be used. This implementation
198 * is WYSIWYG, though I've done my best. */
199#ifndef OPENSSL_NO_DEPRECATED
200void BN_CTX_init(BN_CTX *ctx) 85void BN_CTX_init(BN_CTX *ctx)
201 { 86 {
202 /* Assume the caller obtained the context via BN_CTX_new() and so is 87#if 0 /* explicit version */
203 * trying to reset it for use. Nothing else makes sense, least of all 88 int i;
204 * binary compatibility from a time when they could declare a static 89 ctx->tos = 0;
205 * variable. */ 90 ctx->flags = 0;
206 BN_POOL_reset(&ctx->pool); 91 ctx->depth = 0;
207 BN_STACK_reset(&ctx->stack);
208 ctx->used = 0;
209 ctx->err_stack = 0;
210 ctx->too_many = 0; 92 ctx->too_many = 0;
211 } 93 for (i = 0; i < BN_CTX_NUM; i++)
94 BN_init(&(ctx->bn[i]));
95#else
96 memset(ctx, 0, sizeof *ctx);
212#endif 97#endif
213
214BN_CTX *BN_CTX_new(void)
215 {
216 BN_CTX *ret = OPENSSL_malloc(sizeof(BN_CTX));
217 if(!ret)
218 {
219 BNerr(BN_F_BN_CTX_NEW,ERR_R_MALLOC_FAILURE);
220 return NULL;
221 }
222 /* Initialise the structure */
223 BN_POOL_init(&ret->pool);
224 BN_STACK_init(&ret->stack);
225 ret->used = 0;
226 ret->err_stack = 0;
227 ret->too_many = 0;
228 return ret;
229 } 98 }
230 99
231void BN_CTX_free(BN_CTX *ctx) 100void BN_CTX_free(BN_CTX *ctx)
232 { 101 {
233 if (ctx == NULL) 102 int i;
234 return;
235#ifdef BN_CTX_DEBUG
236 {
237 BN_POOL_ITEM *pool = ctx->pool.head;
238 fprintf(stderr,"BN_CTX_free, stack-size=%d, pool-bignums=%d\n",
239 ctx->stack.size, ctx->pool.size);
240 fprintf(stderr,"dmaxs: ");
241 while(pool) {
242 unsigned loop = 0;
243 while(loop < BN_CTX_POOL_SIZE)
244 fprintf(stderr,"%02x ", pool->vals[loop++].dmax);
245 pool = pool->next;
246 }
247 fprintf(stderr,"\n");
248 }
249#endif
250 BN_STACK_finish(&ctx->stack);
251 BN_POOL_finish(&ctx->pool);
252 OPENSSL_free(ctx);
253 }
254
255void BN_CTX_start(BN_CTX *ctx)
256 {
257 CTXDBG_ENTRY("BN_CTX_start", ctx);
258 /* If we're already overflowing ... */
259 if(ctx->err_stack || ctx->too_many)
260 ctx->err_stack++;
261 /* (Try to) get a new frame pointer */
262 else if(!BN_STACK_push(&ctx->stack, ctx->used))
263 {
264 BNerr(BN_F_BN_CTX_START,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
265 ctx->err_stack++;
266 }
267 CTXDBG_EXIT(ctx);
268 }
269
270void BN_CTX_end(BN_CTX *ctx)
271 {
272 CTXDBG_ENTRY("BN_CTX_end", ctx);
273 if(ctx->err_stack)
274 ctx->err_stack--;
275 else
276 {
277 unsigned int fp = BN_STACK_pop(&ctx->stack);
278 /* Does this stack frame have anything to release? */
279 if(fp < ctx->used)
280 BN_POOL_release(&ctx->pool, ctx->used - fp);
281 ctx->used = fp;
282 /* Unjam "too_many" in case "get" had failed */
283 ctx->too_many = 0;
284 }
285 CTXDBG_EXIT(ctx);
286 }
287
288BIGNUM *BN_CTX_get(BN_CTX *ctx)
289 {
290 BIGNUM *ret;
291 CTXDBG_ENTRY("BN_CTX_get", ctx);
292 if(ctx->err_stack || ctx->too_many) return NULL;
293 if((ret = BN_POOL_get(&ctx->pool)) == NULL)
294 {
295 /* Setting too_many prevents repeated "get" attempts from
296 * cluttering the error stack. */
297 ctx->too_many = 1;
298 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
299 return NULL;
300 }
301 /* OK, make sure the returned bignum is "zero" */
302 BN_zero(ret);
303 ctx->used++;
304 CTXDBG_RET(ctx, ret);
305 return ret;
306 }
307
308/************/
309/* BN_STACK */
310/************/
311
312static void BN_STACK_init(BN_STACK *st)
313 {
314 st->indexes = NULL;
315 st->depth = st->size = 0;
316 }
317
318static void BN_STACK_finish(BN_STACK *st)
319 {
320 if(st->size) OPENSSL_free(st->indexes);
321 }
322
323#ifndef OPENSSL_NO_DEPRECATED
324static void BN_STACK_reset(BN_STACK *st)
325 {
326 st->depth = 0;
327 }
328#endif
329 103
330static int BN_STACK_push(BN_STACK *st, unsigned int idx) 104 if (ctx == NULL) return;
331 { 105 assert(ctx->depth == 0);
332 if(st->depth == st->size)
333 /* Need to expand */
334 {
335 unsigned int newsize = (st->size ?
336 (st->size * 3 / 2) : BN_CTX_START_FRAMES);
337 unsigned int *newitems = OPENSSL_malloc(newsize *
338 sizeof(unsigned int));
339 if(!newitems) return 0;
340 if(st->depth)
341 memcpy(newitems, st->indexes, st->depth *
342 sizeof(unsigned int));
343 if(st->size) OPENSSL_free(st->indexes);
344 st->indexes = newitems;
345 st->size = newsize;
346 }
347 st->indexes[(st->depth)++] = idx;
348 return 1;
349 }
350 106
351static unsigned int BN_STACK_pop(BN_STACK *st) 107 for (i=0; i < BN_CTX_NUM; i++)
352 { 108 BN_clear_free(&(ctx->bn[i]));
353 return st->indexes[--(st->depth)]; 109 if (ctx->flags & BN_FLG_MALLOCED)
110 OPENSSL_free(ctx);
354 } 111 }
355 112
356/***********/ 113void BN_CTX_start(BN_CTX *ctx)
357/* BN_POOL */
358/***********/
359
360static void BN_POOL_init(BN_POOL *p)
361 { 114 {
362 p->head = p->current = p->tail = NULL; 115 if (ctx->depth < BN_CTX_NUM_POS)
363 p->used = p->size = 0; 116 ctx->pos[ctx->depth] = ctx->tos;
117 ctx->depth++;
364 } 118 }
365 119
366static void BN_POOL_finish(BN_POOL *p)
367 {
368 while(p->head)
369 {
370 unsigned int loop = 0;
371 BIGNUM *bn = p->head->vals;
372 while(loop++ < BN_CTX_POOL_SIZE)
373 {
374 if(bn->d) BN_clear_free(bn);
375 bn++;
376 }
377 p->current = p->head->next;
378 OPENSSL_free(p->head);
379 p->head = p->current;
380 }
381 }
382 120
383#ifndef OPENSSL_NO_DEPRECATED 121BIGNUM *BN_CTX_get(BN_CTX *ctx)
384static void BN_POOL_reset(BN_POOL *p)
385 { 122 {
386 BN_POOL_ITEM *item = p->head; 123 /* Note: If BN_CTX_get is ever changed to allocate BIGNUMs dynamically,
387 while(item) 124 * make sure that if BN_CTX_get fails once it will return NULL again
125 * until BN_CTX_end is called. (This is so that callers have to check
126 * only the last return value.)
127 */
128 if (ctx->depth > BN_CTX_NUM_POS || ctx->tos >= BN_CTX_NUM)
388 { 129 {
389 unsigned int loop = 0; 130 if (!ctx->too_many)
390 BIGNUM *bn = item->vals;
391 while(loop++ < BN_CTX_POOL_SIZE)
392 { 131 {
393 if(bn->d) BN_clear(bn); 132 BNerr(BN_F_BN_CTX_GET,BN_R_TOO_MANY_TEMPORARY_VARIABLES);
394 bn++; 133 /* disable error code until BN_CTX_end is called: */
134 ctx->too_many = 1;
395 } 135 }
396 item = item->next; 136 return NULL;
397 } 137 }
398 p->current = p->head; 138 return (&(ctx->bn[ctx->tos++]));
399 p->used = 0;
400 } 139 }
401#endif
402 140
403static BIGNUM *BN_POOL_get(BN_POOL *p) 141void BN_CTX_end(BN_CTX *ctx)
404 { 142 {
405 if(p->used == p->size) 143 if (ctx == NULL) return;
406 { 144 assert(ctx->depth > 0);
407 BIGNUM *bn; 145 if (ctx->depth == 0)
408 unsigned int loop = 0; 146 /* should never happen, but we can tolerate it if not in
409 BN_POOL_ITEM *item = OPENSSL_malloc(sizeof(BN_POOL_ITEM)); 147 * debug mode (could be a 'goto err' in the calling function
410 if(!item) return NULL; 148 * before BN_CTX_start was reached) */
411 /* Initialise the structure */ 149 BN_CTX_start(ctx);
412 bn = item->vals;
413 while(loop++ < BN_CTX_POOL_SIZE)
414 BN_init(bn++);
415 item->prev = p->tail;
416 item->next = NULL;
417 /* Link it in */
418 if(!p->head)
419 p->head = p->current = p->tail = item;
420 else
421 {
422 p->tail->next = item;
423 p->tail = item;
424 p->current = item;
425 }
426 p->size += BN_CTX_POOL_SIZE;
427 p->used++;
428 /* Return the first bignum from the new pool */
429 return item->vals;
430 }
431 if(!p->used)
432 p->current = p->head;
433 else if((p->used % BN_CTX_POOL_SIZE) == 0)
434 p->current = p->current->next;
435 return p->current->vals + ((p->used++) % BN_CTX_POOL_SIZE);
436 }
437 150
438static void BN_POOL_release(BN_POOL *p, unsigned int num) 151 ctx->too_many = 0;
439 { 152 ctx->depth--;
440 unsigned int offset = (p->used - 1) % BN_CTX_POOL_SIZE; 153 if (ctx->depth < BN_CTX_NUM_POS)
441 p->used -= num; 154 ctx->tos = ctx->pos[ctx->depth];
442 while(num--)
443 {
444 bn_check_top(p->current->vals + offset);
445 if(!offset)
446 {
447 offset = BN_CTX_POOL_SIZE - 1;
448 p->current = p->current->prev;
449 }
450 else
451 offset--;
452 }
453 } 155 }
454
diff --git a/src/lib/libcrypto/bn/bn_div.c b/src/lib/libcrypto/bn/bn_div.c
index 8655eb118e..580d1201bc 100644
--- a/src/lib/libcrypto/bn/bn_div.c
+++ b/src/lib/libcrypto/bn/bn_div.c
@@ -169,31 +169,22 @@ int BN_div(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m, const BIGNUM *d,
169#endif /* OPENSSL_NO_ASM */ 169#endif /* OPENSSL_NO_ASM */
170 170
171 171
172/* BN_div[_no_branch] computes dv := num / divisor, rounding towards 172/* BN_div computes dv := num / divisor, rounding towards zero, and sets up
173 * zero, and sets up rm such that dv*divisor + rm = num holds. 173 * rm such that dv*divisor + rm = num holds.
174 * Thus: 174 * Thus:
175 * dv->neg == num->neg ^ divisor->neg (unless the result is zero) 175 * dv->neg == num->neg ^ divisor->neg (unless the result is zero)
176 * rm->neg == num->neg (unless the remainder is zero) 176 * rm->neg == num->neg (unless the remainder is zero)
177 * If 'dv' or 'rm' is NULL, the respective value is not returned. 177 * If 'dv' or 'rm' is NULL, the respective value is not returned.
178 */ 178 */
179static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
180 const BIGNUM *divisor, BN_CTX *ctx);
181int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor, 179int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
182 BN_CTX *ctx) 180 BN_CTX *ctx)
183 { 181 {
184 int norm_shift,i,loop; 182 int norm_shift,i,j,loop;
185 BIGNUM *tmp,wnum,*snum,*sdiv,*res; 183 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
186 BN_ULONG *resp,*wnump; 184 BN_ULONG *resp,*wnump;
187 BN_ULONG d0,d1; 185 BN_ULONG d0,d1;
188 int num_n,div_n; 186 int num_n,div_n;
189 187
190 if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0))
191 {
192 return BN_div_no_branch(dv, rm, num, divisor, ctx);
193 }
194
195 bn_check_top(dv);
196 bn_check_top(rm);
197 bn_check_top(num); 188 bn_check_top(num);
198 bn_check_top(divisor); 189 bn_check_top(divisor);
199 190
@@ -219,6 +210,7 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
219 res=BN_CTX_get(ctx); 210 res=BN_CTX_get(ctx);
220 else res=dv; 211 else res=dv;
221 if (sdiv == NULL || res == NULL) goto err; 212 if (sdiv == NULL || res == NULL) goto err;
213 tmp->neg=0;
222 214
223 /* First we normalise the numbers */ 215 /* First we normalise the numbers */
224 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2); 216 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
@@ -230,17 +222,17 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
230 div_n=sdiv->top; 222 div_n=sdiv->top;
231 num_n=snum->top; 223 num_n=snum->top;
232 loop=num_n-div_n; 224 loop=num_n-div_n;
225
233 /* Lets setup a 'window' into snum 226 /* Lets setup a 'window' into snum
234 * This is the part that corresponds to the current 227 * This is the part that corresponds to the current
235 * 'area' being divided */ 228 * 'area' being divided */
236 wnum.neg = 0; 229 BN_init(&wnum);
237 wnum.d = &(snum->d[loop]); 230 wnum.d= &(snum->d[loop]);
238 wnum.top = div_n; 231 wnum.top= div_n;
239 /* only needed when BN_ucmp messes up the values between top and max */ 232 wnum.dmax= snum->dmax+1; /* a bit of a lie */
240 wnum.dmax = snum->dmax - loop; /* so we don't step out of bounds */
241 233
242 /* Get the top 2 words of sdiv */ 234 /* Get the top 2 words of sdiv */
243 /* div_n=sdiv->top; */ 235 /* i=sdiv->top; */
244 d0=sdiv->d[div_n-1]; 236 d0=sdiv->d[div_n-1];
245 d1=(div_n == 1)?0:sdiv->d[div_n-2]; 237 d1=(div_n == 1)?0:sdiv->d[div_n-2];
246 238
@@ -258,28 +250,19 @@ int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
258 250
259 if (BN_ucmp(&wnum,sdiv) >= 0) 251 if (BN_ucmp(&wnum,sdiv) >= 0)
260 { 252 {
261 /* If BN_DEBUG_RAND is defined BN_ucmp changes (via 253 if (!BN_usub(&wnum,&wnum,sdiv)) goto err;
262 * bn_pollute) the const bignum arguments =>
263 * clean the values between top and max again */
264 bn_clear_top2max(&wnum);
265 bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);
266 *resp=1; 254 *resp=1;
255 res->d[res->top-1]=1;
267 } 256 }
268 else 257 else
269 res->top--; 258 res->top--;
270 /* if res->top == 0 then clear the neg value otherwise decrease
271 * the resp pointer */
272 if (res->top == 0) 259 if (res->top == 0)
273 res->neg = 0; 260 res->neg = 0;
274 else 261 resp--;
275 resp--;
276 262
277 for (i=0; i<loop-1; i++, wnump--, resp--) 263 for (i=0; i<loop-1; i++)
278 { 264 {
279 BN_ULONG q,l0; 265 BN_ULONG q,l0;
280 /* the first part of the loop uses the top two words of
281 * snum and sdiv to calculate a BN_ULONG q such that
282 * | wnum - sdiv * q | < sdiv */
283#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM) 266#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
284 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG); 267 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);
285 q=bn_div_3_words(wnump,d1,d0); 268 q=bn_div_3_words(wnump,d1,d0);
@@ -363,252 +346,27 @@ X) -> 0x%08X\n",
363#endif /* !BN_DIV3W */ 346#endif /* !BN_DIV3W */
364 347
365 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); 348 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q);
349 wnum.d--; wnum.top++;
366 tmp->d[div_n]=l0; 350 tmp->d[div_n]=l0;
367 wnum.d--; 351 for (j=div_n+1; j>0; j--)
368 /* ingore top values of the bignums just sub the two 352 if (tmp->d[j-1]) break;
369 * BN_ULONG arrays with bn_sub_words */ 353 tmp->top=j;
370 if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))
371 {
372 /* Note: As we have considered only the leading
373 * two BN_ULONGs in the calculation of q, sdiv * q
374 * might be greater than wnum (but then (q-1) * sdiv
375 * is less or equal than wnum)
376 */
377 q--;
378 if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))
379 /* we can't have an overflow here (assuming
380 * that q != 0, but if q == 0 then tmp is
381 * zero anyway) */
382 (*wnump)++;
383 }
384 /* store part of the result */
385 *resp = q;
386 }
387 bn_correct_top(snum);
388 if (rm != NULL)
389 {
390 /* Keep a copy of the neg flag in num because if rm==num
391 * BN_rshift() will overwrite it.
392 */
393 int neg = num->neg;
394 BN_rshift(rm,snum,norm_shift);
395 if (!BN_is_zero(rm))
396 rm->neg = neg;
397 bn_check_top(rm);
398 }
399 BN_CTX_end(ctx);
400 return(1);
401err:
402 bn_check_top(rm);
403 BN_CTX_end(ctx);
404 return(0);
405 }
406
407
408/* BN_div_no_branch is a special version of BN_div. It does not contain
409 * branches that may leak sensitive information.
410 */
411static int BN_div_no_branch(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num,
412 const BIGNUM *divisor, BN_CTX *ctx)
413 {
414 int norm_shift,i,loop;
415 BIGNUM *tmp,wnum,*snum,*sdiv,*res;
416 BN_ULONG *resp,*wnump;
417 BN_ULONG d0,d1;
418 int num_n,div_n;
419
420 bn_check_top(dv);
421 bn_check_top(rm);
422 bn_check_top(num);
423 bn_check_top(divisor);
424
425 if (BN_is_zero(divisor))
426 {
427 BNerr(BN_F_BN_DIV_NO_BRANCH,BN_R_DIV_BY_ZERO);
428 return(0);
429 }
430
431 BN_CTX_start(ctx);
432 tmp=BN_CTX_get(ctx);
433 snum=BN_CTX_get(ctx);
434 sdiv=BN_CTX_get(ctx);
435 if (dv == NULL)
436 res=BN_CTX_get(ctx);
437 else res=dv;
438 if (sdiv == NULL || res == NULL) goto err;
439
440 /* First we normalise the numbers */
441 norm_shift=BN_BITS2-((BN_num_bits(divisor))%BN_BITS2);
442 if (!(BN_lshift(sdiv,divisor,norm_shift))) goto err;
443 sdiv->neg=0;
444 norm_shift+=BN_BITS2;
445 if (!(BN_lshift(snum,num,norm_shift))) goto err;
446 snum->neg=0;
447
448 /* Since we don't know whether snum is larger than sdiv,
449 * we pad snum with enough zeroes without changing its
450 * value.
451 */
452 if (snum->top <= sdiv->top+1)
453 {
454 if (bn_wexpand(snum, sdiv->top + 2) == NULL) goto err;
455 for (i = snum->top; i < sdiv->top + 2; i++) snum->d[i] = 0;
456 snum->top = sdiv->top + 2;
457 }
458 else
459 {
460 if (bn_wexpand(snum, snum->top + 1) == NULL) goto err;
461 snum->d[snum->top] = 0;
462 snum->top ++;
463 }
464
465 div_n=sdiv->top;
466 num_n=snum->top;
467 loop=num_n-div_n;
468 /* Lets setup a 'window' into snum
469 * This is the part that corresponds to the current
470 * 'area' being divided */
471 wnum.neg = 0;
472 wnum.d = &(snum->d[loop]);
473 wnum.top = div_n;
474 /* only needed when BN_ucmp messes up the values between top and max */
475 wnum.dmax = snum->dmax - loop; /* so we don't step out of bounds */
476
477 /* Get the top 2 words of sdiv */
478 /* div_n=sdiv->top; */
479 d0=sdiv->d[div_n-1];
480 d1=(div_n == 1)?0:sdiv->d[div_n-2];
481
482 /* pointer to the 'top' of snum */
483 wnump= &(snum->d[num_n-1]);
484
485 /* Setup to 'res' */
486 res->neg= (num->neg^divisor->neg);
487 if (!bn_wexpand(res,(loop+1))) goto err;
488 res->top=loop-1;
489 resp= &(res->d[loop-1]);
490
491 /* space for temp */
492 if (!bn_wexpand(tmp,(div_n+1))) goto err;
493
494 /* if res->top == 0 then clear the neg value otherwise decrease
495 * the resp pointer */
496 if (res->top == 0)
497 res->neg = 0;
498 else
499 resp--;
500
501 for (i=0; i<loop-1; i++, wnump--, resp--)
502 {
503 BN_ULONG q,l0;
504 /* the first part of the loop uses the top two words of
505 * snum and sdiv to calculate a BN_ULONG q such that
506 * | wnum - sdiv * q | < sdiv */
507#if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)
508 BN_ULONG bn_div_3_words(BN_ULONG*,BN_ULONG,BN_ULONG);
509 q=bn_div_3_words(wnump,d1,d0);
510#else
511 BN_ULONG n0,n1,rem=0;
512
513 n0=wnump[0];
514 n1=wnump[-1];
515 if (n0 == d0)
516 q=BN_MASK2;
517 else /* n0 < d0 */
518 {
519#ifdef BN_LLONG
520 BN_ULLONG t2;
521
522#if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)
523 q=(BN_ULONG)(((((BN_ULLONG)n0)<<BN_BITS2)|n1)/d0);
524#else
525 q=bn_div_words(n0,n1,d0);
526#ifdef BN_DEBUG_LEVITTE
527 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
528X) -> 0x%08X\n",
529 n0, n1, d0, q);
530#endif
531#endif
532
533#ifndef REMAINDER_IS_ALREADY_CALCULATED
534 /*
535 * rem doesn't have to be BN_ULLONG. The least we
536 * know it's less that d0, isn't it?
537 */
538 rem=(n1-q*d0)&BN_MASK2;
539#endif
540 t2=(BN_ULLONG)d1*q;
541
542 for (;;)
543 {
544 if (t2 <= ((((BN_ULLONG)rem)<<BN_BITS2)|wnump[-2]))
545 break;
546 q--;
547 rem += d0;
548 if (rem < d0) break; /* don't let rem overflow */
549 t2 -= d1;
550 }
551#else /* !BN_LLONG */
552 BN_ULONG t2l,t2h,ql,qh;
553
554 q=bn_div_words(n0,n1,d0);
555#ifdef BN_DEBUG_LEVITTE
556 fprintf(stderr,"DEBUG: bn_div_words(0x%08X,0x%08X,0x%08\
557X) -> 0x%08X\n",
558 n0, n1, d0, q);
559#endif
560#ifndef REMAINDER_IS_ALREADY_CALCULATED
561 rem=(n1-q*d0)&BN_MASK2;
562#endif
563 354
564#if defined(BN_UMULT_LOHI) 355 j=wnum.top;
565 BN_UMULT_LOHI(t2l,t2h,d1,q); 356 if (!BN_sub(&wnum,&wnum,tmp)) goto err;
566#elif defined(BN_UMULT_HIGH)
567 t2l = d1 * q;
568 t2h = BN_UMULT_HIGH(d1,q);
569#else
570 t2l=LBITS(d1); t2h=HBITS(d1);
571 ql =LBITS(q); qh =HBITS(q);
572 mul64(t2l,t2h,ql,qh); /* t2=(BN_ULLONG)d1*q; */
573#endif
574 357
575 for (;;) 358 snum->top=snum->top+wnum.top-j;
576 {
577 if ((t2h < rem) ||
578 ((t2h == rem) && (t2l <= wnump[-2])))
579 break;
580 q--;
581 rem += d0;
582 if (rem < d0) break; /* don't let rem overflow */
583 if (t2l < d1) t2h--; t2l -= d1;
584 }
585#endif /* !BN_LLONG */
586 }
587#endif /* !BN_DIV3W */
588 359
589 l0=bn_mul_words(tmp->d,sdiv->d,div_n,q); 360 if (wnum.neg)
590 tmp->d[div_n]=l0;
591 wnum.d--;
592 /* ingore top values of the bignums just sub the two
593 * BN_ULONG arrays with bn_sub_words */
594 if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n+1))
595 { 361 {
596 /* Note: As we have considered only the leading
597 * two BN_ULONGs in the calculation of q, sdiv * q
598 * might be greater than wnum (but then (q-1) * sdiv
599 * is less or equal than wnum)
600 */
601 q--; 362 q--;
602 if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n)) 363 j=wnum.top;
603 /* we can't have an overflow here (assuming 364 if (!BN_add(&wnum,&wnum,sdiv)) goto err;
604 * that q != 0, but if q == 0 then tmp is 365 snum->top+=wnum.top-j;
605 * zero anyway) */
606 (*wnump)++;
607 } 366 }
608 /* store part of the result */ 367 *(resp--)=q;
609 *resp = q; 368 wnump--;
610 } 369 }
611 bn_correct_top(snum);
612 if (rm != NULL) 370 if (rm != NULL)
613 { 371 {
614 /* Keep a copy of the neg flag in num because if rm==num 372 /* Keep a copy of the neg flag in num because if rm==num
@@ -618,13 +376,10 @@ X) -> 0x%08X\n",
618 BN_rshift(rm,snum,norm_shift); 376 BN_rshift(rm,snum,norm_shift);
619 if (!BN_is_zero(rm)) 377 if (!BN_is_zero(rm))
620 rm->neg = neg; 378 rm->neg = neg;
621 bn_check_top(rm);
622 } 379 }
623 bn_correct_top(res);
624 BN_CTX_end(ctx); 380 BN_CTX_end(ctx);
625 return(1); 381 return(1);
626err: 382err:
627 bn_check_top(rm);
628 BN_CTX_end(ctx); 383 BN_CTX_end(ctx);
629 return(0); 384 return(0);
630 } 385 }
diff --git a/src/lib/libcrypto/bn/bn_err.c b/src/lib/libcrypto/bn/bn_err.c
index cfe2eb94a0..5dfac00c88 100644
--- a/src/lib/libcrypto/bn/bn_err.c
+++ b/src/lib/libcrypto/bn/bn_err.c
@@ -1,6 +1,6 @@
1/* crypto/bn/bn_err.c */ 1/* crypto/bn/bn_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -70,30 +70,18 @@
70 70
71static ERR_STRING_DATA BN_str_functs[]= 71static ERR_STRING_DATA BN_str_functs[]=
72 { 72 {
73{ERR_FUNC(BN_F_BNRAND), "BNRAND"}, 73{ERR_FUNC(BN_F_BN_BLINDING_CONVERT), "BN_BLINDING_convert"},
74{ERR_FUNC(BN_F_BN_BLINDING_CONVERT_EX), "BN_BLINDING_convert_ex"}, 74{ERR_FUNC(BN_F_BN_BLINDING_INVERT), "BN_BLINDING_invert"},
75{ERR_FUNC(BN_F_BN_BLINDING_CREATE_PARAM), "BN_BLINDING_create_param"},
76{ERR_FUNC(BN_F_BN_BLINDING_INVERT_EX), "BN_BLINDING_invert_ex"},
77{ERR_FUNC(BN_F_BN_BLINDING_NEW), "BN_BLINDING_new"}, 75{ERR_FUNC(BN_F_BN_BLINDING_NEW), "BN_BLINDING_new"},
78{ERR_FUNC(BN_F_BN_BLINDING_UPDATE), "BN_BLINDING_update"}, 76{ERR_FUNC(BN_F_BN_BLINDING_UPDATE), "BN_BLINDING_update"},
79{ERR_FUNC(BN_F_BN_BN2DEC), "BN_bn2dec"}, 77{ERR_FUNC(BN_F_BN_BN2DEC), "BN_bn2dec"},
80{ERR_FUNC(BN_F_BN_BN2HEX), "BN_bn2hex"}, 78{ERR_FUNC(BN_F_BN_BN2HEX), "BN_bn2hex"},
81{ERR_FUNC(BN_F_BN_CTX_GET), "BN_CTX_get"}, 79{ERR_FUNC(BN_F_BN_CTX_GET), "BN_CTX_get"},
82{ERR_FUNC(BN_F_BN_CTX_NEW), "BN_CTX_new"}, 80{ERR_FUNC(BN_F_BN_CTX_NEW), "BN_CTX_new"},
83{ERR_FUNC(BN_F_BN_CTX_START), "BN_CTX_start"},
84{ERR_FUNC(BN_F_BN_DIV), "BN_div"}, 81{ERR_FUNC(BN_F_BN_DIV), "BN_div"},
85{ERR_FUNC(BN_F_BN_DIV_NO_BRANCH), "BN_div_no_branch"},
86{ERR_FUNC(BN_F_BN_DIV_RECP), "BN_div_recp"},
87{ERR_FUNC(BN_F_BN_EXP), "BN_exp"}, 82{ERR_FUNC(BN_F_BN_EXP), "BN_exp"},
88{ERR_FUNC(BN_F_BN_EXPAND2), "bn_expand2"}, 83{ERR_FUNC(BN_F_BN_EXPAND2), "bn_expand2"},
89{ERR_FUNC(BN_F_BN_EXPAND_INTERNAL), "BN_EXPAND_INTERNAL"}, 84{ERR_FUNC(BN_F_BN_EXPAND_INTERNAL), "BN_EXPAND_INTERNAL"},
90{ERR_FUNC(BN_F_BN_GF2M_MOD), "BN_GF2m_mod"},
91{ERR_FUNC(BN_F_BN_GF2M_MOD_EXP), "BN_GF2m_mod_exp"},
92{ERR_FUNC(BN_F_BN_GF2M_MOD_MUL), "BN_GF2m_mod_mul"},
93{ERR_FUNC(BN_F_BN_GF2M_MOD_SOLVE_QUAD), "BN_GF2m_mod_solve_quad"},
94{ERR_FUNC(BN_F_BN_GF2M_MOD_SOLVE_QUAD_ARR), "BN_GF2m_mod_solve_quad_arr"},
95{ERR_FUNC(BN_F_BN_GF2M_MOD_SQR), "BN_GF2m_mod_sqr"},
96{ERR_FUNC(BN_F_BN_GF2M_MOD_SQRT), "BN_GF2m_mod_sqrt"},
97{ERR_FUNC(BN_F_BN_MOD_EXP2_MONT), "BN_mod_exp2_mont"}, 85{ERR_FUNC(BN_F_BN_MOD_EXP2_MONT), "BN_mod_exp2_mont"},
98{ERR_FUNC(BN_F_BN_MOD_EXP_MONT), "BN_mod_exp_mont"}, 86{ERR_FUNC(BN_F_BN_MOD_EXP_MONT), "BN_mod_exp_mont"},
99{ERR_FUNC(BN_F_BN_MOD_EXP_MONT_CONSTTIME), "BN_mod_exp_mont_consttime"}, 87{ERR_FUNC(BN_F_BN_MOD_EXP_MONT_CONSTTIME), "BN_mod_exp_mont_consttime"},
@@ -101,7 +89,6 @@ static ERR_STRING_DATA BN_str_functs[]=
101{ERR_FUNC(BN_F_BN_MOD_EXP_RECP), "BN_mod_exp_recp"}, 89{ERR_FUNC(BN_F_BN_MOD_EXP_RECP), "BN_mod_exp_recp"},
102{ERR_FUNC(BN_F_BN_MOD_EXP_SIMPLE), "BN_mod_exp_simple"}, 90{ERR_FUNC(BN_F_BN_MOD_EXP_SIMPLE), "BN_mod_exp_simple"},
103{ERR_FUNC(BN_F_BN_MOD_INVERSE), "BN_mod_inverse"}, 91{ERR_FUNC(BN_F_BN_MOD_INVERSE), "BN_mod_inverse"},
104{ERR_FUNC(BN_F_BN_MOD_INVERSE_NO_BRANCH), "BN_mod_inverse_no_branch"},
105{ERR_FUNC(BN_F_BN_MOD_LSHIFT_QUICK), "BN_mod_lshift_quick"}, 92{ERR_FUNC(BN_F_BN_MOD_LSHIFT_QUICK), "BN_mod_lshift_quick"},
106{ERR_FUNC(BN_F_BN_MOD_MUL_RECIPROCAL), "BN_mod_mul_reciprocal"}, 93{ERR_FUNC(BN_F_BN_MOD_MUL_RECIPROCAL), "BN_mod_mul_reciprocal"},
107{ERR_FUNC(BN_F_BN_MOD_SQRT), "BN_mod_sqrt"}, 94{ERR_FUNC(BN_F_BN_MOD_SQRT), "BN_mod_sqrt"},
@@ -128,7 +115,6 @@ static ERR_STRING_DATA BN_str_reasons[]=
128{ERR_REASON(BN_R_NOT_A_SQUARE) ,"not a square"}, 115{ERR_REASON(BN_R_NOT_A_SQUARE) ,"not a square"},
129{ERR_REASON(BN_R_NOT_INITIALIZED) ,"not initialized"}, 116{ERR_REASON(BN_R_NOT_INITIALIZED) ,"not initialized"},
130{ERR_REASON(BN_R_NO_INVERSE) ,"no inverse"}, 117{ERR_REASON(BN_R_NO_INVERSE) ,"no inverse"},
131{ERR_REASON(BN_R_NO_SOLUTION) ,"no solution"},
132{ERR_REASON(BN_R_P_IS_NOT_PRIME) ,"p is not prime"}, 118{ERR_REASON(BN_R_P_IS_NOT_PRIME) ,"p is not prime"},
133{ERR_REASON(BN_R_TOO_MANY_ITERATIONS) ,"too many iterations"}, 119{ERR_REASON(BN_R_TOO_MANY_ITERATIONS) ,"too many iterations"},
134{ERR_REASON(BN_R_TOO_MANY_TEMPORARY_VARIABLES),"too many temporary variables"}, 120{ERR_REASON(BN_R_TOO_MANY_TEMPORARY_VARIABLES),"too many temporary variables"},
@@ -139,12 +125,15 @@ static ERR_STRING_DATA BN_str_reasons[]=
139 125
140void ERR_load_BN_strings(void) 126void ERR_load_BN_strings(void)
141 { 127 {
142#ifndef OPENSSL_NO_ERR 128 static int init=1;
143 129
144 if (ERR_func_error_string(BN_str_functs[0].error) == NULL) 130 if (init)
145 { 131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
146 ERR_load_strings(0,BN_str_functs); 134 ERR_load_strings(0,BN_str_functs);
147 ERR_load_strings(0,BN_str_reasons); 135 ERR_load_strings(0,BN_str_reasons);
148 }
149#endif 136#endif
137
138 }
150 } 139 }
diff --git a/src/lib/libcrypto/bn/bn_exp.c b/src/lib/libcrypto/bn/bn_exp.c
index 70a33f0d93..9e1e88abe8 100644
--- a/src/lib/libcrypto/bn/bn_exp.c
+++ b/src/lib/libcrypto/bn/bn_exp.c
@@ -122,9 +122,9 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
122 int i,bits,ret=0; 122 int i,bits,ret=0;
123 BIGNUM *v,*rr; 123 BIGNUM *v,*rr;
124 124
125 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) 125 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
126 { 126 {
127 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 127 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
128 BNerr(BN_F_BN_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 128 BNerr(BN_F_BN_EXP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
129 return -1; 129 return -1;
130 } 130 }
@@ -155,7 +155,6 @@ int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
155err: 155err:
156 if (r != rr) BN_copy(r,rr); 156 if (r != rr) BN_copy(r,rr);
157 BN_CTX_end(ctx); 157 BN_CTX_end(ctx);
158 bn_check_top(r);
159 return(ret); 158 return(ret);
160 } 159 }
161 160
@@ -213,7 +212,7 @@ int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
213 if (BN_is_odd(m)) 212 if (BN_is_odd(m))
214 { 213 {
215# ifdef MONT_EXP_WORD 214# ifdef MONT_EXP_WORD
216 if (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_CONSTTIME) == 0)) 215 if (a->top == 1 && !a->neg && (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) == 0))
217 { 216 {
218 BN_ULONG A = a->d[0]; 217 BN_ULONG A = a->d[0];
219 ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL); 218 ret=BN_mod_exp_mont_word(r,A,p,m,ctx,NULL);
@@ -230,7 +229,6 @@ int BN_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
230 { ret=BN_mod_exp_simple(r,a,p,m,ctx); } 229 { ret=BN_mod_exp_simple(r,a,p,m,ctx); }
231#endif 230#endif
232 231
233 bn_check_top(r);
234 return(ret); 232 return(ret);
235 } 233 }
236 234
@@ -239,15 +237,14 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
239 const BIGNUM *m, BN_CTX *ctx) 237 const BIGNUM *m, BN_CTX *ctx)
240 { 238 {
241 int i,j,bits,ret=0,wstart,wend,window,wvalue; 239 int i,j,bits,ret=0,wstart,wend,window,wvalue;
242 int start=1; 240 int start=1,ts=0;
243 BIGNUM *aa; 241 BIGNUM *aa;
244 /* Table of variables obtained from 'ctx' */ 242 BIGNUM val[TABLE_SIZE];
245 BIGNUM *val[TABLE_SIZE];
246 BN_RECP_CTX recp; 243 BN_RECP_CTX recp;
247 244
248 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) 245 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
249 { 246 {
250 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 247 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
251 BNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 248 BNerr(BN_F_BN_MOD_EXP_RECP,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
252 return -1; 249 return -1;
253 } 250 }
@@ -261,9 +258,7 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
261 } 258 }
262 259
263 BN_CTX_start(ctx); 260 BN_CTX_start(ctx);
264 aa = BN_CTX_get(ctx); 261 if ((aa = BN_CTX_get(ctx)) == NULL) goto err;
265 val[0] = BN_CTX_get(ctx);
266 if(!aa || !val[0]) goto err;
267 262
268 BN_RECP_CTX_init(&recp); 263 BN_RECP_CTX_init(&recp);
269 if (m->neg) 264 if (m->neg)
@@ -278,27 +273,29 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
278 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err; 273 if (BN_RECP_CTX_set(&recp,m,ctx) <= 0) goto err;
279 } 274 }
280 275
281 if (!BN_nnmod(val[0],a,m,ctx)) goto err; /* 1 */ 276 BN_init(&(val[0]));
282 if (BN_is_zero(val[0])) 277 ts=1;
278
279 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
280 if (BN_is_zero(&(val[0])))
283 { 281 {
284 BN_zero(r); 282 ret = BN_zero(r);
285 ret = 1;
286 goto err; 283 goto err;
287 } 284 }
288 285
289 window = BN_window_bits_for_exponent_size(bits); 286 window = BN_window_bits_for_exponent_size(bits);
290 if (window > 1) 287 if (window > 1)
291 { 288 {
292 if (!BN_mod_mul_reciprocal(aa,val[0],val[0],&recp,ctx)) 289 if (!BN_mod_mul_reciprocal(aa,&(val[0]),&(val[0]),&recp,ctx))
293 goto err; /* 2 */ 290 goto err; /* 2 */
294 j=1<<(window-1); 291 j=1<<(window-1);
295 for (i=1; i<j; i++) 292 for (i=1; i<j; i++)
296 { 293 {
297 if(((val[i] = BN_CTX_get(ctx)) == NULL) || 294 BN_init(&val[i]);
298 !BN_mod_mul_reciprocal(val[i],val[i-1], 295 if (!BN_mod_mul_reciprocal(&(val[i]),&(val[i-1]),aa,&recp,ctx))
299 aa,&recp,ctx))
300 goto err; 296 goto err;
301 } 297 }
298 ts=i;
302 } 299 }
303 300
304 start=1; /* This is used to avoid multiplication etc 301 start=1; /* This is used to avoid multiplication etc
@@ -350,7 +347,7 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
350 } 347 }
351 348
352 /* wvalue will be an odd number < 2^window */ 349 /* wvalue will be an odd number < 2^window */
353 if (!BN_mod_mul_reciprocal(r,r,val[wvalue>>1],&recp,ctx)) 350 if (!BN_mod_mul_reciprocal(r,r,&(val[wvalue>>1]),&recp,ctx))
354 goto err; 351 goto err;
355 352
356 /* move the 'window' down further */ 353 /* move the 'window' down further */
@@ -362,8 +359,9 @@ int BN_mod_exp_recp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
362 ret=1; 359 ret=1;
363err: 360err:
364 BN_CTX_end(ctx); 361 BN_CTX_end(ctx);
362 for (i=0; i<ts; i++)
363 BN_clear_free(&(val[i]));
365 BN_RECP_CTX_free(&recp); 364 BN_RECP_CTX_free(&recp);
366 bn_check_top(r);
367 return(ret); 365 return(ret);
368 } 366 }
369 367
@@ -372,14 +370,13 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
372 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont) 370 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
373 { 371 {
374 int i,j,bits,ret=0,wstart,wend,window,wvalue; 372 int i,j,bits,ret=0,wstart,wend,window,wvalue;
375 int start=1; 373 int start=1,ts=0;
376 BIGNUM *d,*r; 374 BIGNUM *d,*r;
377 const BIGNUM *aa; 375 const BIGNUM *aa;
378 /* Table of variables obtained from 'ctx' */ 376 BIGNUM val[TABLE_SIZE];
379 BIGNUM *val[TABLE_SIZE];
380 BN_MONT_CTX *mont=NULL; 377 BN_MONT_CTX *mont=NULL;
381 378
382 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) 379 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
383 { 380 {
384 return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont); 381 return BN_mod_exp_mont_consttime(rr, a, p, m, ctx, in_mont);
385 } 382 }
@@ -388,7 +385,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
388 bn_check_top(p); 385 bn_check_top(p);
389 bn_check_top(m); 386 bn_check_top(m);
390 387
391 if (!BN_is_odd(m)) 388 if (!(m->d[0] & 1))
392 { 389 {
393 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS); 390 BNerr(BN_F_BN_MOD_EXP_MONT,BN_R_CALLED_WITH_EVEN_MODULUS);
394 return(0); 391 return(0);
@@ -403,8 +400,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
403 BN_CTX_start(ctx); 400 BN_CTX_start(ctx);
404 d = BN_CTX_get(ctx); 401 d = BN_CTX_get(ctx);
405 r = BN_CTX_get(ctx); 402 r = BN_CTX_get(ctx);
406 val[0] = BN_CTX_get(ctx); 403 if (d == NULL || r == NULL) goto err;
407 if (!d || !r || !val[0]) goto err;
408 404
409 /* If this is not done, things will break in the montgomery 405 /* If this is not done, things will break in the montgomery
410 * part */ 406 * part */
@@ -417,34 +413,35 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
417 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err; 413 if (!BN_MONT_CTX_set(mont,m,ctx)) goto err;
418 } 414 }
419 415
416 BN_init(&val[0]);
417 ts=1;
420 if (a->neg || BN_ucmp(a,m) >= 0) 418 if (a->neg || BN_ucmp(a,m) >= 0)
421 { 419 {
422 if (!BN_nnmod(val[0],a,m,ctx)) 420 if (!BN_nnmod(&(val[0]),a,m,ctx))
423 goto err; 421 goto err;
424 aa= val[0]; 422 aa= &(val[0]);
425 } 423 }
426 else 424 else
427 aa=a; 425 aa=a;
428 if (BN_is_zero(aa)) 426 if (BN_is_zero(aa))
429 { 427 {
430 BN_zero(rr); 428 ret = BN_zero(rr);
431 ret = 1;
432 goto err; 429 goto err;
433 } 430 }
434 if (!BN_to_montgomery(val[0],aa,mont,ctx)) goto err; /* 1 */ 431 if (!BN_to_montgomery(&(val[0]),aa,mont,ctx)) goto err; /* 1 */
435 432
436 window = BN_window_bits_for_exponent_size(bits); 433 window = BN_window_bits_for_exponent_size(bits);
437 if (window > 1) 434 if (window > 1)
438 { 435 {
439 if (!BN_mod_mul_montgomery(d,val[0],val[0],mont,ctx)) goto err; /* 2 */ 436 if (!BN_mod_mul_montgomery(d,&(val[0]),&(val[0]),mont,ctx)) goto err; /* 2 */
440 j=1<<(window-1); 437 j=1<<(window-1);
441 for (i=1; i<j; i++) 438 for (i=1; i<j; i++)
442 { 439 {
443 if(((val[i] = BN_CTX_get(ctx)) == NULL) || 440 BN_init(&(val[i]));
444 !BN_mod_mul_montgomery(val[i],val[i-1], 441 if (!BN_mod_mul_montgomery(&(val[i]),&(val[i-1]),d,mont,ctx))
445 d,mont,ctx))
446 goto err; 442 goto err;
447 } 443 }
444 ts=i;
448 } 445 }
449 446
450 start=1; /* This is used to avoid multiplication etc 447 start=1; /* This is used to avoid multiplication etc
@@ -497,7 +494,7 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
497 } 494 }
498 495
499 /* wvalue will be an odd number < 2^window */ 496 /* wvalue will be an odd number < 2^window */
500 if (!BN_mod_mul_montgomery(r,r,val[wvalue>>1],mont,ctx)) 497 if (!BN_mod_mul_montgomery(r,r,&(val[wvalue>>1]),mont,ctx))
501 goto err; 498 goto err;
502 499
503 /* move the 'window' down further */ 500 /* move the 'window' down further */
@@ -511,7 +508,8 @@ int BN_mod_exp_mont(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p,
511err: 508err:
512 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 509 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
513 BN_CTX_end(ctx); 510 BN_CTX_end(ctx);
514 bn_check_top(rr); 511 for (i=0; i<ts; i++)
512 BN_clear_free(&(val[i]));
515 return(ret); 513 return(ret);
516 } 514 }
517 515
@@ -537,7 +535,7 @@ static int MOD_EXP_CTIME_COPY_TO_PREBUF(BIGNUM *b, int top, unsigned char *buf,
537 buf[j] = ((unsigned char*)b->d)[i]; 535 buf[j] = ((unsigned char*)b->d)[i];
538 } 536 }
539 537
540 bn_correct_top(b); 538 bn_fix_top(b);
541 return 1; 539 return 1;
542 } 540 }
543 541
@@ -554,7 +552,7 @@ static int MOD_EXP_CTIME_COPY_FROM_PREBUF(BIGNUM *b, int top, unsigned char *buf
554 } 552 }
555 553
556 b->top = top; 554 b->top = top;
557 bn_correct_top(b); 555 bn_fix_top(b);
558 return 1; 556 return 1;
559 } 557 }
560 558
@@ -745,9 +743,9 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
745#define BN_TO_MONTGOMERY_WORD(r, w, mont) \ 743#define BN_TO_MONTGOMERY_WORD(r, w, mont) \
746 (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx)) 744 (BN_set_word(r, (w)) && BN_to_montgomery(r, r, (mont), ctx))
747 745
748 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) 746 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
749 { 747 {
750 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 748 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
751 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 749 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
752 return -1; 750 return -1;
753 } 751 }
@@ -755,7 +753,7 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
755 bn_check_top(p); 753 bn_check_top(p);
756 bn_check_top(m); 754 bn_check_top(m);
757 755
758 if (!BN_is_odd(m)) 756 if (m->top == 0 || !(m->d[0] & 1))
759 { 757 {
760 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS); 758 BNerr(BN_F_BN_MOD_EXP_MONT_WORD,BN_R_CALLED_WITH_EVEN_MODULUS);
761 return(0); 759 return(0);
@@ -771,8 +769,7 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
771 } 769 }
772 if (a == 0) 770 if (a == 0)
773 { 771 {
774 BN_zero(rr); 772 ret = BN_zero(rr);
775 ret = 1;
776 return ret; 773 return ret;
777 } 774 }
778 775
@@ -866,24 +863,23 @@ int BN_mod_exp_mont_word(BIGNUM *rr, BN_ULONG a, const BIGNUM *p,
866err: 863err:
867 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 864 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
868 BN_CTX_end(ctx); 865 BN_CTX_end(ctx);
869 bn_check_top(rr);
870 return(ret); 866 return(ret);
871 } 867 }
872 868
873 869
874/* The old fallback, simple version :-) */ 870/* The old fallback, simple version :-) */
875int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 871int BN_mod_exp_simple(BIGNUM *r,
876 const BIGNUM *m, BN_CTX *ctx) 872 const BIGNUM *a, const BIGNUM *p, const BIGNUM *m,
873 BN_CTX *ctx)
877 { 874 {
878 int i,j,bits,ret=0,wstart,wend,window,wvalue; 875 int i,j,bits,ret=0,wstart,wend,window,wvalue,ts=0;
879 int start=1; 876 int start=1;
880 BIGNUM *d; 877 BIGNUM *d;
881 /* Table of variables obtained from 'ctx' */ 878 BIGNUM val[TABLE_SIZE];
882 BIGNUM *val[TABLE_SIZE];
883 879
884 if (BN_get_flags(p, BN_FLG_CONSTTIME) != 0) 880 if (BN_get_flags(p, BN_FLG_EXP_CONSTTIME) != 0)
885 { 881 {
886 /* BN_FLG_CONSTTIME only supported by BN_mod_exp_mont() */ 882 /* BN_FLG_EXP_CONSTTIME only supported by BN_mod_exp_mont() */
887 BNerr(BN_F_BN_MOD_EXP_SIMPLE,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 883 BNerr(BN_F_BN_MOD_EXP_SIMPLE,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
888 return -1; 884 return -1;
889 } 885 }
@@ -897,30 +893,30 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
897 } 893 }
898 894
899 BN_CTX_start(ctx); 895 BN_CTX_start(ctx);
900 d = BN_CTX_get(ctx); 896 if ((d = BN_CTX_get(ctx)) == NULL) goto err;
901 val[0] = BN_CTX_get(ctx);
902 if(!d || !val[0]) goto err;
903 897
904 if (!BN_nnmod(val[0],a,m,ctx)) goto err; /* 1 */ 898 BN_init(&(val[0]));
905 if (BN_is_zero(val[0])) 899 ts=1;
900 if (!BN_nnmod(&(val[0]),a,m,ctx)) goto err; /* 1 */
901 if (BN_is_zero(&(val[0])))
906 { 902 {
907 BN_zero(r); 903 ret = BN_zero(r);
908 ret = 1;
909 goto err; 904 goto err;
910 } 905 }
911 906
912 window = BN_window_bits_for_exponent_size(bits); 907 window = BN_window_bits_for_exponent_size(bits);
913 if (window > 1) 908 if (window > 1)
914 { 909 {
915 if (!BN_mod_mul(d,val[0],val[0],m,ctx)) 910 if (!BN_mod_mul(d,&(val[0]),&(val[0]),m,ctx))
916 goto err; /* 2 */ 911 goto err; /* 2 */
917 j=1<<(window-1); 912 j=1<<(window-1);
918 for (i=1; i<j; i++) 913 for (i=1; i<j; i++)
919 { 914 {
920 if(((val[i] = BN_CTX_get(ctx)) == NULL) || 915 BN_init(&(val[i]));
921 !BN_mod_mul(val[i],val[i-1],d,m,ctx)) 916 if (!BN_mod_mul(&(val[i]),&(val[i-1]),d,m,ctx))
922 goto err; 917 goto err;
923 } 918 }
919 ts=i;
924 } 920 }
925 921
926 start=1; /* This is used to avoid multiplication etc 922 start=1; /* This is used to avoid multiplication etc
@@ -972,7 +968,7 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
972 } 968 }
973 969
974 /* wvalue will be an odd number < 2^window */ 970 /* wvalue will be an odd number < 2^window */
975 if (!BN_mod_mul(r,r,val[wvalue>>1],m,ctx)) 971 if (!BN_mod_mul(r,r,&(val[wvalue>>1]),m,ctx))
976 goto err; 972 goto err;
977 973
978 /* move the 'window' down further */ 974 /* move the 'window' down further */
@@ -984,7 +980,8 @@ int BN_mod_exp_simple(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
984 ret=1; 980 ret=1;
985err: 981err:
986 BN_CTX_end(ctx); 982 BN_CTX_end(ctx);
987 bn_check_top(r); 983 for (i=0; i<ts; i++)
984 BN_clear_free(&(val[i]));
988 return(ret); 985 return(ret);
989 } 986 }
990 987
diff --git a/src/lib/libcrypto/bn/bn_exp2.c b/src/lib/libcrypto/bn/bn_exp2.c
index b3f43cec8c..73ccd58a83 100644
--- a/src/lib/libcrypto/bn/bn_exp2.c
+++ b/src/lib/libcrypto/bn/bn_exp2.c
@@ -120,11 +120,10 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
120 BN_CTX *ctx, BN_MONT_CTX *in_mont) 120 BN_CTX *ctx, BN_MONT_CTX *in_mont)
121 { 121 {
122 int i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2; 122 int i,j,bits,b,bits1,bits2,ret=0,wpos1,wpos2,window1,window2,wvalue1,wvalue2;
123 int r_is_one=1; 123 int r_is_one=1,ts1=0,ts2=0;
124 BIGNUM *d,*r; 124 BIGNUM *d,*r;
125 const BIGNUM *a_mod_m; 125 const BIGNUM *a_mod_m;
126 /* Tables of variables obtained from 'ctx' */ 126 BIGNUM val1[TABLE_SIZE], val2[TABLE_SIZE];
127 BIGNUM *val1[TABLE_SIZE], *val2[TABLE_SIZE];
128 BN_MONT_CTX *mont=NULL; 127 BN_MONT_CTX *mont=NULL;
129 128
130 bn_check_top(a1); 129 bn_check_top(a1);
@@ -151,9 +150,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
151 BN_CTX_start(ctx); 150 BN_CTX_start(ctx);
152 d = BN_CTX_get(ctx); 151 d = BN_CTX_get(ctx);
153 r = BN_CTX_get(ctx); 152 r = BN_CTX_get(ctx);
154 val1[0] = BN_CTX_get(ctx); 153 if (d == NULL || r == NULL) goto err;
155 val2[0] = BN_CTX_get(ctx);
156 if(!d || !r || !val1[0] || !val2[0]) goto err;
157 154
158 if (in_mont != NULL) 155 if (in_mont != NULL)
159 mont=in_mont; 156 mont=in_mont;
@@ -169,67 +166,69 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
169 /* 166 /*
170 * Build table for a1: val1[i] := a1^(2*i + 1) mod m for i = 0 .. 2^(window1-1) 167 * Build table for a1: val1[i] := a1^(2*i + 1) mod m for i = 0 .. 2^(window1-1)
171 */ 168 */
169 BN_init(&val1[0]);
170 ts1=1;
172 if (a1->neg || BN_ucmp(a1,m) >= 0) 171 if (a1->neg || BN_ucmp(a1,m) >= 0)
173 { 172 {
174 if (!BN_mod(val1[0],a1,m,ctx)) 173 if (!BN_mod(&(val1[0]),a1,m,ctx))
175 goto err; 174 goto err;
176 a_mod_m = val1[0]; 175 a_mod_m = &(val1[0]);
177 } 176 }
178 else 177 else
179 a_mod_m = a1; 178 a_mod_m = a1;
180 if (BN_is_zero(a_mod_m)) 179 if (BN_is_zero(a_mod_m))
181 { 180 {
182 BN_zero(rr); 181 ret = BN_zero(rr);
183 ret = 1;
184 goto err; 182 goto err;
185 } 183 }
186 184
187 if (!BN_to_montgomery(val1[0],a_mod_m,mont,ctx)) goto err; 185 if (!BN_to_montgomery(&(val1[0]),a_mod_m,mont,ctx)) goto err;
188 if (window1 > 1) 186 if (window1 > 1)
189 { 187 {
190 if (!BN_mod_mul_montgomery(d,val1[0],val1[0],mont,ctx)) goto err; 188 if (!BN_mod_mul_montgomery(d,&(val1[0]),&(val1[0]),mont,ctx)) goto err;
191 189
192 j=1<<(window1-1); 190 j=1<<(window1-1);
193 for (i=1; i<j; i++) 191 for (i=1; i<j; i++)
194 { 192 {
195 if(((val1[i] = BN_CTX_get(ctx)) == NULL) || 193 BN_init(&(val1[i]));
196 !BN_mod_mul_montgomery(val1[i],val1[i-1], 194 if (!BN_mod_mul_montgomery(&(val1[i]),&(val1[i-1]),d,mont,ctx))
197 d,mont,ctx))
198 goto err; 195 goto err;
199 } 196 }
197 ts1=i;
200 } 198 }
201 199
202 200
203 /* 201 /*
204 * Build table for a2: val2[i] := a2^(2*i + 1) mod m for i = 0 .. 2^(window2-1) 202 * Build table for a2: val2[i] := a2^(2*i + 1) mod m for i = 0 .. 2^(window2-1)
205 */ 203 */
204 BN_init(&val2[0]);
205 ts2=1;
206 if (a2->neg || BN_ucmp(a2,m) >= 0) 206 if (a2->neg || BN_ucmp(a2,m) >= 0)
207 { 207 {
208 if (!BN_mod(val2[0],a2,m,ctx)) 208 if (!BN_mod(&(val2[0]),a2,m,ctx))
209 goto err; 209 goto err;
210 a_mod_m = val2[0]; 210 a_mod_m = &(val2[0]);
211 } 211 }
212 else 212 else
213 a_mod_m = a2; 213 a_mod_m = a2;
214 if (BN_is_zero(a_mod_m)) 214 if (BN_is_zero(a_mod_m))
215 { 215 {
216 BN_zero(rr); 216 ret = BN_zero(rr);
217 ret = 1;
218 goto err; 217 goto err;
219 } 218 }
220 if (!BN_to_montgomery(val2[0],a_mod_m,mont,ctx)) goto err; 219 if (!BN_to_montgomery(&(val2[0]),a_mod_m,mont,ctx)) goto err;
221 if (window2 > 1) 220 if (window2 > 1)
222 { 221 {
223 if (!BN_mod_mul_montgomery(d,val2[0],val2[0],mont,ctx)) goto err; 222 if (!BN_mod_mul_montgomery(d,&(val2[0]),&(val2[0]),mont,ctx)) goto err;
224 223
225 j=1<<(window2-1); 224 j=1<<(window2-1);
226 for (i=1; i<j; i++) 225 for (i=1; i<j; i++)
227 { 226 {
228 if(((val2[i] = BN_CTX_get(ctx)) == NULL) || 227 BN_init(&(val2[i]));
229 !BN_mod_mul_montgomery(val2[i],val2[i-1], 228 if (!BN_mod_mul_montgomery(&(val2[i]),&(val2[i-1]),d,mont,ctx))
230 d,mont,ctx))
231 goto err; 229 goto err;
232 } 230 }
231 ts2=i;
233 } 232 }
234 233
235 234
@@ -286,7 +285,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
286 if (wvalue1 && b == wpos1) 285 if (wvalue1 && b == wpos1)
287 { 286 {
288 /* wvalue1 is odd and < 2^window1 */ 287 /* wvalue1 is odd and < 2^window1 */
289 if (!BN_mod_mul_montgomery(r,r,val1[wvalue1>>1],mont,ctx)) 288 if (!BN_mod_mul_montgomery(r,r,&(val1[wvalue1>>1]),mont,ctx))
290 goto err; 289 goto err;
291 wvalue1 = 0; 290 wvalue1 = 0;
292 r_is_one = 0; 291 r_is_one = 0;
@@ -295,7 +294,7 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
295 if (wvalue2 && b == wpos2) 294 if (wvalue2 && b == wpos2)
296 { 295 {
297 /* wvalue2 is odd and < 2^window2 */ 296 /* wvalue2 is odd and < 2^window2 */
298 if (!BN_mod_mul_montgomery(r,r,val2[wvalue2>>1],mont,ctx)) 297 if (!BN_mod_mul_montgomery(r,r,&(val2[wvalue2>>1]),mont,ctx))
299 goto err; 298 goto err;
300 wvalue2 = 0; 299 wvalue2 = 0;
301 r_is_one = 0; 300 r_is_one = 0;
@@ -306,6 +305,9 @@ int BN_mod_exp2_mont(BIGNUM *rr, const BIGNUM *a1, const BIGNUM *p1,
306err: 305err:
307 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont); 306 if ((in_mont == NULL) && (mont != NULL)) BN_MONT_CTX_free(mont);
308 BN_CTX_end(ctx); 307 BN_CTX_end(ctx);
309 bn_check_top(rr); 308 for (i=0; i<ts1; i++)
309 BN_clear_free(&(val1[i]));
310 for (i=0; i<ts2; i++)
311 BN_clear_free(&(val2[i]));
310 return(ret); 312 return(ret);
311 } 313 }
diff --git a/src/lib/libcrypto/bn/bn_gcd.c b/src/lib/libcrypto/bn/bn_gcd.c
index 4a352119ba..7649f63fd2 100644
--- a/src/lib/libcrypto/bn/bn_gcd.c
+++ b/src/lib/libcrypto/bn/bn_gcd.c
@@ -140,7 +140,6 @@ int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
140 ret=1; 140 ret=1;
141err: 141err:
142 BN_CTX_end(ctx); 142 BN_CTX_end(ctx);
143 bn_check_top(r);
144 return(ret); 143 return(ret);
145 } 144 }
146 145
@@ -195,7 +194,6 @@ static BIGNUM *euclid(BIGNUM *a, BIGNUM *b)
195 { 194 {
196 if (!BN_lshift(a,a,shifts)) goto err; 195 if (!BN_lshift(a,a,shifts)) goto err;
197 } 196 }
198 bn_check_top(a);
199 return(a); 197 return(a);
200err: 198err:
201 return(NULL); 199 return(NULL);
@@ -203,8 +201,6 @@ err:
203 201
204 202
205/* solves ax == 1 (mod n) */ 203/* solves ax == 1 (mod n) */
206static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,
207 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx);
208BIGNUM *BN_mod_inverse(BIGNUM *in, 204BIGNUM *BN_mod_inverse(BIGNUM *in,
209 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx) 205 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
210 { 206 {
@@ -212,11 +208,6 @@ BIGNUM *BN_mod_inverse(BIGNUM *in,
212 BIGNUM *ret=NULL; 208 BIGNUM *ret=NULL;
213 int sign; 209 int sign;
214 210
215 if ((BN_get_flags(a, BN_FLG_CONSTTIME) != 0) || (BN_get_flags(n, BN_FLG_CONSTTIME) != 0))
216 {
217 return BN_mod_inverse_no_branch(in, a, n, ctx);
218 }
219
220 bn_check_top(a); 211 bn_check_top(a);
221 bn_check_top(n); 212 bn_check_top(n);
222 213
@@ -495,160 +486,5 @@ BIGNUM *BN_mod_inverse(BIGNUM *in,
495err: 486err:
496 if ((ret == NULL) && (in == NULL)) BN_free(R); 487 if ((ret == NULL) && (in == NULL)) BN_free(R);
497 BN_CTX_end(ctx); 488 BN_CTX_end(ctx);
498 bn_check_top(ret);
499 return(ret);
500 }
501
502
503/* BN_mod_inverse_no_branch is a special version of BN_mod_inverse.
504 * It does not contain branches that may leak sensitive information.
505 */
506static BIGNUM *BN_mod_inverse_no_branch(BIGNUM *in,
507 const BIGNUM *a, const BIGNUM *n, BN_CTX *ctx)
508 {
509 BIGNUM *A,*B,*X,*Y,*M,*D,*T,*R=NULL;
510 BIGNUM local_A, local_B;
511 BIGNUM *pA, *pB;
512 BIGNUM *ret=NULL;
513 int sign;
514
515 bn_check_top(a);
516 bn_check_top(n);
517
518 BN_CTX_start(ctx);
519 A = BN_CTX_get(ctx);
520 B = BN_CTX_get(ctx);
521 X = BN_CTX_get(ctx);
522 D = BN_CTX_get(ctx);
523 M = BN_CTX_get(ctx);
524 Y = BN_CTX_get(ctx);
525 T = BN_CTX_get(ctx);
526 if (T == NULL) goto err;
527
528 if (in == NULL)
529 R=BN_new();
530 else
531 R=in;
532 if (R == NULL) goto err;
533
534 BN_one(X);
535 BN_zero(Y);
536 if (BN_copy(B,a) == NULL) goto err;
537 if (BN_copy(A,n) == NULL) goto err;
538 A->neg = 0;
539
540 if (B->neg || (BN_ucmp(B, A) >= 0))
541 {
542 /* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
543 * BN_div_no_branch will be called eventually.
544 */
545 pB = &local_B;
546 BN_with_flags(pB, B, BN_FLG_CONSTTIME);
547 if (!BN_nnmod(B, pB, A, ctx)) goto err;
548 }
549 sign = -1;
550 /* From B = a mod |n|, A = |n| it follows that
551 *
552 * 0 <= B < A,
553 * -sign*X*a == B (mod |n|),
554 * sign*Y*a == A (mod |n|).
555 */
556
557 while (!BN_is_zero(B))
558 {
559 BIGNUM *tmp;
560
561 /*
562 * 0 < B < A,
563 * (*) -sign*X*a == B (mod |n|),
564 * sign*Y*a == A (mod |n|)
565 */
566
567 /* Turn BN_FLG_CONSTTIME flag on, so that when BN_div is invoked,
568 * BN_div_no_branch will be called eventually.
569 */
570 pA = &local_A;
571 BN_with_flags(pA, A, BN_FLG_CONSTTIME);
572
573 /* (D, M) := (A/B, A%B) ... */
574 if (!BN_div(D,M,pA,B,ctx)) goto err;
575
576 /* Now
577 * A = D*B + M;
578 * thus we have
579 * (**) sign*Y*a == D*B + M (mod |n|).
580 */
581
582 tmp=A; /* keep the BIGNUM object, the value does not matter */
583
584 /* (A, B) := (B, A mod B) ... */
585 A=B;
586 B=M;
587 /* ... so we have 0 <= B < A again */
588
589 /* Since the former M is now B and the former B is now A,
590 * (**) translates into
591 * sign*Y*a == D*A + B (mod |n|),
592 * i.e.
593 * sign*Y*a - D*A == B (mod |n|).
594 * Similarly, (*) translates into
595 * -sign*X*a == A (mod |n|).
596 *
597 * Thus,
598 * sign*Y*a + D*sign*X*a == B (mod |n|),
599 * i.e.
600 * sign*(Y + D*X)*a == B (mod |n|).
601 *
602 * So if we set (X, Y, sign) := (Y + D*X, X, -sign), we arrive back at
603 * -sign*X*a == B (mod |n|),
604 * sign*Y*a == A (mod |n|).
605 * Note that X and Y stay non-negative all the time.
606 */
607
608 if (!BN_mul(tmp,D,X,ctx)) goto err;
609 if (!BN_add(tmp,tmp,Y)) goto err;
610
611 M=Y; /* keep the BIGNUM object, the value does not matter */
612 Y=X;
613 X=tmp;
614 sign = -sign;
615 }
616
617 /*
618 * The while loop (Euclid's algorithm) ends when
619 * A == gcd(a,n);
620 * we have
621 * sign*Y*a == A (mod |n|),
622 * where Y is non-negative.
623 */
624
625 if (sign < 0)
626 {
627 if (!BN_sub(Y,n,Y)) goto err;
628 }
629 /* Now Y*a == A (mod |n|). */
630
631 if (BN_is_one(A))
632 {
633 /* Y*a == 1 (mod |n|) */
634 if (!Y->neg && BN_ucmp(Y,n) < 0)
635 {
636 if (!BN_copy(R,Y)) goto err;
637 }
638 else
639 {
640 if (!BN_nnmod(R,Y,n,ctx)) goto err;
641 }
642 }
643 else
644 {
645 BNerr(BN_F_BN_MOD_INVERSE_NO_BRANCH,BN_R_NO_INVERSE);
646 goto err;
647 }
648 ret=R;
649err:
650 if ((ret == NULL) && (in == NULL)) BN_free(R);
651 BN_CTX_end(ctx);
652 bn_check_top(ret);
653 return(ret); 489 return(ret);
654 } 490 }
diff --git a/src/lib/libcrypto/bn/bn_kron.c b/src/lib/libcrypto/bn/bn_kron.c
index 740359b752..49f75594ae 100644
--- a/src/lib/libcrypto/bn/bn_kron.c
+++ b/src/lib/libcrypto/bn/bn_kron.c
@@ -53,9 +53,9 @@
53 * 53 *
54 */ 54 */
55 55
56#include "cryptlib.h"
57#include "bn_lcl.h" 56#include "bn_lcl.h"
58 57
58
59/* least significant word */ 59/* least significant word */
60#define BN_lsw(n) (((n)->top == 0) ? (BN_ULONG) 0 : (n)->d[0]) 60#define BN_lsw(n) (((n)->top == 0) ? (BN_ULONG) 0 : (n)->d[0])
61 61
@@ -74,9 +74,6 @@ int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
74 */ 74 */
75 static const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1}; 75 static const int tab[8] = {0, 1, 0, -1, 0, -1, 0, 1};
76 76
77 bn_check_top(a);
78 bn_check_top(b);
79
80 BN_CTX_start(ctx); 77 BN_CTX_start(ctx);
81 A = BN_CTX_get(ctx); 78 A = BN_CTX_get(ctx);
82 B = BN_CTX_get(ctx); 79 B = BN_CTX_get(ctx);
@@ -175,7 +172,8 @@ int BN_kronecker(const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
175 tmp = A; A = B; B = tmp; 172 tmp = A; A = B; B = tmp;
176 tmp->neg = 0; 173 tmp->neg = 0;
177 } 174 }
178end: 175
176 end:
179 BN_CTX_end(ctx); 177 BN_CTX_end(ctx);
180 if (err) 178 if (err)
181 return -2; 179 return -2;
diff --git a/src/lib/libcrypto/bn/bn_lcl.h b/src/lib/libcrypto/bn/bn_lcl.h
index 27ac4397a1..a84998f2bd 100644
--- a/src/lib/libcrypto/bn/bn_lcl.h
+++ b/src/lib/libcrypto/bn/bn_lcl.h
@@ -119,6 +119,20 @@ extern "C" {
119#endif 119#endif
120 120
121 121
122/* Used for temp variables */
123#define BN_CTX_NUM 32
124#define BN_CTX_NUM_POS 12
125struct bignum_ctx
126 {
127 int tos;
128 BIGNUM bn[BN_CTX_NUM];
129 int flags;
130 int depth;
131 int pos[BN_CTX_NUM_POS];
132 int too_many;
133 } /* BN_CTX */;
134
135
122/* 136/*
123 * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions 137 * BN_window_bits_for_exponent_size -- macro for sliding window mod_exp functions
124 * 138 *
@@ -270,15 +284,6 @@ extern "C" {
270 : "a"(a),"g"(b) \ 284 : "a"(a),"g"(b) \
271 : "cc"); 285 : "cc");
272# endif 286# endif
273# elif (defined(_M_AMD64) || defined(_M_X64)) && defined(SIXTY_FOUR_BIT)
274# if defined(_MSC_VER) && _MSC_VER>=1400
275 unsigned __int64 __umulh (unsigned __int64 a,unsigned __int64 b);
276 unsigned __int64 _umul128 (unsigned __int64 a,unsigned __int64 b,
277 unsigned __int64 *h);
278# pragma intrinsic(__umulh,_umul128)
279# define BN_UMULT_HIGH(a,b) __umulh((a),(b))
280# define BN_UMULT_LOHI(low,high,a,b) ((low)=_umul128((a),(b),&(high)))
281# endif
282# endif /* cpu */ 287# endif /* cpu */
283#endif /* OPENSSL_NO_ASM */ 288#endif /* OPENSSL_NO_ASM */
284 289
@@ -288,18 +293,45 @@ extern "C" {
288#define Lw(t) (((BN_ULONG)(t))&BN_MASK2) 293#define Lw(t) (((BN_ULONG)(t))&BN_MASK2)
289#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2) 294#define Hw(t) (((BN_ULONG)((t)>>BN_BITS2))&BN_MASK2)
290 295
291#ifdef BN_DEBUG_RAND 296/* This is used for internal error checking and is not normally used */
292#define bn_clear_top2max(a) \ 297#ifdef BN_DEBUG
293 { \ 298# include <assert.h>
294 int ind = (a)->dmax - (a)->top; \ 299# define bn_check_top(a) assert ((a)->top >= 0 && (a)->top <= (a)->dmax);
295 BN_ULONG *ftl = &(a)->d[(a)->top-1]; \ 300#else
296 for (; ind != 0; ind--) \ 301# define bn_check_top(a)
297 *(++ftl) = 0x0; \ 302#endif
298 } 303
304/* This macro is to add extra stuff for development checking */
305#ifdef BN_DEBUG
306#define bn_set_max(r) ((r)->max=(r)->top,BN_set_flags((r),BN_FLG_STATIC_DATA))
299#else 307#else
300#define bn_clear_top2max(a) 308#define bn_set_max(r)
301#endif 309#endif
302 310
311/* These macros are used to 'take' a section of a bignum for read only use */
312#define bn_set_low(r,a,n) \
313 { \
314 (r)->top=((a)->top > (n))?(n):(a)->top; \
315 (r)->d=(a)->d; \
316 (r)->neg=(a)->neg; \
317 (r)->flags|=BN_FLG_STATIC_DATA; \
318 bn_set_max(r); \
319 }
320
321#define bn_set_high(r,a,n) \
322 { \
323 if ((a)->top > (n)) \
324 { \
325 (r)->top=(a)->top-n; \
326 (r)->d= &((a)->d[n]); \
327 } \
328 else \
329 (r)->top=0; \
330 (r)->neg=(a)->neg; \
331 (r)->flags|=BN_FLG_STATIC_DATA; \
332 bn_set_max(r); \
333 }
334
303#ifdef BN_LLONG 335#ifdef BN_LLONG
304#define mul_add(r,a,w,c) { \ 336#define mul_add(r,a,w,c) { \
305 BN_ULLONG t; \ 337 BN_ULLONG t; \
@@ -322,33 +354,6 @@ extern "C" {
322 (r1)=Hw(t); \ 354 (r1)=Hw(t); \
323 } 355 }
324 356
325#elif defined(BN_UMULT_LOHI)
326#define mul_add(r,a,w,c) { \
327 BN_ULONG high,low,ret,tmp=(a); \
328 ret = (r); \
329 BN_UMULT_LOHI(low,high,w,tmp); \
330 ret += (c); \
331 (c) = (ret<(c))?1:0; \
332 (c) += high; \
333 ret += low; \
334 (c) += (ret<low)?1:0; \
335 (r) = ret; \
336 }
337
338#define mul(r,a,w,c) { \
339 BN_ULONG high,low,ret,ta=(a); \
340 BN_UMULT_LOHI(low,high,w,ta); \
341 ret = low + (c); \
342 (c) = high; \
343 (c) += (ret<low)?1:0; \
344 (r) = ret; \
345 }
346
347#define sqr(r0,r1,a) { \
348 BN_ULONG tmp=(a); \
349 BN_UMULT_LOHI(r0,r1,tmp,tmp); \
350 }
351
352#elif defined(BN_UMULT_HIGH) 357#elif defined(BN_UMULT_HIGH)
353#define mul_add(r,a,w,c) { \ 358#define mul_add(r,a,w,c) { \
354 BN_ULONG high,low,ret,tmp=(a); \ 359 BN_ULONG high,low,ret,tmp=(a); \
@@ -467,21 +472,18 @@ void bn_sqr_comba4(BN_ULONG *r,const BN_ULONG *a);
467int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n); 472int bn_cmp_words(const BN_ULONG *a,const BN_ULONG *b,int n);
468int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b, 473int bn_cmp_part_words(const BN_ULONG *a, const BN_ULONG *b,
469 int cl, int dl); 474 int cl, int dl);
470void bn_mul_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, 475#ifdef BN_RECURSION
471 int dna,int dnb,BN_ULONG *t); 476void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
472void bn_mul_part_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, 477 BN_ULONG *t);
473 int n,int tna,int tnb,BN_ULONG *t); 478void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
474void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t); 479 int n, BN_ULONG *t);
475void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
476void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2, 480void bn_mul_low_recursive(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,int n2,
477 BN_ULONG *t); 481 BN_ULONG *t);
478void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2, 482void bn_mul_high(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b,BN_ULONG *l,int n2,
479 BN_ULONG *t); 483 BN_ULONG *t);
480BN_ULONG bn_add_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, 484void bn_sqr_recursive(BN_ULONG *r,const BN_ULONG *a, int n2, BN_ULONG *t);
481 int cl, int dl); 485#endif
482BN_ULONG bn_sub_part_words(BN_ULONG *r, const BN_ULONG *a, const BN_ULONG *b, 486void bn_mul_low_normal(BN_ULONG *r,BN_ULONG *a,BN_ULONG *b, int n);
483 int cl, int dl);
484int bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np,const BN_ULONG *n0, int num);
485 487
486#ifdef __cplusplus 488#ifdef __cplusplus
487} 489}
diff --git a/src/lib/libcrypto/bn/bn_lib.c b/src/lib/libcrypto/bn/bn_lib.c
index 2649b8c538..e1660450bc 100644
--- a/src/lib/libcrypto/bn/bn_lib.c
+++ b/src/lib/libcrypto/bn/bn_lib.c
@@ -67,10 +67,8 @@
67#include "cryptlib.h" 67#include "cryptlib.h"
68#include "bn_lcl.h" 68#include "bn_lcl.h"
69 69
70const char BN_version[]="Big Number" OPENSSL_VERSION_PTEXT; 70const char *BN_version="Big Number" OPENSSL_VERSION_PTEXT;
71 71
72/* This stuff appears to be completely unused, so is deprecated */
73#ifndef OPENSSL_NO_DEPRECATED
74/* For a 32 bit machine 72/* For a 32 bit machine
75 * 2 - 4 == 128 73 * 2 - 4 == 128
76 * 3 - 8 == 256 74 * 3 - 8 == 256
@@ -93,28 +91,28 @@ void BN_set_params(int mult, int high, int low, int mont)
93 { 91 {
94 if (mult >= 0) 92 if (mult >= 0)
95 { 93 {
96 if (mult > (int)(sizeof(int)*8)-1) 94 if (mult > (sizeof(int)*8)-1)
97 mult=sizeof(int)*8-1; 95 mult=sizeof(int)*8-1;
98 bn_limit_bits=mult; 96 bn_limit_bits=mult;
99 bn_limit_num=1<<mult; 97 bn_limit_num=1<<mult;
100 } 98 }
101 if (high >= 0) 99 if (high >= 0)
102 { 100 {
103 if (high > (int)(sizeof(int)*8)-1) 101 if (high > (sizeof(int)*8)-1)
104 high=sizeof(int)*8-1; 102 high=sizeof(int)*8-1;
105 bn_limit_bits_high=high; 103 bn_limit_bits_high=high;
106 bn_limit_num_high=1<<high; 104 bn_limit_num_high=1<<high;
107 } 105 }
108 if (low >= 0) 106 if (low >= 0)
109 { 107 {
110 if (low > (int)(sizeof(int)*8)-1) 108 if (low > (sizeof(int)*8)-1)
111 low=sizeof(int)*8-1; 109 low=sizeof(int)*8-1;
112 bn_limit_bits_low=low; 110 bn_limit_bits_low=low;
113 bn_limit_num_low=1<<low; 111 bn_limit_num_low=1<<low;
114 } 112 }
115 if (mont >= 0) 113 if (mont >= 0)
116 { 114 {
117 if (mont > (int)(sizeof(int)*8)-1) 115 if (mont > (sizeof(int)*8)-1)
118 mont=sizeof(int)*8-1; 116 mont=sizeof(int)*8-1;
119 bn_limit_bits_mont=mont; 117 bn_limit_bits_mont=mont;
120 bn_limit_num_mont=1<<mont; 118 bn_limit_num_mont=1<<mont;
@@ -129,12 +127,11 @@ int BN_get_params(int which)
129 else if (which == 3) return(bn_limit_bits_mont); 127 else if (which == 3) return(bn_limit_bits_mont);
130 else return(0); 128 else return(0);
131 } 129 }
132#endif
133 130
134const BIGNUM *BN_value_one(void) 131const BIGNUM *BN_value_one(void)
135 { 132 {
136 static BN_ULONG data_one=1L; 133 static BN_ULONG data_one=1L;
137 static BIGNUM const_one={&data_one,1,1,0,BN_FLG_STATIC_DATA}; 134 static BIGNUM const_one={&data_one,1,1,0};
138 135
139 return(&const_one); 136 return(&const_one);
140 } 137 }
@@ -247,11 +244,16 @@ int BN_num_bits_word(BN_ULONG l)
247 244
248int BN_num_bits(const BIGNUM *a) 245int BN_num_bits(const BIGNUM *a)
249 { 246 {
250 int i = a->top - 1; 247 BN_ULONG l;
248 int i;
249
251 bn_check_top(a); 250 bn_check_top(a);
252 251
253 if (BN_is_zero(a)) return 0; 252 if (a->top == 0) return(0);
254 return ((i*BN_BITS2) + BN_num_bits_word(a->d[i])); 253 l=a->d[a->top-1];
254 assert(l != 0);
255 i=(a->top-1)*BN_BITS2;
256 return(i+BN_num_bits_word(l));
255 } 257 }
256 258
257void BN_clear_free(BIGNUM *a) 259void BN_clear_free(BIGNUM *a)
@@ -259,7 +261,6 @@ void BN_clear_free(BIGNUM *a)
259 int i; 261 int i;
260 262
261 if (a == NULL) return; 263 if (a == NULL) return;
262 bn_check_top(a);
263 if (a->d != NULL) 264 if (a->d != NULL)
264 { 265 {
265 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0])); 266 OPENSSL_cleanse(a->d,a->dmax*sizeof(a->d[0]));
@@ -275,24 +276,16 @@ void BN_clear_free(BIGNUM *a)
275void BN_free(BIGNUM *a) 276void BN_free(BIGNUM *a)
276 { 277 {
277 if (a == NULL) return; 278 if (a == NULL) return;
278 bn_check_top(a);
279 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA))) 279 if ((a->d != NULL) && !(BN_get_flags(a,BN_FLG_STATIC_DATA)))
280 OPENSSL_free(a->d); 280 OPENSSL_free(a->d);
281 a->flags|=BN_FLG_FREE; /* REMOVE? */
281 if (a->flags & BN_FLG_MALLOCED) 282 if (a->flags & BN_FLG_MALLOCED)
282 OPENSSL_free(a); 283 OPENSSL_free(a);
283 else
284 {
285#ifndef OPENSSL_NO_DEPRECATED
286 a->flags|=BN_FLG_FREE;
287#endif
288 a->d = NULL;
289 }
290 } 284 }
291 285
292void BN_init(BIGNUM *a) 286void BN_init(BIGNUM *a)
293 { 287 {
294 memset(a,0,sizeof(BIGNUM)); 288 memset(a,0,sizeof(BIGNUM));
295 bn_check_top(a);
296 } 289 }
297 290
298BIGNUM *BN_new(void) 291BIGNUM *BN_new(void)
@@ -309,7 +302,6 @@ BIGNUM *BN_new(void)
309 ret->neg=0; 302 ret->neg=0;
310 ret->dmax=0; 303 ret->dmax=0;
311 ret->d=NULL; 304 ret->d=NULL;
312 bn_check_top(ret);
313 return(ret); 305 return(ret);
314 } 306 }
315 307
@@ -321,19 +313,19 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
321 const BN_ULONG *B; 313 const BN_ULONG *B;
322 int i; 314 int i;
323 315
324 bn_check_top(b);
325
326 if (words > (INT_MAX/(4*BN_BITS2))) 316 if (words > (INT_MAX/(4*BN_BITS2)))
327 { 317 {
328 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_BIGNUM_TOO_LONG); 318 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_BIGNUM_TOO_LONG);
329 return NULL; 319 return NULL;
330 } 320 }
321
322 bn_check_top(b);
331 if (BN_get_flags(b,BN_FLG_STATIC_DATA)) 323 if (BN_get_flags(b,BN_FLG_STATIC_DATA))
332 { 324 {
333 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA); 325 BNerr(BN_F_BN_EXPAND_INTERNAL,BN_R_EXPAND_ON_STATIC_BIGNUM_DATA);
334 return(NULL); 326 return(NULL);
335 } 327 }
336 a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*words); 328 a=A=(BN_ULONG *)OPENSSL_malloc(sizeof(BN_ULONG)*(words+1));
337 if (A == NULL) 329 if (A == NULL)
338 { 330 {
339 BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE); 331 BNerr(BN_F_BN_EXPAND_INTERNAL,ERR_R_MALLOC_FAILURE);
@@ -371,8 +363,19 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
371 } 363 }
372 } 364 }
373 365
366 /* Now need to zero any data between b->top and b->max */
367 /* XXX Why? */
368
369 A= &(a[b->top]);
370 for (i=(words - b->top)>>3; i>0; i--,A+=8)
371 {
372 A[0]=0; A[1]=0; A[2]=0; A[3]=0;
373 A[4]=0; A[5]=0; A[6]=0; A[7]=0;
374 }
375 for (i=(words - b->top)&7; i>0; i--,A++)
376 A[0]=0;
374#else 377#else
375 memset(A,0,sizeof(BN_ULONG)*words); 378 memset(A,0,sizeof(BN_ULONG)*(words+1));
376 memcpy(A,b->d,sizeof(b->d[0])*b->top); 379 memcpy(A,b->d,sizeof(b->d[0])*b->top);
377#endif 380#endif
378 381
@@ -390,19 +393,16 @@ static BN_ULONG *bn_expand_internal(const BIGNUM *b, int words)
390 * while bn_dup_expand() makes sure allocation is made only once. 393 * while bn_dup_expand() makes sure allocation is made only once.
391 */ 394 */
392 395
393#ifndef OPENSSL_NO_DEPRECATED
394BIGNUM *bn_dup_expand(const BIGNUM *b, int words) 396BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
395 { 397 {
396 BIGNUM *r = NULL; 398 BIGNUM *r = NULL;
397 399
398 bn_check_top(b);
399
400 /* This function does not work if 400 /* This function does not work if
401 * words <= b->dmax && top < words 401 * words <= b->dmax && top < words
402 * because BN_dup() does not preserve 'dmax'! 402 * because BN_dup() does not preserve 'dmax'!
403 * (But bn_dup_expand() is not used anywhere yet.) 403 * (But bn_dup_expand() is not used anywhere yet.)
404 */ 404 */
405 405
406 if (words > b->dmax) 406 if (words > b->dmax)
407 { 407 {
408 BN_ULONG *a = bn_expand_internal(b, words); 408 BN_ULONG *a = bn_expand_internal(b, words);
@@ -431,67 +431,48 @@ BIGNUM *bn_dup_expand(const BIGNUM *b, int words)
431 r = BN_dup(b); 431 r = BN_dup(b);
432 } 432 }
433 433
434 bn_check_top(r);
435 return r; 434 return r;
436 } 435 }
437#endif
438 436
439/* This is an internal function that should not be used in applications. 437/* This is an internal function that should not be used in applications.
440 * It ensures that 'b' has enough room for a 'words' word number 438 * It ensures that 'b' has enough room for a 'words' word number number.
441 * and initialises any unused part of b->d with leading zeros.
442 * It is mostly used by the various BIGNUM routines. If there is an error, 439 * It is mostly used by the various BIGNUM routines. If there is an error,
443 * NULL is returned. If not, 'b' is returned. */ 440 * NULL is returned. If not, 'b' is returned. */
444 441
445BIGNUM *bn_expand2(BIGNUM *b, int words) 442BIGNUM *bn_expand2(BIGNUM *b, int words)
446 { 443 {
447 bn_check_top(b);
448
449 if (words > b->dmax) 444 if (words > b->dmax)
450 { 445 {
451 BN_ULONG *a = bn_expand_internal(b, words); 446 BN_ULONG *a = bn_expand_internal(b, words);
452 if(!a) return NULL;
453 if(b->d) OPENSSL_free(b->d);
454 b->d=a;
455 b->dmax=words;
456 }
457 447
458/* None of this should be necessary because of what b->top means! */ 448 if (a)
459#if 0
460 /* NB: bn_wexpand() calls this only if the BIGNUM really has to grow */
461 if (b->top < b->dmax)
462 {
463 int i;
464 BN_ULONG *A = &(b->d[b->top]);
465 for (i=(b->dmax - b->top)>>3; i>0; i--,A+=8)
466 { 449 {
467 A[0]=0; A[1]=0; A[2]=0; A[3]=0; 450 if (b->d)
468 A[4]=0; A[5]=0; A[6]=0; A[7]=0; 451 OPENSSL_free(b->d);
452 b->d=a;
453 b->dmax=words;
469 } 454 }
470 for (i=(b->dmax - b->top)&7; i>0; i--,A++) 455 else
471 A[0]=0; 456 b = NULL;
472 assert(A == &(b->d[b->dmax]));
473 } 457 }
474#endif
475 bn_check_top(b);
476 return b; 458 return b;
477 } 459 }
478 460
479BIGNUM *BN_dup(const BIGNUM *a) 461BIGNUM *BN_dup(const BIGNUM *a)
480 { 462 {
481 BIGNUM *t; 463 BIGNUM *r, *t;
482 464
483 if (a == NULL) return NULL; 465 if (a == NULL) return NULL;
466
484 bn_check_top(a); 467 bn_check_top(a);
485 468
486 t = BN_new(); 469 t = BN_new();
487 if (t == NULL) return NULL; 470 if (t == NULL) return(NULL);
488 if(!BN_copy(t, a)) 471 r = BN_copy(t, a);
489 { 472 /* now r == t || r == NULL */
473 if (r == NULL)
490 BN_free(t); 474 BN_free(t);
491 return NULL; 475 return r;
492 }
493 bn_check_top(t);
494 return t;
495 } 476 }
496 477
497BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b) 478BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
@@ -525,9 +506,11 @@ BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
525 memcpy(a->d,b->d,sizeof(b->d[0])*b->top); 506 memcpy(a->d,b->d,sizeof(b->d[0])*b->top);
526#endif 507#endif
527 508
509/* memset(&(a->d[b->top]),0,sizeof(a->d[0])*(a->max-b->top));*/
528 a->top=b->top; 510 a->top=b->top;
511 if ((a->top == 0) && (a->d != NULL))
512 a->d[0]=0;
529 a->neg=b->neg; 513 a->neg=b->neg;
530 bn_check_top(a);
531 return(a); 514 return(a);
532 } 515 }
533 516
@@ -537,9 +520,6 @@ void BN_swap(BIGNUM *a, BIGNUM *b)
537 BN_ULONG *tmp_d; 520 BN_ULONG *tmp_d;
538 int tmp_top, tmp_dmax, tmp_neg; 521 int tmp_top, tmp_dmax, tmp_neg;
539 522
540 bn_check_top(a);
541 bn_check_top(b);
542
543 flags_old_a = a->flags; 523 flags_old_a = a->flags;
544 flags_old_b = b->flags; 524 flags_old_b = b->flags;
545 525
@@ -560,13 +540,11 @@ void BN_swap(BIGNUM *a, BIGNUM *b)
560 540
561 a->flags = (flags_old_a & BN_FLG_MALLOCED) | (flags_old_b & BN_FLG_STATIC_DATA); 541 a->flags = (flags_old_a & BN_FLG_MALLOCED) | (flags_old_b & BN_FLG_STATIC_DATA);
562 b->flags = (flags_old_b & BN_FLG_MALLOCED) | (flags_old_a & BN_FLG_STATIC_DATA); 542 b->flags = (flags_old_b & BN_FLG_MALLOCED) | (flags_old_a & BN_FLG_STATIC_DATA);
563 bn_check_top(a);
564 bn_check_top(b);
565 } 543 }
566 544
545
567void BN_clear(BIGNUM *a) 546void BN_clear(BIGNUM *a)
568 { 547 {
569 bn_check_top(a);
570 if (a->d != NULL) 548 if (a->d != NULL)
571 memset(a->d,0,a->dmax*sizeof(a->d[0])); 549 memset(a->d,0,a->dmax*sizeof(a->d[0]));
572 a->top=0; 550 a->top=0;
@@ -575,22 +553,49 @@ void BN_clear(BIGNUM *a)
575 553
576BN_ULONG BN_get_word(const BIGNUM *a) 554BN_ULONG BN_get_word(const BIGNUM *a)
577 { 555 {
578 if (a->top > 1) 556 int i,n;
579 return BN_MASK2; 557 BN_ULONG ret=0;
580 else if (a->top == 1) 558
581 return a->d[0]; 559 n=BN_num_bytes(a);
582 /* a->top == 0 */ 560 if (n > sizeof(BN_ULONG))
583 return 0; 561 return(BN_MASK2);
562 for (i=a->top-1; i>=0; i--)
563 {
564#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
565 ret<<=BN_BITS4; /* stops the compiler complaining */
566 ret<<=BN_BITS4;
567#else
568 ret=0;
569#endif
570 ret|=a->d[i];
571 }
572 return(ret);
584 } 573 }
585 574
586int BN_set_word(BIGNUM *a, BN_ULONG w) 575int BN_set_word(BIGNUM *a, BN_ULONG w)
587 { 576 {
588 bn_check_top(a); 577 int i,n;
589 if (bn_expand(a,(int)sizeof(BN_ULONG)*8) == NULL) return(0); 578 if (bn_expand(a,sizeof(BN_ULONG)*8) == NULL) return(0);
590 a->neg = 0; 579
591 a->d[0] = w; 580 n=sizeof(BN_ULONG)/BN_BYTES;
592 a->top = (w ? 1 : 0); 581 a->neg=0;
593 bn_check_top(a); 582 a->top=0;
583 a->d[0]=(BN_ULONG)w&BN_MASK2;
584 if (a->d[0] != 0) a->top=1;
585 for (i=1; i<n; i++)
586 {
587 /* the following is done instead of
588 * w>>=BN_BITS2 so compilers don't complain
589 * on builds where sizeof(long) == BN_TYPES */
590#ifndef SIXTY_FOUR_BIT /* the data item > unsigned long */
591 w>>=BN_BITS4;
592 w>>=BN_BITS4;
593#else
594 w=0;
595#endif
596 a->d[i]=(BN_ULONG)w&BN_MASK2;
597 if (a->d[i] != 0) a->top=i+1;
598 }
594 return(1); 599 return(1);
595 } 600 }
596 601
@@ -599,12 +604,9 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
599 unsigned int i,m; 604 unsigned int i,m;
600 unsigned int n; 605 unsigned int n;
601 BN_ULONG l; 606 BN_ULONG l;
602 BIGNUM *bn = NULL;
603 607
604 if (ret == NULL) 608 if (ret == NULL) ret=BN_new();
605 ret = bn = BN_new();
606 if (ret == NULL) return(NULL); 609 if (ret == NULL) return(NULL);
607 bn_check_top(ret);
608 l=0; 610 l=0;
609 n=len; 611 n=len;
610 if (n == 0) 612 if (n == 0)
@@ -612,16 +614,13 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
612 ret->top=0; 614 ret->top=0;
613 return(ret); 615 return(ret);
614 } 616 }
617 if (bn_expand(ret,(int)(n+2)*8) == NULL)
618 return(NULL);
615 i=((n-1)/BN_BYTES)+1; 619 i=((n-1)/BN_BYTES)+1;
616 m=((n-1)%(BN_BYTES)); 620 m=((n-1)%(BN_BYTES));
617 if (bn_wexpand(ret, (int)i) == NULL)
618 {
619 if (bn) BN_free(bn);
620 return NULL;
621 }
622 ret->top=i; 621 ret->top=i;
623 ret->neg=0; 622 ret->neg=0;
624 while (n--) 623 while (n-- > 0)
625 { 624 {
626 l=(l<<8L)| *(s++); 625 l=(l<<8L)| *(s++);
627 if (m-- == 0) 626 if (m-- == 0)
@@ -633,7 +632,7 @@ BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
633 } 632 }
634 /* need to call this due to clear byte at top if avoiding 633 /* need to call this due to clear byte at top if avoiding
635 * having the top bit set (-ve number) */ 634 * having the top bit set (-ve number) */
636 bn_correct_top(ret); 635 bn_fix_top(ret);
637 return(ret); 636 return(ret);
638 } 637 }
639 638
@@ -643,9 +642,8 @@ int BN_bn2bin(const BIGNUM *a, unsigned char *to)
643 int n,i; 642 int n,i;
644 BN_ULONG l; 643 BN_ULONG l;
645 644
646 bn_check_top(a);
647 n=i=BN_num_bytes(a); 645 n=i=BN_num_bytes(a);
648 while (i--) 646 while (i-- > 0)
649 { 647 {
650 l=a->d[i/BN_BYTES]; 648 l=a->d[i/BN_BYTES];
651 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff; 649 *(to++)=(unsigned char)(l>>(8*(i%BN_BYTES)))&0xff;
@@ -670,7 +668,7 @@ int BN_ucmp(const BIGNUM *a, const BIGNUM *b)
670 t1= ap[i]; 668 t1= ap[i];
671 t2= bp[i]; 669 t2= bp[i];
672 if (t1 != t2) 670 if (t1 != t2)
673 return((t1 > t2) ? 1 : -1); 671 return(t1 > t2?1:-1);
674 } 672 }
675 return(0); 673 return(0);
676 } 674 }
@@ -720,9 +718,6 @@ int BN_set_bit(BIGNUM *a, int n)
720 { 718 {
721 int i,j,k; 719 int i,j,k;
722 720
723 if (n < 0)
724 return 0;
725
726 i=n/BN_BITS2; 721 i=n/BN_BITS2;
727 j=n%BN_BITS2; 722 j=n%BN_BITS2;
728 if (a->top <= i) 723 if (a->top <= i)
@@ -734,7 +729,6 @@ int BN_set_bit(BIGNUM *a, int n)
734 } 729 }
735 730
736 a->d[i]|=(((BN_ULONG)1)<<j); 731 a->d[i]|=(((BN_ULONG)1)<<j);
737 bn_check_top(a);
738 return(1); 732 return(1);
739 } 733 }
740 734
@@ -742,15 +736,12 @@ int BN_clear_bit(BIGNUM *a, int n)
742 { 736 {
743 int i,j; 737 int i,j;
744 738
745 bn_check_top(a);
746 if (n < 0) return 0;
747
748 i=n/BN_BITS2; 739 i=n/BN_BITS2;
749 j=n%BN_BITS2; 740 j=n%BN_BITS2;
750 if (a->top <= i) return(0); 741 if (a->top <= i) return(0);
751 742
752 a->d[i]&=(~(((BN_ULONG)1)<<j)); 743 a->d[i]&=(~(((BN_ULONG)1)<<j));
753 bn_correct_top(a); 744 bn_fix_top(a);
754 return(1); 745 return(1);
755 } 746 }
756 747
@@ -758,24 +749,20 @@ int BN_is_bit_set(const BIGNUM *a, int n)
758 { 749 {
759 int i,j; 750 int i,j;
760 751
761 bn_check_top(a); 752 if (n < 0) return(0);
762 if (n < 0) return 0;
763 i=n/BN_BITS2; 753 i=n/BN_BITS2;
764 j=n%BN_BITS2; 754 j=n%BN_BITS2;
765 if (a->top <= i) return 0; 755 if (a->top <= i) return(0);
766 return(((a->d[i])>>j)&((BN_ULONG)1)); 756 return((a->d[i]&(((BN_ULONG)1)<<j))?1:0);
767 } 757 }
768 758
769int BN_mask_bits(BIGNUM *a, int n) 759int BN_mask_bits(BIGNUM *a, int n)
770 { 760 {
771 int b,w; 761 int b,w;
772 762
773 bn_check_top(a);
774 if (n < 0) return 0;
775
776 w=n/BN_BITS2; 763 w=n/BN_BITS2;
777 b=n%BN_BITS2; 764 b=n%BN_BITS2;
778 if (w >= a->top) return 0; 765 if (w >= a->top) return(0);
779 if (b == 0) 766 if (b == 0)
780 a->top=w; 767 a->top=w;
781 else 768 else
@@ -783,18 +770,10 @@ int BN_mask_bits(BIGNUM *a, int n)
783 a->top=w+1; 770 a->top=w+1;
784 a->d[w]&= ~(BN_MASK2<<b); 771 a->d[w]&= ~(BN_MASK2<<b);
785 } 772 }
786 bn_correct_top(a); 773 bn_fix_top(a);
787 return(1); 774 return(1);
788 } 775 }
789 776
790void BN_set_negative(BIGNUM *a, int b)
791 {
792 if (b && !BN_is_zero(a))
793 a->neg = 1;
794 else
795 a->neg = 0;
796 }
797
798int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n) 777int bn_cmp_words(const BN_ULONG *a, const BN_ULONG *b, int n)
799 { 778 {
800 int i; 779 int i;
diff --git a/src/lib/libcrypto/bn/bn_mod.c b/src/lib/libcrypto/bn/bn_mod.c
index 77d6ddb91a..5cf82480d7 100644
--- a/src/lib/libcrypto/bn/bn_mod.c
+++ b/src/lib/libcrypto/bn/bn_mod.c
@@ -149,7 +149,7 @@ int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_
149 * and less than m */ 149 * and less than m */
150int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m) 150int BN_mod_add_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m)
151 { 151 {
152 if (!BN_uadd(r, a, b)) return 0; 152 if (!BN_add(r, a, b)) return 0;
153 if (BN_ucmp(r, m) >= 0) 153 if (BN_ucmp(r, m) >= 0)
154 return BN_usub(r, r, m); 154 return BN_usub(r, r, m);
155 return 1; 155 return 1;
@@ -192,7 +192,6 @@ int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
192 else 192 else
193 { if (!BN_mul(t,a,b,ctx)) goto err; } 193 { if (!BN_mul(t,a,b,ctx)) goto err; }
194 if (!BN_nnmod(r,t,m,ctx)) goto err; 194 if (!BN_nnmod(r,t,m,ctx)) goto err;
195 bn_check_top(r);
196 ret=1; 195 ret=1;
197err: 196err:
198 BN_CTX_end(ctx); 197 BN_CTX_end(ctx);
@@ -211,7 +210,6 @@ int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
211int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx) 210int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
212 { 211 {
213 if (!BN_lshift1(r, a)) return 0; 212 if (!BN_lshift1(r, a)) return 0;
214 bn_check_top(r);
215 return BN_nnmod(r, r, m, ctx); 213 return BN_nnmod(r, r, m, ctx);
216 } 214 }
217 215
@@ -221,7 +219,6 @@ int BN_mod_lshift1(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
221int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m) 219int BN_mod_lshift1_quick(BIGNUM *r, const BIGNUM *a, const BIGNUM *m)
222 { 220 {
223 if (!BN_lshift1(r, a)) return 0; 221 if (!BN_lshift1(r, a)) return 0;
224 bn_check_top(r);
225 if (BN_cmp(r, m) >= 0) 222 if (BN_cmp(r, m) >= 0)
226 return BN_sub(r, r, m); 223 return BN_sub(r, r, m);
227 return 1; 224 return 1;
@@ -243,7 +240,6 @@ int BN_mod_lshift(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m, BN_CTX *ct
243 } 240 }
244 241
245 ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m)); 242 ret = BN_mod_lshift_quick(r, r, n, (abs_m ? abs_m : m));
246 bn_check_top(r);
247 243
248 if (abs_m) 244 if (abs_m)
249 BN_free(abs_m); 245 BN_free(abs_m);
@@ -295,7 +291,6 @@ int BN_mod_lshift_quick(BIGNUM *r, const BIGNUM *a, int n, const BIGNUM *m)
295 if (!BN_sub(r, r, m)) return 0; 291 if (!BN_sub(r, r, m)) return 0;
296 } 292 }
297 } 293 }
298 bn_check_top(r);
299 294
300 return 1; 295 return 1;
301 } 296 }
diff --git a/src/lib/libcrypto/bn/bn_mont.c b/src/lib/libcrypto/bn/bn_mont.c
index 4799b152dd..726d5f2b1b 100644
--- a/src/lib/libcrypto/bn/bn_mont.c
+++ b/src/lib/libcrypto/bn/bn_mont.c
@@ -55,59 +55,6 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111 58
112/* 59/*
113 * Details about Montgomery multiplication algorithms can be found at 60 * Details about Montgomery multiplication algorithms can be found at
@@ -122,50 +69,11 @@
122 69
123#define MONT_WORD /* use the faster word-based algorithm */ 70#define MONT_WORD /* use the faster word-based algorithm */
124 71
125#if defined(MONT_WORD) && defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)
126/* This condition means we have a specific non-default build:
127 * In the 0.9.8 branch, OPENSSL_BN_ASM_MONT is normally not set for any
128 * BN_BITS2<=32 platform; an explicit "enable-montasm" is required.
129 * I.e., if we are here, the user intentionally deviates from the
130 * normal stable build to get better Montgomery performance from
131 * the 0.9.9-dev backport.
132 *
133 * In this case only, we also enable BN_from_montgomery_word()
134 * (another non-stable feature from 0.9.9-dev).
135 */
136#define MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
137#endif
138
139#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
140static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont);
141#endif
142
143
144
145int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, 72int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
146 BN_MONT_CTX *mont, BN_CTX *ctx) 73 BN_MONT_CTX *mont, BN_CTX *ctx)
147 { 74 {
148 BIGNUM *tmp; 75 BIGNUM *tmp;
149 int ret=0; 76 int ret=0;
150#if defined(OPENSSL_BN_ASM_MONT) && defined(MONT_WORD)
151 int num = mont->N.top;
152
153 if (num>1 && a->top==num && b->top==num)
154 {
155 if (bn_wexpand(r,num) == NULL) return(0);
156#if 0 /* for OpenSSL 0.9.9 mont->n0 */
157 if (bn_mul_mont(r->d,a->d,b->d,mont->N.d,mont->n0,num))
158#else
159 if (bn_mul_mont(r->d,a->d,b->d,mont->N.d,&mont->n0,num))
160#endif
161 {
162 r->neg = a->neg^b->neg;
163 r->top = num;
164 bn_correct_top(r);
165 return(1);
166 }
167 }
168#endif
169 77
170 BN_CTX_start(ctx); 78 BN_CTX_start(ctx);
171 tmp = BN_CTX_get(ctx); 79 tmp = BN_CTX_get(ctx);
@@ -181,162 +89,13 @@ int BN_mod_mul_montgomery(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
181 if (!BN_mul(tmp,a,b,ctx)) goto err; 89 if (!BN_mul(tmp,a,b,ctx)) goto err;
182 } 90 }
183 /* reduce from aRR to aR */ 91 /* reduce from aRR to aR */
184#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
185 if (!BN_from_montgomery_word(r,tmp,mont)) goto err;
186#else
187 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err; 92 if (!BN_from_montgomery(r,tmp,mont,ctx)) goto err;
188#endif
189 bn_check_top(r);
190 ret=1; 93 ret=1;
191err: 94err:
192 BN_CTX_end(ctx); 95 BN_CTX_end(ctx);
193 return(ret); 96 return(ret);
194 } 97 }
195 98
196#ifdef MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD
197static int BN_from_montgomery_word(BIGNUM *ret, BIGNUM *r, BN_MONT_CTX *mont)
198 {
199 BIGNUM *n;
200 BN_ULONG *ap,*np,*rp,n0,v,*nrp;
201 int al,nl,max,i,x,ri;
202
203 n= &(mont->N);
204 /* mont->ri is the size of mont->N in bits (rounded up
205 to the word size) */
206 al=ri=mont->ri/BN_BITS2;
207
208 nl=n->top;
209 if ((al == 0) || (nl == 0)) { ret->top=0; return(1); }
210
211 max=(nl+al+1); /* allow for overflow (no?) XXX */
212 if (bn_wexpand(r,max) == NULL) return(0);
213
214 r->neg^=n->neg;
215 np=n->d;
216 rp=r->d;
217 nrp= &(r->d[nl]);
218
219 /* clear the top words of T */
220 for (i=r->top; i<max; i++) /* memset? XXX */
221 r->d[i]=0;
222
223 r->top=max;
224#if 0 /* for OpenSSL 0.9.9 mont->n0 */
225 n0=mont->n0[0];
226#else
227 n0=mont->n0;
228#endif
229
230#ifdef BN_COUNT
231 fprintf(stderr,"word BN_from_montgomery_word %d * %d\n",nl,nl);
232#endif
233 for (i=0; i<nl; i++)
234 {
235#ifdef __TANDEM
236 {
237 long long t1;
238 long long t2;
239 long long t3;
240 t1 = rp[0] * (n0 & 0177777);
241 t2 = 037777600000l;
242 t2 = n0 & t2;
243 t3 = rp[0] & 0177777;
244 t2 = (t3 * t2) & BN_MASK2;
245 t1 = t1 + t2;
246 v=bn_mul_add_words(rp,np,nl,(BN_ULONG) t1);
247 }
248#else
249 v=bn_mul_add_words(rp,np,nl,(rp[0]*n0)&BN_MASK2);
250#endif
251 nrp++;
252 rp++;
253 if (((nrp[-1]+=v)&BN_MASK2) >= v)
254 continue;
255 else
256 {
257 if (((++nrp[0])&BN_MASK2) != 0) continue;
258 if (((++nrp[1])&BN_MASK2) != 0) continue;
259 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
260 }
261 }
262 bn_correct_top(r);
263
264 /* mont->ri will be a multiple of the word size and below code
265 * is kind of BN_rshift(ret,r,mont->ri) equivalent */
266 if (r->top <= ri)
267 {
268 ret->top=0;
269 return(1);
270 }
271 al=r->top-ri;
272
273 if (bn_wexpand(ret,ri) == NULL) return(0);
274 x=0-(((al-ri)>>(sizeof(al)*8-1))&1);
275 ret->top=x=(ri&~x)|(al&x); /* min(ri,al) */
276 ret->neg=r->neg;
277
278 rp=ret->d;
279 ap=&(r->d[ri]);
280
281 {
282 size_t m1,m2;
283
284 v=bn_sub_words(rp,ap,np,ri);
285 /* this ----------------^^ works even in al<ri case
286 * thanks to zealous zeroing of top of the vector in the
287 * beginning. */
288
289 /* if (al==ri && !v) || al>ri) nrp=rp; else nrp=ap; */
290 /* in other words if subtraction result is real, then
291 * trick unconditional memcpy below to perform in-place
292 * "refresh" instead of actual copy. */
293 m1=0-(size_t)(((al-ri)>>(sizeof(al)*8-1))&1); /* al<ri */
294 m2=0-(size_t)(((ri-al)>>(sizeof(al)*8-1))&1); /* al>ri */
295 m1|=m2; /* (al!=ri) */
296 m1|=(0-(size_t)v); /* (al!=ri || v) */
297 m1&=~m2; /* (al!=ri || v) && !al>ri */
298 nrp=(BN_ULONG *)(((size_t)rp&~m1)|((size_t)ap&m1));
299 }
300
301 /* 'i<ri' is chosen to eliminate dependency on input data, even
302 * though it results in redundant copy in al<ri case. */
303 for (i=0,ri-=4; i<ri; i+=4)
304 {
305 BN_ULONG t1,t2,t3,t4;
306
307 t1=nrp[i+0];
308 t2=nrp[i+1];
309 t3=nrp[i+2]; ap[i+0]=0;
310 t4=nrp[i+3]; ap[i+1]=0;
311 rp[i+0]=t1; ap[i+2]=0;
312 rp[i+1]=t2; ap[i+3]=0;
313 rp[i+2]=t3;
314 rp[i+3]=t4;
315 }
316 for (ri+=4; i<ri; i++)
317 rp[i]=nrp[i], ap[i]=0;
318 bn_correct_top(r);
319 bn_correct_top(ret);
320 bn_check_top(ret);
321
322 return(1);
323 }
324
325int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
326 BN_CTX *ctx)
327 {
328 int retn=0;
329 BIGNUM *t;
330
331 BN_CTX_start(ctx);
332 if ((t = BN_CTX_get(ctx)) && BN_copy(t,a))
333 retn = BN_from_montgomery_word(ret,t,mont);
334 BN_CTX_end(ctx);
335 return retn;
336 }
337
338#else /* !MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD */
339
340int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont, 99int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
341 BN_CTX *ctx) 100 BN_CTX *ctx)
342 { 101 {
@@ -412,7 +171,7 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
412 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ; 171 for (x=2; (((++nrp[x])&BN_MASK2) == 0); x++) ;
413 } 172 }
414 } 173 }
415 bn_correct_top(r); 174 bn_fix_top(r);
416 175
417 /* mont->ri will be a multiple of the word size and below code 176 /* mont->ri will be a multiple of the word size and below code
418 * is kind of BN_rshift(ret,r,mont->ri) equivalent */ 177 * is kind of BN_rshift(ret,r,mont->ri) equivalent */
@@ -471,8 +230,6 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
471 } 230 }
472 for (ri+=4; i<ri; i++) 231 for (ri+=4; i<ri; i++)
473 rp[i]=nrp[i], ap[i]=0; 232 rp[i]=nrp[i], ap[i]=0;
474 bn_correct_top(r);
475 bn_correct_top(ret);
476# else 233# else
477 if (bn_wexpand(ret,al) == NULL) goto err; 234 if (bn_wexpand(ret,al) == NULL) goto err;
478 ret->top=al; 235 ret->top=al;
@@ -524,12 +281,10 @@ int BN_from_montgomery(BIGNUM *ret, const BIGNUM *a, BN_MONT_CTX *mont,
524 } 281 }
525#endif 282#endif
526 retn=1; 283 retn=1;
527 bn_check_top(ret);
528 err: 284 err:
529 BN_CTX_end(ctx); 285 BN_CTX_end(ctx);
530 return(retn); 286 return(retn);
531 } 287 }
532#endif /* MONT_FROM_WORD___NON_DEFAULT_0_9_8_BUILD */
533 288
534BN_MONT_CTX *BN_MONT_CTX_new(void) 289BN_MONT_CTX *BN_MONT_CTX_new(void)
535 { 290 {
@@ -549,11 +304,6 @@ void BN_MONT_CTX_init(BN_MONT_CTX *ctx)
549 BN_init(&(ctx->RR)); 304 BN_init(&(ctx->RR));
550 BN_init(&(ctx->N)); 305 BN_init(&(ctx->N));
551 BN_init(&(ctx->Ni)); 306 BN_init(&(ctx->Ni));
552#if 0 /* for OpenSSL 0.9.9 mont->n0 */
553 ctx->n0[0] = ctx->n0[1] = 0;
554#else
555 ctx->n0 = 0;
556#endif
557 ctx->flags=0; 307 ctx->flags=0;
558 } 308 }
559 309
@@ -571,11 +321,9 @@ void BN_MONT_CTX_free(BN_MONT_CTX *mont)
571 321
572int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx) 322int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
573 { 323 {
574 int ret = 0; 324 BIGNUM Ri,*R;
575 BIGNUM *Ri,*R;
576 325
577 BN_CTX_start(ctx); 326 BN_init(&Ri);
578 if((Ri = BN_CTX_get(ctx)) == NULL) goto err;
579 R= &(mont->RR); /* grab RR as a temp */ 327 R= &(mont->RR); /* grab RR as a temp */
580 if (!BN_copy(&(mont->N),mod)) goto err; /* Set N */ 328 if (!BN_copy(&(mont->N),mod)) goto err; /* Set N */
581 mont->N.neg = 0; 329 mont->N.neg = 0;
@@ -586,99 +334,57 @@ int BN_MONT_CTX_set(BN_MONT_CTX *mont, const BIGNUM *mod, BN_CTX *ctx)
586 BN_ULONG buf[2]; 334 BN_ULONG buf[2];
587 335
588 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2; 336 mont->ri=(BN_num_bits(mod)+(BN_BITS2-1))/BN_BITS2*BN_BITS2;
589 BN_zero(R); 337 if (!(BN_zero(R))) goto err;
590#if 0 /* for OpenSSL 0.9.9 mont->n0, would be "#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)",
591 only certain BN_BITS2<=32 platforms actually need this */
592 if (!(BN_set_bit(R,2*BN_BITS2))) goto err; /* R */
593#else
594 if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */ 338 if (!(BN_set_bit(R,BN_BITS2))) goto err; /* R */
595#endif
596 339
597 buf[0]=mod->d[0]; /* tmod = N mod word size */ 340 buf[0]=mod->d[0]; /* tmod = N mod word size */
598 buf[1]=0; 341 buf[1]=0;
599
600 BN_init(&tmod);
601 tmod.d=buf; 342 tmod.d=buf;
602 tmod.top = buf[0] != 0 ? 1 : 0; 343 tmod.top=1;
603 tmod.dmax=2; 344 tmod.dmax=2;
604 tmod.neg=0; 345 tmod.neg=0;
605
606#if 0 /* for OpenSSL 0.9.9 mont->n0, would be "#if defined(OPENSSL_BN_ASM_MONT) && (BN_BITS2<=32)";
607 only certain BN_BITS2<=32 platforms actually need this */
608 tmod.top=0;
609 if ((buf[0] = mod->d[0])) tmod.top=1;
610 if ((buf[1] = mod->top>1 ? mod->d[1] : 0)) tmod.top=2;
611
612 if ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL)
613 goto err;
614 if (!BN_lshift(Ri,Ri,2*BN_BITS2)) goto err; /* R*Ri */
615 if (!BN_is_zero(Ri))
616 {
617 if (!BN_sub_word(Ri,1)) goto err;
618 }
619 else /* if N mod word size == 1 */
620 {
621 if (bn_expand(Ri,(int)sizeof(BN_ULONG)*2) == NULL)
622 goto err;
623 /* Ri-- (mod double word size) */
624 Ri->neg=0;
625 Ri->d[0]=BN_MASK2;
626 Ri->d[1]=BN_MASK2;
627 Ri->top=2;
628 }
629 if (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err;
630 /* Ni = (R*Ri-1)/N,
631 * keep only couple of least significant words: */
632 mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0;
633 mont->n0[1] = (Ri->top > 1) ? Ri->d[1] : 0;
634#else
635 /* Ri = R^-1 mod N*/ 346 /* Ri = R^-1 mod N*/
636 if ((BN_mod_inverse(Ri,R,&tmod,ctx)) == NULL) 347 if ((BN_mod_inverse(&Ri,R,&tmod,ctx)) == NULL)
637 goto err; 348 goto err;
638 if (!BN_lshift(Ri,Ri,BN_BITS2)) goto err; /* R*Ri */ 349 if (!BN_lshift(&Ri,&Ri,BN_BITS2)) goto err; /* R*Ri */
639 if (!BN_is_zero(Ri)) 350 if (!BN_is_zero(&Ri))
640 { 351 {
641 if (!BN_sub_word(Ri,1)) goto err; 352 if (!BN_sub_word(&Ri,1)) goto err;
642 } 353 }
643 else /* if N mod word size == 1 */ 354 else /* if N mod word size == 1 */
644 { 355 {
645 if (!BN_set_word(Ri,BN_MASK2)) goto err; /* Ri-- (mod word size) */ 356 if (!BN_set_word(&Ri,BN_MASK2)) goto err; /* Ri-- (mod word size) */
646 } 357 }
647 if (!BN_div(Ri,NULL,Ri,&tmod,ctx)) goto err; 358 if (!BN_div(&Ri,NULL,&Ri,&tmod,ctx)) goto err;
648 /* Ni = (R*Ri-1)/N, 359 /* Ni = (R*Ri-1)/N,
649 * keep only least significant word: */ 360 * keep only least significant word: */
650# if 0 /* for OpenSSL 0.9.9 mont->n0 */ 361 mont->n0 = (Ri.top > 0) ? Ri.d[0] : 0;
651 mont->n0[0] = (Ri->top > 0) ? Ri->d[0] : 0; 362 BN_free(&Ri);
652 mont->n0[1] = 0;
653# else
654 mont->n0 = (Ri->top > 0) ? Ri->d[0] : 0;
655# endif
656#endif
657 } 363 }
658#else /* !MONT_WORD */ 364#else /* !MONT_WORD */
659 { /* bignum version */ 365 { /* bignum version */
660 mont->ri=BN_num_bits(&mont->N); 366 mont->ri=BN_num_bits(&mont->N);
661 BN_zero(R); 367 if (!BN_zero(R)) goto err;
662 if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */ 368 if (!BN_set_bit(R,mont->ri)) goto err; /* R = 2^ri */
663 /* Ri = R^-1 mod N*/ 369 /* Ri = R^-1 mod N*/
664 if ((BN_mod_inverse(Ri,R,&mont->N,ctx)) == NULL) 370 if ((BN_mod_inverse(&Ri,R,&mont->N,ctx)) == NULL)
665 goto err; 371 goto err;
666 if (!BN_lshift(Ri,Ri,mont->ri)) goto err; /* R*Ri */ 372 if (!BN_lshift(&Ri,&Ri,mont->ri)) goto err; /* R*Ri */
667 if (!BN_sub_word(Ri,1)) goto err; 373 if (!BN_sub_word(&Ri,1)) goto err;
668 /* Ni = (R*Ri-1) / N */ 374 /* Ni = (R*Ri-1) / N */
669 if (!BN_div(&(mont->Ni),NULL,Ri,&mont->N,ctx)) goto err; 375 if (!BN_div(&(mont->Ni),NULL,&Ri,&mont->N,ctx)) goto err;
376 BN_free(&Ri);
670 } 377 }
671#endif 378#endif
672 379
673 /* setup RR for conversions */ 380 /* setup RR for conversions */
674 BN_zero(&(mont->RR)); 381 if (!BN_zero(&(mont->RR))) goto err;
675 if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err; 382 if (!BN_set_bit(&(mont->RR),mont->ri*2)) goto err;
676 if (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err; 383 if (!BN_mod(&(mont->RR),&(mont->RR),&(mont->N),ctx)) goto err;
677 384
678 ret = 1; 385 return(1);
679err: 386err:
680 BN_CTX_end(ctx); 387 return(0);
681 return ret;
682 } 388 }
683 389
684BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from) 390BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
@@ -689,44 +395,27 @@ BN_MONT_CTX *BN_MONT_CTX_copy(BN_MONT_CTX *to, BN_MONT_CTX *from)
689 if (!BN_copy(&(to->N),&(from->N))) return NULL; 395 if (!BN_copy(&(to->N),&(from->N))) return NULL;
690 if (!BN_copy(&(to->Ni),&(from->Ni))) return NULL; 396 if (!BN_copy(&(to->Ni),&(from->Ni))) return NULL;
691 to->ri=from->ri; 397 to->ri=from->ri;
692#if 0 /* for OpenSSL 0.9.9 mont->n0 */
693 to->n0[0]=from->n0[0];
694 to->n0[1]=from->n0[1];
695#else
696 to->n0=from->n0; 398 to->n0=from->n0;
697#endif
698 return(to); 399 return(to);
699 } 400 }
700 401
701BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock, 402BN_MONT_CTX *BN_MONT_CTX_set_locked(BN_MONT_CTX **pmont, int lock,
702 const BIGNUM *mod, BN_CTX *ctx) 403 const BIGNUM *mod, BN_CTX *ctx)
703 { 404 {
704 int got_write_lock = 0; 405 if (*pmont)
705 BN_MONT_CTX *ret; 406 return *pmont;
706 407 CRYPTO_w_lock(lock);
707 CRYPTO_r_lock(lock);
708 if (!*pmont) 408 if (!*pmont)
709 { 409 {
710 CRYPTO_r_unlock(lock); 410 *pmont = BN_MONT_CTX_new();
711 CRYPTO_w_lock(lock); 411 if (*pmont && !BN_MONT_CTX_set(*pmont, mod, ctx))
712 got_write_lock = 1;
713
714 if (!*pmont)
715 { 412 {
716 ret = BN_MONT_CTX_new(); 413 BN_MONT_CTX_free(*pmont);
717 if (ret && !BN_MONT_CTX_set(ret, mod, ctx)) 414 *pmont = NULL;
718 BN_MONT_CTX_free(ret);
719 else
720 *pmont = ret;
721 } 415 }
722 } 416 }
723 417 CRYPTO_w_unlock(lock);
724 ret = *pmont; 418 return *pmont;
725
726 if (got_write_lock)
727 CRYPTO_w_unlock(lock);
728 else
729 CRYPTO_r_unlock(lock);
730
731 return ret;
732 } 419 }
420
421
diff --git a/src/lib/libcrypto/bn/bn_mpi.c b/src/lib/libcrypto/bn/bn_mpi.c
index a054d21aed..05fa9d1e9a 100644
--- a/src/lib/libcrypto/bn/bn_mpi.c
+++ b/src/lib/libcrypto/bn/bn_mpi.c
@@ -124,7 +124,6 @@ BIGNUM *BN_mpi2bn(const unsigned char *d, int n, BIGNUM *a)
124 { 124 {
125 BN_clear_bit(a,BN_num_bits(a)-1); 125 BN_clear_bit(a,BN_num_bits(a)-1);
126 } 126 }
127 bn_check_top(a);
128 return(a); 127 return(a);
129 } 128 }
130 129
diff --git a/src/lib/libcrypto/bn/bn_mul.c b/src/lib/libcrypto/bn/bn_mul.c
index b848c8cc60..3ae3822bc2 100644
--- a/src/lib/libcrypto/bn/bn_mul.c
+++ b/src/lib/libcrypto/bn/bn_mul.c
@@ -56,325 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef BN_DEBUG
60# undef NDEBUG /* avoid conflicting definitions */
61# define NDEBUG
62#endif
63
64#include <stdio.h> 59#include <stdio.h>
65#include <assert.h>
66#include "cryptlib.h" 60#include "cryptlib.h"
67#include "bn_lcl.h" 61#include "bn_lcl.h"
68 62
69#if defined(OPENSSL_NO_ASM) || !defined(OPENSSL_BN_ASM_PART_WORDS)
70/* Here follows specialised variants of bn_add_words() and
71 bn_sub_words(). They have the property performing operations on
72 arrays of different sizes. The sizes of those arrays is expressed through
73 cl, which is the common length ( basicall, min(len(a),len(b)) ), and dl,
74 which is the delta between the two lengths, calculated as len(a)-len(b).
75 All lengths are the number of BN_ULONGs... For the operations that require
76 a result array as parameter, it must have the length cl+abs(dl).
77 These functions should probably end up in bn_asm.c as soon as there are
78 assembler counterparts for the systems that use assembler files. */
79
80BN_ULONG bn_sub_part_words(BN_ULONG *r,
81 const BN_ULONG *a, const BN_ULONG *b,
82 int cl, int dl)
83 {
84 BN_ULONG c, t;
85
86 assert(cl >= 0);
87 c = bn_sub_words(r, a, b, cl);
88
89 if (dl == 0)
90 return c;
91
92 r += cl;
93 a += cl;
94 b += cl;
95
96 if (dl < 0)
97 {
98#ifdef BN_COUNT
99 fprintf(stderr, " bn_sub_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c);
100#endif
101 for (;;)
102 {
103 t = b[0];
104 r[0] = (0-t-c)&BN_MASK2;
105 if (t != 0) c=1;
106 if (++dl >= 0) break;
107
108 t = b[1];
109 r[1] = (0-t-c)&BN_MASK2;
110 if (t != 0) c=1;
111 if (++dl >= 0) break;
112
113 t = b[2];
114 r[2] = (0-t-c)&BN_MASK2;
115 if (t != 0) c=1;
116 if (++dl >= 0) break;
117
118 t = b[3];
119 r[3] = (0-t-c)&BN_MASK2;
120 if (t != 0) c=1;
121 if (++dl >= 0) break;
122
123 b += 4;
124 r += 4;
125 }
126 }
127 else
128 {
129 int save_dl = dl;
130#ifdef BN_COUNT
131 fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c = %d)\n", cl, dl, c);
132#endif
133 while(c)
134 {
135 t = a[0];
136 r[0] = (t-c)&BN_MASK2;
137 if (t != 0) c=0;
138 if (--dl <= 0) break;
139
140 t = a[1];
141 r[1] = (t-c)&BN_MASK2;
142 if (t != 0) c=0;
143 if (--dl <= 0) break;
144
145 t = a[2];
146 r[2] = (t-c)&BN_MASK2;
147 if (t != 0) c=0;
148 if (--dl <= 0) break;
149
150 t = a[3];
151 r[3] = (t-c)&BN_MASK2;
152 if (t != 0) c=0;
153 if (--dl <= 0) break;
154
155 save_dl = dl;
156 a += 4;
157 r += 4;
158 }
159 if (dl > 0)
160 {
161#ifdef BN_COUNT
162 fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, c == 0)\n", cl, dl);
163#endif
164 if (save_dl > dl)
165 {
166 switch (save_dl - dl)
167 {
168 case 1:
169 r[1] = a[1];
170 if (--dl <= 0) break;
171 case 2:
172 r[2] = a[2];
173 if (--dl <= 0) break;
174 case 3:
175 r[3] = a[3];
176 if (--dl <= 0) break;
177 }
178 a += 4;
179 r += 4;
180 }
181 }
182 if (dl > 0)
183 {
184#ifdef BN_COUNT
185 fprintf(stderr, " bn_sub_part_words %d + %d (dl > 0, copy)\n", cl, dl);
186#endif
187 for(;;)
188 {
189 r[0] = a[0];
190 if (--dl <= 0) break;
191 r[1] = a[1];
192 if (--dl <= 0) break;
193 r[2] = a[2];
194 if (--dl <= 0) break;
195 r[3] = a[3];
196 if (--dl <= 0) break;
197
198 a += 4;
199 r += 4;
200 }
201 }
202 }
203 return c;
204 }
205#endif
206
207BN_ULONG bn_add_part_words(BN_ULONG *r,
208 const BN_ULONG *a, const BN_ULONG *b,
209 int cl, int dl)
210 {
211 BN_ULONG c, l, t;
212
213 assert(cl >= 0);
214 c = bn_add_words(r, a, b, cl);
215
216 if (dl == 0)
217 return c;
218
219 r += cl;
220 a += cl;
221 b += cl;
222
223 if (dl < 0)
224 {
225 int save_dl = dl;
226#ifdef BN_COUNT
227 fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, c = %d)\n", cl, dl, c);
228#endif
229 while (c)
230 {
231 l=(c+b[0])&BN_MASK2;
232 c=(l < c);
233 r[0]=l;
234 if (++dl >= 0) break;
235
236 l=(c+b[1])&BN_MASK2;
237 c=(l < c);
238 r[1]=l;
239 if (++dl >= 0) break;
240
241 l=(c+b[2])&BN_MASK2;
242 c=(l < c);
243 r[2]=l;
244 if (++dl >= 0) break;
245
246 l=(c+b[3])&BN_MASK2;
247 c=(l < c);
248 r[3]=l;
249 if (++dl >= 0) break;
250
251 save_dl = dl;
252 b+=4;
253 r+=4;
254 }
255 if (dl < 0)
256 {
257#ifdef BN_COUNT
258 fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, c == 0)\n", cl, dl);
259#endif
260 if (save_dl < dl)
261 {
262 switch (dl - save_dl)
263 {
264 case 1:
265 r[1] = b[1];
266 if (++dl >= 0) break;
267 case 2:
268 r[2] = b[2];
269 if (++dl >= 0) break;
270 case 3:
271 r[3] = b[3];
272 if (++dl >= 0) break;
273 }
274 b += 4;
275 r += 4;
276 }
277 }
278 if (dl < 0)
279 {
280#ifdef BN_COUNT
281 fprintf(stderr, " bn_add_part_words %d + %d (dl < 0, copy)\n", cl, dl);
282#endif
283 for(;;)
284 {
285 r[0] = b[0];
286 if (++dl >= 0) break;
287 r[1] = b[1];
288 if (++dl >= 0) break;
289 r[2] = b[2];
290 if (++dl >= 0) break;
291 r[3] = b[3];
292 if (++dl >= 0) break;
293
294 b += 4;
295 r += 4;
296 }
297 }
298 }
299 else
300 {
301 int save_dl = dl;
302#ifdef BN_COUNT
303 fprintf(stderr, " bn_add_part_words %d + %d (dl > 0)\n", cl, dl);
304#endif
305 while (c)
306 {
307 t=(a[0]+c)&BN_MASK2;
308 c=(t < c);
309 r[0]=t;
310 if (--dl <= 0) break;
311
312 t=(a[1]+c)&BN_MASK2;
313 c=(t < c);
314 r[1]=t;
315 if (--dl <= 0) break;
316
317 t=(a[2]+c)&BN_MASK2;
318 c=(t < c);
319 r[2]=t;
320 if (--dl <= 0) break;
321
322 t=(a[3]+c)&BN_MASK2;
323 c=(t < c);
324 r[3]=t;
325 if (--dl <= 0) break;
326
327 save_dl = dl;
328 a+=4;
329 r+=4;
330 }
331#ifdef BN_COUNT
332 fprintf(stderr, " bn_add_part_words %d + %d (dl > 0, c == 0)\n", cl, dl);
333#endif
334 if (dl > 0)
335 {
336 if (save_dl > dl)
337 {
338 switch (save_dl - dl)
339 {
340 case 1:
341 r[1] = a[1];
342 if (--dl <= 0) break;
343 case 2:
344 r[2] = a[2];
345 if (--dl <= 0) break;
346 case 3:
347 r[3] = a[3];
348 if (--dl <= 0) break;
349 }
350 a += 4;
351 r += 4;
352 }
353 }
354 if (dl > 0)
355 {
356#ifdef BN_COUNT
357 fprintf(stderr, " bn_add_part_words %d + %d (dl > 0, copy)\n", cl, dl);
358#endif
359 for(;;)
360 {
361 r[0] = a[0];
362 if (--dl <= 0) break;
363 r[1] = a[1];
364 if (--dl <= 0) break;
365 r[2] = a[2];
366 if (--dl <= 0) break;
367 r[3] = a[3];
368 if (--dl <= 0) break;
369
370 a += 4;
371 r += 4;
372 }
373 }
374 }
375 return c;
376 }
377
378#ifdef BN_RECURSION 63#ifdef BN_RECURSION
379/* Karatsuba recursive multiplication algorithm 64/* Karatsuba recursive multiplication algorithm
380 * (cf. Knuth, The Art of Computer Programming, Vol. 2) */ 65 * (cf. Knuth, The Art of Computer Programming, Vol. 2) */
@@ -389,17 +74,15 @@ BN_ULONG bn_add_part_words(BN_ULONG *r,
389 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0]) 74 * a[0]*b[0]+a[1]*b[1]+(a[0]-a[1])*(b[1]-b[0])
390 * a[1]*b[1] 75 * a[1]*b[1]
391 */ 76 */
392/* dnX may not be positive, but n2/2+dnX has to be */
393void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2, 77void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
394 int dna, int dnb, BN_ULONG *t) 78 BN_ULONG *t)
395 { 79 {
396 int n=n2/2,c1,c2; 80 int n=n2/2,c1,c2;
397 int tna=n+dna, tnb=n+dnb;
398 unsigned int neg,zero; 81 unsigned int neg,zero;
399 BN_ULONG ln,lo,*p; 82 BN_ULONG ln,lo,*p;
400 83
401# ifdef BN_COUNT 84# ifdef BN_COUNT
402 fprintf(stderr," bn_mul_recursive %d%+d * %d%+d\n",n2,dna,n2,dnb); 85 printf(" bn_mul_recursive %d * %d\n",n2,n2);
403# endif 86# endif
404# ifdef BN_MUL_COMBA 87# ifdef BN_MUL_COMBA
405# if 0 88# if 0
@@ -409,40 +92,34 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
409 return; 92 return;
410 } 93 }
411# endif 94# endif
412 /* Only call bn_mul_comba 8 if n2 == 8 and the 95 if (n2 == 8)
413 * two arrays are complete [steve]
414 */
415 if (n2 == 8 && dna == 0 && dnb == 0)
416 { 96 {
417 bn_mul_comba8(r,a,b); 97 bn_mul_comba8(r,a,b);
418 return; 98 return;
419 } 99 }
420# endif /* BN_MUL_COMBA */ 100# endif /* BN_MUL_COMBA */
421 /* Else do normal multiply */
422 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) 101 if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL)
423 { 102 {
424 bn_mul_normal(r,a,n2+dna,b,n2+dnb); 103 /* This should not happen */
425 if ((dna + dnb) < 0) 104 bn_mul_normal(r,a,n2,b,n2);
426 memset(&r[2*n2 + dna + dnb], 0,
427 sizeof(BN_ULONG) * -(dna + dnb));
428 return; 105 return;
429 } 106 }
430 /* r=(a[0]-a[1])*(b[1]-b[0]) */ 107 /* r=(a[0]-a[1])*(b[1]-b[0]) */
431 c1=bn_cmp_part_words(a,&(a[n]),tna,n-tna); 108 c1=bn_cmp_words(a,&(a[n]),n);
432 c2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n); 109 c2=bn_cmp_words(&(b[n]),b,n);
433 zero=neg=0; 110 zero=neg=0;
434 switch (c1*3+c2) 111 switch (c1*3+c2)
435 { 112 {
436 case -4: 113 case -4:
437 bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ 114 bn_sub_words(t, &(a[n]),a, n); /* - */
438 bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ 115 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
439 break; 116 break;
440 case -3: 117 case -3:
441 zero=1; 118 zero=1;
442 break; 119 break;
443 case -2: 120 case -2:
444 bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ 121 bn_sub_words(t, &(a[n]),a, n); /* - */
445 bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); /* + */ 122 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
446 neg=1; 123 neg=1;
447 break; 124 break;
448 case -1: 125 case -1:
@@ -451,22 +128,21 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
451 zero=1; 128 zero=1;
452 break; 129 break;
453 case 2: 130 case 2:
454 bn_sub_part_words(t, a, &(a[n]),tna,n-tna); /* + */ 131 bn_sub_words(t, a, &(a[n]),n); /* + */
455 bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ 132 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
456 neg=1; 133 neg=1;
457 break; 134 break;
458 case 3: 135 case 3:
459 zero=1; 136 zero=1;
460 break; 137 break;
461 case 4: 138 case 4:
462 bn_sub_part_words(t, a, &(a[n]),tna,n-tna); 139 bn_sub_words(t, a, &(a[n]),n);
463 bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); 140 bn_sub_words(&(t[n]),&(b[n]),b, n);
464 break; 141 break;
465 } 142 }
466 143
467# ifdef BN_MUL_COMBA 144# ifdef BN_MUL_COMBA
468 if (n == 4 && dna == 0 && dnb == 0) /* XXX: bn_mul_comba4 could take 145 if (n == 4)
469 extra args to do this well */
470 { 146 {
471 if (!zero) 147 if (!zero)
472 bn_mul_comba4(&(t[n2]),t,&(t[n])); 148 bn_mul_comba4(&(t[n2]),t,&(t[n]));
@@ -476,9 +152,7 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
476 bn_mul_comba4(r,a,b); 152 bn_mul_comba4(r,a,b);
477 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n])); 153 bn_mul_comba4(&(r[n2]),&(a[n]),&(b[n]));
478 } 154 }
479 else if (n == 8 && dna == 0 && dnb == 0) /* XXX: bn_mul_comba8 could 155 else if (n == 8)
480 take extra args to do this
481 well */
482 { 156 {
483 if (!zero) 157 if (!zero)
484 bn_mul_comba8(&(t[n2]),t,&(t[n])); 158 bn_mul_comba8(&(t[n2]),t,&(t[n]));
@@ -493,11 +167,11 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
493 { 167 {
494 p= &(t[n2*2]); 168 p= &(t[n2*2]);
495 if (!zero) 169 if (!zero)
496 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p); 170 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
497 else 171 else
498 memset(&(t[n2]),0,n2*sizeof(BN_ULONG)); 172 memset(&(t[n2]),0,n2*sizeof(BN_ULONG));
499 bn_mul_recursive(r,a,b,n,0,0,p); 173 bn_mul_recursive(r,a,b,n,p);
500 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,dna,dnb,p); 174 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),n,p);
501 } 175 }
502 176
503 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign 177 /* t[32] holds (a[0]-a[1])*(b[1]-b[0]), c1 is the sign
@@ -546,40 +220,39 @@ void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
546 220
547/* n+tn is the word length 221/* n+tn is the word length
548 * t needs to be n*4 is size, as does r */ 222 * t needs to be n*4 is size, as does r */
549/* tnX may not be negative but less than n */ 223void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int tn,
550void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n, 224 int n, BN_ULONG *t)
551 int tna, int tnb, BN_ULONG *t)
552 { 225 {
553 int i,j,n2=n*2; 226 int i,j,n2=n*2;
554 int c1,c2,neg,zero; 227 int c1,c2,neg,zero;
555 BN_ULONG ln,lo,*p; 228 BN_ULONG ln,lo,*p;
556 229
557# ifdef BN_COUNT 230# ifdef BN_COUNT
558 fprintf(stderr," bn_mul_part_recursive (%d%+d) * (%d%+d)\n", 231 printf(" bn_mul_part_recursive %d * %d\n",tn+n,tn+n);
559 n, tna, n, tnb);
560# endif 232# endif
561 if (n < 8) 233 if (n < 8)
562 { 234 {
563 bn_mul_normal(r,a,n+tna,b,n+tnb); 235 i=tn+n;
236 bn_mul_normal(r,a,i,b,i);
564 return; 237 return;
565 } 238 }
566 239
567 /* r=(a[0]-a[1])*(b[1]-b[0]) */ 240 /* r=(a[0]-a[1])*(b[1]-b[0]) */
568 c1=bn_cmp_part_words(a,&(a[n]),tna,n-tna); 241 c1=bn_cmp_words(a,&(a[n]),n);
569 c2=bn_cmp_part_words(&(b[n]),b,tnb,tnb-n); 242 c2=bn_cmp_words(&(b[n]),b,n);
570 zero=neg=0; 243 zero=neg=0;
571 switch (c1*3+c2) 244 switch (c1*3+c2)
572 { 245 {
573 case -4: 246 case -4:
574 bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ 247 bn_sub_words(t, &(a[n]),a, n); /* - */
575 bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ 248 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
576 break; 249 break;
577 case -3: 250 case -3:
578 zero=1; 251 zero=1;
579 /* break; */ 252 /* break; */
580 case -2: 253 case -2:
581 bn_sub_part_words(t, &(a[n]),a, tna,tna-n); /* - */ 254 bn_sub_words(t, &(a[n]),a, n); /* - */
582 bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); /* + */ 255 bn_sub_words(&(t[n]),&(b[n]),b, n); /* + */
583 neg=1; 256 neg=1;
584 break; 257 break;
585 case -1: 258 case -1:
@@ -588,16 +261,16 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
588 zero=1; 261 zero=1;
589 /* break; */ 262 /* break; */
590 case 2: 263 case 2:
591 bn_sub_part_words(t, a, &(a[n]),tna,n-tna); /* + */ 264 bn_sub_words(t, a, &(a[n]),n); /* + */
592 bn_sub_part_words(&(t[n]),b, &(b[n]),tnb,n-tnb); /* - */ 265 bn_sub_words(&(t[n]),b, &(b[n]),n); /* - */
593 neg=1; 266 neg=1;
594 break; 267 break;
595 case 3: 268 case 3:
596 zero=1; 269 zero=1;
597 /* break; */ 270 /* break; */
598 case 4: 271 case 4:
599 bn_sub_part_words(t, a, &(a[n]),tna,n-tna); 272 bn_sub_words(t, a, &(a[n]),n);
600 bn_sub_part_words(&(t[n]),&(b[n]),b, tnb,tnb-n); 273 bn_sub_words(&(t[n]),&(b[n]),b, n);
601 break; 274 break;
602 } 275 }
603 /* The zero case isn't yet implemented here. The speedup 276 /* The zero case isn't yet implemented here. The speedup
@@ -616,62 +289,54 @@ void bn_mul_part_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n,
616 { 289 {
617 bn_mul_comba8(&(t[n2]),t,&(t[n])); 290 bn_mul_comba8(&(t[n2]),t,&(t[n]));
618 bn_mul_comba8(r,a,b); 291 bn_mul_comba8(r,a,b);
619 bn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb); 292 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
620 memset(&(r[n2+tna+tnb]),0,sizeof(BN_ULONG)*(n2-tna-tnb)); 293 memset(&(r[n2+tn*2]),0,sizeof(BN_ULONG)*(n2-tn*2));
621 } 294 }
622 else 295 else
623 { 296 {
624 p= &(t[n2*2]); 297 p= &(t[n2*2]);
625 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,0,0,p); 298 bn_mul_recursive(&(t[n2]),t,&(t[n]),n,p);
626 bn_mul_recursive(r,a,b,n,0,0,p); 299 bn_mul_recursive(r,a,b,n,p);
627 i=n/2; 300 i=n/2;
628 /* If there is only a bottom half to the number, 301 /* If there is only a bottom half to the number,
629 * just do it */ 302 * just do it */
630 if (tna > tnb) 303 j=tn-i;
631 j = tna - i;
632 else
633 j = tnb - i;
634 if (j == 0) 304 if (j == 0)
635 { 305 {
636 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]), 306 bn_mul_recursive(&(r[n2]),&(a[n]),&(b[n]),i,p);
637 i,tna-i,tnb-i,p);
638 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2)); 307 memset(&(r[n2+i*2]),0,sizeof(BN_ULONG)*(n2-i*2));
639 } 308 }
640 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */ 309 else if (j > 0) /* eg, n == 16, i == 8 and tn == 11 */
641 { 310 {
642 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]), 311 bn_mul_part_recursive(&(r[n2]),&(a[n]),&(b[n]),
643 i,tna-i,tnb-i,p); 312 j,i,p);
644 memset(&(r[n2+tna+tnb]),0, 313 memset(&(r[n2+tn*2]),0,
645 sizeof(BN_ULONG)*(n2-tna-tnb)); 314 sizeof(BN_ULONG)*(n2-tn*2));
646 } 315 }
647 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */ 316 else /* (j < 0) eg, n == 16, i == 8 and tn == 5 */
648 { 317 {
649 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2); 318 memset(&(r[n2]),0,sizeof(BN_ULONG)*n2);
650 if (tna < BN_MUL_RECURSIVE_SIZE_NORMAL 319 if (tn < BN_MUL_RECURSIVE_SIZE_NORMAL)
651 && tnb < BN_MUL_RECURSIVE_SIZE_NORMAL)
652 { 320 {
653 bn_mul_normal(&(r[n2]),&(a[n]),tna,&(b[n]),tnb); 321 bn_mul_normal(&(r[n2]),&(a[n]),tn,&(b[n]),tn);
654 } 322 }
655 else 323 else
656 { 324 {
657 for (;;) 325 for (;;)
658 { 326 {
659 i/=2; 327 i/=2;
660 /* these simplified conditions work 328 if (i < tn)
661 * exclusively because difference
662 * between tna and tnb is 1 or 0 */
663 if (i < tna || i < tnb)
664 { 329 {
665 bn_mul_part_recursive(&(r[n2]), 330 bn_mul_part_recursive(&(r[n2]),
666 &(a[n]),&(b[n]), 331 &(a[n]),&(b[n]),
667 i,tna-i,tnb-i,p); 332 tn-i,i,p);
668 break; 333 break;
669 } 334 }
670 else if (i == tna || i == tnb) 335 else if (i == tn)
671 { 336 {
672 bn_mul_recursive(&(r[n2]), 337 bn_mul_recursive(&(r[n2]),
673 &(a[n]),&(b[n]), 338 &(a[n]),&(b[n]),
674 i,tna-i,tnb-i,p); 339 i,p);
675 break; 340 break;
676 } 341 }
677 } 342 }
@@ -732,10 +397,10 @@ void bn_mul_low_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
732 int n=n2/2; 397 int n=n2/2;
733 398
734# ifdef BN_COUNT 399# ifdef BN_COUNT
735 fprintf(stderr," bn_mul_low_recursive %d * %d\n",n2,n2); 400 printf(" bn_mul_low_recursive %d * %d\n",n2,n2);
736# endif 401# endif
737 402
738 bn_mul_recursive(r,a,b,n,0,0,&(t[0])); 403 bn_mul_recursive(r,a,b,n,&(t[0]));
739 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL) 404 if (n >= BN_MUL_LOW_RECURSIVE_SIZE_NORMAL)
740 { 405 {
741 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2])); 406 bn_mul_low_recursive(&(t[0]),&(a[0]),&(b[n]),n,&(t[n2]));
@@ -766,7 +431,7 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
766 BN_ULONG ll,lc,*lp,*mp; 431 BN_ULONG ll,lc,*lp,*mp;
767 432
768# ifdef BN_COUNT 433# ifdef BN_COUNT
769 fprintf(stderr," bn_mul_high %d * %d\n",n2,n2); 434 printf(" bn_mul_high %d * %d\n",n2,n2);
770# endif 435# endif
771 n=n2/2; 436 n=n2/2;
772 437
@@ -819,8 +484,8 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
819 else 484 else
820# endif 485# endif
821 { 486 {
822 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,0,0,&(t[n2])); 487 bn_mul_recursive(&(t[0]),&(r[0]),&(r[n]),n,&(t[n2]));
823 bn_mul_recursive(r,&(a[n]),&(b[n]),n,0,0,&(t[n2])); 488 bn_mul_recursive(r,&(a[n]),&(b[n]),n,&(t[n2]));
824 } 489 }
825 490
826 /* s0 == low(al*bl) 491 /* s0 == low(al*bl)
@@ -945,19 +610,19 @@ void bn_mul_high(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, BN_ULONG *l, int n2,
945 610
946int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 611int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
947 { 612 {
948 int ret=0;
949 int top,al,bl; 613 int top,al,bl;
950 BIGNUM *rr; 614 BIGNUM *rr;
615 int ret = 0;
951#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) 616#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
952 int i; 617 int i;
953#endif 618#endif
954#ifdef BN_RECURSION 619#ifdef BN_RECURSION
955 BIGNUM *t=NULL; 620 BIGNUM *t;
956 int j=0,k; 621 int j,k;
957#endif 622#endif
958 623
959#ifdef BN_COUNT 624#ifdef BN_COUNT
960 fprintf(stderr,"BN_mul %d * %d\n",a->top,b->top); 625 printf("BN_mul %d * %d\n",a->top,b->top);
961#endif 626#endif
962 627
963 bn_check_top(a); 628 bn_check_top(a);
@@ -969,7 +634,7 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
969 634
970 if ((al == 0) || (bl == 0)) 635 if ((al == 0) || (bl == 0))
971 { 636 {
972 BN_zero(r); 637 if (!BN_zero(r)) goto err;
973 return(1); 638 return(1);
974 } 639 }
975 top=al+bl; 640 top=al+bl;
@@ -1010,55 +675,21 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1010#ifdef BN_RECURSION 675#ifdef BN_RECURSION
1011 if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) 676 if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL))
1012 { 677 {
1013 if (i >= -1 && i <= 1) 678 if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA) && bl<b->dmax)
1014 { 679 {
1015 int sav_j =0; 680#if 0 /* tribute to const-ification, bl<b->dmax above covers for this */
1016 /* Find out the power of two lower or equal 681 if (bn_wexpand(b,al) == NULL) goto err;
1017 to the longest of the two numbers */ 682#endif
1018 if (i >= 0) 683 b->d[bl]=0;
1019 {
1020 j = BN_num_bits_word((BN_ULONG)al);
1021 }
1022 if (i == -1)
1023 {
1024 j = BN_num_bits_word((BN_ULONG)bl);
1025 }
1026 sav_j = j;
1027 j = 1<<(j-1);
1028 assert(j <= al || j <= bl);
1029 k = j+j;
1030 t = BN_CTX_get(ctx);
1031 if (al > j || bl > j)
1032 {
1033 bn_wexpand(t,k*4);
1034 bn_wexpand(rr,k*4);
1035 bn_mul_part_recursive(rr->d,a->d,b->d,
1036 j,al-j,bl-j,t->d);
1037 }
1038 else /* al <= j || bl <= j */
1039 {
1040 bn_wexpand(t,k*2);
1041 bn_wexpand(rr,k*2);
1042 bn_mul_recursive(rr->d,a->d,b->d,
1043 j,al-j,bl-j,t->d);
1044 }
1045 rr->top=top;
1046 goto end;
1047 }
1048#if 0
1049 if (i == 1 && !BN_get_flags(b,BN_FLG_STATIC_DATA))
1050 {
1051 BIGNUM *tmp_bn = (BIGNUM *)b;
1052 if (bn_wexpand(tmp_bn,al) == NULL) goto err;
1053 tmp_bn->d[bl]=0;
1054 bl++; 684 bl++;
1055 i--; 685 i--;
1056 } 686 }
1057 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA)) 687 else if (i == -1 && !BN_get_flags(a,BN_FLG_STATIC_DATA) && al<a->dmax)
1058 { 688 {
1059 BIGNUM *tmp_bn = (BIGNUM *)a; 689#if 0 /* tribute to const-ification, al<a->dmax above covers for this */
1060 if (bn_wexpand(tmp_bn,bl) == NULL) goto err; 690 if (bn_wexpand(a,bl) == NULL) goto err;
1061 tmp_bn->d[al]=0; 691#endif
692 a->d[al]=0;
1062 al++; 693 al++;
1063 i++; 694 i++;
1064 } 695 }
@@ -1075,17 +706,26 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1075 if (bn_wexpand(t,k*2) == NULL) goto err; 706 if (bn_wexpand(t,k*2) == NULL) goto err;
1076 if (bn_wexpand(rr,k*2) == NULL) goto err; 707 if (bn_wexpand(rr,k*2) == NULL) goto err;
1077 bn_mul_recursive(rr->d,a->d,b->d,al,t->d); 708 bn_mul_recursive(rr->d,a->d,b->d,al,t->d);
709 rr->top=top;
710 goto end;
1078 } 711 }
712#if 0 /* tribute to const-ification, rsa/dsa performance is not affected */
1079 else 713 else
1080 { 714 {
1081 if (bn_wexpand(t,k*4) == NULL) goto err; 715 if (bn_wexpand(a,k) == NULL ) goto err;
1082 if (bn_wexpand(rr,k*4) == NULL) goto err; 716 if (bn_wexpand(b,k) == NULL ) goto err;
717 if (bn_wexpand(t,k*4) == NULL ) goto err;
718 if (bn_wexpand(rr,k*4) == NULL ) goto err;
719 for (i=a->top; i<k; i++)
720 a->d[i]=0;
721 for (i=b->top; i<k; i++)
722 b->d[i]=0;
1083 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d); 723 bn_mul_part_recursive(rr->d,a->d,b->d,al-j,j,t->d);
1084 } 724 }
1085 rr->top=top; 725 rr->top=top;
1086 goto end; 726 goto end;
1087 }
1088#endif 727#endif
728 }
1089 } 729 }
1090#endif /* BN_RECURSION */ 730#endif /* BN_RECURSION */
1091 if (bn_wexpand(rr,top) == NULL) goto err; 731 if (bn_wexpand(rr,top) == NULL) goto err;
@@ -1095,11 +735,10 @@ int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
1095#if defined(BN_MUL_COMBA) || defined(BN_RECURSION) 735#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)
1096end: 736end:
1097#endif 737#endif
1098 bn_correct_top(rr); 738 bn_fix_top(rr);
1099 if (r != rr) BN_copy(r,rr); 739 if (r != rr) BN_copy(r,rr);
1100 ret=1; 740 ret=1;
1101err: 741err:
1102 bn_check_top(r);
1103 BN_CTX_end(ctx); 742 BN_CTX_end(ctx);
1104 return(ret); 743 return(ret);
1105 } 744 }
@@ -1109,7 +748,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
1109 BN_ULONG *rr; 748 BN_ULONG *rr;
1110 749
1111#ifdef BN_COUNT 750#ifdef BN_COUNT
1112 fprintf(stderr," bn_mul_normal %d * %d\n",na,nb); 751 printf(" bn_mul_normal %d * %d\n",na,nb);
1113#endif 752#endif
1114 753
1115 if (na < nb) 754 if (na < nb)
@@ -1122,13 +761,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
1122 761
1123 } 762 }
1124 rr= &(r[na]); 763 rr= &(r[na]);
1125 if (nb <= 0) 764 rr[0]=bn_mul_words(r,a,na,b[0]);
1126 {
1127 (void)bn_mul_words(r,a,na,0);
1128 return;
1129 }
1130 else
1131 rr[0]=bn_mul_words(r,a,na,b[0]);
1132 765
1133 for (;;) 766 for (;;)
1134 { 767 {
@@ -1149,7 +782,7 @@ void bn_mul_normal(BN_ULONG *r, BN_ULONG *a, int na, BN_ULONG *b, int nb)
1149void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n) 782void bn_mul_low_normal(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n)
1150 { 783 {
1151#ifdef BN_COUNT 784#ifdef BN_COUNT
1152 fprintf(stderr," bn_mul_low_normal %d * %d\n",n,n); 785 printf(" bn_mul_low_normal %d * %d\n",n,n);
1153#endif 786#endif
1154 bn_mul_words(r,a,n,b[0]); 787 bn_mul_words(r,a,n,b[0]);
1155 788
diff --git a/src/lib/libcrypto/bn/bn_prime.c b/src/lib/libcrypto/bn/bn_prime.c
index 7b25979dd1..f422172f16 100644
--- a/src/lib/libcrypto/bn/bn_prime.c
+++ b/src/lib/libcrypto/bn/bn_prime.c
@@ -115,11 +115,6 @@
115#include "bn_lcl.h" 115#include "bn_lcl.h"
116#include <openssl/rand.h> 116#include <openssl/rand.h>
117 117
118/* NB: these functions have been "upgraded", the deprecated versions (which are
119 * compatibility wrappers using these functions) are in bn_depr.c.
120 * - Geoff
121 */
122
123/* The quick sieve algorithm approach to weeding out primes is 118/* The quick sieve algorithm approach to weeding out primes is
124 * Philip Zimmermann's, as implemented in PGP. I have had a read of 119 * Philip Zimmermann's, as implemented in PGP. I have had a read of
125 * his comments and implemented my own version. 120 * his comments and implemented my own version.
@@ -134,69 +129,51 @@ static int probable_prime_dh(BIGNUM *rnd, int bits,
134static int probable_prime_dh_safe(BIGNUM *rnd, int bits, 129static int probable_prime_dh_safe(BIGNUM *rnd, int bits,
135 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx); 130 const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
136 131
137int BN_GENCB_call(BN_GENCB *cb, int a, int b) 132BIGNUM *BN_generate_prime(BIGNUM *ret, int bits, int safe,
138 { 133 const BIGNUM *add, const BIGNUM *rem,
139 /* No callback means continue */ 134 void (*callback)(int,int,void *), void *cb_arg)
140 if(!cb) return 1;
141 switch(cb->ver)
142 {
143 case 1:
144 /* Deprecated-style callbacks */
145 if(!cb->cb.cb_1)
146 return 1;
147 cb->cb.cb_1(a, b, cb->arg);
148 return 1;
149 case 2:
150 /* New-style callbacks */
151 return cb->cb.cb_2(a, b, cb);
152 default:
153 break;
154 }
155 /* Unrecognised callback type */
156 return 0;
157 }
158
159int BN_generate_prime_ex(BIGNUM *ret, int bits, int safe,
160 const BIGNUM *add, const BIGNUM *rem, BN_GENCB *cb)
161 { 135 {
162 BIGNUM *t; 136 BIGNUM *rnd=NULL;
137 BIGNUM t;
163 int found=0; 138 int found=0;
164 int i,j,c1=0; 139 int i,j,c1=0;
165 BN_CTX *ctx; 140 BN_CTX *ctx;
166 int checks = BN_prime_checks_for_size(bits); 141 int checks = BN_prime_checks_for_size(bits);
167 142
143 BN_init(&t);
168 ctx=BN_CTX_new(); 144 ctx=BN_CTX_new();
169 if (ctx == NULL) goto err; 145 if (ctx == NULL) goto err;
170 BN_CTX_start(ctx); 146 if (ret == NULL)
171 t = BN_CTX_get(ctx); 147 {
172 if(!t) goto err; 148 if ((rnd=BN_new()) == NULL) goto err;
149 }
150 else
151 rnd=ret;
173loop: 152loop:
174 /* make a random number and set the top and bottom bits */ 153 /* make a random number and set the top and bottom bits */
175 if (add == NULL) 154 if (add == NULL)
176 { 155 {
177 if (!probable_prime(ret,bits)) goto err; 156 if (!probable_prime(rnd,bits)) goto err;
178 } 157 }
179 else 158 else
180 { 159 {
181 if (safe) 160 if (safe)
182 { 161 {
183 if (!probable_prime_dh_safe(ret,bits,add,rem,ctx)) 162 if (!probable_prime_dh_safe(rnd,bits,add,rem,ctx))
184 goto err; 163 goto err;
185 } 164 }
186 else 165 else
187 { 166 {
188 if (!probable_prime_dh(ret,bits,add,rem,ctx)) 167 if (!probable_prime_dh(rnd,bits,add,rem,ctx))
189 goto err; 168 goto err;
190 } 169 }
191 } 170 }
192 /* if (BN_mod_word(ret,(BN_ULONG)3) == 1) goto loop; */ 171 /* if (BN_mod_word(rnd,(BN_ULONG)3) == 1) goto loop; */
193 if(!BN_GENCB_call(cb, 0, c1++)) 172 if (callback != NULL) callback(0,c1++,cb_arg);
194 /* aborted */
195 goto err;
196 173
197 if (!safe) 174 if (!safe)
198 { 175 {
199 i=BN_is_prime_fasttest_ex(ret,checks,ctx,0,cb); 176 i=BN_is_prime_fasttest(rnd,checks,callback,ctx,cb_arg,0);
200 if (i == -1) goto err; 177 if (i == -1) goto err;
201 if (i == 0) goto loop; 178 if (i == 0) goto loop;
202 } 179 }
@@ -206,42 +183,41 @@ loop:
206 * check that (p-1)/2 is prime. 183 * check that (p-1)/2 is prime.
207 * Since a prime is odd, We just 184 * Since a prime is odd, We just
208 * need to divide by 2 */ 185 * need to divide by 2 */
209 if (!BN_rshift1(t,ret)) goto err; 186 if (!BN_rshift1(&t,rnd)) goto err;
210 187
211 for (i=0; i<checks; i++) 188 for (i=0; i<checks; i++)
212 { 189 {
213 j=BN_is_prime_fasttest_ex(ret,1,ctx,0,cb); 190 j=BN_is_prime_fasttest(rnd,1,callback,ctx,cb_arg,0);
214 if (j == -1) goto err; 191 if (j == -1) goto err;
215 if (j == 0) goto loop; 192 if (j == 0) goto loop;
216 193
217 j=BN_is_prime_fasttest_ex(t,1,ctx,0,cb); 194 j=BN_is_prime_fasttest(&t,1,callback,ctx,cb_arg,0);
218 if (j == -1) goto err; 195 if (j == -1) goto err;
219 if (j == 0) goto loop; 196 if (j == 0) goto loop;
220 197
221 if(!BN_GENCB_call(cb, 2, c1-1)) 198 if (callback != NULL) callback(2,c1-1,cb_arg);
222 goto err;
223 /* We have a safe prime test pass */ 199 /* We have a safe prime test pass */
224 } 200 }
225 } 201 }
226 /* we have a prime :-) */ 202 /* we have a prime :-) */
227 found = 1; 203 found = 1;
228err: 204err:
229 if (ctx != NULL) 205 if (!found && (ret == NULL) && (rnd != NULL)) BN_free(rnd);
230 { 206 BN_free(&t);
231 BN_CTX_end(ctx); 207 if (ctx != NULL) BN_CTX_free(ctx);
232 BN_CTX_free(ctx); 208 return(found ? rnd : NULL);
233 }
234 bn_check_top(ret);
235 return found;
236 } 209 }
237 210
238int BN_is_prime_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, BN_GENCB *cb) 211int BN_is_prime(const BIGNUM *a, int checks, void (*callback)(int,int,void *),
212 BN_CTX *ctx_passed, void *cb_arg)
239 { 213 {
240 return BN_is_prime_fasttest_ex(a, checks, ctx_passed, 0, cb); 214 return BN_is_prime_fasttest(a, checks, callback, ctx_passed, cb_arg, 0);
241 } 215 }
242 216
243int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed, 217int BN_is_prime_fasttest(const BIGNUM *a, int checks,
244 int do_trial_division, BN_GENCB *cb) 218 void (*callback)(int,int,void *),
219 BN_CTX *ctx_passed, void *cb_arg,
220 int do_trial_division)
245 { 221 {
246 int i, j, ret = -1; 222 int i, j, ret = -1;
247 int k; 223 int k;
@@ -260,13 +236,13 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
260 if (!BN_is_odd(a)) 236 if (!BN_is_odd(a))
261 /* a is even => a is prime if and only if a == 2 */ 237 /* a is even => a is prime if and only if a == 2 */
262 return BN_is_word(a, 2); 238 return BN_is_word(a, 2);
239
263 if (do_trial_division) 240 if (do_trial_division)
264 { 241 {
265 for (i = 1; i < NUMPRIMES; i++) 242 for (i = 1; i < NUMPRIMES; i++)
266 if (BN_mod_word(a, primes[i]) == 0) 243 if (BN_mod_word(a, primes[i]) == 0)
267 return 0; 244 return 0;
268 if(!BN_GENCB_call(cb, 1, -1)) 245 if (callback != NULL) callback(1, -1, cb_arg);
269 goto err;
270 } 246 }
271 247
272 if (ctx_passed != NULL) 248 if (ctx_passed != NULL)
@@ -332,8 +308,7 @@ int BN_is_prime_fasttest_ex(const BIGNUM *a, int checks, BN_CTX *ctx_passed,
332 ret=0; 308 ret=0;
333 goto err; 309 goto err;
334 } 310 }
335 if(!BN_GENCB_call(cb, 1, i)) 311 if (callback != NULL) callback(1,i,cb_arg);
336 goto err;
337 } 312 }
338 ret=1; 313 ret=1;
339err: 314err:
@@ -370,22 +345,20 @@ static int witness(BIGNUM *w, const BIGNUM *a, const BIGNUM *a1,
370 } 345 }
371 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w', 346 /* If we get here, 'w' is the (a-1)/2-th power of the original 'w',
372 * and it is neither -1 nor +1 -- so 'a' cannot be prime */ 347 * and it is neither -1 nor +1 -- so 'a' cannot be prime */
373 bn_check_top(w);
374 return 1; 348 return 1;
375 } 349 }
376 350
377static int probable_prime(BIGNUM *rnd, int bits) 351static int probable_prime(BIGNUM *rnd, int bits)
378 { 352 {
379 int i; 353 int i;
380 prime_t mods[NUMPRIMES]; 354 BN_ULONG mods[NUMPRIMES];
381 BN_ULONG delta,maxdelta; 355 BN_ULONG delta,d;
382 356
383again: 357again:
384 if (!BN_rand(rnd,bits,1,1)) return(0); 358 if (!BN_rand(rnd,bits,1,1)) return(0);
385 /* we now have a random number 'rand' to test. */ 359 /* we now have a random number 'rand' to test. */
386 for (i=1; i<NUMPRIMES; i++) 360 for (i=1; i<NUMPRIMES; i++)
387 mods[i]=(prime_t)BN_mod_word(rnd,(BN_ULONG)primes[i]); 361 mods[i]=BN_mod_word(rnd,(BN_ULONG)primes[i]);
388 maxdelta=BN_MASK2 - primes[NUMPRIMES-1];
389 delta=0; 362 delta=0;
390 loop: for (i=1; i<NUMPRIMES; i++) 363 loop: for (i=1; i<NUMPRIMES; i++)
391 { 364 {
@@ -393,13 +366,16 @@ again:
393 * that gcd(rnd-1,primes) == 1 (except for 2) */ 366 * that gcd(rnd-1,primes) == 1 (except for 2) */
394 if (((mods[i]+delta)%primes[i]) <= 1) 367 if (((mods[i]+delta)%primes[i]) <= 1)
395 { 368 {
369 d=delta;
396 delta+=2; 370 delta+=2;
397 if (delta > maxdelta) goto again; 371 /* perhaps need to check for overflow of
372 * delta (but delta can be up to 2^32)
373 * 21-May-98 eay - added overflow check */
374 if (delta < d) goto again;
398 goto loop; 375 goto loop;
399 } 376 }
400 } 377 }
401 if (!BN_add_word(rnd,delta)) return(0); 378 if (!BN_add_word(rnd,delta)) return(0);
402 bn_check_top(rnd);
403 return(1); 379 return(1);
404 } 380 }
405 381
@@ -437,7 +413,6 @@ static int probable_prime_dh(BIGNUM *rnd, int bits,
437 ret=1; 413 ret=1;
438err: 414err:
439 BN_CTX_end(ctx); 415 BN_CTX_end(ctx);
440 bn_check_top(rnd);
441 return(ret); 416 return(ret);
442 } 417 }
443 418
@@ -489,6 +464,5 @@ static int probable_prime_dh_safe(BIGNUM *p, int bits, const BIGNUM *padd,
489 ret=1; 464 ret=1;
490err: 465err:
491 BN_CTX_end(ctx); 466 BN_CTX_end(ctx);
492 bn_check_top(p);
493 return(ret); 467 return(ret);
494 } 468 }
diff --git a/src/lib/libcrypto/bn/bn_prime.h b/src/lib/libcrypto/bn/bn_prime.h
index 51d2194feb..b7cf9a9bfe 100644
--- a/src/lib/libcrypto/bn/bn_prime.h
+++ b/src/lib/libcrypto/bn/bn_prime.h
@@ -58,12 +58,10 @@
58 58
59#ifndef EIGHT_BIT 59#ifndef EIGHT_BIT
60#define NUMPRIMES 2048 60#define NUMPRIMES 2048
61typedef unsigned short prime_t;
62#else 61#else
63#define NUMPRIMES 54 62#define NUMPRIMES 54
64typedef unsigned char prime_t;
65#endif 63#endif
66static const prime_t primes[NUMPRIMES]= 64static const unsigned int primes[NUMPRIMES]=
67 { 65 {
68 2, 3, 5, 7, 11, 13, 17, 19, 66 2, 3, 5, 7, 11, 13, 17, 19,
69 23, 29, 31, 37, 41, 43, 47, 53, 67 23, 29, 31, 37, 41, 43, 47, 53,
diff --git a/src/lib/libcrypto/bn/bn_prime.pl b/src/lib/libcrypto/bn/bn_prime.pl
index 3fafb6f3e9..9fc3765486 100644
--- a/src/lib/libcrypto/bn/bn_prime.pl
+++ b/src/lib/libcrypto/bn/bn_prime.pl
@@ -11,7 +11,7 @@ loop: while ($#primes < $num-1)
11 $p+=2; 11 $p+=2;
12 $s=int(sqrt($p)); 12 $s=int(sqrt($p));
13 13
14 for ($i=0; defined($primes[$i]) && $primes[$i]<=$s; $i++) 14 for ($i=0; $primes[$i]<=$s; $i++)
15 { 15 {
16 next loop if (($p%$primes[$i]) == 0); 16 next loop if (($p%$primes[$i]) == 0);
17 } 17 }
@@ -101,12 +101,10 @@ for ($i=0; $i <= $#primes; $i++)
101 101
102printf "#ifndef EIGHT_BIT\n"; 102printf "#ifndef EIGHT_BIT\n";
103printf "#define NUMPRIMES %d\n",$num; 103printf "#define NUMPRIMES %d\n",$num;
104printf "typedef unsigned short prime_t;\n";
105printf "#else\n"; 104printf "#else\n";
106printf "#define NUMPRIMES %d\n",$eight; 105printf "#define NUMPRIMES %d\n",$eight;
107printf "typedef unsigned char prime_t;\n";
108printf "#endif\n"; 106printf "#endif\n";
109print "static const prime_t primes[NUMPRIMES]=\n\t{\n\t"; 107print "static const unsigned int primes[NUMPRIMES]=\n\t{\n\t";
110$init=0; 108$init=0;
111for ($i=0; $i <= $#primes; $i++) 109for ($i=0; $i <= $#primes; $i++)
112 { 110 {
diff --git a/src/lib/libcrypto/bn/bn_print.c b/src/lib/libcrypto/bn/bn_print.c
index 810dde34e1..acba7ed7ee 100644
--- a/src/lib/libcrypto/bn/bn_print.c
+++ b/src/lib/libcrypto/bn/bn_print.c
@@ -62,7 +62,7 @@
62#include <openssl/buffer.h> 62#include <openssl/buffer.h>
63#include "bn_lcl.h" 63#include "bn_lcl.h"
64 64
65static const char Hex[]="0123456789ABCDEF"; 65static const char *Hex="0123456789ABCDEF";
66 66
67/* Must 'OPENSSL_free' the returned data */ 67/* Must 'OPENSSL_free' the returned data */
68char *BN_bn2hex(const BIGNUM *a) 68char *BN_bn2hex(const BIGNUM *a)
@@ -102,19 +102,14 @@ err:
102/* Must 'OPENSSL_free' the returned data */ 102/* Must 'OPENSSL_free' the returned data */
103char *BN_bn2dec(const BIGNUM *a) 103char *BN_bn2dec(const BIGNUM *a)
104 { 104 {
105 int i=0,num, ok = 0; 105 int i=0,num;
106 char *buf=NULL; 106 char *buf=NULL;
107 char *p; 107 char *p;
108 BIGNUM *t=NULL; 108 BIGNUM *t=NULL;
109 BN_ULONG *bn_data=NULL,*lp; 109 BN_ULONG *bn_data=NULL,*lp;
110 110
111 /* get an upper bound for the length of the decimal integer
112 * num <= (BN_num_bits(a) + 1) * log(2)
113 * <= 3 * BN_num_bits(a) * 0.1001 + log(2) + 1 (rounding error)
114 * <= BN_num_bits(a)/10 + BN_num_bits/1000 + 1 + 1
115 */
116 i=BN_num_bits(a)*3; 111 i=BN_num_bits(a)*3;
117 num=(i/10+i/1000+1)+1; 112 num=(i/10+i/1000+3)+1;
118 bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG)); 113 bn_data=(BN_ULONG *)OPENSSL_malloc((num/BN_DEC_NUM+1)*sizeof(BN_ULONG));
119 buf=(char *)OPENSSL_malloc(num+3); 114 buf=(char *)OPENSSL_malloc(num+3);
120 if ((buf == NULL) || (bn_data == NULL)) 115 if ((buf == NULL) || (bn_data == NULL))
@@ -127,6 +122,7 @@ char *BN_bn2dec(const BIGNUM *a)
127#define BUF_REMAIN (num+3 - (size_t)(p - buf)) 122#define BUF_REMAIN (num+3 - (size_t)(p - buf))
128 p=buf; 123 p=buf;
129 lp=bn_data; 124 lp=bn_data;
125 if (t->neg) *(p++)='-';
130 if (BN_is_zero(t)) 126 if (BN_is_zero(t))
131 { 127 {
132 *(p++)='0'; 128 *(p++)='0';
@@ -134,9 +130,6 @@ char *BN_bn2dec(const BIGNUM *a)
134 } 130 }
135 else 131 else
136 { 132 {
137 if (BN_is_negative(t))
138 *p++ = '-';
139
140 i=0; 133 i=0;
141 while (!BN_is_zero(t)) 134 while (!BN_is_zero(t))
142 { 135 {
@@ -156,16 +149,9 @@ char *BN_bn2dec(const BIGNUM *a)
156 while (*p) p++; 149 while (*p) p++;
157 } 150 }
158 } 151 }
159 ok = 1;
160err: 152err:
161 if (bn_data != NULL) OPENSSL_free(bn_data); 153 if (bn_data != NULL) OPENSSL_free(bn_data);
162 if (t != NULL) BN_free(t); 154 if (t != NULL) BN_free(t);
163 if (!ok && buf)
164 {
165 OPENSSL_free(buf);
166 buf = NULL;
167 }
168
169 return(buf); 155 return(buf);
170 } 156 }
171 157
@@ -225,11 +211,10 @@ int BN_hex2bn(BIGNUM **bn, const char *a)
225 j-=(BN_BYTES*2); 211 j-=(BN_BYTES*2);
226 } 212 }
227 ret->top=h; 213 ret->top=h;
228 bn_correct_top(ret); 214 bn_fix_top(ret);
229 ret->neg=neg; 215 ret->neg=neg;
230 216
231 *bn=ret; 217 *bn=ret;
232 bn_check_top(ret);
233 return(num); 218 return(num);
234err: 219err:
235 if (*bn == NULL) BN_free(ret); 220 if (*bn == NULL) BN_free(ret);
@@ -285,9 +270,8 @@ int BN_dec2bn(BIGNUM **bn, const char *a)
285 } 270 }
286 ret->neg=neg; 271 ret->neg=neg;
287 272
288 bn_correct_top(ret); 273 bn_fix_top(ret);
289 *bn=ret; 274 *bn=ret;
290 bn_check_top(ret);
291 return(num); 275 return(num);
292err: 276err:
293 if (*bn == NULL) BN_free(ret); 277 if (*bn == NULL) BN_free(ret);
@@ -316,7 +300,7 @@ int BN_print(BIO *bp, const BIGNUM *a)
316 int ret=0; 300 int ret=0;
317 301
318 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end; 302 if ((a->neg) && (BIO_write(bp,"-",1) != 1)) goto end;
319 if (BN_is_zero(a) && (BIO_write(bp,"0",1) != 1)) goto end; 303 if ((BN_is_zero(a)) && (BIO_write(bp,"0",1) != 1)) goto end;
320 for (i=a->top-1; i >=0; i--) 304 for (i=a->top-1; i >=0; i--)
321 { 305 {
322 for (j=BN_BITS2-4; j >= 0; j-=4) 306 for (j=BN_BITS2-4; j >= 0; j-=4)
@@ -336,3 +320,14 @@ end:
336 return(ret); 320 return(ret);
337 } 321 }
338#endif 322#endif
323
324#ifdef BN_DEBUG
325void bn_dump1(FILE *o, const char *a, const BN_ULONG *b,int n)
326 {
327 int i;
328 fprintf(o, "%s=", a);
329 for (i=n-1;i>=0;i--)
330 fprintf(o, "%08lX", b[i]); /* assumes 32-bit BN_ULONG */
331 fprintf(o, "\n");
332 }
333#endif
diff --git a/src/lib/libcrypto/bn/bn_rand.c b/src/lib/libcrypto/bn/bn_rand.c
index f51830b12b..893c9d2af9 100644
--- a/src/lib/libcrypto/bn/bn_rand.c
+++ b/src/lib/libcrypto/bn/bn_rand.c
@@ -134,13 +134,13 @@ static int bnrand(int pseudorand, BIGNUM *rnd, int bits, int top, int bottom)
134 buf=(unsigned char *)OPENSSL_malloc(bytes); 134 buf=(unsigned char *)OPENSSL_malloc(bytes);
135 if (buf == NULL) 135 if (buf == NULL)
136 { 136 {
137 BNerr(BN_F_BNRAND,ERR_R_MALLOC_FAILURE); 137 BNerr(BN_F_BN_RAND,ERR_R_MALLOC_FAILURE);
138 goto err; 138 goto err;
139 } 139 }
140 140
141 /* make a random number and set the top and bottom bits */ 141 /* make a random number and set the top and bottom bits */
142 time(&tim); 142 time(&tim);
143 RAND_add(&tim,sizeof(tim),0.0); 143 RAND_add(&tim,sizeof(tim),0);
144 144
145 if (pseudorand) 145 if (pseudorand)
146 { 146 {
@@ -204,7 +204,6 @@ err:
204 OPENSSL_cleanse(buf,bytes); 204 OPENSSL_cleanse(buf,bytes);
205 OPENSSL_free(buf); 205 OPENSSL_free(buf);
206 } 206 }
207 bn_check_top(rnd);
208 return(ret); 207 return(ret);
209 } 208 }
210 209
@@ -231,7 +230,6 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
231 { 230 {
232 int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand; 231 int (*bn_rand)(BIGNUM *, int, int, int) = pseudo ? BN_pseudo_rand : BN_rand;
233 int n; 232 int n;
234 int count = 100;
235 233
236 if (range->neg || BN_is_zero(range)) 234 if (range->neg || BN_is_zero(range))
237 { 235 {
@@ -244,7 +242,9 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
244 /* BN_is_bit_set(range, n - 1) always holds */ 242 /* BN_is_bit_set(range, n - 1) always holds */
245 243
246 if (n == 1) 244 if (n == 1)
247 BN_zero(r); 245 {
246 if (!BN_zero(r)) return 0;
247 }
248 else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) 248 else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3))
249 { 249 {
250 /* range = 100..._2, 250 /* range = 100..._2,
@@ -263,13 +263,6 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
263 if (BN_cmp(r, range) >= 0) 263 if (BN_cmp(r, range) >= 0)
264 if (!BN_sub(r, r, range)) return 0; 264 if (!BN_sub(r, r, range)) return 0;
265 } 265 }
266
267 if (!--count)
268 {
269 BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);
270 return 0;
271 }
272
273 } 266 }
274 while (BN_cmp(r, range) >= 0); 267 while (BN_cmp(r, range) >= 0);
275 } 268 }
@@ -279,17 +272,10 @@ static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
279 { 272 {
280 /* range = 11..._2 or range = 101..._2 */ 273 /* range = 11..._2 or range = 101..._2 */
281 if (!bn_rand(r, n, -1, 0)) return 0; 274 if (!bn_rand(r, n, -1, 0)) return 0;
282
283 if (!--count)
284 {
285 BNerr(BN_F_BN_RAND_RANGE, BN_R_TOO_MANY_ITERATIONS);
286 return 0;
287 }
288 } 275 }
289 while (BN_cmp(r, range) >= 0); 276 while (BN_cmp(r, range) >= 0);
290 } 277 }
291 278
292 bn_check_top(r);
293 return 1; 279 return 1;
294 } 280 }
295 281
diff --git a/src/lib/libcrypto/bn/bn_recp.c b/src/lib/libcrypto/bn/bn_recp.c
index 2e8efb8dae..ef5fdd4708 100644
--- a/src/lib/libcrypto/bn/bn_recp.c
+++ b/src/lib/libcrypto/bn/bn_recp.c
@@ -94,7 +94,7 @@ void BN_RECP_CTX_free(BN_RECP_CTX *recp)
94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx) 94int BN_RECP_CTX_set(BN_RECP_CTX *recp, const BIGNUM *d, BN_CTX *ctx)
95 { 95 {
96 if (!BN_copy(&(recp->N),d)) return 0; 96 if (!BN_copy(&(recp->N),d)) return 0;
97 BN_zero(&(recp->Nr)); 97 if (!BN_zero(&(recp->Nr))) return 0;
98 recp->num_bits=BN_num_bits(d); 98 recp->num_bits=BN_num_bits(d);
99 recp->shift=0; 99 recp->shift=0;
100 return(1); 100 return(1);
@@ -123,7 +123,6 @@ int BN_mod_mul_reciprocal(BIGNUM *r, const BIGNUM *x, const BIGNUM *y,
123 ret = BN_div_recp(NULL,r,ca,recp,ctx); 123 ret = BN_div_recp(NULL,r,ca,recp,ctx);
124err: 124err:
125 BN_CTX_end(ctx); 125 BN_CTX_end(ctx);
126 bn_check_top(r);
127 return(ret); 126 return(ret);
128 } 127 }
129 128
@@ -148,7 +147,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
148 147
149 if (BN_ucmp(m,&(recp->N)) < 0) 148 if (BN_ucmp(m,&(recp->N)) < 0)
150 { 149 {
151 BN_zero(d); 150 if (!BN_zero(d)) return 0;
152 if (!BN_copy(r,m)) return 0; 151 if (!BN_copy(r,m)) return 0;
153 BN_CTX_end(ctx); 152 BN_CTX_end(ctx);
154 return(1); 153 return(1);
@@ -191,7 +190,7 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
191 { 190 {
192 if (j++ > 2) 191 if (j++ > 2)
193 { 192 {
194 BNerr(BN_F_BN_DIV_RECP,BN_R_BAD_RECIPROCAL); 193 BNerr(BN_F_BN_MOD_MUL_RECIPROCAL,BN_R_BAD_RECIPROCAL);
195 goto err; 194 goto err;
196 } 195 }
197 if (!BN_usub(r,r,&(recp->N))) goto err; 196 if (!BN_usub(r,r,&(recp->N))) goto err;
@@ -204,8 +203,6 @@ int BN_div_recp(BIGNUM *dv, BIGNUM *rem, const BIGNUM *m,
204 ret=1; 203 ret=1;
205err: 204err:
206 BN_CTX_end(ctx); 205 BN_CTX_end(ctx);
207 bn_check_top(dv);
208 bn_check_top(rem);
209 return(ret); 206 return(ret);
210 } 207 }
211 208
@@ -217,18 +214,17 @@ err:
217int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx) 214int BN_reciprocal(BIGNUM *r, const BIGNUM *m, int len, BN_CTX *ctx)
218 { 215 {
219 int ret= -1; 216 int ret= -1;
220 BIGNUM *t; 217 BIGNUM t;
221 218
222 BN_CTX_start(ctx); 219 BN_init(&t);
223 if((t = BN_CTX_get(ctx)) == NULL) goto err;
224 220
225 if (!BN_set_bit(t,len)) goto err; 221 if (!BN_zero(&t)) goto err;
222 if (!BN_set_bit(&t,len)) goto err;
226 223
227 if (!BN_div(r,NULL,t,m,ctx)) goto err; 224 if (!BN_div(r,NULL,&t,m,ctx)) goto err;
228 225
229 ret=len; 226 ret=len;
230err: 227err:
231 bn_check_top(r); 228 BN_free(&t);
232 BN_CTX_end(ctx);
233 return(ret); 229 return(ret);
234 } 230 }
diff --git a/src/lib/libcrypto/bn/bn_shift.c b/src/lib/libcrypto/bn/bn_shift.c
index de9312dce2..70f785ea18 100644
--- a/src/lib/libcrypto/bn/bn_shift.c
+++ b/src/lib/libcrypto/bn/bn_shift.c
@@ -65,9 +65,6 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a)
65 register BN_ULONG *ap,*rp,t,c; 65 register BN_ULONG *ap,*rp,t,c;
66 int i; 66 int i;
67 67
68 bn_check_top(r);
69 bn_check_top(a);
70
71 if (r != a) 68 if (r != a)
72 { 69 {
73 r->neg=a->neg; 70 r->neg=a->neg;
@@ -92,7 +89,6 @@ int BN_lshift1(BIGNUM *r, const BIGNUM *a)
92 *rp=1; 89 *rp=1;
93 r->top++; 90 r->top++;
94 } 91 }
95 bn_check_top(r);
96 return(1); 92 return(1);
97 } 93 }
98 94
@@ -101,9 +97,6 @@ int BN_rshift1(BIGNUM *r, const BIGNUM *a)
101 BN_ULONG *ap,*rp,t,c; 97 BN_ULONG *ap,*rp,t,c;
102 int i; 98 int i;
103 99
104 bn_check_top(r);
105 bn_check_top(a);
106
107 if (BN_is_zero(a)) 100 if (BN_is_zero(a))
108 { 101 {
109 BN_zero(r); 102 BN_zero(r);
@@ -124,8 +117,7 @@ int BN_rshift1(BIGNUM *r, const BIGNUM *a)
124 rp[i]=((t>>1)&BN_MASK2)|c; 117 rp[i]=((t>>1)&BN_MASK2)|c;
125 c=(t&1)?BN_TBIT:0; 118 c=(t&1)?BN_TBIT:0;
126 } 119 }
127 bn_correct_top(r); 120 bn_fix_top(r);
128 bn_check_top(r);
129 return(1); 121 return(1);
130 } 122 }
131 123
@@ -135,9 +127,6 @@ int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
135 BN_ULONG *t,*f; 127 BN_ULONG *t,*f;
136 BN_ULONG l; 128 BN_ULONG l;
137 129
138 bn_check_top(r);
139 bn_check_top(a);
140
141 r->neg=a->neg; 130 r->neg=a->neg;
142 nw=n/BN_BITS2; 131 nw=n/BN_BITS2;
143 if (bn_wexpand(r,a->top+nw+1) == NULL) return(0); 132 if (bn_wexpand(r,a->top+nw+1) == NULL) return(0);
@@ -160,8 +149,7 @@ int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
160/* for (i=0; i<nw; i++) 149/* for (i=0; i<nw; i++)
161 t[i]=0;*/ 150 t[i]=0;*/
162 r->top=a->top+nw+1; 151 r->top=a->top+nw+1;
163 bn_correct_top(r); 152 bn_fix_top(r);
164 bn_check_top(r);
165 return(1); 153 return(1);
166 } 154 }
167 155
@@ -171,9 +159,6 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
171 BN_ULONG *t,*f; 159 BN_ULONG *t,*f;
172 BN_ULONG l,tmp; 160 BN_ULONG l,tmp;
173 161
174 bn_check_top(r);
175 bn_check_top(a);
176
177 nw=n/BN_BITS2; 162 nw=n/BN_BITS2;
178 rb=n%BN_BITS2; 163 rb=n%BN_BITS2;
179 lb=BN_BITS2-rb; 164 lb=BN_BITS2-rb;
@@ -200,13 +185,13 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
200 185
201 if (rb == 0) 186 if (rb == 0)
202 { 187 {
203 for (i=j; i != 0; i--) 188 for (i=j+1; i > 0; i--)
204 *(t++)= *(f++); 189 *(t++)= *(f++);
205 } 190 }
206 else 191 else
207 { 192 {
208 l= *(f++); 193 l= *(f++);
209 for (i=j-1; i != 0; i--) 194 for (i=1; i<j; i++)
210 { 195 {
211 tmp =(l>>rb)&BN_MASK2; 196 tmp =(l>>rb)&BN_MASK2;
212 l= *(f++); 197 l= *(f++);
@@ -214,7 +199,7 @@ int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
214 } 199 }
215 *(t++) =(l>>rb)&BN_MASK2; 200 *(t++) =(l>>rb)&BN_MASK2;
216 } 201 }
217 bn_correct_top(r); 202 *t=0;
218 bn_check_top(r); 203 bn_fix_top(r);
219 return(1); 204 return(1);
220 } 205 }
diff --git a/src/lib/libcrypto/bn/bn_sqr.c b/src/lib/libcrypto/bn/bn_sqr.c
index 270d0cd348..c1d0cca438 100644
--- a/src/lib/libcrypto/bn/bn_sqr.c
+++ b/src/lib/libcrypto/bn/bn_sqr.c
@@ -77,16 +77,16 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
77 if (al <= 0) 77 if (al <= 0)
78 { 78 {
79 r->top=0; 79 r->top=0;
80 return 1; 80 return(1);
81 } 81 }
82 82
83 BN_CTX_start(ctx); 83 BN_CTX_start(ctx);
84 rr=(a != r) ? r : BN_CTX_get(ctx); 84 rr=(a != r) ? r : BN_CTX_get(ctx);
85 tmp=BN_CTX_get(ctx); 85 tmp=BN_CTX_get(ctx);
86 if (!rr || !tmp) goto err; 86 if (tmp == NULL) goto err;
87 87
88 max = 2 * al; /* Non-zero (from above) */ 88 max=(al+al);
89 if (bn_wexpand(rr,max) == NULL) goto err; 89 if (bn_wexpand(rr,max+1) == NULL) goto err;
90 90
91 if (al == 4) 91 if (al == 4)
92 { 92 {
@@ -138,18 +138,12 @@ int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
138#endif 138#endif
139 } 139 }
140 140
141 rr->top=max;
141 rr->neg=0; 142 rr->neg=0;
142 /* If the most-significant half of the top word of 'a' is zero, then 143 if ((max > 0) && (rr->d[max-1] == 0)) rr->top--;
143 * the square of 'a' will max-1 words. */
144 if(a->d[al - 1] == (a->d[al - 1] & BN_MASK2l))
145 rr->top = max - 1;
146 else
147 rr->top = max;
148 if (rr != r) BN_copy(r,rr); 144 if (rr != r) BN_copy(r,rr);
149 ret = 1; 145 ret = 1;
150 err: 146 err:
151 bn_check_top(rr);
152 bn_check_top(tmp);
153 BN_CTX_end(ctx); 147 BN_CTX_end(ctx);
154 return(ret); 148 return(ret);
155 } 149 }
diff --git a/src/lib/libcrypto/bn/bn_sqrt.c b/src/lib/libcrypto/bn/bn_sqrt.c
index 6beaf9e5e5..e2a1105dc8 100644
--- a/src/lib/libcrypto/bn/bn_sqrt.c
+++ b/src/lib/libcrypto/bn/bn_sqrt.c
@@ -1,4 +1,4 @@
1/* crypto/bn/bn_sqrt.c */ 1/* crypto/bn/bn_mod.c */
2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * and Bodo Moeller for the OpenSSL project. */ 3 * and Bodo Moeller for the OpenSSL project. */
4/* ==================================================================== 4/* ====================================================================
@@ -65,12 +65,14 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
65 * using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course 65 * using the Tonelli/Shanks algorithm (cf. Henri Cohen, "A Course
66 * in Algebraic Computational Number Theory", algorithm 1.5.1). 66 * in Algebraic Computational Number Theory", algorithm 1.5.1).
67 * 'p' must be prime! 67 * 'p' must be prime!
68 * If 'a' is not a square, this is not necessarily detected by
69 * the algorithms; a bogus result must be expected in this case.
68 */ 70 */
69 { 71 {
70 BIGNUM *ret = in; 72 BIGNUM *ret = in;
71 int err = 1; 73 int err = 1;
72 int r; 74 int r;
73 BIGNUM *A, *b, *q, *t, *x, *y; 75 BIGNUM *b, *q, *t, *x, *y;
74 int e, i, j; 76 int e, i, j;
75 77
76 if (!BN_is_odd(p) || BN_abs_is_word(p, 1)) 78 if (!BN_is_odd(p) || BN_abs_is_word(p, 1))
@@ -83,11 +85,9 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
83 goto end; 85 goto end;
84 if (!BN_set_word(ret, BN_is_bit_set(a, 0))) 86 if (!BN_set_word(ret, BN_is_bit_set(a, 0)))
85 { 87 {
86 if (ret != in) 88 BN_free(ret);
87 BN_free(ret);
88 return NULL; 89 return NULL;
89 } 90 }
90 bn_check_top(ret);
91 return ret; 91 return ret;
92 } 92 }
93 93
@@ -103,16 +103,23 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
103 goto end; 103 goto end;
104 if (!BN_set_word(ret, BN_is_one(a))) 104 if (!BN_set_word(ret, BN_is_one(a)))
105 { 105 {
106 if (ret != in) 106 BN_free(ret);
107 BN_free(ret);
108 return NULL; 107 return NULL;
109 } 108 }
110 bn_check_top(ret);
111 return ret; 109 return ret;
112 } 110 }
113 111
112#if 0 /* if BN_mod_sqrt is used with correct input, this just wastes time */
113 r = BN_kronecker(a, p, ctx);
114 if (r < -1) return NULL;
115 if (r == -1)
116 {
117 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
118 return(NULL);
119 }
120#endif
121
114 BN_CTX_start(ctx); 122 BN_CTX_start(ctx);
115 A = BN_CTX_get(ctx);
116 b = BN_CTX_get(ctx); 123 b = BN_CTX_get(ctx);
117 q = BN_CTX_get(ctx); 124 q = BN_CTX_get(ctx);
118 t = BN_CTX_get(ctx); 125 t = BN_CTX_get(ctx);
@@ -124,9 +131,6 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
124 ret = BN_new(); 131 ret = BN_new();
125 if (ret == NULL) goto end; 132 if (ret == NULL) goto end;
126 133
127 /* A = a mod p */
128 if (!BN_nnmod(A, a, p, ctx)) goto end;
129
130 /* now write |p| - 1 as 2^e*q where q is odd */ 134 /* now write |p| - 1 as 2^e*q where q is odd */
131 e = 1; 135 e = 1;
132 while (!BN_is_bit_set(p, e)) 136 while (!BN_is_bit_set(p, e))
@@ -145,9 +149,9 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
145 if (!BN_rshift(q, p, 2)) goto end; 149 if (!BN_rshift(q, p, 2)) goto end;
146 q->neg = 0; 150 q->neg = 0;
147 if (!BN_add_word(q, 1)) goto end; 151 if (!BN_add_word(q, 1)) goto end;
148 if (!BN_mod_exp(ret, A, q, p, ctx)) goto end; 152 if (!BN_mod_exp(ret, a, q, p, ctx)) goto end;
149 err = 0; 153 err = 0;
150 goto vrfy; 154 goto end;
151 } 155 }
152 156
153 if (e == 2) 157 if (e == 2)
@@ -178,8 +182,15 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
178 * November 1992.) 182 * November 1992.)
179 */ 183 */
180 184
185 /* make sure that a is reduced modulo p */
186 if (a->neg || BN_ucmp(a, p) >= 0)
187 {
188 if (!BN_nnmod(x, a, p, ctx)) goto end;
189 a = x; /* use x as temporary variable */
190 }
191
181 /* t := 2*a */ 192 /* t := 2*a */
182 if (!BN_mod_lshift1_quick(t, A, p)) goto end; 193 if (!BN_mod_lshift1_quick(t, a, p)) goto end;
183 194
184 /* b := (2*a)^((|p|-5)/8) */ 195 /* b := (2*a)^((|p|-5)/8) */
185 if (!BN_rshift(q, p, 3)) goto end; 196 if (!BN_rshift(q, p, 3)) goto end;
@@ -194,12 +205,12 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
194 if (!BN_sub_word(t, 1)) goto end; 205 if (!BN_sub_word(t, 1)) goto end;
195 206
196 /* x = a*b*t */ 207 /* x = a*b*t */
197 if (!BN_mod_mul(x, A, b, p, ctx)) goto end; 208 if (!BN_mod_mul(x, a, b, p, ctx)) goto end;
198 if (!BN_mod_mul(x, x, t, p, ctx)) goto end; 209 if (!BN_mod_mul(x, x, t, p, ctx)) goto end;
199 210
200 if (!BN_copy(ret, x)) goto end; 211 if (!BN_copy(ret, x)) goto end;
201 err = 0; 212 err = 0;
202 goto vrfy; 213 goto end;
203 } 214 }
204 215
205 /* e > 2, so we really have to use the Tonelli/Shanks algorithm. 216 /* e > 2, so we really have to use the Tonelli/Shanks algorithm.
@@ -286,11 +297,11 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
286 /* x := a^((q-1)/2) */ 297 /* x := a^((q-1)/2) */
287 if (BN_is_zero(t)) /* special case: p = 2^e + 1 */ 298 if (BN_is_zero(t)) /* special case: p = 2^e + 1 */
288 { 299 {
289 if (!BN_nnmod(t, A, p, ctx)) goto end; 300 if (!BN_nnmod(t, a, p, ctx)) goto end;
290 if (BN_is_zero(t)) 301 if (BN_is_zero(t))
291 { 302 {
292 /* special case: a == 0 (mod p) */ 303 /* special case: a == 0 (mod p) */
293 BN_zero(ret); 304 if (!BN_zero(ret)) goto end;
294 err = 0; 305 err = 0;
295 goto end; 306 goto end;
296 } 307 }
@@ -299,11 +310,11 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
299 } 310 }
300 else 311 else
301 { 312 {
302 if (!BN_mod_exp(x, A, t, p, ctx)) goto end; 313 if (!BN_mod_exp(x, a, t, p, ctx)) goto end;
303 if (BN_is_zero(x)) 314 if (BN_is_zero(x))
304 { 315 {
305 /* special case: a == 0 (mod p) */ 316 /* special case: a == 0 (mod p) */
306 BN_zero(ret); 317 if (!BN_zero(ret)) goto end;
307 err = 0; 318 err = 0;
308 goto end; 319 goto end;
309 } 320 }
@@ -311,10 +322,10 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
311 322
312 /* b := a*x^2 (= a^q) */ 323 /* b := a*x^2 (= a^q) */
313 if (!BN_mod_sqr(b, x, p, ctx)) goto end; 324 if (!BN_mod_sqr(b, x, p, ctx)) goto end;
314 if (!BN_mod_mul(b, b, A, p, ctx)) goto end; 325 if (!BN_mod_mul(b, b, a, p, ctx)) goto end;
315 326
316 /* x := a*x (= a^((q+1)/2)) */ 327 /* x := a*x (= a^((q+1)/2)) */
317 if (!BN_mod_mul(x, x, A, p, ctx)) goto end; 328 if (!BN_mod_mul(x, x, a, p, ctx)) goto end;
318 329
319 while (1) 330 while (1)
320 { 331 {
@@ -331,7 +342,7 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
331 { 342 {
332 if (!BN_copy(ret, x)) goto end; 343 if (!BN_copy(ret, x)) goto end;
333 err = 0; 344 err = 0;
334 goto vrfy; 345 goto end;
335 } 346 }
336 347
337 348
@@ -362,22 +373,6 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
362 e = i; 373 e = i;
363 } 374 }
364 375
365 vrfy:
366 if (!err)
367 {
368 /* verify the result -- the input might have been not a square
369 * (test added in 0.9.8) */
370
371 if (!BN_mod_sqr(x, ret, p, ctx))
372 err = 1;
373
374 if (!err && 0 != BN_cmp(x, A))
375 {
376 BNerr(BN_F_BN_MOD_SQRT, BN_R_NOT_A_SQUARE);
377 err = 1;
378 }
379 }
380
381 end: 376 end:
382 if (err) 377 if (err)
383 { 378 {
@@ -388,6 +383,5 @@ BIGNUM *BN_mod_sqrt(BIGNUM *in, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
388 ret = NULL; 383 ret = NULL;
389 } 384 }
390 BN_CTX_end(ctx); 385 BN_CTX_end(ctx);
391 bn_check_top(ret);
392 return ret; 386 return ret;
393 } 387 }
diff --git a/src/lib/libcrypto/bn/bn_word.c b/src/lib/libcrypto/bn/bn_word.c
index ee7b87c45c..de610ce54c 100644
--- a/src/lib/libcrypto/bn/bn_word.c
+++ b/src/lib/libcrypto/bn/bn_word.c
@@ -69,10 +69,6 @@ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
69#endif 69#endif
70 int i; 70 int i;
71 71
72 if (w == 0)
73 return (BN_ULONG)-1;
74
75 bn_check_top(a);
76 w&=BN_MASK2; 72 w&=BN_MASK2;
77 for (i=a->top-1; i>=0; i--) 73 for (i=a->top-1; i>=0; i--)
78 { 74 {
@@ -89,24 +85,12 @@ BN_ULONG BN_mod_word(const BIGNUM *a, BN_ULONG w)
89 85
90BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w) 86BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
91 { 87 {
92 BN_ULONG ret = 0; 88 BN_ULONG ret;
93 int i, j; 89 int i;
94
95 bn_check_top(a);
96 w &= BN_MASK2;
97
98 if (!w)
99 /* actually this an error (division by zero) */
100 return (BN_ULONG)-1;
101 if (a->top == 0)
102 return 0;
103
104 /* normalize input (so bn_div_words doesn't complain) */
105 j = BN_BITS2 - BN_num_bits_word(w);
106 w <<= j;
107 if (!BN_lshift(a, a, j))
108 return (BN_ULONG)-1;
109 90
91 if (a->top == 0) return(0);
92 ret=0;
93 w&=BN_MASK2;
110 for (i=a->top-1; i>=0; i--) 94 for (i=a->top-1; i>=0; i--)
111 { 95 {
112 BN_ULONG l,d; 96 BN_ULONG l,d;
@@ -118,8 +102,6 @@ BN_ULONG BN_div_word(BIGNUM *a, BN_ULONG w)
118 } 102 }
119 if ((a->top > 0) && (a->d[a->top-1] == 0)) 103 if ((a->top > 0) && (a->d[a->top-1] == 0))
120 a->top--; 104 a->top--;
121 ret >>= j;
122 bn_check_top(a);
123 return(ret); 105 return(ret);
124 } 106 }
125 107
@@ -128,14 +110,9 @@ int BN_add_word(BIGNUM *a, BN_ULONG w)
128 BN_ULONG l; 110 BN_ULONG l;
129 int i; 111 int i;
130 112
131 bn_check_top(a); 113 if ((w & BN_MASK2) == 0)
132 w &= BN_MASK2; 114 return(1);
133 115
134 /* degenerate case: w is zero */
135 if (!w) return 1;
136 /* degenerate case: a is zero */
137 if(BN_is_zero(a)) return BN_set_word(a, w);
138 /* handle 'a' when negative */
139 if (a->neg) 116 if (a->neg)
140 { 117 {
141 a->neg=0; 118 a->neg=0;
@@ -144,17 +121,15 @@ int BN_add_word(BIGNUM *a, BN_ULONG w)
144 a->neg=!(a->neg); 121 a->neg=!(a->neg);
145 return(i); 122 return(i);
146 } 123 }
147 /* Only expand (and risk failing) if it's possibly necessary */ 124 w&=BN_MASK2;
148 if (((BN_ULONG)(a->d[a->top - 1] + 1) == 0) && 125 if (bn_wexpand(a,a->top+1) == NULL) return(0);
149 (bn_wexpand(a,a->top+1) == NULL))
150 return(0);
151 i=0; 126 i=0;
152 for (;;) 127 for (;;)
153 { 128 {
154 if (i >= a->top) 129 if (i >= a->top)
155 l=w; 130 l=w;
156 else 131 else
157 l=(a->d[i]+w)&BN_MASK2; 132 l=(a->d[i]+(BN_ULONG)w)&BN_MASK2;
158 a->d[i]=l; 133 a->d[i]=l;
159 if (w > l) 134 if (w > l)
160 w=1; 135 w=1;
@@ -164,7 +139,6 @@ int BN_add_word(BIGNUM *a, BN_ULONG w)
164 } 139 }
165 if (i >= a->top) 140 if (i >= a->top)
166 a->top++; 141 a->top++;
167 bn_check_top(a);
168 return(1); 142 return(1);
169 } 143 }
170 144
@@ -172,21 +146,10 @@ int BN_sub_word(BIGNUM *a, BN_ULONG w)
172 { 146 {
173 int i; 147 int i;
174 148
175 bn_check_top(a); 149 if ((w & BN_MASK2) == 0)
176 w &= BN_MASK2; 150 return(1);
177 151
178 /* degenerate case: w is zero */ 152 if (BN_is_zero(a) || a->neg)
179 if (!w) return 1;
180 /* degenerate case: a is zero */
181 if(BN_is_zero(a))
182 {
183 i = BN_set_word(a,w);
184 if (i != 0)
185 BN_set_negative(a, 1);
186 return i;
187 }
188 /* handle 'a' when negative */
189 if (a->neg)
190 { 153 {
191 a->neg=0; 154 a->neg=0;
192 i=BN_add_word(a,w); 155 i=BN_add_word(a,w);
@@ -194,6 +157,7 @@ int BN_sub_word(BIGNUM *a, BN_ULONG w)
194 return(i); 157 return(i);
195 } 158 }
196 159
160 w&=BN_MASK2;
197 if ((a->top == 1) && (a->d[0] < w)) 161 if ((a->top == 1) && (a->d[0] < w))
198 { 162 {
199 a->d[0]=w-a->d[0]; 163 a->d[0]=w-a->d[0];
@@ -217,7 +181,6 @@ int BN_sub_word(BIGNUM *a, BN_ULONG w)
217 } 181 }
218 if ((a->d[i] == 0) && (i == (a->top-1))) 182 if ((a->d[i] == 0) && (i == (a->top-1)))
219 a->top--; 183 a->top--;
220 bn_check_top(a);
221 return(1); 184 return(1);
222 } 185 }
223 186
@@ -225,7 +188,6 @@ int BN_mul_word(BIGNUM *a, BN_ULONG w)
225 { 188 {
226 BN_ULONG ll; 189 BN_ULONG ll;
227 190
228 bn_check_top(a);
229 w&=BN_MASK2; 191 w&=BN_MASK2;
230 if (a->top) 192 if (a->top)
231 { 193 {
@@ -241,7 +203,6 @@ int BN_mul_word(BIGNUM *a, BN_ULONG w)
241 } 203 }
242 } 204 }
243 } 205 }
244 bn_check_top(a);
245 return(1); 206 return(1);
246 } 207 }
247 208
diff --git a/src/lib/libcrypto/bn/bnspeed.c b/src/lib/libcrypto/bn/bnspeed.c
new file mode 100644
index 0000000000..b554ac8cf8
--- /dev/null
+++ b/src/lib/libcrypto/bn/bnspeed.c
@@ -0,0 +1,233 @@
1/* unused */
2
3/* crypto/bn/bnspeed.c */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42 *
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
61/* most of this code has been pilfered from my libdes speed.c program */
62
63#define BASENUM 1000000
64#undef PROG
65#define PROG bnspeed_main
66
67#include <stdio.h>
68#include <stdlib.h>
69#include <signal.h>
70#include <string.h>
71#include <openssl/crypto.h>
72#include <openssl/err.h>
73
74#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
75#define TIMES
76#endif
77
78#ifndef _IRIX
79#include <time.h>
80#endif
81#ifdef TIMES
82#include <sys/types.h>
83#include <sys/times.h>
84#endif
85
86/* Depending on the VMS version, the tms structure is perhaps defined.
87 The __TMS macro will show if it was. If it wasn't defined, we should
88 undefine TIMES, since that tells the rest of the program how things
89 should be handled. -- Richard Levitte */
90#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
91#undef TIMES
92#endif
93
94#ifndef TIMES
95#include <sys/timeb.h>
96#endif
97
98#if defined(sun) || defined(__ultrix)
99#define _POSIX_SOURCE
100#include <limits.h>
101#include <sys/param.h>
102#endif
103
104#include <openssl/bn.h>
105#include <openssl/x509.h>
106
107/* The following if from times(3) man page. It may need to be changed */
108#ifndef HZ
109# ifndef CLK_TCK
110# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
111# define HZ 100.0
112# else /* _BSD_CLK_TCK_ */
113# define HZ ((double)_BSD_CLK_TCK_)
114# endif
115# else /* CLK_TCK */
116# define HZ ((double)CLK_TCK)
117# endif
118#endif
119
120#undef BUFSIZE
121#define BUFSIZE ((long)1024*8)
122int run=0;
123
124static double Time_F(int s);
125#define START 0
126#define STOP 1
127
128static double Time_F(int s)
129 {
130 double ret;
131#ifdef TIMES
132 static struct tms tstart,tend;
133
134 if (s == START)
135 {
136 times(&tstart);
137 return(0);
138 }
139 else
140 {
141 times(&tend);
142 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
143 return((ret < 1e-3)?1e-3:ret);
144 }
145#else /* !times() */
146 static struct timeb tstart,tend;
147 long i;
148
149 if (s == START)
150 {
151 ftime(&tstart);
152 return(0);
153 }
154 else
155 {
156 ftime(&tend);
157 i=(long)tend.millitm-(long)tstart.millitm;
158 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
159 return((ret < 0.001)?0.001:ret);
160 }
161#endif
162 }
163
164#define NUM_SIZES 5
165static int sizes[NUM_SIZES]={128,256,512,1024,2048};
166/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
167
168void do_mul(BIGNUM *r,BIGNUM *a,BIGNUM *b,BN_CTX *ctx);
169
170int main(int argc, char **argv)
171 {
172 BN_CTX *ctx;
173 BIGNUM a,b,c;
174
175 ctx=BN_CTX_new();
176 BN_init(&a);
177 BN_init(&b);
178 BN_init(&c);
179
180 do_mul(&a,&b,&c,ctx);
181 }
182
183void do_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
184 {
185 int i,j,k;
186 double tm;
187 long num;
188
189 for (i=0; i<NUM_SIZES; i++)
190 {
191 num=BASENUM;
192 if (i) num/=(i*3);
193 BN_rand(a,sizes[i],1,0);
194 for (j=i; j<NUM_SIZES; j++)
195 {
196 BN_rand(b,sizes[j],1,0);
197 Time_F(START);
198 for (k=0; k<num; k++)
199 BN_mul(r,b,a,ctx);
200 tm=Time_F(STOP);
201 printf("mul %4d x %4d -> %8.3fms\n",sizes[i],sizes[j],tm*1000.0/num);
202 }
203 }
204
205 for (i=0; i<NUM_SIZES; i++)
206 {
207 num=BASENUM;
208 if (i) num/=(i*3);
209 BN_rand(a,sizes[i],1,0);
210 Time_F(START);
211 for (k=0; k<num; k++)
212 BN_sqr(r,a,ctx);
213 tm=Time_F(STOP);
214 printf("sqr %4d x %4d -> %8.3fms\n",sizes[i],sizes[i],tm*1000.0/num);
215 }
216
217 for (i=0; i<NUM_SIZES; i++)
218 {
219 num=BASENUM/10;
220 if (i) num/=(i*3);
221 BN_rand(a,sizes[i]-1,1,0);
222 for (j=i; j<NUM_SIZES; j++)
223 {
224 BN_rand(b,sizes[j],1,0);
225 Time_F(START);
226 for (k=0; k<100000; k++)
227 BN_div(r, NULL, b, a,ctx);
228 tm=Time_F(STOP);
229 printf("div %4d / %4d -> %8.3fms\n",sizes[j],sizes[i]-1,tm*1000.0/num);
230 }
231 }
232 }
233
diff --git a/src/lib/libcrypto/bn/bntest.c b/src/lib/libcrypto/bn/bntest.c
new file mode 100644
index 0000000000..792a75ff4f
--- /dev/null
+++ b/src/lib/libcrypto/bn/bntest.c
@@ -0,0 +1,1290 @@
1/* crypto/bn/bntest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "e_os.h"
64
65#include <openssl/bio.h>
66#include <openssl/bn.h>
67#include <openssl/rand.h>
68#include <openssl/x509.h>
69#include <openssl/err.h>
70
71const int num0 = 100; /* number of tests */
72const int num1 = 50; /* additional tests for some functions */
73const int num2 = 5; /* number of tests for slow functions */
74
75int test_add(BIO *bp);
76int test_sub(BIO *bp);
77int test_lshift1(BIO *bp);
78int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_);
79int test_rshift1(BIO *bp);
80int test_rshift(BIO *bp,BN_CTX *ctx);
81int test_div(BIO *bp,BN_CTX *ctx);
82int test_div_recp(BIO *bp,BN_CTX *ctx);
83int test_mul(BIO *bp);
84int test_sqr(BIO *bp,BN_CTX *ctx);
85int test_mont(BIO *bp,BN_CTX *ctx);
86int test_mod(BIO *bp,BN_CTX *ctx);
87int test_mod_mul(BIO *bp,BN_CTX *ctx);
88int test_mod_exp(BIO *bp,BN_CTX *ctx);
89int test_mod_exp_mont_consttime(BIO *bp,BN_CTX *ctx);
90int test_exp(BIO *bp,BN_CTX *ctx);
91int test_kron(BIO *bp,BN_CTX *ctx);
92int test_sqrt(BIO *bp,BN_CTX *ctx);
93int rand_neg(void);
94static int results=0;
95
96static unsigned char lst[]="\xC6\x4F\x43\x04\x2A\xEA\xCA\x6E\x58\x36\x80\x5B\xE8\xC9"
97"\x9B\x04\x5D\x48\x36\xC2\xFD\x16\xC9\x64\xF0";
98
99static const char rnd_seed[] = "string to make the random number generator think it has entropy";
100
101static void message(BIO *out, char *m)
102 {
103 fprintf(stderr, "test %s\n", m);
104 BIO_puts(out, "print \"test ");
105 BIO_puts(out, m);
106 BIO_puts(out, "\\n\"\n");
107 }
108
109int main(int argc, char *argv[])
110 {
111 BN_CTX *ctx;
112 BIO *out;
113 char *outfile=NULL;
114
115 results = 0;
116
117 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */
118
119 argc--;
120 argv++;
121 while (argc >= 1)
122 {
123 if (strcmp(*argv,"-results") == 0)
124 results=1;
125 else if (strcmp(*argv,"-out") == 0)
126 {
127 if (--argc < 1) break;
128 outfile= *(++argv);
129 }
130 argc--;
131 argv++;
132 }
133
134
135 ctx=BN_CTX_new();
136 if (ctx == NULL) EXIT(1);
137
138 out=BIO_new(BIO_s_file());
139 if (out == NULL) EXIT(1);
140 if (outfile == NULL)
141 {
142 BIO_set_fp(out,stdout,BIO_NOCLOSE);
143 }
144 else
145 {
146 if (!BIO_write_filename(out,outfile))
147 {
148 perror(outfile);
149 EXIT(1);
150 }
151 }
152
153 if (!results)
154 BIO_puts(out,"obase=16\nibase=16\n");
155
156 message(out,"BN_add");
157 if (!test_add(out)) goto err;
158 BIO_flush(out);
159
160 message(out,"BN_sub");
161 if (!test_sub(out)) goto err;
162 BIO_flush(out);
163
164 message(out,"BN_lshift1");
165 if (!test_lshift1(out)) goto err;
166 BIO_flush(out);
167
168 message(out,"BN_lshift (fixed)");
169 if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL)))
170 goto err;
171 BIO_flush(out);
172
173 message(out,"BN_lshift");
174 if (!test_lshift(out,ctx,NULL)) goto err;
175 BIO_flush(out);
176
177 message(out,"BN_rshift1");
178 if (!test_rshift1(out)) goto err;
179 BIO_flush(out);
180
181 message(out,"BN_rshift");
182 if (!test_rshift(out,ctx)) goto err;
183 BIO_flush(out);
184
185 message(out,"BN_sqr");
186 if (!test_sqr(out,ctx)) goto err;
187 BIO_flush(out);
188
189 message(out,"BN_mul");
190 if (!test_mul(out)) goto err;
191 BIO_flush(out);
192
193 message(out,"BN_div");
194 if (!test_div(out,ctx)) goto err;
195 BIO_flush(out);
196
197 message(out,"BN_div_recp");
198 if (!test_div_recp(out,ctx)) goto err;
199 BIO_flush(out);
200
201 message(out,"BN_mod");
202 if (!test_mod(out,ctx)) goto err;
203 BIO_flush(out);
204
205 message(out,"BN_mod_mul");
206 if (!test_mod_mul(out,ctx)) goto err;
207 BIO_flush(out);
208
209 message(out,"BN_mont");
210 if (!test_mont(out,ctx)) goto err;
211 BIO_flush(out);
212
213 message(out,"BN_mod_exp");
214 if (!test_mod_exp(out,ctx)) goto err;
215 BIO_flush(out);
216
217 message(out,"BN_mod_exp_mont_consttime");
218 if (!test_mod_exp_mont_consttime(out,ctx)) goto err;
219 BIO_flush(out);
220
221 message(out,"BN_exp");
222 if (!test_exp(out,ctx)) goto err;
223 BIO_flush(out);
224
225 message(out,"BN_kronecker");
226 if (!test_kron(out,ctx)) goto err;
227 BIO_flush(out);
228
229 message(out,"BN_mod_sqrt");
230 if (!test_sqrt(out,ctx)) goto err;
231 BIO_flush(out);
232
233 BN_CTX_free(ctx);
234 BIO_free(out);
235
236/**/
237 EXIT(0);
238err:
239 BIO_puts(out,"1\n"); /* make sure the Perl script fed by bc notices
240 * the failure, see test_bn in test/Makefile */
241 BIO_flush(out);
242 ERR_load_crypto_strings();
243 ERR_print_errors_fp(stderr);
244 EXIT(1);
245 return(1);
246 }
247
248int test_add(BIO *bp)
249 {
250 BIGNUM a,b,c;
251 int i;
252
253 BN_init(&a);
254 BN_init(&b);
255 BN_init(&c);
256
257 BN_bntest_rand(&a,512,0,0);
258 for (i=0; i<num0; i++)
259 {
260 BN_bntest_rand(&b,450+i,0,0);
261 a.neg=rand_neg();
262 b.neg=rand_neg();
263 BN_add(&c,&a,&b);
264 if (bp != NULL)
265 {
266 if (!results)
267 {
268 BN_print(bp,&a);
269 BIO_puts(bp," + ");
270 BN_print(bp,&b);
271 BIO_puts(bp," - ");
272 }
273 BN_print(bp,&c);
274 BIO_puts(bp,"\n");
275 }
276 a.neg=!a.neg;
277 b.neg=!b.neg;
278 BN_add(&c,&c,&b);
279 BN_add(&c,&c,&a);
280 if(!BN_is_zero(&c))
281 {
282 fprintf(stderr,"Add test failed!\n");
283 return 0;
284 }
285 }
286 BN_free(&a);
287 BN_free(&b);
288 BN_free(&c);
289 return(1);
290 }
291
292int test_sub(BIO *bp)
293 {
294 BIGNUM a,b,c;
295 int i;
296
297 BN_init(&a);
298 BN_init(&b);
299 BN_init(&c);
300
301 for (i=0; i<num0+num1; i++)
302 {
303 if (i < num1)
304 {
305 BN_bntest_rand(&a,512,0,0);
306 BN_copy(&b,&a);
307 if (BN_set_bit(&a,i)==0) return(0);
308 BN_add_word(&b,i);
309 }
310 else
311 {
312 BN_bntest_rand(&b,400+i-num1,0,0);
313 a.neg=rand_neg();
314 b.neg=rand_neg();
315 }
316 BN_sub(&c,&a,&b);
317 if (bp != NULL)
318 {
319 if (!results)
320 {
321 BN_print(bp,&a);
322 BIO_puts(bp," - ");
323 BN_print(bp,&b);
324 BIO_puts(bp," - ");
325 }
326 BN_print(bp,&c);
327 BIO_puts(bp,"\n");
328 }
329 BN_add(&c,&c,&b);
330 BN_sub(&c,&c,&a);
331 if(!BN_is_zero(&c))
332 {
333 fprintf(stderr,"Subtract test failed!\n");
334 return 0;
335 }
336 }
337 BN_free(&a);
338 BN_free(&b);
339 BN_free(&c);
340 return(1);
341 }
342
343int test_div(BIO *bp, BN_CTX *ctx)
344 {
345 BIGNUM a,b,c,d,e;
346 int i;
347
348 BN_init(&a);
349 BN_init(&b);
350 BN_init(&c);
351 BN_init(&d);
352 BN_init(&e);
353
354 for (i=0; i<num0+num1; i++)
355 {
356 if (i < num1)
357 {
358 BN_bntest_rand(&a,400,0,0);
359 BN_copy(&b,&a);
360 BN_lshift(&a,&a,i);
361 BN_add_word(&a,i);
362 }
363 else
364 BN_bntest_rand(&b,50+3*(i-num1),0,0);
365 a.neg=rand_neg();
366 b.neg=rand_neg();
367 BN_div(&d,&c,&a,&b,ctx);
368 if (bp != NULL)
369 {
370 if (!results)
371 {
372 BN_print(bp,&a);
373 BIO_puts(bp," / ");
374 BN_print(bp,&b);
375 BIO_puts(bp," - ");
376 }
377 BN_print(bp,&d);
378 BIO_puts(bp,"\n");
379
380 if (!results)
381 {
382 BN_print(bp,&a);
383 BIO_puts(bp," % ");
384 BN_print(bp,&b);
385 BIO_puts(bp," - ");
386 }
387 BN_print(bp,&c);
388 BIO_puts(bp,"\n");
389 }
390 BN_mul(&e,&d,&b,ctx);
391 BN_add(&d,&e,&c);
392 BN_sub(&d,&d,&a);
393 if(!BN_is_zero(&d))
394 {
395 fprintf(stderr,"Division test failed!\n");
396 return 0;
397 }
398 }
399 BN_free(&a);
400 BN_free(&b);
401 BN_free(&c);
402 BN_free(&d);
403 BN_free(&e);
404 return(1);
405 }
406
407int test_div_recp(BIO *bp, BN_CTX *ctx)
408 {
409 BIGNUM a,b,c,d,e;
410 BN_RECP_CTX recp;
411 int i;
412
413 BN_RECP_CTX_init(&recp);
414 BN_init(&a);
415 BN_init(&b);
416 BN_init(&c);
417 BN_init(&d);
418 BN_init(&e);
419
420 for (i=0; i<num0+num1; i++)
421 {
422 if (i < num1)
423 {
424 BN_bntest_rand(&a,400,0,0);
425 BN_copy(&b,&a);
426 BN_lshift(&a,&a,i);
427 BN_add_word(&a,i);
428 }
429 else
430 BN_bntest_rand(&b,50+3*(i-num1),0,0);
431 a.neg=rand_neg();
432 b.neg=rand_neg();
433 BN_RECP_CTX_set(&recp,&b,ctx);
434 BN_div_recp(&d,&c,&a,&recp,ctx);
435 if (bp != NULL)
436 {
437 if (!results)
438 {
439 BN_print(bp,&a);
440 BIO_puts(bp," / ");
441 BN_print(bp,&b);
442 BIO_puts(bp," - ");
443 }
444 BN_print(bp,&d);
445 BIO_puts(bp,"\n");
446
447 if (!results)
448 {
449 BN_print(bp,&a);
450 BIO_puts(bp," % ");
451 BN_print(bp,&b);
452 BIO_puts(bp," - ");
453 }
454 BN_print(bp,&c);
455 BIO_puts(bp,"\n");
456 }
457 BN_mul(&e,&d,&b,ctx);
458 BN_add(&d,&e,&c);
459 BN_sub(&d,&d,&a);
460 if(!BN_is_zero(&d))
461 {
462 fprintf(stderr,"Reciprocal division test failed!\n");
463 fprintf(stderr,"a=");
464 BN_print_fp(stderr,&a);
465 fprintf(stderr,"\nb=");
466 BN_print_fp(stderr,&b);
467 fprintf(stderr,"\n");
468 return 0;
469 }
470 }
471 BN_free(&a);
472 BN_free(&b);
473 BN_free(&c);
474 BN_free(&d);
475 BN_free(&e);
476 BN_RECP_CTX_free(&recp);
477 return(1);
478 }
479
480int test_mul(BIO *bp)
481 {
482 BIGNUM a,b,c,d,e;
483 int i;
484 BN_CTX *ctx;
485
486 ctx = BN_CTX_new();
487 if (ctx == NULL) EXIT(1);
488
489 BN_init(&a);
490 BN_init(&b);
491 BN_init(&c);
492 BN_init(&d);
493 BN_init(&e);
494
495 for (i=0; i<num0+num1; i++)
496 {
497 if (i <= num1)
498 {
499 BN_bntest_rand(&a,100,0,0);
500 BN_bntest_rand(&b,100,0,0);
501 }
502 else
503 BN_bntest_rand(&b,i-num1,0,0);
504 a.neg=rand_neg();
505 b.neg=rand_neg();
506 BN_mul(&c,&a,&b,ctx);
507 if (bp != NULL)
508 {
509 if (!results)
510 {
511 BN_print(bp,&a);
512 BIO_puts(bp," * ");
513 BN_print(bp,&b);
514 BIO_puts(bp," - ");
515 }
516 BN_print(bp,&c);
517 BIO_puts(bp,"\n");
518 }
519 BN_div(&d,&e,&c,&a,ctx);
520 BN_sub(&d,&d,&b);
521 if(!BN_is_zero(&d) || !BN_is_zero(&e))
522 {
523 fprintf(stderr,"Multiplication test failed!\n");
524 return 0;
525 }
526 }
527 BN_free(&a);
528 BN_free(&b);
529 BN_free(&c);
530 BN_free(&d);
531 BN_free(&e);
532 BN_CTX_free(ctx);
533 return(1);
534 }
535
536int test_sqr(BIO *bp, BN_CTX *ctx)
537 {
538 BIGNUM a,c,d,e;
539 int i;
540
541 BN_init(&a);
542 BN_init(&c);
543 BN_init(&d);
544 BN_init(&e);
545
546 for (i=0; i<num0; i++)
547 {
548 BN_bntest_rand(&a,40+i*10,0,0);
549 a.neg=rand_neg();
550 BN_sqr(&c,&a,ctx);
551 if (bp != NULL)
552 {
553 if (!results)
554 {
555 BN_print(bp,&a);
556 BIO_puts(bp," * ");
557 BN_print(bp,&a);
558 BIO_puts(bp," - ");
559 }
560 BN_print(bp,&c);
561 BIO_puts(bp,"\n");
562 }
563 BN_div(&d,&e,&c,&a,ctx);
564 BN_sub(&d,&d,&a);
565 if(!BN_is_zero(&d) || !BN_is_zero(&e))
566 {
567 fprintf(stderr,"Square test failed!\n");
568 return 0;
569 }
570 }
571 BN_free(&a);
572 BN_free(&c);
573 BN_free(&d);
574 BN_free(&e);
575 return(1);
576 }
577
578int test_mont(BIO *bp, BN_CTX *ctx)
579 {
580 BIGNUM a,b,c,d,A,B;
581 BIGNUM n;
582 int i;
583 BN_MONT_CTX *mont;
584
585 BN_init(&a);
586 BN_init(&b);
587 BN_init(&c);
588 BN_init(&d);
589 BN_init(&A);
590 BN_init(&B);
591 BN_init(&n);
592
593 mont=BN_MONT_CTX_new();
594
595 BN_bntest_rand(&a,100,0,0); /**/
596 BN_bntest_rand(&b,100,0,0); /**/
597 for (i=0; i<num2; i++)
598 {
599 int bits = (200*(i+1))/num2;
600
601 if (bits == 0)
602 continue;
603 BN_bntest_rand(&n,bits,0,1);
604 BN_MONT_CTX_set(mont,&n,ctx);
605
606 BN_nnmod(&a,&a,&n,ctx);
607 BN_nnmod(&b,&b,&n,ctx);
608
609 BN_to_montgomery(&A,&a,mont,ctx);
610 BN_to_montgomery(&B,&b,mont,ctx);
611
612 BN_mod_mul_montgomery(&c,&A,&B,mont,ctx);/**/
613 BN_from_montgomery(&A,&c,mont,ctx);/**/
614 if (bp != NULL)
615 {
616 if (!results)
617 {
618#ifdef undef
619fprintf(stderr,"%d * %d %% %d\n",
620BN_num_bits(&a),
621BN_num_bits(&b),
622BN_num_bits(mont->N));
623#endif
624 BN_print(bp,&a);
625 BIO_puts(bp," * ");
626 BN_print(bp,&b);
627 BIO_puts(bp," % ");
628 BN_print(bp,&(mont->N));
629 BIO_puts(bp," - ");
630 }
631 BN_print(bp,&A);
632 BIO_puts(bp,"\n");
633 }
634 BN_mod_mul(&d,&a,&b,&n,ctx);
635 BN_sub(&d,&d,&A);
636 if(!BN_is_zero(&d))
637 {
638 fprintf(stderr,"Montgomery multiplication test failed!\n");
639 return 0;
640 }
641 }
642 BN_MONT_CTX_free(mont);
643 BN_free(&a);
644 BN_free(&b);
645 BN_free(&c);
646 BN_free(&d);
647 BN_free(&A);
648 BN_free(&B);
649 BN_free(&n);
650 return(1);
651 }
652
653int test_mod(BIO *bp, BN_CTX *ctx)
654 {
655 BIGNUM *a,*b,*c,*d,*e;
656 int i;
657
658 a=BN_new();
659 b=BN_new();
660 c=BN_new();
661 d=BN_new();
662 e=BN_new();
663
664 BN_bntest_rand(a,1024,0,0); /**/
665 for (i=0; i<num0; i++)
666 {
667 BN_bntest_rand(b,450+i*10,0,0); /**/
668 a->neg=rand_neg();
669 b->neg=rand_neg();
670 BN_mod(c,a,b,ctx);/**/
671 if (bp != NULL)
672 {
673 if (!results)
674 {
675 BN_print(bp,a);
676 BIO_puts(bp," % ");
677 BN_print(bp,b);
678 BIO_puts(bp," - ");
679 }
680 BN_print(bp,c);
681 BIO_puts(bp,"\n");
682 }
683 BN_div(d,e,a,b,ctx);
684 BN_sub(e,e,c);
685 if(!BN_is_zero(e))
686 {
687 fprintf(stderr,"Modulo test failed!\n");
688 return 0;
689 }
690 }
691 BN_free(a);
692 BN_free(b);
693 BN_free(c);
694 BN_free(d);
695 BN_free(e);
696 return(1);
697 }
698
699int test_mod_mul(BIO *bp, BN_CTX *ctx)
700 {
701 BIGNUM *a,*b,*c,*d,*e;
702 int i,j;
703
704 a=BN_new();
705 b=BN_new();
706 c=BN_new();
707 d=BN_new();
708 e=BN_new();
709
710 for (j=0; j<3; j++) {
711 BN_bntest_rand(c,1024,0,0); /**/
712 for (i=0; i<num0; i++)
713 {
714 BN_bntest_rand(a,475+i*10,0,0); /**/
715 BN_bntest_rand(b,425+i*11,0,0); /**/
716 a->neg=rand_neg();
717 b->neg=rand_neg();
718 if (!BN_mod_mul(e,a,b,c,ctx))
719 {
720 unsigned long l;
721
722 while ((l=ERR_get_error()))
723 fprintf(stderr,"ERROR:%s\n",
724 ERR_error_string(l,NULL));
725 EXIT(1);
726 }
727 if (bp != NULL)
728 {
729 if (!results)
730 {
731 BN_print(bp,a);
732 BIO_puts(bp," * ");
733 BN_print(bp,b);
734 BIO_puts(bp," % ");
735 BN_print(bp,c);
736 if ((a->neg ^ b->neg) && !BN_is_zero(e))
737 {
738 /* If (a*b) % c is negative, c must be added
739 * in order to obtain the normalized remainder
740 * (new with OpenSSL 0.9.7, previous versions of
741 * BN_mod_mul could generate negative results)
742 */
743 BIO_puts(bp," + ");
744 BN_print(bp,c);
745 }
746 BIO_puts(bp," - ");
747 }
748 BN_print(bp,e);
749 BIO_puts(bp,"\n");
750 }
751 BN_mul(d,a,b,ctx);
752 BN_sub(d,d,e);
753 BN_div(a,b,d,c,ctx);
754 if(!BN_is_zero(b))
755 {
756 fprintf(stderr,"Modulo multiply test failed!\n");
757 ERR_print_errors_fp(stderr);
758 return 0;
759 }
760 }
761 }
762 BN_free(a);
763 BN_free(b);
764 BN_free(c);
765 BN_free(d);
766 BN_free(e);
767 return(1);
768 }
769
770int test_mod_exp(BIO *bp, BN_CTX *ctx)
771 {
772 BIGNUM *a,*b,*c,*d,*e;
773 int i;
774
775 a=BN_new();
776 b=BN_new();
777 c=BN_new();
778 d=BN_new();
779 e=BN_new();
780
781 BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */
782 for (i=0; i<num2; i++)
783 {
784 BN_bntest_rand(a,20+i*5,0,0); /**/
785 BN_bntest_rand(b,2+i,0,0); /**/
786
787 if (!BN_mod_exp(d,a,b,c,ctx))
788 return(0);
789
790 if (bp != NULL)
791 {
792 if (!results)
793 {
794 BN_print(bp,a);
795 BIO_puts(bp," ^ ");
796 BN_print(bp,b);
797 BIO_puts(bp," % ");
798 BN_print(bp,c);
799 BIO_puts(bp," - ");
800 }
801 BN_print(bp,d);
802 BIO_puts(bp,"\n");
803 }
804 BN_exp(e,a,b,ctx);
805 BN_sub(e,e,d);
806 BN_div(a,b,e,c,ctx);
807 if(!BN_is_zero(b))
808 {
809 fprintf(stderr,"Modulo exponentiation test failed!\n");
810 return 0;
811 }
812 }
813 BN_free(a);
814 BN_free(b);
815 BN_free(c);
816 BN_free(d);
817 BN_free(e);
818 return(1);
819 }
820
821int test_mod_exp_mont_consttime(BIO *bp, BN_CTX *ctx)
822 {
823 BIGNUM *a,*b,*c,*d,*e;
824 int i;
825
826 a=BN_new();
827 b=BN_new();
828 c=BN_new();
829 d=BN_new();
830 e=BN_new();
831
832 BN_bntest_rand(c,30,0,1); /* must be odd for montgomery */
833 for (i=0; i<num2; i++)
834 {
835 BN_bntest_rand(a,20+i*5,0,0); /**/
836 BN_bntest_rand(b,2+i,0,0); /**/
837
838 if (!BN_mod_exp_mont_consttime(d,a,b,c,ctx,NULL))
839 return(00);
840
841 if (bp != NULL)
842 {
843 if (!results)
844 {
845 BN_print(bp,a);
846 BIO_puts(bp," ^ ");
847 BN_print(bp,b);
848 BIO_puts(bp," % ");
849 BN_print(bp,c);
850 BIO_puts(bp," - ");
851 }
852 BN_print(bp,d);
853 BIO_puts(bp,"\n");
854 }
855 BN_exp(e,a,b,ctx);
856 BN_sub(e,e,d);
857 BN_div(a,b,e,c,ctx);
858 if(!BN_is_zero(b))
859 {
860 fprintf(stderr,"Modulo exponentiation test failed!\n");
861 return 0;
862 }
863 }
864 BN_free(a);
865 BN_free(b);
866 BN_free(c);
867 BN_free(d);
868 BN_free(e);
869 return(1);
870 }
871
872int test_exp(BIO *bp, BN_CTX *ctx)
873 {
874 BIGNUM *a,*b,*d,*e,*one;
875 int i;
876
877 a=BN_new();
878 b=BN_new();
879 d=BN_new();
880 e=BN_new();
881 one=BN_new();
882 BN_one(one);
883
884 for (i=0; i<num2; i++)
885 {
886 BN_bntest_rand(a,20+i*5,0,0); /**/
887 BN_bntest_rand(b,2+i,0,0); /**/
888
889 if (!BN_exp(d,a,b,ctx))
890 return(0);
891
892 if (bp != NULL)
893 {
894 if (!results)
895 {
896 BN_print(bp,a);
897 BIO_puts(bp," ^ ");
898 BN_print(bp,b);
899 BIO_puts(bp," - ");
900 }
901 BN_print(bp,d);
902 BIO_puts(bp,"\n");
903 }
904 BN_one(e);
905 for( ; !BN_is_zero(b) ; BN_sub(b,b,one))
906 BN_mul(e,e,a,ctx);
907 BN_sub(e,e,d);
908 if(!BN_is_zero(e))
909 {
910 fprintf(stderr,"Exponentiation test failed!\n");
911 return 0;
912 }
913 }
914 BN_free(a);
915 BN_free(b);
916 BN_free(d);
917 BN_free(e);
918 BN_free(one);
919 return(1);
920 }
921
922static void genprime_cb(int p, int n, void *arg)
923 {
924 char c='*';
925
926 if (p == 0) c='.';
927 if (p == 1) c='+';
928 if (p == 2) c='*';
929 if (p == 3) c='\n';
930 putc(c, stderr);
931 fflush(stderr);
932 (void)n;
933 (void)arg;
934 }
935
936int test_kron(BIO *bp, BN_CTX *ctx)
937 {
938 BIGNUM *a,*b,*r,*t;
939 int i;
940 int legendre, kronecker;
941 int ret = 0;
942
943 a = BN_new();
944 b = BN_new();
945 r = BN_new();
946 t = BN_new();
947 if (a == NULL || b == NULL || r == NULL || t == NULL) goto err;
948
949 /* We test BN_kronecker(a, b, ctx) just for b odd (Jacobi symbol).
950 * In this case we know that if b is prime, then BN_kronecker(a, b, ctx)
951 * is congruent to $a^{(b-1)/2}$, modulo $b$ (Legendre symbol).
952 * So we generate a random prime b and compare these values
953 * for a number of random a's. (That is, we run the Solovay-Strassen
954 * primality test to confirm that b is prime, except that we
955 * don't want to test whether b is prime but whether BN_kronecker
956 * works.) */
957
958 if (!BN_generate_prime(b, 512, 0, NULL, NULL, genprime_cb, NULL)) goto err;
959 b->neg = rand_neg();
960 putc('\n', stderr);
961
962 for (i = 0; i < num0; i++)
963 {
964 if (!BN_bntest_rand(a, 512, 0, 0)) goto err;
965 a->neg = rand_neg();
966
967 /* t := (|b|-1)/2 (note that b is odd) */
968 if (!BN_copy(t, b)) goto err;
969 t->neg = 0;
970 if (!BN_sub_word(t, 1)) goto err;
971 if (!BN_rshift1(t, t)) goto err;
972 /* r := a^t mod b */
973 b->neg=0;
974
975 if (!BN_mod_exp_recp(r, a, t, b, ctx)) goto err;
976 b->neg=1;
977
978 if (BN_is_word(r, 1))
979 legendre = 1;
980 else if (BN_is_zero(r))
981 legendre = 0;
982 else
983 {
984 if (!BN_add_word(r, 1)) goto err;
985 if (0 != BN_ucmp(r, b))
986 {
987 fprintf(stderr, "Legendre symbol computation failed\n");
988 goto err;
989 }
990 legendre = -1;
991 }
992
993 kronecker = BN_kronecker(a, b, ctx);
994 if (kronecker < -1) goto err;
995 /* we actually need BN_kronecker(a, |b|) */
996 if (a->neg && b->neg)
997 kronecker = -kronecker;
998
999 if (legendre != kronecker)
1000 {
1001 fprintf(stderr, "legendre != kronecker; a = ");
1002 BN_print_fp(stderr, a);
1003 fprintf(stderr, ", b = ");
1004 BN_print_fp(stderr, b);
1005 fprintf(stderr, "\n");
1006 goto err;
1007 }
1008
1009 putc('.', stderr);
1010 fflush(stderr);
1011 }
1012
1013 putc('\n', stderr);
1014 fflush(stderr);
1015 ret = 1;
1016 err:
1017 if (a != NULL) BN_free(a);
1018 if (b != NULL) BN_free(b);
1019 if (r != NULL) BN_free(r);
1020 if (t != NULL) BN_free(t);
1021 return ret;
1022 }
1023
1024int test_sqrt(BIO *bp, BN_CTX *ctx)
1025 {
1026 BIGNUM *a,*p,*r;
1027 int i, j;
1028 int ret = 0;
1029
1030 a = BN_new();
1031 p = BN_new();
1032 r = BN_new();
1033 if (a == NULL || p == NULL || r == NULL) goto err;
1034
1035 for (i = 0; i < 16; i++)
1036 {
1037 if (i < 8)
1038 {
1039 unsigned primes[8] = { 2, 3, 5, 7, 11, 13, 17, 19 };
1040
1041 if (!BN_set_word(p, primes[i])) goto err;
1042 }
1043 else
1044 {
1045 if (!BN_set_word(a, 32)) goto err;
1046 if (!BN_set_word(r, 2*i + 1)) goto err;
1047
1048 if (!BN_generate_prime(p, 256, 0, a, r, genprime_cb, NULL)) goto err;
1049 putc('\n', stderr);
1050 }
1051 p->neg = rand_neg();
1052
1053 for (j = 0; j < num2; j++)
1054 {
1055 /* construct 'a' such that it is a square modulo p,
1056 * but in general not a proper square and not reduced modulo p */
1057 if (!BN_bntest_rand(r, 256, 0, 3)) goto err;
1058 if (!BN_nnmod(r, r, p, ctx)) goto err;
1059 if (!BN_mod_sqr(r, r, p, ctx)) goto err;
1060 if (!BN_bntest_rand(a, 256, 0, 3)) goto err;
1061 if (!BN_nnmod(a, a, p, ctx)) goto err;
1062 if (!BN_mod_sqr(a, a, p, ctx)) goto err;
1063 if (!BN_mul(a, a, r, ctx)) goto err;
1064 if (rand_neg())
1065 if (!BN_sub(a, a, p)) goto err;
1066
1067 if (!BN_mod_sqrt(r, a, p, ctx)) goto err;
1068 if (!BN_mod_sqr(r, r, p, ctx)) goto err;
1069
1070 if (!BN_nnmod(a, a, p, ctx)) goto err;
1071
1072 if (BN_cmp(a, r) != 0)
1073 {
1074 fprintf(stderr, "BN_mod_sqrt failed: a = ");
1075 BN_print_fp(stderr, a);
1076 fprintf(stderr, ", r = ");
1077 BN_print_fp(stderr, r);
1078 fprintf(stderr, ", p = ");
1079 BN_print_fp(stderr, p);
1080 fprintf(stderr, "\n");
1081 goto err;
1082 }
1083
1084 putc('.', stderr);
1085 fflush(stderr);
1086 }
1087
1088 putc('\n', stderr);
1089 fflush(stderr);
1090 }
1091 ret = 1;
1092 err:
1093 if (a != NULL) BN_free(a);
1094 if (p != NULL) BN_free(p);
1095 if (r != NULL) BN_free(r);
1096 return ret;
1097 }
1098
1099int test_lshift(BIO *bp,BN_CTX *ctx,BIGNUM *a_)
1100 {
1101 BIGNUM *a,*b,*c,*d;
1102 int i;
1103
1104 b=BN_new();
1105 c=BN_new();
1106 d=BN_new();
1107 BN_one(c);
1108
1109 if(a_)
1110 a=a_;
1111 else
1112 {
1113 a=BN_new();
1114 BN_bntest_rand(a,200,0,0); /**/
1115 a->neg=rand_neg();
1116 }
1117 for (i=0; i<num0; i++)
1118 {
1119 BN_lshift(b,a,i+1);
1120 BN_add(c,c,c);
1121 if (bp != NULL)
1122 {
1123 if (!results)
1124 {
1125 BN_print(bp,a);
1126 BIO_puts(bp," * ");
1127 BN_print(bp,c);
1128 BIO_puts(bp," - ");
1129 }
1130 BN_print(bp,b);
1131 BIO_puts(bp,"\n");
1132 }
1133 BN_mul(d,a,c,ctx);
1134 BN_sub(d,d,b);
1135 if(!BN_is_zero(d))
1136 {
1137 fprintf(stderr,"Left shift test failed!\n");
1138 fprintf(stderr,"a=");
1139 BN_print_fp(stderr,a);
1140 fprintf(stderr,"\nb=");
1141 BN_print_fp(stderr,b);
1142 fprintf(stderr,"\nc=");
1143 BN_print_fp(stderr,c);
1144 fprintf(stderr,"\nd=");
1145 BN_print_fp(stderr,d);
1146 fprintf(stderr,"\n");
1147 return 0;
1148 }
1149 }
1150 BN_free(a);
1151 BN_free(b);
1152 BN_free(c);
1153 BN_free(d);
1154 return(1);
1155 }
1156
1157int test_lshift1(BIO *bp)
1158 {
1159 BIGNUM *a,*b,*c;
1160 int i;
1161
1162 a=BN_new();
1163 b=BN_new();
1164 c=BN_new();
1165
1166 BN_bntest_rand(a,200,0,0); /**/
1167 a->neg=rand_neg();
1168 for (i=0; i<num0; i++)
1169 {
1170 BN_lshift1(b,a);
1171 if (bp != NULL)
1172 {
1173 if (!results)
1174 {
1175 BN_print(bp,a);
1176 BIO_puts(bp," * 2");
1177 BIO_puts(bp," - ");
1178 }
1179 BN_print(bp,b);
1180 BIO_puts(bp,"\n");
1181 }
1182 BN_add(c,a,a);
1183 BN_sub(a,b,c);
1184 if(!BN_is_zero(a))
1185 {
1186 fprintf(stderr,"Left shift one test failed!\n");
1187 return 0;
1188 }
1189
1190 BN_copy(a,b);
1191 }
1192 BN_free(a);
1193 BN_free(b);
1194 BN_free(c);
1195 return(1);
1196 }
1197
1198int test_rshift(BIO *bp,BN_CTX *ctx)
1199 {
1200 BIGNUM *a,*b,*c,*d,*e;
1201 int i;
1202
1203 a=BN_new();
1204 b=BN_new();
1205 c=BN_new();
1206 d=BN_new();
1207 e=BN_new();
1208 BN_one(c);
1209
1210 BN_bntest_rand(a,200,0,0); /**/
1211 a->neg=rand_neg();
1212 for (i=0; i<num0; i++)
1213 {
1214 BN_rshift(b,a,i+1);
1215 BN_add(c,c,c);
1216 if (bp != NULL)
1217 {
1218 if (!results)
1219 {
1220 BN_print(bp,a);
1221 BIO_puts(bp," / ");
1222 BN_print(bp,c);
1223 BIO_puts(bp," - ");
1224 }
1225 BN_print(bp,b);
1226 BIO_puts(bp,"\n");
1227 }
1228 BN_div(d,e,a,c,ctx);
1229 BN_sub(d,d,b);
1230 if(!BN_is_zero(d))
1231 {
1232 fprintf(stderr,"Right shift test failed!\n");
1233 return 0;
1234 }
1235 }
1236 BN_free(a);
1237 BN_free(b);
1238 BN_free(c);
1239 BN_free(d);
1240 BN_free(e);
1241 return(1);
1242 }
1243
1244int test_rshift1(BIO *bp)
1245 {
1246 BIGNUM *a,*b,*c;
1247 int i;
1248
1249 a=BN_new();
1250 b=BN_new();
1251 c=BN_new();
1252
1253 BN_bntest_rand(a,200,0,0); /**/
1254 a->neg=rand_neg();
1255 for (i=0; i<num0; i++)
1256 {
1257 BN_rshift1(b,a);
1258 if (bp != NULL)
1259 {
1260 if (!results)
1261 {
1262 BN_print(bp,a);
1263 BIO_puts(bp," / 2");
1264 BIO_puts(bp," - ");
1265 }
1266 BN_print(bp,b);
1267 BIO_puts(bp,"\n");
1268 }
1269 BN_sub(c,a,b);
1270 BN_sub(c,c,b);
1271 if(!BN_is_zero(c) && !BN_abs_is_word(c, 1))
1272 {
1273 fprintf(stderr,"Right shift one test failed!\n");
1274 return 0;
1275 }
1276 BN_copy(a,b);
1277 }
1278 BN_free(a);
1279 BN_free(b);
1280 BN_free(c);
1281 return(1);
1282 }
1283
1284int rand_neg(void)
1285 {
1286 static unsigned int neg=0;
1287 static int sign[8]={0,0,0,1,1,0,1,1};
1288
1289 return(sign[(neg++)%8]);
1290 }
diff --git a/src/lib/libcrypto/bn/divtest.c b/src/lib/libcrypto/bn/divtest.c
new file mode 100644
index 0000000000..d3fc688f33
--- /dev/null
+++ b/src/lib/libcrypto/bn/divtest.c
@@ -0,0 +1,41 @@
1#include <openssl/bn.h>
2#include <openssl/rand.h>
3
4static int Rand(n)
5{
6 unsigned char x[2];
7 RAND_pseudo_bytes(x,2);
8 return (x[0] + 2*x[1]);
9}
10
11static void bug(char *m, BIGNUM *a, BIGNUM *b)
12{
13 printf("%s!\na=",m);
14 BN_print_fp(stdout, a);
15 printf("\nb=");
16 BN_print_fp(stdout, b);
17 printf("\n");
18 fflush(stdout);
19}
20
21main()
22{
23 BIGNUM *a=BN_new(), *b=BN_new(), *c=BN_new(), *d=BN_new(),
24 *C=BN_new(), *D=BN_new();
25 BN_RECP_CTX *recp=BN_RECP_CTX_new();
26 BN_CTX *ctx=BN_CTX_new();
27
28 for(;;) {
29 BN_pseudo_rand(a,Rand(),0,0);
30 BN_pseudo_rand(b,Rand(),0,0);
31 if (BN_is_zero(b)) continue;
32
33 BN_RECP_CTX_set(recp,b,ctx);
34 if (BN_div(C,D,a,b,ctx) != 1)
35 bug("BN_div failed",a,b);
36 if (BN_div_recp(c,d,a,recp,ctx) != 1)
37 bug("BN_div_recp failed",a,b);
38 else if (BN_cmp(c,C) != 0 || BN_cmp(c,C) != 0)
39 bug("mismatch",a,b);
40 }
41}
diff --git a/src/lib/libcrypto/bn/exp.c b/src/lib/libcrypto/bn/exp.c
new file mode 100644
index 0000000000..4865b0ef74
--- /dev/null
+++ b/src/lib/libcrypto/bn/exp.c
@@ -0,0 +1,62 @@
1/* unused */
2
3#include <stdio.h>
4#include <openssl/tmdiff.h>
5#include "bn_lcl.h"
6
7#define SIZE 256
8#define NUM (8*8*8)
9#define MOD (8*8*8*8*8)
10
11main(argc,argv)
12int argc;
13char *argv[];
14 {
15 BN_CTX ctx;
16 BIGNUM a,b,c,r,rr,t,l;
17 int j,i,size=SIZE,num=NUM,mod=MOD;
18 char *start,*end;
19 BN_MONT_CTX mont;
20 double d,md;
21
22 BN_MONT_CTX_init(&mont);
23 BN_CTX_init(&ctx);
24 BN_init(&a);
25 BN_init(&b);
26 BN_init(&c);
27 BN_init(&r);
28
29 start=ms_time_new();
30 end=ms_time_new();
31 while (size <= 1024*8)
32 {
33 BN_rand(&a,size,0,0);
34 BN_rand(&b,size,1,0);
35 BN_rand(&c,size,0,1);
36
37 BN_mod(&a,&a,&c,&ctx);
38
39 ms_time_get(start);
40 for (i=0; i<10; i++)
41 BN_MONT_CTX_set(&mont,&c,&ctx);
42 ms_time_get(end);
43 md=ms_time_diff(start,end);
44
45 ms_time_get(start);
46 for (i=0; i<num; i++)
47 {
48 /* bn_mull(&r,&a,&b,&ctx); */
49 /* BN_sqr(&r,&a,&ctx); */
50 BN_mod_exp_mont(&r,&a,&b,&c,&ctx,&mont);
51 }
52 ms_time_get(end);
53 d=ms_time_diff(start,end)/* *50/33 */;
54 printf("%5d bit:%6.2f %6d %6.4f %4d m_set(%5.4f)\n",size,
55 d,num,d/num,(int)((d/num)*mod),md/10.0);
56 num/=8;
57 mod/=8;
58 if (num <= 0) num=1;
59 size*=2;
60 }
61
62 }
diff --git a/src/lib/libcrypto/bn/expspeed.c b/src/lib/libcrypto/bn/expspeed.c
new file mode 100644
index 0000000000..4d5f221f33
--- /dev/null
+++ b/src/lib/libcrypto/bn/expspeed.c
@@ -0,0 +1,353 @@
1/* unused */
2
3/* crypto/bn/expspeed.c */
4/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
5 * All rights reserved.
6 *
7 * This package is an SSL implementation written
8 * by Eric Young (eay@cryptsoft.com).
9 * The implementation was written so as to conform with Netscapes SSL.
10 *
11 * This library is free for commercial and non-commercial use as long as
12 * the following conditions are aheared to. The following conditions
13 * apply to all code found in this distribution, be it the RC4, RSA,
14 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
15 * included with this distribution is covered by the same copyright terms
16 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
17 *
18 * Copyright remains Eric Young's, and as such any Copyright notices in
19 * the code are not to be removed.
20 * If this package is used in a product, Eric Young should be given attribution
21 * as the author of the parts of the library used.
22 * This can be in the form of a textual message at program startup or
23 * in documentation (online or textual) provided with the package.
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the copyright
29 * notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 * notice, this list of conditions and the following disclaimer in the
32 * documentation and/or other materials provided with the distribution.
33 * 3. All advertising materials mentioning features or use of this software
34 * must display the following acknowledgement:
35 * "This product includes cryptographic software written by
36 * Eric Young (eay@cryptsoft.com)"
37 * The word 'cryptographic' can be left out if the rouines from the library
38 * being used are not cryptographic related :-).
39 * 4. If you include any Windows specific code (or a derivative thereof) from
40 * the apps directory (application code) you must include an acknowledgement:
41 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
42 *
43 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
44 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
45 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
46 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
47 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
48 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
49 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
51 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
52 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
53 * SUCH DAMAGE.
54 *
55 * The licence and distribution terms for any publically available version or
56 * derivative of this code cannot be changed. i.e. this code cannot simply be
57 * copied and put under another distribution licence
58 * [including the GNU Public Licence.]
59 */
60
61/* most of this code has been pilfered from my libdes speed.c program */
62
63#define BASENUM 5000
64#define NUM_START 0
65
66
67/* determine timings for modexp, modmul, modsqr, gcd, Kronecker symbol,
68 * modular inverse, or modular square roots */
69#define TEST_EXP
70#undef TEST_MUL
71#undef TEST_SQR
72#undef TEST_GCD
73#undef TEST_KRON
74#undef TEST_INV
75#undef TEST_SQRT
76#define P_MOD_64 9 /* least significant 6 bits for prime to be used for BN_sqrt timings */
77
78#if defined(TEST_EXP) + defined(TEST_MUL) + defined(TEST_SQR) + defined(TEST_GCD) + defined(TEST_KRON) + defined(TEST_INV) +defined(TEST_SQRT) != 1
79# error "choose one test"
80#endif
81
82#if defined(TEST_INV) || defined(TEST_SQRT)
83# define C_PRIME
84static void genprime_cb(int p, int n, void *arg);
85#endif
86
87
88
89#undef PROG
90#define PROG bnspeed_main
91
92#include <stdio.h>
93#include <stdlib.h>
94#include <signal.h>
95#include <string.h>
96#include <openssl/crypto.h>
97#include <openssl/err.h>
98#include <openssl/rand.h>
99
100#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
101#define TIMES
102#endif
103
104#ifndef _IRIX
105#include <time.h>
106#endif
107#ifdef TIMES
108#include <sys/types.h>
109#include <sys/times.h>
110#endif
111
112/* Depending on the VMS version, the tms structure is perhaps defined.
113 The __TMS macro will show if it was. If it wasn't defined, we should
114 undefine TIMES, since that tells the rest of the program how things
115 should be handled. -- Richard Levitte */
116#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
117#undef TIMES
118#endif
119
120#ifndef TIMES
121#include <sys/timeb.h>
122#endif
123
124#if defined(sun) || defined(__ultrix)
125#define _POSIX_SOURCE
126#include <limits.h>
127#include <sys/param.h>
128#endif
129
130#include <openssl/bn.h>
131#include <openssl/x509.h>
132
133/* The following if from times(3) man page. It may need to be changed */
134#ifndef HZ
135# ifndef CLK_TCK
136# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
137# define HZ 100.0
138# else /* _BSD_CLK_TCK_ */
139# define HZ ((double)_BSD_CLK_TCK_)
140# endif
141# else /* CLK_TCK */
142# define HZ ((double)CLK_TCK)
143# endif
144#endif
145
146#undef BUFSIZE
147#define BUFSIZE ((long)1024*8)
148int run=0;
149
150static double Time_F(int s);
151#define START 0
152#define STOP 1
153
154static double Time_F(int s)
155 {
156 double ret;
157#ifdef TIMES
158 static struct tms tstart,tend;
159
160 if (s == START)
161 {
162 times(&tstart);
163 return(0);
164 }
165 else
166 {
167 times(&tend);
168 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
169 return((ret < 1e-3)?1e-3:ret);
170 }
171#else /* !times() */
172 static struct timeb tstart,tend;
173 long i;
174
175 if (s == START)
176 {
177 ftime(&tstart);
178 return(0);
179 }
180 else
181 {
182 ftime(&tend);
183 i=(long)tend.millitm-(long)tstart.millitm;
184 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
185 return((ret < 0.001)?0.001:ret);
186 }
187#endif
188 }
189
190#define NUM_SIZES 7
191#if NUM_START > NUM_SIZES
192# error "NUM_START > NUM_SIZES"
193#endif
194static int sizes[NUM_SIZES]={128,256,512,1024,2048,4096,8192};
195static int mul_c[NUM_SIZES]={8*8*8*8*8*8,8*8*8*8*8,8*8*8*8,8*8*8,8*8,8,1};
196/*static int sizes[NUM_SIZES]={59,179,299,419,539}; */
197
198#define RAND_SEED(string) { const char str[] = string; RAND_seed(string, sizeof str); }
199
200void do_mul_exp(BIGNUM *r,BIGNUM *a,BIGNUM *b,BIGNUM *c,BN_CTX *ctx);
201
202int main(int argc, char **argv)
203 {
204 BN_CTX *ctx;
205 BIGNUM *a,*b,*c,*r;
206
207#if 1
208 if (!CRYPTO_set_mem_debug_functions(0,0,0,0,0))
209 abort();
210#endif
211
212 ctx=BN_CTX_new();
213 a=BN_new();
214 b=BN_new();
215 c=BN_new();
216 r=BN_new();
217
218 while (!RAND_status())
219 /* not enough bits */
220 RAND_SEED("I demand a manual recount!");
221
222 do_mul_exp(r,a,b,c,ctx);
223 return 0;
224 }
225
226void do_mul_exp(BIGNUM *r, BIGNUM *a, BIGNUM *b, BIGNUM *c, BN_CTX *ctx)
227 {
228 int i,k;
229 double tm;
230 long num;
231
232 num=BASENUM;
233 for (i=NUM_START; i<NUM_SIZES; i++)
234 {
235#ifdef C_PRIME
236# ifdef TEST_SQRT
237 if (!BN_set_word(a, 64)) goto err;
238 if (!BN_set_word(b, P_MOD_64)) goto err;
239# define ADD a
240# define REM b
241# else
242# define ADD NULL
243# define REM NULL
244# endif
245 if (!BN_generate_prime(c,sizes[i],0,ADD,REM,genprime_cb,NULL)) goto err;
246 putc('\n', stderr);
247 fflush(stderr);
248#endif
249
250 for (k=0; k<num; k++)
251 {
252 if (k%50 == 0) /* Average over num/50 different choices of random numbers. */
253 {
254 if (!BN_pseudo_rand(a,sizes[i],1,0)) goto err;
255
256 if (!BN_pseudo_rand(b,sizes[i],1,0)) goto err;
257
258#ifndef C_PRIME
259 if (!BN_pseudo_rand(c,sizes[i],1,1)) goto err;
260#endif
261
262#ifdef TEST_SQRT
263 if (!BN_mod_sqr(a,a,c,ctx)) goto err;
264 if (!BN_mod_sqr(b,b,c,ctx)) goto err;
265#else
266 if (!BN_nnmod(a,a,c,ctx)) goto err;
267 if (!BN_nnmod(b,b,c,ctx)) goto err;
268#endif
269
270 if (k == 0)
271 Time_F(START);
272 }
273
274#if defined(TEST_EXP)
275 if (!BN_mod_exp(r,a,b,c,ctx)) goto err;
276#elif defined(TEST_MUL)
277 {
278 int i = 0;
279 for (i = 0; i < 50; i++)
280 if (!BN_mod_mul(r,a,b,c,ctx)) goto err;
281 }
282#elif defined(TEST_SQR)
283 {
284 int i = 0;
285 for (i = 0; i < 50; i++)
286 {
287 if (!BN_mod_sqr(r,a,c,ctx)) goto err;
288 if (!BN_mod_sqr(r,b,c,ctx)) goto err;
289 }
290 }
291#elif defined(TEST_GCD)
292 if (!BN_gcd(r,a,b,ctx)) goto err;
293 if (!BN_gcd(r,b,c,ctx)) goto err;
294 if (!BN_gcd(r,c,a,ctx)) goto err;
295#elif defined(TEST_KRON)
296 if (-2 == BN_kronecker(a,b,ctx)) goto err;
297 if (-2 == BN_kronecker(b,c,ctx)) goto err;
298 if (-2 == BN_kronecker(c,a,ctx)) goto err;
299#elif defined(TEST_INV)
300 if (!BN_mod_inverse(r,a,c,ctx)) goto err;
301 if (!BN_mod_inverse(r,b,c,ctx)) goto err;
302#else /* TEST_SQRT */
303 if (!BN_mod_sqrt(r,a,c,ctx)) goto err;
304 if (!BN_mod_sqrt(r,b,c,ctx)) goto err;
305#endif
306 }
307 tm=Time_F(STOP);
308 printf(
309#if defined(TEST_EXP)
310 "modexp %4d ^ %4d %% %4d"
311#elif defined(TEST_MUL)
312 "50*modmul %4d %4d %4d"
313#elif defined(TEST_SQR)
314 "100*modsqr %4d %4d %4d"
315#elif defined(TEST_GCD)
316 "3*gcd %4d %4d %4d"
317#elif defined(TEST_KRON)
318 "3*kronecker %4d %4d %4d"
319#elif defined(TEST_INV)
320 "2*inv %4d %4d mod %4d"
321#else /* TEST_SQRT */
322 "2*sqrt [prime == %d (mod 64)] %4d %4d mod %4d"
323#endif
324 " -> %8.6fms %5.1f (%ld)\n",
325#ifdef TEST_SQRT
326 P_MOD_64,
327#endif
328 sizes[i],sizes[i],sizes[i],tm*1000.0/num,tm*mul_c[i]/num, num);
329 num/=7;
330 if (num <= 0) num=1;
331 }
332 return;
333
334 err:
335 ERR_print_errors_fp(stderr);
336 }
337
338
339#ifdef C_PRIME
340static void genprime_cb(int p, int n, void *arg)
341 {
342 char c='*';
343
344 if (p == 0) c='.';
345 if (p == 1) c='+';
346 if (p == 2) c='*';
347 if (p == 3) c='\n';
348 putc(c, stderr);
349 fflush(stderr);
350 (void)n;
351 (void)arg;
352 }
353#endif
diff --git a/src/lib/libcrypto/bn/exptest.c b/src/lib/libcrypto/bn/exptest.c
new file mode 100644
index 0000000000..28aaac2ac1
--- /dev/null
+++ b/src/lib/libcrypto/bn/exptest.c
@@ -0,0 +1,201 @@
1/* crypto/bn/exptest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "../e_os.h"
64
65#include <openssl/bio.h>
66#include <openssl/bn.h>
67#include <openssl/rand.h>
68#include <openssl/err.h>
69
70#define NUM_BITS (BN_BITS*2)
71
72static const char rnd_seed[] = "string to make the random number generator think it has entropy";
73
74int main(int argc, char *argv[])
75 {
76 BN_CTX *ctx;
77 BIO *out=NULL;
78 int i,ret;
79 unsigned char c;
80 BIGNUM *r_mont,*r_mont_const,*r_recp,*r_simple,*a,*b,*m;
81
82 RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_rand may fail, and we don't
83 * even check its return value
84 * (which we should) */
85
86 ERR_load_BN_strings();
87
88 ctx=BN_CTX_new();
89 if (ctx == NULL) EXIT(1);
90 r_mont=BN_new();
91 r_mont_const=BN_new();
92 r_recp=BN_new();
93 r_simple=BN_new();
94 a=BN_new();
95 b=BN_new();
96 m=BN_new();
97 if ( (r_mont == NULL) || (r_recp == NULL) ||
98 (a == NULL) || (b == NULL))
99 goto err;
100
101 out=BIO_new(BIO_s_file());
102
103 if (out == NULL) EXIT(1);
104 BIO_set_fp(out,stdout,BIO_NOCLOSE);
105
106 for (i=0; i<200; i++)
107 {
108 RAND_bytes(&c,1);
109 c=(c%BN_BITS)-BN_BITS2;
110 BN_rand(a,NUM_BITS+c,0,0);
111
112 RAND_bytes(&c,1);
113 c=(c%BN_BITS)-BN_BITS2;
114 BN_rand(b,NUM_BITS+c,0,0);
115
116 RAND_bytes(&c,1);
117 c=(c%BN_BITS)-BN_BITS2;
118 BN_rand(m,NUM_BITS+c,0,1);
119
120 BN_mod(a,a,m,ctx);
121 BN_mod(b,b,m,ctx);
122
123 ret=BN_mod_exp_mont(r_mont,a,b,m,ctx,NULL);
124 if (ret <= 0)
125 {
126 printf("BN_mod_exp_mont() problems\n");
127 ERR_print_errors(out);
128 EXIT(1);
129 }
130
131 ret=BN_mod_exp_recp(r_recp,a,b,m,ctx);
132 if (ret <= 0)
133 {
134 printf("BN_mod_exp_recp() problems\n");
135 ERR_print_errors(out);
136 EXIT(1);
137 }
138
139 ret=BN_mod_exp_simple(r_simple,a,b,m,ctx);
140 if (ret <= 0)
141 {
142 printf("BN_mod_exp_simple() problems\n");
143 ERR_print_errors(out);
144 EXIT(1);
145 }
146
147 ret=BN_mod_exp_mont_consttime(r_mont_const,a,b,m,ctx,NULL);
148 if (ret <= 0)
149 {
150 printf("BN_mod_exp_mont_consttime() problems\n");
151 ERR_print_errors(out);
152 EXIT(1);
153 }
154
155 if (BN_cmp(r_simple, r_mont) == 0
156 && BN_cmp(r_simple,r_recp) == 0
157 && BN_cmp(r_simple,r_mont_const) == 0)
158 {
159 printf(".");
160 fflush(stdout);
161 }
162 else
163 {
164 if (BN_cmp(r_simple,r_mont) != 0)
165 printf("\nsimple and mont results differ\n");
166 if (BN_cmp(r_simple,r_mont) != 0)
167 printf("\nsimple and mont const time results differ\n");
168 if (BN_cmp(r_simple,r_recp) != 0)
169 printf("\nsimple and recp results differ\n");
170
171 printf("a (%3d) = ",BN_num_bits(a)); BN_print(out,a);
172 printf("\nb (%3d) = ",BN_num_bits(b)); BN_print(out,b);
173 printf("\nm (%3d) = ",BN_num_bits(m)); BN_print(out,m);
174 printf("\nsimple ="); BN_print(out,r_simple);
175 printf("\nrecp ="); BN_print(out,r_recp);
176 printf("\nmont ="); BN_print(out,r_mont);
177 printf("\nmont_ct ="); BN_print(out,r_mont_const);
178 printf("\n");
179 EXIT(1);
180 }
181 }
182 BN_free(r_mont);
183 BN_free(r_mont_const);
184 BN_free(r_recp);
185 BN_free(r_simple);
186 BN_free(a);
187 BN_free(b);
188 BN_free(m);
189 BN_CTX_free(ctx);
190 ERR_remove_state(0);
191 CRYPTO_mem_leaks(out);
192 BIO_free(out);
193 printf(" done\n");
194 EXIT(0);
195err:
196 ERR_load_crypto_strings();
197 ERR_print_errors(out);
198 EXIT(1);
199 return(1);
200 }
201
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..4b63149bf3
--- /dev/null
+++ b/src/lib/libcrypto/bn/vms-helper.c
@@ -0,0 +1,68 @@
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#ifdef BN_DEBUG
63#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
64 fprintf(stderr,"Division would overflow (%d)\n",i);
65#endif
66 abort();
67#endif
68}
diff --git a/src/lib/libcrypto/buffer/Makefile b/src/lib/libcrypto/buffer/Makefile
new file mode 100644
index 0000000000..9f3a88d2d6
--- /dev/null
+++ b/src/lib/libcrypto/buffer/Makefile
@@ -0,0 +1,90 @@
1#
2# OpenSSL/crypto/buffer/Makefile
3#
4
5DIR= buffer
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= buffer.c buf_err.c
21LIBOBJ= buffer.o buf_err.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= buffer.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77buf_err.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
78buf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
79buf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
80buf_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
81buf_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
82buf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
83buf_err.o: buf_err.c
84buffer.o: ../../e_os.h ../../include/openssl/bio.h
85buffer.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
86buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
87buffer.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
88buffer.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
89buffer.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90buffer.o: ../../include/openssl/symhacks.h ../cryptlib.h buffer.c
diff --git a/src/lib/libcrypto/buffer/Makefile.ssl b/src/lib/libcrypto/buffer/Makefile.ssl
new file mode 100644
index 0000000000..b131ca3078
--- /dev/null
+++ b/src/lib/libcrypto/buffer/Makefile.ssl
@@ -0,0 +1,94 @@
1#
2# SSLeay/crypto/buffer/Makefile
3#
4
5DIR= buffer
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= buffer.c buf_err.c
27LIBOBJ= buffer.o buf_err.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= buffer.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82buf_err.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
83buf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
84buf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
85buf_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
86buf_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87buf_err.o: ../../include/openssl/symhacks.h buf_err.c
88buffer.o: ../../e_os.h ../../include/openssl/bio.h
89buffer.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
90buffer.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
91buffer.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
92buffer.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
93buffer.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
94buffer.o: ../cryptlib.h buffer.c
diff --git a/src/lib/libcrypto/buffer/buf_err.c b/src/lib/libcrypto/buffer/buf_err.c
index 3e25bbe879..1fc32a6861 100644
--- a/src/lib/libcrypto/buffer/buf_err.c
+++ b/src/lib/libcrypto/buffer/buf_err.c
@@ -70,12 +70,9 @@
70 70
71static ERR_STRING_DATA BUF_str_functs[]= 71static ERR_STRING_DATA BUF_str_functs[]=
72 { 72 {
73{ERR_FUNC(BUF_F_BUF_MEMDUP), "BUF_memdup"},
74{ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"}, 73{ERR_FUNC(BUF_F_BUF_MEM_GROW), "BUF_MEM_grow"},
75{ERR_FUNC(BUF_F_BUF_MEM_GROW_CLEAN), "BUF_MEM_grow_clean"},
76{ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"}, 74{ERR_FUNC(BUF_F_BUF_MEM_NEW), "BUF_MEM_new"},
77{ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"}, 75{ERR_FUNC(BUF_F_BUF_STRDUP), "BUF_strdup"},
78{ERR_FUNC(BUF_F_BUF_STRNDUP), "BUF_strndup"},
79{0,NULL} 76{0,NULL}
80 }; 77 };
81 78
@@ -88,12 +85,15 @@ static ERR_STRING_DATA BUF_str_reasons[]=
88 85
89void ERR_load_BUF_strings(void) 86void ERR_load_BUF_strings(void)
90 { 87 {
91#ifndef OPENSSL_NO_ERR 88 static int init=1;
92 89
93 if (ERR_func_error_string(BUF_str_functs[0].error) == NULL) 90 if (init)
94 { 91 {
92 init=0;
93#ifndef OPENSSL_NO_ERR
95 ERR_load_strings(0,BUF_str_functs); 94 ERR_load_strings(0,BUF_str_functs);
96 ERR_load_strings(0,BUF_str_reasons); 95 ERR_load_strings(0,BUF_str_reasons);
97 }
98#endif 96#endif
97
98 }
99 } 99 }
diff --git a/src/lib/libcrypto/buffer/buffer.c b/src/lib/libcrypto/buffer/buffer.c
index 3bf03c7eff..d96487e7db 100644
--- a/src/lib/libcrypto/buffer/buffer.c
+++ b/src/lib/libcrypto/buffer/buffer.c
@@ -149,7 +149,7 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
149 ret=OPENSSL_realloc_clean(str->data,str->max,n); 149 ret=OPENSSL_realloc_clean(str->data,str->max,n);
150 if (ret == NULL) 150 if (ret == NULL)
151 { 151 {
152 BUFerr(BUF_F_BUF_MEM_GROW_CLEAN,ERR_R_MALLOC_FAILURE); 152 BUFerr(BUF_F_BUF_MEM_GROW,ERR_R_MALLOC_FAILURE);
153 len=0; 153 len=0;
154 } 154 }
155 else 155 else
@@ -164,41 +164,22 @@ int BUF_MEM_grow_clean(BUF_MEM *str, int len)
164 164
165char *BUF_strdup(const char *str) 165char *BUF_strdup(const char *str)
166 { 166 {
167 if (str == NULL) return(NULL);
168 return BUF_strndup(str, strlen(str));
169 }
170
171char *BUF_strndup(const char *str, size_t siz)
172 {
173 char *ret; 167 char *ret;
168 int n;
174 169
175 if (str == NULL) return(NULL); 170 if (str == NULL) return(NULL);
176 171
177 ret=OPENSSL_malloc(siz+1); 172 n=strlen(str);
173 ret=OPENSSL_malloc(n+1);
178 if (ret == NULL) 174 if (ret == NULL)
179 { 175 {
180 BUFerr(BUF_F_BUF_STRNDUP,ERR_R_MALLOC_FAILURE); 176 BUFerr(BUF_F_BUF_STRDUP,ERR_R_MALLOC_FAILURE);
181 return(NULL); 177 return(NULL);
182 } 178 }
183 BUF_strlcpy(ret,str,siz+1); 179 memcpy(ret,str,n+1);
184 return(ret); 180 return(ret);
185 } 181 }
186 182
187void *BUF_memdup(const void *data, size_t siz)
188 {
189 void *ret;
190
191 if (data == NULL) return(NULL);
192
193 ret=OPENSSL_malloc(siz);
194 if (ret == NULL)
195 {
196 BUFerr(BUF_F_BUF_MEMDUP,ERR_R_MALLOC_FAILURE);
197 return(NULL);
198 }
199 return memcpy(ret, data, siz);
200 }
201
202size_t BUF_strlcpy(char *dst, const char *src, size_t size) 183size_t BUF_strlcpy(char *dst, const char *src, size_t size)
203 { 184 {
204 size_t l = 0; 185 size_t l = 0;
diff --git a/src/lib/libcrypto/buffer/buffer.h b/src/lib/libcrypto/buffer/buffer.h
index 1db9607450..465dc34f3f 100644
--- a/src/lib/libcrypto/buffer/buffer.h
+++ b/src/lib/libcrypto/buffer/buffer.h
@@ -59,35 +59,25 @@
59#ifndef HEADER_BUFFER_H 59#ifndef HEADER_BUFFER_H
60#define HEADER_BUFFER_H 60#define HEADER_BUFFER_H
61 61
62#include <openssl/ossl_typ.h>
63
64#ifdef __cplusplus 62#ifdef __cplusplus
65extern "C" { 63extern "C" {
66#endif 64#endif
67 65
68#include <stddef.h> 66#include <stddef.h>
69
70#if !defined(NO_SYS_TYPES_H)
71#include <sys/types.h> 67#include <sys/types.h>
72#endif
73
74/* Already declared in ossl_typ.h */
75/* typedef struct buf_mem_st BUF_MEM; */
76 68
77struct buf_mem_st 69typedef struct buf_mem_st
78 { 70 {
79 int length; /* current number of bytes */ 71 int length; /* current number of bytes */
80 char *data; 72 char *data;
81 int max; /* size of buffer */ 73 int max; /* size of buffer */
82 }; 74 } BUF_MEM;
83 75
84BUF_MEM *BUF_MEM_new(void); 76BUF_MEM *BUF_MEM_new(void);
85void BUF_MEM_free(BUF_MEM *a); 77void BUF_MEM_free(BUF_MEM *a);
86int BUF_MEM_grow(BUF_MEM *str, int len); 78int BUF_MEM_grow(BUF_MEM *str, int len);
87int BUF_MEM_grow_clean(BUF_MEM *str, int len); 79int BUF_MEM_grow_clean(BUF_MEM *str, int len);
88char * BUF_strdup(const char *str); 80char * BUF_strdup(const char *str);
89char * BUF_strndup(const char *str, size_t siz);
90void * BUF_memdup(const void *data, size_t siz);
91 81
92/* safe string functions */ 82/* safe string functions */
93size_t BUF_strlcpy(char *dst,const char *src,size_t siz); 83size_t BUF_strlcpy(char *dst,const char *src,size_t siz);
@@ -103,12 +93,9 @@ void ERR_load_BUF_strings(void);
103/* Error codes for the BUF functions. */ 93/* Error codes for the BUF functions. */
104 94
105/* Function codes. */ 95/* Function codes. */
106#define BUF_F_BUF_MEMDUP 103
107#define BUF_F_BUF_MEM_GROW 100 96#define BUF_F_BUF_MEM_GROW 100
108#define BUF_F_BUF_MEM_GROW_CLEAN 105
109#define BUF_F_BUF_MEM_NEW 101 97#define BUF_F_BUF_MEM_NEW 101
110#define BUF_F_BUF_STRDUP 102 98#define BUF_F_BUF_STRDUP 102
111#define BUF_F_BUF_STRNDUP 104
112 99
113/* Reason codes. */ 100/* Reason codes. */
114 101
diff --git a/src/lib/libcrypto/camellia/Makefile b/src/lib/libcrypto/camellia/Makefile
new file mode 100644
index 0000000000..1579de5ce5
--- /dev/null
+++ b/src/lib/libcrypto/camellia/Makefile
@@ -0,0 +1,103 @@
1#
2# crypto/camellia/Makefile
3#
4
5DIR= camellia
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14CAMELLIA_ASM_OBJ=
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21#TEST=camelliatest.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=camellia.c cmll_misc.c cmll_ecb.c cmll_cbc.c cmll_ofb.c \
26 cmll_cfb.c cmll_ctr.c
27
28LIBOBJ= camellia.o cmll_misc.o cmll_ecb.o cmll_cbc.o cmll_ofb.o \
29 cmll_cfb.o cmll_ctr.o $(CAMELLIA_ASM_OBJ)
30
31SRC= $(LIBSRC)
32
33EXHEADER= camellia.h
34HEADER= cmll_locl.h $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48$(LIBOBJ): $(LIBSRC)
49
50
51files:
52 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
53
54links:
55 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
56 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
57 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
58
59install:
60 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
61 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
62 do \
63 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
64 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
65 done;
66
67tags:
68 ctags $(SRC)
69
70tests:
71
72lint:
73 lint -DLINT $(INCLUDES) $(SRC)>fluff
74
75depend:
76 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
77 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
78
79dclean:
80 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
81 mv -f Makefile.new $(MAKEFILE)
82
83clean:
84 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
85
86# DO NOT DELETE THIS LINE -- make depend depends on it.
87
88camellia.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
89camellia.o: camellia.c camellia.h cmll_locl.h
90cmll_cbc.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
91cmll_cbc.o: ../../include/openssl/opensslconf.h cmll_cbc.c cmll_locl.h
92cmll_cfb.o: ../../e_os.h ../../include/openssl/camellia.h
93cmll_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
94cmll_cfb.o: cmll_cfb.c cmll_locl.h
95cmll_ctr.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
96cmll_ctr.o: ../../include/openssl/opensslconf.h cmll_ctr.c cmll_locl.h
97cmll_ecb.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
98cmll_ecb.o: ../../include/openssl/opensslconf.h cmll_ecb.c cmll_locl.h
99cmll_misc.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
100cmll_misc.o: ../../include/openssl/opensslconf.h
101cmll_misc.o: ../../include/openssl/opensslv.h cmll_locl.h cmll_misc.c
102cmll_ofb.o: ../../include/openssl/camellia.h ../../include/openssl/e_os2.h
103cmll_ofb.o: ../../include/openssl/opensslconf.h cmll_locl.h cmll_ofb.c
diff --git a/src/lib/libcrypto/cast/Makefile b/src/lib/libcrypto/cast/Makefile
new file mode 100644
index 0000000000..149956ee90
--- /dev/null
+++ b/src/lib/libcrypto/cast/Makefile
@@ -0,0 +1,106 @@
1#
2# OpenSSL/crypto/cast/Makefile
3#
4
5DIR= cast
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14CAST_ENC=c_enc.o
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21TEST=casttest.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c
26LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o
27
28SRC= $(LIBSRC)
29
30EXHEADER= cast.h
31HEADER= cast_s.h cast_lcl.h $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45# ELF
46cx86-elf.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
47 (cd asm; $(PERL) cast-586.pl elf $(CLAGS) $(PROCESSOR) > ../$@)
48# COFF
49cx86-cof.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
50 (cd asm; $(PERL) cast-586.pl coff $(CLAGS) $(PROCESSOR) > ../$@)
51# a.out
52cx86-out.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
53 (cd asm; $(PERL) cast-586.pl a.out $(CLAGS) $(PROCESSOR) > ../$@)
54
55files:
56 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
57
58links:
59 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
60 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
61 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
62
63install:
64 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
65 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
66 do \
67 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
68 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
69 done;
70
71tags:
72 ctags $(SRC)
73
74tests:
75
76lint:
77 lint -DLINT $(INCLUDES) $(SRC)>fluff
78
79depend:
80 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
81 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
82
83dclean:
84 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
85 mv -f Makefile.new $(MAKEFILE)
86
87clean:
88 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
89
90# DO NOT DELETE THIS LINE -- make depend depends on it.
91
92c_cfb64.o: ../../e_os.h ../../include/openssl/cast.h
93c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
94c_cfb64.o: c_cfb64.c cast_lcl.h
95c_ecb.o: ../../e_os.h ../../include/openssl/cast.h
96c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
97c_ecb.o: ../../include/openssl/opensslv.h c_ecb.c cast_lcl.h
98c_enc.o: ../../e_os.h ../../include/openssl/cast.h
99c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
100c_enc.o: c_enc.c cast_lcl.h
101c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h
102c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
103c_ofb64.o: c_ofb64.c cast_lcl.h
104c_skey.o: ../../e_os.h ../../include/openssl/cast.h
105c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
106c_skey.o: c_skey.c cast_lcl.h cast_s.h
diff --git a/src/lib/libcrypto/cast/Makefile.ssl b/src/lib/libcrypto/cast/Makefile.ssl
new file mode 100644
index 0000000000..98393a37ba
--- /dev/null
+++ b/src/lib/libcrypto/cast/Makefile.ssl
@@ -0,0 +1,120 @@
1#
2# SSLeay/crypto/cast/Makefile
3#
4
5DIR= cast
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20CAST_ENC=c_enc.o
21# or use
22#CAST_ENC=asm/cx86-elf.o
23#CAST_ENC=asm/cx86-out.o
24#CAST_ENC=asm/cx86-sol.o
25#CAST_ENC=asm/cx86bdsi.o
26
27CFLAGS= $(INCLUDES) $(CFLAG)
28ASFLAGS= $(INCLUDES) $(ASFLAG)
29
30GENERAL=Makefile
31TEST=casttest.c
32APPS=
33
34LIB=$(TOP)/libcrypto.a
35LIBSRC=c_skey.c c_ecb.c c_enc.c c_cfb64.c c_ofb64.c
36LIBOBJ=c_skey.o c_ecb.o $(CAST_ENC) c_cfb64.o c_ofb64.o
37
38SRC= $(LIBSRC)
39
40EXHEADER= cast.h
41HEADER= cast_s.h cast_lcl.h $(EXHEADER)
42
43ALL= $(GENERAL) $(SRC) $(HEADER)
44
45top:
46 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
47
48all: lib
49
50lib: $(LIBOBJ)
51 $(AR) $(LIB) $(LIBOBJ)
52 $(RANLIB) $(LIB) || echo Never mind.
53 @touch lib
54
55# elf
56asm/cx86-elf.s: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
57 (cd asm; $(PERL) cast-586.pl elf $(CLAGS) $(PROCESSOR) > cx86-elf.s)
58
59# a.out
60asm/cx86-out.o: asm/cx86unix.cpp
61 $(CPP) -DOUT asm/cx86unix.cpp | as -o asm/cx86-out.o
62
63# bsdi
64asm/cx86bsdi.o: asm/cx86unix.cpp
65 $(CPP) -DBSDI asm/cx86unix.cpp | sed 's/ :/:/' | as -o asm/cx86bsdi.o
66
67asm/cx86unix.cpp: asm/cast-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
68 (cd asm; $(PERL) cast-586.pl cpp $(PROCESSOR) >cx86unix.cpp)
69
70files:
71 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
72
73links:
74 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
75 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
76 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
77 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
78
79install:
80 @for i in $(EXHEADER) ; \
81 do \
82 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
83 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
84 done;
85
86tags:
87 ctags $(SRC)
88
89tests:
90
91lint:
92 lint -DLINT $(INCLUDES) $(SRC)>fluff
93
94depend:
95 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
96
97dclean:
98 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
99 mv -f Makefile.new $(MAKEFILE)
100
101clean:
102 rm -f asm/cx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
103
104# DO NOT DELETE THIS LINE -- make depend depends on it.
105
106c_cfb64.o: ../../e_os.h ../../include/openssl/cast.h
107c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
108c_cfb64.o: c_cfb64.c cast_lcl.h
109c_ecb.o: ../../e_os.h ../../include/openssl/cast.h
110c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
111c_ecb.o: ../../include/openssl/opensslv.h c_ecb.c cast_lcl.h
112c_enc.o: ../../e_os.h ../../include/openssl/cast.h
113c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
114c_enc.o: c_enc.c cast_lcl.h
115c_ofb64.o: ../../e_os.h ../../include/openssl/cast.h
116c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
117c_ofb64.o: c_ofb64.c cast_lcl.h
118c_skey.o: ../../e_os.h ../../include/openssl/cast.h
119c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
120c_skey.o: c_skey.c cast_lcl.h cast_s.h
diff --git a/src/lib/libcrypto/cast/asm/cast-586.pl b/src/lib/libcrypto/cast/asm/cast-586.pl
index 6be0bfe572..0ed55d1905 100644
--- a/src/lib/libcrypto/cast/asm/cast-586.pl
+++ b/src/lib/libcrypto/cast/asm/cast-586.pl
@@ -28,7 +28,7 @@ $S4="CAST_S_table3";
28 28
29&CAST_encrypt("CAST_encrypt",1); 29&CAST_encrypt("CAST_encrypt",1);
30&CAST_encrypt("CAST_decrypt",0); 30&CAST_encrypt("CAST_decrypt",0);
31&cbc("CAST_cbc_encrypt","CAST_encrypt","CAST_decrypt",1,4,5,3,-1,-1); 31&cbc("CAST_cbc_encrypt","CAST_encrypt","CAST_decrypt",1,4,5,3,-1,-1) unless $main'openbsd;
32 32
33&asm_finish(); 33&asm_finish();
34 34
diff --git a/src/lib/libcrypto/cast/asm/readme b/src/lib/libcrypto/cast/asm/readme
new file mode 100644
index 0000000000..fbcd76289e
--- /dev/null
+++ b/src/lib/libcrypto/cast/asm/readme
@@ -0,0 +1,7 @@
1There is a ppro flag in cast-586 which turns on/off
2generation of pentium pro/II friendly code
3
4This flag makes the inner loop one cycle longer, but generates
5code that runs %30 faster on the pentium pro/II, while only %7 slower
6on the pentium. By default, this flag is on.
7
diff --git a/src/lib/libcrypto/cast/c_ecb.c b/src/lib/libcrypto/cast/c_ecb.c
index f2dc606226..0b3da9ad87 100644
--- a/src/lib/libcrypto/cast/c_ecb.c
+++ b/src/lib/libcrypto/cast/c_ecb.c
@@ -60,7 +60,7 @@
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63const char CAST_version[]="CAST" OPENSSL_VERSION_PTEXT; 63const char *CAST_version="CAST" OPENSSL_VERSION_PTEXT;
64 64
65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, 65void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out,
66 CAST_KEY *ks, int enc) 66 CAST_KEY *ks, int enc)
diff --git a/src/lib/libcrypto/cast/c_enc.c b/src/lib/libcrypto/cast/c_enc.c
index 0fe2cffecc..e80f65b698 100644
--- a/src/lib/libcrypto/cast/c_enc.c
+++ b/src/lib/libcrypto/cast/c_enc.c
@@ -59,6 +59,7 @@
59#include <openssl/cast.h> 59#include <openssl/cast.h>
60#include "cast_lcl.h" 60#include "cast_lcl.h"
61 61
62#ifndef OPENBSD_CAST_ASM
62void CAST_encrypt(CAST_LONG *data, CAST_KEY *key) 63void CAST_encrypt(CAST_LONG *data, CAST_KEY *key)
63 { 64 {
64 register CAST_LONG l,r,*k,t; 65 register CAST_LONG l,r,*k,t;
@@ -122,6 +123,7 @@ void CAST_decrypt(CAST_LONG *data, CAST_KEY *key)
122 data[1]=l&0xffffffffL; 123 data[1]=l&0xffffffffL;
123 data[0]=r&0xffffffffL; 124 data[0]=r&0xffffffffL;
124 } 125 }
126#endif
125 127
126void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, 128void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length,
127 CAST_KEY *ks, unsigned char *iv, int enc) 129 CAST_KEY *ks, unsigned char *iv, int enc)
diff --git a/src/lib/libcrypto/cast/c_skey.c b/src/lib/libcrypto/cast/c_skey.c
index 76e40005c9..db9b7573e0 100644
--- a/src/lib/libcrypto/cast/c_skey.c
+++ b/src/lib/libcrypto/cast/c_skey.c
@@ -56,7 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <openssl/crypto.h>
60#include <openssl/fips.h>
59#include <openssl/cast.h> 61#include <openssl/cast.h>
62
60#include "cast_lcl.h" 63#include "cast_lcl.h"
61#include "cast_s.h" 64#include "cast_s.h"
62 65
@@ -72,7 +75,7 @@
72#define S6 CAST_S_table6 75#define S6 CAST_S_table6
73#define S7 CAST_S_table7 76#define S7 CAST_S_table7
74 77
75void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data) 78FIPS_NON_FIPS_VCIPHER_Init(CAST)
76 { 79 {
77 CAST_LONG x[16]; 80 CAST_LONG x[16];
78 CAST_LONG z[16]; 81 CAST_LONG z[16];
diff --git a/src/lib/libcrypto/cast/cast.h b/src/lib/libcrypto/cast/cast.h
index 90b45b950a..9e300178d9 100644
--- a/src/lib/libcrypto/cast/cast.h
+++ b/src/lib/libcrypto/cast/cast.h
@@ -63,8 +63,6 @@
63extern "C" { 63extern "C" {
64#endif 64#endif
65 65
66#include <openssl/opensslconf.h>
67
68#ifdef OPENSSL_NO_CAST 66#ifdef OPENSSL_NO_CAST
69#error CAST is disabled. 67#error CAST is disabled.
70#endif 68#endif
@@ -83,7 +81,10 @@ typedef struct cast_key_st
83 int short_key; /* Use reduced rounds for short key */ 81 int short_key; /* Use reduced rounds for short key */
84 } CAST_KEY; 82 } CAST_KEY;
85 83
86 84
85#ifdef OPENSSL_FIPS
86void private_CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
87#endif
87void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data); 88void CAST_set_key(CAST_KEY *key, int len, const unsigned char *data);
88void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key, 89void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key,
89 int enc); 90 int enc);
diff --git a/src/lib/libcrypto/cast/cast_spd.c b/src/lib/libcrypto/cast/cast_spd.c
new file mode 100644
index 0000000000..76abf50d98
--- /dev/null
+++ b/src/lib/libcrypto/cast/cast_spd.c
@@ -0,0 +1,275 @@
1/* crypto/cast/cast_spd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
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 */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/cast.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103#ifndef CLK_TCK
104#define HZ 100.0
105#else /* CLK_TCK */
106#define HZ ((double)CLK_TCK)
107#endif
108#endif
109
110#define BUFSIZE ((long)1024)
111long run=0;
112
113double Time_F(int s);
114#ifdef SIGALRM
115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
116#define SIGRETTYPE void
117#else
118#define SIGRETTYPE int
119#endif
120
121SIGRETTYPE sig_done(int sig);
122SIGRETTYPE sig_done(int sig)
123 {
124 signal(SIGALRM,sig_done);
125 run=0;
126#ifdef LINT
127 sig=sig;
128#endif
129 }
130#endif
131
132#define START 0
133#define STOP 1
134
135double Time_F(int s)
136 {
137 double ret;
138#ifdef TIMES
139 static struct tms tstart,tend;
140
141 if (s == START)
142 {
143 times(&tstart);
144 return(0);
145 }
146 else
147 {
148 times(&tend);
149 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
150 return((ret == 0.0)?1e-6:ret);
151 }
152#else /* !times() */
153 static struct timeb tstart,tend;
154 long i;
155
156 if (s == START)
157 {
158 ftime(&tstart);
159 return(0);
160 }
161 else
162 {
163 ftime(&tend);
164 i=(long)tend.millitm-(long)tstart.millitm;
165 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
166 return((ret == 0.0)?1e-6:ret);
167 }
168#endif
169 }
170
171int main(int argc, char **argv)
172 {
173 long count;
174 static unsigned char buf[BUFSIZE];
175 static unsigned char key[] ={
176 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
177 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
178 };
179 CAST_KEY sch;
180 double a,b,c,d;
181#ifndef SIGALRM
182 long ca,cb,cc;
183#endif
184
185#ifndef TIMES
186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n");
188#endif
189
190#ifndef SIGALRM
191 printf("First we calculate the approximate speed ...\n");
192 CAST_set_key(&sch,16,key);
193 count=10;
194 do {
195 long i;
196 CAST_LONG data[2];
197
198 count*=2;
199 Time_F(START);
200 for (i=count; i; i--)
201 CAST_encrypt(data,&sch);
202 d=Time_F(STOP);
203 } while (d < 3.0);
204 ca=count/512;
205 cb=count;
206 cc=count*8/BUFSIZE+1;
207 printf("Doing CAST_set_key %ld times\n",ca);
208#define COND(d) (count != (d))
209#define COUNT(d) (d)
210#else
211#define COND(c) (run)
212#define COUNT(d) (count)
213 signal(SIGALRM,sig_done);
214 printf("Doing CAST_set_key for 10 seconds\n");
215 alarm(10);
216#endif
217
218 Time_F(START);
219 for (count=0,run=1; COND(ca); count+=4)
220 {
221 CAST_set_key(&sch,16,key);
222 CAST_set_key(&sch,16,key);
223 CAST_set_key(&sch,16,key);
224 CAST_set_key(&sch,16,key);
225 }
226 d=Time_F(STOP);
227 printf("%ld cast set_key's in %.2f seconds\n",count,d);
228 a=((double)COUNT(ca))/d;
229
230#ifdef SIGALRM
231 printf("Doing CAST_encrypt's for 10 seconds\n");
232 alarm(10);
233#else
234 printf("Doing CAST_encrypt %ld times\n",cb);
235#endif
236 Time_F(START);
237 for (count=0,run=1; COND(cb); count+=4)
238 {
239 CAST_LONG data[2];
240
241 CAST_encrypt(data,&sch);
242 CAST_encrypt(data,&sch);
243 CAST_encrypt(data,&sch);
244 CAST_encrypt(data,&sch);
245 }
246 d=Time_F(STOP);
247 printf("%ld CAST_encrypt's in %.2f second\n",count,d);
248 b=((double)COUNT(cb)*8)/d;
249
250#ifdef SIGALRM
251 printf("Doing CAST_cbc_encrypt on %ld byte blocks for 10 seconds\n",
252 BUFSIZE);
253 alarm(10);
254#else
255 printf("Doing CAST_cbc_encrypt %ld times on %ld byte blocks\n",cc,
256 BUFSIZE);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cc); count++)
260 CAST_cbc_encrypt(buf,buf,BUFSIZE,&sch,
261 &(key[0]),CAST_ENCRYPT);
262 d=Time_F(STOP);
263 printf("%ld CAST_cbc_encrypt's of %ld byte blocks in %.2f second\n",
264 count,BUFSIZE,d);
265 c=((double)COUNT(cc)*BUFSIZE)/d;
266
267 printf("CAST set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
268 printf("CAST raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
269 printf("CAST cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
270 exit(0);
271#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
272 return(0);
273#endif
274 }
275
diff --git a/src/lib/libcrypto/cast/castopts.c b/src/lib/libcrypto/cast/castopts.c
new file mode 100644
index 0000000000..1b858d153b
--- /dev/null
+++ b/src/lib/libcrypto/cast/castopts.c
@@ -0,0 +1,339 @@
1/* crypto/cast/castopts.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* define 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. */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC))
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/cast.h>
100
101#define CAST_DEFAULT_OPTIONS
102
103#undef E_CAST
104#define CAST_encrypt CAST_encrypt_normal
105#define CAST_decrypt CAST_decrypt_normal
106#define CAST_cbc_encrypt CAST_cbc_encrypt_normal
107#undef HEADER_CAST_LOCL_H
108#include "c_enc.c"
109
110#define CAST_PTR
111#undef CAST_PTR2
112#undef E_CAST
113#undef CAST_encrypt
114#undef CAST_decrypt
115#undef CAST_cbc_encrypt
116#define CAST_encrypt CAST_encrypt_ptr
117#define CAST_decrypt CAST_decrypt_ptr
118#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr
119#undef HEADER_CAST_LOCL_H
120#include "c_enc.c"
121
122#undef CAST_PTR
123#define CAST_PTR2
124#undef E_CAST
125#undef CAST_encrypt
126#undef CAST_decrypt
127#undef CAST_cbc_encrypt
128#define CAST_encrypt CAST_encrypt_ptr2
129#define CAST_decrypt CAST_decrypt_ptr2
130#define CAST_cbc_encrypt CAST_cbc_encrypt_ptr2
131#undef HEADER_CAST_LOCL_H
132#include "c_enc.c"
133
134/* The following if from times(3) man page. It may need to be changed */
135#ifndef HZ
136# ifndef CLK_TCK
137# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
138# define HZ 100.0
139# else /* _BSD_CLK_TCK_ */
140# define HZ ((double)_BSD_CLK_TCK_)
141# endif
142# else /* CLK_TCK */
143# define HZ ((double)CLK_TCK)
144# endif
145#endif
146
147#define BUFSIZE ((long)1024)
148long run=0;
149
150double Time_F(int s);
151#ifdef SIGALRM
152#if defined(__STDC__) || defined(sgi)
153#define SIGRETTYPE void
154#else
155#define SIGRETTYPE int
156#endif
157
158SIGRETTYPE sig_done(int sig);
159SIGRETTYPE sig_done(int sig)
160 {
161 signal(SIGALRM,sig_done);
162 run=0;
163#ifdef LINT
164 sig=sig;
165#endif
166 }
167#endif
168
169#define START 0
170#define STOP 1
171
172double Time_F(int s)
173 {
174 double ret;
175#ifdef TIMES
176 static struct tms tstart,tend;
177
178 if (s == START)
179 {
180 times(&tstart);
181 return(0);
182 }
183 else
184 {
185 times(&tend);
186 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
187 return((ret == 0.0)?1e-6:ret);
188 }
189#else /* !times() */
190 static struct timeb tstart,tend;
191 long i;
192
193 if (s == START)
194 {
195 ftime(&tstart);
196 return(0);
197 }
198 else
199 {
200 ftime(&tend);
201 i=(long)tend.millitm-(long)tstart.millitm;
202 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
203 return((ret == 0.0)?1e-6:ret);
204 }
205#endif
206 }
207
208#ifdef SIGALRM
209#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
210#else
211#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
212#endif
213
214#define time_it(func,name,index) \
215 print_name(name); \
216 Time_F(START); \
217 for (count=0,run=1; COND(cb); count+=4) \
218 { \
219 unsigned long d[2]; \
220 func(d,&sch); \
221 func(d,&sch); \
222 func(d,&sch); \
223 func(d,&sch); \
224 } \
225 tm[index]=Time_F(STOP); \
226 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
227 tm[index]=((double)COUNT(cb))/tm[index];
228
229#define print_it(name,index) \
230 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
231 tm[index]*8,1.0e6/tm[index]);
232
233int main(int argc, char **argv)
234 {
235 long count;
236 static unsigned char buf[BUFSIZE];
237 static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
238 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
239 CAST_KEY sch;
240 double d,tm[16],max=0;
241 int rank[16];
242 char *str[16];
243 int max_idx=0,i,num=0,j;
244#ifndef SIGALARM
245 long ca,cb,cc,cd,ce;
246#endif
247
248 for (i=0; i<12; i++)
249 {
250 tm[i]=0.0;
251 rank[i]=0;
252 }
253
254#ifndef TIMES
255 fprintf(stderr,"To get the most accurate results, try to run this\n");
256 fprintf(stderr,"program when this computer is idle.\n");
257#endif
258
259 CAST_set_key(&sch,16,key);
260
261#ifndef SIGALRM
262 fprintf(stderr,"First we calculate the approximate speed ...\n");
263 count=10;
264 do {
265 long i;
266 unsigned long data[2];
267
268 count*=2;
269 Time_F(START);
270 for (i=count; i; i--)
271 CAST_encrypt(data,&sch);
272 d=Time_F(STOP);
273 } while (d < 3.0);
274 ca=count;
275 cb=count*3;
276 cc=count*3*8/BUFSIZE+1;
277 cd=count*8/BUFSIZE+1;
278
279 ce=count/20+1;
280#define COND(d) (count != (d))
281#define COUNT(d) (d)
282#else
283#define COND(c) (run)
284#define COUNT(d) (count)
285 signal(SIGALRM,sig_done);
286 alarm(10);
287#endif
288
289 time_it(CAST_encrypt_normal, "CAST_encrypt_normal ", 0);
290 time_it(CAST_encrypt_ptr, "CAST_encrypt_ptr ", 1);
291 time_it(CAST_encrypt_ptr2, "CAST_encrypt_ptr2 ", 2);
292 num+=3;
293
294 str[0]="<nothing>";
295 print_it("CAST_encrypt_normal ",0);
296 max=tm[0];
297 max_idx=0;
298 str[1]="ptr ";
299 print_it("CAST_encrypt_ptr ",1);
300 if (max < tm[1]) { max=tm[1]; max_idx=1; }
301 str[2]="ptr2 ";
302 print_it("CAST_encrypt_ptr2 ",2);
303 if (max < tm[2]) { max=tm[2]; max_idx=2; }
304
305 printf("options CAST ecb/s\n");
306 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
307 d=tm[max_idx];
308 tm[max_idx]= -2.0;
309 max= -1.0;
310 for (;;)
311 {
312 for (i=0; i<3; i++)
313 {
314 if (max < tm[i]) { max=tm[i]; j=i; }
315 }
316 if (max < 0.0) break;
317 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
318 tm[j]= -2.0;
319 max= -1.0;
320 }
321
322 switch (max_idx)
323 {
324 case 0:
325 printf("-DCAST_DEFAULT_OPTIONS\n");
326 break;
327 case 1:
328 printf("-DCAST_PTR\n");
329 break;
330 case 2:
331 printf("-DCAST_PTR2\n");
332 break;
333 }
334 exit(0);
335#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
336 return(0);
337#endif
338 }
339
diff --git a/src/lib/libcrypto/cast/casts.cpp b/src/lib/libcrypto/cast/casts.cpp
new file mode 100644
index 0000000000..8d7bd468d2
--- /dev/null
+++ b/src/lib/libcrypto/cast/casts.cpp
@@ -0,0 +1,70 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/cast.h>
36
37void main(int argc,char *argv[])
38 {
39 CAST_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43 static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
44
45 CAST_set_key(&key, 16,d);
46
47 for (j=0; j<6; j++)
48 {
49 for (i=0; i<1000; i++) /**/
50 {
51 CAST_encrypt(&data[0],&key);
52 GetTSC(s1);
53 CAST_encrypt(&data[0],&key);
54 CAST_encrypt(&data[0],&key);
55 CAST_encrypt(&data[0],&key);
56 GetTSC(e1);
57 GetTSC(s2);
58 CAST_encrypt(&data[0],&key);
59 CAST_encrypt(&data[0],&key);
60 CAST_encrypt(&data[0],&key);
61 CAST_encrypt(&data[0],&key);
62 GetTSC(e2);
63 CAST_encrypt(&data[0],&key);
64 }
65
66 printf("cast %d %d (%d)\n",
67 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
68 }
69 }
70
diff --git a/src/lib/libcrypto/cast/casttest.c b/src/lib/libcrypto/cast/casttest.c
new file mode 100644
index 0000000000..83e5a16c73
--- /dev/null
+++ b/src/lib/libcrypto/cast/casttest.c
@@ -0,0 +1,232 @@
1/* crypto/cast/casttest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_CAST
66int main(int argc, char *argv[])
67{
68 printf("No CAST support\n");
69 return(0);
70}
71#else
72#include <openssl/cast.h>
73
74#define FULL_TEST
75
76static unsigned char k[16]={
77 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
78 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A
79 };
80
81static unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
82
83static int k_len[3]={16,10,5};
84static unsigned char c[3][8]={
85 {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2},
86 {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B},
87 {0x7A,0xC8,0x16,0xD1,0x6E,0x9B,0x30,0x2E},
88 };
89static unsigned char out[80];
90
91static unsigned char in_a[16]={
92 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
93 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
94static unsigned char in_b[16]={
95 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78,
96 0x23,0x45,0x67,0x89,0x34,0x56,0x78,0x9A};
97
98static unsigned char c_a[16]={
99 0xEE,0xA9,0xD0,0xA2,0x49,0xFD,0x3B,0xA6,
100 0xB3,0x43,0x6F,0xB8,0x9D,0x6D,0xCA,0x92};
101static unsigned char c_b[16]={
102 0xB2,0xC9,0x5E,0xB0,0x0C,0x31,0xAD,0x71,
103 0x80,0xAC,0x05,0xB8,0xE8,0x3D,0x69,0x6E};
104
105#if 0
106char *text="Hello to all people out there";
107
108static unsigned char cfb_key[16]={
109 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
110 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
111 };
112static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
113static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
114#define CFB_TEST_SIZE 24
115static unsigned char plain[CFB_TEST_SIZE]=
116 {
117 0x4e,0x6f,0x77,0x20,0x69,0x73,
118 0x20,0x74,0x68,0x65,0x20,0x74,
119 0x69,0x6d,0x65,0x20,0x66,0x6f,
120 0x72,0x20,0x61,0x6c,0x6c,0x20
121 };
122static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
123 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
124 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
125 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
126
127/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
128 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
129 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
130 };
131#endif
132
133int main(int argc, char *argv[])
134 {
135#ifdef FULL_TEST
136 long l;
137 CAST_KEY key_b;
138#endif
139 int i,z,err=0;
140 CAST_KEY key;
141
142 for (z=0; z<3; z++)
143 {
144 CAST_set_key(&key,k_len[z],k);
145
146 CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT);
147 if (memcmp(out,&(c[z][0]),8) != 0)
148 {
149 printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8);
150 printf("got :");
151 for (i=0; i<8; i++)
152 printf("%02X ",out[i]);
153 printf("\n");
154 printf("expected:");
155 for (i=0; i<8; i++)
156 printf("%02X ",c[z][i]);
157 err=20;
158 printf("\n");
159 }
160
161 CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT);
162 if (memcmp(out,in,8) != 0)
163 {
164 printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8);
165 printf("got :");
166 for (i=0; i<8; i++)
167 printf("%02X ",out[i]);
168 printf("\n");
169 printf("expected:");
170 for (i=0; i<8; i++)
171 printf("%02X ",in[i]);
172 printf("\n");
173 err=3;
174 }
175 }
176 if (err == 0)
177 printf("ecb cast5 ok\n");
178
179#ifdef FULL_TEST
180 {
181 unsigned char out_a[16],out_b[16];
182 static char *hex="0123456789ABCDEF";
183
184 printf("This test will take some time....");
185 fflush(stdout);
186 memcpy(out_a,in_a,sizeof(in_a));
187 memcpy(out_b,in_b,sizeof(in_b));
188 i=1;
189
190 for (l=0; l<1000000L; l++)
191 {
192 CAST_set_key(&key_b,16,out_b);
193 CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT);
194 CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT);
195 CAST_set_key(&key,16,out_a);
196 CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT);
197 CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT);
198 if ((l & 0xffff) == 0xffff)
199 {
200 printf("%c",hex[i&0x0f]);
201 fflush(stdout);
202 i++;
203 }
204 }
205
206 if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) ||
207 (memcmp(out_b,c_b,sizeof(c_b)) != 0))
208 {
209 printf("\n");
210 printf("Error\n");
211
212 printf("A out =");
213 for (i=0; i<16; i++) printf("%02X ",out_a[i]);
214 printf("\nactual=");
215 for (i=0; i<16; i++) printf("%02X ",c_a[i]);
216 printf("\n");
217
218 printf("B out =");
219 for (i=0; i<16; i++) printf("%02X ",out_b[i]);
220 printf("\nactual=");
221 for (i=0; i<16; i++) printf("%02X ",c_b[i]);
222 printf("\n");
223 }
224 else
225 printf(" ok\n");
226 }
227#endif
228
229 EXIT(err);
230 return(err);
231 }
232#endif
diff --git a/src/lib/libcrypto/cms/Makefile b/src/lib/libcrypto/cms/Makefile
new file mode 100644
index 0000000000..e39c310b6c
--- /dev/null
+++ b/src/lib/libcrypto/cms/Makefile
@@ -0,0 +1,183 @@
1#
2# OpenSSL/crypto/cms/Makefile
3#
4
5DIR= cms
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= cms_lib.c cms_asn1.c cms_att.c cms_io.c cms_smime.c cms_err.c \
21 cms_sd.c cms_dd.c cms_cd.c cms_env.c cms_enc.c cms_ess.c
22LIBOBJ= cms_lib.o cms_asn1.o cms_att.o cms_io.o cms_smime.o cms_err.o \
23 cms_sd.o cms_dd.o cms_cd.o cms_env.o cms_enc.o cms_ess.o
24
25SRC= $(LIBSRC)
26
27EXHEADER= cms.h
28HEADER= cms_lcl.h $(EXHEADER)
29
30ALL= $(GENERAL) $(SRC) $(HEADER)
31
32top:
33 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
34
35test:
36
37all: lib
38
39lib: $(LIBOBJ)
40 $(AR) $(LIB) $(LIBOBJ)
41 $(RANLIB) $(LIB) || echo Never mind.
42 @touch lib
43
44files:
45 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
46
47links:
48 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51
52install:
53 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
54 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
55 do \
56 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done;
59
60tags:
61 ctags $(SRC)
62
63tests:
64
65lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff
67
68depend:
69 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
70 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
71
72dclean:
73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
74 mv -f Makefile.new $(MAKEFILE)
75
76clean:
77 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
78
79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81cms_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
82cms_asn1.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
83cms_asn1.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
84cms_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
85cms_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
86cms_asn1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
87cms_asn1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
88cms_asn1.o: ../../include/openssl/opensslconf.h
89cms_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
90cms_asn1.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
91cms_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
92cms_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
93cms_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
94cms_asn1.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
95cms_asn1.o: cms.h cms_asn1.c cms_lcl.h
96cms_att.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
97cms_att.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
98cms_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
99cms_att.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
100cms_att.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
101cms_att.o: ../../include/openssl/err.h ../../include/openssl/evp.h
102cms_att.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
103cms_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104cms_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105cms_att.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
106cms_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
107cms_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
108cms_att.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
109cms_att.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
110cms_att.o: cms.h cms_att.c cms_lcl.h
111cms_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
112cms_err.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
113cms_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
114cms_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
115cms_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
116cms_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
117cms_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
118cms_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
119cms_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
120cms_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
121cms_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
122cms_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
123cms_err.o: cms_err.c
124cms_io.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
125cms_io.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
126cms_io.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
127cms_io.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
128cms_io.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
129cms_io.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
130cms_io.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
131cms_io.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132cms_io.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
133cms_io.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
134cms_io.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
135cms_io.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
136cms_io.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h
137cms_io.o: cms_io.c cms_lcl.h
138cms_lib.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
139cms_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
140cms_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
141cms_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
142cms_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
143cms_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
144cms_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
145cms_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
146cms_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
147cms_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
148cms_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
149cms_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
150cms_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h cms.h
151cms_lib.o: cms_lcl.h cms_lib.c
152cms_sd.o: ../../e_os.h ../../include/openssl/asn1.h
153cms_sd.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
154cms_sd.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
155cms_sd.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
156cms_sd.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
157cms_sd.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
158cms_sd.o: ../../include/openssl/err.h ../../include/openssl/evp.h
159cms_sd.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
160cms_sd.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
161cms_sd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
162cms_sd.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
163cms_sd.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
164cms_sd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
165cms_sd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
166cms_sd.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
167cms_sd.o: ../cryptlib.h cms_lcl.h cms_sd.c
168cms_smime.o: ../../e_os.h ../../include/openssl/asn1.h
169cms_smime.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
170cms_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cms.h
171cms_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
172cms_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
173cms_smime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
174cms_smime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
175cms_smime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
176cms_smime.o: ../../include/openssl/objects.h
177cms_smime.o: ../../include/openssl/opensslconf.h
178cms_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
179cms_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
180cms_smime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
181cms_smime.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
182cms_smime.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
183cms_smime.o: ../cryptlib.h cms_lcl.h cms_smime.c
diff --git a/src/lib/libcrypto/comp/Makefile b/src/lib/libcrypto/comp/Makefile
new file mode 100644
index 0000000000..efda832dce
--- /dev/null
+++ b/src/lib/libcrypto/comp/Makefile
@@ -0,0 +1,108 @@
1#
2# OpenSSL/crypto/comp/Makefile
3#
4
5DIR= comp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= comp_lib.c comp_err.c \
21 c_rle.c c_zlib.c
22
23LIBOBJ= comp_lib.o comp_err.o \
24 c_rle.o c_zlib.o
25
26SRC= $(LIBSRC)
27
28EXHEADER= comp.h
29HEADER= $(EXHEADER)
30
31ALL= $(GENERAL) $(SRC) $(HEADER)
32
33top:
34 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
35
36all: lib
37
38lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ)
40 $(RANLIB) $(LIB) || echo Never mind.
41 @touch lib
42
43files:
44 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
45
46links:
47 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
48 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
49 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
50
51install:
52 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
53 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
54 do \
55 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
56 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
57 done;
58
59tags:
60 ctags $(SRC)
61
62tests:
63
64lint:
65 lint -DLINT $(INCLUDES) $(SRC)>fluff
66
67depend:
68 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
69 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
70
71dclean:
72 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE)
74
75clean:
76 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78# DO NOT DELETE THIS LINE -- make depend depends on it.
79
80c_rle.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
81c_rle.o: ../../include/openssl/comp.h ../../include/openssl/crypto.h
82c_rle.o: ../../include/openssl/e_os2.h ../../include/openssl/obj_mac.h
83c_rle.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
84c_rle.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
85c_rle.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
86c_rle.o: ../../include/openssl/symhacks.h c_rle.c
87c_zlib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
88c_zlib.o: ../../include/openssl/comp.h ../../include/openssl/crypto.h
89c_zlib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
90c_zlib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
91c_zlib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
92c_zlib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93c_zlib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94c_zlib.o: ../../include/openssl/symhacks.h c_zlib.c
95comp_err.o: ../../include/openssl/bio.h ../../include/openssl/comp.h
96comp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
97comp_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
98comp_err.o: ../../include/openssl/opensslconf.h
99comp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
100comp_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
101comp_err.o: ../../include/openssl/symhacks.h comp_err.c
102comp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
103comp_lib.o: ../../include/openssl/comp.h ../../include/openssl/crypto.h
104comp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/obj_mac.h
105comp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
106comp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
107comp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
108comp_lib.o: ../../include/openssl/symhacks.h comp_lib.c
diff --git a/src/lib/libcrypto/comp/Makefile.ssl b/src/lib/libcrypto/comp/Makefile.ssl
new file mode 100644
index 0000000000..f70ba1b285
--- /dev/null
+++ b/src/lib/libcrypto/comp/Makefile.ssl
@@ -0,0 +1,114 @@
1#
2# SSLeay/crypto/comp/Makefile
3#
4
5DIR= comp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= comp_lib.c comp_err.c \
27 c_rle.c c_zlib.c
28
29LIBOBJ= comp_lib.o comp_err.o \
30 c_rle.o c_zlib.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= comp.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) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links:
53 @sh $(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) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(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
85c_rle.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
86c_rle.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
87c_rle.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88c_rle.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
89c_rle.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
90c_rle.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
91c_rle.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h c_rle.c
92c_zlib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
93c_zlib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
94c_zlib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
95c_zlib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
96c_zlib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
97c_zlib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
98c_zlib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
99c_zlib.o: c_zlib.c
100comp_err.o: ../../include/openssl/bio.h ../../include/openssl/comp.h
101comp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102comp_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
103comp_err.o: ../../include/openssl/opensslconf.h
104comp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
105comp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
106comp_err.o: comp_err.c
107comp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
108comp_lib.o: ../../include/openssl/bn.h ../../include/openssl/comp.h
109comp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
110comp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
111comp_lib.o: ../../include/openssl/opensslconf.h
112comp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113comp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
114comp_lib.o: ../../include/openssl/symhacks.h comp_lib.c
diff --git a/src/lib/libcrypto/comp/c_zlib.c b/src/lib/libcrypto/comp/c_zlib.c
index 0f34597e70..5fcb521ffb 100644
--- a/src/lib/libcrypto/comp/c_zlib.c
+++ b/src/lib/libcrypto/comp/c_zlib.c
@@ -24,32 +24,6 @@ static COMP_METHOD zlib_method_nozlib={
24 24
25#include <zlib.h> 25#include <zlib.h>
26 26
27static int zlib_stateful_init(COMP_CTX *ctx);
28static void zlib_stateful_finish(COMP_CTX *ctx);
29static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
30 unsigned int olen, unsigned char *in, unsigned int ilen);
31static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
32 unsigned int olen, unsigned char *in, unsigned int ilen);
33
34
35/* memory allocations functions for zlib intialization */
36static void* zlib_zalloc(void* opaque, unsigned int no, unsigned int size)
37{
38 void *p;
39
40 p=OPENSSL_malloc(no*size);
41 if (p)
42 memset(p, 0, no*size);
43 return p;
44}
45
46
47static void zlib_zfree(void* opaque, void* address)
48{
49 OPENSSL_free(address);
50}
51
52#if 0
53static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 27static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
54 unsigned int olen, unsigned char *in, unsigned int ilen); 28 unsigned int olen, unsigned char *in, unsigned int ilen);
55static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 29static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
@@ -58,7 +32,7 @@ static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
58static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source, 32static int zz_uncompress(Bytef *dest, uLongf *destLen, const Bytef *source,
59 uLong sourceLen); 33 uLong sourceLen);
60 34
61static COMP_METHOD zlib_stateless_method={ 35static COMP_METHOD zlib_method={
62 NID_zlib_compression, 36 NID_zlib_compression,
63 LN_zlib_compression, 37 LN_zlib_compression,
64 NULL, 38 NULL,
@@ -68,24 +42,12 @@ static COMP_METHOD zlib_stateless_method={
68 NULL, 42 NULL,
69 NULL, 43 NULL,
70 }; 44 };
71#endif
72
73static COMP_METHOD zlib_stateful_method={
74 NID_zlib_compression,
75 LN_zlib_compression,
76 zlib_stateful_init,
77 zlib_stateful_finish,
78 zlib_stateful_compress_block,
79 zlib_stateful_expand_block,
80 NULL,
81 NULL,
82 };
83 45
84/* 46/*
85 * When OpenSSL is built on Windows, we do not want to require that 47 * When OpenSSL is built on Windows, we do not want to require that
86 * the ZLIB.DLL be available in order for the OpenSSL DLLs to 48 * the ZLIB.DLL be available in order for the OpenSSL DLLs to
87 * work. Therefore, all ZLIB routines are loaded at run time 49 * work. Therefore, all ZLIB routines are loaded at run time
88 * and we do not link to a .LIB file when ZLIB_SHARED is set. 50 * and we do not link to a .LIB file.
89 */ 51 */
90#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) 52#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
91# include <windows.h> 53# include <windows.h>
@@ -101,19 +63,10 @@ typedef int (*inflateEnd_ft)(z_streamp strm);
101typedef int (*inflate_ft)(z_streamp strm, int flush); 63typedef int (*inflate_ft)(z_streamp strm, int flush);
102typedef int (*inflateInit__ft)(z_streamp strm, 64typedef int (*inflateInit__ft)(z_streamp strm,
103 const char * version, int stream_size); 65 const char * version, int stream_size);
104typedef int (*deflateEnd_ft)(z_streamp strm);
105typedef int (*deflate_ft)(z_streamp strm, int flush);
106typedef int (*deflateInit__ft)(z_streamp strm, int level,
107 const char * version, int stream_size);
108typedef const char * (*zError__ft)(int err);
109static compress_ft p_compress=NULL; 66static compress_ft p_compress=NULL;
110static inflateEnd_ft p_inflateEnd=NULL; 67static inflateEnd_ft p_inflateEnd=NULL;
111static inflate_ft p_inflate=NULL; 68static inflate_ft p_inflate=NULL;
112static inflateInit__ft p_inflateInit_=NULL; 69static inflateInit__ft p_inflateInit_=NULL;
113static deflateEnd_ft p_deflateEnd=NULL;
114static deflate_ft p_deflate=NULL;
115static deflateInit__ft p_deflateInit_=NULL;
116static zError__ft p_zError=NULL;
117 70
118static int zlib_loaded = 0; /* only attempt to init func pts once */ 71static int zlib_loaded = 0; /* only attempt to init func pts once */
119static DSO *zlib_dso = NULL; 72static DSO *zlib_dso = NULL;
@@ -122,133 +75,10 @@ static DSO *zlib_dso = NULL;
122#define inflateEnd p_inflateEnd 75#define inflateEnd p_inflateEnd
123#define inflate p_inflate 76#define inflate p_inflate
124#define inflateInit_ p_inflateInit_ 77#define inflateInit_ p_inflateInit_
125#define deflateEnd p_deflateEnd
126#define deflate p_deflate
127#define deflateInit_ p_deflateInit_
128#define zError p_zError
129#endif /* ZLIB_SHARED */ 78#endif /* ZLIB_SHARED */
130 79
131struct zlib_state
132 {
133 z_stream istream;
134 z_stream ostream;
135 };
136
137static int zlib_stateful_ex_idx = -1;
138
139static void zlib_stateful_free_ex_data(void *obj, void *item,
140 CRYPTO_EX_DATA *ad, int ind,long argl, void *argp)
141 {
142 struct zlib_state *state = (struct zlib_state *)item;
143 inflateEnd(&state->istream);
144 deflateEnd(&state->ostream);
145 OPENSSL_free(state);
146 }
147
148static int zlib_stateful_init(COMP_CTX *ctx)
149 {
150 int err;
151 struct zlib_state *state =
152 (struct zlib_state *)OPENSSL_malloc(sizeof(struct zlib_state));
153
154 if (state == NULL)
155 goto err;
156
157 state->istream.zalloc = zlib_zalloc;
158 state->istream.zfree = zlib_zfree;
159 state->istream.opaque = Z_NULL;
160 state->istream.next_in = Z_NULL;
161 state->istream.next_out = Z_NULL;
162 state->istream.avail_in = 0;
163 state->istream.avail_out = 0;
164 err = inflateInit_(&state->istream,
165 ZLIB_VERSION, sizeof(z_stream));
166 if (err != Z_OK)
167 goto err;
168
169 state->ostream.zalloc = zlib_zalloc;
170 state->ostream.zfree = zlib_zfree;
171 state->ostream.opaque = Z_NULL;
172 state->ostream.next_in = Z_NULL;
173 state->ostream.next_out = Z_NULL;
174 state->ostream.avail_in = 0;
175 state->ostream.avail_out = 0;
176 err = deflateInit_(&state->ostream,Z_DEFAULT_COMPRESSION,
177 ZLIB_VERSION, sizeof(z_stream));
178 if (err != Z_OK)
179 goto err;
180
181 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
182 CRYPTO_set_ex_data(&ctx->ex_data,zlib_stateful_ex_idx,state);
183 return 1;
184 err:
185 if (state) OPENSSL_free(state);
186 return 0;
187 }
188
189static void zlib_stateful_finish(COMP_CTX *ctx)
190 {
191 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_COMP,ctx,&ctx->ex_data);
192 }
193
194static int zlib_stateful_compress_block(COMP_CTX *ctx, unsigned char *out,
195 unsigned int olen, unsigned char *in, unsigned int ilen)
196 {
197 int err = Z_OK;
198 struct zlib_state *state =
199 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
200 zlib_stateful_ex_idx);
201
202 if (state == NULL)
203 return -1;
204
205 state->ostream.next_in = in;
206 state->ostream.avail_in = ilen;
207 state->ostream.next_out = out;
208 state->ostream.avail_out = olen;
209 if (ilen > 0)
210 err = deflate(&state->ostream, Z_SYNC_FLUSH);
211 if (err != Z_OK)
212 return -1;
213#ifdef DEBUG_ZLIB
214 fprintf(stderr,"compress(%4d)->%4d %s\n",
215 ilen,olen - state->ostream.avail_out,
216 (ilen != olen - state->ostream.avail_out)?"zlib":"clear");
217#endif
218 return olen - state->ostream.avail_out;
219 }
220
221static int zlib_stateful_expand_block(COMP_CTX *ctx, unsigned char *out,
222 unsigned int olen, unsigned char *in, unsigned int ilen)
223 {
224 int err = Z_OK;
225
226 struct zlib_state *state =
227 (struct zlib_state *)CRYPTO_get_ex_data(&ctx->ex_data,
228 zlib_stateful_ex_idx);
229
230 if (state == NULL)
231 return 0;
232
233 state->istream.next_in = in;
234 state->istream.avail_in = ilen;
235 state->istream.next_out = out;
236 state->istream.avail_out = olen;
237 if (ilen > 0)
238 err = inflate(&state->istream, Z_SYNC_FLUSH);
239 if (err != Z_OK)
240 return -1;
241#ifdef DEBUG_ZLIB
242 fprintf(stderr,"expand(%4d)->%4d %s\n",
243 ilen,olen - state->istream.avail_out,
244 (ilen != olen - state->istream.avail_out)?"zlib":"clear");
245#endif
246 return olen - state->istream.avail_out;
247 }
248
249#if 0
250static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out, 80static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
251 unsigned int olen, unsigned char *in, unsigned int ilen) 81 unsigned int olen, unsigned char *in, unsigned int ilen)
252 { 82 {
253 unsigned long l; 83 unsigned long l;
254 int i; 84 int i;
@@ -281,7 +111,7 @@ static int zlib_compress_block(COMP_CTX *ctx, unsigned char *out,
281 } 111 }
282 112
283static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out, 113static int zlib_expand_block(COMP_CTX *ctx, unsigned char *out,
284 unsigned int olen, unsigned char *in, unsigned int ilen) 114 unsigned int olen, unsigned char *in, unsigned int ilen)
285 { 115 {
286 unsigned long l; 116 unsigned long l;
287 int i; 117 int i;
@@ -323,8 +153,7 @@ static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
323 stream.zalloc = (alloc_func)0; 153 stream.zalloc = (alloc_func)0;
324 stream.zfree = (free_func)0; 154 stream.zfree = (free_func)0;
325 155
326 err = inflateInit_(&stream, 156 err = inflateInit(&stream);
327 ZLIB_VERSION, sizeof(z_stream));
328 if (err != Z_OK) return err; 157 if (err != Z_OK) return err;
329 158
330 err = inflate(&stream, Z_FINISH); 159 err = inflate(&stream, Z_FINISH);
@@ -337,7 +166,6 @@ static int zz_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source,
337 err = inflateEnd(&stream); 166 err = inflateEnd(&stream);
338 return err; 167 return err;
339} 168}
340#endif
341 169
342#endif 170#endif
343 171
@@ -367,22 +195,9 @@ COMP_METHOD *COMP_zlib(void)
367 p_inflateInit_ 195 p_inflateInit_
368 = (inflateInit__ft) DSO_bind_func(zlib_dso, 196 = (inflateInit__ft) DSO_bind_func(zlib_dso,
369 "inflateInit_"); 197 "inflateInit_");
370 p_deflateEnd
371 = (deflateEnd_ft) DSO_bind_func(zlib_dso,
372 "deflateEnd");
373 p_deflate
374 = (deflate_ft) DSO_bind_func(zlib_dso,
375 "deflate");
376 p_deflateInit_
377 = (deflateInit__ft) DSO_bind_func(zlib_dso,
378 "deflateInit_");
379 p_zError
380 = (zError__ft) DSO_bind_func(zlib_dso,
381 "zError");
382 198
383 if (p_compress && p_inflateEnd && p_inflate 199 if (p_compress && p_inflateEnd && p_inflate
384 && p_inflateInit_ && p_deflateEnd 200 && p_inflateInit_)
385 && p_deflate && p_deflateInit_ && p_zError)
386 zlib_loaded++; 201 zlib_loaded++;
387 } 202 }
388 } 203 }
@@ -392,410 +207,9 @@ COMP_METHOD *COMP_zlib(void)
392 if (zlib_loaded) 207 if (zlib_loaded)
393#endif 208#endif
394#if defined(ZLIB) || defined(ZLIB_SHARED) 209#if defined(ZLIB) || defined(ZLIB_SHARED)
395 { 210 meth = &zlib_method;
396 /* init zlib_stateful_ex_idx here so that in a multi-process
397 * application it's enough to intialize openssl before forking
398 * (idx will be inherited in all the children) */
399 if (zlib_stateful_ex_idx == -1)
400 {
401 CRYPTO_w_lock(CRYPTO_LOCK_COMP);
402 if (zlib_stateful_ex_idx == -1)
403 zlib_stateful_ex_idx =
404 CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_COMP,
405 0,NULL,NULL,NULL,zlib_stateful_free_ex_data);
406 CRYPTO_w_unlock(CRYPTO_LOCK_COMP);
407 if (zlib_stateful_ex_idx == -1)
408 goto err;
409 }
410
411 meth = &zlib_stateful_method;
412 }
413err:
414#endif 211#endif
415 212
416 return(meth); 213 return(meth);
417 } 214 }
418 215
419void COMP_zlib_cleanup(void)
420 {
421#ifdef ZLIB_SHARED
422 if (zlib_dso)
423 DSO_free(zlib_dso);
424#endif
425 }
426
427#ifdef ZLIB
428
429/* Zlib based compression/decompression filter BIO */
430
431typedef struct
432 {
433 unsigned char *ibuf; /* Input buffer */
434 int ibufsize; /* Buffer size */
435 z_stream zin; /* Input decompress context */
436 unsigned char *obuf; /* Output buffer */
437 int obufsize; /* Output buffer size */
438 unsigned char *optr; /* Position in output buffer */
439 int ocount; /* Amount of data in output buffer */
440 int odone; /* deflate EOF */
441 int comp_level; /* Compression level to use */
442 z_stream zout; /* Output compression context */
443 } BIO_ZLIB_CTX;
444
445#define ZLIB_DEFAULT_BUFSIZE 1024
446
447static int bio_zlib_new(BIO *bi);
448static int bio_zlib_free(BIO *bi);
449static int bio_zlib_read(BIO *b, char *out, int outl);
450static int bio_zlib_write(BIO *b, const char *in, int inl);
451static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr);
452static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp);
453
454static BIO_METHOD bio_meth_zlib =
455 {
456 BIO_TYPE_COMP,
457 "zlib",
458 bio_zlib_write,
459 bio_zlib_read,
460 NULL,
461 NULL,
462 bio_zlib_ctrl,
463 bio_zlib_new,
464 bio_zlib_free,
465 bio_zlib_callback_ctrl
466 };
467
468BIO_METHOD *BIO_f_zlib(void)
469 {
470 return &bio_meth_zlib;
471 }
472
473
474static int bio_zlib_new(BIO *bi)
475 {
476 BIO_ZLIB_CTX *ctx;
477#ifdef ZLIB_SHARED
478 (void)COMP_zlib();
479 if (!zlib_loaded)
480 {
481 COMPerr(COMP_F_BIO_ZLIB_NEW, COMP_R_ZLIB_NOT_SUPPORTED);
482 return 0;
483 }
484#endif
485 ctx = OPENSSL_malloc(sizeof(BIO_ZLIB_CTX));
486 if(!ctx)
487 {
488 COMPerr(COMP_F_BIO_ZLIB_NEW, ERR_R_MALLOC_FAILURE);
489 return 0;
490 }
491 ctx->ibuf = NULL;
492 ctx->obuf = NULL;
493 ctx->ibufsize = ZLIB_DEFAULT_BUFSIZE;
494 ctx->obufsize = ZLIB_DEFAULT_BUFSIZE;
495 ctx->zin.zalloc = Z_NULL;
496 ctx->zin.zfree = Z_NULL;
497 ctx->zin.next_in = NULL;
498 ctx->zin.avail_in = 0;
499 ctx->zin.next_out = NULL;
500 ctx->zin.avail_out = 0;
501 ctx->zout.zalloc = Z_NULL;
502 ctx->zout.zfree = Z_NULL;
503 ctx->zout.next_in = NULL;
504 ctx->zout.avail_in = 0;
505 ctx->zout.next_out = NULL;
506 ctx->zout.avail_out = 0;
507 ctx->odone = 0;
508 ctx->comp_level = Z_DEFAULT_COMPRESSION;
509 bi->init = 1;
510 bi->ptr = (char *)ctx;
511 bi->flags = 0;
512 return 1;
513 }
514
515static int bio_zlib_free(BIO *bi)
516 {
517 BIO_ZLIB_CTX *ctx;
518 if(!bi) return 0;
519 ctx = (BIO_ZLIB_CTX *)bi->ptr;
520 if(ctx->ibuf)
521 {
522 /* Destroy decompress context */
523 inflateEnd(&ctx->zin);
524 OPENSSL_free(ctx->ibuf);
525 }
526 if(ctx->obuf)
527 {
528 /* Destroy compress context */
529 deflateEnd(&ctx->zout);
530 OPENSSL_free(ctx->obuf);
531 }
532 OPENSSL_free(ctx);
533 bi->ptr = NULL;
534 bi->init = 0;
535 bi->flags = 0;
536 return 1;
537 }
538
539static int bio_zlib_read(BIO *b, char *out, int outl)
540 {
541 BIO_ZLIB_CTX *ctx;
542 int ret;
543 z_stream *zin;
544 if(!out || !outl) return 0;
545 ctx = (BIO_ZLIB_CTX *)b->ptr;
546 zin = &ctx->zin;
547 BIO_clear_retry_flags(b);
548 if(!ctx->ibuf)
549 {
550 ctx->ibuf = OPENSSL_malloc(ctx->ibufsize);
551 if(!ctx->ibuf)
552 {
553 COMPerr(COMP_F_BIO_ZLIB_READ, ERR_R_MALLOC_FAILURE);
554 return 0;
555 }
556 inflateInit(zin);
557 zin->next_in = ctx->ibuf;
558 zin->avail_in = 0;
559 }
560
561 /* Copy output data directly to supplied buffer */
562 zin->next_out = (unsigned char *)out;
563 zin->avail_out = (unsigned int)outl;
564 for(;;)
565 {
566 /* Decompress while data available */
567 while(zin->avail_in)
568 {
569 ret = inflate(zin, 0);
570 if((ret != Z_OK) && (ret != Z_STREAM_END))
571 {
572 COMPerr(COMP_F_BIO_ZLIB_READ,
573 COMP_R_ZLIB_INFLATE_ERROR);
574 ERR_add_error_data(2, "zlib error:",
575 zError(ret));
576 return 0;
577 }
578 /* If EOF or we've read everything then return */
579 if((ret == Z_STREAM_END) || !zin->avail_out)
580 return outl - zin->avail_out;
581 }
582
583 /* No data in input buffer try to read some in,
584 * if an error then return the total data read.
585 */
586 ret = BIO_read(b->next_bio, ctx->ibuf, ctx->ibufsize);
587 if(ret <= 0)
588 {
589 /* Total data read */
590 int tot = outl - zin->avail_out;
591 BIO_copy_next_retry(b);
592 if(ret < 0) return (tot > 0) ? tot : ret;
593 return tot;
594 }
595 zin->avail_in = ret;
596 zin->next_in = ctx->ibuf;
597 }
598 }
599
600static int bio_zlib_write(BIO *b, const char *in, int inl)
601 {
602 BIO_ZLIB_CTX *ctx;
603 int ret;
604 z_stream *zout;
605 if(!in || !inl) return 0;
606 ctx = (BIO_ZLIB_CTX *)b->ptr;
607 if(ctx->odone) return 0;
608 zout = &ctx->zout;
609 BIO_clear_retry_flags(b);
610 if(!ctx->obuf)
611 {
612 ctx->obuf = OPENSSL_malloc(ctx->obufsize);
613 /* Need error here */
614 if(!ctx->obuf)
615 {
616 COMPerr(COMP_F_BIO_ZLIB_WRITE, ERR_R_MALLOC_FAILURE);
617 return 0;
618 }
619 ctx->optr = ctx->obuf;
620 ctx->ocount = 0;
621 deflateInit(zout, ctx->comp_level);
622 zout->next_out = ctx->obuf;
623 zout->avail_out = ctx->obufsize;
624 }
625 /* Obtain input data directly from supplied buffer */
626 zout->next_in = (void *)in;
627 zout->avail_in = inl;
628 for(;;)
629 {
630 /* If data in output buffer write it first */
631 while(ctx->ocount) {
632 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
633 if(ret <= 0)
634 {
635 /* Total data written */
636 int tot = inl - zout->avail_in;
637 BIO_copy_next_retry(b);
638 if(ret < 0) return (tot > 0) ? tot : ret;
639 return tot;
640 }
641 ctx->optr += ret;
642 ctx->ocount -= ret;
643 }
644
645 /* Have we consumed all supplied data? */
646 if(!zout->avail_in)
647 return inl;
648
649 /* Compress some more */
650
651 /* Reset buffer */
652 ctx->optr = ctx->obuf;
653 zout->next_out = ctx->obuf;
654 zout->avail_out = ctx->obufsize;
655 /* Compress some more */
656 ret = deflate(zout, 0);
657 if(ret != Z_OK)
658 {
659 COMPerr(COMP_F_BIO_ZLIB_WRITE,
660 COMP_R_ZLIB_DEFLATE_ERROR);
661 ERR_add_error_data(2, "zlib error:", zError(ret));
662 return 0;
663 }
664 ctx->ocount = ctx->obufsize - zout->avail_out;
665 }
666 }
667
668static int bio_zlib_flush(BIO *b)
669 {
670 BIO_ZLIB_CTX *ctx;
671 int ret;
672 z_stream *zout;
673 ctx = (BIO_ZLIB_CTX *)b->ptr;
674 /* If no data written or already flush show success */
675 if(!ctx->obuf || (ctx->odone && !ctx->ocount)) return 1;
676 zout = &ctx->zout;
677 BIO_clear_retry_flags(b);
678 /* No more input data */
679 zout->next_in = NULL;
680 zout->avail_in = 0;
681 for(;;)
682 {
683 /* If data in output buffer write it first */
684 while(ctx->ocount)
685 {
686 ret = BIO_write(b->next_bio, ctx->optr, ctx->ocount);
687 if(ret <= 0)
688 {
689 BIO_copy_next_retry(b);
690 return ret;
691 }
692 ctx->optr += ret;
693 ctx->ocount -= ret;
694 }
695 if(ctx->odone) return 1;
696
697 /* Compress some more */
698
699 /* Reset buffer */
700 ctx->optr = ctx->obuf;
701 zout->next_out = ctx->obuf;
702 zout->avail_out = ctx->obufsize;
703 /* Compress some more */
704 ret = deflate(zout, Z_FINISH);
705 if(ret == Z_STREAM_END) ctx->odone = 1;
706 else if(ret != Z_OK)
707 {
708 COMPerr(COMP_F_BIO_ZLIB_FLUSH,
709 COMP_R_ZLIB_DEFLATE_ERROR);
710 ERR_add_error_data(2, "zlib error:", zError(ret));
711 return 0;
712 }
713 ctx->ocount = ctx->obufsize - zout->avail_out;
714 }
715 }
716
717static long bio_zlib_ctrl(BIO *b, int cmd, long num, void *ptr)
718 {
719 BIO_ZLIB_CTX *ctx;
720 int ret, *ip;
721 int ibs, obs;
722 if(!b->next_bio) return 0;
723 ctx = (BIO_ZLIB_CTX *)b->ptr;
724 switch (cmd)
725 {
726
727 case BIO_CTRL_RESET:
728 ctx->ocount = 0;
729 ctx->odone = 0;
730 break;
731
732 case BIO_CTRL_FLUSH:
733 ret = bio_zlib_flush(b);
734 if (ret > 0)
735 ret = BIO_flush(b->next_bio);
736 break;
737
738 case BIO_C_SET_BUFF_SIZE:
739 ibs = -1;
740 obs = -1;
741 if (ptr != NULL)
742 {
743 ip = ptr;
744 if (*ip == 0)
745 ibs = (int) num;
746 else
747 obs = (int) num;
748 }
749 else
750 {
751 ibs = (int)num;
752 obs = ibs;
753 }
754
755 if (ibs != -1)
756 {
757 if (ctx->ibuf)
758 {
759 OPENSSL_free(ctx->ibuf);
760 ctx->ibuf = NULL;
761 }
762 ctx->ibufsize = ibs;
763 }
764
765 if (obs != -1)
766 {
767 if (ctx->obuf)
768 {
769 OPENSSL_free(ctx->obuf);
770 ctx->obuf = NULL;
771 }
772 ctx->obufsize = obs;
773 }
774
775 break;
776
777 case BIO_C_DO_STATE_MACHINE:
778 BIO_clear_retry_flags(b);
779 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
780 BIO_copy_next_retry(b);
781 break;
782
783 default:
784 ret = BIO_ctrl(b->next_bio, cmd, num, ptr);
785 break;
786
787 }
788
789 return ret;
790 }
791
792
793static long bio_zlib_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
794 {
795 if(!b->next_bio)
796 return 0;
797 return
798 BIO_callback_ctrl(b->next_bio, cmd, fp);
799 }
800
801#endif
diff --git a/src/lib/libcrypto/comp/comp.h b/src/lib/libcrypto/comp/comp.h
index 4b405c7d49..ab48b78ae9 100644
--- a/src/lib/libcrypto/comp/comp.h
+++ b/src/lib/libcrypto/comp/comp.h
@@ -8,26 +8,19 @@
8extern "C" { 8extern "C" {
9#endif 9#endif
10 10
11typedef struct comp_ctx_st COMP_CTX;
12
13typedef struct comp_method_st 11typedef struct comp_method_st
14 { 12 {
15 int type; /* NID for compression library */ 13 int type; /* NID for compression library */
16 const char *name; /* A text string to identify the library */ 14 const char *name; /* A text string to identify the library */
17 int (*init)(COMP_CTX *ctx); 15 int (*init)();
18 void (*finish)(COMP_CTX *ctx); 16 void (*finish)();
19 int (*compress)(COMP_CTX *ctx, 17 int (*compress)();
20 unsigned char *out, unsigned int olen, 18 int (*expand)();
21 unsigned char *in, unsigned int ilen); 19 long (*ctrl)();
22 int (*expand)(COMP_CTX *ctx, 20 long (*callback_ctrl)();
23 unsigned char *out, unsigned int olen,
24 unsigned char *in, unsigned int ilen);
25 /* The following two do NOTHING, but are kept for backward compatibility */
26 long (*ctrl)(void);
27 long (*callback_ctrl)(void);
28 } COMP_METHOD; 21 } COMP_METHOD;
29 22
30struct comp_ctx_st 23typedef struct comp_ctx_st
31 { 24 {
32 COMP_METHOD *meth; 25 COMP_METHOD *meth;
33 unsigned long compress_in; 26 unsigned long compress_in;
@@ -36,7 +29,7 @@ struct comp_ctx_st
36 unsigned long expand_out; 29 unsigned long expand_out;
37 30
38 CRYPTO_EX_DATA ex_data; 31 CRYPTO_EX_DATA ex_data;
39 }; 32 } COMP_CTX;
40 33
41 34
42COMP_CTX *COMP_CTX_new(COMP_METHOD *meth); 35COMP_CTX *COMP_CTX_new(COMP_METHOD *meth);
@@ -47,13 +40,6 @@ int COMP_expand_block(COMP_CTX *ctx, unsigned char *out, int olen,
47 unsigned char *in, int ilen); 40 unsigned char *in, int ilen);
48COMP_METHOD *COMP_rle(void ); 41COMP_METHOD *COMP_rle(void );
49COMP_METHOD *COMP_zlib(void ); 42COMP_METHOD *COMP_zlib(void );
50void COMP_zlib_cleanup(void);
51
52#ifdef HEADER_BIO_H
53#ifdef ZLIB
54BIO_METHOD *BIO_f_zlib(void);
55#endif
56#endif
57 43
58/* BEGIN ERROR CODES */ 44/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes 45/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -64,15 +50,8 @@ void ERR_load_COMP_strings(void);
64/* Error codes for the COMP functions. */ 50/* Error codes for the COMP functions. */
65 51
66/* Function codes. */ 52/* Function codes. */
67#define COMP_F_BIO_ZLIB_FLUSH 99
68#define COMP_F_BIO_ZLIB_NEW 100
69#define COMP_F_BIO_ZLIB_READ 101
70#define COMP_F_BIO_ZLIB_WRITE 102
71 53
72/* Reason codes. */ 54/* Reason codes. */
73#define COMP_R_ZLIB_DEFLATE_ERROR 99
74#define COMP_R_ZLIB_INFLATE_ERROR 100
75#define COMP_R_ZLIB_NOT_SUPPORTED 101
76 55
77#ifdef __cplusplus 56#ifdef __cplusplus
78} 57}
diff --git a/src/lib/libcrypto/comp/comp_err.c b/src/lib/libcrypto/comp/comp_err.c
index 187d68b725..1652b8c2c4 100644
--- a/src/lib/libcrypto/comp/comp_err.c
+++ b/src/lib/libcrypto/comp/comp_err.c
@@ -1,6 +1,6 @@
1/* crypto/comp/comp_err.c */ 1/* crypto/comp/comp_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -64,24 +64,13 @@
64 64
65/* BEGIN ERROR CODES */ 65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR 66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_COMP,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_COMP,0,reason)
70
71static ERR_STRING_DATA COMP_str_functs[]= 67static ERR_STRING_DATA COMP_str_functs[]=
72 { 68 {
73{ERR_FUNC(COMP_F_BIO_ZLIB_FLUSH), "BIO_ZLIB_FLUSH"},
74{ERR_FUNC(COMP_F_BIO_ZLIB_NEW), "BIO_ZLIB_NEW"},
75{ERR_FUNC(COMP_F_BIO_ZLIB_READ), "BIO_ZLIB_READ"},
76{ERR_FUNC(COMP_F_BIO_ZLIB_WRITE), "BIO_ZLIB_WRITE"},
77{0,NULL} 69{0,NULL}
78 }; 70 };
79 71
80static ERR_STRING_DATA COMP_str_reasons[]= 72static ERR_STRING_DATA COMP_str_reasons[]=
81 { 73 {
82{ERR_REASON(COMP_R_ZLIB_DEFLATE_ERROR) ,"zlib deflate error"},
83{ERR_REASON(COMP_R_ZLIB_INFLATE_ERROR) ,"zlib inflate error"},
84{ERR_REASON(COMP_R_ZLIB_NOT_SUPPORTED) ,"zlib not supported"},
85{0,NULL} 74{0,NULL}
86 }; 75 };
87 76
@@ -89,12 +78,15 @@ static ERR_STRING_DATA COMP_str_reasons[]=
89 78
90void ERR_load_COMP_strings(void) 79void ERR_load_COMP_strings(void)
91 { 80 {
92#ifndef OPENSSL_NO_ERR 81 static int init=1;
93 82
94 if (ERR_func_error_string(COMP_str_functs[0].error) == NULL) 83 if (init)
95 { 84 {
96 ERR_load_strings(0,COMP_str_functs); 85 init=0;
97 ERR_load_strings(0,COMP_str_reasons); 86#ifndef OPENSSL_NO_ERR
98 } 87 ERR_load_strings(ERR_LIB_COMP,COMP_str_functs);
88 ERR_load_strings(ERR_LIB_COMP,COMP_str_reasons);
99#endif 89#endif
90
91 }
100 } 92 }
diff --git a/src/lib/libcrypto/comp/comp_lib.c b/src/lib/libcrypto/comp/comp_lib.c
index b60ae371e8..beb98ce8cc 100644
--- a/src/lib/libcrypto/comp/comp_lib.c
+++ b/src/lib/libcrypto/comp/comp_lib.c
@@ -20,11 +20,17 @@ COMP_CTX *COMP_CTX_new(COMP_METHOD *meth)
20 OPENSSL_free(ret); 20 OPENSSL_free(ret);
21 ret=NULL; 21 ret=NULL;
22 } 22 }
23#if 0
24 else
25 CRYPTO_new_ex_data(rsa_meth,(char *)ret,&ret->ex_data);
26#endif
23 return(ret); 27 return(ret);
24 } 28 }
25 29
26void COMP_CTX_free(COMP_CTX *ctx) 30void COMP_CTX_free(COMP_CTX *ctx)
27 { 31 {
32 /* CRYPTO_free_ex_data(rsa_meth,(char *)ctx,&ctx->ex_data); */
33
28 if(ctx == NULL) 34 if(ctx == NULL)
29 return; 35 return;
30 36
diff --git a/src/lib/libcrypto/conf/Makefile b/src/lib/libcrypto/conf/Makefile
new file mode 100644
index 0000000000..78bb324106
--- /dev/null
+++ b/src/lib/libcrypto/conf/Makefile
@@ -0,0 +1,152 @@
1#
2# OpenSSL/crypto/conf/Makefile
3#
4
5DIR= conf
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= conf_err.c conf_lib.c conf_api.c conf_def.c conf_mod.c \
21 conf_mall.c conf_sap.c
22
23LIBOBJ= conf_err.o conf_lib.o conf_api.o conf_def.o conf_mod.o \
24 conf_mall.o conf_sap.o
25
26SRC= $(LIBSRC)
27
28EXHEADER= conf.h conf_api.h
29HEADER= conf_def.h $(EXHEADER)
30
31ALL= $(GENERAL) $(SRC) $(HEADER)
32
33top:
34 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
35
36all: lib
37
38lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ)
40 $(RANLIB) $(LIB) || echo Never mind.
41 @touch lib
42
43files:
44 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
45
46links:
47 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
48 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
49 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
50
51install:
52 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
53 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
54 do \
55 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
56 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
57 done;
58
59tags:
60 ctags $(SRC)
61
62tests:
63
64lint:
65 lint -DLINT $(INCLUDES) $(SRC)>fluff
66
67depend:
68 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
69 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
70
71dclean:
72 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE)
74
75clean:
76 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78# DO NOT DELETE THIS LINE -- make depend depends on it.
79
80conf_api.o: ../../e_os.h ../../include/openssl/bio.h
81conf_api.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
82conf_api.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
83conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
84conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
85conf_api.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
86conf_api.o: ../../include/openssl/symhacks.h conf_api.c
87conf_def.o: ../../e_os.h ../../include/openssl/bio.h
88conf_def.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
89conf_def.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
90conf_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
91conf_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
92conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93conf_def.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94conf_def.o: ../../include/openssl/symhacks.h ../cryptlib.h conf_def.c
95conf_def.o: conf_def.h
96conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
97conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
98conf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
99conf_err.o: ../../include/openssl/opensslconf.h
100conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101conf_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
102conf_err.o: ../../include/openssl/symhacks.h conf_err.c
103conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
104conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
105conf_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
106conf_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
107conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
108conf_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
109conf_lib.o: ../../include/openssl/symhacks.h conf_lib.c
110conf_mall.o: ../../e_os.h ../../include/openssl/asn1.h
111conf_mall.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
112conf_mall.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
113conf_mall.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
114conf_mall.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
115conf_mall.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
116conf_mall.o: ../../include/openssl/err.h ../../include/openssl/evp.h
117conf_mall.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
118conf_mall.o: ../../include/openssl/objects.h
119conf_mall.o: ../../include/openssl/opensslconf.h
120conf_mall.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
121conf_mall.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
122conf_mall.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
123conf_mall.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
124conf_mall.o: ../../include/openssl/x509_vfy.h ../cryptlib.h conf_mall.c
125conf_mod.o: ../../e_os.h ../../include/openssl/asn1.h
126conf_mod.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
127conf_mod.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
128conf_mod.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
129conf_mod.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
130conf_mod.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
131conf_mod.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
132conf_mod.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
133conf_mod.o: ../../include/openssl/opensslconf.h
134conf_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
135conf_mod.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
136conf_mod.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
137conf_mod.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
138conf_mod.o: ../../include/openssl/x509_vfy.h ../cryptlib.h conf_mod.c
139conf_sap.o: ../../e_os.h ../../include/openssl/asn1.h
140conf_sap.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
141conf_sap.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
142conf_sap.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
143conf_sap.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
144conf_sap.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
145conf_sap.o: ../../include/openssl/err.h ../../include/openssl/evp.h
146conf_sap.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
147conf_sap.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
148conf_sap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149conf_sap.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
150conf_sap.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151conf_sap.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
152conf_sap.o: ../../include/openssl/x509_vfy.h ../cryptlib.h conf_sap.c
diff --git a/src/lib/libcrypto/conf/Makefile.ssl b/src/lib/libcrypto/conf/Makefile.ssl
new file mode 100644
index 0000000000..c5873bc6e7
--- /dev/null
+++ b/src/lib/libcrypto/conf/Makefile.ssl
@@ -0,0 +1,183 @@
1#
2# SSLeay/crypto/conf/Makefile
3#
4
5DIR= conf
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= conf_err.c conf_lib.c conf_api.c conf_def.c conf_mod.c \
27 conf_mall.c conf_sap.c
28
29LIBOBJ= conf_err.o conf_lib.o conf_api.o conf_def.o conf_mod.o \
30 conf_mall.o conf_sap.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= conf.h conf_api.h
35HEADER= conf_def.h $(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) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links:
53 @sh $(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) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(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
85conf_api.o: ../../e_os.h ../../include/openssl/bio.h
86conf_api.o: ../../include/openssl/conf.h ../../include/openssl/conf_api.h
87conf_api.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88conf_api.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
89conf_api.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
90conf_api.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
91conf_api.o: conf_api.c
92conf_def.o: ../../e_os.h ../../include/openssl/bio.h
93conf_def.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
94conf_def.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
95conf_def.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
96conf_def.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
97conf_def.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
98conf_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
99conf_def.o: ../cryptlib.h conf_def.c conf_def.h
100conf_err.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
101conf_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102conf_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
103conf_err.o: ../../include/openssl/opensslconf.h
104conf_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
105conf_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
106conf_err.o: conf_err.c
107conf_lib.o: ../../include/openssl/bio.h ../../include/openssl/conf.h
108conf_lib.o: ../../include/openssl/conf_api.h ../../include/openssl/crypto.h
109conf_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
110conf_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
111conf_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
112conf_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
113conf_lib.o: conf_lib.c
114conf_mall.o: ../../e_os.h ../../include/openssl/aes.h
115conf_mall.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
116conf_mall.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
117conf_mall.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
118conf_mall.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
119conf_mall.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
120conf_mall.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
121conf_mall.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
122conf_mall.o: ../../include/openssl/engine.h ../../include/openssl/err.h
123conf_mall.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
124conf_mall.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
125conf_mall.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
126conf_mall.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
127conf_mall.o: ../../include/openssl/objects.h
128conf_mall.o: ../../include/openssl/opensslconf.h
129conf_mall.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130conf_mall.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
131conf_mall.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
132conf_mall.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
133conf_mall.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
134conf_mall.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
135conf_mall.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
136conf_mall.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
137conf_mall.o: ../../include/openssl/x509_vfy.h ../cryptlib.h conf_mall.c
138conf_mod.o: ../../e_os.h ../../include/openssl/aes.h
139conf_mod.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
140conf_mod.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
141conf_mod.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
142conf_mod.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
143conf_mod.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
144conf_mod.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
145conf_mod.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
146conf_mod.o: ../../include/openssl/err.h ../../include/openssl/evp.h
147conf_mod.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
148conf_mod.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
149conf_mod.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
150conf_mod.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
151conf_mod.o: ../../include/openssl/opensslconf.h
152conf_mod.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
153conf_mod.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
154conf_mod.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
155conf_mod.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
156conf_mod.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
157conf_mod.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
158conf_mod.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
159conf_mod.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
160conf_mod.o: ../cryptlib.h conf_mod.c
161conf_sap.o: ../../e_os.h ../../include/openssl/aes.h
162conf_sap.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
163conf_sap.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
164conf_sap.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
165conf_sap.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
166conf_sap.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
167conf_sap.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
168conf_sap.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
169conf_sap.o: ../../include/openssl/engine.h ../../include/openssl/err.h
170conf_sap.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
171conf_sap.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
172conf_sap.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
173conf_sap.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
174conf_sap.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
175conf_sap.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
176conf_sap.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
177conf_sap.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
178conf_sap.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
179conf_sap.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
180conf_sap.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
181conf_sap.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
182conf_sap.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
183conf_sap.o: ../../include/openssl/x509_vfy.h ../cryptlib.h conf_sap.c
diff --git a/src/lib/libcrypto/conf/cnf_save.c b/src/lib/libcrypto/conf/cnf_save.c
new file mode 100644
index 0000000000..1439487526
--- /dev/null
+++ b/src/lib/libcrypto/conf/cnf_save.c
@@ -0,0 +1,106 @@
1/* crypto/conf/cnf_save.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/conf.h>
61
62static void print_conf(CONF_VALUE *cv);
63static IMPLEMENT_LHASH_DOALL_FN(print_conf, CONF_VALUE *);
64
65main()
66 {
67 LHASH *conf;
68 long l;
69
70 conf=CONF_load(NULL,"../../apps/openssl.cnf",&l);
71 if (conf == NULL)
72 {
73 fprintf(stderr,"error loading config, line %ld\n",l);
74 exit(1);
75 }
76
77 lh_doall(conf,LHASH_DOALL_FN(print_conf));
78 }
79
80
81static void print_conf(CONF_VALUE *cv)
82 {
83 int i;
84 CONF_VALUE *v;
85 char *section;
86 char *name;
87 char *value;
88 STACK *s;
89
90 /* If it is a single entry, return */
91
92 if (cv->name != NULL) return;
93
94 printf("[ %s ]\n",cv->section);
95 s=(STACK *)cv->value;
96
97 for (i=0; i<sk_num(s); i++)
98 {
99 v=(CONF_VALUE *)sk_value(s,i);
100 section=(v->section == NULL)?"None":v->section;
101 name=(v->name == NULL)?"None":v->name;
102 value=(v->value == NULL)?"None":v->value;
103 printf("%s=%s\n",name,value);
104 }
105 printf("\n");
106 }
diff --git a/src/lib/libcrypto/conf/conf.h b/src/lib/libcrypto/conf/conf.h
index 8aa06bc5ec..f4671442ab 100644
--- a/src/lib/libcrypto/conf/conf.h
+++ b/src/lib/libcrypto/conf/conf.h
@@ -65,8 +65,6 @@
65#include <openssl/safestack.h> 65#include <openssl/safestack.h>
66#include <openssl/e_os2.h> 66#include <openssl/e_os2.h>
67 67
68#include <openssl/ossl_typ.h>
69
70#ifdef __cplusplus 68#ifdef __cplusplus
71extern "C" { 69extern "C" {
72#endif 70#endif
@@ -83,6 +81,7 @@ DECLARE_STACK_OF(CONF_MODULE)
83DECLARE_STACK_OF(CONF_IMODULE) 81DECLARE_STACK_OF(CONF_IMODULE)
84 82
85struct conf_st; 83struct conf_st;
84typedef struct conf_st CONF;
86struct conf_method_st; 85struct conf_method_st;
87typedef struct conf_method_st CONF_METHOD; 86typedef struct conf_method_st CONF_METHOD;
88 87
@@ -114,7 +113,6 @@ typedef void conf_finish_func(CONF_IMODULE *md);
114#define CONF_MFLAGS_SILENT 0x4 113#define CONF_MFLAGS_SILENT 0x4
115#define CONF_MFLAGS_NO_DSO 0x8 114#define CONF_MFLAGS_NO_DSO 0x8
116#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10 115#define CONF_MFLAGS_IGNORE_MISSING_FILE 0x10
117#define CONF_MFLAGS_DEFAULT_SECTION 0x20
118 116
119int CONF_set_default_method(CONF_METHOD *meth); 117int CONF_set_default_method(CONF_METHOD *meth);
120void CONF_set_nconf(CONF *conf,LHASH *hash); 118void CONF_set_nconf(CONF *conf,LHASH *hash);
@@ -214,8 +212,6 @@ void ERR_load_CONF_strings(void);
214#define CONF_F_CONF_LOAD_BIO 102 212#define CONF_F_CONF_LOAD_BIO 102
215#define CONF_F_CONF_LOAD_FP 103 213#define CONF_F_CONF_LOAD_FP 103
216#define CONF_F_CONF_MODULES_LOAD 116 214#define CONF_F_CONF_MODULES_LOAD 116
217#define CONF_F_DEF_LOAD 120
218#define CONF_F_DEF_LOAD_BIO 121
219#define CONF_F_MODULE_INIT 115 215#define CONF_F_MODULE_INIT 115
220#define CONF_F_MODULE_LOAD_DSO 117 216#define CONF_F_MODULE_LOAD_DSO 117
221#define CONF_F_MODULE_RUN 118 217#define CONF_F_MODULE_RUN 118
diff --git a/src/lib/libcrypto/conf/conf_api.c b/src/lib/libcrypto/conf/conf_api.c
index 909d72b4b8..0032baa711 100644
--- a/src/lib/libcrypto/conf/conf_api.c
+++ b/src/lib/libcrypto/conf/conf_api.c
@@ -121,7 +121,7 @@ int _CONF_add_string(CONF *conf, CONF_VALUE *section, CONF_VALUE *value)
121 v = (CONF_VALUE *)lh_insert(conf->data, value); 121 v = (CONF_VALUE *)lh_insert(conf->data, value);
122 if (v != NULL) 122 if (v != NULL)
123 { 123 {
124 (void)sk_CONF_VALUE_delete_ptr(ts,v); 124 sk_CONF_VALUE_delete_ptr(ts,v);
125 OPENSSL_free(v->name); 125 OPENSSL_free(v->name);
126 OPENSSL_free(v->value); 126 OPENSSL_free(v->value);
127 OPENSSL_free(v); 127 OPENSSL_free(v);
diff --git a/src/lib/libcrypto/conf/conf_def.c b/src/lib/libcrypto/conf/conf_def.c
index d8bce8732a..2464f8ed90 100644
--- a/src/lib/libcrypto/conf/conf_def.c
+++ b/src/lib/libcrypto/conf/conf_def.c
@@ -60,7 +60,6 @@
60 60
61#include <stdio.h> 61#include <stdio.h>
62#include <string.h> 62#include <string.h>
63#include "cryptlib.h"
64#include <openssl/stack.h> 63#include <openssl/stack.h>
65#include <openssl/lhash.h> 64#include <openssl/lhash.h>
66#include <openssl/conf.h> 65#include <openssl/conf.h>
@@ -68,6 +67,7 @@
68#include "conf_def.h" 67#include "conf_def.h"
69#include <openssl/buffer.h> 68#include <openssl/buffer.h>
70#include <openssl/err.h> 69#include <openssl/err.h>
70#include "cryptlib.h"
71 71
72static char *eat_ws(CONF *conf, char *p); 72static char *eat_ws(CONF *conf, char *p);
73static char *eat_alpha_numeric(CONF *conf, char *p); 73static char *eat_alpha_numeric(CONF *conf, char *p);
@@ -88,7 +88,7 @@ static int def_dump(const CONF *conf, BIO *bp);
88static int def_is_number(const CONF *conf, char c); 88static int def_is_number(const CONF *conf, char c);
89static int def_to_int(const CONF *conf, char c); 89static int def_to_int(const CONF *conf, char c);
90 90
91const char CONF_def_version[]="CONF_def" OPENSSL_VERSION_PTEXT; 91const char *CONF_def_version="CONF_def" OPENSSL_VERSION_PTEXT;
92 92
93static CONF_METHOD default_method = { 93static CONF_METHOD default_method = {
94 "OpenSSL default", 94 "OpenSSL default",
@@ -194,9 +194,9 @@ static int def_load(CONF *conf, const char *name, long *line)
194 if (in == NULL) 194 if (in == NULL)
195 { 195 {
196 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE) 196 if (ERR_GET_REASON(ERR_peek_last_error()) == BIO_R_NO_SUCH_FILE)
197 CONFerr(CONF_F_DEF_LOAD,CONF_R_NO_SUCH_FILE); 197 CONFerr(CONF_F_CONF_LOAD,CONF_R_NO_SUCH_FILE);
198 else 198 else
199 CONFerr(CONF_F_DEF_LOAD,ERR_R_SYS_LIB); 199 CONFerr(CONF_F_CONF_LOAD,ERR_R_SYS_LIB);
200 return 0; 200 return 0;
201 } 201 }
202 202
@@ -225,28 +225,28 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
225 225
226 if ((buff=BUF_MEM_new()) == NULL) 226 if ((buff=BUF_MEM_new()) == NULL)
227 { 227 {
228 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); 228 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
229 goto err; 229 goto err;
230 } 230 }
231 231
232 section=(char *)OPENSSL_malloc(10); 232 section=(char *)OPENSSL_malloc(10);
233 if (section == NULL) 233 if (section == NULL)
234 { 234 {
235 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); 235 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
236 goto err; 236 goto err;
237 } 237 }
238 BUF_strlcpy(section,"default",10); 238 BUF_strlcpy(section,"default",10);
239 239
240 if (_CONF_new_data(conf) == 0) 240 if (_CONF_new_data(conf) == 0)
241 { 241 {
242 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_MALLOC_FAILURE); 242 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_MALLOC_FAILURE);
243 goto err; 243 goto err;
244 } 244 }
245 245
246 sv=_CONF_new_section(conf,section); 246 sv=_CONF_new_section(conf,section);
247 if (sv == NULL) 247 if (sv == NULL)
248 { 248 {
249 CONFerr(CONF_F_DEF_LOAD_BIO, 249 CONFerr(CONF_F_CONF_LOAD_BIO,
250 CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 250 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
251 goto err; 251 goto err;
252 } 252 }
@@ -258,7 +258,7 @@ static int def_load_bio(CONF *conf, BIO *in, long *line)
258 { 258 {
259 if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE)) 259 if (!BUF_MEM_grow(buff,bufnum+CONFBUFSIZE))
260 { 260 {
261 CONFerr(CONF_F_DEF_LOAD_BIO,ERR_R_BUF_LIB); 261 CONFerr(CONF_F_CONF_LOAD_BIO,ERR_R_BUF_LIB);
262 goto err; 262 goto err;
263 } 263 }
264 p= &(buff->data[bufnum]); 264 p= &(buff->data[bufnum]);
@@ -329,7 +329,7 @@ again:
329 ss=p; 329 ss=p;
330 goto again; 330 goto again;
331 } 331 }
332 CONFerr(CONF_F_DEF_LOAD_BIO, 332 CONFerr(CONF_F_CONF_LOAD_BIO,
333 CONF_R_MISSING_CLOSE_SQUARE_BRACKET); 333 CONF_R_MISSING_CLOSE_SQUARE_BRACKET);
334 goto err; 334 goto err;
335 } 335 }
@@ -339,7 +339,7 @@ again:
339 sv=_CONF_new_section(conf,section); 339 sv=_CONF_new_section(conf,section);
340 if (sv == NULL) 340 if (sv == NULL)
341 { 341 {
342 CONFerr(CONF_F_DEF_LOAD_BIO, 342 CONFerr(CONF_F_CONF_LOAD_BIO,
343 CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 343 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
344 goto err; 344 goto err;
345 } 345 }
@@ -362,7 +362,7 @@ again:
362 p=eat_ws(conf, end); 362 p=eat_ws(conf, end);
363 if (*p != '=') 363 if (*p != '=')
364 { 364 {
365 CONFerr(CONF_F_DEF_LOAD_BIO, 365 CONFerr(CONF_F_CONF_LOAD_BIO,
366 CONF_R_MISSING_EQUAL_SIGN); 366 CONF_R_MISSING_EQUAL_SIGN);
367 goto err; 367 goto err;
368 } 368 }
@@ -379,7 +379,7 @@ again:
379 379
380 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) 380 if (!(v=(CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE))))
381 { 381 {
382 CONFerr(CONF_F_DEF_LOAD_BIO, 382 CONFerr(CONF_F_CONF_LOAD_BIO,
383 ERR_R_MALLOC_FAILURE); 383 ERR_R_MALLOC_FAILURE);
384 goto err; 384 goto err;
385 } 385 }
@@ -388,7 +388,7 @@ again:
388 v->value=NULL; 388 v->value=NULL;
389 if (v->name == NULL) 389 if (v->name == NULL)
390 { 390 {
391 CONFerr(CONF_F_DEF_LOAD_BIO, 391 CONFerr(CONF_F_CONF_LOAD_BIO,
392 ERR_R_MALLOC_FAILURE); 392 ERR_R_MALLOC_FAILURE);
393 goto err; 393 goto err;
394 } 394 }
@@ -402,7 +402,7 @@ again:
402 tv=_CONF_new_section(conf,psection); 402 tv=_CONF_new_section(conf,psection);
403 if (tv == NULL) 403 if (tv == NULL)
404 { 404 {
405 CONFerr(CONF_F_DEF_LOAD_BIO, 405 CONFerr(CONF_F_CONF_LOAD_BIO,
406 CONF_R_UNABLE_TO_CREATE_NEW_SECTION); 406 CONF_R_UNABLE_TO_CREATE_NEW_SECTION);
407 goto err; 407 goto err;
408 } 408 }
@@ -416,7 +416,7 @@ again:
416#if 1 416#if 1
417 if (_CONF_add_string(conf, tv, v) == 0) 417 if (_CONF_add_string(conf, tv, v) == 0)
418 { 418 {
419 CONFerr(CONF_F_DEF_LOAD_BIO, 419 CONFerr(CONF_F_CONF_LOAD_BIO,
420 ERR_R_MALLOC_FAILURE); 420 ERR_R_MALLOC_FAILURE);
421 goto err; 421 goto err;
422 } 422 }
@@ -424,7 +424,7 @@ again:
424 v->section=tv->section; 424 v->section=tv->section;
425 if (!sk_CONF_VALUE_push(ts,v)) 425 if (!sk_CONF_VALUE_push(ts,v))
426 { 426 {
427 CONFerr(CONF_F_DEF_LOAD_BIO, 427 CONFerr(CONF_F_CONF_LOAD_BIO,
428 ERR_R_MALLOC_FAILURE); 428 ERR_R_MALLOC_FAILURE);
429 goto err; 429 goto err;
430 } 430 }
@@ -629,7 +629,7 @@ static int str_copy(CONF *conf, char *section, char **pto, char *from)
629 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE); 629 CONFerr(CONF_F_STR_COPY,CONF_R_VARIABLE_HAS_NO_VALUE);
630 goto err; 630 goto err;
631 } 631 }
632 BUF_MEM_grow_clean(buf,(strlen(p)+buf->length-(e-from))); 632 BUF_MEM_grow_clean(buf,(strlen(p)+len-(e-from)));
633 while (*p) 633 while (*p)
634 buf->data[to++]= *(p++); 634 buf->data[to++]= *(p++);
635 635
diff --git a/src/lib/libcrypto/conf/conf_err.c b/src/lib/libcrypto/conf/conf_err.c
index a16a5e0bd4..f5e2ca4bf0 100644
--- a/src/lib/libcrypto/conf/conf_err.c
+++ b/src/lib/libcrypto/conf/conf_err.c
@@ -75,8 +75,6 @@ static ERR_STRING_DATA CONF_str_functs[]=
75{ERR_FUNC(CONF_F_CONF_LOAD_BIO), "CONF_load_bio"}, 75{ERR_FUNC(CONF_F_CONF_LOAD_BIO), "CONF_load_bio"},
76{ERR_FUNC(CONF_F_CONF_LOAD_FP), "CONF_load_fp"}, 76{ERR_FUNC(CONF_F_CONF_LOAD_FP), "CONF_load_fp"},
77{ERR_FUNC(CONF_F_CONF_MODULES_LOAD), "CONF_modules_load"}, 77{ERR_FUNC(CONF_F_CONF_MODULES_LOAD), "CONF_modules_load"},
78{ERR_FUNC(CONF_F_DEF_LOAD), "DEF_LOAD"},
79{ERR_FUNC(CONF_F_DEF_LOAD_BIO), "DEF_LOAD_BIO"},
80{ERR_FUNC(CONF_F_MODULE_INIT), "MODULE_INIT"}, 78{ERR_FUNC(CONF_F_MODULE_INIT), "MODULE_INIT"},
81{ERR_FUNC(CONF_F_MODULE_LOAD_DSO), "MODULE_LOAD_DSO"}, 79{ERR_FUNC(CONF_F_MODULE_LOAD_DSO), "MODULE_LOAD_DSO"},
82{ERR_FUNC(CONF_F_MODULE_RUN), "MODULE_RUN"}, 80{ERR_FUNC(CONF_F_MODULE_RUN), "MODULE_RUN"},
@@ -118,12 +116,15 @@ static ERR_STRING_DATA CONF_str_reasons[]=
118 116
119void ERR_load_CONF_strings(void) 117void ERR_load_CONF_strings(void)
120 { 118 {
121#ifndef OPENSSL_NO_ERR 119 static int init=1;
122 120
123 if (ERR_func_error_string(CONF_str_functs[0].error) == NULL) 121 if (init)
124 { 122 {
123 init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(0,CONF_str_functs); 125 ERR_load_strings(0,CONF_str_functs);
126 ERR_load_strings(0,CONF_str_reasons); 126 ERR_load_strings(0,CONF_str_reasons);
127 }
128#endif 127#endif
128
129 }
129 } 130 }
diff --git a/src/lib/libcrypto/conf/conf_lib.c b/src/lib/libcrypto/conf/conf_lib.c
index 2a3399d269..6a3cf109dd 100644
--- a/src/lib/libcrypto/conf/conf_lib.c
+++ b/src/lib/libcrypto/conf/conf_lib.c
@@ -63,7 +63,7 @@
63#include <openssl/conf_api.h> 63#include <openssl/conf_api.h>
64#include <openssl/lhash.h> 64#include <openssl/lhash.h>
65 65
66const char CONF_version[]="CONF" OPENSSL_VERSION_PTEXT; 66const char *CONF_version="CONF" OPENSSL_VERSION_PTEXT;
67 67
68static CONF_METHOD *default_CONF_method=NULL; 68static CONF_METHOD *default_CONF_method=NULL;
69 69
@@ -184,7 +184,7 @@ long CONF_get_number(LHASH *conf,const char *group,const char *name)
184 if (status == 0) 184 if (status == 0)
185 { 185 {
186 /* This function does not believe in errors... */ 186 /* This function does not believe in errors... */
187 ERR_clear_error(); 187 ERR_get_error();
188 } 188 }
189 return result; 189 return result;
190 } 190 }
diff --git a/src/lib/libcrypto/conf/conf_mod.c b/src/lib/libcrypto/conf/conf_mod.c
index 628e8333a6..812e60dc70 100644
--- a/src/lib/libcrypto/conf/conf_mod.c
+++ b/src/lib/libcrypto/conf/conf_mod.c
@@ -126,18 +126,17 @@ int CONF_modules_load(const CONF *cnf, const char *appname,
126 { 126 {
127 STACK_OF(CONF_VALUE) *values; 127 STACK_OF(CONF_VALUE) *values;
128 CONF_VALUE *vl; 128 CONF_VALUE *vl;
129 char *vsection = NULL; 129 char *vsection;
130 130
131 int ret, i; 131 int ret, i;
132 132
133 if (!cnf) 133 if (!cnf)
134 return 1; 134 return 1;
135 135
136 if (appname) 136 if (appname == NULL)
137 vsection = NCONF_get_string(cnf, NULL, appname); 137 appname = "openssl_conf";
138 138
139 if (!appname || (!vsection && (flags & CONF_MFLAGS_DEFAULT_SECTION))) 139 vsection = NCONF_get_string(cnf, NULL, appname);
140 vsection = NCONF_get_string(cnf, NULL, "openssl_conf");
141 140
142 if (!vsection) 141 if (!vsection)
143 { 142 {
@@ -232,7 +231,7 @@ static int module_run(const CONF *cnf, char *name, char *value,
232 if (!(flags & CONF_MFLAGS_SILENT)) 231 if (!(flags & CONF_MFLAGS_SILENT))
233 { 232 {
234 char rcode[DECIMAL_SIZE(ret)+1]; 233 char rcode[DECIMAL_SIZE(ret)+1];
235 CONFerr(CONF_F_MODULE_RUN, CONF_R_MODULE_INITIALIZATION_ERROR); 234 CONFerr(CONF_F_CONF_MODULES_LOAD, CONF_R_MODULE_INITIALIZATION_ERROR);
236 BIO_snprintf(rcode, sizeof rcode, "%-8d", ret); 235 BIO_snprintf(rcode, sizeof rcode, "%-8d", ret);
237 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode); 236 ERR_add_error_data(6, "module=", name, ", value=", value, ", retcode=", rcode);
238 } 237 }
@@ -255,7 +254,7 @@ static CONF_MODULE *module_load_dso(const CONF *cnf, char *name, char *value,
255 path = NCONF_get_string(cnf, value, "path"); 254 path = NCONF_get_string(cnf, value, "path");
256 if (!path) 255 if (!path)
257 { 256 {
258 ERR_clear_error(); 257 ERR_get_error();
259 path = name; 258 path = name;
260 } 259 }
261 dso = DSO_load(NULL, path, NULL, 0); 260 dso = DSO_load(NULL, path, NULL, 0);
@@ -432,7 +431,7 @@ void CONF_modules_unload(int all)
432 if (((md->links > 0) || !md->dso) && !all) 431 if (((md->links > 0) || !md->dso) && !all)
433 continue; 432 continue;
434 /* Since we're working in reverse this is OK */ 433 /* Since we're working in reverse this is OK */
435 (void)sk_CONF_MODULE_delete(supported_modules, i); 434 sk_CONF_MODULE_delete(supported_modules, i);
436 module_free(md); 435 module_free(md);
437 } 436 }
438 if (sk_CONF_MODULE_num(supported_modules) == 0) 437 if (sk_CONF_MODULE_num(supported_modules) == 0)
@@ -588,7 +587,7 @@ int CONF_parse_list(const char *list_, int sep, int nospc,
588 { 587 {
589 if (nospc) 588 if (nospc)
590 { 589 {
591 while(*lstart && isspace((unsigned char)*lstart)) 590 while(isspace((unsigned char)*lstart))
592 lstart++; 591 lstart++;
593 } 592 }
594 p = strchr(lstart, sep); 593 p = strchr(lstart, sep);
diff --git a/src/lib/libcrypto/conf/conf_sap.c b/src/lib/libcrypto/conf/conf_sap.c
index 9c53bac1a8..e15c2e5546 100644
--- a/src/lib/libcrypto/conf/conf_sap.c
+++ b/src/lib/libcrypto/conf/conf_sap.c
@@ -88,8 +88,8 @@ void OPENSSL_config(const char *config_name)
88 88
89 89
90 ERR_clear_error(); 90 ERR_clear_error();
91 if (CONF_modules_load_file(NULL, config_name, 91 if (CONF_modules_load_file(NULL, NULL,
92 CONF_MFLAGS_DEFAULT_SECTION|CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0) 92 CONF_MFLAGS_IGNORE_MISSING_FILE) <= 0)
93 { 93 {
94 BIO *bio_err; 94 BIO *bio_err;
95 ERR_load_crypto_strings(); 95 ERR_load_crypto_strings();
diff --git a/src/lib/libcrypto/conf/test.c b/src/lib/libcrypto/conf/test.c
new file mode 100644
index 0000000000..7fab85053e
--- /dev/null
+++ b/src/lib/libcrypto/conf/test.c
@@ -0,0 +1,98 @@
1/* crypto/conf/test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/conf.h>
62#include <openssl/err.h>
63
64main()
65 {
66 LHASH *conf;
67 long eline;
68 char *s,*s2;
69
70#ifdef USE_WIN32
71 CONF_set_default_method(CONF_WIN32);
72#endif
73 conf=CONF_load(NULL,"ssleay.cnf",&eline);
74 if (conf == NULL)
75 {
76 ERR_load_crypto_strings();
77 printf("unable to load configuration, line %ld\n",eline);
78 ERR_print_errors_fp(stderr);
79 exit(1);
80 }
81 lh_stats(conf,stdout);
82 lh_node_stats(conf,stdout);
83 lh_node_usage_stats(conf,stdout);
84
85 s=CONF_get_string(conf,NULL,"init2");
86 printf("init2=%s\n",(s == NULL)?"NULL":s);
87
88 s=CONF_get_string(conf,NULL,"cipher1");
89 printf("cipher1=%s\n",(s == NULL)?"NULL":s);
90
91 s=CONF_get_string(conf,"s_client","cipher1");
92 printf("s_client:cipher1=%s\n",(s == NULL)?"NULL":s);
93
94 printf("---------------------------- DUMP ------------------------\n");
95 CONF_dump_fp(conf, stdout);
96
97 exit(0);
98 }
diff --git a/src/lib/libcrypto/cpt_err.c b/src/lib/libcrypto/cpt_err.c
index 9fd41fff8c..06a6109cce 100644
--- a/src/lib/libcrypto/cpt_err.c
+++ b/src/lib/libcrypto/cpt_err.c
@@ -92,12 +92,15 @@ static ERR_STRING_DATA CRYPTO_str_reasons[]=
92 92
93void ERR_load_CRYPTO_strings(void) 93void ERR_load_CRYPTO_strings(void)
94 { 94 {
95#ifndef OPENSSL_NO_ERR 95 static int init=1;
96 96
97 if (ERR_func_error_string(CRYPTO_str_functs[0].error) == NULL) 97 if (init)
98 { 98 {
99 init=0;
100#ifndef OPENSSL_NO_ERR
99 ERR_load_strings(0,CRYPTO_str_functs); 101 ERR_load_strings(0,CRYPTO_str_functs);
100 ERR_load_strings(0,CRYPTO_str_reasons); 102 ERR_load_strings(0,CRYPTO_str_reasons);
101 }
102#endif 103#endif
104
105 }
103 } 106 }
diff --git a/src/lib/libcrypto/cryptlib.c b/src/lib/libcrypto/cryptlib.c
index 8c68623828..e63bbe8dba 100644
--- a/src/lib/libcrypto/cryptlib.c
+++ b/src/lib/libcrypto/cryptlib.c
@@ -1,57 +1,4 @@
1/* crypto/cryptlib.c */ 1/* crypto/cryptlib.c */
2/* ====================================================================
3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved. 3 * All rights reserved.
57 * 4 *
@@ -108,13 +55,11 @@
108 * copied and put under another distribution licence 55 * copied and put under another distribution licence
109 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
110 */ 57 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECDH support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116 58
59#include <stdio.h>
60#include <string.h>
117#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/crypto.h>
118#include <openssl/safestack.h> 63#include <openssl/safestack.h>
119 64
120#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) 65#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16)
@@ -125,7 +70,7 @@ DECLARE_STACK_OF(CRYPTO_dynlock)
125IMPLEMENT_STACK_OF(CRYPTO_dynlock) 70IMPLEMENT_STACK_OF(CRYPTO_dynlock)
126 71
127/* real #defines in crypto.h, keep these upto date */ 72/* real #defines in crypto.h, keep these upto date */
128static const char* const lock_names[CRYPTO_NUM_LOCKS] = 73static const char* lock_names[CRYPTO_NUM_LOCKS] =
129 { 74 {
130 "<<ERROR>>", 75 "<<ERROR>>",
131 "err", 76 "err",
@@ -159,14 +104,10 @@ static const char* const lock_names[CRYPTO_NUM_LOCKS] =
159 "dynlock", 104 "dynlock",
160 "engine", 105 "engine",
161 "ui", 106 "ui",
162 "ecdsa", 107 "hwcrhk", /* This is a HACK which will disappear in 0.9.8 */
163 "ec", 108 "fips",
164 "ecdh", 109 "fips2",
165 "bn", 110#if CRYPTO_NUM_LOCKS != 35
166 "ec_pre_comp",
167 "store",
168 "comp",
169#if CRYPTO_NUM_LOCKS != 39
170# error "Inconsistency between crypto.h and cryptlib.c" 111# error "Inconsistency between crypto.h and cryptlib.c"
171#endif 112#endif
172 }; 113 };
@@ -277,7 +218,7 @@ int CRYPTO_get_new_dynlockid(void)
277 else 218 else
278 /* If we found a place with a NULL pointer, put our pointer 219 /* If we found a place with a NULL pointer, put our pointer
279 in it. */ 220 in it. */
280 (void)sk_CRYPTO_dynlock_set(dyn_locks,i,pointer); 221 sk_CRYPTO_dynlock_set(dyn_locks,i,pointer);
281 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK); 222 CRYPTO_w_unlock(CRYPTO_LOCK_DYNLOCK);
282 223
283 if (i == -1) 224 if (i == -1)
@@ -319,7 +260,7 @@ void CRYPTO_destroy_dynlockid(int i)
319#endif 260#endif
320 if (pointer->references <= 0) 261 if (pointer->references <= 0)
321 { 262 {
322 (void)sk_CRYPTO_dynlock_set(dyn_locks, i, NULL); 263 sk_CRYPTO_dynlock_set(dyn_locks, i, NULL);
323 } 264 }
324 else 265 else
325 pointer = NULL; 266 pointer = NULL;
@@ -539,48 +480,9 @@ const char *CRYPTO_get_lock_name(int type)
539 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS)); 480 return(sk_value(app_locks,type-CRYPTO_NUM_LOCKS));
540 } 481 }
541 482
542#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ 483int OPENSSL_NONPIC_relocated=0;
543 defined(__INTEL__) || \
544 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64)
545
546unsigned long OPENSSL_ia32cap_P=0;
547unsigned long *OPENSSL_ia32cap_loc(void) { return &OPENSSL_ia32cap_P; }
548
549#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM) && !defined(I386_ONLY)
550#define OPENSSL_CPUID_SETUP
551void OPENSSL_cpuid_setup(void)
552{ static int trigger=0;
553 unsigned long OPENSSL_ia32_cpuid(void);
554 char *env;
555 484
556 if (trigger) return; 485#if defined(_WIN32) && defined(_WINDLL)
557
558 trigger=1;
559 if ((env=getenv("OPENSSL_ia32cap")))
560 OPENSSL_ia32cap_P = strtoul(env,NULL,0)|(1<<10);
561 else
562 OPENSSL_ia32cap_P = OPENSSL_ia32_cpuid()|(1<<10);
563 /*
564 * |(1<<10) sets a reserved bit to signal that variable
565 * was initialized already... This is to avoid interference
566 * with cpuid snippets in ELF .init segment.
567 */
568}
569#endif
570
571#else
572unsigned long *OPENSSL_ia32cap_loc(void) { return NULL; }
573#endif
574int OPENSSL_NONPIC_relocated = 0;
575#if !defined(OPENSSL_CPUID_SETUP)
576void OPENSSL_cpuid_setup(void) {}
577#endif
578
579#if (defined(_WIN32) || defined(__CYGWIN__)) && defined(_WINDLL)
580#ifdef __CYGWIN__
581/* pick DLL_[PROCESS|THREAD]_[ATTACH|DETACH] definitions */
582#include <windows.h>
583#endif
584 486
585/* All we really need to do is remove the 'error' state when a thread 487/* All we really need to do is remove the 'error' state when a thread
586 * detaches */ 488 * detaches */
@@ -591,7 +493,6 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
591 switch(fdwReason) 493 switch(fdwReason)
592 { 494 {
593 case DLL_PROCESS_ATTACH: 495 case DLL_PROCESS_ATTACH:
594 OPENSSL_cpuid_setup();
595#if defined(_WIN32_WINNT) 496#if defined(_WIN32_WINNT)
596 { 497 {
597 IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL; 498 IMAGE_DOS_HEADER *dos_header = (IMAGE_DOS_HEADER *)hinstDLL;
@@ -620,11 +521,11 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason,
620 } 521 }
621#endif 522#endif
622 523
623#if defined(_WIN32) && !defined(__CYGWIN__) 524#if defined(_WIN32)
624#include <tchar.h> 525#include <tchar.h>
625 526
626#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 527#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
627int OPENSSL_isservice(void) 528static int IsService(void)
628{ HWINSTA h; 529{ HWINSTA h;
629 DWORD len; 530 DWORD len;
630 WCHAR *name; 531 WCHAR *name;
@@ -661,15 +562,12 @@ int OPENSSL_isservice(void)
661#endif 562#endif
662 else return 0; 563 else return 0;
663} 564}
664#else
665int OPENSSL_isservice(void) { return 0; }
666#endif 565#endif
667 566
668void OPENSSL_showfatal (const char *fmta,...) 567void OPENSSL_showfatal (const char *fmta,...)
669{ va_list ap; 568{ va_list ap;
670 TCHAR buf[256]; 569 TCHAR buf[256];
671 const TCHAR *fmt; 570 const TCHAR *fmt;
672#ifdef STD_ERROR_HANDLE /* what a dirty trick! */
673 HANDLE h; 571 HANDLE h;
674 572
675 if ((h=GetStdHandle(STD_ERROR_HANDLE)) != NULL && 573 if ((h=GetStdHandle(STD_ERROR_HANDLE)) != NULL &&
@@ -680,7 +578,6 @@ void OPENSSL_showfatal (const char *fmta,...)
680 va_end (ap); 578 va_end (ap);
681 return; 579 return;
682 } 580 }
683#endif
684 581
685 if (sizeof(TCHAR)==sizeof(char)) 582 if (sizeof(TCHAR)==sizeof(char))
686 fmt=(const TCHAR *)fmta; 583 fmt=(const TCHAR *)fmta;
@@ -726,7 +623,7 @@ void OPENSSL_showfatal (const char *fmta,...)
726 623
727#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333 624#if defined(_WIN32_WINNT) && _WIN32_WINNT>=0x0333
728 /* this -------------v--- guards NT-specific calls */ 625 /* this -------------v--- guards NT-specific calls */
729 if (GetVersion() < 0x80000000 && OPENSSL_isservice()) 626 if (GetVersion() < 0x80000000 && IsService())
730 { HANDLE h = RegisterEventSource(0,_T("OPENSSL")); 627 { HANDLE h = RegisterEventSource(0,_T("OPENSSL"));
731 const TCHAR *pmsg=buf; 628 const TCHAR *pmsg=buf;
732 ReportEvent(h,EVENTLOG_ERROR_TYPE,0,0,0,1,0,&pmsg,0); 629 ReportEvent(h,EVENTLOG_ERROR_TYPE,0,0,0,1,0,&pmsg,0);
@@ -734,7 +631,21 @@ void OPENSSL_showfatal (const char *fmta,...)
734 } 631 }
735 else 632 else
736#endif 633#endif
737 MessageBox (NULL,buf,_T("OpenSSL: FATAL"),MB_OK|MB_ICONSTOP); 634 { MSGBOXPARAMS m;
635
636 m.cbSize = sizeof(m);
637 m.hwndOwner = NULL;
638 m.lpszCaption = _T("OpenSSL: FATAL");
639 m.dwStyle = MB_OK;
640 m.hInstance = NULL;
641 m.lpszIcon = IDI_ERROR;
642 m.dwContextHelpId = 0;
643 m.lpfnMsgBoxCallback = NULL;
644 m.dwLanguageId = MAKELANGID(LANG_ENGLISH,SUBLANG_ENGLISH_US);
645 m.lpszText = buf;
646
647 MessageBoxIndirect (&m);
648 }
738} 649}
739#else 650#else
740void OPENSSL_showfatal (const char *fmta,...) 651void OPENSSL_showfatal (const char *fmta,...)
@@ -744,7 +655,6 @@ void OPENSSL_showfatal (const char *fmta,...)
744 vfprintf (stderr,fmta,ap); 655 vfprintf (stderr,fmta,ap);
745 va_end (ap); 656 va_end (ap);
746} 657}
747int OPENSSL_isservice (void) { return 0; }
748#endif 658#endif
749 659
750void OpenSSLDie(const char *file,int line,const char *assertion) 660void OpenSSLDie(const char *file,int line,const char *assertion)
@@ -756,3 +666,79 @@ void OpenSSLDie(const char *file,int line,const char *assertion)
756 } 666 }
757 667
758void *OPENSSL_stderr(void) { return stderr; } 668void *OPENSSL_stderr(void) { return stderr; }
669
670#ifdef OPENSSL_FIPS
671
672void fips_w_lock(void) { CRYPTO_w_lock(CRYPTO_LOCK_FIPS); }
673void fips_w_unlock(void) { CRYPTO_w_unlock(CRYPTO_LOCK_FIPS); }
674void fips_r_lock(void) { CRYPTO_r_lock(CRYPTO_LOCK_FIPS); }
675void fips_r_unlock(void) { CRYPTO_r_unlock(CRYPTO_LOCK_FIPS); }
676
677static int fips_started = 0;
678static unsigned long fips_thread = 0;
679
680void fips_set_started(void)
681 {
682 fips_started = 1;
683 }
684
685int fips_is_started(void)
686 {
687 return fips_started;
688 }
689
690int fips_is_owning_thread(void)
691 {
692 int ret = 0;
693
694 if (fips_is_started())
695 {
696 CRYPTO_r_lock(CRYPTO_LOCK_FIPS2);
697 if (fips_thread != 0 && fips_thread == CRYPTO_thread_id())
698 ret = 1;
699 CRYPTO_r_unlock(CRYPTO_LOCK_FIPS2);
700 }
701 return ret;
702 }
703
704int fips_set_owning_thread(void)
705 {
706 int ret = 0;
707
708 if (fips_is_started())
709 {
710 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
711 if (fips_thread == 0)
712 {
713 fips_thread = CRYPTO_thread_id();
714 ret = 1;
715 }
716 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
717 }
718 return ret;
719 }
720
721int fips_clear_owning_thread(void)
722 {
723 int ret = 0;
724
725 if (fips_is_started())
726 {
727 CRYPTO_w_lock(CRYPTO_LOCK_FIPS2);
728 if (fips_thread == CRYPTO_thread_id())
729 {
730 fips_thread = 0;
731 ret = 1;
732 }
733 CRYPTO_w_unlock(CRYPTO_LOCK_FIPS2);
734 }
735 return ret;
736 }
737
738unsigned char *fips_signature_witness(void)
739 {
740 extern unsigned char FIPS_signature[];
741 return FIPS_signature;
742 }
743#endif /* OPENSSL_FIPS */
744
diff --git a/src/lib/libcrypto/cryptlib.h b/src/lib/libcrypto/cryptlib.h
index 5ceaa964b5..6f59e08ca6 100644
--- a/src/lib/libcrypto/cryptlib.h
+++ b/src/lib/libcrypto/cryptlib.h
@@ -64,11 +64,6 @@
64 64
65#include "e_os.h" 65#include "e_os.h"
66 66
67#ifdef OPENSSL_USE_APPLINK
68#define BIO_FLAGS_UPLINK 0x8000
69#include "ms/uplink.h"
70#endif
71
72#include <openssl/crypto.h> 67#include <openssl/crypto.h>
73#include <openssl/buffer.h> 68#include <openssl/buffer.h>
74#include <openssl/bio.h> 69#include <openssl/bio.h>
@@ -98,12 +93,9 @@ extern "C" {
98#define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1) 93#define DECIMAL_SIZE(type) ((sizeof(type)*8+2)/3+1)
99#define HEX_SIZE(type) (sizeof(type)*2) 94#define HEX_SIZE(type) (sizeof(type)*2)
100 95
101void OPENSSL_cpuid_setup(void);
102extern unsigned long OPENSSL_ia32cap_P;
103void OPENSSL_showfatal(const char *,...); 96void OPENSSL_showfatal(const char *,...);
104void *OPENSSL_stderr(void); 97void *OPENSSL_stderr(void);
105extern int OPENSSL_NONPIC_relocated; 98extern int OPENSSL_NONPIC_relocated;
106int OPENSSL_isservice(void);
107 99
108#ifdef __cplusplus 100#ifdef __cplusplus
109} 101}
diff --git a/src/lib/libcrypto/crypto-lib.com b/src/lib/libcrypto/crypto-lib.com
new file mode 100644
index 0000000000..427c321f25
--- /dev/null
+++ b/src/lib/libcrypto/crypto-lib.com
@@ -0,0 +1,1299 @@
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 the following as P1 to build just that part or ALL to just
18$! build everything.
19$!
20$! LIBRARY To just compile the [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library.
21$! APPS To just compile the [.xxx.EXE.CRYPTO]*.EXE
22$! ALL To do both LIBRARY and APPS
23$!
24$! Specify DEBUG or NODEBUG as P2 to compile with or without debugger
25$! information.
26$!
27$! Specify which compiler at P3 to try to compile under.
28$!
29$! VAXC For VAX C.
30$! DECC For DEC C.
31$! GNUC For GNU C.
32$!
33$! If you don't speficy a compiler, it will try to determine which
34$! "C" compiler to use.
35$!
36$! P4, if defined, sets a TCP/IP library to use, through one of the following
37$! keywords:
38$!
39$! UCX for UCX
40$! TCPIP for TCPIP (post UCX)
41$! SOCKETSHR for SOCKETSHR+NETLIB
42$!
43$! P5, if defined, sets a compiler thread NOT needed on OpenVMS 7.1 (and up)
44$!
45$! P6, if defined, sets a choice of crypto methods to compile.
46$! WARNING: this should only be done to recompile some part of an already
47$! fully compiled library.
48$!
49$!
50$! Define A TCP/IP Library That We Will Need To Link To.
51$! (That Is, If We Need To Link To One.)
52$!
53$ TCPIP_LIB = ""
54$!
55$! Check Which Architecture We Are Using.
56$!
57$ IF (F$GETSYI("CPU").GE.128)
58$ THEN
59$!
60$! The Architecture Is AXP
61$!
62$ ARCH := AXP
63$!
64$! Else...
65$!
66$ ELSE
67$!
68$! The Architecture Is VAX.
69$!
70$ ARCH := VAX
71$!
72$! End The Architecture Check.
73$!
74$ ENDIF
75$!
76$! Define The Different Encryption Types.
77$!
78$ ENCRYPT_TYPES = "Basic,MD2,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,"+ -
79 "DES,RC2,RC4,RC5,IDEA,BF,CAST,"+ -
80 "BN,EC,RSA,DSA,DH,DSO,ENGINE,AES,"+ -
81 "BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,"+ -
82 "EVP,EVP_2,ASN1,ASN1_2,PEM,X509,X509V3,"+ -
83 "CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,UI,KRB5"
84$!
85$! Check To Make Sure We Have Valid Command Line Parameters.
86$!
87$ GOSUB CHECK_OPTIONS
88$!
89$! Initialise logical names and such
90$!
91$ GOSUB INITIALISE
92$!
93$! Tell The User What Kind of Machine We Run On.
94$!
95$ WRITE SYS$OUTPUT "Compiling On A ",ARCH," Machine."
96$!
97$! Define The OBJ Directory.
98$!
99$ OBJ_DIR := SYS$DISK:[-.'ARCH'.OBJ.CRYPTO]
100$!
101$! Check To See If The Architecture Specific OBJ Directory Exists.
102$!
103$ IF (F$PARSE(OBJ_DIR).EQS."")
104$ THEN
105$!
106$! It Dosen't Exist, So Create It.
107$!
108$ CREATE/DIR 'OBJ_DIR'
109$!
110$! End The Architecture Specific OBJ Directory Check.
111$!
112$ ENDIF
113$!
114$! Define The EXE Directory.
115$!
116$ EXE_DIR := SYS$DISK:[-.'ARCH'.EXE.CRYPTO]
117$!
118$! Check To See If The Architecture Specific Directory Exists.
119$!
120$ IF (F$PARSE(EXE_DIR).EQS."")
121$ THEN
122$!
123$! It Dosen't Exist, So Create It.
124$!
125$ CREATE/DIRECTORY 'EXE_DIR'
126$!
127$! End The Architecture Specific Directory Check.
128$!
129$ ENDIF
130$!
131$! Define The Library Name.
132$!
133$ LIB_NAME := 'EXE_DIR'LIBCRYPTO.OLB
134$!
135$! Define The CRYPTO-LIB We Are To Use.
136$!
137$ CRYPTO_LIB := '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$! Build our options file for the application
153$!
154$ GOSUB CHECK_OPT_FILE
155$!
156$! Define The Different Encryption "library" Strings.
157$!
158$ APPS_DES = "DES/DES,CBC3_ENC"
159$ APPS_PKCS7 = "ENC/ENC;DEC/DEC;SIGN/SIGN;VERIFY/VERIFY,EXAMPLE"
160$
161$ LIB_ = "cryptlib,mem,mem_clr,mem_dbg,cversion,ex_data,tmdiff,cpt_err,ebcdic,uid,o_time,o_str"
162$ LIB_MD2 = "md2_dgst,md2_one"
163$ LIB_MD4 = "md4_dgst,md4_one"
164$ LIB_MD5 = "md5_dgst,md5_one"
165$ LIB_SHA = "sha_dgst,sha1dgst,sha_one,sha1_one"
166$ LIB_MDC2 = "mdc2dgst,mdc2_one"
167$ LIB_HMAC = "hmac"
168$ LIB_RIPEMD = "rmd_dgst,rmd_one"
169$ LIB_DES = "set_key,ecb_enc,cbc_enc,"+ -
170 "ecb3_enc,cfb64enc,cfb64ede,cfb_enc,ofb64ede,"+ -
171 "enc_read,enc_writ,ofb64enc,"+ -
172 "ofb_enc,str2key,pcbc_enc,qud_cksm,rand_key,"+ -
173 "des_enc,fcrypt_b,"+ -
174 "fcrypt,xcbc_enc,rpc_enc,cbc_cksm,"+ -
175 "ede_cbcm_enc,des_old,des_old2,read2pwd"
176$ LIB_RC2 = "rc2_ecb,rc2_skey,rc2_cbc,rc2cfb64,rc2ofb64"
177$ LIB_RC4 = "rc4_skey,rc4_enc"
178$ LIB_RC5 = "rc5_skey,rc5_ecb,rc5_enc,rc5cfb64,rc5ofb64"
179$ LIB_IDEA = "i_cbc,i_cfb64,i_ofb64,i_ecb,i_skey"
180$ LIB_BF = "bf_skey,bf_ecb,bf_enc,bf_cfb64,bf_ofb64"
181$ LIB_CAST = "c_skey,c_ecb,c_enc,c_cfb64,c_ofb64"
182$ LIB_BN_ASM = "[.asm]vms.mar,vms-helper"
183$ IF F$TRNLNM("OPENSSL_NO_ASM").OR.ARCH.EQS."AXP" THEN LIB_BN_ASM = "bn_asm"
184$ LIB_BN = "bn_add,bn_div,bn_exp,bn_lib,bn_ctx,bn_mul,bn_mod,"+ -
185 "bn_print,bn_rand,bn_shift,bn_word,bn_blind,"+ -
186 "bn_kron,bn_sqrt,bn_gcd,bn_prime,bn_err,bn_sqr,"+LIB_BN_ASM+","+ -
187 "bn_recp,bn_mont,bn_mpi,bn_exp2,bn_x931p"
188$ LIB_RSA = "rsa_eay,rsa_gen,rsa_lib,rsa_sign,rsa_saos,rsa_err,"+ -
189 "rsa_pk1,rsa_ssl,rsa_none,rsa_oaep,rsa_chk,rsa_null,"+ -
190 "rsa_pss,rsa_x931,rsa_asn1"
191$ LIB_EC = "ec_lib,ecp_smpl,ecp_mont,ecp_recp,ecp_nist,ec_cvt,ec_mult,"+ -
192 "ec_err"
193$ LIB_DSA = "dsa_gen,dsa_key,dsa_lib,dsa_asn1,dsa_vrf,dsa_sign,dsa_err,dsa_ossl"
194$ LIB_DH = "dh_asn1,dh_gen,dh_key,dh_lib,dh_check,dh_err"
195$ LIB_DSO = "dso_dl,dso_dlfcn,dso_err,dso_lib,dso_null,"+ -
196 "dso_openssl,dso_win32,dso_vms"
197$ LIB_ENGINE = "eng_err,eng_lib,eng_list,eng_init,eng_ctrl,"+ -
198 "eng_table,eng_pkey,eng_fat,eng_all,"+ -
199 "tb_rsa,tb_dsa,tb_dh,tb_rand,tb_cipher,tb_digest,"+ -
200 "eng_openssl,eng_dyn,eng_cnf,"+ -
201 "hw_atalla,hw_cswift,hw_ncipher,hw_nuron,hw_ubsec,"+ -
202 "hw_cryptodev,hw_aep,hw_sureware,hw_4758_cca"
203$ LIB_AES = "aes_core,aes_misc,aes_ecb,aes_cbc,aes_cfb,aes_ofb,aes_ctr"
204$ LIB_BUFFER = "buffer,buf_err"
205$ LIB_BIO = "bio_lib,bio_cb,bio_err,"+ -
206 "bss_mem,bss_null,bss_fd,"+ -
207 "bss_file,bss_sock,bss_conn,"+ -
208 "bf_null,bf_buff,b_print,b_dump,"+ -
209 "b_sock,bss_acpt,bf_nbio,bss_rtcp,bss_bio,bss_log,"+ -
210 "bf_lbuf"
211$ LIB_STACK = "stack"
212$ LIB_LHASH = "lhash,lh_stats"
213$ LIB_RAND = "md_rand,randfile,rand_lib,rand_err,rand_egd,"+ -
214 "rand_vms"
215$ LIB_ERR = "err,err_all,err_prn"
216$ LIB_OBJECTS = "o_names,obj_dat,obj_lib,obj_err"
217$ LIB_EVP = "encode,digest,evp_enc,evp_key,evp_acnf,"+ -
218 "e_des,e_bf,e_idea,e_des3,"+ -
219 "e_rc4,e_aes,names,"+ -
220 "e_xcbc_d,e_rc2,e_cast,e_rc5"
221$ LIB_EVP_2 = "m_null,m_md2,m_md4,m_md5,m_sha,m_sha1," + -
222 "m_dss,m_dss1,m_mdc2,m_ripemd,"+ -
223 "p_open,p_seal,p_sign,p_verify,p_lib,p_enc,p_dec,"+ -
224 "bio_md,bio_b64,bio_enc,evp_err,e_null,"+ -
225 "c_all,c_allc,c_alld,evp_lib,bio_ok,"+-
226 "evp_pkey,evp_pbe,p5_crpt,p5_crpt2"
227$ LIB_ASN1 = "a_object,a_bitstr,a_utctm,a_gentm,a_time,a_int,a_octet,"+ -
228 "a_print,a_type,a_set,a_dup,a_d2i_fp,a_i2d_fp,"+ -
229 "a_enum,a_utf8,a_sign,a_digest,a_verify,a_mbstr,a_strex,"+ -
230 "x_algor,x_val,x_pubkey,x_sig,x_req,x_attrib,x_bignum,"+ -
231 "x_long,x_name,x_x509,x_x509a,x_crl,x_info,x_spki,nsseq,"+ -
232 "d2i_pu,d2i_pr,i2d_pu,i2d_pr"
233$ LIB_ASN1_2 = "t_req,t_x509,t_x509a,t_crl,t_pkey,t_spki,t_bitst,"+ -
234 "tasn_new,tasn_fre,tasn_enc,tasn_dec,tasn_utl,tasn_typ,"+ -
235 "f_int,f_string,n_pkey,"+ -
236 "f_enum,a_hdr,x_pkey,a_bool,x_exten,"+ -
237 "asn1_par,asn1_lib,asn1_err,a_meth,a_bytes,a_strnid,"+ -
238 "evp_asn1,asn_pack,p5_pbe,p5_pbev2,p8_pkey,asn_moid"
239$ LIB_PEM = "pem_sign,pem_seal,pem_info,pem_lib,pem_all,pem_err,"+ -
240 "pem_x509,pem_xaux,pem_oth,pem_pk8,pem_pkey"
241$ LIB_X509 = "x509_def,x509_d2,x509_r2x,x509_cmp,"+ -
242 "x509_obj,x509_req,x509spki,x509_vfy,"+ -
243 "x509_set,x509cset,x509rset,x509_err,"+ -
244 "x509name,x509_v3,x509_ext,x509_att,"+ -
245 "x509type,x509_lu,x_all,x509_txt,"+ -
246 "x509_trs,by_file,by_dir"
247$ LIB_X509V3 = "v3_bcons,v3_bitst,v3_conf,v3_extku,v3_ia5,v3_lib,"+ -
248 "v3_prn,v3_utl,v3err,v3_genn,v3_alt,v3_skey,v3_akey,v3_pku,"+ -
249 "v3_int,v3_enum,v3_sxnet,v3_cpols,v3_crld,v3_purp,v3_info,"+ -
250 "v3_ocsp,v3_akeya,v3_pcia,v3_pci"
251$ LIB_CONF = "conf_err,conf_lib,conf_api,conf_def,conf_mod,conf_mall,conf_sap"
252$ LIB_TXT_DB = "txt_db"
253$ LIB_PKCS7 = "pk7_asn1,pk7_lib,pkcs7err,pk7_doit,pk7_smime,pk7_attr,"+ -
254 "pk7_mime"
255$ LIB_PKCS12 = "p12_add,p12_asn,p12_attr,p12_crpt,p12_crt,p12_decr,"+ -
256 "p12_init,p12_key,p12_kiss,p12_mutl,"+ -
257 "p12_utl,p12_npas,pk12err,p12_p8d,p12_p8e"
258$ LIB_COMP = "comp_lib,comp_err,"+ -
259 "c_rle,c_zlib"
260$ LIB_OCSP = "ocsp_asn,ocsp_ext,ocsp_ht,ocsp_lib,ocsp_cl,"+ -
261 "ocsp_srv,ocsp_prn,ocsp_vfy,ocsp_err"
262$ LIB_UI_COMPAT = ",ui_compat"
263$ LIB_UI = "ui_err,ui_lib,ui_openssl,ui_util"+LIB_UI_COMPAT
264$ LIB_KRB5 = "krb5_asn"
265$!
266$! Setup exceptional compilations
267$!
268$ ! Add definitions for no threads on OpenVMS 7.1 and higher
269$ COMPILEWITH_CC3 = ",bss_rtcp,"
270$ ! Disable the DOLLARID warning
271$ COMPILEWITH_CC4 = ",a_utctm,bss_log,o_time,"
272$ ! Disable disjoint optimization
273$ COMPILEWITH_CC5 = ",md2_dgst,md4_dgst,md5_dgst,mdc2dgst," + -
274 "sha_dgst,sha1dgst,rmd_dgst,bf_enc,"
275$ ! Disable the MIXLINKAGE warning
276$ COMPILEWITH_CC6 = ",enc_read,set_key,"
277$!
278$! Figure Out What Other Modules We Are To Build.
279$!
280$ BUILD_SET:
281$!
282$! Define A Module Counter.
283$!
284$ MODULE_COUNTER = 0
285$!
286$! Top Of The Loop.
287$!
288$ MODULE_NEXT:
289$!
290$! Extract The Module Name From The Encryption List.
291$!
292$ MODULE_NAME = F$ELEMENT(MODULE_COUNTER,",",ENCRYPT_TYPES)
293$ IF MODULE_NAME.EQS."Basic" THEN MODULE_NAME = ""
294$ MODULE_NAME1 = MODULE_NAME
295$!
296$! Check To See If We Are At The End Of The Module List.
297$!
298$ IF (MODULE_NAME.EQS.",")
299$ THEN
300$!
301$! We Are At The End Of The Module List, Go To MODULE_DONE.
302$!
303$ GOTO MODULE_DONE
304$!
305$! End The Module List Check.
306$!
307$ ENDIF
308$!
309$! Increment The Moudle Counter.
310$!
311$ MODULE_COUNTER = MODULE_COUNTER + 1
312$!
313$! Create The Library and Apps Module Names.
314$!
315$ LIB_MODULE = "LIB_" + MODULE_NAME
316$ APPS_MODULE = "APPS_" + MODULE_NAME
317$ IF (MODULE_NAME.EQS."ASN1_2")
318$ THEN
319$ MODULE_NAME = "ASN1"
320$ ENDIF
321$ IF (MODULE_NAME.EQS."EVP_2")
322$ THEN
323$ MODULE_NAME = "EVP"
324$ ENDIF
325$!
326$! Set state (can be LIB and APPS)
327$!
328$ STATE = "LIB"
329$ IF BUILDALL .EQS. "APPS" THEN STATE = "APPS"
330$!
331$! Check if the library module name actually is defined
332$!
333$ IF F$TYPE('LIB_MODULE') .EQS. ""
334$ THEN
335$ WRITE SYS$ERROR ""
336$ WRITE SYS$ERROR "The module ",MODULE_NAME," does not exist. Continuing..."
337$ WRITE SYS$ERROR ""
338$ GOTO MODULE_NEXT
339$ ENDIF
340$!
341$! Top Of The Module Loop.
342$!
343$ MODULE_AGAIN:
344$!
345$! Tell The User What Module We Are Building.
346$!
347$ IF (MODULE_NAME1.NES."")
348$ THEN
349$ IF STATE .EQS. "LIB"
350$ THEN
351$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Library Files. (",BUILDALL,",",STATE,")"
352$ ELSE IF F$TYPE('APPS_MODULE') .NES. ""
353$ THEN
354$ WRITE SYS$OUTPUT "Compiling The ",MODULE_NAME1," Applications. (",BUILDALL,",",STATE,")"
355$ ENDIF
356$ ENDIF
357$ ENDIF
358$!
359$! Define A File Counter And Set It To "0".
360$!
361$ FILE_COUNTER = 0
362$ APPLICATION = ""
363$ APPLICATION_COUNTER = 0
364$!
365$! Top Of The File Loop.
366$!
367$ NEXT_FILE:
368$!
369$! Look in the LIB_MODULE is we're in state LIB
370$!
371$ IF STATE .EQS. "LIB"
372$ THEN
373$!
374$! O.K, Extract The File Name From The File List.
375$!
376$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",'LIB_MODULE')
377$!
378$! else
379$!
380$ ELSE
381$ FILE_NAME = ","
382$!
383$ IF F$TYPE('APPS_MODULE') .NES. ""
384$ THEN
385$!
386$! Extract The File Name From The File List.
387$! This part is a bit more complicated.
388$!
389$ IF APPLICATION .EQS. ""
390$ THEN
391$ APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
392$ APPLICATION_COUNTER = APPLICATION_COUNTER + 1
393$ APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
394$ APPLICATION = F$ELEMENT(0,"/",APPLICATION)
395$ FILE_COUNTER = 0
396$ ENDIF
397$
398$! WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
399$! SHOW SYMBOL APPLICATION*
400$!
401$ IF APPLICATION .NES. ";"
402$ THEN
403$ FILE_NAME = F$ELEMENT(FILE_COUNTER,",",APPLICATION_OBJECTS)
404$ IF FILE_NAME .EQS. ","
405$ THEN
406$ APPLICATION = ""
407$ GOTO NEXT_FILE
408$ ENDIF
409$ ENDIF
410$ ENDIF
411$ ENDIF
412$!
413$! Check To See If We Are At The End Of The File List.
414$!
415$ IF (FILE_NAME.EQS.",")
416$ THEN
417$!
418$! We Are At The End Of The File List, Change State Or Goto FILE_DONE.
419$!
420$ IF STATE .EQS. "LIB" .AND. BUILDALL .NES. "LIBRARY"
421$ THEN
422$ STATE = "APPS"
423$ GOTO MODULE_AGAIN
424$ ELSE
425$ GOTO FILE_DONE
426$ ENDIF
427$!
428$! End The File List Check.
429$!
430$ ENDIF
431$!
432$! Increment The Counter.
433$!
434$ FILE_COUNTER = FILE_COUNTER + 1
435$!
436$! Create The Source File Name.
437$!
438$ TMP_FILE_NAME = F$ELEMENT(1,"]",FILE_NAME)
439$ IF TMP_FILE_NAME .EQS. "]" THEN TMP_FILE_NAME = FILE_NAME
440$ IF F$ELEMENT(0,".",TMP_FILE_NAME) .EQS. TMP_FILE_NAME THEN -
441 FILE_NAME = FILE_NAME + ".c"
442$ IF (MODULE_NAME.NES."")
443$ THEN
444$ SOURCE_FILE = "SYS$DISK:[." + MODULE_NAME+ "]" + FILE_NAME
445$ ELSE
446$ SOURCE_FILE = "SYS$DISK:[]" + FILE_NAME
447$ ENDIF
448$ SOURCE_FILE = SOURCE_FILE - "]["
449$!
450$! Create The Object File Name.
451$!
452$ OBJECT_FILE = OBJ_DIR + F$PARSE(FILE_NAME,,,"NAME","SYNTAX_ONLY") + ".OBJ"
453$ ON WARNING THEN GOTO NEXT_FILE
454$!
455$! Check To See If The File We Want To Compile Is Actually There.
456$!
457$ IF (F$SEARCH(SOURCE_FILE).EQS."")
458$ THEN
459$!
460$! Tell The User That The File Doesn't Exist.
461$!
462$ WRITE SYS$OUTPUT ""
463$ WRITE SYS$OUTPUT "The File ",SOURCE_FILE," Doesn't Exist."
464$ WRITE SYS$OUTPUT ""
465$!
466$! Exit The Build.
467$!
468$ GOTO EXIT
469$!
470$! End The File Exist Check.
471$!
472$ ENDIF
473$!
474$! Tell The User We Are Compiling The File.
475$!
476$ IF (MODULE_NAME.EQS."")
477$ THEN
478$ WRITE SYS$OUTPUT "Compiling The ",FILE_NAME," File. (",BUILDALL,",",STATE,")"
479$ ENDIF
480$ IF (MODULE_NAME.NES."")
481$ THEN
482$ WRITE SYS$OUTPUT " ",FILE_NAME,""
483$ ENDIF
484$!
485$! Compile The File.
486$!
487$ ON ERROR THEN GOTO NEXT_FILE
488$ FILE_NAME0 = F$ELEMENT(0,".",FILE_NAME)
489$ IF FILE_NAME - ".mar" .NES. FILE_NAME
490$ THEN
491$ MACRO/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
492$ ELSE
493$ IF COMPILEWITH_CC3 - FILE_NAME0 .NES. COMPILEWITH_CC3
494$ THEN
495$ CC3/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
496$ ELSE
497$ IF COMPILEWITH_CC4 - FILE_NAME0 .NES. COMPILEWITH_CC4
498$ THEN
499$ CC4/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
500$ ELSE
501$ IF COMPILEWITH_CC5 - FILE_NAME0 .NES. COMPILEWITH_CC5
502$ THEN
503$ CC5/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
504$ ELSE
505$ IF COMPILEWITH_CC6 - FILE_NAME0 .NES. COMPILEWITH_CC6
506$ THEN
507$ CC6/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
508$ ELSE
509$ CC/OBJECT='OBJECT_FILE' 'SOURCE_FILE'
510$ ENDIF
511$ ENDIF
512$ ENDIF
513$ ENDIF
514$ ENDIF
515$ IF STATE .EQS. "LIB"
516$ THEN
517$!
518$! Add It To The Library.
519$!
520$ LIBRARY/REPLACE 'LIB_NAME' 'OBJECT_FILE'
521$!
522$! Time To Clean Up The Object File.
523$!
524$ DELETE 'OBJECT_FILE';*
525$ ENDIF
526$!
527$! Go Back And Do It Again.
528$!
529$ GOTO NEXT_FILE
530$!
531$! All Done With This Library Part.
532$!
533$ FILE_DONE:
534$!
535$! Time To Build Some Applications
536$!
537$ IF F$TYPE('APPS_MODULE') .NES. "" .AND. BUILDALL .NES. "LIBRARY"
538$ THEN
539$ APPLICATION_COUNTER = 0
540$ NEXT_APPLICATION:
541$ APPLICATION = F$ELEMENT(APPLICATION_COUNTER,";",'APPS_MODULE')
542$ IF APPLICATION .EQS. ";" THEN GOTO APPLICATION_DONE
543$
544$ APPLICATION_COUNTER = APPLICATION_COUNTER + 1
545$ APPLICATION_OBJECTS = F$ELEMENT(1,"/",APPLICATION)
546$ APPLICATION = F$ELEMENT(0,"/",APPLICATION)
547$
548$! WRITE SYS$OUTPUT "DEBUG: SHOW SYMBOL APPLICATION*"
549$! SHOW SYMBOL APPLICATION*
550$!
551$! Tell the user what happens
552$!
553$ WRITE SYS$OUTPUT " ",APPLICATION,".exe"
554$!
555$! Link The Program.
556$!
557$ ON ERROR THEN GOTO NEXT_APPLICATION
558$!
559$! Check To See If We Are To Link With A Specific TCP/IP Library.
560$!
561$ IF (TCPIP_LIB.NES."")
562$ THEN
563$!
564$! Link With A TCP/IP Library.
565$!
566$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
567 'OBJ_DIR''APPLICATION_OBJECTS', -
568 'CRYPTO_LIB'/LIBRARY, -
569 'TCPIP_LIB','OPT_FILE'/OPTION
570$!
571$! Else...
572$!
573$ ELSE
574$!
575$! Don't Link With A TCP/IP Library.
576$!
577$ LINK/'DEBUGGER'/'TRACEBACK'/EXE='EXE_DIR''APPLICATION'.EXE -
578 'OBJ_DIR''APPLICATION_OBJECTS',-
579 'CRYPTO_LIB'/LIBRARY, -
580 'OPT_FILE'/OPTION
581$!
582$! End The TCP/IP Library Check.
583$!
584$ ENDIF
585$ GOTO NEXT_APPLICATION
586$ APPLICATION_DONE:
587$ ENDIF
588$!
589$! Go Back And Get The Next Module.
590$!
591$ GOTO MODULE_NEXT
592$!
593$! All Done With This Module.
594$!
595$ MODULE_DONE:
596$!
597$! Tell The User That We Are All Done.
598$!
599$ WRITE SYS$OUTPUT "All Done..."
600$ EXIT:
601$ GOSUB CLEANUP
602$ EXIT
603$!
604$! Check For The Link Option FIle.
605$!
606$ CHECK_OPT_FILE:
607$!
608$! Check To See If We Need To Make A VAX C Option File.
609$!
610$ IF (COMPILER.EQS."VAXC")
611$ THEN
612$!
613$! Check To See If We Already Have A VAX C Linker Option File.
614$!
615$ IF (F$SEARCH(OPT_FILE).EQS."")
616$ THEN
617$!
618$! We Need A VAX C Linker Option File.
619$!
620$ CREATE 'OPT_FILE'
621$DECK
622!
623! Default System Options File To Link Agianst
624! The Sharable VAX C Runtime Library.
625!
626SYS$SHARE:VAXCRTL.EXE/SHARE
627$EOD
628$!
629$! End The Option File Check.
630$!
631$ ENDIF
632$!
633$! End The VAXC Check.
634$!
635$ ENDIF
636$!
637$! Check To See If We Need A GNU C Option File.
638$!
639$ IF (COMPILER.EQS."GNUC")
640$ THEN
641$!
642$! Check To See If We Already Have A GNU C Linker Option File.
643$!
644$ IF (F$SEARCH(OPT_FILE).EQS."")
645$ THEN
646$!
647$! We Need A GNU C Linker Option File.
648$!
649$ CREATE 'OPT_FILE'
650$DECK
651!
652! Default System Options File To Link Agianst
653! The Sharable C Runtime Library.
654!
655GNU_CC:[000000]GCCLIB/LIBRARY
656SYS$SHARE:VAXCRTL/SHARE
657$EOD
658$!
659$! End The Option File Check.
660$!
661$ ENDIF
662$!
663$! End The GNU C Check.
664$!
665$ ENDIF
666$!
667$! Check To See If We Need A DEC C Option File.
668$!
669$ IF (COMPILER.EQS."DECC")
670$ THEN
671$!
672$! Check To See If We Already Have A DEC C Linker Option File.
673$!
674$ IF (F$SEARCH(OPT_FILE).EQS."")
675$ THEN
676$!
677$! Figure Out If We Need An AXP Or A VAX Linker Option File.
678$!
679$ IF ARCH .EQS. "VAX"
680$ THEN
681$!
682$! We Need A DEC C Linker Option File For VAX.
683$!
684$ CREATE 'OPT_FILE'
685$DECK
686!
687! Default System Options File To Link Agianst
688! The Sharable DEC C Runtime Library.
689!
690SYS$SHARE:DECC$SHR.EXE/SHARE
691$EOD
692$!
693$! Else...
694$!
695$ ELSE
696$!
697$! Create The AXP Linker Option File.
698$!
699$ CREATE 'OPT_FILE'
700$DECK
701!
702! Default System Options File For AXP To Link Agianst
703! The Sharable C Runtime Library.
704!
705SYS$SHARE:CMA$OPEN_LIB_SHR/SHARE
706SYS$SHARE:CMA$OPEN_RTL/SHARE
707$EOD
708$!
709$! End The VAX/AXP DEC C Option File Check.
710$!
711$ ENDIF
712$!
713$! End The Option File Search.
714$!
715$ ENDIF
716$!
717$! End The DEC C Check.
718$!
719$ ENDIF
720$!
721$! Tell The User What Linker Option File We Are Using.
722$!
723$ WRITE SYS$OUTPUT "Using Linker Option File ",OPT_FILE,"."
724$!
725$! Time To RETURN.
726$!
727$ RETURN
728$!
729$! Check The User's Options.
730$!
731$ CHECK_OPTIONS:
732$!
733$! Check To See If P1 Is Blank.
734$!
735$ IF (P1.EQS."ALL")
736$ THEN
737$!
738$! P1 Is Blank, So Build Everything.
739$!
740$ BUILDALL = "TRUE"
741$!
742$! Else...
743$!
744$ ELSE
745$!
746$! Else, Check To See If P1 Has A Valid Arguement.
747$!
748$ IF (P1.EQS."LIBRARY").OR.(P1.EQS."APPS")
749$ THEN
750$!
751$! A Valid Arguement.
752$!
753$ BUILDALL = P1
754$!
755$! Else...
756$!
757$ ELSE
758$!
759$! Tell The User We Don't Know What They Want.
760$!
761$ WRITE SYS$OUTPUT ""
762$ WRITE SYS$OUTPUT "The Option ",P1," Is Invalid. The Valid Options Are:"
763$ WRITE SYS$OUTPUT ""
764$ WRITE SYS$OUTPUT " ALL : Just Build Everything."
765$ WRITE SYS$OUTPUT " LIBRARY : To Compile Just The [.xxx.EXE.CRYPTO]LIBCRYPTO.OLB Library."
766$ WRITE SYS$OUTPUT " APPS : To Compile Just The [.xxx.EXE.CRYPTO]*.EXE Programs."
767$ WRITE SYS$OUTPUT ""
768$ WRITE SYS$OUTPUT " Where 'xxx' Stands For:"
769$ WRITE SYS$OUTPUT ""
770$ WRITE SYS$OUTPUT " AXP : Alpha Architecture."
771$ WRITE SYS$OUTPUT " VAX : VAX Architecture."
772$ WRITE SYS$OUTPUT ""
773$!
774$! Time To EXIT.
775$!
776$ EXIT
777$!
778$! End The Valid Arguement Check.
779$!
780$ ENDIF
781$!
782$! End The P1 Check.
783$!
784$ ENDIF
785$!
786$! Check To See If P2 Is Blank.
787$!
788$ IF (P2.EQS."NODEBUG")
789$ THEN
790$!
791$! P2 Is NODEBUG, So Compile Without The Debugger Information.
792$!
793$ DEBUGGER = "NODEBUG"
794$ TRACEBACK = "NOTRACEBACK"
795$ GCC_OPTIMIZE = "OPTIMIZE"
796$ CC_OPTIMIZE = "OPTIMIZE"
797$ MACRO_OPTIMIZE = "OPTIMIZE"
798$ WRITE SYS$OUTPUT "No Debugger Information Will Be Produced During Compile."
799$ WRITE SYS$OUTPUT "Compiling With Compiler Optimization."
800$ ELSE
801$!
802$! Check To See If We Are To Compile With Debugger Information.
803$!
804$ IF (P2.EQS."DEBUG")
805$ THEN
806$!
807$! Compile With Debugger Information.
808$!
809$ DEBUGGER = "DEBUG"
810$ TRACEBACK = "TRACEBACK"
811$ GCC_OPTIMIZE = "NOOPTIMIZE"
812$ CC_OPTIMIZE = "NOOPTIMIZE"
813$ MACRO_OPTIMIZE = "NOOPTIMIZE"
814$ WRITE SYS$OUTPUT "Debugger Information Will Be Produced During Compile."
815$ WRITE SYS$OUTPUT "Compiling Without Compiler Optimization."
816$ ELSE
817$!
818$! They Entered An Invalid Option..
819$!
820$ WRITE SYS$OUTPUT ""
821$ WRITE SYS$OUTPUT "The Option ",P2," Is Invalid. The Valid Options Are:"
822$ WRITE SYS$OUTPUT ""
823$ WRITE SYS$OUTPUT " DEBUG : Compile With The Debugger Information."
824$ WRITE SYS$OUTPUT " NODEBUG : Compile Without The Debugger Information."
825$ WRITE SYS$OUTPUT ""
826$!
827$! Time To EXIT.
828$!
829$ EXIT
830$!
831$! End The Valid Arguement Check.
832$!
833$ ENDIF
834$!
835$! End The P2 Check.
836$!
837$ ENDIF
838$!
839$! Special Threads For OpenVMS v7.1 Or Later
840$!
841$! Written By: Richard Levitte
842$! richard@levitte.org
843$!
844$!
845$! Check To See If We Have A Option For P5.
846$!
847$ IF (P5.EQS."")
848$ THEN
849$!
850$! Get The Version Of VMS We Are Using.
851$!
852$ ISSEVEN :=
853$ TMP = F$ELEMENT(0,"-",F$EXTRACT(1,4,F$GETSYI("VERSION")))
854$ TMP = F$INTEGER(F$ELEMENT(0,".",TMP)+F$ELEMENT(1,".",TMP))
855$!
856$! Check To See If The VMS Version Is v7.1 Or Later.
857$!
858$ IF (TMP.GE.71)
859$ THEN
860$!
861$! We Have OpenVMS v7.1 Or Later, So Use The Special Threads.
862$!
863$ ISSEVEN := ,PTHREAD_USE_D4
864$!
865$! End The VMS Version Check.
866$!
867$ ENDIF
868$!
869$! End The P5 Check.
870$!
871$ ENDIF
872$!
873$! Check To See If P3 Is Blank.
874$!
875$ IF (P3.EQS."")
876$ THEN
877$!
878$! O.K., The User Didn't Specify A Compiler, Let's Try To
879$! Find Out Which One To Use.
880$!
881$! Check To See If We Have GNU C.
882$!
883$ IF (F$TRNLNM("GNU_CC").NES."")
884$ THEN
885$!
886$! Looks Like GNUC, Set To Use GNUC.
887$!
888$ P3 = "GNUC"
889$!
890$! Else...
891$!
892$ ELSE
893$!
894$! Check To See If We Have VAXC Or DECC.
895$!
896$ IF (ARCH.EQS."AXP").OR.(F$TRNLNM("DECC$CC_DEFAULT").NES."")
897$ THEN
898$!
899$! Looks Like DECC, Set To Use DECC.
900$!
901$ P3 = "DECC"
902$!
903$! Else...
904$!
905$ ELSE
906$!
907$! Looks Like VAXC, Set To Use VAXC.
908$!
909$ P3 = "VAXC"
910$!
911$! End The VAXC Compiler Check.
912$!
913$ ENDIF
914$!
915$! End The DECC & VAXC Compiler Check.
916$!
917$ ENDIF
918$!
919$! End The Compiler Check.
920$!
921$ ENDIF
922$!
923$! Check To See If We Have A Option For P4.
924$!
925$ IF (P4.EQS."")
926$ THEN
927$!
928$! Find out what socket library we have available
929$!
930$ IF F$PARSE("SOCKETSHR:") .NES. ""
931$ THEN
932$!
933$! We have SOCKETSHR, and it is my opinion that it's the best to use.
934$!
935$ P4 = "SOCKETSHR"
936$!
937$! Tell the user
938$!
939$ WRITE SYS$OUTPUT "Using SOCKETSHR for TCP/IP"
940$!
941$! Else, let's look for something else
942$!
943$ ELSE
944$!
945$! Like UCX (the reason to do this before Multinet is that the UCX
946$! emulation is easier to use...)
947$!
948$ IF F$TRNLNM("UCX$IPC_SHR") .NES. "" -
949 .OR. F$PARSE("SYS$SHARE:UCX$IPC_SHR.EXE") .NES. "" -
950 .OR. F$PARSE("SYS$LIBRARY:UCX$IPC.OLB") .NES. ""
951$ THEN
952$!
953$! Last resort: a UCX or UCX-compatible library
954$!
955$ P4 = "UCX"
956$!
957$! Tell the user
958$!
959$ WRITE SYS$OUTPUT "Using UCX or an emulation thereof for TCP/IP"
960$!
961$! That was all...
962$!
963$ ENDIF
964$ ENDIF
965$ ENDIF
966$!
967$! Set Up Initial CC Definitions, Possibly With User Ones
968$!
969$ CCDEFS = "TCPIP_TYPE_''P4',DSO_VMS"
970$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN CCDEFS = CCDEFS + "," + USER_CCDEFS
971$ CCEXTRAFLAGS = ""
972$ IF F$TYPE(USER_CCFLAGS) .NES. "" THEN CCEXTRAFLAGS = USER_CCFLAGS
973$ CCDISABLEWARNINGS = "LONGLONGTYPE,LONGLONGSUFX,FOUNDCR"
974$ IF F$TYPE(USER_CCDISABLEWARNINGS) .NES. "" THEN -
975 CCDISABLEWARNINGS = CCDISABLEWARNINGS + "," + USER_CCDISABLEWARNINGS
976$!
977$! Check To See If The User Entered A Valid Paramter.
978$!
979$ IF (P3.EQS."VAXC").OR.(P3.EQS."DECC").OR.(P3.EQS."GNUC")
980$ THEN
981$!
982$! Check To See If The User Wanted DECC.
983$!
984$ IF (P3.EQS."DECC")
985$ THEN
986$!
987$! Looks Like DECC, Set To Use DECC.
988$!
989$ COMPILER = "DECC"
990$!
991$! Tell The User We Are Using DECC.
992$!
993$ WRITE SYS$OUTPUT "Using DECC 'C' Compiler."
994$!
995$! Use DECC...
996$!
997$ CC = "CC"
998$ IF ARCH.EQS."VAX" .AND. F$TRNLNM("DECC$CC_DEFAULT").NES."/DECC" -
999 THEN CC = "CC/DECC"
1000$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/STANDARD=ANSI89" + -
1001 "/NOLIST/PREFIX=ALL" + -
1002 "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS],SYS$DISK:[.EVP])" + -
1003 CCEXTRAFLAGS
1004$!
1005$! Define The Linker Options File Name.
1006$!
1007$ OPT_FILE = "SYS$DISK:[]VAX_DECC_OPTIONS.OPT"
1008$!
1009$! End DECC Check.
1010$!
1011$ ENDIF
1012$!
1013$! Check To See If We Are To Use VAXC.
1014$!
1015$ IF (P3.EQS."VAXC")
1016$ THEN
1017$!
1018$! Looks Like VAXC, Set To Use VAXC.
1019$!
1020$ COMPILER = "VAXC"
1021$!
1022$! Tell The User We Are Using VAX C.
1023$!
1024$ WRITE SYS$OUTPUT "Using VAXC 'C' Compiler."
1025$!
1026$! Compile Using VAXC.
1027$!
1028$ CC = "CC"
1029$ IF ARCH.EQS."AXP"
1030$ THEN
1031$ WRITE SYS$OUTPUT "There is no VAX C on Alpha!"
1032$ EXIT
1033$ ENDIF
1034$ IF F$TRNLNM("DECC$CC_DEFAULT").EQS."/DECC" THEN CC = "CC/VAXC"
1035$ CC = CC + "/''CC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
1036 "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
1037 CCEXTRAFLAGS
1038$ CCDEFS = """VAXC""," + CCDEFS
1039$!
1040$! Define <sys> As SYS$COMMON:[SYSLIB]
1041$!
1042$ DEFINE/NOLOG SYS SYS$COMMON:[SYSLIB]
1043$!
1044$! Define The Linker Options File Name.
1045$!
1046$ OPT_FILE = "SYS$DISK:[]VAX_VAXC_OPTIONS.OPT"
1047$!
1048$! End VAXC Check
1049$!
1050$ ENDIF
1051$!
1052$! Check To See If We Are To Use GNU C.
1053$!
1054$ IF (P3.EQS."GNUC")
1055$ THEN
1056$!
1057$! Looks Like GNUC, Set To Use GNUC.
1058$!
1059$ COMPILER = "GNUC"
1060$!
1061$! Tell The User We Are Using GNUC.
1062$!
1063$ WRITE SYS$OUTPUT "Using GNU 'C' Compiler."
1064$!
1065$! Use GNU C...
1066$!
1067$ CC = "GCC/NOCASE_HACK/''GCC_OPTIMIZE'/''DEBUGGER'/NOLIST" + -
1068 "/INCLUDE=(SYS$DISK:[],SYS$DISK:[-],SYS$DISK:[.ENGINE.VENDOR_DEFNS])" + -
1069 CCEXTRAFLAGS
1070$!
1071$! Define The Linker Options File Name.
1072$!
1073$ OPT_FILE = "SYS$DISK:[]VAX_GNUC_OPTIONS.OPT"
1074$!
1075$! End The GNU C Check.
1076$!
1077$ ENDIF
1078$!
1079$! Set up default defines
1080$!
1081$ CCDEFS = """FLAT_INC=1""," + CCDEFS
1082$!
1083$! Finish up the definition of CC.
1084$!
1085$ IF COMPILER .EQS. "DECC"
1086$ THEN
1087$ IF CCDISABLEWARNINGS .EQS. ""
1088$ THEN
1089$ CC4DISABLEWARNINGS = "DOLLARID"
1090$ CC6DISABLEWARNINGS = "MIXLINKAGE"
1091$ ELSE
1092$ CC4DISABLEWARNINGS = CCDISABLEWARNINGS + ",DOLLARID"
1093$ CC6DISABLEWARNINGS = CCDISABLEWARNINGS + ",MIXLINKAGE"
1094$ CCDISABLEWARNINGS = "/WARNING=(DISABLE=(" + CCDISABLEWARNINGS + "))"
1095$ ENDIF
1096$ CC4DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC4DISABLEWARNINGS + "))"
1097$ CC6DISABLEWARNINGS = "/WARNING=(DISABLE=(" + CC6DISABLEWARNINGS + "))"
1098$ ELSE
1099$ CCDISABLEWARNINGS = ""
1100$ CC4DISABLEWARNINGS = ""
1101$ CC6DISABLEWARNINGS = ""
1102$ ENDIF
1103$ CC3 = CC + "/DEFINE=(" + CCDEFS + ISSEVEN + ")" + CCDISABLEWARNINGS
1104$ CC = CC + "/DEFINE=(" + CCDEFS + ")" + CCDISABLEWARNINGS
1105$ IF ARCH .EQS. "VAX" .AND. COMPILER .EQS. "DECC" .AND. P2 .NES. "DEBUG"
1106$ THEN
1107$ CC5 = CC + "/OPTIMIZE=NODISJOINT"
1108$ ELSE
1109$ CC5 = CC + "/NOOPTIMIZE"
1110$ ENDIF
1111$ CC4 = CC - CCDISABLEWARNINGS + CC4DISABLEWARNINGS
1112$ CC6 = CC - CCDISABLEWARNINGS + CC6DISABLEWARNINGS
1113$!
1114$! Show user the result
1115$!
1116$ WRITE/SYMBOL SYS$OUTPUT "Main C Compiling Command: ",CC
1117$!
1118$! Else The User Entered An Invalid Arguement.
1119$!
1120$ ELSE
1121$!
1122$! Tell The User We Don't Know What They Want.
1123$!
1124$ WRITE SYS$OUTPUT ""
1125$ WRITE SYS$OUTPUT "The Option ",P3," Is Invalid. The Valid Options Are:"
1126$ WRITE SYS$OUTPUT ""
1127$ WRITE SYS$OUTPUT " VAXC : To Compile With VAX C."
1128$ WRITE SYS$OUTPUT " DECC : To Compile With DEC C."
1129$ WRITE SYS$OUTPUT " GNUC : To Compile With GNU C."
1130$ WRITE SYS$OUTPUT ""
1131$!
1132$! Time To EXIT.
1133$!
1134$ EXIT
1135$!
1136$! End The Valid Arguement Check.
1137$!
1138$ ENDIF
1139$!
1140$! Build a MACRO command for the architecture at hand
1141$!
1142$ IF ARCH .EQS. "VAX" THEN MACRO = "MACRO/''DEBUGGER'"
1143$ IF ARCH .EQS. "AXP" THEN MACRO = "MACRO/MIGRATION/''DEBUGGER'/''MACRO_OPTIMIZE'"
1144$!
1145$! Show user the result
1146$!
1147$ WRITE/SYMBOL SYS$OUTPUT "Main MACRO Compiling Command: ",MACRO
1148$!
1149$! Time to check the contents, and to make sure we get the correct library.
1150$!
1151$ IF P4.EQS."SOCKETSHR" .OR. P4.EQS."MULTINET" .OR. P4.EQS."UCX" -
1152 .OR. P4.EQS."TCPIP" .OR. P4.EQS."NONE"
1153$ THEN
1154$!
1155$! Check to see if SOCKETSHR was chosen
1156$!
1157$ IF P4.EQS."SOCKETSHR"
1158$ THEN
1159$!
1160$! Set the library to use SOCKETSHR
1161$!
1162$ TCPIP_LIB = "SYS$DISK:[-.VMS]SOCKETSHR_SHR.OPT/OPT"
1163$!
1164$! Done with SOCKETSHR
1165$!
1166$ ENDIF
1167$!
1168$! Check to see if MULTINET was chosen
1169$!
1170$ IF P4.EQS."MULTINET"
1171$ THEN
1172$!
1173$! Set the library to use UCX emulation.
1174$!
1175$ P4 = "UCX"
1176$!
1177$! Done with MULTINET
1178$!
1179$ ENDIF
1180$!
1181$! Check to see if UCX was chosen
1182$!
1183$ IF P4.EQS."UCX"
1184$ THEN
1185$!
1186$! Set the library to use UCX.
1187$!
1188$ TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC.OPT/OPT"
1189$ IF F$TRNLNM("UCX$IPC_SHR") .NES. ""
1190$ THEN
1191$ TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_DECC_LOG.OPT/OPT"
1192$ ELSE
1193$ IF COMPILER .NES. "DECC" .AND. ARCH .EQS. "VAX" THEN -
1194 TCPIP_LIB = "SYS$DISK:[-.VMS]UCX_SHR_VAXC.OPT/OPT"
1195$ ENDIF
1196$!
1197$! Done with UCX
1198$!
1199$ ENDIF
1200$!
1201$! Check to see if TCPIP was chosen
1202$!
1203$ IF P4.EQS."TCPIP"
1204$ THEN
1205$!
1206$! Set the library to use TCPIP (post UCX).
1207$!
1208$ TCPIP_LIB = "SYS$DISK:[-.VMS]TCPIP_SHR_DECC.OPT/OPT"
1209$!
1210$! Done with TCPIP
1211$!
1212$ ENDIF
1213$!
1214$! Check to see if NONE was chosen
1215$!
1216$ IF P4.EQS."NONE"
1217$ THEN
1218$!
1219$! Do not use a TCPIP library.
1220$!
1221$ TCPIP_LIB = ""
1222$!
1223$! Done with TCPIP
1224$!
1225$ ENDIF
1226$!
1227$! Print info
1228$!
1229$ WRITE SYS$OUTPUT "TCP/IP library spec: ", TCPIP_LIB
1230$!
1231$! Else The User Entered An Invalid Arguement.
1232$!
1233$ ELSE
1234$!
1235$! Tell The User We Don't Know What They Want.
1236$!
1237$ WRITE SYS$OUTPUT ""
1238$ WRITE SYS$OUTPUT "The Option ",P4," Is Invalid. The Valid Options Are:"
1239$ WRITE SYS$OUTPUT ""
1240$ WRITE SYS$OUTPUT " SOCKETSHR : To link with SOCKETSHR TCP/IP library."
1241$ WRITE SYS$OUTPUT " UCX : To link with UCX TCP/IP library."
1242$ WRITE SYS$OUTPUT " TCPIP : To link with TCPIP (post UCX) TCP/IP library."
1243$ WRITE SYS$OUTPUT ""
1244$!
1245$! Time To EXIT.
1246$!
1247$ EXIT
1248$!
1249$! Done with TCP/IP libraries
1250$!
1251$ ENDIF
1252$!
1253$! Check if the user wanted to compile just a subset of all the encryption
1254$! methods.
1255$!
1256$ IF P6 .NES. ""
1257$ THEN
1258$ ENCRYPT_TYPES = P6
1259$ ENDIF
1260$!
1261$! Time To RETURN...
1262$!
1263$ RETURN
1264$!
1265$ INITIALISE:
1266$!
1267$! Save old value of the logical name OPENSSL
1268$!
1269$ __SAVE_OPENSSL = F$TRNLNM("OPENSSL","LNM$PROCESS_TABLE")
1270$!
1271$! Save directory information
1272$!
1273$ __HERE = F$PARSE(F$PARSE("A.;",F$ENVIRONMENT("PROCEDURE"))-"A.;","[]A.;") - "A.;"
1274$ __HERE = F$EDIT(__HERE,"UPCASE")
1275$ __TOP = __HERE - "CRYPTO]"
1276$ __INCLUDE = __TOP + "INCLUDE.OPENSSL]"
1277$!
1278$! Set up the logical name OPENSSL to point at the include directory
1279$!
1280$ DEFINE OPENSSL/NOLOG '__INCLUDE'
1281$!
1282$! Done
1283$!
1284$ RETURN
1285$!
1286$ CLEANUP:
1287$!
1288$! Restore the logical name OPENSSL if it had a value
1289$!
1290$ IF __SAVE_OPENSSL .EQS. ""
1291$ THEN
1292$ DEASSIGN OPENSSL
1293$ ELSE
1294$ DEFINE/NOLOG OPENSSL '__SAVE_OPENSSL'
1295$ ENDIF
1296$!
1297$! Done
1298$!
1299$ RETURN
diff --git a/src/lib/libcrypto/crypto.h b/src/lib/libcrypto/crypto.h
index d2b5ffe332..22fd939e65 100644
--- a/src/lib/libcrypto/crypto.h
+++ b/src/lib/libcrypto/crypto.h
@@ -1,57 +1,4 @@
1/* crypto/crypto.h */ 1/* crypto/crypto.h */
2/* ====================================================================
3 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved. 3 * All rights reserved.
57 * 4 *
@@ -108,19 +55,12 @@
108 * copied and put under another distribution licence 55 * copied and put under another distribution licence
109 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
110 */ 57 */
111/* ====================================================================
112 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
113 * ECDH support in OpenSSL originally developed by
114 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
115 */
116 58
117#ifndef HEADER_CRYPTO_H 59#ifndef HEADER_CRYPTO_H
118#define HEADER_CRYPTO_H 60#define HEADER_CRYPTO_H
119 61
120#include <stdlib.h> 62#include <stdlib.h>
121 63
122#include <openssl/e_os2.h>
123
124#ifndef OPENSSL_NO_FP_API 64#ifndef OPENSSL_NO_FP_API
125#include <stdio.h> 65#include <stdio.h>
126#endif 66#endif
@@ -128,7 +68,6 @@
128#include <openssl/stack.h> 68#include <openssl/stack.h>
129#include <openssl/safestack.h> 69#include <openssl/safestack.h>
130#include <openssl/opensslv.h> 70#include <openssl/opensslv.h>
131#include <openssl/ossl_typ.h>
132 71
133#ifdef CHARSET_EBCDIC 72#ifdef CHARSET_EBCDIC
134#include <openssl/ebcdic.h> 73#include <openssl/ebcdic.h>
@@ -153,39 +92,15 @@ extern "C" {
153#define SSLEAY_PLATFORM 4 92#define SSLEAY_PLATFORM 4
154#define SSLEAY_DIR 5 93#define SSLEAY_DIR 5
155 94
156/* Already declared in ossl_typ.h */
157#if 0
158typedef struct crypto_ex_data_st CRYPTO_EX_DATA;
159/* Called when a new object is created */
160typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
161 int idx, long argl, void *argp);
162/* Called when an object is free()ed */
163typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
164 int idx, long argl, void *argp);
165/* Called when we need to dup an object */
166typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
167 int idx, long argl, void *argp);
168#endif
169
170/* A generic structure to pass assorted data in a expandable way */
171typedef struct openssl_item_st
172 {
173 int code;
174 void *value; /* Not used for flag attributes */
175 size_t value_size; /* Max size of value for output, length for input */
176 size_t *value_length; /* Returned length of value for output */
177 } OPENSSL_ITEM;
178
179
180/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock 95/* When changing the CRYPTO_LOCK_* list, be sure to maintin the text lock
181 * names in cryptlib.c 96 * names in cryptlib.c
182 */ 97 */
183 98
184#define CRYPTO_LOCK_ERR 1 99#define CRYPTO_LOCK_ERR 1
185#define CRYPTO_LOCK_EX_DATA 2 100#define CRYPTO_LOCK_EX_DATA 2
186#define CRYPTO_LOCK_X509 3 101#define CRYPTO_LOCK_X509 3
187#define CRYPTO_LOCK_X509_INFO 4 102#define CRYPTO_LOCK_X509_INFO 4
188#define CRYPTO_LOCK_X509_PKEY 5 103#define CRYPTO_LOCK_X509_PKEY 5
189#define CRYPTO_LOCK_X509_CRL 6 104#define CRYPTO_LOCK_X509_CRL 6
190#define CRYPTO_LOCK_X509_REQ 7 105#define CRYPTO_LOCK_X509_REQ 7
191#define CRYPTO_LOCK_DSA 8 106#define CRYPTO_LOCK_DSA 8
@@ -212,14 +127,10 @@ typedef struct openssl_item_st
212#define CRYPTO_LOCK_DYNLOCK 29 127#define CRYPTO_LOCK_DYNLOCK 29
213#define CRYPTO_LOCK_ENGINE 30 128#define CRYPTO_LOCK_ENGINE 30
214#define CRYPTO_LOCK_UI 31 129#define CRYPTO_LOCK_UI 31
215#define CRYPTO_LOCK_ECDSA 32 130#define CRYPTO_LOCK_HWCRHK 32 /* This is a HACK which will disappear in 0.9.8 */
216#define CRYPTO_LOCK_EC 33 131#define CRYPTO_LOCK_FIPS 33
217#define CRYPTO_LOCK_ECDH 34 132#define CRYPTO_LOCK_FIPS2 34
218#define CRYPTO_LOCK_BN 35 133#define CRYPTO_NUM_LOCKS 35
219#define CRYPTO_LOCK_EC_PRE_COMP 36
220#define CRYPTO_LOCK_STORE 37
221#define CRYPTO_LOCK_COMP 38
222#define CRYPTO_NUM_LOCKS 39
223 134
224#define CRYPTO_LOCK 1 135#define CRYPTO_LOCK 1
225#define CRYPTO_UNLOCK 2 136#define CRYPTO_UNLOCK 2
@@ -280,11 +191,21 @@ typedef struct
280/* predec of the BIO type */ 191/* predec of the BIO type */
281typedef struct bio_st BIO_dummy; 192typedef struct bio_st BIO_dummy;
282 193
283struct crypto_ex_data_st 194typedef struct crypto_ex_data_st
284 { 195 {
285 STACK *sk; 196 STACK *sk;
286 int dummy; /* gcc is screwing up this data structure :-( */ 197 int dummy; /* gcc is screwing up this data structure :-( */
287 }; 198 } CRYPTO_EX_DATA;
199
200/* Called when a new object is created */
201typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
202 int idx, long argl, void *argp);
203/* Called when an object is free()ed */
204typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
205 int idx, long argl, void *argp);
206/* Called when we need to dup an object */
207typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
208 int idx, long argl, void *argp);
288 209
289/* This stuff is basically class callback functions 210/* This stuff is basically class callback functions
290 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */ 211 * The current classes are SSL_CTX, SSL, SSL_SESSION, and a few more */
@@ -316,10 +237,6 @@ DECLARE_STACK_OF(CRYPTO_EX_DATA_FUNCS)
316#define CRYPTO_EX_INDEX_ENGINE 9 237#define CRYPTO_EX_INDEX_ENGINE 9
317#define CRYPTO_EX_INDEX_X509 10 238#define CRYPTO_EX_INDEX_X509 10
318#define CRYPTO_EX_INDEX_UI 11 239#define CRYPTO_EX_INDEX_UI 11
319#define CRYPTO_EX_INDEX_ECDSA 12
320#define CRYPTO_EX_INDEX_ECDH 13
321#define CRYPTO_EX_INDEX_COMP 14
322#define CRYPTO_EX_INDEX_STORE 15
323 240
324/* Dynamically assigned indexes start from this value (don't use directly, use 241/* Dynamically assigned indexes start from this value (don't use directly, use
325 * via CRYPTO_ex_data_new_class). */ 242 * via CRYPTO_ex_data_new_class). */
@@ -517,10 +434,61 @@ void CRYPTO_mem_leaks_cb(CRYPTO_MEM_LEAK_CB *cb);
517 434
518/* die if we have to */ 435/* die if we have to */
519void OpenSSLDie(const char *file,int line,const char *assertion); 436void OpenSSLDie(const char *file,int line,const char *assertion);
520#define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1)) 437#define OPENSSL_assert(e) (void)((e) ? 0 : (OpenSSLDie(__FILE__, __LINE__, #e),1))
438
439#ifdef OPENSSL_FIPS
440#define FIPS_ERROR_IGNORED(alg) OpenSSLDie(__FILE__, __LINE__, \
441 alg " previous FIPS forbidden algorithm error ignored");
442
443#define FIPS_BAD_ABORT(alg) OpenSSLDie(__FILE__, __LINE__, \
444 #alg " Algorithm forbidden in FIPS mode");
445
446#ifdef OPENSSL_FIPS_STRICT
447#define FIPS_BAD_ALGORITHM(alg) FIPS_BAD_ABORT(alg)
448#else
449#define FIPS_BAD_ALGORITHM(alg) \
450 { \
451 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD); \
452 ERR_add_error_data(2, "Algorithm=", #alg); \
453 return 0; \
454 }
455#endif
456
457/* Low level digest API blocking macro */
458
459#define FIPS_NON_FIPS_MD_Init(alg) \
460 int alg##_Init(alg##_CTX *c) \
461 { \
462 if (FIPS_mode()) \
463 FIPS_BAD_ALGORITHM(alg) \
464 return private_##alg##_Init(c); \
465 } \
466 int private_##alg##_Init(alg##_CTX *c)
467
468/* For ciphers the API often varies from cipher to cipher and each needs to
469 * be treated as a special case. Variable key length ciphers (Blowfish, RC4,
470 * CAST) however are very similar and can use a blocking macro.
471 */
472
473#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
474 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data) \
475 { \
476 if (FIPS_mode()) \
477 FIPS_BAD_ABORT(alg) \
478 private_##alg##_set_key(key, len, data); \
479 } \
480 void private_##alg##_set_key(alg##_KEY *key, int len, \
481 const unsigned char *data)
482
483#else
484
485#define FIPS_NON_FIPS_VCIPHER_Init(alg) \
486 void alg##_set_key(alg##_KEY *key, int len, const unsigned char *data)
487
488#define FIPS_NON_FIPS_MD_Init(alg) \
489 int alg##_Init(alg##_CTX *c)
521 490
522unsigned long *OPENSSL_ia32cap_loc(void); 491#endif /* def OPENSSL_FIPS */
523#define OPENSSL_ia32cap (*(OPENSSL_ia32cap_loc()))
524 492
525/* BEGIN ERROR CODES */ 493/* BEGIN ERROR CODES */
526/* The following lines are auto generated by the script mkerr.pl. Any changes 494/* The following lines are auto generated by the script mkerr.pl. Any changes
diff --git a/src/lib/libcrypto/cversion.c b/src/lib/libcrypto/cversion.c
index ea9f25fd16..beeeb14013 100644
--- a/src/lib/libcrypto/cversion.c
+++ b/src/lib/libcrypto/cversion.c
@@ -56,7 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h>
60#include <string.h>
59#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/crypto.h>
60 63
61#ifndef NO_WINDOWS_BRAINDEATH 64#ifndef NO_WINDOWS_BRAINDEATH
62#include "buildinf.h" 65#include "buildinf.h"
diff --git a/src/lib/libcrypto/des/DES.pm b/src/lib/libcrypto/des/DES.pm
new file mode 100644
index 0000000000..6a175b6ca4
--- /dev/null
+++ b/src/lib/libcrypto/des/DES.pm
@@ -0,0 +1,19 @@
1package DES;
2
3require Exporter;
4require DynaLoader;
5@ISA = qw(Exporter DynaLoader);
6# Items to export into callers namespace by default
7# (move infrequently used names to @EXPORT_OK below)
8@EXPORT = qw(
9);
10# Other items we are prepared to export if requested
11@EXPORT_OK = qw(
12crypt
13);
14
15# Preloaded methods go here. Autoload methods go after __END__, and are
16# processed by the autosplit program.
17bootstrap DES;
181;
19__END__
diff --git a/src/lib/libcrypto/des/DES.xs b/src/lib/libcrypto/des/DES.xs
new file mode 100644
index 0000000000..b8050b9edf
--- /dev/null
+++ b/src/lib/libcrypto/des/DES.xs
@@ -0,0 +1,268 @@
1#include "EXTERN.h"
2#include "perl.h"
3#include "XSUB.h"
4#include "des.h"
5
6#define deschar char
7static STRLEN len;
8
9static int
10not_here(s)
11char *s;
12{
13 croak("%s not implemented on this architecture", s);
14 return -1;
15}
16
17MODULE = DES PACKAGE = DES PREFIX = des_
18
19char *
20des_crypt(buf,salt)
21 char * buf
22 char * salt
23
24void
25des_set_odd_parity(key)
26 des_cblock * key
27PPCODE:
28 {
29 SV *s;
30
31 s=sv_newmortal();
32 sv_setpvn(s,(char *)key,8);
33 des_set_odd_parity((des_cblock *)SvPV(s,na));
34 PUSHs(s);
35 }
36
37int
38des_is_weak_key(key)
39 des_cblock * key
40
41des_key_schedule
42des_set_key(key)
43 des_cblock * key
44CODE:
45 des_set_key(key,RETVAL);
46OUTPUT:
47RETVAL
48
49des_cblock
50des_ecb_encrypt(input,ks,encrypt)
51 des_cblock * input
52 des_key_schedule * ks
53 int encrypt
54CODE:
55 des_ecb_encrypt(input,&RETVAL,*ks,encrypt);
56OUTPUT:
57RETVAL
58
59void
60des_cbc_encrypt(input,ks,ivec,encrypt)
61 char * input
62 des_key_schedule * ks
63 des_cblock * ivec
64 int encrypt
65PPCODE:
66 {
67 SV *s;
68 STRLEN len,l;
69 char *c;
70
71 l=SvCUR(ST(0));
72 len=((((unsigned long)l)+7)/8)*8;
73 s=sv_newmortal();
74 sv_setpvn(s,"",0);
75 SvGROW(s,len);
76 SvCUR_set(s,len);
77 c=(char *)SvPV(s,na);
78 des_cbc_encrypt((des_cblock *)input,(des_cblock *)c,
79 l,*ks,ivec,encrypt);
80 sv_setpvn(ST(2),(char *)c[len-8],8);
81 PUSHs(s);
82 }
83
84void
85des_cbc3_encrypt(input,ks1,ks2,ivec1,ivec2,encrypt)
86 char * input
87 des_key_schedule * ks1
88 des_key_schedule * ks2
89 des_cblock * ivec1
90 des_cblock * ivec2
91 int encrypt
92PPCODE:
93 {
94 SV *s;
95 STRLEN len,l;
96
97 l=SvCUR(ST(0));
98 len=((((unsigned long)l)+7)/8)*8;
99 s=sv_newmortal();
100 sv_setpvn(s,"",0);
101 SvGROW(s,len);
102 SvCUR_set(s,len);
103 des_3cbc_encrypt((des_cblock *)input,(des_cblock *)SvPV(s,na),
104 l,*ks1,*ks2,ivec1,ivec2,encrypt);
105 sv_setpvn(ST(3),(char *)ivec1,8);
106 sv_setpvn(ST(4),(char *)ivec2,8);
107 PUSHs(s);
108 }
109
110void
111des_cbc_cksum(input,ks,ivec)
112 char * input
113 des_key_schedule * ks
114 des_cblock * ivec
115PPCODE:
116 {
117 SV *s1,*s2;
118 STRLEN len,l;
119 des_cblock c;
120 unsigned long i1,i2;
121
122 s1=sv_newmortal();
123 s2=sv_newmortal();
124 l=SvCUR(ST(0));
125 des_cbc_cksum((des_cblock *)input,(des_cblock *)c,
126 l,*ks,ivec);
127 i1=c[4]|(c[5]<<8)|(c[6]<<16)|(c[7]<<24);
128 i2=c[0]|(c[1]<<8)|(c[2]<<16)|(c[3]<<24);
129 sv_setiv(s1,i1);
130 sv_setiv(s2,i2);
131 sv_setpvn(ST(2),(char *)c,8);
132 PUSHs(s1);
133 PUSHs(s2);
134 }
135
136void
137des_cfb_encrypt(input,numbits,ks,ivec,encrypt)
138 char * input
139 int numbits
140 des_key_schedule * ks
141 des_cblock * ivec
142 int encrypt
143PPCODE:
144 {
145 SV *s;
146 STRLEN len;
147 char *c;
148
149 len=SvCUR(ST(0));
150 s=sv_newmortal();
151 sv_setpvn(s,"",0);
152 SvGROW(s,len);
153 SvCUR_set(s,len);
154 c=(char *)SvPV(s,na);
155 des_cfb_encrypt((unsigned char *)input,(unsigned char *)c,
156 (int)numbits,(long)len,*ks,ivec,encrypt);
157 sv_setpvn(ST(3),(char *)ivec,8);
158 PUSHs(s);
159 }
160
161des_cblock *
162des_ecb3_encrypt(input,ks1,ks2,encrypt)
163 des_cblock * input
164 des_key_schedule * ks1
165 des_key_schedule * ks2
166 int encrypt
167CODE:
168 {
169 des_cblock c;
170
171 des_ecb3_encrypt((des_cblock *)input,(des_cblock *)&c,
172 *ks1,*ks2,encrypt);
173 RETVAL= &c;
174 }
175OUTPUT:
176RETVAL
177
178void
179des_ofb_encrypt(input,numbits,ks,ivec)
180 unsigned char * input
181 int numbits
182 des_key_schedule * ks
183 des_cblock * ivec
184PPCODE:
185 {
186 SV *s;
187 STRLEN len,l;
188 unsigned char *c;
189
190 len=SvCUR(ST(0));
191 s=sv_newmortal();
192 sv_setpvn(s,"",0);
193 SvGROW(s,len);
194 SvCUR_set(s,len);
195 c=(unsigned char *)SvPV(s,na);
196 des_ofb_encrypt((unsigned char *)input,(unsigned char *)c,
197 numbits,len,*ks,ivec);
198 sv_setpvn(ST(3),(char *)ivec,8);
199 PUSHs(s);
200 }
201
202void
203des_pcbc_encrypt(input,ks,ivec,encrypt)
204 char * input
205 des_key_schedule * ks
206 des_cblock * ivec
207 int encrypt
208PPCODE:
209 {
210 SV *s;
211 STRLEN len,l;
212 char *c;
213
214 l=SvCUR(ST(0));
215 len=((((unsigned long)l)+7)/8)*8;
216 s=sv_newmortal();
217 sv_setpvn(s,"",0);
218 SvGROW(s,len);
219 SvCUR_set(s,len);
220 c=(char *)SvPV(s,na);
221 des_pcbc_encrypt((des_cblock *)input,(des_cblock *)c,
222 l,*ks,ivec,encrypt);
223 sv_setpvn(ST(2),(char *)c[len-8],8);
224 PUSHs(s);
225 }
226
227des_cblock *
228des_random_key()
229CODE:
230 {
231 des_cblock c;
232
233 des_random_key(c);
234 RETVAL=&c;
235 }
236OUTPUT:
237RETVAL
238
239des_cblock *
240des_string_to_key(str)
241char * str
242CODE:
243 {
244 des_cblock c;
245
246 des_string_to_key(str,&c);
247 RETVAL=&c;
248 }
249OUTPUT:
250RETVAL
251
252void
253des_string_to_2keys(str)
254char * str
255PPCODE:
256 {
257 des_cblock c1,c2;
258 SV *s1,*s2;
259
260 des_string_to_2keys(str,&c1,&c2);
261 EXTEND(sp,2);
262 s1=sv_newmortal();
263 sv_setpvn(s1,(char *)c1,8);
264 s2=sv_newmortal();
265 sv_setpvn(s2,(char *)c2,8);
266 PUSHs(s1);
267 PUSHs(s2);
268 }
diff --git a/src/lib/libcrypto/des/FILES0 b/src/lib/libcrypto/des/FILES0
new file mode 100644
index 0000000000..4c7ea2de7a
--- /dev/null
+++ b/src/lib/libcrypto/des/FILES0
@@ -0,0 +1,96 @@
1/* General stuff */
2COPYRIGHT - Copyright info.
3MODES.DES - A description of the features of the different modes of DES.
4FILES - This file.
5INSTALL - How to make things compile.
6Imakefile - For use with kerberos.
7README - What this package is.
8VERSION - Which version this is and what was changed.
9KERBEROS - Kerberos version 4 notes.
10Makefile.PL - An old makefile to build with perl5, not current.
11Makefile.ssl - The SSLeay makefile
12Makefile.uni - The normal unix makefile.
13GNUmakefile - The makefile for use with glibc.
14makefile.bc - A Borland C makefile
15times - Some outputs from 'speed' on some machines.
16vms.com - For use when compiling under VMS
17
18/* My SunOS des(1) replacement */
19des.c - des(1) source code.
20des.man - des(1) manual.
21
22/* Testing and timing programs. */
23destest.c - Source for libdes.a test program.
24speed.c - Source for libdes.a timing program.
25rpw.c - Source for libdes.a testing password reading routines.
26
27/* libdes.a source code */
28des_crypt.man - libdes.a manual page.
29des.h - Public libdes.a header file.
30ecb_enc.c - des_ecb_encrypt() source, this contains the basic DES code.
31ecb3_enc.c - des_ecb3_encrypt() source.
32cbc_ckm.c - des_cbc_cksum() source.
33cbc_enc.c - des_cbc_encrypt() source.
34ncbc_enc.c - des_cbc_encrypt() that is 'normal' in that it copies
35 the new iv values back in the passed iv vector.
36ede_enc.c - des_ede3_cbc_encrypt() cbc mode des using triple DES.
37cbc3_enc.c - des_3cbc_encrypt() source, don't use this function.
38cfb_enc.c - des_cfb_encrypt() source.
39cfb64enc.c - des_cfb64_encrypt() cfb in 64 bit mode but setup to be
40 used as a stream cipher.
41cfb64ede.c - des_ede3_cfb64_encrypt() cfb in 64 bit mode but setup to be
42 used as a stream cipher and using triple DES.
43ofb_enc.c - des_cfb_encrypt() source.
44ofb64_enc.c - des_ofb_encrypt() ofb in 64 bit mode but setup to be
45 used as a stream cipher.
46ofb64ede.c - des_ede3_ofb64_encrypt() ofb in 64 bit mode but setup to be
47 used as a stream cipher and using triple DES.
48enc_read.c - des_enc_read() source.
49enc_writ.c - des_enc_write() source.
50pcbc_enc.c - des_pcbc_encrypt() source.
51qud_cksm.c - quad_cksum() source.
52rand_key.c - des_random_key() source.
53read_pwd.c - Source for des_read_password() plus related functions.
54set_key.c - Source for des_set_key().
55str2key.c - Covert a string of any length into a key.
56fcrypt.c - A small, fast version of crypt(3).
57des_locl.h - Internal libdes.a header file.
58podd.h - Odd parity tables - used in des_set_key().
59sk.h - Lookup tables used in des_set_key().
60spr.h - What is left of the S tables - used in ecb_encrypt().
61des_ver.h - header file for the external definition of the
62 version string.
63des.doc - SSLeay documentation for the library.
64
65/* The perl scripts - you can ignore these files they are only
66 * included for the curious */
67des.pl - des in perl anyone? des_set_key and des_ecb_encrypt
68 both done in a perl library.
69testdes.pl - Testing program for des.pl
70doIP - Perl script used to develop IP xor/shift code.
71doPC1 - Perl script used to develop PC1 xor/shift code.
72doPC2 - Generates sk.h.
73PC1 - Output of doPC1 should be the same as output from PC1.
74PC2 - used in development of doPC2.
75shifts.pl - Perl library used by my perl scripts.
76
77/* I started making a perl5 dynamic library for libdes
78 * but did not fully finish, these files are part of that effort. */
79DES.pm
80DES.pod
81DES.xs
82t
83typemap
84
85/* The following are for use with sun RPC implementaions. */
86rpc_des.h
87rpc_enc.c
88
89/* The following are contibuted by Mark Murray <mark@grondar.za>. They
90 * are not normally built into libdes due to machine specific routines
91 * contained in them. They are for use in the most recent incarnation of
92 * export kerberos v 4 (eBones). */
93supp.c
94new_rkey.c
95
96
diff --git a/src/lib/libcrypto/des/INSTALL b/src/lib/libcrypto/des/INSTALL
new file mode 100644
index 0000000000..8aebdfe110
--- /dev/null
+++ b/src/lib/libcrypto/des/INSTALL
@@ -0,0 +1,69 @@
1Check the CC and CFLAGS lines in the makefile
2
3If your C library does not support the times(3) function, change the
4#define TIMES to
5#undef TIMES in speed.c
6If it does, check the HZ value for the times(3) function.
7If your system does not define CLK_TCK it will be assumed to
8be 100.0.
9
10If possible use gcc v 2.7.?
11Turn on the maximum optimising (normally '-O3 -fomit-frame-pointer' for gcc)
12In recent times, some system compilers give better performace.
13
14type 'make'
15
16run './destest' to check things are ok.
17run './rpw' to check the tty code for reading passwords works.
18run './speed' to see how fast those optimisations make the library run :-)
19run './des_opts' to determin the best compile time options.
20
21The output from des_opts should be put in the makefile options and des_enc.c
22should be rebuilt. For 64 bit computers, do not use the DES_PTR option.
23For the DEC Alpha, edit des.h and change DES_LONG to 'unsigned int'
24and then you can use the 'DES_PTR' option.
25
26The file options.txt has the options listed for best speed on quite a
27few systems. Look and the options (UNROLL, PTR, RISC2 etc) and then
28turn on the relevant option in the Makefile.
29
30There are some special Makefile targets that make life easier.
31make cc - standard cc build
32make gcc - standard gcc build
33make x86-elf - x86 assembler (elf), linux-elf.
34make x86-out - x86 assembler (a.out), FreeBSD
35make x86-solaris- x86 assembler
36make x86-bsdi - x86 assembler (a.out with primative assembler).
37
38If at all possible use the assembler (for Windows NT/95, use
39asm/win32.obj to link with). The x86 assembler is very very fast.
40
41A make install will by default install
42libdes.a in /usr/local/lib/libdes.a
43des in /usr/local/bin/des
44des_crypt.man in /usr/local/man/man3/des_crypt.3
45des.man in /usr/local/man/man1/des.1
46des.h in /usr/include/des.h
47
48des(1) should be compatible with sunOS's but I have been unable to
49test it.
50
51These routines should compile on MSDOS, most 32bit and 64bit version
52of Unix (BSD and SYSV) and VMS, without modification.
53The only problems should be #include files that are in the wrong places.
54
55These routines can be compiled under MSDOS.
56I have successfully encrypted files using des(1) under MSDOS and then
57decrypted the files on a SparcStation.
58I have been able to compile and test the routines with
59Microsoft C v 5.1 and Turbo C v 2.0.
60The code in this library is in no way optimised for the 16bit
61operation of MSDOS.
62
63When building for glibc, ignore all of the above and just unpack into
64glibc-1.??/des and then gmake as per normal.
65
66As a final note on performace. Certain CPUs like sparcs and Alpha often give
67a %10 speed difference depending on the link order. It is rather anoying
68when one program reports 'x' DES encrypts a second and another reports
69'x*0.9' the speed.
diff --git a/src/lib/libcrypto/des/Imakefile b/src/lib/libcrypto/des/Imakefile
new file mode 100644
index 0000000000..1b9b5629e1
--- /dev/null
+++ b/src/lib/libcrypto/des/Imakefile
@@ -0,0 +1,35 @@
1# This Imakefile has not been tested for a while but it should still
2# work when placed in the correct directory in the kerberos v 4 distribution
3
4SRCS= cbc_cksm.c cbc_enc.c ecb_enc.c pcbc_enc.c \
5 qud_cksm.c rand_key.c read_pwd.c set_key.c str2key.c \
6 enc_read.c enc_writ.c fcrypt.c cfb_enc.c \
7 ecb3_enc.c ofb_enc.c ofb64enc.c
8
9OBJS= cbc_cksm.o cbc_enc.o ecb_enc.o pcbc_enc.o \
10 qud_cksm.o rand_key.o read_pwd.o set_key.o str2key.o \
11 enc_read.o enc_writ.o fcrypt.o cfb_enc.o \
12 ecb3_enc.o ofb_enc.o ofb64enc.o
13
14GENERAL=COPYRIGHT FILES INSTALL Imakefile README VERSION makefile times \
15 vms.com KERBEROS
16DES= des.c des.man
17TESTING=destest.c speed.c rpw.c
18LIBDES= des_crypt.man des.h des_locl.h podd.h sk.h spr.h
19
20PERL= des.pl testdes.pl doIP doPC1 doPC2 PC1 PC2 shifts.pl
21
22CODE= $(GENERAL) $(DES) $(TESTING) $(SRCS) $(LIBDES) $(PERL)
23
24SRCDIR=$(SRCTOP)/lib/des
25
26DBG= -O
27INCLUDE= -I$(SRCDIR)
28CC= cc
29
30library_obj_rule()
31
32install_library_target(des,$(OBJS),$(SRCS),)
33
34test(destest,libdes.a,)
35test(rpw,libdes.a,)
diff --git a/src/lib/libcrypto/des/KERBEROS b/src/lib/libcrypto/des/KERBEROS
new file mode 100644
index 0000000000..f401b10014
--- /dev/null
+++ b/src/lib/libcrypto/des/KERBEROS
@@ -0,0 +1,41 @@
1 [ This is an old file, I don't know if it is true anymore
2 but I will leave the file here - eay 21/11/95 ]
3
4To use this library with Bones (kerberos without DES):
51) Get my modified Bones - eBones. It can be found on
6 gondwana.ecr.mu.oz.au (128.250.1.63) /pub/athena/eBones-p9.tar.Z
7 and
8 nic.funet.fi (128.214.6.100) /pub/unix/security/Kerberos/eBones-p9.tar.Z
9
102) Unpack this library in src/lib/des, makeing sure it is version
11 3.00 or greater (libdes.tar.93-10-07.Z). This versions differences
12 from the version in comp.sources.misc volume 29 patchlevel2.
13 The primarily difference is that it should compile under kerberos :-).
14 It can be found at.
15 ftp.psy.uq.oz.au (130.102.32.1) /pub/DES/libdes.tar.93-10-07.Z
16
17Now do a normal kerberos build and things should work.
18
19One problem I found when I was build on my local sun.
20---
21For sunOS 4.1.1 apply the following patch to src/util/ss/make_commands.c
22
23*** make_commands.c.orig Fri Jul 3 04:18:35 1987
24--- make_commands.c Wed May 20 08:47:42 1992
25***************
26*** 98,104 ****
27 if (!rename(o_file, z_file)) {
28 if (!vfork()) {
29 chdir("/tmp");
30! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r", "-n",
31 z_file+5, 0);
32 perror("/bin/ld");
33 _exit(1);
34--- 98,104 ----
35 if (!rename(o_file, z_file)) {
36 if (!vfork()) {
37 chdir("/tmp");
38! execl("/bin/ld", "ld", "-o", o_file+5, "-s", "-r",
39 z_file+5, 0);
40 perror("/bin/ld");
41 _exit(1);
diff --git a/src/lib/libcrypto/des/Makefile b/src/lib/libcrypto/des/Makefile
new file mode 100644
index 0000000000..523dfe38f2
--- /dev/null
+++ b/src/lib/libcrypto/des/Makefile
@@ -0,0 +1,292 @@
1#
2# OpenSSL/crypto/des/Makefile
3#
4
5DIR= des
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I$(TOP) -I../../include
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13RANLIB= ranlib
14DES_ENC= des_enc.o fcrypt_b.o
15# or use
16#DES_ENC= dx86-elf.o yx86-elf.o
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG)
20AFLAGS= $(ASFLAGS)
21
22GENERAL=Makefile
23TEST=destest.c
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
28 ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \
29 fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \
30 qud_cksm.c rand_key.c rpc_enc.c set_key.c \
31 des_enc.c fcrypt_b.c \
32 xcbc_enc.c \
33 str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
34 read2pwd.c
35
36LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
37 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
38 enc_read.o enc_writ.o ofb64enc.o \
39 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
40 ${DES_ENC} \
41 fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \
42 ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o
43
44SRC= $(LIBSRC)
45
46EXHEADER= des.h des_old.h
47HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER)
48
49ALL= $(GENERAL) $(SRC) $(HEADER)
50
51top:
52 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
53
54all: lib
55
56lib: $(LIBOBJ)
57 $(AR) $(LIB) $(LIBOBJ)
58 $(RANLIB) $(LIB) || echo Never mind.
59 @touch lib
60
61des: des.o cbc3_enc.o lib
62 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
63
64des_enc-sparc.S: asm/des_enc.m4
65 m4 -B 8192 asm/des_enc.m4 > des_enc-sparc.S
66
67# ELF
68dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
69 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > ../$@)
70yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
71 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > ../$@)
72# COFF
73dx86-cof.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
74 (cd asm; $(PERL) des-586.pl coff $(CFLAGS) > ../$@)
75yx86-cof.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
76 (cd asm; $(PERL) crypt586.pl coff $(CFLAGS) > ../$@)
77# a.out
78dx86-out.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
79 (cd asm; $(PERL) des-586.pl a.out $(CFLAGS) > ../$@)
80yx86-out.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
81 (cd asm; $(PERL) crypt586.pl a.out $(CFLAGS) > ../$@)
82
83files:
84 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
85
86links:
87 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
88 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
89 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
90
91# We need to use force because 'install' matches 'INSTALL' on case
92# insensitive systems
93FRC.install:
94install: FRC.install
95 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
96 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
97 do \
98 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
99 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
100 done;
101
102tags:
103 ctags $(SRC)
104
105tests:
106
107lint:
108 lint -DLINT $(INCLUDES) $(SRC)>fluff
109
110depend:
111 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
112 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
113
114dclean:
115 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
116 mv -f Makefile.new $(MAKEFILE)
117
118clean:
119 rm -f *.s *.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
120
121# DO NOT DELETE THIS LINE -- make depend depends on it.
122
123cbc_cksm.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
124cbc_cksm.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
125cbc_cksm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
126cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
127cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
128cbc_cksm.o: cbc_cksm.c des_locl.h
129cbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
130cbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
131cbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
132cbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
133cbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
134cbc_enc.o: cbc_enc.c des_locl.h ncbc_enc.c
135cfb64ede.o: ../../e_os.h ../../include/openssl/des.h
136cfb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
137cfb64ede.o: ../../include/openssl/opensslconf.h
138cfb64ede.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
139cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
140cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
141cfb64ede.o: cfb64ede.c des_locl.h
142cfb64enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
143cfb64enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
144cfb64enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
145cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
146cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
147cfb64enc.o: cfb64enc.c des_locl.h
148cfb_enc.o: ../../e_os.h ../../include/openssl/des.h
149cfb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
150cfb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/ossl_typ.h
151cfb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
152cfb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
153cfb_enc.o: ../../include/openssl/ui_compat.h cfb_enc.c des_locl.h
154des_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
155des_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
156des_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
157des_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
158des_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
159des_enc.o: des_enc.c des_locl.h ncbc_enc.c
160des_old.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
161des_old.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
162des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
163des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
164des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
165des_old.o: ../../include/openssl/ui_compat.h des_old.c
166des_old2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
167des_old2.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
168des_old2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
169des_old2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
170des_old2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
171des_old2.o: ../../include/openssl/ui_compat.h des_old2.c
172ecb3_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
173ecb3_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
174ecb3_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
175ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
177ecb3_enc.o: des_locl.h ecb3_enc.c
178ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
179ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
180ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
181ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
182ecb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
183ecb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
184ecb_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h ecb_enc.c
185ecb_enc.o: spr.h
186ede_cbcm_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
187ede_cbcm_enc.o: ../../include/openssl/e_os2.h
188ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
189ede_cbcm_enc.o: ../../include/openssl/ossl_typ.h
190ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
191ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
192ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c
193enc_read.o: ../../e_os.h ../../include/openssl/bio.h
194enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
195enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
196enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
197enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
198enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
199enc_read.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
200enc_read.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
201enc_read.o: ../../include/openssl/ui_compat.h ../cryptlib.h des_locl.h
202enc_read.o: enc_read.c
203enc_writ.o: ../../e_os.h ../../include/openssl/bio.h
204enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
205enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
206enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
207enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
208enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
209enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
210enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
211enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
212enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c
213fcrypt.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
214fcrypt.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
215fcrypt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
216fcrypt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217fcrypt.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
218fcrypt.o: des_locl.h fcrypt.c
219fcrypt_b.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
220fcrypt_b.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
221fcrypt_b.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
222fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
223fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
224fcrypt_b.o: des_locl.h fcrypt_b.c
225ofb64ede.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
226ofb64ede.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
227ofb64ede.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
228ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
229ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
230ofb64ede.o: des_locl.h ofb64ede.c
231ofb64enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
232ofb64enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
233ofb64enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
234ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
235ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
236ofb64enc.o: des_locl.h ofb64enc.c
237ofb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
238ofb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
239ofb_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
240ofb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
241ofb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
242ofb_enc.o: des_locl.h ofb_enc.c
243pcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
244pcbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
245pcbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
246pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
248pcbc_enc.o: des_locl.h pcbc_enc.c
249qud_cksm.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
250qud_cksm.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
251qud_cksm.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
252qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
253qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
254qud_cksm.o: des_locl.h qud_cksm.c
255rand_key.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
256rand_key.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
257rand_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
258rand_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
259rand_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
260rand_key.o: ../../include/openssl/ui_compat.h rand_key.c
261read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
262read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
263read2pwd.o: ../../include/openssl/opensslconf.h
264read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
265read2pwd.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
266read2pwd.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
267read2pwd.o: ../../include/openssl/ui_compat.h read2pwd.c
268rpc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
269rpc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
270rpc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
271rpc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
272rpc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
273rpc_enc.o: des_locl.h des_ver.h rpc_des.h rpc_enc.c
274set_key.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
275set_key.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
276set_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
277set_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
278set_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
279set_key.o: des_locl.h set_key.c
280str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
281str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
282str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
283str2key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
284str2key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
285str2key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
286str2key.o: des_locl.h str2key.c
287xcbc_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
288xcbc_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
289xcbc_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
290xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
291xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
292xcbc_enc.o: des_locl.h xcbc_enc.c
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl
new file mode 100644
index 0000000000..0d9ba2b42f
--- /dev/null
+++ b/src/lib/libcrypto/des/Makefile.ssl
@@ -0,0 +1,316 @@
1#
2# SSLeay/crypto/des/Makefile
3#
4
5DIR= des
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I$(TOP) -I../../include
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19RANLIB= ranlib
20DES_ENC= des_enc.o fcrypt_b.o
21# or use
22#DES_ENC= dx86-elf.o yx86-elf.o
23
24CFLAGS= $(INCLUDES) $(CFLAG)
25ASFLAGS= $(INCLUDES) $(ASFLAG)
26
27GENERAL=Makefile
28TEST=destest.c
29APPS=
30
31LIB=$(TOP)/libcrypto.a
32LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \
33 ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \
34 fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \
35 qud_cksm.c rand_key.c rpc_enc.c set_key.c \
36 des_enc.c fcrypt_b.c \
37 xcbc_enc.c \
38 str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \
39 read2pwd.c
40
41LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \
42 ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \
43 enc_read.o enc_writ.o ofb64enc.o \
44 ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \
45 ${DES_ENC} \
46 fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \
47 ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o
48
49SRC= $(LIBSRC)
50
51EXHEADER= des.h des_old.h
52HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER)
53
54ALL= $(GENERAL) $(SRC) $(HEADER)
55
56top:
57 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
58
59all: lib
60
61lib: $(LIBOBJ)
62 $(AR) $(LIB) $(LIBOBJ)
63 $(RANLIB) $(LIB) || echo Never mind.
64 @touch lib
65
66des: des.o cbc3_enc.o lib
67 $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB)
68
69# elf
70asm/dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
71 (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > dx86-elf.s)
72
73asm/yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
74 (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > yx86-elf.s)
75
76# a.out
77asm/dx86-out.o: asm/dx86unix.cpp
78 $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
79
80asm/yx86-out.o: asm/yx86unix.cpp
81 $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o
82
83# bsdi
84asm/dx86bsdi.o: asm/dx86unix.cpp
85 $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o
86
87asm/yx86bsdi.o: asm/yx86unix.cpp
88 $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o
89
90asm/dx86unix.cpp: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
91 (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp)
92
93asm/yx86unix.cpp: asm/crypt586.pl ../perlasm/x86asm.pl
94 (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp)
95
96files:
97 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
98
99links:
100 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
101 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
102 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
103 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
104
105install: installs
106
107installs:
108 @for i in $(EXHEADER) ; \
109 do \
110 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
111 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
112 done;
113
114tags:
115 ctags $(SRC)
116
117tests:
118
119lint:
120 lint -DLINT $(INCLUDES) $(SRC)>fluff
121
122depend:
123 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
124
125dclean:
126 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
127 mv -f Makefile.new $(MAKEFILE)
128
129clean:
130 rm -f asm/dx86unix.cpp asm/yx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff
131
132# DO NOT DELETE THIS LINE -- make depend depends on it.
133
134cbc_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
135cbc_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
136cbc_cksm.o: ../../include/openssl/opensslconf.h
137cbc_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
138cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
139cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
140cbc_cksm.o: cbc_cksm.c des_locl.h
141cbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
142cbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
143cbc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
144cbc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
145cbc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
146cbc_enc.o: ../../include/openssl/ui_compat.h cbc_enc.c des_locl.h ncbc_enc.c
147cfb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
148cfb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
149cfb64ede.o: ../../include/openssl/opensslconf.h
150cfb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
151cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
152cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
153cfb64ede.o: cfb64ede.c des_locl.h
154cfb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
155cfb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
156cfb64enc.o: ../../include/openssl/opensslconf.h
157cfb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
158cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
159cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
160cfb64enc.o: cfb64enc.c des_locl.h
161cfb_enc.o: ../../e_os.h ../../include/openssl/crypto.h
162cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
163cfb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
164cfb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
165cfb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
166cfb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
167cfb_enc.o: cfb_enc.c des_locl.h
168des_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
169des_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
170des_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
171des_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
172des_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
173des_enc.o: ../../include/openssl/ui_compat.h des_enc.c des_locl.h ncbc_enc.c
174des_old.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
175des_old.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
176des_old.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
177des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
178des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
179des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
180des_old.o: ../../include/openssl/ui_compat.h des_old.c
181des_old2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
182des_old2.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
183des_old2.o: ../../include/openssl/opensslconf.h
184des_old2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
185des_old2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
186des_old2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
187des_old2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
188des_old2.o: des_old2.c
189ecb3_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
190ecb3_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
191ecb3_enc.o: ../../include/openssl/opensslconf.h
192ecb3_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
193ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
194ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
195ecb3_enc.o: des_locl.h ecb3_enc.c
196ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
197ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
198ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
199ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
200ecb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
201ecb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
202ecb_enc.o: des_locl.h des_ver.h ecb_enc.c spr.h
203ede_cbcm_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
204ede_cbcm_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
205ede_cbcm_enc.o: ../../include/openssl/opensslconf.h
206ede_cbcm_enc.o: ../../include/openssl/opensslv.h
207ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
208ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
209ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c
210enc_read.o: ../../e_os.h ../../include/openssl/bio.h
211enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
212enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
213enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
214enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
215enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
216enc_read.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
217enc_read.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
218enc_read.o: ../cryptlib.h des_locl.h enc_read.c
219enc_writ.o: ../../e_os.h ../../include/openssl/bio.h
220enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
221enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
222enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
223enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
224enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
225enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
226enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
227enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
228enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c
229fcrypt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
230fcrypt.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
231fcrypt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
232fcrypt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
233fcrypt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
234fcrypt.o: ../../include/openssl/ui_compat.h des_locl.h fcrypt.c
235fcrypt_b.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
236fcrypt_b.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
237fcrypt_b.o: ../../include/openssl/opensslconf.h
238fcrypt_b.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
239fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
240fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
241fcrypt_b.o: des_locl.h fcrypt_b.c
242ofb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
243ofb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
244ofb64ede.o: ../../include/openssl/opensslconf.h
245ofb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
246ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
248ofb64ede.o: des_locl.h ofb64ede.c
249ofb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
250ofb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
251ofb64enc.o: ../../include/openssl/opensslconf.h
252ofb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
253ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
254ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
255ofb64enc.o: des_locl.h ofb64enc.c
256ofb_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
257ofb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
258ofb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
259ofb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
260ofb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
261ofb_enc.o: ../../include/openssl/ui_compat.h des_locl.h ofb_enc.c
262pcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
263pcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
264pcbc_enc.o: ../../include/openssl/opensslconf.h
265pcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
266pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
267pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
268pcbc_enc.o: des_locl.h pcbc_enc.c
269qud_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
270qud_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
271qud_cksm.o: ../../include/openssl/opensslconf.h
272qud_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
273qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
274qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
275qud_cksm.o: des_locl.h qud_cksm.c
276rand_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
277rand_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
278rand_key.o: ../../include/openssl/opensslconf.h
279rand_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
280rand_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
281rand_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
282rand_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
283rand_key.o: rand_key.c
284read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
285read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
286read2pwd.o: ../../include/openssl/opensslconf.h
287read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
288read2pwd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
289read2pwd.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
290read2pwd.o: read2pwd.c
291rpc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
292rpc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
293rpc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
294rpc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
295rpc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
296rpc_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h rpc_des.h
297rpc_enc.o: rpc_enc.c
298set_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
299set_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
300set_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
301set_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
302set_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
303set_key.o: ../../include/openssl/ui_compat.h des_locl.h set_key.c
304str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
305str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
306str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
307str2key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
308str2key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
309str2key.o: ../../include/openssl/ui_compat.h des_locl.h str2key.c
310xcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
311xcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
312xcbc_enc.o: ../../include/openssl/opensslconf.h
313xcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
314xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
315xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
316xcbc_enc.o: des_locl.h xcbc_enc.c
diff --git a/src/lib/libcrypto/des/README b/src/lib/libcrypto/des/README
new file mode 100644
index 0000000000..621a5ab467
--- /dev/null
+++ b/src/lib/libcrypto/des/README
@@ -0,0 +1,54 @@
1
2 libdes, Version 4.01 10-Jan-97
3
4 Copyright (c) 1997, Eric Young
5 All rights reserved.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms specified in COPYRIGHT.
9
10--
11The primary ftp site for this library is
12ftp://ftp.psy.uq.oz.au/pub/Crypto/DES/libdes-x.xx.tar.gz
13libdes is now also shipped with SSLeay. Primary ftp site of
14ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL/SSLeay-x.x.x.tar.gz
15
16The best way to build this library is to build it as part of SSLeay.
17
18This kit builds a DES encryption library and a DES encryption program.
19It supports ecb, cbc, ofb, cfb, triple ecb, triple cbc, triple ofb,
20triple cfb, desx, and MIT's pcbc encryption modes and also has a fast
21implementation of crypt(3).
22It contains support routines to read keys from a terminal,
23generate a random key, generate a key from an arbitrary length string,
24read/write encrypted data from/to a file descriptor.
25
26The implementation was written so as to conform with the manual entry
27for the des_crypt(3) library routines from MIT's project Athena.
28
29destest should be run after compilation to test the des routines.
30rpw should be run after compilation to test the read password routines.
31The des program is a replacement for the sun des command. I believe it
32conforms to the sun version.
33
34The Imakefile is setup for use in the kerberos distribution.
35
36These routines are best compiled with gcc or any other good
37optimising compiler.
38Just turn you optimiser up to the highest settings and run destest
39after the build to make sure everything works.
40
41I believe these routines are close to the fastest and most portable DES
42routines that use small lookup tables (4.5k) that are publicly available.
43The fcrypt routine is faster than ufc's fcrypt (when compiling with
44gcc2 -O2) on the sparc 2 (1410 vs 1270) but is not so good on other machines
45(on a sun3/260 168 vs 336). It is a function of CPU on chip cache size.
46[ 10-Jan-97 and a function of an incorrect speed testing program in
47 ufc which gave much better test figures that reality ].
48
49It is worth noting that on sparc and Alpha CPUs, performance of the DES
50library can vary by upto %10 due to the positioning of files after application
51linkage.
52
53Eric Young (eay@cryptsoft.com)
54
diff --git a/src/lib/libcrypto/des/VERSION b/src/lib/libcrypto/des/VERSION
new file mode 100644
index 0000000000..c7d01542bc
--- /dev/null
+++ b/src/lib/libcrypto/des/VERSION
@@ -0,0 +1,412 @@
1 Fixed the weak key values which were wrong :-(
2 Defining SIGACTION causes sigaction() to be used instead of signal().
3 SIGUSR1/SIGUSR2 are no longer mapped in the read tty stuff because it
4 can cause problems. This should hopefully not affect normal
5 applications.
6
7Version 4.04
8 Fixed a few tests in destest. Also added x86 assember for
9 des_ncbc_encrypt() which is the standard cbc mode function.
10 This makes a very very large performace difference.
11 Ariel Glenn ariel@columbia.edu reports that the terminal
12 'turn echo off' can return (errno == EINVAL) under solaris
13 when redirection is used. So I now catch that as well as ENOTTY.
14
15
16Version 4.03
17 Left a static out of enc_write.c, which caused to buffer to be
18 continiously malloc()ed. Does anyone use these functions? I keep
19 on feeling like removing them since I only had these in there
20 for a version of kerberised login. Anyway, this was pointed out
21 by Theo de Raadt <deraadt@cvs.openbsd.org>
22 The 'n' bit ofb code was wrong, it was not shifting the shift
23 register. It worked correctly for n == 64. Thanks to
24 Gigi Ankeny <Gigi.Ankeny@Eng.Sun.COM> for pointing this one out.
25
26Version 4.02
27 I was doing 'if (memcmp(weak_keys[i],key,sizeof(key)) == 0)'
28 when checking for weak keys which is wrong :-(, pointed out by
29 Markus F.X.J. Oberhumer <markus.oberhumer@jk.uni-linz.ac.at>.
30
31Version 4.01
32 Even faster inner loop in the DES assembler for x86 and a modification
33 for IP/FP which is faster on x86. Both of these changes are
34 from Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk>. His
35 changes make the assembler run %40 faster on a pentium. This is just
36 a case of getting the instruction sequence 'just right'.
37 All credit to 'Svend' :-)
38 Quite a few special x86 'make' targets.
39 A libdes-l (lite) distribution.
40
41Version 4.00
42 After a bit of a pause, I'll up the major version number since this
43 is mostly a performace release. I've added x86 assembler and
44 added more options for performance. A %28 speedup for gcc
45 on a pentium and the assembler is a %50 speedup.
46 MIPS CPU's, sparc and Alpha are the main CPU's with speedups.
47 Run des_opts to work out which options should be used.
48 DES_RISC1/DES_RISC2 use alternative inner loops which use
49 more registers but should give speedups on any CPU that does
50 dual issue (pentium). DES_UNROLL unrolls the inner loop,
51 which costs in code size.
52
53Version 3.26
54 I've finally removed one of the shifts in D_ENCRYPT. This
55 meant I've changed the des_SPtrans table (spr.h), the set_key()
56 function and some things in des_enc.c. This has definitly
57 made things faster :-). I've known about this one for some
58 time but I've been too lazy to follow it up :-).
59 Noticed that in the D_ENCRYPT() macro, we can just do L^=(..)^(..)^..
60 instead of L^=((..)|(..)|(..).. This should save a register at
61 least.
62 Assember for x86. The file to replace is des_enc.c, which is replaced
63 by one of the assembler files found in asm. Look at des/asm/readme
64 for more info.
65
66 /* Modification to fcrypt so it can be compiled to support
67 HPUX 10.x's long password format, define -DLONGCRYPT to use this.
68 Thanks to Jens Kupferschmidt <bt1cu@hpboot.rz.uni-leipzig.de>. */
69
70 SIGWINCH case put in des_read_passwd() so the function does not
71 'exit' if this function is recieved.
72
73Version 3.25 17/07/96
74 Modified read_pwd.c so that stdin can be read if not a tty.
75 Thanks to Jeff Barber <jeffb@issl.atl.hp.com> for the patches.
76 des_init_random_number_generator() shortened due to VMS linker
77 limits.
78 Added RSA's DESX cbc mode. It is a form of cbc encryption, with 2
79 8 byte quantites xored before and after encryption.
80 des_xcbc_encryption() - the name is funny to preserve the des_
81 prefix on all functions.
82
83Version 3.24 20/04/96
84 The DES_PTR macro option checked and used by SSLeay configuration
85
86Version 3.23 11/04/96
87 Added DES_LONG. If defined to 'unsigned int' on the DEC Alpha,
88 it gives a %20 speedup :-)
89 Fixed the problem with des.pl under perl5. The patches were
90 sent by Ed Kubaitis (ejk@uiuc.edu).
91 if fcrypt.c, changed values to handle illegal salt values the way
92 normal crypt() implementations do. Some programs apparently use
93 them :-(. The patch was sent by Bjorn Gronvall <bg@sics.se>
94
95Version 3.22 29/11/95
96 Bug in des(1), an error with the uuencoding stuff when the
97 'data' is small, thanks to Geoff Keating <keagchon@mehta.anu.edu.au>
98 for the patch.
99
100Version 3.21 22/11/95
101 After some emailing back and forth with
102 Colin Plumb <colin@nyx10.cs.du.edu>, I've tweaked a few things
103 and in a future version I will probably put in some of the
104 optimisation he suggested for use with the DES_USE_PTR option.
105 Extra routines from Mark Murray <mark@grondar.za> for use in
106 freeBSD. They mostly involve random number generation for use
107 with kerberos. They involve evil machine specific system calls
108 etc so I would normally suggest pushing this stuff into the
109 application and/or using RAND_seed()/RAND_bytes() if you are
110 using this DES library as part of SSLeay.
111 Redone the read_pw() function so that it is cleaner and
112 supports termios, thanks to Sameer Parekh <sameer@c2.org>
113 for the initial patches for this.
114 Renamed 3ecb_encrypt() to ecb3_encrypt(). This has been
115 done just to make things more consistent.
116 I have also now added triple DES versions of cfb and ofb.
117
118Version 3.20
119 Damn, Damn, Damn, as pointed out by Mike_Spreitzer.PARC@xerox.com,
120 my des_random_seed() function was only copying 4 bytes of the
121 passed seed into the init structure. It is now fixed to copy 8.
122 My own suggestion is to used something like MD5 :-)
123
124Version 3.19
125 While looking at my code one day, I though, why do I keep on
126 calling des_encrypt(in,out,ks,enc) when every function that
127 calls it has in and out the same. So I dropped the 'out'
128 parameter, people should not be using this function.
129
130Version 3.18 30/08/95
131 Fixed a few bit with the distribution and the filenames.
132 3.17 had been munged via a move to DOS and back again.
133 NO CODE CHANGES
134
135Version 3.17 14/07/95
136 Fixed ede3 cbc which I had broken in 3.16. I have also
137 removed some unneeded variables in 7-8 of the routines.
138
139Version 3.16 26/06/95
140 Added des_encrypt2() which does not use IP/FP, used by triple
141 des routines. Tweaked things a bit elsewhere. %13 speedup on
142 sparc and %6 on a R4400 for ede3 cbc mode.
143
144Version 3.15 06/06/95
145 Added des_ncbc_encrypt(), it is des_cbc mode except that it is
146 'normal' and copies the new iv value back over the top of the
147 passed parameter.
148 CHANGED des_ede3_cbc_encrypt() so that it too now overwrites
149 the iv. THIS WILL BREAK EXISTING CODE, but since this function
150 only new, I feel I can change it, not so with des_cbc_encrypt :-(.
151 I need to update the documentation.
152
153Version 3.14 31/05/95
154 New release upon the world, as part of my SSL implementation.
155 New copyright and usage stuff. Basically free for all to use
156 as long as you say it came from me :-)
157
158Version 3.13 31/05/95
159 A fix in speed.c, if HZ is not defined, I set it to 100.0
160 which is reasonable for most unixes except SunOS 4.x.
161 I now have a #ifdef sun but timing for SunOS 4.x looked very
162 good :-(. At my last job where I used SunOS 4.x, it was
163 defined to be 60.0 (look at the old INSTALL documentation), at
164 the last release had it changed to 100.0 since I now work with
165 Solaris2 and SVR4 boxes.
166 Thanks to Rory Chisholm <rchishol@math.ethz.ch> for pointing this
167 one out.
168
169Version 3.12 08/05/95
170 As pointed out by The Crypt Keeper <tck@bend.UCSD.EDU>,
171 my D_ENCRYPT macro in crypt() had an un-necessary variable.
172 It has been removed.
173
174Version 3.11 03/05/95
175 Added des_ede3_cbc_encrypt() which is cbc mode des with 3 keys
176 and one iv. It is a standard and I needed it for my SSL code.
177 It makes more sense to use this for triple DES than
178 3cbc_encrypt(). I have also added (or should I say tested :-)
179 cfb64_encrypt() which is cfb64 but it will encrypt a partial
180 number of bytes - 3 bytes in 3 bytes out. Again this is for
181 my SSL library, as a form of encryption to use with SSL
182 telnet.
183
184Version 3.10 22/03/95
185 Fixed a bug in 3cbc_encrypt() :-(. When making repeated calls
186 to cbc3_encrypt, the 2 iv values that were being returned to
187 be used in the next call were reversed :-(.
188 Many thanks to Bill Wade <wade@Stoner.COM> for pointing out
189 this error.
190
191Version 3.09 01/02/95
192 Fixed des_random_key to far more random, it was rather feeble
193 with regards to picking the initial seed. The problem was
194 pointed out by Olaf Kirch <okir@monad.swb.de>.
195
196Version 3.08 14/12/94
197 Added Makefile.PL so libdes can be built into perl5.
198 Changed des_locl.h so RAND is always defined.
199
200Version 3.07 05/12/94
201 Added GNUmake and stuff so the library can be build with
202 glibc.
203
204Version 3.06 30/08/94
205 Added rpc_enc.c which contains _des_crypt. This is for use in
206 secure_rpc v 4.0
207 Finally fixed the cfb_enc problems.
208 Fixed a few parameter parsing bugs in des (-3 and -b), thanks
209 to Rob McMillan <R.McMillan@its.gu.edu.au>
210
211Version 3.05 21/04/94
212 for unsigned long l; gcc does not produce ((l>>34) == 0)
213 This causes bugs in cfb_enc.
214 Thanks to Hadmut Danisch <danisch@ira.uka.de>
215
216Version 3.04 20/04/94
217 Added a version number to des.c and libdes.a
218
219Version 3.03 12/01/94
220 Fixed a bug in non zero iv in 3cbc_enc.
221
222Version 3.02 29/10/93
223 I now work in a place where there are 6+ architectures and 14+
224 OS versions :-).
225 Fixed TERMIO definition so the most sys V boxes will work :-)
226
227Release upon comp.sources.misc
228Version 3.01 08/10/93
229 Added des_3cbc_encrypt()
230
231Version 3.00 07/10/93
232 Fixed up documentation.
233 quad_cksum definitely compatible with MIT's now.
234
235Version 2.30 24/08/93
236 Triple DES now defaults to triple cbc but can do triple ecb
237 with the -b flag.
238 Fixed some MSDOS uuen/uudecoding problems, thanks to
239 Added prototypes.
240
241Version 2.22 29/06/93
242 Fixed a bug in des_is_weak_key() which stopped it working :-(
243 thanks to engineering@MorningStar.Com.
244
245Version 2.21 03/06/93
246 des(1) with no arguments gives quite a bit of help.
247 Added -c (generate ckecksum) flag to des(1).
248 Added -3 (triple DES) flag to des(1).
249 Added cfb and ofb routines to the library.
250
251Version 2.20 11/03/93
252 Added -u (uuencode) flag to des(1).
253 I have been playing with byte order in quad_cksum to make it
254 compatible with MIT's version. All I can say is avid this
255 function if possible since MIT's output is endian dependent.
256
257Version 2.12 14/10/92
258 Added MSDOS specific macro in ecb_encrypt which gives a %70
259 speed up when the code is compiled with turbo C.
260
261Version 2.11 12/10/92
262 Speedup in set_key (recoding of PC-1)
263 I now do it in 47 simple operations, down from 60.
264 Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov)
265 for motivating me to look for a faster system :-)
266 The speedup is probably less that 1% but it is still 13
267 instructions less :-).
268
269Version 2.10 06/10/92
270 The code now works on the 64bit ETA10 and CRAY without modifications or
271 #defines. I believe the code should work on any machine that
272 defines long, int or short to be 8 bytes long.
273 Thanks to Shabbir J. Safdar (shabby@mentor.cc.purdue.edu)
274 for helping me fix the code to run on 64bit machines (he had
275 access to an ETA10).
276 Thanks also to John Fletcher <john_fletcher@lccmail.ocf.llnl.gov>
277 for testing the routines on a CRAY.
278 read_password.c has been renamed to read_passwd.c
279 string_to_key.c has been renamed to string2key.c
280
281Version 2.00 14/09/92
282 Made mods so that the library should work on 64bit CPU's.
283 Removed all my uchar and ulong defs. To many different
284 versions of unix define them in their header files in too many
285 different combinations :-)
286 IRIX - Sillicon Graphics mods (mostly in read_password.c).
287 Thanks to Andrew Daviel (advax@erich.triumf.ca)
288
289Version 1.99 26/08/92
290 Fixed a bug or 2 in enc_read.c
291 Fixed a bug in enc_write.c
292 Fixed a pseudo bug in fcrypt.c (very obscure).
293
294Version 1.98 31/07/92
295 Support for the ETA10. This is a strange machine that defines
296 longs and ints as 8 bytes and shorts as 4 bytes.
297 Since I do evil things with long * that assume that they are 4
298 bytes. Look in the Makefile for the option to compile for
299 this machine. quad_cksum appears to have problems but I
300 will don't have the time to fix it right now, and this is not
301 a function that uses DES and so will not effect the main uses
302 of the library.
303
304Version 1.97 20/05/92 eay
305 Fixed the Imakefile and made some changes to des.h to fix some
306 problems when building this package with Kerberos v 4.
307
308Version 1.96 18/05/92 eay
309 Fixed a small bug in string_to_key() where problems could
310 occur if des_check_key was set to true and the string
311 generated a weak key.
312
313Patch2 posted to comp.sources.misc
314Version 1.95 13/05/92 eay
315 Added an alternative version of the D_ENCRYPT macro in
316 ecb_encrypt and fcrypt. Depending on the compiler, one version or the
317 other will be faster. This was inspired by
318 Dana How <how@isl.stanford.edu>, and her pointers about doing the
319 *(ulong *)((uchar *)ptr+(value&0xfc))
320 vs
321 ptr[value&0x3f]
322 to stop the C compiler doing a <<2 to convert the long array index.
323
324Version 1.94 05/05/92 eay
325 Fixed an incompatibility between my string_to_key and the MIT
326 version. When the key is longer than 8 chars, I was wrapping
327 with a different method. To use the old version, define
328 OLD_STR_TO_KEY in the makefile. Thanks to
329 viktor@newsu.shearson.com (Viktor Dukhovni).
330
331Version 1.93 28/04/92 eay
332 Fixed the VMS mods so that echo is now turned off in
333 read_password. Thanks again to brennan@coco.cchs.su.oz.AU.
334 MSDOS support added. The routines can be compiled with
335 Turbo C (v2.0) and MSC (v5.1). Make sure MSDOS is defined.
336
337Patch1 posted to comp.sources.misc
338Version 1.92 13/04/92 eay
339 Changed D_ENCRYPT so that the rotation of R occurs outside of
340 the loop. This required rotating all the longs in sp.h (now
341 called spr.h). Thanks to Richard Outerbridge <71755.204@CompuServe.COM>
342 speed.c has been changed so it will work without SIGALRM. If
343 times(3) is not present it will try to use ftime() instead.
344
345Version 1.91 08/04/92 eay
346 Added -E/-D options to des(1) so it can use string_to_key.
347 Added SVR4 mods suggested by witr@rwwa.COM
348 Added VMS mods suggested by brennan@coco.cchs.su.oz.AU. If
349 anyone knows how to turn of tty echo in VMS please tell me or
350 implement it yourself :-).
351 Changed FILE *IN/*OUT to *DES_IN/*DES_OUT since it appears VMS
352 does not like IN/OUT being used.
353
354Libdes posted to comp.sources.misc
355Version 1.9 24/03/92 eay
356 Now contains a fast small crypt replacement.
357 Added des(1) command.
358 Added des_rw_mode so people can use cbc encryption with
359 enc_read and enc_write.
360
361Version 1.8 15/10/91 eay
362 Bug in cbc_cksum.
363 Many thanks to Keith Reynolds (keithr@sco.COM) for pointing this
364 one out.
365
366Version 1.7 24/09/91 eay
367 Fixed set_key :-)
368 set_key is 4 times faster and takes less space.
369 There are a few minor changes that could be made.
370
371Version 1.6 19/09/1991 eay
372 Finally go IP and FP finished.
373 Now I need to fix set_key.
374 This version is quite a bit faster that 1.51
375
376Version 1.52 15/06/1991 eay
377 20% speedup in ecb_encrypt by changing the E bit selection
378 to use 2 32bit words. This also required modification of the
379 sp table. There is still a way to speedup the IP and IP-1
380 (hints from outer@sq.com) still working on this one :-(.
381
382Version 1.51 07/06/1991 eay
383 Faster des_encrypt by loop unrolling
384 Fixed bug in quad_cksum.c (thanks to hughes@logos.ucs.indiana.edu)
385
386Version 1.50 28/05/1991 eay
387 Optimised the code a bit more for the sparc. I have improved the
388 speed of the inner des_encrypt by speeding up the initial and
389 final permutations.
390
391Version 1.40 23/10/1990 eay
392 Fixed des_random_key, it did not produce a random key :-(
393
394Version 1.30 2/10/1990 eay
395 Have made des_quad_cksum the same as MIT's, the full package
396 should be compatible with MIT's
397 Have tested on a DECstation 3100
398 Still need to fix des_set_key (make it faster).
399 Does des_cbc_encrypts at 70.5k/sec on a 3100.
400
401Version 1.20 18/09/1990 eay
402 Fixed byte order dependencies.
403 Fixed (I hope) all the word alignment problems.
404 Speedup in des_ecb_encrypt.
405
406Version 1.10 11/09/1990 eay
407 Added des_enc_read and des_enc_write.
408 Still need to fix des_quad_cksum.
409 Still need to document des_enc_read and des_enc_write.
410
411Version 1.00 27/08/1990 eay
412
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl
index b75d3c6b3a..60d577cc8d 100644
--- a/src/lib/libcrypto/des/asm/des-586.pl
+++ b/src/lib/libcrypto/des/asm/des-586.pl
@@ -22,10 +22,14 @@ $R="esi";
22&external_label("DES_SPtrans"); 22&external_label("DES_SPtrans");
23&DES_encrypt("DES_encrypt1",1); 23&DES_encrypt("DES_encrypt1",1);
24&DES_encrypt("DES_encrypt2",0); 24&DES_encrypt("DES_encrypt2",0);
25&DES_encrypt3("DES_encrypt3",1); 25
26&DES_encrypt3("DES_decrypt3",0); 26if (!$main'openbsd)
27&cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1); 27 {
28&cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5); 28 &DES_encrypt3("DES_encrypt3",1);
29 &DES_encrypt3("DES_decrypt3",0);
30 &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1);
31 &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5);
32 }
29 33
30&asm_finish(); 34&asm_finish();
31 35
diff --git a/src/lib/libcrypto/des/asm/des686.pl b/src/lib/libcrypto/des/asm/des686.pl
new file mode 100644
index 0000000000..d3ad5d5edd
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/des686.pl
@@ -0,0 +1,230 @@
1#!/usr/local/bin/perl
2
3$prog="des686.pl";
4
5# base code is in microsft
6# op dest, source
7# format.
8#
9
10# WILL NOT WORK ANYMORE WITH desboth.pl
11require "desboth.pl";
12
13if ( ($ARGV[0] eq "elf"))
14 { require "x86unix.pl"; }
15elsif ( ($ARGV[0] eq "a.out"))
16 { $aout=1; require "x86unix.pl"; }
17elsif ( ($ARGV[0] eq "sol"))
18 { $sol=1; require "x86unix.pl"; }
19elsif ( ($ARGV[0] eq "cpp"))
20 { $cpp=1; require "x86unix.pl"; }
21elsif ( ($ARGV[0] eq "win32"))
22 { require "x86ms.pl"; }
23else
24 {
25 print STDERR <<"EOF";
26Pick one target type from
27 elf - linux, FreeBSD etc
28 a.out - old linux
29 sol - x86 solaris
30 cpp - format so x86unix.cpp can be used
31 win32 - Windows 95/Windows NT
32EOF
33 exit(1);
34 }
35
36&comment("Don't even think of reading this code");
37&comment("It was automatically generated by $prog");
38&comment("Which is a perl program used to generate the x86 assember for");
39&comment("any of elf, a.out, Win32, or Solaris");
40&comment("It can be found in SSLeay 0.6.5+ or in libdes 3.26+");
41&comment("eric <eay\@cryptsoft.com>");
42&comment("");
43
44&file("dx86xxxx");
45
46$L="edi";
47$R="esi";
48
49&DES_encrypt("DES_encrypt1",1);
50&DES_encrypt("DES_encrypt2",0);
51
52&DES_encrypt3("DES_encrypt3",1);
53&DES_encrypt3("DES_decrypt3",0);
54
55&file_end();
56
57sub DES_encrypt
58 {
59 local($name,$do_ip)=@_;
60
61 &function_begin($name,"EXTRN _DES_SPtrans:DWORD");
62
63 &comment("");
64 &comment("Load the 2 words");
65 &mov("eax",&wparam(0));
66 &mov($L,&DWP(0,"eax","",0));
67 &mov($R,&DWP(4,"eax","",0));
68
69 $ksp=&wparam(1);
70
71 if ($do_ip)
72 {
73 &comment("");
74 &comment("IP");
75 &IP_new($L,$R,"eax");
76 }
77
78 &comment("");
79 &comment("fixup rotate");
80 &rotl($R,3);
81 &rotl($L,3);
82 &exch($L,$R);
83
84 &comment("");
85 &comment("load counter, key_schedule and enc flag");
86 &mov("eax",&wparam(2)); # get encrypt flag
87 &mov("ebp",&wparam(1)); # get ks
88 &cmp("eax","0");
89 &je(&label("start_decrypt"));
90
91 # encrypting part
92
93 for ($i=0; $i<16; $i+=2)
94 {
95 &comment("");
96 &comment("Round $i");
97 &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
98
99 &comment("");
100 &comment("Round ".sprintf("%d",$i+1));
101 &D_ENCRYPT($R,$L,($i+1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
102 }
103 &jmp(&label("end"));
104
105 &set_label("start_decrypt");
106
107 for ($i=15; $i>0; $i-=2)
108 {
109 &comment("");
110 &comment("Round $i");
111 &D_ENCRYPT($L,$R,$i*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
112 &comment("");
113 &comment("Round ".sprintf("%d",$i-1));
114 &D_ENCRYPT($R,$L,($i-1)*2,"ebp","DES_SPtrans","ecx","edx","eax","ebx");
115 }
116
117 &set_label("end");
118
119 &comment("");
120 &comment("Fixup");
121 &rotr($L,3); # r
122 &rotr($R,3); # l
123
124 if ($do_ip)
125 {
126 &comment("");
127 &comment("FP");
128 &FP_new($R,$L,"eax");
129 }
130
131 &mov("eax",&wparam(0));
132 &mov(&DWP(0,"eax","",0),$L);
133 &mov(&DWP(4,"eax","",0),$R);
134
135 &function_end($name);
136 }
137
138
139# The logic is to load R into 2 registers and operate on both at the same time.
140# We also load the 2 R's into 2 more registers so we can do the 'move word down a byte'
141# while also masking the other copy and doing a lookup. We then also accumulate the
142# L value in 2 registers then combine them at the end.
143sub D_ENCRYPT
144 {
145 local($L,$R,$S,$ks,$desSP,$u,$t,$tmp1,$tmp2,$tmp3)=@_;
146
147 &mov( $u, &DWP(&n2a($S*4),$ks,"",0));
148 &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0));
149 &xor( $u, $R );
150 &xor( $t, $R );
151 &rotr( $t, 4 );
152
153 # the numbers at the end of the line are origional instruction order
154 &mov( $tmp2, $u ); # 1 2
155 &mov( $tmp1, $t ); # 1 1
156 &and( $tmp2, "0xfc" ); # 1 4
157 &and( $tmp1, "0xfc" ); # 1 3
158 &shr( $t, 8 ); # 1 5
159 &xor( $L, &DWP("0x100+$desSP",$tmp1,"",0)); # 1 7
160 &shr( $u, 8 ); # 1 6
161 &mov( $tmp1, &DWP(" $desSP",$tmp2,"",0)); # 1 8
162
163 &mov( $tmp2, $u ); # 2 2
164 &xor( $L, $tmp1 ); # 1 9
165 &and( $tmp2, "0xfc" ); # 2 4
166 &mov( $tmp1, $t ); # 2 1
167 &and( $tmp1, "0xfc" ); # 2 3
168 &shr( $t, 8 ); # 2 5
169 &xor( $L, &DWP("0x300+$desSP",$tmp1,"",0)); # 2 7
170 &shr( $u, 8 ); # 2 6
171 &mov( $tmp1, &DWP("0x200+$desSP",$tmp2,"",0)); # 2 8
172 &mov( $tmp2, $u ); # 3 2
173
174 &xor( $L, $tmp1 ); # 2 9
175 &and( $tmp2, "0xfc" ); # 3 4
176
177 &mov( $tmp1, $t ); # 3 1
178 &shr( $u, 8 ); # 3 6
179 &and( $tmp1, "0xfc" ); # 3 3
180 &shr( $t, 8 ); # 3 5
181 &xor( $L, &DWP("0x500+$desSP",$tmp1,"",0)); # 3 7
182 &mov( $tmp1, &DWP("0x400+$desSP",$tmp2,"",0)); # 3 8
183
184 &and( $t, "0xfc" ); # 4 1
185 &xor( $L, $tmp1 ); # 3 9
186
187 &and( $u, "0xfc" ); # 4 2
188 &xor( $L, &DWP("0x700+$desSP",$t,"",0)); # 4 3
189 &xor( $L, &DWP("0x600+$desSP",$u,"",0)); # 4 4
190 }
191
192sub PERM_OP
193 {
194 local($a,$b,$tt,$shift,$mask)=@_;
195
196 &mov( $tt, $a );
197 &shr( $tt, $shift );
198 &xor( $tt, $b );
199 &and( $tt, $mask );
200 &xor( $b, $tt );
201 &shl( $tt, $shift );
202 &xor( $a, $tt );
203 }
204
205sub IP_new
206 {
207 local($l,$r,$tt)=@_;
208
209 &PERM_OP($r,$l,$tt, 4,"0x0f0f0f0f");
210 &PERM_OP($l,$r,$tt,16,"0x0000ffff");
211 &PERM_OP($r,$l,$tt, 2,"0x33333333");
212 &PERM_OP($l,$r,$tt, 8,"0x00ff00ff");
213 &PERM_OP($r,$l,$tt, 1,"0x55555555");
214 }
215
216sub FP_new
217 {
218 local($l,$r,$tt)=@_;
219
220 &PERM_OP($l,$r,$tt, 1,"0x55555555");
221 &PERM_OP($r,$l,$tt, 8,"0x00ff00ff");
222 &PERM_OP($l,$r,$tt, 2,"0x33333333");
223 &PERM_OP($r,$l,$tt,16,"0x0000ffff");
224 &PERM_OP($l,$r,$tt, 4,"0x0f0f0f0f");
225 }
226
227sub n2a
228 {
229 sprintf("%d",$_[0]);
230 }
diff --git a/src/lib/libcrypto/des/asm/readme b/src/lib/libcrypto/des/asm/readme
new file mode 100644
index 0000000000..1beafe253b
--- /dev/null
+++ b/src/lib/libcrypto/des/asm/readme
@@ -0,0 +1,131 @@
1First up, let me say I don't like writing in assembler. It is not portable,
2dependant on the particular CPU architecture release and is generally a pig
3to debug and get right. Having said that, the x86 architecture is probably
4the most important for speed due to number of boxes and since
5it appears to be the worst architecture to to get
6good C compilers for. So due to this, I have lowered myself to do
7assembler for the inner DES routines in libdes :-).
8
9The file to implement in assembler is des_enc.c. Replace the following
104 functions
11des_encrypt1(DES_LONG data[2],des_key_schedule ks, int encrypt);
12des_encrypt2(DES_LONG data[2],des_key_schedule ks, int encrypt);
13des_encrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
14des_decrypt3(DES_LONG data[2],des_key_schedule ks1,ks2,ks3);
15
16They encrypt/decrypt the 64 bits held in 'data' using
17the 'ks' key schedules. The only difference between the 4 functions is that
18des_encrypt2() does not perform IP() or FP() on the data (this is an
19optimization for when doing triple DES and des_encrypt3() and des_decrypt3()
20perform triple des. The triple DES routines are in here because it does
21make a big difference to have them located near the des_encrypt2 function
22at link time..
23
24Now as we all know, there are lots of different operating systems running on
25x86 boxes, and unfortunately they normally try to make sure their assembler
26formating is not the same as the other peoples.
27The 4 main formats I know of are
28Microsoft Windows 95/Windows NT
29Elf Includes Linux and FreeBSD(?).
30a.out The older Linux.
31Solaris Same as Elf but different comments :-(.
32
33Now I was not overly keen to write 4 different copies of the same code,
34so I wrote a few perl routines to output the correct assembler, given
35a target assembler type. This code is ugly and is just a hack.
36The libraries are x86unix.pl and x86ms.pl.
37des586.pl, des686.pl and des-som[23].pl are the programs to actually
38generate the assembler.
39
40So to generate elf assembler
41perl des-som3.pl elf >dx86-elf.s
42For Windows 95/NT
43perl des-som2.pl win32 >win32.asm
44
45[ update 4 Jan 1996 ]
46I have added another way to do things.
47perl des-som3.pl cpp >dx86-cpp.s
48generates a file that will be included by dx86unix.cpp when it is compiled.
49To build for elf, a.out, solaris, bsdi etc,
50cc -E -DELF asm/dx86unix.cpp | as -o asm/dx86-elf.o
51cc -E -DSOL asm/dx86unix.cpp | as -o asm/dx86-sol.o
52cc -E -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o
53cc -E -DBSDI asm/dx86unix.cpp | as -o asm/dx86bsdi.o
54This was done to cut down the number of files in the distribution.
55
56Now the ugly part. I acquired my copy of Intels
57"Optimization's For Intel's 32-Bit Processors" and found a few interesting
58things. First, the aim of the exersize is to 'extract' one byte at a time
59from a word and do an array lookup. This involves getting the byte from
60the 4 locations in the word and moving it to a new word and doing the lookup.
61The most obvious way to do this is
62xor eax, eax # clear word
63movb al, cl # get low byte
64xor edi DWORD PTR 0x100+des_SP[eax] # xor in word
65movb al, ch # get next byte
66xor edi DWORD PTR 0x300+des_SP[eax] # xor in word
67shr ecx 16
68which seems ok. For the pentium, this system appears to be the best.
69One has to do instruction interleaving to keep both functional units
70operating, but it is basically very efficient.
71
72Now the crunch. When a full register is used after a partial write, eg.
73mov al, cl
74xor edi, DWORD PTR 0x100+des_SP[eax]
75386 - 1 cycle stall
76486 - 1 cycle stall
77586 - 0 cycle stall
78686 - at least 7 cycle stall (page 22 of the above mentioned document).
79
80So the technique that produces the best results on a pentium, according to
81the documentation, will produce hideous results on a pentium pro.
82
83To get around this, des686.pl will generate code that is not as fast on
84a pentium, should be very good on a pentium pro.
85mov eax, ecx # copy word
86shr ecx, 8 # line up next byte
87and eax, 0fch # mask byte
88xor edi DWORD PTR 0x100+des_SP[eax] # xor in array lookup
89mov eax, ecx # get word
90shr ecx 8 # line up next byte
91and eax, 0fch # mask byte
92xor edi DWORD PTR 0x300+des_SP[eax] # xor in array lookup
93
94Due to the execution units in the pentium, this actually works quite well.
95For a pentium pro it should be very good. This is the type of output
96Visual C++ generates.
97
98There is a third option. instead of using
99mov al, ch
100which is bad on the pentium pro, one may be able to use
101movzx eax, ch
102which may not incur the partial write penalty. On the pentium,
103this instruction takes 4 cycles so is not worth using but on the
104pentium pro it appears it may be worth while. I need access to one to
105experiment :-).
106
107eric (20 Oct 1996)
108
10922 Nov 1996 - I have asked people to run the 2 different version on pentium
110pros and it appears that the intel documentation is wrong. The
111mov al,bh is still faster on a pentium pro, so just use the des586.pl
112install des686.pl
113
1143 Dec 1996 - I added des_encrypt3/des_decrypt3 because I have moved these
115functions into des_enc.c because it does make a massive performance
116difference on some boxes to have the functions code located close to
117the des_encrypt2() function.
118
1199 Jan 1997 - des-som2.pl is now the correct perl script to use for
120pentiums. It contains an inner loop from
121Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> which does raw ecb DES calls at
122273,000 per second. He had a previous version at 250,000 and the best
123I was able to get was 203,000. The content has not changed, this is all
124due to instruction sequencing (and actual instructions choice) which is able
125to keep both functional units of the pentium going.
126We may have lost the ugly register usage restrictions when x86 went 32 bit
127but for the pentium it has been replaced by evil instruction ordering tricks.
128
12913 Jan 1997 - des-som3.pl, more optimizations from Svend Olaf.
130raw DES at 281,000 per second on a pentium 100.
131
diff --git a/src/lib/libcrypto/des/cbc3_enc.c b/src/lib/libcrypto/des/cbc3_enc.c
new file mode 100644
index 0000000000..b5db4e14f7
--- /dev/null
+++ b/src/lib/libcrypto/des/cbc3_enc.c
@@ -0,0 +1,99 @@
1/* crypto/des/cbc3_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include "des_locl.h"
60
61/* HAS BUGS! DON'T USE - this is only present for use in des.c */
62void DES_3cbc_encrypt(DES_cblock *input, DES_cblock *output, long length,
63 DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock *iv1,
64 DES_cblock *iv2, int enc)
65 {
66 int off=((int)length-1)/8;
67 long l8=((length+7)/8)*8;
68 DES_cblock niv1,niv2;
69
70 if (enc == DES_ENCRYPT)
71 {
72 DES_cbc_encrypt((unsigned char*)input,
73 (unsigned char*)output,length,&ks1,iv1,enc);
74 if (length >= sizeof(DES_cblock))
75 memcpy(niv1,output[off],sizeof(DES_cblock));
76 DES_cbc_encrypt((unsigned char*)output,
77 (unsigned char*)output,l8,&ks2,iv1,!enc);
78 DES_cbc_encrypt((unsigned char*)output,
79 (unsigned char*)output,l8,&ks1,iv2,enc);
80 if (length >= sizeof(DES_cblock))
81 memcpy(niv2,output[off],sizeof(DES_cblock));
82 }
83 else
84 {
85 if (length >= sizeof(DES_cblock))
86 memcpy(niv2,input[off],sizeof(DES_cblock));
87 DES_cbc_encrypt((unsigned char*)input,
88 (unsigned char*)output,l8,&ks1,iv2,enc);
89 DES_cbc_encrypt((unsigned char*)output,
90 (unsigned char*)output,l8,&ks2,iv1,!enc);
91 if (length >= sizeof(DES_cblock))
92 memcpy(niv1,output[off],sizeof(DES_cblock));
93 DES_cbc_encrypt((unsigned char*)output,
94 (unsigned char*)output,length,&ks1,iv1,enc);
95 }
96 memcpy(*iv1,niv1,sizeof(DES_cblock));
97 memcpy(*iv2,niv2,sizeof(DES_cblock));
98 }
99
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c
index de34ecceb9..f3c6018528 100644
--- a/src/lib/libcrypto/des/cfb64ede.c
+++ b/src/lib/libcrypto/des/cfb64ede.c
@@ -152,8 +152,8 @@ void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out,
152 DES_cblock *ivec,int enc) 152 DES_cblock *ivec,int enc)
153 { 153 {
154 register DES_LONG d0,d1,v0,v1; 154 register DES_LONG d0,d1,v0,v1;
155 register unsigned long l=length,n=((unsigned int)numbits+7)/8; 155 register long l=length;
156 register int num=numbits,i; 156 register int num=numbits,n=(numbits+7)/8,i;
157 DES_LONG ti[2]; 157 DES_LONG ti[2];
158 unsigned char *iv; 158 unsigned char *iv;
159 unsigned char ovec[16]; 159 unsigned char ovec[16];
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c
index 720f29a28e..03cabb223c 100644
--- a/src/lib/libcrypto/des/cfb_enc.c
+++ b/src/lib/libcrypto/des/cfb_enc.c
@@ -58,7 +58,6 @@
58 58
59#include "e_os.h" 59#include "e_os.h"
60#include "des_locl.h" 60#include "des_locl.h"
61#include <assert.h>
62 61
63/* The input and output are loaded in multiples of 8 bits. 62/* The input and output are loaded in multiples of 8 bits.
64 * What this means is that if you hame numbits=12 and length=2 63 * What this means is that if you hame numbits=12 and length=2
@@ -73,29 +72,19 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
73 int enc) 72 int enc)
74 { 73 {
75 register DES_LONG d0,d1,v0,v1; 74 register DES_LONG d0,d1,v0,v1;
76 register unsigned long l=length; 75 register unsigned long l=length,n=(numbits+7)/8;
77 register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8; 76 register int num=numbits,i;
78 DES_LONG ti[2]; 77 DES_LONG ti[2];
79 unsigned char *iv; 78 unsigned char *iv;
80#ifndef L_ENDIAN
81 unsigned char ovec[16]; 79 unsigned char ovec[16];
82#else
83 unsigned int sh[4];
84 unsigned char *ovec=(unsigned char *)sh;
85 80
86 /* I kind of count that compiler optimizes away this assertioni,*/ 81 if (num > 64) return;
87 assert (sizeof(sh[0])==4); /* as this holds true for all, */
88 /* but 16-bit platforms... */
89
90#endif
91
92 if (numbits<=0 || numbits > 64) return;
93 iv = &(*ivec)[0]; 82 iv = &(*ivec)[0];
94 c2l(iv,v0); 83 c2l(iv,v0);
95 c2l(iv,v1); 84 c2l(iv,v1);
96 if (enc) 85 if (enc)
97 { 86 {
98 while (l >= (unsigned long)n) 87 while (l >= n)
99 { 88 {
100 l-=n; 89 l-=n;
101 ti[0]=v0; 90 ti[0]=v0;
@@ -109,40 +98,35 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
109 out+=n; 98 out+=n;
110 /* 30-08-94 - eay - changed because l>>32 and 99 /* 30-08-94 - eay - changed because l>>32 and
111 * l<<32 are bad under gcc :-( */ 100 * l<<32 are bad under gcc :-( */
112 if (numbits == 32) 101 if (num == 32)
113 { v0=v1; v1=d0; } 102 { v0=v1; v1=d0; }
114 else if (numbits == 64) 103 else if (num == 64)
115 { v0=d0; v1=d1; } 104 { v0=d0; v1=d1; }
116 else 105 else
117 { 106 {
118#ifndef L_ENDIAN
119 iv=&ovec[0]; 107 iv=&ovec[0];
120 l2c(v0,iv); 108 l2c(v0,iv);
121 l2c(v1,iv); 109 l2c(v1,iv);
122 l2c(d0,iv); 110 l2c(d0,iv);
123 l2c(d1,iv); 111 l2c(d1,iv);
124#else 112 /* shift ovec left most of the bits... */
125 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; 113 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
126#endif 114 /* now the remaining bits */
127 if (rem==0) 115 if(num%8 != 0)
128 memmove(ovec,ovec+num,8);
129 else
130 for(i=0 ; i < 8 ; ++i) 116 for(i=0 ; i < 8 ; ++i)
131 ovec[i]=ovec[i+num]<<rem | 117 {
132 ovec[i+num+1]>>(8-rem); 118 ovec[i]<<=num%8;
133#ifdef L_ENDIAN 119 ovec[i]|=ovec[i+1]>>(8-num%8);
134 v0=sh[0], v1=sh[1]; 120 }
135#else
136 iv=&ovec[0]; 121 iv=&ovec[0];
137 c2l(iv,v0); 122 c2l(iv,v0);
138 c2l(iv,v1); 123 c2l(iv,v1);
139#endif
140 } 124 }
141 } 125 }
142 } 126 }
143 else 127 else
144 { 128 {
145 while (l >= (unsigned long)n) 129 while (l >= n)
146 { 130 {
147 l-=n; 131 l-=n;
148 ti[0]=v0; 132 ti[0]=v0;
@@ -152,34 +136,29 @@ void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits,
152 in+=n; 136 in+=n;
153 /* 30-08-94 - eay - changed because l>>32 and 137 /* 30-08-94 - eay - changed because l>>32 and
154 * l<<32 are bad under gcc :-( */ 138 * l<<32 are bad under gcc :-( */
155 if (numbits == 32) 139 if (num == 32)
156 { v0=v1; v1=d0; } 140 { v0=v1; v1=d0; }
157 else if (numbits == 64) 141 else if (num == 64)
158 { v0=d0; v1=d1; } 142 { v0=d0; v1=d1; }
159 else 143 else
160 { 144 {
161#ifndef L_ENDIAN
162 iv=&ovec[0]; 145 iv=&ovec[0];
163 l2c(v0,iv); 146 l2c(v0,iv);
164 l2c(v1,iv); 147 l2c(v1,iv);
165 l2c(d0,iv); 148 l2c(d0,iv);
166 l2c(d1,iv); 149 l2c(d1,iv);
167#else 150 /* shift ovec left most of the bits... */
168 sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; 151 memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0));
169#endif 152 /* now the remaining bits */
170 if (rem==0) 153 if(num%8 != 0)
171 memmove(ovec,ovec+num,8);
172 else
173 for(i=0 ; i < 8 ; ++i) 154 for(i=0 ; i < 8 ; ++i)
174 ovec[i]=ovec[i+num]<<rem | 155 {
175 ovec[i+num+1]>>(8-rem); 156 ovec[i]<<=num%8;
176#ifdef L_ENDIAN 157 ovec[i]|=ovec[i+1]>>(8-num%8);
177 v0=sh[0], v1=sh[1]; 158 }
178#else
179 iv=&ovec[0]; 159 iv=&ovec[0];
180 c2l(iv,v0); 160 c2l(iv,v0);
181 c2l(iv,v1); 161 c2l(iv,v1);
182#endif
183 } 162 }
184 d0^=ti[0]; 163 d0^=ti[0];
185 d1^=ti[1]; 164 d1^=ti[1];
diff --git a/src/lib/libcrypto/des/des-lib.com b/src/lib/libcrypto/des/des-lib.com
new file mode 100644
index 0000000000..fc2c35a1ce
--- /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 = ""
850$ IF F$TYPE(USER_CCDEFS) .NES. "" THEN 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
new file mode 100644
index 0000000000..343135ff9e
--- /dev/null
+++ b/src/lib/libcrypto/des/des.c
@@ -0,0 +1,932 @@
1/* crypto/des/des.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/opensslconf.h>
63#ifndef OPENSSL_SYS_MSDOS
64#ifndef OPENSSL_SYS_VMS
65#include OPENSSL_UNISTD
66#else /* OPENSSL_SYS_VMS */
67#ifdef __DECC
68#include <unistd.h>
69#else /* not __DECC */
70#include <math.h>
71#endif /* __DECC */
72#endif /* OPENSSL_SYS_VMS */
73#else /* OPENSSL_SYS_MSDOS */
74#include <io.h>
75#endif
76
77#include <time.h>
78#include "des_ver.h"
79
80#ifdef OPENSSL_SYS_VMS
81#include <types.h>
82#include <stat.h>
83#else
84#ifndef _IRIX
85#include <sys/types.h>
86#endif
87#include <sys/stat.h>
88#endif
89#include <openssl/des.h>
90#include <openssl/rand.h>
91#include <openssl/ui_compat.h>
92
93void usage(void);
94void doencryption(void);
95int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp);
96void uufwriteEnd(FILE *fp);
97int uufread(unsigned char *out,int size,unsigned int num,FILE *fp);
98int uuencode(unsigned char *in,int num,unsigned char *out);
99int uudecode(unsigned char *in,int num,unsigned char *out);
100void DES_3cbc_encrypt(DES_cblock *input,DES_cblock *output,long length,
101 DES_key_schedule sk1,DES_key_schedule sk2,
102 DES_cblock *ivec1,DES_cblock *ivec2,int enc);
103#ifdef OPENSSL_SYS_VMS
104#define EXIT(a) exit(a&0x10000000L)
105#else
106#define EXIT(a) exit(a)
107#endif
108
109#define BUFSIZE (8*1024)
110#define VERIFY 1
111#define KEYSIZ 8
112#define KEYSIZB 1024 /* should hit tty line limit first :-) */
113char key[KEYSIZB+1];
114int do_encrypt,longk=0;
115FILE *DES_IN,*DES_OUT,*CKSUM_OUT;
116char uuname[200];
117unsigned char uubuf[50];
118int uubufnum=0;
119#define INUUBUFN (45*100)
120#define OUTUUBUF (65*100)
121unsigned char b[OUTUUBUF];
122unsigned char bb[300];
123DES_cblock cksum={0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
124char cksumname[200]="";
125
126int vflag,cflag,eflag,dflag,kflag,bflag,fflag,sflag,uflag,flag3,hflag,error;
127
128int main(int argc, char **argv)
129 {
130 int i;
131 struct stat ins,outs;
132 char *p;
133 char *in=NULL,*out=NULL;
134
135 vflag=cflag=eflag=dflag=kflag=hflag=bflag=fflag=sflag=uflag=flag3=0;
136 error=0;
137 memset(key,0,sizeof(key));
138
139 for (i=1; i<argc; i++)
140 {
141 p=argv[i];
142 if ((p[0] == '-') && (p[1] != '\0'))
143 {
144 p++;
145 while (*p)
146 {
147 switch (*(p++))
148 {
149 case '3':
150 flag3=1;
151 longk=1;
152 break;
153 case 'c':
154 cflag=1;
155 strncpy(cksumname,p,200);
156 cksumname[sizeof(cksumname)-1]='\0';
157 p+=strlen(cksumname);
158 break;
159 case 'C':
160 cflag=1;
161 longk=1;
162 strncpy(cksumname,p,200);
163 cksumname[sizeof(cksumname)-1]='\0';
164 p+=strlen(cksumname);
165 break;
166 case 'e':
167 eflag=1;
168 break;
169 case 'v':
170 vflag=1;
171 break;
172 case 'E':
173 eflag=1;
174 longk=1;
175 break;
176 case 'd':
177 dflag=1;
178 break;
179 case 'D':
180 dflag=1;
181 longk=1;
182 break;
183 case 'b':
184 bflag=1;
185 break;
186 case 'f':
187 fflag=1;
188 break;
189 case 's':
190 sflag=1;
191 break;
192 case 'u':
193 uflag=1;
194 strncpy(uuname,p,200);
195 uuname[sizeof(uuname)-1]='\0';
196 p+=strlen(uuname);
197 break;
198 case 'h':
199 hflag=1;
200 break;
201 case 'k':
202 kflag=1;
203 if ((i+1) == argc)
204 {
205 fputs("must have a key with the -k option\n",stderr);
206 error=1;
207 }
208 else
209 {
210 int j;
211
212 i++;
213 strncpy(key,argv[i],KEYSIZB);
214 for (j=strlen(argv[i])-1; j>=0; j--)
215 argv[i][j]='\0';
216 }
217 break;
218 default:
219 fprintf(stderr,"'%c' unknown flag\n",p[-1]);
220 error=1;
221 break;
222 }
223 }
224 }
225 else
226 {
227 if (in == NULL)
228 in=argv[i];
229 else if (out == NULL)
230 out=argv[i];
231 else
232 error=1;
233 }
234 }
235 if (error) usage();
236 /* We either
237 * do checksum or
238 * do encrypt or
239 * do decrypt or
240 * do decrypt then ckecksum or
241 * do checksum then encrypt
242 */
243 if (((eflag+dflag) == 1) || cflag)
244 {
245 if (eflag) do_encrypt=DES_ENCRYPT;
246 if (dflag) do_encrypt=DES_DECRYPT;
247 }
248 else
249 {
250 if (vflag)
251 {
252#ifndef _Windows
253 fprintf(stderr,"des(1) built with %s\n",libdes_version);
254#endif
255 EXIT(1);
256 }
257 else usage();
258 }
259
260#ifndef _Windows
261 if (vflag) fprintf(stderr,"des(1) built with %s\n",libdes_version);
262#endif
263 if ( (in != NULL) &&
264 (out != NULL) &&
265#ifndef OPENSSL_SYS_MSDOS
266 (stat(in,&ins) != -1) &&
267 (stat(out,&outs) != -1) &&
268 (ins.st_dev == outs.st_dev) &&
269 (ins.st_ino == outs.st_ino))
270#else /* OPENSSL_SYS_MSDOS */
271 (strcmp(in,out) == 0))
272#endif
273 {
274 fputs("input and output file are the same\n",stderr);
275 EXIT(3);
276 }
277
278 if (!kflag)
279 if (des_read_pw_string(key,KEYSIZB+1,"Enter key:",eflag?VERIFY:0))
280 {
281 fputs("password error\n",stderr);
282 EXIT(2);
283 }
284
285 if (in == NULL)
286 DES_IN=stdin;
287 else if ((DES_IN=fopen(in,"r")) == NULL)
288 {
289 perror("opening input file");
290 EXIT(4);
291 }
292
293 CKSUM_OUT=stdout;
294 if (out == NULL)
295 {
296 DES_OUT=stdout;
297 CKSUM_OUT=stderr;
298 }
299 else if ((DES_OUT=fopen(out,"w")) == NULL)
300 {
301 perror("opening output file");
302 EXIT(5);
303 }
304
305#ifdef OPENSSL_SYS_MSDOS
306 /* This should set the file to binary mode. */
307 {
308#include <fcntl.h>
309 if (!(uflag && dflag))
310 setmode(fileno(DES_IN),O_BINARY);
311 if (!(uflag && eflag))
312 setmode(fileno(DES_OUT),O_BINARY);
313 }
314#endif
315
316 doencryption();
317 fclose(DES_IN);
318 fclose(DES_OUT);
319 EXIT(0);
320 }
321
322void usage(void)
323 {
324 char **u;
325 static const char *Usage[]={
326"des <options> [input-file [output-file]]",
327"options:",
328"-v : des(1) version number",
329"-e : encrypt using SunOS compatible user key to DES key conversion.",
330"-E : encrypt ",
331"-d : decrypt using SunOS compatible user key to DES key conversion.",
332"-D : decrypt ",
333"-c[ckname] : generate a cbc_cksum using SunOS compatible user key to",
334" DES key conversion and output to ckname (stdout default,",
335" stderr if data being output on stdout). The checksum is",
336" generated before encryption and after decryption if used",
337" in conjunction with -[eEdD].",
338"-C[ckname] : generate a cbc_cksum as for -c but compatible with -[ED].",
339"-k key : use key 'key'",
340"-h : the key that is entered will be a hexadecimal number",
341" that is used directly as the des key",
342"-u[uuname] : input file is uudecoded if -[dD] or output uuencoded data if -[eE]",
343" (uuname is the filename to put in the uuencode header).",
344"-b : encrypt using DES in ecb encryption mode, the default is cbc mode.",
345"-3 : encrypt using triple DES encryption. This uses 2 keys",
346" generated from the input key. If the input key is less",
347" than 8 characters long, this is equivalent to normal",
348" encryption. Default is triple cbc, -b makes it triple ecb.",
349NULL
350};
351 for (u=(char **)Usage; *u; u++)
352 {
353 fputs(*u,stderr);
354 fputc('\n',stderr);
355 }
356
357 EXIT(1);
358 }
359
360void doencryption(void)
361 {
362#ifdef _LIBC
363 extern unsigned long time();
364#endif
365
366 register int i;
367 DES_key_schedule ks,ks2;
368 DES_cblock iv,iv2;
369 char *p;
370 int num=0,j,k,l,rem,ll,len,last,ex=0;
371 DES_cblock kk,k2;
372 FILE *O;
373 int Exit=0;
374#ifndef OPENSSL_SYS_MSDOS
375 static unsigned char buf[BUFSIZE+8],obuf[BUFSIZE+8];
376#else
377 static unsigned char *buf=NULL,*obuf=NULL;
378
379 if (buf == NULL)
380 {
381 if ( (( buf=OPENSSL_malloc(BUFSIZE+8)) == NULL) ||
382 ((obuf=OPENSSL_malloc(BUFSIZE+8)) == NULL))
383 {
384 fputs("Not enough memory\n",stderr);
385 Exit=10;
386 goto problems;
387 }
388 }
389#endif
390
391 if (hflag)
392 {
393 j=(flag3?16:8);
394 p=key;
395 for (i=0; i<j; i++)
396 {
397 k=0;
398 if ((*p <= '9') && (*p >= '0'))
399 k=(*p-'0')<<4;
400 else if ((*p <= 'f') && (*p >= 'a'))
401 k=(*p-'a'+10)<<4;
402 else if ((*p <= 'F') && (*p >= 'A'))
403 k=(*p-'A'+10)<<4;
404 else
405 {
406 fputs("Bad hex key\n",stderr);
407 Exit=9;
408 goto problems;
409 }
410 p++;
411 if ((*p <= '9') && (*p >= '0'))
412 k|=(*p-'0');
413 else if ((*p <= 'f') && (*p >= 'a'))
414 k|=(*p-'a'+10);
415 else if ((*p <= 'F') && (*p >= 'A'))
416 k|=(*p-'A'+10);
417 else
418 {
419 fputs("Bad hex key\n",stderr);
420 Exit=9;
421 goto problems;
422 }
423 p++;
424 if (i < 8)
425 kk[i]=k;
426 else
427 k2[i-8]=k;
428 }
429 DES_set_key_unchecked(&k2,&ks2);
430 OPENSSL_cleanse(k2,sizeof(k2));
431 }
432 else if (longk || flag3)
433 {
434 if (flag3)
435 {
436 DES_string_to_2keys(key,&kk,&k2);
437 DES_set_key_unchecked(&k2,&ks2);
438 OPENSSL_cleanse(k2,sizeof(k2));
439 }
440 else
441 DES_string_to_key(key,&kk);
442 }
443 else
444 for (i=0; i<KEYSIZ; i++)
445 {
446 l=0;
447 k=key[i];
448 for (j=0; j<8; j++)
449 {
450 if (k&1) l++;
451 k>>=1;
452 }
453 if (l & 1)
454 kk[i]=key[i]&0x7f;
455 else
456 kk[i]=key[i]|0x80;
457 }
458
459 DES_set_key_unchecked(&kk,&ks);
460 OPENSSL_cleanse(key,sizeof(key));
461 OPENSSL_cleanse(kk,sizeof(kk));
462 /* woops - A bug that does not showup under unix :-( */
463 memset(iv,0,sizeof(iv));
464 memset(iv2,0,sizeof(iv2));
465
466 l=1;
467 rem=0;
468 /* first read */
469 if (eflag || (!dflag && cflag))
470 {
471 for (;;)
472 {
473 num=l=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
474 l+=rem;
475 num+=rem;
476 if (l < 0)
477 {
478 perror("read error");
479 Exit=6;
480 goto problems;
481 }
482
483 rem=l%8;
484 len=l-rem;
485 if (feof(DES_IN))
486 {
487 for (i=7-rem; i>0; i--)
488 RAND_pseudo_bytes(buf + l++, 1);
489 buf[l++]=rem;
490 ex=1;
491 len+=rem;
492 }
493 else
494 l-=rem;
495
496 if (cflag)
497 {
498 DES_cbc_cksum(buf,&cksum,
499 (long)len,&ks,&cksum);
500 if (!eflag)
501 {
502 if (feof(DES_IN)) break;
503 else continue;
504 }
505 }
506
507 if (bflag && !flag3)
508 for (i=0; i<l; i+=8)
509 DES_ecb_encrypt(
510 (DES_cblock *)&(buf[i]),
511 (DES_cblock *)&(obuf[i]),
512 &ks,do_encrypt);
513 else if (flag3 && bflag)
514 for (i=0; i<l; i+=8)
515 DES_ecb2_encrypt(
516 (DES_cblock *)&(buf[i]),
517 (DES_cblock *)&(obuf[i]),
518 &ks,&ks2,do_encrypt);
519 else if (flag3 && !bflag)
520 {
521 char tmpbuf[8];
522
523 if (rem) memcpy(tmpbuf,&(buf[l]),
524 (unsigned int)rem);
525 DES_3cbc_encrypt(
526 (DES_cblock *)buf,(DES_cblock *)obuf,
527 (long)l,ks,ks2,&iv,
528 &iv2,do_encrypt);
529 if (rem) memcpy(&(buf[l]),tmpbuf,
530 (unsigned int)rem);
531 }
532 else
533 {
534 DES_cbc_encrypt(
535 buf,obuf,
536 (long)l,&ks,&iv,do_encrypt);
537 if (l >= 8) memcpy(iv,&(obuf[l-8]),8);
538 }
539 if (rem) memcpy(buf,&(buf[l]),(unsigned int)rem);
540
541 i=0;
542 while (i < l)
543 {
544 if (uflag)
545 j=uufwrite(obuf,1,(unsigned int)l-i,
546 DES_OUT);
547 else
548 j=fwrite(obuf,1,(unsigned int)l-i,
549 DES_OUT);
550 if (j == -1)
551 {
552 perror("Write error");
553 Exit=7;
554 goto problems;
555 }
556 i+=j;
557 }
558 if (feof(DES_IN))
559 {
560 if (uflag) uufwriteEnd(DES_OUT);
561 break;
562 }
563 }
564 }
565 else /* decrypt */
566 {
567 ex=1;
568 for (;;)
569 {
570 if (ex) {
571 if (uflag)
572 l=uufread(buf,1,BUFSIZE,DES_IN);
573 else
574 l=fread(buf,1,BUFSIZE,DES_IN);
575 ex=0;
576 rem=l%8;
577 l-=rem;
578 }
579 if (l < 0)
580 {
581 perror("read error");
582 Exit=6;
583 goto problems;
584 }
585
586 if (bflag && !flag3)
587 for (i=0; i<l; i+=8)
588 DES_ecb_encrypt(
589 (DES_cblock *)&(buf[i]),
590 (DES_cblock *)&(obuf[i]),
591 &ks,do_encrypt);
592 else if (flag3 && bflag)
593 for (i=0; i<l; i+=8)
594 DES_ecb2_encrypt(
595 (DES_cblock *)&(buf[i]),
596 (DES_cblock *)&(obuf[i]),
597 &ks,&ks2,do_encrypt);
598 else if (flag3 && !bflag)
599 {
600 DES_3cbc_encrypt(
601 (DES_cblock *)buf,(DES_cblock *)obuf,
602 (long)l,ks,ks2,&iv,
603 &iv2,do_encrypt);
604 }
605 else
606 {
607 DES_cbc_encrypt(
608 buf,obuf,
609 (long)l,&ks,&iv,do_encrypt);
610 if (l >= 8) memcpy(iv,&(buf[l-8]),8);
611 }
612
613 if (uflag)
614 ll=uufread(&(buf[rem]),1,BUFSIZE,DES_IN);
615 else
616 ll=fread(&(buf[rem]),1,BUFSIZE,DES_IN);
617 ll+=rem;
618 rem=ll%8;
619 ll-=rem;
620 if (feof(DES_IN) && (ll == 0))
621 {
622 last=obuf[l-1];
623
624 if ((last > 7) || (last < 0))
625 {
626 fputs("The file was not decrypted correctly.\n",
627 stderr);
628 Exit=8;
629 last=0;
630 }
631 l=l-8+last;
632 }
633 i=0;
634 if (cflag) DES_cbc_cksum(obuf,
635 (DES_cblock *)cksum,(long)l/8*8,&ks,
636 (DES_cblock *)cksum);
637 while (i != l)
638 {
639 j=fwrite(obuf,1,(unsigned int)l-i,DES_OUT);
640 if (j == -1)
641 {
642 perror("Write error");
643 Exit=7;
644 goto problems;
645 }
646 i+=j;
647 }
648 l=ll;
649 if ((l == 0) && feof(DES_IN)) break;
650 }
651 }
652 if (cflag)
653 {
654 l=0;
655 if (cksumname[0] != '\0')
656 {
657 if ((O=fopen(cksumname,"w")) != NULL)
658 {
659 CKSUM_OUT=O;
660 l=1;
661 }
662 }
663 for (i=0; i<8; i++)
664 fprintf(CKSUM_OUT,"%02X",cksum[i]);
665 fprintf(CKSUM_OUT,"\n");
666 if (l) fclose(CKSUM_OUT);
667 }
668problems:
669 OPENSSL_cleanse(buf,sizeof(buf));
670 OPENSSL_cleanse(obuf,sizeof(obuf));
671 OPENSSL_cleanse(&ks,sizeof(ks));
672 OPENSSL_cleanse(&ks2,sizeof(ks2));
673 OPENSSL_cleanse(iv,sizeof(iv));
674 OPENSSL_cleanse(iv2,sizeof(iv2));
675 OPENSSL_cleanse(kk,sizeof(kk));
676 OPENSSL_cleanse(k2,sizeof(k2));
677 OPENSSL_cleanse(uubuf,sizeof(uubuf));
678 OPENSSL_cleanse(b,sizeof(b));
679 OPENSSL_cleanse(bb,sizeof(bb));
680 OPENSSL_cleanse(cksum,sizeof(cksum));
681 if (Exit) EXIT(Exit);
682 }
683
684/* We ignore this parameter but it should be > ~50 I believe */
685int uufwrite(unsigned char *data, int size, unsigned int num, FILE *fp)
686 {
687 int i,j,left,rem,ret=num;
688 static int start=1;
689
690 if (start)
691 {
692 fprintf(fp,"begin 600 %s\n",
693 (uuname[0] == '\0')?"text.d":uuname);
694 start=0;
695 }
696
697 if (uubufnum)
698 {
699 if (uubufnum+num < 45)
700 {
701 memcpy(&(uubuf[uubufnum]),data,(unsigned int)num);
702 uubufnum+=num;
703 return(num);
704 }
705 else
706 {
707 i=45-uubufnum;
708 memcpy(&(uubuf[uubufnum]),data,(unsigned int)i);
709 j=uuencode((unsigned char *)uubuf,45,b);
710 fwrite(b,1,(unsigned int)j,fp);
711 uubufnum=0;
712 data+=i;
713 num-=i;
714 }
715 }
716
717 for (i=0; i<(((int)num)-INUUBUFN); i+=INUUBUFN)
718 {
719 j=uuencode(&(data[i]),INUUBUFN,b);
720 fwrite(b,1,(unsigned int)j,fp);
721 }
722 rem=(num-i)%45;
723 left=(num-i-rem);
724 if (left)
725 {
726 j=uuencode(&(data[i]),left,b);
727 fwrite(b,1,(unsigned int)j,fp);
728 i+=left;
729 }
730 if (i != num)
731 {
732 memcpy(uubuf,&(data[i]),(unsigned int)rem);
733 uubufnum=rem;
734 }
735 return(ret);
736 }
737
738void uufwriteEnd(FILE *fp)
739 {
740 int j;
741 static const char *end=" \nend\n";
742
743 if (uubufnum != 0)
744 {
745 uubuf[uubufnum]='\0';
746 uubuf[uubufnum+1]='\0';
747 uubuf[uubufnum+2]='\0';
748 j=uuencode(uubuf,uubufnum,b);
749 fwrite(b,1,(unsigned int)j,fp);
750 }
751 fwrite(end,1,strlen(end),fp);
752 }
753
754/* int size: should always be > ~ 60; I actually ignore this parameter :-) */
755int uufread(unsigned char *out, int size, unsigned int num, FILE *fp)
756 {
757 int i,j,tot;
758 static int done=0;
759 static int valid=0;
760 static int start=1;
761
762 if (start)
763 {
764 for (;;)
765 {
766 b[0]='\0';
767 fgets((char *)b,300,fp);
768 if (b[0] == '\0')
769 {
770 fprintf(stderr,"no 'begin' found in uuencoded input\n");
771 return(-1);
772 }
773 if (strncmp((char *)b,"begin ",6) == 0) break;
774 }
775 start=0;
776 }
777 if (done) return(0);
778 tot=0;
779 if (valid)
780 {
781 memcpy(out,bb,(unsigned int)valid);
782 tot=valid;
783 valid=0;
784 }
785 for (;;)
786 {
787 b[0]='\0';
788 fgets((char *)b,300,fp);
789 if (b[0] == '\0') break;
790 i=strlen((char *)b);
791 if ((b[0] == 'e') && (b[1] == 'n') && (b[2] == 'd'))
792 {
793 done=1;
794 while (!feof(fp))
795 {
796 fgets((char *)b,300,fp);
797 }
798 break;
799 }
800 i=uudecode(b,i,bb);
801 if (i < 0) break;
802 if ((i+tot+8) > num)
803 {
804 /* num to copy to make it a multiple of 8 */
805 j=(num/8*8)-tot-8;
806 memcpy(&(out[tot]),bb,(unsigned int)j);
807 tot+=j;
808 memcpy(bb,&(bb[j]),(unsigned int)i-j);
809 valid=i-j;
810 break;
811 }
812 memcpy(&(out[tot]),bb,(unsigned int)i);
813 tot+=i;
814 }
815 return(tot);
816 }
817
818#define ccc2l(c,l) (l =((DES_LONG)(*((c)++)))<<16, \
819 l|=((DES_LONG)(*((c)++)))<< 8, \
820 l|=((DES_LONG)(*((c)++))))
821
822#define l2ccc(l,c) (*((c)++)=(unsigned char)(((l)>>16)&0xff), \
823 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
824 *((c)++)=(unsigned char)(((l) )&0xff))
825
826
827int uuencode(unsigned char *in, int num, unsigned char *out)
828 {
829 int j,i,n,tot=0;
830 DES_LONG l;
831 register unsigned char *p;
832 p=out;
833
834 for (j=0; j<num; j+=45)
835 {
836 if (j+45 > num)
837 i=(num-j);
838 else i=45;
839 *(p++)=i+' ';
840 for (n=0; n<i; n+=3)
841 {
842 ccc2l(in,l);
843 *(p++)=((l>>18)&0x3f)+' ';
844 *(p++)=((l>>12)&0x3f)+' ';
845 *(p++)=((l>> 6)&0x3f)+' ';
846 *(p++)=((l )&0x3f)+' ';
847 tot+=4;
848 }
849 *(p++)='\n';
850 tot+=2;
851 }
852 *p='\0';
853 l=0;
854 return(tot);
855 }
856
857int uudecode(unsigned char *in, int num, unsigned char *out)
858 {
859 int j,i,k;
860 unsigned int n=0,space=0;
861 DES_LONG l;
862 DES_LONG w,x,y,z;
863 unsigned int blank=(unsigned int)'\n'-' ';
864
865 for (j=0; j<num; )
866 {
867 n= *(in++)-' ';
868 if (n == blank)
869 {
870 n=0;
871 in--;
872 }
873 if (n > 60)
874 {
875 fprintf(stderr,"uuencoded line length too long\n");
876 return(-1);
877 }
878 j++;
879
880 for (i=0; i<n; j+=4,i+=3)
881 {
882 /* the following is for cases where spaces are
883 * removed from lines.
884 */
885 if (space)
886 {
887 w=x=y=z=0;
888 }
889 else
890 {
891 w= *(in++)-' ';
892 x= *(in++)-' ';
893 y= *(in++)-' ';
894 z= *(in++)-' ';
895 }
896 if ((w > 63) || (x > 63) || (y > 63) || (z > 63))
897 {
898 k=0;
899 if (w == blank) k=1;
900 if (x == blank) k=2;
901 if (y == blank) k=3;
902 if (z == blank) k=4;
903 space=1;
904 switch (k) {
905 case 1: w=0; in--;
906 case 2: x=0; in--;
907 case 3: y=0; in--;
908 case 4: z=0; in--;
909 break;
910 case 0:
911 space=0;
912 fprintf(stderr,"bad uuencoded data values\n");
913 w=x=y=z=0;
914 return(-1);
915 break;
916 }
917 }
918 l=(w<<18)|(x<<12)|(y<< 6)|(z );
919 l2ccc(l,out);
920 }
921 if (*(in++) != '\n')
922 {
923 fprintf(stderr,"missing nl in uuencoded line\n");
924 w=x=y=z=0;
925 return(-1);
926 }
927 j++;
928 }
929 *out='\0';
930 w=x=y=z=0;
931 return(n);
932 }
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h
index 92b6663599..81bd874edd 100644
--- a/src/lib/libcrypto/des/des.h
+++ b/src/lib/libcrypto/des/des.h
@@ -56,21 +56,23 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef HEADER_NEW_DES_H 59#ifndef HEADER_DES_H
60#define HEADER_NEW_DES_H 60#define HEADER_DES_H
61
62#include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES,
63 DES_LONG (via openssl/opensslconf.h */
64 61
65#ifdef OPENSSL_NO_DES 62#ifdef OPENSSL_NO_DES
66#error DES is disabled. 63#error DES is disabled.
67#endif 64#endif
68 65
66#include <openssl/opensslconf.h> /* DES_LONG */
67#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
68
69#ifdef OPENSSL_BUILD_SHLIBCRYPTO 69#ifdef OPENSSL_BUILD_SHLIBCRYPTO
70# undef OPENSSL_EXTERN 70# undef OPENSSL_EXTERN
71# define OPENSSL_EXTERN OPENSSL_EXPORT 71# define OPENSSL_EXTERN OPENSSL_EXPORT
72#endif 72#endif
73 73
74#define des_SPtrans DES_SPtrans
75
74#ifdef __cplusplus 76#ifdef __cplusplus
75extern "C" { 77extern "C" {
76#endif 78#endif
@@ -128,7 +130,7 @@ OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */
128#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) 130#define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode)
129 131
130const char *DES_options(void); 132const char *DES_options(void);
131void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 133void DES_ecb3_encrypt(const unsigned char *input, unsigned char *output,
132 DES_key_schedule *ks1,DES_key_schedule *ks2, 134 DES_key_schedule *ks1,DES_key_schedule *ks2,
133 DES_key_schedule *ks3, int enc); 135 DES_key_schedule *ks3, int enc);
134DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, 136DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output,
@@ -195,10 +197,9 @@ void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out,
195 long length,DES_key_schedule *ks1, 197 long length,DES_key_schedule *ks1,
196 DES_key_schedule *ks2,DES_key_schedule *ks3, 198 DES_key_schedule *ks2,DES_key_schedule *ks3,
197 DES_cblock *ivec,int *num); 199 DES_cblock *ivec,int *num);
198#if 0 200
199void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white, 201void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white,
200 DES_cblock *out_white); 202 DES_cblock *out_white);
201#endif
202 203
203int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, 204int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched,
204 DES_cblock *iv); 205 DES_cblock *iv);
diff --git a/src/lib/libcrypto/des/des.pod b/src/lib/libcrypto/des/des.pod
new file mode 100644
index 0000000000..bf479e83d2
--- /dev/null
+++ b/src/lib/libcrypto/des/des.pod
@@ -0,0 +1,217 @@
1=pod
2
3=head1 NAME
4
5des - encrypt or decrypt data using Data Encryption Standard
6
7=head1 SYNOPSIS
8
9B<des>
10(
11B<-e>
12|
13B<-E>
14) | (
15B<-d>
16|
17B<-D>
18) | (
19B<->[B<cC>][B<ckname>]
20) |
21[
22B<-b3hfs>
23] [
24B<-k>
25I<key>
26]
27] [
28B<-u>[I<uuname>]
29[
30I<input-file>
31[
32I<output-file>
33] ]
34
35=head1 NOTE
36
37This page describes the B<des> stand-alone program, not the B<openssl des>
38command.
39
40=head1 DESCRIPTION
41
42B<des>
43encrypts and decrypts data using the
44Data Encryption Standard algorithm.
45One of
46B<-e>, B<-E>
47(for encrypt) or
48B<-d>, B<-D>
49(for decrypt) must be specified.
50It is also possible to use
51B<-c>
52or
53B<-C>
54in conjunction or instead of the a encrypt/decrypt option to generate
55a 16 character hexadecimal checksum, generated via the
56I<des_cbc_cksum>.
57
58Two standard encryption modes are supported by the
59B<des>
60program, Cipher Block Chaining (the default) and Electronic Code Book
61(specified with
62B<-b>).
63
64The key used for the DES
65algorithm is obtained by prompting the user unless the
66B<-k>
67I<key>
68option is given.
69If the key is an argument to the
70B<des>
71command, it is potentially visible to users executing
72ps(1)
73or a derivative. To minimise this possibility,
74B<des>
75takes care to destroy the key argument immediately upon entry.
76If your shell keeps a history file be careful to make sure it is not
77world readable.
78
79Since this program attempts to maintain compatibility with sunOS's
80des(1) command, there are 2 different methods used to convert the user
81supplied key to a des key.
82Whenever and one or more of
83B<-E>, B<-D>, B<-C>
84or
85B<-3>
86options are used, the key conversion procedure will not be compatible
87with the sunOS des(1) version but will use all the user supplied
88character to generate the des key.
89B<des>
90command reads from standard input unless
91I<input-file>
92is specified and writes to standard output unless
93I<output-file>
94is given.
95
96=head1 OPTIONS
97
98=over 4
99
100=item B<-b>
101
102Select ECB
103(eight bytes at a time) encryption mode.
104
105=item B<-3>
106
107Encrypt using triple encryption.
108By default triple cbc encryption is used but if the
109B<-b>
110option is used then triple ECB encryption is performed.
111If the key is less than 8 characters long, the flag has no effect.
112
113=item B<-e>
114
115Encrypt data using an 8 byte key in a manner compatible with sunOS
116des(1).
117
118=item B<-E>
119
120Encrypt data using a key of nearly unlimited length (1024 bytes).
121This will product a more secure encryption.
122
123=item B<-d>
124
125Decrypt data that was encrypted with the B<-e> option.
126
127=item B<-D>
128
129Decrypt data that was encrypted with the B<-E> option.
130
131=item B<-c>
132
133Generate a 16 character hexadecimal cbc checksum and output this to
134stderr.
135If a filename was specified after the
136B<-c>
137option, the checksum is output to that file.
138The checksum is generated using a key generated in a sunOS compatible
139manner.
140
141=item B<-C>
142
143A cbc checksum is generated in the same manner as described for the
144B<-c>
145option but the DES key is generated in the same manner as used for the
146B<-E>
147and
148B<-D>
149options
150
151=item B<-f>
152
153Does nothing - allowed for compatibility with sunOS des(1) command.
154
155=item B<-s>
156
157Does nothing - allowed for compatibility with sunOS des(1) command.
158
159=item B<-k> I<key>
160
161Use the encryption
162I<key>
163specified.
164
165=item B<-h>
166
167The
168I<key>
169is assumed to be a 16 character hexadecimal number.
170If the
171B<-3>
172option is used the key is assumed to be a 32 character hexadecimal
173number.
174
175=item B<-u>
176
177This flag is used to read and write uuencoded files. If decrypting,
178the input file is assumed to contain uuencoded, DES encrypted data.
179If encrypting, the characters following the B<-u> are used as the name of
180the uuencoded file to embed in the begin line of the uuencoded
181output. If there is no name specified after the B<-u>, the name text.des
182will be embedded in the header.
183
184=head1 SEE ALSO
185
186ps(1),
187L<des_crypt(3)|des_crypt(3)>
188
189=head1 BUGS
190
191The problem with using the
192B<-e>
193option is the short key length.
194It would be better to use a real 56-bit key rather than an
195ASCII-based 56-bit pattern. Knowing that the key was derived from ASCII
196radically reduces the time necessary for a brute-force cryptographic attack.
197My attempt to remove this problem is to add an alternative text-key to
198DES-key function. This alternative function (accessed via
199B<-E>, B<-D>, B<-S>
200and
201B<-3>)
202uses DES to help generate the key.
203
204Be carefully when using the B<-u> option. Doing B<des -ud> I<filename> will
205not decrypt filename (the B<-u> option will gobble the B<-d> option).
206
207The VMS operating system operates in a world where files are always a
208multiple of 512 bytes. This causes problems when encrypted data is
209send from Unix to VMS since a 88 byte file will suddenly be padded
210with 424 null bytes. To get around this problem, use the B<-u> option
211to uuencode the data before it is send to the VMS system.
212
213=head1 AUTHOR
214
215Eric Young (eay@cryptsoft.com)
216
217=cut
diff --git a/src/lib/libcrypto/des/des3s.cpp b/src/lib/libcrypto/des/des3s.cpp
new file mode 100644
index 0000000000..02d527c057
--- /dev/null
+++ b/src/lib/libcrypto/des/des3s.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/des.h>
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key1,key2,key3;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt3(&data[0],key1,key2,key3);
49 GetTSC(s1);
50 des_encrypt3(&data[0],key1,key2,key3);
51 des_encrypt3(&data[0],key1,key2,key3);
52 des_encrypt3(&data[0],key1,key2,key3);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt3(&data[0],key1,key2,key3);
56 des_encrypt3(&data[0],key1,key2,key3);
57 des_encrypt3(&data[0],key1,key2,key3);
58 des_encrypt3(&data[0],key1,key2,key3);
59 GetTSC(e2);
60 des_encrypt3(&data[0],key1,key2,key3);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c
index 1c37ab96d3..6a49ec4a55 100644
--- a/src/lib/libcrypto/des/des_enc.c
+++ b/src/lib/libcrypto/des/des_enc.c
@@ -58,6 +58,9 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61#ifndef OPENSSL_FIPS
62#ifndef OPENBSD_DES_ASM
63
61void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) 64void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc)
62 { 65 {
63 register DES_LONG l,r,t,u; 66 register DES_LONG l,r,t,u;
@@ -246,6 +249,7 @@ void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc)
246 data[1]=ROTATE(r,3)&0xffffffffL; 249 data[1]=ROTATE(r,3)&0xffffffffL;
247 l=r=t=u=0; 250 l=r=t=u=0;
248 } 251 }
252#endif
249 253
250void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, 254void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1,
251 DES_key_schedule *ks2, DES_key_schedule *ks3) 255 DES_key_schedule *ks2, DES_key_schedule *ks3)
@@ -287,8 +291,12 @@ void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1,
287 data[1]=r; 291 data[1]=r;
288 } 292 }
289 293
294#endif /* ndef OPENSSL_FIPS */
295
290#ifndef DES_DEFAULT_OPTIONS 296#ifndef DES_DEFAULT_OPTIONS
291 297
298#if !defined(OPENSSL_FIPS_DES_ASM)
299
292#undef CBC_ENC_C__DONT_UPDATE_IV 300#undef CBC_ENC_C__DONT_UPDATE_IV
293#include "ncbc_enc.c" /* DES_ncbc_encrypt */ 301#include "ncbc_enc.c" /* DES_ncbc_encrypt */
294 302
@@ -404,4 +412,6 @@ void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
404 tin[0]=tin[1]=0; 412 tin[0]=tin[1]=0;
405 } 413 }
406 414
415#endif /* !defined(OPENSSL_FIPS_DES_ASM) */
416
407#endif /* DES_DEFAULT_OPTIONS */ 417#endif /* DES_DEFAULT_OPTIONS */
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h
index 4b9ecff233..8f04b18c50 100644
--- a/src/lib/libcrypto/des/des_locl.h
+++ b/src/lib/libcrypto/des/des_locl.h
@@ -160,7 +160,7 @@
160 } \ 160 } \
161 } 161 }
162 162
163#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)) || defined(__ICC) 163#if defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)
164#define ROTATE(a,n) (_lrotr(a,n)) 164#define ROTATE(a,n) (_lrotr(a,n))
165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC) 165#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) 166# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
diff --git a/src/lib/libcrypto/des/des_old.c b/src/lib/libcrypto/des/des_old.c
new file mode 100644
index 0000000000..88e9802aad
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.c
@@ -0,0 +1,271 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with libdes. OpenSSL now provides
7 * functions where "des_" has been replaced with "DES_" in the names,
8 * to make it possible to make incompatible changes that are needed
9 * for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#define OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79const char *_ossl_old_des_options(void)
80 {
81 return DES_options();
82 }
83void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
84 des_key_schedule ks1,des_key_schedule ks2,
85 des_key_schedule ks3, int enc)
86 {
87 DES_ecb3_encrypt((const unsigned char *)input, (unsigned char *)output,
88 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
89 (DES_key_schedule *)ks3, enc);
90 }
91DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
92 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
93 {
94 return DES_cbc_cksum((unsigned char *)input, output, length,
95 (DES_key_schedule *)schedule, ivec);
96 }
97void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
98 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
99 {
100 DES_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
101 length, (DES_key_schedule *)schedule, ivec, enc);
102 }
103void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
104 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
105 {
106 DES_ncbc_encrypt((unsigned char *)input, (unsigned char *)output,
107 length, (DES_key_schedule *)schedule, ivec, enc);
108 }
109void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
110 des_key_schedule schedule,_ossl_old_des_cblock *ivec,
111 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc)
112 {
113 DES_xcbc_encrypt((unsigned char *)input, (unsigned char *)output,
114 length, (DES_key_schedule *)schedule, ivec, inw, outw, enc);
115 }
116void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
117 long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
118 {
119 DES_cfb_encrypt(in, out, numbits, length,
120 (DES_key_schedule *)schedule, ivec, enc);
121 }
122void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
123 des_key_schedule ks,int enc)
124 {
125 DES_ecb_encrypt(input, output, (DES_key_schedule *)ks, enc);
126 }
127void _ossl_old_des_encrypt(DES_LONG *data,des_key_schedule ks, int enc)
128 {
129 DES_encrypt1(data, (DES_key_schedule *)ks, enc);
130 }
131void _ossl_old_des_encrypt2(DES_LONG *data,des_key_schedule ks, int enc)
132 {
133 DES_encrypt2(data, (DES_key_schedule *)ks, enc);
134 }
135void _ossl_old_des_encrypt3(DES_LONG *data, des_key_schedule ks1,
136 des_key_schedule ks2, des_key_schedule ks3)
137 {
138 DES_encrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
139 (DES_key_schedule *)ks3);
140 }
141void _ossl_old_des_decrypt3(DES_LONG *data, des_key_schedule ks1,
142 des_key_schedule ks2, des_key_schedule ks3)
143 {
144 DES_decrypt3(data, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
145 (DES_key_schedule *)ks3);
146 }
147void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
148 long length, des_key_schedule ks1, des_key_schedule ks2,
149 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc)
150 {
151 DES_ede3_cbc_encrypt((unsigned char *)input, (unsigned char *)output,
152 length, (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
153 (DES_key_schedule *)ks3, ivec, enc);
154 }
155void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
156 long length, des_key_schedule ks1, des_key_schedule ks2,
157 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc)
158 {
159 DES_ede3_cfb64_encrypt(in, out, length,
160 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
161 (DES_key_schedule *)ks3, ivec, num, enc);
162 }
163void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
164 long length, des_key_schedule ks1, des_key_schedule ks2,
165 des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num)
166 {
167 DES_ede3_ofb64_encrypt(in, out, length,
168 (DES_key_schedule *)ks1, (DES_key_schedule *)ks2,
169 (DES_key_schedule *)ks3, ivec, num);
170 }
171
172void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
173 _ossl_old_des_cblock (*out_white))
174 {
175 DES_xwhite_in2out(des_key, in_white, out_white);
176 }
177
178int _ossl_old_des_enc_read(int fd,char *buf,int len,des_key_schedule sched,
179 _ossl_old_des_cblock *iv)
180 {
181 return DES_enc_read(fd, buf, len, (DES_key_schedule *)sched, iv);
182 }
183int _ossl_old_des_enc_write(int fd,char *buf,int len,des_key_schedule sched,
184 _ossl_old_des_cblock *iv)
185 {
186 return DES_enc_write(fd, buf, len, (DES_key_schedule *)sched, iv);
187 }
188char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret)
189 {
190 return DES_fcrypt(buf, salt, ret);
191 }
192char *_ossl_old_des_crypt(const char *buf,const char *salt)
193 {
194 return DES_crypt(buf, salt);
195 }
196char *_ossl_old_crypt(const char *buf,const char *salt)
197 {
198 return DES_crypt(buf, salt);
199 }
200void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
201 int numbits,long length,des_key_schedule schedule,_ossl_old_des_cblock *ivec)
202 {
203 DES_ofb_encrypt(in, out, numbits, length, (DES_key_schedule *)schedule,
204 ivec);
205 }
206void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
207 des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc)
208 {
209 DES_pcbc_encrypt((unsigned char *)input, (unsigned char *)output,
210 length, (DES_key_schedule *)schedule, ivec, enc);
211 }
212DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
213 long length,int out_count,_ossl_old_des_cblock *seed)
214 {
215 return DES_quad_cksum((unsigned char *)input, output, length,
216 out_count, seed);
217 }
218void _ossl_old_des_random_seed(_ossl_old_des_cblock key)
219 {
220 RAND_seed(key, sizeof(_ossl_old_des_cblock));
221 }
222void _ossl_old_des_random_key(_ossl_old_des_cblock ret)
223 {
224 DES_random_key((DES_cblock *)ret);
225 }
226int _ossl_old_des_read_password(_ossl_old_des_cblock *key, const char *prompt,
227 int verify)
228 {
229 return DES_read_password(key, prompt, verify);
230 }
231int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1, _ossl_old_des_cblock *key2,
232 const char *prompt, int verify)
233 {
234 return DES_read_2passwords(key1, key2, prompt, verify);
235 }
236void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key)
237 {
238 DES_set_odd_parity(key);
239 }
240int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key)
241 {
242 return DES_is_weak_key(key);
243 }
244int _ossl_old_des_set_key(_ossl_old_des_cblock *key,des_key_schedule schedule)
245 {
246 return DES_set_key(key, (DES_key_schedule *)schedule);
247 }
248int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,des_key_schedule schedule)
249 {
250 return DES_key_sched(key, (DES_key_schedule *)schedule);
251 }
252void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key)
253 {
254 DES_string_to_key(str, key);
255 }
256void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2)
257 {
258 DES_string_to_2keys(str, key1, key2);
259 }
260void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
261 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc)
262 {
263 DES_cfb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
264 ivec, num, enc);
265 }
266void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
267 des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num)
268 {
269 DES_ofb64_encrypt(in, out, length, (DES_key_schedule *)schedule,
270 ivec, num);
271 }
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h
new file mode 100644
index 0000000000..1d8bf65101
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old.h
@@ -0,0 +1,441 @@
1/* crypto/des/des_old.h -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with openssl 0.9.6 and older as
7 * well as libdes. OpenSSL now provides functions where "des_" has
8 * been replaced with "DES_" in the names, to make it possible to
9 * make incompatible changes that are needed for C type security and
10 * other stuff.
11 *
12 * This include files has two compatibility modes:
13 *
14 * - If OPENSSL_DES_LIBDES_COMPATIBILITY is defined, you get an API
15 * that is compatible with libdes and SSLeay.
16 * - If OPENSSL_DES_LIBDES_COMPATIBILITY isn't defined, you get an
17 * API that is compatible with OpenSSL 0.9.5x to 0.9.6x.
18 *
19 * Note that these modes break earlier snapshots of OpenSSL, where
20 * libdes compatibility was the only available mode or (later on) the
21 * prefered compatibility mode. However, after much consideration
22 * (and more or less violent discussions with external parties), it
23 * was concluded that OpenSSL should be compatible with earlier versions
24 * of itself before anything else. Also, in all honesty, libdes is
25 * an old beast that shouldn't really be used any more.
26 *
27 * Please consider starting to use the DES_ functions rather than the
28 * des_ ones. The des_ functions will disappear completely before
29 * OpenSSL 1.0!
30 *
31 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 */
33
34/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
35 * project 2001.
36 */
37/* ====================================================================
38 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 *
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 *
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in
49 * the documentation and/or other materials provided with the
50 * distribution.
51 *
52 * 3. All advertising materials mentioning features or use of this
53 * software must display the following acknowledgment:
54 * "This product includes software developed by the OpenSSL Project
55 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
56 *
57 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
58 * endorse or promote products derived from this software without
59 * prior written permission. For written permission, please contact
60 * openssl-core@openssl.org.
61 *
62 * 5. Products derived from this software may not be called "OpenSSL"
63 * nor may "OpenSSL" appear in their names without prior written
64 * permission of the OpenSSL Project.
65 *
66 * 6. Redistributions of any form whatsoever must retain the following
67 * acknowledgment:
68 * "This product includes software developed by the OpenSSL Project
69 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
70 *
71 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
72 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
73 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
74 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
75 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
76 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
77 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
78 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
79 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
80 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
81 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
82 * OF THE POSSIBILITY OF SUCH DAMAGE.
83 * ====================================================================
84 *
85 * This product includes cryptographic software written by Eric Young
86 * (eay@cryptsoft.com). This product includes software written by Tim
87 * Hudson (tjh@cryptsoft.com).
88 *
89 */
90
91#ifndef HEADER_DES_OLD_H
92#define HEADER_DES_OLD_H
93
94#ifdef OPENSSL_NO_DES
95#error DES is disabled.
96#endif
97
98#ifndef HEADER_DES_H
99#error You must include des.h, not des_old.h directly.
100#endif
101
102#ifdef _KERBEROS_DES_H
103#error <openssl/des_old.h> replaces <kerberos/des.h>.
104#endif
105
106#include <openssl/opensslconf.h> /* DES_LONG */
107#include <openssl/e_os2.h> /* OPENSSL_EXTERN */
108#include <openssl/symhacks.h>
109
110#ifdef OPENSSL_BUILD_SHLIBCRYPTO
111# undef OPENSSL_EXTERN
112# define OPENSSL_EXTERN OPENSSL_EXPORT
113#endif
114
115#ifdef __cplusplus
116extern "C" {
117#endif
118
119typedef unsigned char _ossl_old_des_cblock[8];
120typedef struct _ossl_old_des_ks_struct
121 {
122 union {
123 _ossl_old_des_cblock _;
124 /* make sure things are correct size on machines with
125 * 8 byte longs */
126 DES_LONG pad[2];
127 } ks;
128 } _ossl_old_des_key_schedule[16];
129
130#ifndef OPENSSL_DES_LIBDES_COMPATIBILITY
131#define des_cblock DES_cblock
132#define const_des_cblock const_DES_cblock
133#define des_key_schedule DES_key_schedule
134#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
135 DES_ecb3_encrypt((i),(o),&(k1),&(k2),&(k3),(e))
136#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
137 DES_ede3_cbc_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(e))
138#define des_ede3_cbcm_encrypt(i,o,l,k1,k2,k3,iv1,iv2,e)\
139 DES_ede3_cbcm_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv1),(iv2),(e))
140#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
141 DES_ede3_cfb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n),(e))
142#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
143 DES_ede3_ofb64_encrypt((i),(o),(l),&(k1),&(k2),&(k3),(iv),(n))
144#define des_options()\
145 DES_options()
146#define des_cbc_cksum(i,o,l,k,iv)\
147 DES_cbc_cksum((i),(o),(l),&(k),(iv))
148#define des_cbc_encrypt(i,o,l,k,iv,e)\
149 DES_cbc_encrypt((i),(o),(l),&(k),(iv),(e))
150#define des_ncbc_encrypt(i,o,l,k,iv,e)\
151 DES_ncbc_encrypt((i),(o),(l),&(k),(iv),(e))
152#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
153 DES_xcbc_encrypt((i),(o),(l),&(k),(iv),(inw),(outw),(e))
154#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
155 DES_cfb_encrypt((i),(o),(n),(l),&(k),(iv),(e))
156#define des_ecb_encrypt(i,o,k,e)\
157 DES_ecb_encrypt((i),(o),&(k),(e))
158#define des_encrypt1(d,k,e)\
159 DES_encrypt1((d),&(k),(e))
160#define des_encrypt2(d,k,e)\
161 DES_encrypt2((d),&(k),(e))
162#define des_encrypt3(d,k1,k2,k3)\
163 DES_encrypt3((d),&(k1),&(k2),&(k3))
164#define des_decrypt3(d,k1,k2,k3)\
165 DES_decrypt3((d),&(k1),&(k2),&(k3))
166#define des_xwhite_in2out(k,i,o)\
167 DES_xwhite_in2out((k),(i),(o))
168#define des_enc_read(f,b,l,k,iv)\
169 DES_enc_read((f),(b),(l),&(k),(iv))
170#define des_enc_write(f,b,l,k,iv)\
171 DES_enc_write((f),(b),(l),&(k),(iv))
172#define des_fcrypt(b,s,r)\
173 DES_fcrypt((b),(s),(r))
174#define des_crypt(b,s)\
175 DES_crypt((b),(s))
176#if 0
177#if !defined(PERL5) && !defined(__FreeBSD__) && !defined(NeXT) && !defined(__OpenBSD__)
178#define crypt(b,s)\
179 DES_crypt((b),(s))
180#endif
181#endif
182#define des_ofb_encrypt(i,o,n,l,k,iv)\
183 DES_ofb_encrypt((i),(o),(n),(l),&(k),(iv))
184#define des_pcbc_encrypt(i,o,l,k,iv,e)\
185 DES_pcbc_encrypt((i),(o),(l),&(k),(iv),(e))
186#define des_quad_cksum(i,o,l,c,s)\
187 DES_quad_cksum((i),(o),(l),(c),(s))
188#define des_random_seed(k)\
189 _ossl_096_des_random_seed((k))
190#define des_random_key(r)\
191 DES_random_key((r))
192#define des_read_password(k,p,v) \
193 DES_read_password((k),(p),(v))
194#define des_read_2passwords(k1,k2,p,v) \
195 DES_read_2passwords((k1),(k2),(p),(v))
196#define des_set_odd_parity(k)\
197 DES_set_odd_parity((k))
198#define des_check_key_parity(k)\
199 DES_check_key_parity((k))
200#define des_is_weak_key(k)\
201 DES_is_weak_key((k))
202#define des_set_key(k,ks)\
203 DES_set_key((k),&(ks))
204#define des_key_sched(k,ks)\
205 DES_key_sched((k),&(ks))
206#define des_set_key_checked(k,ks)\
207 DES_set_key_checked((k),&(ks))
208#define des_set_key_unchecked(k,ks)\
209 DES_set_key_unchecked((k),&(ks))
210#define des_string_to_key(s,k)\
211 DES_string_to_key((s),(k))
212#define des_string_to_2keys(s,k1,k2)\
213 DES_string_to_2keys((s),(k1),(k2))
214#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
215 DES_cfb64_encrypt((i),(o),(l),&(ks),(iv),(n),(e))
216#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
217 DES_ofb64_encrypt((i),(o),(l),&(ks),(iv),(n))
218
219
220#define des_ecb2_encrypt(i,o,k1,k2,e) \
221 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
222
223#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
224 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
225
226#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
227 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
228
229#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
230 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
231
232#define des_check_key DES_check_key
233#define des_rw_mode DES_rw_mode
234#else /* libdes compatibility */
235/* Map all symbol names to _ossl_old_des_* form, so we avoid all
236 clashes with libdes */
237#define des_cblock _ossl_old_des_cblock
238#define des_key_schedule _ossl_old_des_key_schedule
239#define des_ecb3_encrypt(i,o,k1,k2,k3,e)\
240 _ossl_old_des_ecb3_encrypt((i),(o),(k1),(k2),(k3),(e))
241#define des_ede3_cbc_encrypt(i,o,l,k1,k2,k3,iv,e)\
242 _ossl_old_des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(e))
243#define des_ede3_cfb64_encrypt(i,o,l,k1,k2,k3,iv,n,e)\
244 _ossl_old_des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n),(e))
245#define des_ede3_ofb64_encrypt(i,o,l,k1,k2,k3,iv,n)\
246 _ossl_old_des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k3),(iv),(n))
247#define des_options()\
248 _ossl_old_des_options()
249#define des_cbc_cksum(i,o,l,k,iv)\
250 _ossl_old_des_cbc_cksum((i),(o),(l),(k),(iv))
251#define des_cbc_encrypt(i,o,l,k,iv,e)\
252 _ossl_old_des_cbc_encrypt((i),(o),(l),(k),(iv),(e))
253#define des_ncbc_encrypt(i,o,l,k,iv,e)\
254 _ossl_old_des_ncbc_encrypt((i),(o),(l),(k),(iv),(e))
255#define des_xcbc_encrypt(i,o,l,k,iv,inw,outw,e)\
256 _ossl_old_des_xcbc_encrypt((i),(o),(l),(k),(iv),(inw),(outw),(e))
257#define des_cfb_encrypt(i,o,n,l,k,iv,e)\
258 _ossl_old_des_cfb_encrypt((i),(o),(n),(l),(k),(iv),(e))
259#define des_ecb_encrypt(i,o,k,e)\
260 _ossl_old_des_ecb_encrypt((i),(o),(k),(e))
261#define des_encrypt(d,k,e)\
262 _ossl_old_des_encrypt((d),(k),(e))
263#define des_encrypt2(d,k,e)\
264 _ossl_old_des_encrypt2((d),(k),(e))
265#define des_encrypt3(d,k1,k2,k3)\
266 _ossl_old_des_encrypt3((d),(k1),(k2),(k3))
267#define des_decrypt3(d,k1,k2,k3)\
268 _ossl_old_des_decrypt3((d),(k1),(k2),(k3))
269#define des_xwhite_in2out(k,i,o)\
270 _ossl_old_des_xwhite_in2out((k),(i),(o))
271#define des_enc_read(f,b,l,k,iv)\
272 _ossl_old_des_enc_read((f),(b),(l),(k),(iv))
273#define des_enc_write(f,b,l,k,iv)\
274 _ossl_old_des_enc_write((f),(b),(l),(k),(iv))
275#define des_fcrypt(b,s,r)\
276 _ossl_old_des_fcrypt((b),(s),(r))
277#define des_crypt(b,s)\
278 _ossl_old_des_crypt((b),(s))
279#if 0
280#define crypt(b,s)\
281 _ossl_old_crypt((b),(s))
282#endif
283#define des_ofb_encrypt(i,o,n,l,k,iv)\
284 _ossl_old_des_ofb_encrypt((i),(o),(n),(l),(k),(iv))
285#define des_pcbc_encrypt(i,o,l,k,iv,e)\
286 _ossl_old_des_pcbc_encrypt((i),(o),(l),(k),(iv),(e))
287#define des_quad_cksum(i,o,l,c,s)\
288 _ossl_old_des_quad_cksum((i),(o),(l),(c),(s))
289#define des_random_seed(k)\
290 _ossl_old_des_random_seed((k))
291#define des_random_key(r)\
292 _ossl_old_des_random_key((r))
293#define des_read_password(k,p,v) \
294 _ossl_old_des_read_password((k),(p),(v))
295#define des_read_2passwords(k1,k2,p,v) \
296 _ossl_old_des_read_2passwords((k1),(k2),(p),(v))
297#define des_set_odd_parity(k)\
298 _ossl_old_des_set_odd_parity((k))
299#define des_is_weak_key(k)\
300 _ossl_old_des_is_weak_key((k))
301#define des_set_key(k,ks)\
302 _ossl_old_des_set_key((k),(ks))
303#define des_key_sched(k,ks)\
304 _ossl_old_des_key_sched((k),(ks))
305#define des_string_to_key(s,k)\
306 _ossl_old_des_string_to_key((s),(k))
307#define des_string_to_2keys(s,k1,k2)\
308 _ossl_old_des_string_to_2keys((s),(k1),(k2))
309#define des_cfb64_encrypt(i,o,l,ks,iv,n,e)\
310 _ossl_old_des_cfb64_encrypt((i),(o),(l),(ks),(iv),(n),(e))
311#define des_ofb64_encrypt(i,o,l,ks,iv,n)\
312 _ossl_old_des_ofb64_encrypt((i),(o),(l),(ks),(iv),(n))
313
314
315#define des_ecb2_encrypt(i,o,k1,k2,e) \
316 des_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e))
317
318#define des_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \
319 des_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e))
320
321#define des_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \
322 des_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e))
323
324#define des_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \
325 des_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n))
326
327#define des_check_key DES_check_key
328#define des_rw_mode DES_rw_mode
329#endif
330
331const char *_ossl_old_des_options(void);
332void _ossl_old_des_ecb3_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
333 _ossl_old_des_key_schedule ks1,_ossl_old_des_key_schedule ks2,
334 _ossl_old_des_key_schedule ks3, int enc);
335DES_LONG _ossl_old_des_cbc_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
336 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
337void _ossl_old_des_cbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
338 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
339void _ossl_old_des_ncbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
340 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
341void _ossl_old_des_xcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
342 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,
343 _ossl_old_des_cblock *inw,_ossl_old_des_cblock *outw,int enc);
344void _ossl_old_des_cfb_encrypt(unsigned char *in,unsigned char *out,int numbits,
345 long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
346void _ossl_old_des_ecb_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
347 _ossl_old_des_key_schedule ks,int enc);
348void _ossl_old_des_encrypt(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
349void _ossl_old_des_encrypt2(DES_LONG *data,_ossl_old_des_key_schedule ks, int enc);
350void _ossl_old_des_encrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
351 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
352void _ossl_old_des_decrypt3(DES_LONG *data, _ossl_old_des_key_schedule ks1,
353 _ossl_old_des_key_schedule ks2, _ossl_old_des_key_schedule ks3);
354void _ossl_old_des_ede3_cbc_encrypt(_ossl_old_des_cblock *input, _ossl_old_des_cblock *output,
355 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
356 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int enc);
357void _ossl_old_des_ede3_cfb64_encrypt(unsigned char *in, unsigned char *out,
358 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
359 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num, int enc);
360void _ossl_old_des_ede3_ofb64_encrypt(unsigned char *in, unsigned char *out,
361 long length, _ossl_old_des_key_schedule ks1, _ossl_old_des_key_schedule ks2,
362 _ossl_old_des_key_schedule ks3, _ossl_old_des_cblock *ivec, int *num);
363
364void _ossl_old_des_xwhite_in2out(_ossl_old_des_cblock (*des_key), _ossl_old_des_cblock (*in_white),
365 _ossl_old_des_cblock (*out_white));
366
367int _ossl_old_des_enc_read(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
368 _ossl_old_des_cblock *iv);
369int _ossl_old_des_enc_write(int fd,char *buf,int len,_ossl_old_des_key_schedule sched,
370 _ossl_old_des_cblock *iv);
371char *_ossl_old_des_fcrypt(const char *buf,const char *salt, char *ret);
372char *_ossl_old_des_crypt(const char *buf,const char *salt);
373#if !defined(PERL5) && !defined(NeXT)
374char *_ossl_old_crypt(const char *buf,const char *salt);
375#endif
376void _ossl_old_des_ofb_encrypt(unsigned char *in,unsigned char *out,
377 int numbits,long length,_ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec);
378void _ossl_old_des_pcbc_encrypt(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,long length,
379 _ossl_old_des_key_schedule schedule,_ossl_old_des_cblock *ivec,int enc);
380DES_LONG _ossl_old_des_quad_cksum(_ossl_old_des_cblock *input,_ossl_old_des_cblock *output,
381 long length,int out_count,_ossl_old_des_cblock *seed);
382void _ossl_old_des_random_seed(_ossl_old_des_cblock key);
383void _ossl_old_des_random_key(_ossl_old_des_cblock ret);
384int _ossl_old_des_read_password(_ossl_old_des_cblock *key,const char *prompt,int verify);
385int _ossl_old_des_read_2passwords(_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2,
386 const char *prompt,int verify);
387void _ossl_old_des_set_odd_parity(_ossl_old_des_cblock *key);
388int _ossl_old_des_is_weak_key(_ossl_old_des_cblock *key);
389int _ossl_old_des_set_key(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
390int _ossl_old_des_key_sched(_ossl_old_des_cblock *key,_ossl_old_des_key_schedule schedule);
391void _ossl_old_des_string_to_key(char *str,_ossl_old_des_cblock *key);
392void _ossl_old_des_string_to_2keys(char *str,_ossl_old_des_cblock *key1,_ossl_old_des_cblock *key2);
393void _ossl_old_des_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
394 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num, int enc);
395void _ossl_old_des_ofb64_encrypt(unsigned char *in, unsigned char *out, long length,
396 _ossl_old_des_key_schedule schedule, _ossl_old_des_cblock *ivec, int *num);
397
398void _ossl_096_des_random_seed(des_cblock *key);
399
400/* The following definitions provide compatibility with the MIT Kerberos
401 * library. The _ossl_old_des_key_schedule structure is not binary compatible. */
402
403#define _KERBEROS_DES_H
404
405#define KRBDES_ENCRYPT DES_ENCRYPT
406#define KRBDES_DECRYPT DES_DECRYPT
407
408#ifdef KERBEROS
409# define ENCRYPT DES_ENCRYPT
410# define DECRYPT DES_DECRYPT
411#endif
412
413#ifndef NCOMPAT
414# define C_Block des_cblock
415# define Key_schedule des_key_schedule
416# define KEY_SZ DES_KEY_SZ
417# define string_to_key des_string_to_key
418# define read_pw_string des_read_pw_string
419# define random_key des_random_key
420# define pcbc_encrypt des_pcbc_encrypt
421# define set_key des_set_key
422# define key_sched des_key_sched
423# define ecb_encrypt des_ecb_encrypt
424# define cbc_encrypt des_cbc_encrypt
425# define ncbc_encrypt des_ncbc_encrypt
426# define xcbc_encrypt des_xcbc_encrypt
427# define cbc_cksum des_cbc_cksum
428# define quad_cksum des_quad_cksum
429# define check_parity des_check_key_parity
430#endif
431
432#define des_fixup_key_parity DES_fixup_key_parity
433
434#ifdef __cplusplus
435}
436#endif
437
438/* for DES_read_pw_string et al */
439#include <openssl/ui_compat.h>
440
441#endif
diff --git a/src/lib/libcrypto/des/des_old2.c b/src/lib/libcrypto/des/des_old2.c
new file mode 100644
index 0000000000..c8fa3ee135
--- /dev/null
+++ b/src/lib/libcrypto/des/des_old2.c
@@ -0,0 +1,82 @@
1/* crypto/des/des_old.c -*- mode:C; c-file-style: "eay" -*- */
2
3/* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
4 *
5 * The function names in here are deprecated and are only present to
6 * provide an interface compatible with OpenSSL 0.9.6c. OpenSSL now
7 * provides functions where "des_" has been replaced with "DES_" in
8 * the names, to make it possible to make incompatible changes that
9 * are needed for C type security and other stuff.
10 *
11 * Please consider starting to use the DES_ functions rather than the
12 * des_ ones. The des_ functions will dissapear completely before
13 * OpenSSL 1.0!
14 *
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
16 */
17
18/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
19 * project 2001.
20 */
21/* ====================================================================
22 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
23 *
24 * Redistribution and use in source and binary forms, with or without
25 * modification, are permitted provided that the following conditions
26 * are met:
27 *
28 * 1. Redistributions of source code must retain the above copyright
29 * notice, this list of conditions and the following disclaimer.
30 *
31 * 2. Redistributions in binary form must reproduce the above copyright
32 * notice, this list of conditions and the following disclaimer in
33 * the documentation and/or other materials provided with the
34 * distribution.
35 *
36 * 3. All advertising materials mentioning features or use of this
37 * software must display the following acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
40 *
41 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
42 * endorse or promote products derived from this software without
43 * prior written permission. For written permission, please contact
44 * openssl-core@openssl.org.
45 *
46 * 5. Products derived from this software may not be called "OpenSSL"
47 * nor may "OpenSSL" appear in their names without prior written
48 * permission of the OpenSSL Project.
49 *
50 * 6. Redistributions of any form whatsoever must retain the following
51 * acknowledgment:
52 * "This product includes software developed by the OpenSSL Project
53 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
54 *
55 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
56 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
57 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
58 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
59 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
60 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
62 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
64 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
65 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
66 * OF THE POSSIBILITY OF SUCH DAMAGE.
67 * ====================================================================
68 *
69 * This product includes cryptographic software written by Eric Young
70 * (eay@cryptsoft.com). This product includes software written by Tim
71 * Hudson (tjh@cryptsoft.com).
72 *
73 */
74
75#undef OPENSSL_DES_LIBDES_COMPATIBILITY
76#include <openssl/des.h>
77#include <openssl/rand.h>
78
79void _ossl_096_des_random_seed(DES_cblock *key)
80 {
81 RAND_seed(key, sizeof(DES_cblock));
82 }
diff --git a/src/lib/libcrypto/des/des_opts.c b/src/lib/libcrypto/des/des_opts.c
new file mode 100644
index 0000000000..79278b920e
--- /dev/null
+++ b/src/lib/libcrypto/des/des_opts.c
@@ -0,0 +1,604 @@
1/* crypto/des/des_opts.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* define 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. */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67#ifndef OPENSSL_SYS_MSDOS
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD
70#else
71#include <io.h>
72extern void exit();
73#endif
74#include <signal.h>
75#ifndef _IRIX
76#include <time.h>
77#endif
78#ifdef TIMES
79#include <sys/types.h>
80#include <sys/times.h>
81#endif
82
83/* Depending on the VMS version, the tms structure is perhaps defined.
84 The __TMS macro will show if it was. If it wasn't defined, we should
85 undefine TIMES, since that tells the rest of the program how things
86 should be handled. -- Richard Levitte */
87#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
88#undef TIMES
89#endif
90
91#ifndef TIMES
92#include <sys/timeb.h>
93#endif
94
95
96#if defined(sun) || defined(__ultrix)
97#define _POSIX_SOURCE
98#include <limits.h>
99#include <sys/param.h>
100#endif
101
102#include <openssl/des.h>
103#include "spr.h"
104
105#define DES_DEFAULT_OPTIONS
106
107#if !defined(PART1) && !defined(PART2) && !defined(PART3) && !defined(PART4)
108#define PART1
109#define PART2
110#define PART3
111#define PART4
112#endif
113
114#ifdef PART1
115
116#undef DES_UNROLL
117#undef DES_RISC1
118#undef DES_RISC2
119#undef DES_PTR
120#undef D_ENCRYPT
121#define DES_encrypt1 des_encrypt_u4_cisc_idx
122#define DES_encrypt2 des_encrypt2_u4_cisc_idx
123#define DES_encrypt3 des_encrypt3_u4_cisc_idx
124#define DES_decrypt3 des_decrypt3_u4_cisc_idx
125#undef HEADER_DES_LOCL_H
126#include "des_enc.c"
127
128#define DES_UNROLL
129#undef DES_RISC1
130#undef DES_RISC2
131#undef DES_PTR
132#undef D_ENCRYPT
133#undef DES_encrypt1
134#undef DES_encrypt2
135#undef DES_encrypt3
136#undef DES_decrypt3
137#define DES_encrypt1 des_encrypt_u16_cisc_idx
138#define DES_encrypt2 des_encrypt2_u16_cisc_idx
139#define DES_encrypt3 des_encrypt3_u16_cisc_idx
140#define DES_decrypt3 des_decrypt3_u16_cisc_idx
141#undef HEADER_DES_LOCL_H
142#include "des_enc.c"
143
144#undef DES_UNROLL
145#define DES_RISC1
146#undef DES_RISC2
147#undef DES_PTR
148#undef D_ENCRYPT
149#undef DES_encrypt1
150#undef DES_encrypt2
151#undef DES_encrypt3
152#undef DES_decrypt3
153#define DES_encrypt1 des_encrypt_u4_risc1_idx
154#define DES_encrypt2 des_encrypt2_u4_risc1_idx
155#define DES_encrypt3 des_encrypt3_u4_risc1_idx
156#define DES_decrypt3 des_decrypt3_u4_risc1_idx
157#undef HEADER_DES_LOCL_H
158#include "des_enc.c"
159
160#endif
161
162#ifdef PART2
163
164#undef DES_UNROLL
165#undef DES_RISC1
166#define DES_RISC2
167#undef DES_PTR
168#undef D_ENCRYPT
169#undef DES_encrypt1
170#undef DES_encrypt2
171#undef DES_encrypt3
172#undef DES_decrypt3
173#define DES_encrypt1 des_encrypt_u4_risc2_idx
174#define DES_encrypt2 des_encrypt2_u4_risc2_idx
175#define DES_encrypt3 des_encrypt3_u4_risc2_idx
176#define DES_decrypt3 des_decrypt3_u4_risc2_idx
177#undef HEADER_DES_LOCL_H
178#include "des_enc.c"
179
180#define DES_UNROLL
181#define DES_RISC1
182#undef DES_RISC2
183#undef DES_PTR
184#undef D_ENCRYPT
185#undef DES_encrypt1
186#undef DES_encrypt2
187#undef DES_encrypt3
188#undef DES_decrypt3
189#define DES_encrypt1 des_encrypt_u16_risc1_idx
190#define DES_encrypt2 des_encrypt2_u16_risc1_idx
191#define DES_encrypt3 des_encrypt3_u16_risc1_idx
192#define DES_decrypt3 des_decrypt3_u16_risc1_idx
193#undef HEADER_DES_LOCL_H
194#include "des_enc.c"
195
196#define DES_UNROLL
197#undef DES_RISC1
198#define DES_RISC2
199#undef DES_PTR
200#undef D_ENCRYPT
201#undef DES_encrypt1
202#undef DES_encrypt2
203#undef DES_encrypt3
204#undef DES_decrypt3
205#define DES_encrypt1 des_encrypt_u16_risc2_idx
206#define DES_encrypt2 des_encrypt2_u16_risc2_idx
207#define DES_encrypt3 des_encrypt3_u16_risc2_idx
208#define DES_decrypt3 des_decrypt3_u16_risc2_idx
209#undef HEADER_DES_LOCL_H
210#include "des_enc.c"
211
212#endif
213
214#ifdef PART3
215
216#undef DES_UNROLL
217#undef DES_RISC1
218#undef DES_RISC2
219#define DES_PTR
220#undef D_ENCRYPT
221#undef DES_encrypt1
222#undef DES_encrypt2
223#undef DES_encrypt3
224#undef DES_decrypt3
225#define DES_encrypt1 des_encrypt_u4_cisc_ptr
226#define DES_encrypt2 des_encrypt2_u4_cisc_ptr
227#define DES_encrypt3 des_encrypt3_u4_cisc_ptr
228#define DES_decrypt3 des_decrypt3_u4_cisc_ptr
229#undef HEADER_DES_LOCL_H
230#include "des_enc.c"
231
232#define DES_UNROLL
233#undef DES_RISC1
234#undef DES_RISC2
235#define DES_PTR
236#undef D_ENCRYPT
237#undef DES_encrypt1
238#undef DES_encrypt2
239#undef DES_encrypt3
240#undef DES_decrypt3
241#define DES_encrypt1 des_encrypt_u16_cisc_ptr
242#define DES_encrypt2 des_encrypt2_u16_cisc_ptr
243#define DES_encrypt3 des_encrypt3_u16_cisc_ptr
244#define DES_decrypt3 des_decrypt3_u16_cisc_ptr
245#undef HEADER_DES_LOCL_H
246#include "des_enc.c"
247
248#undef DES_UNROLL
249#define DES_RISC1
250#undef DES_RISC2
251#define DES_PTR
252#undef D_ENCRYPT
253#undef DES_encrypt1
254#undef DES_encrypt2
255#undef DES_encrypt3
256#undef DES_decrypt3
257#define DES_encrypt1 des_encrypt_u4_risc1_ptr
258#define DES_encrypt2 des_encrypt2_u4_risc1_ptr
259#define DES_encrypt3 des_encrypt3_u4_risc1_ptr
260#define DES_decrypt3 des_decrypt3_u4_risc1_ptr
261#undef HEADER_DES_LOCL_H
262#include "des_enc.c"
263
264#endif
265
266#ifdef PART4
267
268#undef DES_UNROLL
269#undef DES_RISC1
270#define DES_RISC2
271#define DES_PTR
272#undef D_ENCRYPT
273#undef DES_encrypt1
274#undef DES_encrypt2
275#undef DES_encrypt3
276#undef DES_decrypt3
277#define DES_encrypt1 des_encrypt_u4_risc2_ptr
278#define DES_encrypt2 des_encrypt2_u4_risc2_ptr
279#define DES_encrypt3 des_encrypt3_u4_risc2_ptr
280#define DES_decrypt3 des_decrypt3_u4_risc2_ptr
281#undef HEADER_DES_LOCL_H
282#include "des_enc.c"
283
284#define DES_UNROLL
285#define DES_RISC1
286#undef DES_RISC2
287#define DES_PTR
288#undef D_ENCRYPT
289#undef DES_encrypt1
290#undef DES_encrypt2
291#undef DES_encrypt3
292#undef DES_decrypt3
293#define DES_encrypt1 des_encrypt_u16_risc1_ptr
294#define DES_encrypt2 des_encrypt2_u16_risc1_ptr
295#define DES_encrypt3 des_encrypt3_u16_risc1_ptr
296#define DES_decrypt3 des_decrypt3_u16_risc1_ptr
297#undef HEADER_DES_LOCL_H
298#include "des_enc.c"
299
300#define DES_UNROLL
301#undef DES_RISC1
302#define DES_RISC2
303#define DES_PTR
304#undef D_ENCRYPT
305#undef DES_encrypt1
306#undef DES_encrypt2
307#undef DES_encrypt3
308#undef DES_decrypt3
309#define DES_encrypt1 des_encrypt_u16_risc2_ptr
310#define DES_encrypt2 des_encrypt2_u16_risc2_ptr
311#define DES_encrypt3 des_encrypt3_u16_risc2_ptr
312#define DES_decrypt3 des_decrypt3_u16_risc2_ptr
313#undef HEADER_DES_LOCL_H
314#include "des_enc.c"
315
316#endif
317
318/* The following if from times(3) man page. It may need to be changed */
319#ifndef HZ
320# ifndef CLK_TCK
321# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
322# define HZ 100.0
323# else /* _BSD_CLK_TCK_ */
324# define HZ ((double)_BSD_CLK_TCK_)
325# endif
326# else /* CLK_TCK */
327# define HZ ((double)CLK_TCK)
328# endif
329#endif
330
331#define BUFSIZE ((long)1024)
332long run=0;
333
334double Time_F(int s);
335#ifdef SIGALRM
336#if defined(__STDC__) || defined(sgi)
337#define SIGRETTYPE void
338#else
339#define SIGRETTYPE int
340#endif
341
342SIGRETTYPE sig_done(int sig);
343SIGRETTYPE sig_done(int sig)
344 {
345 signal(SIGALRM,sig_done);
346 run=0;
347#ifdef LINT
348 sig=sig;
349#endif
350 }
351#endif
352
353#define START 0
354#define STOP 1
355
356double Time_F(int s)
357 {
358 double ret;
359#ifdef TIMES
360 static struct tms tstart,tend;
361
362 if (s == START)
363 {
364 times(&tstart);
365 return(0);
366 }
367 else
368 {
369 times(&tend);
370 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
371 return((ret == 0.0)?1e-6:ret);
372 }
373#else /* !times() */
374 static struct timeb tstart,tend;
375 long i;
376
377 if (s == START)
378 {
379 ftime(&tstart);
380 return(0);
381 }
382 else
383 {
384 ftime(&tend);
385 i=(long)tend.millitm-(long)tstart.millitm;
386 ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
387 return((ret == 0.0)?1e-6:ret);
388 }
389#endif
390 }
391
392#ifdef SIGALRM
393#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
394#else
395#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
396#endif
397
398#define time_it(func,name,index) \
399 print_name(name); \
400 Time_F(START); \
401 for (count=0,run=1; COND(cb); count++) \
402 { \
403 unsigned long d[2]; \
404 func(d,&sch,DES_ENCRYPT); \
405 } \
406 tm[index]=Time_F(STOP); \
407 fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
408 tm[index]=((double)COUNT(cb))/tm[index];
409
410#define print_it(name,index) \
411 fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
412 tm[index]*8,1.0e6/tm[index]);
413
414int main(int argc, char **argv)
415 {
416 long count;
417 static unsigned char buf[BUFSIZE];
418 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
419 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
420 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
421 DES_key_schedule sch,sch2,sch3;
422 double d,tm[16],max=0;
423 int rank[16];
424 char *str[16];
425 int max_idx=0,i,num=0,j;
426#ifndef SIGALARM
427 long ca,cb,cc,cd,ce;
428#endif
429
430 for (i=0; i<12; i++)
431 {
432 tm[i]=0.0;
433 rank[i]=0;
434 }
435
436#ifndef TIMES
437 fprintf(stderr,"To get the most accurate results, try to run this\n");
438 fprintf(stderr,"program when this computer is idle.\n");
439#endif
440
441 DES_set_key_unchecked(&key,&sch);
442 DES_set_key_unchecked(&key2,&sch2);
443 DES_set_key_unchecked(&key3,&sch3);
444
445#ifndef SIGALRM
446 fprintf(stderr,"First we calculate the approximate speed ...\n");
447 DES_set_key_unchecked(&key,sch);
448 count=10;
449 do {
450 long i;
451 unsigned long data[2];
452
453 count*=2;
454 Time_F(START);
455 for (i=count; i; i--)
456 DES_encrypt1(data,&(sch[0]),DES_ENCRYPT);
457 d=Time_F(STOP);
458 } while (d < 3.0);
459 ca=count;
460 cb=count*3;
461 cc=count*3*8/BUFSIZE+1;
462 cd=count*8/BUFSIZE+1;
463
464 ce=count/20+1;
465#define COND(d) (count != (d))
466#define COUNT(d) (d)
467#else
468#define COND(c) (run)
469#define COUNT(d) (count)
470 signal(SIGALRM,sig_done);
471 alarm(10);
472#endif
473
474#ifdef PART1
475 time_it(des_encrypt_u4_cisc_idx, "des_encrypt_u4_cisc_idx ", 0);
476 time_it(des_encrypt_u16_cisc_idx, "des_encrypt_u16_cisc_idx ", 1);
477 time_it(des_encrypt_u4_risc1_idx, "des_encrypt_u4_risc1_idx ", 2);
478 num+=3;
479#endif
480#ifdef PART2
481 time_it(des_encrypt_u16_risc1_idx,"des_encrypt_u16_risc1_idx", 3);
482 time_it(des_encrypt_u4_risc2_idx, "des_encrypt_u4_risc2_idx ", 4);
483 time_it(des_encrypt_u16_risc2_idx,"des_encrypt_u16_risc2_idx", 5);
484 num+=3;
485#endif
486#ifdef PART3
487 time_it(des_encrypt_u4_cisc_ptr, "des_encrypt_u4_cisc_ptr ", 6);
488 time_it(des_encrypt_u16_cisc_ptr, "des_encrypt_u16_cisc_ptr ", 7);
489 time_it(des_encrypt_u4_risc1_ptr, "des_encrypt_u4_risc1_ptr ", 8);
490 num+=3;
491#endif
492#ifdef PART4
493 time_it(des_encrypt_u16_risc1_ptr,"des_encrypt_u16_risc1_ptr", 9);
494 time_it(des_encrypt_u4_risc2_ptr, "des_encrypt_u4_risc2_ptr ",10);
495 time_it(des_encrypt_u16_risc2_ptr,"des_encrypt_u16_risc2_ptr",11);
496 num+=3;
497#endif
498
499#ifdef PART1
500 str[0]=" 4 c i";
501 print_it("des_encrypt_u4_cisc_idx ",0);
502 max=tm[0];
503 max_idx=0;
504 str[1]="16 c i";
505 print_it("des_encrypt_u16_cisc_idx ",1);
506 if (max < tm[1]) { max=tm[1]; max_idx=1; }
507 str[2]=" 4 r1 i";
508 print_it("des_encrypt_u4_risc1_idx ",2);
509 if (max < tm[2]) { max=tm[2]; max_idx=2; }
510#endif
511#ifdef PART2
512 str[3]="16 r1 i";
513 print_it("des_encrypt_u16_risc1_idx",3);
514 if (max < tm[3]) { max=tm[3]; max_idx=3; }
515 str[4]=" 4 r2 i";
516 print_it("des_encrypt_u4_risc2_idx ",4);
517 if (max < tm[4]) { max=tm[4]; max_idx=4; }
518 str[5]="16 r2 i";
519 print_it("des_encrypt_u16_risc2_idx",5);
520 if (max < tm[5]) { max=tm[5]; max_idx=5; }
521#endif
522#ifdef PART3
523 str[6]=" 4 c p";
524 print_it("des_encrypt_u4_cisc_ptr ",6);
525 if (max < tm[6]) { max=tm[6]; max_idx=6; }
526 str[7]="16 c p";
527 print_it("des_encrypt_u16_cisc_ptr ",7);
528 if (max < tm[7]) { max=tm[7]; max_idx=7; }
529 str[8]=" 4 r1 p";
530 print_it("des_encrypt_u4_risc1_ptr ",8);
531 if (max < tm[8]) { max=tm[8]; max_idx=8; }
532#endif
533#ifdef PART4
534 str[9]="16 r1 p";
535 print_it("des_encrypt_u16_risc1_ptr",9);
536 if (max < tm[9]) { max=tm[9]; max_idx=9; }
537 str[10]=" 4 r2 p";
538 print_it("des_encrypt_u4_risc2_ptr ",10);
539 if (max < tm[10]) { max=tm[10]; max_idx=10; }
540 str[11]="16 r2 p";
541 print_it("des_encrypt_u16_risc2_ptr",11);
542 if (max < tm[11]) { max=tm[11]; max_idx=11; }
543#endif
544 printf("options des ecb/s\n");
545 printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
546 d=tm[max_idx];
547 tm[max_idx]= -2.0;
548 max= -1.0;
549 for (;;)
550 {
551 for (i=0; i<12; i++)
552 {
553 if (max < tm[i]) { max=tm[i]; j=i; }
554 }
555 if (max < 0.0) break;
556 printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
557 tm[j]= -2.0;
558 max= -1.0;
559 }
560
561 switch (max_idx)
562 {
563 case 0:
564 printf("-DDES_DEFAULT_OPTIONS\n");
565 break;
566 case 1:
567 printf("-DDES_UNROLL\n");
568 break;
569 case 2:
570 printf("-DDES_RISC1\n");
571 break;
572 case 3:
573 printf("-DDES_UNROLL -DDES_RISC1\n");
574 break;
575 case 4:
576 printf("-DDES_RISC2\n");
577 break;
578 case 5:
579 printf("-DDES_UNROLL -DDES_RISC2\n");
580 break;
581 case 6:
582 printf("-DDES_PTR\n");
583 break;
584 case 7:
585 printf("-DDES_UNROLL -DDES_PTR\n");
586 break;
587 case 8:
588 printf("-DDES_RISC1 -DDES_PTR\n");
589 break;
590 case 9:
591 printf("-DDES_UNROLL -DDES_RISC1 -DDES_PTR\n");
592 break;
593 case 10:
594 printf("-DDES_RISC2 -DDES_PTR\n");
595 break;
596 case 11:
597 printf("-DDES_UNROLL -DDES_RISC2 -DDES_PTR\n");
598 break;
599 }
600 exit(0);
601#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
602 return(0);
603#endif
604 }
diff --git a/src/lib/libcrypto/des/des_ver.h b/src/lib/libcrypto/des/des_ver.h
new file mode 100644
index 0000000000..379bbadda2
--- /dev/null
+++ b/src/lib/libcrypto/des/des_ver.h
@@ -0,0 +1,71 @@
1/* crypto/des/des_ver.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/e_os2.h>
60
61#ifdef OPENSSL_BUILD_SHLIBCRYPTO
62# undef OPENSSL_EXTERN
63# define OPENSSL_EXTERN OPENSSL_EXPORT
64#endif
65
66/* The following macros make sure the names are different from libdes names */
67#define DES_version OSSL_DES_version
68#define libdes_version OSSL_libdes_version
69
70OPENSSL_EXTERN const char *OSSL_DES_version; /* SSLeay version string */
71OPENSSL_EXTERN const char *OSSL_libdes_version; /* old libdes version string */
diff --git a/src/lib/libcrypto/des/dess.cpp b/src/lib/libcrypto/des/dess.cpp
new file mode 100644
index 0000000000..5549bab90a
--- /dev/null
+++ b/src/lib/libcrypto/des/dess.cpp
@@ -0,0 +1,67 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/des.h>
36
37void main(int argc,char *argv[])
38 {
39 des_key_schedule key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43
44 for (j=0; j<6; j++)
45 {
46 for (i=0; i<1000; i++) /**/
47 {
48 des_encrypt1(&data[0],key,1);
49 GetTSC(s1);
50 des_encrypt1(&data[0],key,1);
51 des_encrypt1(&data[0],key,1);
52 des_encrypt1(&data[0],key,1);
53 GetTSC(e1);
54 GetTSC(s2);
55 des_encrypt1(&data[0],key,1);
56 des_encrypt1(&data[0],key,1);
57 des_encrypt1(&data[0],key,1);
58 des_encrypt1(&data[0],key,1);
59 GetTSC(e2);
60 des_encrypt1(&data[0],key,1);
61 }
62
63 printf("des %d %d (%d)\n",
64 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
65 }
66 }
67
diff --git a/src/lib/libcrypto/des/destest.c b/src/lib/libcrypto/des/destest.c
new file mode 100644
index 0000000000..e3e9d77f14
--- /dev/null
+++ b/src/lib/libcrypto/des/destest.c
@@ -0,0 +1,948 @@
1/* crypto/des/destest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61
62#include <openssl/e_os2.h>
63#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_WINDOWS)
64#ifndef OPENSSL_SYS_MSDOS
65#define OPENSSL_SYS_MSDOS
66#endif
67#endif
68
69#ifndef OPENSSL_SYS_MSDOS
70#if !defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_VMS_DECC)
71#include OPENSSL_UNISTD
72#endif
73#else
74#include <io.h>
75#endif
76#include <string.h>
77
78#ifdef OPENSSL_NO_DES
79int main(int argc, char *argv[])
80{
81 printf("No DES support\n");
82 return(0);
83}
84#else
85#include <openssl/des.h>
86
87#define crypt(c,s) (des_crypt((c),(s)))
88
89/* tisk tisk - the test keys don't all have odd parity :-( */
90/* test data */
91#define NUM_TESTS 34
92static unsigned char key_data[NUM_TESTS][8]={
93 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
94 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
95 {0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
96 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
97 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
98 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
99 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
100 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10},
101 {0x7C,0xA1,0x10,0x45,0x4A,0x1A,0x6E,0x57},
102 {0x01,0x31,0xD9,0x61,0x9D,0xC1,0x37,0x6E},
103 {0x07,0xA1,0x13,0x3E,0x4A,0x0B,0x26,0x86},
104 {0x38,0x49,0x67,0x4C,0x26,0x02,0x31,0x9E},
105 {0x04,0xB9,0x15,0xBA,0x43,0xFE,0xB5,0xB6},
106 {0x01,0x13,0xB9,0x70,0xFD,0x34,0xF2,0xCE},
107 {0x01,0x70,0xF1,0x75,0x46,0x8F,0xB5,0xE6},
108 {0x43,0x29,0x7F,0xAD,0x38,0xE3,0x73,0xFE},
109 {0x07,0xA7,0x13,0x70,0x45,0xDA,0x2A,0x16},
110 {0x04,0x68,0x91,0x04,0xC2,0xFD,0x3B,0x2F},
111 {0x37,0xD0,0x6B,0xB5,0x16,0xCB,0x75,0x46},
112 {0x1F,0x08,0x26,0x0D,0x1A,0xC2,0x46,0x5E},
113 {0x58,0x40,0x23,0x64,0x1A,0xBA,0x61,0x76},
114 {0x02,0x58,0x16,0x16,0x46,0x29,0xB0,0x07},
115 {0x49,0x79,0x3E,0xBC,0x79,0xB3,0x25,0x8F},
116 {0x4F,0xB0,0x5E,0x15,0x15,0xAB,0x73,0xA7},
117 {0x49,0xE9,0x5D,0x6D,0x4C,0xA2,0x29,0xBF},
118 {0x01,0x83,0x10,0xDC,0x40,0x9B,0x26,0xD6},
119 {0x1C,0x58,0x7F,0x1C,0x13,0x92,0x4F,0xEF},
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E},
122 {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE},
123 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
124 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
125 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
126 {0xFE,0xDC,0xBA,0x98,0x76,0x54,0x32,0x10}};
127
128static unsigned char plain_data[NUM_TESTS][8]={
129 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
130 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
131 {0x10,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
132 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
133 {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11},
134 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
135 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
136 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
137 {0x01,0xA1,0xD6,0xD0,0x39,0x77,0x67,0x42},
138 {0x5C,0xD5,0x4C,0xA8,0x3D,0xEF,0x57,0xDA},
139 {0x02,0x48,0xD4,0x38,0x06,0xF6,0x71,0x72},
140 {0x51,0x45,0x4B,0x58,0x2D,0xDF,0x44,0x0A},
141 {0x42,0xFD,0x44,0x30,0x59,0x57,0x7F,0xA2},
142 {0x05,0x9B,0x5E,0x08,0x51,0xCF,0x14,0x3A},
143 {0x07,0x56,0xD8,0xE0,0x77,0x47,0x61,0xD2},
144 {0x76,0x25,0x14,0xB8,0x29,0xBF,0x48,0x6A},
145 {0x3B,0xDD,0x11,0x90,0x49,0x37,0x28,0x02},
146 {0x26,0x95,0x5F,0x68,0x35,0xAF,0x60,0x9A},
147 {0x16,0x4D,0x5E,0x40,0x4F,0x27,0x52,0x32},
148 {0x6B,0x05,0x6E,0x18,0x75,0x9F,0x5C,0xCA},
149 {0x00,0x4B,0xD6,0xEF,0x09,0x17,0x60,0x62},
150 {0x48,0x0D,0x39,0x00,0x6E,0xE7,0x62,0xF2},
151 {0x43,0x75,0x40,0xC8,0x69,0x8F,0x3C,0xFA},
152 {0x07,0x2D,0x43,0xA0,0x77,0x07,0x52,0x92},
153 {0x02,0xFE,0x55,0x77,0x81,0x17,0xF1,0x2A},
154 {0x1D,0x9D,0x5C,0x50,0x18,0xF7,0x28,0xC2},
155 {0x30,0x55,0x32,0x28,0x6D,0x6F,0x29,0x5A},
156 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
157 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
158 {0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF},
159 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
160 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
161 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
162 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF}};
163
164static unsigned char cipher_data[NUM_TESTS][8]={
165 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
166 {0x73,0x59,0xB2,0x16,0x3E,0x4E,0xDC,0x58},
167 {0x95,0x8E,0x6E,0x62,0x7A,0x05,0x55,0x7B},
168 {0xF4,0x03,0x79,0xAB,0x9E,0x0E,0xC5,0x33},
169 {0x17,0x66,0x8D,0xFC,0x72,0x92,0x53,0x2D},
170 {0x8A,0x5A,0xE1,0xF8,0x1A,0xB8,0xF2,0xDD},
171 {0x8C,0xA6,0x4D,0xE9,0xC1,0xB1,0x23,0xA7},
172 {0xED,0x39,0xD9,0x50,0xFA,0x74,0xBC,0xC4},
173 {0x69,0x0F,0x5B,0x0D,0x9A,0x26,0x93,0x9B},
174 {0x7A,0x38,0x9D,0x10,0x35,0x4B,0xD2,0x71},
175 {0x86,0x8E,0xBB,0x51,0xCA,0xB4,0x59,0x9A},
176 {0x71,0x78,0x87,0x6E,0x01,0xF1,0x9B,0x2A},
177 {0xAF,0x37,0xFB,0x42,0x1F,0x8C,0x40,0x95},
178 {0x86,0xA5,0x60,0xF1,0x0E,0xC6,0xD8,0x5B},
179 {0x0C,0xD3,0xDA,0x02,0x00,0x21,0xDC,0x09},
180 {0xEA,0x67,0x6B,0x2C,0xB7,0xDB,0x2B,0x7A},
181 {0xDF,0xD6,0x4A,0x81,0x5C,0xAF,0x1A,0x0F},
182 {0x5C,0x51,0x3C,0x9C,0x48,0x86,0xC0,0x88},
183 {0x0A,0x2A,0xEE,0xAE,0x3F,0xF4,0xAB,0x77},
184 {0xEF,0x1B,0xF0,0x3E,0x5D,0xFA,0x57,0x5A},
185 {0x88,0xBF,0x0D,0xB6,0xD7,0x0D,0xEE,0x56},
186 {0xA1,0xF9,0x91,0x55,0x41,0x02,0x0B,0x56},
187 {0x6F,0xBF,0x1C,0xAF,0xCF,0xFD,0x05,0x56},
188 {0x2F,0x22,0xE4,0x9B,0xAB,0x7C,0xA1,0xAC},
189 {0x5A,0x6B,0x61,0x2C,0xC2,0x6C,0xCE,0x4A},
190 {0x5F,0x4C,0x03,0x8E,0xD1,0x2B,0x2E,0x41},
191 {0x63,0xFA,0xC0,0xD0,0x34,0xD9,0xF7,0x93},
192 {0x61,0x7B,0x3A,0x0C,0xE8,0xF0,0x71,0x00},
193 {0xDB,0x95,0x86,0x05,0xF8,0xC8,0xC6,0x06},
194 {0xED,0xBF,0xD1,0xC6,0x6C,0x29,0xCC,0xC7},
195 {0x35,0x55,0x50,0xB2,0x15,0x0E,0x24,0x51},
196 {0xCA,0xAA,0xAF,0x4D,0xEA,0xF1,0xDB,0xAE},
197 {0xD5,0xD4,0x4F,0xF7,0x20,0x68,0x3D,0x0D},
198 {0x2A,0x2B,0xB0,0x08,0xDF,0x97,0xC2,0xF2}};
199
200static unsigned char cipher_ecb2[NUM_TESTS-1][8]={
201 {0x92,0x95,0xB5,0x9B,0xB3,0x84,0x73,0x6E},
202 {0x19,0x9E,0x9D,0x6D,0xF3,0x9A,0xA8,0x16},
203 {0x2A,0x4B,0x4D,0x24,0x52,0x43,0x84,0x27},
204 {0x35,0x84,0x3C,0x01,0x9D,0x18,0xC5,0xB6},
205 {0x4A,0x5B,0x2F,0x42,0xAA,0x77,0x19,0x25},
206 {0xA0,0x6B,0xA9,0xB8,0xCA,0x5B,0x17,0x8A},
207 {0xAB,0x9D,0xB7,0xFB,0xED,0x95,0xF2,0x74},
208 {0x3D,0x25,0x6C,0x23,0xA7,0x25,0x2F,0xD6},
209 {0xB7,0x6F,0xAB,0x4F,0xBD,0xBD,0xB7,0x67},
210 {0x8F,0x68,0x27,0xD6,0x9C,0xF4,0x1A,0x10},
211 {0x82,0x57,0xA1,0xD6,0x50,0x5E,0x81,0x85},
212 {0xA2,0x0F,0x0A,0xCD,0x80,0x89,0x7D,0xFA},
213 {0xCD,0x2A,0x53,0x3A,0xDB,0x0D,0x7E,0xF3},
214 {0xD2,0xC2,0xBE,0x27,0xE8,0x1B,0x68,0xE3},
215 {0xE9,0x24,0xCF,0x4F,0x89,0x3C,0x5B,0x0A},
216 {0xA7,0x18,0xC3,0x9F,0xFA,0x9F,0xD7,0x69},
217 {0x77,0x2C,0x79,0xB1,0xD2,0x31,0x7E,0xB1},
218 {0x49,0xAB,0x92,0x7F,0xD0,0x22,0x00,0xB7},
219 {0xCE,0x1C,0x6C,0x7D,0x85,0xE3,0x4A,0x6F},
220 {0xBE,0x91,0xD6,0xE1,0x27,0xB2,0xE9,0x87},
221 {0x70,0x28,0xAE,0x8F,0xD1,0xF5,0x74,0x1A},
222 {0xAA,0x37,0x80,0xBB,0xF3,0x22,0x1D,0xDE},
223 {0xA6,0xC4,0xD2,0x5E,0x28,0x93,0xAC,0xB3},
224 {0x22,0x07,0x81,0x5A,0xE4,0xB7,0x1A,0xAD},
225 {0xDC,0xCE,0x05,0xE7,0x07,0xBD,0xF5,0x84},
226 {0x26,0x1D,0x39,0x2C,0xB3,0xBA,0xA5,0x85},
227 {0xB4,0xF7,0x0F,0x72,0xFB,0x04,0xF0,0xDC},
228 {0x95,0xBA,0xA9,0x4E,0x87,0x36,0xF2,0x89},
229 {0xD4,0x07,0x3A,0xF1,0x5A,0x17,0x82,0x0E},
230 {0xEF,0x6F,0xAF,0xA7,0x66,0x1A,0x7E,0x89},
231 {0xC1,0x97,0xF5,0x58,0x74,0x8A,0x20,0xE7},
232 {0x43,0x34,0xCF,0xDA,0x22,0xC4,0x86,0xC8},
233 {0x08,0xD7,0xB4,0xFB,0x62,0x9D,0x08,0x85}};
234
235static unsigned char cbc_key [8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
236static unsigned char cbc2_key[8]={0xf1,0xe0,0xd3,0xc2,0xb5,0xa4,0x97,0x86};
237static unsigned char cbc3_key[8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
238static unsigned char cbc_iv [8]={0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10};
239/* Changed the following text constant to binary so it will work on ebcdic
240 * machines :-) */
241/* static char cbc_data[40]="7654321 Now is the time for \0001"; */
242static unsigned char cbc_data[40]={
243 0x37,0x36,0x35,0x34,0x33,0x32,0x31,0x20,
244 0x4E,0x6F,0x77,0x20,0x69,0x73,0x20,0x74,
245 0x68,0x65,0x20,0x74,0x69,0x6D,0x65,0x20,
246 0x66,0x6F,0x72,0x20,0x00,0x31,0x00,0x00,
247 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
248 };
249
250static unsigned char cbc_ok[32]={
251 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
252 0xac,0xd8,0xae,0xfd,0xdf,0xd8,0xa1,0xeb,
253 0x46,0x8e,0x91,0x15,0x78,0x88,0xba,0x68,
254 0x1d,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
255
256#ifdef SCREW_THE_PARITY
257#error "SCREW_THE_PARITY is not ment to be defined."
258#error "Original vectors are preserved for reference only."
259static unsigned char cbc2_key[8]={0xf0,0xe1,0xd2,0xc3,0xb4,0xa5,0x96,0x87};
260static unsigned char xcbc_ok[32]={
261 0x86,0x74,0x81,0x0D,0x61,0xA4,0xA5,0x48,
262 0xB9,0x93,0x03,0xE1,0xB8,0xBB,0xBD,0xBD,
263 0x64,0x30,0x0B,0xB9,0x06,0x65,0x81,0x76,
264 0x04,0x1D,0x77,0x62,0x17,0xCA,0x2B,0xD2,
265 };
266#else
267static unsigned char xcbc_ok[32]={
268 0x84,0x6B,0x29,0x14,0x85,0x1E,0x9A,0x29,
269 0x54,0x73,0x2F,0x8A,0xA0,0xA6,0x11,0xC1,
270 0x15,0xCD,0xC2,0xD7,0x95,0x1B,0x10,0x53,
271 0xA6,0x3C,0x5E,0x03,0xB2,0x1A,0xA3,0xC4,
272 };
273#endif
274
275static unsigned char cbc3_ok[32]={
276 0x3F,0xE3,0x01,0xC9,0x62,0xAC,0x01,0xD0,
277 0x22,0x13,0x76,0x3C,0x1C,0xBD,0x4C,0xDC,
278 0x79,0x96,0x57,0xC0,0x64,0xEC,0xF5,0xD4,
279 0x1C,0x67,0x38,0x12,0xCF,0xDE,0x96,0x75};
280
281static unsigned char pcbc_ok[32]={
282 0xcc,0xd1,0x73,0xff,0xab,0x20,0x39,0xf4,
283 0x6d,0xec,0xb4,0x70,0xa0,0xe5,0x6b,0x15,
284 0xae,0xa6,0xbf,0x61,0xed,0x7d,0x9c,0x9f,
285 0xf7,0x17,0x46,0x3b,0x8a,0xb3,0xcc,0x88};
286
287static unsigned char cfb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
288static unsigned char cfb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
289static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
290static unsigned char plain[24]=
291 {
292 0x4e,0x6f,0x77,0x20,0x69,0x73,
293 0x20,0x74,0x68,0x65,0x20,0x74,
294 0x69,0x6d,0x65,0x20,0x66,0x6f,
295 0x72,0x20,0x61,0x6c,0x6c,0x20
296 };
297static unsigned char cfb_cipher8[24]= {
298 0xf3,0x1f,0xda,0x07,0x01,0x14, 0x62,0xee,0x18,0x7f,0x43,0xd8,
299 0x0a,0x7c,0xd9,0xb5,0xb0,0xd2, 0x90,0xda,0x6e,0x5b,0x9a,0x87 };
300static unsigned char cfb_cipher16[24]={
301 0xF3,0x09,0x87,0x87,0x7F,0x57, 0xF7,0x3C,0x36,0xB6,0xDB,0x70,
302 0xD8,0xD5,0x34,0x19,0xD3,0x86, 0xB2,0x23,0xB7,0xB2,0xAD,0x1B };
303static unsigned char cfb_cipher32[24]={
304 0xF3,0x09,0x62,0x49,0xA4,0xDF, 0xA4,0x9F,0x33,0xDC,0x7B,0xAD,
305 0x4C,0xC8,0x9F,0x64,0xE4,0x53, 0xE5,0xEC,0x67,0x20,0xDA,0xB6 };
306static unsigned char cfb_cipher48[24]={
307 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x30,0xB5,0x15,0xEC,0xBB,0x85,
308 0x97,0x5A,0x13,0x8C,0x68,0x60, 0xE2,0x38,0x34,0x3C,0xDC,0x1F };
309static unsigned char cfb_cipher64[24]={
310 0xF3,0x09,0x62,0x49,0xC7,0xF4, 0x6E,0x51,0xA6,0x9E,0x83,0x9B,
311 0x1A,0x92,0xF7,0x84,0x03,0x46, 0x71,0x33,0x89,0x8E,0xA6,0x22 };
312
313static unsigned char ofb_key[8]={0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef};
314static unsigned char ofb_iv[8]={0x12,0x34,0x56,0x78,0x90,0xab,0xcd,0xef};
315static unsigned char ofb_buf1[24],ofb_buf2[24],ofb_tmp[8];
316static unsigned char ofb_cipher[24]=
317 {
318 0xf3,0x09,0x62,0x49,0xc7,0xf4,0x6e,0x51,
319 0x35,0xf2,0x4a,0x24,0x2e,0xeb,0x3d,0x3f,
320 0x3d,0x6d,0x5b,0xe3,0x25,0x5a,0xf8,0xc3
321 };
322
323#if 0
324static DES_LONG cbc_cksum_ret=0xB462FEF7L;
325#else
326static DES_LONG cbc_cksum_ret=0xF7FE62B4L;
327#endif
328static unsigned char cbc_cksum_data[8]={0x1D,0x26,0x93,0x97,0xf7,0xfe,0x62,0xb4};
329
330static char *pt(unsigned char *p);
331static int cfb_test(int bits, unsigned char *cfb_cipher);
332static int cfb64_test(unsigned char *cfb_cipher);
333static int ede_cfb64_test(unsigned char *cfb_cipher);
334int main(int argc, char *argv[])
335 {
336 int i,j,err=0;
337 des_cblock in,out,outin,iv3,iv2;
338 des_key_schedule ks,ks2,ks3;
339 unsigned char cbc_in[40];
340 unsigned char cbc_out[40];
341 DES_LONG cs;
342 unsigned char cret[8];
343#ifdef _CRAY
344 struct {
345 int a:32;
346 int b:32;
347 } lqret[2];
348#else
349 DES_LONG lqret[4];
350#endif
351 int num;
352 char *str;
353
354#ifndef OPENSSL_NO_DESCBCM
355 printf("Doing cbcm\n");
356 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
357 {
358 printf("Key error %d\n",j);
359 err=1;
360 }
361 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
362 {
363 printf("Key error %d\n",j);
364 err=1;
365 }
366 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
367 {
368 printf("Key error %d\n",j);
369 err=1;
370 }
371 memset(cbc_out,0,40);
372 memset(cbc_in,0,40);
373 i=strlen((char *)cbc_data)+1;
374 /* i=((i+7)/8)*8; */
375 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
376 memset(iv2,'\0',sizeof iv2);
377
378 DES_ede3_cbcm_encrypt(cbc_data,cbc_out,16L,&ks,&ks2,&ks3,&iv3,&iv2,
379 DES_ENCRYPT);
380 DES_ede3_cbcm_encrypt(&cbc_data[16],&cbc_out[16],i-16,&ks,&ks2,&ks3,
381 &iv3,&iv2,DES_ENCRYPT);
382 /* if (memcmp(cbc_out,cbc3_ok,
383 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
384 {
385 printf("des_ede3_cbc_encrypt encrypt error\n");
386 err=1;
387 }
388 */
389 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
390 memset(iv2,'\0',sizeof iv2);
391 DES_ede3_cbcm_encrypt(cbc_out,cbc_in,i,&ks,&ks2,&ks3,&iv3,&iv2,DES_DECRYPT);
392 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
393 {
394 int n;
395
396 printf("des_ede3_cbcm_encrypt decrypt error\n");
397 for(n=0 ; n < i ; ++n)
398 printf(" %02x",cbc_data[n]);
399 printf("\n");
400 for(n=0 ; n < i ; ++n)
401 printf(" %02x",cbc_in[n]);
402 printf("\n");
403 err=1;
404 }
405#endif
406
407 printf("Doing ecb\n");
408 for (i=0; i<NUM_TESTS; i++)
409 {
410 DES_set_key_unchecked(&key_data[i],&ks);
411 memcpy(in,plain_data[i],8);
412 memset(out,0,8);
413 memset(outin,0,8);
414 des_ecb_encrypt(&in,&out,ks,DES_ENCRYPT);
415 des_ecb_encrypt(&out,&outin,ks,DES_DECRYPT);
416
417 if (memcmp(out,cipher_data[i],8) != 0)
418 {
419 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
420 i+1,pt(key_data[i]),pt(in),pt(cipher_data[i]),
421 pt(out));
422 err=1;
423 }
424 if (memcmp(in,outin,8) != 0)
425 {
426 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
427 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
428 err=1;
429 }
430 }
431
432#ifndef LIBDES_LIT
433 printf("Doing ede ecb\n");
434 for (i=0; i<(NUM_TESTS-2); i++)
435 {
436 DES_set_key_unchecked(&key_data[i],&ks);
437 DES_set_key_unchecked(&key_data[i+1],&ks2);
438 DES_set_key_unchecked(&key_data[i+2],&ks3);
439 memcpy(in,plain_data[i],8);
440 memset(out,0,8);
441 memset(outin,0,8);
442 des_ecb2_encrypt(in,out,ks,ks2,DES_ENCRYPT);
443 des_ecb2_encrypt(out,outin,ks,ks2,DES_DECRYPT);
444
445 if (memcmp(out,cipher_ecb2[i],8) != 0)
446 {
447 printf("Encryption error %2d\nk=%s p=%s o=%s act=%s\n",
448 i+1,pt(key_data[i]),pt(in),pt(cipher_ecb2[i]),
449 pt(out));
450 err=1;
451 }
452 if (memcmp(in,outin,8) != 0)
453 {
454 printf("Decryption error %2d\nk=%s p=%s o=%s act=%s\n",
455 i+1,pt(key_data[i]),pt(out),pt(in),pt(outin));
456 err=1;
457 }
458 }
459#endif
460
461 printf("Doing cbc\n");
462 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
463 {
464 printf("Key error %d\n",j);
465 err=1;
466 }
467 memset(cbc_out,0,40);
468 memset(cbc_in,0,40);
469 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
470 des_ncbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
471 &iv3,DES_ENCRYPT);
472 if (memcmp(cbc_out,cbc_ok,32) != 0)
473 {
474 printf("cbc_encrypt encrypt error\n");
475 err=1;
476 }
477
478 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
479 des_ncbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
480 &iv3,DES_DECRYPT);
481 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)) != 0)
482 {
483 printf("cbc_encrypt decrypt error\n");
484 err=1;
485 }
486
487#ifndef LIBDES_LIT
488 printf("Doing desx cbc\n");
489 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
490 {
491 printf("Key error %d\n",j);
492 err=1;
493 }
494 memset(cbc_out,0,40);
495 memset(cbc_in,0,40);
496 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
497 des_xcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
498 &iv3,&cbc2_key,&cbc3_key, DES_ENCRYPT);
499 if (memcmp(cbc_out,xcbc_ok,32) != 0)
500 {
501 printf("des_xcbc_encrypt encrypt error\n");
502 err=1;
503 }
504 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
505 des_xcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,
506 &iv3,&cbc2_key,&cbc3_key, DES_DECRYPT);
507 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
508 {
509 printf("des_xcbc_encrypt decrypt error\n");
510 err=1;
511 }
512#endif
513
514 printf("Doing ede cbc\n");
515 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
516 {
517 printf("Key error %d\n",j);
518 err=1;
519 }
520 if ((j=DES_set_key_checked(&cbc2_key,&ks2)) != 0)
521 {
522 printf("Key error %d\n",j);
523 err=1;
524 }
525 if ((j=DES_set_key_checked(&cbc3_key,&ks3)) != 0)
526 {
527 printf("Key error %d\n",j);
528 err=1;
529 }
530 memset(cbc_out,0,40);
531 memset(cbc_in,0,40);
532 i=strlen((char *)cbc_data)+1;
533 /* i=((i+7)/8)*8; */
534 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
535
536 des_ede3_cbc_encrypt(cbc_data,cbc_out,16L,ks,ks2,ks3,&iv3,
537 DES_ENCRYPT);
538 des_ede3_cbc_encrypt(&(cbc_data[16]),&(cbc_out[16]),i-16,ks,ks2,ks3,
539 &iv3,DES_ENCRYPT);
540 if (memcmp(cbc_out,cbc3_ok,
541 (unsigned int)(strlen((char *)cbc_data)+1+7)/8*8) != 0)
542 {
543 int n;
544
545 printf("des_ede3_cbc_encrypt encrypt error\n");
546 for(n=0 ; n < i ; ++n)
547 printf(" %02x",cbc_out[n]);
548 printf("\n");
549 for(n=0 ; n < i ; ++n)
550 printf(" %02x",cbc3_ok[n]);
551 printf("\n");
552 err=1;
553 }
554
555 memcpy(iv3,cbc_iv,sizeof(cbc_iv));
556 des_ede3_cbc_encrypt(cbc_out,cbc_in,i,ks,ks2,ks3,&iv3,DES_DECRYPT);
557 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
558 {
559 int n;
560
561 printf("des_ede3_cbc_encrypt decrypt error\n");
562 for(n=0 ; n < i ; ++n)
563 printf(" %02x",cbc_data[n]);
564 printf("\n");
565 for(n=0 ; n < i ; ++n)
566 printf(" %02x",cbc_in[n]);
567 printf("\n");
568 err=1;
569 }
570
571#ifndef LIBDES_LIT
572 printf("Doing pcbc\n");
573 if ((j=DES_set_key_checked(&cbc_key,&ks)) != 0)
574 {
575 printf("Key error %d\n",j);
576 err=1;
577 }
578 memset(cbc_out,0,40);
579 memset(cbc_in,0,40);
580 des_pcbc_encrypt(cbc_data,cbc_out,strlen((char *)cbc_data)+1,ks,
581 &cbc_iv,DES_ENCRYPT);
582 if (memcmp(cbc_out,pcbc_ok,32) != 0)
583 {
584 printf("pcbc_encrypt encrypt error\n");
585 err=1;
586 }
587 des_pcbc_encrypt(cbc_out,cbc_in,strlen((char *)cbc_data)+1,ks,&cbc_iv,
588 DES_DECRYPT);
589 if (memcmp(cbc_in,cbc_data,strlen((char *)cbc_data)+1) != 0)
590 {
591 printf("pcbc_encrypt decrypt error\n");
592 err=1;
593 }
594
595 printf("Doing ");
596 printf("cfb8 ");
597 err+=cfb_test(8,cfb_cipher8);
598 printf("cfb16 ");
599 err+=cfb_test(16,cfb_cipher16);
600 printf("cfb32 ");
601 err+=cfb_test(32,cfb_cipher32);
602 printf("cfb48 ");
603 err+=cfb_test(48,cfb_cipher48);
604 printf("cfb64 ");
605 err+=cfb_test(64,cfb_cipher64);
606
607 printf("cfb64() ");
608 err+=cfb64_test(cfb_cipher64);
609
610 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
611 for (i=0; i<sizeof(plain); i++)
612 des_cfb_encrypt(&(plain[i]),&(cfb_buf1[i]),
613 8,1,ks,&cfb_tmp,DES_ENCRYPT);
614 if (memcmp(cfb_cipher8,cfb_buf1,sizeof(plain)) != 0)
615 {
616 printf("cfb_encrypt small encrypt error\n");
617 err=1;
618 }
619
620 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
621 for (i=0; i<sizeof(plain); i++)
622 des_cfb_encrypt(&(cfb_buf1[i]),&(cfb_buf2[i]),
623 8,1,ks,&cfb_tmp,DES_DECRYPT);
624 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
625 {
626 printf("cfb_encrypt small decrypt error\n");
627 err=1;
628 }
629
630 printf("ede_cfb64() ");
631 err+=ede_cfb64_test(cfb_cipher64);
632
633 printf("done\n");
634
635 printf("Doing ofb\n");
636 DES_set_key_checked(&ofb_key,&ks);
637 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
638 des_ofb_encrypt(plain,ofb_buf1,64,sizeof(plain)/8,ks,&ofb_tmp);
639 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
640 {
641 printf("ofb_encrypt encrypt error\n");
642printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
643ofb_buf1[8+0], ofb_buf1[8+1], ofb_buf1[8+2], ofb_buf1[8+3],
644ofb_buf1[8+4], ofb_buf1[8+5], ofb_buf1[8+6], ofb_buf1[8+7]);
645printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
646ofb_buf1[8+0], ofb_cipher[8+1], ofb_cipher[8+2], ofb_cipher[8+3],
647ofb_buf1[8+4], ofb_cipher[8+5], ofb_cipher[8+6], ofb_cipher[8+7]);
648 err=1;
649 }
650 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
651 des_ofb_encrypt(ofb_buf1,ofb_buf2,64,sizeof(ofb_buf1)/8,ks,&ofb_tmp);
652 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
653 {
654 printf("ofb_encrypt decrypt error\n");
655printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
656ofb_buf2[8+0], ofb_buf2[8+1], ofb_buf2[8+2], ofb_buf2[8+3],
657ofb_buf2[8+4], ofb_buf2[8+5], ofb_buf2[8+6], ofb_buf2[8+7]);
658printf("%02X %02X %02X %02X %02X %02X %02X %02X\n",
659plain[8+0], plain[8+1], plain[8+2], plain[8+3],
660plain[8+4], plain[8+5], plain[8+6], plain[8+7]);
661 err=1;
662 }
663
664 printf("Doing ofb64\n");
665 DES_set_key_checked(&ofb_key,&ks);
666 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
667 memset(ofb_buf1,0,sizeof(ofb_buf1));
668 memset(ofb_buf2,0,sizeof(ofb_buf1));
669 num=0;
670 for (i=0; i<sizeof(plain); i++)
671 {
672 des_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,&ofb_tmp,
673 &num);
674 }
675 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
676 {
677 printf("ofb64_encrypt encrypt error\n");
678 err=1;
679 }
680 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
681 num=0;
682 des_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,&ofb_tmp,
683 &num);
684 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
685 {
686 printf("ofb64_encrypt decrypt error\n");
687 err=1;
688 }
689
690 printf("Doing ede_ofb64\n");
691 DES_set_key_checked(&ofb_key,&ks);
692 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
693 memset(ofb_buf1,0,sizeof(ofb_buf1));
694 memset(ofb_buf2,0,sizeof(ofb_buf1));
695 num=0;
696 for (i=0; i<sizeof(plain); i++)
697 {
698 des_ede3_ofb64_encrypt(&(plain[i]),&(ofb_buf1[i]),1,ks,ks,
699 ks,&ofb_tmp,&num);
700 }
701 if (memcmp(ofb_cipher,ofb_buf1,sizeof(ofb_buf1)) != 0)
702 {
703 printf("ede_ofb64_encrypt encrypt error\n");
704 err=1;
705 }
706 memcpy(ofb_tmp,ofb_iv,sizeof(ofb_iv));
707 num=0;
708 des_ede3_ofb64_encrypt(ofb_buf1,ofb_buf2,sizeof(ofb_buf1),ks,ks,ks,
709 &ofb_tmp,&num);
710 if (memcmp(plain,ofb_buf2,sizeof(ofb_buf2)) != 0)
711 {
712 printf("ede_ofb64_encrypt decrypt error\n");
713 err=1;
714 }
715
716 printf("Doing cbc_cksum\n");
717 DES_set_key_checked(&cbc_key,&ks);
718 cs=des_cbc_cksum(cbc_data,&cret,strlen((char *)cbc_data),ks,&cbc_iv);
719 if (cs != cbc_cksum_ret)
720 {
721 printf("bad return value (%08lX), should be %08lX\n",
722 (unsigned long)cs,(unsigned long)cbc_cksum_ret);
723 err=1;
724 }
725 if (memcmp(cret,cbc_cksum_data,8) != 0)
726 {
727 printf("bad cbc_cksum block returned\n");
728 err=1;
729 }
730
731 printf("Doing quad_cksum\n");
732 cs=des_quad_cksum(cbc_data,(des_cblock *)lqret,
733 (long)strlen((char *)cbc_data),2,(des_cblock *)cbc_iv);
734 if (cs != 0x70d7a63aL)
735 {
736 printf("quad_cksum error, ret %08lx should be 70d7a63a\n",
737 (unsigned long)cs);
738 err=1;
739 }
740#ifdef _CRAY
741 if (lqret[0].a != 0x327eba8dL)
742 {
743 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
744 (unsigned long)lqret[0].a,0x327eba8dUL);
745 err=1;
746 }
747 if (lqret[0].b != 0x201a49ccL)
748 {
749 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
750 (unsigned long)lqret[0].b,0x201a49ccUL);
751 err=1;
752 }
753 if (lqret[1].a != 0x70d7a63aL)
754 {
755 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
756 (unsigned long)lqret[1].a,0x70d7a63aUL);
757 err=1;
758 }
759 if (lqret[1].b != 0x501c2c26L)
760 {
761 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
762 (unsigned long)lqret[1].b,0x501c2c26UL);
763 err=1;
764 }
765#else
766 if (lqret[0] != 0x327eba8dL)
767 {
768 printf("quad_cksum error, out[0] %08lx is not %08lx\n",
769 (unsigned long)lqret[0],0x327eba8dUL);
770 err=1;
771 }
772 if (lqret[1] != 0x201a49ccL)
773 {
774 printf("quad_cksum error, out[1] %08lx is not %08lx\n",
775 (unsigned long)lqret[1],0x201a49ccUL);
776 err=1;
777 }
778 if (lqret[2] != 0x70d7a63aL)
779 {
780 printf("quad_cksum error, out[2] %08lx is not %08lx\n",
781 (unsigned long)lqret[2],0x70d7a63aUL);
782 err=1;
783 }
784 if (lqret[3] != 0x501c2c26L)
785 {
786 printf("quad_cksum error, out[3] %08lx is not %08lx\n",
787 (unsigned long)lqret[3],0x501c2c26UL);
788 err=1;
789 }
790#endif
791#endif
792
793 printf("input word alignment test");
794 for (i=0; i<4; i++)
795 {
796 printf(" %d",i);
797 des_ncbc_encrypt(&(cbc_out[i]),cbc_in,
798 strlen((char *)cbc_data)+1,ks,
799 &cbc_iv,DES_ENCRYPT);
800 }
801 printf("\noutput word alignment test");
802 for (i=0; i<4; i++)
803 {
804 printf(" %d",i);
805 des_ncbc_encrypt(cbc_out,&(cbc_in[i]),
806 strlen((char *)cbc_data)+1,ks,
807 &cbc_iv,DES_ENCRYPT);
808 }
809 printf("\n");
810 printf("fast crypt test ");
811 str=crypt("testing","ef");
812 if (strcmp("efGnQx2725bI2",str) != 0)
813 {
814 printf("fast crypt error, %s should be efGnQx2725bI2\n",str);
815 err=1;
816 }
817 str=crypt("bca76;23","yA");
818 if (strcmp("yA1Rp/1hZXIJk",str) != 0)
819 {
820 printf("fast crypt error, %s should be yA1Rp/1hZXIJk\n",str);
821 err=1;
822 }
823 printf("\n");
824 return(err);
825 }
826
827static char *pt(unsigned char *p)
828 {
829 static char bufs[10][20];
830 static int bnum=0;
831 char *ret;
832 int i;
833 static char *f="0123456789ABCDEF";
834
835 ret= &(bufs[bnum++][0]);
836 bnum%=10;
837 for (i=0; i<8; i++)
838 {
839 ret[i*2]=f[(p[i]>>4)&0xf];
840 ret[i*2+1]=f[p[i]&0xf];
841 }
842 ret[16]='\0';
843 return(ret);
844 }
845
846#ifndef LIBDES_LIT
847
848static int cfb_test(int bits, unsigned char *cfb_cipher)
849 {
850 des_key_schedule ks;
851 int i,err=0;
852
853 DES_set_key_checked(&cfb_key,&ks);
854 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
855 des_cfb_encrypt(plain,cfb_buf1,bits,sizeof(plain),ks,&cfb_tmp,
856 DES_ENCRYPT);
857 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
858 {
859 err=1;
860 printf("cfb_encrypt encrypt error\n");
861 for (i=0; i<24; i+=8)
862 printf("%s\n",pt(&(cfb_buf1[i])));
863 }
864 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
865 des_cfb_encrypt(cfb_buf1,cfb_buf2,bits,sizeof(plain),ks,&cfb_tmp,
866 DES_DECRYPT);
867 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
868 {
869 err=1;
870 printf("cfb_encrypt decrypt error\n");
871 for (i=0; i<24; i+=8)
872 printf("%s\n",pt(&(cfb_buf1[i])));
873 }
874 return(err);
875 }
876
877static int cfb64_test(unsigned char *cfb_cipher)
878 {
879 des_key_schedule ks;
880 int err=0,i,n;
881
882 DES_set_key_checked(&cfb_key,&ks);
883 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
884 n=0;
885 des_cfb64_encrypt(plain,cfb_buf1,12,ks,&cfb_tmp,&n,DES_ENCRYPT);
886 des_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),sizeof(plain)-12,ks,
887 &cfb_tmp,&n,DES_ENCRYPT);
888 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
889 {
890 err=1;
891 printf("cfb_encrypt encrypt error\n");
892 for (i=0; i<24; i+=8)
893 printf("%s\n",pt(&(cfb_buf1[i])));
894 }
895 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
896 n=0;
897 des_cfb64_encrypt(cfb_buf1,cfb_buf2,17,ks,&cfb_tmp,&n,DES_DECRYPT);
898 des_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
899 sizeof(plain)-17,ks,&cfb_tmp,&n,DES_DECRYPT);
900 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
901 {
902 err=1;
903 printf("cfb_encrypt decrypt error\n");
904 for (i=0; i<24; i+=8)
905 printf("%s\n",pt(&(cfb_buf2[i])));
906 }
907 return(err);
908 }
909
910static int ede_cfb64_test(unsigned char *cfb_cipher)
911 {
912 des_key_schedule ks;
913 int err=0,i,n;
914
915 DES_set_key_checked(&cfb_key,&ks);
916 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
917 n=0;
918 des_ede3_cfb64_encrypt(plain,cfb_buf1,12,ks,ks,ks,&cfb_tmp,&n,
919 DES_ENCRYPT);
920 des_ede3_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
921 sizeof(plain)-12,ks,ks,ks,
922 &cfb_tmp,&n,DES_ENCRYPT);
923 if (memcmp(cfb_cipher,cfb_buf1,sizeof(plain)) != 0)
924 {
925 err=1;
926 printf("ede_cfb_encrypt encrypt error\n");
927 for (i=0; i<24; i+=8)
928 printf("%s\n",pt(&(cfb_buf1[i])));
929 }
930 memcpy(cfb_tmp,cfb_iv,sizeof(cfb_iv));
931 n=0;
932 des_ede3_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,ks,ks,ks,
933 &cfb_tmp,&n,DES_DECRYPT);
934 des_ede3_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
935 sizeof(plain)-17,ks,ks,ks,
936 &cfb_tmp,&n,DES_DECRYPT);
937 if (memcmp(plain,cfb_buf2,sizeof(plain)) != 0)
938 {
939 err=1;
940 printf("ede_cfb_encrypt decrypt error\n");
941 for (i=0; i<24; i+=8)
942 printf("%s\n",pt(&(cfb_buf2[i])));
943 }
944 return(err);
945 }
946
947#endif
948#endif
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c
index c3437bc606..fa0c9c4d4f 100644
--- a/src/lib/libcrypto/des/ecb3_enc.c
+++ b/src/lib/libcrypto/des/ecb3_enc.c
@@ -58,15 +58,13 @@
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60 60
61void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, 61void DES_ecb3_encrypt(const unsigned char *in, unsigned char *out,
62 DES_key_schedule *ks1, DES_key_schedule *ks2, 62 DES_key_schedule *ks1, DES_key_schedule *ks2,
63 DES_key_schedule *ks3, 63 DES_key_schedule *ks3,
64 int enc) 64 int enc)
65 { 65 {
66 register DES_LONG l0,l1; 66 register DES_LONG l0,l1;
67 DES_LONG ll[2]; 67 DES_LONG ll[2];
68 const unsigned char *in = &(*input)[0];
69 unsigned char *out = &(*output)[0];
70 68
71 c2l(in,l0); 69 c2l(in,l0);
72 c2l(in,l1); 70 c2l(in,l1);
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c
index 00d5b91e8c..784aa5ba23 100644
--- a/src/lib/libcrypto/des/ecb_enc.c
+++ b/src/lib/libcrypto/des/ecb_enc.c
@@ -62,8 +62,8 @@
62#include <openssl/opensslv.h> 62#include <openssl/opensslv.h>
63#include <openssl/bio.h> 63#include <openssl/bio.h>
64 64
65OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT; 65OPENSSL_GLOBAL const char *libdes_version="libdes" OPENSSL_VERSION_PTEXT;
66OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT; 66OPENSSL_GLOBAL const char *DES_version="DES" OPENSSL_VERSION_PTEXT;
67 67
68const char *DES_options(void) 68const char *DES_options(void)
69 { 69 {
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c
index adfcb75cf3..fa45aa272b 100644
--- a/src/lib/libcrypto/des/ede_cbcm_enc.c
+++ b/src/lib/libcrypto/des/ede_cbcm_enc.c
@@ -68,8 +68,6 @@ http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz
68 68
69*/ 69*/
70 70
71#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_DESCBCM is defined */
72
73#ifndef OPENSSL_NO_DESCBCM 71#ifndef OPENSSL_NO_DESCBCM
74#include "des_locl.h" 72#include "des_locl.h"
75 73
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c
index ccbdff250f..2758c32656 100644
--- a/src/lib/libcrypto/des/fcrypt.c
+++ b/src/lib/libcrypto/des/fcrypt.c
@@ -58,6 +58,9 @@ static unsigned const char cov_2char[64]={
580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A 580x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A
59}; 59};
60 60
61void fcrypt_body(DES_LONG *out,DES_key_schedule *ks,
62 DES_LONG Eswap0, DES_LONG Eswap1);
63
61char *DES_crypt(const char *buf, const char *salt) 64char *DES_crypt(const char *buf, const char *salt)
62 { 65 {
63 static char buff[14]; 66 static char buff[14];
diff --git a/src/lib/libcrypto/des/makefile.bc b/src/lib/libcrypto/des/makefile.bc
new file mode 100644
index 0000000000..1fe6d4915a
--- /dev/null
+++ b/src/lib/libcrypto/des/makefile.bc
@@ -0,0 +1,50 @@
1#
2# Origional BC Makefile from Teun <Teun.Nijssen@kub.nl>
3#
4#
5CC = bcc
6TLIB = tlib /0 /C
7# note: the -3 flag produces code for 386, 486, Pentium etc; omit it for 286s
8OPTIMIZE= -3 -O2
9#WINDOWS= -W
10CFLAGS = -c -ml -d $(OPTIMIZE) $(WINDOWS) -DMSDOS
11LFLAGS = -ml $(WINDOWS)
12
13.c.obj:
14 $(CC) $(CFLAGS) $*.c
15
16.obj.exe:
17 $(CC) $(LFLAGS) -e$*.exe $*.obj libdes.lib
18
19all: $(LIB) destest.exe rpw.exe des.exe speed.exe
20
21# "make clean": use a directory containing only libdes .exe and .obj files...
22clean:
23 del *.exe
24 del *.obj
25 del libdes.lib
26 del libdes.rsp
27
28OBJS= cbc_cksm.obj cbc_enc.obj ecb_enc.obj pcbc_enc.obj \
29 qud_cksm.obj rand_key.obj set_key.obj str2key.obj \
30 enc_read.obj enc_writ.obj fcrypt.obj cfb_enc.obj \
31 ecb3_enc.obj ofb_enc.obj cbc3_enc.obj read_pwd.obj\
32 cfb64enc.obj ofb64enc.obj ede_enc.obj cfb64ede.obj\
33 ofb64ede.obj supp.obj
34
35LIB= libdes.lib
36
37$(LIB): $(OBJS)
38 del $(LIB)
39 makersp "+%s &\n" &&|
40 $(OBJS)
41| >libdes.rsp
42 $(TLIB) libdes.lib @libdes.rsp,nul
43 del libdes.rsp
44
45destest.exe: destest.obj libdes.lib
46rpw.exe: rpw.obj libdes.lib
47speed.exe: speed.obj libdes.lib
48des.exe: des.obj libdes.lib
49
50
diff --git a/src/lib/libcrypto/des/options.txt b/src/lib/libcrypto/des/options.txt
new file mode 100644
index 0000000000..6e2b50f765
--- /dev/null
+++ b/src/lib/libcrypto/des/options.txt
@@ -0,0 +1,39 @@
1Note that the UNROLL option makes the 'inner' des loop unroll all 16 rounds
2instead of the default 4.
3RISC1 and RISC2 are 2 alternatives for the inner loop and
4PTR means to use pointers arithmatic instead of arrays.
5
6FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - assembler 577,000 4620k/s
7IRIX 6.2 - R10000 195mhz - cc (-O3 -n32) - UNROLL RISC2 PTR 496,000 3968k/s
8solaris 2.5.1 usparc 167mhz?? - SC4.0 - UNROLL RISC1 PTR [1] 459,400 3672k/s
9FreeBSD - Pentium Pro 200mhz - gcc 2.7.2.2 - UNROLL RISC1 433,000 3468k/s
10solaris 2.5.1 usparc 167mhz?? - gcc 2.7.2 - UNROLL 380,000 3041k/s
11linux - pentium 100mhz - gcc 2.7.0 - assembler 281,000 2250k/s
12NT 4.0 - pentium 100mhz - VC 4.2 - assembler 281,000 2250k/s
13AIX 4.1? - PPC604 100mhz - cc - UNROLL 275,000 2200k/s
14IRIX 5.3 - R4400 200mhz - gcc 2.6.3 - UNROLL RISC2 PTR 235,300 1882k/s
15IRIX 5.3 - R4400 200mhz - cc - UNROLL RISC2 PTR 233,700 1869k/s
16NT 4.0 - pentium 100mhz - VC 4.2 - UNROLL RISC1 PTR 191,000 1528k/s
17DEC Alpha 165mhz?? - cc - RISC2 PTR [2] 181,000 1448k/s
18linux - pentium 100mhz - gcc 2.7.0 - UNROLL RISC1 PTR 158,500 1268k/s
19HPUX 10 - 9000/887 - cc - UNROLL [3] 148,000 1190k/s
20solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2 - UNROLL 123,600 989k/s
21IRIX 5.3 - R4000 100mhz - cc - UNROLL RISC2 PTR 101,000 808k/s
22DGUX - 88100 50mhz(?) - gcc 2.6.3 - UNROLL 81,000 648k/s
23solaris 2.4 486 50mhz - gcc 2.6.3 - assembler 65,000 522k/s
24HPUX 10 - 9000/887 - k&r cc (default compiler) - UNROLL PTR 76,000 608k/s
25solaris 2.4 486 50mhz - gcc 2.6.3 - UNROLL RISC2 43,500 344k/s
26AIX - old slow one :-) - cc - 39,000 312k/s
27
28Notes.
29[1] For the ultra sparc, SunC 4.0
30 cc -xtarget=ultra -xarch=v8plus -Xa -xO5, running 'des_opts'
31 gives a speed of 344,000 des/s while 'speed' gives 459,000 des/s.
32 I'll record the higher since it is coming from the library but it
33 is all rather weird.
34[2] Similar to the ultra sparc ([1]), 181,000 for 'des_opts' vs 175,000.
35[3] I was unable to get access to this machine when it was not heavily loaded.
36 As such, my timing program was never able to get more that %30 of the CPU.
37 This would cause the program to give much lower speed numbers because
38 it would be 'fighting' to stay in the cache with the other CPU burning
39 processes.
diff --git a/src/lib/libcrypto/des/read2pwd.c b/src/lib/libcrypto/des/read2pwd.c
new file mode 100644
index 0000000000..3a63c4016c
--- /dev/null
+++ b/src/lib/libcrypto/des/read2pwd.c
@@ -0,0 +1,139 @@
1/* crypto/des/read2pwd.c */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
56 * All rights reserved.
57 *
58 * This package is an SSL implementation written
59 * by Eric Young (eay@cryptsoft.com).
60 * The implementation was written so as to conform with Netscapes SSL.
61 *
62 * This library is free for commercial and non-commercial use as long as
63 * the following conditions are aheared to. The following conditions
64 * apply to all code found in this distribution, be it the RC4, RSA,
65 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
66 * included with this distribution is covered by the same copyright terms
67 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
68 *
69 * Copyright remains Eric Young's, and as such any Copyright notices in
70 * the code are not to be removed.
71 * If this package is used in a product, Eric Young should be given attribution
72 * as the author of the parts of the library used.
73 * This can be in the form of a textual message at program startup or
74 * in documentation (online or textual) provided with the package.
75 *
76 * Redistribution and use in source and binary forms, with or without
77 * modification, are permitted provided that the following conditions
78 * are met:
79 * 1. Redistributions of source code must retain the copyright
80 * notice, this list of conditions and the following disclaimer.
81 * 2. Redistributions in binary form must reproduce the above copyright
82 * notice, this list of conditions and the following disclaimer in the
83 * documentation and/or other materials provided with the distribution.
84 * 3. All advertising materials mentioning features or use of this software
85 * must display the following acknowledgement:
86 * "This product includes cryptographic software written by
87 * Eric Young (eay@cryptsoft.com)"
88 * The word 'cryptographic' can be left out if the rouines from the library
89 * being used are not cryptographic related :-).
90 * 4. If you include any Windows specific code (or a derivative thereof) from
91 * the apps directory (application code) you must include an acknowledgement:
92 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
93 *
94 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
95 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
98 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 * SUCH DAMAGE.
105 *
106 * The licence and distribution terms for any publically available version or
107 * derivative of this code cannot be changed. i.e. this code cannot simply be
108 * copied and put under another distribution licence
109 * [including the GNU Public Licence.]
110 */
111
112#include <string.h>
113#include <openssl/des.h>
114#include <openssl/ui.h>
115
116int DES_read_password(DES_cblock *key, const char *prompt, int verify)
117 {
118 int ok;
119 char buf[BUFSIZ],buff[BUFSIZ];
120
121 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
122 DES_string_to_key(buf,key);
123 OPENSSL_cleanse(buf,BUFSIZ);
124 OPENSSL_cleanse(buff,BUFSIZ);
125 return(ok);
126 }
127
128int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt,
129 int verify)
130 {
131 int ok;
132 char buf[BUFSIZ],buff[BUFSIZ];
133
134 if ((ok=UI_UTIL_read_pw(buf,buff,BUFSIZ,prompt,verify)) == 0)
135 DES_string_to_2keys(buf,key1,key2);
136 OPENSSL_cleanse(buf,BUFSIZ);
137 OPENSSL_cleanse(buff,BUFSIZ);
138 return(ok);
139 }
diff --git a/src/lib/libcrypto/des/read_pwd.c b/src/lib/libcrypto/des/read_pwd.c
new file mode 100644
index 0000000000..ce5fa00a37
--- /dev/null
+++ b/src/lib/libcrypto/des/read_pwd.c
@@ -0,0 +1,521 @@
1/* crypto/des/read_pwd.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <openssl/e_os2.h>
60#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_WIN32)
61#ifdef OPENSSL_UNISTD
62# include OPENSSL_UNISTD
63#else
64# include <unistd.h>
65#endif
66/* If unistd.h defines _POSIX_VERSION, we conclude that we
67 * are on a POSIX system and have sigaction and termios. */
68#if defined(_POSIX_VERSION)
69
70# define SIGACTION
71# if !defined(TERMIOS) && !defined(TERMIO) && !defined(SGTTY)
72# define TERMIOS
73# endif
74
75#endif
76#endif
77
78/* #define SIGACTION */ /* Define this if you have sigaction() */
79
80#ifdef WIN16TTY
81#undef OPENSSL_SYS_WIN16
82#undef _WINDOWS
83#include <graph.h>
84#endif
85
86/* 06-Apr-92 Luke Brennan Support for VMS */
87#include "des_locl.h"
88#include "cryptlib.h"
89#include <signal.h>
90#include <stdio.h>
91#include <string.h>
92#include <setjmp.h>
93#include <errno.h>
94
95#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
96#include <starlet.h>
97#ifdef __DECC
98#pragma message disable DOLLARID
99#endif
100#endif
101
102#ifdef WIN_CONSOLE_BUG
103#include <windows.h>
104#ifndef OPENSSL_SYS_WINCE
105#include <wincon.h>
106#endif
107#endif
108
109
110/* There are 5 types of terminal interface supported,
111 * TERMIO, TERMIOS, VMS, MSDOS and SGTTY
112 */
113
114#if defined(__sgi) && !defined(TERMIOS)
115#define TERMIOS
116#undef TERMIO
117#undef SGTTY
118#endif
119
120#if defined(linux) && !defined(TERMIO)
121#undef TERMIOS
122#define TERMIO
123#undef SGTTY
124#endif
125
126#ifdef _LIBC
127#undef TERMIOS
128#define TERMIO
129#undef SGTTY
130#endif
131
132#if !defined(TERMIO) && !defined(TERMIOS) && !defined(OPENSSL_SYS_VMS) && !defined(OPENSSL_SYS_MSDOS) && !defined(MAC_OS_pre_X) && !defined(MAC_OS_GUSI_SOURCE)
133#undef TERMIOS
134#undef TERMIO
135#define SGTTY
136#endif
137
138#if defined(OPENSSL_SYS_VXWORKS)
139#undef TERMIOS
140#undef TERMIO
141#undef SGTTY
142#endif
143
144#ifdef TERMIOS
145#include <termios.h>
146#define TTY_STRUCT struct termios
147#define TTY_FLAGS c_lflag
148#define TTY_get(tty,data) tcgetattr(tty,data)
149#define TTY_set(tty,data) tcsetattr(tty,TCSANOW,data)
150#endif
151
152#ifdef TERMIO
153#include <termio.h>
154#define TTY_STRUCT struct termio
155#define TTY_FLAGS c_lflag
156#define TTY_get(tty,data) ioctl(tty,TCGETA,data)
157#define TTY_set(tty,data) ioctl(tty,TCSETA,data)
158#endif
159
160#ifdef SGTTY
161#include <sgtty.h>
162#define TTY_STRUCT struct sgttyb
163#define TTY_FLAGS sg_flags
164#define TTY_get(tty,data) ioctl(tty,TIOCGETP,data)
165#define TTY_set(tty,data) ioctl(tty,TIOCSETP,data)
166#endif
167
168#if !defined(_LIBC) && !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) && !defined(MAC_OS_pre_X)
169#include <sys/ioctl.h>
170#endif
171
172#if defined(OPENSSL_SYS_MSDOS) && !defined(__CYGWIN32__) && !defined(OPENSSL_SYS_WINCE)
173#include <conio.h>
174#define fgets(a,b,c) noecho_fgets(a,b,c)
175#endif
176
177#ifdef OPENSSL_SYS_VMS
178#include <ssdef.h>
179#include <iodef.h>
180#include <ttdef.h>
181#include <descrip.h>
182struct IOSB {
183 short iosb$w_value;
184 short iosb$w_count;
185 long iosb$l_info;
186 };
187#endif
188
189#if defined(MAC_OS_pre_X) || defined(MAC_OS_GUSI_SOURCE)
190/*
191 * This one needs work. As a matter of fact the code is unoperational
192 * and this is only a trick to get it compiled.
193 * <appro@fy.chalmers.se>
194 */
195#define TTY_STRUCT int
196#endif
197
198#ifndef NX509_SIG
199#define NX509_SIG 32
200#endif
201
202static void read_till_nl(FILE *);
203static void recsig(int);
204static void pushsig(void);
205static void popsig(void);
206#if defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN16)
207static int noecho_fgets(char *buf, int size, FILE *tty);
208#endif
209#ifdef SIGACTION
210 static struct sigaction savsig[NX509_SIG];
211#else
212 static void (*savsig[NX509_SIG])(int );
213#endif
214static jmp_buf save;
215
216int des_read_pw_string(char *buf, int length, const char *prompt,
217 int verify)
218 {
219 char buff[BUFSIZ];
220 int ret;
221
222 ret=des_read_pw(buf,buff,(length>BUFSIZ)?BUFSIZ:length,prompt,verify);
223 OPENSSL_cleanse(buff,BUFSIZ);
224 return(ret);
225 }
226
227#ifdef OPENSSL_SYS_WINCE
228
229int des_read_pw(char *buf, char *buff, int size, const char *prompt, int verify)
230 {
231 memset(buf,0,size);
232 memset(buff,0,size);
233 return(0);
234 }
235
236#elif defined(OPENSSL_SYS_WIN16)
237
238int des_read_pw(char *buf, char *buff, int size, char *prompt, int verify)
239 {
240 memset(buf,0,size);
241 memset(buff,0,size);
242 return(0);
243 }
244
245#else /* !OPENSSL_SYS_WINCE && !OPENSSL_SYS_WIN16 */
246
247static void read_till_nl(FILE *in)
248 {
249#define SIZE 4
250 char buf[SIZE+1];
251
252 do {
253 fgets(buf,SIZE,in);
254 } while (strchr(buf,'\n') == NULL);
255 }
256
257
258/* return 0 if ok, 1 (or -1) otherwise */
259int des_read_pw(char *buf, char *buff, int size, const char *prompt,
260 int verify)
261 {
262#ifdef OPENSSL_SYS_VMS
263 struct IOSB iosb;
264 $DESCRIPTOR(terminal,"TT");
265 long tty_orig[3], tty_new[3];
266 long status;
267 unsigned short channel = 0;
268#else
269#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
270 TTY_STRUCT tty_orig,tty_new;
271#endif
272#endif
273 int number;
274 int ok;
275 /* statics are simply to avoid warnings about longjmp clobbering
276 things */
277 static int ps;
278 int is_a_tty;
279 static FILE *tty;
280 char *p;
281
282 if (setjmp(save))
283 {
284 ok=0;
285 goto error;
286 }
287
288 number=5;
289 ok=0;
290 ps=0;
291 is_a_tty=1;
292 tty=NULL;
293
294#ifdef OPENSSL_SYS_MSDOS
295 if ((tty=fopen("con","r")) == NULL)
296 tty=stdin;
297#elif defined(MAC_OS_pre_X) || defined(OPENSSL_SYS_VXWORKS)
298 tty=stdin;
299#else
300#ifndef OPENSSL_SYS_MPE
301 if ((tty=fopen("/dev/tty","r")) == NULL)
302#endif
303 tty=stdin;
304#endif
305
306#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
307 if (TTY_get(fileno(tty),&tty_orig) == -1)
308 {
309#ifdef ENOTTY
310 if (errno == ENOTTY)
311 is_a_tty=0;
312 else
313#endif
314#ifdef EINVAL
315 /* Ariel Glenn ariel@columbia.edu reports that solaris
316 * can return EINVAL instead. This should be ok */
317 if (errno == EINVAL)
318 is_a_tty=0;
319 else
320#endif
321 return(-1);
322 }
323 memcpy(&(tty_new),&(tty_orig),sizeof(tty_orig));
324#endif
325#ifdef OPENSSL_SYS_VMS
326 status = sys$assign(&terminal,&channel,0,0);
327 if (status != SS$_NORMAL)
328 return(-1);
329 status=sys$qiow(0,channel,IO$_SENSEMODE,&iosb,0,0,tty_orig,12,0,0,0,0);
330 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
331 return(-1);
332#endif
333
334 pushsig();
335 ps=1;
336
337#ifdef TTY_FLAGS
338 tty_new.TTY_FLAGS &= ~ECHO;
339#endif
340
341#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
342 if (is_a_tty && (TTY_set(fileno(tty),&tty_new) == -1))
343#ifdef OPENSSL_SYS_MPE
344 ; /* MPE lies -- echo really has been disabled */
345#else
346 return(-1);
347#endif
348#endif
349#ifdef OPENSSL_SYS_VMS
350 tty_new[0] = tty_orig[0];
351 tty_new[1] = tty_orig[1] | TT$M_NOECHO;
352 tty_new[2] = tty_orig[2];
353 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0,tty_new,12,0,0,0,0);
354 if ((status != SS$_NORMAL) || (iosb.iosb$w_value != SS$_NORMAL))
355 return(-1);
356#endif
357 ps=2;
358
359 while ((!ok) && (number--))
360 {
361 fputs(prompt,stderr);
362 fflush(stderr);
363
364 buf[0]='\0';
365 fgets(buf,size,tty);
366 if (feof(tty)) goto error;
367 if (ferror(tty)) goto error;
368 if ((p=(char *)strchr(buf,'\n')) != NULL)
369 *p='\0';
370 else read_till_nl(tty);
371 if (verify)
372 {
373 fprintf(stderr,"\nVerifying password - %s",prompt);
374 fflush(stderr);
375 buff[0]='\0';
376 fgets(buff,size,tty);
377 if (feof(tty)) goto error;
378 if ((p=(char *)strchr(buff,'\n')) != NULL)
379 *p='\0';
380 else read_till_nl(tty);
381
382 if (strcmp(buf,buff) != 0)
383 {
384 fprintf(stderr,"\nVerify failure");
385 fflush(stderr);
386 break;
387 /* continue; */
388 }
389 }
390 ok=1;
391 }
392
393error:
394 fprintf(stderr,"\n");
395#if 0
396 perror("fgets(tty)");
397#endif
398 /* What can we do if there is an error? */
399#if defined(TTY_set) && !defined(OPENSSL_SYS_VMS)
400 if (ps >= 2) TTY_set(fileno(tty),&tty_orig);
401#endif
402#ifdef OPENSSL_SYS_VMS
403 if (ps >= 2)
404 status = sys$qiow(0,channel,IO$_SETMODE,&iosb,0,0
405 ,tty_orig,12,0,0,0,0);
406#endif
407
408 if (ps >= 1) popsig();
409 if (stdin != tty) fclose(tty);
410#ifdef OPENSSL_SYS_VMS
411 status = sys$dassgn(channel);
412#endif
413 return(!ok);
414 }
415
416static void pushsig(void)
417 {
418 int i;
419#ifdef SIGACTION
420 struct sigaction sa;
421
422 memset(&sa,0,sizeof sa);
423 sa.sa_handler=recsig;
424#endif
425
426 for (i=1; i<NX509_SIG; i++)
427 {
428#ifdef SIGUSR1
429 if (i == SIGUSR1)
430 continue;
431#endif
432#ifdef SIGUSR2
433 if (i == SIGUSR2)
434 continue;
435#endif
436#ifdef SIGACTION
437 sigaction(i,&sa,&savsig[i]);
438#else
439 savsig[i]=signal(i,recsig);
440#endif
441 }
442
443#ifdef SIGWINCH
444 signal(SIGWINCH,SIG_DFL);
445#endif
446 }
447
448static void popsig(void)
449 {
450 int i;
451
452 for (i=1; i<NX509_SIG; i++)
453 {
454#ifdef SIGUSR1
455 if (i == SIGUSR1)
456 continue;
457#endif
458#ifdef SIGUSR2
459 if (i == SIGUSR2)
460 continue;
461#endif
462#ifdef SIGACTION
463 sigaction(i,&savsig[i],NULL);
464#else
465 signal(i,savsig[i]);
466#endif
467 }
468 }
469
470static void recsig(int i)
471 {
472 longjmp(save,1);
473#ifdef LINT
474 i=i;
475#endif
476 }
477
478#ifdef OPENSSL_SYS_MSDOS
479static int noecho_fgets(char *buf, int size, FILE *tty)
480 {
481 int i;
482 char *p;
483
484 p=buf;
485 for (;;)
486 {
487 if (size == 0)
488 {
489 *p='\0';
490 break;
491 }
492 size--;
493#ifdef WIN16TTY
494 i=_inchar();
495#else
496 i=getch();
497#endif
498 if (i == '\r') i='\n';
499 *(p++)=i;
500 if (i == '\n')
501 {
502 *p='\0';
503 break;
504 }
505 }
506#ifdef WIN_CONSOLE_BUG
507/* Win95 has several evil console bugs: one of these is that the
508 * last character read using getch() is passed to the next read: this is
509 * usually a CR so this can be trouble. No STDIO fix seems to work but
510 * flushing the console appears to do the trick.
511 */
512 {
513 HANDLE inh;
514 inh = GetStdHandle(STD_INPUT_HANDLE);
515 FlushConsoleInputBuffer(inh);
516 }
517#endif
518 return(strlen(buf));
519 }
520#endif
521#endif /* !OPENSSL_SYS_WINCE && !WIN16 */
diff --git a/src/lib/libcrypto/des/rpc_des.h b/src/lib/libcrypto/des/rpc_des.h
new file mode 100644
index 0000000000..4cbb4d2dcd
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_des.h
@@ -0,0 +1,131 @@
1/* crypto/des/rpc_des.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* @(#)des.h 2.2 88/08/10 4.0 RPCSRC; from 2.7 88/02/08 SMI */
60/*
61 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
62 * unrestricted use provided that this legend is included on all tape
63 * media and as a part of the software program in whole or part. Users
64 * may copy or modify Sun RPC without charge, but are not authorized
65 * to license or distribute it to anyone else except as part of a product or
66 * program developed by the user.
67 *
68 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
69 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
70 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
71 *
72 * Sun RPC is provided with no support and without any obligation on the
73 * part of Sun Microsystems, Inc. to assist in its use, correction,
74 * modification or enhancement.
75 *
76 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
77 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
78 * OR ANY PART THEREOF.
79 *
80 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
81 * or profits or other special, indirect and consequential damages, even if
82 * Sun has been advised of the possibility of such damages.
83 *
84 * Sun Microsystems, Inc.
85 * 2550 Garcia Avenue
86 * Mountain View, California 94043
87 */
88/*
89 * Generic DES driver interface
90 * Keep this file hardware independent!
91 * Copyright (c) 1986 by Sun Microsystems, Inc.
92 */
93
94#define DES_MAXLEN 65536 /* maximum # of bytes to encrypt */
95#define DES_QUICKLEN 16 /* maximum # of bytes to encrypt quickly */
96
97#ifdef HEADER_DES_H
98#undef ENCRYPT
99#undef DECRYPT
100#endif
101
102enum desdir { ENCRYPT, DECRYPT };
103enum desmode { CBC, ECB };
104
105/*
106 * parameters to ioctl call
107 */
108struct desparams {
109 unsigned char des_key[8]; /* key (with low bit parity) */
110 enum desdir des_dir; /* direction */
111 enum desmode des_mode; /* mode */
112 unsigned char des_ivec[8]; /* input vector */
113 unsigned des_len; /* number of bytes to crypt */
114 union {
115 unsigned char UDES_data[DES_QUICKLEN];
116 unsigned char *UDES_buf;
117 } UDES;
118# define des_data UDES.UDES_data /* direct data here if quick */
119# define des_buf UDES.UDES_buf /* otherwise, pointer to data */
120};
121
122/*
123 * Encrypt an arbitrary sized buffer
124 */
125#define DESIOCBLOCK _IOWR(d, 6, struct desparams)
126
127/*
128 * Encrypt of small amount of data, quickly
129 */
130#define DESIOCQUICK _IOWR(d, 7, struct desparams)
131
diff --git a/src/lib/libcrypto/des/rpc_enc.c b/src/lib/libcrypto/des/rpc_enc.c
new file mode 100644
index 0000000000..d937d08da5
--- /dev/null
+++ b/src/lib/libcrypto/des/rpc_enc.c
@@ -0,0 +1,98 @@
1/* crypto/des/rpc_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 "rpc_des.h"
60#include "des_locl.h"
61#include "des_ver.h"
62
63int _des_crypt(char *buf,int len,struct desparams *desp);
64int _des_crypt(char *buf, int len, struct desparams *desp)
65 {
66 DES_key_schedule ks;
67 int enc;
68
69 DES_set_key_unchecked(&desp->des_key,&ks);
70 enc=(desp->des_dir == ENCRYPT)?DES_ENCRYPT:DES_DECRYPT;
71
72 if (desp->des_mode == CBC)
73 DES_ecb_encrypt((const_DES_cblock *)desp->UDES.UDES_buf,
74 (DES_cblock *)desp->UDES.UDES_buf,&ks,
75 enc);
76 else
77 {
78 DES_ncbc_encrypt(desp->UDES.UDES_buf,desp->UDES.UDES_buf,
79 len,&ks,&desp->des_ivec,enc);
80#ifdef undef
81 /* len will always be %8 if called from common_crypt
82 * in secure_rpc.
83 * Libdes's cbc encrypt does not copy back the iv,
84 * so we have to do it here. */
85 /* It does now :-) eay 20/09/95 */
86
87 a=(char *)&(desp->UDES.UDES_buf[len-8]);
88 b=(char *)&(desp->des_ivec[0]);
89
90 *(a++)= *(b++); *(a++)= *(b++);
91 *(a++)= *(b++); *(a++)= *(b++);
92 *(a++)= *(b++); *(a++)= *(b++);
93 *(a++)= *(b++); *(a++)= *(b++);
94#endif
95 }
96 return(1);
97 }
98
diff --git a/src/lib/libcrypto/des/rpw.c b/src/lib/libcrypto/des/rpw.c
new file mode 100644
index 0000000000..8a9473c4f9
--- /dev/null
+++ b/src/lib/libcrypto/des/rpw.c
@@ -0,0 +1,99 @@
1/* crypto/des/rpw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/des.h>
61
62int main(int argc, char *argv[])
63 {
64 DES_cblock k,k1;
65 int i;
66
67 printf("read passwd\n");
68 if ((i=des_read_password(&k,"Enter password:",0)) == 0)
69 {
70 printf("password = ");
71 for (i=0; i<8; i++)
72 printf("%02x ",k[i]);
73 }
74 else
75 printf("error %d\n",i);
76 printf("\n");
77 printf("read 2passwds and verify\n");
78 if ((i=des_read_2passwords(&k,&k1,
79 "Enter verified password:",1)) == 0)
80 {
81 printf("password1 = ");
82 for (i=0; i<8; i++)
83 printf("%02x ",k[i]);
84 printf("\n");
85 printf("password2 = ");
86 for (i=0; i<8; i++)
87 printf("%02x ",k1[i]);
88 printf("\n");
89 exit(1);
90 }
91 else
92 {
93 printf("error %d\n",i);
94 exit(0);
95 }
96#ifdef LINT
97 return(0);
98#endif
99 }
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c
index a43ef3c881..8881d46a7a 100644
--- a/src/lib/libcrypto/des/set_key.c
+++ b/src/lib/libcrypto/des/set_key.c
@@ -65,6 +65,8 @@
65 */ 65 */
66#include "des_locl.h" 66#include "des_locl.h"
67 67
68#ifndef OPENSSL_FIPS
69
68OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */ 70OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */
69 71
70static const unsigned char odd_parity[256]={ 72static const unsigned char odd_parity[256]={
@@ -87,7 +89,7 @@ static const unsigned char odd_parity[256]={
87 89
88void DES_set_odd_parity(DES_cblock *key) 90void DES_set_odd_parity(DES_cblock *key)
89 { 91 {
90 unsigned int i; 92 int i;
91 93
92 for (i=0; i<DES_KEY_SZ; i++) 94 for (i=0; i<DES_KEY_SZ; i++)
93 (*key)[i]=odd_parity[(*key)[i]]; 95 (*key)[i]=odd_parity[(*key)[i]];
@@ -95,7 +97,7 @@ void DES_set_odd_parity(DES_cblock *key)
95 97
96int DES_check_key_parity(const_DES_cblock *key) 98int DES_check_key_parity(const_DES_cblock *key)
97 { 99 {
98 unsigned int i; 100 int i;
99 101
100 for (i=0; i<DES_KEY_SZ; i++) 102 for (i=0; i<DES_KEY_SZ; i++)
101 { 103 {
@@ -115,7 +117,7 @@ int DES_check_key_parity(const_DES_cblock *key)
115 * (and actual cblock values). 117 * (and actual cblock values).
116 */ 118 */
117#define NUM_WEAK_KEY 16 119#define NUM_WEAK_KEY 16
118static const DES_cblock weak_keys[NUM_WEAK_KEY]={ 120static DES_cblock weak_keys[NUM_WEAK_KEY]={
119 /* weak keys */ 121 /* weak keys */
120 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, 122 {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
121 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, 123 {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE},
@@ -405,3 +407,5 @@ void des_fixup_key_parity(des_cblock *key)
405 des_set_odd_parity(key); 407 des_set_odd_parity(key);
406 } 408 }
407*/ 409*/
410
411#endif /* ndef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/des/speed.c b/src/lib/libcrypto/des/speed.c
new file mode 100644
index 0000000000..48fc1d49fc
--- /dev/null
+++ b/src/lib/libcrypto/des/speed.c
@@ -0,0 +1,310 @@
1/* crypto/des/speed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
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 */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/des.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103# ifndef CLK_TCK
104# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
105# define HZ 100.0
106# else /* _BSD_CLK_TCK_ */
107# define HZ ((double)_BSD_CLK_TCK_)
108# endif
109# else /* CLK_TCK */
110# define HZ ((double)CLK_TCK)
111# endif
112#endif
113
114#define BUFSIZE ((long)1024)
115long run=0;
116
117double Time_F(int s);
118#ifdef SIGALRM
119#if defined(__STDC__) || defined(sgi) || defined(_AIX)
120#define SIGRETTYPE void
121#else
122#define SIGRETTYPE int
123#endif
124
125SIGRETTYPE sig_done(int sig);
126SIGRETTYPE sig_done(int sig)
127 {
128 signal(SIGALRM,sig_done);
129 run=0;
130#ifdef LINT
131 sig=sig;
132#endif
133 }
134#endif
135
136#define START 0
137#define STOP 1
138
139double Time_F(int s)
140 {
141 double ret;
142#ifdef TIMES
143 static struct tms tstart,tend;
144
145 if (s == START)
146 {
147 times(&tstart);
148 return(0);
149 }
150 else
151 {
152 times(&tend);
153 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
154 return((ret == 0.0)?1e-6:ret);
155 }
156#else /* !times() */
157 static struct timeb tstart,tend;
158 long i;
159
160 if (s == START)
161 {
162 ftime(&tstart);
163 return(0);
164 }
165 else
166 {
167 ftime(&tend);
168 i=(long)tend.millitm-(long)tstart.millitm;
169 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
170 return((ret == 0.0)?1e-6:ret);
171 }
172#endif
173 }
174
175int main(int argc, char **argv)
176 {
177 long count;
178 static unsigned char buf[BUFSIZE];
179 static DES_cblock key ={0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
180 static DES_cblock key2={0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12};
181 static DES_cblock key3={0x56,0x78,0x9a,0xbc,0xde,0xf0,0x12,0x34};
182 DES_key_schedule sch,sch2,sch3;
183 double a,b,c,d,e;
184#ifndef SIGALRM
185 long ca,cb,cc,cd,ce;
186#endif
187
188#ifndef TIMES
189 printf("To get the most accurate results, try to run this\n");
190 printf("program when this computer is idle.\n");
191#endif
192
193 DES_set_key_unchecked(&key2,&sch2);
194 DES_set_key_unchecked(&key3,&sch3);
195
196#ifndef SIGALRM
197 printf("First we calculate the approximate speed ...\n");
198 DES_set_key_unchecked(&key,&sch);
199 count=10;
200 do {
201 long i;
202 DES_LONG data[2];
203
204 count*=2;
205 Time_F(START);
206 for (i=count; i; i--)
207 DES_encrypt1(data,&sch,DES_ENCRYPT);
208 d=Time_F(STOP);
209 } while (d < 3.0);
210 ca=count;
211 cb=count*3;
212 cc=count*3*8/BUFSIZE+1;
213 cd=count*8/BUFSIZE+1;
214 ce=count/20+1;
215 printf("Doing set_key %ld times\n",ca);
216#define COND(d) (count != (d))
217#define COUNT(d) (d)
218#else
219#define COND(c) (run)
220#define COUNT(d) (count)
221 signal(SIGALRM,sig_done);
222 printf("Doing set_key for 10 seconds\n");
223 alarm(10);
224#endif
225
226 Time_F(START);
227 for (count=0,run=1; COND(ca); count++)
228 DES_set_key_unchecked(&key,&sch);
229 d=Time_F(STOP);
230 printf("%ld set_key's in %.2f seconds\n",count,d);
231 a=((double)COUNT(ca))/d;
232
233#ifdef SIGALRM
234 printf("Doing DES_encrypt's for 10 seconds\n");
235 alarm(10);
236#else
237 printf("Doing DES_encrypt %ld times\n",cb);
238#endif
239 Time_F(START);
240 for (count=0,run=1; COND(cb); count++)
241 {
242 DES_LONG data[2];
243
244 DES_encrypt1(data,&sch,DES_ENCRYPT);
245 }
246 d=Time_F(STOP);
247 printf("%ld DES_encrypt's in %.2f second\n",count,d);
248 b=((double)COUNT(cb)*8)/d;
249
250#ifdef SIGALRM
251 printf("Doing DES_cbc_encrypt on %ld byte blocks for 10 seconds\n",
252 BUFSIZE);
253 alarm(10);
254#else
255 printf("Doing DES_cbc_encrypt %ld times on %ld byte blocks\n",cc,
256 BUFSIZE);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cc); count++)
260 DES_ncbc_encrypt(buf,buf,BUFSIZE,&sch,
261 &key,DES_ENCRYPT);
262 d=Time_F(STOP);
263 printf("%ld DES_cbc_encrypt's of %ld byte blocks in %.2f second\n",
264 count,BUFSIZE,d);
265 c=((double)COUNT(cc)*BUFSIZE)/d;
266
267#ifdef SIGALRM
268 printf("Doing DES_ede_cbc_encrypt on %ld byte blocks for 10 seconds\n",
269 BUFSIZE);
270 alarm(10);
271#else
272 printf("Doing DES_ede_cbc_encrypt %ld times on %ld byte blocks\n",cd,
273 BUFSIZE);
274#endif
275 Time_F(START);
276 for (count=0,run=1; COND(cd); count++)
277 DES_ede3_cbc_encrypt(buf,buf,BUFSIZE,
278 &sch,
279 &sch2,
280 &sch3,
281 &key,
282 DES_ENCRYPT);
283 d=Time_F(STOP);
284 printf("%ld DES_ede_cbc_encrypt's of %ld byte blocks in %.2f second\n",
285 count,BUFSIZE,d);
286 d=((double)COUNT(cd)*BUFSIZE)/d;
287
288#ifdef SIGALRM
289 printf("Doing crypt for 10 seconds\n");
290 alarm(10);
291#else
292 printf("Doing crypt %ld times\n",ce);
293#endif
294 Time_F(START);
295 for (count=0,run=1; COND(ce); count++)
296 crypt("testing1","ef");
297 e=Time_F(STOP);
298 printf("%ld crypts in %.2f second\n",count,e);
299 e=((double)COUNT(ce))/e;
300
301 printf("set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
302 printf("DES raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
303 printf("DES cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
304 printf("DES ede cbc bytes per sec = %12.2f (%9.3fuS)\n",d,8.0e6/d);
305 printf("crypt per sec = %12.2f (%9.3fuS)\n",e,1.0e6/e);
306 exit(0);
307#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
308 return(0);
309#endif
310 }
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c
index 9c2054bda6..0373db469c 100644
--- a/src/lib/libcrypto/des/str2key.c
+++ b/src/lib/libcrypto/des/str2key.c
@@ -57,7 +57,6 @@
57 */ 57 */
58 58
59#include "des_locl.h" 59#include "des_locl.h"
60#include <openssl/crypto.h>
61 60
62void DES_string_to_key(const char *str, DES_cblock *key) 61void DES_string_to_key(const char *str, DES_cblock *key)
63 { 62 {
diff --git a/src/lib/libcrypto/des/t/test b/src/lib/libcrypto/des/t/test
new file mode 100644
index 0000000000..97acd0552e
--- /dev/null
+++ b/src/lib/libcrypto/des/t/test
@@ -0,0 +1,27 @@
1#!./perl
2
3BEGIN { push(@INC, qw(../../../lib ../../lib ../lib lib)); }
4
5use DES;
6
7$key='00000000';
8$ks=DES::set_key($key);
9@a=split(//,$ks);
10foreach (@a) { printf "%02x-",ord($_); }
11print "\n";
12
13
14$key=DES::random_key();
15print "($_)\n";
16@a=split(//,$key);
17foreach (@a) { printf "%02x-",ord($_); }
18print "\n";
19$str="this is and again into the breach";
20($k1,$k2)=DES::string_to_2keys($str);
21@a=split(//,$k1);
22foreach (@a) { printf "%02x-",ord($_); }
23print "\n";
24@a=split(//,$k2);
25foreach (@a) { printf "%02x-",ord($_); }
26print "\n";
27
diff --git a/src/lib/libcrypto/des/times/486-50.sol b/src/lib/libcrypto/des/times/486-50.sol
new file mode 100644
index 0000000000..0de62d6db3
--- /dev/null
+++ b/src/lib/libcrypto/des/times/486-50.sol
@@ -0,0 +1,16 @@
1Solaris 2.4, 486 50mhz, gcc 2.6.3
2options des ecb/s
316 r2 i 43552.51 100.0%
416 r1 i 43487.45 99.9%
516 c p 43003.23 98.7%
616 r2 p 42339.00 97.2%
716 c i 41900.91 96.2%
816 r1 p 41360.64 95.0%
9 4 c i 38728.48 88.9%
10 4 c p 38225.63 87.8%
11 4 r1 i 38085.79 87.4%
12 4 r2 i 37825.64 86.9%
13 4 r2 p 34611.00 79.5%
14 4 r1 p 31802.00 73.0%
15-DDES_UNROLL -DDES_RISC2
16
diff --git a/src/lib/libcrypto/des/times/586-100.lnx b/src/lib/libcrypto/des/times/586-100.lnx
new file mode 100644
index 0000000000..4323914a11
--- /dev/null
+++ b/src/lib/libcrypto/des/times/586-100.lnx
@@ -0,0 +1,20 @@
1Pentium 100
2Linux 2 kernel
3gcc 2.7.0 -O3 -fomit-frame-pointer
4No X server running, just a console, it makes the top speed jump from 151,000
5to 158,000 :-).
6options des ecb/s
7assember 281000.00 177.1%
816 r1 p 158667.40 100.0%
916 r1 i 148471.70 93.6%
1016 r2 p 143961.80 90.7%
1116 r2 i 141689.20 89.3%
12 4 r1 i 140100.00 88.3%
13 4 r2 i 134049.40 84.5%
1416 c i 124145.20 78.2%
1516 c p 121584.20 76.6%
16 4 c i 118116.00 74.4%
17 4 r2 p 117977.90 74.4%
18 4 c p 114971.40 72.5%
19 4 r1 p 114578.40 72.2%
20-DDES_UNROLL -DDES_RISC1 -DDES_PTR
diff --git a/src/lib/libcrypto/des/times/686-200.fre b/src/lib/libcrypto/des/times/686-200.fre
new file mode 100644
index 0000000000..7d83f6adee
--- /dev/null
+++ b/src/lib/libcrypto/des/times/686-200.fre
@@ -0,0 +1,18 @@
1Pentium 100
2Free BSD 2.1.5 kernel
3gcc 2.7.2.2 -O3 -fomit-frame-pointer
4options des ecb/s
5assember 578000.00 133.1%
616 r2 i 434454.80 100.0%
716 r1 i 433621.43 99.8%
816 r2 p 431375.69 99.3%
9 4 r1 i 423722.30 97.5%
10 4 r2 i 422399.40 97.2%
1116 r1 p 421739.40 97.1%
1216 c i 399027.94 91.8%
1316 c p 372251.70 85.7%
14 4 c i 365118.35 84.0%
15 4 c p 352880.51 81.2%
16 4 r2 p 255104.90 58.7%
17 4 r1 p 251289.18 57.8%
18-DDES_UNROLL -DDES_RISC2
diff --git a/src/lib/libcrypto/des/times/aix.cc b/src/lib/libcrypto/des/times/aix.cc
new file mode 100644
index 0000000000..d96b74e2ce
--- /dev/null
+++ b/src/lib/libcrypto/des/times/aix.cc
@@ -0,0 +1,26 @@
1From: Paco Garcia <pgarcia@cam.es>
2
3This machine is a Bull Estrella Minitower Model MT604-100
4Processor : PPC604
5P.Speed : 100Mhz
6Data/Instr Cache : 16 K
7L2 Cache : 256 K
8PCI BUS Speed : 33 Mhz
9TransfRate PCI : 132 MB/s
10Memory : 96 MB
11
12options des ecb/s
13 4 c p 275118.61 100.0%
14 4 c i 273545.07 99.4%
15 4 r2 p 270441.02 98.3%
16 4 r1 p 253052.15 92.0%
17 4 r2 i 240842.97 87.5%
18 4 r1 i 240556.66 87.4%
1916 c i 224603.99 81.6%
2016 c p 224483.98 81.6%
2116 r2 p 215691.19 78.4%
2216 r1 p 208332.83 75.7%
2316 r1 i 199206.50 72.4%
2416 r2 i 198963.70 72.3%
25-DDES_PTR
26
diff --git a/src/lib/libcrypto/des/times/alpha.cc b/src/lib/libcrypto/des/times/alpha.cc
new file mode 100644
index 0000000000..95c17efae7
--- /dev/null
+++ b/src/lib/libcrypto/des/times/alpha.cc
@@ -0,0 +1,18 @@
1cc -O2
2DES_LONG is 'unsigned int'
3
4options des ecb/s
5 4 r2 p 181146.14 100.0%
616 r2 p 172102.94 95.0%
7 4 r2 i 165424.11 91.3%
816 c p 160468.64 88.6%
9 4 c p 156653.59 86.5%
10 4 c i 155245.18 85.7%
11 4 r1 p 154729.68 85.4%
1216 r2 i 154137.69 85.1%
1316 r1 p 152357.96 84.1%
1416 c i 148743.91 82.1%
15 4 r1 i 146695.59 81.0%
1616 r1 i 144961.00 80.0%
17-DDES_RISC2 -DDES_PTR
18
diff --git a/src/lib/libcrypto/des/times/hpux.cc b/src/lib/libcrypto/des/times/hpux.cc
new file mode 100644
index 0000000000..3de856ddac
--- /dev/null
+++ b/src/lib/libcrypto/des/times/hpux.cc
@@ -0,0 +1,17 @@
1HPUX 10 - 9000/887 - cc -D_HPUX_SOURCE -Aa +ESlit +O2 -Wl,-a,archive
2
3options des ecb/s
416 c i 149448.90 100.0%
5 4 c i 145861.79 97.6%
616 r2 i 141710.96 94.8%
716 r1 i 139455.33 93.3%
8 4 r2 i 138800.00 92.9%
9 4 r1 i 136692.65 91.5%
1016 r2 p 110228.17 73.8%
1116 r1 p 109397.07 73.2%
1216 c p 109209.89 73.1%
13 4 c p 108014.71 72.3%
14 4 r2 p 107873.88 72.2%
15 4 r1 p 107685.83 72.1%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/sparc.gcc b/src/lib/libcrypto/des/times/sparc.gcc
new file mode 100644
index 0000000000..8eaa042104
--- /dev/null
+++ b/src/lib/libcrypto/des/times/sparc.gcc
@@ -0,0 +1,17 @@
1solaris 2.5.1 - sparc 10 50mhz - gcc 2.7.2
2
3options des ecb/s
416 c i 124382.70 100.0%
5 4 c i 118884.68 95.6%
616 c p 112261.20 90.3%
716 r2 i 111777.10 89.9%
816 r2 p 108896.30 87.5%
916 r1 p 108791.59 87.5%
10 4 c p 107290.10 86.3%
11 4 r1 p 104583.80 84.1%
1216 r1 i 104206.20 83.8%
13 4 r2 p 103709.80 83.4%
14 4 r2 i 98306.43 79.0%
15 4 r1 i 91525.80 73.6%
16-DDES_UNROLL
17
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc
new file mode 100644
index 0000000000..0864285ef6
--- /dev/null
+++ b/src/lib/libcrypto/des/times/usparc.cc
@@ -0,0 +1,31 @@
1solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5
2
3For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts'
4gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s.
5I believe the difference is tied up in optimisation that the compiler
6is able to perform when the code is 'inlined'. For 'speed', the DES
7routines are being linked from a library. I'll record the higher
8speed since if performance is everything, you can always inline
9'des_enc.c'.
10
11[ 16-Jan-06 - I've been playing with the
12 '-xtarget=ultra -xarch=v8plus -Xa -xO5 -Xa'
13 and while it makes the des_opts numbers much slower, it makes the
14 actual 'speed' numbers look better which is a realistic version of
15 using the libraries. ]
16
17options des ecb/s
1816 r1 p 475516.90 100.0%
1916 r2 p 439388.10 92.4%
2016 c i 427001.40 89.8%
2116 c p 419516.50 88.2%
22 4 r2 p 409491.70 86.1%
23 4 r1 p 404266.90 85.0%
24 4 c p 398121.00 83.7%
25 4 c i 370588.40 77.9%
26 4 r1 i 362742.20 76.3%
2716 r2 i 331275.50 69.7%
2816 r1 i 324730.60 68.3%
29 4 r2 i 63535.10 13.4% <-- very very weird, must be cache problems.
30-DDES_UNROLL -DDES_RISC1 -DDES_PTR
31
diff --git a/src/lib/libcrypto/des/typemap b/src/lib/libcrypto/des/typemap
new file mode 100644
index 0000000000..a524f53634
--- /dev/null
+++ b/src/lib/libcrypto/des/typemap
@@ -0,0 +1,34 @@
1#
2# DES SECTION
3#
4deschar * T_DESCHARP
5des_cblock * T_CBLOCK
6des_cblock T_CBLOCK
7des_key_schedule T_SCHEDULE
8des_key_schedule * T_SCHEDULE
9
10INPUT
11T_CBLOCK
12 $var=(des_cblock *)SvPV($arg,len);
13 if (len < DES_KEY_SZ)
14 {
15 croak(\"$var needs to be at least %u bytes long\",DES_KEY_SZ);
16 }
17
18T_SCHEDULE
19 $var=(des_key_schedule *)SvPV($arg,len);
20 if (len < DES_SCHEDULE_SZ)
21 {
22 croak(\"$var needs to be at least %u bytes long\",
23 DES_SCHEDULE_SZ);
24 }
25
26OUTPUT
27T_CBLOCK
28 sv_setpvn($arg,(char *)$var,DES_KEY_SZ);
29
30T_SCHEDULE
31 sv_setpvn($arg,(char *)$var,DES_SCHEDULE_SZ);
32
33T_DESCHARP
34 sv_setpvn($arg,(char *)$var,len);
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c
index dc0c761b71..47246eb466 100644
--- a/src/lib/libcrypto/des/xcbc_enc.c
+++ b/src/lib/libcrypto/des/xcbc_enc.c
@@ -60,7 +60,6 @@
60 60
61/* RSA's DESX */ 61/* RSA's DESX */
62 62
63#if 0 /* broken code, preserved just in case anyone specifically looks for this */
64static unsigned char desx_white_in2out[256]={ 63static unsigned char desx_white_in2out[256]={
650xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, 640xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0,
660x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, 650x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A,
@@ -99,7 +98,7 @@ void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
99 } 98 }
100 99
101 out0=out[0]; 100 out0=out[0];
102 out1=out[i]; /* BUG: out-of-bounds read */ 101 out1=out[i];
103 for (i=0; i<8; i++) 102 for (i=0; i<8; i++)
104 { 103 {
105 out[i]=in[i]^desx_white_in2out[out0^out1]; 104 out[i]=in[i]^desx_white_in2out[out0^out1];
@@ -107,7 +106,6 @@ void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white,
107 out1=(int)out[i&0x07]; 106 out1=(int)out[i&0x07];
108 } 107 }
109 } 108 }
110#endif
111 109
112void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out, 110void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out,
113 long length, DES_key_schedule *schedule, 111 long length, DES_key_schedule *schedule,
diff --git a/src/lib/libcrypto/dh/Makefile b/src/lib/libcrypto/dh/Makefile
new file mode 100644
index 0000000000..d368e33b4c
--- /dev/null
+++ b/src/lib/libcrypto/dh/Makefile
@@ -0,0 +1,133 @@
1#
2# OpenSSL/crypto/dh/Makefile
3#
4
5DIR= dh
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST= dhtest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= dh_asn1.c dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c dh_depr.c
21LIBOBJ= dh_asn1.o dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o dh_depr.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= dh.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77dh_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
78dh_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
79dh_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
80dh_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
81dh_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
82dh_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
83dh_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
84dh_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
85dh_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
86dh_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_asn1.c
87dh_check.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
88dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
90dh_check.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
91dh_check.o: ../../include/openssl/opensslconf.h
92dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93dh_check.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94dh_check.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_check.c
95dh_depr.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
96dh_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
97dh_depr.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
98dh_depr.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
99dh_depr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
100dh_depr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
101dh_depr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
102dh_depr.o: ../cryptlib.h dh_depr.c
103dh_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
104dh_err.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
105dh_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
106dh_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
107dh_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
108dh_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
109dh_err.o: dh_err.c
110dh_gen.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
111dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
112dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
113dh_gen.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
114dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
115dh_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
116dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
117dh_gen.o: ../cryptlib.h dh_gen.c
118dh_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
119dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
120dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
121dh_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
122dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
123dh_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
124dh_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
125dh_key.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_key.c
126dh_lib.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
127dh_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
128dh_lib.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
129dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
130dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
131dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
132dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
133dh_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_lib.c
diff --git a/src/lib/libcrypto/dh/Makefile.ssl b/src/lib/libcrypto/dh/Makefile.ssl
new file mode 100644
index 0000000000..e05fc01a12
--- /dev/null
+++ b/src/lib/libcrypto/dh/Makefile.ssl
@@ -0,0 +1,133 @@
1#
2# SSLeay/crypto/dh/Makefile
3#
4
5DIR= dh
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST= dhtest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= dh_asn1.c dh_gen.c dh_key.c dh_lib.c dh_check.c dh_err.c
27LIBOBJ= dh_asn1.o dh_gen.o dh_key.o dh_lib.o dh_check.o dh_err.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= dh.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82dh_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
83dh_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
84dh_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
85dh_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
86dh_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
87dh_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
88dh_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
89dh_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
90dh_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
91dh_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_asn1.c
92dh_check.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
93dh_check.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
94dh_check.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
95dh_check.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
96dh_check.o: ../../include/openssl/opensslconf.h
97dh_check.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
98dh_check.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
99dh_check.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_check.c
100dh_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101dh_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
102dh_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
103dh_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
104dh_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105dh_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
106dh_err.o: ../../include/openssl/symhacks.h dh_err.c
107dh_gen.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
108dh_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
109dh_gen.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
110dh_gen.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
111dh_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
112dh_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
113dh_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
114dh_gen.o: ../cryptlib.h dh_gen.c
115dh_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
116dh_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
117dh_key.o: ../../include/openssl/dh.h ../../include/openssl/e_os2.h
118dh_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
119dh_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
120dh_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
121dh_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
122dh_key.o: ../../include/openssl/symhacks.h ../cryptlib.h dh_key.c
123dh_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
124dh_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
125dh_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
126dh_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
127dh_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
128dh_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
129dh_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130dh_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
131dh_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
132dh_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
133dh_lib.o: ../cryptlib.h dh_lib.c
diff --git a/src/lib/libcrypto/dh/dh.h b/src/lib/libcrypto/dh/dh.h
index ccdf35ae1c..582b34329f 100644
--- a/src/lib/libcrypto/dh/dh.h
+++ b/src/lib/libcrypto/dh/dh.h
@@ -59,8 +59,6 @@
59#ifndef HEADER_DH_H 59#ifndef HEADER_DH_H
60#define HEADER_DH_H 60#define HEADER_DH_H
61 61
62#include <openssl/e_os2.h>
63
64#ifdef OPENSSL_NO_DH 62#ifdef OPENSSL_NO_DH
65#error DH is disabled. 63#error DH is disabled.
66#endif 64#endif
@@ -68,14 +66,11 @@
68#ifndef OPENSSL_NO_BIO 66#ifndef OPENSSL_NO_BIO
69#include <openssl/bio.h> 67#include <openssl/bio.h>
70#endif 68#endif
71#include <openssl/ossl_typ.h>
72#ifndef OPENSSL_NO_DEPRECATED
73#include <openssl/bn.h> 69#include <openssl/bn.h>
74#endif 70#include <openssl/crypto.h>
71#include <openssl/ossl_typ.h>
75 72
76#ifndef OPENSSL_DH_MAX_MODULUS_BITS 73#define OPENSSL_DH_MAX_MODULUS_BITS 10000
77# define OPENSSL_DH_MAX_MODULUS_BITS 10000
78#endif
79 74
80#define DH_FLAG_CACHE_MONT_P 0x01 75#define DH_FLAG_CACHE_MONT_P 0x01
81#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH 76#define DH_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DH
@@ -90,12 +85,9 @@
90extern "C" { 85extern "C" {
91#endif 86#endif
92 87
93/* Already defined in ossl_typ.h */ 88typedef struct dh_st DH;
94/* typedef struct dh_st DH; */
95/* typedef struct dh_method DH_METHOD; */
96 89
97struct dh_method 90typedef struct dh_method {
98 {
99 const char *name; 91 const char *name;
100 /* Methods here */ 92 /* Methods here */
101 int (*generate_key)(DH *dh); 93 int (*generate_key)(DH *dh);
@@ -108,9 +100,7 @@ struct dh_method
108 int (*finish)(DH *dh); 100 int (*finish)(DH *dh);
109 int flags; 101 int flags;
110 char *app_data; 102 char *app_data;
111 /* If this is non-NULL, it will be used to generate parameters */ 103} DH_METHOD;
112 int (*generate_params)(DH *dh, int prime_len, int generator, BN_GENCB *cb);
113 };
114 104
115struct dh_st 105struct dh_st
116 { 106 {
@@ -120,12 +110,12 @@ struct dh_st
120 int version; 110 int version;
121 BIGNUM *p; 111 BIGNUM *p;
122 BIGNUM *g; 112 BIGNUM *g;
123 long length; /* optional */ 113 int length; /* optional */
124 BIGNUM *pub_key; /* g^x */ 114 BIGNUM *pub_key; /* g^x */
125 BIGNUM *priv_key; /* x */ 115 BIGNUM *priv_key; /* x */
126 116
127 int flags; 117 int flags;
128 BN_MONT_CTX *method_mont_p; 118 char *method_mont_p;
129 /* Place holders if we want to do X9.42 DH */ 119 /* Place holders if we want to do X9.42 DH */
130 BIGNUM *q; 120 BIGNUM *q;
131 BIGNUM *j; 121 BIGNUM *j;
@@ -157,13 +147,21 @@ struct dh_st
157 this for backward compatibility: */ 147 this for backward compatibility: */
158#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME 148#define DH_CHECK_P_NOT_STRONG_PRIME DH_CHECK_P_NOT_SAFE_PRIME
159 149
160#define DHparams_dup(x) ASN1_dup_of_const(DH,i2d_DHparams,d2i_DHparams,x) 150#define DHparams_dup(x) (DH *)ASN1_dup((int (*)())i2d_DHparams, \
151 (char *(*)())d2i_DHparams,(char *)(x))
161#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \ 152#define d2i_DHparams_fp(fp,x) (DH *)ASN1_d2i_fp((char *(*)())DH_new, \
162 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x)) 153 (char *(*)())d2i_DHparams,(fp),(unsigned char **)(x))
163#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \ 154#define i2d_DHparams_fp(fp,x) ASN1_i2d_fp(i2d_DHparams,(fp), \
164 (unsigned char *)(x)) 155 (unsigned char *)(x))
165#define d2i_DHparams_bio(bp,x) ASN1_d2i_bio_of(DH,DH_new,d2i_DHparams,bp,x) 156#define d2i_DHparams_bio(bp,x) (DH *)ASN1_d2i_bio((char *(*)())DH_new, \
166#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio_of_const(DH,i2d_DHparams,bp,x) 157 (char *(*)())d2i_DHparams,(bp),(unsigned char **)(x))
158#ifdef __cplusplus
159#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio((int (*)())i2d_DHparams,(bp), \
160 (unsigned char *)(x))
161#else
162#define i2d_DHparams_bio(bp,x) ASN1_i2d_bio(i2d_DHparams,(bp), \
163 (unsigned char *)(x))
164#endif
167 165
168const DH_METHOD *DH_OpenSSL(void); 166const DH_METHOD *DH_OpenSSL(void);
169 167
@@ -180,16 +178,8 @@ int DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
180 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 178 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
181int DH_set_ex_data(DH *d, int idx, void *arg); 179int DH_set_ex_data(DH *d, int idx, void *arg);
182void *DH_get_ex_data(DH *d, int idx); 180void *DH_get_ex_data(DH *d, int idx);
183
184/* Deprecated version */
185#ifndef OPENSSL_NO_DEPRECATED
186DH * DH_generate_parameters(int prime_len,int generator, 181DH * DH_generate_parameters(int prime_len,int generator,
187 void (*callback)(int,int,void *),void *cb_arg); 182 void (*callback)(int,int,void *),void *cb_arg);
188#endif /* !defined(OPENSSL_NO_DEPRECATED) */
189
190/* New version */
191int DH_generate_parameters_ex(DH *dh, int prime_len,int generator, BN_GENCB *cb);
192
193int DH_check(const DH *dh,int *codes); 183int DH_check(const DH *dh,int *codes);
194int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes); 184int DH_check_pub_key(const DH *dh,const BIGNUM *pub_key, int *codes);
195int DH_generate_key(DH *dh); 185int DH_generate_key(DH *dh);
@@ -214,19 +204,18 @@ void ERR_load_DH_strings(void);
214/* Error codes for the DH functions. */ 204/* Error codes for the DH functions. */
215 205
216/* Function codes. */ 206/* Function codes. */
217#define DH_F_COMPUTE_KEY 102
218#define DH_F_DHPARAMS_PRINT 100 207#define DH_F_DHPARAMS_PRINT 100
219#define DH_F_DHPARAMS_PRINT_FP 101 208#define DH_F_DHPARAMS_PRINT_FP 101
220#define DH_F_DH_BUILTIN_GENPARAMS 106 209#define DH_F_DH_COMPUTE_KEY 102
210#define DH_F_DH_GENERATE_KEY 103
211#define DH_F_DH_GENERATE_PARAMETERS 104
221#define DH_F_DH_NEW_METHOD 105 212#define DH_F_DH_NEW_METHOD 105
222#define DH_F_GENERATE_KEY 103
223#define DH_F_GENERATE_PARAMETERS 104
224 213
225/* Reason codes. */ 214/* Reason codes. */
226#define DH_R_BAD_GENERATOR 101 215#define DH_R_BAD_GENERATOR 101
216#define DH_R_NO_PRIVATE_VALUE 100
227#define DH_R_INVALID_PUBKEY 102 217#define DH_R_INVALID_PUBKEY 102
228#define DH_R_MODULUS_TOO_LARGE 103 218#define DH_R_MODULUS_TOO_LARGE 103
229#define DH_R_NO_PRIVATE_VALUE 100
230 219
231#ifdef __cplusplus 220#ifdef __cplusplus
232} 221}
diff --git a/src/lib/libcrypto/dh/dh1024.pem b/src/lib/libcrypto/dh/dh1024.pem
new file mode 100644
index 0000000000..81d43f6a3e
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh1024.pem
@@ -0,0 +1,5 @@
1-----BEGIN DH PARAMETERS-----
2MIGHAoGBAJf2QmHKtQXdKCjhPx1ottPb0PMTBH9A6FbaWMsTuKG/K3g6TG1Z1fkq
3/Gz/PWk/eLI9TzFgqVAuPvr3q14a1aZeVUMTgo2oO5/y2UHe6VaJ+trqCTat3xlx
4/mNbIK9HA2RgPC3gWfVLZQrY+gz3ASHHR5nXWHEyvpuZm7m3h+irAgEC
5-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh192.pem b/src/lib/libcrypto/dh/dh192.pem
new file mode 100644
index 0000000000..521c07271d
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh192.pem
@@ -0,0 +1,3 @@
1-----BEGIN DH PARAMETERS-----
2MB4CGQDUoLoCULb9LsYm5+/WN992xxbiLQlEuIsCAQM=
3-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh2048.pem b/src/lib/libcrypto/dh/dh2048.pem
new file mode 100644
index 0000000000..295460f508
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh2048.pem
@@ -0,0 +1,16 @@
1-----BEGIN DH PARAMETERS-----
2MIIBCAKCAQEA7ZKJNYJFVcs7+6J2WmkEYb8h86tT0s0h2v94GRFS8Q7B4lW9aG9o
3AFO5Imov5Jo0H2XMWTKKvbHbSe3fpxJmw/0hBHAY8H/W91hRGXKCeyKpNBgdL8sh
4z22SrkO2qCnHJ6PLAMXy5fsKpFmFor2tRfCzrfnggTXu2YOzzK7q62bmqVdmufEo
5pT8igNcLpvZxk5uBDvhakObMym9mX3rAEBoe8PwttggMYiiw7NuJKO4MqD1llGkW
6aVM8U2ATsCun1IKHrRxynkE1/MJ86VHeYYX8GZt2YA8z+GuzylIOKcMH6JAWzMwA
7Gbatw6QwizOhr9iMjZ0B26TE3X8LvW84wwIBAg==
8-----END DH PARAMETERS-----
9-----BEGIN DH PARAMETERS-----
10MIIBCAKCAQEArtA3w73zP6Lu3EOQtwogiXt3AXXpuS6yD4BhzNS1pZFyPHk0/an5
118ydEkPhQZHKDW+BZJxxPLANaTudWo2YT8TgtvUdN6KSgMiEi6McwqDw+SADuvW+F
12SKUYFxG6VFIxyEP6xBdf+vhJxEDbRG2EYsHDRRtJ76gp9cSKTHusf2R+4AAVGqnt
13gRAbNqtcOar/7FSj+Pl8G3v0Bty0LcCSpbqgYlnv6z+rErQmmC6PPvSz97TDMCok
14yKpCE9hFA1zkqK3TH4FmFvGeIaXJUIBZf4mArWuBTjWFW3nmhESRUn1VK3K3x42N
15a5k6c2+EhrMFiLjxuH6JZoqL0/E93FF9SwIBAg==
16-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh4096.pem b/src/lib/libcrypto/dh/dh4096.pem
new file mode 100644
index 0000000000..390943a21d
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh4096.pem
@@ -0,0 +1,14 @@
1-----BEGIN DH PARAMETERS-----
2MIICCAKCAgEA/urRnb6vkPYc/KEGXWnbCIOaKitq7ySIq9dTH7s+Ri59zs77zty7
3vfVlSe6VFTBWgYjD2XKUFmtqq6CqXMhVX5ElUDoYDpAyTH85xqNFLzFC7nKrff/H
4TFKNttp22cZE9V0IPpzedPfnQkE7aUdmF9JnDyv21Z/818O93u1B4r0szdnmEvEF
5bKuIxEHX+bp0ZR7RqE1AeifXGJX3d6tsd2PMAObxwwsv55RGkn50vHO4QxtTARr1
6rRUV5j3B3oPMgC7Offxx+98Xn45B1/G0Prp11anDsR1PGwtaCYipqsvMwQUSJtyE
7EOQWk+yFkeMe4vWv367eEi0Sd/wnC+TSXBE3pYvpYerJ8n1MceI5GQTdarJ77OW9
8bGTHmxRsLSCM1jpLdPja5jjb4siAa6EHc4qN9c/iFKS3PQPJEnX7pXKBRs5f7AF3
9W3RIGt+G9IVNZfXaS7Z/iCpgzgvKCs0VeqN38QsJGtC1aIkwOeyjPNy2G6jJ4yqH
10ovXYt/0mc00vCWeSNS1wren0pR2EiLxX0ypjjgsU1mk/Z3b/+zVf7fZSIB+nDLjb
11NPtUlJCVGnAeBK1J1nG3TQicqowOXoM6ISkdaXj5GPJdXHab2+S7cqhKGv5qC7rR
12jT6sx7RUr0CNTxzLI7muV2/a4tGmj0PSdXQdsZ7tw7gbXlaWT1+MM2MCAQI=
13-----END DH PARAMETERS-----
14
diff --git a/src/lib/libcrypto/dh/dh512.pem b/src/lib/libcrypto/dh/dh512.pem
new file mode 100644
index 0000000000..0a4d863ebe
--- /dev/null
+++ b/src/lib/libcrypto/dh/dh512.pem
@@ -0,0 +1,4 @@
1-----BEGIN DH PARAMETERS-----
2MEYCQQDaWDwW2YUiidDkr3VvTMqS3UvlM7gE+w/tlO+cikQD7VdGUNNpmdsp13Yn
3a6LT1BLiGPTdHghM9tgAPnxHdOgzAgEC
4-----END DH PARAMETERS-----
diff --git a/src/lib/libcrypto/dh/dh_check.c b/src/lib/libcrypto/dh/dh_check.c
index b846913004..17debff62d 100644
--- a/src/lib/libcrypto/dh/dh_check.c
+++ b/src/lib/libcrypto/dh/dh_check.c
@@ -62,7 +62,7 @@
62#include <openssl/dh.h> 62#include <openssl/dh.h>
63 63
64/* Check that p is a safe prime and 64/* Check that p is a safe prime and
65 * if g is 2, 3 or 5, check that it is a suitable generator 65 * if g is 2, 3 or 5, check that is is a suitable generator
66 * where 66 * where
67 * for 2, p mod 24 == 11 67 * for 2, p mod 24 == 11
68 * for 3, p mod 12 == 5 68 * for 3, p mod 12 == 5
@@ -70,6 +70,8 @@
70 * should hold. 70 * should hold.
71 */ 71 */
72 72
73#ifndef OPENSSL_FIPS
74
73int DH_check(const DH *dh, int *ret) 75int DH_check(const DH *dh, int *ret)
74 { 76 {
75 int ok=0; 77 int ok=0;
@@ -104,12 +106,12 @@ int DH_check(const DH *dh, int *ret)
104 else 106 else
105 *ret|=DH_UNABLE_TO_CHECK_GENERATOR; 107 *ret|=DH_UNABLE_TO_CHECK_GENERATOR;
106 108
107 if (!BN_is_prime_ex(dh->p,BN_prime_checks,ctx,NULL)) 109 if (!BN_is_prime(dh->p,BN_prime_checks,NULL,ctx,NULL))
108 *ret|=DH_CHECK_P_NOT_PRIME; 110 *ret|=DH_CHECK_P_NOT_PRIME;
109 else 111 else
110 { 112 {
111 if (!BN_rshift1(q,dh->p)) goto err; 113 if (!BN_rshift1(q,dh->p)) goto err;
112 if (!BN_is_prime_ex(q,BN_prime_checks,ctx,NULL)) 114 if (!BN_is_prime(q,BN_prime_checks,NULL,ctx,NULL))
113 *ret|=DH_CHECK_P_NOT_SAFE_PRIME; 115 *ret|=DH_CHECK_P_NOT_SAFE_PRIME;
114 } 116 }
115 ok=1; 117 ok=1;
@@ -140,3 +142,5 @@ err:
140 if (q != NULL) BN_free(q); 142 if (q != NULL) BN_free(q);
141 return(ok); 143 return(ok);
142 } 144 }
145
146#endif
diff --git a/src/lib/libcrypto/dh/dh_err.c b/src/lib/libcrypto/dh/dh_err.c
index a2d8196ecb..611067ef4a 100644
--- a/src/lib/libcrypto/dh/dh_err.c
+++ b/src/lib/libcrypto/dh/dh_err.c
@@ -70,22 +70,21 @@
70 70
71static ERR_STRING_DATA DH_str_functs[]= 71static ERR_STRING_DATA DH_str_functs[]=
72 { 72 {
73{ERR_FUNC(DH_F_COMPUTE_KEY), "COMPUTE_KEY"},
74{ERR_FUNC(DH_F_DHPARAMS_PRINT), "DHparams_print"}, 73{ERR_FUNC(DH_F_DHPARAMS_PRINT), "DHparams_print"},
75{ERR_FUNC(DH_F_DHPARAMS_PRINT_FP), "DHparams_print_fp"}, 74{ERR_FUNC(DH_F_DHPARAMS_PRINT_FP), "DHparams_print_fp"},
76{ERR_FUNC(DH_F_DH_BUILTIN_GENPARAMS), "DH_BUILTIN_GENPARAMS"}, 75{ERR_FUNC(DH_F_DH_COMPUTE_KEY), "DH_compute_key"},
76{ERR_FUNC(DH_F_DH_GENERATE_KEY), "DH_generate_key"},
77{ERR_FUNC(DH_F_DH_GENERATE_PARAMETERS), "DH_generate_parameters"},
77{ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"}, 78{ERR_FUNC(DH_F_DH_NEW_METHOD), "DH_new_method"},
78{ERR_FUNC(DH_F_GENERATE_KEY), "GENERATE_KEY"},
79{ERR_FUNC(DH_F_GENERATE_PARAMETERS), "GENERATE_PARAMETERS"},
80{0,NULL} 79{0,NULL}
81 }; 80 };
82 81
83static ERR_STRING_DATA DH_str_reasons[]= 82static ERR_STRING_DATA DH_str_reasons[]=
84 { 83 {
85{ERR_REASON(DH_R_BAD_GENERATOR) ,"bad generator"}, 84{ERR_REASON(DH_R_BAD_GENERATOR) ,"bad generator"},
85{ERR_REASON(DH_R_NO_PRIVATE_VALUE) ,"no private value"},
86{ERR_REASON(DH_R_INVALID_PUBKEY) ,"invalid public key"}, 86{ERR_REASON(DH_R_INVALID_PUBKEY) ,"invalid public key"},
87{ERR_REASON(DH_R_MODULUS_TOO_LARGE) ,"modulus too large"}, 87{ERR_REASON(DH_R_MODULUS_TOO_LARGE) ,"modulus too large"},
88{ERR_REASON(DH_R_NO_PRIVATE_VALUE) ,"no private value"},
89{0,NULL} 88{0,NULL}
90 }; 89 };
91 90
@@ -93,12 +92,15 @@ static ERR_STRING_DATA DH_str_reasons[]=
93 92
94void ERR_load_DH_strings(void) 93void ERR_load_DH_strings(void)
95 { 94 {
96#ifndef OPENSSL_NO_ERR 95 static int init=1;
97 96
98 if (ERR_func_error_string(DH_str_functs[0].error) == NULL) 97 if (init)
99 { 98 {
99 init=0;
100#ifndef OPENSSL_NO_ERR
100 ERR_load_strings(0,DH_str_functs); 101 ERR_load_strings(0,DH_str_functs);
101 ERR_load_strings(0,DH_str_reasons); 102 ERR_load_strings(0,DH_str_reasons);
102 }
103#endif 103#endif
104
105 }
104 } 106 }
diff --git a/src/lib/libcrypto/dh/dh_gen.c b/src/lib/libcrypto/dh/dh_gen.c
index cfd5b11868..23777f5a16 100644
--- a/src/lib/libcrypto/dh/dh_gen.c
+++ b/src/lib/libcrypto/dh/dh_gen.c
@@ -56,25 +56,11 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59/* NB: These functions have been upgraded - the previous prototypes are in
60 * dh_depr.c as wrappers to these ones.
61 * - Geoff
62 */
63
64#include <stdio.h> 59#include <stdio.h>
65#include "cryptlib.h" 60#include "cryptlib.h"
66#include <openssl/bn.h> 61#include <openssl/bn.h>
67#include <openssl/dh.h> 62#include <openssl/dh.h>
68 63
69static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb);
70
71int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
72 {
73 if(ret->meth->generate_params)
74 return ret->meth->generate_params(ret, prime_len, generator, cb);
75 return dh_builtin_genparams(ret, prime_len, generator, cb);
76 }
77
78/* We generate DH parameters as follows 64/* We generate DH parameters as follows
79 * find a prime q which is prime_len/2 bits long. 65 * find a prime q which is prime_len/2 bits long.
80 * p=(2*q)+1 or (p-1)/2 = q 66 * p=(2*q)+1 or (p-1)/2 = q
@@ -100,26 +86,29 @@ int DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *c
100 * It's just as OK (and in some sense better) to use a generator of the 86 * It's just as OK (and in some sense better) to use a generator of the
101 * order-q subgroup. 87 * order-q subgroup.
102 */ 88 */
103static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB *cb) 89
90#ifndef OPENSSL_FIPS
91
92DH *DH_generate_parameters(int prime_len, int generator,
93 void (*callback)(int,int,void *), void *cb_arg)
104 { 94 {
105 BIGNUM *t1,*t2; 95 BIGNUM *p=NULL,*t1,*t2;
96 DH *ret=NULL;
106 int g,ok= -1; 97 int g,ok= -1;
107 BN_CTX *ctx=NULL; 98 BN_CTX *ctx=NULL;
108 99
100 ret=DH_new();
101 if (ret == NULL) goto err;
109 ctx=BN_CTX_new(); 102 ctx=BN_CTX_new();
110 if (ctx == NULL) goto err; 103 if (ctx == NULL) goto err;
111 BN_CTX_start(ctx); 104 BN_CTX_start(ctx);
112 t1 = BN_CTX_get(ctx); 105 t1 = BN_CTX_get(ctx);
113 t2 = BN_CTX_get(ctx); 106 t2 = BN_CTX_get(ctx);
114 if (t1 == NULL || t2 == NULL) goto err; 107 if (t1 == NULL || t2 == NULL) goto err;
115
116 /* Make sure 'ret' has the necessary elements */
117 if(!ret->p && ((ret->p = BN_new()) == NULL)) goto err;
118 if(!ret->g && ((ret->g = BN_new()) == NULL)) goto err;
119 108
120 if (generator <= 1) 109 if (generator <= 1)
121 { 110 {
122 DHerr(DH_F_DH_BUILTIN_GENPARAMS, DH_R_BAD_GENERATOR); 111 DHerr(DH_F_DH_GENERATE_PARAMETERS, DH_R_BAD_GENERATOR);
123 goto err; 112 goto err;
124 } 113 }
125 if (generator == DH_GENERATOR_2) 114 if (generator == DH_GENERATOR_2)
@@ -155,14 +144,18 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator, BN_GENCB
155 g=generator; 144 g=generator;
156 } 145 }
157 146
158 if(!BN_generate_prime_ex(ret->p,prime_len,1,t1,t2,cb)) goto err; 147 p=BN_generate_prime(NULL,prime_len,1,t1,t2,callback,cb_arg);
159 if(!BN_GENCB_call(cb, 3, 0)) goto err; 148 if (p == NULL) goto err;
149 if (callback != NULL) callback(3,0,cb_arg);
150 ret->p=p;
151 ret->g=BN_new();
152 if (ret->g == NULL) goto err;
160 if (!BN_set_word(ret->g,g)) goto err; 153 if (!BN_set_word(ret->g,g)) goto err;
161 ok=1; 154 ok=1;
162err: 155err:
163 if (ok == -1) 156 if (ok == -1)
164 { 157 {
165 DHerr(DH_F_DH_BUILTIN_GENPARAMS,ERR_R_BN_LIB); 158 DHerr(DH_F_DH_GENERATE_PARAMETERS,ERR_R_BN_LIB);
166 ok=0; 159 ok=0;
167 } 160 }
168 161
@@ -171,5 +164,12 @@ err:
171 BN_CTX_end(ctx); 164 BN_CTX_end(ctx);
172 BN_CTX_free(ctx); 165 BN_CTX_free(ctx);
173 } 166 }
174 return ok; 167 if (!ok && (ret != NULL))
168 {
169 DH_free(ret);
170 ret=NULL;
171 }
172 return(ret);
175 } 173 }
174
175#endif
diff --git a/src/lib/libcrypto/dh/dh_key.c b/src/lib/libcrypto/dh/dh_key.c
index e7db440342..74de589204 100644
--- a/src/lib/libcrypto/dh/dh_key.c
+++ b/src/lib/libcrypto/dh/dh_key.c
@@ -62,6 +62,8 @@
62#include <openssl/rand.h> 62#include <openssl/rand.h>
63#include <openssl/dh.h> 63#include <openssl/dh.h>
64 64
65#ifndef OPENSSL_FIPS
66
65static int generate_key(DH *dh); 67static int generate_key(DH *dh);
66static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh); 68static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
67static int dh_bn_mod_exp(const DH *dh, BIGNUM *r, 69static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
@@ -89,7 +91,6 @@ dh_bn_mod_exp,
89dh_init, 91dh_init,
90dh_finish, 92dh_finish,
910, 930,
92NULL,
93NULL 94NULL
94}; 95};
95 96
@@ -130,7 +131,8 @@ static int generate_key(DH *dh)
130 131
131 if (dh->flags & DH_FLAG_CACHE_MONT_P) 132 if (dh->flags & DH_FLAG_CACHE_MONT_P)
132 { 133 {
133 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, 134 mont = BN_MONT_CTX_set_locked(
135 (BN_MONT_CTX **)&dh->method_mont_p,
134 CRYPTO_LOCK_DH, dh->p, ctx); 136 CRYPTO_LOCK_DH, dh->p, ctx);
135 if (!mont) 137 if (!mont)
136 goto err; 138 goto err;
@@ -150,7 +152,7 @@ static int generate_key(DH *dh)
150 { 152 {
151 BN_init(&local_prk); 153 BN_init(&local_prk);
152 prk = &local_prk; 154 prk = &local_prk;
153 BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); 155 BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);
154 } 156 }
155 else 157 else
156 prk = priv_key; 158 prk = priv_key;
@@ -163,7 +165,7 @@ static int generate_key(DH *dh)
163 ok=1; 165 ok=1;
164err: 166err:
165 if (ok != 1) 167 if (ok != 1)
166 DHerr(DH_F_GENERATE_KEY,ERR_R_BN_LIB); 168 DHerr(DH_F_DH_GENERATE_KEY,ERR_R_BN_LIB);
167 169
168 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key); 170 if ((pub_key != NULL) && (dh->pub_key == NULL)) BN_free(pub_key);
169 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key); 171 if ((priv_key != NULL) && (dh->priv_key == NULL)) BN_free(priv_key);
@@ -173,16 +175,16 @@ err:
173 175
174static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh) 176static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
175 { 177 {
176 BN_CTX *ctx=NULL; 178 BN_CTX *ctx;
177 BN_MONT_CTX *mont=NULL; 179 BN_MONT_CTX *mont=NULL;
178 BIGNUM *tmp; 180 BIGNUM *tmp;
179 int ret= -1; 181 int ret= -1;
180 int check_result; 182 int check_result;
181 183
182 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS) 184 if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
183 { 185 {
184 DHerr(DH_F_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE); 186 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_MODULUS_TOO_LARGE);
185 goto err; 187 return -1;
186 } 188 }
187 189
188 ctx = BN_CTX_new(); 190 ctx = BN_CTX_new();
@@ -192,32 +194,31 @@ static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
192 194
193 if (dh->priv_key == NULL) 195 if (dh->priv_key == NULL)
194 { 196 {
195 DHerr(DH_F_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE); 197 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_NO_PRIVATE_VALUE);
196 goto err; 198 goto err;
197 } 199 }
198 200
199 if (dh->flags & DH_FLAG_CACHE_MONT_P) 201 if (dh->flags & DH_FLAG_CACHE_MONT_P)
200 { 202 {
201 mont = BN_MONT_CTX_set_locked(&dh->method_mont_p, 203 mont = BN_MONT_CTX_set_locked(
204 (BN_MONT_CTX **)&dh->method_mont_p,
202 CRYPTO_LOCK_DH, dh->p, ctx); 205 CRYPTO_LOCK_DH, dh->p, ctx);
203 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0) 206 if ((dh->flags & DH_FLAG_NO_EXP_CONSTTIME) == 0)
204 { 207 {
205 /* XXX */ 208 /* XXX */
206 BN_set_flags(dh->priv_key, BN_FLG_CONSTTIME); 209 BN_set_flags(dh->priv_key, BN_FLG_EXP_CONSTTIME);
207 } 210 }
208 if (!mont) 211 if (!mont)
209 goto err; 212 goto err;
210 } 213 }
211 214 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result)
212 if (!DH_check_pub_key(dh, pub_key, &check_result) || check_result)
213 { 215 {
214 DHerr(DH_F_COMPUTE_KEY,DH_R_INVALID_PUBKEY); 216 DHerr(DH_F_DH_COMPUTE_KEY,DH_R_INVALID_PUBKEY);
215 goto err; 217 goto err;
216 } 218 }
217
218 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont)) 219 if (!dh->meth->bn_mod_exp(dh, tmp, pub_key, dh->priv_key,dh->p,ctx,mont))
219 { 220 {
220 DHerr(DH_F_COMPUTE_KEY,ERR_R_BN_LIB); 221 DHerr(DH_F_DH_COMPUTE_KEY,ERR_R_BN_LIB);
221 goto err; 222 goto err;
222 } 223 }
223 224
@@ -258,6 +259,8 @@ static int dh_init(DH *dh)
258static int dh_finish(DH *dh) 259static int dh_finish(DH *dh)
259 { 260 {
260 if(dh->method_mont_p) 261 if(dh->method_mont_p)
261 BN_MONT_CTX_free(dh->method_mont_p); 262 BN_MONT_CTX_free((BN_MONT_CTX *)dh->method_mont_p);
262 return(1); 263 return(1);
263 } 264 }
265
266#endif
diff --git a/src/lib/libcrypto/dh/dh_lib.c b/src/lib/libcrypto/dh/dh_lib.c
index 7aef080e7a..09965ee2ea 100644
--- a/src/lib/libcrypto/dh/dh_lib.c
+++ b/src/lib/libcrypto/dh/dh_lib.c
@@ -64,7 +64,7 @@
64#include <openssl/engine.h> 64#include <openssl/engine.h>
65#endif 65#endif
66 66
67const char DH_version[]="Diffie-Hellman" OPENSSL_VERSION_PTEXT; 67const char *DH_version="Diffie-Hellman" OPENSSL_VERSION_PTEXT;
68 68
69static const DH_METHOD *default_DH_method = NULL; 69static const DH_METHOD *default_DH_method = NULL;
70 70
diff --git a/src/lib/libcrypto/dh/dhtest.c b/src/lib/libcrypto/dh/dhtest.c
new file mode 100644
index 0000000000..b76dede771
--- /dev/null
+++ b/src/lib/libcrypto/dh/dhtest.c
@@ -0,0 +1,216 @@
1/* crypto/dh/dhtest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "../e_os.h"
64
65#include <openssl/crypto.h>
66#include <openssl/bio.h>
67#include <openssl/bn.h>
68#include <openssl/rand.h>
69#include <openssl/err.h>
70
71#ifdef OPENSSL_NO_DH
72int main(int argc, char *argv[])
73{
74 printf("No DH support\n");
75 return(0);
76}
77#else
78#include <openssl/dh.h>
79
80#ifdef OPENSSL_SYS_WIN16
81#define MS_CALLBACK _far _loadds
82#else
83#define MS_CALLBACK
84#endif
85
86static void MS_CALLBACK cb(int p, int n, void *arg);
87
88static const char rnd_seed[] = "string to make the random number generator think it has entropy";
89
90int main(int argc, char *argv[])
91 {
92 DH *a;
93 DH *b=NULL;
94 char buf[12];
95 unsigned char *abuf=NULL,*bbuf=NULL;
96 int i,alen,blen,aout,bout,ret=1;
97 BIO *out;
98
99 CRYPTO_malloc_debug_init();
100 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
101 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
102
103#ifdef OPENSSL_SYS_WIN32
104 CRYPTO_malloc_init();
105#endif
106
107 RAND_seed(rnd_seed, sizeof rnd_seed);
108
109 out=BIO_new(BIO_s_file());
110 if (out == NULL) EXIT(1);
111 BIO_set_fp(out,stdout,BIO_NOCLOSE);
112
113 a=DH_generate_parameters(64,DH_GENERATOR_5,cb,out);
114 if (a == NULL) goto err;
115
116 if (!DH_check(a, &i)) goto err;
117 if (i & DH_CHECK_P_NOT_PRIME)
118 BIO_puts(out, "p value is not prime\n");
119 if (i & DH_CHECK_P_NOT_SAFE_PRIME)
120 BIO_puts(out, "p value is not a safe prime\n");
121 if (i & DH_UNABLE_TO_CHECK_GENERATOR)
122 BIO_puts(out, "unable to check the generator value\n");
123 if (i & DH_NOT_SUITABLE_GENERATOR)
124 BIO_puts(out, "the g value is not a generator\n");
125
126 BIO_puts(out,"\np =");
127 BN_print(out,a->p);
128 BIO_puts(out,"\ng =");
129 BN_print(out,a->g);
130 BIO_puts(out,"\n");
131
132 b=DH_new();
133 if (b == NULL) goto err;
134
135 b->p=BN_dup(a->p);
136 b->g=BN_dup(a->g);
137 if ((b->p == NULL) || (b->g == NULL)) goto err;
138
139 /* Set a to run with normal modexp and b to use constant time */
140 a->flags &= ~DH_FLAG_NO_EXP_CONSTTIME;
141 b->flags |= DH_FLAG_NO_EXP_CONSTTIME;
142
143 if (!DH_generate_key(a)) goto err;
144 BIO_puts(out,"pri 1=");
145 BN_print(out,a->priv_key);
146 BIO_puts(out,"\npub 1=");
147 BN_print(out,a->pub_key);
148 BIO_puts(out,"\n");
149
150 if (!DH_generate_key(b)) goto err;
151 BIO_puts(out,"pri 2=");
152 BN_print(out,b->priv_key);
153 BIO_puts(out,"\npub 2=");
154 BN_print(out,b->pub_key);
155 BIO_puts(out,"\n");
156
157 alen=DH_size(a);
158 abuf=(unsigned char *)OPENSSL_malloc(alen);
159 aout=DH_compute_key(abuf,b->pub_key,a);
160
161 BIO_puts(out,"key1 =");
162 for (i=0; i<aout; i++)
163 {
164 sprintf(buf,"%02X",abuf[i]);
165 BIO_puts(out,buf);
166 }
167 BIO_puts(out,"\n");
168
169 blen=DH_size(b);
170 bbuf=(unsigned char *)OPENSSL_malloc(blen);
171 bout=DH_compute_key(bbuf,a->pub_key,b);
172
173 BIO_puts(out,"key2 =");
174 for (i=0; i<bout; i++)
175 {
176 sprintf(buf,"%02X",bbuf[i]);
177 BIO_puts(out,buf);
178 }
179 BIO_puts(out,"\n");
180 if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0))
181 {
182 fprintf(stderr,"Error in DH routines\n");
183 ret=1;
184 }
185 else
186 ret=0;
187err:
188 ERR_print_errors_fp(stderr);
189
190 if (abuf != NULL) OPENSSL_free(abuf);
191 if (bbuf != NULL) OPENSSL_free(bbuf);
192 if(b != NULL) DH_free(b);
193 if(a != NULL) DH_free(a);
194 BIO_free(out);
195 CRYPTO_cleanup_all_ex_data();
196 ERR_remove_state(0);
197 CRYPTO_mem_leaks_fp(stderr);
198 EXIT(ret);
199 return(ret);
200 }
201
202static void MS_CALLBACK cb(int p, int n, void *arg)
203 {
204 char c='*';
205
206 if (p == 0) c='.';
207 if (p == 1) c='+';
208 if (p == 2) c='*';
209 if (p == 3) c='\n';
210 BIO_write((BIO *)arg,&c,1);
211 (void)BIO_flush((BIO *)arg);
212#ifdef LINT
213 p=n;
214#endif
215 }
216#endif
diff --git a/src/lib/libcrypto/dh/example b/src/lib/libcrypto/dh/example
new file mode 100644
index 0000000000..16a33d2910
--- /dev/null
+++ b/src/lib/libcrypto/dh/example
@@ -0,0 +1,50 @@
1From owner-cypherpunks@toad.com Mon Sep 25 10:50:51 1995
2Received: from minbne.mincom.oz.au by orb.mincom.oz.au with SMTP id AA10562
3 (5.65c/IDA-1.4.4 for eay); Wed, 27 Sep 1995 19:41:55 +1000
4Received: by minbne.mincom.oz.au id AA19958
5 (5.65c/IDA-1.4.4 for eay@orb.mincom.oz.au); Wed, 27 Sep 1995 19:34:59 +1000
6Received: from relay3.UU.NET by bunyip.cc.uq.oz.au with SMTP (PP);
7 Wed, 27 Sep 1995 19:13:05 +1000
8Received: from toad.com by relay3.UU.NET with SMTP id QQzizb16156;
9 Wed, 27 Sep 1995 04:48:46 -0400
10Received: by toad.com id AA07905; Tue, 26 Sep 95 06:31:45 PDT
11Received: from by toad.com id AB07851; Tue, 26 Sep 95 06:31:40 PDT
12Received: from servo.qualcomm.com (servo.qualcomm.com [129.46.128.14])
13 by cygnus.com (8.6.12/8.6.9) with ESMTP id RAA18442
14 for <cypherpunks@toad.com>; Mon, 25 Sep 1995 17:52:47 -0700
15Received: (karn@localhost) by servo.qualcomm.com (8.6.12/QC-BSD-2.5.1)
16 id RAA14732; Mon, 25 Sep 1995 17:50:51 -0700
17Date: Mon, 25 Sep 1995 17:50:51 -0700
18From: Phil Karn <karn@qualcomm.com>
19Message-Id: <199509260050.RAA14732@servo.qualcomm.com>
20To: cypherpunks@toad.com, ipsec-dev@eit.com
21Subject: Primality verification needed
22Sender: owner-cypherpunks@toad.com
23Precedence: bulk
24Status: RO
25X-Status:
26
27Hi. I've generated a 2047-bit "strong" prime number that I would like to
28use with Diffie-Hellman key exchange. I assert that not only is this number
29'p' prime, but so is (p-1)/2.
30
31I've used the mpz_probab_prime() function in the Gnu Math Package (GMP) version
321.3.2 to test this number. This function uses the Miller-Rabin primality test.
33However, to increase my confidence that this number really is a strong prime,
34I'd like to ask others to confirm it with other tests. Here's the number in hex:
35
3672a925f760b2f954ed287f1b0953f3e6aef92e456172f9fe86fdd8822241b9c9788fbc289982743e
37fbcd2ccf062b242d7a567ba8bbb40d79bca7b8e0b6c05f835a5b938d985816bc648985adcff5402a
38a76756b36c845a840a1d059ce02707e19cf47af0b5a882f32315c19d1b86a56c5389c5e9bee16b65
39fde7b1a8d74a7675de9b707d4c5a4633c0290c95ff30a605aeb7ae864ff48370f13cf01d49adb9f2
403d19a439f753ee7703cf342d87f431105c843c78ca4df639931f3458fae8a94d1687e99a76ed99d0
41ba87189f42fd31ad8262c54a8cf5914ae6c28c540d714a5f6087a171fb74f4814c6f968d72386ef3
4256a05180c3bec7ddd5ef6fe76b1f717b
43
44The generator, g, for this prime is 2.
45
46Thanks!
47
48Phil Karn
49
50
diff --git a/src/lib/libcrypto/dh/generate b/src/lib/libcrypto/dh/generate
new file mode 100644
index 0000000000..5d407231df
--- /dev/null
+++ b/src/lib/libcrypto/dh/generate
@@ -0,0 +1,65 @@
1From: stewarts@ix.netcom.com (Bill Stewart)
2Newsgroups: sci.crypt
3Subject: Re: Diffie-Hellman key exchange
4Date: Wed, 11 Oct 1995 23:08:28 GMT
5Organization: Freelance Information Architect
6Lines: 32
7Message-ID: <45hir2$7l8@ixnews7.ix.netcom.com>
8References: <458rhn$76m$1@mhadf.production.compuserve.com>
9NNTP-Posting-Host: ix-pl4-16.ix.netcom.com
10X-NETCOM-Date: Wed Oct 11 4:09:22 PM PDT 1995
11X-Newsreader: Forte Free Agent 1.0.82
12
13Kent Briggs <72124.3234@CompuServe.COM> wrote:
14
15>I have a copy of the 1976 IEEE article describing the
16>Diffie-Hellman public key exchange algorithm: y=a^x mod q. I'm
17>looking for sources that give examples of secure a,q pairs and
18>possible some source code that I could examine.
19
20q should be prime, and ideally should be a "strong prime",
21which means it's of the form 2n+1 where n is also prime.
22q also needs to be long enough to prevent the attacks LaMacchia and
23Odlyzko described (some variant on a factoring attack which generates
24a large pile of simultaneous equations and then solves them);
25long enough is about the same size as factoring, so 512 bits may not
26be secure enough for most applications. (The 192 bits used by
27"secure NFS" was certainly not long enough.)
28
29a should be a generator for q, which means it needs to be
30relatively prime to q-1. Usually a small prime like 2, 3 or 5 will
31work.
32
33....
34
35Date: Tue, 26 Sep 1995 13:52:36 MST
36From: "Richard Schroeppel" <rcs@cs.arizona.edu>
37To: karn
38Cc: ho@cs.arizona.edu
39Subject: random large primes
40
41Since your prime is really random, proving it is hard.
42My personal limit on rigorously proved primes is ~350 digits.
43If you really want a proof, we should talk to Francois Morain,
44or the Australian group.
45
46If you want 2 to be a generator (mod P), then you need it
47to be a non-square. If (P-1)/2 is also prime, then
48non-square == primitive-root for bases << P.
49
50In the case at hand, this means 2 is a generator iff P = 11 (mod 24).
51If you want this, you should restrict your sieve accordingly.
52
533 is a generator iff P = 5 (mod 12).
54
555 is a generator iff P = 3 or 7 (mod 10).
56
572 is perfectly usable as a base even if it's a non-generator, since
58it still covers half the space of possible residues. And an
59eavesdropper can always determine the low-bit of your exponent for
60a generator anyway.
61
62Rich rcs@cs.arizona.edu
63
64
65
diff --git a/src/lib/libcrypto/dh/p1024.c b/src/lib/libcrypto/dh/p1024.c
new file mode 100644
index 0000000000..368ceca4eb
--- /dev/null
+++ b/src/lib/libcrypto/dh/p1024.c
@@ -0,0 +1,92 @@
1/* crypto/dh/p1024.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/bn.h>
61#include <openssl/asn1.h>
62#include <openssl/dh.h>
63#include <openssl/pem.h>
64
65unsigned char data[]={0x97,0xF6,0x42,0x61,0xCA,0xB5,0x05,0xDD,
66 0x28,0x28,0xE1,0x3F,0x1D,0x68,0xB6,0xD3,
67 0xDB,0xD0,0xF3,0x13,0x04,0x7F,0x40,0xE8,
68 0x56,0xDA,0x58,0xCB,0x13,0xB8,0xA1,0xBF,
69 0x2B,0x78,0x3A,0x4C,0x6D,0x59,0xD5,0xF9,
70 0x2A,0xFC,0x6C,0xFF,0x3D,0x69,0x3F,0x78,
71 0xB2,0x3D,0x4F,0x31,0x60,0xA9,0x50,0x2E,
72 0x3E,0xFA,0xF7,0xAB,0x5E,0x1A,0xD5,0xA6,
73 0x5E,0x55,0x43,0x13,0x82,0x8D,0xA8,0x3B,
74 0x9F,0xF2,0xD9,0x41,0xDE,0xE9,0x56,0x89,
75 0xFA,0xDA,0xEA,0x09,0x36,0xAD,0xDF,0x19,
76 0x71,0xFE,0x63,0x5B,0x20,0xAF,0x47,0x03,
77 0x64,0x60,0x3C,0x2D,0xE0,0x59,0xF5,0x4B,
78 0x65,0x0A,0xD8,0xFA,0x0C,0xF7,0x01,0x21,
79 0xC7,0x47,0x99,0xD7,0x58,0x71,0x32,0xBE,
80 0x9B,0x99,0x9B,0xB9,0xB7,0x87,0xE8,0xAB,
81 };
82
83main()
84 {
85 DH *dh;
86
87 dh=DH_new();
88 dh->p=BN_bin2bn(data,sizeof(data),NULL);
89 dh->g=BN_new();
90 BN_set_word(dh->g,2);
91 PEM_write_DHparams(stdout,dh);
92 }
diff --git a/src/lib/libcrypto/dh/p192.c b/src/lib/libcrypto/dh/p192.c
new file mode 100644
index 0000000000..7bdf40410e
--- /dev/null
+++ b/src/lib/libcrypto/dh/p192.c
@@ -0,0 +1,80 @@
1/* crypto/dh/p192.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/bn.h>
61#include <openssl/asn1.h>
62#include <openssl/dh.h>
63#include <openssl/pem.h>
64
65unsigned char data[]={
660xD4,0xA0,0xBA,0x02,0x50,0xB6,0xFD,0x2E,
670xC6,0x26,0xE7,0xEF,0xD6,0x37,0xDF,0x76,
680xC7,0x16,0xE2,0x2D,0x09,0x44,0xB8,0x8B,
69 };
70
71main()
72 {
73 DH *dh;
74
75 dh=DH_new();
76 dh->p=BN_bin2bn(data,sizeof(data),NULL);
77 dh->g=BN_new();
78 BN_set_word(dh->g,3);
79 PEM_write_DHparams(stdout,dh);
80 }
diff --git a/src/lib/libcrypto/dh/p512.c b/src/lib/libcrypto/dh/p512.c
new file mode 100644
index 0000000000..a9b6aa83f0
--- /dev/null
+++ b/src/lib/libcrypto/dh/p512.c
@@ -0,0 +1,85 @@
1/* crypto/dh/p512.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/bn.h>
61#include <openssl/asn1.h>
62#include <openssl/dh.h>
63#include <openssl/pem.h>
64
65unsigned char data[]={
660xDA,0x58,0x3C,0x16,0xD9,0x85,0x22,0x89,
670xD0,0xE4,0xAF,0x75,0x6F,0x4C,0xCA,0x92,
680xDD,0x4B,0xE5,0x33,0xB8,0x04,0xFB,0x0F,
690xED,0x94,0xEF,0x9C,0x8A,0x44,0x03,0xED,
700x57,0x46,0x50,0xD3,0x69,0x99,0xDB,0x29,
710xD7,0x76,0x27,0x6B,0xA2,0xD3,0xD4,0x12,
720xE2,0x18,0xF4,0xDD,0x1E,0x08,0x4C,0xF6,
730xD8,0x00,0x3E,0x7C,0x47,0x74,0xE8,0x33,
74 };
75
76main()
77 {
78 DH *dh;
79
80 dh=DH_new();
81 dh->p=BN_bin2bn(data,sizeof(data),NULL);
82 dh->g=BN_new();
83 BN_set_word(dh->g,2);
84 PEM_write_DHparams(stdout,dh);
85 }
diff --git a/src/lib/libcrypto/doc/DH_set_method.pod b/src/lib/libcrypto/doc/DH_set_method.pod
index d5cdc3be0c..73261fc467 100644
--- a/src/lib/libcrypto/doc/DH_set_method.pod
+++ b/src/lib/libcrypto/doc/DH_set_method.pod
@@ -36,7 +36,7 @@ structures created later. B<NB>: This is true only whilst no ENGINE has been set
36as a default for DH, so this function is no longer recommended. 36as a default for DH, so this function is no longer recommended.
37 37
38DH_get_default_method() returns a pointer to the current default DH_METHOD. 38DH_get_default_method() returns a pointer to the current default DH_METHOD.
39However, the meaningfulness of this result is dependent on whether the ENGINE 39However, the meaningfulness of this result is dependant on whether the ENGINE
40API is being used, so this function is no longer recommended. 40API is being used, so this function is no longer recommended.
41 41
42DH_set_method() selects B<meth> to perform all operations using the key B<dh>. 42DH_set_method() selects B<meth> to perform all operations using the key B<dh>.
diff --git a/src/lib/libcrypto/doc/DSA_set_method.pod b/src/lib/libcrypto/doc/DSA_set_method.pod
index 9c1434bd8d..bc3cfb1f0a 100644
--- a/src/lib/libcrypto/doc/DSA_set_method.pod
+++ b/src/lib/libcrypto/doc/DSA_set_method.pod
@@ -36,7 +36,7 @@ structures created later. B<NB>: This is true only whilst no ENGINE has
36been set as a default for DSA, so this function is no longer recommended. 36been set as a default for DSA, so this function is no longer recommended.
37 37
38DSA_get_default_method() returns a pointer to the current default 38DSA_get_default_method() returns a pointer to the current default
39DSA_METHOD. However, the meaningfulness of this result is dependent on 39DSA_METHOD. However, the meaningfulness of this result is dependant on
40whether the ENGINE API is being used, so this function is no longer 40whether the ENGINE API is being used, so this function is no longer
41recommended. 41recommended.
42 42
diff --git a/src/lib/libcrypto/doc/EVP_BytesToKey.pod b/src/lib/libcrypto/doc/EVP_BytesToKey.pod
index d375c46e03..016381f3e9 100644
--- a/src/lib/libcrypto/doc/EVP_BytesToKey.pod
+++ b/src/lib/libcrypto/doc/EVP_BytesToKey.pod
@@ -60,7 +60,7 @@ EVP_BytesToKey() returns the size of the derived key in bytes.
60=head1 SEE ALSO 60=head1 SEE ALSO
61 61
62L<evp(3)|evp(3)>, L<rand(3)|rand(3)>, 62L<evp(3)|evp(3)>, L<rand(3)|rand(3)>,
63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)> 63L<EVP_EncryptInit(3)|EVP_EncryptInit(3)>,
64 64
65=head1 HISTORY 65=head1 HISTORY
66 66
diff --git a/src/lib/libcrypto/doc/EVP_DigestInit.pod b/src/lib/libcrypto/doc/EVP_DigestInit.pod
index 130cd7f60a..faa992286b 100644
--- a/src/lib/libcrypto/doc/EVP_DigestInit.pod
+++ b/src/lib/libcrypto/doc/EVP_DigestInit.pod
@@ -18,7 +18,7 @@ EVP digest routines
18 EVP_MD_CTX *EVP_MD_CTX_create(void); 18 EVP_MD_CTX *EVP_MD_CTX_create(void);
19 19
20 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); 20 int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
21 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, size_t cnt); 21 int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *d, unsigned int cnt);
22 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, 22 int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md,
23 unsigned int *s); 23 unsigned int *s);
24 24
@@ -236,9 +236,9 @@ even though they are identical digests.
236 236
237=head1 SEE ALSO 237=head1 SEE ALSO
238 238
239L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, 239L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
240L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>, 240L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD160(3)|RIPEMD160(3)>,
241L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> 241L<SHA1(3)|SHA1(3)>
242 242
243=head1 HISTORY 243=head1 HISTORY
244 244
diff --git a/src/lib/libcrypto/doc/EVP_SealInit.pod b/src/lib/libcrypto/doc/EVP_SealInit.pod
index 7d793e19ef..48a0e29954 100644
--- a/src/lib/libcrypto/doc/EVP_SealInit.pod
+++ b/src/lib/libcrypto/doc/EVP_SealInit.pod
@@ -8,9 +8,9 @@ EVP_SealInit, EVP_SealUpdate, EVP_SealFinal - EVP envelope encryption
8 8
9 #include <openssl/evp.h> 9 #include <openssl/evp.h>
10 10
11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 11 int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type,
12 unsigned char **ek, int *ekl, unsigned char *iv, 12 unsigned char **ek, int *ekl, unsigned char *iv,
13 EVP_PKEY **pubk, int npubk); 13 EVP_PKEY **pubk, int npubk);
14 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, 14 int EVP_SealUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out,
15 int *outl, unsigned char *in, int inl); 15 int *outl, unsigned char *in, int inl);
16 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, 16 int EVP_SealFinal(EVP_CIPHER_CTX *ctx, unsigned char *out,
diff --git a/src/lib/libcrypto/doc/EVP_SignInit.pod b/src/lib/libcrypto/doc/EVP_SignInit.pod
index b6e62ce7f6..0bace24938 100644
--- a/src/lib/libcrypto/doc/EVP_SignInit.pod
+++ b/src/lib/libcrypto/doc/EVP_SignInit.pod
@@ -80,10 +80,10 @@ EVP_SignUpdate() could not be made after calling EVP_SignFinal().
80=head1 SEE ALSO 80=head1 SEE ALSO
81 81
82L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>, 82L<EVP_VerifyInit(3)|EVP_VerifyInit(3)>,
83L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<err(3)|err(3)>, 83L<EVP_DigestInit(3)|EVP_DigestInit(3)>, L<ERR_get_error(3)|ERR_get_error(3)>,
84L<evp(3)|evp(3)>, L<hmac(3)|hmac(3)>, L<md2(3)|md2(3)>, 84L<evp(3)|evp(3)>, L<HMAC(3)|HMAC(3)>, L<MD2(3)|MD2(3)>,
85L<md5(3)|md5(3)>, L<mdc2(3)|mdc2(3)>, L<ripemd(3)|ripemd(3)>, 85L<MD5(3)|MD5(3)>, L<MDC2(3)|MDC2(3)>, L<RIPEMD(3)|RIPEMD(3)>,
86L<sha(3)|sha(3)>, L<dgst(1)|dgst(1)> 86L<SHA1(3)|SHA1(3)>, L<digest(1)|digest(1)>
87 87
88=head1 HISTORY 88=head1 HISTORY
89 89
diff --git a/src/lib/libcrypto/doc/RAND_bytes.pod b/src/lib/libcrypto/doc/RAND_bytes.pod
index 1a9b91e281..ce6329ce54 100644
--- a/src/lib/libcrypto/doc/RAND_bytes.pod
+++ b/src/lib/libcrypto/doc/RAND_bytes.pod
@@ -25,9 +25,6 @@ unpredictable. They can be used for non-cryptographic purposes and for
25certain purposes in cryptographic protocols, but usually not for key 25certain purposes in cryptographic protocols, but usually not for key
26generation etc. 26generation etc.
27 27
28The contents of B<buf> is mixed into the entropy pool before retrieving
29the new pseudo-random bytes unless disabled at compile time (see FAQ).
30
31=head1 RETURN VALUES 28=head1 RETURN VALUES
32 29
33RAND_bytes() returns 1 on success, 0 otherwise. The error code can be 30RAND_bytes() returns 1 on success, 0 otherwise. The error code can be
diff --git a/src/lib/libcrypto/doc/RAND_set_rand_method.pod b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
index e5b780fad0..c9bb6d9f27 100644
--- a/src/lib/libcrypto/doc/RAND_set_rand_method.pod
+++ b/src/lib/libcrypto/doc/RAND_set_rand_method.pod
@@ -30,7 +30,7 @@ true only whilst no ENGINE has been set as a default for RAND, so this function
30is no longer recommended. 30is no longer recommended.
31 31
32RAND_get_default_method() returns a pointer to the current RAND_METHOD. 32RAND_get_default_method() returns a pointer to the current RAND_METHOD.
33However, the meaningfulness of this result is dependent on whether the ENGINE 33However, the meaningfulness of this result is dependant on whether the ENGINE
34API is being used, so this function is no longer recommended. 34API is being used, so this function is no longer recommended.
35 35
36=head1 THE RAND_METHOD STRUCTURE 36=head1 THE RAND_METHOD STRUCTURE
diff --git a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
index 7d0fd1f91d..46cc8f5359 100644
--- a/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
+++ b/src/lib/libcrypto/doc/RSA_get_ex_new_index.pod
@@ -17,12 +17,12 @@ RSA_get_ex_new_index, RSA_set_ex_data, RSA_get_ex_data - add application specifi
17 17
18 void *RSA_get_ex_data(RSA *r, int idx); 18 void *RSA_get_ex_data(RSA *r, int idx);
19 19
20 typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 20 typedef int new_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
21 int idx, long argl, void *argp); 21 int idx, long argl, void *argp);
22 typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad, 22 typedef void free_func(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
23 int idx, long argl, void *argp); 23 int idx, long argl, void *argp);
24 typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d, 24 typedef int dup_func(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
25 int idx, long argl, void *argp); 25 int idx, long argl, void *argp);
26 26
27=head1 DESCRIPTION 27=head1 DESCRIPTION
28 28
diff --git a/src/lib/libcrypto/doc/RSA_set_method.pod b/src/lib/libcrypto/doc/RSA_set_method.pod
index 2c963d7e5b..0a305f6b14 100644
--- a/src/lib/libcrypto/doc/RSA_set_method.pod
+++ b/src/lib/libcrypto/doc/RSA_set_method.pod
@@ -42,7 +42,7 @@ structures created later. B<NB>: This is true only whilst no ENGINE has
42been set as a default for RSA, so this function is no longer recommended. 42been set as a default for RSA, so this function is no longer recommended.
43 43
44RSA_get_default_method() returns a pointer to the current default 44RSA_get_default_method() returns a pointer to the current default
45RSA_METHOD. However, the meaningfulness of this result is dependent on 45RSA_METHOD. However, the meaningfulness of this result is dependant on
46whether the ENGINE API is being used, so this function is no longer 46whether the ENGINE API is being used, so this function is no longer
47recommended. 47recommended.
48 48
diff --git a/src/lib/libcrypto/doc/RSA_sign.pod b/src/lib/libcrypto/doc/RSA_sign.pod
index 8553be8e99..71688a665e 100644
--- a/src/lib/libcrypto/doc/RSA_sign.pod
+++ b/src/lib/libcrypto/doc/RSA_sign.pod
@@ -8,10 +8,10 @@ RSA_sign, RSA_verify - RSA signatures
8 8
9 #include <openssl/rsa.h> 9 #include <openssl/rsa.h>
10 10
11 int RSA_sign(int type, const unsigned char *m, unsigned int m_len, 11 int RSA_sign(int type, unsigned char *m, unsigned int m_len,
12 unsigned char *sigret, unsigned int *siglen, RSA *rsa); 12 unsigned char *sigret, unsigned int *siglen, RSA *rsa);
13 13
14 int RSA_verify(int type, const unsigned char *m, unsigned int m_len, 14 int RSA_verify(int type, unsigned char *m, unsigned int m_len,
15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa); 15 unsigned char *sigbuf, unsigned int siglen, RSA *rsa);
16 16
17=head1 DESCRIPTION 17=head1 DESCRIPTION
diff --git a/src/lib/libcrypto/doc/bn.pod b/src/lib/libcrypto/doc/bn.pod
index cd2f8e50c6..210dfeac08 100644
--- a/src/lib/libcrypto/doc/bn.pod
+++ b/src/lib/libcrypto/doc/bn.pod
@@ -27,9 +27,6 @@ bn - multiprecision integer arithmetics
27 int BN_num_bits(const BIGNUM *a); 27 int BN_num_bits(const BIGNUM *a);
28 int BN_num_bits_word(BN_ULONG w); 28 int BN_num_bits_word(BN_ULONG w);
29 29
30 void BN_set_negative(BIGNUM *a, int n);
31 int BN_is_negative(const BIGNUM *a);
32
33 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 30 int BN_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
34 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b); 31 int BN_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b);
35 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx); 32 int BN_mul(BIGNUM *r, BIGNUM *a, BIGNUM *b, BN_CTX *ctx);
@@ -121,25 +118,6 @@ bn - multiprecision integer arithmetics
121 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont, 118 int BN_to_montgomery(BIGNUM *r, BIGNUM *a, BN_MONT_CTX *mont,
122 BN_CTX *ctx); 119 BN_CTX *ctx);
123 120
124 BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai,
125 BIGNUM *mod);
126 void BN_BLINDING_free(BN_BLINDING *b);
127 int BN_BLINDING_update(BN_BLINDING *b,BN_CTX *ctx);
128 int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
129 int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
130 int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b,
131 BN_CTX *ctx);
132 int BN_BLINDING_invert_ex(BIGNUM *n,const BIGNUM *r,BN_BLINDING *b,
133 BN_CTX *ctx);
134 unsigned long BN_BLINDING_get_thread_id(const BN_BLINDING *);
135 void BN_BLINDING_set_thread_id(BN_BLINDING *, unsigned long);
136 unsigned long BN_BLINDING_get_flags(const BN_BLINDING *);
137 void BN_BLINDING_set_flags(BN_BLINDING *, unsigned long);
138 BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
139 const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
140 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
141 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx),
142 BN_MONT_CTX *m_ctx);
143 121
144=head1 DESCRIPTION 122=head1 DESCRIPTION
145 123
@@ -175,7 +153,6 @@ L<BN_cmp(3)|BN_cmp(3)>, L<BN_zero(3)|BN_zero(3)>, L<BN_rand(3)|BN_rand(3)>,
175L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>, 153L<BN_generate_prime(3)|BN_generate_prime(3)>, L<BN_set_bit(3)|BN_set_bit(3)>,
176L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>, 154L<BN_bn2bin(3)|BN_bn2bin(3)>, L<BN_mod_inverse(3)|BN_mod_inverse(3)>,
177L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>, 155L<BN_mod_mul_reciprocal(3)|BN_mod_mul_reciprocal(3)>,
178L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>, 156L<BN_mod_mul_montgomery(3)|BN_mod_mul_montgomery(3)>
179L<BN_BLINDING_new(3)|BN_BLINDING_new(3)>
180 157
181=cut 158=cut
diff --git a/src/lib/libcrypto/doc/dsa.pod b/src/lib/libcrypto/doc/dsa.pod
index da07d2b930..ae2e5d81f9 100644
--- a/src/lib/libcrypto/doc/dsa.pod
+++ b/src/lib/libcrypto/doc/dsa.pod
@@ -101,8 +101,7 @@ Standard, DSS), ANSI X9.30
101=head1 SEE ALSO 101=head1 SEE ALSO
102 102
103L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>, 103L<bn(3)|bn(3)>, L<dh(3)|dh(3)>, L<err(3)|err(3)>, L<rand(3)|rand(3)>,
104L<rsa(3)|rsa(3)>, L<sha(3)|sha(3)>, L<engine(3)|engine(3)>, 104L<rsa(3)|rsa(3)>, L<SHA1(3)|SHA1(3)>, L<DSA_new(3)|DSA_new(3)>,
105L<DSA_new(3)|DSA_new(3)>,
106L<DSA_size(3)|DSA_size(3)>, 105L<DSA_size(3)|DSA_size(3)>,
107L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>, 106L<DSA_generate_parameters(3)|DSA_generate_parameters(3)>,
108L<DSA_dup_DH(3)|DSA_dup_DH(3)>, 107L<DSA_dup_DH(3)|DSA_dup_DH(3)>,
diff --git a/src/lib/libcrypto/dsa/Makefile b/src/lib/libcrypto/dsa/Makefile
new file mode 100644
index 0000000000..676baf7d49
--- /dev/null
+++ b/src/lib/libcrypto/dsa/Makefile
@@ -0,0 +1,164 @@
1#
2# OpenSSL/crypto/dsa/Makefile
3#
4
5DIR= dsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=dsatest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \
21 dsa_err.c dsa_ossl.c dsa_depr.c
22LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \
23 dsa_err.o dsa_ossl.o dsa_depr.o
24
25SRC= $(LIBSRC)
26
27EXHEADER= dsa.h
28HEADER= $(EXHEADER)
29
30ALL= $(GENERAL) $(SRC) $(HEADER)
31
32top:
33 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
34
35all: lib
36
37lib: $(LIBOBJ)
38 $(AR) $(LIB) $(LIBOBJ)
39 $(RANLIB) $(LIB) || echo Never mind.
40 @touch lib
41
42files:
43 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
44
45links:
46 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
47 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
48 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
49
50install:
51 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
52 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
53 do \
54 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
55 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
56 done;
57
58tags:
59 ctags $(SRC)
60
61tests:
62
63lint:
64 lint -DLINT $(INCLUDES) $(SRC)>fluff
65
66depend:
67 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
68 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
69
70dclean:
71 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
72 mv -f Makefile.new $(MAKEFILE)
73
74clean:
75 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
76
77# DO NOT DELETE THIS LINE -- make depend depends on it.
78
79dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
80dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
81dsa_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
82dsa_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
83dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
84dsa_asn1.o: ../../include/openssl/opensslconf.h
85dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
86dsa_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87dsa_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_asn1.c
88dsa_depr.o: ../../e_os.h ../../include/openssl/asn1.h
89dsa_depr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
90dsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
91dsa_depr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
92dsa_depr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93dsa_depr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
94dsa_depr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
95dsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96dsa_depr.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
97dsa_depr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
98dsa_depr.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_depr.c
99dsa_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
100dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
101dsa_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
102dsa_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103dsa_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
104dsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
105dsa_err.o: dsa_err.c
106dsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h
107dsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
108dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
109dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
110dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
111dsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
112dsa_gen.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
113dsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114dsa_gen.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
115dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
116dsa_gen.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_gen.c
117dsa_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
118dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
119dsa_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
120dsa_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
121dsa_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
122dsa_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
123dsa_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
124dsa_key.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_key.c
125dsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
126dsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
127dsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
128dsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
129dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
130dsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
131dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132dsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
133dsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
134dsa_lib.o: ../cryptlib.h dsa_lib.c
135dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
136dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
137dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
138dsa_ossl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
139dsa_ossl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
140dsa_ossl.o: ../../include/openssl/opensslconf.h
141dsa_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
142dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
143dsa_ossl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
144dsa_ossl.o: ../cryptlib.h dsa_ossl.c
145dsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
146dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
147dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
148dsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
149dsa_sign.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
150dsa_sign.o: ../../include/openssl/opensslconf.h
151dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
152dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
153dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
154dsa_sign.o: ../cryptlib.h dsa_sign.c
155dsa_vrf.o: ../../e_os.h ../../include/openssl/asn1.h
156dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
157dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
158dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
159dsa_vrf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
160dsa_vrf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
161dsa_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
162dsa_vrf.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
163dsa_vrf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
164dsa_vrf.o: ../cryptlib.h dsa_vrf.c
diff --git a/src/lib/libcrypto/dsa/Makefile.ssl b/src/lib/libcrypto/dsa/Makefile.ssl
new file mode 100644
index 0000000000..e5f8a8cf51
--- /dev/null
+++ b/src/lib/libcrypto/dsa/Makefile.ssl
@@ -0,0 +1,171 @@
1#
2# SSLeay/crypto/dsa/Makefile
3#
4
5DIR= dsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=dsatest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= dsa_gen.c dsa_key.c dsa_lib.c dsa_asn1.c dsa_vrf.c dsa_sign.c \
27 dsa_err.c dsa_ossl.c
28LIBOBJ= dsa_gen.o dsa_key.o dsa_lib.o dsa_asn1.o dsa_vrf.o dsa_sign.o \
29 dsa_err.o dsa_ossl.o
30
31SRC= $(LIBSRC)
32
33EXHEADER= dsa.h
34HEADER= $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48files:
49 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
50
51links:
52 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
53 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
54 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
55 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
56
57install:
58 @for i in $(EXHEADER) ; \
59 do \
60 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done;
63
64tags:
65 ctags $(SRC)
66
67tests:
68
69lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff
71
72depend:
73 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
74
75dclean:
76 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
77 mv -f Makefile.new $(MAKEFILE)
78
79clean:
80 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
81
82# DO NOT DELETE THIS LINE -- make depend depends on it.
83
84dsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
85dsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
86dsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
87dsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
88dsa_asn1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
89dsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
90dsa_asn1.o: ../../include/openssl/opensslconf.h
91dsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
92dsa_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
93dsa_asn1.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_asn1.c
94dsa_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
95dsa_err.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
96dsa_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
97dsa_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
98dsa_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
99dsa_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
100dsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
101dsa_err.o: dsa_err.c
102dsa_gen.o: ../../e_os.h ../../include/openssl/aes.h
103dsa_gen.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
104dsa_gen.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
105dsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
106dsa_gen.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
107dsa_gen.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
108dsa_gen.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
109dsa_gen.o: ../../include/openssl/err.h ../../include/openssl/evp.h
110dsa_gen.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
111dsa_gen.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
112dsa_gen.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
113dsa_gen.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
114dsa_gen.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
115dsa_gen.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
116dsa_gen.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
117dsa_gen.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
118dsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119dsa_gen.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
120dsa_gen.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
121dsa_gen.o: ../../include/openssl/ui_compat.h ../cryptlib.h dsa_gen.c
122dsa_key.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
123dsa_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
124dsa_key.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
125dsa_key.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
126dsa_key.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
127dsa_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
128dsa_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
129dsa_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
130dsa_key.o: ../cryptlib.h dsa_key.c
131dsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
132dsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
133dsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
134dsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
135dsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
136dsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
137dsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
138dsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
139dsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
140dsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
141dsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h dsa_lib.c
142dsa_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
143dsa_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
144dsa_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
145dsa_ossl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
146dsa_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
147dsa_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
148dsa_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149dsa_ossl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
150dsa_ossl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
151dsa_ossl.o: ../cryptlib.h dsa_ossl.c
152dsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
153dsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
154dsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
155dsa_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
156dsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
157dsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
158dsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
159dsa_sign.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
160dsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
161dsa_sign.o: ../cryptlib.h dsa_sign.c
162dsa_vrf.o: ../../e_os.h ../../include/openssl/asn1.h
163dsa_vrf.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
164dsa_vrf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
165dsa_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
166dsa_vrf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
167dsa_vrf.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
168dsa_vrf.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
169dsa_vrf.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
170dsa_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
171dsa_vrf.o: ../../include/openssl/symhacks.h ../cryptlib.h dsa_vrf.c
diff --git a/src/lib/libcrypto/dsa/README b/src/lib/libcrypto/dsa/README
new file mode 100644
index 0000000000..6a7e9c170a
--- /dev/null
+++ b/src/lib/libcrypto/dsa/README
@@ -0,0 +1,4 @@
1The stuff in here is based on patches supplied to me by
2Steven Schoch <schoch@sheba.arc.nasa.gov> to do DSS.
3I have since modified a them a little but a debt of gratitude
4is due for doing the initial work.
diff --git a/src/lib/libcrypto/dsa/dsa.h b/src/lib/libcrypto/dsa/dsa.h
index 3a8fe5b56b..aa0669eb7a 100644
--- a/src/lib/libcrypto/dsa/dsa.h
+++ b/src/lib/libcrypto/dsa/dsa.h
@@ -65,8 +65,6 @@
65#ifndef HEADER_DSA_H 65#ifndef HEADER_DSA_H
66#define HEADER_DSA_H 66#define HEADER_DSA_H
67 67
68#include <openssl/e_os2.h>
69
70#ifdef OPENSSL_NO_DSA 68#ifdef OPENSSL_NO_DSA
71#error DSA is disabled. 69#error DSA is disabled.
72#endif 70#endif
@@ -74,19 +72,14 @@
74#ifndef OPENSSL_NO_BIO 72#ifndef OPENSSL_NO_BIO
75#include <openssl/bio.h> 73#include <openssl/bio.h>
76#endif 74#endif
75#include <openssl/bn.h>
77#include <openssl/crypto.h> 76#include <openssl/crypto.h>
78#include <openssl/ossl_typ.h> 77#include <openssl/ossl_typ.h>
79
80#ifndef OPENSSL_NO_DEPRECATED
81#include <openssl/bn.h>
82#ifndef OPENSSL_NO_DH 78#ifndef OPENSSL_NO_DH
83# include <openssl/dh.h> 79# include <openssl/dh.h>
84#endif 80#endif
85#endif
86 81
87#ifndef OPENSSL_DSA_MAX_MODULUS_BITS 82#define OPENSSL_DSA_MAX_MODULUS_BITS 3072
88# define OPENSSL_DSA_MAX_MODULUS_BITS 10000
89#endif
90 83
91#define DSA_FLAG_CACHE_MONT_P 0x01 84#define DSA_FLAG_CACHE_MONT_P 0x01
92#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA 85#define DSA_FLAG_NO_EXP_CONSTTIME 0x02 /* new with 0.9.7h; the built-in DSA
@@ -97,13 +90,22 @@
97 * be used for all exponents. 90 * be used for all exponents.
98 */ 91 */
99 92
93/* If this flag is set external DSA_METHOD callbacks are allowed in FIPS mode
94 * it is then the applications responsibility to ensure the external method
95 * is compliant.
96 */
97
98#define DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW 0x04
99
100#if defined(OPENSSL_FIPS)
101#define FIPS_DSA_SIZE_T int
102#endif
103
100#ifdef __cplusplus 104#ifdef __cplusplus
101extern "C" { 105extern "C" {
102#endif 106#endif
103 107
104/* Already defined in ossl_typ.h */ 108typedef struct dsa_st DSA;
105/* typedef struct dsa_st DSA; */
106/* typedef struct dsa_method DSA_METHOD; */
107 109
108typedef struct DSA_SIG_st 110typedef struct DSA_SIG_st
109 { 111 {
@@ -111,8 +113,7 @@ typedef struct DSA_SIG_st
111 BIGNUM *s; 113 BIGNUM *s;
112 } DSA_SIG; 114 } DSA_SIG;
113 115
114struct dsa_method 116typedef struct dsa_method {
115 {
116 const char *name; 117 const char *name;
117 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa); 118 DSA_SIG * (*dsa_do_sign)(const unsigned char *dgst, int dlen, DSA *dsa);
118 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, 119 int (*dsa_sign_setup)(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp,
@@ -129,14 +130,7 @@ struct dsa_method
129 int (*finish)(DSA *dsa); 130 int (*finish)(DSA *dsa);
130 int flags; 131 int flags;
131 char *app_data; 132 char *app_data;
132 /* If this is non-NULL, it is used to generate DSA parameters */ 133} DSA_METHOD;
133 int (*dsa_paramgen)(DSA *dsa, int bits,
134 unsigned char *seed, int seed_len,
135 int *counter_ret, unsigned long *h_ret,
136 BN_GENCB *cb);
137 /* If this is non-NULL, it is used to generate DSA keys */
138 int (*dsa_keygen)(DSA *dsa);
139 };
140 134
141struct dsa_st 135struct dsa_st
142 { 136 {
@@ -157,7 +151,7 @@ struct dsa_st
157 151
158 int flags; 152 int flags;
159 /* Normally used to cache montgomery values */ 153 /* Normally used to cache montgomery values */
160 BN_MONT_CTX *method_mont_p; 154 char *method_mont_p;
161 int references; 155 int references;
162 CRYPTO_EX_DATA ex_data; 156 CRYPTO_EX_DATA ex_data;
163 const DSA_METHOD *meth; 157 const DSA_METHOD *meth;
@@ -165,13 +159,16 @@ struct dsa_st
165 ENGINE *engine; 159 ENGINE *engine;
166 }; 160 };
167 161
168#define DSAparams_dup(x) ASN1_dup_of_const(DSA,i2d_DSAparams,d2i_DSAparams,x) 162#define DSAparams_dup(x) (DSA *)ASN1_dup((int (*)())i2d_DSAparams, \
163 (char *(*)())d2i_DSAparams,(char *)(x))
169#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \ 164#define d2i_DSAparams_fp(fp,x) (DSA *)ASN1_d2i_fp((char *(*)())DSA_new, \
170 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x)) 165 (char *(*)())d2i_DSAparams,(fp),(unsigned char **)(x))
171#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \ 166#define i2d_DSAparams_fp(fp,x) ASN1_i2d_fp(i2d_DSAparams,(fp), \
172 (unsigned char *)(x)) 167 (unsigned char *)(x))
173#define d2i_DSAparams_bio(bp,x) ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAparams,bp,x) 168#define d2i_DSAparams_bio(bp,x) (DSA *)ASN1_d2i_bio((char *(*)())DSA_new, \
174#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio_of_const(DSA,i2d_DSAparams,bp,x) 169 (char *(*)())d2i_DSAparams,(bp),(unsigned char **)(x))
170#define i2d_DSAparams_bio(bp,x) ASN1_i2d_bio(i2d_DSAparams,(bp), \
171 (unsigned char *)(x))
175 172
176 173
177DSA_SIG * DSA_SIG_new(void); 174DSA_SIG * DSA_SIG_new(void);
@@ -209,20 +206,10 @@ void *DSA_get_ex_data(DSA *d, int idx);
209DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length); 206DSA * d2i_DSAPublicKey(DSA **a, const unsigned char **pp, long length);
210DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length); 207DSA * d2i_DSAPrivateKey(DSA **a, const unsigned char **pp, long length);
211DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length); 208DSA * d2i_DSAparams(DSA **a, const unsigned char **pp, long length);
212
213/* Deprecated version */
214#ifndef OPENSSL_NO_DEPRECATED
215DSA * DSA_generate_parameters(int bits, 209DSA * DSA_generate_parameters(int bits,
216 unsigned char *seed,int seed_len, 210 unsigned char *seed,int seed_len,
217 int *counter_ret, unsigned long *h_ret,void 211 int *counter_ret, unsigned long *h_ret,void
218 (*callback)(int, int, void *),void *cb_arg); 212 (*callback)(int, int, void *),void *cb_arg);
219#endif /* !defined(OPENSSL_NO_DEPRECATED) */
220
221/* New version */
222int DSA_generate_parameters_ex(DSA *dsa, int bits,
223 unsigned char *seed,int seed_len,
224 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
225
226int DSA_generate_key(DSA *a); 213int DSA_generate_key(DSA *a);
227int i2d_DSAPublicKey(const DSA *a, unsigned char **pp); 214int i2d_DSAPublicKey(const DSA *a, unsigned char **pp);
228int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp); 215int i2d_DSAPrivateKey(const DSA *a, unsigned char **pp);
diff --git a/src/lib/libcrypto/dsa/dsa_err.c b/src/lib/libcrypto/dsa/dsa_err.c
index 768711994b..d7fac69154 100644
--- a/src/lib/libcrypto/dsa/dsa_err.c
+++ b/src/lib/libcrypto/dsa/dsa_err.c
@@ -100,12 +100,15 @@ static ERR_STRING_DATA DSA_str_reasons[]=
100 100
101void ERR_load_DSA_strings(void) 101void ERR_load_DSA_strings(void)
102 { 102 {
103#ifndef OPENSSL_NO_ERR 103 static int init=1;
104 104
105 if (ERR_func_error_string(DSA_str_functs[0].error) == NULL) 105 if (init)
106 { 106 {
107 init=0;
108#ifndef OPENSSL_NO_ERR
107 ERR_load_strings(0,DSA_str_functs); 109 ERR_load_strings(0,DSA_str_functs);
108 ERR_load_strings(0,DSA_str_reasons); 110 ERR_load_strings(0,DSA_str_reasons);
109 }
110#endif 111#endif
112
113 }
111 } 114 }
diff --git a/src/lib/libcrypto/dsa/dsa_gen.c b/src/lib/libcrypto/dsa/dsa_gen.c
index ca0b86a6cf..e40afeea51 100644
--- a/src/lib/libcrypto/dsa/dsa_gen.c
+++ b/src/lib/libcrypto/dsa/dsa_gen.c
@@ -69,8 +69,6 @@
69#define HASH EVP_sha1() 69#define HASH EVP_sha1()
70#endif 70#endif
71 71
72#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_SHA is defined */
73
74#ifndef OPENSSL_NO_SHA 72#ifndef OPENSSL_NO_SHA
75 73
76#include <stdio.h> 74#include <stdio.h>
@@ -82,24 +80,12 @@
82#include <openssl/rand.h> 80#include <openssl/rand.h>
83#include <openssl/sha.h> 81#include <openssl/sha.h>
84 82
85static int dsa_builtin_paramgen(DSA *ret, int bits, 83#ifndef OPENSSL_FIPS
86 unsigned char *seed_in, int seed_len, 84DSA *DSA_generate_parameters(int bits,
87 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb);
88
89int DSA_generate_parameters_ex(DSA *ret, int bits,
90 unsigned char *seed_in, int seed_len,
91 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb)
92 {
93 if(ret->meth->dsa_paramgen)
94 return ret->meth->dsa_paramgen(ret, bits, seed_in, seed_len,
95 counter_ret, h_ret, cb);
96 return dsa_builtin_paramgen(ret, bits, seed_in, seed_len,
97 counter_ret, h_ret, cb);
98 }
99
100static int dsa_builtin_paramgen(DSA *ret, int bits,
101 unsigned char *seed_in, int seed_len, 85 unsigned char *seed_in, int seed_len,
102 int *counter_ret, unsigned long *h_ret, BN_GENCB *cb) 86 int *counter_ret, unsigned long *h_ret,
87 void (*callback)(int, int, void *),
88 void *cb_arg)
103 { 89 {
104 int ok=0; 90 int ok=0;
105 unsigned char seed[SHA_DIGEST_LENGTH]; 91 unsigned char seed[SHA_DIGEST_LENGTH];
@@ -111,43 +97,40 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
111 int k,n=0,i,b,m=0; 97 int k,n=0,i,b,m=0;
112 int counter=0; 98 int counter=0;
113 int r=0; 99 int r=0;
114 BN_CTX *ctx=NULL; 100 BN_CTX *ctx=NULL,*ctx2=NULL,*ctx3=NULL;
115 unsigned int h=2; 101 unsigned int h=2;
102 DSA *ret=NULL;
116 103
117 if (bits < 512) bits=512; 104 if (bits < 512) bits=512;
118 bits=(bits+63)/64*64; 105 bits=(bits+63)/64*64;
119 106
120 /* NB: seed_len == 0 is special case: copy generated seed to 107 if (seed_len < 20)
121 * seed_in if it is not NULL.
122 */
123 if (seed_len && (seed_len < 20))
124 seed_in = NULL; /* seed buffer too small -- ignore */ 108 seed_in = NULL; /* seed buffer too small -- ignore */
125 if (seed_len > 20) 109 if (seed_len > 20)
126 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED, 110 seed_len = 20; /* App. 2.2 of FIPS PUB 186 allows larger SEED,
127 * but our internal buffers are restricted to 160 bits*/ 111 * but our internal buffers are restricted to 160 bits*/
128 if ((seed_in != NULL) && (seed_len == 20)) 112 if ((seed_in != NULL) && (seed_len == 20))
129 {
130 memcpy(seed,seed_in,seed_len); 113 memcpy(seed,seed_in,seed_len);
131 /* set seed_in to NULL to avoid it being copied back */
132 seed_in = NULL;
133 }
134 114
135 if ((ctx=BN_CTX_new()) == NULL) goto err; 115 if ((ctx=BN_CTX_new()) == NULL) goto err;
116 if ((ctx2=BN_CTX_new()) == NULL) goto err;
117 if ((ctx3=BN_CTX_new()) == NULL) goto err;
118 if ((ret=DSA_new()) == NULL) goto err;
136 119
137 if ((mont=BN_MONT_CTX_new()) == NULL) goto err; 120 if ((mont=BN_MONT_CTX_new()) == NULL) goto err;
138 121
139 BN_CTX_start(ctx); 122 BN_CTX_start(ctx2);
140 r0 = BN_CTX_get(ctx); 123 r0 = BN_CTX_get(ctx2);
141 g = BN_CTX_get(ctx); 124 g = BN_CTX_get(ctx2);
142 W = BN_CTX_get(ctx); 125 W = BN_CTX_get(ctx2);
143 q = BN_CTX_get(ctx); 126 q = BN_CTX_get(ctx2);
144 X = BN_CTX_get(ctx); 127 X = BN_CTX_get(ctx2);
145 c = BN_CTX_get(ctx); 128 c = BN_CTX_get(ctx2);
146 p = BN_CTX_get(ctx); 129 p = BN_CTX_get(ctx2);
147 test = BN_CTX_get(ctx); 130 test = BN_CTX_get(ctx2);
131 if (test == NULL) goto err;
148 132
149 if (!BN_lshift(test,BN_value_one(),bits-1)) 133 if (!BN_lshift(test,BN_value_one(),bits-1)) goto err;
150 goto err;
151 134
152 for (;;) 135 for (;;)
153 { 136 {
@@ -156,8 +139,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
156 int seed_is_random; 139 int seed_is_random;
157 140
158 /* step 1 */ 141 /* step 1 */
159 if(!BN_GENCB_call(cb, 0, m++)) 142 if (callback != NULL) callback(0,m++,cb_arg);
160 goto err;
161 143
162 if (!seed_len) 144 if (!seed_len)
163 { 145 {
@@ -190,8 +172,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
190 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err; 172 if (!BN_bin2bn(md,SHA_DIGEST_LENGTH,q)) goto err;
191 173
192 /* step 4 */ 174 /* step 4 */
193 r = BN_is_prime_fasttest_ex(q, DSS_prime_checks, ctx, 175 r = BN_is_prime_fasttest(q, DSS_prime_checks, callback, ctx3, cb_arg, seed_is_random);
194 seed_is_random, cb);
195 if (r > 0) 176 if (r > 0)
196 break; 177 break;
197 if (r != 0) 178 if (r != 0)
@@ -201,8 +182,8 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
201 /* step 5 */ 182 /* step 5 */
202 } 183 }
203 184
204 if(!BN_GENCB_call(cb, 2, 0)) goto err; 185 if (callback != NULL) callback(2,0,cb_arg);
205 if(!BN_GENCB_call(cb, 3, 0)) goto err; 186 if (callback != NULL) callback(3,0,cb_arg);
206 187
207 /* step 6 */ 188 /* step 6 */
208 counter=0; 189 counter=0;
@@ -213,11 +194,11 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
213 194
214 for (;;) 195 for (;;)
215 { 196 {
216 if ((counter != 0) && !BN_GENCB_call(cb, 0, counter)) 197 if (callback != NULL && counter != 0)
217 goto err; 198 callback(0,counter,cb_arg);
218 199
219 /* step 7 */ 200 /* step 7 */
220 BN_zero(W); 201 if (!BN_zero(W)) goto err;
221 /* now 'buf' contains "SEED + offset - 1" */ 202 /* now 'buf' contains "SEED + offset - 1" */
222 for (k=0; k<=n; k++) 203 for (k=0; k<=n; k++)
223 { 204 {
@@ -252,8 +233,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
252 if (BN_cmp(p,test) >= 0) 233 if (BN_cmp(p,test) >= 0)
253 { 234 {
254 /* step 11 */ 235 /* step 11 */
255 r = BN_is_prime_fasttest_ex(p, DSS_prime_checks, 236 r = BN_is_prime_fasttest(p, DSS_prime_checks, callback, ctx3, cb_arg, 1);
256 ctx, 1, cb);
257 if (r > 0) 237 if (r > 0)
258 goto end; /* found it */ 238 goto end; /* found it */
259 if (r != 0) 239 if (r != 0)
@@ -269,8 +249,7 @@ static int dsa_builtin_paramgen(DSA *ret, int bits,
269 } 249 }
270 } 250 }
271end: 251end:
272 if(!BN_GENCB_call(cb, 2, 1)) 252 if (callback != NULL) callback(2,1,cb_arg);
273 goto err;
274 253
275 /* We now need to generate g */ 254 /* We now need to generate g */
276 /* Set r0=(p-1)/q */ 255 /* Set r0=(p-1)/q */
@@ -289,16 +268,16 @@ end:
289 h++; 268 h++;
290 } 269 }
291 270
292 if(!BN_GENCB_call(cb, 3, 1)) 271 if (callback != NULL) callback(3,1,cb_arg);
293 goto err;
294 272
295 ok=1; 273 ok=1;
296err: 274err:
297 if (ok) 275 if (!ok)
276 {
277 if (ret != NULL) DSA_free(ret);
278 }
279 else
298 { 280 {
299 if(ret->p) BN_free(ret->p);
300 if(ret->q) BN_free(ret->q);
301 if(ret->g) BN_free(ret->g);
302 ret->p=BN_dup(p); 281 ret->p=BN_dup(p);
303 ret->q=BN_dup(q); 282 ret->q=BN_dup(q);
304 ret->g=BN_dup(g); 283 ret->g=BN_dup(g);
@@ -307,16 +286,20 @@ err:
307 ok=0; 286 ok=0;
308 goto err; 287 goto err;
309 } 288 }
310 if (seed_in != NULL) memcpy(seed_in,seed,20); 289 if ((m > 1) && (seed_in != NULL)) memcpy(seed_in,seed,20);
311 if (counter_ret != NULL) *counter_ret=counter; 290 if (counter_ret != NULL) *counter_ret=counter;
312 if (h_ret != NULL) *h_ret=h; 291 if (h_ret != NULL) *h_ret=h;
313 } 292 }
314 if(ctx) 293 if (ctx != NULL) BN_CTX_free(ctx);
294 if (ctx2 != NULL)
315 { 295 {
316 BN_CTX_end(ctx); 296 BN_CTX_end(ctx2);
317 BN_CTX_free(ctx); 297 BN_CTX_free(ctx2);
318 } 298 }
299 if (ctx3 != NULL) BN_CTX_free(ctx3);
319 if (mont != NULL) BN_MONT_CTX_free(mont); 300 if (mont != NULL) BN_MONT_CTX_free(mont);
320 return ok; 301 return(ok?ret:NULL);
321 } 302 }
322#endif 303#endif /* ndef OPENSSL_FIPS */
304#endif /* ndef OPENSSL_NO_SHA */
305
diff --git a/src/lib/libcrypto/dsa/dsa_key.c b/src/lib/libcrypto/dsa/dsa_key.c
index c4aa86bc6d..980b6dc2d3 100644
--- a/src/lib/libcrypto/dsa/dsa_key.c
+++ b/src/lib/libcrypto/dsa/dsa_key.c
@@ -56,25 +56,17 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_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#ifndef OPENSSL_NO_SHA
63#include <openssl/bn.h> 63#include <openssl/bn.h>
64#include <openssl/dsa.h> 64#include <openssl/dsa.h>
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66 66
67static int dsa_builtin_keygen(DSA *dsa); 67#ifndef OPENSSL_FIPS
68
69int DSA_generate_key(DSA *dsa) 68int DSA_generate_key(DSA *dsa)
70 { 69 {
71 if(dsa->meth->dsa_keygen)
72 return dsa->meth->dsa_keygen(dsa);
73 return dsa_builtin_keygen(dsa);
74 }
75
76static int dsa_builtin_keygen(DSA *dsa)
77 {
78 int ok=0; 70 int ok=0;
79 BN_CTX *ctx=NULL; 71 BN_CTX *ctx=NULL;
80 BIGNUM *pub_key=NULL,*priv_key=NULL; 72 BIGNUM *pub_key=NULL,*priv_key=NULL;
@@ -107,7 +99,7 @@ static int dsa_builtin_keygen(DSA *dsa)
107 { 99 {
108 BN_init(&local_prk); 100 BN_init(&local_prk);
109 prk = &local_prk; 101 prk = &local_prk;
110 BN_with_flags(prk, priv_key, BN_FLG_CONSTTIME); 102 BN_with_flags(prk, priv_key, BN_FLG_EXP_CONSTTIME);
111 } 103 }
112 else 104 else
113 prk = priv_key; 105 prk = priv_key;
@@ -126,3 +118,4 @@ err:
126 return(ok); 118 return(ok);
127 } 119 }
128#endif 120#endif
121#endif
diff --git a/src/lib/libcrypto/dsa/dsa_lib.c b/src/lib/libcrypto/dsa/dsa_lib.c
index e9b75902db..4171af24c6 100644
--- a/src/lib/libcrypto/dsa/dsa_lib.c
+++ b/src/lib/libcrypto/dsa/dsa_lib.c
@@ -66,11 +66,8 @@
66#ifndef OPENSSL_NO_ENGINE 66#ifndef OPENSSL_NO_ENGINE
67#include <openssl/engine.h> 67#include <openssl/engine.h>
68#endif 68#endif
69#ifndef OPENSSL_NO_DH
70#include <openssl/dh.h>
71#endif
72 69
73const char DSA_version[]="DSA" OPENSSL_VERSION_PTEXT; 70const char *DSA_version="DSA" OPENSSL_VERSION_PTEXT;
74 71
75static const DSA_METHOD *default_DSA_method = NULL; 72static const DSA_METHOD *default_DSA_method = NULL;
76 73
diff --git a/src/lib/libcrypto/dsa/dsa_ossl.c b/src/lib/libcrypto/dsa/dsa_ossl.c
index 75ff7cc4af..5de5fc7e91 100644
--- a/src/lib/libcrypto/dsa/dsa_ossl.c
+++ b/src/lib/libcrypto/dsa/dsa_ossl.c
@@ -65,63 +65,33 @@
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67 67
68#ifndef OPENSSL_FIPS
68static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa); 69static DSA_SIG *dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
69static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp); 70static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp);
70static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 71static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
71 DSA *dsa); 72 DSA *dsa);
72static int dsa_init(DSA *dsa); 73static int dsa_init(DSA *dsa);
73static int dsa_finish(DSA *dsa); 74static int dsa_finish(DSA *dsa);
75static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
76 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
77 BN_MONT_CTX *in_mont);
78static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
79 const BIGNUM *m, BN_CTX *ctx,
80 BN_MONT_CTX *m_ctx);
74 81
75static DSA_METHOD openssl_dsa_meth = { 82static DSA_METHOD openssl_dsa_meth = {
76"OpenSSL DSA method", 83"OpenSSL DSA method",
77dsa_do_sign, 84dsa_do_sign,
78dsa_sign_setup, 85dsa_sign_setup,
79dsa_do_verify, 86dsa_do_verify,
80NULL, /* dsa_mod_exp, */ 87dsa_mod_exp,
81NULL, /* dsa_bn_mod_exp, */ 88dsa_bn_mod_exp,
82dsa_init, 89dsa_init,
83dsa_finish, 90dsa_finish,
840, 910,
85NULL,
86NULL,
87NULL 92NULL
88}; 93};
89 94
90/* These macro wrappers replace attempts to use the dsa_mod_exp() and
91 * bn_mod_exp() handlers in the DSA_METHOD structure. We avoid the problem of
92 * having a the macro work as an expression by bundling an "err_instr". So;
93 *
94 * if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,&k,dsa->p,ctx,
95 * dsa->method_mont_p)) goto err;
96 *
97 * can be replaced by;
98 *
99 * DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, &k, dsa->p, ctx,
100 * dsa->method_mont_p);
101 */
102
103#define DSA_MOD_EXP(err_instr,dsa,rr,a1,p1,a2,p2,m,ctx,in_mont) \
104 do { \
105 int _tmp_res53; \
106 if((dsa)->meth->dsa_mod_exp) \
107 _tmp_res53 = (dsa)->meth->dsa_mod_exp((dsa), (rr), (a1), (p1), \
108 (a2), (p2), (m), (ctx), (in_mont)); \
109 else \
110 _tmp_res53 = BN_mod_exp2_mont((rr), (a1), (p1), (a2), (p2), \
111 (m), (ctx), (in_mont)); \
112 if(!_tmp_res53) err_instr; \
113 } while(0)
114#define DSA_BN_MOD_EXP(err_instr,dsa,r,a,p,m,ctx,m_ctx) \
115 do { \
116 int _tmp_res53; \
117 if((dsa)->meth->bn_mod_exp) \
118 _tmp_res53 = (dsa)->meth->bn_mod_exp((dsa), (r), (a), (p), \
119 (m), (ctx), (m_ctx)); \
120 else \
121 _tmp_res53 = BN_mod_exp_mont((r), (a), (p), (m), (ctx), (m_ctx)); \
122 if(!_tmp_res53) err_instr; \
123 } while(0)
124
125const DSA_METHOD *DSA_OpenSSL(void) 95const DSA_METHOD *DSA_OpenSSL(void)
126{ 96{
127 return &openssl_dsa_meth; 97 return &openssl_dsa_meth;
@@ -229,12 +199,12 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
229 while (BN_is_zero(&k)); 199 while (BN_is_zero(&k));
230 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0) 200 if ((dsa->flags & DSA_FLAG_NO_EXP_CONSTTIME) == 0)
231 { 201 {
232 BN_set_flags(&k, BN_FLG_CONSTTIME); 202 BN_set_flags(&k, BN_FLG_EXP_CONSTTIME);
233 } 203 }
234 204
235 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) 205 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
236 { 206 {
237 if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p, 207 if (!BN_MONT_CTX_set_locked((BN_MONT_CTX **)&dsa->method_mont_p,
238 CRYPTO_LOCK_DSA, 208 CRYPTO_LOCK_DSA,
239 dsa->p, ctx)) 209 dsa->p, ctx))
240 goto err; 210 goto err;
@@ -264,8 +234,8 @@ static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
264 { 234 {
265 K = &k; 235 K = &k;
266 } 236 }
267 DSA_BN_MOD_EXP(goto err, dsa, r, dsa->g, K, dsa->p, ctx, 237 if (!dsa->meth->bn_mod_exp(dsa, r,dsa->g,K,dsa->p,ctx,
268 dsa->method_mont_p); 238 (BN_MONT_CTX *)dsa->method_mont_p)) goto err;
269 if (!BN_mod(r,r,dsa->q,ctx)) goto err; 239 if (!BN_mod(r,r,dsa->q,ctx)) goto err;
270 240
271 /* Compute part of 's = inv(k) (m + xr) mod q' */ 241 /* Compute part of 's = inv(k) (m + xr) mod q' */
@@ -322,14 +292,12 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
322 292
323 if ((ctx=BN_CTX_new()) == NULL) goto err; 293 if ((ctx=BN_CTX_new()) == NULL) goto err;
324 294
325 if (BN_is_zero(sig->r) || BN_is_negative(sig->r) || 295 if (BN_is_zero(sig->r) || sig->r->neg || BN_ucmp(sig->r, dsa->q) >= 0)
326 BN_ucmp(sig->r, dsa->q) >= 0)
327 { 296 {
328 ret = 0; 297 ret = 0;
329 goto err; 298 goto err;
330 } 299 }
331 if (BN_is_zero(sig->s) || BN_is_negative(sig->s) || 300 if (BN_is_zero(sig->s) || sig->s->neg || BN_ucmp(sig->s, dsa->q) >= 0)
332 BN_ucmp(sig->s, dsa->q) >= 0)
333 { 301 {
334 ret = 0; 302 ret = 0;
335 goto err; 303 goto err;
@@ -351,25 +319,43 @@ static int dsa_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
351 319
352 if (dsa->flags & DSA_FLAG_CACHE_MONT_P) 320 if (dsa->flags & DSA_FLAG_CACHE_MONT_P)
353 { 321 {
354 mont = BN_MONT_CTX_set_locked(&dsa->method_mont_p, 322 mont = BN_MONT_CTX_set_locked(
323 (BN_MONT_CTX **)&dsa->method_mont_p,
355 CRYPTO_LOCK_DSA, dsa->p, ctx); 324 CRYPTO_LOCK_DSA, dsa->p, ctx);
356 if (!mont) 325 if (!mont)
357 goto err; 326 goto err;
358 } 327 }
359 328
360 329#if 0
361 DSA_MOD_EXP(goto err, dsa, &t1, dsa->g, &u1, dsa->pub_key, &u2, dsa->p, ctx, mont); 330 {
331 BIGNUM t2;
332
333 BN_init(&t2);
334 /* v = ( g^u1 * y^u2 mod p ) mod q */
335 /* let t1 = g ^ u1 mod p */
336 if (!BN_mod_exp_mont(&t1,dsa->g,&u1,dsa->p,ctx,mont)) goto err;
337 /* let t2 = y ^ u2 mod p */
338 if (!BN_mod_exp_mont(&t2,dsa->pub_key,&u2,dsa->p,ctx,mont)) goto err;
339 /* let u1 = t1 * t2 mod p */
340 if (!BN_mod_mul(&u1,&t1,&t2,dsa->p,ctx)) goto err_bn;
341 BN_free(&t2);
342 }
343 /* let u1 = u1 mod q */
344 if (!BN_mod(&u1,&u1,dsa->q,ctx)) goto err;
345#else
346 {
347 if (!dsa->meth->dsa_mod_exp(dsa, &t1,dsa->g,&u1,dsa->pub_key,&u2,
348 dsa->p,ctx,mont)) goto err;
362 /* BN_copy(&u1,&t1); */ 349 /* BN_copy(&u1,&t1); */
363 /* let u1 = u1 mod q */ 350 /* let u1 = u1 mod q */
364 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err; 351 if (!BN_mod(&u1,&t1,dsa->q,ctx)) goto err;
365 352 }
353#endif
366 /* V is now in u1. If the signature is correct, it will be 354 /* V is now in u1. If the signature is correct, it will be
367 * equal to R. */ 355 * equal to R. */
368 ret=(BN_ucmp(&u1, sig->r) == 0); 356 ret=(BN_ucmp(&u1, sig->r) == 0);
369 357
370 err: 358 err:
371 /* XXX: surely this is wrong - if ret is 0, it just didn't verify;
372 there is no error in BN. Test should be ret == -1 (Ben) */
373 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB); 359 if (ret != 1) DSAerr(DSA_F_DSA_DO_VERIFY,ERR_R_BN_LIB);
374 if (ctx != NULL) BN_CTX_free(ctx); 360 if (ctx != NULL) BN_CTX_free(ctx);
375 BN_free(&u1); 361 BN_free(&u1);
@@ -387,7 +373,21 @@ static int dsa_init(DSA *dsa)
387static int dsa_finish(DSA *dsa) 373static int dsa_finish(DSA *dsa)
388{ 374{
389 if(dsa->method_mont_p) 375 if(dsa->method_mont_p)
390 BN_MONT_CTX_free(dsa->method_mont_p); 376 BN_MONT_CTX_free((BN_MONT_CTX *)dsa->method_mont_p);
391 return(1); 377 return(1);
392} 378}
393 379
380static int dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1, BIGNUM *p1,
381 BIGNUM *a2, BIGNUM *p2, BIGNUM *m, BN_CTX *ctx,
382 BN_MONT_CTX *in_mont)
383{
384 return BN_mod_exp2_mont(rr, a1, p1, a2, p2, m, ctx, in_mont);
385}
386
387static int dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
388 const BIGNUM *m, BN_CTX *ctx,
389 BN_MONT_CTX *m_ctx)
390{
391 return BN_mod_exp_mont(r, a, p, m, ctx, m_ctx);
392}
393#endif
diff --git a/src/lib/libcrypto/dsa/dsa_sign.c b/src/lib/libcrypto/dsa/dsa_sign.c
index 89205026f0..37c65efb20 100644
--- a/src/lib/libcrypto/dsa/dsa_sign.c
+++ b/src/lib/libcrypto/dsa/dsa_sign.c
@@ -64,9 +64,18 @@
64#include <openssl/dsa.h> 64#include <openssl/dsa.h>
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67#ifndef OPENSSL_NO_ENGINE
68#include <openssl/engine.h>
69#endif
70#include <openssl/fips.h>
67 71
68DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa) 72DSA_SIG * DSA_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
69 { 73 {
74#ifdef OPENSSL_FIPS
75 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
76 && !FIPS_dsa_check(dsa))
77 return NULL;
78#endif
70 return dsa->meth->dsa_do_sign(dgst, dlen, dsa); 79 return dsa->meth->dsa_do_sign(dgst, dlen, dsa);
71 } 80 }
72 81
@@ -87,6 +96,11 @@ int DSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
87 96
88int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) 97int DSA_sign_setup(DSA *dsa, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
89 { 98 {
99#ifdef OPENSSL_FIPS
100 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
101 && !FIPS_dsa_check(dsa))
102 return 0;
103#endif
90 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp); 104 return dsa->meth->dsa_sign_setup(dsa, ctx_in, kinvp, rp);
91 } 105 }
92 106
diff --git a/src/lib/libcrypto/dsa/dsa_vrf.c b/src/lib/libcrypto/dsa/dsa_vrf.c
index c4aeddd056..c9784bed48 100644
--- a/src/lib/libcrypto/dsa/dsa_vrf.c
+++ b/src/lib/libcrypto/dsa/dsa_vrf.c
@@ -65,10 +65,19 @@
65#include <openssl/rand.h> 65#include <openssl/rand.h>
66#include <openssl/asn1.h> 66#include <openssl/asn1.h>
67#include <openssl/asn1_mac.h> 67#include <openssl/asn1_mac.h>
68#ifndef OPENSSL_NO_ENGINE
69#include <openssl/engine.h>
70#endif
71#include <openssl/fips.h>
68 72
69int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig, 73int DSA_do_verify(const unsigned char *dgst, int dgst_len, DSA_SIG *sig,
70 DSA *dsa) 74 DSA *dsa)
71 { 75 {
76#ifdef OPENSSL_FIPS
77 if(FIPS_mode() && !(dsa->flags & DSA_FLAG_FIPS_EXTERNAL_METHOD_ALLOW)
78 && !FIPS_dsa_check(dsa))
79 return -1;
80#endif
72 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa); 81 return dsa->meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
73 } 82 }
74 83
diff --git a/src/lib/libcrypto/dsa/dsagen.c b/src/lib/libcrypto/dsa/dsagen.c
new file mode 100644
index 0000000000..1b6a1cca0f
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsagen.c
@@ -0,0 +1,111 @@
1/* crypto/dsa/dsagen.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <openssl/dsa.h>
61
62#define TEST
63#define GENUINE_DSA
64
65#ifdef GENUINE_DSA
66#define LAST_VALUE 0xbd
67#else
68#define LAST_VALUE 0xd3
69#endif
70
71#ifdef TEST
72unsigned char seed[20]={
73 0xd5,0x01,0x4e,0x4b,
74 0x60,0xef,0x2b,0xa8,
75 0xb6,0x21,0x1b,0x40,
76 0x62,0xba,0x32,0x24,
77 0xe0,0x42,0x7d,LAST_VALUE};
78#endif
79
80int cb(int p, int n)
81 {
82 char c='*';
83
84 if (p == 0) c='.';
85 if (p == 1) c='+';
86 if (p == 2) c='*';
87 if (p == 3) c='\n';
88 printf("%c",c);
89 fflush(stdout);
90 }
91
92main()
93 {
94 int i;
95 BIGNUM *n;
96 BN_CTX *ctx;
97 unsigned char seed_buf[20];
98 DSA *dsa;
99 int counter,h;
100 BIO *bio_err=NULL;
101
102 if (bio_err == NULL)
103 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
104
105 memcpy(seed_buf,seed,20);
106 dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb,bio_err);
107
108 if (dsa == NULL)
109 DSA_print(bio_err,dsa,0);
110 }
111
diff --git a/src/lib/libcrypto/dsa/dsatest.c b/src/lib/libcrypto/dsa/dsatest.c
new file mode 100644
index 0000000000..55a3756aff
--- /dev/null
+++ b/src/lib/libcrypto/dsa/dsatest.c
@@ -0,0 +1,251 @@
1/* crypto/dsa/dsatest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <sys/types.h>
63#include <sys/stat.h>
64
65#include "../e_os.h"
66
67#include <openssl/crypto.h>
68#include <openssl/rand.h>
69#include <openssl/bio.h>
70#include <openssl/err.h>
71
72#ifdef OPENSSL_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
81#ifdef OPENSSL_SYS_WIN16
82#define MS_CALLBACK _far _loadds
83#else
84#define MS_CALLBACK
85#endif
86
87static void MS_CALLBACK dsa_cb(int p, int n, void *arg);
88
89/* seed, out_p, out_q, out_g are taken from the updated Appendix 5 to
90 * FIPS PUB 186 and also appear in Appendix 5 to FIPS PIB 186-1 */
91static unsigned char seed[20]={
92 0xd5,0x01,0x4e,0x4b,0x60,0xef,0x2b,0xa8,0xb6,0x21,0x1b,0x40,
93 0x62,0xba,0x32,0x24,0xe0,0x42,0x7d,0xd3,
94 };
95
96static unsigned char out_p[]={
97 0x8d,0xf2,0xa4,0x94,0x49,0x22,0x76,0xaa,
98 0x3d,0x25,0x75,0x9b,0xb0,0x68,0x69,0xcb,
99 0xea,0xc0,0xd8,0x3a,0xfb,0x8d,0x0c,0xf7,
100 0xcb,0xb8,0x32,0x4f,0x0d,0x78,0x82,0xe5,
101 0xd0,0x76,0x2f,0xc5,0xb7,0x21,0x0e,0xaf,
102 0xc2,0xe9,0xad,0xac,0x32,0xab,0x7a,0xac,
103 0x49,0x69,0x3d,0xfb,0xf8,0x37,0x24,0xc2,
104 0xec,0x07,0x36,0xee,0x31,0xc8,0x02,0x91,
105 };
106
107static unsigned char out_q[]={
108 0xc7,0x73,0x21,0x8c,0x73,0x7e,0xc8,0xee,
109 0x99,0x3b,0x4f,0x2d,0xed,0x30,0xf4,0x8e,
110 0xda,0xce,0x91,0x5f,
111 };
112
113static unsigned char out_g[]={
114 0x62,0x6d,0x02,0x78,0x39,0xea,0x0a,0x13,
115 0x41,0x31,0x63,0xa5,0x5b,0x4c,0xb5,0x00,
116 0x29,0x9d,0x55,0x22,0x95,0x6c,0xef,0xcb,
117 0x3b,0xff,0x10,0xf3,0x99,0xce,0x2c,0x2e,
118 0x71,0xcb,0x9d,0xe5,0xfa,0x24,0xba,0xbf,
119 0x58,0xe5,0xb7,0x95,0x21,0x92,0x5c,0x9c,
120 0xc4,0x2e,0x9f,0x6f,0x46,0x4b,0x08,0x8c,
121 0xc5,0x72,0xaf,0x53,0xe6,0xd7,0x88,0x02,
122 };
123
124static const unsigned char str1[]="12345678901234567890";
125
126static const char rnd_seed[] = "string to make the random number generator think it has entropy";
127
128static BIO *bio_err=NULL;
129
130int main(int argc, char **argv)
131 {
132 DSA *dsa=NULL;
133 int counter,ret=0,i,j;
134 unsigned char buf[256];
135 unsigned long h;
136 unsigned char sig[256];
137 unsigned int siglen;
138
139 if (bio_err == NULL)
140 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
141
142 CRYPTO_malloc_debug_init();
143 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
144 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
145
146 ERR_load_crypto_strings();
147 RAND_seed(rnd_seed, sizeof rnd_seed);
148
149 BIO_printf(bio_err,"test generation of DSA parameters\n");
150
151 dsa=DSA_generate_parameters(512,seed,20,&counter,&h,dsa_cb,bio_err);
152
153 BIO_printf(bio_err,"seed\n");
154 for (i=0; i<20; i+=4)
155 {
156 BIO_printf(bio_err,"%02X%02X%02X%02X ",
157 seed[i],seed[i+1],seed[i+2],seed[i+3]);
158 }
159 BIO_printf(bio_err,"\ncounter=%d h=%d\n",counter,h);
160
161 if (dsa == NULL) goto end;
162 DSA_print(bio_err,dsa,0);
163 if (counter != 105)
164 {
165 BIO_printf(bio_err,"counter should be 105\n");
166 goto end;
167 }
168 if (h != 2)
169 {
170 BIO_printf(bio_err,"h should be 2\n");
171 goto end;
172 }
173
174 i=BN_bn2bin(dsa->q,buf);
175 j=sizeof(out_q);
176 if ((i != j) || (memcmp(buf,out_q,i) != 0))
177 {
178 BIO_printf(bio_err,"q value is wrong\n");
179 goto end;
180 }
181
182 i=BN_bn2bin(dsa->p,buf);
183 j=sizeof(out_p);
184 if ((i != j) || (memcmp(buf,out_p,i) != 0))
185 {
186 BIO_printf(bio_err,"p value is wrong\n");
187 goto end;
188 }
189
190 i=BN_bn2bin(dsa->g,buf);
191 j=sizeof(out_g);
192 if ((i != j) || (memcmp(buf,out_g,i) != 0))
193 {
194 BIO_printf(bio_err,"g value is wrong\n");
195 goto end;
196 }
197
198 dsa->flags |= DSA_FLAG_NO_EXP_CONSTTIME;
199 DSA_generate_key(dsa);
200 DSA_sign(0, str1, 20, sig, &siglen, dsa);
201 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
202 ret=1;
203
204 dsa->flags &= ~DSA_FLAG_NO_EXP_CONSTTIME;
205 DSA_generate_key(dsa);
206 DSA_sign(0, str1, 20, sig, &siglen, dsa);
207 if (DSA_verify(0, str1, 20, sig, siglen, dsa) == 1)
208 ret=1;
209
210end:
211 if (!ret)
212 ERR_print_errors(bio_err);
213 if (dsa != NULL) DSA_free(dsa);
214 CRYPTO_cleanup_all_ex_data();
215 ERR_remove_state(0);
216 ERR_free_strings();
217 CRYPTO_mem_leaks(bio_err);
218 if (bio_err != NULL)
219 {
220 BIO_free(bio_err);
221 bio_err = NULL;
222 }
223 EXIT(!ret);
224 return(0);
225 }
226
227static int cb_exit(int ec)
228 {
229 EXIT(ec);
230 return(0); /* To keep some compilers quiet */
231 }
232
233static void MS_CALLBACK dsa_cb(int p, int n, void *arg)
234 {
235 char c='*';
236 static int ok=0,num=0;
237
238 if (p == 0) { c='.'; num++; };
239 if (p == 1) c='+';
240 if (p == 2) { c='*'; ok++; }
241 if (p == 3) c='\n';
242 BIO_write(arg,&c,1);
243 (void)BIO_flush(arg);
244
245 if (!ok && (p == 0) && (num > 1))
246 {
247 BIO_printf((BIO *)arg,"error in dsatest\n");
248 cb_exit(1);
249 }
250 }
251#endif
diff --git a/src/lib/libcrypto/dsa/fips186a.txt b/src/lib/libcrypto/dsa/fips186a.txt
new file mode 100644
index 0000000000..3a2e0a0d51
--- /dev/null
+++ b/src/lib/libcrypto/dsa/fips186a.txt
@@ -0,0 +1,122 @@
1The origional FIPE 180 used SHA-0 (FIPS 180) for its appendix 5
2examples. This is an updated version that uses SHA-1 (FIPS 180-1)
3supplied to me by Wei Dai
4--
5 APPENDIX 5. EXAMPLE OF THE DSA
6
7
8This appendix is for informational purposes only and is not required to meet
9the standard.
10
11Let L = 512 (size of p). The values in this example are expressed in
12hexadecimal notation. The p and q given here were generated by the prime
13generation standard described in appendix 2 using the 160-bit SEED:
14
15 d5014e4b 60ef2ba8 b6211b40 62ba3224 e0427dd3
16
17With this SEED, the algorithm found p and q when the counter was at 105.
18
19x was generated by the algorithm described in appendix 3, section 3.1, using
20the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit XSEED:
21
22XSEED =
23
24 bd029bbe 7f51960b cf9edb2b 61f06f0f eb5a38b6
25
26t =
27 67452301 EFCDAB89 98BADCFE 10325476 C3D2E1F0
28
29x = G(t,XSEED) mod q
30
31k was generated by the algorithm described in appendix 3, section 3.2, using
32the SHA to construct G (as in appendix 3, section 3.3) and a 160-bit KSEED:
33
34KSEED =
35
36 687a66d9 0648f993 867e121f 4ddf9ddb 01205584
37
38t =
39 EFCDAB89 98BADCFE 10325476 C3D2E1F0 67452301
40
41k = G(t,KSEED) mod q
42
43Finally:
44
45h = 2
46
47p =
48 8df2a494 492276aa 3d25759b b06869cb eac0d83a fb8d0cf7
49 cbb8324f 0d7882e5 d0762fc5 b7210eaf c2e9adac 32ab7aac
50 49693dfb f83724c2 ec0736ee 31c80291
51
52
53q =
54 c773218c 737ec8ee 993b4f2d ed30f48e dace915f
55
56
57g =
58 626d0278 39ea0a13 413163a5 5b4cb500 299d5522 956cefcb
59 3bff10f3 99ce2c2e 71cb9de5 fa24babf 58e5b795 21925c9c
60 c42e9f6f 464b088c c572af53 e6d78802
61
62
63x =
64 2070b322 3dba372f de1c0ffc 7b2e3b49 8b260614
65
66
67k =
68 358dad57 1462710f 50e254cf 1a376b2b deaadfbf
69
70
71kinv =
72
73 0d516729 8202e49b 4116ac10 4fc3f415 ae52f917
74
75M = ASCII form of "abc" (See FIPS PUB 180-1, Appendix A)
76
77SHA(M) =
78
79 a9993e36 4706816a ba3e2571 7850c26c 9cd0d89d
80
81
82y =
83
84 19131871 d75b1612 a819f29d 78d1b0d7 346f7aa7 7bb62a85
85 9bfd6c56 75da9d21 2d3a36ef 1672ef66 0b8c7c25 5cc0ec74
86 858fba33 f44c0669 9630a76b 030ee333
87
88
89r =
90 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
91
92s =
93 41e2345f 1f56df24 58f426d1 55b4ba2d b6dcd8c8
94
95
96w =
97 9df4ece5 826be95f ed406d41 b43edc0b 1c18841b
98
99
100u1 =
101 bf655bd0 46f0b35e c791b004 804afcbb 8ef7d69d
102
103
104u2 =
105 821a9263 12e97ade abcc8d08 2b527897 8a2df4b0
106
107
108gu1 mod p =
109
110 51b1bf86 7888e5f3 af6fb476 9dd016bc fe667a65 aafc2753
111 9063bd3d 2b138b4c e02cc0c0 2ec62bb6 7306c63e 4db95bbf
112 6f96662a 1987a21b e4ec1071 010b6069
113
114
115yu2 mod p =
116
117 8b510071 2957e950 50d6b8fd 376a668e 4b0d633c 1e46e665
118 5c611a72 e2b28483 be52c74d 4b30de61 a668966e dc307a67
119 c19441f4 22bf3c34 08aeba1f 0a4dbec7
120
121v =
122 8bac1ab6 6410435c b7181f95 b16ab97c 92b341c0
diff --git a/src/lib/libcrypto/dso/Makefile b/src/lib/libcrypto/dso/Makefile
new file mode 100644
index 0000000000..07f5d8d159
--- /dev/null
+++ b/src/lib/libcrypto/dso/Makefile
@@ -0,0 +1,142 @@
1#
2# OpenSSL/crypto/dso/Makefile
3#
4
5DIR= dso
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= dso_dl.c dso_dlfcn.c dso_err.c dso_lib.c dso_null.c \
21 dso_openssl.c dso_win32.c dso_vms.c
22LIBOBJ= dso_dl.o dso_dlfcn.o dso_err.o dso_lib.o dso_null.o \
23 dso_openssl.o dso_win32.o dso_vms.o
24
25SRC= $(LIBSRC)
26
27EXHEADER= dso.h
28HEADER= $(EXHEADER)
29
30ALL= $(GENERAL) $(SRC) $(HEADER)
31
32top:
33 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
34
35all: lib
36
37lib: $(LIBOBJ)
38 $(AR) $(LIB) $(LIBOBJ)
39 $(RANLIB) $(LIB) || echo Never mind.
40 @touch lib
41
42files:
43 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
44
45links:
46 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
47 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
48 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
49
50install:
51 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
52 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
53 do \
54 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
55 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
56 done;
57
58tags:
59 ctags $(SRC)
60
61tests:
62
63lint:
64 lint -DLINT $(INCLUDES) $(SRC)>fluff
65
66depend:
67 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
68 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
69
70dclean:
71 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
72 mv -f Makefile.new $(MAKEFILE)
73
74clean:
75 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
76
77# DO NOT DELETE THIS LINE -- make depend depends on it.
78
79dso_dl.o: ../../e_os.h ../../include/openssl/bio.h
80dso_dl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
81dso_dl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
82dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
83dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
84dso_dl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
85dso_dl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
86dso_dl.o: ../cryptlib.h dso_dl.c
87dso_dlfcn.o: ../../e_os.h ../../include/openssl/bio.h
88dso_dlfcn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89dso_dlfcn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
90dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
91dso_dlfcn.o: ../../include/openssl/opensslconf.h
92dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93dso_dlfcn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
94dso_dlfcn.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_dlfcn.c
95dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
96dso_err.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
97dso_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
98dso_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
99dso_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
100dso_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
101dso_err.o: dso_err.c
102dso_lib.o: ../../e_os.h ../../include/openssl/bio.h
103dso_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
104dso_lib.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
105dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
106dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
107dso_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
108dso_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
109dso_lib.o: ../cryptlib.h dso_lib.c
110dso_null.o: ../../e_os.h ../../include/openssl/bio.h
111dso_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
112dso_null.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
113dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
114dso_null.o: ../../include/openssl/opensslconf.h
115dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
116dso_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
117dso_null.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_null.c
118dso_openssl.o: ../../e_os.h ../../include/openssl/bio.h
119dso_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
120dso_openssl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
121dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
122dso_openssl.o: ../../include/openssl/opensslconf.h
123dso_openssl.o: ../../include/openssl/opensslv.h
124dso_openssl.o: ../../include/openssl/ossl_typ.h
125dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
126dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_openssl.c
127dso_vms.o: ../../e_os.h ../../include/openssl/bio.h
128dso_vms.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
129dso_vms.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
130dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
131dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132dso_vms.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
133dso_vms.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
134dso_vms.o: ../cryptlib.h dso_vms.c
135dso_win32.o: ../../e_os.h ../../include/openssl/bio.h
136dso_win32.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
137dso_win32.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
138dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
139dso_win32.o: ../../include/openssl/opensslconf.h
140dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
141dso_win32.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
142dso_win32.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_win32.c
diff --git a/src/lib/libcrypto/dso/Makefile.ssl b/src/lib/libcrypto/dso/Makefile.ssl
new file mode 100644
index 0000000000..c0449d184e
--- /dev/null
+++ b/src/lib/libcrypto/dso/Makefile.ssl
@@ -0,0 +1,142 @@
1#
2# SSLeay/crypto/dso/Makefile
3#
4
5DIR= dso
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= dso_dl.c dso_dlfcn.c dso_err.c dso_lib.c dso_null.c \
27 dso_openssl.c dso_win32.c dso_vms.c
28LIBOBJ= dso_dl.o dso_dlfcn.o dso_err.o dso_lib.o dso_null.o \
29 dso_openssl.o dso_win32.o dso_vms.o
30
31SRC= $(LIBSRC)
32
33EXHEADER= dso.h
34HEADER= $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48files:
49 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
50
51links:
52 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
53 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
54 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
55 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
56
57install:
58 @for i in $(EXHEADER) ; \
59 do \
60 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done;
63
64tags:
65 ctags $(SRC)
66
67tests:
68
69lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff
71
72depend:
73 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
74
75dclean:
76 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
77 mv -f Makefile.new $(MAKEFILE)
78
79clean:
80 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
81
82# DO NOT DELETE THIS LINE -- make depend depends on it.
83
84dso_dl.o: ../../e_os.h ../../include/openssl/bio.h
85dso_dl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
86dso_dl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
87dso_dl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
88dso_dl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
89dso_dl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90dso_dl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_dl.c
91dso_dlfcn.o: ../../e_os.h ../../include/openssl/bio.h
92dso_dlfcn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
93dso_dlfcn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
94dso_dlfcn.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
95dso_dlfcn.o: ../../include/openssl/opensslconf.h
96dso_dlfcn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
97dso_dlfcn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98dso_dlfcn.o: ../cryptlib.h dso_dlfcn.c
99dso_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
100dso_err.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
101dso_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
102dso_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103dso_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
104dso_err.o: ../../include/openssl/symhacks.h dso_err.c
105dso_lib.o: ../../e_os.h ../../include/openssl/bio.h
106dso_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
107dso_lib.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
108dso_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
109dso_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
110dso_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
111dso_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_lib.c
112dso_null.o: ../../e_os.h ../../include/openssl/bio.h
113dso_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
114dso_null.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
115dso_null.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
116dso_null.o: ../../include/openssl/opensslconf.h
117dso_null.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
118dso_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119dso_null.o: ../cryptlib.h dso_null.c
120dso_openssl.o: ../../e_os.h ../../include/openssl/bio.h
121dso_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
122dso_openssl.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
123dso_openssl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
124dso_openssl.o: ../../include/openssl/opensslconf.h
125dso_openssl.o: ../../include/openssl/opensslv.h
126dso_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
127dso_openssl.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_openssl.c
128dso_vms.o: ../../e_os.h ../../include/openssl/bio.h
129dso_vms.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
130dso_vms.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
131dso_vms.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
132dso_vms.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
133dso_vms.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
134dso_vms.o: ../../include/openssl/symhacks.h ../cryptlib.h dso_vms.c
135dso_win32.o: ../../e_os.h ../../include/openssl/bio.h
136dso_win32.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
137dso_win32.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
138dso_win32.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
139dso_win32.o: ../../include/openssl/opensslconf.h
140dso_win32.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
141dso_win32.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
142dso_win32.o: ../cryptlib.h dso_win32.c
diff --git a/src/lib/libcrypto/dso/README b/src/lib/libcrypto/dso/README
new file mode 100644
index 0000000000..d0bc9a89fb
--- /dev/null
+++ b/src/lib/libcrypto/dso/README
@@ -0,0 +1,22 @@
1NOTES
2-----
3
4I've checked out HPUX (well, version 11 at least) and shl_t is
5a pointer type so it's safe to use in the way it has been in
6dso_dl.c. On the other hand, HPUX11 support dlfcn too and
7according to their man page, prefer developers to move to that.
8I'll leave Richard's changes there as I guess dso_dl is needed
9for HPUX10.20.
10
11There is now a callback scheme in place where filename conversion can
12(a) be turned off altogether through the use of the
13 DSO_FLAG_NO_NAME_TRANSLATION flag,
14(b) be handled by default using the default DSO_METHOD's converter
15(c) overriden per-DSO by setting the override callback
16(d) a mix of (b) and (c) - eg. implement an override callback that;
17 (i) checks if we're win32 (if(strstr(dso->meth->name, "win32")....)
18 and if so, convert "blah" into "blah32.dll" (the default is
19 otherwise to make it "blah.dll").
20 (ii) default to the normal behaviour - we're not on win32, eg.
21 finish with (return dso->meth->dso_name_converter(dso,NULL)).
22
diff --git a/src/lib/libcrypto/dso/dso.h b/src/lib/libcrypto/dso/dso.h
index 3e51913a72..aa721f7feb 100644
--- a/src/lib/libcrypto/dso/dso.h
+++ b/src/lib/libcrypto/dso/dso.h
@@ -1,4 +1,4 @@
1/* dso.h -*- mode:C; c-file-style: "eay" -*- */ 1/* dso.h */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -95,13 +95,6 @@ extern "C" {
95 */ 95 */
96#define DSO_FLAG_UPCASE_SYMBOL 0x10 96#define DSO_FLAG_UPCASE_SYMBOL 0x10
97 97
98/* This flag loads the library with public symbols.
99 * Meaning: The exported symbols of this library are public
100 * to all libraries loaded after this library.
101 * At the moment only implemented in unix.
102 */
103#define DSO_FLAG_GLOBAL_SYMBOLS 0x20
104
105 98
106typedef void (*DSO_FUNC_TYPE)(void); 99typedef void (*DSO_FUNC_TYPE)(void);
107 100
@@ -114,22 +107,6 @@ typedef struct dso_st DSO;
114 * condition) or a newly allocated string containing the transformed form that 107 * condition) or a newly allocated string containing the transformed form that
115 * the caller will need to free with OPENSSL_free() when done. */ 108 * the caller will need to free with OPENSSL_free() when done. */
116typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *); 109typedef char* (*DSO_NAME_CONVERTER_FUNC)(DSO *, const char *);
117/* The function prototype used for method functions (or caller-provided
118 * callbacks) that merge two file specifications. They are passed a
119 * DSO structure pointer (or NULL if they are to be used independantly of
120 * a DSO object) and two file specifications to merge. They should
121 * either return NULL (if there is an error condition) or a newly allocated
122 * string containing the result of merging that the caller will need
123 * to free with OPENSSL_free() when done.
124 * Here, merging means that bits and pieces are taken from each of the
125 * file specifications and added together in whatever fashion that is
126 * sensible for the DSO method in question. The only rule that really
127 * applies is that if the two specification contain pieces of the same
128 * type, the copy from the first string takes priority. One could see
129 * it as the first specification is the one given by the user and the
130 * second being a bunch of defaults to add on if they're missing in the
131 * first. */
132typedef char* (*DSO_MERGER_FUNC)(DSO *, const char *, const char *);
133 110
134typedef struct dso_meth_st 111typedef struct dso_meth_st
135 { 112 {
@@ -163,9 +140,6 @@ typedef struct dso_meth_st
163 /* The default DSO_METHOD-specific function for converting filenames to 140 /* The default DSO_METHOD-specific function for converting filenames to
164 * a canonical native form. */ 141 * a canonical native form. */
165 DSO_NAME_CONVERTER_FUNC dso_name_converter; 142 DSO_NAME_CONVERTER_FUNC dso_name_converter;
166 /* The default DSO_METHOD-specific function for converting filenames to
167 * a canonical native form. */
168 DSO_MERGER_FUNC dso_merger;
169 143
170 /* [De]Initialisation handlers. */ 144 /* [De]Initialisation handlers. */
171 int (*init)(DSO *dso); 145 int (*init)(DSO *dso);
@@ -190,13 +164,9 @@ struct dso_st
190 * don't touch meth_data! */ 164 * don't touch meth_data! */
191 CRYPTO_EX_DATA ex_data; 165 CRYPTO_EX_DATA ex_data;
192 /* If this callback function pointer is set to non-NULL, then it will 166 /* If this callback function pointer is set to non-NULL, then it will
193 * be used in DSO_load() in place of meth->dso_name_converter. NB: This 167 * be used on DSO_load() in place of meth->dso_name_converter. NB: This
194 * should normally set using DSO_set_name_converter(). */ 168 * should normally set using DSO_set_name_converter(). */
195 DSO_NAME_CONVERTER_FUNC name_converter; 169 DSO_NAME_CONVERTER_FUNC name_converter;
196 /* If this callback function pointer is set to non-NULL, then it will
197 * be used in DSO_load() in place of meth->dso_merger. NB: This
198 * should normally set using DSO_set_merger(). */
199 DSO_MERGER_FUNC merger;
200 /* This is populated with (a copy of) the platform-independant 170 /* This is populated with (a copy of) the platform-independant
201 * filename used for this DSO. */ 171 * filename used for this DSO. */
202 char *filename; 172 char *filename;
@@ -239,11 +209,6 @@ int DSO_set_filename(DSO *dso, const char *filename);
239 * caller-created DSO_METHODs can do the same thing. A non-NULL return value 209 * caller-created DSO_METHODs can do the same thing. A non-NULL return value
240 * will need to be OPENSSL_free()'d. */ 210 * will need to be OPENSSL_free()'d. */
241char *DSO_convert_filename(DSO *dso, const char *filename); 211char *DSO_convert_filename(DSO *dso, const char *filename);
242/* This function will invoke the DSO's merger callback to merge two file
243 * specifications, or if the callback isn't set it will instead use the
244 * DSO_METHOD's merger. A non-NULL return value will need to be
245 * OPENSSL_free()'d. */
246char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2);
247/* If the DSO is currently loaded, this returns the filename that it was loaded 212/* If the DSO is currently loaded, this returns the filename that it was loaded
248 * under, otherwise it returns NULL. So it is also useful as a test as to 213 * under, otherwise it returns NULL. So it is also useful as a test as to
249 * whether the DSO is currently loaded. NB: This will not necessarily return 214 * whether the DSO is currently loaded. NB: This will not necessarily return
@@ -308,13 +273,11 @@ void ERR_load_DSO_strings(void);
308#define DSO_F_DLFCN_BIND_FUNC 100 273#define DSO_F_DLFCN_BIND_FUNC 100
309#define DSO_F_DLFCN_BIND_VAR 101 274#define DSO_F_DLFCN_BIND_VAR 101
310#define DSO_F_DLFCN_LOAD 102 275#define DSO_F_DLFCN_LOAD 102
311#define DSO_F_DLFCN_MERGER 130
312#define DSO_F_DLFCN_NAME_CONVERTER 123 276#define DSO_F_DLFCN_NAME_CONVERTER 123
313#define DSO_F_DLFCN_UNLOAD 103 277#define DSO_F_DLFCN_UNLOAD 103
314#define DSO_F_DL_BIND_FUNC 104 278#define DSO_F_DL_BIND_FUNC 104
315#define DSO_F_DL_BIND_VAR 105 279#define DSO_F_DL_BIND_VAR 105
316#define DSO_F_DL_LOAD 106 280#define DSO_F_DL_LOAD 106
317#define DSO_F_DL_MERGER 131
318#define DSO_F_DL_NAME_CONVERTER 124 281#define DSO_F_DL_NAME_CONVERTER 124
319#define DSO_F_DL_UNLOAD 107 282#define DSO_F_DL_UNLOAD 107
320#define DSO_F_DSO_BIND_FUNC 108 283#define DSO_F_DSO_BIND_FUNC 108
@@ -325,36 +288,27 @@ void ERR_load_DSO_strings(void);
325#define DSO_F_DSO_GET_FILENAME 127 288#define DSO_F_DSO_GET_FILENAME 127
326#define DSO_F_DSO_GET_LOADED_FILENAME 128 289#define DSO_F_DSO_GET_LOADED_FILENAME 128
327#define DSO_F_DSO_LOAD 112 290#define DSO_F_DSO_LOAD 112
328#define DSO_F_DSO_MERGE 132
329#define DSO_F_DSO_NEW_METHOD 113 291#define DSO_F_DSO_NEW_METHOD 113
330#define DSO_F_DSO_SET_FILENAME 129 292#define DSO_F_DSO_SET_FILENAME 129
331#define DSO_F_DSO_SET_NAME_CONVERTER 122 293#define DSO_F_DSO_SET_NAME_CONVERTER 122
332#define DSO_F_DSO_UP_REF 114 294#define DSO_F_DSO_UP_REF 114
333#define DSO_F_VMS_BIND_SYM 115 295#define DSO_F_VMS_BIND_VAR 115
334#define DSO_F_VMS_LOAD 116 296#define DSO_F_VMS_LOAD 116
335#define DSO_F_VMS_MERGER 133
336#define DSO_F_VMS_UNLOAD 117 297#define DSO_F_VMS_UNLOAD 117
337#define DSO_F_WIN32_BIND_FUNC 118 298#define DSO_F_WIN32_BIND_FUNC 118
338#define DSO_F_WIN32_BIND_VAR 119 299#define DSO_F_WIN32_BIND_VAR 119
339#define DSO_F_WIN32_JOINER 135
340#define DSO_F_WIN32_LOAD 120 300#define DSO_F_WIN32_LOAD 120
341#define DSO_F_WIN32_MERGER 134
342#define DSO_F_WIN32_NAME_CONVERTER 125 301#define DSO_F_WIN32_NAME_CONVERTER 125
343#define DSO_F_WIN32_SPLITTER 136
344#define DSO_F_WIN32_UNLOAD 121 302#define DSO_F_WIN32_UNLOAD 121
345 303
346/* Reason codes. */ 304/* Reason codes. */
347#define DSO_R_CTRL_FAILED 100 305#define DSO_R_CTRL_FAILED 100
348#define DSO_R_DSO_ALREADY_LOADED 110 306#define DSO_R_DSO_ALREADY_LOADED 110
349#define DSO_R_EMPTY_FILE_STRUCTURE 113
350#define DSO_R_FAILURE 114
351#define DSO_R_FILENAME_TOO_BIG 101 307#define DSO_R_FILENAME_TOO_BIG 101
352#define DSO_R_FINISH_FAILED 102 308#define DSO_R_FINISH_FAILED 102
353#define DSO_R_INCORRECT_FILE_SYNTAX 115
354#define DSO_R_LOAD_FAILED 103 309#define DSO_R_LOAD_FAILED 103
355#define DSO_R_NAME_TRANSLATION_FAILED 109 310#define DSO_R_NAME_TRANSLATION_FAILED 109
356#define DSO_R_NO_FILENAME 111 311#define DSO_R_NO_FILENAME 111
357#define DSO_R_NO_FILE_SPECIFICATION 116
358#define DSO_R_NULL_HANDLE 104 312#define DSO_R_NULL_HANDLE 104
359#define DSO_R_SET_FILENAME_FAILED 112 313#define DSO_R_SET_FILENAME_FAILED 112
360#define DSO_R_STACK_ERROR 105 314#define DSO_R_STACK_ERROR 105
diff --git a/src/lib/libcrypto/dso/dso_dl.c b/src/lib/libcrypto/dso/dso_dl.c
new file mode 100644
index 0000000000..f7b4dfc0c3
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_dl.c
@@ -0,0 +1,317 @@
1/* dso_dl.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/dso.h>
62
63#ifndef DSO_DL
64DSO_METHOD *DSO_METHOD_dl(void)
65 {
66 return NULL;
67 }
68#else
69
70#include <dl.h>
71
72/* Part of the hack in "dl_load" ... */
73#define DSO_MAX_TRANSLATED_SIZE 256
74
75static int dl_load(DSO *dso);
76static int dl_unload(DSO *dso);
77static void *dl_bind_var(DSO *dso, const char *symname);
78static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname);
79#if 0
80static int dl_unbind_var(DSO *dso, char *symname, void *symptr);
81static int dl_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
82static int dl_init(DSO *dso);
83static int dl_finish(DSO *dso);
84static int dl_ctrl(DSO *dso, int cmd, long larg, void *parg);
85#endif
86static char *dl_name_converter(DSO *dso, const char *filename);
87
88static DSO_METHOD dso_meth_dl = {
89 "OpenSSL 'dl' shared library method",
90 dl_load,
91 dl_unload,
92 dl_bind_var,
93 dl_bind_func,
94/* For now, "unbind" doesn't exist */
95#if 0
96 NULL, /* unbind_var */
97 NULL, /* unbind_func */
98#endif
99 NULL, /* ctrl */
100 dl_name_converter,
101 NULL, /* init */
102 NULL /* finish */
103 };
104
105DSO_METHOD *DSO_METHOD_dl(void)
106 {
107 return(&dso_meth_dl);
108 }
109
110/* For this DSO_METHOD, our meth_data STACK will contain;
111 * (i) the handle (shl_t) returned from shl_load().
112 * NB: I checked on HPUX11 and shl_t is itself a pointer
113 * type so the cast is safe.
114 */
115
116static int dl_load(DSO *dso)
117 {
118 shl_t ptr = NULL;
119 /* We don't do any fancy retries or anything, just take the method's
120 * (or DSO's if it has the callback set) best translation of the
121 * platform-independant filename and try once with that. */
122 char *filename= DSO_convert_filename(dso, NULL);
123
124 if(filename == NULL)
125 {
126 DSOerr(DSO_F_DL_LOAD,DSO_R_NO_FILENAME);
127 goto err;
128 }
129 ptr = shl_load(filename, BIND_IMMEDIATE |
130 (dso->flags&DSO_FLAG_NO_NAME_TRANSLATION?0:DYNAMIC_PATH), 0L);
131 if(ptr == NULL)
132 {
133 DSOerr(DSO_F_DL_LOAD,DSO_R_LOAD_FAILED);
134 ERR_add_error_data(4, "filename(", filename, "): ",
135 strerror(errno));
136 goto err;
137 }
138 if(!sk_push(dso->meth_data, (char *)ptr))
139 {
140 DSOerr(DSO_F_DL_LOAD,DSO_R_STACK_ERROR);
141 goto err;
142 }
143 /* Success, stick the converted filename we've loaded under into the DSO
144 * (it also serves as the indicator that we are currently loaded). */
145 dso->loaded_filename = filename;
146 return(1);
147err:
148 /* Cleanup! */
149 if(filename != NULL)
150 OPENSSL_free(filename);
151 if(ptr != NULL)
152 shl_unload(ptr);
153 return(0);
154 }
155
156static int dl_unload(DSO *dso)
157 {
158 shl_t ptr;
159 if(dso == NULL)
160 {
161 DSOerr(DSO_F_DL_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
162 return(0);
163 }
164 if(sk_num(dso->meth_data) < 1)
165 return(1);
166 /* Is this statement legal? */
167 ptr = (shl_t)sk_pop(dso->meth_data);
168 if(ptr == NULL)
169 {
170 DSOerr(DSO_F_DL_UNLOAD,DSO_R_NULL_HANDLE);
171 /* Should push the value back onto the stack in
172 * case of a retry. */
173 sk_push(dso->meth_data, (char *)ptr);
174 return(0);
175 }
176 shl_unload(ptr);
177 return(1);
178 }
179
180static void *dl_bind_var(DSO *dso, const char *symname)
181 {
182 shl_t ptr;
183 void *sym;
184
185 if((dso == NULL) || (symname == NULL))
186 {
187 DSOerr(DSO_F_DL_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
188 return(NULL);
189 }
190 if(sk_num(dso->meth_data) < 1)
191 {
192 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_STACK_ERROR);
193 return(NULL);
194 }
195 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
196 if(ptr == NULL)
197 {
198 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_NULL_HANDLE);
199 return(NULL);
200 }
201 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
202 {
203 DSOerr(DSO_F_DL_BIND_VAR,DSO_R_SYM_FAILURE);
204 ERR_add_error_data(4, "symname(", symname, "): ",
205 strerror(errno));
206 return(NULL);
207 }
208 return(sym);
209 }
210
211static DSO_FUNC_TYPE dl_bind_func(DSO *dso, const char *symname)
212 {
213 shl_t ptr;
214 void *sym;
215
216 if((dso == NULL) || (symname == NULL))
217 {
218 DSOerr(DSO_F_DL_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
219 return(NULL);
220 }
221 if(sk_num(dso->meth_data) < 1)
222 {
223 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_STACK_ERROR);
224 return(NULL);
225 }
226 ptr = (shl_t)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
227 if(ptr == NULL)
228 {
229 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_NULL_HANDLE);
230 return(NULL);
231 }
232 if (shl_findsym(&ptr, symname, TYPE_UNDEFINED, &sym) < 0)
233 {
234 DSOerr(DSO_F_DL_BIND_FUNC,DSO_R_SYM_FAILURE);
235 ERR_add_error_data(4, "symname(", symname, "): ",
236 strerror(errno));
237 return(NULL);
238 }
239 return((DSO_FUNC_TYPE)sym);
240 }
241
242/* This function is identical to the one in dso_dlfcn.c, but as it is highly
243 * unlikely that both the "dl" *and* "dlfcn" variants are being compiled at the
244 * same time, there's no great duplicating the code. Figuring out an elegant
245 * way to share one copy of the code would be more difficult and would not
246 * leave the implementations independant. */
247#if defined(__hpux)
248static const char extension[] = ".sl";
249#else
250static const char extension[] = ".so";
251#endif
252static char *dl_name_converter(DSO *dso, const char *filename)
253 {
254 char *translated;
255 int len, rsize, transform;
256
257 len = strlen(filename);
258 rsize = len + 1;
259 transform = (strstr(filename, "/") == NULL);
260 {
261 /* We will convert this to "%s.s?" or "lib%s.s?" */
262 rsize += strlen(extension);/* The length of ".s?" */
263 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
264 rsize += 3; /* The length of "lib" */
265 }
266 translated = OPENSSL_malloc(rsize);
267 if(translated == NULL)
268 {
269 DSOerr(DSO_F_DL_NAME_CONVERTER,
270 DSO_R_NAME_TRANSLATION_FAILED);
271 return(NULL);
272 }
273 if(transform)
274 {
275 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
276 sprintf(translated, "lib%s%s", filename, extension);
277 else
278 sprintf(translated, "%s%s", filename, extension);
279 }
280 else
281 sprintf(translated, "%s", filename);
282 return(translated);
283 }
284
285#ifdef OPENSSL_FIPS
286static void dl_ref_point(){}
287
288int DSO_pathbyaddr(void *addr,char *path,int sz)
289 {
290 struct shl_descriptor inf;
291 int i,len;
292
293 if (addr == NULL)
294 {
295 union { void(*f)(); void *p; } t = { dl_ref_point };
296 addr = t.p;
297 }
298
299 for (i=-1;shl_get_r(i,&inf)==0;i++)
300 {
301 if (((size_t)addr >= inf.tstart && (size_t)addr < inf.tend) ||
302 ((size_t)addr >= inf.dstart && (size_t)addr < inf.dend))
303 {
304 len = (int)strlen(inf.filename);
305 if (sz <= 0) return len+1;
306 if (len >= sz) len=sz-1;
307 memcpy(path,inf.filename,len);
308 path[len++] = 0;
309 return len;
310 }
311 }
312
313 return -1;
314 }
315#endif
316
317#endif /* DSO_DL */
diff --git a/src/lib/libcrypto/dso/dso_dlfcn.c b/src/lib/libcrypto/dso/dso_dlfcn.c
index 1fd10104c5..d48b4202f2 100644
--- a/src/lib/libcrypto/dso/dso_dlfcn.c
+++ b/src/lib/libcrypto/dso/dso_dlfcn.c
@@ -1,4 +1,4 @@
1/* dso_dlfcn.c -*- mode:C; c-file-style: "eay" -*- */ 1/* dso_dlfcn.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -56,6 +56,10 @@
56 * 56 *
57 */ 57 */
58 58
59#ifdef __linux
60#define _GNU_SOURCE
61#endif
62
59#include <stdio.h> 63#include <stdio.h>
60#include "cryptlib.h" 64#include "cryptlib.h"
61#include <openssl/dso.h> 65#include <openssl/dso.h>
@@ -85,8 +89,6 @@ static int dlfcn_finish(DSO *dso);
85static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg); 89static long dlfcn_ctrl(DSO *dso, int cmd, long larg, void *parg);
86#endif 90#endif
87static char *dlfcn_name_converter(DSO *dso, const char *filename); 91static char *dlfcn_name_converter(DSO *dso, const char *filename);
88static char *dlfcn_merger(DSO *dso, const char *filespec1,
89 const char *filespec2);
90 92
91static DSO_METHOD dso_meth_dlfcn = { 93static DSO_METHOD dso_meth_dlfcn = {
92 "OpenSSL 'dlfcn' shared library method", 94 "OpenSSL 'dlfcn' shared library method",
@@ -101,7 +103,6 @@ static DSO_METHOD dso_meth_dlfcn = {
101#endif 103#endif
102 NULL, /* ctrl */ 104 NULL, /* ctrl */
103 dlfcn_name_converter, 105 dlfcn_name_converter,
104 dlfcn_merger,
105 NULL, /* init */ 106 NULL, /* init */
106 NULL /* finish */ 107 NULL /* finish */
107 }; 108 };
@@ -144,19 +145,13 @@ static int dlfcn_load(DSO *dso)
144 void *ptr = NULL; 145 void *ptr = NULL;
145 /* See applicable comments in dso_dl.c */ 146 /* See applicable comments in dso_dl.c */
146 char *filename = DSO_convert_filename(dso, NULL); 147 char *filename = DSO_convert_filename(dso, NULL);
147 int flags = DLOPEN_FLAG;
148 148
149 if(filename == NULL) 149 if(filename == NULL)
150 { 150 {
151 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME); 151 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
152 goto err; 152 goto err;
153 } 153 }
154 154 ptr = dlopen(filename, DLOPEN_FLAG);
155#ifdef RTLD_GLOBAL
156 if (dso->flags & DSO_FLAG_GLOBAL_SYMBOLS)
157 flags |= RTLD_GLOBAL;
158#endif
159 ptr = dlopen(filename, flags);
160 if(ptr == NULL) 155 if(ptr == NULL)
161 { 156 {
162 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED); 157 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_LOAD_FAILED);
@@ -255,7 +250,7 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
255 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE); 250 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_NULL_HANDLE);
256 return(NULL); 251 return(NULL);
257 } 252 }
258 *(void **)(tsym) = dlsym(ptr, symname); 253 *(void**)(tsym) = dlsym(ptr, symname);
259 if(sym == NULL) 254 if(sym == NULL)
260 { 255 {
261 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE); 256 DSOerr(DSO_F_DLFCN_BIND_FUNC,DSO_R_SYM_FAILURE);
@@ -265,73 +260,6 @@ static DSO_FUNC_TYPE dlfcn_bind_func(DSO *dso, const char *symname)
265 return(sym); 260 return(sym);
266 } 261 }
267 262
268static char *dlfcn_merger(DSO *dso, const char *filespec1,
269 const char *filespec2)
270 {
271 char *merged;
272
273 if(!filespec1 && !filespec2)
274 {
275 DSOerr(DSO_F_DLFCN_MERGER,
276 ERR_R_PASSED_NULL_PARAMETER);
277 return(NULL);
278 }
279 /* If the first file specification is a rooted path, it rules.
280 same goes if the second file specification is missing. */
281 if (!filespec2 || filespec1[0] == '/')
282 {
283 merged = OPENSSL_malloc(strlen(filespec1) + 1);
284 if(!merged)
285 {
286 DSOerr(DSO_F_DLFCN_MERGER,
287 ERR_R_MALLOC_FAILURE);
288 return(NULL);
289 }
290 strcpy(merged, filespec1);
291 }
292 /* If the first file specification is missing, the second one rules. */
293 else if (!filespec1)
294 {
295 merged = OPENSSL_malloc(strlen(filespec2) + 1);
296 if(!merged)
297 {
298 DSOerr(DSO_F_DLFCN_MERGER,
299 ERR_R_MALLOC_FAILURE);
300 return(NULL);
301 }
302 strcpy(merged, filespec2);
303 }
304 else
305 /* This part isn't as trivial as it looks. It assumes that
306 the second file specification really is a directory, and
307 makes no checks whatsoever. Therefore, the result becomes
308 the concatenation of filespec2 followed by a slash followed
309 by filespec1. */
310 {
311 int spec2len, len;
312
313 spec2len = (filespec2 ? strlen(filespec2) : 0);
314 len = spec2len + (filespec1 ? strlen(filespec1) : 0);
315
316 if(filespec2 && filespec2[spec2len - 1] == '/')
317 {
318 spec2len--;
319 len--;
320 }
321 merged = OPENSSL_malloc(len + 2);
322 if(!merged)
323 {
324 DSOerr(DSO_F_DLFCN_MERGER,
325 ERR_R_MALLOC_FAILURE);
326 return(NULL);
327 }
328 strcpy(merged, filespec2);
329 merged[spec2len] = '/';
330 strcpy(&merged[spec2len + 1], filespec1);
331 }
332 return(merged);
333 }
334
335static char *dlfcn_name_converter(DSO *dso, const char *filename) 263static char *dlfcn_name_converter(DSO *dso, const char *filename)
336 { 264 {
337 char *translated; 265 char *translated;
@@ -357,13 +285,41 @@ static char *dlfcn_name_converter(DSO *dso, const char *filename)
357 if(transform) 285 if(transform)
358 { 286 {
359 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0) 287 if ((DSO_flags(dso) & DSO_FLAG_NAME_TRANSLATION_EXT_ONLY) == 0)
360 sprintf(translated, "lib%s.so", filename); 288 snprintf(translated, rsize, "lib%s.so", filename);
361 else 289 else
362 sprintf(translated, "%s.so", filename); 290 snprintf(translated, rsize, "%s.so", filename);
363 } 291 }
364 else 292 else
365 sprintf(translated, "%s", filename); 293 snprintf(translated, rsize, "%s", filename);
366 return(translated); 294 return(translated);
367 } 295 }
368 296
297#ifdef OPENSSL_FIPS
298static void dlfcn_ref_point(){}
299
300int DSO_pathbyaddr(void *addr,char *path,int sz)
301 {
302 Dl_info dli;
303 int len;
304
305 if (addr == NULL)
306 {
307 union { void(*f)(void); void *p; } t = { dlfcn_ref_point };
308 addr = t.p;
309 }
310
311 if (dladdr(addr,&dli))
312 {
313 len = (int)strlen(dli.dli_fname);
314 if (sz <= 0) return len+1;
315 if (len >= sz) len=sz-1;
316 memcpy(path,dli.dli_fname,len);
317 path[len++]=0;
318 return len;
319 }
320
321 ERR_add_error_data(4, "dlfcn_pathbyaddr(): ", dlerror());
322 return -1;
323 }
324#endif
369#endif /* DSO_DLFCN */ 325#endif /* DSO_DLFCN */
diff --git a/src/lib/libcrypto/dso/dso_err.c b/src/lib/libcrypto/dso/dso_err.c
index a8b0a210de..581677cc36 100644
--- a/src/lib/libcrypto/dso/dso_err.c
+++ b/src/lib/libcrypto/dso/dso_err.c
@@ -73,13 +73,11 @@ static ERR_STRING_DATA DSO_str_functs[]=
73{ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"}, 73{ERR_FUNC(DSO_F_DLFCN_BIND_FUNC), "DLFCN_BIND_FUNC"},
74{ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"}, 74{ERR_FUNC(DSO_F_DLFCN_BIND_VAR), "DLFCN_BIND_VAR"},
75{ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"}, 75{ERR_FUNC(DSO_F_DLFCN_LOAD), "DLFCN_LOAD"},
76{ERR_FUNC(DSO_F_DLFCN_MERGER), "DLFCN_MERGER"},
77{ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"}, 76{ERR_FUNC(DSO_F_DLFCN_NAME_CONVERTER), "DLFCN_NAME_CONVERTER"},
78{ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"}, 77{ERR_FUNC(DSO_F_DLFCN_UNLOAD), "DLFCN_UNLOAD"},
79{ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"}, 78{ERR_FUNC(DSO_F_DL_BIND_FUNC), "DL_BIND_FUNC"},
80{ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"}, 79{ERR_FUNC(DSO_F_DL_BIND_VAR), "DL_BIND_VAR"},
81{ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"}, 80{ERR_FUNC(DSO_F_DL_LOAD), "DL_LOAD"},
82{ERR_FUNC(DSO_F_DL_MERGER), "DL_MERGER"},
83{ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"}, 81{ERR_FUNC(DSO_F_DL_NAME_CONVERTER), "DL_NAME_CONVERTER"},
84{ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"}, 82{ERR_FUNC(DSO_F_DL_UNLOAD), "DL_UNLOAD"},
85{ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"}, 83{ERR_FUNC(DSO_F_DSO_BIND_FUNC), "DSO_bind_func"},
@@ -90,22 +88,17 @@ static ERR_STRING_DATA DSO_str_functs[]=
90{ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"}, 88{ERR_FUNC(DSO_F_DSO_GET_FILENAME), "DSO_get_filename"},
91{ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"}, 89{ERR_FUNC(DSO_F_DSO_GET_LOADED_FILENAME), "DSO_get_loaded_filename"},
92{ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"}, 90{ERR_FUNC(DSO_F_DSO_LOAD), "DSO_load"},
93{ERR_FUNC(DSO_F_DSO_MERGE), "DSO_merge"},
94{ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"}, 91{ERR_FUNC(DSO_F_DSO_NEW_METHOD), "DSO_new_method"},
95{ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"}, 92{ERR_FUNC(DSO_F_DSO_SET_FILENAME), "DSO_set_filename"},
96{ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"}, 93{ERR_FUNC(DSO_F_DSO_SET_NAME_CONVERTER), "DSO_set_name_converter"},
97{ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"}, 94{ERR_FUNC(DSO_F_DSO_UP_REF), "DSO_up_ref"},
98{ERR_FUNC(DSO_F_VMS_BIND_SYM), "VMS_BIND_SYM"}, 95{ERR_FUNC(DSO_F_VMS_BIND_VAR), "VMS_BIND_VAR"},
99{ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"}, 96{ERR_FUNC(DSO_F_VMS_LOAD), "VMS_LOAD"},
100{ERR_FUNC(DSO_F_VMS_MERGER), "VMS_MERGER"},
101{ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"}, 97{ERR_FUNC(DSO_F_VMS_UNLOAD), "VMS_UNLOAD"},
102{ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"}, 98{ERR_FUNC(DSO_F_WIN32_BIND_FUNC), "WIN32_BIND_FUNC"},
103{ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"}, 99{ERR_FUNC(DSO_F_WIN32_BIND_VAR), "WIN32_BIND_VAR"},
104{ERR_FUNC(DSO_F_WIN32_JOINER), "WIN32_JOINER"},
105{ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"}, 100{ERR_FUNC(DSO_F_WIN32_LOAD), "WIN32_LOAD"},
106{ERR_FUNC(DSO_F_WIN32_MERGER), "WIN32_MERGER"},
107{ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"}, 101{ERR_FUNC(DSO_F_WIN32_NAME_CONVERTER), "WIN32_NAME_CONVERTER"},
108{ERR_FUNC(DSO_F_WIN32_SPLITTER), "WIN32_SPLITTER"},
109{ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"}, 102{ERR_FUNC(DSO_F_WIN32_UNLOAD), "WIN32_UNLOAD"},
110{0,NULL} 103{0,NULL}
111 }; 104 };
@@ -114,15 +107,11 @@ static ERR_STRING_DATA DSO_str_reasons[]=
114 { 107 {
115{ERR_REASON(DSO_R_CTRL_FAILED) ,"control command failed"}, 108{ERR_REASON(DSO_R_CTRL_FAILED) ,"control command failed"},
116{ERR_REASON(DSO_R_DSO_ALREADY_LOADED) ,"dso already loaded"}, 109{ERR_REASON(DSO_R_DSO_ALREADY_LOADED) ,"dso already loaded"},
117{ERR_REASON(DSO_R_EMPTY_FILE_STRUCTURE) ,"empty file structure"},
118{ERR_REASON(DSO_R_FAILURE) ,"failure"},
119{ERR_REASON(DSO_R_FILENAME_TOO_BIG) ,"filename too big"}, 110{ERR_REASON(DSO_R_FILENAME_TOO_BIG) ,"filename too big"},
120{ERR_REASON(DSO_R_FINISH_FAILED) ,"cleanup method function failed"}, 111{ERR_REASON(DSO_R_FINISH_FAILED) ,"cleanup method function failed"},
121{ERR_REASON(DSO_R_INCORRECT_FILE_SYNTAX) ,"incorrect file syntax"},
122{ERR_REASON(DSO_R_LOAD_FAILED) ,"could not load the shared library"}, 112{ERR_REASON(DSO_R_LOAD_FAILED) ,"could not load the shared library"},
123{ERR_REASON(DSO_R_NAME_TRANSLATION_FAILED),"name translation failed"}, 113{ERR_REASON(DSO_R_NAME_TRANSLATION_FAILED),"name translation failed"},
124{ERR_REASON(DSO_R_NO_FILENAME) ,"no filename"}, 114{ERR_REASON(DSO_R_NO_FILENAME) ,"no filename"},
125{ERR_REASON(DSO_R_NO_FILE_SPECIFICATION) ,"no file specification"},
126{ERR_REASON(DSO_R_NULL_HANDLE) ,"a null shared library handle was used"}, 115{ERR_REASON(DSO_R_NULL_HANDLE) ,"a null shared library handle was used"},
127{ERR_REASON(DSO_R_SET_FILENAME_FAILED) ,"set filename failed"}, 116{ERR_REASON(DSO_R_SET_FILENAME_FAILED) ,"set filename failed"},
128{ERR_REASON(DSO_R_STACK_ERROR) ,"the meth_data stack is corrupt"}, 117{ERR_REASON(DSO_R_STACK_ERROR) ,"the meth_data stack is corrupt"},
@@ -136,12 +125,15 @@ static ERR_STRING_DATA DSO_str_reasons[]=
136 125
137void ERR_load_DSO_strings(void) 126void ERR_load_DSO_strings(void)
138 { 127 {
139#ifndef OPENSSL_NO_ERR 128 static int init=1;
140 129
141 if (ERR_func_error_string(DSO_str_functs[0].error) == NULL) 130 if (init)
142 { 131 {
132 init=0;
133#ifndef OPENSSL_NO_ERR
143 ERR_load_strings(0,DSO_str_functs); 134 ERR_load_strings(0,DSO_str_functs);
144 ERR_load_strings(0,DSO_str_reasons); 135 ERR_load_strings(0,DSO_str_reasons);
145 }
146#endif 136#endif
137
138 }
147 } 139 }
diff --git a/src/lib/libcrypto/dso/dso_lib.c b/src/lib/libcrypto/dso/dso_lib.c
index 49bdd71309..48d9fdb25e 100644
--- a/src/lib/libcrypto/dso/dso_lib.c
+++ b/src/lib/libcrypto/dso/dso_lib.c
@@ -1,4 +1,4 @@
1/* dso_lib.c -*- mode:C; c-file-style: "eay" -*- */ 1/* dso_lib.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL 2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -390,33 +390,6 @@ int DSO_set_filename(DSO *dso, const char *filename)
390 return(1); 390 return(1);
391 } 391 }
392 392
393char *DSO_merge(DSO *dso, const char *filespec1, const char *filespec2)
394 {
395 char *result = NULL;
396
397 if(dso == NULL || filespec1 == NULL)
398 {
399 DSOerr(DSO_F_DSO_MERGE,ERR_R_PASSED_NULL_PARAMETER);
400 return(NULL);
401 }
402 if(filespec1 == NULL)
403 filespec1 = dso->filename;
404 if(filespec1 == NULL)
405 {
406 DSOerr(DSO_F_DSO_MERGE,DSO_R_NO_FILE_SPECIFICATION);
407 return(NULL);
408 }
409 if((dso->flags & DSO_FLAG_NO_NAME_TRANSLATION) == 0)
410 {
411 if(dso->merger != NULL)
412 result = dso->merger(dso, filespec1, filespec2);
413 else if(dso->meth->dso_merger != NULL)
414 result = dso->meth->dso_merger(dso,
415 filespec1, filespec2);
416 }
417 return(result);
418 }
419
420char *DSO_convert_filename(DSO *dso, const char *filename) 393char *DSO_convert_filename(DSO *dso, const char *filename)
421 { 394 {
422 char *result = NULL; 395 char *result = NULL;
diff --git a/src/lib/libcrypto/dso/dso_null.c b/src/lib/libcrypto/dso/dso_null.c
index 4972984651..fa13a7cb0f 100644
--- a/src/lib/libcrypto/dso/dso_null.c
+++ b/src/lib/libcrypto/dso/dso_null.c
@@ -75,8 +75,6 @@ static DSO_METHOD dso_meth_null = {
75 NULL, /* unbind_func */ 75 NULL, /* unbind_func */
76#endif 76#endif
77 NULL, /* ctrl */ 77 NULL, /* ctrl */
78 NULL, /* dso_name_converter */
79 NULL, /* dso_merger */
80 NULL, /* init */ 78 NULL, /* init */
81 NULL /* finish */ 79 NULL /* finish */
82 }; 80 };
diff --git a/src/lib/libcrypto/dso/dso_vms.c b/src/lib/libcrypto/dso/dso_vms.c
new file mode 100644
index 0000000000..1674619d17
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_vms.c
@@ -0,0 +1,379 @@
1/* dso_vms.c */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <errno.h>
62#include "cryptlib.h"
63#include <openssl/dso.h>
64#ifdef OPENSSL_SYS_VMS
65#pragma message disable DOLLARID
66#include <lib$routines.h>
67#include <stsdef.h>
68#include <descrip.h>
69#include <starlet.h>
70#endif
71
72#ifndef OPENSSL_SYS_VMS
73DSO_METHOD *DSO_METHOD_vms(void)
74 {
75 return NULL;
76 }
77#else
78#pragma message disable DOLLARID
79
80static int vms_load(DSO *dso);
81static int vms_unload(DSO *dso);
82static void *vms_bind_var(DSO *dso, const char *symname);
83static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname);
84#if 0
85static int vms_unbind_var(DSO *dso, char *symname, void *symptr);
86static int vms_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
87static int vms_init(DSO *dso);
88static int vms_finish(DSO *dso);
89static long vms_ctrl(DSO *dso, int cmd, long larg, void *parg);
90#endif
91static char *vms_name_converter(DSO *dso, const char *filename);
92
93static DSO_METHOD dso_meth_vms = {
94 "OpenSSL 'VMS' shared library method",
95 vms_load,
96 NULL, /* unload */
97 vms_bind_var,
98 vms_bind_func,
99/* For now, "unbind" doesn't exist */
100#if 0
101 NULL, /* unbind_var */
102 NULL, /* unbind_func */
103#endif
104 NULL, /* ctrl */
105 vms_name_converter,
106 NULL, /* init */
107 NULL /* finish */
108 };
109
110/* On VMS, the only "handle" is the file name. LIB$FIND_IMAGE_SYMBOL depends
111 * on the reference to the file name being the same for all calls regarding
112 * one shared image, so we'll just store it in an instance of the following
113 * structure and put a pointer to that instance in the meth_data stack.
114 */
115typedef struct dso_internal_st
116 {
117 /* This should contain the name only, no directory,
118 * no extension, nothing but a name. */
119 struct dsc$descriptor_s filename_dsc;
120 char filename[FILENAME_MAX+1];
121 /* This contains whatever is not in filename, if needed.
122 * Normally not defined. */
123 struct dsc$descriptor_s imagename_dsc;
124 char imagename[FILENAME_MAX+1];
125 } DSO_VMS_INTERNAL;
126
127
128DSO_METHOD *DSO_METHOD_vms(void)
129 {
130 return(&dso_meth_vms);
131 }
132
133static int vms_load(DSO *dso)
134 {
135 void *ptr = NULL;
136 /* See applicable comments in dso_dl.c */
137 char *filename = DSO_convert_filename(dso, NULL);
138 DSO_VMS_INTERNAL *p;
139 const char *sp1, *sp2; /* Search result */
140
141 if(filename == NULL)
142 {
143 DSOerr(DSO_F_DLFCN_LOAD,DSO_R_NO_FILENAME);
144 goto err;
145 }
146
147 /* A file specification may look like this:
148 *
149 * node::dev:[dir-spec]name.type;ver
150 *
151 * or (for compatibility with TOPS-20):
152 *
153 * node::dev:<dir-spec>name.type;ver
154 *
155 * and the dir-spec uses '.' as separator. Also, a dir-spec
156 * may consist of several parts, with mixed use of [] and <>:
157 *
158 * [dir1.]<dir2>
159 *
160 * We need to split the file specification into the name and
161 * the rest (both before and after the name itself).
162 */
163 /* Start with trying to find the end of a dir-spec, and save the
164 position of the byte after in sp1 */
165 sp1 = strrchr(filename, ']');
166 sp2 = strrchr(filename, '>');
167 if (sp1 == NULL) sp1 = sp2;
168 if (sp2 != NULL && sp2 > sp1) sp1 = sp2;
169 if (sp1 == NULL) sp1 = strrchr(filename, ':');
170 if (sp1 == NULL)
171 sp1 = filename;
172 else
173 sp1++; /* The byte after the found character */
174 /* Now, let's see if there's a type, and save the position in sp2 */
175 sp2 = strchr(sp1, '.');
176 /* If we found it, that's where we'll cut. Otherwise, look for a
177 version number and save the position in sp2 */
178 if (sp2 == NULL) sp2 = strchr(sp1, ';');
179 /* If there was still nothing to find, set sp2 to point at the end of
180 the string */
181 if (sp2 == NULL) sp2 = sp1 + strlen(sp1);
182
183 /* Check that we won't get buffer overflows */
184 if (sp2 - sp1 > FILENAME_MAX
185 || (sp1 - filename) + strlen(sp2) > FILENAME_MAX)
186 {
187 DSOerr(DSO_F_VMS_LOAD,DSO_R_FILENAME_TOO_BIG);
188 goto err;
189 }
190
191 p = (DSO_VMS_INTERNAL *)OPENSSL_malloc(sizeof(DSO_VMS_INTERNAL));
192 if(p == NULL)
193 {
194 DSOerr(DSO_F_VMS_LOAD,ERR_R_MALLOC_FAILURE);
195 goto err;
196 }
197
198 strncpy(p->filename, sp1, sp2-sp1);
199 p->filename[sp2-sp1] = '\0';
200
201 strncpy(p->imagename, filename, sp1-filename);
202 p->imagename[sp1-filename] = '\0';
203 strcat(p->imagename, sp2);
204
205 p->filename_dsc.dsc$w_length = strlen(p->filename);
206 p->filename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
207 p->filename_dsc.dsc$b_class = DSC$K_CLASS_S;
208 p->filename_dsc.dsc$a_pointer = p->filename;
209 p->imagename_dsc.dsc$w_length = strlen(p->imagename);
210 p->imagename_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
211 p->imagename_dsc.dsc$b_class = DSC$K_CLASS_S;
212 p->imagename_dsc.dsc$a_pointer = p->imagename;
213
214 if(!sk_push(dso->meth_data, (char *)p))
215 {
216 DSOerr(DSO_F_VMS_LOAD,DSO_R_STACK_ERROR);
217 goto err;
218 }
219
220 /* Success (for now, we lie. We actually do not know...) */
221 dso->loaded_filename = filename;
222 return(1);
223err:
224 /* Cleanup! */
225 if(p != NULL)
226 OPENSSL_free(p);
227 if(filename != NULL)
228 OPENSSL_free(filename);
229 return(0);
230 }
231
232/* Note that this doesn't actually unload the shared image, as there is no
233 * such thing in VMS. Next time it get loaded again, a new copy will
234 * actually be loaded.
235 */
236static int vms_unload(DSO *dso)
237 {
238 DSO_VMS_INTERNAL *p;
239 if(dso == NULL)
240 {
241 DSOerr(DSO_F_VMS_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
242 return(0);
243 }
244 if(sk_num(dso->meth_data) < 1)
245 return(1);
246 p = (DSO_VMS_INTERNAL *)sk_pop(dso->meth_data);
247 if(p == NULL)
248 {
249 DSOerr(DSO_F_VMS_UNLOAD,DSO_R_NULL_HANDLE);
250 return(0);
251 }
252 /* Cleanup */
253 OPENSSL_free(p);
254 return(1);
255 }
256
257/* We must do this in a separate function because of the way the exception
258 handler works (it makes this function return */
259static int do_find_symbol(DSO_VMS_INTERNAL *ptr,
260 struct dsc$descriptor_s *symname_dsc, void **sym,
261 unsigned long flags)
262 {
263 /* Make sure that signals are caught and returned instead of
264 aborting the program. The exception handler gets unestablished
265 automatically on return from this function. */
266 lib$establish(lib$sig_to_ret);
267
268 if(ptr->imagename_dsc.dsc$w_length)
269 return lib$find_image_symbol(&ptr->filename_dsc,
270 symname_dsc, sym,
271 &ptr->imagename_dsc, flags);
272 else
273 return lib$find_image_symbol(&ptr->filename_dsc,
274 symname_dsc, sym,
275 0, flags);
276 }
277
278void vms_bind_sym(DSO *dso, const char *symname, void **sym)
279 {
280 DSO_VMS_INTERNAL *ptr;
281 int status;
282#if 0
283 int flags = (1<<4); /* LIB$M_FIS_MIXEDCASE, but this symbol isn't
284 defined in VMS older than 7.0 or so */
285#else
286 int flags = 0;
287#endif
288 struct dsc$descriptor_s symname_dsc;
289 *sym = NULL;
290
291 symname_dsc.dsc$w_length = strlen(symname);
292 symname_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
293 symname_dsc.dsc$b_class = DSC$K_CLASS_S;
294 symname_dsc.dsc$a_pointer = (char *)symname; /* The cast is needed */
295
296 if((dso == NULL) || (symname == NULL))
297 {
298 DSOerr(DSO_F_VMS_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
299 return;
300 }
301 if(sk_num(dso->meth_data) < 1)
302 {
303 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_STACK_ERROR);
304 return;
305 }
306 ptr = (DSO_VMS_INTERNAL *)sk_value(dso->meth_data,
307 sk_num(dso->meth_data) - 1);
308 if(ptr == NULL)
309 {
310 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_NULL_HANDLE);
311 return;
312 }
313
314 if(dso->flags & DSO_FLAG_UPCASE_SYMBOL) flags = 0;
315
316 status = do_find_symbol(ptr, &symname_dsc, sym, flags);
317
318 if(!$VMS_STATUS_SUCCESS(status))
319 {
320 unsigned short length;
321 char errstring[257];
322 struct dsc$descriptor_s errstring_dsc;
323
324 errstring_dsc.dsc$w_length = sizeof(errstring);
325 errstring_dsc.dsc$b_dtype = DSC$K_DTYPE_T;
326 errstring_dsc.dsc$b_class = DSC$K_CLASS_S;
327 errstring_dsc.dsc$a_pointer = errstring;
328
329 *sym = NULL;
330
331 status = sys$getmsg(status, &length, &errstring_dsc, 1, 0);
332
333 if (!$VMS_STATUS_SUCCESS(status))
334 lib$signal(status); /* This is really bad. Abort! */
335 else
336 {
337 errstring[length] = '\0';
338
339 DSOerr(DSO_F_VMS_BIND_VAR,DSO_R_SYM_FAILURE);
340 if (ptr->imagename_dsc.dsc$w_length)
341 ERR_add_error_data(9,
342 "Symbol ", symname,
343 " in ", ptr->filename,
344 " (", ptr->imagename, ")",
345 ": ", errstring);
346 else
347 ERR_add_error_data(6,
348 "Symbol ", symname,
349 " in ", ptr->filename,
350 ": ", errstring);
351 }
352 return;
353 }
354 return;
355 }
356
357static void *vms_bind_var(DSO *dso, const char *symname)
358 {
359 void *sym = 0;
360 vms_bind_sym(dso, symname, &sym);
361 return sym;
362 }
363
364static DSO_FUNC_TYPE vms_bind_func(DSO *dso, const char *symname)
365 {
366 DSO_FUNC_TYPE sym = 0;
367 vms_bind_sym(dso, symname, (void **)&sym);
368 return sym;
369 }
370
371static char *vms_name_converter(DSO *dso, const char *filename)
372 {
373 int len = strlen(filename);
374 char *not_translated = OPENSSL_malloc(len+1);
375 strcpy(not_translated,filename);
376 return(not_translated);
377 }
378
379#endif /* OPENSSL_SYS_VMS */
diff --git a/src/lib/libcrypto/dso/dso_win32.c b/src/lib/libcrypto/dso/dso_win32.c
new file mode 100644
index 0000000000..cc4ac68696
--- /dev/null
+++ b/src/lib/libcrypto/dso/dso_win32.c
@@ -0,0 +1,298 @@
1/* dso_win32.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63
64#if !defined(DSO_WIN32)
65DSO_METHOD *DSO_METHOD_win32(void)
66 {
67 return NULL;
68 }
69#else
70
71#ifdef _WIN32_WCE
72# if _WIN32_WCE < 300
73static FARPROC GetProcAddressA(HMODULE hModule,LPCSTR lpProcName)
74 {
75 WCHAR lpProcNameW[64];
76 int i;
77
78 for (i=0;lpProcName[i] && i<64;i++)
79 lpProcNameW[i] = (WCHAR)lpProcName[i];
80 if (i==64) return NULL;
81 lpProcNameW[i] = 0;
82
83 return GetProcAddressW(hModule,lpProcNameW);
84 }
85# endif
86# undef GetProcAddress
87# define GetProcAddress GetProcAddressA
88#endif
89
90/* Part of the hack in "win32_load" ... */
91#define DSO_MAX_TRANSLATED_SIZE 256
92
93static int win32_load(DSO *dso);
94static int win32_unload(DSO *dso);
95static void *win32_bind_var(DSO *dso, const char *symname);
96static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname);
97#if 0
98static int win32_unbind_var(DSO *dso, char *symname, void *symptr);
99static int win32_unbind_func(DSO *dso, char *symname, DSO_FUNC_TYPE symptr);
100static int win32_init(DSO *dso);
101static int win32_finish(DSO *dso);
102static long win32_ctrl(DSO *dso, int cmd, long larg, void *parg);
103#endif
104static char *win32_name_converter(DSO *dso, const char *filename);
105
106static DSO_METHOD dso_meth_win32 = {
107 "OpenSSL 'win32' shared library method",
108 win32_load,
109 win32_unload,
110 win32_bind_var,
111 win32_bind_func,
112/* For now, "unbind" doesn't exist */
113#if 0
114 NULL, /* unbind_var */
115 NULL, /* unbind_func */
116#endif
117 NULL, /* ctrl */
118 win32_name_converter,
119 NULL, /* init */
120 NULL /* finish */
121 };
122
123DSO_METHOD *DSO_METHOD_win32(void)
124 {
125 return(&dso_meth_win32);
126 }
127
128/* For this DSO_METHOD, our meth_data STACK will contain;
129 * (i) a pointer to the handle (HINSTANCE) returned from
130 * LoadLibrary(), and copied.
131 */
132
133static int win32_load(DSO *dso)
134 {
135 HINSTANCE h = NULL, *p = NULL;
136 /* See applicable comments from dso_dl.c */
137 char *filename = DSO_convert_filename(dso, NULL);
138
139 if(filename == NULL)
140 {
141 DSOerr(DSO_F_WIN32_LOAD,DSO_R_NO_FILENAME);
142 goto err;
143 }
144 h = LoadLibraryA(filename);
145 if(h == NULL)
146 {
147 DSOerr(DSO_F_WIN32_LOAD,DSO_R_LOAD_FAILED);
148 ERR_add_error_data(3, "filename(", filename, ")");
149 goto err;
150 }
151 p = (HINSTANCE *)OPENSSL_malloc(sizeof(HINSTANCE));
152 if(p == NULL)
153 {
154 DSOerr(DSO_F_WIN32_LOAD,ERR_R_MALLOC_FAILURE);
155 goto err;
156 }
157 *p = h;
158 if(!sk_push(dso->meth_data, (char *)p))
159 {
160 DSOerr(DSO_F_WIN32_LOAD,DSO_R_STACK_ERROR);
161 goto err;
162 }
163 /* Success */
164 dso->loaded_filename = filename;
165 return(1);
166err:
167 /* Cleanup !*/
168 if(filename != NULL)
169 OPENSSL_free(filename);
170 if(p != NULL)
171 OPENSSL_free(p);
172 if(h != NULL)
173 FreeLibrary(h);
174 return(0);
175 }
176
177static int win32_unload(DSO *dso)
178 {
179 HINSTANCE *p;
180 if(dso == NULL)
181 {
182 DSOerr(DSO_F_WIN32_UNLOAD,ERR_R_PASSED_NULL_PARAMETER);
183 return(0);
184 }
185 if(sk_num(dso->meth_data) < 1)
186 return(1);
187 p = (HINSTANCE *)sk_pop(dso->meth_data);
188 if(p == NULL)
189 {
190 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_NULL_HANDLE);
191 return(0);
192 }
193 if(!FreeLibrary(*p))
194 {
195 DSOerr(DSO_F_WIN32_UNLOAD,DSO_R_UNLOAD_FAILED);
196 /* We should push the value back onto the stack in
197 * case of a retry. */
198 sk_push(dso->meth_data, (char *)p);
199 return(0);
200 }
201 /* Cleanup */
202 OPENSSL_free(p);
203 return(1);
204 }
205
206/* Using GetProcAddress for variables? TODO: Check this out in
207 * the Win32 API docs, there's probably a variant for variables. */
208static void *win32_bind_var(DSO *dso, const char *symname)
209 {
210 HINSTANCE *ptr;
211 void *sym;
212
213 if((dso == NULL) || (symname == NULL))
214 {
215 DSOerr(DSO_F_WIN32_BIND_VAR,ERR_R_PASSED_NULL_PARAMETER);
216 return(NULL);
217 }
218 if(sk_num(dso->meth_data) < 1)
219 {
220 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_STACK_ERROR);
221 return(NULL);
222 }
223 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
224 if(ptr == NULL)
225 {
226 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_NULL_HANDLE);
227 return(NULL);
228 }
229 sym = GetProcAddress(*ptr, symname);
230 if(sym == NULL)
231 {
232 DSOerr(DSO_F_WIN32_BIND_VAR,DSO_R_SYM_FAILURE);
233 ERR_add_error_data(3, "symname(", symname, ")");
234 return(NULL);
235 }
236 return(sym);
237 }
238
239static DSO_FUNC_TYPE win32_bind_func(DSO *dso, const char *symname)
240 {
241 HINSTANCE *ptr;
242 void *sym;
243
244 if((dso == NULL) || (symname == NULL))
245 {
246 DSOerr(DSO_F_WIN32_BIND_FUNC,ERR_R_PASSED_NULL_PARAMETER);
247 return(NULL);
248 }
249 if(sk_num(dso->meth_data) < 1)
250 {
251 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_STACK_ERROR);
252 return(NULL);
253 }
254 ptr = (HINSTANCE *)sk_value(dso->meth_data, sk_num(dso->meth_data) - 1);
255 if(ptr == NULL)
256 {
257 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_NULL_HANDLE);
258 return(NULL);
259 }
260 sym = GetProcAddress(*ptr, symname);
261 if(sym == NULL)
262 {
263 DSOerr(DSO_F_WIN32_BIND_FUNC,DSO_R_SYM_FAILURE);
264 ERR_add_error_data(3, "symname(", symname, ")");
265 return(NULL);
266 }
267 return((DSO_FUNC_TYPE)sym);
268 }
269
270static char *win32_name_converter(DSO *dso, const char *filename)
271 {
272 char *translated;
273 int len, transform;
274
275 len = strlen(filename);
276 transform = ((strstr(filename, "/") == NULL) &&
277 (strstr(filename, "\\") == NULL) &&
278 (strstr(filename, ":") == NULL));
279 if(transform)
280 /* We will convert this to "%s.dll" */
281 translated = OPENSSL_malloc(len + 5);
282 else
283 /* We will simply duplicate filename */
284 translated = OPENSSL_malloc(len + 1);
285 if(translated == NULL)
286 {
287 DSOerr(DSO_F_WIN32_NAME_CONVERTER,
288 DSO_R_NAME_TRANSLATION_FAILED);
289 return(NULL);
290 }
291 if(transform)
292 sprintf(translated, "%s.dll", filename);
293 else
294 sprintf(translated, "%s", filename);
295 return(translated);
296 }
297
298#endif /* OPENSSL_SYS_WIN32 */
diff --git a/src/lib/libcrypto/ebcdic.c b/src/lib/libcrypto/ebcdic.c
new file mode 100644
index 0000000000..d1bece87f7
--- /dev/null
+++ b/src/lib/libcrypto/ebcdic.c
@@ -0,0 +1,218 @@
1/* crypto/ebcdic.c */
2
3#ifdef CHARSET_EBCDIC
4#include "ebcdic.h"
5/* Initial Port for Apache-1.3 by <Martin.Kraemer@Mch.SNI.De>
6 * Adapted for OpenSSL-0.9.4 by <Martin.Kraemer@Mch.SNI.De>
7 */
8
9#ifdef _OSD_POSIX
10/*
11 "BS2000 OSD" is a POSIX subsystem on a main frame.
12 It is made by Siemens AG, Germany, for their BS2000 mainframe machines.
13 Within the POSIX subsystem, the same character set was chosen as in
14 "native BS2000", namely EBCDIC. (EDF04)
15
16 The name "ASCII" in these routines is misleading: actually, conversion
17 is not between EBCDIC and ASCII, but EBCDIC(EDF04) and ISO-8859.1;
18 that means that (western european) national characters are preserved.
19
20 This table is identical to the one used by rsh/rcp/ftp and other POSIX tools.
21*/
22
23/* Here's the bijective ebcdic-to-ascii table: */
24const unsigned char os_toascii[256] = {
25/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,
26 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
27/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,
28 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
29/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,
30 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
31/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,
32 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
33/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,
34 0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
35/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,
36 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
37/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,
38 0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
39/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,
40 0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
41/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
42 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
43/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,
44 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
45/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
46 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
47/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,
48 0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
49/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
50 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
51/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,
52 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
53/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
54 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
55/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
56 0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
57};
58
59
60/* The ascii-to-ebcdic table: */
61const unsigned char os_toebcdic[256] = {
62/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,
63 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
64/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,
65 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
66/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
67 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
68/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
69 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
70/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
71 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
72/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,
73 0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
74/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
75 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
76/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,
77 0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
78/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,
79 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
80/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,
81 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
82/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,
83 0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
84/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,
85 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
86/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,
87 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
88/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,
89 0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
90/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,
91 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
92/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,
93 0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
94};
95
96#else /*_OSD_POSIX*/
97
98/*
99This code does basic character mapping for IBM's TPF and OS/390 operating systems.
100It is a modified version of the BS2000 table.
101
102Bijective EBCDIC (character set IBM-1047) to US-ASCII table:
103This table is bijective - there are no ambigous or duplicate characters.
104*/
105const unsigned char os_toascii[256] = {
106 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f, /* 00-0f: */
107 0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
108 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97, /* 10-1f: */
109 0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
110 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b, /* 20-2f: */
111 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /* ................ */
112 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30-3f: */
113 0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /* ................ */
114 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, /* 40-4f: */
115 0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* ...........<(+| */
116 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, /* 50-5f: */
117 0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, /* &.........!$*);^ */
118 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, /* 60-6f: */
119 0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /* -/.........,%_>? */
120 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, /* 70-7f: */
121 0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /* .........`:#@'=" */
122 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80-8f: */
123 0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /* .abcdefghi...... */
124 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, /* 90-9f: */
125 0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /* .jklmnopqr...... */
126 0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* a0-af: */
127 0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, /* .~stuvwxyz...[.. */
128 0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, /* b0-bf: */
129 0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7, /* .............].. */
130 0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* c0-cf: */
131 0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /* {ABCDEFGHI...... */
132 0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, /* d0-df: */
133 0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, /* }JKLMNOPQR...... */
134 0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* e0-ef: */
135 0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /* \.STUVWXYZ...... */
136 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* f0-ff: */
137 0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f /* 0123456789...... */
138};
139
140
141/*
142The US-ASCII to EBCDIC (character set IBM-1047) table:
143This table is bijective (no ambiguous or duplicate characters)
144*/
145const unsigned char os_toebcdic[256] = {
146 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, /* 00-0f: */
147 0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */
148 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, /* 10-1f: */
149 0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */
150 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, /* 20-2f: */
151 0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
152 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 30-3f: */
153 0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /* 0123456789:;<=>? */
154 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 40-4f: */
155 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /* @ABCDEFGHIJKLMNO */
156 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, /* 50-5f: */
157 0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, /* PQRSTUVWXYZ[\]^_ */
158 0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60-6f: */
159 0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* `abcdefghijklmno */
160 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, /* 70-7f: */
161 0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, /* pqrstuvwxyz{|}~. */
162 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08, /* 80-8f: */
163 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /* ................ */
164 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17, /* 90-9f: */
165 0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0xff, /* ................ */
166 0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, /* a0-af: */
167 0xbb, 0xb4, 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, /* ................ */
168 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, /* b0-bf: */
169 0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /* ................ */
170 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, /* c0-cf: */
171 0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* ................ */
172 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, /* d0-df: */
173 0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xba, 0xae, 0x59, /* ................ */
174 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, /* e0-ef: */
175 0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* ................ */
176 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff: */
177 0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /* ................ */
178};
179#endif /*_OSD_POSIX*/
180
181/* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)
182 * dest and srce may be identical, or separate memory blocks, but
183 * should not overlap. These functions intentionally have an interface
184 * compatible to memcpy(3).
185 */
186
187void *
188ebcdic2ascii(void *dest, const void *srce, size_t count)
189{
190 unsigned char *udest = dest;
191 const unsigned char *usrce = srce;
192
193 while (count-- != 0) {
194 *udest++ = os_toascii[*usrce++];
195 }
196
197 return dest;
198}
199
200void *
201ascii2ebcdic(void *dest, const void *srce, size_t count)
202{
203 unsigned char *udest = dest;
204 const unsigned char *usrce = srce;
205
206 while (count-- != 0) {
207 *udest++ = os_toebcdic[*usrce++];
208 }
209
210 return dest;
211}
212
213#else /*CHARSET_EBCDIC*/
214#include <openssl/e_os2.h>
215#if defined(PEDANTIC) || defined(__DECC) || defined(OPENSSL_SYS_MACOSX)
216static void *dummy=&dummy;
217#endif
218#endif
diff --git a/src/lib/libcrypto/ebcdic.h b/src/lib/libcrypto/ebcdic.h
new file mode 100644
index 0000000000..6d65afcf9e
--- /dev/null
+++ b/src/lib/libcrypto/ebcdic.h
@@ -0,0 +1,19 @@
1/* crypto/ebcdic.h */
2
3#ifndef HEADER_EBCDIC_H
4#define HEADER_EBCDIC_H
5
6#include <sys/types.h>
7
8/* Avoid name clashes with other applications */
9#define os_toascii _openssl_os_toascii
10#define os_toebcdic _openssl_os_toebcdic
11#define ebcdic2ascii _openssl_ebcdic2ascii
12#define ascii2ebcdic _openssl_ascii2ebcdic
13
14extern const unsigned char os_toascii[256];
15extern const unsigned char os_toebcdic[256];
16void *ebcdic2ascii(void *dest, const void *srce, size_t count);
17void *ascii2ebcdic(void *dest, const void *srce, size_t count);
18
19#endif
diff --git a/src/lib/libcrypto/ec/Makefile b/src/lib/libcrypto/ec/Makefile
new file mode 100644
index 0000000000..42f7bb7fc8
--- /dev/null
+++ b/src/lib/libcrypto/ec/Makefile
@@ -0,0 +1,193 @@
1#
2# crypto/ec/Makefile
3#
4
5DIR= ec
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=ectest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= ec_lib.c ecp_smpl.c ecp_mont.c ecp_nist.c ec_cvt.c ec_mult.c\
21 ec_err.c ec_curve.c ec_check.c ec_print.c ec_asn1.c ec_key.c\
22 ec2_smpl.c ec2_smpt.c ec2_mult.c
23
24LIBOBJ= ec_lib.o ecp_smpl.o ecp_mont.o ecp_nist.o ec_cvt.o ec_mult.o\
25 ec_err.o ec_curve.o ec_check.o ec_print.o ec_asn1.o ec_key.o\
26 ec2_smpl.o ec2_mult.o
27
28SRC= $(LIBSRC)
29
30EXHEADER= ec.h
31HEADER= ec_lcl.h $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45files:
46 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
47
48links:
49 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
50 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
51 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
52
53install:
54 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
55 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
56 do \
57 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
58 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
59 done;
60
61tags:
62 ctags $(SRC)
63
64tests:
65
66lint:
67 lint -DLINT $(INCLUDES) $(SRC)>fluff
68
69depend:
70 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82ec2_mult.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
83ec2_mult.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
84ec2_mult.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
85ec2_mult.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
86ec2_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
87ec2_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
88ec2_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
89ec2_mult.o: ../../include/openssl/symhacks.h ec2_mult.c ec_lcl.h
90ec2_smpl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
91ec2_smpl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
92ec2_smpl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
93ec2_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
94ec2_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
95ec2_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96ec2_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
97ec2_smpl.o: ../../include/openssl/symhacks.h ec2_smpl.c ec2_smpt.c ec_lcl.h
98ec2_smpt.o: ec2_smpt.c
99ec_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
100ec_asn1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101ec_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102ec_asn1.o: ../../include/openssl/ec.h ../../include/openssl/err.h
103ec_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
104ec_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
105ec_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
106ec_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
107ec_asn1.o: ../../include/openssl/symhacks.h ec_asn1.c ec_lcl.h
108ec_check.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109ec_check.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
110ec_check.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
111ec_check.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
112ec_check.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
113ec_check.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114ec_check.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
115ec_check.o: ../../include/openssl/symhacks.h ec_check.c ec_lcl.h
116ec_curve.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
117ec_curve.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
118ec_curve.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
119ec_curve.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
120ec_curve.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
121ec_curve.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122ec_curve.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123ec_curve.o: ../../include/openssl/symhacks.h ec_curve.c ec_lcl.h
124ec_cvt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
125ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
126ec_cvt.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
127ec_cvt.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
128ec_cvt.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
129ec_cvt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130ec_cvt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
131ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h
132ec_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
133ec_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
134ec_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h
135ec_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
136ec_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
137ec_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
138ec_err.o: ../../include/openssl/symhacks.h ec_err.c
139ec_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
140ec_key.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
141ec_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
142ec_key.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
143ec_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
144ec_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
145ec_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
146ec_key.o: ../../include/openssl/symhacks.h ec_key.c ec_lcl.h
147ec_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
148ec_lib.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
149ec_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
150ec_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
151ec_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
152ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
153ec_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
154ec_lib.o: ../../include/openssl/symhacks.h ec_lcl.h ec_lib.c
155ec_mult.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
156ec_mult.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
157ec_mult.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
158ec_mult.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
159ec_mult.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
160ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
161ec_mult.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
162ec_mult.o: ../../include/openssl/symhacks.h ec_lcl.h ec_mult.c
163ec_print.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
164ec_print.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
165ec_print.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
166ec_print.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
167ec_print.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
168ec_print.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
169ec_print.o: ../../include/openssl/symhacks.h ec_lcl.h ec_print.c
170ecp_mont.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
171ecp_mont.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
172ecp_mont.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
173ecp_mont.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
174ecp_mont.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
175ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
176ecp_mont.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
177ecp_mont.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_mont.c
178ecp_nist.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
179ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
180ecp_nist.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
181ecp_nist.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
182ecp_nist.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
183ecp_nist.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
184ecp_nist.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
185ecp_nist.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_nist.c
186ecp_smpl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
187ecp_smpl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
188ecp_smpl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
189ecp_smpl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
190ecp_smpl.o: ../../include/openssl/obj_mac.h ../../include/openssl/opensslconf.h
191ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
192ecp_smpl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
193ecp_smpl.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_smpl.c
diff --git a/src/lib/libcrypto/ec/Makefile.ssl b/src/lib/libcrypto/ec/Makefile.ssl
new file mode 100644
index 0000000000..a2805c47a2
--- /dev/null
+++ b/src/lib/libcrypto/ec/Makefile.ssl
@@ -0,0 +1,128 @@
1#
2# crypto/ec/Makefile
3#
4
5DIR= ec
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=ectest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= ec_lib.c ecp_smpl.c ecp_mont.c ecp_recp.c ecp_nist.c ec_cvt.c ec_mult.c \
27 ec_err.c
28
29LIBOBJ= ec_lib.o ecp_smpl.o ecp_mont.o ecp_recp.o ecp_nist.o ec_cvt.o ec_mult.o \
30 ec_err.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= ec.h
35HEADER= ec_lcl.h $(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) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links:
53 @sh $(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) -- $(CFLAG) $(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 */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
82
83# DO NOT DELETE THIS LINE -- make depend depends on it.
84
85ec_cvt.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
86ec_cvt.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
87ec_cvt.o: ../../include/openssl/symhacks.h ec_cvt.c ec_lcl.h
88ec_err.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
89ec_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
90ec_err.o: ../../include/openssl/ec.h ../../include/openssl/err.h
91ec_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
92ec_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
93ec_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
94ec_err.o: ec_err.c
95ec_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
96ec_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
97ec_lib.o: ../../include/openssl/ec.h ../../include/openssl/err.h
98ec_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
99ec_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
100ec_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
101ec_lib.o: ec_lcl.h ec_lib.c
102ec_mult.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
103ec_mult.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
104ec_mult.o: ../../include/openssl/ec.h ../../include/openssl/err.h
105ec_mult.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
106ec_mult.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
107ec_mult.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
108ec_mult.o: ec_lcl.h ec_mult.c
109ecp_mont.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
110ecp_mont.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
111ecp_mont.o: ../../include/openssl/ec.h ../../include/openssl/err.h
112ecp_mont.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
113ecp_mont.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
114ecp_mont.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
115ecp_mont.o: ec_lcl.h ecp_mont.c
116ecp_nist.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
117ecp_nist.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
118ecp_nist.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_nist.c
119ecp_recp.o: ../../include/openssl/bn.h ../../include/openssl/e_os2.h
120ecp_recp.o: ../../include/openssl/ec.h ../../include/openssl/opensslconf.h
121ecp_recp.o: ../../include/openssl/symhacks.h ec_lcl.h ecp_recp.c
122ecp_smpl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
123ecp_smpl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
124ecp_smpl.o: ../../include/openssl/ec.h ../../include/openssl/err.h
125ecp_smpl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
126ecp_smpl.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
127ecp_smpl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
128ecp_smpl.o: ec_lcl.h ecp_smpl.c
diff --git a/src/lib/libcrypto/ec/ec.h b/src/lib/libcrypto/ec/ec.h
index 8bc2a235b1..6d6a9b7127 100644
--- a/src/lib/libcrypto/ec/ec.h
+++ b/src/lib/libcrypto/ec/ec.h
@@ -1,9 +1,6 @@
1/* crypto/ec/ec.h */ 1/* crypto/ec/ec.h */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,48 +52,22 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
66 *
67 * The elliptic curve binary polynomial software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71 55
72#ifndef HEADER_EC_H 56#ifndef HEADER_EC_H
73#define HEADER_EC_H 57#define HEADER_EC_H
74 58
75#include <openssl/opensslconf.h>
76
77#ifdef OPENSSL_NO_EC 59#ifdef OPENSSL_NO_EC
78#error EC is disabled. 60#error EC is disabled.
79#endif 61#endif
80 62
81#include <openssl/asn1.h>
82#include <openssl/symhacks.h>
83#ifndef OPENSSL_NO_DEPRECATED
84#include <openssl/bn.h> 63#include <openssl/bn.h>
85#endif 64#include <openssl/symhacks.h>
86 65
87#ifdef __cplusplus 66#ifdef __cplusplus
88extern "C" { 67extern "C" {
89#elif defined(__SUNPRO_C)
90# if __SUNPRO_C >= 0x520
91# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
92# endif
93#endif 68#endif
94 69
95 70
96#ifndef OPENSSL_ECC_MAX_FIELD_BITS
97# define OPENSSL_ECC_MAX_FIELD_BITS 661
98#endif
99
100typedef enum { 71typedef enum {
101 /* values as defined in X9.62 (ECDSA) and elsewhere */ 72 /* values as defined in X9.62 (ECDSA) and elsewhere */
102 POINT_CONVERSION_COMPRESSED = 2, 73 POINT_CONVERSION_COMPRESSED = 2,
@@ -113,8 +84,7 @@ typedef struct ec_group_st
113 -- field definition 84 -- field definition
114 -- curve coefficients 85 -- curve coefficients
115 -- optional generator with associated information (order, cofactor) 86 -- optional generator with associated information (order, cofactor)
116 -- optional extra data (precomputed table for fast computation of multiples of generator) 87 -- optional extra data (TODO: precomputed table for fast computation of multiples of generator)
117 -- ASN1 stuff
118 */ 88 */
119 EC_GROUP; 89 EC_GROUP;
120 90
@@ -126,84 +96,40 @@ typedef struct ec_point_st EC_POINT;
126 */ 96 */
127const EC_METHOD *EC_GFp_simple_method(void); 97const EC_METHOD *EC_GFp_simple_method(void);
128const EC_METHOD *EC_GFp_mont_method(void); 98const EC_METHOD *EC_GFp_mont_method(void);
129const EC_METHOD *EC_GFp_nist_method(void); 99#if 0
130 100const EC_METHOD *EC_GFp_recp_method(void); /* TODO */
131/* EC_METHOD for curves over GF(2^m). 101const EC_METHOD *EC_GFp_nist_method(void); /* TODO */
132 */ 102#endif
133const EC_METHOD *EC_GF2m_simple_method(void);
134 103
135 104
136EC_GROUP *EC_GROUP_new(const EC_METHOD *); 105EC_GROUP *EC_GROUP_new(const EC_METHOD *);
137void EC_GROUP_free(EC_GROUP *); 106void EC_GROUP_free(EC_GROUP *);
138void EC_GROUP_clear_free(EC_GROUP *); 107void EC_GROUP_clear_free(EC_GROUP *);
139int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *); 108int EC_GROUP_copy(EC_GROUP *, const EC_GROUP *);
140EC_GROUP *EC_GROUP_dup(const EC_GROUP *);
141 109
142const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *); 110const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *);
143int EC_METHOD_get_field_type(const EC_METHOD *); 111
144
145int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
146const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
147int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
148int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
149
150void EC_GROUP_set_curve_name(EC_GROUP *, int nid);
151int EC_GROUP_get_curve_name(const EC_GROUP *);
152
153void EC_GROUP_set_asn1_flag(EC_GROUP *, int flag);
154int EC_GROUP_get_asn1_flag(const EC_GROUP *);
155
156void EC_GROUP_set_point_conversion_form(EC_GROUP *, point_conversion_form_t);
157point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *);
158
159unsigned char *EC_GROUP_get0_seed(const EC_GROUP *);
160size_t EC_GROUP_get_seed_len(const EC_GROUP *);
161size_t EC_GROUP_set_seed(EC_GROUP *, const unsigned char *, size_t len);
162 112
113/* We don't have types for field specifications and field elements in general.
114 * Otherwise we could declare
115 * int EC_GROUP_set_curve(EC_GROUP *, .....);
116 */
163int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 117int EC_GROUP_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
164int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 118int EC_GROUP_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
165int EC_GROUP_set_curve_GF2m(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
166int EC_GROUP_get_curve_GF2m(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
167
168/* returns the number of bits needed to represent a field element */
169int EC_GROUP_get_degree(const EC_GROUP *);
170
171/* EC_GROUP_check() returns 1 if 'group' defines a valid group, 0 otherwise */
172int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx);
173/* EC_GROUP_check_discriminant() returns 1 if the discriminant of the
174 * elliptic curve is not zero, 0 otherwise */
175int EC_GROUP_check_discriminant(const EC_GROUP *, BN_CTX *);
176 119
177/* EC_GROUP_cmp() returns 0 if both groups are equal and 1 otherwise */ 120/* EC_GROUP_new_GFp() calls EC_GROUP_new() and EC_GROUP_set_GFp()
178int EC_GROUP_cmp(const EC_GROUP *, const EC_GROUP *, BN_CTX *);
179
180/* EC_GROUP_new_GF*() calls EC_GROUP_new() and EC_GROUP_set_GF*()
181 * after choosing an appropriate EC_METHOD */ 121 * after choosing an appropriate EC_METHOD */
182EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 122EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
183EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
184
185/* EC_GROUP_new_by_curve_name() creates a EC_GROUP structure
186 * specified by a curve name (in form of a NID) */
187EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
188/* handling of internal curves */
189typedef struct {
190 int nid;
191 const char *comment;
192 } EC_builtin_curve;
193/* EC_builtin_curves(EC_builtin_curve *r, size_t size) returns number
194 * of all available curves or zero if a error occurred.
195 * In case r ist not zero nitems EC_builtin_curve structures
196 * are filled with the data of the first nitems internal groups */
197size_t EC_get_builtin_curves(EC_builtin_curve *r, size_t nitems);
198 123
199 124int EC_GROUP_set_generator(EC_GROUP *, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor);
200/* EC_POINT functions */ 125EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *);
126int EC_GROUP_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
127int EC_GROUP_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
201 128
202EC_POINT *EC_POINT_new(const EC_GROUP *); 129EC_POINT *EC_POINT_new(const EC_GROUP *);
203void EC_POINT_free(EC_POINT *); 130void EC_POINT_free(EC_POINT *);
204void EC_POINT_clear_free(EC_POINT *); 131void EC_POINT_clear_free(EC_POINT *);
205int EC_POINT_copy(EC_POINT *, const EC_POINT *); 132int EC_POINT_copy(EC_POINT *, const EC_POINT *);
206EC_POINT *EC_POINT_dup(const EC_POINT *, const EC_GROUP *);
207 133
208const EC_METHOD *EC_POINT_method_of(const EC_POINT *); 134const EC_METHOD *EC_POINT_method_of(const EC_POINT *);
209 135
@@ -219,28 +145,11 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
219int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *, 145int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
220 const BIGNUM *x, int y_bit, BN_CTX *); 146 const BIGNUM *x, int y_bit, BN_CTX *);
221 147
222int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
223 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
224int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *, const EC_POINT *,
225 BIGNUM *x, BIGNUM *y, BN_CTX *);
226int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *, EC_POINT *,
227 const BIGNUM *x, int y_bit, BN_CTX *);
228
229size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 148size_t EC_POINT_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
230 unsigned char *buf, size_t len, BN_CTX *); 149 unsigned char *buf, size_t len, BN_CTX *);
231int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *, 150int EC_POINT_oct2point(const EC_GROUP *, EC_POINT *,
232 const unsigned char *buf, size_t len, BN_CTX *); 151 const unsigned char *buf, size_t len, BN_CTX *);
233 152
234/* other interfaces to point2oct/oct2point: */
235BIGNUM *EC_POINT_point2bn(const EC_GROUP *, const EC_POINT *,
236 point_conversion_form_t form, BIGNUM *, BN_CTX *);
237EC_POINT *EC_POINT_bn2point(const EC_GROUP *, const BIGNUM *,
238 EC_POINT *, BN_CTX *);
239char *EC_POINT_point2hex(const EC_GROUP *, const EC_POINT *,
240 point_conversion_form_t form, BN_CTX *);
241EC_POINT *EC_POINT_hex2point(const EC_GROUP *, const char *,
242 EC_POINT *, BN_CTX *);
243
244int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *); 153int EC_POINT_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
245int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *); 154int EC_POINT_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
246int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); 155int EC_POINT_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
@@ -255,112 +164,9 @@ int EC_POINTs_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
255 164
256int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *); 165int EC_POINTs_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, size_t num, const EC_POINT *[], const BIGNUM *[], BN_CTX *);
257int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *); 166int EC_POINT_mul(const EC_GROUP *, EC_POINT *r, const BIGNUM *, const EC_POINT *, const BIGNUM *, BN_CTX *);
258
259/* EC_GROUP_precompute_mult() stores multiples of generator for faster point multiplication */
260int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *); 167int EC_GROUP_precompute_mult(EC_GROUP *, BN_CTX *);
261/* EC_GROUP_have_precompute_mult() reports whether such precomputation has been done */
262int EC_GROUP_have_precompute_mult(const EC_GROUP *);
263
264
265 168
266/* ASN1 stuff */
267 169
268/* EC_GROUP_get_basis_type() returns the NID of the basis type
269 * used to represent the field elements */
270int EC_GROUP_get_basis_type(const EC_GROUP *);
271int EC_GROUP_get_trinomial_basis(const EC_GROUP *, unsigned int *k);
272int EC_GROUP_get_pentanomial_basis(const EC_GROUP *, unsigned int *k1,
273 unsigned int *k2, unsigned int *k3);
274
275#define OPENSSL_EC_NAMED_CURVE 0x001
276
277typedef struct ecpk_parameters_st ECPKPARAMETERS;
278
279EC_GROUP *d2i_ECPKParameters(EC_GROUP **, const unsigned char **in, long len);
280int i2d_ECPKParameters(const EC_GROUP *, unsigned char **out);
281
282#define d2i_ECPKParameters_bio(bp,x) ASN1_d2i_bio_of(EC_GROUP,NULL,d2i_ECPKParameters,bp,x)
283#define i2d_ECPKParameters_bio(bp,x) ASN1_i2d_bio_of_const(EC_GROUP,i2d_ECPKParameters,bp,x)
284#define d2i_ECPKParameters_fp(fp,x) (EC_GROUP *)ASN1_d2i_fp(NULL, \
285 (char *(*)())d2i_ECPKParameters,(fp),(unsigned char **)(x))
286#define i2d_ECPKParameters_fp(fp,x) ASN1_i2d_fp(i2d_ECPKParameters,(fp), \
287 (unsigned char *)(x))
288
289#ifndef OPENSSL_NO_BIO
290int ECPKParameters_print(BIO *bp, const EC_GROUP *x, int off);
291#endif
292#ifndef OPENSSL_NO_FP_API
293int ECPKParameters_print_fp(FILE *fp, const EC_GROUP *x, int off);
294#endif
295
296/* the EC_KEY stuff */
297typedef struct ec_key_st EC_KEY;
298
299/* some values for the encoding_flag */
300#define EC_PKEY_NO_PARAMETERS 0x001
301#define EC_PKEY_NO_PUBKEY 0x002
302
303EC_KEY *EC_KEY_new(void);
304EC_KEY *EC_KEY_new_by_curve_name(int nid);
305void EC_KEY_free(EC_KEY *);
306EC_KEY *EC_KEY_copy(EC_KEY *, const EC_KEY *);
307EC_KEY *EC_KEY_dup(const EC_KEY *);
308
309int EC_KEY_up_ref(EC_KEY *);
310
311const EC_GROUP *EC_KEY_get0_group(const EC_KEY *);
312int EC_KEY_set_group(EC_KEY *, const EC_GROUP *);
313const BIGNUM *EC_KEY_get0_private_key(const EC_KEY *);
314int EC_KEY_set_private_key(EC_KEY *, const BIGNUM *);
315const EC_POINT *EC_KEY_get0_public_key(const EC_KEY *);
316int EC_KEY_set_public_key(EC_KEY *, const EC_POINT *);
317unsigned EC_KEY_get_enc_flags(const EC_KEY *);
318void EC_KEY_set_enc_flags(EC_KEY *, unsigned int);
319point_conversion_form_t EC_KEY_get_conv_form(const EC_KEY *);
320void EC_KEY_set_conv_form(EC_KEY *, point_conversion_form_t);
321/* functions to set/get method specific data */
322void *EC_KEY_get_key_method_data(EC_KEY *,
323 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
324void EC_KEY_insert_key_method_data(EC_KEY *, void *data,
325 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
326/* wrapper functions for the underlying EC_GROUP object */
327void EC_KEY_set_asn1_flag(EC_KEY *, int);
328int EC_KEY_precompute_mult(EC_KEY *, BN_CTX *ctx);
329
330/* EC_KEY_generate_key() creates a ec private (public) key */
331int EC_KEY_generate_key(EC_KEY *);
332/* EC_KEY_check_key() */
333int EC_KEY_check_key(const EC_KEY *);
334
335/* de- and encoding functions for SEC1 ECPrivateKey */
336EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len);
337int i2d_ECPrivateKey(EC_KEY *a, unsigned char **out);
338/* de- and encoding functions for EC parameters */
339EC_KEY *d2i_ECParameters(EC_KEY **a, const unsigned char **in, long len);
340int i2d_ECParameters(EC_KEY *a, unsigned char **out);
341/* de- and encoding functions for EC public key
342 * (octet string, not DER -- hence 'o2i' and 'i2o') */
343EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len);
344int i2o_ECPublicKey(EC_KEY *a, unsigned char **out);
345
346#ifndef OPENSSL_NO_BIO
347int ECParameters_print(BIO *bp, const EC_KEY *x);
348int EC_KEY_print(BIO *bp, const EC_KEY *x, int off);
349#endif
350#ifndef OPENSSL_NO_FP_API
351int ECParameters_print_fp(FILE *fp, const EC_KEY *x);
352int EC_KEY_print_fp(FILE *fp, const EC_KEY *x, int off);
353#endif
354
355#define ECParameters_dup(x) ASN1_dup_of(EC_KEY,i2d_ECParameters,d2i_ECParameters,x)
356
357#ifndef __cplusplus
358#if defined(__SUNPRO_C)
359# if __SUNPRO_C >= 0x520
360# pragma error_messages (default,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
361# endif
362# endif
363#endif
364 170
365/* BEGIN ERROR CODES */ 171/* BEGIN ERROR CODES */
366/* The following lines are auto generated by the script mkerr.pl. Any changes 172/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -372,124 +178,51 @@ void ERR_load_EC_strings(void);
372 178
373/* Function codes. */ 179/* Function codes. */
374#define EC_F_COMPUTE_WNAF 143 180#define EC_F_COMPUTE_WNAF 143
375#define EC_F_D2I_ECPARAMETERS 144
376#define EC_F_D2I_ECPKPARAMETERS 145
377#define EC_F_D2I_ECPRIVATEKEY 146
378#define EC_F_ECPARAMETERS_PRINT 147
379#define EC_F_ECPARAMETERS_PRINT_FP 148
380#define EC_F_ECPKPARAMETERS_PRINT 149
381#define EC_F_ECPKPARAMETERS_PRINT_FP 150
382#define EC_F_ECP_NIST_MOD_192 203
383#define EC_F_ECP_NIST_MOD_224 204
384#define EC_F_ECP_NIST_MOD_256 205
385#define EC_F_ECP_NIST_MOD_521 206
386#define EC_F_EC_ASN1_GROUP2CURVE 153
387#define EC_F_EC_ASN1_GROUP2FIELDID 154
388#define EC_F_EC_ASN1_GROUP2PARAMETERS 155
389#define EC_F_EC_ASN1_GROUP2PKPARAMETERS 156
390#define EC_F_EC_ASN1_PARAMETERS2GROUP 157
391#define EC_F_EC_ASN1_PKPARAMETERS2GROUP 158
392#define EC_F_EC_EX_DATA_SET_DATA 211
393#define EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY 208
394#define EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT 159
395#define EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE 195
396#define EC_F_EC_GF2M_SIMPLE_OCT2POINT 160
397#define EC_F_EC_GF2M_SIMPLE_POINT2OCT 161
398#define EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES 162
399#define EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES 163
400#define EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES 164
401#define EC_F_EC_GFP_MONT_FIELD_DECODE 133 181#define EC_F_EC_GFP_MONT_FIELD_DECODE 133
402#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134 182#define EC_F_EC_GFP_MONT_FIELD_ENCODE 134
403#define EC_F_EC_GFP_MONT_FIELD_MUL 131 183#define EC_F_EC_GFP_MONT_FIELD_MUL 131
404#define EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE 209
405#define EC_F_EC_GFP_MONT_FIELD_SQR 132 184#define EC_F_EC_GFP_MONT_FIELD_SQR 132
406#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE 189
407#define EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP 135
408#define EC_F_EC_GFP_NIST_FIELD_MUL 200
409#define EC_F_EC_GFP_NIST_FIELD_SQR 201
410#define EC_F_EC_GFP_NIST_GROUP_SET_CURVE 202
411#define EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT 165
412#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE 166
413#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100 185#define EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP 100
414#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101 186#define EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR 101
415#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102 187#define EC_F_EC_GFP_SIMPLE_MAKE_AFFINE 102
416#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103 188#define EC_F_EC_GFP_SIMPLE_OCT2POINT 103
417#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104 189#define EC_F_EC_GFP_SIMPLE_POINT2OCT 104
418#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137 190#define EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE 137
419#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES 167
420#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105 191#define EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP 105
421#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES 168
422#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128 192#define EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP 128
423#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES 169
424#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129 193#define EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP 129
425#define EC_F_EC_GROUP_CHECK 170
426#define EC_F_EC_GROUP_CHECK_DISCRIMINANT 171
427#define EC_F_EC_GROUP_COPY 106 194#define EC_F_EC_GROUP_COPY 106
428#define EC_F_EC_GROUP_GET0_GENERATOR 139 195#define EC_F_EC_GROUP_GET0_GENERATOR 139
429#define EC_F_EC_GROUP_GET_COFACTOR 140 196#define EC_F_EC_GROUP_GET_COFACTOR 140
430#define EC_F_EC_GROUP_GET_CURVE_GF2M 172
431#define EC_F_EC_GROUP_GET_CURVE_GFP 130 197#define EC_F_EC_GROUP_GET_CURVE_GFP 130
432#define EC_F_EC_GROUP_GET_DEGREE 173
433#define EC_F_EC_GROUP_GET_ORDER 141 198#define EC_F_EC_GROUP_GET_ORDER 141
434#define EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS 193
435#define EC_F_EC_GROUP_GET_TRINOMIAL_BASIS 194
436#define EC_F_EC_GROUP_NEW 108 199#define EC_F_EC_GROUP_NEW 108
437#define EC_F_EC_GROUP_NEW_BY_CURVE_NAME 174
438#define EC_F_EC_GROUP_NEW_FROM_DATA 175
439#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142 200#define EC_F_EC_GROUP_PRECOMPUTE_MULT 142
440#define EC_F_EC_GROUP_SET_CURVE_GF2M 176
441#define EC_F_EC_GROUP_SET_CURVE_GFP 109 201#define EC_F_EC_GROUP_SET_CURVE_GFP 109
442#define EC_F_EC_GROUP_SET_EXTRA_DATA 110 202#define EC_F_EC_GROUP_SET_EXTRA_DATA 110
443#define EC_F_EC_GROUP_SET_GENERATOR 111 203#define EC_F_EC_GROUP_SET_GENERATOR 111
444#define EC_F_EC_KEY_CHECK_KEY 177
445#define EC_F_EC_KEY_COPY 178
446#define EC_F_EC_KEY_GENERATE_KEY 179
447#define EC_F_EC_KEY_NEW 182
448#define EC_F_EC_KEY_PRINT 180
449#define EC_F_EC_KEY_PRINT_FP 181
450#define EC_F_EC_POINTS_MAKE_AFFINE 136 204#define EC_F_EC_POINTS_MAKE_AFFINE 136
451#define EC_F_EC_POINTS_MUL 138 205#define EC_F_EC_POINTS_MUL 138
452#define EC_F_EC_POINT_ADD 112 206#define EC_F_EC_POINT_ADD 112
453#define EC_F_EC_POINT_CMP 113 207#define EC_F_EC_POINT_CMP 113
454#define EC_F_EC_POINT_COPY 114 208#define EC_F_EC_POINT_COPY 114
455#define EC_F_EC_POINT_DBL 115 209#define EC_F_EC_POINT_DBL 115
456#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M 183
457#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116 210#define EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP 116
458#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117 211#define EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP 117
459#define EC_F_EC_POINT_INVERT 210
460#define EC_F_EC_POINT_IS_AT_INFINITY 118 212#define EC_F_EC_POINT_IS_AT_INFINITY 118
461#define EC_F_EC_POINT_IS_ON_CURVE 119 213#define EC_F_EC_POINT_IS_ON_CURVE 119
462#define EC_F_EC_POINT_MAKE_AFFINE 120 214#define EC_F_EC_POINT_MAKE_AFFINE 120
463#define EC_F_EC_POINT_MUL 184
464#define EC_F_EC_POINT_NEW 121 215#define EC_F_EC_POINT_NEW 121
465#define EC_F_EC_POINT_OCT2POINT 122 216#define EC_F_EC_POINT_OCT2POINT 122
466#define EC_F_EC_POINT_POINT2OCT 123 217#define EC_F_EC_POINT_POINT2OCT 123
467#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M 185
468#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124 218#define EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP 124
469#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M 186
470#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125 219#define EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP 125
471#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126 220#define EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP 126
472#define EC_F_EC_POINT_SET_TO_INFINITY 127 221#define EC_F_EC_POINT_SET_TO_INFINITY 127
473#define EC_F_EC_PRE_COMP_DUP 207 222#define EC_F_GFP_MONT_GROUP_SET_CURVE_GFP 135
474#define EC_F_EC_PRE_COMP_NEW 196
475#define EC_F_EC_WNAF_MUL 187
476#define EC_F_EC_WNAF_PRECOMPUTE_MULT 188
477#define EC_F_I2D_ECPARAMETERS 190
478#define EC_F_I2D_ECPKPARAMETERS 191
479#define EC_F_I2D_ECPRIVATEKEY 192
480#define EC_F_I2O_ECPUBLICKEY 151
481#define EC_F_O2I_ECPUBLICKEY 152
482 223
483/* Reason codes. */ 224/* Reason codes. */
484#define EC_R_ASN1_ERROR 115
485#define EC_R_ASN1_UNKNOWN_FIELD 116
486#define EC_R_BUFFER_TOO_SMALL 100 225#define EC_R_BUFFER_TOO_SMALL 100
487#define EC_R_D2I_ECPKPARAMETERS_FAILURE 117
488#define EC_R_DISCRIMINANT_IS_ZERO 118
489#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 119
490#define EC_R_FIELD_TOO_LARGE 138
491#define EC_R_GROUP2PKPARAMETERS_FAILURE 120
492#define EC_R_I2D_ECPKPARAMETERS_FAILURE 121
493#define EC_R_INCOMPATIBLE_OBJECTS 101 226#define EC_R_INCOMPATIBLE_OBJECTS 101
494#define EC_R_INVALID_ARGUMENT 112 227#define EC_R_INVALID_ARGUMENT 112
495#define EC_R_INVALID_COMPRESSED_POINT 110 228#define EC_R_INVALID_COMPRESSED_POINT 110
@@ -497,28 +230,12 @@ void ERR_load_EC_strings(void);
497#define EC_R_INVALID_ENCODING 102 230#define EC_R_INVALID_ENCODING 102
498#define EC_R_INVALID_FIELD 103 231#define EC_R_INVALID_FIELD 103
499#define EC_R_INVALID_FORM 104 232#define EC_R_INVALID_FORM 104
500#define EC_R_INVALID_GROUP_ORDER 122
501#define EC_R_INVALID_PENTANOMIAL_BASIS 132
502#define EC_R_INVALID_PRIVATE_KEY 123
503#define EC_R_INVALID_TRINOMIAL_BASIS 137
504#define EC_R_MISSING_PARAMETERS 124
505#define EC_R_MISSING_PRIVATE_KEY 125
506#define EC_R_NOT_A_NIST_PRIME 135
507#define EC_R_NOT_A_SUPPORTED_NIST_PRIME 136
508#define EC_R_NOT_IMPLEMENTED 126
509#define EC_R_NOT_INITIALIZED 111 233#define EC_R_NOT_INITIALIZED 111
510#define EC_R_NO_FIELD_MOD 133
511#define EC_R_PASSED_NULL_PARAMETER 134
512#define EC_R_PKPARAMETERS2GROUP_FAILURE 127
513#define EC_R_POINT_AT_INFINITY 106 234#define EC_R_POINT_AT_INFINITY 106
514#define EC_R_POINT_IS_NOT_ON_CURVE 107 235#define EC_R_POINT_IS_NOT_ON_CURVE 107
515#define EC_R_SLOT_FULL 108 236#define EC_R_SLOT_FULL 108
516#define EC_R_UNDEFINED_GENERATOR 113 237#define EC_R_UNDEFINED_GENERATOR 113
517#define EC_R_UNDEFINED_ORDER 128
518#define EC_R_UNKNOWN_GROUP 129
519#define EC_R_UNKNOWN_ORDER 114 238#define EC_R_UNKNOWN_ORDER 114
520#define EC_R_UNSUPPORTED_FIELD 131
521#define EC_R_WRONG_ORDER 130
522 239
523#ifdef __cplusplus 240#ifdef __cplusplus
524} 241}
diff --git a/src/lib/libcrypto/ec/ec2_smpt.c b/src/lib/libcrypto/ec/ec2_smpt.c
new file mode 100644
index 0000000000..59d52bf663
--- /dev/null
+++ b/src/lib/libcrypto/ec/ec2_smpt.c
@@ -0,0 +1,74 @@
1/* crypto/ec/ec2_smpt.c */
2/* This code was originally written by Douglas Stebila
3 * <dstebila@student.math.uwaterloo.ca> for the OpenSSL project.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59
60/* Calaculates and sets the affine coordinates of an EC_POINT from the given
61 * compressed coordinates. Uses algorithm 2.3.4 of SEC 1.
62 * Note that the simple implementation only uses affine coordinates.
63 *
64 * This algorithm is patented by Certicom Corp. under US Patent 6,141,420
65 * (for licensing information, contact licensing@certicom.com).
66 * This function is disabled by default and can be enabled by defining the
67 * preprocessor macro OPENSSL_EC_BIN_PT_COMP at Configure-time.
68 */
69int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
70 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
71 {
72 ECerr(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_DISABLED);
73 return 0;
74 }
diff --git a/src/lib/libcrypto/ec/ec_cvt.c b/src/lib/libcrypto/ec/ec_cvt.c
index d45640bab9..45b0ec33a0 100644
--- a/src/lib/libcrypto/ec/ec_cvt.c
+++ b/src/lib/libcrypto/ec/ec_cvt.c
@@ -1,9 +1,6 @@
1/* crypto/ec/ec_cvt.c */ 1/* crypto/ec/ec_cvt.c */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,21 +52,7 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
66 *
67 * The elliptic curve binary polynomial software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71 55
72#include <openssl/err.h>
73#include "ec_lcl.h" 56#include "ec_lcl.h"
74 57
75 58
@@ -77,64 +60,17 @@ EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM
77 { 60 {
78 const EC_METHOD *meth; 61 const EC_METHOD *meth;
79 EC_GROUP *ret; 62 EC_GROUP *ret;
80
81 meth = EC_GFp_nist_method();
82 63
83 ret = EC_GROUP_new(meth); 64 /* Finally, this will use EC_GFp_nist_method if 'p' is a special
84 if (ret == NULL) 65 * prime with optimized modular arithmetics (for NIST curves)
85 return NULL; 66 */
86 67 meth = EC_GFp_mont_method();
87 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
88 {
89 unsigned long err;
90
91 err = ERR_peek_last_error();
92
93 if (!(ERR_GET_LIB(err) == ERR_LIB_EC &&
94 ((ERR_GET_REASON(err) == EC_R_NOT_A_NIST_PRIME) ||
95 (ERR_GET_REASON(err) == EC_R_NOT_A_SUPPORTED_NIST_PRIME))))
96 {
97 /* real error */
98
99 EC_GROUP_clear_free(ret);
100 return NULL;
101 }
102
103
104 /* not an actual error, we just cannot use EC_GFp_nist_method */
105
106 ERR_clear_error();
107
108 EC_GROUP_clear_free(ret);
109 meth = EC_GFp_mont_method();
110
111 ret = EC_GROUP_new(meth);
112 if (ret == NULL)
113 return NULL;
114
115 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
116 {
117 EC_GROUP_clear_free(ret);
118 return NULL;
119 }
120 }
121
122 return ret;
123 }
124
125
126EC_GROUP *EC_GROUP_new_curve_GF2m(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
127 {
128 const EC_METHOD *meth;
129 EC_GROUP *ret;
130
131 meth = EC_GF2m_simple_method();
132 68
133 ret = EC_GROUP_new(meth); 69 ret = EC_GROUP_new(meth);
134 if (ret == NULL) 70 if (ret == NULL)
135 return NULL; 71 return NULL;
136 72
137 if (!EC_GROUP_set_curve_GF2m(ret, p, a, b, ctx)) 73 if (!EC_GROUP_set_curve_GFp(ret, p, a, b, ctx))
138 { 74 {
139 EC_GROUP_clear_free(ret); 75 EC_GROUP_clear_free(ret);
140 return NULL; 76 return NULL;
diff --git a/src/lib/libcrypto/ec/ec_err.c b/src/lib/libcrypto/ec/ec_err.c
index d04c895560..5b70f94382 100644
--- a/src/lib/libcrypto/ec/ec_err.c
+++ b/src/lib/libcrypto/ec/ec_err.c
@@ -1,6 +1,6 @@
1/* crypto/ec/ec_err.c */ 1/* crypto/ec/ec_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -71,127 +71,54 @@
71static ERR_STRING_DATA EC_str_functs[]= 71static ERR_STRING_DATA EC_str_functs[]=
72 { 72 {
73{ERR_FUNC(EC_F_COMPUTE_WNAF), "COMPUTE_WNAF"}, 73{ERR_FUNC(EC_F_COMPUTE_WNAF), "COMPUTE_WNAF"},
74{ERR_FUNC(EC_F_D2I_ECPARAMETERS), "d2i_ECParameters"},
75{ERR_FUNC(EC_F_D2I_ECPKPARAMETERS), "d2i_ECPKParameters"},
76{ERR_FUNC(EC_F_D2I_ECPRIVATEKEY), "d2i_ECPrivateKey"},
77{ERR_FUNC(EC_F_ECPARAMETERS_PRINT), "ECParameters_print"},
78{ERR_FUNC(EC_F_ECPARAMETERS_PRINT_FP), "ECParameters_print_fp"},
79{ERR_FUNC(EC_F_ECPKPARAMETERS_PRINT), "ECPKParameters_print"},
80{ERR_FUNC(EC_F_ECPKPARAMETERS_PRINT_FP), "ECPKParameters_print_fp"},
81{ERR_FUNC(EC_F_ECP_NIST_MOD_192), "ECP_NIST_MOD_192"},
82{ERR_FUNC(EC_F_ECP_NIST_MOD_224), "ECP_NIST_MOD_224"},
83{ERR_FUNC(EC_F_ECP_NIST_MOD_256), "ECP_NIST_MOD_256"},
84{ERR_FUNC(EC_F_ECP_NIST_MOD_521), "ECP_NIST_MOD_521"},
85{ERR_FUNC(EC_F_EC_ASN1_GROUP2CURVE), "EC_ASN1_GROUP2CURVE"},
86{ERR_FUNC(EC_F_EC_ASN1_GROUP2FIELDID), "EC_ASN1_GROUP2FIELDID"},
87{ERR_FUNC(EC_F_EC_ASN1_GROUP2PARAMETERS), "EC_ASN1_GROUP2PARAMETERS"},
88{ERR_FUNC(EC_F_EC_ASN1_GROUP2PKPARAMETERS), "EC_ASN1_GROUP2PKPARAMETERS"},
89{ERR_FUNC(EC_F_EC_ASN1_PARAMETERS2GROUP), "EC_ASN1_PARAMETERS2GROUP"},
90{ERR_FUNC(EC_F_EC_ASN1_PKPARAMETERS2GROUP), "EC_ASN1_PKPARAMETERS2GROUP"},
91{ERR_FUNC(EC_F_EC_EX_DATA_SET_DATA), "EC_EX_DATA_set_data"},
92{ERR_FUNC(EC_F_EC_GF2M_MONTGOMERY_POINT_MULTIPLY), "EC_GF2M_MONTGOMERY_POINT_MULTIPLY"},
93{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_GROUP_CHECK_DISCRIMINANT), "ec_GF2m_simple_group_check_discriminant"},
94{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_GROUP_SET_CURVE), "ec_GF2m_simple_group_set_curve"},
95{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_OCT2POINT), "ec_GF2m_simple_oct2point"},
96{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT2OCT), "ec_GF2m_simple_point2oct"},
97{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT_GET_AFFINE_COORDINATES), "ec_GF2m_simple_point_get_affine_coordinates"},
98{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_POINT_SET_AFFINE_COORDINATES), "ec_GF2m_simple_point_set_affine_coordinates"},
99{ERR_FUNC(EC_F_EC_GF2M_SIMPLE_SET_COMPRESSED_COORDINATES), "ec_GF2m_simple_set_compressed_coordinates"},
100{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_DECODE), "ec_GFp_mont_field_decode"}, 74{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_DECODE), "ec_GFp_mont_field_decode"},
101{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_ENCODE), "ec_GFp_mont_field_encode"}, 75{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_ENCODE), "ec_GFp_mont_field_encode"},
102{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_MUL), "ec_GFp_mont_field_mul"}, 76{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_MUL), "ec_GFp_mont_field_mul"},
103{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE), "ec_GFp_mont_field_set_to_one"},
104{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SQR), "ec_GFp_mont_field_sqr"}, 77{ERR_FUNC(EC_F_EC_GFP_MONT_FIELD_SQR), "ec_GFp_mont_field_sqr"},
105{ERR_FUNC(EC_F_EC_GFP_MONT_GROUP_SET_CURVE), "ec_GFp_mont_group_set_curve"}, 78{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP), "ec_GFp_simple_group_set_curve_GFp"},
106{ERR_FUNC(EC_F_EC_GFP_MONT_GROUP_SET_CURVE_GFP), "EC_GFP_MONT_GROUP_SET_CURVE_GFP"}, 79{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR), "ec_GFp_simple_group_set_generator"},
107{ERR_FUNC(EC_F_EC_GFP_NIST_FIELD_MUL), "ec_GFp_nist_field_mul"},
108{ERR_FUNC(EC_F_EC_GFP_NIST_FIELD_SQR), "ec_GFp_nist_field_sqr"},
109{ERR_FUNC(EC_F_EC_GFP_NIST_GROUP_SET_CURVE), "ec_GFp_nist_group_set_curve"},
110{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT), "ec_GFp_simple_group_check_discriminant"},
111{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE), "ec_GFp_simple_group_set_curve"},
112{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP), "EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP"},
113{ERR_FUNC(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR), "EC_GFP_SIMPLE_GROUP_SET_GENERATOR"},
114{ERR_FUNC(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE), "ec_GFp_simple_make_affine"}, 80{ERR_FUNC(EC_F_EC_GFP_SIMPLE_MAKE_AFFINE), "ec_GFp_simple_make_affine"},
115{ERR_FUNC(EC_F_EC_GFP_SIMPLE_OCT2POINT), "ec_GFp_simple_oct2point"}, 81{ERR_FUNC(EC_F_EC_GFP_SIMPLE_OCT2POINT), "ec_GFp_simple_oct2point"},
116{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT2OCT), "ec_GFp_simple_point2oct"}, 82{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT2OCT), "ec_GFp_simple_point2oct"},
117{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE), "ec_GFp_simple_points_make_affine"}, 83{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINTS_MAKE_AFFINE), "ec_GFp_simple_points_make_affine"},
118{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES), "ec_GFp_simple_point_get_affine_coordinates"}, 84{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP), "ec_GFp_simple_point_get_affine_coordinates_GFp"},
119{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP), "EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP"}, 85{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP), "ec_GFp_simple_point_set_affine_coordinates_GFp"},
120{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES), "ec_GFp_simple_point_set_affine_coordinates"}, 86{ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP), "ec_GFp_simple_set_compressed_coordinates_GFp"},
121{ERR_FUNC(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP), "EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP"},
122{ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES), "ec_GFp_simple_set_compressed_coordinates"},
123{ERR_FUNC(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP), "EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP"},
124{ERR_FUNC(EC_F_EC_GROUP_CHECK), "EC_GROUP_check"},
125{ERR_FUNC(EC_F_EC_GROUP_CHECK_DISCRIMINANT), "EC_GROUP_check_discriminant"},
126{ERR_FUNC(EC_F_EC_GROUP_COPY), "EC_GROUP_copy"}, 87{ERR_FUNC(EC_F_EC_GROUP_COPY), "EC_GROUP_copy"},
127{ERR_FUNC(EC_F_EC_GROUP_GET0_GENERATOR), "EC_GROUP_get0_generator"}, 88{ERR_FUNC(EC_F_EC_GROUP_GET0_GENERATOR), "EC_GROUP_get0_generator"},
128{ERR_FUNC(EC_F_EC_GROUP_GET_COFACTOR), "EC_GROUP_get_cofactor"}, 89{ERR_FUNC(EC_F_EC_GROUP_GET_COFACTOR), "EC_GROUP_get_cofactor"},
129{ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GF2M), "EC_GROUP_get_curve_GF2m"},
130{ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GFP), "EC_GROUP_get_curve_GFp"}, 90{ERR_FUNC(EC_F_EC_GROUP_GET_CURVE_GFP), "EC_GROUP_get_curve_GFp"},
131{ERR_FUNC(EC_F_EC_GROUP_GET_DEGREE), "EC_GROUP_get_degree"},
132{ERR_FUNC(EC_F_EC_GROUP_GET_ORDER), "EC_GROUP_get_order"}, 91{ERR_FUNC(EC_F_EC_GROUP_GET_ORDER), "EC_GROUP_get_order"},
133{ERR_FUNC(EC_F_EC_GROUP_GET_PENTANOMIAL_BASIS), "EC_GROUP_get_pentanomial_basis"},
134{ERR_FUNC(EC_F_EC_GROUP_GET_TRINOMIAL_BASIS), "EC_GROUP_get_trinomial_basis"},
135{ERR_FUNC(EC_F_EC_GROUP_NEW), "EC_GROUP_new"}, 92{ERR_FUNC(EC_F_EC_GROUP_NEW), "EC_GROUP_new"},
136{ERR_FUNC(EC_F_EC_GROUP_NEW_BY_CURVE_NAME), "EC_GROUP_new_by_curve_name"},
137{ERR_FUNC(EC_F_EC_GROUP_NEW_FROM_DATA), "EC_GROUP_NEW_FROM_DATA"},
138{ERR_FUNC(EC_F_EC_GROUP_PRECOMPUTE_MULT), "EC_GROUP_precompute_mult"}, 93{ERR_FUNC(EC_F_EC_GROUP_PRECOMPUTE_MULT), "EC_GROUP_precompute_mult"},
139{ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GF2M), "EC_GROUP_set_curve_GF2m"},
140{ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GFP), "EC_GROUP_set_curve_GFp"}, 94{ERR_FUNC(EC_F_EC_GROUP_SET_CURVE_GFP), "EC_GROUP_set_curve_GFp"},
141{ERR_FUNC(EC_F_EC_GROUP_SET_EXTRA_DATA), "EC_GROUP_SET_EXTRA_DATA"}, 95{ERR_FUNC(EC_F_EC_GROUP_SET_EXTRA_DATA), "EC_GROUP_set_extra_data"},
142{ERR_FUNC(EC_F_EC_GROUP_SET_GENERATOR), "EC_GROUP_set_generator"}, 96{ERR_FUNC(EC_F_EC_GROUP_SET_GENERATOR), "EC_GROUP_set_generator"},
143{ERR_FUNC(EC_F_EC_KEY_CHECK_KEY), "EC_KEY_check_key"},
144{ERR_FUNC(EC_F_EC_KEY_COPY), "EC_KEY_copy"},
145{ERR_FUNC(EC_F_EC_KEY_GENERATE_KEY), "EC_KEY_generate_key"},
146{ERR_FUNC(EC_F_EC_KEY_NEW), "EC_KEY_new"},
147{ERR_FUNC(EC_F_EC_KEY_PRINT), "EC_KEY_print"},
148{ERR_FUNC(EC_F_EC_KEY_PRINT_FP), "EC_KEY_print_fp"},
149{ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"}, 97{ERR_FUNC(EC_F_EC_POINTS_MAKE_AFFINE), "EC_POINTs_make_affine"},
150{ERR_FUNC(EC_F_EC_POINTS_MUL), "EC_POINTs_mul"}, 98{ERR_FUNC(EC_F_EC_POINTS_MUL), "EC_POINTs_mul"},
151{ERR_FUNC(EC_F_EC_POINT_ADD), "EC_POINT_add"}, 99{ERR_FUNC(EC_F_EC_POINT_ADD), "EC_POINT_add"},
152{ERR_FUNC(EC_F_EC_POINT_CMP), "EC_POINT_cmp"}, 100{ERR_FUNC(EC_F_EC_POINT_CMP), "EC_POINT_cmp"},
153{ERR_FUNC(EC_F_EC_POINT_COPY), "EC_POINT_copy"}, 101{ERR_FUNC(EC_F_EC_POINT_COPY), "EC_POINT_copy"},
154{ERR_FUNC(EC_F_EC_POINT_DBL), "EC_POINT_dbl"}, 102{ERR_FUNC(EC_F_EC_POINT_DBL), "EC_POINT_dbl"},
155{ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M), "EC_POINT_get_affine_coordinates_GF2m"},
156{ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP), "EC_POINT_get_affine_coordinates_GFp"}, 103{ERR_FUNC(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP), "EC_POINT_get_affine_coordinates_GFp"},
157{ERR_FUNC(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_get_Jprojective_coordinates_GFp"}, 104{ERR_FUNC(EC_F_EC_POINT_GET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_get_Jprojective_coordinates_GFp"},
158{ERR_FUNC(EC_F_EC_POINT_INVERT), "EC_POINT_invert"},
159{ERR_FUNC(EC_F_EC_POINT_IS_AT_INFINITY), "EC_POINT_is_at_infinity"}, 105{ERR_FUNC(EC_F_EC_POINT_IS_AT_INFINITY), "EC_POINT_is_at_infinity"},
160{ERR_FUNC(EC_F_EC_POINT_IS_ON_CURVE), "EC_POINT_is_on_curve"}, 106{ERR_FUNC(EC_F_EC_POINT_IS_ON_CURVE), "EC_POINT_is_on_curve"},
161{ERR_FUNC(EC_F_EC_POINT_MAKE_AFFINE), "EC_POINT_make_affine"}, 107{ERR_FUNC(EC_F_EC_POINT_MAKE_AFFINE), "EC_POINT_make_affine"},
162{ERR_FUNC(EC_F_EC_POINT_MUL), "EC_POINT_mul"},
163{ERR_FUNC(EC_F_EC_POINT_NEW), "EC_POINT_new"}, 108{ERR_FUNC(EC_F_EC_POINT_NEW), "EC_POINT_new"},
164{ERR_FUNC(EC_F_EC_POINT_OCT2POINT), "EC_POINT_oct2point"}, 109{ERR_FUNC(EC_F_EC_POINT_OCT2POINT), "EC_POINT_oct2point"},
165{ERR_FUNC(EC_F_EC_POINT_POINT2OCT), "EC_POINT_point2oct"}, 110{ERR_FUNC(EC_F_EC_POINT_POINT2OCT), "EC_POINT_point2oct"},
166{ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M), "EC_POINT_set_affine_coordinates_GF2m"},
167{ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP), "EC_POINT_set_affine_coordinates_GFp"}, 111{ERR_FUNC(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP), "EC_POINT_set_affine_coordinates_GFp"},
168{ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M), "EC_POINT_set_compressed_coordinates_GF2m"},
169{ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP), "EC_POINT_set_compressed_coordinates_GFp"}, 112{ERR_FUNC(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP), "EC_POINT_set_compressed_coordinates_GFp"},
170{ERR_FUNC(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_set_Jprojective_coordinates_GFp"}, 113{ERR_FUNC(EC_F_EC_POINT_SET_JPROJECTIVE_COORDINATES_GFP), "EC_POINT_set_Jprojective_coordinates_GFp"},
171{ERR_FUNC(EC_F_EC_POINT_SET_TO_INFINITY), "EC_POINT_set_to_infinity"}, 114{ERR_FUNC(EC_F_EC_POINT_SET_TO_INFINITY), "EC_POINT_set_to_infinity"},
172{ERR_FUNC(EC_F_EC_PRE_COMP_DUP), "EC_PRE_COMP_DUP"}, 115{ERR_FUNC(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP), "GFP_MONT_GROUP_SET_CURVE_GFP"},
173{ERR_FUNC(EC_F_EC_PRE_COMP_NEW), "EC_PRE_COMP_NEW"},
174{ERR_FUNC(EC_F_EC_WNAF_MUL), "ec_wNAF_mul"},
175{ERR_FUNC(EC_F_EC_WNAF_PRECOMPUTE_MULT), "ec_wNAF_precompute_mult"},
176{ERR_FUNC(EC_F_I2D_ECPARAMETERS), "i2d_ECParameters"},
177{ERR_FUNC(EC_F_I2D_ECPKPARAMETERS), "i2d_ECPKParameters"},
178{ERR_FUNC(EC_F_I2D_ECPRIVATEKEY), "i2d_ECPrivateKey"},
179{ERR_FUNC(EC_F_I2O_ECPUBLICKEY), "i2o_ECPublicKey"},
180{ERR_FUNC(EC_F_O2I_ECPUBLICKEY), "o2i_ECPublicKey"},
181{0,NULL} 116{0,NULL}
182 }; 117 };
183 118
184static ERR_STRING_DATA EC_str_reasons[]= 119static ERR_STRING_DATA EC_str_reasons[]=
185 { 120 {
186{ERR_REASON(EC_R_ASN1_ERROR) ,"asn1 error"},
187{ERR_REASON(EC_R_ASN1_UNKNOWN_FIELD) ,"asn1 unknown field"},
188{ERR_REASON(EC_R_BUFFER_TOO_SMALL) ,"buffer too small"}, 121{ERR_REASON(EC_R_BUFFER_TOO_SMALL) ,"buffer too small"},
189{ERR_REASON(EC_R_D2I_ECPKPARAMETERS_FAILURE),"d2i ecpkparameters failure"},
190{ERR_REASON(EC_R_DISCRIMINANT_IS_ZERO) ,"discriminant is zero"},
191{ERR_REASON(EC_R_EC_GROUP_NEW_BY_NAME_FAILURE),"ec group new by name failure"},
192{ERR_REASON(EC_R_FIELD_TOO_LARGE) ,"field too large"},
193{ERR_REASON(EC_R_GROUP2PKPARAMETERS_FAILURE),"group2pkparameters failure"},
194{ERR_REASON(EC_R_I2D_ECPKPARAMETERS_FAILURE),"i2d ecpkparameters failure"},
195{ERR_REASON(EC_R_INCOMPATIBLE_OBJECTS) ,"incompatible objects"}, 122{ERR_REASON(EC_R_INCOMPATIBLE_OBJECTS) ,"incompatible objects"},
196{ERR_REASON(EC_R_INVALID_ARGUMENT) ,"invalid argument"}, 123{ERR_REASON(EC_R_INVALID_ARGUMENT) ,"invalid argument"},
197{ERR_REASON(EC_R_INVALID_COMPRESSED_POINT),"invalid compressed point"}, 124{ERR_REASON(EC_R_INVALID_COMPRESSED_POINT),"invalid compressed point"},
@@ -199,28 +126,12 @@ static ERR_STRING_DATA EC_str_reasons[]=
199{ERR_REASON(EC_R_INVALID_ENCODING) ,"invalid encoding"}, 126{ERR_REASON(EC_R_INVALID_ENCODING) ,"invalid encoding"},
200{ERR_REASON(EC_R_INVALID_FIELD) ,"invalid field"}, 127{ERR_REASON(EC_R_INVALID_FIELD) ,"invalid field"},
201{ERR_REASON(EC_R_INVALID_FORM) ,"invalid form"}, 128{ERR_REASON(EC_R_INVALID_FORM) ,"invalid form"},
202{ERR_REASON(EC_R_INVALID_GROUP_ORDER) ,"invalid group order"},
203{ERR_REASON(EC_R_INVALID_PENTANOMIAL_BASIS),"invalid pentanomial basis"},
204{ERR_REASON(EC_R_INVALID_PRIVATE_KEY) ,"invalid private key"},
205{ERR_REASON(EC_R_INVALID_TRINOMIAL_BASIS),"invalid trinomial basis"},
206{ERR_REASON(EC_R_MISSING_PARAMETERS) ,"missing parameters"},
207{ERR_REASON(EC_R_MISSING_PRIVATE_KEY) ,"missing private key"},
208{ERR_REASON(EC_R_NOT_A_NIST_PRIME) ,"not a NIST prime"},
209{ERR_REASON(EC_R_NOT_A_SUPPORTED_NIST_PRIME),"not a supported NIST prime"},
210{ERR_REASON(EC_R_NOT_IMPLEMENTED) ,"not implemented"},
211{ERR_REASON(EC_R_NOT_INITIALIZED) ,"not initialized"}, 129{ERR_REASON(EC_R_NOT_INITIALIZED) ,"not initialized"},
212{ERR_REASON(EC_R_NO_FIELD_MOD) ,"no field mod"},
213{ERR_REASON(EC_R_PASSED_NULL_PARAMETER) ,"passed null parameter"},
214{ERR_REASON(EC_R_PKPARAMETERS2GROUP_FAILURE),"pkparameters2group failure"},
215{ERR_REASON(EC_R_POINT_AT_INFINITY) ,"point at infinity"}, 130{ERR_REASON(EC_R_POINT_AT_INFINITY) ,"point at infinity"},
216{ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE) ,"point is not on curve"}, 131{ERR_REASON(EC_R_POINT_IS_NOT_ON_CURVE) ,"point is not on curve"},
217{ERR_REASON(EC_R_SLOT_FULL) ,"slot full"}, 132{ERR_REASON(EC_R_SLOT_FULL) ,"slot full"},
218{ERR_REASON(EC_R_UNDEFINED_GENERATOR) ,"undefined generator"}, 133{ERR_REASON(EC_R_UNDEFINED_GENERATOR) ,"undefined generator"},
219{ERR_REASON(EC_R_UNDEFINED_ORDER) ,"undefined order"},
220{ERR_REASON(EC_R_UNKNOWN_GROUP) ,"unknown group"},
221{ERR_REASON(EC_R_UNKNOWN_ORDER) ,"unknown order"}, 134{ERR_REASON(EC_R_UNKNOWN_ORDER) ,"unknown order"},
222{ERR_REASON(EC_R_UNSUPPORTED_FIELD) ,"unsupported field"},
223{ERR_REASON(EC_R_WRONG_ORDER) ,"wrong order"},
224{0,NULL} 135{0,NULL}
225 }; 136 };
226 137
@@ -228,12 +139,15 @@ static ERR_STRING_DATA EC_str_reasons[]=
228 139
229void ERR_load_EC_strings(void) 140void ERR_load_EC_strings(void)
230 { 141 {
231#ifndef OPENSSL_NO_ERR 142 static int init=1;
232 143
233 if (ERR_func_error_string(EC_str_functs[0].error) == NULL) 144 if (init)
234 { 145 {
146 init=0;
147#ifndef OPENSSL_NO_ERR
235 ERR_load_strings(0,EC_str_functs); 148 ERR_load_strings(0,EC_str_functs);
236 ERR_load_strings(0,EC_str_reasons); 149 ERR_load_strings(0,EC_str_reasons);
237 }
238#endif 150#endif
151
152 }
239 } 153 }
diff --git a/src/lib/libcrypto/ec/ec_lcl.h b/src/lib/libcrypto/ec/ec_lcl.h
index fdd7aa2755..cc4cf27755 100644
--- a/src/lib/libcrypto/ec/ec_lcl.h
+++ b/src/lib/libcrypto/ec/ec_lcl.h
@@ -1,9 +1,6 @@
1/* crypto/ec/ec_lcl.h */ 1/* crypto/ec/ec_lcl.h */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,56 +52,35 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
66 *
67 * The elliptic curve binary polynomial software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71 55
72 56
73#include <stdlib.h> 57#include <stdlib.h>
74 58
75#include <openssl/obj_mac.h>
76#include <openssl/ec.h> 59#include <openssl/ec.h>
77#include <openssl/bn.h>
78 60
79#if defined(__SUNPRO_C)
80# if __SUNPRO_C >= 0x520
81# pragma error_messages (off,E_ARRAY_OF_INCOMPLETE_NONAME,E_ARRAY_OF_INCOMPLETE)
82# endif
83#endif
84 61
85/* Structure details are not part of the exported interface, 62/* Structure details are not part of the exported interface,
86 * so all this may change in future versions. */ 63 * so all this may change in future versions. */
87 64
88struct ec_method_st { 65struct ec_method_st {
89 /* used by EC_METHOD_get_field_type: */
90 int field_type; /* a NID */
91
92 /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */ 66 /* used by EC_GROUP_new, EC_GROUP_free, EC_GROUP_clear_free, EC_GROUP_copy: */
93 int (*group_init)(EC_GROUP *); 67 int (*group_init)(EC_GROUP *);
94 void (*group_finish)(EC_GROUP *); 68 void (*group_finish)(EC_GROUP *);
95 void (*group_clear_finish)(EC_GROUP *); 69 void (*group_clear_finish)(EC_GROUP *);
96 int (*group_copy)(EC_GROUP *, const EC_GROUP *); 70 int (*group_copy)(EC_GROUP *, const EC_GROUP *);
97 71
98 /* used by EC_GROUP_set_curve_GFp, EC_GROUP_get_curve_GFp, */ 72 /* used by EC_GROUP_set_curve_GFp and EC_GROUP_get_curve_GFp: */
99 /* EC_GROUP_set_curve_GF2m, and EC_GROUP_get_curve_GF2m: */ 73 int (*group_set_curve_GFp)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
100 int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 74 int (*group_get_curve_GFp)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
101 int (*group_get_curve)(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
102 75
103 /* used by EC_GROUP_get_degree: */ 76 /* used by EC_GROUP_set_generator, EC_GROUP_get0_generator,
104 int (*group_get_degree)(const EC_GROUP *); 77 * EC_GROUP_get_order, EC_GROUP_get_cofactor:
105 78 */
106 /* used by EC_GROUP_check: */ 79 int (*group_set_generator)(EC_GROUP *, const EC_POINT *generator,
107 int (*group_check_discriminant)(const EC_GROUP *, BN_CTX *); 80 const BIGNUM *order, const BIGNUM *cofactor);
81 EC_POINT *(*group_get0_generator)(const EC_GROUP *);
82 int (*group_get_order)(const EC_GROUP *, BIGNUM *order, BN_CTX *);
83 int (*group_get_cofactor)(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
108 84
109 /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */ 85 /* used by EC_POINT_new, EC_POINT_free, EC_POINT_clear_free, EC_POINT_copy: */
110 int (*point_init)(EC_POINT *); 86 int (*point_init)(EC_POINT *);
@@ -113,22 +89,20 @@ struct ec_method_st {
113 int (*point_copy)(EC_POINT *, const EC_POINT *); 89 int (*point_copy)(EC_POINT *, const EC_POINT *);
114 90
115 /* used by EC_POINT_set_to_infinity, 91 /* used by EC_POINT_set_to_infinity,
116 * EC_POINT_set_Jprojective_coordinates_GFp, 92 * EC_POINT_set_Jprojective_coordinates_GFp, EC_POINT_get_Jprojective_coordinates_GFp,
117 * EC_POINT_get_Jprojective_coordinates_GFp, 93 * EC_POINT_set_affine_coordinates_GFp, EC_POINT_get_affine_coordinates_GFp,
118 * EC_POINT_set_affine_coordinates_GFp, ..._GF2m, 94 * EC_POINT_set_compressed_coordinates_GFp:
119 * EC_POINT_get_affine_coordinates_GFp, ..._GF2m,
120 * EC_POINT_set_compressed_coordinates_GFp, ..._GF2m:
121 */ 95 */
122 int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *); 96 int (*point_set_to_infinity)(const EC_GROUP *, EC_POINT *);
123 int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *, 97 int (*point_set_Jprojective_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
124 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 98 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
125 int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *, 99 int (*point_get_Jprojective_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
126 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 100 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
127 int (*point_set_affine_coordinates)(const EC_GROUP *, EC_POINT *, 101 int (*point_set_affine_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
128 const BIGNUM *x, const BIGNUM *y, BN_CTX *); 102 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
129 int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, 103 int (*point_get_affine_coordinates_GFp)(const EC_GROUP *, const EC_POINT *,
130 BIGNUM *x, BIGNUM *y, BN_CTX *); 104 BIGNUM *x, BIGNUM *y, BN_CTX *);
131 int (*point_set_compressed_coordinates)(const EC_GROUP *, EC_POINT *, 105 int (*point_set_compressed_coordinates_GFp)(const EC_GROUP *, EC_POINT *,
132 const BIGNUM *x, int y_bit, BN_CTX *); 106 const BIGNUM *x, int y_bit, BN_CTX *);
133 107
134 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */ 108 /* used by EC_POINT_point2oct, EC_POINT_oct2point: */
@@ -151,65 +125,34 @@ struct ec_method_st {
151 int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *); 125 int (*make_affine)(const EC_GROUP *, EC_POINT *, BN_CTX *);
152 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *); 126 int (*points_make_affine)(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
153 127
154 /* used by EC_POINTs_mul, EC_POINT_mul, EC_POINT_precompute_mult, EC_POINT_have_precompute_mult
155 * (default implementations are used if the 'mul' pointer is 0): */
156 int (*mul)(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
157 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
158 int (*precompute_mult)(EC_GROUP *group, BN_CTX *);
159 int (*have_precompute_mult)(const EC_GROUP *group);
160
161 128
162 /* internal functions */ 129 /* internal functions */
163 130
164 /* 'field_mul', 'field_sqr', and 'field_div' can be used by 'add' and 'dbl' so that 131 /* 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that
165 * the same implementations of point operations can be used with different 132 * the same implementations of point operations can be used with different
166 * optimized implementations of expensive field operations: */ 133 * optimized implementations of expensive field operations: */
167 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 134 int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
168 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 135 int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
169 int (*field_div)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
170 136
171 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */ 137 int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. to Montgomery */
172 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */ 138 int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); /* e.g. from Montgomery */
173 int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *); 139 int (*field_set_to_one)(const EC_GROUP *, BIGNUM *r, BN_CTX *);
174} /* EC_METHOD */; 140} /* EC_METHOD */;
175 141
176typedef struct ec_extra_data_st {
177 struct ec_extra_data_st *next;
178 void *data;
179 void *(*dup_func)(void *);
180 void (*free_func)(void *);
181 void (*clear_free_func)(void *);
182} EC_EXTRA_DATA; /* used in EC_GROUP */
183 142
184struct ec_group_st { 143struct ec_group_st {
185 const EC_METHOD *meth; 144 const EC_METHOD *meth;
186 145
187 EC_POINT *generator; /* optional */ 146 void *extra_data;
188 BIGNUM order, cofactor; 147 void *(*extra_data_dup_func)(void *);
189 148 void (*extra_data_free_func)(void *);
190 int curve_name;/* optional NID for named curve */ 149 void (*extra_data_clear_free_func)(void *);
191 int asn1_flag; /* flag to control the asn1 encoding */
192 point_conversion_form_t asn1_form;
193
194 unsigned char *seed; /* optional seed for parameters (appears in ASN1) */
195 size_t seed_len;
196 150
197 EC_EXTRA_DATA *extra_data; /* linked list */ 151 /* All members except 'meth' and 'extra_data...' are handled by
198 152 * the method functions, even if they appear generic */
199 /* The following members are handled by the method functions,
200 * even if they appear generic */
201 153
202 BIGNUM field; /* Field specification. 154 BIGNUM field; /* Field specification.
203 * For curves over GF(p), this is the modulus; 155 * For curves over GF(p), this is the modulus. */
204 * for curves over GF(2^m), this is the
205 * irreducible polynomial defining the field.
206 */
207
208 unsigned int poly[5]; /* Field specification for curves over GF(2^m).
209 * The irreducible f(t) is then of the form:
210 * t^poly[0] + t^poly[1] + ... + t^poly[k]
211 * where m = poly[0] > poly[1] > ... > poly[k] = 0.
212 */
213 156
214 BIGNUM a, b; /* Curve coefficients. 157 BIGNUM a, b; /* Curve coefficients.
215 * (Here the assumption is that BIGNUMs can be used 158 * (Here the assumption is that BIGNUMs can be used
@@ -217,49 +160,29 @@ struct ec_group_st {
217 * For characteristic > 3, the curve is defined 160 * For characteristic > 3, the curve is defined
218 * by a Weierstrass equation of the form 161 * by a Weierstrass equation of the form
219 * y^2 = x^3 + a*x + b. 162 * y^2 = x^3 + a*x + b.
220 * For characteristic 2, the curve is defined by
221 * an equation of the form
222 * y^2 + x*y = x^3 + a*x^2 + b.
223 */ 163 */
224
225 int a_is_minus3; /* enable optimized point arithmetics for special case */ 164 int a_is_minus3; /* enable optimized point arithmetics for special case */
226 165
166 EC_POINT *generator; /* optional */
167 BIGNUM order, cofactor;
168
227 void *field_data1; /* method-specific (e.g., Montgomery structure) */ 169 void *field_data1; /* method-specific (e.g., Montgomery structure) */
228 void *field_data2; /* method-specific */ 170 void *field_data2; /* method-specific */
229 int (*field_mod_func)(BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *); /* method-specific */
230} /* EC_GROUP */; 171} /* EC_GROUP */;
231 172
232struct ec_key_st {
233 int version;
234
235 EC_GROUP *group;
236
237 EC_POINT *pub_key;
238 BIGNUM *priv_key;
239
240 unsigned int enc_flag;
241 point_conversion_form_t conv_form;
242 173
243 int references; 174/* Basically a 'mixin' for extra data, but available for EC_GROUPs only
244
245 EC_EXTRA_DATA *method_data;
246} /* EC_KEY */;
247
248/* Basically a 'mixin' for extra data, but available for EC_GROUPs/EC_KEYs only
249 * (with visibility limited to 'package' level for now). 175 * (with visibility limited to 'package' level for now).
250 * We use the function pointers as index for retrieval; this obviates 176 * We use the function pointers as index for retrieval; this obviates
251 * global ex_data-style index tables. 177 * global ex_data-style index tables.
252 */ 178 * (Currently, we have one slot only, but is is possible to extend this
253int EC_EX_DATA_set_data(EC_EXTRA_DATA **, void *data, 179 * if necessary.) */
254 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 180int EC_GROUP_set_extra_data(EC_GROUP *, void *extra_data, void *(*extra_data_dup_func)(void *),
255void *EC_EX_DATA_get_data(const EC_EXTRA_DATA *, 181 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
256 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 182void *EC_GROUP_get_extra_data(const EC_GROUP *, void *(*extra_data_dup_func)(void *),
257void EC_EX_DATA_free_data(EC_EXTRA_DATA **, 183 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *));
258 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)); 184void EC_GROUP_free_extra_data(EC_GROUP *);
259void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **, 185void EC_GROUP_clear_free_extra_data(EC_GROUP *);
260 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *));
261void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **);
262void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **);
263 186
264 187
265 188
@@ -278,23 +201,18 @@ struct ec_point_st {
278 201
279 202
280 203
281/* method functions in ec_mult.c
282 * (ec_lib.c uses these as defaults if group->method->mul is 0) */
283int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
284 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
285int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *);
286int ec_wNAF_have_precompute_mult(const EC_GROUP *group);
287
288
289/* method functions in ecp_smpl.c */ 204/* method functions in ecp_smpl.c */
290int ec_GFp_simple_group_init(EC_GROUP *); 205int ec_GFp_simple_group_init(EC_GROUP *);
291void ec_GFp_simple_group_finish(EC_GROUP *); 206void ec_GFp_simple_group_finish(EC_GROUP *);
292void ec_GFp_simple_group_clear_finish(EC_GROUP *); 207void ec_GFp_simple_group_clear_finish(EC_GROUP *);
293int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *); 208int ec_GFp_simple_group_copy(EC_GROUP *, const EC_GROUP *);
294int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 209int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
295int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *); 210int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
296int ec_GFp_simple_group_get_degree(const EC_GROUP *); 211int ec_GFp_simple_group_set_generator(EC_GROUP *, const EC_POINT *generator,
297int ec_GFp_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *); 212 const BIGNUM *order, const BIGNUM *cofactor);
213EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *);
214int ec_GFp_simple_group_get_order(const EC_GROUP *, BIGNUM *order, BN_CTX *);
215int ec_GFp_simple_group_get_cofactor(const EC_GROUP *, BIGNUM *cofactor, BN_CTX *);
298int ec_GFp_simple_point_init(EC_POINT *); 216int ec_GFp_simple_point_init(EC_POINT *);
299void ec_GFp_simple_point_finish(EC_POINT *); 217void ec_GFp_simple_point_finish(EC_POINT *);
300void ec_GFp_simple_point_clear_finish(EC_POINT *); 218void ec_GFp_simple_point_clear_finish(EC_POINT *);
@@ -304,11 +222,11 @@ int ec_GFp_simple_set_Jprojective_coordinates_GFp(const EC_GROUP *, EC_POINT *,
304 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *); 222 const BIGNUM *x, const BIGNUM *y, const BIGNUM *z, BN_CTX *);
305int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *, 223int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
306 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *); 224 BIGNUM *x, BIGNUM *y, BIGNUM *z, BN_CTX *);
307int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, 225int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *, EC_POINT *,
308 const BIGNUM *x, const BIGNUM *y, BN_CTX *); 226 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
309int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *, 227int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *, const EC_POINT *,
310 BIGNUM *x, BIGNUM *y, BN_CTX *); 228 BIGNUM *x, BIGNUM *y, BN_CTX *);
311int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *, 229int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *, EC_POINT *,
312 const BIGNUM *x, int y_bit, BN_CTX *); 230 const BIGNUM *x, int y_bit, BN_CTX *);
313size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form, 231size_t ec_GFp_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
314 unsigned char *buf, size_t len, BN_CTX *); 232 unsigned char *buf, size_t len, BN_CTX *);
@@ -328,7 +246,7 @@ int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX
328 246
329/* method functions in ecp_mont.c */ 247/* method functions in ecp_mont.c */
330int ec_GFp_mont_group_init(EC_GROUP *); 248int ec_GFp_mont_group_init(EC_GROUP *);
331int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 249int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
332void ec_GFp_mont_group_finish(EC_GROUP *); 250void ec_GFp_mont_group_finish(EC_GROUP *);
333void ec_GFp_mont_group_clear_finish(EC_GROUP *); 251void ec_GFp_mont_group_clear_finish(EC_GROUP *);
334int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *); 252int ec_GFp_mont_group_copy(EC_GROUP *, const EC_GROUP *);
@@ -339,52 +257,21 @@ int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CT
339int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *); 257int ec_GFp_mont_field_set_to_one(const EC_GROUP *, BIGNUM *r, BN_CTX *);
340 258
341 259
260/* method functions in ecp_recp.c */
261int ec_GFp_recp_group_init(EC_GROUP *);
262int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
263void ec_GFp_recp_group_finish(EC_GROUP *);
264void ec_GFp_recp_group_clear_finish(EC_GROUP *);
265int ec_GFp_recp_group_copy(EC_GROUP *, const EC_GROUP *);
266int ec_GFp_recp_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
267int ec_GFp_recp_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
268
269
342/* method functions in ecp_nist.c */ 270/* method functions in ecp_nist.c */
343int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); 271int ec_GFp_nist_group_init(EC_GROUP *);
344int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 272int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
273void ec_GFp_nist_group_finish(EC_GROUP *);
274void ec_GFp_nist_group_clear_finish(EC_GROUP *);
275int ec_GFp_nist_group_copy(EC_GROUP *, const EC_GROUP *);
345int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); 276int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
346int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); 277int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
347
348
349/* method functions in ec2_smpl.c */
350int ec_GF2m_simple_group_init(EC_GROUP *);
351void ec_GF2m_simple_group_finish(EC_GROUP *);
352void ec_GF2m_simple_group_clear_finish(EC_GROUP *);
353int ec_GF2m_simple_group_copy(EC_GROUP *, const EC_GROUP *);
354int ec_GF2m_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
355int ec_GF2m_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *);
356int ec_GF2m_simple_group_get_degree(const EC_GROUP *);
357int ec_GF2m_simple_group_check_discriminant(const EC_GROUP *, BN_CTX *);
358int ec_GF2m_simple_point_init(EC_POINT *);
359void ec_GF2m_simple_point_finish(EC_POINT *);
360void ec_GF2m_simple_point_clear_finish(EC_POINT *);
361int ec_GF2m_simple_point_copy(EC_POINT *, const EC_POINT *);
362int ec_GF2m_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *);
363int ec_GF2m_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *,
364 const BIGNUM *x, const BIGNUM *y, BN_CTX *);
365int ec_GF2m_simple_point_get_affine_coordinates(const EC_GROUP *, const EC_POINT *,
366 BIGNUM *x, BIGNUM *y, BN_CTX *);
367int ec_GF2m_simple_set_compressed_coordinates(const EC_GROUP *, EC_POINT *,
368 const BIGNUM *x, int y_bit, BN_CTX *);
369size_t ec_GF2m_simple_point2oct(const EC_GROUP *, const EC_POINT *, point_conversion_form_t form,
370 unsigned char *buf, size_t len, BN_CTX *);
371int ec_GF2m_simple_oct2point(const EC_GROUP *, EC_POINT *,
372 const unsigned char *buf, size_t len, BN_CTX *);
373int ec_GF2m_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
374int ec_GF2m_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, BN_CTX *);
375int ec_GF2m_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *);
376int ec_GF2m_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *);
377int ec_GF2m_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *);
378int ec_GF2m_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, BN_CTX *);
379int ec_GF2m_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *);
380int ec_GF2m_simple_points_make_affine(const EC_GROUP *, size_t num, EC_POINT *[], BN_CTX *);
381int ec_GF2m_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
382int ec_GF2m_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *);
383int ec_GF2m_simple_field_div(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *);
384
385
386/* method functions in ec2_mult.c */
387int ec_GF2m_simple_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
388 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *);
389int ec_GF2m_precompute_mult(EC_GROUP *group, BN_CTX *ctx);
390int ec_GF2m_have_precompute_mult(const EC_GROUP *group);
diff --git a/src/lib/libcrypto/ec/ec_lib.c b/src/lib/libcrypto/ec/ec_lib.c
index 5af84376c6..deb522060f 100644
--- a/src/lib/libcrypto/ec/ec_lib.c
+++ b/src/lib/libcrypto/ec/ec_lib.c
@@ -1,9 +1,6 @@
1/* crypto/ec/ec_lib.c */ 1/* crypto/ec/ec_lib.c */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,11 +52,6 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Binary polynomial ECC support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 55
64#include <string.h> 56#include <string.h>
65 57
@@ -98,18 +90,10 @@ EC_GROUP *EC_GROUP_new(const EC_METHOD *meth)
98 ret->meth = meth; 90 ret->meth = meth;
99 91
100 ret->extra_data = NULL; 92 ret->extra_data = NULL;
101 93 ret->extra_data_dup_func = 0;
102 ret->generator = NULL; 94 ret->extra_data_free_func = 0;
103 BN_init(&ret->order); 95 ret->extra_data_clear_free_func = 0;
104 BN_init(&ret->cofactor); 96
105
106 ret->curve_name = 0;
107 ret->asn1_flag = 0;
108 ret->asn1_form = POINT_CONVERSION_UNCOMPRESSED;
109
110 ret->seed = NULL;
111 ret->seed_len = 0;
112
113 if (!meth->group_init(ret)) 97 if (!meth->group_init(ret))
114 { 98 {
115 OPENSSL_free(ret); 99 OPENSSL_free(ret);
@@ -127,15 +111,7 @@ void EC_GROUP_free(EC_GROUP *group)
127 if (group->meth->group_finish != 0) 111 if (group->meth->group_finish != 0)
128 group->meth->group_finish(group); 112 group->meth->group_finish(group);
129 113
130 EC_EX_DATA_free_all_data(&group->extra_data); 114 EC_GROUP_free_extra_data(group);
131
132 if (group->generator != NULL)
133 EC_POINT_free(group->generator);
134 BN_free(&group->order);
135 BN_free(&group->cofactor);
136
137 if (group->seed)
138 OPENSSL_free(group->seed);
139 115
140 OPENSSL_free(group); 116 OPENSSL_free(group);
141 } 117 }
@@ -147,21 +123,10 @@ void EC_GROUP_clear_free(EC_GROUP *group)
147 123
148 if (group->meth->group_clear_finish != 0) 124 if (group->meth->group_clear_finish != 0)
149 group->meth->group_clear_finish(group); 125 group->meth->group_clear_finish(group);
150 else if (group->meth->group_finish != 0) 126 else if (group->meth != NULL && group->meth->group_finish != 0)
151 group->meth->group_finish(group); 127 group->meth->group_finish(group);
152 128
153 EC_EX_DATA_clear_free_all_data(&group->extra_data); 129 EC_GROUP_clear_free_extra_data(group);
154
155 if (group->generator != NULL)
156 EC_POINT_clear_free(group->generator);
157 BN_clear_free(&group->order);
158 BN_clear_free(&group->cofactor);
159
160 if (group->seed)
161 {
162 OPENSSL_cleanse(group->seed, group->seed_len);
163 OPENSSL_free(group->seed);
164 }
165 130
166 OPENSSL_cleanse(group, sizeof *group); 131 OPENSSL_cleanse(group, sizeof *group);
167 OPENSSL_free(group); 132 OPENSSL_free(group);
@@ -170,8 +135,6 @@ void EC_GROUP_clear_free(EC_GROUP *group)
170 135
171int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src) 136int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
172 { 137 {
173 EC_EXTRA_DATA *d;
174
175 if (dest->meth->group_copy == 0) 138 if (dest->meth->group_copy == 0)
176 { 139 {
177 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 140 ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
@@ -185,507 +148,161 @@ int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
185 if (dest == src) 148 if (dest == src)
186 return 1; 149 return 1;
187 150
188 EC_EX_DATA_free_all_data(&dest->extra_data); 151 EC_GROUP_clear_free_extra_data(dest);
189 152 if (src->extra_data_dup_func)
190 for (d = src->extra_data; d != NULL; d = d->next)
191 { 153 {
192 void *t = d->dup_func(d->data); 154 if (src->extra_data != NULL)
193
194 if (t == NULL)
195 return 0;
196 if (!EC_EX_DATA_set_data(&dest->extra_data, t, d->dup_func, d->free_func, d->clear_free_func))
197 return 0;
198 }
199
200 if (src->generator != NULL)
201 {
202 if (dest->generator == NULL)
203 {
204 dest->generator = EC_POINT_new(dest);
205 if (dest->generator == NULL) return 0;
206 }
207 if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
208 }
209 else
210 {
211 /* src->generator == NULL */
212 if (dest->generator != NULL)
213 { 155 {
214 EC_POINT_clear_free(dest->generator); 156 dest->extra_data = src->extra_data_dup_func(src->extra_data);
215 dest->generator = NULL; 157 if (dest->extra_data == NULL)
158 return 0;
216 } 159 }
217 }
218
219 if (!BN_copy(&dest->order, &src->order)) return 0;
220 if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
221 160
222 dest->curve_name = src->curve_name; 161 dest->extra_data_dup_func = src->extra_data_dup_func;
223 dest->asn1_flag = src->asn1_flag; 162 dest->extra_data_free_func = src->extra_data_free_func;
224 dest->asn1_form = src->asn1_form; 163 dest->extra_data_clear_free_func = src->extra_data_clear_free_func;
225
226 if (src->seed)
227 {
228 if (dest->seed)
229 OPENSSL_free(dest->seed);
230 dest->seed = OPENSSL_malloc(src->seed_len);
231 if (dest->seed == NULL)
232 return 0;
233 if (!memcpy(dest->seed, src->seed, src->seed_len))
234 return 0;
235 dest->seed_len = src->seed_len;
236 }
237 else
238 {
239 if (dest->seed)
240 OPENSSL_free(dest->seed);
241 dest->seed = NULL;
242 dest->seed_len = 0;
243 } 164 }
244
245 165
246 return dest->meth->group_copy(dest, src); 166 return dest->meth->group_copy(dest, src);
247 } 167 }
248 168
249 169
250EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)
251 {
252 EC_GROUP *t = NULL;
253 int ok = 0;
254
255 if (a == NULL) return NULL;
256
257 if ((t = EC_GROUP_new(a->meth)) == NULL) return(NULL);
258 if (!EC_GROUP_copy(t, a)) goto err;
259
260 ok = 1;
261
262 err:
263 if (!ok)
264 {
265 if (t) EC_GROUP_free(t);
266 return NULL;
267 }
268 else return t;
269 }
270
271
272const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group) 170const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group)
273 { 171 {
274 return group->meth; 172 return group->meth;
275 } 173 }
276 174
277 175
278int EC_METHOD_get_field_type(const EC_METHOD *meth)
279 {
280 return meth->field_type;
281 }
282
283
284int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
285 {
286 if (generator == NULL)
287 {
288 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
289 return 0 ;
290 }
291
292 if (group->generator == NULL)
293 {
294 group->generator = EC_POINT_new(group);
295 if (group->generator == NULL) return 0;
296 }
297 if (!EC_POINT_copy(group->generator, generator)) return 0;
298
299 if (order != NULL)
300 { if (!BN_copy(&group->order, order)) return 0; }
301 else
302 BN_zero(&group->order);
303
304 if (cofactor != NULL)
305 { if (!BN_copy(&group->cofactor, cofactor)) return 0; }
306 else
307 BN_zero(&group->cofactor);
308
309 return 1;
310 }
311
312
313const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
314 {
315 return group->generator;
316 }
317
318
319int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
320 {
321 if (!BN_copy(order, &group->order))
322 return 0;
323
324 return !BN_is_zero(order);
325 }
326
327
328int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
329 {
330 if (!BN_copy(cofactor, &group->cofactor))
331 return 0;
332
333 return !BN_is_zero(&group->cofactor);
334 }
335
336
337void EC_GROUP_set_curve_name(EC_GROUP *group, int nid)
338 {
339 group->curve_name = nid;
340 }
341
342
343int EC_GROUP_get_curve_name(const EC_GROUP *group)
344 {
345 return group->curve_name;
346 }
347
348
349void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag)
350 {
351 group->asn1_flag = flag;
352 }
353
354
355int EC_GROUP_get_asn1_flag(const EC_GROUP *group)
356 {
357 return group->asn1_flag;
358 }
359
360
361void EC_GROUP_set_point_conversion_form(EC_GROUP *group,
362 point_conversion_form_t form)
363 {
364 group->asn1_form = form;
365 }
366
367
368point_conversion_form_t EC_GROUP_get_point_conversion_form(const EC_GROUP *group)
369 {
370 return group->asn1_form;
371 }
372
373
374size_t EC_GROUP_set_seed(EC_GROUP *group, const unsigned char *p, size_t len)
375 {
376 if (group->seed)
377 {
378 OPENSSL_free(group->seed);
379 group->seed = NULL;
380 group->seed_len = 0;
381 }
382
383 if (!len || !p)
384 return 1;
385
386 if ((group->seed = OPENSSL_malloc(len)) == NULL)
387 return 0;
388 memcpy(group->seed, p, len);
389 group->seed_len = len;
390
391 return len;
392 }
393
394
395unsigned char *EC_GROUP_get0_seed(const EC_GROUP *group)
396 {
397 return group->seed;
398 }
399
400
401size_t EC_GROUP_get_seed_len(const EC_GROUP *group)
402 {
403 return group->seed_len;
404 }
405
406
407int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 176int EC_GROUP_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
408 { 177 {
409 if (group->meth->group_set_curve == 0) 178 if (group->meth->group_set_curve_GFp == 0)
410 { 179 {
411 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 180 ECerr(EC_F_EC_GROUP_SET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
412 return 0; 181 return 0;
413 } 182 }
414 return group->meth->group_set_curve(group, p, a, b, ctx); 183 return group->meth->group_set_curve_GFp(group, p, a, b, ctx);
415 } 184 }
416 185
417 186
418int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) 187int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
419 { 188 {
420 if (group->meth->group_get_curve == 0) 189 if (group->meth->group_get_curve_GFp == 0)
421 { 190 {
422 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 191 ECerr(EC_F_EC_GROUP_GET_CURVE_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
423 return 0; 192 return 0;
424 } 193 }
425 return group->meth->group_get_curve(group, p, a, b, ctx); 194 return group->meth->group_get_curve_GFp(group, p, a, b, ctx);
426 } 195 }
427 196
428 197
429int EC_GROUP_set_curve_GF2m(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 198int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order, const BIGNUM *cofactor)
430 { 199 {
431 if (group->meth->group_set_curve == 0) 200 if (group->meth->group_set_generator == 0)
432 { 201 {
433 ECerr(EC_F_EC_GROUP_SET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 202 ECerr(EC_F_EC_GROUP_SET_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
434 return 0; 203 return 0;
435 } 204 }
436 return group->meth->group_set_curve(group, p, a, b, ctx); 205 return group->meth->group_set_generator(group, generator, order, cofactor);
437 } 206 }
438 207
439 208
440int EC_GROUP_get_curve_GF2m(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) 209EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group)
441 { 210 {
442 if (group->meth->group_get_curve == 0) 211 if (group->meth->group_get0_generator == 0)
443 { 212 {
444 ECerr(EC_F_EC_GROUP_GET_CURVE_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 213 ECerr(EC_F_EC_GROUP_GET0_GENERATOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
445 return 0; 214 return 0;
446 } 215 }
447 return group->meth->group_get_curve(group, p, a, b, ctx); 216 return group->meth->group_get0_generator(group);
448 } 217 }
449 218
450 219
451int EC_GROUP_get_degree(const EC_GROUP *group) 220int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
452 { 221 {
453 if (group->meth->group_get_degree == 0) 222 if (group->meth->group_get_order == 0)
454 { 223 {
455 ECerr(EC_F_EC_GROUP_GET_DEGREE, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 224 ECerr(EC_F_EC_GROUP_GET_ORDER, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
456 return 0; 225 return 0;
457 } 226 }
458 return group->meth->group_get_degree(group); 227 return group->meth->group_get_order(group, order, ctx);
459 } 228 }
460 229
461 230
462int EC_GROUP_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) 231int EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
463 { 232 {
464 if (group->meth->group_check_discriminant == 0) 233 if (group->meth->group_get_cofactor == 0)
465 { 234 {
466 ECerr(EC_F_EC_GROUP_CHECK_DISCRIMINANT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 235 ECerr(EC_F_EC_GROUP_GET_COFACTOR, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
467 return 0; 236 return 0;
468 } 237 }
469 return group->meth->group_check_discriminant(group, ctx); 238 return group->meth->group_get_cofactor(group, cofactor, ctx);
470 } 239 }
471 240
472 241
473int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx) 242/* this has 'package' visibility */
243int EC_GROUP_set_extra_data(EC_GROUP *group, void *extra_data, void *(*extra_data_dup_func)(void *),
244 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
474 { 245 {
475 int r = 0; 246 if ((group->extra_data != NULL)
476 BIGNUM *a1, *a2, *a3, *b1, *b2, *b3; 247 || (group->extra_data_dup_func != 0)
477 BN_CTX *ctx_new = NULL; 248 || (group->extra_data_free_func != 0)
478 249 || (group->extra_data_clear_free_func != 0))
479 /* compare the field types*/
480 if (EC_METHOD_get_field_type(EC_GROUP_method_of(a)) !=
481 EC_METHOD_get_field_type(EC_GROUP_method_of(b)))
482 return 1;
483 /* compare the curve name (if present) */
484 if (EC_GROUP_get_curve_name(a) && EC_GROUP_get_curve_name(b) &&
485 EC_GROUP_get_curve_name(a) == EC_GROUP_get_curve_name(b))
486 return 0;
487
488 if (!ctx)
489 ctx_new = ctx = BN_CTX_new();
490 if (!ctx)
491 return -1;
492
493 BN_CTX_start(ctx);
494 a1 = BN_CTX_get(ctx);
495 a2 = BN_CTX_get(ctx);
496 a3 = BN_CTX_get(ctx);
497 b1 = BN_CTX_get(ctx);
498 b2 = BN_CTX_get(ctx);
499 b3 = BN_CTX_get(ctx);
500 if (!b3)
501 { 250 {
502 BN_CTX_end(ctx); 251 ECerr(EC_F_EC_GROUP_SET_EXTRA_DATA, EC_R_SLOT_FULL);
503 if (ctx_new) 252 return 0;
504 BN_CTX_free(ctx);
505 return -1;
506 }
507
508 /* XXX This approach assumes that the external representation
509 * of curves over the same field type is the same.
510 */
511 if (!a->meth->group_get_curve(a, a1, a2, a3, ctx) ||
512 !b->meth->group_get_curve(b, b1, b2, b3, ctx))
513 r = 1;
514
515 if (r || BN_cmp(a1, b1) || BN_cmp(a2, b2) || BN_cmp(a3, b3))
516 r = 1;
517
518 /* XXX EC_POINT_cmp() assumes that the methods are equal */
519 if (r || EC_POINT_cmp(a, EC_GROUP_get0_generator(a),
520 EC_GROUP_get0_generator(b), ctx))
521 r = 1;
522
523 if (!r)
524 {
525 /* compare the order and cofactor */
526 if (!EC_GROUP_get_order(a, a1, ctx) ||
527 !EC_GROUP_get_order(b, b1, ctx) ||
528 !EC_GROUP_get_cofactor(a, a2, ctx) ||
529 !EC_GROUP_get_cofactor(b, b2, ctx))
530 {
531 BN_CTX_end(ctx);
532 if (ctx_new)
533 BN_CTX_free(ctx);
534 return -1;
535 }
536 if (BN_cmp(a1, b1) || BN_cmp(a2, b2))
537 r = 1;
538 } 253 }
539 254
540 BN_CTX_end(ctx); 255 group->extra_data = extra_data;
541 if (ctx_new) 256 group->extra_data_dup_func = extra_data_dup_func;
542 BN_CTX_free(ctx); 257 group->extra_data_free_func = extra_data_free_func;
543 258 group->extra_data_clear_free_func = extra_data_clear_free_func;
544 return r; 259 return 1;
545 } 260 }
546 261
547 262
548/* this has 'package' visibility */ 263/* this has 'package' visibility */
549int EC_EX_DATA_set_data(EC_EXTRA_DATA **ex_data, void *data, 264void *EC_GROUP_get_extra_data(const EC_GROUP *group, void *(*extra_data_dup_func)(void *),
550 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *)) 265 void (*extra_data_free_func)(void *), void (*extra_data_clear_free_func)(void *))
551 { 266 {
552 EC_EXTRA_DATA *d; 267 if ((group->extra_data_dup_func != extra_data_dup_func)
553 268 || (group->extra_data_free_func != extra_data_free_func)
554 if (ex_data == NULL) 269 || (group->extra_data_clear_free_func != extra_data_clear_free_func))
555 return 0;
556
557 for (d = *ex_data; d != NULL; d = d->next)
558 { 270 {
559 if (d->dup_func == dup_func && d->free_func == free_func && d->clear_free_func == clear_free_func) 271#if 0 /* this was an error in 0.9.7, but that does not make a lot of sense */
560 { 272 ECerr(..._F_EC_GROUP_GET_EXTRA_DATA, ..._R_NO_SUCH_EXTRA_DATA);
561 ECerr(EC_F_EC_EX_DATA_SET_DATA, EC_R_SLOT_FULL); 273#endif
562 return 0; 274 return NULL;
563 }
564 } 275 }
565 276
566 if (data == NULL) 277 return group->extra_data;
567 /* no explicit entry needed */
568 return 1;
569
570 d = OPENSSL_malloc(sizeof *d);
571 if (d == NULL)
572 return 0;
573
574 d->data = data;
575 d->dup_func = dup_func;
576 d->free_func = free_func;
577 d->clear_free_func = clear_free_func;
578
579 d->next = *ex_data;
580 *ex_data = d;
581
582 return 1;
583 } 278 }
584 279
585/* this has 'package' visibility */
586void *EC_EX_DATA_get_data(const EC_EXTRA_DATA *ex_data,
587 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
588 {
589 const EC_EXTRA_DATA *d;
590
591 for (d = ex_data; d != NULL; d = d->next)
592 {
593 if (d->dup_func == dup_func && d->free_func == free_func && d->clear_free_func == clear_free_func)
594 return d->data;
595 }
596
597 return NULL;
598 }
599 280
600/* this has 'package' visibility */ 281/* this has 'package' visibility */
601void EC_EX_DATA_free_data(EC_EXTRA_DATA **ex_data, 282void EC_GROUP_free_extra_data(EC_GROUP *group)
602 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
603 { 283 {
604 EC_EXTRA_DATA **p; 284 if (group->extra_data_free_func)
605 285 group->extra_data_free_func(group->extra_data);
606 if (ex_data == NULL) 286 group->extra_data = NULL;
607 return; 287 group->extra_data_dup_func = 0;
608 288 group->extra_data_free_func = 0;
609 for (p = ex_data; *p != NULL; p = &((*p)->next)) 289 group->extra_data_clear_free_func = 0;
610 {
611 if ((*p)->dup_func == dup_func && (*p)->free_func == free_func && (*p)->clear_free_func == clear_free_func)
612 {
613 EC_EXTRA_DATA *next = (*p)->next;
614
615 (*p)->free_func((*p)->data);
616 OPENSSL_free(*p);
617
618 *p = next;
619 return;
620 }
621 }
622 } 290 }
623 291
624/* this has 'package' visibility */
625void EC_EX_DATA_clear_free_data(EC_EXTRA_DATA **ex_data,
626 void *(*dup_func)(void *), void (*free_func)(void *), void (*clear_free_func)(void *))
627 {
628 EC_EXTRA_DATA **p;
629
630 if (ex_data == NULL)
631 return;
632
633 for (p = ex_data; *p != NULL; p = &((*p)->next))
634 {
635 if ((*p)->dup_func == dup_func && (*p)->free_func == free_func && (*p)->clear_free_func == clear_free_func)
636 {
637 EC_EXTRA_DATA *next = (*p)->next;
638
639 (*p)->clear_free_func((*p)->data);
640 OPENSSL_free(*p);
641
642 *p = next;
643 return;
644 }
645 }
646 }
647 292
648/* this has 'package' visibility */ 293/* this has 'package' visibility */
649void EC_EX_DATA_free_all_data(EC_EXTRA_DATA **ex_data) 294void EC_GROUP_clear_free_extra_data(EC_GROUP *group)
650 { 295 {
651 EC_EXTRA_DATA *d; 296 if (group->extra_data_clear_free_func)
652 297 group->extra_data_clear_free_func(group->extra_data);
653 if (ex_data == NULL) 298 else if (group->extra_data_free_func)
654 return; 299 group->extra_data_free_func(group->extra_data);
655 300 group->extra_data = NULL;
656 d = *ex_data; 301 group->extra_data_dup_func = 0;
657 while (d) 302 group->extra_data_free_func = 0;
658 { 303 group->extra_data_clear_free_func = 0;
659 EC_EXTRA_DATA *next = d->next;
660
661 d->free_func(d->data);
662 OPENSSL_free(d);
663
664 d = next;
665 }
666 *ex_data = NULL;
667 } 304 }
668 305
669/* this has 'package' visibility */
670void EC_EX_DATA_clear_free_all_data(EC_EXTRA_DATA **ex_data)
671 {
672 EC_EXTRA_DATA *d;
673
674 if (ex_data == NULL)
675 return;
676
677 d = *ex_data;
678 while (d)
679 {
680 EC_EXTRA_DATA *next = d->next;
681
682 d->clear_free_func(d->data);
683 OPENSSL_free(d);
684
685 d = next;
686 }
687 *ex_data = NULL;
688 }
689 306
690 307
691/* functions for EC_POINT objects */ 308/* functions for EC_POINT objects */
@@ -765,25 +382,6 @@ int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
765 } 382 }
766 383
767 384
768EC_POINT *EC_POINT_dup(const EC_POINT *a, const EC_GROUP *group)
769 {
770 EC_POINT *t;
771 int r;
772
773 if (a == NULL) return NULL;
774
775 t = EC_POINT_new(group);
776 if (t == NULL) return(NULL);
777 r = EC_POINT_copy(t, a);
778 if (!r)
779 {
780 EC_POINT_free(t);
781 return NULL;
782 }
783 else return t;
784 }
785
786
787const EC_METHOD *EC_POINT_method_of(const EC_POINT *point) 385const EC_METHOD *EC_POINT_method_of(const EC_POINT *point)
788 { 386 {
789 return point->meth; 387 return point->meth;
@@ -843,7 +441,7 @@ int EC_POINT_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const EC_POI
843int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, 441int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
844 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) 442 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
845 { 443 {
846 if (group->meth->point_set_affine_coordinates == 0) 444 if (group->meth->point_set_affine_coordinates_GFp == 0)
847 { 445 {
848 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 446 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
849 return 0; 447 return 0;
@@ -853,31 +451,14 @@ int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
853 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 451 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
854 return 0; 452 return 0;
855 } 453 }
856 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx); 454 return group->meth->point_set_affine_coordinates_GFp(group, point, x, y, ctx);
857 }
858
859
860int EC_POINT_set_affine_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
861 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
862 {
863 if (group->meth->point_set_affine_coordinates == 0)
864 {
865 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
866 return 0;
867 }
868 if (group->meth != point->meth)
869 {
870 ECerr(EC_F_EC_POINT_SET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
871 return 0;
872 }
873 return group->meth->point_set_affine_coordinates(group, point, x, y, ctx);
874 } 455 }
875 456
876 457
877int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point, 458int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
878 BIGNUM *x, BIGNUM *y, BN_CTX *ctx) 459 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
879 { 460 {
880 if (group->meth->point_get_affine_coordinates == 0) 461 if (group->meth->point_get_affine_coordinates_GFp == 0)
881 { 462 {
882 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 463 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
883 return 0; 464 return 0;
@@ -887,31 +468,14 @@ int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *p
887 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 468 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
888 return 0; 469 return 0;
889 } 470 }
890 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx); 471 return group->meth->point_get_affine_coordinates_GFp(group, point, x, y, ctx);
891 }
892
893
894int EC_POINT_get_affine_coordinates_GF2m(const EC_GROUP *group, const EC_POINT *point,
895 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
896 {
897 if (group->meth->point_get_affine_coordinates == 0)
898 {
899 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
900 return 0;
901 }
902 if (group->meth != point->meth)
903 {
904 ECerr(EC_F_EC_POINT_GET_AFFINE_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
905 return 0;
906 }
907 return group->meth->point_get_affine_coordinates(group, point, x, y, ctx);
908 } 472 }
909 473
910 474
911int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, 475int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
912 const BIGNUM *x, int y_bit, BN_CTX *ctx) 476 const BIGNUM *x, int y_bit, BN_CTX *ctx)
913 { 477 {
914 if (group->meth->point_set_compressed_coordinates == 0) 478 if (group->meth->point_set_compressed_coordinates_GFp == 0)
915 { 479 {
916 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 480 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
917 return 0; 481 return 0;
@@ -921,24 +485,7 @@ int EC_POINT_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *poi
921 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS); 485 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GFP, EC_R_INCOMPATIBLE_OBJECTS);
922 return 0; 486 return 0;
923 } 487 }
924 return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx); 488 return group->meth->point_set_compressed_coordinates_GFp(group, point, x, y_bit, ctx);
925 }
926
927
928int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group, EC_POINT *point,
929 const BIGNUM *x, int y_bit, BN_CTX *ctx)
930 {
931 if (group->meth->point_set_compressed_coordinates == 0)
932 {
933 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
934 return 0;
935 }
936 if (group->meth != point->meth)
937 {
938 ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M, EC_R_INCOMPATIBLE_OBJECTS);
939 return 0;
940 }
941 return group->meth->point_set_compressed_coordinates(group, point, x, y_bit, ctx);
942 } 489 }
943 490
944 491
@@ -1012,12 +559,12 @@ int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, BN_CTX *ctx)
1012 { 559 {
1013 if (group->meth->dbl == 0) 560 if (group->meth->dbl == 0)
1014 { 561 {
1015 ECerr(EC_F_EC_POINT_INVERT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 562 ECerr(EC_F_EC_POINT_DBL, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
1016 return 0; 563 return 0;
1017 } 564 }
1018 if (group->meth != a->meth) 565 if (group->meth != a->meth)
1019 { 566 {
1020 ECerr(EC_F_EC_POINT_INVERT, EC_R_INCOMPATIBLE_OBJECTS); 567 ECerr(EC_F_EC_POINT_DBL, EC_R_INCOMPATIBLE_OBJECTS);
1021 return 0; 568 return 0;
1022 } 569 }
1023 return group->meth->invert(group, a, ctx); 570 return group->meth->invert(group, a, ctx);
@@ -1107,58 +654,3 @@ int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[],
1107 } 654 }
1108 return group->meth->points_make_affine(group, num, points, ctx); 655 return group->meth->points_make_affine(group, num, points, ctx);
1109 } 656 }
1110
1111
1112/* Functions for point multiplication.
1113 *
1114 * If group->meth->mul is 0, we use the wNAF-based implementations in ec_mult.c;
1115 * otherwise we dispatch through methods.
1116 */
1117
1118int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
1119 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
1120 {
1121 if (group->meth->mul == 0)
1122 /* use default */
1123 return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
1124
1125 return group->meth->mul(group, r, scalar, num, points, scalars, ctx);
1126 }
1127
1128int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
1129 const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
1130 {
1131 /* just a convenient interface to EC_POINTs_mul() */
1132
1133 const EC_POINT *points[1];
1134 const BIGNUM *scalars[1];
1135
1136 points[0] = point;
1137 scalars[0] = p_scalar;
1138
1139 return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
1140 }
1141
1142int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
1143 {
1144 if (group->meth->mul == 0)
1145 /* use default */
1146 return ec_wNAF_precompute_mult(group, ctx);
1147
1148 if (group->meth->precompute_mult != 0)
1149 return group->meth->precompute_mult(group, ctx);
1150 else
1151 return 1; /* nothing to do, so report success */
1152 }
1153
1154int EC_GROUP_have_precompute_mult(const EC_GROUP *group)
1155 {
1156 if (group->meth->mul == 0)
1157 /* use default */
1158 return ec_wNAF_have_precompute_mult(group);
1159
1160 if (group->meth->have_precompute_mult != 0)
1161 return group->meth->have_precompute_mult(group);
1162 else
1163 return 0; /* cannot tell whether precomputation has been performed */
1164 }
diff --git a/src/lib/libcrypto/ec/ec_mult.c b/src/lib/libcrypto/ec/ec_mult.c
index 2ba173ef36..16822a73cf 100644
--- a/src/lib/libcrypto/ec/ec_mult.c
+++ b/src/lib/libcrypto/ec/ec_mult.c
@@ -1,9 +1,6 @@
1/* crypto/ec/ec_mult.c */ 1/* crypto/ec/ec_mult.c */
2/*
3 * Originally written by Bodo Moeller and Nils Larsch for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,161 +52,41 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Portions of this software developed by SUN MICROSYSTEMS, INC.,
61 * and contributed to the OpenSSL project.
62 */
63
64#include <string.h>
65 55
66#include <openssl/err.h> 56#include <openssl/err.h>
67 57
68#include "ec_lcl.h" 58#include "ec_lcl.h"
69 59
70 60
71/* 61/* TODO: optional precomputation of multiples of the generator */
72 * This file implements the wNAF-based interleaving multi-exponentation method
73 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#multiexp>);
74 * for multiplication with precomputation, we use wNAF splitting
75 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#fastexp>).
76 */
77
78
79
80
81/* structure for precomputed multiples of the generator */
82typedef struct ec_pre_comp_st {
83 const EC_GROUP *group; /* parent EC_GROUP object */
84 size_t blocksize; /* block size for wNAF splitting */
85 size_t numblocks; /* max. number of blocks for which we have precomputation */
86 size_t w; /* window size */
87 EC_POINT **points; /* array with pre-calculated multiples of generator:
88 * 'num' pointers to EC_POINT objects followed by a NULL */
89 size_t num; /* numblocks * 2^(w-1) */
90 int references;
91} EC_PRE_COMP;
92
93/* functions to manage EC_PRE_COMP within the EC_GROUP extra_data framework */
94static void *ec_pre_comp_dup(void *);
95static void ec_pre_comp_free(void *);
96static void ec_pre_comp_clear_free(void *);
97
98static EC_PRE_COMP *ec_pre_comp_new(const EC_GROUP *group)
99 {
100 EC_PRE_COMP *ret = NULL;
101
102 if (!group)
103 return NULL;
104
105 ret = (EC_PRE_COMP *)OPENSSL_malloc(sizeof(EC_PRE_COMP));
106 if (!ret)
107 {
108 ECerr(EC_F_EC_PRE_COMP_NEW, ERR_R_MALLOC_FAILURE);
109 return ret;
110 }
111 ret->group = group;
112 ret->blocksize = 8; /* default */
113 ret->numblocks = 0;
114 ret->w = 4; /* default */
115 ret->points = NULL;
116 ret->num = 0;
117 ret->references = 1;
118 return ret;
119 }
120
121static void *ec_pre_comp_dup(void *src_)
122 {
123 EC_PRE_COMP *src = src_;
124
125 /* no need to actually copy, these objects never change! */
126
127 CRYPTO_add(&src->references, 1, CRYPTO_LOCK_EC_PRE_COMP);
128
129 return src_;
130 }
131
132static void ec_pre_comp_free(void *pre_)
133 {
134 int i;
135 EC_PRE_COMP *pre = pre_;
136
137 if (!pre)
138 return;
139
140 i = CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP);
141 if (i > 0)
142 return;
143
144 if (pre->points)
145 {
146 EC_POINT **p;
147
148 for (p = pre->points; *p != NULL; p++)
149 EC_POINT_free(*p);
150 OPENSSL_free(pre->points);
151 }
152 OPENSSL_free(pre);
153 }
154
155static void ec_pre_comp_clear_free(void *pre_)
156 {
157 int i;
158 EC_PRE_COMP *pre = pre_;
159
160 if (!pre)
161 return;
162
163 i = CRYPTO_add(&pre->references, -1, CRYPTO_LOCK_EC_PRE_COMP);
164 if (i > 0)
165 return;
166
167 if (pre->points)
168 {
169 EC_POINT **p;
170 62
171 for (p = pre->points; *p != NULL; p++)
172 EC_POINT_clear_free(*p);
173 OPENSSL_cleanse(pre->points, sizeof pre->points);
174 OPENSSL_free(pre->points);
175 }
176 OPENSSL_cleanse(pre, sizeof pre);
177 OPENSSL_free(pre);
178 }
179 63
180 64
65/*
66 * wNAF-based interleaving multi-exponentation method
67 * (<URL:http://www.informatik.tu-darmstadt.de/TI/Mitarbeiter/moeller.html#multiexp>)
68 */
181 69
182 70
183/* Determine the modified width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'. 71/* Determine the width-(w+1) Non-Adjacent Form (wNAF) of 'scalar'.
184 * This is an array r[] of values that are either zero or odd with an 72 * This is an array r[] of values that are either zero or odd with an
185 * absolute value less than 2^w satisfying 73 * absolute value less than 2^w satisfying
186 * scalar = \sum_j r[j]*2^j 74 * scalar = \sum_j r[j]*2^j
187 * where at most one of any w+1 consecutive digits is non-zero 75 * where at most one of any w+1 consecutive digits is non-zero.
188 * with the exception that the most significant digit may be only
189 * w-1 zeros away from that next non-zero digit.
190 */ 76 */
191static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len) 77static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len, BN_CTX *ctx)
192 { 78 {
193 int window_val; 79 BIGNUM *c;
194 int ok = 0; 80 int ok = 0;
195 signed char *r = NULL; 81 signed char *r = NULL;
196 int sign = 1; 82 int sign = 1;
197 int bit, next_bit, mask; 83 int bit, next_bit, mask;
198 size_t len = 0, j; 84 size_t len = 0, j;
199 85
200 if (BN_is_zero(scalar)) 86 BN_CTX_start(ctx);
201 { 87 c = BN_CTX_get(ctx);
202 r = OPENSSL_malloc(1); 88 if (c == NULL) goto err;
203 if (!r) 89
204 {
205 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
206 goto err;
207 }
208 r[0] = 0;
209 *ret_len = 1;
210 return r;
211 }
212
213 if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */ 90 if (w <= 0 || w > 7) /* 'signed char' can represent integers with absolute values less than 2^7 */
214 { 91 {
215 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 92 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
@@ -219,90 +96,60 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
219 next_bit = bit << 1; /* at most 256 */ 96 next_bit = bit << 1; /* at most 256 */
220 mask = next_bit - 1; /* at most 255 */ 97 mask = next_bit - 1; /* at most 255 */
221 98
222 if (BN_is_negative(scalar)) 99 if (!BN_copy(c, scalar)) goto err;
100 if (c->neg)
223 { 101 {
224 sign = -1; 102 sign = -1;
103 c->neg = 0;
225 } 104 }
226 105
227 len = BN_num_bits(scalar); 106 len = BN_num_bits(c) + 1; /* wNAF may be one digit longer than binary representation */
228 r = OPENSSL_malloc(len + 1); /* modified wNAF may be one digit longer than binary representation 107 r = OPENSSL_malloc(len);
229 * (*ret_len will be set to the actual length, i.e. at most 108 if (r == NULL) goto err;
230 * BN_num_bits(scalar) + 1) */
231 if (r == NULL)
232 {
233 ECerr(EC_F_COMPUTE_WNAF, ERR_R_MALLOC_FAILURE);
234 goto err;
235 }
236 109
237 if (scalar->d == NULL || scalar->top == 0)
238 {
239 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
240 goto err;
241 }
242 window_val = scalar->d[0] & mask;
243 j = 0; 110 j = 0;
244 while ((window_val != 0) || (j + w + 1 < len)) /* if j+w+1 >= len, window_val will not increase */ 111 while (!BN_is_zero(c))
245 { 112 {
246 int digit = 0; 113 int u = 0;
247 114
248 /* 0 <= window_val <= 2^(w+1) */ 115 if (BN_is_odd(c))
249
250 if (window_val & 1)
251 { 116 {
252 /* 0 < window_val < 2^(w+1) */ 117 if (c->d == NULL || c->top == 0)
253
254 if (window_val & bit)
255 { 118 {
256 digit = window_val - next_bit; /* -2^w < digit < 0 */ 119 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
257 120 goto err;
258#if 1 /* modified wNAF */
259 if (j + w + 1 >= len)
260 {
261 /* special case for generating modified wNAFs:
262 * no new bits will be added into window_val,
263 * so using a positive digit here will decrease
264 * the total length of the representation */
265
266 digit = window_val & (mask >> 1); /* 0 < digit < 2^w */
267 }
268#endif
269 } 121 }
270 else 122 u = c->d[0] & mask;
123 if (u & bit)
271 { 124 {
272 digit = window_val; /* 0 < digit < 2^w */ 125 u -= next_bit;
126 /* u < 0 */
127 if (!BN_add_word(c, -u)) goto err;
273 } 128 }
274 129 else
275 if (digit <= -bit || digit >= bit || !(digit & 1))
276 { 130 {
277 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 131 /* u > 0 */
278 goto err; 132 if (!BN_sub_word(c, u)) goto err;
279 } 133 }
280 134
281 window_val -= digit; 135 if (u <= -bit || u >= bit || !(u & 1) || c->neg)
282
283 /* now window_val is 0 or 2^(w+1) in standard wNAF generation;
284 * for modified window NAFs, it may also be 2^w
285 */
286 if (window_val != 0 && window_val != next_bit && window_val != bit)
287 { 136 {
288 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 137 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
289 goto err; 138 goto err;
290 } 139 }
291 } 140 }
292 141
293 r[j++] = sign * digit; 142 r[j++] = sign * u;
294 143
295 window_val >>= 1; 144 if (BN_is_odd(c))
296 window_val += bit * BN_is_bit_set(scalar, j + w);
297
298 if (window_val > next_bit)
299 { 145 {
300 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 146 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
301 goto err; 147 goto err;
302 } 148 }
149 if (!BN_rshift1(c, c)) goto err;
303 } 150 }
304 151
305 if (j > len + 1) 152 if (j > len)
306 { 153 {
307 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR); 154 ECerr(EC_F_COMPUTE_WNAF, ERR_R_INTERNAL_ERROR);
308 goto err; 155 goto err;
@@ -311,6 +158,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
311 ok = 1; 158 ok = 1;
312 159
313 err: 160 err:
161 BN_CTX_end(ctx);
314 if (!ok) 162 if (!ok)
315 { 163 {
316 OPENSSL_free(r); 164 OPENSSL_free(r);
@@ -333,7 +181,7 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
333 (b) >= 300 ? 4 : \ 181 (b) >= 300 ? 4 : \
334 (b) >= 70 ? 3 : \ 182 (b) >= 70 ? 3 : \
335 (b) >= 20 ? 2 : \ 183 (b) >= 20 ? 2 : \
336 1)) 184 1))
337 185
338/* Compute 186/* Compute
339 * \sum scalars[i]*points[i], 187 * \sum scalars[i]*points[i],
@@ -341,15 +189,13 @@ static signed char *compute_wNAF(const BIGNUM *scalar, int w, size_t *ret_len)
341 * scalar*generator 189 * scalar*generator
342 * in the addition if scalar != NULL 190 * in the addition if scalar != NULL
343 */ 191 */
344int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar, 192int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
345 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx) 193 size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
346 { 194 {
347 BN_CTX *new_ctx = NULL; 195 BN_CTX *new_ctx = NULL;
348 const EC_POINT *generator = NULL; 196 EC_POINT *generator = NULL;
349 EC_POINT *tmp = NULL; 197 EC_POINT *tmp = NULL;
350 size_t totalnum; 198 size_t totalnum;
351 size_t blocksize = 0, numblocks = 0; /* for wNAF splitting */
352 size_t pre_points_per_block = 0;
353 size_t i, j; 199 size_t i, j;
354 int k; 200 int k;
355 int r_is_inverted = 0; 201 int r_is_inverted = 0;
@@ -361,15 +207,12 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
361 size_t num_val; 207 size_t num_val;
362 EC_POINT **val = NULL; /* precomputation */ 208 EC_POINT **val = NULL; /* precomputation */
363 EC_POINT **v; 209 EC_POINT **v;
364 EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' or 'pre_comp->points' */ 210 EC_POINT ***val_sub = NULL; /* pointers to sub-arrays of 'val' */
365 const EC_PRE_COMP *pre_comp = NULL;
366 int num_scalar = 0; /* flag: will be set to 1 if 'scalar' must be treated like other scalars,
367 * i.e. precomputation is not available */
368 int ret = 0; 211 int ret = 0;
369 212
370 if (group->meth != r->meth) 213 if (group->meth != r->meth)
371 { 214 {
372 ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS); 215 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
373 return 0; 216 return 0;
374 } 217 }
375 218
@@ -378,226 +221,59 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
378 return EC_POINT_set_to_infinity(group, r); 221 return EC_POINT_set_to_infinity(group, r);
379 } 222 }
380 223
381 for (i = 0; i < num; i++)
382 {
383 if (group->meth != points[i]->meth)
384 {
385 ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);
386 return 0;
387 }
388 }
389
390 if (ctx == NULL)
391 {
392 ctx = new_ctx = BN_CTX_new();
393 if (ctx == NULL)
394 goto err;
395 }
396
397 if (scalar != NULL) 224 if (scalar != NULL)
398 { 225 {
399 generator = EC_GROUP_get0_generator(group); 226 generator = EC_GROUP_get0_generator(group);
400 if (generator == NULL) 227 if (generator == NULL)
401 { 228 {
402 ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR); 229 ECerr(EC_F_EC_POINTS_MUL, EC_R_UNDEFINED_GENERATOR);
403 goto err; 230 return 0;
404 }
405
406 /* look if we can use precomputed multiples of generator */
407
408 pre_comp = EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
409
410 if (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0))
411 {
412 blocksize = pre_comp->blocksize;
413
414 /* determine maximum number of blocks that wNAF splitting may yield
415 * (NB: maximum wNAF length is bit length plus one) */
416 numblocks = (BN_num_bits(scalar) / blocksize) + 1;
417
418 /* we cannot use more blocks than we have precomputation for */
419 if (numblocks > pre_comp->numblocks)
420 numblocks = pre_comp->numblocks;
421
422 pre_points_per_block = 1u << (pre_comp->w - 1);
423
424 /* check that pre_comp looks sane */
425 if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block))
426 {
427 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
428 goto err;
429 }
430 } 231 }
431 else 232 }
233
234 for (i = 0; i < num; i++)
235 {
236 if (group->meth != points[i]->meth)
432 { 237 {
433 /* can't use precomputation */ 238 ECerr(EC_F_EC_POINTS_MUL, EC_R_INCOMPATIBLE_OBJECTS);
434 pre_comp = NULL; 239 return 0;
435 numblocks = 1;
436 num_scalar = 1; /* treat 'scalar' like 'num'-th element of 'scalars' */
437 } 240 }
438 } 241 }
439
440 totalnum = num + numblocks;
441 242
442 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]); 243 totalnum = num + (scalar != NULL);
244
245 wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);
443 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]); 246 wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
444 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]); /* includes space for pivot */ 247 wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);
445 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]); 248 if (wNAF != NULL)
446
447 if (!wsize || !wNAF_len || !wNAF || !val_sub)
448 { 249 {
449 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE); 250 wNAF[0] = NULL; /* preliminary pivot */
450 goto err;
451 } 251 }
252 if (wsize == NULL || wNAF_len == NULL || wNAF == NULL) goto err;
452 253
453 wNAF[0] = NULL; /* preliminary pivot */ 254 /* num_val := total number of points to precompute */
454
455 /* num_val will be the total number of temporarily precomputed points */
456 num_val = 0; 255 num_val = 0;
457 256 for (i = 0; i < totalnum; i++)
458 for (i = 0; i < num + num_scalar; i++)
459 { 257 {
460 size_t bits; 258 size_t bits;
461 259
462 bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar); 260 bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
463 wsize[i] = EC_window_bits_for_scalar_size(bits); 261 wsize[i] = EC_window_bits_for_scalar_size(bits);
464 num_val += 1u << (wsize[i] - 1); 262 num_val += 1u << (wsize[i] - 1);
465 wNAF[i + 1] = NULL; /* make sure we always have a pivot */
466 wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]);
467 if (wNAF[i] == NULL)
468 goto err;
469 if (wNAF_len[i] > max_len)
470 max_len = wNAF_len[i];
471 }
472
473 if (numblocks)
474 {
475 /* we go here iff scalar != NULL */
476
477 if (pre_comp == NULL)
478 {
479 if (num_scalar != 1)
480 {
481 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
482 goto err;
483 }
484 /* we have already generated a wNAF for 'scalar' */
485 }
486 else
487 {
488 signed char *tmp_wNAF = NULL;
489 size_t tmp_len = 0;
490
491 if (num_scalar != 0)
492 {
493 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
494 goto err;
495 }
496
497 /* use the window size for which we have precomputation */
498 wsize[num] = pre_comp->w;
499 tmp_wNAF = compute_wNAF(scalar, wsize[num], &tmp_len);
500 if (!tmp_wNAF)
501 goto err;
502
503 if (tmp_len <= max_len)
504 {
505 /* One of the other wNAFs is at least as long
506 * as the wNAF belonging to the generator,
507 * so wNAF splitting will not buy us anything. */
508
509 numblocks = 1;
510 totalnum = num + 1; /* don't use wNAF splitting */
511 wNAF[num] = tmp_wNAF;
512 wNAF[num + 1] = NULL;
513 wNAF_len[num] = tmp_len;
514 if (tmp_len > max_len)
515 max_len = tmp_len;
516 /* pre_comp->points starts with the points that we need here: */
517 val_sub[num] = pre_comp->points;
518 }
519 else
520 {
521 /* don't include tmp_wNAF directly into wNAF array
522 * - use wNAF splitting and include the blocks */
523
524 signed char *pp;
525 EC_POINT **tmp_points;
526
527 if (tmp_len < numblocks * blocksize)
528 {
529 /* possibly we can do with fewer blocks than estimated */
530 numblocks = (tmp_len + blocksize - 1) / blocksize;
531 if (numblocks > pre_comp->numblocks)
532 {
533 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
534 goto err;
535 }
536 totalnum = num + numblocks;
537 }
538
539 /* split wNAF in 'numblocks' parts */
540 pp = tmp_wNAF;
541 tmp_points = pre_comp->points;
542
543 for (i = num; i < totalnum; i++)
544 {
545 if (i < totalnum - 1)
546 {
547 wNAF_len[i] = blocksize;
548 if (tmp_len < blocksize)
549 {
550 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
551 goto err;
552 }
553 tmp_len -= blocksize;
554 }
555 else
556 /* last block gets whatever is left
557 * (this could be more or less than 'blocksize'!) */
558 wNAF_len[i] = tmp_len;
559
560 wNAF[i + 1] = NULL;
561 wNAF[i] = OPENSSL_malloc(wNAF_len[i]);
562 if (wNAF[i] == NULL)
563 {
564 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
565 OPENSSL_free(tmp_wNAF);
566 goto err;
567 }
568 memcpy(wNAF[i], pp, wNAF_len[i]);
569 if (wNAF_len[i] > max_len)
570 max_len = wNAF_len[i];
571
572 if (*tmp_points == NULL)
573 {
574 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
575 OPENSSL_free(tmp_wNAF);
576 goto err;
577 }
578 val_sub[i] = tmp_points;
579 tmp_points += pre_points_per_block;
580 pp += blocksize;
581 }
582 OPENSSL_free(tmp_wNAF);
583 }
584 }
585 } 263 }
586 264
587 /* All points we precompute now go into a single array 'val'. 265 /* all precomputed points go into a single array 'val',
588 * 'val_sub[i]' is a pointer to the subarray for the i-th point, 266 * 'val_sub[i]' is a pointer to the subarray for the i-th point */
589 * or to a subarray of 'pre_comp->points' if we already have precomputation. */
590 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]); 267 val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);
591 if (val == NULL) 268 if (val == NULL) goto err;
592 {
593 ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
594 goto err;
595 }
596 val[num_val] = NULL; /* pivot element */ 269 val[num_val] = NULL; /* pivot element */
597 270
271 val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
272 if (val_sub == NULL) goto err;
273
598 /* allocate points for precomputation */ 274 /* allocate points for precomputation */
599 v = val; 275 v = val;
600 for (i = 0; i < num + num_scalar; i++) 276 for (i = 0; i < totalnum; i++)
601 { 277 {
602 val_sub[i] = v; 278 val_sub[i] = v;
603 for (j = 0; j < (1u << (wsize[i] - 1)); j++) 279 for (j = 0; j < (1u << (wsize[i] - 1)); j++)
@@ -609,12 +285,19 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
609 } 285 }
610 if (!(v == val + num_val)) 286 if (!(v == val + num_val))
611 { 287 {
612 ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR); 288 ECerr(EC_F_EC_POINTS_MUL, ERR_R_INTERNAL_ERROR);
613 goto err; 289 goto err;
614 } 290 }
615 291
616 if (!(tmp = EC_POINT_new(group))) 292 if (ctx == NULL)
617 goto err; 293 {
294 ctx = new_ctx = BN_CTX_new();
295 if (ctx == NULL)
296 goto err;
297 }
298
299 tmp = EC_POINT_new(group);
300 if (tmp == NULL) goto err;
618 301
619 /* prepare precomputed values: 302 /* prepare precomputed values:
620 * val_sub[i][0] := points[i] 303 * val_sub[i][0] := points[i]
@@ -622,7 +305,7 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
622 * val_sub[i][2] := 5 * points[i] 305 * val_sub[i][2] := 5 * points[i]
623 * ... 306 * ...
624 */ 307 */
625 for (i = 0; i < num + num_scalar; i++) 308 for (i = 0; i < totalnum; i++)
626 { 309 {
627 if (i < num) 310 if (i < num)
628 { 311 {
@@ -641,11 +324,16 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
641 if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err; 324 if (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;
642 } 325 }
643 } 326 }
327
328 wNAF[i + 1] = NULL; /* make sure we always have a pivot */
329 wNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i], ctx);
330 if (wNAF[i] == NULL) goto err;
331 if (wNAF_len[i] > max_len)
332 max_len = wNAF_len[i];
644 } 333 }
645 334
646#if 1 /* optional; EC_window_bits_for_scalar_size assumes we do this step */ 335#if 1 /* optional; EC_window_bits_for_scalar_size assumes we do this step */
647 if (!EC_POINTs_make_affine(group, num_val, val, ctx)) 336 if (!EC_POINTs_make_affine(group, num_val, val, ctx)) goto err;
648 goto err;
649#endif 337#endif
650 338
651 r_is_at_infinity = 1; 339 r_is_at_infinity = 1;
@@ -741,198 +429,57 @@ int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
741 } 429 }
742 430
743 431
744/* ec_wNAF_precompute_mult() 432int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
745 * creates an EC_PRE_COMP object with preprecomputed multiples of the generator 433 {
746 * for use with wNAF splitting as implemented in ec_wNAF_mul(). 434 const EC_POINT *points[1];
747 * 435 const BIGNUM *scalars[1];
748 * 'pre_comp->points' is an array of multiples of the generator 436
749 * of the following form: 437 points[0] = point;
750 * points[0] = generator; 438 scalars[0] = p_scalar;
751 * points[1] = 3 * generator; 439
752 * ... 440 return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
753 * points[2^(w-1)-1] = (2^(w-1)-1) * generator; 441 }
754 * points[2^(w-1)] = 2^blocksize * generator; 442
755 * points[2^(w-1)+1] = 3 * 2^blocksize * generator; 443
756 * ... 444int EC_GROUP_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
757 * points[2^(w-1)*(numblocks-1)-1] = (2^(w-1)) * 2^(blocksize*(numblocks-2)) * generator
758 * points[2^(w-1)*(numblocks-1)] = 2^(blocksize*(numblocks-1)) * generator
759 * ...
760 * points[2^(w-1)*numblocks-1] = (2^(w-1)) * 2^(blocksize*(numblocks-1)) * generator
761 * points[2^(w-1)*numblocks] = NULL
762 */
763int ec_wNAF_precompute_mult(EC_GROUP *group, BN_CTX *ctx)
764 { 445 {
765 const EC_POINT *generator; 446 const EC_POINT *generator;
766 EC_POINT *tmp_point = NULL, *base = NULL, **var;
767 BN_CTX *new_ctx = NULL; 447 BN_CTX *new_ctx = NULL;
768 BIGNUM *order; 448 BIGNUM *order;
769 size_t i, bits, w, pre_points_per_block, blocksize, numblocks, num;
770 EC_POINT **points = NULL;
771 EC_PRE_COMP *pre_comp;
772 int ret = 0; 449 int ret = 0;
773 450
774 /* if there is an old EC_PRE_COMP object, throw it away */
775 EC_EX_DATA_free_data(&group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);
776
777 if ((pre_comp = ec_pre_comp_new(group)) == NULL)
778 return 0;
779
780 generator = EC_GROUP_get0_generator(group); 451 generator = EC_GROUP_get0_generator(group);
781 if (generator == NULL) 452 if (generator == NULL)
782 { 453 {
783 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR); 454 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNDEFINED_GENERATOR);
784 goto err; 455 return 0;
785 } 456 }
786 457
787 if (ctx == NULL) 458 if (ctx == NULL)
788 { 459 {
789 ctx = new_ctx = BN_CTX_new(); 460 ctx = new_ctx = BN_CTX_new();
790 if (ctx == NULL) 461 if (ctx == NULL)
791 goto err; 462 return 0;
792 } 463 }
793 464
794 BN_CTX_start(ctx); 465 BN_CTX_start(ctx);
795 order = BN_CTX_get(ctx); 466 order = BN_CTX_get(ctx);
796 if (order == NULL) goto err; 467 if (order == NULL) goto err;
797 468
798 if (!EC_GROUP_get_order(group, order, ctx)) goto err; 469 if (!EC_GROUP_get_order(group, order, ctx)) return 0;
799 if (BN_is_zero(order)) 470 if (BN_is_zero(order))
800 { 471 {
801 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER); 472 ECerr(EC_F_EC_GROUP_PRECOMPUTE_MULT, EC_R_UNKNOWN_ORDER);
802 goto err; 473 goto err;
803 } 474 }
804 475
805 bits = BN_num_bits(order); 476 /* TODO */
806 /* The following parameters mean we precompute (approximately)
807 * one point per bit.
808 *
809 * TBD: The combination 8, 4 is perfect for 160 bits; for other
810 * bit lengths, other parameter combinations might provide better
811 * efficiency.
812 */
813 blocksize = 8;
814 w = 4;
815 if (EC_window_bits_for_scalar_size(bits) > w)
816 {
817 /* let's not make the window too small ... */
818 w = EC_window_bits_for_scalar_size(bits);
819 }
820
821 numblocks = (bits + blocksize - 1) / blocksize; /* max. number of blocks to use for wNAF splitting */
822
823 pre_points_per_block = 1u << (w - 1);
824 num = pre_points_per_block * numblocks; /* number of points to compute and store */
825
826 points = OPENSSL_malloc(sizeof (EC_POINT*)*(num + 1));
827 if (!points)
828 {
829 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
830 goto err;
831 }
832
833 var = points;
834 var[num] = NULL; /* pivot */
835 for (i = 0; i < num; i++)
836 {
837 if ((var[i] = EC_POINT_new(group)) == NULL)
838 {
839 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
840 goto err;
841 }
842 }
843
844 if (!(tmp_point = EC_POINT_new(group)) || !(base = EC_POINT_new(group)))
845 {
846 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_MALLOC_FAILURE);
847 goto err;
848 }
849
850 if (!EC_POINT_copy(base, generator))
851 goto err;
852
853 /* do the precomputation */
854 for (i = 0; i < numblocks; i++)
855 {
856 size_t j;
857
858 if (!EC_POINT_dbl(group, tmp_point, base, ctx))
859 goto err;
860
861 if (!EC_POINT_copy(*var++, base))
862 goto err;
863
864 for (j = 1; j < pre_points_per_block; j++, var++)
865 {
866 /* calculate odd multiples of the current base point */
867 if (!EC_POINT_add(group, *var, tmp_point, *(var - 1), ctx))
868 goto err;
869 }
870
871 if (i < numblocks - 1)
872 {
873 /* get the next base (multiply current one by 2^blocksize) */
874 size_t k;
875
876 if (blocksize <= 2)
877 {
878 ECerr(EC_F_EC_WNAF_PRECOMPUTE_MULT, ERR_R_INTERNAL_ERROR);
879 goto err;
880 }
881
882 if (!EC_POINT_dbl(group, base, tmp_point, ctx))
883 goto err;
884 for (k = 2; k < blocksize; k++)
885 {
886 if (!EC_POINT_dbl(group,base,base,ctx))
887 goto err;
888 }
889 }
890 }
891
892 if (!EC_POINTs_make_affine(group, num, points, ctx))
893 goto err;
894
895 pre_comp->group = group;
896 pre_comp->blocksize = blocksize;
897 pre_comp->numblocks = numblocks;
898 pre_comp->w = w;
899 pre_comp->points = points;
900 points = NULL;
901 pre_comp->num = num;
902
903 if (!EC_EX_DATA_set_data(&group->extra_data, pre_comp,
904 ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free))
905 goto err;
906 pre_comp = NULL;
907 477
908 ret = 1; 478 ret = 1;
479
909 err: 480 err:
910 if (ctx != NULL) 481 BN_CTX_end(ctx);
911 BN_CTX_end(ctx);
912 if (new_ctx != NULL) 482 if (new_ctx != NULL)
913 BN_CTX_free(new_ctx); 483 BN_CTX_free(new_ctx);
914 if (pre_comp)
915 ec_pre_comp_free(pre_comp);
916 if (points)
917 {
918 EC_POINT **p;
919
920 for (p = points; *p != NULL; p++)
921 EC_POINT_free(*p);
922 OPENSSL_free(points);
923 }
924 if (tmp_point)
925 EC_POINT_free(tmp_point);
926 if (base)
927 EC_POINT_free(base);
928 return ret; 484 return ret;
929 } 485 }
930
931
932int ec_wNAF_have_precompute_mult(const EC_GROUP *group)
933 {
934 if (EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free) != NULL)
935 return 1;
936 else
937 return 0;
938 }
diff --git a/src/lib/libcrypto/ec/ecp_mont.c b/src/lib/libcrypto/ec/ecp_mont.c
index 9fc4a466a5..7b30d4c38a 100644
--- a/src/lib/libcrypto/ec/ecp_mont.c
+++ b/src/lib/libcrypto/ec/ecp_mont.c
@@ -1,7 +1,4 @@
1/* crypto/ec/ecp_mont.c */ 1/* crypto/ec/ecp_mont.c */
2/*
3 * Originally written by Bodo Moeller for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
@@ -55,11 +52,6 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Portions of this software developed by SUN MICROSYSTEMS, INC.,
61 * and contributed to the OpenSSL project.
62 */
63 55
64#include <openssl/err.h> 56#include <openssl/err.h>
65 57
@@ -69,15 +61,16 @@
69const EC_METHOD *EC_GFp_mont_method(void) 61const EC_METHOD *EC_GFp_mont_method(void)
70 { 62 {
71 static const EC_METHOD ret = { 63 static const EC_METHOD ret = {
72 NID_X9_62_prime_field,
73 ec_GFp_mont_group_init, 64 ec_GFp_mont_group_init,
74 ec_GFp_mont_group_finish, 65 ec_GFp_mont_group_finish,
75 ec_GFp_mont_group_clear_finish, 66 ec_GFp_mont_group_clear_finish,
76 ec_GFp_mont_group_copy, 67 ec_GFp_mont_group_copy,
77 ec_GFp_mont_group_set_curve, 68 ec_GFp_mont_group_set_curve_GFp,
78 ec_GFp_simple_group_get_curve, 69 ec_GFp_simple_group_get_curve_GFp,
79 ec_GFp_simple_group_get_degree, 70 ec_GFp_simple_group_set_generator,
80 ec_GFp_simple_group_check_discriminant, 71 ec_GFp_simple_group_get0_generator,
72 ec_GFp_simple_group_get_order,
73 ec_GFp_simple_group_get_cofactor,
81 ec_GFp_simple_point_init, 74 ec_GFp_simple_point_init,
82 ec_GFp_simple_point_finish, 75 ec_GFp_simple_point_finish,
83 ec_GFp_simple_point_clear_finish, 76 ec_GFp_simple_point_clear_finish,
@@ -85,9 +78,9 @@ const EC_METHOD *EC_GFp_mont_method(void)
85 ec_GFp_simple_point_set_to_infinity, 78 ec_GFp_simple_point_set_to_infinity,
86 ec_GFp_simple_set_Jprojective_coordinates_GFp, 79 ec_GFp_simple_set_Jprojective_coordinates_GFp,
87 ec_GFp_simple_get_Jprojective_coordinates_GFp, 80 ec_GFp_simple_get_Jprojective_coordinates_GFp,
88 ec_GFp_simple_point_set_affine_coordinates, 81 ec_GFp_simple_point_set_affine_coordinates_GFp,
89 ec_GFp_simple_point_get_affine_coordinates, 82 ec_GFp_simple_point_get_affine_coordinates_GFp,
90 ec_GFp_simple_set_compressed_coordinates, 83 ec_GFp_simple_set_compressed_coordinates_GFp,
91 ec_GFp_simple_point2oct, 84 ec_GFp_simple_point2oct,
92 ec_GFp_simple_oct2point, 85 ec_GFp_simple_oct2point,
93 ec_GFp_simple_add, 86 ec_GFp_simple_add,
@@ -98,12 +91,8 @@ const EC_METHOD *EC_GFp_mont_method(void)
98 ec_GFp_simple_cmp, 91 ec_GFp_simple_cmp,
99 ec_GFp_simple_make_affine, 92 ec_GFp_simple_make_affine,
100 ec_GFp_simple_points_make_affine, 93 ec_GFp_simple_points_make_affine,
101 0 /* mul */,
102 0 /* precompute_mult */,
103 0 /* have_precompute_mult */,
104 ec_GFp_mont_field_mul, 94 ec_GFp_mont_field_mul,
105 ec_GFp_mont_field_sqr, 95 ec_GFp_mont_field_sqr,
106 0 /* field_div */,
107 ec_GFp_mont_field_encode, 96 ec_GFp_mont_field_encode,
108 ec_GFp_mont_field_decode, 97 ec_GFp_mont_field_decode,
109 ec_GFp_mont_field_set_to_one }; 98 ec_GFp_mont_field_set_to_one };
@@ -123,6 +112,66 @@ int ec_GFp_mont_group_init(EC_GROUP *group)
123 } 112 }
124 113
125 114
115int ec_GFp_mont_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
116 {
117 BN_CTX *new_ctx = NULL;
118 BN_MONT_CTX *mont = NULL;
119 BIGNUM *one = NULL;
120 int ret = 0;
121
122 if (group->field_data1 != NULL)
123 {
124 BN_MONT_CTX_free(group->field_data1);
125 group->field_data1 = NULL;
126 }
127 if (group->field_data2 != NULL)
128 {
129 BN_free(group->field_data2);
130 group->field_data2 = NULL;
131 }
132
133 if (ctx == NULL)
134 {
135 ctx = new_ctx = BN_CTX_new();
136 if (ctx == NULL)
137 return 0;
138 }
139
140 mont = BN_MONT_CTX_new();
141 if (mont == NULL) goto err;
142 if (!BN_MONT_CTX_set(mont, p, ctx))
143 {
144 ECerr(EC_F_GFP_MONT_GROUP_SET_CURVE_GFP, ERR_R_BN_LIB);
145 goto err;
146 }
147 one = BN_new();
148 if (one == NULL) goto err;
149 if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) goto err;
150
151 group->field_data1 = mont;
152 mont = NULL;
153 group->field_data2 = one;
154 one = NULL;
155
156 ret = ec_GFp_simple_group_set_curve_GFp(group, p, a, b, ctx);
157
158 if (!ret)
159 {
160 BN_MONT_CTX_free(group->field_data1);
161 group->field_data1 = NULL;
162 BN_free(group->field_data2);
163 group->field_data2 = NULL;
164 }
165
166 err:
167 if (new_ctx != NULL)
168 BN_CTX_free(new_ctx);
169 if (mont != NULL)
170 BN_MONT_CTX_free(mont);
171 return ret;
172 }
173
174
126void ec_GFp_mont_group_finish(EC_GROUP *group) 175void ec_GFp_mont_group_finish(EC_GROUP *group)
127 { 176 {
128 if (group->field_data1 != NULL) 177 if (group->field_data1 != NULL)
@@ -194,66 +243,6 @@ int ec_GFp_mont_group_copy(EC_GROUP *dest, const EC_GROUP *src)
194 } 243 }
195 244
196 245
197int ec_GFp_mont_group_set_curve(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
198 {
199 BN_CTX *new_ctx = NULL;
200 BN_MONT_CTX *mont = NULL;
201 BIGNUM *one = NULL;
202 int ret = 0;
203
204 if (group->field_data1 != NULL)
205 {
206 BN_MONT_CTX_free(group->field_data1);
207 group->field_data1 = NULL;
208 }
209 if (group->field_data2 != NULL)
210 {
211 BN_free(group->field_data2);
212 group->field_data2 = NULL;
213 }
214
215 if (ctx == NULL)
216 {
217 ctx = new_ctx = BN_CTX_new();
218 if (ctx == NULL)
219 return 0;
220 }
221
222 mont = BN_MONT_CTX_new();
223 if (mont == NULL) goto err;
224 if (!BN_MONT_CTX_set(mont, p, ctx))
225 {
226 ECerr(EC_F_EC_GFP_MONT_GROUP_SET_CURVE, ERR_R_BN_LIB);
227 goto err;
228 }
229 one = BN_new();
230 if (one == NULL) goto err;
231 if (!BN_to_montgomery(one, BN_value_one(), mont, ctx)) goto err;
232
233 group->field_data1 = mont;
234 mont = NULL;
235 group->field_data2 = one;
236 one = NULL;
237
238 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
239
240 if (!ret)
241 {
242 BN_MONT_CTX_free(group->field_data1);
243 group->field_data1 = NULL;
244 BN_free(group->field_data2);
245 group->field_data2 = NULL;
246 }
247
248 err:
249 if (new_ctx != NULL)
250 BN_CTX_free(new_ctx);
251 if (mont != NULL)
252 BN_MONT_CTX_free(mont);
253 return ret;
254 }
255
256
257int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 246int ec_GFp_mont_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
258 { 247 {
259 if (group->field_data1 == NULL) 248 if (group->field_data1 == NULL)
@@ -306,7 +295,7 @@ int ec_GFp_mont_field_set_to_one(const EC_GROUP *group, BIGNUM *r, BN_CTX *ctx)
306 { 295 {
307 if (group->field_data2 == NULL) 296 if (group->field_data2 == NULL)
308 { 297 {
309 ECerr(EC_F_EC_GFP_MONT_FIELD_SET_TO_ONE, EC_R_NOT_INITIALIZED); 298 ECerr(EC_F_EC_GFP_MONT_FIELD_DECODE, EC_R_NOT_INITIALIZED);
310 return 0; 299 return 0;
311 } 300 }
312 301
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c
index 71893d5eab..ed07748675 100644
--- a/src/lib/libcrypto/ec/ecp_nist.c
+++ b/src/lib/libcrypto/ec/ecp_nist.c
@@ -1,9 +1,6 @@
1/* crypto/ec/ecp_nist.c */ 1/* crypto/ec/ecp_nist.c */
2/*
3 * Written by Nils Larsch for the OpenSSL project.
4 */
5/* ==================================================================== 2/* ====================================================================
6 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
7 * 4 *
8 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -55,30 +52,23 @@
55 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
56 * 53 *
57 */ 54 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * Portions of this software developed by SUN MICROSYSTEMS, INC.,
61 * and contributed to the OpenSSL project.
62 */
63 55
64#include <limits.h>
65
66#include <openssl/err.h>
67#include <openssl/obj_mac.h>
68#include "ec_lcl.h" 56#include "ec_lcl.h"
69 57
58#if 0
70const EC_METHOD *EC_GFp_nist_method(void) 59const EC_METHOD *EC_GFp_nist_method(void)
71 { 60 {
72 static const EC_METHOD ret = { 61 static const EC_METHOD ret = {
73 NID_X9_62_prime_field, 62 ec_GFp_nist_group_init,
74 ec_GFp_simple_group_init, 63 ec_GFp_nist_group_finish,
75 ec_GFp_simple_group_finish, 64 ec_GFp_nist_group_clear_finish,
76 ec_GFp_simple_group_clear_finish,
77 ec_GFp_nist_group_copy, 65 ec_GFp_nist_group_copy,
78 ec_GFp_nist_group_set_curve, 66 ec_GFp_nist_group_set_curve_GFp,
79 ec_GFp_simple_group_get_curve, 67 ec_GFp_simple_group_get_curve_GFp,
80 ec_GFp_simple_group_get_degree, 68 ec_GFp_simple_group_set_generator,
81 ec_GFp_simple_group_check_discriminant, 69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
82 ec_GFp_simple_point_init, 72 ec_GFp_simple_point_init,
83 ec_GFp_simple_point_finish, 73 ec_GFp_simple_point_finish,
84 ec_GFp_simple_point_clear_finish, 74 ec_GFp_simple_point_clear_finish,
@@ -86,9 +76,9 @@ const EC_METHOD *EC_GFp_nist_method(void)
86 ec_GFp_simple_point_set_to_infinity, 76 ec_GFp_simple_point_set_to_infinity,
87 ec_GFp_simple_set_Jprojective_coordinates_GFp, 77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
88 ec_GFp_simple_get_Jprojective_coordinates_GFp, 78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
89 ec_GFp_simple_point_set_affine_coordinates, 79 ec_GFp_simple_point_set_affine_coordinates_GFp,
90 ec_GFp_simple_point_get_affine_coordinates, 80 ec_GFp_simple_point_get_affine_coordinates_GFp,
91 ec_GFp_simple_set_compressed_coordinates, 81 ec_GFp_simple_set_compressed_coordinates_GFp,
92 ec_GFp_simple_point2oct, 82 ec_GFp_simple_point2oct,
93 ec_GFp_simple_oct2point, 83 ec_GFp_simple_oct2point,
94 ec_GFp_simple_add, 84 ec_GFp_simple_add,
@@ -99,138 +89,46 @@ const EC_METHOD *EC_GFp_nist_method(void)
99 ec_GFp_simple_cmp, 89 ec_GFp_simple_cmp,
100 ec_GFp_simple_make_affine, 90 ec_GFp_simple_make_affine,
101 ec_GFp_simple_points_make_affine, 91 ec_GFp_simple_points_make_affine,
102 0 /* mul */,
103 0 /* precompute_mult */,
104 0 /* have_precompute_mult */,
105 ec_GFp_nist_field_mul, 92 ec_GFp_nist_field_mul,
106 ec_GFp_nist_field_sqr, 93 ec_GFp_nist_field_sqr,
107 0 /* field_div */,
108 0 /* field_encode */, 94 0 /* field_encode */,
109 0 /* field_decode */, 95 0 /* field_decode */,
110 0 /* field_set_to_one */ }; 96 0 /* field_set_to_one */ };
111 97
112 return &ret; 98 return &ret;
113 } 99 }
114
115#if BN_BITS2 == 64
116#define NO_32_BIT_TYPE
117#endif 100#endif
118 101
119int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) 102
103int ec_GFp_nist_group_init(EC_GROUP *group)
120 { 104 {
121 dest->field_mod_func = src->field_mod_func; 105 int ok;
122 106
123 return ec_GFp_simple_group_copy(dest, src); 107 ok = ec_GFp_simple_group_init(group);
108 group->field_data1 = NULL;
109 return ok;
124 } 110 }
125 111
126int ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p,
127 const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
128 {
129 int ret = 0;
130 BN_CTX *new_ctx = NULL;
131 BIGNUM *tmp_bn;
132
133 if (ctx == NULL)
134 if ((ctx = new_ctx = BN_CTX_new()) == NULL) return 0;
135
136 BN_CTX_start(ctx);
137 if ((tmp_bn = BN_CTX_get(ctx)) == NULL) goto err;
138
139 if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0)
140 group->field_mod_func = BN_nist_mod_192;
141 else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0)
142 {
143#ifndef NO_32_BIT_TYPE
144 group->field_mod_func = BN_nist_mod_224;
145#else
146 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
147 goto err;
148#endif
149 }
150 else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0)
151 {
152#ifndef NO_32_BIT_TYPE
153 group->field_mod_func = BN_nist_mod_256;
154#else
155 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
156 goto err;
157#endif
158 }
159 else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0)
160 {
161#ifndef NO_32_BIT_TYPE
162 group->field_mod_func = BN_nist_mod_384;
163#else
164 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_SUPPORTED_NIST_PRIME);
165 goto err;
166#endif
167 }
168 else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0)
169 /* this one works in the NO_32_BIT_TYPE case */
170 group->field_mod_func = BN_nist_mod_521;
171 else
172 {
173 ECerr(EC_F_EC_GFP_NIST_GROUP_SET_CURVE, EC_R_NOT_A_NIST_PRIME);
174 goto err;
175 }
176
177 ret = ec_GFp_simple_group_set_curve(group, p, a, b, ctx);
178
179 err:
180 BN_CTX_end(ctx);
181 if (new_ctx != NULL)
182 BN_CTX_free(new_ctx);
183 return ret;
184 }
185 112
113int ec_GFp_nist_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
114/* TODO */
186 115
187int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a,
188 const BIGNUM *b, BN_CTX *ctx)
189 {
190 int ret=0;
191 BN_CTX *ctx_new=NULL;
192
193 if (!group || !r || !a || !b)
194 {
195 ECerr(EC_F_EC_GFP_NIST_FIELD_MUL, ERR_R_PASSED_NULL_PARAMETER);
196 goto err;
197 }
198 if (!ctx)
199 if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err;
200
201 if (!BN_mul(r, a, b, ctx)) goto err;
202 if (!group->field_mod_func(r, r, &group->field, ctx))
203 goto err;
204
205 ret=1;
206err:
207 if (ctx_new)
208 BN_CTX_free(ctx_new);
209 return ret;
210 }
211 116
117void ec_GFp_nist_group_finish(EC_GROUP *group);
118/* TODO */
212 119
213int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, 120
214 BN_CTX *ctx) 121void ec_GFp_nist_group_clear_finish(EC_GROUP *group);
215 { 122/* TODO */
216 int ret=0; 123
217 BN_CTX *ctx_new=NULL; 124
218 125int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src);
219 if (!group || !r || !a) 126/* TODO */
220 { 127
221 ECerr(EC_F_EC_GFP_NIST_FIELD_SQR, EC_R_PASSED_NULL_PARAMETER); 128
222 goto err; 129int ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
223 } 130/* TODO */
224 if (!ctx) 131
225 if ((ctx_new = ctx = BN_CTX_new()) == NULL) goto err; 132
226 133int ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
227 if (!BN_sqr(r, a, ctx)) goto err; 134/* TODO */
228 if (!group->field_mod_func(r, r, &group->field, ctx))
229 goto err;
230
231 ret=1;
232err:
233 if (ctx_new)
234 BN_CTX_free(ctx_new);
235 return ret;
236 }
diff --git a/src/lib/libcrypto/ec/ecp_recp.c b/src/lib/libcrypto/ec/ecp_recp.c
new file mode 100644
index 0000000000..fec843b5c8
--- /dev/null
+++ b/src/lib/libcrypto/ec/ecp_recp.c
@@ -0,0 +1,133 @@
1/* crypto/ec/ecp_recp.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "ec_lcl.h"
57
58#if 0
59const EC_METHOD *EC_GFp_recp_method(void)
60 {
61 static const EC_METHOD ret = {
62 ec_GFp_recp_group_init,
63 ec_GFp_recp_group_finish,
64 ec_GFp_recp_group_clear_finish,
65 ec_GFp_recp_group_copy,
66 ec_GFp_recp_group_set_curve_GFp,
67 ec_GFp_simple_group_get_curve_GFp,
68 ec_GFp_simple_group_set_generator,
69 ec_GFp_simple_group_get0_generator,
70 ec_GFp_simple_group_get_order,
71 ec_GFp_simple_group_get_cofactor,
72 ec_GFp_simple_point_init,
73 ec_GFp_simple_point_finish,
74 ec_GFp_simple_point_clear_finish,
75 ec_GFp_simple_point_copy,
76 ec_GFp_simple_point_set_to_infinity,
77 ec_GFp_simple_set_Jprojective_coordinates_GFp,
78 ec_GFp_simple_get_Jprojective_coordinates_GFp,
79 ec_GFp_simple_point_set_affine_coordinates_GFp,
80 ec_GFp_simple_point_get_affine_coordinates_GFp,
81 ec_GFp_simple_set_compressed_coordinates_GFp,
82 ec_GFp_simple_point2oct,
83 ec_GFp_simple_oct2point,
84 ec_GFp_simple_add,
85 ec_GFp_simple_dbl,
86 ec_GFp_simple_invert,
87 ec_GFp_simple_is_at_infinity,
88 ec_GFp_simple_is_on_curve,
89 ec_GFp_simple_cmp,
90 ec_GFp_simple_make_affine,
91 ec_GFp_simple_points_make_affine,
92 ec_GFp_recp_field_mul,
93 ec_GFp_recp_field_sqr,
94 0 /* field_encode */,
95 0 /* field_decode */,
96 0 /* field_set_to_one */ };
97
98 return &ret;
99 }
100#endif
101
102int ec_GFp_recp_group_init(EC_GROUP *group)
103 {
104 int ok;
105
106 ok = ec_GFp_simple_group_init(group);
107 group->field_data1 = NULL;
108 return ok;
109 }
110
111
112int ec_GFp_recp_group_set_curve_GFp(EC_GROUP *group, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
113/* TODO */
114
115
116void ec_GFp_recp_group_finish(EC_GROUP *group);
117/* TODO */
118
119
120void ec_GFp_recp_group_clear_finish(EC_GROUP *group);
121/* TODO */
122
123
124int ec_GFp_recp_group_copy(EC_GROUP *dest, const EC_GROUP *src);
125/* TODO */
126
127
128int ec_GFp_recp_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx);
129/* TODO */
130
131
132int ec_GFp_recp_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, BN_CTX *ctx);
133/* TODO */
diff --git a/src/lib/libcrypto/ec/ecp_smpl.c b/src/lib/libcrypto/ec/ecp_smpl.c
index 4d26f8bdf6..e9a51fb87a 100644
--- a/src/lib/libcrypto/ec/ecp_smpl.c
+++ b/src/lib/libcrypto/ec/ecp_smpl.c
@@ -1,10 +1,8 @@
1/* crypto/ec/ecp_smpl.c */ 1/* crypto/ec/ecp_smpl.c */
2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de> 2/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
3 * for the OpenSSL project. 3 * for the OpenSSL project. */
4 * Includes code written by Bodo Moeller for the OpenSSL project.
5*/
6/* ==================================================================== 4/* ====================================================================
7 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 5 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
8 * 6 *
9 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
@@ -56,29 +54,25 @@
56 * Hudson (tjh@cryptsoft.com). 54 * Hudson (tjh@cryptsoft.com).
57 * 55 *
58 */ 56 */
59/* ====================================================================
60 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
61 * Portions of this software developed by SUN MICROSYSTEMS, INC.,
62 * and contributed to the OpenSSL project.
63 */
64 57
65#include <openssl/err.h> 58#include <openssl/err.h>
66#include <openssl/symhacks.h>
67 59
68#include "ec_lcl.h" 60#include "ec_lcl.h"
69 61
62
70const EC_METHOD *EC_GFp_simple_method(void) 63const EC_METHOD *EC_GFp_simple_method(void)
71 { 64 {
72 static const EC_METHOD ret = { 65 static const EC_METHOD ret = {
73 NID_X9_62_prime_field,
74 ec_GFp_simple_group_init, 66 ec_GFp_simple_group_init,
75 ec_GFp_simple_group_finish, 67 ec_GFp_simple_group_finish,
76 ec_GFp_simple_group_clear_finish, 68 ec_GFp_simple_group_clear_finish,
77 ec_GFp_simple_group_copy, 69 ec_GFp_simple_group_copy,
78 ec_GFp_simple_group_set_curve, 70 ec_GFp_simple_group_set_curve_GFp,
79 ec_GFp_simple_group_get_curve, 71 ec_GFp_simple_group_get_curve_GFp,
80 ec_GFp_simple_group_get_degree, 72 ec_GFp_simple_group_set_generator,
81 ec_GFp_simple_group_check_discriminant, 73 ec_GFp_simple_group_get0_generator,
74 ec_GFp_simple_group_get_order,
75 ec_GFp_simple_group_get_cofactor,
82 ec_GFp_simple_point_init, 76 ec_GFp_simple_point_init,
83 ec_GFp_simple_point_finish, 77 ec_GFp_simple_point_finish,
84 ec_GFp_simple_point_clear_finish, 78 ec_GFp_simple_point_clear_finish,
@@ -86,9 +80,9 @@ const EC_METHOD *EC_GFp_simple_method(void)
86 ec_GFp_simple_point_set_to_infinity, 80 ec_GFp_simple_point_set_to_infinity,
87 ec_GFp_simple_set_Jprojective_coordinates_GFp, 81 ec_GFp_simple_set_Jprojective_coordinates_GFp,
88 ec_GFp_simple_get_Jprojective_coordinates_GFp, 82 ec_GFp_simple_get_Jprojective_coordinates_GFp,
89 ec_GFp_simple_point_set_affine_coordinates, 83 ec_GFp_simple_point_set_affine_coordinates_GFp,
90 ec_GFp_simple_point_get_affine_coordinates, 84 ec_GFp_simple_point_get_affine_coordinates_GFp,
91 ec_GFp_simple_set_compressed_coordinates, 85 ec_GFp_simple_set_compressed_coordinates_GFp,
92 ec_GFp_simple_point2oct, 86 ec_GFp_simple_point2oct,
93 ec_GFp_simple_oct2point, 87 ec_GFp_simple_oct2point,
94 ec_GFp_simple_add, 88 ec_GFp_simple_add,
@@ -99,12 +93,8 @@ const EC_METHOD *EC_GFp_simple_method(void)
99 ec_GFp_simple_cmp, 93 ec_GFp_simple_cmp,
100 ec_GFp_simple_make_affine, 94 ec_GFp_simple_make_affine,
101 ec_GFp_simple_points_make_affine, 95 ec_GFp_simple_points_make_affine,
102 0 /* mul */,
103 0 /* precompute_mult */,
104 0 /* have_precompute_mult */,
105 ec_GFp_simple_field_mul, 96 ec_GFp_simple_field_mul,
106 ec_GFp_simple_field_sqr, 97 ec_GFp_simple_field_sqr,
107 0 /* field_div */,
108 0 /* field_encode */, 98 0 /* field_encode */,
109 0 /* field_decode */, 99 0 /* field_decode */,
110 0 /* field_set_to_one */ }; 100 0 /* field_set_to_one */ };
@@ -113,26 +103,15 @@ const EC_METHOD *EC_GFp_simple_method(void)
113 } 103 }
114 104
115 105
116/* Most method functions in this file are designed to work with
117 * non-trivial representations of field elements if necessary
118 * (see ecp_mont.c): while standard modular addition and subtraction
119 * are used, the field_mul and field_sqr methods will be used for
120 * multiplication, and field_encode and field_decode (if defined)
121 * will be used for converting between representations.
122
123 * Functions ec_GFp_simple_points_make_affine() and
124 * ec_GFp_simple_point_get_affine_coordinates() specifically assume
125 * that if a non-trivial representation is used, it is a Montgomery
126 * representation (i.e. 'encoding' means multiplying by some factor R).
127 */
128
129
130int ec_GFp_simple_group_init(EC_GROUP *group) 106int ec_GFp_simple_group_init(EC_GROUP *group)
131 { 107 {
132 BN_init(&group->field); 108 BN_init(&group->field);
133 BN_init(&group->a); 109 BN_init(&group->a);
134 BN_init(&group->b); 110 BN_init(&group->b);
135 group->a_is_minus3 = 0; 111 group->a_is_minus3 = 0;
112 group->generator = NULL;
113 BN_init(&group->order);
114 BN_init(&group->cofactor);
136 return 1; 115 return 1;
137 } 116 }
138 117
@@ -142,6 +121,10 @@ void ec_GFp_simple_group_finish(EC_GROUP *group)
142 BN_free(&group->field); 121 BN_free(&group->field);
143 BN_free(&group->a); 122 BN_free(&group->a);
144 BN_free(&group->b); 123 BN_free(&group->b);
124 if (group->generator != NULL)
125 EC_POINT_free(group->generator);
126 BN_free(&group->order);
127 BN_free(&group->cofactor);
145 } 128 }
146 129
147 130
@@ -150,6 +133,13 @@ void ec_GFp_simple_group_clear_finish(EC_GROUP *group)
150 BN_clear_free(&group->field); 133 BN_clear_free(&group->field);
151 BN_clear_free(&group->a); 134 BN_clear_free(&group->a);
152 BN_clear_free(&group->b); 135 BN_clear_free(&group->b);
136 if (group->generator != NULL)
137 {
138 EC_POINT_clear_free(group->generator);
139 group->generator = NULL;
140 }
141 BN_clear_free(&group->order);
142 BN_clear_free(&group->cofactor);
153 } 143 }
154 144
155 145
@@ -161,11 +151,33 @@ int ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
161 151
162 dest->a_is_minus3 = src->a_is_minus3; 152 dest->a_is_minus3 = src->a_is_minus3;
163 153
154 if (src->generator != NULL)
155 {
156 if (dest->generator == NULL)
157 {
158 dest->generator = EC_POINT_new(dest);
159 if (dest->generator == NULL) return 0;
160 }
161 if (!EC_POINT_copy(dest->generator, src->generator)) return 0;
162 }
163 else
164 {
165 /* src->generator == NULL */
166 if (dest->generator != NULL)
167 {
168 EC_POINT_clear_free(dest->generator);
169 dest->generator = NULL;
170 }
171 }
172
173 if (!BN_copy(&dest->order, &src->order)) return 0;
174 if (!BN_copy(&dest->cofactor, &src->cofactor)) return 0;
175
164 return 1; 176 return 1;
165 } 177 }
166 178
167 179
168int ec_GFp_simple_group_set_curve(EC_GROUP *group, 180int ec_GFp_simple_group_set_curve_GFp(EC_GROUP *group,
169 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) 181 const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
170 { 182 {
171 int ret = 0; 183 int ret = 0;
@@ -175,7 +187,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
175 /* p must be a prime > 3 */ 187 /* p must be a prime > 3 */
176 if (BN_num_bits(p) <= 2 || !BN_is_odd(p)) 188 if (BN_num_bits(p) <= 2 || !BN_is_odd(p))
177 { 189 {
178 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE, EC_R_INVALID_FIELD); 190 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_CURVE_GFP, EC_R_INVALID_FIELD);
179 return 0; 191 return 0;
180 } 192 }
181 193
@@ -192,7 +204,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
192 204
193 /* group->field */ 205 /* group->field */
194 if (!BN_copy(&group->field, p)) goto err; 206 if (!BN_copy(&group->field, p)) goto err;
195 BN_set_negative(&group->field, 0); 207 group->field.neg = 0;
196 208
197 /* group->a */ 209 /* group->a */
198 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err; 210 if (!BN_nnmod(tmp_a, a, p, ctx)) goto err;
@@ -220,7 +232,7 @@ int ec_GFp_simple_group_set_curve(EC_GROUP *group,
220 } 232 }
221 233
222 234
223int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx) 235int ec_GFp_simple_group_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
224 { 236 {
225 int ret = 0; 237 int ret = 0;
226 BN_CTX *new_ctx = NULL; 238 BN_CTX *new_ctx = NULL;
@@ -271,76 +283,58 @@ int ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, B
271 } 283 }
272 284
273 285
274int ec_GFp_simple_group_get_degree(const EC_GROUP *group)
275 {
276 return BN_num_bits(&group->field);
277 }
278
279 286
280int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) 287int ec_GFp_simple_group_set_generator(EC_GROUP *group, const EC_POINT *generator,
288 const BIGNUM *order, const BIGNUM *cofactor)
281 { 289 {
282 int ret = 0; 290 if (generator == NULL)
283 BIGNUM *a,*b,*order,*tmp_1,*tmp_2;
284 const BIGNUM *p = &group->field;
285 BN_CTX *new_ctx = NULL;
286
287 if (ctx == NULL)
288 { 291 {
289 ctx = new_ctx = BN_CTX_new(); 292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_SET_GENERATOR, ERR_R_PASSED_NULL_PARAMETER);
290 if (ctx == NULL) 293 return 0 ;
291 {
292 ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE);
293 goto err;
294 }
295 } 294 }
296 BN_CTX_start(ctx);
297 a = BN_CTX_get(ctx);
298 b = BN_CTX_get(ctx);
299 tmp_1 = BN_CTX_get(ctx);
300 tmp_2 = BN_CTX_get(ctx);
301 order = BN_CTX_get(ctx);
302 if (order == NULL) goto err;
303 295
304 if (group->meth->field_decode) 296 if (group->generator == NULL)
305 { 297 {
306 if (!group->meth->field_decode(group, a, &group->a, ctx)) goto err; 298 group->generator = EC_POINT_new(group);
307 if (!group->meth->field_decode(group, b, &group->b, ctx)) goto err; 299 if (group->generator == NULL) return 0;
308 } 300 }
301 if (!EC_POINT_copy(group->generator, generator)) return 0;
302
303 if (order != NULL)
304 { if (!BN_copy(&group->order, order)) return 0; }
309 else 305 else
310 { 306 { if (!BN_zero(&group->order)) return 0; }
311 if (!BN_copy(a, &group->a)) goto err;
312 if (!BN_copy(b, &group->b)) goto err;
313 }
314
315 /* check the discriminant:
316 * y^2 = x^3 + a*x + b is an elliptic curve <=> 4*a^3 + 27*b^2 != 0 (mod p)
317 * 0 =< a, b < p */
318 if (BN_is_zero(a))
319 {
320 if (BN_is_zero(b)) goto err;
321 }
322 else if (!BN_is_zero(b))
323 {
324 if (!BN_mod_sqr(tmp_1, a, p, ctx)) goto err;
325 if (!BN_mod_mul(tmp_2, tmp_1, a, p, ctx)) goto err;
326 if (!BN_lshift(tmp_1, tmp_2, 2)) goto err;
327 /* tmp_1 = 4*a^3 */
328 307
329 if (!BN_mod_sqr(tmp_2, b, p, ctx)) goto err; 308 if (cofactor != NULL)
330 if (!BN_mul_word(tmp_2, 27)) goto err; 309 { if (!BN_copy(&group->cofactor, cofactor)) return 0; }
331 /* tmp_2 = 27*b^2 */ 310 else
311 { if (!BN_zero(&group->cofactor)) return 0; }
332 312
333 if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx)) goto err; 313 return 1;
334 if (BN_is_zero(a)) goto err; 314 }
335 }
336 ret = 1;
337 315
338err: 316
339 if (ctx != NULL) 317EC_POINT *ec_GFp_simple_group_get0_generator(const EC_GROUP *group)
340 BN_CTX_end(ctx); 318 {
341 if (new_ctx != NULL) 319 return group->generator;
342 BN_CTX_free(new_ctx); 320 }
343 return ret; 321
322
323int ec_GFp_simple_group_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
324 {
325 if (!BN_copy(order, &group->order))
326 return 0;
327
328 return !BN_is_zero(&group->order);
329 }
330
331
332int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
333 {
334 if (!BN_copy(cofactor, &group->cofactor))
335 return 0;
336
337 return !BN_is_zero(&group->cofactor);
344 } 338 }
345 339
346 340
@@ -386,8 +380,7 @@ int ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
386int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point) 380int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
387 { 381 {
388 point->Z_is_one = 0; 382 point->Z_is_one = 0;
389 BN_zero(&point->Z); 383 return (BN_zero(&point->Z));
390 return 1;
391 } 384 }
392 385
393 386
@@ -504,13 +497,13 @@ int ec_GFp_simple_get_Jprojective_coordinates_GFp(const EC_GROUP *group, const E
504 } 497 }
505 498
506 499
507int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *point, 500int ec_GFp_simple_point_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
508 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx) 501 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
509 { 502 {
510 if (x == NULL || y == NULL) 503 if (x == NULL || y == NULL)
511 { 504 {
512 /* unlike for projective coordinates, we do not tolerate this */ 505 /* unlike for projective coordinates, we do not tolerate this */
513 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES, ERR_R_PASSED_NULL_PARAMETER); 506 ECerr(EC_F_EC_GFP_SIMPLE_POINT_SET_AFFINE_COORDINATES_GFP, ERR_R_PASSED_NULL_PARAMETER);
514 return 0; 507 return 0;
515 } 508 }
516 509
@@ -518,17 +511,17 @@ int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *group, EC_POINT *
518 } 511 }
519 512
520 513
521int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_POINT *point, 514int ec_GFp_simple_point_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point,
522 BIGNUM *x, BIGNUM *y, BN_CTX *ctx) 515 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
523 { 516 {
524 BN_CTX *new_ctx = NULL; 517 BN_CTX *new_ctx = NULL;
525 BIGNUM *Z, *Z_1, *Z_2, *Z_3; 518 BIGNUM *X, *Y, *Z, *Z_1, *Z_2, *Z_3;
526 const BIGNUM *Z_; 519 const BIGNUM *X_, *Y_, *Z_;
527 int ret = 0; 520 int ret = 0;
528 521
529 if (EC_POINT_is_at_infinity(group, point)) 522 if (EC_POINT_is_at_infinity(group, point))
530 { 523 {
531 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, EC_R_POINT_AT_INFINITY); 524 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, EC_R_POINT_AT_INFINITY);
532 return 0; 525 return 0;
533 } 526 }
534 527
@@ -540,6 +533,8 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
540 } 533 }
541 534
542 BN_CTX_start(ctx); 535 BN_CTX_start(ctx);
536 X = BN_CTX_get(ctx);
537 Y = BN_CTX_get(ctx);
543 Z = BN_CTX_get(ctx); 538 Z = BN_CTX_get(ctx);
544 Z_1 = BN_CTX_get(ctx); 539 Z_1 = BN_CTX_get(ctx);
545 Z_2 = BN_CTX_get(ctx); 540 Z_2 = BN_CTX_get(ctx);
@@ -550,44 +545,34 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
550 545
551 if (group->meth->field_decode) 546 if (group->meth->field_decode)
552 { 547 {
548 if (!group->meth->field_decode(group, X, &point->X, ctx)) goto err;
549 if (!group->meth->field_decode(group, Y, &point->Y, ctx)) goto err;
553 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err; 550 if (!group->meth->field_decode(group, Z, &point->Z, ctx)) goto err;
554 Z_ = Z; 551 X_ = X; Y_ = Y; Z_ = Z;
555 } 552 }
556 else 553 else
557 { 554 {
555 X_ = &point->X;
556 Y_ = &point->Y;
558 Z_ = &point->Z; 557 Z_ = &point->Z;
559 } 558 }
560 559
561 if (BN_is_one(Z_)) 560 if (BN_is_one(Z_))
562 { 561 {
563 if (group->meth->field_decode) 562 if (x != NULL)
564 { 563 {
565 if (x != NULL) 564 if (!BN_copy(x, X_)) goto err;
566 {
567 if (!group->meth->field_decode(group, x, &point->X, ctx)) goto err;
568 }
569 if (y != NULL)
570 {
571 if (!group->meth->field_decode(group, y, &point->Y, ctx)) goto err;
572 }
573 } 565 }
574 else 566 if (y != NULL)
575 { 567 {
576 if (x != NULL) 568 if (!BN_copy(y, Y_)) goto err;
577 {
578 if (!BN_copy(x, &point->X)) goto err;
579 }
580 if (y != NULL)
581 {
582 if (!BN_copy(y, &point->Y)) goto err;
583 }
584 } 569 }
585 } 570 }
586 else 571 else
587 { 572 {
588 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx)) 573 if (!BN_mod_inverse(Z_1, Z_, &group->field, ctx))
589 { 574 {
590 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES, ERR_R_BN_LIB); 575 ECerr(EC_F_EC_GFP_SIMPLE_POINT_GET_AFFINE_COORDINATES_GFP, ERR_R_BN_LIB);
591 goto err; 576 goto err;
592 } 577 }
593 578
@@ -603,8 +588,15 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
603 588
604 if (x != NULL) 589 if (x != NULL)
605 { 590 {
606 /* in the Montgomery case, field_mul will cancel out Montgomery factor in X: */ 591 if (group->meth->field_encode == 0)
607 if (!group->meth->field_mul(group, x, &point->X, Z_2, ctx)) goto err; 592 {
593 /* field_mul works on standard representation */
594 if (!group->meth->field_mul(group, x, X_, Z_2, ctx)) goto err;
595 }
596 else
597 {
598 if (!BN_mod_mul(x, X_, Z_2, &group->field, ctx)) goto err;
599 }
608 } 600 }
609 601
610 if (y != NULL) 602 if (y != NULL)
@@ -613,14 +605,14 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
613 { 605 {
614 /* field_mul works on standard representation */ 606 /* field_mul works on standard representation */
615 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err; 607 if (!group->meth->field_mul(group, Z_3, Z_2, Z_1, ctx)) goto err;
608 if (!group->meth->field_mul(group, y, Y_, Z_3, ctx)) goto err;
609
616 } 610 }
617 else 611 else
618 { 612 {
619 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err; 613 if (!BN_mod_mul(Z_3, Z_2, Z_1, &group->field, ctx)) goto err;
614 if (!BN_mod_mul(y, Y_, Z_3, &group->field, ctx)) goto err;
620 } 615 }
621
622 /* in the Montgomery case, field_mul will cancel out Montgomery factor in Y: */
623 if (!group->meth->field_mul(group, y, &point->Y, Z_3, ctx)) goto err;
624 } 616 }
625 } 617 }
626 618
@@ -634,16 +626,13 @@ int ec_GFp_simple_point_get_affine_coordinates(const EC_GROUP *group, const EC_P
634 } 626 }
635 627
636 628
637int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point, 629int ec_GFp_simple_set_compressed_coordinates_GFp(const EC_GROUP *group, EC_POINT *point,
638 const BIGNUM *x_, int y_bit, BN_CTX *ctx) 630 const BIGNUM *x_, int y_bit, BN_CTX *ctx)
639 { 631 {
640 BN_CTX *new_ctx = NULL; 632 BN_CTX *new_ctx = NULL;
641 BIGNUM *tmp1, *tmp2, *x, *y; 633 BIGNUM *tmp1, *tmp2, *x, *y;
642 int ret = 0; 634 int ret = 0;
643 635
644 /* clear error queue*/
645 ERR_clear_error();
646
647 if (ctx == NULL) 636 if (ctx == NULL)
648 { 637 {
649 ctx = new_ctx = BN_CTX_new(); 638 ctx = new_ctx = BN_CTX_new();
@@ -715,17 +704,19 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *po
715 704
716 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx)) 705 if (!BN_mod_sqrt(y, tmp1, &group->field, ctx))
717 { 706 {
718 unsigned long err = ERR_peek_last_error(); 707 unsigned long err = ERR_peek_error();
719 708
720 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) 709 if (ERR_GET_LIB(err) == ERR_LIB_BN && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE)
721 { 710 {
722 ERR_clear_error(); 711 (void)ERR_get_error();
723 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT); 712 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
724 } 713 }
725 else 714 else
726 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_BN_LIB); 715 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_BN_LIB);
727 goto err; 716 goto err;
728 } 717 }
718 /* If tmp1 is not a square (i.e. there is no point on the curve with
719 * our x), then y now is a nonsense value too */
729 720
730 if (y_bit != BN_is_odd(y)) 721 if (y_bit != BN_is_odd(y))
731 { 722 {
@@ -737,17 +728,16 @@ int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *po
737 if (kron == -2) goto err; 728 if (kron == -2) goto err;
738 729
739 if (kron == 1) 730 if (kron == 1)
740 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSION_BIT); 731 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSION_BIT);
741 else 732 else
742 /* BN_mod_sqrt() should have cought this error (not a square) */ 733 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, EC_R_INVALID_COMPRESSED_POINT);
743 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, EC_R_INVALID_COMPRESSED_POINT);
744 goto err; 734 goto err;
745 } 735 }
746 if (!BN_usub(y, &group->field, y)) goto err; 736 if (!BN_usub(y, &group->field, y)) goto err;
747 } 737 }
748 if (y_bit != BN_is_odd(y)) 738 if (y_bit != BN_is_odd(y))
749 { 739 {
750 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES, ERR_R_INTERNAL_ERROR); 740 ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES_GFP, ERR_R_INTERNAL_ERROR);
751 goto err; 741 goto err;
752 } 742 }
753 743
@@ -1098,7 +1088,7 @@ int ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, con
1098 else 1088 else
1099 { 1089 {
1100 /* a is the inverse of b */ 1090 /* a is the inverse of b */
1101 BN_zero(&r->Z); 1091 if (!BN_zero(&r->Z)) goto end;
1102 r->Z_is_one = 0; 1092 r->Z_is_one = 0;
1103 ret = 1; 1093 ret = 1;
1104 goto end; 1094 goto end;
@@ -1174,7 +1164,7 @@ int ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_
1174 1164
1175 if (EC_POINT_is_at_infinity(group, a)) 1165 if (EC_POINT_is_at_infinity(group, a))
1176 { 1166 {
1177 BN_zero(&r->Z); 1167 if (!BN_zero(&r->Z)) return 0;
1178 r->Z_is_one = 0; 1168 r->Z_is_one = 0;
1179 return 1; 1169 return 1;
1180 } 1170 }
@@ -1302,7 +1292,7 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_C
1302 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *); 1292 int (*field_sqr)(const EC_GROUP *, BIGNUM *, const BIGNUM *, BN_CTX *);
1303 const BIGNUM *p; 1293 const BIGNUM *p;
1304 BN_CTX *new_ctx = NULL; 1294 BN_CTX *new_ctx = NULL;
1305 BIGNUM *rh, *tmp, *Z4, *Z6; 1295 BIGNUM *rh, *tmp1, *tmp2, *Z4, *Z6;
1306 int ret = -1; 1296 int ret = -1;
1307 1297
1308 if (EC_POINT_is_at_infinity(group, point)) 1298 if (EC_POINT_is_at_infinity(group, point))
@@ -1321,7 +1311,8 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_C
1321 1311
1322 BN_CTX_start(ctx); 1312 BN_CTX_start(ctx);
1323 rh = BN_CTX_get(ctx); 1313 rh = BN_CTX_get(ctx);
1324 tmp = BN_CTX_get(ctx); 1314 tmp1 = BN_CTX_get(ctx);
1315 tmp2 = BN_CTX_get(ctx);
1325 Z4 = BN_CTX_get(ctx); 1316 Z4 = BN_CTX_get(ctx);
1326 Z6 = BN_CTX_get(ctx); 1317 Z6 = BN_CTX_get(ctx);
1327 if (Z6 == NULL) goto err; 1318 if (Z6 == NULL) goto err;
@@ -1335,49 +1326,59 @@ int ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_C
1335 * To test this, we add up the right-hand side in 'rh'. 1326 * To test this, we add up the right-hand side in 'rh'.
1336 */ 1327 */
1337 1328
1338 /* rh := X^2 */ 1329 /* rh := X^3 */
1339 if (!field_sqr(group, rh, &point->X, ctx)) goto err; 1330 if (!field_sqr(group, rh, &point->X, ctx)) goto err;
1331 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1340 1332
1341 if (!point->Z_is_one) 1333 if (!point->Z_is_one)
1342 { 1334 {
1343 if (!field_sqr(group, tmp, &point->Z, ctx)) goto err; 1335 if (!field_sqr(group, tmp1, &point->Z, ctx)) goto err;
1344 if (!field_sqr(group, Z4, tmp, ctx)) goto err; 1336 if (!field_sqr(group, Z4, tmp1, ctx)) goto err;
1345 if (!field_mul(group, Z6, Z4, tmp, ctx)) goto err; 1337 if (!field_mul(group, Z6, Z4, tmp1, ctx)) goto err;
1346 1338
1347 /* rh := (rh + a*Z^4)*X */ 1339 /* rh := rh + a*X*Z^4 */
1340 if (!field_mul(group, tmp1, &point->X, Z4, ctx)) goto err;
1348 if (group->a_is_minus3) 1341 if (group->a_is_minus3)
1349 { 1342 {
1350 if (!BN_mod_lshift1_quick(tmp, Z4, p)) goto err; 1343 if (!BN_mod_lshift1_quick(tmp2, tmp1, p)) goto err;
1351 if (!BN_mod_add_quick(tmp, tmp, Z4, p)) goto err; 1344 if (!BN_mod_add_quick(tmp2, tmp2, tmp1, p)) goto err;
1352 if (!BN_mod_sub_quick(rh, rh, tmp, p)) goto err; 1345 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1353 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1354 } 1346 }
1355 else 1347 else
1356 { 1348 {
1357 if (!field_mul(group, tmp, Z4, &group->a, ctx)) goto err; 1349 if (!field_mul(group, tmp2, tmp1, &group->a, ctx)) goto err;
1358 if (!BN_mod_add_quick(rh, rh, tmp, p)) goto err; 1350 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1359 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err;
1360 } 1351 }
1361 1352
1362 /* rh := rh + b*Z^6 */ 1353 /* rh := rh + b*Z^6 */
1363 if (!field_mul(group, tmp, &group->b, Z6, ctx)) goto err; 1354 if (!field_mul(group, tmp1, &group->b, Z6, ctx)) goto err;
1364 if (!BN_mod_add_quick(rh, rh, tmp, p)) goto err; 1355 if (!BN_mod_add_quick(rh, rh, tmp1, p)) goto err;
1365 } 1356 }
1366 else 1357 else
1367 { 1358 {
1368 /* point->Z_is_one */ 1359 /* point->Z_is_one */
1369 1360
1370 /* rh := (rh + a)*X */ 1361 /* rh := rh + a*X */
1371 if (!BN_mod_add_quick(rh, rh, &group->a, p)) goto err; 1362 if (group->a_is_minus3)
1372 if (!field_mul(group, rh, rh, &point->X, ctx)) goto err; 1363 {
1364 if (!BN_mod_lshift1_quick(tmp2, &point->X, p)) goto err;
1365 if (!BN_mod_add_quick(tmp2, tmp2, &point->X, p)) goto err;
1366 if (!BN_mod_sub_quick(rh, rh, tmp2, p)) goto err;
1367 }
1368 else
1369 {
1370 if (!field_mul(group, tmp2, &point->X, &group->a, ctx)) goto err;
1371 if (!BN_mod_add_quick(rh, rh, tmp2, p)) goto err;
1372 }
1373
1373 /* rh := rh + b */ 1374 /* rh := rh + b */
1374 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err; 1375 if (!BN_mod_add_quick(rh, rh, &group->b, p)) goto err;
1375 } 1376 }
1376 1377
1377 /* 'lh' := Y^2 */ 1378 /* 'lh' := Y^2 */
1378 if (!field_sqr(group, tmp, &point->Y, ctx)) goto err; 1379 if (!field_sqr(group, tmp1, &point->Y, ctx)) goto err;
1379 1380
1380 ret = (0 == BN_ucmp(tmp, rh)); 1381 ret = (0 == BN_cmp(tmp1, rh));
1381 1382
1382 err: 1383 err:
1383 BN_CTX_end(ctx); 1384 BN_CTX_end(ctx);
diff --git a/src/lib/libcrypto/ec/ectest.c b/src/lib/libcrypto/ec/ectest.c
new file mode 100644
index 0000000000..fcf969f3cf
--- /dev/null
+++ b/src/lib/libcrypto/ec/ectest.c
@@ -0,0 +1,643 @@
1/* crypto/ec/ectest.c */
2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <stdio.h>
57#include <stdlib.h>
58#ifdef FLAT_INC
59#include "e_os.h"
60#else
61#include "../e_os.h"
62#endif
63#include <string.h>
64#include <time.h>
65
66
67#ifdef OPENSSL_NO_EC
68int main(int argc, char * argv[]) { puts("Elliptic curves are disabled."); return 0; }
69#else
70
71
72#include <openssl/ec.h>
73#ifndef OPENSSL_NO_ENGINE
74#include <openssl/engine.h>
75#endif
76#include <openssl/err.h>
77
78#define ABORT do { \
79 fflush(stdout); \
80 fprintf(stderr, "%s:%d: ABORT\n", __FILE__, __LINE__); \
81 ERR_print_errors_fp(stderr); \
82 EXIT(1); \
83} while (0)
84
85#if 0
86static void timings(EC_GROUP *group, int multi, BN_CTX *ctx)
87 {
88 clock_t clck;
89 int i, j;
90 BIGNUM *s, *s0;
91 EC_POINT *P;
92
93 s = BN_new();
94 s0 = BN_new();
95 if (s == NULL || s0 == NULL) ABORT;
96
97 if (!EC_GROUP_get_curve_GFp(group, s, NULL, NULL, ctx)) ABORT;
98 fprintf(stdout, "Timings for %d bit prime, ", (int)BN_num_bits(s));
99 if (!EC_GROUP_get_order(group, s, ctx)) ABORT;
100 fprintf(stdout, "%d bit scalars ", (int)BN_num_bits(s));
101 fflush(stdout);
102
103 P = EC_POINT_new(group);
104 if (P == NULL) ABORT;
105 EC_POINT_copy(P, EC_GROUP_get0_generator(group));
106
107 clck = clock();
108 for (i = 0; i < 10; i++)
109 {
110 if (!BN_pseudo_rand(s, BN_num_bits(s), 0, 0)) ABORT;
111 if (multi)
112 {
113 if (!BN_pseudo_rand(s0, BN_num_bits(s), 0, 0)) ABORT;
114 }
115 for (j = 0; j < 10; j++)
116 {
117 if (!EC_POINT_mul(group, P, s, multi ? P : NULL, multi ? s0 : NULL, ctx)) ABORT;
118 }
119 fprintf(stdout, ".");
120 fflush(stdout);
121 }
122 fprintf(stdout, "\n");
123
124 clck = clock() - clck;
125
126#ifdef CLOCKS_PER_SEC
127 /* "To determine the time in seconds, the value returned
128 * by the clock function should be divided by the value
129 * of the macro CLOCKS_PER_SEC."
130 * -- ISO/IEC 9899 */
131# define UNIT "s"
132#else
133 /* "`CLOCKS_PER_SEC' undeclared (first use this function)"
134 * -- cc on NeXTstep/OpenStep */
135# define UNIT "units"
136# define CLOCKS_PER_SEC 1
137#endif
138
139 fprintf(stdout, "%i %s in %.2f " UNIT "\n", i*j,
140 multi ? "s*P+t*Q operations" : "point multiplications",
141 (double)clck/CLOCKS_PER_SEC);
142 fprintf(stdout, "average: %.4f " UNIT "\n", (double)clck/(CLOCKS_PER_SEC*i*j));
143
144 EC_POINT_free(P);
145 BN_free(s);
146 BN_free(s0);
147 }
148#endif
149
150int main(int argc, char *argv[])
151 {
152 BN_CTX *ctx = NULL;
153 BIGNUM *p, *a, *b;
154 EC_GROUP *group;
155 EC_GROUP *P_192 = NULL, *P_224 = NULL, *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;
156 EC_POINT *P, *Q, *R;
157 BIGNUM *x, *y, *z;
158 unsigned char buf[100];
159 size_t i, len;
160 int k;
161
162 /* enable memory leak checking unless explicitly disabled */
163 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
164 {
165 CRYPTO_malloc_debug_init();
166 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
167 }
168 else
169 {
170 /* OPENSSL_DEBUG_MEMORY=off */
171 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
172 }
173 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
174 ERR_load_crypto_strings();
175
176#if 1 /* optional */
177 ctx = BN_CTX_new();
178 if (!ctx) ABORT;
179#endif
180
181 p = BN_new();
182 a = BN_new();
183 b = BN_new();
184 if (!p || !a || !b) ABORT;
185
186 if (!BN_hex2bn(&p, "17")) ABORT;
187 if (!BN_hex2bn(&a, "1")) ABORT;
188 if (!BN_hex2bn(&b, "1")) ABORT;
189
190 group = EC_GROUP_new(EC_GFp_mont_method()); /* applications should use EC_GROUP_new_curve_GFp
191 * so that the library gets to choose the EC_METHOD */
192 if (!group) ABORT;
193
194 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
195
196 {
197 EC_GROUP *tmp;
198 tmp = EC_GROUP_new(EC_GROUP_method_of(group));
199 if (!tmp) ABORT;
200 if (!EC_GROUP_copy(tmp, group)) ABORT;
201 EC_GROUP_free(group);
202 group = tmp;
203 }
204
205 if (!EC_GROUP_get_curve_GFp(group, p, a, b, ctx)) ABORT;
206
207 fprintf(stdout, "Curve defined by Weierstrass equation\n y^2 = x^3 + a*x + b (mod 0x");
208 BN_print_fp(stdout, p);
209 fprintf(stdout, ")\n a = 0x");
210 BN_print_fp(stdout, a);
211 fprintf(stdout, "\n b = 0x");
212 BN_print_fp(stdout, b);
213 fprintf(stdout, "\n");
214
215 P = EC_POINT_new(group);
216 Q = EC_POINT_new(group);
217 R = EC_POINT_new(group);
218 if (!P || !Q || !R) ABORT;
219
220 if (!EC_POINT_set_to_infinity(group, P)) ABORT;
221 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
222
223 buf[0] = 0;
224 if (!EC_POINT_oct2point(group, Q, buf, 1, ctx)) ABORT;
225
226 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
227 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
228
229 x = BN_new();
230 y = BN_new();
231 z = BN_new();
232 if (!x || !y || !z) ABORT;
233
234 if (!BN_hex2bn(&x, "D")) ABORT;
235 if (!EC_POINT_set_compressed_coordinates_GFp(group, Q, x, 1, ctx)) ABORT;
236 if (!EC_POINT_is_on_curve(group, Q, ctx))
237 {
238 if (!EC_POINT_get_affine_coordinates_GFp(group, Q, x, y, ctx)) ABORT;
239 fprintf(stderr, "Point is not on curve: x = 0x");
240 BN_print_fp(stderr, x);
241 fprintf(stderr, ", y = 0x");
242 BN_print_fp(stderr, y);
243 fprintf(stderr, "\n");
244 ABORT;
245 }
246
247 fprintf(stdout, "A cyclic subgroup:\n");
248 k = 100;
249 do
250 {
251 if (k-- == 0) ABORT;
252
253 if (EC_POINT_is_at_infinity(group, P))
254 fprintf(stdout, " point at infinity\n");
255 else
256 {
257 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
258
259 fprintf(stdout, " x = 0x");
260 BN_print_fp(stdout, x);
261 fprintf(stdout, ", y = 0x");
262 BN_print_fp(stdout, y);
263 fprintf(stdout, "\n");
264 }
265
266 if (!EC_POINT_copy(R, P)) ABORT;
267 if (!EC_POINT_add(group, P, P, Q, ctx)) ABORT;
268
269#if 0 /* optional */
270 {
271 EC_POINT *points[3];
272
273 points[0] = R;
274 points[1] = Q;
275 points[2] = P;
276 if (!EC_POINTs_make_affine(group, 2, points, ctx)) ABORT;
277 }
278#endif
279
280 }
281 while (!EC_POINT_is_at_infinity(group, P));
282
283 if (!EC_POINT_add(group, P, Q, R, ctx)) ABORT;
284 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
285
286 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf, sizeof buf, ctx);
287 if (len == 0) ABORT;
288 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
289 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
290 fprintf(stdout, "Generator as octect string, compressed form:\n ");
291 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
292
293 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED, buf, sizeof buf, ctx);
294 if (len == 0) ABORT;
295 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
296 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
297 fprintf(stdout, "\nGenerator as octect string, uncompressed form:\n ");
298 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
299
300 len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID, buf, sizeof buf, ctx);
301 if (len == 0) ABORT;
302 if (!EC_POINT_oct2point(group, P, buf, len, ctx)) ABORT;
303 if (0 != EC_POINT_cmp(group, P, Q, ctx)) ABORT;
304 fprintf(stdout, "\nGenerator as octect string, hybrid form:\n ");
305 for (i = 0; i < len; i++) fprintf(stdout, "%02X", buf[i]);
306
307 if (!EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z, ctx)) ABORT;
308 fprintf(stdout, "\nA representation of the inverse of that generator in\nJacobian projective coordinates:\n X = 0x");
309 BN_print_fp(stdout, x);
310 fprintf(stdout, ", Y = 0x");
311 BN_print_fp(stdout, y);
312 fprintf(stdout, ", Z = 0x");
313 BN_print_fp(stdout, z);
314 fprintf(stdout, "\n");
315
316 if (!EC_POINT_invert(group, P, ctx)) ABORT;
317 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
318
319
320 /* Curve P-192 (FIPS PUB 186-2, App. 6) */
321
322 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF")) ABORT;
323 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
324 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC")) ABORT;
325 if (!BN_hex2bn(&b, "64210519E59C80E70FA7E9AB72243049FEB8DEECC146B9B1")) ABORT;
326 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
327
328 if (!BN_hex2bn(&x, "188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012")) ABORT;
329 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
330 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
331 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFF99DEF836146BC9B1B4D22831")) ABORT;
332 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
333
334 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
335 fprintf(stdout, "\nNIST curve P-192 -- Generator:\n x = 0x");
336 BN_print_fp(stdout, x);
337 fprintf(stdout, "\n y = 0x");
338 BN_print_fp(stdout, y);
339 fprintf(stdout, "\n");
340 /* G_y value taken from the standard: */
341 if (!BN_hex2bn(&z, "07192B95FFC8DA78631011ED6B24CDD573F977A11E794811")) ABORT;
342 if (0 != BN_cmp(y, z)) ABORT;
343
344 fprintf(stdout, "verify group order ...");
345 fflush(stdout);
346 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
347 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
348 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
349 fprintf(stdout, ".");
350 fflush(stdout);
351 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
352 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
353 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
354 fprintf(stdout, " ok\n");
355
356 if (!(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
357 if (!EC_GROUP_copy(P_192, group)) ABORT;
358
359
360 /* Curve P-224 (FIPS PUB 186-2, App. 6) */
361
362 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000000000000001")) ABORT;
363 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
364 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE")) ABORT;
365 if (!BN_hex2bn(&b, "B4050A850C04B3ABF54132565044B0B7D7BFD8BA270B39432355FFB4")) ABORT;
366 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
367
368 if (!BN_hex2bn(&x, "B70E0CBD6BB4BF7F321390B94A03C1D356C21122343280D6115C1D21")) ABORT;
369 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
370 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
371 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFF16A2E0B8F03E13DD29455C5C2A3D")) ABORT;
372 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
373
374 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
375 fprintf(stdout, "\nNIST curve P-224 -- Generator:\n x = 0x");
376 BN_print_fp(stdout, x);
377 fprintf(stdout, "\n y = 0x");
378 BN_print_fp(stdout, y);
379 fprintf(stdout, "\n");
380 /* G_y value taken from the standard: */
381 if (!BN_hex2bn(&z, "BD376388B5F723FB4C22DFE6CD4375A05A07476444D5819985007E34")) ABORT;
382 if (0 != BN_cmp(y, z)) ABORT;
383
384 fprintf(stdout, "verify group order ...");
385 fflush(stdout);
386 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
387 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
388 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
389 fprintf(stdout, ".");
390 fflush(stdout);
391 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
392 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
393 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
394 fprintf(stdout, " ok\n");
395
396 if (!(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
397 if (!EC_GROUP_copy(P_224, group)) ABORT;
398
399
400 /* Curve P-256 (FIPS PUB 186-2, App. 6) */
401
402 if (!BN_hex2bn(&p, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
403 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
404 if (!BN_hex2bn(&a, "FFFFFFFF00000001000000000000000000000000FFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
405 if (!BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC651D06B0CC53B0F63BCE3C3E27D2604B")) ABORT;
406 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
407
408 if (!BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296")) ABORT;
409 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
410 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
411 if (!BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFFBCE6FAADA7179E"
412 "84F3B9CAC2FC632551")) ABORT;
413 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
414
415 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
416 fprintf(stdout, "\nNIST curve P-256 -- Generator:\n x = 0x");
417 BN_print_fp(stdout, x);
418 fprintf(stdout, "\n y = 0x");
419 BN_print_fp(stdout, y);
420 fprintf(stdout, "\n");
421 /* G_y value taken from the standard: */
422 if (!BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5")) ABORT;
423 if (0 != BN_cmp(y, z)) ABORT;
424
425 fprintf(stdout, "verify group order ...");
426 fflush(stdout);
427 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
428 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
429 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
430 fprintf(stdout, ".");
431 fflush(stdout);
432 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
433 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
434 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
435 fprintf(stdout, " ok\n");
436
437 if (!(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
438 if (!EC_GROUP_copy(P_256, group)) ABORT;
439
440
441 /* Curve P-384 (FIPS PUB 186-2, App. 6) */
442
443 if (!BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
444 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFF")) ABORT;
445 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
446 if (!BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
447 "FFFFFFFFFFFFFFFFFEFFFFFFFF0000000000000000FFFFFFFC")) ABORT;
448 if (!BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19181D9C6EFE8141"
449 "120314088F5013875AC656398D8A2ED19D2A85C8EDD3EC2AEF")) ABORT;
450 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
451
452 if (!BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD746E1D3B628BA79B"
453 "9859F741E082542A385502F25DBF55296C3A545E3872760AB7")) ABORT;
454 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 1, ctx)) ABORT;
455 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
456 if (!BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
457 "FFC7634D81F4372DDF581A0DB248B0A77AECEC196ACCC52973")) ABORT;
458 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
459
460 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
461 fprintf(stdout, "\nNIST curve P-384 -- Generator:\n x = 0x");
462 BN_print_fp(stdout, x);
463 fprintf(stdout, "\n y = 0x");
464 BN_print_fp(stdout, y);
465 fprintf(stdout, "\n");
466 /* G_y value taken from the standard: */
467 if (!BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29F8F41DBD289A14"
468 "7CE9DA3113B5F0B8C00A60B1CE1D7E819D7A431D7C90EA0E5F")) ABORT;
469 if (0 != BN_cmp(y, z)) ABORT;
470
471 fprintf(stdout, "verify group order ...");
472 fflush(stdout);
473 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
474 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
475 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
476 fprintf(stdout, ".");
477 fflush(stdout);
478 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
479 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
480 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
481 fprintf(stdout, " ok\n");
482
483 if (!(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
484 if (!EC_GROUP_copy(P_384, group)) ABORT;
485
486
487 /* Curve P-521 (FIPS PUB 186-2, App. 6) */
488
489 if (!BN_hex2bn(&p, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
490 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
491 "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")) ABORT;
492 if (1 != BN_is_prime(p, BN_prime_checks, 0, ctx, NULL)) ABORT;
493 if (!BN_hex2bn(&a, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
494 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
495 "FFFFFFFFFFFFFFFFFFFFFFFFFFFC")) ABORT;
496 if (!BN_hex2bn(&b, "051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B"
497 "315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573"
498 "DF883D2C34F1EF451FD46B503F00")) ABORT;
499 if (!EC_GROUP_set_curve_GFp(group, p, a, b, ctx)) ABORT;
500
501 if (!BN_hex2bn(&x, "C6858E06B70404E9CD9E3ECB662395B4429C648139053F"
502 "B521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B"
503 "3C1856A429BF97E7E31C2E5BD66")) ABORT;
504 if (!EC_POINT_set_compressed_coordinates_GFp(group, P, x, 0, ctx)) ABORT;
505 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
506 if (!BN_hex2bn(&z, "1FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
507 "FFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5"
508 "C9B8899C47AEBB6FB71E91386409")) ABORT;
509 if (!EC_GROUP_set_generator(group, P, z, BN_value_one())) ABORT;
510
511 if (!EC_POINT_get_affine_coordinates_GFp(group, P, x, y, ctx)) ABORT;
512 fprintf(stdout, "\nNIST curve P-521 -- Generator:\n x = 0x");
513 BN_print_fp(stdout, x);
514 fprintf(stdout, "\n y = 0x");
515 BN_print_fp(stdout, y);
516 fprintf(stdout, "\n");
517 /* G_y value taken from the standard: */
518 if (!BN_hex2bn(&z, "11839296A789A3BC0045C8A5FB42C7D1BD998F54449579"
519 "B446817AFBD17273E662C97EE72995EF42640C550B9013FAD0761353C"
520 "7086A272C24088BE94769FD16650")) ABORT;
521 if (0 != BN_cmp(y, z)) ABORT;
522
523 fprintf(stdout, "verify group order ...");
524 fflush(stdout);
525 if (!EC_GROUP_get_order(group, z, ctx)) ABORT;
526 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
527 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
528 fprintf(stdout, ".");
529 fflush(stdout);
530 if (!EC_GROUP_precompute_mult(group, ctx)) ABORT;
531 if (!EC_POINT_mul(group, Q, z, NULL, NULL, ctx)) ABORT;
532 if (!EC_POINT_is_at_infinity(group, Q)) ABORT;
533 fprintf(stdout, " ok\n");
534
535 if (!(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))) ABORT;
536 if (!EC_GROUP_copy(P_521, group)) ABORT;
537
538
539 /* more tests using the last curve */
540
541 if (!EC_POINT_copy(Q, P)) ABORT;
542 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
543 if (!EC_POINT_dbl(group, P, P, ctx)) ABORT;
544 if (!EC_POINT_is_on_curve(group, P, ctx)) ABORT;
545 if (!EC_POINT_invert(group, Q, ctx)) ABORT; /* P = -2Q */
546
547 if (!EC_POINT_add(group, R, P, Q, ctx)) ABORT;
548 if (!EC_POINT_add(group, R, R, Q, ctx)) ABORT;
549 if (!EC_POINT_is_at_infinity(group, R)) ABORT; /* R = P + 2Q */
550
551 {
552 const EC_POINT *points[3];
553 const BIGNUM *scalars[3];
554
555 if (EC_POINT_is_at_infinity(group, Q)) ABORT;
556 points[0] = Q;
557 points[1] = Q;
558 points[2] = Q;
559
560 if (!BN_add(y, z, BN_value_one())) ABORT;
561 if (BN_is_odd(y)) ABORT;
562 if (!BN_rshift1(y, y)) ABORT;
563 scalars[0] = y; /* (group order + 1)/2, so y*Q + y*Q = Q */
564 scalars[1] = y;
565
566 fprintf(stdout, "combined multiplication ...");
567 fflush(stdout);
568
569 /* z is still the group order */
570 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
571 if (!EC_POINTs_mul(group, R, z, 2, points, scalars, ctx)) ABORT;
572 if (0 != EC_POINT_cmp(group, P, R, ctx)) ABORT;
573 if (0 != EC_POINT_cmp(group, R, Q, ctx)) ABORT;
574
575 fprintf(stdout, ".");
576 fflush(stdout);
577
578 if (!BN_pseudo_rand(y, BN_num_bits(y), 0, 0)) ABORT;
579 if (!BN_add(z, z, y)) ABORT;
580 z->neg = 1;
581 scalars[0] = y;
582 scalars[1] = z; /* z = -(order + y) */
583
584 if (!EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx)) ABORT;
585 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
586
587 fprintf(stdout, ".");
588 fflush(stdout);
589
590 if (!BN_pseudo_rand(x, BN_num_bits(y) - 1, 0, 0)) ABORT;
591 if (!BN_add(z, x, y)) ABORT;
592 z->neg = 1;
593 scalars[0] = x;
594 scalars[1] = y;
595 scalars[2] = z; /* z = -(x+y) */
596
597 if (!EC_POINTs_mul(group, P, NULL, 3, points, scalars, ctx)) ABORT;
598 if (!EC_POINT_is_at_infinity(group, P)) ABORT;
599
600 fprintf(stdout, " ok\n\n");
601 }
602
603
604#if 0
605 timings(P_192, 0, ctx);
606 timings(P_192, 1, ctx);
607 timings(P_224, 0, ctx);
608 timings(P_224, 1, ctx);
609 timings(P_256, 0, ctx);
610 timings(P_256, 1, ctx);
611 timings(P_384, 0, ctx);
612 timings(P_384, 1, ctx);
613 timings(P_521, 0, ctx);
614 timings(P_521, 1, ctx);
615#endif
616
617
618 if (ctx)
619 BN_CTX_free(ctx);
620 BN_free(p); BN_free(a); BN_free(b);
621 EC_GROUP_free(group);
622 EC_POINT_free(P);
623 EC_POINT_free(Q);
624 EC_POINT_free(R);
625 BN_free(x); BN_free(y); BN_free(z);
626
627 if (P_192) EC_GROUP_free(P_192);
628 if (P_224) EC_GROUP_free(P_224);
629 if (P_256) EC_GROUP_free(P_256);
630 if (P_384) EC_GROUP_free(P_384);
631 if (P_521) EC_GROUP_free(P_521);
632
633#ifndef OPENSSL_NO_ENGINE
634 ENGINE_cleanup();
635#endif
636 CRYPTO_cleanup_all_ex_data();
637 ERR_free_strings();
638 ERR_remove_state(0);
639 CRYPTO_mem_leaks_fp(stderr);
640
641 return 0;
642 }
643#endif
diff --git a/src/lib/libcrypto/ecdh/Makefile b/src/lib/libcrypto/ecdh/Makefile
new file mode 100644
index 0000000000..95aa69fea5
--- /dev/null
+++ b/src/lib/libcrypto/ecdh/Makefile
@@ -0,0 +1,111 @@
1#
2# crypto/ecdh/Makefile
3#
4
5DIR= ecdh
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g -Wall
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=ecdhtest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= ech_lib.c ech_ossl.c ech_key.c ech_err.c
21
22LIBOBJ= ech_lib.o ech_ossl.o ech_key.o ech_err.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= ecdh.h
27HEADER= ech_locl.h $(EXHEADER)
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41files:
42 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
43
44links:
45 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
46 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
47 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
48
49install:
50 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
51 @headerlist="$(EXHEADER)"; for i in $$headerlist; \
52 do \
53 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
54 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
55 done;
56
57tags:
58 ctags $(SRC)
59
60tests:
61
62lint:
63 lint -DLINT $(INCLUDES) $(SRC)>fluff
64
65depend:
66 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
67 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
68
69dclean:
70 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
71 mv -f Makefile.new $(MAKEFILE)
72
73clean:
74 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78ech_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
79ech_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
80ech_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
81ech_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
82ech_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
83ech_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
84ech_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
85ech_err.o: ech_err.c
86ech_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87ech_key.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88ech_key.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
89ech_key.o: ../../include/openssl/engine.h ../../include/openssl/opensslconf.h
90ech_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
91ech_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
92ech_key.o: ../../include/openssl/symhacks.h ech_key.c ech_locl.h
93ech_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
94ech_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
95ech_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
96ech_lib.o: ../../include/openssl/engine.h ../../include/openssl/err.h
97ech_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
98ech_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
99ech_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
100ech_lib.o: ../../include/openssl/symhacks.h ech_lib.c ech_locl.h
101ech_ossl.o: ../../e_os.h ../../include/openssl/asn1.h
102ech_ossl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
103ech_ossl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
104ech_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
105ech_ossl.o: ../../include/openssl/ecdh.h ../../include/openssl/err.h
106ech_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
107ech_ossl.o: ../../include/openssl/opensslconf.h
108ech_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
109ech_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
110ech_ossl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
111ech_ossl.o: ../cryptlib.h ech_locl.h ech_ossl.c
diff --git a/src/lib/libcrypto/ecdh/ecdhtest.c b/src/lib/libcrypto/ecdh/ecdhtest.c
new file mode 100644
index 0000000000..1575006b51
--- /dev/null
+++ b/src/lib/libcrypto/ecdh/ecdhtest.c
@@ -0,0 +1,368 @@
1/* crypto/ecdh/ecdhtest.c */
2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 *
5 * The Elliptic Curve Public-Key Crypto Library (ECC Code) included
6 * herein is developed by SUN MICROSYSTEMS, INC., and is contributed
7 * to the OpenSSL project.
8 *
9 * The ECC Code is licensed pursuant to the OpenSSL open source
10 * license provided below.
11 *
12 * The ECDH software is originally written by Douglas Stebila of
13 * Sun Microsystems Laboratories.
14 *
15 */
16/* ====================================================================
17 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 *
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 *
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 *
31 * 3. All advertising materials mentioning features or use of this
32 * software must display the following acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
35 *
36 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
37 * endorse or promote products derived from this software without
38 * prior written permission. For written permission, please contact
39 * openssl-core@openssl.org.
40 *
41 * 5. Products derived from this software may not be called "OpenSSL"
42 * nor may "OpenSSL" appear in their names without prior written
43 * permission of the OpenSSL Project.
44 *
45 * 6. Redistributions of any form whatsoever must retain the following
46 * acknowledgment:
47 * "This product includes software developed by the OpenSSL Project
48 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
51 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
54 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
57 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
59 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
61 * OF THE POSSIBILITY OF SUCH DAMAGE.
62 * ====================================================================
63 *
64 * This product includes cryptographic software written by Eric Young
65 * (eay@cryptsoft.com). This product includes software written by Tim
66 * Hudson (tjh@cryptsoft.com).
67 *
68 */
69
70#include <stdio.h>
71#include <stdlib.h>
72#include <string.h>
73
74#include "../e_os.h"
75
76#include <openssl/opensslconf.h> /* for OPENSSL_NO_ECDH */
77#include <openssl/crypto.h>
78#include <openssl/bio.h>
79#include <openssl/bn.h>
80#include <openssl/objects.h>
81#include <openssl/rand.h>
82#include <openssl/sha.h>
83#include <openssl/err.h>
84
85#ifdef OPENSSL_NO_ECDH
86int main(int argc, char *argv[])
87{
88 printf("No ECDH support\n");
89 return(0);
90}
91#else
92#include <openssl/ec.h>
93#include <openssl/ecdh.h>
94
95#ifdef OPENSSL_SYS_WIN16
96#define MS_CALLBACK _far _loadds
97#else
98#define MS_CALLBACK
99#endif
100
101#if 0
102static void MS_CALLBACK cb(int p, int n, void *arg);
103#endif
104
105static const char rnd_seed[] = "string to make the random number generator think it has entropy";
106
107
108static const int KDF1_SHA1_len = 20;
109static void *KDF1_SHA1(const void *in, size_t inlen, void *out, size_t *outlen)
110 {
111#ifndef OPENSSL_NO_SHA
112 if (*outlen < SHA_DIGEST_LENGTH)
113 return NULL;
114 else
115 *outlen = SHA_DIGEST_LENGTH;
116 return SHA1(in, inlen, out);
117#else
118 return NULL;
119#endif
120 }
121
122
123static int test_ecdh_curve(int nid, const char *text, BN_CTX *ctx, BIO *out)
124 {
125 EC_KEY *a=NULL;
126 EC_KEY *b=NULL;
127 BIGNUM *x_a=NULL, *y_a=NULL,
128 *x_b=NULL, *y_b=NULL;
129 char buf[12];
130 unsigned char *abuf=NULL,*bbuf=NULL;
131 int i,alen,blen,aout,bout,ret=0;
132 const EC_GROUP *group;
133
134 a = EC_KEY_new_by_curve_name(nid);
135 b = EC_KEY_new_by_curve_name(nid);
136 if (a == NULL || b == NULL)
137 goto err;
138
139 group = EC_KEY_get0_group(a);
140
141 if ((x_a=BN_new()) == NULL) goto err;
142 if ((y_a=BN_new()) == NULL) goto err;
143 if ((x_b=BN_new()) == NULL) goto err;
144 if ((y_b=BN_new()) == NULL) goto err;
145
146 BIO_puts(out,"Testing key generation with ");
147 BIO_puts(out,text);
148#ifdef NOISY
149 BIO_puts(out,"\n");
150#else
151 (void)BIO_flush(out);
152#endif
153
154 if (!EC_KEY_generate_key(a)) goto err;
155
156 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field)
157 {
158 if (!EC_POINT_get_affine_coordinates_GFp(group,
159 EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err;
160 }
161 else
162 {
163 if (!EC_POINT_get_affine_coordinates_GF2m(group,
164 EC_KEY_get0_public_key(a), x_a, y_a, ctx)) goto err;
165 }
166#ifdef NOISY
167 BIO_puts(out," pri 1=");
168 BN_print(out,a->priv_key);
169 BIO_puts(out,"\n pub 1=");
170 BN_print(out,x_a);
171 BIO_puts(out,",");
172 BN_print(out,y_a);
173 BIO_puts(out,"\n");
174#else
175 BIO_printf(out," .");
176 (void)BIO_flush(out);
177#endif
178
179 if (!EC_KEY_generate_key(b)) goto err;
180
181 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field)
182 {
183 if (!EC_POINT_get_affine_coordinates_GFp(group,
184 EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err;
185 }
186 else
187 {
188 if (!EC_POINT_get_affine_coordinates_GF2m(group,
189 EC_KEY_get0_public_key(b), x_b, y_b, ctx)) goto err;
190 }
191
192#ifdef NOISY
193 BIO_puts(out," pri 2=");
194 BN_print(out,b->priv_key);
195 BIO_puts(out,"\n pub 2=");
196 BN_print(out,x_b);
197 BIO_puts(out,",");
198 BN_print(out,y_b);
199 BIO_puts(out,"\n");
200#else
201 BIO_printf(out,".");
202 (void)BIO_flush(out);
203#endif
204
205 alen=KDF1_SHA1_len;
206 abuf=(unsigned char *)OPENSSL_malloc(alen);
207 aout=ECDH_compute_key(abuf,alen,EC_KEY_get0_public_key(b),a,KDF1_SHA1);
208
209#ifdef NOISY
210 BIO_puts(out," key1 =");
211 for (i=0; i<aout; i++)
212 {
213 sprintf(buf,"%02X",abuf[i]);
214 BIO_puts(out,buf);
215 }
216 BIO_puts(out,"\n");
217#else
218 BIO_printf(out,".");
219 (void)BIO_flush(out);
220#endif
221
222 blen=KDF1_SHA1_len;
223 bbuf=(unsigned char *)OPENSSL_malloc(blen);
224 bout=ECDH_compute_key(bbuf,blen,EC_KEY_get0_public_key(a),b,KDF1_SHA1);
225
226#ifdef NOISY
227 BIO_puts(out," key2 =");
228 for (i=0; i<bout; i++)
229 {
230 sprintf(buf,"%02X",bbuf[i]);
231 BIO_puts(out,buf);
232 }
233 BIO_puts(out,"\n");
234#else
235 BIO_printf(out,".");
236 (void)BIO_flush(out);
237#endif
238
239 if ((aout < 4) || (bout != aout) || (memcmp(abuf,bbuf,aout) != 0))
240 {
241#ifndef NOISY
242 BIO_printf(out, " failed\n\n");
243 BIO_printf(out, "key a:\n");
244 BIO_printf(out, "private key: ");
245 BN_print(out, EC_KEY_get0_private_key(a));
246 BIO_printf(out, "\n");
247 BIO_printf(out, "public key (x,y): ");
248 BN_print(out, x_a);
249 BIO_printf(out, ",");
250 BN_print(out, y_a);
251 BIO_printf(out, "\nkey b:\n");
252 BIO_printf(out, "private key: ");
253 BN_print(out, EC_KEY_get0_private_key(b));
254 BIO_printf(out, "\n");
255 BIO_printf(out, "public key (x,y): ");
256 BN_print(out, x_b);
257 BIO_printf(out, ",");
258 BN_print(out, y_b);
259 BIO_printf(out, "\n");
260 BIO_printf(out, "generated key a: ");
261 for (i=0; i<bout; i++)
262 {
263 sprintf(buf, "%02X", bbuf[i]);
264 BIO_puts(out, buf);
265 }
266 BIO_printf(out, "\n");
267 BIO_printf(out, "generated key b: ");
268 for (i=0; i<aout; i++)
269 {
270 sprintf(buf, "%02X", abuf[i]);
271 BIO_puts(out,buf);
272 }
273 BIO_printf(out, "\n");
274#endif
275 fprintf(stderr,"Error in ECDH routines\n");
276 ret=0;
277 }
278 else
279 {
280#ifndef NOISY
281 BIO_printf(out, " ok\n");
282#endif
283 ret=1;
284 }
285err:
286 ERR_print_errors_fp(stderr);
287
288 if (abuf != NULL) OPENSSL_free(abuf);
289 if (bbuf != NULL) OPENSSL_free(bbuf);
290 if (x_a) BN_free(x_a);
291 if (y_a) BN_free(y_a);
292 if (x_b) BN_free(x_b);
293 if (y_b) BN_free(y_b);
294 if (b) EC_KEY_free(b);
295 if (a) EC_KEY_free(a);
296 return(ret);
297 }
298
299int main(int argc, char *argv[])
300 {
301 BN_CTX *ctx=NULL;
302 int ret=1;
303 BIO *out;
304
305 CRYPTO_malloc_debug_init();
306 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
307 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
308
309#ifdef OPENSSL_SYS_WIN32
310 CRYPTO_malloc_init();
311#endif
312
313 RAND_seed(rnd_seed, sizeof rnd_seed);
314
315 out=BIO_new(BIO_s_file());
316 if (out == NULL) EXIT(1);
317 BIO_set_fp(out,stdout,BIO_NOCLOSE);
318
319 if ((ctx=BN_CTX_new()) == NULL) goto err;
320
321 /* NIST PRIME CURVES TESTS */
322 if (!test_ecdh_curve(NID_X9_62_prime192v1, "NIST Prime-Curve P-192", ctx, out)) goto err;
323 if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out)) goto err;
324 if (!test_ecdh_curve(NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out)) goto err;
325 if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) goto err;
326 if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) goto err;
327 /* NIST BINARY CURVES TESTS */
328 if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out)) goto err;
329 if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out)) goto err;
330 if (!test_ecdh_curve(NID_sect233k1, "NIST Binary-Curve K-233", ctx, out)) goto err;
331 if (!test_ecdh_curve(NID_sect233r1, "NIST Binary-Curve B-233", ctx, out)) goto err;
332 if (!test_ecdh_curve(NID_sect283k1, "NIST Binary-Curve K-283", ctx, out)) goto err;
333 if (!test_ecdh_curve(NID_sect283r1, "NIST Binary-Curve B-283", ctx, out)) goto err;
334 if (!test_ecdh_curve(NID_sect409k1, "NIST Binary-Curve K-409", ctx, out)) goto err;
335 if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out)) goto err;
336 if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out)) goto err;
337 if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out)) goto err;
338
339 ret = 0;
340
341err:
342 ERR_print_errors_fp(stderr);
343 if (ctx) BN_CTX_free(ctx);
344 BIO_free(out);
345 CRYPTO_cleanup_all_ex_data();
346 ERR_remove_state(0);
347 CRYPTO_mem_leaks_fp(stderr);
348 EXIT(ret);
349 return(ret);
350 }
351
352#if 0
353static void MS_CALLBACK cb(int p, int n, void *arg)
354 {
355 char c='*';
356
357 if (p == 0) c='.';
358 if (p == 1) c='+';
359 if (p == 2) c='*';
360 if (p == 3) c='\n';
361 BIO_write((BIO *)arg,&c,1);
362 (void)BIO_flush((BIO *)arg);
363#ifdef LINT
364 p=n;
365#endif
366 }
367#endif
368#endif
diff --git a/src/lib/libcrypto/ecdh/ech_ossl.c b/src/lib/libcrypto/ecdh/ech_ossl.c
new file mode 100644
index 0000000000..2a40ff12df
--- /dev/null
+++ b/src/lib/libcrypto/ecdh/ech_ossl.c
@@ -0,0 +1,213 @@
1/* crypto/ecdh/ech_ossl.c */
2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 *
5 * The Elliptic Curve Public-Key Crypto Library (ECC Code) included
6 * herein is developed by SUN MICROSYSTEMS, INC., and is contributed
7 * to the OpenSSL project.
8 *
9 * The ECC Code is licensed pursuant to the OpenSSL open source
10 * license provided below.
11 *
12 * The ECDH software is originally written by Douglas Stebila of
13 * Sun Microsystems Laboratories.
14 *
15 */
16/* ====================================================================
17 * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 *
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 *
26 * 2. Redistributions in binary form must reproduce the above copyright
27 * notice, this list of conditions and the following disclaimer in
28 * the documentation and/or other materials provided with the
29 * distribution.
30 *
31 * 3. All advertising materials mentioning features or use of this
32 * software must display the following acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
35 *
36 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
37 * endorse or promote products derived from this software without
38 * prior written permission. For written permission, please contact
39 * openssl-core@OpenSSL.org.
40 *
41 * 5. Products derived from this software may not be called "OpenSSL"
42 * nor may "OpenSSL" appear in their names without prior written
43 * permission of the OpenSSL Project.
44 *
45 * 6. Redistributions of any form whatsoever must retain the following
46 * acknowledgment:
47 * "This product includes software developed by the OpenSSL Project
48 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
51 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
52 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
53 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
54 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
57 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
59 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
60 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
61 * OF THE POSSIBILITY OF SUCH DAMAGE.
62 * ====================================================================
63 *
64 * This product includes cryptographic software written by Eric Young
65 * (eay@cryptsoft.com). This product includes software written by Tim
66 * Hudson (tjh@cryptsoft.com).
67 *
68 */
69
70
71#include <string.h>
72#include <limits.h>
73
74#include "cryptlib.h"
75
76#include "ech_locl.h"
77#include <openssl/err.h>
78#include <openssl/sha.h>
79#include <openssl/obj_mac.h>
80#include <openssl/bn.h>
81
82static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key,
83 EC_KEY *ecdh,
84 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen));
85
86static ECDH_METHOD openssl_ecdh_meth = {
87 "OpenSSL ECDH method",
88 ecdh_compute_key,
89#if 0
90 NULL, /* init */
91 NULL, /* finish */
92#endif
93 0, /* flags */
94 NULL /* app_data */
95};
96
97const ECDH_METHOD *ECDH_OpenSSL(void)
98 {
99 return &openssl_ecdh_meth;
100 }
101
102
103/* This implementation is based on the following primitives in the IEEE 1363 standard:
104 * - ECKAS-DH1
105 * - ECSVDP-DH
106 * Finally an optional KDF is applied.
107 */
108static int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
109 EC_KEY *ecdh,
110 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen))
111 {
112 BN_CTX *ctx;
113 EC_POINT *tmp=NULL;
114 BIGNUM *x=NULL, *y=NULL;
115 const BIGNUM *priv_key;
116 const EC_GROUP* group;
117 int ret= -1;
118 size_t buflen, len;
119 unsigned char *buf=NULL;
120
121 if (outlen > INT_MAX)
122 {
123 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE); /* sort of, anyway */
124 return -1;
125 }
126
127 if ((ctx = BN_CTX_new()) == NULL) goto err;
128 BN_CTX_start(ctx);
129 x = BN_CTX_get(ctx);
130 y = BN_CTX_get(ctx);
131
132 priv_key = EC_KEY_get0_private_key(ecdh);
133 if (priv_key == NULL)
134 {
135 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_NO_PRIVATE_VALUE);
136 goto err;
137 }
138
139 group = EC_KEY_get0_group(ecdh);
140 if ((tmp=EC_POINT_new(group)) == NULL)
141 {
142 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE);
143 goto err;
144 }
145
146 if (!EC_POINT_mul(group, tmp, NULL, pub_key, priv_key, ctx))
147 {
148 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE);
149 goto err;
150 }
151
152 if (EC_METHOD_get_field_type(EC_GROUP_method_of(group)) == NID_X9_62_prime_field)
153 {
154 if (!EC_POINT_get_affine_coordinates_GFp(group, tmp, x, y, ctx))
155 {
156 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE);
157 goto err;
158 }
159 }
160 else
161 {
162 if (!EC_POINT_get_affine_coordinates_GF2m(group, tmp, x, y, ctx))
163 {
164 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_POINT_ARITHMETIC_FAILURE);
165 goto err;
166 }
167 }
168
169 buflen = (EC_GROUP_get_degree(group) + 7)/8;
170 len = BN_num_bytes(x);
171 if (len > buflen)
172 {
173 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_INTERNAL_ERROR);
174 goto err;
175 }
176 if ((buf = OPENSSL_malloc(buflen)) == NULL)
177 {
178 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_MALLOC_FAILURE);
179 goto err;
180 }
181
182 memset(buf, 0, buflen - len);
183 if (len != (size_t)BN_bn2bin(x, buf + buflen - len))
184 {
185 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ERR_R_BN_LIB);
186 goto err;
187 }
188
189 if (KDF != 0)
190 {
191 if (KDF(buf, buflen, out, &outlen) == NULL)
192 {
193 ECDHerr(ECDH_F_ECDH_COMPUTE_KEY,ECDH_R_KDF_FAILED);
194 goto err;
195 }
196 ret = outlen;
197 }
198 else
199 {
200 /* no KDF, just copy as much as we can */
201 if (outlen > buflen)
202 outlen = buflen;
203 memcpy(out, buf, outlen);
204 ret = outlen;
205 }
206
207err:
208 if (tmp) EC_POINT_free(tmp);
209 if (ctx) BN_CTX_end(ctx);
210 if (ctx) BN_CTX_free(ctx);
211 if (buf) OPENSSL_free(buf);
212 return(ret);
213 }
diff --git a/src/lib/libcrypto/ecdsa/Makefile b/src/lib/libcrypto/ecdsa/Makefile
new file mode 100644
index 0000000000..16a93cd3ae
--- /dev/null
+++ b/src/lib/libcrypto/ecdsa/Makefile
@@ -0,0 +1,125 @@
1#
2# crypto/ecdsa/Makefile
3#
4
5DIR= ecdsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g -Wall
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=ecdsatest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= ecs_lib.c ecs_asn1.c ecs_ossl.c ecs_sign.c ecs_vrf.c ecs_err.c
21
22LIBOBJ= ecs_lib.o ecs_asn1.o ecs_ossl.o ecs_sign.o ecs_vrf.o ecs_err.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= ecdsa.h
27HEADER= ecs_locl.h $(EXHEADER)
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41files:
42 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
43
44links:
45 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
46 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
47 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
48
49install:
50 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
51 @headerlist="$(EXHEADER)"; for i in $$headerlist; \
52 do \
53 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
54 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
55 done;
56
57tags:
58 ctags $(SRC)
59
60tests:
61
62lint:
63 lint -DLINT $(INCLUDES) $(SRC)>fluff
64
65depend:
66 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
67 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
68
69dclean:
70 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
71 mv -f Makefile.new $(MAKEFILE)
72
73clean:
74 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78ecs_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
79ecs_asn1.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
80ecs_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
81ecs_asn1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
82ecs_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
83ecs_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
84ecs_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
85ecs_asn1.o: ../../include/openssl/symhacks.h ecs_asn1.c ecs_locl.h
86ecs_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87ecs_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88ecs_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h
89ecs_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
90ecs_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
91ecs_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
92ecs_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
93ecs_err.o: ecs_err.c
94ecs_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
95ecs_lib.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
96ecs_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
97ecs_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
98ecs_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
99ecs_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
100ecs_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
101ecs_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
102ecs_lib.o: ecs_lib.c ecs_locl.h
103ecs_ossl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
104ecs_ossl.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
105ecs_ossl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
106ecs_ossl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
107ecs_ossl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
108ecs_ossl.o: ../../include/openssl/opensslconf.h
109ecs_ossl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
110ecs_ossl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
111ecs_ossl.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_ossl.c
112ecs_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
113ecs_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
114ecs_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h
115ecs_sign.o: ../../include/openssl/engine.h ../../include/openssl/opensslconf.h
116ecs_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
117ecs_sign.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
118ecs_sign.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_sign.c
119ecs_vrf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
120ecs_vrf.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
121ecs_vrf.o: ../../include/openssl/ec.h ../../include/openssl/ecdsa.h
122ecs_vrf.o: ../../include/openssl/engine.h ../../include/openssl/opensslconf.h
123ecs_vrf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
124ecs_vrf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
125ecs_vrf.o: ../../include/openssl/symhacks.h ecs_locl.h ecs_vrf.c
diff --git a/src/lib/libcrypto/ecdsa/ecdsatest.c b/src/lib/libcrypto/ecdsa/ecdsatest.c
new file mode 100644
index 0000000000..b07e31252b
--- /dev/null
+++ b/src/lib/libcrypto/ecdsa/ecdsatest.c
@@ -0,0 +1,500 @@
1/* crypto/ecdsa/ecdsatest.c */
2/*
3 * Written by Nils Larsch for the OpenSSL project.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2005 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 *
61 * Portions of the attached software ("Contribution") are developed by
62 * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
63 *
64 * The Contribution is licensed pursuant to the OpenSSL open source
65 * license provided above.
66 *
67 * The elliptic curve binary polynomial software is originally written by
68 * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems Laboratories.
69 *
70 */
71
72#include <stdio.h>
73#include <stdlib.h>
74#include <string.h>
75
76#include <openssl/opensslconf.h> /* To see if OPENSSL_NO_ECDSA is defined */
77
78#ifdef OPENSSL_NO_ECDSA
79int main(int argc, char * argv[])
80 {
81 puts("Elliptic curves are disabled.");
82 return 0;
83 }
84#else
85
86#include <openssl/crypto.h>
87#include <openssl/bio.h>
88#include <openssl/evp.h>
89#include <openssl/bn.h>
90#include <openssl/ecdsa.h>
91#ifndef OPENSSL_NO_ENGINE
92#include <openssl/engine.h>
93#endif
94#include <openssl/err.h>
95#include <openssl/rand.h>
96
97static const char rnd_seed[] = "string to make the random number generator "
98 "think it has entropy";
99
100/* declaration of the test functions */
101int x9_62_tests(BIO *);
102int x9_62_test_internal(BIO *out, int nid, const char *r, const char *s);
103int test_builtin(BIO *);
104
105/* functions to change the RAND_METHOD */
106int change_rand(void);
107int restore_rand(void);
108int fbytes(unsigned char *buf, int num);
109
110RAND_METHOD fake_rand;
111const RAND_METHOD *old_rand;
112
113int change_rand(void)
114 {
115 /* save old rand method */
116 if ((old_rand = RAND_get_rand_method()) == NULL)
117 return 0;
118
119 fake_rand.seed = old_rand->seed;
120 fake_rand.cleanup = old_rand->cleanup;
121 fake_rand.add = old_rand->add;
122 fake_rand.status = old_rand->status;
123 /* use own random function */
124 fake_rand.bytes = fbytes;
125 fake_rand.pseudorand = old_rand->bytes;
126 /* set new RAND_METHOD */
127 if (!RAND_set_rand_method(&fake_rand))
128 return 0;
129 return 1;
130 }
131
132int restore_rand(void)
133 {
134 if (!RAND_set_rand_method(old_rand))
135 return 0;
136 else
137 return 1;
138 }
139
140static int fbytes_counter = 0;
141static const char *numbers[8] = {
142 "651056770906015076056810763456358567190100156695615665659",
143 "6140507067065001063065065565667405560006161556565665656654",
144 "8763001015071075675010661307616710783570106710677817767166"
145 "71676178726717",
146 "7000000175690566466555057817571571075705015757757057795755"
147 "55657156756655",
148 "1275552191113212300012030439187146164646146646466749494799",
149 "1542725565216523985789236956265265265235675811949404040041",
150 "1456427555219115346513212300075341203043918714616464614664"
151 "64667494947990",
152 "1712787255652165239672857892369562652652652356758119494040"
153 "40041670216363"};
154
155int fbytes(unsigned char *buf, int num)
156 {
157 int ret;
158 BIGNUM *tmp = NULL;
159
160 if (fbytes_counter >= 8)
161 return 0;
162 tmp = BN_new();
163 if (!tmp)
164 return 0;
165 if (!BN_dec2bn(&tmp, numbers[fbytes_counter]))
166 {
167 BN_free(tmp);
168 return 0;
169 }
170 fbytes_counter ++;
171 ret = BN_bn2bin(tmp, buf);
172 if (ret == 0 || ret != num)
173 ret = 0;
174 else
175 ret = 1;
176 if (tmp)
177 BN_free(tmp);
178 return ret;
179 }
180
181/* some tests from the X9.62 draft */
182int x9_62_test_internal(BIO *out, int nid, const char *r_in, const char *s_in)
183 {
184 int ret = 0;
185 const char message[] = "abc";
186 unsigned char digest[20];
187 unsigned int dgst_len = 0;
188 EVP_MD_CTX md_ctx;
189 EC_KEY *key = NULL;
190 ECDSA_SIG *signature = NULL;
191 BIGNUM *r = NULL, *s = NULL;
192
193 EVP_MD_CTX_init(&md_ctx);
194 /* get the message digest */
195 EVP_DigestInit(&md_ctx, EVP_ecdsa());
196 EVP_DigestUpdate(&md_ctx, (const void*)message, 3);
197 EVP_DigestFinal(&md_ctx, digest, &dgst_len);
198
199 BIO_printf(out, "testing %s: ", OBJ_nid2sn(nid));
200 /* create the key */
201 if ((key = EC_KEY_new_by_curve_name(nid)) == NULL)
202 goto x962_int_err;
203 if (!EC_KEY_generate_key(key))
204 goto x962_int_err;
205 BIO_printf(out, ".");
206 (void)BIO_flush(out);
207 /* create the signature */
208 signature = ECDSA_do_sign(digest, 20, key);
209 if (signature == NULL)
210 goto x962_int_err;
211 BIO_printf(out, ".");
212 (void)BIO_flush(out);
213 /* compare the created signature with the expected signature */
214 if ((r = BN_new()) == NULL || (s = BN_new()) == NULL)
215 goto x962_int_err;
216 if (!BN_dec2bn(&r, r_in) ||
217 !BN_dec2bn(&s, s_in))
218 goto x962_int_err;
219 if (BN_cmp(signature->r ,r) || BN_cmp(signature->s, s))
220 goto x962_int_err;
221 BIO_printf(out, ".");
222 (void)BIO_flush(out);
223 /* verify the signature */
224 if (ECDSA_do_verify(digest, 20, signature, key) != 1)
225 goto x962_int_err;
226 BIO_printf(out, ".");
227 (void)BIO_flush(out);
228
229 BIO_printf(out, " ok\n");
230 ret = 1;
231x962_int_err:
232 if (!ret)
233 BIO_printf(out, " failed\n");
234 if (key)
235 EC_KEY_free(key);
236 if (signature)
237 ECDSA_SIG_free(signature);
238 if (r)
239 BN_free(r);
240 if (s)
241 BN_free(s);
242 EVP_MD_CTX_cleanup(&md_ctx);
243 return ret;
244 }
245
246int x9_62_tests(BIO *out)
247 {
248 int ret = 0;
249
250 BIO_printf(out, "some tests from X9.62:\n");
251
252 /* set own rand method */
253 if (!change_rand())
254 goto x962_err;
255
256 if (!x9_62_test_internal(out, NID_X9_62_prime192v1,
257 "3342403536405981729393488334694600415596881826869351677613",
258 "5735822328888155254683894997897571951568553642892029982342"))
259 goto x962_err;
260 if (!x9_62_test_internal(out, NID_X9_62_prime239v1,
261 "3086361431751678114926225473006680188549593787585317781474"
262 "62058306432176",
263 "3238135532097973577080787768312505059318910517550078427819"
264 "78505179448783"))
265 goto x962_err;
266 if (!x9_62_test_internal(out, NID_X9_62_c2tnb191v1,
267 "87194383164871543355722284926904419997237591535066528048",
268 "308992691965804947361541664549085895292153777025772063598"))
269 goto x962_err;
270 if (!x9_62_test_internal(out, NID_X9_62_c2tnb239v1,
271 "2159633321041961198501834003903461262881815148684178964245"
272 "5876922391552",
273 "1970303740007316867383349976549972270528498040721988191026"
274 "49413465737174"))
275 goto x962_err;
276
277 ret = 1;
278x962_err:
279 if (!restore_rand())
280 ret = 0;
281 return ret;
282 }
283
284int test_builtin(BIO *out)
285 {
286 EC_builtin_curve *curves = NULL;
287 size_t crv_len = 0, n = 0;
288 EC_KEY *eckey = NULL, *wrong_eckey = NULL;
289 EC_GROUP *group;
290 unsigned char digest[20], wrong_digest[20];
291 unsigned char *signature = NULL;
292 unsigned int sig_len;
293 int nid, ret = 0;
294
295 /* fill digest values with some random data */
296 if (!RAND_pseudo_bytes(digest, 20) ||
297 !RAND_pseudo_bytes(wrong_digest, 20))
298 {
299 BIO_printf(out, "ERROR: unable to get random data\n");
300 goto builtin_err;
301 }
302
303 /* create and verify a ecdsa signature with every availble curve
304 * (with ) */
305 BIO_printf(out, "\ntesting ECDSA_sign() and ECDSA_verify() "
306 "with some internal curves:\n");
307
308 /* get a list of all internal curves */
309 crv_len = EC_get_builtin_curves(NULL, 0);
310
311 curves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);
312
313 if (curves == NULL)
314 {
315 BIO_printf(out, "malloc error\n");
316 goto builtin_err;
317 }
318
319 if (!EC_get_builtin_curves(curves, crv_len))
320 {
321 BIO_printf(out, "unable to get internal curves\n");
322 goto builtin_err;
323 }
324
325 /* now create and verify a signature for every curve */
326 for (n = 0; n < crv_len; n++)
327 {
328 unsigned char dirt, offset;
329
330 nid = curves[n].nid;
331 if (nid == NID_ipsec4)
332 continue;
333 /* create new ecdsa key (== EC_KEY) */
334 if ((eckey = EC_KEY_new()) == NULL)
335 goto builtin_err;
336 group = EC_GROUP_new_by_curve_name(nid);
337 if (group == NULL)
338 goto builtin_err;
339 if (EC_KEY_set_group(eckey, group) == 0)
340 goto builtin_err;
341 EC_GROUP_free(group);
342 if (EC_GROUP_get_degree(EC_KEY_get0_group(eckey)) < 160)
343 /* drop the curve */
344 {
345 EC_KEY_free(eckey);
346 eckey = NULL;
347 continue;
348 }
349 BIO_printf(out, "%s: ", OBJ_nid2sn(nid));
350 /* create key */
351 if (!EC_KEY_generate_key(eckey))
352 {
353 BIO_printf(out, " failed\n");
354 goto builtin_err;
355 }
356 /* create second key */
357 if ((wrong_eckey = EC_KEY_new()) == NULL)
358 goto builtin_err;
359 group = EC_GROUP_new_by_curve_name(nid);
360 if (group == NULL)
361 goto builtin_err;
362 if (EC_KEY_set_group(wrong_eckey, group) == 0)
363 goto builtin_err;
364 EC_GROUP_free(group);
365 if (!EC_KEY_generate_key(wrong_eckey))
366 {
367 BIO_printf(out, " failed\n");
368 goto builtin_err;
369 }
370
371 BIO_printf(out, ".");
372 (void)BIO_flush(out);
373 /* check key */
374 if (!EC_KEY_check_key(eckey))
375 {
376 BIO_printf(out, " failed\n");
377 goto builtin_err;
378 }
379 BIO_printf(out, ".");
380 (void)BIO_flush(out);
381 /* create signature */
382 sig_len = ECDSA_size(eckey);
383 if ((signature = OPENSSL_malloc(sig_len)) == NULL)
384 goto builtin_err;
385 if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey))
386 {
387 BIO_printf(out, " failed\n");
388 goto builtin_err;
389 }
390 BIO_printf(out, ".");
391 (void)BIO_flush(out);
392 /* verify signature */
393 if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)
394 {
395 BIO_printf(out, " failed\n");
396 goto builtin_err;
397 }
398 BIO_printf(out, ".");
399 (void)BIO_flush(out);
400 /* verify signature with the wrong key */
401 if (ECDSA_verify(0, digest, 20, signature, sig_len,
402 wrong_eckey) == 1)
403 {
404 BIO_printf(out, " failed\n");
405 goto builtin_err;
406 }
407 BIO_printf(out, ".");
408 (void)BIO_flush(out);
409 /* wrong digest */
410 if (ECDSA_verify(0, wrong_digest, 20, signature, sig_len,
411 eckey) == 1)
412 {
413 BIO_printf(out, " failed\n");
414 goto builtin_err;
415 }
416 BIO_printf(out, ".");
417 (void)BIO_flush(out);
418 /* modify a single byte of the signature */
419 offset = signature[10] % sig_len;
420 dirt = signature[11];
421 signature[offset] ^= dirt ? dirt : 1;
422 if (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1)
423 {
424 BIO_printf(out, " failed\n");
425 goto builtin_err;
426 }
427 BIO_printf(out, ".");
428 (void)BIO_flush(out);
429
430 BIO_printf(out, " ok\n");
431 /* cleanup */
432 OPENSSL_free(signature);
433 signature = NULL;
434 EC_KEY_free(eckey);
435 eckey = NULL;
436 EC_KEY_free(wrong_eckey);
437 wrong_eckey = NULL;
438 }
439
440 ret = 1;
441builtin_err:
442 if (eckey)
443 EC_KEY_free(eckey);
444 if (wrong_eckey)
445 EC_KEY_free(wrong_eckey);
446 if (signature)
447 OPENSSL_free(signature);
448 if (curves)
449 OPENSSL_free(curves);
450
451 return ret;
452 }
453
454int main(void)
455 {
456 int ret = 1;
457 BIO *out;
458
459 out = BIO_new_fp(stdout, BIO_NOCLOSE);
460
461 /* enable memory leak checking unless explicitly disabled */
462 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) &&
463 (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
464 {
465 CRYPTO_malloc_debug_init();
466 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
467 }
468 else
469 {
470 /* OPENSSL_DEBUG_MEMORY=off */
471 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
472 }
473 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
474
475 ERR_load_crypto_strings();
476
477 /* initialize the prng */
478 RAND_seed(rnd_seed, sizeof(rnd_seed));
479
480 /* the tests */
481 if (!x9_62_tests(out)) goto err;
482 if (!test_builtin(out)) goto err;
483
484 ret = 0;
485err:
486 if (ret)
487 BIO_printf(out, "\nECDSA test failed\n");
488 else
489 BIO_printf(out, "\nECDSA test passed\n");
490 if (ret)
491 ERR_print_errors(out);
492 CRYPTO_cleanup_all_ex_data();
493 ERR_remove_state(0);
494 ERR_free_strings();
495 CRYPTO_mem_leaks(out);
496 if (out != NULL)
497 BIO_free(out);
498 return ret;
499 }
500#endif
diff --git a/src/lib/libcrypto/engine/Makefile b/src/lib/libcrypto/engine/Makefile
new file mode 100644
index 0000000000..13f211a0ae
--- /dev/null
+++ b/src/lib/libcrypto/engine/Makefile
@@ -0,0 +1,288 @@
1#
2# OpenSSL/crypto/engine/Makefile
3#
4
5DIR= engine
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST= enginetest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \
21 eng_table.c eng_pkey.c eng_fat.c eng_all.c \
22 tb_rsa.c tb_dsa.c tb_ecdsa.c tb_dh.c tb_ecdh.c tb_rand.c tb_store.c \
23 tb_cipher.c tb_digest.c \
24 eng_openssl.c eng_cnf.c eng_dyn.c eng_cryptodev.c eng_padlock.c
25LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \
26 eng_table.o eng_pkey.o eng_fat.o eng_all.o \
27 tb_rsa.o tb_dsa.o tb_ecdsa.o tb_dh.o tb_ecdh.o tb_rand.o tb_store.o \
28 tb_cipher.o tb_digest.o \
29 eng_openssl.o eng_cnf.o eng_dyn.o eng_cryptodev.o eng_padlock.o
30
31SRC= $(LIBSRC)
32
33EXHEADER= engine.h
34HEADER= $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48files:
49 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
50
51links:
52 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
53 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
54 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
55
56install:
57 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
58 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
59 do \
60 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done;
63
64tags:
65 ctags $(SRC)
66
67tests:
68
69lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff
71
72depend:
73 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
74 $(MAKEDEPEND) -- $(CFLAG) $(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 */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
82
83# DO NOT DELETE THIS LINE -- make depend depends on it.
84
85eng_all.o: ../../e_os.h ../../include/openssl/bio.h
86eng_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
87eng_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
88eng_all.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
89eng_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
90eng_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
91eng_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
92eng_all.o: ../cryptlib.h eng_all.c eng_int.h
93eng_cnf.o: ../../e_os.h ../../include/openssl/bio.h
94eng_cnf.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
95eng_cnf.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
96eng_cnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
97eng_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
98eng_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
99eng_cnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
100eng_cnf.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_cnf.c eng_int.h
101eng_cryptodev.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
102eng_cryptodev.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
103eng_cryptodev.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
104eng_cryptodev.o: ../../include/openssl/evp.h ../../include/openssl/obj_mac.h
105eng_cryptodev.o: ../../include/openssl/objects.h
106eng_cryptodev.o: ../../include/openssl/opensslconf.h
107eng_cryptodev.o: ../../include/openssl/opensslv.h
108eng_cryptodev.o: ../../include/openssl/ossl_typ.h
109eng_cryptodev.o: ../../include/openssl/safestack.h
110eng_cryptodev.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
111eng_cryptodev.o: eng_cryptodev.c
112eng_ctrl.o: ../../e_os.h ../../include/openssl/bio.h
113eng_ctrl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
114eng_ctrl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
115eng_ctrl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
116eng_ctrl.o: ../../include/openssl/opensslconf.h
117eng_ctrl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
118eng_ctrl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
119eng_ctrl.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_ctrl.c eng_int.h
120eng_dyn.o: ../../e_os.h ../../include/openssl/bio.h
121eng_dyn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
122eng_dyn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
123eng_dyn.o: ../../include/openssl/engine.h ../../include/openssl/err.h
124eng_dyn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
125eng_dyn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
126eng_dyn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
127eng_dyn.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_dyn.c eng_int.h
128eng_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
129eng_err.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
130eng_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
131eng_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132eng_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
133eng_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
134eng_err.o: eng_err.c
135eng_fat.o: ../../e_os.h ../../include/openssl/bio.h
136eng_fat.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
137eng_fat.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
138eng_fat.o: ../../include/openssl/engine.h ../../include/openssl/err.h
139eng_fat.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
140eng_fat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
141eng_fat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
142eng_fat.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_fat.c eng_int.h
143eng_init.o: ../../e_os.h ../../include/openssl/bio.h
144eng_init.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
145eng_init.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
146eng_init.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
147eng_init.o: ../../include/openssl/opensslconf.h
148eng_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149eng_init.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
150eng_init.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_init.c eng_int.h
151eng_lib.o: ../../e_os.h ../../include/openssl/bio.h
152eng_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
153eng_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
154eng_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
155eng_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
156eng_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
157eng_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158eng_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h eng_lib.c
159eng_list.o: ../../e_os.h ../../include/openssl/bio.h
160eng_list.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
161eng_list.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
162eng_list.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
163eng_list.o: ../../include/openssl/opensslconf.h
164eng_list.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
165eng_list.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
166eng_list.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h eng_list.c
167eng_openssl.o: ../../e_os.h ../../include/openssl/asn1.h
168eng_openssl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
169eng_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
170eng_openssl.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
171eng_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
172eng_openssl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
173eng_openssl.o: ../../include/openssl/engine.h ../../include/openssl/err.h
174eng_openssl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
175eng_openssl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
176eng_openssl.o: ../../include/openssl/opensslconf.h
177eng_openssl.o: ../../include/openssl/opensslv.h
178eng_openssl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
179eng_openssl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
180eng_openssl.o: ../../include/openssl/rand.h ../../include/openssl/rc4.h
181eng_openssl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
182eng_openssl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
183eng_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
184eng_openssl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h eng_openssl.c
185eng_padlock.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
186eng_padlock.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
187eng_padlock.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
188eng_padlock.o: ../../include/openssl/engine.h ../../include/openssl/err.h
189eng_padlock.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
190eng_padlock.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
191eng_padlock.o: ../../include/openssl/opensslconf.h
192eng_padlock.o: ../../include/openssl/opensslv.h
193eng_padlock.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
194eng_padlock.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
195eng_padlock.o: ../../include/openssl/symhacks.h eng_padlock.c
196eng_pkey.o: ../../e_os.h ../../include/openssl/bio.h
197eng_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
198eng_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
199eng_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
200eng_pkey.o: ../../include/openssl/opensslconf.h
201eng_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
202eng_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
203eng_pkey.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h eng_pkey.c
204eng_table.o: ../../e_os.h ../../include/openssl/asn1.h
205eng_table.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
206eng_table.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
207eng_table.o: ../../include/openssl/engine.h ../../include/openssl/err.h
208eng_table.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
209eng_table.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
210eng_table.o: ../../include/openssl/opensslconf.h
211eng_table.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
212eng_table.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
213eng_table.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h
214eng_table.o: eng_table.c
215tb_cipher.o: ../../e_os.h ../../include/openssl/bio.h
216tb_cipher.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
217tb_cipher.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
218tb_cipher.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
219tb_cipher.o: ../../include/openssl/opensslconf.h
220tb_cipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
221tb_cipher.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
222tb_cipher.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h
223tb_cipher.o: tb_cipher.c
224tb_dh.o: ../../e_os.h ../../include/openssl/bio.h
225tb_dh.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
226tb_dh.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
227tb_dh.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
228tb_dh.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
229tb_dh.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
230tb_dh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
231tb_dh.o: ../cryptlib.h eng_int.h tb_dh.c
232tb_digest.o: ../../e_os.h ../../include/openssl/bio.h
233tb_digest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
234tb_digest.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
235tb_digest.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
236tb_digest.o: ../../include/openssl/opensslconf.h
237tb_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
238tb_digest.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
239tb_digest.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h
240tb_digest.o: tb_digest.c
241tb_dsa.o: ../../e_os.h ../../include/openssl/bio.h
242tb_dsa.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
243tb_dsa.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
244tb_dsa.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
245tb_dsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
246tb_dsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
247tb_dsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
248tb_dsa.o: ../cryptlib.h eng_int.h tb_dsa.c
249tb_ecdh.o: ../../e_os.h ../../include/openssl/bio.h
250tb_ecdh.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
251tb_ecdh.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
252tb_ecdh.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
253tb_ecdh.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
254tb_ecdh.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
255tb_ecdh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
256tb_ecdh.o: ../cryptlib.h eng_int.h tb_ecdh.c
257tb_ecdsa.o: ../../e_os.h ../../include/openssl/bio.h
258tb_ecdsa.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
259tb_ecdsa.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
260tb_ecdsa.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
261tb_ecdsa.o: ../../include/openssl/opensslconf.h
262tb_ecdsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
263tb_ecdsa.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
264tb_ecdsa.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h tb_ecdsa.c
265tb_rand.o: ../../e_os.h ../../include/openssl/bio.h
266tb_rand.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
267tb_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
268tb_rand.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
269tb_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
270tb_rand.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
271tb_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
272tb_rand.o: ../cryptlib.h eng_int.h tb_rand.c
273tb_rsa.o: ../../e_os.h ../../include/openssl/bio.h
274tb_rsa.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
275tb_rsa.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
276tb_rsa.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
277tb_rsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
278tb_rsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
279tb_rsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
280tb_rsa.o: ../cryptlib.h eng_int.h tb_rsa.c
281tb_store.o: ../../e_os.h ../../include/openssl/bio.h
282tb_store.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
283tb_store.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
284tb_store.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
285tb_store.o: ../../include/openssl/opensslconf.h
286tb_store.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
287tb_store.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
288tb_store.o: ../../include/openssl/symhacks.h ../cryptlib.h eng_int.h tb_store.c
diff --git a/src/lib/libcrypto/engine/Makefile.ssl b/src/lib/libcrypto/engine/Makefile.ssl
new file mode 100644
index 0000000000..30a4446ff9
--- /dev/null
+++ b/src/lib/libcrypto/engine/Makefile.ssl
@@ -0,0 +1,538 @@
1#
2# OpenSSL/crypto/engine/Makefile
3#
4
5DIR= engine
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST= enginetest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= eng_err.c eng_lib.c eng_list.c eng_init.c eng_ctrl.c \
27 eng_table.c eng_pkey.c eng_fat.c eng_all.c \
28 tb_rsa.c tb_dsa.c tb_dh.c tb_rand.c tb_cipher.c tb_digest.c \
29 eng_openssl.c eng_dyn.c eng_cnf.c \
30 hw_atalla.c hw_cswift.c hw_ncipher.c hw_nuron.c hw_ubsec.c \
31 hw_cryptodev.c hw_aep.c hw_sureware.c hw_4758_cca.c
32LIBOBJ= eng_err.o eng_lib.o eng_list.o eng_init.o eng_ctrl.o \
33 eng_table.o eng_pkey.o eng_fat.o eng_all.o \
34 tb_rsa.o tb_dsa.o tb_dh.o tb_rand.o tb_cipher.o tb_digest.o \
35 eng_openssl.o eng_dyn.o eng_cnf.o \
36 hw_atalla.o hw_cswift.o hw_ncipher.o hw_nuron.o hw_ubsec.o \
37 hw_cryptodev.o hw_aep.o hw_sureware.o hw_4758_cca.o
38
39SRC= $(LIBSRC)
40
41EXHEADER= engine.h
42HEADER= $(EXHEADER)
43
44ALL= $(GENERAL) $(SRC) $(HEADER)
45
46top:
47 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
48
49all: lib
50
51lib: $(LIBOBJ)
52 $(AR) $(LIB) $(LIBOBJ)
53 $(RANLIB) $(LIB) || echo Never mind.
54 @touch lib
55
56files:
57 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
58
59links:
60 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65install:
66 @for i in $(EXHEADER) ; \
67 do \
68 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
69 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
70 done;
71
72tags:
73 ctags $(SRC)
74
75errors:
76 $(PERL) $(TOP)/util/mkerr.pl -conf hw.ec \
77 -nostatic -staticloader -write hw_*.c
78
79tests:
80
81lint:
82 lint -DLINT $(INCLUDES) $(SRC)>fluff
83
84depend:
85 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
86
87dclean:
88 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
89 mv -f Makefile.new $(MAKEFILE)
90
91clean:
92 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
93
94# DO NOT DELETE THIS LINE -- make depend depends on it.
95
96eng_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
97eng_all.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
98eng_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
99eng_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
100eng_all.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
101eng_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
102eng_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
103eng_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
104eng_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
105eng_all.o: ../../include/openssl/ui.h eng_all.c eng_int.h
106eng_cnf.o: ../../e_os.h ../../include/openssl/asn1.h
107eng_cnf.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
108eng_cnf.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
109eng_cnf.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
110eng_cnf.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
111eng_cnf.o: ../../include/openssl/engine.h ../../include/openssl/err.h
112eng_cnf.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
113eng_cnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114eng_cnf.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
115eng_cnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116eng_cnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
117eng_cnf.o: ../cryptlib.h eng_cnf.c
118eng_ctrl.o: ../../e_os.h ../../include/openssl/asn1.h
119eng_ctrl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
120eng_ctrl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
121eng_ctrl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
122eng_ctrl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
123eng_ctrl.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
124eng_ctrl.o: ../../include/openssl/opensslconf.h
125eng_ctrl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
126eng_ctrl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
127eng_ctrl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
128eng_ctrl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
129eng_ctrl.o: ../cryptlib.h eng_ctrl.c eng_int.h
130eng_dyn.o: ../../e_os.h ../../include/openssl/asn1.h
131eng_dyn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
132eng_dyn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
133eng_dyn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
134eng_dyn.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
135eng_dyn.o: ../../include/openssl/engine.h ../../include/openssl/err.h
136eng_dyn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
137eng_dyn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
138eng_dyn.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
139eng_dyn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
140eng_dyn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
141eng_dyn.o: ../cryptlib.h eng_dyn.c eng_int.h
142eng_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
143eng_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
144eng_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
145eng_err.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
146eng_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
147eng_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
148eng_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
149eng_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
150eng_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
151eng_err.o: ../../include/openssl/ui.h eng_err.c
152eng_fat.o: ../../e_os.h ../../include/openssl/asn1.h
153eng_fat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
154eng_fat.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
155eng_fat.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
156eng_fat.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
157eng_fat.o: ../../include/openssl/engine.h ../../include/openssl/err.h
158eng_fat.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
159eng_fat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
160eng_fat.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
161eng_fat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
162eng_fat.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
163eng_fat.o: ../cryptlib.h eng_fat.c eng_int.h
164eng_init.o: ../../e_os.h ../../include/openssl/asn1.h
165eng_init.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
166eng_init.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
167eng_init.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
168eng_init.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
169eng_init.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
170eng_init.o: ../../include/openssl/opensslconf.h
171eng_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
172eng_init.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
173eng_init.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
174eng_init.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
175eng_init.o: ../cryptlib.h eng_init.c eng_int.h
176eng_lib.o: ../../e_os.h ../../include/openssl/asn1.h
177eng_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
178eng_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
179eng_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
180eng_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
181eng_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
182eng_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
183eng_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
184eng_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
185eng_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
186eng_lib.o: ../../include/openssl/ui.h ../cryptlib.h eng_int.h eng_lib.c
187eng_list.o: ../../e_os.h ../../include/openssl/asn1.h
188eng_list.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
189eng_list.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
190eng_list.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
191eng_list.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
192eng_list.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
193eng_list.o: ../../include/openssl/opensslconf.h
194eng_list.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
195eng_list.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
196eng_list.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
197eng_list.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
198eng_list.o: ../cryptlib.h eng_int.h eng_list.c
199eng_openssl.o: ../../e_os.h ../../include/openssl/aes.h
200eng_openssl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
201eng_openssl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
202eng_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
203eng_openssl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
204eng_openssl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
205eng_openssl.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
206eng_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
207eng_openssl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
208eng_openssl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
209eng_openssl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
210eng_openssl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
211eng_openssl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
212eng_openssl.o: ../../include/openssl/opensslconf.h
213eng_openssl.o: ../../include/openssl/opensslv.h
214eng_openssl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
215eng_openssl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
216eng_openssl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
217eng_openssl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
218eng_openssl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
219eng_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
220eng_openssl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
221eng_openssl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
222eng_openssl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
223eng_openssl.o: ../cryptlib.h eng_openssl.c
224eng_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
225eng_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
226eng_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
227eng_pkey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
228eng_pkey.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
229eng_pkey.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
230eng_pkey.o: ../../include/openssl/opensslconf.h
231eng_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
232eng_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
233eng_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
234eng_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
235eng_pkey.o: ../cryptlib.h eng_int.h eng_pkey.c
236eng_table.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
237eng_table.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
238eng_table.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
239eng_table.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
240eng_table.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
241eng_table.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
242eng_table.o: ../../include/openssl/engine.h ../../include/openssl/err.h
243eng_table.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
244eng_table.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
245eng_table.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
246eng_table.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
247eng_table.o: ../../include/openssl/objects.h
248eng_table.o: ../../include/openssl/opensslconf.h
249eng_table.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
250eng_table.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
251eng_table.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
252eng_table.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
253eng_table.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
254eng_table.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
255eng_table.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
256eng_table.o: eng_int.h eng_table.c
257hw_4758_cca.o: ../../e_os.h ../../include/openssl/aes.h
258hw_4758_cca.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
259hw_4758_cca.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
260hw_4758_cca.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
261hw_4758_cca.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
262hw_4758_cca.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
263hw_4758_cca.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
264hw_4758_cca.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
265hw_4758_cca.o: ../../include/openssl/err.h ../../include/openssl/evp.h
266hw_4758_cca.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
267hw_4758_cca.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
268hw_4758_cca.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
269hw_4758_cca.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
270hw_4758_cca.o: ../../include/openssl/opensslconf.h
271hw_4758_cca.o: ../../include/openssl/opensslv.h
272hw_4758_cca.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
273hw_4758_cca.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
274hw_4758_cca.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
275hw_4758_cca.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
276hw_4758_cca.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
277hw_4758_cca.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
278hw_4758_cca.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
279hw_4758_cca.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
280hw_4758_cca.o: ../cryptlib.h hw_4758_cca.c hw_4758_cca_err.c hw_4758_cca_err.h
281hw_4758_cca.o: vendor_defns/hw_4758_cca.h
282hw_aep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
283hw_aep.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
284hw_aep.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
285hw_aep.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
286hw_aep.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
287hw_aep.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
288hw_aep.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
289hw_aep.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
290hw_aep.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
291hw_aep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
292hw_aep.o: ../../include/openssl/ui.h hw_aep.c hw_aep_err.c hw_aep_err.h
293hw_aep.o: vendor_defns/aep.h
294hw_atalla.o: ../../e_os.h ../../include/openssl/asn1.h
295hw_atalla.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
296hw_atalla.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
297hw_atalla.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
298hw_atalla.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
299hw_atalla.o: ../../include/openssl/engine.h ../../include/openssl/err.h
300hw_atalla.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
301hw_atalla.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
302hw_atalla.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
303hw_atalla.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
304hw_atalla.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
305hw_atalla.o: ../cryptlib.h hw_atalla.c hw_atalla_err.c hw_atalla_err.h
306hw_atalla.o: vendor_defns/atalla.h
307hw_cryptodev.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
308hw_cryptodev.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
309hw_cryptodev.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
310hw_cryptodev.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
311hw_cryptodev.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
312hw_cryptodev.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
313hw_cryptodev.o: ../../include/openssl/engine.h ../../include/openssl/err.h
314hw_cryptodev.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
315hw_cryptodev.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
316hw_cryptodev.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
317hw_cryptodev.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
318hw_cryptodev.o: ../../include/openssl/objects.h
319hw_cryptodev.o: ../../include/openssl/opensslconf.h
320hw_cryptodev.o: ../../include/openssl/opensslv.h
321hw_cryptodev.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
322hw_cryptodev.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
323hw_cryptodev.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
324hw_cryptodev.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
325hw_cryptodev.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
326hw_cryptodev.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
327hw_cryptodev.o: ../../include/openssl/ui_compat.h hw_cryptodev.c
328hw_cswift.o: ../../e_os.h ../../include/openssl/asn1.h
329hw_cswift.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
330hw_cswift.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
331hw_cswift.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
332hw_cswift.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
333hw_cswift.o: ../../include/openssl/engine.h ../../include/openssl/err.h
334hw_cswift.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
335hw_cswift.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
336hw_cswift.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
337hw_cswift.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
338hw_cswift.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
339hw_cswift.o: ../cryptlib.h hw_cswift.c hw_cswift_err.c hw_cswift_err.h
340hw_cswift.o: vendor_defns/cswift.h
341hw_ncipher.o: ../../e_os.h ../../include/openssl/aes.h
342hw_ncipher.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
343hw_ncipher.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
344hw_ncipher.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
345hw_ncipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
346hw_ncipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
347hw_ncipher.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
348hw_ncipher.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
349hw_ncipher.o: ../../include/openssl/err.h ../../include/openssl/evp.h
350hw_ncipher.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
351hw_ncipher.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
352hw_ncipher.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
353hw_ncipher.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
354hw_ncipher.o: ../../include/openssl/opensslconf.h
355hw_ncipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
356hw_ncipher.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
357hw_ncipher.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
358hw_ncipher.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
359hw_ncipher.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
360hw_ncipher.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
361hw_ncipher.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
362hw_ncipher.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
363hw_ncipher.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
364hw_ncipher.o: ../../include/openssl/x509_vfy.h ../cryptlib.h hw_ncipher.c
365hw_ncipher.o: hw_ncipher_err.c hw_ncipher_err.h vendor_defns/hwcryptohook.h
366hw_nuron.o: ../../e_os.h ../../include/openssl/asn1.h
367hw_nuron.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
368hw_nuron.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
369hw_nuron.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
370hw_nuron.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
371hw_nuron.o: ../../include/openssl/engine.h ../../include/openssl/err.h
372hw_nuron.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
373hw_nuron.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
374hw_nuron.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
375hw_nuron.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
376hw_nuron.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
377hw_nuron.o: ../cryptlib.h hw_nuron.c hw_nuron_err.c hw_nuron_err.h
378hw_sureware.o: ../../e_os.h ../../include/openssl/aes.h
379hw_sureware.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
380hw_sureware.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
381hw_sureware.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
382hw_sureware.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
383hw_sureware.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
384hw_sureware.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
385hw_sureware.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
386hw_sureware.o: ../../include/openssl/err.h ../../include/openssl/evp.h
387hw_sureware.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
388hw_sureware.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
389hw_sureware.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
390hw_sureware.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
391hw_sureware.o: ../../include/openssl/opensslconf.h
392hw_sureware.o: ../../include/openssl/opensslv.h
393hw_sureware.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
394hw_sureware.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
395hw_sureware.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
396hw_sureware.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
397hw_sureware.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
398hw_sureware.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
399hw_sureware.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
400hw_sureware.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
401hw_sureware.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
402hw_sureware.o: ../cryptlib.h eng_int.h engine.h hw_sureware.c hw_sureware_err.c
403hw_sureware.o: hw_sureware_err.h vendor_defns/sureware.h
404hw_ubsec.o: ../../e_os.h ../../include/openssl/asn1.h
405hw_ubsec.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
406hw_ubsec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
407hw_ubsec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
408hw_ubsec.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
409hw_ubsec.o: ../../include/openssl/engine.h ../../include/openssl/err.h
410hw_ubsec.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
411hw_ubsec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
412hw_ubsec.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
413hw_ubsec.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
414hw_ubsec.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
415hw_ubsec.o: ../cryptlib.h hw_ubsec.c hw_ubsec_err.c hw_ubsec_err.h
416hw_ubsec.o: vendor_defns/hw_ubsec.h
417tb_cipher.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
418tb_cipher.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
419tb_cipher.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
420tb_cipher.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
421tb_cipher.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
422tb_cipher.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
423tb_cipher.o: ../../include/openssl/engine.h ../../include/openssl/err.h
424tb_cipher.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
425tb_cipher.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
426tb_cipher.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
427tb_cipher.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
428tb_cipher.o: ../../include/openssl/objects.h
429tb_cipher.o: ../../include/openssl/opensslconf.h
430tb_cipher.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
431tb_cipher.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
432tb_cipher.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
433tb_cipher.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
434tb_cipher.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
435tb_cipher.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
436tb_cipher.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
437tb_cipher.o: eng_int.h tb_cipher.c
438tb_dh.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
439tb_dh.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
440tb_dh.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
441tb_dh.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
442tb_dh.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
443tb_dh.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
444tb_dh.o: ../../include/openssl/engine.h ../../include/openssl/err.h
445tb_dh.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
446tb_dh.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
447tb_dh.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
448tb_dh.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
449tb_dh.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
450tb_dh.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
451tb_dh.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
452tb_dh.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
453tb_dh.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
454tb_dh.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
455tb_dh.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
456tb_dh.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h eng_int.h
457tb_dh.o: tb_dh.c
458tb_digest.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
459tb_digest.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
460tb_digest.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
461tb_digest.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
462tb_digest.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
463tb_digest.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
464tb_digest.o: ../../include/openssl/engine.h ../../include/openssl/err.h
465tb_digest.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
466tb_digest.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
467tb_digest.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
468tb_digest.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
469tb_digest.o: ../../include/openssl/objects.h
470tb_digest.o: ../../include/openssl/opensslconf.h
471tb_digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
472tb_digest.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
473tb_digest.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
474tb_digest.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
475tb_digest.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
476tb_digest.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
477tb_digest.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
478tb_digest.o: eng_int.h tb_digest.c
479tb_dsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
480tb_dsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
481tb_dsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
482tb_dsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
483tb_dsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
484tb_dsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
485tb_dsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h
486tb_dsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
487tb_dsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
488tb_dsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
489tb_dsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
490tb_dsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
491tb_dsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
492tb_dsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
493tb_dsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
494tb_dsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
495tb_dsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
496tb_dsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
497tb_dsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
498tb_dsa.o: eng_int.h tb_dsa.c
499tb_rand.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
500tb_rand.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
501tb_rand.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
502tb_rand.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
503tb_rand.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
504tb_rand.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
505tb_rand.o: ../../include/openssl/engine.h ../../include/openssl/err.h
506tb_rand.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
507tb_rand.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
508tb_rand.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
509tb_rand.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
510tb_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
511tb_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
512tb_rand.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
513tb_rand.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
514tb_rand.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
515tb_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
516tb_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
517tb_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
518tb_rand.o: eng_int.h tb_rand.c
519tb_rsa.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
520tb_rsa.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
521tb_rsa.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
522tb_rsa.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
523tb_rsa.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
524tb_rsa.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
525tb_rsa.o: ../../include/openssl/engine.h ../../include/openssl/err.h
526tb_rsa.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
527tb_rsa.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
528tb_rsa.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
529tb_rsa.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
530tb_rsa.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
531tb_rsa.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
532tb_rsa.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
533tb_rsa.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
534tb_rsa.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
535tb_rsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
536tb_rsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
537tb_rsa.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
538tb_rsa.o: eng_int.h tb_rsa.c
diff --git a/src/lib/libcrypto/engine/eng_all.c b/src/lib/libcrypto/engine/eng_all.c
index 8599046717..0f6992a40d 100644
--- a/src/lib/libcrypto/engine/eng_all.c
+++ b/src/lib/libcrypto/engine/eng_all.c
@@ -56,7 +56,8 @@
56 * 56 *
57 */ 57 */
58 58
59#include "cryptlib.h" 59#include <openssl/err.h>
60#include <openssl/engine.h>
60#include "eng_int.h" 61#include "eng_int.h"
61 62
62void ENGINE_load_builtin_engines(void) 63void ENGINE_load_builtin_engines(void)
@@ -68,42 +69,32 @@ void ENGINE_load_builtin_engines(void)
68#if 0 69#if 0
69 ENGINE_load_openssl(); 70 ENGINE_load_openssl();
70#endif 71#endif
71#if !defined(OPENSSL_NO_HW) && !defined(OPENSSL_NO_HW_PADLOCK)
72 ENGINE_load_padlock();
73#endif
74 ENGINE_load_dynamic(); 72 ENGINE_load_dynamic();
75#ifndef OPENSSL_NO_STATIC_ENGINE
76#ifndef OPENSSL_NO_HW 73#ifndef OPENSSL_NO_HW
77#ifndef OPENSSL_NO_HW_4758_CCA
78 ENGINE_load_4758cca();
79#endif
80#ifndef OPENSSL_NO_HW_AEP
81 ENGINE_load_aep();
82#endif
83#ifndef OPENSSL_NO_HW_ATALLA
84 ENGINE_load_atalla();
85#endif
86#ifndef OPENSSL_NO_HW_CSWIFT 74#ifndef OPENSSL_NO_HW_CSWIFT
87 ENGINE_load_cswift(); 75 ENGINE_load_cswift();
88#endif 76#endif
89#ifndef OPENSSL_NO_HW_NCIPHER 77#ifndef OPENSSL_NO_HW_NCIPHER
90 ENGINE_load_chil(); 78 ENGINE_load_chil();
91#endif 79#endif
80#ifndef OPENSSL_NO_HW_ATALLA
81 ENGINE_load_atalla();
82#endif
92#ifndef OPENSSL_NO_HW_NURON 83#ifndef OPENSSL_NO_HW_NURON
93 ENGINE_load_nuron(); 84 ENGINE_load_nuron();
94#endif 85#endif
95#ifndef OPENSSL_NO_HW_SUREWARE
96 ENGINE_load_sureware();
97#endif
98#ifndef OPENSSL_NO_HW_UBSEC 86#ifndef OPENSSL_NO_HW_UBSEC
99 ENGINE_load_ubsec(); 87 ENGINE_load_ubsec();
100#endif 88#endif
89#ifndef OPENSSL_NO_HW_AEP
90 ENGINE_load_aep();
101#endif 91#endif
102#if !defined(OPENSSL_NO_GMP) && !defined(OPENSSL_NO_HW_GMP) 92#ifndef OPENSSL_NO_HW_SUREWARE
103 ENGINE_load_gmp(); 93 ENGINE_load_sureware();
104#endif 94#endif
95#ifndef OPENSSL_NO_HW_4758_CCA
96 ENGINE_load_4758cca();
105#endif 97#endif
106#ifndef OPENSSL_NO_HW
107#if defined(__OpenBSD__) || defined(__FreeBSD__) 98#if defined(__OpenBSD__) || defined(__FreeBSD__)
108 ENGINE_load_cryptodev(); 99 ENGINE_load_cryptodev();
109#endif 100#endif
diff --git a/src/lib/libcrypto/engine/eng_cnf.c b/src/lib/libcrypto/engine/eng_cnf.c
index a97e01e619..4225760af1 100644
--- a/src/lib/libcrypto/engine/eng_cnf.c
+++ b/src/lib/libcrypto/engine/eng_cnf.c
@@ -56,8 +56,11 @@
56 * 56 *
57 */ 57 */
58 58
59#include "eng_int.h" 59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
60#include <openssl/conf.h> 62#include <openssl/conf.h>
63#include <openssl/engine.h>
61 64
62/* #define ENGINE_CONF_DEBUG */ 65/* #define ENGINE_CONF_DEBUG */
63 66
@@ -207,7 +210,7 @@ static int int_engine_module_init(CONF_IMODULE *md, const CONF *cnf)
207 210
208 if (!elist) 211 if (!elist)
209 { 212 {
210 ENGINEerr(ENGINE_F_INT_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR); 213 ENGINEerr(ENGINE_F_ENGINE_MODULE_INIT, ENGINE_R_ENGINES_SECTION_ERROR);
211 return 0; 214 return 0;
212 } 215 }
213 216
diff --git a/src/lib/libcrypto/engine/eng_cryptodev.c b/src/lib/libcrypto/engine/eng_cryptodev.c
new file mode 100644
index 0000000000..ab38cd52f0
--- /dev/null
+++ b/src/lib/libcrypto/engine/eng_cryptodev.c
@@ -0,0 +1,1133 @@
1/*
2 * Copyright (c) 2002 Bob Beck <beck@openbsd.org>
3 * Copyright (c) 2002 Theo de Raadt
4 * Copyright (c) 2002 Markus Friedl
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#include <openssl/objects.h>
30#include <openssl/engine.h>
31#include <openssl/evp.h>
32#include <openssl/bn.h>
33
34#if (defined(__unix__) || defined(unix)) && !defined(USG) && \
35 (defined(OpenBSD) || defined(__FreeBSD_version))
36#include <sys/param.h>
37# if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041)
38# define HAVE_CRYPTODEV
39# endif
40# if (OpenBSD >= 200110)
41# define HAVE_SYSLOG_R
42# endif
43#endif
44
45#ifndef HAVE_CRYPTODEV
46
47void
48ENGINE_load_cryptodev(void)
49{
50 /* This is a NOP on platforms without /dev/crypto */
51 return;
52}
53
54#else
55
56#include <sys/types.h>
57#include <crypto/cryptodev.h>
58#include <sys/ioctl.h>
59#include <errno.h>
60#include <stdio.h>
61#include <unistd.h>
62#include <fcntl.h>
63#include <stdarg.h>
64#include <syslog.h>
65#include <errno.h>
66#include <string.h>
67
68struct dev_crypto_state {
69 struct session_op d_sess;
70 int d_fd;
71};
72
73static u_int32_t cryptodev_asymfeat = 0;
74
75static int get_asym_dev_crypto(void);
76static int open_dev_crypto(void);
77static int get_dev_crypto(void);
78static int cryptodev_max_iv(int cipher);
79static int cryptodev_key_length_valid(int cipher, int len);
80static int cipher_nid_to_cryptodev(int nid);
81static int get_cryptodev_ciphers(const int **cnids);
82static int get_cryptodev_digests(const int **cnids);
83static int cryptodev_usable_ciphers(const int **nids);
84static int cryptodev_usable_digests(const int **nids);
85static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
86 const unsigned char *in, unsigned int inl);
87static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
88 const unsigned char *iv, int enc);
89static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx);
90static int cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
91 const int **nids, int nid);
92static int cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
93 const int **nids, int nid);
94static int bn2crparam(const BIGNUM *a, struct crparam *crp);
95static int crparam2bn(struct crparam *crp, BIGNUM *a);
96static void zapparams(struct crypt_kop *kop);
97static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r,
98 int slen, BIGNUM *s);
99
100static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
101 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
102static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I,
103 RSA *rsa);
104static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx);
105static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
106 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
107static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g,
108 BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p,
109 BN_CTX *ctx, BN_MONT_CTX *mont);
110static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst,
111 int dlen, DSA *dsa);
112static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len,
113 DSA_SIG *sig, DSA *dsa);
114static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
115 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
116 BN_MONT_CTX *m_ctx);
117static int cryptodev_dh_compute_key(unsigned char *key,
118 const BIGNUM *pub_key, DH *dh);
119static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p,
120 void (*f)());
121void ENGINE_load_cryptodev(void);
122
123static const ENGINE_CMD_DEFN cryptodev_defns[] = {
124 { 0, NULL, NULL, 0 }
125};
126
127static struct {
128 int id;
129 int nid;
130 int ivmax;
131 int keylen;
132} ciphers[] = {
133 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
134 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
135 { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, },
136 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
137 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, },
138 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
139 { 0, NID_undef, 0, 0, },
140};
141
142static struct {
143 int id;
144 int nid;
145} digests[] = {
146 { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, },
147 { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, },
148 { CRYPTO_MD5_KPDK, NID_undef, },
149 { CRYPTO_SHA1_KPDK, NID_undef, },
150 { CRYPTO_MD5, NID_md5, },
151 { CRYPTO_SHA1, NID_undef, },
152 { 0, NID_undef, },
153};
154
155/*
156 * Return a fd if /dev/crypto seems usable, 0 otherwise.
157 */
158static int
159open_dev_crypto(void)
160{
161 static int fd = -1;
162
163 if (fd == -1) {
164 if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
165 return (-1);
166 /* close on exec */
167 if (fcntl(fd, F_SETFD, 1) == -1) {
168 close(fd);
169 fd = -1;
170 return (-1);
171 }
172 }
173 return (fd);
174}
175
176static int
177get_dev_crypto(void)
178{
179 int fd, retfd;
180
181 if ((fd = open_dev_crypto()) == -1)
182 return (-1);
183 if (ioctl(fd, CRIOGET, &retfd) == -1)
184 return (-1);
185
186 /* close on exec */
187 if (fcntl(retfd, F_SETFD, 1) == -1) {
188 close(retfd);
189 return (-1);
190 }
191 return (retfd);
192}
193
194/* Caching version for asym operations */
195static int
196get_asym_dev_crypto(void)
197{
198 static int fd = -1;
199
200 if (fd == -1)
201 fd = get_dev_crypto();
202 return fd;
203}
204
205/*
206 * XXXX this needs to be set for each alg - and determined from
207 * a running card.
208 */
209static int
210cryptodev_max_iv(int cipher)
211{
212 int i;
213
214 for (i = 0; ciphers[i].id; i++)
215 if (ciphers[i].id == cipher)
216 return (ciphers[i].ivmax);
217 return (0);
218}
219
220/*
221 * XXXX this needs to be set for each alg - and determined from
222 * a running card. For now, fake it out - but most of these
223 * for real devices should return 1 for the supported key
224 * sizes the device can handle.
225 */
226static int
227cryptodev_key_length_valid(int cipher, int len)
228{
229 int i;
230
231 for (i = 0; ciphers[i].id; i++)
232 if (ciphers[i].id == cipher)
233 return (ciphers[i].keylen == len);
234 return (0);
235}
236
237/* convert libcrypto nids to cryptodev */
238static int
239cipher_nid_to_cryptodev(int nid)
240{
241 int i;
242
243 for (i = 0; ciphers[i].id; i++)
244 if (ciphers[i].nid == nid)
245 return (ciphers[i].id);
246 return (0);
247}
248
249/*
250 * Find out what ciphers /dev/crypto will let us have a session for.
251 * XXX note, that some of these openssl doesn't deal with yet!
252 * returning them here is harmless, as long as we return NULL
253 * when asked for a handler in the cryptodev_engine_ciphers routine
254 */
255static int
256get_cryptodev_ciphers(const int **cnids)
257{
258 static int nids[CRYPTO_ALGORITHM_MAX];
259 struct session_op sess;
260 int fd, i, count = 0;
261
262 if ((fd = get_dev_crypto()) < 0) {
263 *cnids = NULL;
264 return (0);
265 }
266 memset(&sess, 0, sizeof(sess));
267 sess.key = (caddr_t)"123456781234567812345678";
268
269 for (i = 0; ciphers[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
270 if (ciphers[i].nid == NID_undef)
271 continue;
272 sess.cipher = ciphers[i].id;
273 sess.keylen = ciphers[i].keylen;
274 sess.mac = 0;
275 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
276 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
277 nids[count++] = ciphers[i].nid;
278 }
279 close(fd);
280
281 if (count > 0)
282 *cnids = nids;
283 else
284 *cnids = NULL;
285 return (count);
286}
287
288/*
289 * Find out what digests /dev/crypto will let us have a session for.
290 * XXX note, that some of these openssl doesn't deal with yet!
291 * returning them here is harmless, as long as we return NULL
292 * when asked for a handler in the cryptodev_engine_digests routine
293 */
294static int
295get_cryptodev_digests(const int **cnids)
296{
297 static int nids[CRYPTO_ALGORITHM_MAX];
298 struct session_op sess;
299 int fd, i, count = 0;
300
301 if ((fd = get_dev_crypto()) < 0) {
302 *cnids = NULL;
303 return (0);
304 }
305 memset(&sess, 0, sizeof(sess));
306 for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
307 if (digests[i].nid == NID_undef)
308 continue;
309 sess.mac = digests[i].id;
310 sess.cipher = 0;
311 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
312 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
313 nids[count++] = digests[i].nid;
314 }
315 close(fd);
316
317 if (count > 0)
318 *cnids = nids;
319 else
320 *cnids = NULL;
321 return (count);
322}
323
324/*
325 * Find the useable ciphers|digests from dev/crypto - this is the first
326 * thing called by the engine init crud which determines what it
327 * can use for ciphers from this engine. We want to return
328 * only what we can do, anythine else is handled by software.
329 *
330 * If we can't initialize the device to do anything useful for
331 * any reason, we want to return a NULL array, and 0 length,
332 * which forces everything to be done is software. By putting
333 * the initalization of the device in here, we ensure we can
334 * use this engine as the default, and if for whatever reason
335 * /dev/crypto won't do what we want it will just be done in
336 * software
337 *
338 * This can (should) be greatly expanded to perhaps take into
339 * account speed of the device, and what we want to do.
340 * (although the disabling of particular alg's could be controlled
341 * by the device driver with sysctl's.) - this is where we
342 * want most of the decisions made about what we actually want
343 * to use from /dev/crypto.
344 */
345static int
346cryptodev_usable_ciphers(const int **nids)
347{
348 return (get_cryptodev_ciphers(nids));
349}
350
351static int
352cryptodev_usable_digests(const int **nids)
353{
354 /*
355 * XXXX just disable all digests for now, because it sucks.
356 * we need a better way to decide this - i.e. I may not
357 * want digests on slow cards like hifn on fast machines,
358 * but might want them on slow or loaded machines, etc.
359 * will also want them when using crypto cards that don't
360 * suck moose gonads - would be nice to be able to decide something
361 * as reasonable default without having hackery that's card dependent.
362 * of course, the default should probably be just do everything,
363 * with perhaps a sysctl to turn algoritms off (or have them off
364 * by default) on cards that generally suck like the hifn.
365 */
366 *nids = NULL;
367 return (0);
368}
369
370static int
371cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
372 const unsigned char *in, unsigned int inl)
373{
374 struct crypt_op cryp;
375 struct dev_crypto_state *state = ctx->cipher_data;
376 struct session_op *sess = &state->d_sess;
377 void *iiv;
378 unsigned char save_iv[EVP_MAX_IV_LENGTH];
379
380 if (state->d_fd < 0)
381 return (0);
382 if (!inl)
383 return (1);
384 if ((inl % ctx->cipher->block_size) != 0)
385 return (0);
386
387 memset(&cryp, 0, sizeof(cryp));
388
389 cryp.ses = sess->ses;
390 cryp.flags = 0;
391 cryp.len = inl;
392 cryp.src = (caddr_t) in;
393 cryp.dst = (caddr_t) out;
394 cryp.mac = 0;
395
396 cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
397
398 if (ctx->cipher->iv_len) {
399 cryp.iv = (caddr_t) ctx->iv;
400 if (!ctx->encrypt) {
401 iiv = (void *) in + inl - ctx->cipher->iv_len;
402 memcpy(save_iv, iiv, ctx->cipher->iv_len);
403 }
404 } else
405 cryp.iv = NULL;
406
407 if (ioctl(state->d_fd, CIOCCRYPT, &cryp) == -1) {
408 /* XXX need better errror handling
409 * this can fail for a number of different reasons.
410 */
411 return (0);
412 }
413
414 if (ctx->cipher->iv_len) {
415 if (ctx->encrypt)
416 iiv = (void *) out + inl - ctx->cipher->iv_len;
417 else
418 iiv = save_iv;
419 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
420 }
421 return (1);
422}
423
424static int
425cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
426 const unsigned char *iv, int enc)
427{
428 struct dev_crypto_state *state = ctx->cipher_data;
429 struct session_op *sess = &state->d_sess;
430 int cipher;
431
432 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NID_undef)
433 return (0);
434
435 if (ctx->cipher->iv_len > cryptodev_max_iv(cipher))
436 return (0);
437
438 if (!cryptodev_key_length_valid(cipher, ctx->key_len))
439 return (0);
440
441 memset(sess, 0, sizeof(struct session_op));
442
443 if ((state->d_fd = get_dev_crypto()) < 0)
444 return (0);
445
446 sess->key = (unsigned char *)key;
447 sess->keylen = ctx->key_len;
448 sess->cipher = cipher;
449
450 if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) {
451 close(state->d_fd);
452 state->d_fd = -1;
453 return (0);
454 }
455 return (1);
456}
457
458/*
459 * free anything we allocated earlier when initting a
460 * session, and close the session.
461 */
462static int
463cryptodev_cleanup(EVP_CIPHER_CTX *ctx)
464{
465 int ret = 0;
466 struct dev_crypto_state *state = ctx->cipher_data;
467 struct session_op *sess = &state->d_sess;
468
469 if (state->d_fd < 0)
470 return (0);
471
472 /* XXX if this ioctl fails, someting's wrong. the invoker
473 * may have called us with a bogus ctx, or we could
474 * have a device that for whatever reason just doesn't
475 * want to play ball - it's not clear what's right
476 * here - should this be an error? should it just
477 * increase a counter, hmm. For right now, we return
478 * 0 - I don't believe that to be "right". we could
479 * call the gorpy openssl lib error handlers that
480 * print messages to users of the library. hmm..
481 */
482
483 if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) == -1) {
484 ret = 0;
485 } else {
486 ret = 1;
487 }
488 close(state->d_fd);
489 state->d_fd = -1;
490
491 return (ret);
492}
493
494/*
495 * libcrypto EVP stuff - this is how we get wired to EVP so the engine
496 * gets called when libcrypto requests a cipher NID.
497 */
498
499/* DES CBC EVP */
500const EVP_CIPHER cryptodev_des_cbc = {
501 NID_des_cbc,
502 8, 8, 8,
503 EVP_CIPH_CBC_MODE,
504 cryptodev_init_key,
505 cryptodev_cipher,
506 cryptodev_cleanup,
507 sizeof(struct dev_crypto_state),
508 EVP_CIPHER_set_asn1_iv,
509 EVP_CIPHER_get_asn1_iv,
510 NULL
511};
512
513/* 3DES CBC EVP */
514const EVP_CIPHER cryptodev_3des_cbc = {
515 NID_des_ede3_cbc,
516 8, 24, 8,
517 EVP_CIPH_CBC_MODE,
518 cryptodev_init_key,
519 cryptodev_cipher,
520 cryptodev_cleanup,
521 sizeof(struct dev_crypto_state),
522 EVP_CIPHER_set_asn1_iv,
523 EVP_CIPHER_get_asn1_iv,
524 NULL
525};
526
527const EVP_CIPHER cryptodev_bf_cbc = {
528 NID_bf_cbc,
529 8, 16, 8,
530 EVP_CIPH_CBC_MODE,
531 cryptodev_init_key,
532 cryptodev_cipher,
533 cryptodev_cleanup,
534 sizeof(struct dev_crypto_state),
535 EVP_CIPHER_set_asn1_iv,
536 EVP_CIPHER_get_asn1_iv,
537 NULL
538};
539
540const EVP_CIPHER cryptodev_cast_cbc = {
541 NID_cast5_cbc,
542 8, 16, 8,
543 EVP_CIPH_CBC_MODE,
544 cryptodev_init_key,
545 cryptodev_cipher,
546 cryptodev_cleanup,
547 sizeof(struct dev_crypto_state),
548 EVP_CIPHER_set_asn1_iv,
549 EVP_CIPHER_get_asn1_iv,
550 NULL
551};
552
553const EVP_CIPHER cryptodev_aes_cbc = {
554 NID_aes_128_cbc,
555 16, 16, 16,
556 EVP_CIPH_CBC_MODE,
557 cryptodev_init_key,
558 cryptodev_cipher,
559 cryptodev_cleanup,
560 sizeof(struct dev_crypto_state),
561 EVP_CIPHER_set_asn1_iv,
562 EVP_CIPHER_get_asn1_iv,
563 NULL
564};
565
566/*
567 * Registered by the ENGINE when used to find out how to deal with
568 * a particular NID in the ENGINE. this says what we'll do at the
569 * top level - note, that list is restricted by what we answer with
570 */
571static int
572cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
573 const int **nids, int nid)
574{
575 if (!cipher)
576 return (cryptodev_usable_ciphers(nids));
577
578 switch (nid) {
579 case NID_des_ede3_cbc:
580 *cipher = &cryptodev_3des_cbc;
581 break;
582 case NID_des_cbc:
583 *cipher = &cryptodev_des_cbc;
584 break;
585 case NID_bf_cbc:
586 *cipher = &cryptodev_bf_cbc;
587 break;
588 case NID_cast5_cbc:
589 *cipher = &cryptodev_cast_cbc;
590 break;
591 case NID_aes_128_cbc:
592 *cipher = &cryptodev_aes_cbc;
593 break;
594 default:
595 *cipher = NULL;
596 break;
597 }
598 return (*cipher != NULL);
599}
600
601static int
602cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
603 const int **nids, int nid)
604{
605 if (!digest)
606 return (cryptodev_usable_digests(nids));
607
608 switch (nid) {
609 case NID_md5:
610 *digest = NULL; /* need to make a clean md5 critter */
611 break;
612 default:
613 *digest = NULL;
614 break;
615 }
616 return (*digest != NULL);
617}
618
619/*
620 * Convert a BIGNUM to the representation that /dev/crypto needs.
621 * Upon completion of use, the caller is responsible for freeing
622 * crp->crp_p.
623 */
624static int
625bn2crparam(const BIGNUM *a, struct crparam *crp)
626{
627 int i, j, k;
628 ssize_t words, bytes, bits;
629 u_char *b;
630
631 crp->crp_p = NULL;
632 crp->crp_nbits = 0;
633
634 bits = BN_num_bits(a);
635 bytes = (bits + 7) / 8;
636
637 b = malloc(bytes);
638 if (b == NULL)
639 return (1);
640
641 crp->crp_p = b;
642 crp->crp_nbits = bits;
643
644 for (i = 0, j = 0; i < a->top; i++) {
645 for (k = 0; k < BN_BITS2 / 8; k++) {
646 if ((j + k) >= bytes)
647 return (0);
648 b[j + k] = a->d[i] >> (k * 8);
649 }
650 j += BN_BITS2 / 8;
651 }
652 return (0);
653}
654
655/* Convert a /dev/crypto parameter to a BIGNUM */
656static int
657crparam2bn(struct crparam *crp, BIGNUM *a)
658{
659 u_int8_t *pd;
660 int i, bytes;
661
662 bytes = (crp->crp_nbits + 7) / 8;
663
664 if (bytes == 0)
665 return (-1);
666
667 if ((pd = (u_int8_t *) malloc(bytes)) == NULL)
668 return (-1);
669
670 for (i = 0; i < bytes; i++)
671 pd[i] = crp->crp_p[bytes - i - 1];
672
673 BN_bin2bn(pd, bytes, a);
674 free(pd);
675
676 return (0);
677}
678
679static void
680zapparams(struct crypt_kop *kop)
681{
682 int i;
683
684 for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
685 if (kop->crk_param[i].crp_p)
686 free(kop->crk_param[i].crp_p);
687 kop->crk_param[i].crp_p = NULL;
688 kop->crk_param[i].crp_nbits = 0;
689 }
690}
691
692static int
693cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s)
694{
695 int fd, ret = -1;
696
697 if ((fd = get_asym_dev_crypto()) < 0)
698 return (ret);
699
700 if (r) {
701 kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char));
702 kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8;
703 kop->crk_oparams++;
704 }
705 if (s) {
706 kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char));
707 kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8;
708 kop->crk_oparams++;
709 }
710
711 if (ioctl(fd, CIOCKEY, kop) == 0) {
712 if (r)
713 crparam2bn(&kop->crk_param[kop->crk_iparams], r);
714 if (s)
715 crparam2bn(&kop->crk_param[kop->crk_iparams+1], s);
716 ret = 0;
717 }
718
719 return (ret);
720}
721
722static int
723cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
724 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
725{
726 struct crypt_kop kop;
727 int ret = 1;
728
729 /* Currently, we know we can do mod exp iff we can do any
730 * asymmetric operations at all.
731 */
732 if (cryptodev_asymfeat == 0) {
733 ret = BN_mod_exp(r, a, p, m, ctx);
734 return (ret);
735 }
736
737 memset(&kop, 0, sizeof kop);
738 kop.crk_op = CRK_MOD_EXP;
739
740 /* inputs: a^p % m */
741 if (bn2crparam(a, &kop.crk_param[0]))
742 goto err;
743 if (bn2crparam(p, &kop.crk_param[1]))
744 goto err;
745 if (bn2crparam(m, &kop.crk_param[2]))
746 goto err;
747 kop.crk_iparams = 3;
748
749 if (cryptodev_asym(&kop, BN_num_bytes(m), r, 0, NULL) == -1) {
750 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
751 ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont);
752 }
753err:
754 zapparams(&kop);
755 return (ret);
756}
757
758static int
759cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
760{
761 int r;
762 BN_CTX *ctx;
763
764 ctx = BN_CTX_new();
765 r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL);
766 BN_CTX_free(ctx);
767 return (r);
768}
769
770static int
771cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
772{
773 struct crypt_kop kop;
774 int ret = 1;
775
776 if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
777 /* XXX 0 means failure?? */
778 return (0);
779 }
780
781 memset(&kop, 0, sizeof kop);
782 kop.crk_op = CRK_MOD_EXP_CRT;
783 /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
784 if (bn2crparam(rsa->p, &kop.crk_param[0]))
785 goto err;
786 if (bn2crparam(rsa->q, &kop.crk_param[1]))
787 goto err;
788 if (bn2crparam(I, &kop.crk_param[2]))
789 goto err;
790 if (bn2crparam(rsa->dmp1, &kop.crk_param[3]))
791 goto err;
792 if (bn2crparam(rsa->dmq1, &kop.crk_param[4]))
793 goto err;
794 if (bn2crparam(rsa->iqmp, &kop.crk_param[5]))
795 goto err;
796 kop.crk_iparams = 6;
797
798 if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL) == -1) {
799 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
800 ret = (*meth->rsa_mod_exp)(r0, I, rsa, ctx);
801 }
802err:
803 zapparams(&kop);
804 return (ret);
805}
806
807static RSA_METHOD cryptodev_rsa = {
808 "cryptodev RSA method",
809 NULL, /* rsa_pub_enc */
810 NULL, /* rsa_pub_dec */
811 NULL, /* rsa_priv_enc */
812 NULL, /* rsa_priv_dec */
813 NULL,
814 NULL,
815 NULL, /* init */
816 NULL, /* finish */
817 0, /* flags */
818 NULL, /* app_data */
819 NULL, /* rsa_sign */
820 NULL /* rsa_verify */
821};
822
823static int
824cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
825 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
826{
827 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
828}
829
830static int
831cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g,
832 BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p,
833 BN_CTX *ctx, BN_MONT_CTX *mont)
834{
835 BIGNUM t2;
836 int ret = 0;
837
838 BN_init(&t2);
839
840 /* v = ( g^u1 * y^u2 mod p ) mod q */
841 /* let t1 = g ^ u1 mod p */
842 ret = 0;
843
844 if (!dsa->meth->bn_mod_exp(dsa,t1,dsa->g,u1,dsa->p,ctx,mont))
845 goto err;
846
847 /* let t2 = y ^ u2 mod p */
848 if (!dsa->meth->bn_mod_exp(dsa,&t2,dsa->pub_key,u2,dsa->p,ctx,mont))
849 goto err;
850 /* let u1 = t1 * t2 mod p */
851 if (!BN_mod_mul(u1,t1,&t2,dsa->p,ctx))
852 goto err;
853
854 BN_copy(t1,u1);
855
856 ret = 1;
857err:
858 BN_free(&t2);
859 return(ret);
860}
861
862static DSA_SIG *
863cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
864{
865 struct crypt_kop kop;
866 BIGNUM *r = NULL, *s = NULL;
867 DSA_SIG *dsaret = NULL;
868
869 if ((r = BN_new()) == NULL)
870 goto err;
871 if ((s = BN_new()) == NULL) {
872 BN_free(r);
873 goto err;
874 }
875
876 memset(&kop, 0, sizeof kop);
877 kop.crk_op = CRK_DSA_SIGN;
878
879 /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */
880 kop.crk_param[0].crp_p = (caddr_t)dgst;
881 kop.crk_param[0].crp_nbits = dlen * 8;
882 if (bn2crparam(dsa->p, &kop.crk_param[1]))
883 goto err;
884 if (bn2crparam(dsa->q, &kop.crk_param[2]))
885 goto err;
886 if (bn2crparam(dsa->g, &kop.crk_param[3]))
887 goto err;
888 if (bn2crparam(dsa->priv_key, &kop.crk_param[4]))
889 goto err;
890 kop.crk_iparams = 5;
891
892 if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r,
893 BN_num_bytes(dsa->q), s) == 0) {
894 dsaret = DSA_SIG_new();
895 dsaret->r = r;
896 dsaret->s = s;
897 } else {
898 const DSA_METHOD *meth = DSA_OpenSSL();
899 BN_free(r);
900 BN_free(s);
901 dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa);
902 }
903err:
904 kop.crk_param[0].crp_p = NULL;
905 zapparams(&kop);
906 return (dsaret);
907}
908
909static int
910cryptodev_dsa_verify(const unsigned char *dgst, int dlen,
911 DSA_SIG *sig, DSA *dsa)
912{
913 struct crypt_kop kop;
914 int dsaret = 1;
915
916 memset(&kop, 0, sizeof kop);
917 kop.crk_op = CRK_DSA_VERIFY;
918
919 /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */
920 kop.crk_param[0].crp_p = (caddr_t)dgst;
921 kop.crk_param[0].crp_nbits = dlen * 8;
922 if (bn2crparam(dsa->p, &kop.crk_param[1]))
923 goto err;
924 if (bn2crparam(dsa->q, &kop.crk_param[2]))
925 goto err;
926 if (bn2crparam(dsa->g, &kop.crk_param[3]))
927 goto err;
928 if (bn2crparam(dsa->pub_key, &kop.crk_param[4]))
929 goto err;
930 if (bn2crparam(sig->r, &kop.crk_param[5]))
931 goto err;
932 if (bn2crparam(sig->s, &kop.crk_param[6]))
933 goto err;
934 kop.crk_iparams = 7;
935
936 if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) {
937 dsaret = kop.crk_status;
938 } else {
939 const DSA_METHOD *meth = DSA_OpenSSL();
940
941 dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa);
942 }
943err:
944 kop.crk_param[0].crp_p = NULL;
945 zapparams(&kop);
946 return (dsaret);
947}
948
949static DSA_METHOD cryptodev_dsa = {
950 "cryptodev DSA method",
951 NULL,
952 NULL, /* dsa_sign_setup */
953 NULL,
954 NULL, /* dsa_mod_exp */
955 NULL,
956 NULL, /* init */
957 NULL, /* finish */
958 0, /* flags */
959 NULL /* app_data */
960};
961
962static int
963cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
964 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
965 BN_MONT_CTX *m_ctx)
966{
967 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
968}
969
970static int
971cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
972{
973 struct crypt_kop kop;
974 int dhret = 1;
975 int fd, keylen;
976
977 if ((fd = get_asym_dev_crypto()) < 0) {
978 const DH_METHOD *meth = DH_OpenSSL();
979
980 return ((meth->compute_key)(key, pub_key, dh));
981 }
982
983 keylen = BN_num_bits(dh->p);
984
985 memset(&kop, 0, sizeof kop);
986 kop.crk_op = CRK_DH_COMPUTE_KEY;
987
988 /* inputs: dh->priv_key pub_key dh->p key */
989 if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
990 goto err;
991 if (bn2crparam(pub_key, &kop.crk_param[1]))
992 goto err;
993 if (bn2crparam(dh->p, &kop.crk_param[2]))
994 goto err;
995 kop.crk_iparams = 3;
996
997 kop.crk_param[3].crp_p = key;
998 kop.crk_param[3].crp_nbits = keylen * 8;
999 kop.crk_oparams = 1;
1000
1001 if (ioctl(fd, CIOCKEY, &kop) == -1) {
1002 const DH_METHOD *meth = DH_OpenSSL();
1003
1004 dhret = (meth->compute_key)(key, pub_key, dh);
1005 }
1006err:
1007 kop.crk_param[3].crp_p = NULL;
1008 zapparams(&kop);
1009 return (dhret);
1010}
1011
1012static DH_METHOD cryptodev_dh = {
1013 "cryptodev DH method",
1014 NULL, /* cryptodev_dh_generate_key */
1015 NULL,
1016 NULL,
1017 NULL,
1018 NULL,
1019 0, /* flags */
1020 NULL /* app_data */
1021};
1022
1023/*
1024 * ctrl right now is just a wrapper that doesn't do much
1025 * but I expect we'll want some options soon.
1026 */
1027static int
1028cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
1029{
1030#ifdef HAVE_SYSLOG_R
1031 struct syslog_data sd = SYSLOG_DATA_INIT;
1032#endif
1033
1034 switch (cmd) {
1035 default:
1036#ifdef HAVE_SYSLOG_R
1037 syslog_r(LOG_ERR, &sd,
1038 "cryptodev_ctrl: unknown command %d", cmd);
1039#else
1040 syslog(LOG_ERR, "cryptodev_ctrl: unknown command %d", cmd);
1041#endif
1042 break;
1043 }
1044 return (1);
1045}
1046
1047void
1048ENGINE_load_cryptodev(void)
1049{
1050 ENGINE *engine = ENGINE_new();
1051 int fd;
1052
1053 if (engine == NULL)
1054 return;
1055 if ((fd = get_dev_crypto()) < 0) {
1056 ENGINE_free(engine);
1057 return;
1058 }
1059
1060 /*
1061 * find out what asymmetric crypto algorithms we support
1062 */
1063 if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) {
1064 close(fd);
1065 ENGINE_free(engine);
1066 return;
1067 }
1068 close(fd);
1069
1070 if (!ENGINE_set_id(engine, "cryptodev") ||
1071 !ENGINE_set_name(engine, "BSD cryptodev engine") ||
1072 !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) ||
1073 !ENGINE_set_digests(engine, cryptodev_engine_digests) ||
1074 !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) ||
1075 !ENGINE_set_cmd_defns(engine, cryptodev_defns)) {
1076 ENGINE_free(engine);
1077 return;
1078 }
1079
1080 if (ENGINE_set_RSA(engine, &cryptodev_rsa)) {
1081 const RSA_METHOD *rsa_meth = RSA_PKCS1_SSLeay();
1082
1083 cryptodev_rsa.bn_mod_exp = rsa_meth->bn_mod_exp;
1084 cryptodev_rsa.rsa_mod_exp = rsa_meth->rsa_mod_exp;
1085 cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc;
1086 cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec;
1087 cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_enc;
1088 cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec;
1089 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1090 cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp;
1091 if (cryptodev_asymfeat & CRF_MOD_EXP_CRT)
1092 cryptodev_rsa.rsa_mod_exp =
1093 cryptodev_rsa_mod_exp;
1094 else
1095 cryptodev_rsa.rsa_mod_exp =
1096 cryptodev_rsa_nocrt_mod_exp;
1097 }
1098 }
1099
1100 if (ENGINE_set_DSA(engine, &cryptodev_dsa)) {
1101 const DSA_METHOD *meth = DSA_OpenSSL();
1102
1103 memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD));
1104 if (cryptodev_asymfeat & CRF_DSA_SIGN)
1105 cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign;
1106 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1107 cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp;
1108 cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp;
1109 }
1110 if (cryptodev_asymfeat & CRF_DSA_VERIFY)
1111 cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify;
1112 }
1113
1114 if (ENGINE_set_DH(engine, &cryptodev_dh)){
1115 const DH_METHOD *dh_meth = DH_OpenSSL();
1116
1117 cryptodev_dh.generate_key = dh_meth->generate_key;
1118 cryptodev_dh.compute_key = dh_meth->compute_key;
1119 cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp;
1120 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1121 cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh;
1122 if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY)
1123 cryptodev_dh.compute_key =
1124 cryptodev_dh_compute_key;
1125 }
1126 }
1127
1128 ENGINE_add(engine);
1129 ENGINE_free(engine);
1130 ERR_clear_error();
1131}
1132
1133#endif /* HAVE_CRYPTODEV */
diff --git a/src/lib/libcrypto/engine/eng_ctrl.c b/src/lib/libcrypto/engine/eng_ctrl.c
index 95b6b455aa..412c73fb0f 100644
--- a/src/lib/libcrypto/engine/eng_ctrl.c
+++ b/src/lib/libcrypto/engine/eng_ctrl.c
@@ -53,7 +53,10 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
56#include "eng_int.h" 58#include "eng_int.h"
59#include <openssl/engine.h>
57 60
58/* When querying a ENGINE-specific control command's 'description', this string 61/* When querying a ENGINE-specific control command's 'description', this string
59 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */ 62 * is used if the ENGINE_CMD_DEFN has cmd_desc set to NULL. */
@@ -100,8 +103,7 @@ static int int_ctrl_cmd_by_num(const ENGINE_CMD_DEFN *defn, unsigned int num)
100 return -1; 103 return -1;
101 } 104 }
102 105
103static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, 106static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p, void (*f)())
104 void (*f)(void))
105 { 107 {
106 int idx; 108 int idx;
107 char *s = (char *)p; 109 char *s = (char *)p;
@@ -179,7 +181,7 @@ static int int_ctrl_helper(ENGINE *e, int cmd, long i, void *p,
179 return -1; 181 return -1;
180 } 182 }
181 183
182int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) 184int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
183 { 185 {
184 int ctrl_exists, ref_exists; 186 int ctrl_exists, ref_exists;
185 if(e == NULL) 187 if(e == NULL)
@@ -249,13 +251,13 @@ int ENGINE_cmd_is_executable(ENGINE *e, int cmd)
249 } 251 }
250 252
251int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 253int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
252 long i, void *p, void (*f)(void), int cmd_optional) 254 long i, void *p, void (*f)(), int cmd_optional)
253 { 255 {
254 int num; 256 int num;
255 257
256 if((e == NULL) || (cmd_name == NULL)) 258 if((e == NULL) || (cmd_name == NULL))
257 { 259 {
258 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD, 260 ENGINEerr(ENGINE_F_ENGINE_CTRL_CMD_STRING,
259 ERR_R_PASSED_NULL_PARAMETER); 261 ERR_R_PASSED_NULL_PARAMETER);
260 return 0; 262 return 0;
261 } 263 }
diff --git a/src/lib/libcrypto/engine/eng_dyn.c b/src/lib/libcrypto/engine/eng_dyn.c
index acb30c34d8..4139a16e76 100644
--- a/src/lib/libcrypto/engine/eng_dyn.c
+++ b/src/lib/libcrypto/engine/eng_dyn.c
@@ -57,7 +57,11 @@
57 */ 57 */
58 58
59 59
60#include <stdio.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
60#include "eng_int.h" 63#include "eng_int.h"
64#include <openssl/engine.h>
61#include <openssl/dso.h> 65#include <openssl/dso.h>
62 66
63/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader 67/* Shared libraries implementing ENGINEs for use by the "dynamic" ENGINE loader
@@ -66,7 +70,7 @@
66/* Our ENGINE handlers */ 70/* Our ENGINE handlers */
67static int dynamic_init(ENGINE *e); 71static int dynamic_init(ENGINE *e);
68static int dynamic_finish(ENGINE *e); 72static int dynamic_finish(ENGINE *e);
69static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); 73static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
70/* Predeclare our context type */ 74/* Predeclare our context type */
71typedef struct st_dynamic_data_ctx dynamic_data_ctx; 75typedef struct st_dynamic_data_ctx dynamic_data_ctx;
72/* The implementation for the important control command */ 76/* The implementation for the important control command */
@@ -76,9 +80,7 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx);
76#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1) 80#define DYNAMIC_CMD_NO_VCHECK (ENGINE_CMD_BASE + 1)
77#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2) 81#define DYNAMIC_CMD_ID (ENGINE_CMD_BASE + 2)
78#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3) 82#define DYNAMIC_CMD_LIST_ADD (ENGINE_CMD_BASE + 3)
79#define DYNAMIC_CMD_DIR_LOAD (ENGINE_CMD_BASE + 4) 83#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 4)
80#define DYNAMIC_CMD_DIR_ADD (ENGINE_CMD_BASE + 5)
81#define DYNAMIC_CMD_LOAD (ENGINE_CMD_BASE + 6)
82 84
83/* The constants used when creating the ENGINE */ 85/* The constants used when creating the ENGINE */
84static const char *engine_dynamic_id = "dynamic"; 86static const char *engine_dynamic_id = "dynamic";
@@ -100,14 +102,6 @@ static const ENGINE_CMD_DEFN dynamic_cmd_defns[] = {
100 "LIST_ADD", 102 "LIST_ADD",
101 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)", 103 "Whether to add a loaded ENGINE to the internal list (0=no,1=yes,2=mandatory)",
102 ENGINE_CMD_FLAG_NUMERIC}, 104 ENGINE_CMD_FLAG_NUMERIC},
103 {DYNAMIC_CMD_DIR_LOAD,
104 "DIR_LOAD",
105 "Specifies whether to load from 'DIR_ADD' directories (0=no,1=yes,2=mandatory)",
106 ENGINE_CMD_FLAG_NUMERIC},
107 {DYNAMIC_CMD_DIR_ADD,
108 "DIR_ADD",
109 "Adds a directory from which ENGINEs can be loaded",
110 ENGINE_CMD_FLAG_STRING},
111 {DYNAMIC_CMD_LOAD, 105 {DYNAMIC_CMD_LOAD,
112 "LOAD", 106 "LOAD",
113 "Load up the ENGINE specified by other settings", 107 "Load up the ENGINE specified by other settings",
@@ -142,18 +136,12 @@ struct st_dynamic_data_ctx
142 const char *DYNAMIC_F1; 136 const char *DYNAMIC_F1;
143 /* The symbol name for the "initialise ENGINE structure" function */ 137 /* The symbol name for the "initialise ENGINE structure" function */
144 const char *DYNAMIC_F2; 138 const char *DYNAMIC_F2;
145 /* Whether to never use 'dirs', use 'dirs' as a fallback, or only use
146 * 'dirs' for loading. Default is to use 'dirs' as a fallback. */
147 int dir_load;
148 /* A stack of directories from which ENGINEs could be loaded */
149 STACK *dirs;
150 }; 139 };
151 140
152/* This is the "ex_data" index we obtain and reserve for use with our context 141/* This is the "ex_data" index we obtain and reserve for use with our context
153 * structure. */ 142 * structure. */
154static int dynamic_ex_data_idx = -1; 143static int dynamic_ex_data_idx = -1;
155 144
156static void int_free_str(void *s) { OPENSSL_free(s); }
157/* Because our ex_data element may or may not get allocated depending on whether 145/* Because our ex_data element may or may not get allocated depending on whether
158 * a "first-use" occurs before the ENGINE is freed, we have a memory leak 146 * a "first-use" occurs before the ENGINE is freed, we have a memory leak
159 * problem to solve. We can't declare a "new" handler for the ex_data as we 147 * problem to solve. We can't declare a "new" handler for the ex_data as we
@@ -173,8 +161,6 @@ static void dynamic_data_ctx_free_func(void *parent, void *ptr,
173 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME); 161 OPENSSL_free((void*)ctx->DYNAMIC_LIBNAME);
174 if(ctx->engine_id) 162 if(ctx->engine_id)
175 OPENSSL_free((void*)ctx->engine_id); 163 OPENSSL_free((void*)ctx->engine_id);
176 if(ctx->dirs)
177 sk_pop_free(ctx->dirs, int_free_str);
178 OPENSSL_free(ctx); 164 OPENSSL_free(ctx);
179 } 165 }
180 } 166 }
@@ -189,7 +175,7 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
189 c = OPENSSL_malloc(sizeof(dynamic_data_ctx)); 175 c = OPENSSL_malloc(sizeof(dynamic_data_ctx));
190 if(!c) 176 if(!c)
191 { 177 {
192 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE); 178 ENGINEerr(ENGINE_F_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
193 return 0; 179 return 0;
194 } 180 }
195 memset(c, 0, sizeof(dynamic_data_ctx)); 181 memset(c, 0, sizeof(dynamic_data_ctx));
@@ -202,14 +188,6 @@ static int dynamic_set_data_ctx(ENGINE *e, dynamic_data_ctx **ctx)
202 c->list_add_value = 0; 188 c->list_add_value = 0;
203 c->DYNAMIC_F1 = "v_check"; 189 c->DYNAMIC_F1 = "v_check";
204 c->DYNAMIC_F2 = "bind_engine"; 190 c->DYNAMIC_F2 = "bind_engine";
205 c->dir_load = 1;
206 c->dirs = sk_new_null();
207 if(!c->dirs)
208 {
209 ENGINEerr(ENGINE_F_DYNAMIC_SET_DATA_CTX,ERR_R_MALLOC_FAILURE);
210 OPENSSL_free(c);
211 return 0;
212 }
213 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 191 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
214 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e, 192 if((*ctx = (dynamic_data_ctx *)ENGINE_get_ex_data(e,
215 dynamic_ex_data_idx)) == NULL) 193 dynamic_ex_data_idx)) == NULL)
@@ -312,7 +290,7 @@ static int dynamic_finish(ENGINE *e)
312 return 0; 290 return 0;
313 } 291 }
314 292
315static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)) 293static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
316 { 294 {
317 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e); 295 dynamic_data_ctx *ctx = dynamic_get_data_ctx(e);
318 int initialised; 296 int initialised;
@@ -368,34 +346,6 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
368 return 1; 346 return 1;
369 case DYNAMIC_CMD_LOAD: 347 case DYNAMIC_CMD_LOAD:
370 return dynamic_load(e, ctx); 348 return dynamic_load(e, ctx);
371 case DYNAMIC_CMD_DIR_LOAD:
372 if((i < 0) || (i > 2))
373 {
374 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
375 ENGINE_R_INVALID_ARGUMENT);
376 return 0;
377 }
378 ctx->dir_load = (int)i;
379 return 1;
380 case DYNAMIC_CMD_DIR_ADD:
381 /* a NULL 'p' or a string of zero-length is the same thing */
382 if(!p || (strlen((const char *)p) < 1))
383 {
384 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
385 ENGINE_R_INVALID_ARGUMENT);
386 return 0;
387 }
388 {
389 char *tmp_str = BUF_strdup(p);
390 if(!tmp_str)
391 {
392 ENGINEerr(ENGINE_F_DYNAMIC_CTRL,
393 ERR_R_MALLOC_FAILURE);
394 return 0;
395 }
396 sk_insert(ctx->dirs, tmp_str, -1);
397 }
398 return 1;
399 default: 349 default:
400 break; 350 break;
401 } 351 }
@@ -403,53 +353,16 @@ static int dynamic_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void))
403 return 0; 353 return 0;
404 } 354 }
405 355
406static int int_load(dynamic_data_ctx *ctx)
407 {
408 int num, loop;
409 /* Unless told not to, try a direct load */
410 if((ctx->dir_load != 2) && (DSO_load(ctx->dynamic_dso,
411 ctx->DYNAMIC_LIBNAME, NULL, 0)) != NULL)
412 return 1;
413 /* If we're not allowed to use 'dirs' or we have none, fail */
414 if(!ctx->dir_load || ((num = sk_num(ctx->dirs)) < 1))
415 return 0;
416 for(loop = 0; loop < num; loop++)
417 {
418 const char *s = sk_value(ctx->dirs, loop);
419 char *merge = DSO_merge(ctx->dynamic_dso, ctx->DYNAMIC_LIBNAME, s);
420 if(!merge)
421 return 0;
422 if(DSO_load(ctx->dynamic_dso, merge, NULL, 0))
423 {
424 /* Found what we're looking for */
425 OPENSSL_free(merge);
426 return 1;
427 }
428 OPENSSL_free(merge);
429 }
430 return 0;
431 }
432
433static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx) 356static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
434 { 357 {
435 ENGINE cpy; 358 ENGINE cpy;
436 dynamic_fns fns; 359 dynamic_fns fns;
437 360
438 if(!ctx->dynamic_dso) 361 if(!ctx->DYNAMIC_LIBNAME || ((ctx->dynamic_dso = DSO_load(NULL,
439 ctx->dynamic_dso = DSO_new(); 362 ctx->DYNAMIC_LIBNAME, NULL, 0)) == NULL))
440 if(!ctx->DYNAMIC_LIBNAME)
441 {
442 if(!ctx->engine_id)
443 return 0;
444 ctx->DYNAMIC_LIBNAME =
445 DSO_convert_filename(ctx->dynamic_dso, ctx->engine_id);
446 }
447 if(!int_load(ctx))
448 { 363 {
449 ENGINEerr(ENGINE_F_DYNAMIC_LOAD, 364 ENGINEerr(ENGINE_F_DYNAMIC_LOAD,
450 ENGINE_R_DSO_NOT_FOUND); 365 ENGINE_R_DSO_NOT_FOUND);
451 DSO_free(ctx->dynamic_dso);
452 ctx->dynamic_dso = NULL;
453 return 0; 366 return 0;
454 } 367 }
455 /* We have to find a bind function otherwise it'll always end badly */ 368 /* We have to find a bind function otherwise it'll always end badly */
@@ -496,7 +409,6 @@ static int dynamic_load(ENGINE *e, dynamic_data_ctx *ctx)
496 * engine.h, much of this would be simplified if each area of code 409 * engine.h, much of this would be simplified if each area of code
497 * provided its own "summary" structure of all related callbacks. It 410 * provided its own "summary" structure of all related callbacks. It
498 * would also increase opaqueness. */ 411 * would also increase opaqueness. */
499 fns.static_state = ENGINE_get_static_state();
500 fns.err_fns = ERR_get_implementation(); 412 fns.err_fns = ERR_get_implementation();
501 fns.ex_data_fns = CRYPTO_get_ex_data_implementation(); 413 fns.ex_data_fns = CRYPTO_get_ex_data_implementation();
502 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb, 414 CRYPTO_get_mem_functions(&fns.mem_fns.malloc_cb,
diff --git a/src/lib/libcrypto/engine/eng_err.c b/src/lib/libcrypto/engine/eng_err.c
index 369f2e22d3..fdc0e7be0f 100644
--- a/src/lib/libcrypto/engine/eng_err.c
+++ b/src/lib/libcrypto/engine/eng_err.c
@@ -73,7 +73,6 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"}, 73{ERR_FUNC(ENGINE_F_DYNAMIC_CTRL), "DYNAMIC_CTRL"},
74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"}, 74{ERR_FUNC(ENGINE_F_DYNAMIC_GET_DATA_CTX), "DYNAMIC_GET_DATA_CTX"},
75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"}, 75{ERR_FUNC(ENGINE_F_DYNAMIC_LOAD), "DYNAMIC_LOAD"},
76{ERR_FUNC(ENGINE_F_DYNAMIC_SET_DATA_CTX), "DYNAMIC_SET_DATA_CTX"},
77{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"}, 76{ERR_FUNC(ENGINE_F_ENGINE_ADD), "ENGINE_add"},
78{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"}, 77{ERR_FUNC(ENGINE_F_ENGINE_BY_ID), "ENGINE_by_id"},
79{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"}, 78{ERR_FUNC(ENGINE_F_ENGINE_CMD_IS_EXECUTABLE), "ENGINE_cmd_is_executable"},
@@ -81,7 +80,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"}, 80{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD), "ENGINE_ctrl_cmd"},
82{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"}, 81{ERR_FUNC(ENGINE_F_ENGINE_CTRL_CMD_STRING), "ENGINE_ctrl_cmd_string"},
83{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"}, 82{ERR_FUNC(ENGINE_F_ENGINE_FINISH), "ENGINE_finish"},
84{ERR_FUNC(ENGINE_F_ENGINE_FREE_UTIL), "ENGINE_FREE_UTIL"}, 83{ERR_FUNC(ENGINE_F_ENGINE_FREE), "ENGINE_free"},
85{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"}, 84{ERR_FUNC(ENGINE_F_ENGINE_GET_CIPHER), "ENGINE_get_cipher"},
86{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"}, 85{ERR_FUNC(ENGINE_F_ENGINE_GET_DEFAULT_TYPE), "ENGINE_GET_DEFAULT_TYPE"},
87{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"}, 86{ERR_FUNC(ENGINE_F_ENGINE_GET_DIGEST), "ENGINE_get_digest"},
@@ -92,6 +91,7 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
92{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"}, 91{ERR_FUNC(ENGINE_F_ENGINE_LIST_REMOVE), "ENGINE_LIST_REMOVE"},
93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"}, 92{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PRIVATE_KEY), "ENGINE_load_private_key"},
94{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"}, 93{ERR_FUNC(ENGINE_F_ENGINE_LOAD_PUBLIC_KEY), "ENGINE_load_public_key"},
94{ERR_FUNC(ENGINE_F_ENGINE_MODULE_INIT), "ENGINE_MODULE_INIT"},
95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"}, 95{ERR_FUNC(ENGINE_F_ENGINE_NEW), "ENGINE_new"},
96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"}, 96{ERR_FUNC(ENGINE_F_ENGINE_REMOVE), "ENGINE_remove"},
97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"}, 97{ERR_FUNC(ENGINE_F_ENGINE_SET_DEFAULT_STRING), "ENGINE_set_default_string"},
@@ -100,12 +100,11 @@ static ERR_STRING_DATA ENGINE_str_functs[]=
100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"}, 100{ERR_FUNC(ENGINE_F_ENGINE_SET_NAME), "ENGINE_set_name"},
101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"}, 101{ERR_FUNC(ENGINE_F_ENGINE_TABLE_REGISTER), "ENGINE_TABLE_REGISTER"},
102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"}, 102{ERR_FUNC(ENGINE_F_ENGINE_UNLOAD_KEY), "ENGINE_UNLOAD_KEY"},
103{ERR_FUNC(ENGINE_F_ENGINE_UNLOCKED_FINISH), "ENGINE_UNLOCKED_FINISH"},
104{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"}, 103{ERR_FUNC(ENGINE_F_ENGINE_UP_REF), "ENGINE_up_ref"},
105{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"}, 104{ERR_FUNC(ENGINE_F_INT_CTRL_HELPER), "INT_CTRL_HELPER"},
106{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"}, 105{ERR_FUNC(ENGINE_F_INT_ENGINE_CONFIGURE), "INT_ENGINE_CONFIGURE"},
107{ERR_FUNC(ENGINE_F_INT_ENGINE_MODULE_INIT), "INT_ENGINE_MODULE_INIT"},
108{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"}, 106{ERR_FUNC(ENGINE_F_LOG_MESSAGE), "LOG_MESSAGE"},
107{ERR_FUNC(ENGINE_F_SET_DATA_CTX), "SET_DATA_CTX"},
109{0,NULL} 108{0,NULL}
110 }; 109 };
111 110
@@ -157,12 +156,15 @@ static ERR_STRING_DATA ENGINE_str_reasons[]=
157 156
158void ERR_load_ENGINE_strings(void) 157void ERR_load_ENGINE_strings(void)
159 { 158 {
160#ifndef OPENSSL_NO_ERR 159 static int init=1;
161 160
162 if (ERR_func_error_string(ENGINE_str_functs[0].error) == NULL) 161 if (init)
163 { 162 {
163 init=0;
164#ifndef OPENSSL_NO_ERR
164 ERR_load_strings(0,ENGINE_str_functs); 165 ERR_load_strings(0,ENGINE_str_functs);
165 ERR_load_strings(0,ENGINE_str_reasons); 166 ERR_load_strings(0,ENGINE_str_reasons);
166 }
167#endif 167#endif
168
169 }
168 } 170 }
diff --git a/src/lib/libcrypto/engine/eng_fat.c b/src/lib/libcrypto/engine/eng_fat.c
index 27c1662f62..7ccf7022ee 100644
--- a/src/lib/libcrypto/engine/eng_fat.c
+++ b/src/lib/libcrypto/engine/eng_fat.c
@@ -52,13 +52,11 @@
52 * Hudson (tjh@cryptsoft.com). 52 * Hudson (tjh@cryptsoft.com).
53 * 53 *
54 */ 54 */
55/* ====================================================================
56 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
57 * ECDH support in OpenSSL originally developed by
58 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
59 */
60 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
61#include "eng_int.h" 58#include "eng_int.h"
59#include <openssl/engine.h>
62#include <openssl/conf.h> 60#include <openssl/conf.h>
63 61
64int ENGINE_set_default(ENGINE *e, unsigned int flags) 62int ENGINE_set_default(ENGINE *e, unsigned int flags)
@@ -79,14 +77,6 @@ int ENGINE_set_default(ENGINE *e, unsigned int flags)
79 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e)) 77 if((flags & ENGINE_METHOD_DH) && !ENGINE_set_default_DH(e))
80 return 0; 78 return 0;
81#endif 79#endif
82#ifndef OPENSSL_NO_ECDH
83 if((flags & ENGINE_METHOD_ECDH) && !ENGINE_set_default_ECDH(e))
84 return 0;
85#endif
86#ifndef OPENSSL_NO_ECDSA
87 if((flags & ENGINE_METHOD_ECDSA) && !ENGINE_set_default_ECDSA(e))
88 return 0;
89#endif
90 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e)) 80 if((flags & ENGINE_METHOD_RAND) && !ENGINE_set_default_RAND(e))
91 return 0; 81 return 0;
92 return 1; 82 return 1;
@@ -103,10 +93,6 @@ static int int_def_cb(const char *alg, int len, void *arg)
103 *pflags |= ENGINE_METHOD_RSA; 93 *pflags |= ENGINE_METHOD_RSA;
104 else if (!strncmp(alg, "DSA", len)) 94 else if (!strncmp(alg, "DSA", len))
105 *pflags |= ENGINE_METHOD_DSA; 95 *pflags |= ENGINE_METHOD_DSA;
106 else if (!strncmp(alg, "ECDH", len))
107 *pflags |= ENGINE_METHOD_ECDH;
108 else if (!strncmp(alg, "ECDSA", len))
109 *pflags |= ENGINE_METHOD_ECDSA;
110 else if (!strncmp(alg, "DH", len)) 96 else if (!strncmp(alg, "DH", len))
111 *pflags |= ENGINE_METHOD_DH; 97 *pflags |= ENGINE_METHOD_DH;
112 else if (!strncmp(alg, "RAND", len)) 98 else if (!strncmp(alg, "RAND", len))
@@ -147,12 +133,6 @@ int ENGINE_register_complete(ENGINE *e)
147#ifndef OPENSSL_NO_DH 133#ifndef OPENSSL_NO_DH
148 ENGINE_register_DH(e); 134 ENGINE_register_DH(e);
149#endif 135#endif
150#ifndef OPENSSL_NO_ECDH
151 ENGINE_register_ECDH(e);
152#endif
153#ifndef OPENSSL_NO_ECDSA
154 ENGINE_register_ECDSA(e);
155#endif
156 ENGINE_register_RAND(e); 136 ENGINE_register_RAND(e);
157 return 1; 137 return 1;
158 } 138 }
diff --git a/src/lib/libcrypto/engine/eng_init.c b/src/lib/libcrypto/engine/eng_init.c
index 7633cf5f1d..170c1791b3 100644
--- a/src/lib/libcrypto/engine/eng_init.c
+++ b/src/lib/libcrypto/engine/eng_init.c
@@ -53,7 +53,10 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
56#include "eng_int.h" 58#include "eng_int.h"
59#include <openssl/engine.h>
57 60
58/* Initialise a engine type for use (or up its functional reference count 61/* Initialise a engine type for use (or up its functional reference count
59 * if it's already in use). This version is only used internally. */ 62 * if it's already in use). This version is only used internally. */
@@ -111,7 +114,7 @@ int engine_unlocked_finish(ENGINE *e, int unlock_for_handlers)
111 /* Release the structural reference too */ 114 /* Release the structural reference too */
112 if(!engine_free_util(e, 0)) 115 if(!engine_free_util(e, 0))
113 { 116 {
114 ENGINEerr(ENGINE_F_ENGINE_UNLOCKED_FINISH,ENGINE_R_FINISH_FAILED); 117 ENGINEerr(ENGINE_F_ENGINE_FINISH,ENGINE_R_FINISH_FAILED);
115 return 0; 118 return 0;
116 } 119 }
117 return to_return; 120 return to_return;
diff --git a/src/lib/libcrypto/engine/eng_int.h b/src/lib/libcrypto/engine/eng_int.h
index a5b1edebf4..38335f99cd 100644
--- a/src/lib/libcrypto/engine/eng_int.h
+++ b/src/lib/libcrypto/engine/eng_int.h
@@ -55,16 +55,10 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
64#ifndef HEADER_ENGINE_INT_H 59#ifndef HEADER_ENGINE_INT_H
65#define HEADER_ENGINE_INT_H 60#define HEADER_ENGINE_INT_H
66 61
67#include "cryptlib.h"
68/* Take public definitions from engine.h */ 62/* Take public definitions from engine.h */
69#include <openssl/engine.h> 63#include <openssl/engine.h>
70 64
@@ -152,10 +146,7 @@ struct engine_st
152 const RSA_METHOD *rsa_meth; 146 const RSA_METHOD *rsa_meth;
153 const DSA_METHOD *dsa_meth; 147 const DSA_METHOD *dsa_meth;
154 const DH_METHOD *dh_meth; 148 const DH_METHOD *dh_meth;
155 const ECDH_METHOD *ecdh_meth;
156 const ECDSA_METHOD *ecdsa_meth;
157 const RAND_METHOD *rand_meth; 149 const RAND_METHOD *rand_meth;
158 const STORE_METHOD *store_meth;
159 /* Cipher handling is via this callback */ 150 /* Cipher handling is via this callback */
160 ENGINE_CIPHERS_PTR ciphers; 151 ENGINE_CIPHERS_PTR ciphers;
161 /* Digest handling is via this callback */ 152 /* Digest handling is via this callback */
diff --git a/src/lib/libcrypto/engine/eng_lib.c b/src/lib/libcrypto/engine/eng_lib.c
index 5815b867f4..a66d0f08af 100644
--- a/src/lib/libcrypto/engine/eng_lib.c
+++ b/src/lib/libcrypto/engine/eng_lib.c
@@ -56,8 +56,11 @@
56 * 56 *
57 */ 57 */
58 58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
59#include "eng_int.h" 61#include "eng_int.h"
60#include <openssl/rand.h> 62#include <openssl/rand.h> /* FIXME: This shouldn't be needed */
63#include <openssl/engine.h>
61 64
62/* The "new"/"free" stuff first */ 65/* The "new"/"free" stuff first */
63 66
@@ -89,7 +92,6 @@ void engine_set_all_null(ENGINE *e)
89 e->dsa_meth = NULL; 92 e->dsa_meth = NULL;
90 e->dh_meth = NULL; 93 e->dh_meth = NULL;
91 e->rand_meth = NULL; 94 e->rand_meth = NULL;
92 e->store_meth = NULL;
93 e->ciphers = NULL; 95 e->ciphers = NULL;
94 e->digests = NULL; 96 e->digests = NULL;
95 e->destroy = NULL; 97 e->destroy = NULL;
@@ -108,7 +110,7 @@ int engine_free_util(ENGINE *e, int locked)
108 110
109 if(e == NULL) 111 if(e == NULL)
110 { 112 {
111 ENGINEerr(ENGINE_F_ENGINE_FREE_UTIL, 113 ENGINEerr(ENGINE_F_ENGINE_FREE,
112 ERR_R_PASSED_NULL_PARAMETER); 114 ERR_R_PASSED_NULL_PARAMETER);
113 return 0; 115 return 0;
114 } 116 }
@@ -317,13 +319,3 @@ const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e)
317 { 319 {
318 return e->cmd_defns; 320 return e->cmd_defns;
319 } 321 }
320
321/* eng_lib.o is pretty much linked into anything that touches ENGINE already, so
322 * put the "static_state" hack here. */
323
324static int internal_static_hack = 0;
325
326void *ENGINE_get_static_state(void)
327 {
328 return &internal_static_hack;
329 }
diff --git a/src/lib/libcrypto/engine/eng_list.c b/src/lib/libcrypto/engine/eng_list.c
index bd511944ba..1cc3217f4c 100644
--- a/src/lib/libcrypto/engine/eng_list.c
+++ b/src/lib/libcrypto/engine/eng_list.c
@@ -55,13 +55,11 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
59#include <openssl/crypto.h>
60#include "cryptlib.h"
64#include "eng_int.h" 61#include "eng_int.h"
62#include <openssl/engine.h>
65 63
66/* The linked-list of pointers to engine types. engine_list_head 64/* The linked-list of pointers to engine types. engine_list_head
67 * incorporates an implicit structural reference but engine_list_tail 65 * incorporates an implicit structural reference but engine_list_tail
@@ -326,14 +324,7 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
326#ifndef OPENSSL_NO_DH 324#ifndef OPENSSL_NO_DH
327 dest->dh_meth = src->dh_meth; 325 dest->dh_meth = src->dh_meth;
328#endif 326#endif
329#ifndef OPENSSL_NO_ECDH
330 dest->ecdh_meth = src->ecdh_meth;
331#endif
332#ifndef OPENSSL_NO_ECDSA
333 dest->ecdsa_meth = src->ecdsa_meth;
334#endif
335 dest->rand_meth = src->rand_meth; 327 dest->rand_meth = src->rand_meth;
336 dest->store_meth = src->store_meth;
337 dest->ciphers = src->ciphers; 328 dest->ciphers = src->ciphers;
338 dest->digests = src->digests; 329 dest->digests = src->digests;
339 dest->destroy = src->destroy; 330 dest->destroy = src->destroy;
@@ -349,7 +340,6 @@ static void engine_cpy(ENGINE *dest, const ENGINE *src)
349ENGINE *ENGINE_by_id(const char *id) 340ENGINE *ENGINE_by_id(const char *id)
350 { 341 {
351 ENGINE *iterator; 342 ENGINE *iterator;
352 char *load_dir = NULL;
353 if(id == NULL) 343 if(id == NULL)
354 { 344 {
355 ENGINEerr(ENGINE_F_ENGINE_BY_ID, 345 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -383,7 +373,6 @@ ENGINE *ENGINE_by_id(const char *id)
383 } 373 }
384 } 374 }
385 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 375 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
386#if 0
387 if(iterator == NULL) 376 if(iterator == NULL)
388 { 377 {
389 ENGINEerr(ENGINE_F_ENGINE_BY_ID, 378 ENGINEerr(ENGINE_F_ENGINE_BY_ID,
@@ -391,32 +380,6 @@ ENGINE *ENGINE_by_id(const char *id)
391 ERR_add_error_data(2, "id=", id); 380 ERR_add_error_data(2, "id=", id);
392 } 381 }
393 return iterator; 382 return iterator;
394#else
395 /* EEK! Experimental code starts */
396 if(iterator) return iterator;
397 /* Prevent infinite recusrion if we're looking for the dynamic engine. */
398 if (strcmp(id, "dynamic"))
399 {
400#ifdef OPENSSL_SYS_VMS
401 if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = "SSLROOT:[ENGINES]";
402#else
403 if((load_dir = getenv("OPENSSL_ENGINES")) == 0) load_dir = ENGINESDIR;
404#endif
405 iterator = ENGINE_by_id("dynamic");
406 if(!iterator || !ENGINE_ctrl_cmd_string(iterator, "ID", id, 0) ||
407 !ENGINE_ctrl_cmd_string(iterator, "DIR_LOAD", "2", 0) ||
408 !ENGINE_ctrl_cmd_string(iterator, "DIR_ADD",
409 load_dir, 0) ||
410 !ENGINE_ctrl_cmd_string(iterator, "LOAD", NULL, 0))
411 goto notfound;
412 return iterator;
413 }
414notfound:
415 ENGINEerr(ENGINE_F_ENGINE_BY_ID,ENGINE_R_NO_SUCH_ENGINE);
416 ERR_add_error_data(2, "id=", id);
417 return NULL;
418 /* EEK! Experimental code ends */
419#endif
420 } 383 }
421 384
422int ENGINE_up_ref(ENGINE *e) 385int ENGINE_up_ref(ENGINE *e)
diff --git a/src/lib/libcrypto/engine/eng_openssl.c b/src/lib/libcrypto/engine/eng_openssl.c
index 7c139ae2ef..54579eea2e 100644
--- a/src/lib/libcrypto/engine/eng_openssl.c
+++ b/src/lib/libcrypto/engine/eng_openssl.c
@@ -55,11 +55,6 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
64 59
65#include <stdio.h> 60#include <stdio.h>
@@ -69,16 +64,6 @@
69#include <openssl/dso.h> 64#include <openssl/dso.h>
70#include <openssl/pem.h> 65#include <openssl/pem.h>
71#include <openssl/evp.h> 66#include <openssl/evp.h>
72#include <openssl/rand.h>
73#ifndef OPENSSL_NO_RSA
74#include <openssl/rsa.h>
75#endif
76#ifndef OPENSSL_NO_DSA
77#include <openssl/dsa.h>
78#endif
79#ifndef OPENSSL_NO_DH
80#include <openssl/dh.h>
81#endif
82 67
83/* This testing gunk is implemented (and explained) lower down. It also assumes 68/* This testing gunk is implemented (and explained) lower down. It also assumes
84 * the application explicitly calls "ENGINE_load_openssl()" because this is no 69 * the application explicitly calls "ENGINE_load_openssl()" because this is no
@@ -140,12 +125,6 @@ static int bind_helper(ENGINE *e)
140#ifndef OPENSSL_NO_DSA 125#ifndef OPENSSL_NO_DSA
141 || !ENGINE_set_DSA(e, DSA_get_default_method()) 126 || !ENGINE_set_DSA(e, DSA_get_default_method())
142#endif 127#endif
143#ifndef OPENSSL_NO_ECDH
144 || !ENGINE_set_ECDH(e, ECDH_OpenSSL())
145#endif
146#ifndef OPENSSL_NO_ECDSA
147 || !ENGINE_set_ECDSA(e, ECDSA_OpenSSL())
148#endif
149#ifndef OPENSSL_NO_DH 128#ifndef OPENSSL_NO_DH
150 || !ENGINE_set_DH(e, DH_get_default_method()) 129 || !ENGINE_set_DH(e, DH_get_default_method())
151#endif 130#endif
@@ -257,7 +236,6 @@ static const EVP_CIPHER test_r4_cipher=
257 sizeof(TEST_RC4_KEY), 236 sizeof(TEST_RC4_KEY),
258 NULL, 237 NULL,
259 NULL, 238 NULL,
260 NULL,
261 NULL 239 NULL
262 }; 240 };
263static const EVP_CIPHER test_r4_40_cipher= 241static const EVP_CIPHER test_r4_40_cipher=
@@ -271,7 +249,6 @@ static const EVP_CIPHER test_r4_40_cipher=
271 sizeof(TEST_RC4_KEY), 249 sizeof(TEST_RC4_KEY),
272 NULL, 250 NULL,
273 NULL, 251 NULL,
274 NULL,
275 NULL 252 NULL
276 }; 253 };
277static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher, 254static int openssl_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
@@ -313,7 +290,7 @@ static int test_sha1_init(EVP_MD_CTX *ctx)
313#endif 290#endif
314 return SHA1_Init(ctx->md_data); 291 return SHA1_Init(ctx->md_data);
315 } 292 }
316static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,size_t count) 293static int test_sha1_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
317 { 294 {
318#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE 295#ifdef TEST_ENG_OPENSSL_SHA_P_UPDATE
319 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n"); 296 fprintf(stderr, "(TEST_ENG_OPENSSL_SHA) test_sha1_update() called\n");
diff --git a/src/lib/libcrypto/engine/eng_pkey.c b/src/lib/libcrypto/engine/eng_pkey.c
index bc8b21abec..8c69171511 100644
--- a/src/lib/libcrypto/engine/eng_pkey.c
+++ b/src/lib/libcrypto/engine/eng_pkey.c
@@ -53,7 +53,10 @@
53 * 53 *
54 */ 54 */
55 55
56#include <openssl/crypto.h>
57#include "cryptlib.h"
56#include "eng_int.h" 58#include "eng_int.h"
59#include <openssl/engine.h>
57 60
58/* Basic get/set stuff */ 61/* Basic get/set stuff */
59 62
diff --git a/src/lib/libcrypto/engine/eng_table.c b/src/lib/libcrypto/engine/eng_table.c
index 8879a267d1..c69a84a8bf 100644
--- a/src/lib/libcrypto/engine/eng_table.c
+++ b/src/lib/libcrypto/engine/eng_table.c
@@ -52,31 +52,49 @@
52 * 52 *
53 */ 53 */
54 54
55#include "cryptlib.h"
56#include <openssl/evp.h> 55#include <openssl/evp.h>
57#include <openssl/lhash.h> 56#include <openssl/engine.h>
58#include "eng_int.h" 57#include "eng_int.h"
59 58
59/* This is the type of item in the 'implementation' table. Each 'nid' hashes to
60 * a (potentially NULL) ENGINE_PILE structure which contains a stack of ENGINE*
61 * pointers. These pointers aren't references, because they're inserted and
62 * removed during ENGINE creation and ENGINE destruction. They point to ENGINEs
63 * that *exist* (ie. have a structural reference count greater than zero) rather
64 * than ENGINEs that are *functional*. Each pointer in those stacks are to
65 * ENGINEs that implements the algorithm corresponding to each 'nid'. */
66
60/* The type of the items in the table */ 67/* The type of the items in the table */
61typedef struct st_engine_pile 68typedef struct st_engine_pile
62 { 69 {
63 /* The 'nid' of this algorithm/mode */ 70 /* The 'nid' of the algorithm/mode this ENGINE_PILE structure represents
71 * */
64 int nid; 72 int nid;
65 /* ENGINEs that implement this algorithm/mode. */ 73 /* A stack of ENGINE pointers for ENGINEs that support this
74 * algorithm/mode. In the event that 'funct' is NULL, the first entry in
75 * this stack that initialises will be set as 'funct' and assumed as the
76 * default for operations of this type. */
66 STACK_OF(ENGINE) *sk; 77 STACK_OF(ENGINE) *sk;
67 /* The default ENGINE to perform this algorithm/mode. */ 78 /* The default ENGINE to perform this algorithm/mode. */
68 ENGINE *funct; 79 ENGINE *funct;
69 /* Zero if 'sk' is newer than the cached 'funct', non-zero otherwise */ 80 /* This value optimises engine_table_select(). If it is called it sets
81 * this value to 1. Any changes to this ENGINE_PILE resets it to zero.
82 * As such, no ENGINE_init() thrashing is done unless ENGINEs
83 * continually register (and/or unregister). */
70 int uptodate; 84 int uptodate;
71 } ENGINE_PILE; 85 } ENGINE_PILE;
72 86
73/* The type exposed in eng_int.h */ 87/* The type of the hash table of ENGINE_PILE structures such that each are
88 * unique and keyed by the 'nid' value. */
74struct st_engine_table 89struct st_engine_table
75 { 90 {
76 LHASH piles; 91 LHASH piles;
77 }; /* ENGINE_TABLE */ 92 }; /* ENGINE_TABLE */
78 93
79/* Global flags (ENGINE_TABLE_FLAG_***). */ 94/* This value stores global options controlling behaviour of (mostly) the
95 * engine_table_select() function. It's a bitmask of flag values of the form
96 * ENGINE_TABLE_FLAG_*** (as defined in engine.h) and is controlled by the
97 * ENGINE_[get|set]_table_flags() function. */
80static unsigned int table_flags = 0; 98static unsigned int table_flags = 0;
81 99
82/* API function manipulating 'table_flags' */ 100/* API function manipulating 'table_flags' */
@@ -103,8 +121,10 @@ static IMPLEMENT_LHASH_COMP_FN(engine_pile_cmp, const ENGINE_PILE *)
103static int int_table_check(ENGINE_TABLE **t, int create) 121static int int_table_check(ENGINE_TABLE **t, int create)
104 { 122 {
105 LHASH *lh; 123 LHASH *lh;
106 if(*t) return 1; 124 if(*t)
107 if(!create) return 0; 125 return 1;
126 if(!create)
127 return 0;
108 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash), 128 if((lh = lh_new(LHASH_HASH_FN(engine_pile_hash),
109 LHASH_COMP_FN(engine_pile_cmp))) == NULL) 129 LHASH_COMP_FN(engine_pile_cmp))) == NULL)
110 return 0; 130 return 0;
@@ -134,7 +154,8 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
134 if(!fnd) 154 if(!fnd)
135 { 155 {
136 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE)); 156 fnd = OPENSSL_malloc(sizeof(ENGINE_PILE));
137 if(!fnd) goto end; 157 if(!fnd)
158 goto end;
138 fnd->uptodate = 1; 159 fnd->uptodate = 1;
139 fnd->nid = *nids; 160 fnd->nid = *nids;
140 fnd->sk = sk_ENGINE_new_null(); 161 fnd->sk = sk_ENGINE_new_null();
@@ -143,11 +164,11 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
143 OPENSSL_free(fnd); 164 OPENSSL_free(fnd);
144 goto end; 165 goto end;
145 } 166 }
146 fnd->funct = NULL; 167 fnd->funct= NULL;
147 lh_insert(&(*table)->piles, fnd); 168 lh_insert(&(*table)->piles, fnd);
148 } 169 }
149 /* A registration shouldn't add duplciate entries */ 170 /* A registration shouldn't add duplciate entries */
150 (void)sk_ENGINE_delete_ptr(fnd->sk, e); 171 sk_ENGINE_delete_ptr(fnd->sk, e);
151 /* if 'setdefault', this ENGINE goes to the head of the list */ 172 /* if 'setdefault', this ENGINE goes to the head of the list */
152 if(!sk_ENGINE_push(fnd->sk, e)) 173 if(!sk_ENGINE_push(fnd->sk, e))
153 goto end; 174 goto end;
@@ -164,7 +185,6 @@ int engine_table_register(ENGINE_TABLE **table, ENGINE_CLEANUP_CB *cleanup,
164 if(fnd->funct) 185 if(fnd->funct)
165 engine_unlocked_finish(fnd->funct, 0); 186 engine_unlocked_finish(fnd->funct, 0);
166 fnd->funct = e; 187 fnd->funct = e;
167 fnd->uptodate = 1;
168 } 188 }
169 nids++; 189 nids++;
170 } 190 }
@@ -179,7 +199,8 @@ static void int_unregister_cb(ENGINE_PILE *pile, ENGINE *e)
179 /* Iterate the 'c->sk' stack removing any occurance of 'e' */ 199 /* Iterate the 'c->sk' stack removing any occurance of 'e' */
180 while((n = sk_ENGINE_find(pile->sk, e)) >= 0) 200 while((n = sk_ENGINE_find(pile->sk, e)) >= 0)
181 { 201 {
182 (void)sk_ENGINE_delete(pile->sk, n); 202 sk_ENGINE_delete(pile->sk, n);
203 /* "touch" this ENGINE_CIPHER */
183 pile->uptodate = 0; 204 pile->uptodate = 0;
184 } 205 }
185 if(pile->funct == e) 206 if(pile->funct == e)
@@ -218,7 +239,9 @@ void engine_table_cleanup(ENGINE_TABLE **table)
218 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE); 239 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
219 } 240 }
220 241
221/* return a functional reference for a given 'nid' */ 242/* Exposed API function to get a functional reference from the implementation
243 * table (ie. try to get a functional reference from the tabled structural
244 * references) for a given cipher 'nid' */
222#ifndef ENGINE_TABLE_DEBUG 245#ifndef ENGINE_TABLE_DEBUG
223ENGINE *engine_table_select(ENGINE_TABLE **table, int nid) 246ENGINE *engine_table_select(ENGINE_TABLE **table, int nid)
224#else 247#else
@@ -229,21 +252,25 @@ ENGINE *engine_table_select_tmp(ENGINE_TABLE **table, int nid, const char *f, in
229 ENGINE_PILE tmplate, *fnd=NULL; 252 ENGINE_PILE tmplate, *fnd=NULL;
230 int initres, loop = 0; 253 int initres, loop = 0;
231 254
255 /* If 'engine_ciphers' is NULL, then it's absolutely *sure* that no
256 * ENGINEs have registered any implementations! */
232 if(!(*table)) 257 if(!(*table))
233 { 258 {
234#ifdef ENGINE_TABLE_DEBUG 259#ifdef ENGINE_TABLE_DEBUG
235 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, nothing " 260 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, no "
236 "registered!\n", f, l, nid); 261 "registered for anything!\n", f, l, nid);
237#endif 262#endif
238 return NULL; 263 return NULL;
239 } 264 }
240 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE); 265 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
241 /* Check again inside the lock otherwise we could race against cleanup 266 /* Check again inside the lock otherwise we could race against cleanup
242 * operations. But don't worry about a fprintf(stderr). */ 267 * operations. But don't worry about a fprintf(stderr). */
243 if(!int_table_check(table, 0)) goto end; 268 if(!int_table_check(table, 0))
269 goto end;
244 tmplate.nid = nid; 270 tmplate.nid = nid;
245 fnd = lh_retrieve(&(*table)->piles, &tmplate); 271 fnd = lh_retrieve(&(*table)->piles, &tmplate);
246 if(!fnd) goto end; 272 if(!fnd)
273 goto end;
247 if(fnd->funct && engine_unlocked_init(fnd->funct)) 274 if(fnd->funct && engine_unlocked_init(fnd->funct))
248 { 275 {
249#ifdef ENGINE_TABLE_DEBUG 276#ifdef ENGINE_TABLE_DEBUG
@@ -269,19 +296,34 @@ trynext:
269#endif 296#endif
270 goto end; 297 goto end;
271 } 298 }
272 /* Try to initialise the ENGINE? */ 299#if 0
300 /* Don't need to get a reference if we hold the lock. If the locking has
301 * to change in future, that would be different ... */
302 ret->struct_ref++; engine_ref_debug(ret, 0, 1)
303#endif
304 /* Try and initialise the ENGINE if it's already functional *or* if the
305 * ENGINE_TABLE_FLAG_NOINIT flag is not set. */
273 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT)) 306 if((ret->funct_ref > 0) || !(table_flags & ENGINE_TABLE_FLAG_NOINIT))
274 initres = engine_unlocked_init(ret); 307 initres = engine_unlocked_init(ret);
275 else 308 else
276 initres = 0; 309 initres = 0;
310#if 0
311 /* Release the structural reference */
312 ret->struct_ref--; engine_ref_debug(ret, 0, -1);
313#endif
277 if(initres) 314 if(initres)
278 { 315 {
279 /* Update 'funct' */ 316 /* If we didn't have a default (functional reference) for this
317 * 'nid' (or we had one but for whatever reason we're now
318 * initialising a different one), use this opportunity to set
319 * 'funct'. */
280 if((fnd->funct != ret) && engine_unlocked_init(ret)) 320 if((fnd->funct != ret) && engine_unlocked_init(ret))
281 { 321 {
282 /* If there was a previous default we release it. */ 322 /* If there was a previous default we release it. */
283 if(fnd->funct) 323 if(fnd->funct)
284 engine_unlocked_finish(fnd->funct, 0); 324 engine_unlocked_finish(fnd->funct, 0);
325 /* We got an extra functional reference for the
326 * per-'nid' default */
285 fnd->funct = ret; 327 fnd->funct = ret;
286#ifdef ENGINE_TABLE_DEBUG 328#ifdef ENGINE_TABLE_DEBUG
287 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, " 329 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, "
@@ -296,9 +338,13 @@ trynext:
296 } 338 }
297 goto trynext; 339 goto trynext;
298end: 340end:
299 /* If it failed, it is unlikely to succeed again until some future 341 /* Whatever happened - we should "untouch" our uptodate file seeing as
300 * registrations have taken place. In all cases, we cache. */ 342 * we have tried our best to find a functional reference for 'nid'. If
301 if(fnd) fnd->uptodate = 1; 343 * it failed, it is unlikely to succeed again until some future
344 * registrations (or unregistrations) have taken place that affect that
345 * 'nid'. */
346 if(fnd)
347 fnd->uptodate = 1;
302#ifdef ENGINE_TABLE_DEBUG 348#ifdef ENGINE_TABLE_DEBUG
303 if(ret) 349 if(ret)
304 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching " 350 fprintf(stderr, "engine_table_dbg: %s:%d, nid=%d, caching "
diff --git a/src/lib/libcrypto/engine/engine.h b/src/lib/libcrypto/engine/engine.h
index 3ec59338ff..900f75ce8d 100644
--- a/src/lib/libcrypto/engine/engine.h
+++ b/src/lib/libcrypto/engine/engine.h
@@ -3,7 +3,7 @@
3 * project 2000. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -55,11 +55,6 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
64#ifndef HEADER_ENGINE_H 59#ifndef HEADER_ENGINE_H
65#define HEADER_ENGINE_H 60#define HEADER_ENGINE_H
@@ -70,7 +65,7 @@
70#error ENGINE is disabled. 65#error ENGINE is disabled.
71#endif 66#endif
72 67
73#ifndef OPENSSL_NO_DEPRECATED 68#include <openssl/ossl_typ.h>
74#include <openssl/bn.h> 69#include <openssl/bn.h>
75#ifndef OPENSSL_NO_RSA 70#ifndef OPENSSL_NO_RSA
76#include <openssl/rsa.h> 71#include <openssl/rsa.h>
@@ -81,36 +76,34 @@
81#ifndef OPENSSL_NO_DH 76#ifndef OPENSSL_NO_DH
82#include <openssl/dh.h> 77#include <openssl/dh.h>
83#endif 78#endif
84#ifndef OPENSSL_NO_ECDH
85#include <openssl/ecdh.h>
86#endif
87#ifndef OPENSSL_NO_ECDSA
88#include <openssl/ecdsa.h>
89#endif
90#include <openssl/rand.h> 79#include <openssl/rand.h>
91#include <openssl/store.h>
92#include <openssl/ui.h> 80#include <openssl/ui.h>
93#include <openssl/err.h>
94#endif
95
96#include <openssl/ossl_typ.h>
97#include <openssl/symhacks.h> 81#include <openssl/symhacks.h>
82#include <openssl/err.h>
98 83
99#ifdef __cplusplus 84#ifdef __cplusplus
100extern "C" { 85extern "C" {
101#endif 86#endif
102 87
88/* Fixups for missing algorithms */
89#ifdef OPENSSL_NO_RSA
90typedef void RSA_METHOD;
91#endif
92#ifdef OPENSSL_NO_DSA
93typedef void DSA_METHOD;
94#endif
95#ifdef OPENSSL_NO_DH
96typedef void DH_METHOD;
97#endif
98
103/* These flags are used to control combinations of algorithm (methods) 99/* These flags are used to control combinations of algorithm (methods)
104 * by bitwise "OR"ing. */ 100 * by bitwise "OR"ing. */
105#define ENGINE_METHOD_RSA (unsigned int)0x0001 101#define ENGINE_METHOD_RSA (unsigned int)0x0001
106#define ENGINE_METHOD_DSA (unsigned int)0x0002 102#define ENGINE_METHOD_DSA (unsigned int)0x0002
107#define ENGINE_METHOD_DH (unsigned int)0x0004 103#define ENGINE_METHOD_DH (unsigned int)0x0004
108#define ENGINE_METHOD_RAND (unsigned int)0x0008 104#define ENGINE_METHOD_RAND (unsigned int)0x0008
109#define ENGINE_METHOD_ECDH (unsigned int)0x0010
110#define ENGINE_METHOD_ECDSA (unsigned int)0x0020
111#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040 105#define ENGINE_METHOD_CIPHERS (unsigned int)0x0040
112#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080 106#define ENGINE_METHOD_DIGESTS (unsigned int)0x0080
113#define ENGINE_METHOD_STORE (unsigned int)0x0100
114/* Obvious all-or-nothing cases. */ 107/* Obvious all-or-nothing cases. */
115#define ENGINE_METHOD_ALL (unsigned int)0xFFFF 108#define ENGINE_METHOD_ALL (unsigned int)0xFFFF
116#define ENGINE_METHOD_NONE (unsigned int)0x0000 109#define ENGINE_METHOD_NONE (unsigned int)0x0000
@@ -180,15 +173,9 @@ extern "C" {
180 handles/connections etc. */ 173 handles/connections etc. */
181#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */ 174#define ENGINE_CTRL_SET_USER_INTERFACE 4 /* Alternative to callback */
182#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used 175#define ENGINE_CTRL_SET_CALLBACK_DATA 5 /* User-specific data, used
183 when calling the password 176 when calling the password
184 callback and the user 177 callback and the user
185 interface */ 178 interface */
186#define ENGINE_CTRL_LOAD_CONFIGURATION 6 /* Load a configuration, given
187 a string that represents a
188 file name or so */
189#define ENGINE_CTRL_LOAD_SECTION 7 /* Load data from a given
190 section in the already loaded
191 configuration */
192 179
193/* These control commands allow an application to deal with an arbitrary engine 180/* These control commands allow an application to deal with an arbitrary engine
194 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE 181 * in a dynamic way. Warn: Negative return values indicate errors FOR THESE
@@ -235,7 +222,7 @@ extern "C" {
235 222
236/* ENGINE implementations should start the numbering of their own control 223/* ENGINE implementations should start the numbering of their own control
237 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */ 224 * commands from this value. (ie. ENGINE_CMD_BASE, ENGINE_CMD_BASE + 1, etc). */
238#define ENGINE_CMD_BASE 200 225#define ENGINE_CMD_BASE 200
239 226
240/* NB: These 2 nCipher "chil" control commands are deprecated, and their 227/* NB: These 2 nCipher "chil" control commands are deprecated, and their
241 * functionality is now available through ENGINE-specific control commands 228 * functionality is now available through ENGINE-specific control commands
@@ -270,11 +257,11 @@ typedef struct ENGINE_CMD_DEFN_st
270 } ENGINE_CMD_DEFN; 257 } ENGINE_CMD_DEFN;
271 258
272/* Generic function pointer */ 259/* Generic function pointer */
273typedef int (*ENGINE_GEN_FUNC_PTR)(void); 260typedef int (*ENGINE_GEN_FUNC_PTR)();
274/* Generic function pointer taking no arguments */ 261/* Generic function pointer taking no arguments */
275typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *); 262typedef int (*ENGINE_GEN_INT_FUNC_PTR)(ENGINE *);
276/* Specific control function pointer */ 263/* Specific control function pointer */
277typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)(void)); 264typedef int (*ENGINE_CTRL_FUNC_PTR)(ENGINE *, int, long, void *, void (*f)());
278/* Generic load_key function pointer */ 265/* Generic load_key function pointer */
279typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *, 266typedef EVP_PKEY * (*ENGINE_LOAD_KEY_PTR)(ENGINE *, const char *,
280 UI_METHOD *ui_method, void *callback_data); 267 UI_METHOD *ui_method, void *callback_data);
@@ -318,21 +305,15 @@ ENGINE *ENGINE_by_id(const char *id);
318/* Add all the built-in engines. */ 305/* Add all the built-in engines. */
319void ENGINE_load_openssl(void); 306void ENGINE_load_openssl(void);
320void ENGINE_load_dynamic(void); 307void ENGINE_load_dynamic(void);
321#ifndef OPENSSL_NO_STATIC_ENGINE
322void ENGINE_load_4758cca(void);
323void ENGINE_load_aep(void);
324void ENGINE_load_atalla(void);
325void ENGINE_load_chil(void);
326void ENGINE_load_cswift(void); 308void ENGINE_load_cswift(void);
327#ifndef OPENSSL_NO_GMP 309void ENGINE_load_chil(void);
328void ENGINE_load_gmp(void); 310void ENGINE_load_atalla(void);
329#endif
330void ENGINE_load_nuron(void); 311void ENGINE_load_nuron(void);
331void ENGINE_load_sureware(void);
332void ENGINE_load_ubsec(void); 312void ENGINE_load_ubsec(void);
333#endif 313void ENGINE_load_aep(void);
314void ENGINE_load_sureware(void);
315void ENGINE_load_4758cca(void);
334void ENGINE_load_cryptodev(void); 316void ENGINE_load_cryptodev(void);
335void ENGINE_load_padlock(void);
336void ENGINE_load_builtin_engines(void); 317void ENGINE_load_builtin_engines(void);
337 318
338/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation 319/* Get and set global flags (ENGINE_TABLE_FLAG_***) for the implementation
@@ -356,14 +337,6 @@ int ENGINE_register_DSA(ENGINE *e);
356void ENGINE_unregister_DSA(ENGINE *e); 337void ENGINE_unregister_DSA(ENGINE *e);
357void ENGINE_register_all_DSA(void); 338void ENGINE_register_all_DSA(void);
358 339
359int ENGINE_register_ECDH(ENGINE *e);
360void ENGINE_unregister_ECDH(ENGINE *e);
361void ENGINE_register_all_ECDH(void);
362
363int ENGINE_register_ECDSA(ENGINE *e);
364void ENGINE_unregister_ECDSA(ENGINE *e);
365void ENGINE_register_all_ECDSA(void);
366
367int ENGINE_register_DH(ENGINE *e); 340int ENGINE_register_DH(ENGINE *e);
368void ENGINE_unregister_DH(ENGINE *e); 341void ENGINE_unregister_DH(ENGINE *e);
369void ENGINE_register_all_DH(void); 342void ENGINE_register_all_DH(void);
@@ -372,10 +345,6 @@ int ENGINE_register_RAND(ENGINE *e);
372void ENGINE_unregister_RAND(ENGINE *e); 345void ENGINE_unregister_RAND(ENGINE *e);
373void ENGINE_register_all_RAND(void); 346void ENGINE_register_all_RAND(void);
374 347
375int ENGINE_register_STORE(ENGINE *e);
376void ENGINE_unregister_STORE(ENGINE *e);
377void ENGINE_register_all_STORE(void);
378
379int ENGINE_register_ciphers(ENGINE *e); 348int ENGINE_register_ciphers(ENGINE *e);
380void ENGINE_unregister_ciphers(ENGINE *e); 349void ENGINE_unregister_ciphers(ENGINE *e);
381void ENGINE_register_all_ciphers(void); 350void ENGINE_register_all_ciphers(void);
@@ -398,7 +367,7 @@ int ENGINE_register_all_complete(void);
398 * reference to an engine, but many control commands may require the engine be 367 * reference to an engine, but many control commands may require the engine be
399 * functional. The caller should be aware of trying commands that require an 368 * functional. The caller should be aware of trying commands that require an
400 * operational ENGINE, and only use functional references in such situations. */ 369 * operational ENGINE, and only use functional references in such situations. */
401int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)(void)); 370int ENGINE_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
402 371
403/* This function tests if an ENGINE-specific command is usable as a "setting". 372/* This function tests if an ENGINE-specific command is usable as a "setting".
404 * Eg. in an application's config file that gets processed through 373 * Eg. in an application's config file that gets processed through
@@ -411,7 +380,7 @@ int ENGINE_cmd_is_executable(ENGINE *e, int cmd);
411 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to 380 * See the comment on ENGINE_ctrl_cmd_string() for an explanation on how to
412 * use the cmd_name and cmd_optional. */ 381 * use the cmd_name and cmd_optional. */
413int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name, 382int ENGINE_ctrl_cmd(ENGINE *e, const char *cmd_name,
414 long i, void *p, void (*f)(void), int cmd_optional); 383 long i, void *p, void (*f)(), int cmd_optional);
415 384
416/* This function passes a command-name and argument to an ENGINE. The cmd_name 385/* This function passes a command-name and argument to an ENGINE. The cmd_name
417 * is converted to a command number and the control command is called using 386 * is converted to a command number and the control command is called using
@@ -448,11 +417,8 @@ int ENGINE_set_id(ENGINE *e, const char *id);
448int ENGINE_set_name(ENGINE *e, const char *name); 417int ENGINE_set_name(ENGINE *e, const char *name);
449int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth); 418int ENGINE_set_RSA(ENGINE *e, const RSA_METHOD *rsa_meth);
450int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth); 419int ENGINE_set_DSA(ENGINE *e, const DSA_METHOD *dsa_meth);
451int ENGINE_set_ECDH(ENGINE *e, const ECDH_METHOD *ecdh_meth);
452int ENGINE_set_ECDSA(ENGINE *e, const ECDSA_METHOD *ecdsa_meth);
453int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth); 420int ENGINE_set_DH(ENGINE *e, const DH_METHOD *dh_meth);
454int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth); 421int ENGINE_set_RAND(ENGINE *e, const RAND_METHOD *rand_meth);
455int ENGINE_set_STORE(ENGINE *e, const STORE_METHOD *store_meth);
456int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f); 422int ENGINE_set_destroy_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR destroy_f);
457int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f); 423int ENGINE_set_init_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR init_f);
458int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f); 424int ENGINE_set_finish_function(ENGINE *e, ENGINE_GEN_INT_FUNC_PTR finish_f);
@@ -463,11 +429,11 @@ int ENGINE_set_ciphers(ENGINE *e, ENGINE_CIPHERS_PTR f);
463int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f); 429int ENGINE_set_digests(ENGINE *e, ENGINE_DIGESTS_PTR f);
464int ENGINE_set_flags(ENGINE *e, int flags); 430int ENGINE_set_flags(ENGINE *e, int flags);
465int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns); 431int ENGINE_set_cmd_defns(ENGINE *e, const ENGINE_CMD_DEFN *defns);
466/* These functions allow control over any per-structure ENGINE data. */ 432/* These functions (and the "get" function lower down) allow control over any
433 * per-structure ENGINE data. */
467int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 434int ENGINE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
468 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 435 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
469int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg); 436int ENGINE_set_ex_data(ENGINE *e, int idx, void *arg);
470void *ENGINE_get_ex_data(const ENGINE *e, int idx);
471 437
472/* This function cleans up anything that needs it. Eg. the ENGINE_add() function 438/* This function cleans up anything that needs it. Eg. the ENGINE_add() function
473 * automatically ensures the list cleanup function is registered to be called 439 * automatically ensures the list cleanup function is registered to be called
@@ -483,11 +449,8 @@ const char *ENGINE_get_id(const ENGINE *e);
483const char *ENGINE_get_name(const ENGINE *e); 449const char *ENGINE_get_name(const ENGINE *e);
484const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e); 450const RSA_METHOD *ENGINE_get_RSA(const ENGINE *e);
485const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e); 451const DSA_METHOD *ENGINE_get_DSA(const ENGINE *e);
486const ECDH_METHOD *ENGINE_get_ECDH(const ENGINE *e);
487const ECDSA_METHOD *ENGINE_get_ECDSA(const ENGINE *e);
488const DH_METHOD *ENGINE_get_DH(const ENGINE *e); 452const DH_METHOD *ENGINE_get_DH(const ENGINE *e);
489const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e); 453const RAND_METHOD *ENGINE_get_RAND(const ENGINE *e);
490const STORE_METHOD *ENGINE_get_STORE(const ENGINE *e);
491ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e); 454ENGINE_GEN_INT_FUNC_PTR ENGINE_get_destroy_function(const ENGINE *e);
492ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e); 455ENGINE_GEN_INT_FUNC_PTR ENGINE_get_init_function(const ENGINE *e);
493ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e); 456ENGINE_GEN_INT_FUNC_PTR ENGINE_get_finish_function(const ENGINE *e);
@@ -500,6 +463,7 @@ const EVP_CIPHER *ENGINE_get_cipher(ENGINE *e, int nid);
500const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid); 463const EVP_MD *ENGINE_get_digest(ENGINE *e, int nid);
501const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e); 464const ENGINE_CMD_DEFN *ENGINE_get_cmd_defns(const ENGINE *e);
502int ENGINE_get_flags(const ENGINE *e); 465int ENGINE_get_flags(const ENGINE *e);
466void *ENGINE_get_ex_data(const ENGINE *e, int idx);
503 467
504/* FUNCTIONAL functions. These functions deal with ENGINE structures 468/* FUNCTIONAL functions. These functions deal with ENGINE structures
505 * that have (or will) be initialised for use. Broadly speaking, the 469 * that have (or will) be initialised for use. Broadly speaking, the
@@ -537,8 +501,6 @@ EVP_PKEY *ENGINE_load_public_key(ENGINE *e, const char *key_id,
537ENGINE *ENGINE_get_default_RSA(void); 501ENGINE *ENGINE_get_default_RSA(void);
538/* Same for the other "methods" */ 502/* Same for the other "methods" */
539ENGINE *ENGINE_get_default_DSA(void); 503ENGINE *ENGINE_get_default_DSA(void);
540ENGINE *ENGINE_get_default_ECDH(void);
541ENGINE *ENGINE_get_default_ECDSA(void);
542ENGINE *ENGINE_get_default_DH(void); 504ENGINE *ENGINE_get_default_DH(void);
543ENGINE *ENGINE_get_default_RAND(void); 505ENGINE *ENGINE_get_default_RAND(void);
544/* These functions can be used to get a functional reference to perform 506/* These functions can be used to get a functional reference to perform
@@ -554,8 +516,6 @@ int ENGINE_set_default_RSA(ENGINE *e);
554int ENGINE_set_default_string(ENGINE *e, const char *def_list); 516int ENGINE_set_default_string(ENGINE *e, const char *def_list);
555/* Same for the other "methods" */ 517/* Same for the other "methods" */
556int ENGINE_set_default_DSA(ENGINE *e); 518int ENGINE_set_default_DSA(ENGINE *e);
557int ENGINE_set_default_ECDH(ENGINE *e);
558int ENGINE_set_default_ECDSA(ENGINE *e);
559int ENGINE_set_default_DH(ENGINE *e); 519int ENGINE_set_default_DH(ENGINE *e);
560int ENGINE_set_default_RAND(ENGINE *e); 520int ENGINE_set_default_RAND(ENGINE *e);
561int ENGINE_set_default_ciphers(ENGINE *e); 521int ENGINE_set_default_ciphers(ENGINE *e);
@@ -578,20 +538,17 @@ void ENGINE_add_conf_module(void);
578/**************************/ 538/**************************/
579 539
580/* Binary/behaviour compatibility levels */ 540/* Binary/behaviour compatibility levels */
581#define OSSL_DYNAMIC_VERSION (unsigned long)0x00020000 541#define OSSL_DYNAMIC_VERSION (unsigned long)0x00010200
582/* Binary versions older than this are too old for us (whether we're a loader or 542/* Binary versions older than this are too old for us (whether we're a loader or
583 * a loadee) */ 543 * a loadee) */
584#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00020000 544#define OSSL_DYNAMIC_OLDEST (unsigned long)0x00010200
585 545
586/* When compiling an ENGINE entirely as an external shared library, loadable by 546/* When compiling an ENGINE entirely as an external shared library, loadable by
587 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure 547 * the "dynamic" ENGINE, these types are needed. The 'dynamic_fns' structure
588 * type provides the calling application's (or library's) error functionality 548 * type provides the calling application's (or library's) error functionality
589 * and memory management function pointers to the loaded library. These should 549 * and memory management function pointers to the loaded library. These should
590 * be used/set in the loaded library code so that the loading application's 550 * be used/set in the loaded library code so that the loading application's
591 * 'state' will be used/changed in all operations. The 'static_state' pointer 551 * 'state' will be used/changed in all operations. */
592 * allows the loaded library to know if it shares the same static data as the
593 * calling application (or library), and thus whether these callbacks need to be
594 * set or not. */
595typedef void *(*dyn_MEM_malloc_cb)(size_t); 552typedef void *(*dyn_MEM_malloc_cb)(size_t);
596typedef void *(*dyn_MEM_realloc_cb)(void *, size_t); 553typedef void *(*dyn_MEM_realloc_cb)(void *, size_t);
597typedef void (*dyn_MEM_free_cb)(void *); 554typedef void (*dyn_MEM_free_cb)(void *);
@@ -619,7 +576,6 @@ typedef struct st_dynamic_LOCK_fns {
619 } dynamic_LOCK_fns; 576 } dynamic_LOCK_fns;
620/* The top-level structure */ 577/* The top-level structure */
621typedef struct st_dynamic_fns { 578typedef struct st_dynamic_fns {
622 void *static_state;
623 const ERR_FNS *err_fns; 579 const ERR_FNS *err_fns;
624 const CRYPTO_EX_DATA_IMPL *ex_data_fns; 580 const CRYPTO_EX_DATA_IMPL *ex_data_fns;
625 dynamic_MEM_fns mem_fns; 581 dynamic_MEM_fns mem_fns;
@@ -637,7 +593,7 @@ typedef struct st_dynamic_fns {
637 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */ 593 * can be fully instantiated with IMPLEMENT_DYNAMIC_CHECK_FN(). */
638typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version); 594typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
639#define IMPLEMENT_DYNAMIC_CHECK_FN() \ 595#define IMPLEMENT_DYNAMIC_CHECK_FN() \
640 OPENSSL_EXPORT unsigned long v_check(unsigned long v) { \ 596 unsigned long v_check(unsigned long v) { \
641 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \ 597 if(v >= OSSL_DYNAMIC_OLDEST) return OSSL_DYNAMIC_VERSION; \
642 return 0; } 598 return 0; }
643 599
@@ -659,35 +615,24 @@ typedef unsigned long (*dynamic_v_check_fn)(unsigned long ossl_version);
659typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id, 615typedef int (*dynamic_bind_engine)(ENGINE *e, const char *id,
660 const dynamic_fns *fns); 616 const dynamic_fns *fns);
661#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \ 617#define IMPLEMENT_DYNAMIC_BIND_FN(fn) \
662 OPENSSL_EXPORT \
663 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \ 618 int bind_engine(ENGINE *e, const char *id, const dynamic_fns *fns) { \
664 if(ENGINE_get_static_state() == fns->static_state) goto skip_cbs; \ 619 if (ERR_get_implementation() != fns->err_fns) \
665 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \ 620 { \
666 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \ 621 if(!CRYPTO_set_mem_functions(fns->mem_fns.malloc_cb, \
667 return 0; \ 622 fns->mem_fns.realloc_cb, fns->mem_fns.free_cb)) \
668 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \ 623 return 0; \
669 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \ 624 CRYPTO_set_locking_callback(fns->lock_fns.lock_locking_cb); \
670 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \ 625 CRYPTO_set_add_lock_callback(fns->lock_fns.lock_add_lock_cb); \
671 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \ 626 CRYPTO_set_dynlock_create_callback(fns->lock_fns.dynlock_create_cb); \
672 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \ 627 CRYPTO_set_dynlock_lock_callback(fns->lock_fns.dynlock_lock_cb); \
673 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \ 628 CRYPTO_set_dynlock_destroy_callback(fns->lock_fns.dynlock_destroy_cb); \
674 return 0; \ 629 if(!CRYPTO_set_ex_data_implementation(fns->ex_data_fns)) \
675 if(!ERR_set_implementation(fns->err_fns)) return 0; \ 630 return 0; \
676 skip_cbs: \ 631 if(!ERR_set_implementation(fns->err_fns)) return 0; \
632 } \
677 if(!fn(e,id)) return 0; \ 633 if(!fn(e,id)) return 0; \
678 return 1; } 634 return 1; }
679 635
680/* If the loading application (or library) and the loaded ENGINE library share
681 * the same static data (eg. they're both dynamically linked to the same
682 * libcrypto.so) we need a way to avoid trying to set system callbacks - this
683 * would fail, and for the same reason that it's unnecessary to try. If the
684 * loaded ENGINE has (or gets from through the loader) its own copy of the
685 * libcrypto static data, we will need to set the callbacks. The easiest way to
686 * detect this is to have a function that returns a pointer to some static data
687 * and let the loading application and loaded ENGINE compare their respective
688 * values. */
689void *ENGINE_get_static_state(void);
690
691#if defined(__OpenBSD__) || defined(__FreeBSD__) 636#if defined(__OpenBSD__) || defined(__FreeBSD__)
692void ENGINE_setup_bsd_cryptodev(void); 637void ENGINE_setup_bsd_cryptodev(void);
693#endif 638#endif
@@ -704,7 +649,6 @@ void ERR_load_ENGINE_strings(void);
704#define ENGINE_F_DYNAMIC_CTRL 180 649#define ENGINE_F_DYNAMIC_CTRL 180
705#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181 650#define ENGINE_F_DYNAMIC_GET_DATA_CTX 181
706#define ENGINE_F_DYNAMIC_LOAD 182 651#define ENGINE_F_DYNAMIC_LOAD 182
707#define ENGINE_F_DYNAMIC_SET_DATA_CTX 183
708#define ENGINE_F_ENGINE_ADD 105 652#define ENGINE_F_ENGINE_ADD 105
709#define ENGINE_F_ENGINE_BY_ID 106 653#define ENGINE_F_ENGINE_BY_ID 106
710#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170 654#define ENGINE_F_ENGINE_CMD_IS_EXECUTABLE 170
@@ -712,7 +656,7 @@ void ERR_load_ENGINE_strings(void);
712#define ENGINE_F_ENGINE_CTRL_CMD 178 656#define ENGINE_F_ENGINE_CTRL_CMD 178
713#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171 657#define ENGINE_F_ENGINE_CTRL_CMD_STRING 171
714#define ENGINE_F_ENGINE_FINISH 107 658#define ENGINE_F_ENGINE_FINISH 107
715#define ENGINE_F_ENGINE_FREE_UTIL 108 659#define ENGINE_F_ENGINE_FREE 108
716#define ENGINE_F_ENGINE_GET_CIPHER 185 660#define ENGINE_F_ENGINE_GET_CIPHER 185
717#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177 661#define ENGINE_F_ENGINE_GET_DEFAULT_TYPE 177
718#define ENGINE_F_ENGINE_GET_DIGEST 186 662#define ENGINE_F_ENGINE_GET_DIGEST 186
@@ -723,6 +667,7 @@ void ERR_load_ENGINE_strings(void);
723#define ENGINE_F_ENGINE_LIST_REMOVE 121 667#define ENGINE_F_ENGINE_LIST_REMOVE 121
724#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150 668#define ENGINE_F_ENGINE_LOAD_PRIVATE_KEY 150
725#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151 669#define ENGINE_F_ENGINE_LOAD_PUBLIC_KEY 151
670#define ENGINE_F_ENGINE_MODULE_INIT 187
726#define ENGINE_F_ENGINE_NEW 122 671#define ENGINE_F_ENGINE_NEW 122
727#define ENGINE_F_ENGINE_REMOVE 123 672#define ENGINE_F_ENGINE_REMOVE 123
728#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189 673#define ENGINE_F_ENGINE_SET_DEFAULT_STRING 189
@@ -731,12 +676,11 @@ void ERR_load_ENGINE_strings(void);
731#define ENGINE_F_ENGINE_SET_NAME 130 676#define ENGINE_F_ENGINE_SET_NAME 130
732#define ENGINE_F_ENGINE_TABLE_REGISTER 184 677#define ENGINE_F_ENGINE_TABLE_REGISTER 184
733#define ENGINE_F_ENGINE_UNLOAD_KEY 152 678#define ENGINE_F_ENGINE_UNLOAD_KEY 152
734#define ENGINE_F_ENGINE_UNLOCKED_FINISH 191
735#define ENGINE_F_ENGINE_UP_REF 190 679#define ENGINE_F_ENGINE_UP_REF 190
736#define ENGINE_F_INT_CTRL_HELPER 172 680#define ENGINE_F_INT_CTRL_HELPER 172
737#define ENGINE_F_INT_ENGINE_CONFIGURE 188 681#define ENGINE_F_INT_ENGINE_CONFIGURE 188
738#define ENGINE_F_INT_ENGINE_MODULE_INIT 187
739#define ENGINE_F_LOG_MESSAGE 141 682#define ENGINE_F_LOG_MESSAGE 141
683#define ENGINE_F_SET_DATA_CTX 183
740 684
741/* Reason codes. */ 685/* Reason codes. */
742#define ENGINE_R_ALREADY_LOADED 100 686#define ENGINE_R_ALREADY_LOADED 100
diff --git a/src/lib/libcrypto/engine/enginetest.c b/src/lib/libcrypto/engine/enginetest.c
new file mode 100644
index 0000000000..c2d0297392
--- /dev/null
+++ b/src/lib/libcrypto/engine/enginetest.c
@@ -0,0 +1,283 @@
1/* crypto/engine/enginetest.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <string.h>
61
62#ifdef OPENSSL_NO_ENGINE
63int main(int argc, char *argv[])
64{
65 printf("No ENGINE support\n");
66 return(0);
67}
68#else
69#include <openssl/e_os2.h>
70#include <openssl/buffer.h>
71#include <openssl/crypto.h>
72#include <openssl/engine.h>
73#include <openssl/err.h>
74
75static void display_engine_list()
76 {
77 ENGINE *h;
78 int loop;
79
80 h = ENGINE_get_first();
81 loop = 0;
82 printf("listing available engine types\n");
83 while(h)
84 {
85 printf("engine %i, id = \"%s\", name = \"%s\"\n",
86 loop++, ENGINE_get_id(h), ENGINE_get_name(h));
87 h = ENGINE_get_next(h);
88 }
89 printf("end of list\n");
90 /* ENGINE_get_first() increases the struct_ref counter, so we
91 must call ENGINE_free() to decrease it again */
92 ENGINE_free(h);
93 }
94
95int main(int argc, char *argv[])
96 {
97 ENGINE *block[512];
98 char buf[256];
99 const char *id, *name;
100 ENGINE *ptr;
101 int loop;
102 int to_return = 1;
103 ENGINE *new_h1 = NULL;
104 ENGINE *new_h2 = NULL;
105 ENGINE *new_h3 = NULL;
106 ENGINE *new_h4 = NULL;
107
108 /* enable memory leak checking unless explicitly disabled */
109 if (!((getenv("OPENSSL_DEBUG_MEMORY") != NULL) && (0 == strcmp(getenv("OPENSSL_DEBUG_MEMORY"), "off"))))
110 {
111 CRYPTO_malloc_debug_init();
112 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
113 }
114 else
115 {
116 /* OPENSSL_DEBUG_MEMORY=off */
117 CRYPTO_set_mem_debug_functions(0, 0, 0, 0, 0);
118 }
119 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
120 ERR_load_crypto_strings();
121
122 memset(block, 0, 512 * sizeof(ENGINE *));
123 if(((new_h1 = ENGINE_new()) == NULL) ||
124 !ENGINE_set_id(new_h1, "test_id0") ||
125 !ENGINE_set_name(new_h1, "First test item") ||
126 ((new_h2 = ENGINE_new()) == NULL) ||
127 !ENGINE_set_id(new_h2, "test_id1") ||
128 !ENGINE_set_name(new_h2, "Second test item") ||
129 ((new_h3 = ENGINE_new()) == NULL) ||
130 !ENGINE_set_id(new_h3, "test_id2") ||
131 !ENGINE_set_name(new_h3, "Third test item") ||
132 ((new_h4 = ENGINE_new()) == NULL) ||
133 !ENGINE_set_id(new_h4, "test_id3") ||
134 !ENGINE_set_name(new_h4, "Fourth test item"))
135 {
136 printf("Couldn't set up test ENGINE structures\n");
137 goto end;
138 }
139 printf("\nenginetest beginning\n\n");
140 display_engine_list();
141 if(!ENGINE_add(new_h1))
142 {
143 printf("Add failed!\n");
144 goto end;
145 }
146 display_engine_list();
147 ptr = ENGINE_get_first();
148 if(!ENGINE_remove(ptr))
149 {
150 printf("Remove failed!\n");
151 goto end;
152 }
153 if (ptr)
154 ENGINE_free(ptr);
155 display_engine_list();
156 if(!ENGINE_add(new_h3) || !ENGINE_add(new_h2))
157 {
158 printf("Add failed!\n");
159 goto end;
160 }
161 display_engine_list();
162 if(!ENGINE_remove(new_h2))
163 {
164 printf("Remove failed!\n");
165 goto end;
166 }
167 display_engine_list();
168 if(!ENGINE_add(new_h4))
169 {
170 printf("Add failed!\n");
171 goto end;
172 }
173 display_engine_list();
174 if(ENGINE_add(new_h3))
175 {
176 printf("Add *should* have failed but didn't!\n");
177 goto end;
178 }
179 else
180 printf("Add that should fail did.\n");
181 ERR_clear_error();
182 if(ENGINE_remove(new_h2))
183 {
184 printf("Remove *should* have failed but didn't!\n");
185 goto end;
186 }
187 else
188 printf("Remove that should fail did.\n");
189 ERR_clear_error();
190 if(!ENGINE_remove(new_h3))
191 {
192 printf("Remove failed!\n");
193 goto end;
194 }
195 display_engine_list();
196 if(!ENGINE_remove(new_h4))
197 {
198 printf("Remove failed!\n");
199 goto end;
200 }
201 display_engine_list();
202 /* Depending on whether there's any hardware support compiled
203 * in, this remove may be destined to fail. */
204 ptr = ENGINE_get_first();
205 if(ptr)
206 if(!ENGINE_remove(ptr))
207 printf("Remove failed!i - probably no hardware "
208 "support present.\n");
209 if (ptr)
210 ENGINE_free(ptr);
211 display_engine_list();
212 if(!ENGINE_add(new_h1) || !ENGINE_remove(new_h1))
213 {
214 printf("Couldn't add and remove to an empty list!\n");
215 goto end;
216 }
217 else
218 printf("Successfully added and removed to an empty list!\n");
219 printf("About to beef up the engine-type list\n");
220 for(loop = 0; loop < 512; loop++)
221 {
222 sprintf(buf, "id%i", loop);
223 id = BUF_strdup(buf);
224 sprintf(buf, "Fake engine type %i", loop);
225 name = BUF_strdup(buf);
226 if(((block[loop] = ENGINE_new()) == NULL) ||
227 !ENGINE_set_id(block[loop], id) ||
228 !ENGINE_set_name(block[loop], name))
229 {
230 printf("Couldn't create block of ENGINE structures.\n"
231 "I'll probably also core-dump now, damn.\n");
232 goto end;
233 }
234 }
235 for(loop = 0; loop < 512; loop++)
236 {
237 if(!ENGINE_add(block[loop]))
238 {
239 printf("\nAdding stopped at %i, (%s,%s)\n",
240 loop, ENGINE_get_id(block[loop]),
241 ENGINE_get_name(block[loop]));
242 goto cleanup_loop;
243 }
244 else
245 printf("."); fflush(stdout);
246 }
247cleanup_loop:
248 printf("\nAbout to empty the engine-type list\n");
249 while((ptr = ENGINE_get_first()) != NULL)
250 {
251 if(!ENGINE_remove(ptr))
252 {
253 printf("\nRemove failed!\n");
254 goto end;
255 }
256 ENGINE_free(ptr);
257 printf("."); fflush(stdout);
258 }
259 for(loop = 0; loop < 512; loop++)
260 {
261 OPENSSL_free((void *)ENGINE_get_id(block[loop]));
262 OPENSSL_free((void *)ENGINE_get_name(block[loop]));
263 }
264 printf("\nTests completed happily\n");
265 to_return = 0;
266end:
267 if(to_return)
268 ERR_print_errors_fp(stderr);
269 if(new_h1) ENGINE_free(new_h1);
270 if(new_h2) ENGINE_free(new_h2);
271 if(new_h3) ENGINE_free(new_h3);
272 if(new_h4) ENGINE_free(new_h4);
273 for(loop = 0; loop < 512; loop++)
274 if(block[loop])
275 ENGINE_free(block[loop]);
276 ENGINE_cleanup();
277 CRYPTO_cleanup_all_ex_data();
278 ERR_free_strings();
279 ERR_remove_state(0);
280 CRYPTO_mem_leaks_fp(stderr);
281 return to_return;
282 }
283#endif
diff --git a/src/lib/libcrypto/engine/hw.ec b/src/lib/libcrypto/engine/hw.ec
new file mode 100644
index 0000000000..5481a43918
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw.ec
@@ -0,0 +1,8 @@
1L AEPHK hw_aep_err.h hw_aep_err.c
2L ATALLA hw_atalla_err.h hw_atalla_err.c
3L CSWIFT hw_cswift_err.h hw_cswift_err.c
4L HWCRHK hw_ncipher_err.h hw_ncipher_err.c
5L NURON hw_nuron_err.h hw_nuron_err.c
6L SUREWARE hw_sureware_err.h hw_sureware_err.c
7L UBSEC hw_ubsec_err.h hw_ubsec_err.c
8L CCA4758 hw_4758_cca_err.h hw_4758_cca_err.c
diff --git a/src/lib/libcrypto/engine/hw_4758_cca.c b/src/lib/libcrypto/engine/hw_4758_cca.c
new file mode 100644
index 0000000000..4f5ae8a46d
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca.c
@@ -0,0 +1,969 @@
1/* Author: Maurice Gittens <maurice@gittens.nl> */
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#include <stdio.h>
57#include <openssl/crypto.h>
58/* #include <openssl/pem.h> */
59#include "cryptlib.h"
60#include <openssl/dso.h>
61#include <openssl/x509.h>
62#include <openssl/objects.h>
63#include <openssl/engine.h>
64
65#ifndef OPENSSL_NO_HW
66#ifndef OPENSSL_NO_HW_4758_CCA
67
68#ifdef FLAT_INC
69#include "hw_4758_cca.h"
70#else
71#include "vendor_defns/hw_4758_cca.h"
72#endif
73
74#include "hw_4758_cca_err.c"
75
76static int ibm_4758_cca_destroy(ENGINE *e);
77static int ibm_4758_cca_init(ENGINE *e);
78static int ibm_4758_cca_finish(ENGINE *e);
79static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
80
81/* rsa functions */
82/*---------------*/
83#ifndef OPENSSL_NO_RSA
84static int cca_rsa_pub_enc(int flen, const unsigned char *from,
85 unsigned char *to, RSA *rsa,int padding);
86static int cca_rsa_priv_dec(int flen, const unsigned char *from,
87 unsigned char *to, RSA *rsa,int padding);
88static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
89 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
90static int cca_rsa_verify(int dtype, const unsigned char *m, unsigned int m_len,
91 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
92
93/* utility functions */
94/*-----------------------*/
95static EVP_PKEY *ibm_4758_load_privkey(ENGINE*, const char*,
96 UI_METHOD *ui_method, void *callback_data);
97static EVP_PKEY *ibm_4758_load_pubkey(ENGINE*, const char*,
98 UI_METHOD *ui_method, void *callback_data);
99
100static int getModulusAndExponent(const unsigned char *token, long *exponentLength,
101 unsigned char *exponent, long *modulusLength,
102 long *modulusFieldLength, unsigned char *modulus);
103#endif
104
105/* RAND number functions */
106/*-----------------------*/
107static int cca_get_random_bytes(unsigned char*, int );
108static int cca_random_status(void);
109
110static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
111 int idx,long argl, void *argp);
112
113/* Function pointers for CCA verbs */
114/*---------------------------------*/
115#ifndef OPENSSL_NO_RSA
116static F_KEYRECORDREAD keyRecordRead;
117static F_DIGITALSIGNATUREGENERATE digitalSignatureGenerate;
118static F_DIGITALSIGNATUREVERIFY digitalSignatureVerify;
119static F_PUBLICKEYEXTRACT publicKeyExtract;
120static F_PKAENCRYPT pkaEncrypt;
121static F_PKADECRYPT pkaDecrypt;
122#endif
123static F_RANDOMNUMBERGENERATE randomNumberGenerate;
124
125/* static variables */
126/*------------------*/
127static const char *CCA4758_LIB_NAME = NULL;
128static const char *get_CCA4758_LIB_NAME(void)
129 {
130 if(CCA4758_LIB_NAME)
131 return CCA4758_LIB_NAME;
132 return CCA_LIB_NAME;
133 }
134static void free_CCA4758_LIB_NAME(void)
135 {
136 if(CCA4758_LIB_NAME)
137 OPENSSL_free((void*)CCA4758_LIB_NAME);
138 CCA4758_LIB_NAME = NULL;
139 }
140static long set_CCA4758_LIB_NAME(const char *name)
141 {
142 free_CCA4758_LIB_NAME();
143 return (((CCA4758_LIB_NAME = BUF_strdup(name)) != NULL) ? 1 : 0);
144 }
145#ifndef OPENSSL_NO_RSA
146static const char* n_keyRecordRead = CSNDKRR;
147static const char* n_digitalSignatureGenerate = CSNDDSG;
148static const char* n_digitalSignatureVerify = CSNDDSV;
149static const char* n_publicKeyExtract = CSNDPKX;
150static const char* n_pkaEncrypt = CSNDPKE;
151static const char* n_pkaDecrypt = CSNDPKD;
152#endif
153static const char* n_randomNumberGenerate = CSNBRNG;
154
155static int hndidx = -1;
156static DSO *dso = NULL;
157
158/* openssl engine initialization structures */
159/*------------------------------------------*/
160
161#define CCA4758_CMD_SO_PATH ENGINE_CMD_BASE
162static const ENGINE_CMD_DEFN cca4758_cmd_defns[] = {
163 {CCA4758_CMD_SO_PATH,
164 "SO_PATH",
165 "Specifies the path to the '4758cca' shared library",
166 ENGINE_CMD_FLAG_STRING},
167 {0, NULL, NULL, 0}
168 };
169
170#ifndef OPENSSL_NO_RSA
171static RSA_METHOD ibm_4758_cca_rsa =
172 {
173 "IBM 4758 CCA RSA method",
174 cca_rsa_pub_enc,
175 NULL,
176 NULL,
177 cca_rsa_priv_dec,
178 NULL, /*rsa_mod_exp,*/
179 NULL, /*mod_exp_mont,*/
180 NULL, /* init */
181 NULL, /* finish */
182 RSA_FLAG_SIGN_VER, /* flags */
183 NULL, /* app_data */
184 cca_rsa_sign, /* rsa_sign */
185 cca_rsa_verify /* rsa_verify */
186 };
187#endif
188
189static RAND_METHOD ibm_4758_cca_rand =
190 {
191 /* "IBM 4758 RAND method", */
192 NULL, /* seed */
193 cca_get_random_bytes, /* get random bytes from the card */
194 NULL, /* cleanup */
195 NULL, /* add */
196 cca_get_random_bytes, /* pseudo rand */
197 cca_random_status, /* status */
198 };
199
200static const char *engine_4758_cca_id = "4758cca";
201static const char *engine_4758_cca_name = "IBM 4758 CCA hardware engine support";
202
203/* engine implementation */
204/*-----------------------*/
205static int bind_helper(ENGINE *e)
206 {
207 if(!ENGINE_set_id(e, engine_4758_cca_id) ||
208 !ENGINE_set_name(e, engine_4758_cca_name) ||
209#ifndef OPENSSL_NO_RSA
210 !ENGINE_set_RSA(e, &ibm_4758_cca_rsa) ||
211#endif
212 !ENGINE_set_RAND(e, &ibm_4758_cca_rand) ||
213 !ENGINE_set_destroy_function(e, ibm_4758_cca_destroy) ||
214 !ENGINE_set_init_function(e, ibm_4758_cca_init) ||
215 !ENGINE_set_finish_function(e, ibm_4758_cca_finish) ||
216 !ENGINE_set_ctrl_function(e, ibm_4758_cca_ctrl) ||
217 !ENGINE_set_load_privkey_function(e, ibm_4758_load_privkey) ||
218 !ENGINE_set_load_pubkey_function(e, ibm_4758_load_pubkey) ||
219 !ENGINE_set_cmd_defns(e, cca4758_cmd_defns))
220 return 0;
221 /* Ensure the error handling is set up */
222 ERR_load_CCA4758_strings();
223 return 1;
224 }
225
226#ifndef ENGINE_DYNAMIC_SUPPORT
227static ENGINE *engine_4758_cca(void)
228 {
229 ENGINE *ret = ENGINE_new();
230 if(!ret)
231 return NULL;
232 if(!bind_helper(ret))
233 {
234 ENGINE_free(ret);
235 return NULL;
236 }
237 return ret;
238 }
239
240void ENGINE_load_4758cca(void)
241 {
242 ENGINE *e_4758 = engine_4758_cca();
243 if (!e_4758) return;
244 ENGINE_add(e_4758);
245 ENGINE_free(e_4758);
246 ERR_clear_error();
247 }
248#endif
249
250static int ibm_4758_cca_destroy(ENGINE *e)
251 {
252 ERR_unload_CCA4758_strings();
253 free_CCA4758_LIB_NAME();
254 return 1;
255 }
256
257static int ibm_4758_cca_init(ENGINE *e)
258 {
259 if(dso)
260 {
261 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_ALREADY_LOADED);
262 goto err;
263 }
264
265 dso = DSO_load(NULL, get_CCA4758_LIB_NAME(), NULL, 0);
266 if(!dso)
267 {
268 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
269 goto err;
270 }
271
272#ifndef OPENSSL_NO_RSA
273 if(!(keyRecordRead = (F_KEYRECORDREAD)
274 DSO_bind_func(dso, n_keyRecordRead)) ||
275 !(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
276 DSO_bind_func(dso, n_randomNumberGenerate)) ||
277 !(digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)
278 DSO_bind_func(dso, n_digitalSignatureGenerate)) ||
279 !(digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)
280 DSO_bind_func(dso, n_digitalSignatureVerify)) ||
281 !(publicKeyExtract = (F_PUBLICKEYEXTRACT)
282 DSO_bind_func(dso, n_publicKeyExtract)) ||
283 !(pkaEncrypt = (F_PKAENCRYPT)
284 DSO_bind_func(dso, n_pkaEncrypt)) ||
285 !(pkaDecrypt = (F_PKADECRYPT)
286 DSO_bind_func(dso, n_pkaDecrypt)))
287 {
288 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
289 goto err;
290 }
291#else
292 if(!(randomNumberGenerate = (F_RANDOMNUMBERGENERATE)
293 DSO_bind_func(dso, n_randomNumberGenerate)))
294 {
295 CCA4758err(CCA4758_F_IBM_4758_CCA_INIT,CCA4758_R_DSO_FAILURE);
296 goto err;
297 }
298#endif
299
300 hndidx = RSA_get_ex_new_index(0, "IBM 4758 CCA RSA key handle",
301 NULL, NULL, cca_ex_free);
302
303 return 1;
304err:
305 if(dso)
306 DSO_free(dso);
307 dso = NULL;
308
309 keyRecordRead = (F_KEYRECORDREAD)0;
310 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
311 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
312 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
313 publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
314 pkaEncrypt = (F_PKAENCRYPT)0;
315 pkaDecrypt = (F_PKADECRYPT)0;
316 return 0;
317 }
318
319static int ibm_4758_cca_finish(ENGINE *e)
320 {
321 free_CCA4758_LIB_NAME();
322 if(!dso)
323 {
324 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
325 CCA4758_R_NOT_LOADED);
326 return 0;
327 }
328 if(!DSO_free(dso))
329 {
330 CCA4758err(CCA4758_F_IBM_4758_CCA_FINISH,
331 CCA4758_R_UNIT_FAILURE);
332 return 0;
333 }
334 dso = NULL;
335 keyRecordRead = (F_KEYRECORDREAD)0;
336 randomNumberGenerate = (F_RANDOMNUMBERGENERATE)0;
337 digitalSignatureGenerate = (F_DIGITALSIGNATUREGENERATE)0;
338 digitalSignatureVerify = (F_DIGITALSIGNATUREVERIFY)0;
339 publicKeyExtract = (F_PUBLICKEYEXTRACT)0;
340 pkaEncrypt = (F_PKAENCRYPT)0;
341 pkaDecrypt = (F_PKADECRYPT)0;
342 return 1;
343 }
344
345static int ibm_4758_cca_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
346 {
347 int initialised = ((dso == NULL) ? 0 : 1);
348 switch(cmd)
349 {
350 case CCA4758_CMD_SO_PATH:
351 if(p == NULL)
352 {
353 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
354 ERR_R_PASSED_NULL_PARAMETER);
355 return 0;
356 }
357 if(initialised)
358 {
359 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
360 CCA4758_R_ALREADY_LOADED);
361 return 0;
362 }
363 return set_CCA4758_LIB_NAME((const char *)p);
364 default:
365 break;
366 }
367 CCA4758err(CCA4758_F_IBM_4758_CCA_CTRL,
368 CCA4758_R_COMMAND_NOT_IMPLEMENTED);
369 return 0;
370 }
371
372#ifndef OPENSSL_NO_RSA
373
374#define MAX_CCA_PKA_TOKEN_SIZE 2500
375
376static EVP_PKEY *ibm_4758_load_privkey(ENGINE* e, const char* key_id,
377 UI_METHOD *ui_method, void *callback_data)
378 {
379 RSA *rtmp = NULL;
380 EVP_PKEY *res = NULL;
381 unsigned char* keyToken = NULL;
382 unsigned char pubKeyToken[MAX_CCA_PKA_TOKEN_SIZE];
383 long pubKeyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
384 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
385 long returnCode;
386 long reasonCode;
387 long exitDataLength = 0;
388 long ruleArrayLength = 0;
389 unsigned char exitData[8];
390 unsigned char ruleArray[8];
391 unsigned char keyLabel[64];
392 long keyLabelLength = strlen(key_id);
393 unsigned char modulus[256];
394 long modulusFieldLength = sizeof(modulus);
395 long modulusLength = 0;
396 unsigned char exponent[256];
397 long exponentLength = sizeof(exponent);
398
399 if (keyLabelLength > sizeof(keyLabel))
400 {
401 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
402 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
403 return NULL;
404 }
405
406 memset(keyLabel,' ', sizeof(keyLabel));
407 memcpy(keyLabel, key_id, keyLabelLength);
408
409 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
410 if (!keyToken)
411 {
412 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
413 ERR_R_MALLOC_FAILURE);
414 goto err;
415 }
416
417 keyRecordRead(&returnCode, &reasonCode, &exitDataLength,
418 exitData, &ruleArrayLength, ruleArray, keyLabel,
419 &keyTokenLength, keyToken+sizeof(long));
420
421 if (returnCode)
422 {
423 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
424 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
425 goto err;
426 }
427
428 publicKeyExtract(&returnCode, &reasonCode, &exitDataLength,
429 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
430 keyToken+sizeof(long), &pubKeyTokenLength, pubKeyToken);
431
432 if (returnCode)
433 {
434 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
435 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
436 goto err;
437 }
438
439 if (!getModulusAndExponent(pubKeyToken, &exponentLength,
440 exponent, &modulusLength, &modulusFieldLength,
441 modulus))
442 {
443 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
444 CCA4758_R_FAILED_LOADING_PRIVATE_KEY);
445 goto err;
446 }
447
448 (*(long*)keyToken) = keyTokenLength;
449 rtmp = RSA_new_method(e);
450 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
451
452 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
453 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
454 rtmp->flags |= RSA_FLAG_EXT_PKEY;
455
456 res = EVP_PKEY_new();
457 EVP_PKEY_assign_RSA(res, rtmp);
458
459 return res;
460err:
461 if (keyToken)
462 OPENSSL_free(keyToken);
463 if (res)
464 EVP_PKEY_free(res);
465 if (rtmp)
466 RSA_free(rtmp);
467 return NULL;
468 }
469
470static EVP_PKEY *ibm_4758_load_pubkey(ENGINE* e, const char* key_id,
471 UI_METHOD *ui_method, void *callback_data)
472 {
473 RSA *rtmp = NULL;
474 EVP_PKEY *res = NULL;
475 unsigned char* keyToken = NULL;
476 long keyTokenLength = MAX_CCA_PKA_TOKEN_SIZE;
477 long returnCode;
478 long reasonCode;
479 long exitDataLength = 0;
480 long ruleArrayLength = 0;
481 unsigned char exitData[8];
482 unsigned char ruleArray[8];
483 unsigned char keyLabel[64];
484 long keyLabelLength = strlen(key_id);
485 unsigned char modulus[512];
486 long modulusFieldLength = sizeof(modulus);
487 long modulusLength = 0;
488 unsigned char exponent[512];
489 long exponentLength = sizeof(exponent);
490
491 if (keyLabelLength > sizeof(keyLabel))
492 {
493 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
494 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
495 return NULL;
496 }
497
498 memset(keyLabel,' ', sizeof(keyLabel));
499 memcpy(keyLabel, key_id, keyLabelLength);
500
501 keyToken = OPENSSL_malloc(MAX_CCA_PKA_TOKEN_SIZE + sizeof(long));
502 if (!keyToken)
503 {
504 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,
505 ERR_R_MALLOC_FAILURE);
506 goto err;
507 }
508
509 keyRecordRead(&returnCode, &reasonCode, &exitDataLength, exitData,
510 &ruleArrayLength, ruleArray, keyLabel, &keyTokenLength,
511 keyToken+sizeof(long));
512
513 if (returnCode)
514 {
515 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
516 ERR_R_MALLOC_FAILURE);
517 goto err;
518 }
519
520 if (!getModulusAndExponent(keyToken+sizeof(long), &exponentLength,
521 exponent, &modulusLength, &modulusFieldLength, modulus))
522 {
523 CCA4758err(CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,
524 CCA4758_R_FAILED_LOADING_PUBLIC_KEY);
525 goto err;
526 }
527
528 (*(long*)keyToken) = keyTokenLength;
529 rtmp = RSA_new_method(e);
530 RSA_set_ex_data(rtmp, hndidx, (char *)keyToken);
531 rtmp->e = BN_bin2bn(exponent, exponentLength, NULL);
532 rtmp->n = BN_bin2bn(modulus, modulusFieldLength, NULL);
533 rtmp->flags |= RSA_FLAG_EXT_PKEY;
534 res = EVP_PKEY_new();
535 EVP_PKEY_assign_RSA(res, rtmp);
536
537 return res;
538err:
539 if (keyToken)
540 OPENSSL_free(keyToken);
541 if (res)
542 EVP_PKEY_free(res);
543 if (rtmp)
544 RSA_free(rtmp);
545 return NULL;
546 }
547
548static int cca_rsa_pub_enc(int flen, const unsigned char *from,
549 unsigned char *to, RSA *rsa,int padding)
550 {
551 long returnCode;
552 long reasonCode;
553 long lflen = flen;
554 long exitDataLength = 0;
555 unsigned char exitData[8];
556 long ruleArrayLength = 1;
557 unsigned char ruleArray[8] = "PKCS-1.2";
558 long dataStructureLength = 0;
559 unsigned char dataStructure[8];
560 long outputLength = RSA_size(rsa);
561 long keyTokenLength;
562 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
563
564 keyTokenLength = *(long*)keyToken;
565 keyToken+=sizeof(long);
566
567 pkaEncrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
568 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
569 &dataStructureLength, dataStructure, &keyTokenLength,
570 keyToken, &outputLength, to);
571
572 if (returnCode || reasonCode)
573 return -(returnCode << 16 | reasonCode);
574 return outputLength;
575 }
576
577static int cca_rsa_priv_dec(int flen, const unsigned char *from,
578 unsigned char *to, RSA *rsa,int padding)
579 {
580 long returnCode;
581 long reasonCode;
582 long lflen = flen;
583 long exitDataLength = 0;
584 unsigned char exitData[8];
585 long ruleArrayLength = 1;
586 unsigned char ruleArray[8] = "PKCS-1.2";
587 long dataStructureLength = 0;
588 unsigned char dataStructure[8];
589 long outputLength = RSA_size(rsa);
590 long keyTokenLength;
591 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
592
593 keyTokenLength = *(long*)keyToken;
594 keyToken+=sizeof(long);
595
596 pkaDecrypt(&returnCode, &reasonCode, &exitDataLength, exitData,
597 &ruleArrayLength, ruleArray, &lflen, (unsigned char*)from,
598 &dataStructureLength, dataStructure, &keyTokenLength,
599 keyToken, &outputLength, to);
600
601 return (returnCode | reasonCode) ? 0 : 1;
602 }
603
604#define SSL_SIG_LEN 36
605
606static int cca_rsa_verify(int type, const unsigned char *m, unsigned int m_len,
607 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa)
608 {
609 long returnCode;
610 long reasonCode;
611 long lsiglen = siglen;
612 long exitDataLength = 0;
613 unsigned char exitData[8];
614 long ruleArrayLength = 1;
615 unsigned char ruleArray[8] = "PKCS-1.1";
616 long keyTokenLength;
617 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
618 long length = SSL_SIG_LEN;
619 long keyLength ;
620 unsigned char *hashBuffer = NULL;
621 X509_SIG sig;
622 ASN1_TYPE parameter;
623 X509_ALGOR algorithm;
624 ASN1_OCTET_STRING digest;
625
626 keyTokenLength = *(long*)keyToken;
627 keyToken+=sizeof(long);
628
629 if (type == NID_md5 || type == NID_sha1)
630 {
631 sig.algor = &algorithm;
632 algorithm.algorithm = OBJ_nid2obj(type);
633
634 if (!algorithm.algorithm)
635 {
636 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
637 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
638 return 0;
639 }
640
641 if (!algorithm.algorithm->length)
642 {
643 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
644 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
645 return 0;
646 }
647
648 parameter.type = V_ASN1_NULL;
649 parameter.value.ptr = NULL;
650 algorithm.parameter = &parameter;
651
652 sig.digest = &digest;
653 sig.digest->data = (unsigned char*)m;
654 sig.digest->length = m_len;
655
656 length = i2d_X509_SIG(&sig, NULL);
657 }
658
659 keyLength = RSA_size(rsa);
660
661 if (length - RSA_PKCS1_PADDING > keyLength)
662 {
663 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
664 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
665 return 0;
666 }
667
668 switch (type)
669 {
670 case NID_md5_sha1 :
671 if (m_len != SSL_SIG_LEN)
672 {
673 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
674 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
675 return 0;
676 }
677
678 hashBuffer = (unsigned char *)m;
679 length = m_len;
680 break;
681 case NID_md5 :
682 {
683 unsigned char *ptr;
684 ptr = hashBuffer = OPENSSL_malloc(
685 (unsigned int)keyLength+1);
686 if (!hashBuffer)
687 {
688 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
689 ERR_R_MALLOC_FAILURE);
690 return 0;
691 }
692
693 i2d_X509_SIG(&sig, &ptr);
694 }
695 break;
696 case NID_sha1 :
697 {
698 unsigned char *ptr;
699 ptr = hashBuffer = OPENSSL_malloc(
700 (unsigned int)keyLength+1);
701 if (!hashBuffer)
702 {
703 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
704 ERR_R_MALLOC_FAILURE);
705 return 0;
706 }
707 i2d_X509_SIG(&sig, &ptr);
708 }
709 break;
710 default:
711 return 0;
712 }
713
714 digitalSignatureVerify(&returnCode, &reasonCode, &exitDataLength,
715 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
716 keyToken, &length, hashBuffer, &lsiglen, sigbuf);
717
718 if (type == NID_sha1 || type == NID_md5)
719 {
720 OPENSSL_cleanse(hashBuffer, keyLength+1);
721 OPENSSL_free(hashBuffer);
722 }
723
724 return ((returnCode || reasonCode) ? 0 : 1);
725 }
726
727#define SSL_SIG_LEN 36
728
729static int cca_rsa_sign(int type, const unsigned char *m, unsigned int m_len,
730 unsigned char *sigret, unsigned int *siglen, const RSA *rsa)
731 {
732 long returnCode;
733 long reasonCode;
734 long exitDataLength = 0;
735 unsigned char exitData[8];
736 long ruleArrayLength = 1;
737 unsigned char ruleArray[8] = "PKCS-1.1";
738 long outputLength=256;
739 long outputBitLength;
740 long keyTokenLength;
741 unsigned char *hashBuffer = NULL;
742 unsigned char* keyToken = (unsigned char*)RSA_get_ex_data(rsa, hndidx);
743 long length = SSL_SIG_LEN;
744 long keyLength ;
745 X509_SIG sig;
746 ASN1_TYPE parameter;
747 X509_ALGOR algorithm;
748 ASN1_OCTET_STRING digest;
749
750 keyTokenLength = *(long*)keyToken;
751 keyToken+=sizeof(long);
752
753 if (type == NID_md5 || type == NID_sha1)
754 {
755 sig.algor = &algorithm;
756 algorithm.algorithm = OBJ_nid2obj(type);
757
758 if (!algorithm.algorithm)
759 {
760 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
761 CCA4758_R_UNKNOWN_ALGORITHM_TYPE);
762 return 0;
763 }
764
765 if (!algorithm.algorithm->length)
766 {
767 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
768 CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD);
769 return 0;
770 }
771
772 parameter.type = V_ASN1_NULL;
773 parameter.value.ptr = NULL;
774 algorithm.parameter = &parameter;
775
776 sig.digest = &digest;
777 sig.digest->data = (unsigned char*)m;
778 sig.digest->length = m_len;
779
780 length = i2d_X509_SIG(&sig, NULL);
781 }
782
783 keyLength = RSA_size(rsa);
784
785 if (length - RSA_PKCS1_PADDING > keyLength)
786 {
787 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
788 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
789 return 0;
790 }
791
792 switch (type)
793 {
794 case NID_md5_sha1 :
795 if (m_len != SSL_SIG_LEN)
796 {
797 CCA4758err(CCA4758_F_IBM_4758_CCA_SIGN,
798 CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
799 return 0;
800 }
801 hashBuffer = (unsigned char*)m;
802 length = m_len;
803 break;
804 case NID_md5 :
805 {
806 unsigned char *ptr;
807 ptr = hashBuffer = OPENSSL_malloc(
808 (unsigned int)keyLength+1);
809 if (!hashBuffer)
810 {
811 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
812 ERR_R_MALLOC_FAILURE);
813 return 0;
814 }
815 i2d_X509_SIG(&sig, &ptr);
816 }
817 break;
818 case NID_sha1 :
819 {
820 unsigned char *ptr;
821 ptr = hashBuffer = OPENSSL_malloc(
822 (unsigned int)keyLength+1);
823 if (!hashBuffer)
824 {
825 CCA4758err(CCA4758_F_IBM_4758_CCA_VERIFY,
826 ERR_R_MALLOC_FAILURE);
827 return 0;
828 }
829 i2d_X509_SIG(&sig, &ptr);
830 }
831 break;
832 default:
833 return 0;
834 }
835
836 digitalSignatureGenerate(&returnCode, &reasonCode, &exitDataLength,
837 exitData, &ruleArrayLength, ruleArray, &keyTokenLength,
838 keyToken, &length, hashBuffer, &outputLength, &outputBitLength,
839 sigret);
840
841 if (type == NID_sha1 || type == NID_md5)
842 {
843 OPENSSL_cleanse(hashBuffer, keyLength+1);
844 OPENSSL_free(hashBuffer);
845 }
846
847 *siglen = outputLength;
848
849 return ((returnCode || reasonCode) ? 0 : 1);
850 }
851
852static int getModulusAndExponent(const unsigned char*token, long *exponentLength,
853 unsigned char *exponent, long *modulusLength, long *modulusFieldLength,
854 unsigned char *modulus)
855 {
856 unsigned long len;
857
858 if (*token++ != (char)0x1E) /* internal PKA token? */
859 return 0;
860
861 if (*token++) /* token version must be zero */
862 return 0;
863
864 len = *token++;
865 len = len << 8;
866 len |= (unsigned char)*token++;
867
868 token += 4; /* skip reserved bytes */
869
870 if (*token++ == (char)0x04)
871 {
872 if (*token++) /* token version must be zero */
873 return 0;
874
875 len = *token++;
876 len = len << 8;
877 len |= (unsigned char)*token++;
878
879 token+=2; /* skip reserved section */
880
881 len = *token++;
882 len = len << 8;
883 len |= (unsigned char)*token++;
884
885 *exponentLength = len;
886
887 len = *token++;
888 len = len << 8;
889 len |= (unsigned char)*token++;
890
891 *modulusLength = len;
892
893 len = *token++;
894 len = len << 8;
895 len |= (unsigned char)*token++;
896
897 *modulusFieldLength = len;
898
899 memcpy(exponent, token, *exponentLength);
900 token+= *exponentLength;
901
902 memcpy(modulus, token, *modulusFieldLength);
903 return 1;
904 }
905 return 0;
906 }
907
908#endif /* OPENSSL_NO_RSA */
909
910static int cca_random_status(void)
911 {
912 return 1;
913 }
914
915static int cca_get_random_bytes(unsigned char* buf, int num)
916 {
917 long ret_code;
918 long reason_code;
919 long exit_data_length;
920 unsigned char exit_data[4];
921 unsigned char form[] = "RANDOM ";
922 unsigned char rand_buf[8];
923
924 while(num >= sizeof(rand_buf))
925 {
926 randomNumberGenerate(&ret_code, &reason_code, &exit_data_length,
927 exit_data, form, rand_buf);
928 if (ret_code)
929 return 0;
930 num -= sizeof(rand_buf);
931 memcpy(buf, rand_buf, sizeof(rand_buf));
932 buf += sizeof(rand_buf);
933 }
934
935 if (num)
936 {
937 randomNumberGenerate(&ret_code, &reason_code, NULL, NULL,
938 form, rand_buf);
939 if (ret_code)
940 return 0;
941 memcpy(buf, rand_buf, num);
942 }
943
944 return 1;
945 }
946
947static void cca_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad, int idx,
948 long argl, void *argp)
949 {
950 if (item)
951 OPENSSL_free(item);
952 }
953
954/* Goo to handle building as a dynamic engine */
955#ifdef ENGINE_DYNAMIC_SUPPORT
956static int bind_fn(ENGINE *e, const char *id)
957 {
958 if(id && (strcmp(id, engine_4758_cca_id) != 0))
959 return 0;
960 if(!bind_helper(e))
961 return 0;
962 return 1;
963 }
964IMPLEMENT_DYNAMIC_CHECK_FN()
965IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
966#endif /* ENGINE_DYNAMIC_SUPPORT */
967
968#endif /* !OPENSSL_NO_HW_4758_CCA */
969#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.c b/src/lib/libcrypto/engine/hw_4758_cca_err.c
new file mode 100644
index 0000000000..7ea5c63707
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca_err.c
@@ -0,0 +1,149 @@
1/* hw_4758_cca_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_4758_cca_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CCA4758_str_functs[]=
68 {
69{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_CTRL,0), "IBM_4758_CCA_CTRL"},
70{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_FINISH,0), "IBM_4758_CCA_FINISH"},
71{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_INIT,0), "IBM_4758_CCA_INIT"},
72{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY,0), "IBM_4758_CCA_LOAD_PRIVKEY"},
73{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY,0), "IBM_4758_CCA_LOAD_PUBKEY"},
74{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_SIGN,0), "IBM_4758_CCA_SIGN"},
75{ERR_PACK(0,CCA4758_F_IBM_4758_CCA_VERIFY,0), "IBM_4758_CCA_VERIFY"},
76{0,NULL}
77 };
78
79static ERR_STRING_DATA CCA4758_str_reasons[]=
80 {
81{CCA4758_R_ALREADY_LOADED ,"already loaded"},
82{CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD ,"asn1 oid unknown for md"},
83{CCA4758_R_COMMAND_NOT_IMPLEMENTED ,"command not implemented"},
84{CCA4758_R_DSO_FAILURE ,"dso failure"},
85{CCA4758_R_FAILED_LOADING_PRIVATE_KEY ,"failed loading private key"},
86{CCA4758_R_FAILED_LOADING_PUBLIC_KEY ,"failed loading public key"},
87{CCA4758_R_NOT_LOADED ,"not loaded"},
88{CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
89{CCA4758_R_UNIT_FAILURE ,"unit failure"},
90{CCA4758_R_UNKNOWN_ALGORITHM_TYPE ,"unknown algorithm type"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CCA4758_LIB_NAME
97static ERR_STRING_DATA CCA4758_lib_name[]=
98 {
99{0 ,CCA4758_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CCA4758_lib_error_code=0;
106static int CCA4758_error_init=1;
107
108static void ERR_load_CCA4758_strings(void)
109 {
110 if (CCA4758_lib_error_code == 0)
111 CCA4758_lib_error_code=ERR_get_next_error_library();
112
113 if (CCA4758_error_init)
114 {
115 CCA4758_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_functs);
118 ERR_load_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
119#endif
120
121#ifdef CCA4758_LIB_NAME
122 CCA4758_lib_name->error = ERR_PACK(CCA4758_lib_error_code,0,0);
123 ERR_load_strings(0,CCA4758_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CCA4758_strings(void)
129 {
130 if (CCA4758_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_functs);
134 ERR_unload_strings(CCA4758_lib_error_code,CCA4758_str_reasons);
135#endif
136
137#ifdef CCA4758_LIB_NAME
138 ERR_unload_strings(0,CCA4758_lib_name);
139#endif
140 CCA4758_error_init=1;
141 }
142 }
143
144static void ERR_CCA4758_error(int function, int reason, char *file, int line)
145 {
146 if (CCA4758_lib_error_code == 0)
147 CCA4758_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CCA4758_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libcrypto/engine/hw_4758_cca_err.h b/src/lib/libcrypto/engine/hw_4758_cca_err.h
new file mode 100644
index 0000000000..2fc563ab11
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_4758_cca_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_CCA4758_ERR_H
56#define HEADER_CCA4758_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CCA4758_strings(void);
63static void ERR_unload_CCA4758_strings(void);
64static void ERR_CCA4758_error(int function, int reason, char *file, int line);
65#define CCA4758err(f,r) ERR_CCA4758_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CCA4758 functions. */
68
69/* Function codes. */
70#define CCA4758_F_IBM_4758_CCA_CTRL 100
71#define CCA4758_F_IBM_4758_CCA_FINISH 101
72#define CCA4758_F_IBM_4758_CCA_INIT 102
73#define CCA4758_F_IBM_4758_CCA_LOAD_PRIVKEY 103
74#define CCA4758_F_IBM_4758_CCA_LOAD_PUBKEY 104
75#define CCA4758_F_IBM_4758_CCA_SIGN 105
76#define CCA4758_F_IBM_4758_CCA_VERIFY 106
77
78/* Reason codes. */
79#define CCA4758_R_ALREADY_LOADED 100
80#define CCA4758_R_ASN1_OID_UNKNOWN_FOR_MD 101
81#define CCA4758_R_COMMAND_NOT_IMPLEMENTED 102
82#define CCA4758_R_DSO_FAILURE 103
83#define CCA4758_R_FAILED_LOADING_PRIVATE_KEY 104
84#define CCA4758_R_FAILED_LOADING_PUBLIC_KEY 105
85#define CCA4758_R_NOT_LOADED 106
86#define CCA4758_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
87#define CCA4758_R_UNIT_FAILURE 108
88#define CCA4758_R_UNKNOWN_ALGORITHM_TYPE 109
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libcrypto/engine/hw_aep.c b/src/lib/libcrypto/engine/hw_aep.c
new file mode 100644
index 0000000000..5f1772ea99
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep.c
@@ -0,0 +1,1120 @@
1/* crypto/engine/hw_aep.c */
2/*
3 */
4/* ====================================================================
5 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
17 * distribution.
18 *
19 * 3. All advertising materials mentioning features or use of this
20 * software must display the following acknowledgment:
21 * "This product includes software developed by the OpenSSL Project
22 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
23 *
24 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25 * endorse or promote products derived from this software without
26 * prior written permission. For written permission, please contact
27 * licensing@OpenSSL.org.
28 *
29 * 5. Products derived from this software may not be called "OpenSSL"
30 * nor may "OpenSSL" appear in their names without prior written
31 * permission of the OpenSSL Project.
32 *
33 * 6. Redistributions of any form whatsoever must retain the following
34 * acknowledgment:
35 * "This product includes software developed by the OpenSSL Project
36 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
37 *
38 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
42 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49 * OF THE POSSIBILITY OF SUCH DAMAGE.
50 * ====================================================================
51 *
52 * This product includes cryptographic software written by Eric Young
53 * (eay@cryptsoft.com). This product includes software written by Tim
54 * Hudson (tjh@cryptsoft.com).
55 *
56 */
57
58#include <stdio.h>
59#include <openssl/bn.h>
60#include <string.h>
61
62#include <openssl/e_os2.h>
63#if !defined(OPENSSL_SYS_MSDOS) || defined(__DJGPP__)
64#include <sys/types.h>
65#include <unistd.h>
66#else
67#include <process.h>
68typedef int pid_t;
69#endif
70
71#include <openssl/crypto.h>
72#include <openssl/dso.h>
73#include <openssl/engine.h>
74#include <openssl/buffer.h>
75
76#ifndef OPENSSL_NO_HW
77#ifndef OPENSSL_NO_HW_AEP
78#ifdef FLAT_INC
79#include "aep.h"
80#else
81#include "vendor_defns/aep.h"
82#endif
83
84#define AEP_LIB_NAME "aep engine"
85#define FAIL_TO_SW 0x10101010
86
87#include "hw_aep_err.c"
88
89static int aep_init(ENGINE *e);
90static int aep_finish(ENGINE *e);
91static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
92static int aep_destroy(ENGINE *e);
93
94static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR hConnection);
95static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection);
96static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection);
97static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use);
98
99/* BIGNUM stuff */
100static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
101 const BIGNUM *m, BN_CTX *ctx);
102
103static AEP_RV aep_mod_exp_crt(BIGNUM *r,const BIGNUM *a, const BIGNUM *p,
104 const BIGNUM *q, const BIGNUM *dmp1,const BIGNUM *dmq1,
105 const BIGNUM *iqmp, BN_CTX *ctx);
106
107/* RSA stuff */
108#ifndef OPENSSL_NO_RSA
109static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
110#endif
111
112/* This function is aliased to mod_exp (with the mont stuff dropped). */
113static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
114 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
115
116/* DSA stuff */
117#ifndef OPENSSL_NO_DSA
118static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
119 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
120 BN_CTX *ctx, BN_MONT_CTX *in_mont);
121
122static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
123 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
124 BN_MONT_CTX *m_ctx);
125#endif
126
127/* DH stuff */
128/* This function is aliased to mod_exp (with the DH and mont dropped). */
129#ifndef OPENSSL_NO_DH
130static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
131 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
132#endif
133
134/* rand stuff */
135#ifdef AEPRAND
136static int aep_rand(unsigned char *buf, int num);
137static int aep_rand_status(void);
138#endif
139
140/* Bignum conversion stuff */
141static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize);
142static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
143 unsigned char* AEP_BigNum);
144static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
145 unsigned char* AEP_BigNum);
146
147/* The definitions for control commands specific to this engine */
148#define AEP_CMD_SO_PATH ENGINE_CMD_BASE
149static const ENGINE_CMD_DEFN aep_cmd_defns[] =
150 {
151 { AEP_CMD_SO_PATH,
152 "SO_PATH",
153 "Specifies the path to the 'aep' shared library",
154 ENGINE_CMD_FLAG_STRING
155 },
156 {0, NULL, NULL, 0}
157 };
158
159#ifndef OPENSSL_NO_RSA
160/* Our internal RSA_METHOD that we provide pointers to */
161static RSA_METHOD aep_rsa =
162 {
163 "Aep RSA method",
164 NULL, /*rsa_pub_encrypt*/
165 NULL, /*rsa_pub_decrypt*/
166 NULL, /*rsa_priv_encrypt*/
167 NULL, /*rsa_priv_encrypt*/
168 aep_rsa_mod_exp, /*rsa_mod_exp*/
169 aep_mod_exp_mont, /*bn_mod_exp*/
170 NULL, /*init*/
171 NULL, /*finish*/
172 0, /*flags*/
173 NULL, /*app_data*/
174 NULL, /*rsa_sign*/
175 NULL /*rsa_verify*/
176 };
177#endif
178
179#ifndef OPENSSL_NO_DSA
180/* Our internal DSA_METHOD that we provide pointers to */
181static DSA_METHOD aep_dsa =
182 {
183 "Aep DSA method",
184 NULL, /* dsa_do_sign */
185 NULL, /* dsa_sign_setup */
186 NULL, /* dsa_do_verify */
187 aep_dsa_mod_exp, /* dsa_mod_exp */
188 aep_mod_exp_dsa, /* bn_mod_exp */
189 NULL, /* init */
190 NULL, /* finish */
191 0, /* flags */
192 NULL /* app_data */
193 };
194#endif
195
196#ifndef OPENSSL_NO_DH
197/* Our internal DH_METHOD that we provide pointers to */
198static DH_METHOD aep_dh =
199 {
200 "Aep DH method",
201 NULL,
202 NULL,
203 aep_mod_exp_dh,
204 NULL,
205 NULL,
206 0,
207 NULL
208 };
209#endif
210
211#ifdef AEPRAND
212/* our internal RAND_method that we provide pointers to */
213static RAND_METHOD aep_random =
214 {
215 /*"AEP RAND method", */
216 NULL,
217 aep_rand,
218 NULL,
219 NULL,
220 aep_rand,
221 aep_rand_status,
222 };
223#endif
224
225/*Define an array of structures to hold connections*/
226static AEP_CONNECTION_ENTRY aep_app_conn_table[MAX_PROCESS_CONNECTIONS];
227
228/*Used to determine if this is a new process*/
229static pid_t recorded_pid = 0;
230
231#ifdef AEPRAND
232static AEP_U8 rand_block[RAND_BLK_SIZE];
233static AEP_U32 rand_block_bytes = 0;
234#endif
235
236/* Constants used when creating the ENGINE */
237static const char *engine_aep_id = "aep";
238static const char *engine_aep_name = "Aep hardware engine support";
239
240static int max_key_len = 2176;
241
242
243/* This internal function is used by ENGINE_aep() and possibly by the
244 * "dynamic" ENGINE support too */
245static int bind_aep(ENGINE *e)
246 {
247#ifndef OPENSSL_NO_RSA
248 const RSA_METHOD *meth1;
249#endif
250#ifndef OPENSSL_NO_DSA
251 const DSA_METHOD *meth2;
252#endif
253#ifndef OPENSSL_NO_DH
254 const DH_METHOD *meth3;
255#endif
256
257 if(!ENGINE_set_id(e, engine_aep_id) ||
258 !ENGINE_set_name(e, engine_aep_name) ||
259#ifndef OPENSSL_NO_RSA
260 !ENGINE_set_RSA(e, &aep_rsa) ||
261#endif
262#ifndef OPENSSL_NO_DSA
263 !ENGINE_set_DSA(e, &aep_dsa) ||
264#endif
265#ifndef OPENSSL_NO_DH
266 !ENGINE_set_DH(e, &aep_dh) ||
267#endif
268#ifdef AEPRAND
269 !ENGINE_set_RAND(e, &aep_random) ||
270#endif
271 !ENGINE_set_init_function(e, aep_init) ||
272 !ENGINE_set_destroy_function(e, aep_destroy) ||
273 !ENGINE_set_finish_function(e, aep_finish) ||
274 !ENGINE_set_ctrl_function(e, aep_ctrl) ||
275 !ENGINE_set_cmd_defns(e, aep_cmd_defns))
276 return 0;
277
278#ifndef OPENSSL_NO_RSA
279 /* We know that the "PKCS1_SSLeay()" functions hook properly
280 * to the aep-specific mod_exp and mod_exp_crt so we use
281 * those functions. NB: We don't use ENGINE_openssl() or
282 * anything "more generic" because something like the RSAref
283 * code may not hook properly, and if you own one of these
284 * cards then you have the right to do RSA operations on it
285 * anyway! */
286 meth1 = RSA_PKCS1_SSLeay();
287 aep_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
288 aep_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
289 aep_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
290 aep_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
291#endif
292
293
294#ifndef OPENSSL_NO_DSA
295 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
296 * bits. */
297 meth2 = DSA_OpenSSL();
298 aep_dsa.dsa_do_sign = meth2->dsa_do_sign;
299 aep_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
300 aep_dsa.dsa_do_verify = meth2->dsa_do_verify;
301
302 aep_dsa = *DSA_get_default_method();
303 aep_dsa.dsa_mod_exp = aep_dsa_mod_exp;
304 aep_dsa.bn_mod_exp = aep_mod_exp_dsa;
305#endif
306
307#ifndef OPENSSL_NO_DH
308 /* Much the same for Diffie-Hellman */
309 meth3 = DH_OpenSSL();
310 aep_dh.generate_key = meth3->generate_key;
311 aep_dh.compute_key = meth3->compute_key;
312 aep_dh.bn_mod_exp = meth3->bn_mod_exp;
313#endif
314
315 /* Ensure the aep error handling is set up */
316 ERR_load_AEPHK_strings();
317
318 return 1;
319}
320
321#ifdef ENGINE_DYNAMIC_SUPPORT
322static int bind_helper(ENGINE *e, const char *id)
323 {
324 if(id && (strcmp(id, engine_aep_id) != 0))
325 return 0;
326 if(!bind_aep(e))
327 return 0;
328 return 1;
329 }
330IMPLEMENT_DYNAMIC_CHECK_FN()
331IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
332#else
333static ENGINE *engine_aep(void)
334 {
335 ENGINE *ret = ENGINE_new();
336 if(!ret)
337 return NULL;
338 if(!bind_aep(ret))
339 {
340 ENGINE_free(ret);
341 return NULL;
342 }
343 return ret;
344 }
345
346void ENGINE_load_aep(void)
347 {
348 /* Copied from eng_[openssl|dyn].c */
349 ENGINE *toadd = engine_aep();
350 if(!toadd) return;
351 ENGINE_add(toadd);
352 ENGINE_free(toadd);
353 ERR_clear_error();
354 }
355#endif
356
357/* This is a process-global DSO handle used for loading and unloading
358 * the Aep library. NB: This is only set (or unset) during an
359 * init() or finish() call (reference counts permitting) and they're
360 * operating with global locks, so this should be thread-safe
361 * implicitly. */
362static DSO *aep_dso = NULL;
363
364/* These are the static string constants for the DSO file name and the function
365 * symbol names to bind to.
366*/
367static const char *AEP_LIBNAME = NULL;
368static const char *get_AEP_LIBNAME(void)
369 {
370 if(AEP_LIBNAME)
371 return AEP_LIBNAME;
372 return "aep";
373 }
374static void free_AEP_LIBNAME(void)
375 {
376 if(AEP_LIBNAME)
377 OPENSSL_free((void*)AEP_LIBNAME);
378 AEP_LIBNAME = NULL;
379 }
380static long set_AEP_LIBNAME(const char *name)
381 {
382 free_AEP_LIBNAME();
383 return ((AEP_LIBNAME = BUF_strdup(name)) != NULL ? 1 : 0);
384 }
385
386static const char *AEP_F1 = "AEP_ModExp";
387static const char *AEP_F2 = "AEP_ModExpCrt";
388#ifdef AEPRAND
389static const char *AEP_F3 = "AEP_GenRandom";
390#endif
391static const char *AEP_F4 = "AEP_Finalize";
392static const char *AEP_F5 = "AEP_Initialize";
393static const char *AEP_F6 = "AEP_OpenConnection";
394static const char *AEP_F7 = "AEP_SetBNCallBacks";
395static const char *AEP_F8 = "AEP_CloseConnection";
396
397/* These are the function pointers that are (un)set when the library has
398 * successfully (un)loaded. */
399static t_AEP_OpenConnection *p_AEP_OpenConnection = NULL;
400static t_AEP_CloseConnection *p_AEP_CloseConnection = NULL;
401static t_AEP_ModExp *p_AEP_ModExp = NULL;
402static t_AEP_ModExpCrt *p_AEP_ModExpCrt = NULL;
403#ifdef AEPRAND
404static t_AEP_GenRandom *p_AEP_GenRandom = NULL;
405#endif
406static t_AEP_Initialize *p_AEP_Initialize = NULL;
407static t_AEP_Finalize *p_AEP_Finalize = NULL;
408static t_AEP_SetBNCallBacks *p_AEP_SetBNCallBacks = NULL;
409
410/* (de)initialisation functions. */
411static int aep_init(ENGINE *e)
412 {
413 t_AEP_ModExp *p1;
414 t_AEP_ModExpCrt *p2;
415#ifdef AEPRAND
416 t_AEP_GenRandom *p3;
417#endif
418 t_AEP_Finalize *p4;
419 t_AEP_Initialize *p5;
420 t_AEP_OpenConnection *p6;
421 t_AEP_SetBNCallBacks *p7;
422 t_AEP_CloseConnection *p8;
423
424 int to_return = 0;
425
426 if(aep_dso != NULL)
427 {
428 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_ALREADY_LOADED);
429 goto err;
430 }
431 /* Attempt to load libaep.so. */
432
433 aep_dso = DSO_load(NULL, get_AEP_LIBNAME(), NULL, 0);
434
435 if(aep_dso == NULL)
436 {
437 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
438 goto err;
439 }
440
441 if( !(p1 = (t_AEP_ModExp *) DSO_bind_func( aep_dso,AEP_F1)) ||
442 !(p2 = (t_AEP_ModExpCrt*) DSO_bind_func( aep_dso,AEP_F2)) ||
443#ifdef AEPRAND
444 !(p3 = (t_AEP_GenRandom*) DSO_bind_func( aep_dso,AEP_F3)) ||
445#endif
446 !(p4 = (t_AEP_Finalize*) DSO_bind_func( aep_dso,AEP_F4)) ||
447 !(p5 = (t_AEP_Initialize*) DSO_bind_func( aep_dso,AEP_F5)) ||
448 !(p6 = (t_AEP_OpenConnection*) DSO_bind_func( aep_dso,AEP_F6)) ||
449 !(p7 = (t_AEP_SetBNCallBacks*) DSO_bind_func( aep_dso,AEP_F7)) ||
450 !(p8 = (t_AEP_CloseConnection*) DSO_bind_func( aep_dso,AEP_F8)))
451 {
452 AEPHKerr(AEPHK_F_AEP_INIT,AEPHK_R_NOT_LOADED);
453 goto err;
454 }
455
456 /* Copy the pointers */
457
458 p_AEP_ModExp = p1;
459 p_AEP_ModExpCrt = p2;
460#ifdef AEPRAND
461 p_AEP_GenRandom = p3;
462#endif
463 p_AEP_Finalize = p4;
464 p_AEP_Initialize = p5;
465 p_AEP_OpenConnection = p6;
466 p_AEP_SetBNCallBacks = p7;
467 p_AEP_CloseConnection = p8;
468
469 to_return = 1;
470
471 return to_return;
472
473 err:
474
475 if(aep_dso)
476 DSO_free(aep_dso);
477 aep_dso = NULL;
478
479 p_AEP_OpenConnection = NULL;
480 p_AEP_ModExp = NULL;
481 p_AEP_ModExpCrt = NULL;
482#ifdef AEPRAND
483 p_AEP_GenRandom = NULL;
484#endif
485 p_AEP_Initialize = NULL;
486 p_AEP_Finalize = NULL;
487 p_AEP_SetBNCallBacks = NULL;
488 p_AEP_CloseConnection = NULL;
489
490 return to_return;
491 }
492
493/* Destructor (complements the "ENGINE_aep()" constructor) */
494static int aep_destroy(ENGINE *e)
495 {
496 free_AEP_LIBNAME();
497 ERR_unload_AEPHK_strings();
498 return 1;
499 }
500
501static int aep_finish(ENGINE *e)
502 {
503 int to_return = 0, in_use;
504 AEP_RV rv;
505
506 if(aep_dso == NULL)
507 {
508 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_NOT_LOADED);
509 goto err;
510 }
511
512 rv = aep_close_all_connections(0, &in_use);
513 if (rv != AEP_R_OK)
514 {
515 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CLOSE_HANDLES_FAILED);
516 goto err;
517 }
518 if (in_use)
519 {
520 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_CONNECTIONS_IN_USE);
521 goto err;
522 }
523
524 rv = p_AEP_Finalize();
525 if (rv != AEP_R_OK)
526 {
527 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_FINALIZE_FAILED);
528 goto err;
529 }
530
531 if(!DSO_free(aep_dso))
532 {
533 AEPHKerr(AEPHK_F_AEP_FINISH,AEPHK_R_UNIT_FAILURE);
534 goto err;
535 }
536
537 aep_dso = NULL;
538 p_AEP_CloseConnection = NULL;
539 p_AEP_OpenConnection = NULL;
540 p_AEP_ModExp = NULL;
541 p_AEP_ModExpCrt = NULL;
542#ifdef AEPRAND
543 p_AEP_GenRandom = NULL;
544#endif
545 p_AEP_Initialize = NULL;
546 p_AEP_Finalize = NULL;
547 p_AEP_SetBNCallBacks = NULL;
548
549 to_return = 1;
550 err:
551 return to_return;
552 }
553
554static int aep_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
555 {
556 int initialised = ((aep_dso == NULL) ? 0 : 1);
557 switch(cmd)
558 {
559 case AEP_CMD_SO_PATH:
560 if(p == NULL)
561 {
562 AEPHKerr(AEPHK_F_AEP_CTRL,
563 ERR_R_PASSED_NULL_PARAMETER);
564 return 0;
565 }
566 if(initialised)
567 {
568 AEPHKerr(AEPHK_F_AEP_CTRL,
569 AEPHK_R_ALREADY_LOADED);
570 return 0;
571 }
572 return set_AEP_LIBNAME((const char*)p);
573 default:
574 break;
575 }
576 AEPHKerr(AEPHK_F_AEP_CTRL,AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED);
577 return 0;
578 }
579
580static int aep_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
581 const BIGNUM *m, BN_CTX *ctx)
582 {
583 int to_return = 0;
584 int r_len = 0;
585 AEP_CONNECTION_HNDL hConnection;
586 AEP_RV rv;
587
588 r_len = BN_num_bits(m);
589
590 /* Perform in software if modulus is too large for hardware. */
591
592 if (r_len > max_key_len){
593 AEPHKerr(AEPHK_F_AEP_MOD_EXP, AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
594 return BN_mod_exp(r, a, p, m, ctx);
595 }
596
597 /*Grab a connection from the pool*/
598 rv = aep_get_connection(&hConnection);
599 if (rv != AEP_R_OK)
600 {
601 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_GET_HANDLE_FAILED);
602 return BN_mod_exp(r, a, p, m, ctx);
603 }
604
605 /*To the card with the mod exp*/
606 rv = p_AEP_ModExp(hConnection,(void*)a, (void*)p,(void*)m, (void*)r,NULL);
607
608 if (rv != AEP_R_OK)
609 {
610 AEPHKerr(AEPHK_F_AEP_MOD_EXP,AEPHK_R_MOD_EXP_FAILED);
611 rv = aep_close_connection(hConnection);
612 return BN_mod_exp(r, a, p, m, ctx);
613 }
614
615 /*Return the connection to the pool*/
616 rv = aep_return_connection(hConnection);
617 if (rv != AEP_R_OK)
618 {
619 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
620 goto err;
621 }
622
623 to_return = 1;
624 err:
625 return to_return;
626 }
627
628static AEP_RV aep_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
629 const BIGNUM *q, const BIGNUM *dmp1,
630 const BIGNUM *dmq1,const BIGNUM *iqmp, BN_CTX *ctx)
631 {
632 AEP_RV rv = AEP_R_OK;
633 AEP_CONNECTION_HNDL hConnection;
634
635 /*Grab a connection from the pool*/
636 rv = aep_get_connection(&hConnection);
637 if (rv != AEP_R_OK)
638 {
639 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_GET_HANDLE_FAILED);
640 return FAIL_TO_SW;
641 }
642
643 /*To the card with the mod exp*/
644 rv = p_AEP_ModExpCrt(hConnection,(void*)a, (void*)p, (void*)q, (void*)dmp1,(void*)dmq1,
645 (void*)iqmp,(void*)r,NULL);
646 if (rv != AEP_R_OK)
647 {
648 AEPHKerr(AEPHK_F_AEP_MOD_EXP_CRT,AEPHK_R_MOD_EXP_CRT_FAILED);
649 rv = aep_close_connection(hConnection);
650 return FAIL_TO_SW;
651 }
652
653 /*Return the connection to the pool*/
654 rv = aep_return_connection(hConnection);
655 if (rv != AEP_R_OK)
656 {
657 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
658 goto err;
659 }
660
661 err:
662 return rv;
663 }
664
665
666#ifdef AEPRAND
667static int aep_rand(unsigned char *buf,int len )
668 {
669 AEP_RV rv = AEP_R_OK;
670 AEP_CONNECTION_HNDL hConnection;
671
672 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
673
674 /*Can the request be serviced with what's already in the buffer?*/
675 if (len <= rand_block_bytes)
676 {
677 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
678 rand_block_bytes -= len;
679 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
680 }
681 else
682 /*If not the get another block of random bytes*/
683 {
684 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
685
686 rv = aep_get_connection(&hConnection);
687 if (rv != AEP_R_OK)
688 {
689 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_HANDLE_FAILED);
690 goto err_nounlock;
691 }
692
693 if (len > RAND_BLK_SIZE)
694 {
695 rv = p_AEP_GenRandom(hConnection, len, 2, buf, NULL);
696 if (rv != AEP_R_OK)
697 {
698 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
699 goto err_nounlock;
700 }
701 }
702 else
703 {
704 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
705
706 rv = p_AEP_GenRandom(hConnection, RAND_BLK_SIZE, 2, &rand_block[0], NULL);
707 if (rv != AEP_R_OK)
708 {
709 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_GET_RANDOM_FAILED);
710
711 goto err;
712 }
713
714 rand_block_bytes = RAND_BLK_SIZE;
715
716 memcpy(buf, &rand_block[RAND_BLK_SIZE - rand_block_bytes], len);
717 rand_block_bytes -= len;
718
719 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
720 }
721
722 rv = aep_return_connection(hConnection);
723 if (rv != AEP_R_OK)
724 {
725 AEPHKerr(AEPHK_F_AEP_RAND,AEPHK_R_RETURN_CONNECTION_FAILED);
726
727 goto err_nounlock;
728 }
729 }
730
731 return 1;
732 err:
733 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
734 err_nounlock:
735 return 0;
736 }
737
738static int aep_rand_status(void)
739{
740 return 1;
741}
742#endif
743
744#ifndef OPENSSL_NO_RSA
745static int aep_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
746 {
747 BN_CTX *ctx = NULL;
748 int to_return = 0;
749 AEP_RV rv = AEP_R_OK;
750
751 if ((ctx = BN_CTX_new()) == NULL)
752 goto err;
753
754 if (!aep_dso)
755 {
756 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_NOT_LOADED);
757 goto err;
758 }
759
760 /*See if we have all the necessary bits for a crt*/
761 if (rsa->q && rsa->dmp1 && rsa->dmq1 && rsa->iqmp)
762 {
763 rv = aep_mod_exp_crt(r0,I,rsa->p,rsa->q, rsa->dmp1,rsa->dmq1,rsa->iqmp,ctx);
764
765 if (rv == FAIL_TO_SW){
766 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
767 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
768 goto err;
769 }
770 else if (rv != AEP_R_OK)
771 goto err;
772 }
773 else
774 {
775 if (!rsa->d || !rsa->n)
776 {
777 AEPHKerr(AEPHK_F_AEP_RSA_MOD_EXP,AEPHK_R_MISSING_KEY_COMPONENTS);
778 goto err;
779 }
780
781 rv = aep_mod_exp(r0,I,rsa->d,rsa->n,ctx);
782 if (rv != AEP_R_OK)
783 goto err;
784
785 }
786
787 to_return = 1;
788
789 err:
790 if(ctx)
791 BN_CTX_free(ctx);
792 return to_return;
793}
794#endif
795
796#ifndef OPENSSL_NO_DSA
797static int aep_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
798 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
799 BN_CTX *ctx, BN_MONT_CTX *in_mont)
800 {
801 BIGNUM t;
802 int to_return = 0;
803 BN_init(&t);
804
805 /* let rr = a1 ^ p1 mod m */
806 if (!aep_mod_exp(rr,a1,p1,m,ctx)) goto end;
807 /* let t = a2 ^ p2 mod m */
808 if (!aep_mod_exp(&t,a2,p2,m,ctx)) goto end;
809 /* let rr = rr * t mod m */
810 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
811 to_return = 1;
812 end:
813 BN_free(&t);
814 return to_return;
815 }
816
817static int aep_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
818 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
819 BN_MONT_CTX *m_ctx)
820 {
821 return aep_mod_exp(r, a, p, m, ctx);
822 }
823#endif
824
825/* This function is aliased to mod_exp (with the mont stuff dropped). */
826static int aep_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
827 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
828 {
829 return aep_mod_exp(r, a, p, m, ctx);
830 }
831
832#ifndef OPENSSL_NO_DH
833/* This function is aliased to mod_exp (with the dh and mont dropped). */
834static int aep_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
835 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
836 BN_MONT_CTX *m_ctx)
837 {
838 return aep_mod_exp(r, a, p, m, ctx);
839 }
840#endif
841
842static AEP_RV aep_get_connection(AEP_CONNECTION_HNDL_PTR phConnection)
843 {
844 int count;
845 AEP_RV rv = AEP_R_OK;
846
847 /*Get the current process id*/
848 pid_t curr_pid;
849
850 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
851
852 curr_pid = getpid();
853
854 /*Check if this is the first time this is being called from the current
855 process*/
856 if (recorded_pid != curr_pid)
857 {
858 /*Remember our pid so we can check if we're in a new process*/
859 recorded_pid = curr_pid;
860
861 /*Call Finalize to make sure we have not inherited some data
862 from a parent process*/
863 p_AEP_Finalize();
864
865 /*Initialise the AEP API*/
866 rv = p_AEP_Initialize(NULL);
867
868 if (rv != AEP_R_OK)
869 {
870 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_INIT_FAILURE);
871 recorded_pid = 0;
872 goto end;
873 }
874
875 /*Set the AEP big num call back functions*/
876 rv = p_AEP_SetBNCallBacks(&GetBigNumSize, &MakeAEPBigNum,
877 &ConvertAEPBigNum);
878
879 if (rv != AEP_R_OK)
880 {
881 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_SETBNCALLBACK_FAILURE);
882 recorded_pid = 0;
883 goto end;
884 }
885
886#ifdef AEPRAND
887 /*Reset the rand byte count*/
888 rand_block_bytes = 0;
889#endif
890
891 /*Init the structures*/
892 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
893 {
894 aep_app_conn_table[count].conn_state = NotConnected;
895 aep_app_conn_table[count].conn_hndl = 0;
896 }
897
898 /*Open a connection*/
899 rv = p_AEP_OpenConnection(phConnection);
900
901 if (rv != AEP_R_OK)
902 {
903 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
904 recorded_pid = 0;
905 goto end;
906 }
907
908 aep_app_conn_table[0].conn_state = InUse;
909 aep_app_conn_table[0].conn_hndl = *phConnection;
910 goto end;
911 }
912 /*Check the existing connections to see if we can find a free one*/
913 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
914 {
915 if (aep_app_conn_table[count].conn_state == Connected)
916 {
917 aep_app_conn_table[count].conn_state = InUse;
918 *phConnection = aep_app_conn_table[count].conn_hndl;
919 goto end;
920 }
921 }
922 /*If no connections available, we're going to have to try
923 to open a new one*/
924 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
925 {
926 if (aep_app_conn_table[count].conn_state == NotConnected)
927 {
928 /*Open a connection*/
929 rv = p_AEP_OpenConnection(phConnection);
930
931 if (rv != AEP_R_OK)
932 {
933 AEPHKerr(AEPHK_F_AEP_GET_CONNECTION,AEPHK_R_UNIT_FAILURE);
934 goto end;
935 }
936
937 aep_app_conn_table[count].conn_state = InUse;
938 aep_app_conn_table[count].conn_hndl = *phConnection;
939 goto end;
940 }
941 }
942 rv = AEP_R_GENERAL_ERROR;
943 end:
944 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
945 return rv;
946 }
947
948
949static AEP_RV aep_return_connection(AEP_CONNECTION_HNDL hConnection)
950 {
951 int count;
952
953 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
954
955 /*Find the connection item that matches this connection handle*/
956 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
957 {
958 if (aep_app_conn_table[count].conn_hndl == hConnection)
959 {
960 aep_app_conn_table[count].conn_state = Connected;
961 break;
962 }
963 }
964
965 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
966
967 return AEP_R_OK;
968 }
969
970static AEP_RV aep_close_connection(AEP_CONNECTION_HNDL hConnection)
971 {
972 int count;
973 AEP_RV rv = AEP_R_OK;
974
975 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
976
977 /*Find the connection item that matches this connection handle*/
978 for(count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
979 {
980 if (aep_app_conn_table[count].conn_hndl == hConnection)
981 {
982 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
983 if (rv != AEP_R_OK)
984 goto end;
985 aep_app_conn_table[count].conn_state = NotConnected;
986 aep_app_conn_table[count].conn_hndl = 0;
987 break;
988 }
989 }
990
991 end:
992 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
993 return rv;
994 }
995
996static AEP_RV aep_close_all_connections(int use_engine_lock, int *in_use)
997 {
998 int count;
999 AEP_RV rv = AEP_R_OK;
1000
1001 *in_use = 0;
1002 if (use_engine_lock) CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
1003 for (count = 0;count < MAX_PROCESS_CONNECTIONS;count ++)
1004 {
1005 switch (aep_app_conn_table[count].conn_state)
1006 {
1007 case Connected:
1008 rv = p_AEP_CloseConnection(aep_app_conn_table[count].conn_hndl);
1009 if (rv != AEP_R_OK)
1010 goto end;
1011 aep_app_conn_table[count].conn_state = NotConnected;
1012 aep_app_conn_table[count].conn_hndl = 0;
1013 break;
1014 case InUse:
1015 (*in_use)++;
1016 break;
1017 case NotConnected:
1018 break;
1019 }
1020 }
1021 end:
1022 if (use_engine_lock) CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
1023 return rv;
1024 }
1025
1026/*BigNum call back functions, used to convert OpenSSL bignums into AEP bignums.
1027 Note only 32bit Openssl build support*/
1028
1029static AEP_RV GetBigNumSize(AEP_VOID_PTR ArbBigNum, AEP_U32* BigNumSize)
1030 {
1031 BIGNUM* bn;
1032
1033 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1034 bn = (BIGNUM*) ArbBigNum;
1035
1036#ifdef SIXTY_FOUR_BIT_LONG
1037 *BigNumSize = bn->top << 3;
1038#else
1039 /*Size of the bignum in bytes is equal to the bn->top (no of 32 bit
1040 words) multiplies by 4*/
1041 *BigNumSize = bn->top << 2;
1042#endif
1043
1044 return AEP_R_OK;
1045 }
1046
1047static AEP_RV MakeAEPBigNum(AEP_VOID_PTR ArbBigNum, AEP_U32 BigNumSize,
1048 unsigned char* AEP_BigNum)
1049 {
1050 BIGNUM* bn;
1051
1052#ifndef SIXTY_FOUR_BIT_LONG
1053 unsigned char* buf;
1054 int i;
1055#endif
1056
1057 /*Cast the ArbBigNum pointer to our BIGNUM struct*/
1058 bn = (BIGNUM*) ArbBigNum;
1059
1060#ifdef SIXTY_FOUR_BIT_LONG
1061 memcpy(AEP_BigNum, bn->d, BigNumSize);
1062#else
1063 /*Must copy data into a (monotone) least significant byte first format
1064 performing endian conversion if necessary*/
1065 for(i=0;i<bn->top;i++)
1066 {
1067 buf = (unsigned char*)&bn->d[i];
1068
1069 *((AEP_U32*)AEP_BigNum) = (AEP_U32)
1070 ((unsigned) buf[1] << 8 | buf[0]) |
1071 ((unsigned) buf[3] << 8 | buf[2]) << 16;
1072
1073 AEP_BigNum += 4;
1074 }
1075#endif
1076
1077 return AEP_R_OK;
1078 }
1079
1080/*Turn an AEP Big Num back to a user big num*/
1081static AEP_RV ConvertAEPBigNum(void* ArbBigNum, AEP_U32 BigNumSize,
1082 unsigned char* AEP_BigNum)
1083 {
1084 BIGNUM* bn;
1085#ifndef SIXTY_FOUR_BIT_LONG
1086 int i;
1087#endif
1088
1089 bn = (BIGNUM*)ArbBigNum;
1090
1091 /*Expand the result bn so that it can hold our big num.
1092 Size is in bits*/
1093 bn_expand(bn, (int)(BigNumSize << 3));
1094
1095#ifdef SIXTY_FOUR_BIT_LONG
1096 bn->top = BigNumSize >> 3;
1097
1098 if((BigNumSize & 7) != 0)
1099 bn->top++;
1100
1101 memset(bn->d, 0, bn->top << 3);
1102
1103 memcpy(bn->d, AEP_BigNum, BigNumSize);
1104#else
1105 bn->top = BigNumSize >> 2;
1106
1107 for(i=0;i<bn->top;i++)
1108 {
1109 bn->d[i] = (AEP_U32)
1110 ((unsigned) AEP_BigNum[3] << 8 | AEP_BigNum[2]) << 16 |
1111 ((unsigned) AEP_BigNum[1] << 8 | AEP_BigNum[0]);
1112 AEP_BigNum += 4;
1113 }
1114#endif
1115
1116 return AEP_R_OK;
1117}
1118
1119#endif /* !OPENSSL_NO_HW_AEP */
1120#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_aep_err.c b/src/lib/libcrypto/engine/hw_aep_err.c
new file mode 100644
index 0000000000..092f532946
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep_err.c
@@ -0,0 +1,157 @@
1/* hw_aep_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_aep_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA AEPHK_str_functs[]=
68 {
69{ERR_PACK(0,AEPHK_F_AEP_CTRL,0), "AEP_CTRL"},
70{ERR_PACK(0,AEPHK_F_AEP_FINISH,0), "AEP_FINISH"},
71{ERR_PACK(0,AEPHK_F_AEP_GET_CONNECTION,0), "AEP_GET_CONNECTION"},
72{ERR_PACK(0,AEPHK_F_AEP_INIT,0), "AEP_INIT"},
73{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP,0), "AEP_MOD_EXP"},
74{ERR_PACK(0,AEPHK_F_AEP_MOD_EXP_CRT,0), "AEP_MOD_EXP_CRT"},
75{ERR_PACK(0,AEPHK_F_AEP_RAND,0), "AEP_RAND"},
76{ERR_PACK(0,AEPHK_F_AEP_RSA_MOD_EXP,0), "AEP_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA AEPHK_str_reasons[]=
81 {
82{AEPHK_R_ALREADY_LOADED ,"already loaded"},
83{AEPHK_R_CLOSE_HANDLES_FAILED ,"close handles failed"},
84{AEPHK_R_CONNECTIONS_IN_USE ,"connections in use"},
85{AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
86{AEPHK_R_FINALIZE_FAILED ,"finalize failed"},
87{AEPHK_R_GET_HANDLE_FAILED ,"get handle failed"},
88{AEPHK_R_GET_RANDOM_FAILED ,"get random failed"},
89{AEPHK_R_INIT_FAILURE ,"init failure"},
90{AEPHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
91{AEPHK_R_MOD_EXP_CRT_FAILED ,"mod exp crt failed"},
92{AEPHK_R_MOD_EXP_FAILED ,"mod exp failed"},
93{AEPHK_R_NOT_LOADED ,"not loaded"},
94{AEPHK_R_OK ,"ok"},
95{AEPHK_R_RETURN_CONNECTION_FAILED ,"return connection failed"},
96{AEPHK_R_SETBNCALLBACK_FAILURE ,"setbncallback failure"},
97{AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
98{AEPHK_R_UNIT_FAILURE ,"unit failure"},
99{0,NULL}
100 };
101
102#endif
103
104#ifdef AEPHK_LIB_NAME
105static ERR_STRING_DATA AEPHK_lib_name[]=
106 {
107{0 ,AEPHK_LIB_NAME},
108{0,NULL}
109 };
110#endif
111
112
113static int AEPHK_lib_error_code=0;
114static int AEPHK_error_init=1;
115
116static void ERR_load_AEPHK_strings(void)
117 {
118 if (AEPHK_lib_error_code == 0)
119 AEPHK_lib_error_code=ERR_get_next_error_library();
120
121 if (AEPHK_error_init)
122 {
123 AEPHK_error_init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_functs);
126 ERR_load_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
127#endif
128
129#ifdef AEPHK_LIB_NAME
130 AEPHK_lib_name->error = ERR_PACK(AEPHK_lib_error_code,0,0);
131 ERR_load_strings(0,AEPHK_lib_name);
132#endif
133 }
134 }
135
136static void ERR_unload_AEPHK_strings(void)
137 {
138 if (AEPHK_error_init == 0)
139 {
140#ifndef OPENSSL_NO_ERR
141 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_functs);
142 ERR_unload_strings(AEPHK_lib_error_code,AEPHK_str_reasons);
143#endif
144
145#ifdef AEPHK_LIB_NAME
146 ERR_unload_strings(0,AEPHK_lib_name);
147#endif
148 AEPHK_error_init=1;
149 }
150 }
151
152static void ERR_AEPHK_error(int function, int reason, char *file, int line)
153 {
154 if (AEPHK_lib_error_code == 0)
155 AEPHK_lib_error_code=ERR_get_next_error_library();
156 ERR_PUT_error(AEPHK_lib_error_code,function,reason,file,line);
157 }
diff --git a/src/lib/libcrypto/engine/hw_aep_err.h b/src/lib/libcrypto/engine/hw_aep_err.h
new file mode 100644
index 0000000000..8fe4cf921f
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_aep_err.h
@@ -0,0 +1,101 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_AEPHK_ERR_H
56#define HEADER_AEPHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_AEPHK_strings(void);
63static void ERR_unload_AEPHK_strings(void);
64static void ERR_AEPHK_error(int function, int reason, char *file, int line);
65#define AEPHKerr(f,r) ERR_AEPHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the AEPHK functions. */
68
69/* Function codes. */
70#define AEPHK_F_AEP_CTRL 100
71#define AEPHK_F_AEP_FINISH 101
72#define AEPHK_F_AEP_GET_CONNECTION 102
73#define AEPHK_F_AEP_INIT 103
74#define AEPHK_F_AEP_MOD_EXP 104
75#define AEPHK_F_AEP_MOD_EXP_CRT 105
76#define AEPHK_F_AEP_RAND 106
77#define AEPHK_F_AEP_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define AEPHK_R_ALREADY_LOADED 100
81#define AEPHK_R_CLOSE_HANDLES_FAILED 101
82#define AEPHK_R_CONNECTIONS_IN_USE 102
83#define AEPHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
84#define AEPHK_R_FINALIZE_FAILED 104
85#define AEPHK_R_GET_HANDLE_FAILED 105
86#define AEPHK_R_GET_RANDOM_FAILED 106
87#define AEPHK_R_INIT_FAILURE 107
88#define AEPHK_R_MISSING_KEY_COMPONENTS 108
89#define AEPHK_R_MOD_EXP_CRT_FAILED 109
90#define AEPHK_R_MOD_EXP_FAILED 110
91#define AEPHK_R_NOT_LOADED 111
92#define AEPHK_R_OK 112
93#define AEPHK_R_RETURN_CONNECTION_FAILED 113
94#define AEPHK_R_SETBNCALLBACK_FAILURE 114
95#define AEPHK_R_SIZE_TOO_LARGE_OR_TOO_SMALL 116
96#define AEPHK_R_UNIT_FAILURE 115
97
98#ifdef __cplusplus
99}
100#endif
101#endif
diff --git a/src/lib/libcrypto/engine/hw_atalla.c b/src/lib/libcrypto/engine/hw_atalla.c
new file mode 100644
index 0000000000..2b8342bbdd
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla.c
@@ -0,0 +1,595 @@
1/* crypto/engine/hw_atalla.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include <openssl/engine.h>
64
65#ifndef OPENSSL_NO_HW
66#ifndef OPENSSL_NO_HW_ATALLA
67
68#ifdef FLAT_INC
69#include "atalla.h"
70#else
71#include "vendor_defns/atalla.h"
72#endif
73
74#define ATALLA_LIB_NAME "atalla engine"
75#include "hw_atalla_err.c"
76
77static int atalla_destroy(ENGINE *e);
78static int atalla_init(ENGINE *e);
79static int atalla_finish(ENGINE *e);
80static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
81
82/* BIGNUM stuff */
83static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
84 const BIGNUM *m, BN_CTX *ctx);
85
86#ifndef OPENSSL_NO_RSA
87/* RSA stuff */
88static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
89#endif
90/* This function is aliased to mod_exp (with the mont stuff dropped). */
91static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
92 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
93
94#ifndef OPENSSL_NO_DSA
95/* DSA stuff */
96static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
97 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
98 BN_CTX *ctx, BN_MONT_CTX *in_mont);
99static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
100 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
101 BN_MONT_CTX *m_ctx);
102#endif
103
104#ifndef OPENSSL_NO_DH
105/* DH stuff */
106/* This function is alised to mod_exp (with the DH and mont dropped). */
107static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
108 const BIGNUM *a, const BIGNUM *p,
109 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
110#endif
111
112/* The definitions for control commands specific to this engine */
113#define ATALLA_CMD_SO_PATH ENGINE_CMD_BASE
114static const ENGINE_CMD_DEFN atalla_cmd_defns[] = {
115 {ATALLA_CMD_SO_PATH,
116 "SO_PATH",
117 "Specifies the path to the 'atasi' shared library",
118 ENGINE_CMD_FLAG_STRING},
119 {0, NULL, NULL, 0}
120 };
121
122#ifndef OPENSSL_NO_RSA
123/* Our internal RSA_METHOD that we provide pointers to */
124static RSA_METHOD atalla_rsa =
125 {
126 "Atalla RSA method",
127 NULL,
128 NULL,
129 NULL,
130 NULL,
131 atalla_rsa_mod_exp,
132 atalla_mod_exp_mont,
133 NULL,
134 NULL,
135 0,
136 NULL,
137 NULL,
138 NULL
139 };
140#endif
141
142#ifndef OPENSSL_NO_DSA
143/* Our internal DSA_METHOD that we provide pointers to */
144static DSA_METHOD atalla_dsa =
145 {
146 "Atalla DSA method",
147 NULL, /* dsa_do_sign */
148 NULL, /* dsa_sign_setup */
149 NULL, /* dsa_do_verify */
150 atalla_dsa_mod_exp, /* dsa_mod_exp */
151 atalla_mod_exp_dsa, /* bn_mod_exp */
152 NULL, /* init */
153 NULL, /* finish */
154 0, /* flags */
155 NULL /* app_data */
156 };
157#endif
158
159#ifndef OPENSSL_NO_DH
160/* Our internal DH_METHOD that we provide pointers to */
161static DH_METHOD atalla_dh =
162 {
163 "Atalla DH method",
164 NULL,
165 NULL,
166 atalla_mod_exp_dh,
167 NULL,
168 NULL,
169 0,
170 NULL
171 };
172#endif
173
174/* Constants used when creating the ENGINE */
175static const char *engine_atalla_id = "atalla";
176static const char *engine_atalla_name = "Atalla hardware engine support";
177
178/* This internal function is used by ENGINE_atalla() and possibly by the
179 * "dynamic" ENGINE support too */
180static int bind_helper(ENGINE *e)
181 {
182#ifndef OPENSSL_NO_RSA
183 const RSA_METHOD *meth1;
184#endif
185#ifndef OPENSSL_NO_DSA
186 const DSA_METHOD *meth2;
187#endif
188#ifndef OPENSSL_NO_DH
189 const DH_METHOD *meth3;
190#endif
191 if(!ENGINE_set_id(e, engine_atalla_id) ||
192 !ENGINE_set_name(e, engine_atalla_name) ||
193#ifndef OPENSSL_NO_RSA
194 !ENGINE_set_RSA(e, &atalla_rsa) ||
195#endif
196#ifndef OPENSSL_NO_DSA
197 !ENGINE_set_DSA(e, &atalla_dsa) ||
198#endif
199#ifndef OPENSSL_NO_DH
200 !ENGINE_set_DH(e, &atalla_dh) ||
201#endif
202 !ENGINE_set_destroy_function(e, atalla_destroy) ||
203 !ENGINE_set_init_function(e, atalla_init) ||
204 !ENGINE_set_finish_function(e, atalla_finish) ||
205 !ENGINE_set_ctrl_function(e, atalla_ctrl) ||
206 !ENGINE_set_cmd_defns(e, atalla_cmd_defns))
207 return 0;
208
209#ifndef OPENSSL_NO_RSA
210 /* We know that the "PKCS1_SSLeay()" functions hook properly
211 * to the atalla-specific mod_exp and mod_exp_crt so we use
212 * those functions. NB: We don't use ENGINE_openssl() or
213 * anything "more generic" because something like the RSAref
214 * code may not hook properly, and if you own one of these
215 * cards then you have the right to do RSA operations on it
216 * anyway! */
217 meth1 = RSA_PKCS1_SSLeay();
218 atalla_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
219 atalla_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
220 atalla_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
221 atalla_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
222#endif
223
224#ifndef OPENSSL_NO_DSA
225 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
226 * bits. */
227 meth2 = DSA_OpenSSL();
228 atalla_dsa.dsa_do_sign = meth2->dsa_do_sign;
229 atalla_dsa.dsa_sign_setup = meth2->dsa_sign_setup;
230 atalla_dsa.dsa_do_verify = meth2->dsa_do_verify;
231#endif
232
233#ifndef OPENSSL_NO_DH
234 /* Much the same for Diffie-Hellman */
235 meth3 = DH_OpenSSL();
236 atalla_dh.generate_key = meth3->generate_key;
237 atalla_dh.compute_key = meth3->compute_key;
238#endif
239
240 /* Ensure the atalla error handling is set up */
241 ERR_load_ATALLA_strings();
242 return 1;
243 }
244
245#ifndef ENGINE_DYNAMIC_SUPPORT
246static ENGINE *engine_atalla(void)
247 {
248 ENGINE *ret = ENGINE_new();
249 if(!ret)
250 return NULL;
251 if(!bind_helper(ret))
252 {
253 ENGINE_free(ret);
254 return NULL;
255 }
256 return ret;
257 }
258
259void ENGINE_load_atalla(void)
260 {
261 /* Copied from eng_[openssl|dyn].c */
262 ENGINE *toadd = engine_atalla();
263 if(!toadd) return;
264 ENGINE_add(toadd);
265 ENGINE_free(toadd);
266 ERR_clear_error();
267 }
268#endif
269
270/* This is a process-global DSO handle used for loading and unloading
271 * the Atalla library. NB: This is only set (or unset) during an
272 * init() or finish() call (reference counts permitting) and they're
273 * operating with global locks, so this should be thread-safe
274 * implicitly. */
275static DSO *atalla_dso = NULL;
276
277/* These are the function pointers that are (un)set when the library has
278 * successfully (un)loaded. */
279static tfnASI_GetHardwareConfig *p_Atalla_GetHardwareConfig = NULL;
280static tfnASI_RSAPrivateKeyOpFn *p_Atalla_RSAPrivateKeyOpFn = NULL;
281static tfnASI_GetPerformanceStatistics *p_Atalla_GetPerformanceStatistics = NULL;
282
283/* These are the static string constants for the DSO file name and the function
284 * symbol names to bind to. Regrettably, the DSO name on *nix appears to be
285 * "atasi.so" rather than something more consistent like "libatasi.so". At the
286 * time of writing, I'm not sure what the file name on win32 is but clearly
287 * native name translation is not possible (eg libatasi.so on *nix, and
288 * atasi.dll on win32). For the purposes of testing, I have created a symbollic
289 * link called "libatasi.so" so that we can use native name-translation - a
290 * better solution will be needed. */
291static const char *ATALLA_LIBNAME = NULL;
292static const char *get_ATALLA_LIBNAME(void)
293 {
294 if(ATALLA_LIBNAME)
295 return ATALLA_LIBNAME;
296 return "atasi";
297 }
298static void free_ATALLA_LIBNAME(void)
299 {
300 if(ATALLA_LIBNAME)
301 OPENSSL_free((void*)ATALLA_LIBNAME);
302 ATALLA_LIBNAME = NULL;
303 }
304static long set_ATALLA_LIBNAME(const char *name)
305 {
306 free_ATALLA_LIBNAME();
307 return (((ATALLA_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
308 }
309static const char *ATALLA_F1 = "ASI_GetHardwareConfig";
310static const char *ATALLA_F2 = "ASI_RSAPrivateKeyOpFn";
311static const char *ATALLA_F3 = "ASI_GetPerformanceStatistics";
312
313/* Destructor (complements the "ENGINE_atalla()" constructor) */
314static int atalla_destroy(ENGINE *e)
315 {
316 free_ATALLA_LIBNAME();
317 /* Unload the atalla error strings so any error state including our
318 * functs or reasons won't lead to a segfault (they simply get displayed
319 * without corresponding string data because none will be found). */
320 ERR_unload_ATALLA_strings();
321 return 1;
322 }
323
324/* (de)initialisation functions. */
325static int atalla_init(ENGINE *e)
326 {
327 tfnASI_GetHardwareConfig *p1;
328 tfnASI_RSAPrivateKeyOpFn *p2;
329 tfnASI_GetPerformanceStatistics *p3;
330 /* Not sure of the origin of this magic value, but Ben's code had it
331 * and it seemed to have been working for a few people. :-) */
332 unsigned int config_buf[1024];
333
334 if(atalla_dso != NULL)
335 {
336 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_ALREADY_LOADED);
337 goto err;
338 }
339 /* Attempt to load libatasi.so/atasi.dll/whatever. Needs to be
340 * changed unfortunately because the Atalla drivers don't have
341 * standard library names that can be platform-translated well. */
342 /* TODO: Work out how to actually map to the names the Atalla
343 * drivers really use - for now a symbollic link needs to be
344 * created on the host system from libatasi.so to atasi.so on
345 * unix variants. */
346 atalla_dso = DSO_load(NULL, get_ATALLA_LIBNAME(), NULL, 0);
347 if(atalla_dso == NULL)
348 {
349 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
350 goto err;
351 }
352 if(!(p1 = (tfnASI_GetHardwareConfig *)DSO_bind_func(
353 atalla_dso, ATALLA_F1)) ||
354 !(p2 = (tfnASI_RSAPrivateKeyOpFn *)DSO_bind_func(
355 atalla_dso, ATALLA_F2)) ||
356 !(p3 = (tfnASI_GetPerformanceStatistics *)DSO_bind_func(
357 atalla_dso, ATALLA_F3)))
358 {
359 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_NOT_LOADED);
360 goto err;
361 }
362 /* Copy the pointers */
363 p_Atalla_GetHardwareConfig = p1;
364 p_Atalla_RSAPrivateKeyOpFn = p2;
365 p_Atalla_GetPerformanceStatistics = p3;
366 /* Perform a basic test to see if there's actually any unit
367 * running. */
368 if(p1(0L, config_buf) != 0)
369 {
370 ATALLAerr(ATALLA_F_ATALLA_INIT,ATALLA_R_UNIT_FAILURE);
371 goto err;
372 }
373 /* Everything's fine. */
374 return 1;
375err:
376 if(atalla_dso)
377 DSO_free(atalla_dso);
378 atalla_dso = NULL;
379 p_Atalla_GetHardwareConfig = NULL;
380 p_Atalla_RSAPrivateKeyOpFn = NULL;
381 p_Atalla_GetPerformanceStatistics = NULL;
382 return 0;
383 }
384
385static int atalla_finish(ENGINE *e)
386 {
387 free_ATALLA_LIBNAME();
388 if(atalla_dso == NULL)
389 {
390 ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_NOT_LOADED);
391 return 0;
392 }
393 if(!DSO_free(atalla_dso))
394 {
395 ATALLAerr(ATALLA_F_ATALLA_FINISH,ATALLA_R_UNIT_FAILURE);
396 return 0;
397 }
398 atalla_dso = NULL;
399 p_Atalla_GetHardwareConfig = NULL;
400 p_Atalla_RSAPrivateKeyOpFn = NULL;
401 p_Atalla_GetPerformanceStatistics = NULL;
402 return 1;
403 }
404
405static int atalla_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
406 {
407 int initialised = ((atalla_dso == NULL) ? 0 : 1);
408 switch(cmd)
409 {
410 case ATALLA_CMD_SO_PATH:
411 if(p == NULL)
412 {
413 ATALLAerr(ATALLA_F_ATALLA_CTRL,ERR_R_PASSED_NULL_PARAMETER);
414 return 0;
415 }
416 if(initialised)
417 {
418 ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_ALREADY_LOADED);
419 return 0;
420 }
421 return set_ATALLA_LIBNAME((const char *)p);
422 default:
423 break;
424 }
425 ATALLAerr(ATALLA_F_ATALLA_CTRL,ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED);
426 return 0;
427 }
428
429static int atalla_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
430 const BIGNUM *m, BN_CTX *ctx)
431 {
432 /* I need somewhere to store temporary serialised values for
433 * use with the Atalla API calls. A neat cheat - I'll use
434 * BIGNUMs from the BN_CTX but access their arrays directly as
435 * byte arrays <grin>. This way I don't have to clean anything
436 * up. */
437 BIGNUM *modulus;
438 BIGNUM *exponent;
439 BIGNUM *argument;
440 BIGNUM *result;
441 RSAPrivateKey keydata;
442 int to_return, numbytes;
443
444 modulus = exponent = argument = result = NULL;
445 to_return = 0; /* expect failure */
446
447 if(!atalla_dso)
448 {
449 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_NOT_LOADED);
450 goto err;
451 }
452 /* Prepare the params */
453 BN_CTX_start(ctx);
454 modulus = BN_CTX_get(ctx);
455 exponent = BN_CTX_get(ctx);
456 argument = BN_CTX_get(ctx);
457 result = BN_CTX_get(ctx);
458 if (!result)
459 {
460 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_CTX_FULL);
461 goto err;
462 }
463 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, m->top) ||
464 !bn_wexpand(argument, m->top) || !bn_wexpand(result, m->top))
465 {
466 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_BN_EXPAND_FAIL);
467 goto err;
468 }
469 /* Prepare the key-data */
470 memset(&keydata, 0,sizeof keydata);
471 numbytes = BN_num_bytes(m);
472 memset(exponent->d, 0, numbytes);
473 memset(modulus->d, 0, numbytes);
474 BN_bn2bin(p, (unsigned char *)exponent->d + numbytes - BN_num_bytes(p));
475 BN_bn2bin(m, (unsigned char *)modulus->d + numbytes - BN_num_bytes(m));
476 keydata.privateExponent.data = (unsigned char *)exponent->d;
477 keydata.privateExponent.len = numbytes;
478 keydata.modulus.data = (unsigned char *)modulus->d;
479 keydata.modulus.len = numbytes;
480 /* Prepare the argument */
481 memset(argument->d, 0, numbytes);
482 memset(result->d, 0, numbytes);
483 BN_bn2bin(a, (unsigned char *)argument->d + numbytes - BN_num_bytes(a));
484 /* Perform the operation */
485 if(p_Atalla_RSAPrivateKeyOpFn(&keydata, (unsigned char *)result->d,
486 (unsigned char *)argument->d,
487 keydata.modulus.len) != 0)
488 {
489 ATALLAerr(ATALLA_F_ATALLA_MOD_EXP,ATALLA_R_REQUEST_FAILED);
490 goto err;
491 }
492 /* Convert the response */
493 BN_bin2bn((unsigned char *)result->d, numbytes, r);
494 to_return = 1;
495err:
496 BN_CTX_end(ctx);
497 return to_return;
498 }
499
500#ifndef OPENSSL_NO_RSA
501static int atalla_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
502 {
503 BN_CTX *ctx = NULL;
504 int to_return = 0;
505
506 if(!atalla_dso)
507 {
508 ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_NOT_LOADED);
509 goto err;
510 }
511 if((ctx = BN_CTX_new()) == NULL)
512 goto err;
513 if(!rsa->d || !rsa->n)
514 {
515 ATALLAerr(ATALLA_F_ATALLA_RSA_MOD_EXP,ATALLA_R_MISSING_KEY_COMPONENTS);
516 goto err;
517 }
518 to_return = atalla_mod_exp(r0, I, rsa->d, rsa->n, ctx);
519err:
520 if(ctx)
521 BN_CTX_free(ctx);
522 return to_return;
523 }
524#endif
525
526#ifndef OPENSSL_NO_DSA
527/* This code was liberated and adapted from the commented-out code in
528 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
529 * (it doesn't have a CRT form for RSA), this function means that an
530 * Atalla system running with a DSA server certificate can handshake
531 * around 5 or 6 times faster/more than an equivalent system running with
532 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
533 * of "openssl speed -engine atalla dsa1024 rsa1024". */
534static int atalla_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
535 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
536 BN_CTX *ctx, BN_MONT_CTX *in_mont)
537 {
538 BIGNUM t;
539 int to_return = 0;
540
541 BN_init(&t);
542 /* let rr = a1 ^ p1 mod m */
543 if (!atalla_mod_exp(rr,a1,p1,m,ctx)) goto end;
544 /* let t = a2 ^ p2 mod m */
545 if (!atalla_mod_exp(&t,a2,p2,m,ctx)) goto end;
546 /* let rr = rr * t mod m */
547 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
548 to_return = 1;
549end:
550 BN_free(&t);
551 return to_return;
552 }
553
554static int atalla_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
555 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
556 BN_MONT_CTX *m_ctx)
557 {
558 return atalla_mod_exp(r, a, p, m, ctx);
559 }
560#endif
561
562/* This function is aliased to mod_exp (with the mont stuff dropped). */
563static int atalla_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
564 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
565 {
566 return atalla_mod_exp(r, a, p, m, ctx);
567 }
568
569#ifndef OPENSSL_NO_DH
570/* This function is aliased to mod_exp (with the dh and mont dropped). */
571static int atalla_mod_exp_dh(const DH *dh, BIGNUM *r,
572 const BIGNUM *a, const BIGNUM *p,
573 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
574 {
575 return atalla_mod_exp(r, a, p, m, ctx);
576 }
577#endif
578
579/* This stuff is needed if this ENGINE is being compiled into a self-contained
580 * shared-library. */
581#ifdef ENGINE_DYNAMIC_SUPPORT
582static int bind_fn(ENGINE *e, const char *id)
583 {
584 if(id && (strcmp(id, engine_atalla_id) != 0))
585 return 0;
586 if(!bind_helper(e))
587 return 0;
588 return 1;
589 }
590IMPLEMENT_DYNAMIC_CHECK_FN()
591IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
592#endif /* ENGINE_DYNAMIC_SUPPORT */
593
594#endif /* !OPENSSL_NO_HW_ATALLA */
595#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.c b/src/lib/libcrypto/engine/hw_atalla_err.c
new file mode 100644
index 0000000000..1df9c4570c
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla_err.c
@@ -0,0 +1,145 @@
1/* hw_atalla_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_atalla_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA ATALLA_str_functs[]=
68 {
69{ERR_PACK(0,ATALLA_F_ATALLA_CTRL,0), "ATALLA_CTRL"},
70{ERR_PACK(0,ATALLA_F_ATALLA_FINISH,0), "ATALLA_FINISH"},
71{ERR_PACK(0,ATALLA_F_ATALLA_INIT,0), "ATALLA_INIT"},
72{ERR_PACK(0,ATALLA_F_ATALLA_MOD_EXP,0), "ATALLA_MOD_EXP"},
73{ERR_PACK(0,ATALLA_F_ATALLA_RSA_MOD_EXP,0), "ATALLA_RSA_MOD_EXP"},
74{0,NULL}
75 };
76
77static ERR_STRING_DATA ATALLA_str_reasons[]=
78 {
79{ATALLA_R_ALREADY_LOADED ,"already loaded"},
80{ATALLA_R_BN_CTX_FULL ,"bn ctx full"},
81{ATALLA_R_BN_EXPAND_FAIL ,"bn expand fail"},
82{ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
83{ATALLA_R_MISSING_KEY_COMPONENTS ,"missing key components"},
84{ATALLA_R_NOT_LOADED ,"not loaded"},
85{ATALLA_R_REQUEST_FAILED ,"request failed"},
86{ATALLA_R_UNIT_FAILURE ,"unit failure"},
87{0,NULL}
88 };
89
90#endif
91
92#ifdef ATALLA_LIB_NAME
93static ERR_STRING_DATA ATALLA_lib_name[]=
94 {
95{0 ,ATALLA_LIB_NAME},
96{0,NULL}
97 };
98#endif
99
100
101static int ATALLA_lib_error_code=0;
102static int ATALLA_error_init=1;
103
104static void ERR_load_ATALLA_strings(void)
105 {
106 if (ATALLA_lib_error_code == 0)
107 ATALLA_lib_error_code=ERR_get_next_error_library();
108
109 if (ATALLA_error_init)
110 {
111 ATALLA_error_init=0;
112#ifndef OPENSSL_NO_ERR
113 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_functs);
114 ERR_load_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
115#endif
116
117#ifdef ATALLA_LIB_NAME
118 ATALLA_lib_name->error = ERR_PACK(ATALLA_lib_error_code,0,0);
119 ERR_load_strings(0,ATALLA_lib_name);
120#endif
121 }
122 }
123
124static void ERR_unload_ATALLA_strings(void)
125 {
126 if (ATALLA_error_init == 0)
127 {
128#ifndef OPENSSL_NO_ERR
129 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_functs);
130 ERR_unload_strings(ATALLA_lib_error_code,ATALLA_str_reasons);
131#endif
132
133#ifdef ATALLA_LIB_NAME
134 ERR_unload_strings(0,ATALLA_lib_name);
135#endif
136 ATALLA_error_init=1;
137 }
138 }
139
140static void ERR_ATALLA_error(int function, int reason, char *file, int line)
141 {
142 if (ATALLA_lib_error_code == 0)
143 ATALLA_lib_error_code=ERR_get_next_error_library();
144 ERR_PUT_error(ATALLA_lib_error_code,function,reason,file,line);
145 }
diff --git a/src/lib/libcrypto/engine/hw_atalla_err.h b/src/lib/libcrypto/engine/hw_atalla_err.h
new file mode 100644
index 0000000000..cdac052d8c
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_atalla_err.h
@@ -0,0 +1,89 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_ATALLA_ERR_H
56#define HEADER_ATALLA_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_ATALLA_strings(void);
63static void ERR_unload_ATALLA_strings(void);
64static void ERR_ATALLA_error(int function, int reason, char *file, int line);
65#define ATALLAerr(f,r) ERR_ATALLA_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the ATALLA functions. */
68
69/* Function codes. */
70#define ATALLA_F_ATALLA_CTRL 100
71#define ATALLA_F_ATALLA_FINISH 101
72#define ATALLA_F_ATALLA_INIT 102
73#define ATALLA_F_ATALLA_MOD_EXP 103
74#define ATALLA_F_ATALLA_RSA_MOD_EXP 104
75
76/* Reason codes. */
77#define ATALLA_R_ALREADY_LOADED 100
78#define ATALLA_R_BN_CTX_FULL 101
79#define ATALLA_R_BN_EXPAND_FAIL 102
80#define ATALLA_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
81#define ATALLA_R_MISSING_KEY_COMPONENTS 104
82#define ATALLA_R_NOT_LOADED 105
83#define ATALLA_R_REQUEST_FAILED 106
84#define ATALLA_R_UNIT_FAILURE 107
85
86#ifdef __cplusplus
87}
88#endif
89#endif
diff --git a/src/lib/libcrypto/engine/hw_cryptodev.c b/src/lib/libcrypto/engine/hw_cryptodev.c
new file mode 100644
index 0000000000..a98f5d7e57
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cryptodev.c
@@ -0,0 +1,1355 @@
1/*
2 * Copyright (c) 2002-2004 Theo de Raadt
3 * Copyright (c) 2002 Bob Beck <beck@openbsd.org>
4 * Copyright (c) 2002 Markus Friedl
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29#include <openssl/objects.h>
30#include <openssl/engine.h>
31#include <openssl/evp.h>
32
33#if (defined(__unix__) || defined(unix)) && !defined(USG)
34#include <sys/param.h>
35# if (OpenBSD >= 200112) || ((__FreeBSD_version >= 470101 && __FreeBSD_version < 500000) || __FreeBSD_version >= 500041)
36# define HAVE_CRYPTODEV
37# endif
38# if (OpenBSD >= 200110)
39# define HAVE_SYSLOG_R
40# endif
41#endif
42
43#ifndef HAVE_CRYPTODEV
44
45void
46ENGINE_load_cryptodev(void)
47{
48 /* This is a NOP on platforms without /dev/crypto */
49 return;
50}
51
52#else
53
54#include <sys/types.h>
55#include <crypto/cryptodev.h>
56#include <sys/ioctl.h>
57
58#include <errno.h>
59#include <stdio.h>
60#include <unistd.h>
61#include <fcntl.h>
62#include <stdarg.h>
63#include <syslog.h>
64#include <errno.h>
65#include <string.h>
66
67#ifdef __i386__
68#include <sys/sysctl.h>
69#include <machine/cpu.h>
70#include <machine/specialreg.h>
71
72#include <ssl/aes.h>
73
74static int check_viac3aes(void);
75#endif
76
77struct dev_crypto_state {
78 struct session_op d_sess;
79 int d_fd;
80};
81
82struct dev_crypto_cipher {
83 int c_id;
84 int c_nid;
85 int c_ivmax;
86 int c_keylen;
87};
88
89static u_int32_t cryptodev_asymfeat = 0;
90
91static int get_asym_dev_crypto(void);
92static int open_dev_crypto(void);
93static int get_dev_crypto(void);
94static struct dev_crypto_cipher *cipher_nid_to_cryptodev(int nid);
95static int get_cryptodev_ciphers(const int **cnids);
96/*static int get_cryptodev_digests(const int **cnids);*/
97static int cryptodev_usable_ciphers(const int **nids);
98static int cryptodev_usable_digests(const int **nids);
99static int cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
100 const unsigned char *in, unsigned int inl);
101static int cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
102 const unsigned char *iv, int enc);
103static int cryptodev_cleanup(EVP_CIPHER_CTX *ctx);
104static int cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
105 const int **nids, int nid);
106static int cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
107 const int **nids, int nid);
108static int bn2crparam(const BIGNUM *a, struct crparam *crp);
109static int crparam2bn(struct crparam *crp, BIGNUM *a);
110static void zapparams(struct crypt_kop *kop);
111static int cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r,
112 int slen, BIGNUM *s);
113
114static int cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a,
115 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
116static int cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I,
117 RSA *rsa);
118static int cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
119static int cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a,
120 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
121static int cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g,
122 BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p,
123 BN_CTX *ctx, BN_MONT_CTX *mont);
124static DSA_SIG *cryptodev_dsa_do_sign(const unsigned char *dgst,
125 int dlen, DSA *dsa);
126static int cryptodev_dsa_verify(const unsigned char *dgst, int dgst_len,
127 DSA_SIG *sig, DSA *dsa);
128static int cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
129 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
130 BN_MONT_CTX *m_ctx);
131static int cryptodev_dh_compute_key(unsigned char *key,
132 const BIGNUM *pub_key, DH *dh);
133static int cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p,
134 void (*f)());
135void ENGINE_load_cryptodev(void);
136
137static const ENGINE_CMD_DEFN cryptodev_defns[] = {
138 { 0, NULL, NULL, 0 }
139};
140
141static struct dev_crypto_cipher ciphers[] = {
142 { CRYPTO_DES_CBC, NID_des_cbc, 8, 8, },
143 { CRYPTO_3DES_CBC, NID_des_ede3_cbc, 8, 24, },
144 { CRYPTO_AES_CBC, NID_aes_128_cbc, 16, 16, },
145 { CRYPTO_AES_CBC, NID_aes_192_cbc, 16, 24, },
146 { CRYPTO_AES_CBC, NID_aes_256_cbc, 16, 32, },
147 { CRYPTO_BLF_CBC, NID_bf_cbc, 8, 16, },
148 { CRYPTO_CAST_CBC, NID_cast5_cbc, 8, 16, },
149 { CRYPTO_SKIPJACK_CBC, NID_undef, 0, 0, },
150 { 0, NID_undef, 0, 0, },
151};
152
153#if 0 /* UNUSED */
154static struct {
155 int id;
156 int nid;
157} digests[] = {
158 { CRYPTO_SHA1_HMAC, NID_hmacWithSHA1, },
159 { CRYPTO_RIPEMD160_HMAC, NID_ripemd160, },
160 { CRYPTO_MD5_KPDK, NID_undef, },
161 { CRYPTO_SHA1_KPDK, NID_undef, },
162 { CRYPTO_MD5, NID_md5, },
163 { CRYPTO_SHA1, NID_undef, },
164 { 0, NID_undef, },
165};
166#endif
167
168/*
169 * Return a fd if /dev/crypto seems usable, -1 otherwise.
170 */
171static int
172open_dev_crypto(void)
173{
174 static int fd = -1;
175
176 if (fd == -1) {
177 if ((fd = open("/dev/crypto", O_RDWR, 0)) == -1)
178 return (-1);
179 /* close on exec */
180 if (fcntl(fd, F_SETFD, 1) == -1) {
181 close(fd);
182 fd = -1;
183 return (-1);
184 }
185 }
186 return (fd);
187}
188
189static int
190get_dev_crypto(void)
191{
192 int fd, retfd;
193
194 if ((fd = open_dev_crypto()) == -1)
195 return (-1);
196 if (ioctl(fd, CRIOGET, &retfd) == -1) {
197 close(fd);
198 return (-1);
199 }
200
201 /* close on exec */
202 if (fcntl(retfd, F_SETFD, 1) == -1) {
203 close(retfd);
204 return (-1);
205 }
206 return (retfd);
207}
208
209/* Caching version for asym operations */
210static int
211get_asym_dev_crypto(void)
212{
213 static int fd = -1;
214
215 if (fd == -1)
216 fd = get_dev_crypto();
217 return fd;
218}
219
220/* convert libcrypto nids to cryptodev */
221static struct dev_crypto_cipher *
222cipher_nid_to_cryptodev(int nid)
223{
224 int i;
225
226 for (i = 0; ciphers[i].c_id; i++)
227 if (ciphers[i].c_nid == nid)
228 return (&ciphers[i]);
229 return (NULL);
230}
231
232/*
233 * Find out what ciphers /dev/crypto will let us have a session for.
234 * XXX note, that some of these openssl doesn't deal with yet!
235 * returning them here is harmless, as long as we return NULL
236 * when asked for a handler in the cryptodev_engine_ciphers routine
237 */
238static int
239get_cryptodev_ciphers(const int **cnids)
240{
241 static int nids[CRYPTO_ALGORITHM_MAX];
242 struct session_op sess;
243 int fd, i, count = 0;
244
245 if ((fd = get_dev_crypto()) < 0) {
246 *cnids = NULL;
247 return (0);
248 }
249 memset(&sess, 0, sizeof(sess));
250 sess.key = (caddr_t)"123456781234567812345678";
251
252 for (i = 0; ciphers[i].c_id && count < CRYPTO_ALGORITHM_MAX; i++) {
253 if (ciphers[i].c_nid == NID_undef)
254 continue;
255 sess.cipher = ciphers[i].c_id;
256 sess.keylen = ciphers[i].c_keylen;
257 sess.mac = 0;
258 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
259 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
260 nids[count++] = ciphers[i].c_nid;
261 }
262 close(fd);
263
264#if defined(__i386__)
265 /*
266 * On i386, always check for the VIA C3 AES instructions;
267 * even if /dev/crypto is disabled.
268 */
269 if (check_viac3aes() >= 1) {
270 int have_NID_aes_128_cbc = 0;
271 int have_NID_aes_192_cbc = 0;
272 int have_NID_aes_256_cbc = 0;
273
274 for (i = 0; i < count; i++) {
275 if (nids[i] == NID_aes_128_cbc)
276 have_NID_aes_128_cbc = 1;
277 if (nids[i] == NID_aes_192_cbc)
278 have_NID_aes_192_cbc = 1;
279 if (nids[i] == NID_aes_256_cbc)
280 have_NID_aes_256_cbc = 1;
281 }
282 if (!have_NID_aes_128_cbc)
283 nids[count++] = NID_aes_128_cbc;
284 if (!have_NID_aes_192_cbc)
285 nids[count++] = NID_aes_192_cbc;
286 if (!have_NID_aes_256_cbc)
287 nids[count++] = NID_aes_256_cbc;
288 }
289#endif
290
291 if (count > 0)
292 *cnids = nids;
293 else
294 *cnids = NULL;
295 return (count);
296}
297
298/*
299 * Find out what digests /dev/crypto will let us have a session for.
300 * XXX note, that some of these openssl doesn't deal with yet!
301 * returning them here is harmless, as long as we return NULL
302 * when asked for a handler in the cryptodev_engine_digests routine
303 */
304#if 0 /* UNUSED */
305static int
306get_cryptodev_digests(const int **cnids)
307{
308 static int nids[CRYPTO_ALGORITHM_MAX];
309 struct session_op sess;
310 int fd, i, count = 0;
311
312 if ((fd = get_dev_crypto()) < 0) {
313 *cnids = NULL;
314 return (0);
315 }
316 memset(&sess, 0, sizeof(sess));
317 for (i = 0; digests[i].id && count < CRYPTO_ALGORITHM_MAX; i++) {
318 if (digests[i].nid == NID_undef)
319 continue;
320 sess.mac = digests[i].id;
321 sess.cipher = 0;
322 if (ioctl(fd, CIOCGSESSION, &sess) != -1 &&
323 ioctl(fd, CIOCFSESSION, &sess.ses) != -1)
324 nids[count++] = digests[i].nid;
325 }
326 close(fd);
327
328 if (count > 0)
329 *cnids = nids;
330 else
331 *cnids = NULL;
332 return (count);
333}
334#endif
335
336/*
337 * Find the useable ciphers|digests from dev/crypto - this is the first
338 * thing called by the engine init crud which determines what it
339 * can use for ciphers from this engine. We want to return
340 * only what we can do, anythine else is handled by software.
341 *
342 * If we can't initialize the device to do anything useful for
343 * any reason, we want to return a NULL array, and 0 length,
344 * which forces everything to be done is software. By putting
345 * the initalization of the device in here, we ensure we can
346 * use this engine as the default, and if for whatever reason
347 * /dev/crypto won't do what we want it will just be done in
348 * software
349 *
350 * This can (should) be greatly expanded to perhaps take into
351 * account speed of the device, and what we want to do.
352 * (although the disabling of particular alg's could be controlled
353 * by the device driver with sysctl's.) - this is where we
354 * want most of the decisions made about what we actually want
355 * to use from /dev/crypto.
356 */
357static int
358cryptodev_usable_ciphers(const int **nids)
359{
360 return (get_cryptodev_ciphers(nids));
361}
362
363static int
364cryptodev_usable_digests(const int **nids)
365{
366 /*
367 * XXXX just disable all digests for now, because it sucks.
368 * we need a better way to decide this - i.e. I may not
369 * want digests on slow cards like hifn on fast machines,
370 * but might want them on slow or loaded machines, etc.
371 * will also want them when using crypto cards that don't
372 * suck moose gonads - would be nice to be able to decide something
373 * as reasonable default without having hackery that's card dependent.
374 * of course, the default should probably be just do everything,
375 * with perhaps a sysctl to turn algoritms off (or have them off
376 * by default) on cards that generally suck like the hifn.
377 */
378 *nids = NULL;
379 return (0);
380}
381
382static int
383cryptodev_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
384 const unsigned char *in, unsigned int inl)
385{
386 struct crypt_op cryp;
387 struct dev_crypto_state *state = ctx->cipher_data;
388 struct session_op *sess = &state->d_sess;
389 void *iiv;
390 unsigned char save_iv[EVP_MAX_IV_LENGTH];
391
392 if (state->d_fd < 0)
393 return (0);
394 if (!inl)
395 return (1);
396 if ((inl % ctx->cipher->block_size) != 0)
397 return (0);
398
399 memset(&cryp, 0, sizeof(cryp));
400
401 cryp.ses = sess->ses;
402 cryp.flags = 0;
403 cryp.len = inl;
404 cryp.src = (caddr_t) in;
405 cryp.dst = (caddr_t) out;
406 cryp.mac = 0;
407
408 cryp.op = ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
409
410 if (ctx->cipher->iv_len) {
411 cryp.iv = (caddr_t) ctx->iv;
412 if (!ctx->encrypt) {
413 iiv = (void *) in + inl - ctx->cipher->iv_len;
414 memcpy(save_iv, iiv, ctx->cipher->iv_len);
415 }
416 } else
417 cryp.iv = NULL;
418
419 if (ioctl(state->d_fd, CIOCCRYPT, &cryp) == -1) {
420 /* XXX need better errror handling
421 * this can fail for a number of different reasons.
422 */
423 return (0);
424 }
425
426 if (ctx->cipher->iv_len) {
427 if (ctx->encrypt)
428 iiv = (void *) out + inl - ctx->cipher->iv_len;
429 else
430 iiv = save_iv;
431 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
432 }
433 return (1);
434}
435
436static int
437cryptodev_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
438 const unsigned char *iv, int enc)
439{
440 struct dev_crypto_state *state = ctx->cipher_data;
441 struct session_op *sess = &state->d_sess;
442 struct dev_crypto_cipher *cipher;
443
444 if ((cipher = cipher_nid_to_cryptodev(ctx->cipher->nid)) == NULL)
445 return (0);
446
447 if (ctx->cipher->iv_len > cipher->c_ivmax)
448 return (0);
449
450 if (ctx->key_len != cipher->c_keylen)
451 return (0);
452
453 memset(sess, 0, sizeof(struct session_op));
454
455 if ((state->d_fd = get_dev_crypto()) < 0)
456 return (0);
457
458 sess->key = (unsigned char *)key;
459 sess->keylen = ctx->key_len;
460 sess->cipher = cipher->c_id;
461
462 if (ioctl(state->d_fd, CIOCGSESSION, sess) == -1) {
463 close(state->d_fd);
464 state->d_fd = -1;
465 return (0);
466 }
467 return (1);
468}
469
470/*
471 * free anything we allocated earlier when initting a
472 * session, and close the session.
473 */
474static int
475cryptodev_cleanup(EVP_CIPHER_CTX *ctx)
476{
477 int ret = 0;
478 struct dev_crypto_state *state = ctx->cipher_data;
479 struct session_op *sess = &state->d_sess;
480
481 if (state->d_fd < 0)
482 return (0);
483
484 /* XXX if this ioctl fails, someting's wrong. the invoker
485 * may have called us with a bogus ctx, or we could
486 * have a device that for whatever reason just doesn't
487 * want to play ball - it's not clear what's right
488 * here - should this be an error? should it just
489 * increase a counter, hmm. For right now, we return
490 * 0 - I don't believe that to be "right". we could
491 * call the gorpy openssl lib error handlers that
492 * print messages to users of the library. hmm..
493 */
494
495 if (ioctl(state->d_fd, CIOCFSESSION, &sess->ses) == -1) {
496 ret = 0;
497 } else {
498 ret = 1;
499 }
500 close(state->d_fd);
501 state->d_fd = -1;
502
503 return (ret);
504}
505
506/*
507 * libcrypto EVP stuff - this is how we get wired to EVP so the engine
508 * gets called when libcrypto requests a cipher NID.
509 */
510
511/* DES CBC EVP */
512const EVP_CIPHER cryptodev_des_cbc = {
513 NID_des_cbc,
514 8, 8, 8,
515 EVP_CIPH_CBC_MODE,
516 cryptodev_init_key,
517 cryptodev_cipher,
518 cryptodev_cleanup,
519 sizeof(struct dev_crypto_state),
520 EVP_CIPHER_set_asn1_iv,
521 EVP_CIPHER_get_asn1_iv,
522 NULL
523};
524
525/* 3DES CBC EVP */
526const EVP_CIPHER cryptodev_3des_cbc = {
527 NID_des_ede3_cbc,
528 8, 24, 8,
529 EVP_CIPH_CBC_MODE,
530 cryptodev_init_key,
531 cryptodev_cipher,
532 cryptodev_cleanup,
533 sizeof(struct dev_crypto_state),
534 EVP_CIPHER_set_asn1_iv,
535 EVP_CIPHER_get_asn1_iv,
536 NULL
537};
538
539const EVP_CIPHER cryptodev_bf_cbc = {
540 NID_bf_cbc,
541 8, 16, 8,
542 EVP_CIPH_CBC_MODE,
543 cryptodev_init_key,
544 cryptodev_cipher,
545 cryptodev_cleanup,
546 sizeof(struct dev_crypto_state),
547 EVP_CIPHER_set_asn1_iv,
548 EVP_CIPHER_get_asn1_iv,
549 NULL
550};
551
552const EVP_CIPHER cryptodev_cast_cbc = {
553 NID_cast5_cbc,
554 8, 16, 8,
555 EVP_CIPH_CBC_MODE,
556 cryptodev_init_key,
557 cryptodev_cipher,
558 cryptodev_cleanup,
559 sizeof(struct dev_crypto_state),
560 EVP_CIPHER_set_asn1_iv,
561 EVP_CIPHER_get_asn1_iv,
562 NULL
563};
564
565EVP_CIPHER cryptodev_aes_128_cbc = {
566 NID_aes_128_cbc,
567 16, 16, 16,
568 EVP_CIPH_CBC_MODE,
569 cryptodev_init_key,
570 cryptodev_cipher,
571 cryptodev_cleanup,
572 sizeof(struct dev_crypto_state),
573 EVP_CIPHER_set_asn1_iv,
574 EVP_CIPHER_get_asn1_iv,
575 NULL
576};
577
578EVP_CIPHER cryptodev_aes_192_cbc = {
579 NID_aes_192_cbc,
580 16, 24, 16,
581 EVP_CIPH_CBC_MODE,
582 cryptodev_init_key,
583 cryptodev_cipher,
584 cryptodev_cleanup,
585 sizeof(struct dev_crypto_state),
586 EVP_CIPHER_set_asn1_iv,
587 EVP_CIPHER_get_asn1_iv,
588 NULL
589};
590
591EVP_CIPHER cryptodev_aes_256_cbc = {
592 NID_aes_256_cbc,
593 16, 32, 16,
594 EVP_CIPH_CBC_MODE,
595 cryptodev_init_key,
596 cryptodev_cipher,
597 cryptodev_cleanup,
598 sizeof(struct dev_crypto_state),
599 EVP_CIPHER_set_asn1_iv,
600 EVP_CIPHER_get_asn1_iv,
601 NULL
602};
603
604#if defined(__i386__)
605
606static inline void
607viac3_xcrypt_cbc(int *cw, const void *src, void *dst, void *key, int rep,
608 void *iv)
609{
610#ifdef notdef
611 printf("cw %x[%x %x %x %x] src %x dst %x key %x rep %x iv %x\n",
612 cw, cw[0], cw[1], cw[2], cw[3],
613 src, dst, key, rep, iv);
614#endif
615 /*
616 * Clear bit 30 of EFLAGS.
617 */
618 __asm __volatile("pushfl; popfl");
619
620 /*
621 * Cannot simply place key into "b" register, since the compiler
622 * -pic mode uses that register; so instead we must dance a little.
623 */
624 __asm __volatile("pushl %%ebx; movl %0, %%ebx; rep xcrypt-cbc; popl %%ebx" :
625 : "mr" (key), "a" (iv), "c" (rep), "d" (cw), "S" (src), "D" (dst)
626 : "memory", "cc");
627}
628
629#define ISUNALIGNED(x) ((long)(x)) & 15
630#define DOALIGN(v) ((void *)(((long)(v) + 15) & ~15))
631
632static int
633xcrypt_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
634 const unsigned char *in, unsigned int inl)
635{
636 unsigned char *save_iv_store[EVP_MAX_IV_LENGTH + 15];
637 unsigned char *save_iv = DOALIGN(save_iv_store);
638 unsigned char *ivs_store[EVP_MAX_IV_LENGTH + 15];
639 unsigned char *ivs = DOALIGN(ivs_store);
640 void *iiv, *iv = NULL, *ivp = NULL;
641 const void *usein = in;
642 void *useout = out, *spare;
643 int cws[4 + 3], *cw = DOALIGN(cws);
644
645 if (!inl)
646 return (1);
647 if ((inl % ctx->cipher->block_size) != 0)
648 return (0);
649
650 if (ISUNALIGNED(in) || ISUNALIGNED(out)) {
651 spare = malloc(inl);
652 if (spare == NULL)
653 return (0);
654
655 if (ISUNALIGNED(in)) {
656 bcopy(in, spare, inl);
657 usein = spare;
658 }
659 if (ISUNALIGNED(out))
660 useout = spare;
661 }
662
663 cw[0] = C3_CRYPT_CWLO_ALG_AES | C3_CRYPT_CWLO_KEYGEN_SW |
664 C3_CRYPT_CWLO_NORMAL;
665 cw[0] |= ctx->encrypt ? C3_CRYPT_CWLO_ENCRYPT : C3_CRYPT_CWLO_DECRYPT;
666 cw[1] = cw[2] = cw[3] = 0;
667
668 switch (ctx->key_len * 8) {
669 case 128:
670 cw[0] |= C3_CRYPT_CWLO_KEY128;
671 break;
672 case 192:
673 cw[0] |= C3_CRYPT_CWLO_KEY192;
674 break;
675 case 256:
676 cw[0] |= C3_CRYPT_CWLO_KEY256;
677 break;
678 }
679
680 if (ctx->cipher->iv_len) {
681 iv = (caddr_t) ctx->iv;
682 if (!ctx->encrypt) {
683 iiv = (void *) in + inl - ctx->cipher->iv_len;
684 memcpy(save_iv, iiv, ctx->cipher->iv_len);
685 }
686 }
687
688 ivp = iv;
689 if (ISUNALIGNED(iv)) {
690 bcopy(iv, ivs, ctx->cipher->iv_len);
691 ivp = ivs;
692 }
693
694 viac3_xcrypt_cbc(cw, usein, useout, ctx->cipher_data, inl / 16, ivp);
695
696 if (ISUNALIGNED(in) || ISUNALIGNED(out)) {
697 if (ISUNALIGNED(out))
698 bcopy(spare, out, inl);
699 free(spare);
700 }
701
702 if (ivp == ivs)
703 bcopy(ivp, iv, ctx->cipher->iv_len);
704
705 if (ctx->cipher->iv_len) {
706 if (ctx->encrypt)
707 iiv = (void *) out + inl - ctx->cipher->iv_len;
708 else
709 iiv = save_iv;
710 memcpy(ctx->iv, iiv, ctx->cipher->iv_len);
711 }
712 return (1);
713}
714
715static int
716xcrypt_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
717 const unsigned char *iv, int enc)
718{
719 AES_KEY *k = ctx->cipher_data;
720#ifndef AES_ASM
721 int i;
722#endif
723
724 bzero(k, sizeof *k);
725 if (enc)
726 AES_set_encrypt_key(key, ctx->key_len * 8, k);
727 else
728 AES_set_decrypt_key(key, ctx->key_len * 8, k);
729
730#ifndef AES_ASM
731 /*
732 * XXX Damn OpenSSL byte swaps the expanded key!!
733 *
734 * XXX But only if we're using the C implementation of AES
735 */
736 for (i = 0; i < 4 * (AES_MAXNR + 1); i++)
737 k->rd_key[i] = htonl(k->rd_key[i]);
738#endif
739
740 return (1);
741}
742
743static int
744xcrypt_cleanup(EVP_CIPHER_CTX *ctx)
745{
746 bzero(ctx->cipher_data, ctx->cipher->ctx_size);
747 return (1);
748}
749
750static int
751check_viac3aes(void)
752{
753 int mib[2] = { CTL_MACHDEP, CPU_XCRYPT }, value;
754 size_t size = sizeof(value);
755
756 if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &value, &size,
757 NULL, 0) < 0)
758 return (0);
759 if (value == 0)
760 return (0);
761
762 if (value & C3_HAS_AES) {
763 cryptodev_aes_128_cbc.init = xcrypt_init_key;
764 cryptodev_aes_128_cbc.do_cipher = xcrypt_cipher;
765 cryptodev_aes_128_cbc.cleanup = xcrypt_cleanup;
766 cryptodev_aes_128_cbc.ctx_size = sizeof(AES_KEY);
767
768 cryptodev_aes_192_cbc.init = xcrypt_init_key;
769 cryptodev_aes_192_cbc.do_cipher = xcrypt_cipher;
770 cryptodev_aes_192_cbc.cleanup = xcrypt_cleanup;
771 cryptodev_aes_192_cbc.ctx_size = sizeof(AES_KEY);
772
773 cryptodev_aes_256_cbc.init = xcrypt_init_key;
774 cryptodev_aes_256_cbc.do_cipher = xcrypt_cipher;
775 cryptodev_aes_256_cbc.cleanup = xcrypt_cleanup;
776 cryptodev_aes_256_cbc.ctx_size = sizeof(AES_KEY);
777 }
778 return (value);
779}
780#endif /* __i386__ */
781
782/*
783 * Registered by the ENGINE when used to find out how to deal with
784 * a particular NID in the ENGINE. this says what we'll do at the
785 * top level - note, that list is restricted by what we answer with
786 */
787static int
788cryptodev_engine_ciphers(ENGINE *e, const EVP_CIPHER **cipher,
789 const int **nids, int nid)
790{
791 if (!cipher)
792 return (cryptodev_usable_ciphers(nids));
793
794 switch (nid) {
795 case NID_des_ede3_cbc:
796 *cipher = &cryptodev_3des_cbc;
797 break;
798 case NID_des_cbc:
799 *cipher = &cryptodev_des_cbc;
800 break;
801 case NID_bf_cbc:
802 *cipher = &cryptodev_bf_cbc;
803 break;
804 case NID_cast5_cbc:
805 *cipher = &cryptodev_cast_cbc;
806 break;
807 case NID_aes_128_cbc:
808 *cipher = &cryptodev_aes_128_cbc;
809 break;
810 case NID_aes_192_cbc:
811 *cipher = &cryptodev_aes_192_cbc;
812 break;
813 case NID_aes_256_cbc:
814 *cipher = &cryptodev_aes_256_cbc;
815 break;
816 default:
817 *cipher = NULL;
818 break;
819 }
820 return (*cipher != NULL);
821}
822
823static int
824cryptodev_engine_digests(ENGINE *e, const EVP_MD **digest,
825 const int **nids, int nid)
826{
827 if (!digest)
828 return (cryptodev_usable_digests(nids));
829
830 switch (nid) {
831 case NID_md5:
832 *digest = NULL; /* need to make a clean md5 critter */
833 break;
834 default:
835 *digest = NULL;
836 break;
837 }
838 return (*digest != NULL);
839}
840
841/*
842 * Convert a BIGNUM to the representation that /dev/crypto needs.
843 * Upon completion of use, the caller is responsible for freeing
844 * crp->crp_p.
845 */
846static int
847bn2crparam(const BIGNUM *a, struct crparam *crp)
848{
849 int i, j, k;
850 ssize_t bytes, bits;
851 u_char *b;
852
853 crp->crp_p = NULL;
854 crp->crp_nbits = 0;
855
856 bits = BN_num_bits(a);
857 bytes = (bits + 7) / 8;
858
859 b = malloc(bytes);
860 if (b == NULL)
861 return (1);
862
863 crp->crp_p = b;
864 crp->crp_nbits = bits;
865
866 for (i = 0, j = 0; i < a->top; i++) {
867 for (k = 0; k < BN_BITS2 / 8; k++) {
868 if ((j + k) >= bytes)
869 return (0);
870 b[j + k] = a->d[i] >> (k * 8);
871 }
872 j += BN_BITS2 / 8;
873 }
874 return (0);
875}
876
877/* Convert a /dev/crypto parameter to a BIGNUM */
878static int
879crparam2bn(struct crparam *crp, BIGNUM *a)
880{
881 u_int8_t *pd;
882 int i, bytes;
883
884 bytes = (crp->crp_nbits + 7) / 8;
885
886 if (bytes == 0)
887 return (-1);
888
889 if ((pd = (u_int8_t *) malloc(bytes)) == NULL)
890 return (-1);
891
892 for (i = 0; i < bytes; i++)
893 pd[i] = crp->crp_p[bytes - i - 1];
894
895 BN_bin2bn(pd, bytes, a);
896 free(pd);
897
898 return (0);
899}
900
901static void
902zapparams(struct crypt_kop *kop)
903{
904 int i;
905
906 for (i = 0; i <= kop->crk_iparams + kop->crk_oparams; i++) {
907 if (kop->crk_param[i].crp_p)
908 free(kop->crk_param[i].crp_p);
909 kop->crk_param[i].crp_p = NULL;
910 kop->crk_param[i].crp_nbits = 0;
911 }
912}
913
914static int
915cryptodev_asym(struct crypt_kop *kop, int rlen, BIGNUM *r, int slen, BIGNUM *s)
916{
917 int fd, ret = -1;
918
919 if ((fd = get_asym_dev_crypto()) < 0)
920 return (ret);
921
922 if (r) {
923 kop->crk_param[kop->crk_iparams].crp_p = calloc(rlen, sizeof(char));
924 kop->crk_param[kop->crk_iparams].crp_nbits = rlen * 8;
925 kop->crk_oparams++;
926 }
927 if (s) {
928 kop->crk_param[kop->crk_iparams+1].crp_p = calloc(slen, sizeof(char));
929 kop->crk_param[kop->crk_iparams+1].crp_nbits = slen * 8;
930 kop->crk_oparams++;
931 }
932
933 if (ioctl(fd, CIOCKEY, kop) == 0) {
934 if (r)
935 crparam2bn(&kop->crk_param[kop->crk_iparams], r);
936 if (s)
937 crparam2bn(&kop->crk_param[kop->crk_iparams+1], s);
938 ret = 0;
939 }
940
941 return (ret);
942}
943
944static int
945cryptodev_bn_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
946 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *in_mont)
947{
948 struct crypt_kop kop;
949 int ret = 1;
950
951 /* Currently, we know we can do mod exp iff we can do any
952 * asymmetric operations at all.
953 */
954 if (cryptodev_asymfeat == 0) {
955 ret = BN_mod_exp(r, a, p, m, ctx);
956 return (ret);
957 }
958
959 memset(&kop, 0, sizeof kop);
960 kop.crk_op = CRK_MOD_EXP;
961
962 /* inputs: a^p % m */
963 if (bn2crparam(a, &kop.crk_param[0]))
964 goto err;
965 if (bn2crparam(p, &kop.crk_param[1]))
966 goto err;
967 if (bn2crparam(m, &kop.crk_param[2]))
968 goto err;
969 kop.crk_iparams = 3;
970
971 if (cryptodev_asym(&kop, BN_num_bytes(m), r, 0, NULL) == -1) {
972 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
973 ret = meth->bn_mod_exp(r, a, p, m, ctx, in_mont);
974 }
975err:
976 zapparams(&kop);
977 return (ret);
978}
979
980static int
981cryptodev_rsa_nocrt_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
982{
983 int r;
984 BN_CTX *ctx;
985
986 ctx = BN_CTX_new();
987 r = cryptodev_bn_mod_exp(r0, I, rsa->d, rsa->n, ctx, NULL);
988 BN_CTX_free(ctx);
989 return (r);
990}
991
992static int
993cryptodev_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
994{
995 struct crypt_kop kop;
996 int ret = 1;
997
998 if (!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp) {
999 /* XXX 0 means failure?? */
1000 return (0);
1001 }
1002
1003 memset(&kop, 0, sizeof kop);
1004 kop.crk_op = CRK_MOD_EXP_CRT;
1005 /* inputs: rsa->p rsa->q I rsa->dmp1 rsa->dmq1 rsa->iqmp */
1006 if (bn2crparam(rsa->p, &kop.crk_param[0]))
1007 goto err;
1008 if (bn2crparam(rsa->q, &kop.crk_param[1]))
1009 goto err;
1010 if (bn2crparam(I, &kop.crk_param[2]))
1011 goto err;
1012 if (bn2crparam(rsa->dmp1, &kop.crk_param[3]))
1013 goto err;
1014 if (bn2crparam(rsa->dmq1, &kop.crk_param[4]))
1015 goto err;
1016 if (bn2crparam(rsa->iqmp, &kop.crk_param[5]))
1017 goto err;
1018 kop.crk_iparams = 6;
1019
1020 if (cryptodev_asym(&kop, BN_num_bytes(rsa->n), r0, 0, NULL) == -1) {
1021 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
1022 ret = (*meth->rsa_mod_exp)(r0, I, rsa);
1023 }
1024err:
1025 zapparams(&kop);
1026 return (ret);
1027}
1028
1029static RSA_METHOD cryptodev_rsa = {
1030 "cryptodev RSA method",
1031 NULL, /* rsa_pub_enc */
1032 NULL, /* rsa_pub_dec */
1033 NULL, /* rsa_priv_enc */
1034 NULL, /* rsa_priv_dec */
1035 NULL,
1036 NULL,
1037 NULL, /* init */
1038 NULL, /* finish */
1039 0, /* flags */
1040 NULL, /* app_data */
1041 NULL, /* rsa_sign */
1042 NULL /* rsa_verify */
1043};
1044
1045static int
1046cryptodev_dsa_bn_mod_exp(DSA *dsa, BIGNUM *r, BIGNUM *a, const BIGNUM *p,
1047 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1048{
1049 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
1050}
1051
1052static int
1053cryptodev_dsa_dsa_mod_exp(DSA *dsa, BIGNUM *t1, BIGNUM *g,
1054 BIGNUM *u1, BIGNUM *pub_key, BIGNUM *u2, BIGNUM *p,
1055 BN_CTX *ctx, BN_MONT_CTX *mont)
1056{
1057 BIGNUM t2;
1058 int ret = 0;
1059
1060 BN_init(&t2);
1061
1062 /* v = ( g^u1 * y^u2 mod p ) mod q */
1063 /* let t1 = g ^ u1 mod p */
1064 ret = 0;
1065
1066 if (!dsa->meth->bn_mod_exp(dsa,t1,dsa->g,u1,dsa->p,ctx,mont))
1067 goto err;
1068
1069 /* let t2 = y ^ u2 mod p */
1070 if (!dsa->meth->bn_mod_exp(dsa,&t2,dsa->pub_key,u2,dsa->p,ctx,mont))
1071 goto err;
1072 /* let u1 = t1 * t2 mod p */
1073 if (!BN_mod_mul(u1,t1,&t2,dsa->p,ctx))
1074 goto err;
1075
1076 BN_copy(t1,u1);
1077
1078 ret = 1;
1079err:
1080 BN_free(&t2);
1081 return(ret);
1082}
1083
1084static DSA_SIG *
1085cryptodev_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
1086{
1087 struct crypt_kop kop;
1088 BIGNUM *r = NULL, *s = NULL;
1089 DSA_SIG *dsaret = NULL;
1090
1091 if ((r = BN_new()) == NULL)
1092 goto err;
1093 if ((s = BN_new()) == NULL) {
1094 BN_free(r);
1095 goto err;
1096 }
1097
1098 memset(&kop, 0, sizeof kop);
1099 kop.crk_op = CRK_DSA_SIGN;
1100
1101 /* inputs: dgst dsa->p dsa->q dsa->g dsa->priv_key */
1102 kop.crk_param[0].crp_p = (caddr_t)dgst;
1103 kop.crk_param[0].crp_nbits = dlen * 8;
1104 if (bn2crparam(dsa->p, &kop.crk_param[1]))
1105 goto err;
1106 if (bn2crparam(dsa->q, &kop.crk_param[2]))
1107 goto err;
1108 if (bn2crparam(dsa->g, &kop.crk_param[3]))
1109 goto err;
1110 if (bn2crparam(dsa->priv_key, &kop.crk_param[4]))
1111 goto err;
1112 kop.crk_iparams = 5;
1113
1114 if (cryptodev_asym(&kop, BN_num_bytes(dsa->q), r,
1115 BN_num_bytes(dsa->q), s) == 0) {
1116 dsaret = DSA_SIG_new();
1117 dsaret->r = r;
1118 dsaret->s = s;
1119 } else {
1120 const DSA_METHOD *meth = DSA_OpenSSL();
1121 BN_free(r);
1122 BN_free(s);
1123 dsaret = (meth->dsa_do_sign)(dgst, dlen, dsa);
1124 }
1125err:
1126 kop.crk_param[0].crp_p = NULL;
1127 zapparams(&kop);
1128 return (dsaret);
1129}
1130
1131static int
1132cryptodev_dsa_verify(const unsigned char *dgst, int dlen,
1133 DSA_SIG *sig, DSA *dsa)
1134{
1135 struct crypt_kop kop;
1136 int dsaret = 1;
1137
1138 memset(&kop, 0, sizeof kop);
1139 kop.crk_op = CRK_DSA_VERIFY;
1140
1141 /* inputs: dgst dsa->p dsa->q dsa->g dsa->pub_key sig->r sig->s */
1142 kop.crk_param[0].crp_p = (caddr_t)dgst;
1143 kop.crk_param[0].crp_nbits = dlen * 8;
1144 if (bn2crparam(dsa->p, &kop.crk_param[1]))
1145 goto err;
1146 if (bn2crparam(dsa->q, &kop.crk_param[2]))
1147 goto err;
1148 if (bn2crparam(dsa->g, &kop.crk_param[3]))
1149 goto err;
1150 if (bn2crparam(dsa->pub_key, &kop.crk_param[4]))
1151 goto err;
1152 if (bn2crparam(sig->r, &kop.crk_param[5]))
1153 goto err;
1154 if (bn2crparam(sig->s, &kop.crk_param[6]))
1155 goto err;
1156 kop.crk_iparams = 7;
1157
1158 if (cryptodev_asym(&kop, 0, NULL, 0, NULL) == 0) {
1159 dsaret = kop.crk_status;
1160 } else {
1161 const DSA_METHOD *meth = DSA_OpenSSL();
1162
1163 dsaret = (meth->dsa_do_verify)(dgst, dlen, sig, dsa);
1164 }
1165err:
1166 kop.crk_param[0].crp_p = NULL;
1167 zapparams(&kop);
1168 return (dsaret);
1169}
1170
1171static DSA_METHOD cryptodev_dsa = {
1172 "cryptodev DSA method",
1173 NULL,
1174 NULL, /* dsa_sign_setup */
1175 NULL,
1176 NULL, /* dsa_mod_exp */
1177 NULL,
1178 NULL, /* init */
1179 NULL, /* finish */
1180 0, /* flags */
1181 NULL /* app_data */
1182};
1183
1184static int
1185cryptodev_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
1186 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
1187 BN_MONT_CTX *m_ctx)
1188{
1189 return (cryptodev_bn_mod_exp(r, a, p, m, ctx, m_ctx));
1190}
1191
1192static int
1193cryptodev_dh_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
1194{
1195 struct crypt_kop kop;
1196 int dhret = 1;
1197 int fd, keylen;
1198
1199 if ((fd = get_asym_dev_crypto()) < 0) {
1200 const DH_METHOD *meth = DH_OpenSSL();
1201
1202 return ((meth->compute_key)(key, pub_key, dh));
1203 }
1204
1205 keylen = BN_num_bits(dh->p);
1206
1207 memset(&kop, 0, sizeof kop);
1208 kop.crk_op = CRK_DH_COMPUTE_KEY;
1209
1210 /* inputs: dh->priv_key pub_key dh->p key */
1211 if (bn2crparam(dh->priv_key, &kop.crk_param[0]))
1212 goto err;
1213 if (bn2crparam(pub_key, &kop.crk_param[1]))
1214 goto err;
1215 if (bn2crparam(dh->p, &kop.crk_param[2]))
1216 goto err;
1217 kop.crk_iparams = 3;
1218
1219 kop.crk_param[3].crp_p = key;
1220 kop.crk_param[3].crp_nbits = keylen * 8;
1221 kop.crk_oparams = 1;
1222
1223 if (ioctl(fd, CIOCKEY, &kop) == -1) {
1224 const DH_METHOD *meth = DH_OpenSSL();
1225
1226 dhret = (meth->compute_key)(key, pub_key, dh);
1227 }
1228err:
1229 kop.crk_param[3].crp_p = NULL;
1230 zapparams(&kop);
1231 return (dhret);
1232}
1233
1234static DH_METHOD cryptodev_dh = {
1235 "cryptodev DH method",
1236 NULL, /* cryptodev_dh_generate_key */
1237 NULL,
1238 NULL,
1239 NULL,
1240 NULL,
1241 0, /* flags */
1242 NULL /* app_data */
1243};
1244
1245/*
1246 * ctrl right now is just a wrapper that doesn't do much
1247 * but I expect we'll want some options soon.
1248 */
1249static int
1250cryptodev_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
1251{
1252#ifdef HAVE_SYSLOG_R
1253 struct syslog_data sd = SYSLOG_DATA_INIT;
1254#endif
1255
1256 switch (cmd) {
1257 default:
1258#ifdef HAVE_SYSLOG_R
1259 syslog_r(LOG_ERR, &sd,
1260 "cryptodev_ctrl: unknown command %d", cmd);
1261#else
1262 syslog(LOG_ERR, "cryptodev_ctrl: unknown command %d", cmd);
1263#endif
1264 break;
1265 }
1266 return (1);
1267}
1268
1269void
1270ENGINE_load_cryptodev(void)
1271{
1272 ENGINE *engine = ENGINE_new();
1273 int fd;
1274
1275 if (engine == NULL)
1276 return;
1277 if ((fd = get_dev_crypto()) < 0) {
1278 ENGINE_free(engine);
1279 return;
1280 }
1281
1282 /*
1283 * find out what asymmetric crypto algorithms we support
1284 */
1285 if (ioctl(fd, CIOCASYMFEAT, &cryptodev_asymfeat) == -1) {
1286 close(fd);
1287 ENGINE_free(engine);
1288 return;
1289 }
1290 close(fd);
1291
1292 if (!ENGINE_set_id(engine, "cryptodev") ||
1293 !ENGINE_set_name(engine, "BSD cryptodev engine") ||
1294 !ENGINE_set_ciphers(engine, cryptodev_engine_ciphers) ||
1295 !ENGINE_set_digests(engine, cryptodev_engine_digests) ||
1296 !ENGINE_set_ctrl_function(engine, cryptodev_ctrl) ||
1297 !ENGINE_set_cmd_defns(engine, cryptodev_defns)) {
1298 ENGINE_free(engine);
1299 return;
1300 }
1301
1302 if (ENGINE_set_RSA(engine, &cryptodev_rsa)) {
1303 const RSA_METHOD *rsa_meth = RSA_PKCS1_SSLeay();
1304
1305 cryptodev_rsa.bn_mod_exp = rsa_meth->bn_mod_exp;
1306 cryptodev_rsa.rsa_mod_exp = rsa_meth->rsa_mod_exp;
1307 cryptodev_rsa.rsa_pub_enc = rsa_meth->rsa_pub_enc;
1308 cryptodev_rsa.rsa_pub_dec = rsa_meth->rsa_pub_dec;
1309 cryptodev_rsa.rsa_priv_enc = rsa_meth->rsa_priv_enc;
1310 cryptodev_rsa.rsa_priv_dec = rsa_meth->rsa_priv_dec;
1311 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1312 cryptodev_rsa.bn_mod_exp = cryptodev_bn_mod_exp;
1313 if (cryptodev_asymfeat & CRF_MOD_EXP_CRT)
1314 cryptodev_rsa.rsa_mod_exp =
1315 cryptodev_rsa_mod_exp;
1316 else
1317 cryptodev_rsa.rsa_mod_exp =
1318 cryptodev_rsa_nocrt_mod_exp;
1319 }
1320 }
1321
1322 if (ENGINE_set_DSA(engine, &cryptodev_dsa)) {
1323 const DSA_METHOD *meth = DSA_OpenSSL();
1324
1325 memcpy(&cryptodev_dsa, meth, sizeof(DSA_METHOD));
1326 if (cryptodev_asymfeat & CRF_DSA_SIGN)
1327 cryptodev_dsa.dsa_do_sign = cryptodev_dsa_do_sign;
1328 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1329 cryptodev_dsa.bn_mod_exp = cryptodev_dsa_bn_mod_exp;
1330 cryptodev_dsa.dsa_mod_exp = cryptodev_dsa_dsa_mod_exp;
1331 }
1332 if (cryptodev_asymfeat & CRF_DSA_VERIFY)
1333 cryptodev_dsa.dsa_do_verify = cryptodev_dsa_verify;
1334 }
1335
1336 if (ENGINE_set_DH(engine, &cryptodev_dh)){
1337 const DH_METHOD *dh_meth = DH_OpenSSL();
1338
1339 cryptodev_dh.generate_key = dh_meth->generate_key;
1340 cryptodev_dh.compute_key = dh_meth->compute_key;
1341 cryptodev_dh.bn_mod_exp = dh_meth->bn_mod_exp;
1342 if (cryptodev_asymfeat & CRF_MOD_EXP) {
1343 cryptodev_dh.bn_mod_exp = cryptodev_mod_exp_dh;
1344 if (cryptodev_asymfeat & CRF_DH_COMPUTE_KEY)
1345 cryptodev_dh.compute_key =
1346 cryptodev_dh_compute_key;
1347 }
1348 }
1349
1350 ENGINE_add(engine);
1351 ENGINE_free(engine);
1352 ERR_clear_error();
1353}
1354
1355#endif /* HAVE_CRYPTODEV */
diff --git a/src/lib/libcrypto/engine/hw_cswift.c b/src/lib/libcrypto/engine/hw_cswift.c
new file mode 100644
index 0000000000..1411fd8333
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift.c
@@ -0,0 +1,1109 @@
1/* crypto/engine/hw_cswift.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include <openssl/engine.h>
64
65#ifndef OPENSSL_NO_HW
66#ifndef OPENSSL_NO_HW_CSWIFT
67
68/* Attribution notice: Rainbow have generously allowed me to reproduce
69 * the necessary definitions here from their API. This means the support
70 * can build independently of whether application builders have the
71 * API or hardware. This will allow developers to easily produce software
72 * that has latent hardware support for any users that have accelerators
73 * installed, without the developers themselves needing anything extra.
74 *
75 * I have only clipped the parts from the CryptoSwift header files that
76 * are (or seem) relevant to the CryptoSwift support code. This is
77 * simply to keep the file sizes reasonable.
78 * [Geoff]
79 */
80#ifdef FLAT_INC
81#include "cswift.h"
82#else
83#include "vendor_defns/cswift.h"
84#endif
85
86#define CSWIFT_LIB_NAME "cswift engine"
87#include "hw_cswift_err.c"
88
89static int cswift_destroy(ENGINE *e);
90static int cswift_init(ENGINE *e);
91static int cswift_finish(ENGINE *e);
92static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
93static int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in);
94
95/* BIGNUM stuff */
96static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
97 const BIGNUM *m, BN_CTX *ctx);
98static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
99 const BIGNUM *q, const BIGNUM *dmp1, const BIGNUM *dmq1,
100 const BIGNUM *iqmp, BN_CTX *ctx);
101
102#ifndef OPENSSL_NO_RSA
103/* RSA stuff */
104static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
105#endif
106/* This function is aliased to mod_exp (with the mont stuff dropped). */
107static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
108 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
109
110#ifndef OPENSSL_NO_DSA
111/* DSA stuff */
112static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa);
113static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
114 DSA_SIG *sig, DSA *dsa);
115#endif
116
117#ifndef OPENSSL_NO_DH
118/* DH stuff */
119/* This function is alised to mod_exp (with the DH and mont dropped). */
120static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r,
121 const BIGNUM *a, const BIGNUM *p,
122 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
123#endif
124
125/* RAND stuff */
126static int cswift_rand_bytes(unsigned char *buf, int num);
127static int cswift_rand_status(void);
128
129/* The definitions for control commands specific to this engine */
130#define CSWIFT_CMD_SO_PATH ENGINE_CMD_BASE
131static const ENGINE_CMD_DEFN cswift_cmd_defns[] = {
132 {CSWIFT_CMD_SO_PATH,
133 "SO_PATH",
134 "Specifies the path to the 'cswift' shared library",
135 ENGINE_CMD_FLAG_STRING},
136 {0, NULL, NULL, 0}
137 };
138
139#ifndef OPENSSL_NO_RSA
140/* Our internal RSA_METHOD that we provide pointers to */
141static RSA_METHOD cswift_rsa =
142 {
143 "CryptoSwift RSA method",
144 NULL,
145 NULL,
146 NULL,
147 NULL,
148 cswift_rsa_mod_exp,
149 cswift_mod_exp_mont,
150 NULL,
151 NULL,
152 0,
153 NULL,
154 NULL,
155 NULL
156 };
157#endif
158
159#ifndef OPENSSL_NO_DSA
160/* Our internal DSA_METHOD that we provide pointers to */
161static DSA_METHOD cswift_dsa =
162 {
163 "CryptoSwift DSA method",
164 cswift_dsa_sign,
165 NULL, /* dsa_sign_setup */
166 cswift_dsa_verify,
167 NULL, /* dsa_mod_exp */
168 NULL, /* bn_mod_exp */
169 NULL, /* init */
170 NULL, /* finish */
171 0, /* flags */
172 NULL /* app_data */
173 };
174#endif
175
176#ifndef OPENSSL_NO_DH
177/* Our internal DH_METHOD that we provide pointers to */
178static DH_METHOD cswift_dh =
179 {
180 "CryptoSwift DH method",
181 NULL,
182 NULL,
183 cswift_mod_exp_dh,
184 NULL,
185 NULL,
186 0,
187 NULL
188 };
189#endif
190
191static RAND_METHOD cswift_random =
192 {
193 /* "CryptoSwift RAND method", */
194 NULL,
195 cswift_rand_bytes,
196 NULL,
197 NULL,
198 cswift_rand_bytes,
199 cswift_rand_status,
200 };
201
202
203/* Constants used when creating the ENGINE */
204static const char *engine_cswift_id = "cswift";
205static const char *engine_cswift_name = "CryptoSwift hardware engine support";
206
207/* This internal function is used by ENGINE_cswift() and possibly by the
208 * "dynamic" ENGINE support too */
209static int bind_helper(ENGINE *e)
210 {
211#ifndef OPENSSL_NO_RSA
212 const RSA_METHOD *meth1;
213#endif
214#ifndef OPENSSL_NO_DH
215 const DH_METHOD *meth2;
216#endif
217 if(!ENGINE_set_id(e, engine_cswift_id) ||
218 !ENGINE_set_name(e, engine_cswift_name) ||
219#ifndef OPENSSL_NO_RSA
220 !ENGINE_set_RSA(e, &cswift_rsa) ||
221#endif
222#ifndef OPENSSL_NO_DSA
223 !ENGINE_set_DSA(e, &cswift_dsa) ||
224#endif
225#ifndef OPENSSL_NO_DH
226 !ENGINE_set_DH(e, &cswift_dh) ||
227#endif
228 !ENGINE_set_RAND(e, &cswift_random) ||
229 !ENGINE_set_destroy_function(e, cswift_destroy) ||
230 !ENGINE_set_init_function(e, cswift_init) ||
231 !ENGINE_set_finish_function(e, cswift_finish) ||
232 !ENGINE_set_ctrl_function(e, cswift_ctrl) ||
233 !ENGINE_set_cmd_defns(e, cswift_cmd_defns))
234 return 0;
235
236#ifndef OPENSSL_NO_RSA
237 /* We know that the "PKCS1_SSLeay()" functions hook properly
238 * to the cswift-specific mod_exp and mod_exp_crt so we use
239 * those functions. NB: We don't use ENGINE_openssl() or
240 * anything "more generic" because something like the RSAref
241 * code may not hook properly, and if you own one of these
242 * cards then you have the right to do RSA operations on it
243 * anyway! */
244 meth1 = RSA_PKCS1_SSLeay();
245 cswift_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
246 cswift_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
247 cswift_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
248 cswift_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
249#endif
250
251#ifndef OPENSSL_NO_DH
252 /* Much the same for Diffie-Hellman */
253 meth2 = DH_OpenSSL();
254 cswift_dh.generate_key = meth2->generate_key;
255 cswift_dh.compute_key = meth2->compute_key;
256#endif
257
258 /* Ensure the cswift error handling is set up */
259 ERR_load_CSWIFT_strings();
260 return 1;
261 }
262
263#ifndef ENGINE_DYNAMIC_SUPPORT
264static ENGINE *engine_cswift(void)
265 {
266 ENGINE *ret = ENGINE_new();
267 if(!ret)
268 return NULL;
269 if(!bind_helper(ret))
270 {
271 ENGINE_free(ret);
272 return NULL;
273 }
274 return ret;
275 }
276
277void ENGINE_load_cswift(void)
278 {
279 /* Copied from eng_[openssl|dyn].c */
280 ENGINE *toadd = engine_cswift();
281 if(!toadd) return;
282 ENGINE_add(toadd);
283 ENGINE_free(toadd);
284 ERR_clear_error();
285 }
286#endif
287
288/* This is a process-global DSO handle used for loading and unloading
289 * the CryptoSwift library. NB: This is only set (or unset) during an
290 * init() or finish() call (reference counts permitting) and they're
291 * operating with global locks, so this should be thread-safe
292 * implicitly. */
293static DSO *cswift_dso = NULL;
294
295/* These are the function pointers that are (un)set when the library has
296 * successfully (un)loaded. */
297t_swAcquireAccContext *p_CSwift_AcquireAccContext = NULL;
298t_swAttachKeyParam *p_CSwift_AttachKeyParam = NULL;
299t_swSimpleRequest *p_CSwift_SimpleRequest = NULL;
300t_swReleaseAccContext *p_CSwift_ReleaseAccContext = NULL;
301
302/* Used in the DSO operations. */
303static const char *CSWIFT_LIBNAME = NULL;
304static const char *get_CSWIFT_LIBNAME(void)
305 {
306 if(CSWIFT_LIBNAME)
307 return CSWIFT_LIBNAME;
308 return "swift";
309 }
310static void free_CSWIFT_LIBNAME(void)
311 {
312 if(CSWIFT_LIBNAME)
313 OPENSSL_free((void*)CSWIFT_LIBNAME);
314 CSWIFT_LIBNAME = NULL;
315 }
316static long set_CSWIFT_LIBNAME(const char *name)
317 {
318 free_CSWIFT_LIBNAME();
319 return (((CSWIFT_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
320 }
321static const char *CSWIFT_F1 = "swAcquireAccContext";
322static const char *CSWIFT_F2 = "swAttachKeyParam";
323static const char *CSWIFT_F3 = "swSimpleRequest";
324static const char *CSWIFT_F4 = "swReleaseAccContext";
325
326
327/* CryptoSwift library functions and mechanics - these are used by the
328 * higher-level functions further down. NB: As and where there's no
329 * error checking, take a look lower down where these functions are
330 * called, the checking and error handling is probably down there. */
331
332/* utility function to obtain a context */
333static int get_context(SW_CONTEXT_HANDLE *hac)
334 {
335 SW_STATUS status;
336
337 status = p_CSwift_AcquireAccContext(hac);
338 if(status != SW_OK)
339 return 0;
340 return 1;
341 }
342
343/* similarly to release one. */
344static void release_context(SW_CONTEXT_HANDLE hac)
345 {
346 p_CSwift_ReleaseAccContext(hac);
347 }
348
349/* Destructor (complements the "ENGINE_cswift()" constructor) */
350static int cswift_destroy(ENGINE *e)
351 {
352 free_CSWIFT_LIBNAME();
353 ERR_unload_CSWIFT_strings();
354 return 1;
355 }
356
357/* (de)initialisation functions. */
358static int cswift_init(ENGINE *e)
359 {
360 SW_CONTEXT_HANDLE hac;
361 t_swAcquireAccContext *p1;
362 t_swAttachKeyParam *p2;
363 t_swSimpleRequest *p3;
364 t_swReleaseAccContext *p4;
365
366 if(cswift_dso != NULL)
367 {
368 CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_ALREADY_LOADED);
369 goto err;
370 }
371 /* Attempt to load libswift.so/swift.dll/whatever. */
372 cswift_dso = DSO_load(NULL, get_CSWIFT_LIBNAME(), NULL, 0);
373 if(cswift_dso == NULL)
374 {
375 CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED);
376 goto err;
377 }
378 if(!(p1 = (t_swAcquireAccContext *)
379 DSO_bind_func(cswift_dso, CSWIFT_F1)) ||
380 !(p2 = (t_swAttachKeyParam *)
381 DSO_bind_func(cswift_dso, CSWIFT_F2)) ||
382 !(p3 = (t_swSimpleRequest *)
383 DSO_bind_func(cswift_dso, CSWIFT_F3)) ||
384 !(p4 = (t_swReleaseAccContext *)
385 DSO_bind_func(cswift_dso, CSWIFT_F4)))
386 {
387 CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_NOT_LOADED);
388 goto err;
389 }
390 /* Copy the pointers */
391 p_CSwift_AcquireAccContext = p1;
392 p_CSwift_AttachKeyParam = p2;
393 p_CSwift_SimpleRequest = p3;
394 p_CSwift_ReleaseAccContext = p4;
395 /* Try and get a context - if not, we may have a DSO but no
396 * accelerator! */
397 if(!get_context(&hac))
398 {
399 CSWIFTerr(CSWIFT_F_CSWIFT_INIT,CSWIFT_R_UNIT_FAILURE);
400 goto err;
401 }
402 release_context(hac);
403 /* Everything's fine. */
404 return 1;
405err:
406 if(cswift_dso)
407 {
408 DSO_free(cswift_dso);
409 cswift_dso = NULL;
410 }
411 p_CSwift_AcquireAccContext = NULL;
412 p_CSwift_AttachKeyParam = NULL;
413 p_CSwift_SimpleRequest = NULL;
414 p_CSwift_ReleaseAccContext = NULL;
415 return 0;
416 }
417
418static int cswift_finish(ENGINE *e)
419 {
420 free_CSWIFT_LIBNAME();
421 if(cswift_dso == NULL)
422 {
423 CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_NOT_LOADED);
424 return 0;
425 }
426 if(!DSO_free(cswift_dso))
427 {
428 CSWIFTerr(CSWIFT_F_CSWIFT_FINISH,CSWIFT_R_UNIT_FAILURE);
429 return 0;
430 }
431 cswift_dso = NULL;
432 p_CSwift_AcquireAccContext = NULL;
433 p_CSwift_AttachKeyParam = NULL;
434 p_CSwift_SimpleRequest = NULL;
435 p_CSwift_ReleaseAccContext = NULL;
436 return 1;
437 }
438
439static int cswift_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
440 {
441 int initialised = ((cswift_dso == NULL) ? 0 : 1);
442 switch(cmd)
443 {
444 case CSWIFT_CMD_SO_PATH:
445 if(p == NULL)
446 {
447 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,ERR_R_PASSED_NULL_PARAMETER);
448 return 0;
449 }
450 if(initialised)
451 {
452 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_ALREADY_LOADED);
453 return 0;
454 }
455 return set_CSWIFT_LIBNAME((const char *)p);
456 default:
457 break;
458 }
459 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL,CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED);
460 return 0;
461 }
462
463/* Un petit mod_exp */
464static int cswift_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
465 const BIGNUM *m, BN_CTX *ctx)
466 {
467 /* I need somewhere to store temporary serialised values for
468 * use with the CryptoSwift API calls. A neat cheat - I'll use
469 * BIGNUMs from the BN_CTX but access their arrays directly as
470 * byte arrays <grin>. This way I don't have to clean anything
471 * up. */
472 BIGNUM *modulus;
473 BIGNUM *exponent;
474 BIGNUM *argument;
475 BIGNUM *result;
476 SW_STATUS sw_status;
477 SW_LARGENUMBER arg, res;
478 SW_PARAM sw_param;
479 SW_CONTEXT_HANDLE hac;
480 int to_return, acquired;
481
482 modulus = exponent = argument = result = NULL;
483 to_return = 0; /* expect failure */
484 acquired = 0;
485
486 if(!get_context(&hac))
487 {
488 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_UNIT_FAILURE);
489 goto err;
490 }
491 acquired = 1;
492 /* Prepare the params */
493 BN_CTX_start(ctx);
494 modulus = BN_CTX_get(ctx);
495 exponent = BN_CTX_get(ctx);
496 argument = BN_CTX_get(ctx);
497 result = BN_CTX_get(ctx);
498 if(!result)
499 {
500 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_CTX_FULL);
501 goto err;
502 }
503 if(!bn_wexpand(modulus, m->top) || !bn_wexpand(exponent, p->top) ||
504 !bn_wexpand(argument, a->top) || !bn_wexpand(result, m->top))
505 {
506 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BN_EXPAND_FAIL);
507 goto err;
508 }
509 sw_param.type = SW_ALG_EXP;
510 sw_param.up.exp.modulus.nbytes = BN_bn2bin(m,
511 (unsigned char *)modulus->d);
512 sw_param.up.exp.modulus.value = (unsigned char *)modulus->d;
513 sw_param.up.exp.exponent.nbytes = BN_bn2bin(p,
514 (unsigned char *)exponent->d);
515 sw_param.up.exp.exponent.value = (unsigned char *)exponent->d;
516 /* Attach the key params */
517 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
518 switch(sw_status)
519 {
520 case SW_OK:
521 break;
522 case SW_ERR_INPUT_SIZE:
523 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_BAD_KEY_SIZE);
524 goto err;
525 default:
526 {
527 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
528 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED);
529 sprintf(tmpbuf, "%ld", sw_status);
530 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
531 }
532 goto err;
533 }
534 /* Prepare the argument and response */
535 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
536 arg.value = (unsigned char *)argument->d;
537 res.nbytes = BN_num_bytes(m);
538 memset(result->d, 0, res.nbytes);
539 res.value = (unsigned char *)result->d;
540 /* Perform the operation */
541 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP, &arg, 1,
542 &res, 1)) != SW_OK)
543 {
544 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
545 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP,CSWIFT_R_REQUEST_FAILED);
546 sprintf(tmpbuf, "%ld", sw_status);
547 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
548 goto err;
549 }
550 /* Convert the response */
551 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
552 to_return = 1;
553err:
554 if(acquired)
555 release_context(hac);
556 BN_CTX_end(ctx);
557 return to_return;
558 }
559
560
561int cswift_bn_32copy(SW_LARGENUMBER * out, const BIGNUM * in)
562{
563 int mod;
564 int numbytes = BN_num_bytes(in);
565
566 mod = 0;
567 while( ((out->nbytes = (numbytes+mod)) % 32) )
568 {
569 mod++;
570 }
571 out->value = (unsigned char*)OPENSSL_malloc(out->nbytes);
572 if(!out->value)
573 {
574 return 0;
575 }
576 BN_bn2bin(in, &out->value[mod]);
577 if(mod)
578 memset(out->value, 0, mod);
579
580 return 1;
581}
582
583/* Un petit mod_exp chinois */
584static int cswift_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
585 const BIGNUM *q, const BIGNUM *dmp1,
586 const BIGNUM *dmq1, const BIGNUM *iqmp, BN_CTX *ctx)
587 {
588 SW_STATUS sw_status;
589 SW_LARGENUMBER arg, res;
590 SW_PARAM sw_param;
591 SW_CONTEXT_HANDLE hac;
592 BIGNUM *result = NULL;
593 BIGNUM *argument = NULL;
594 int to_return = 0; /* expect failure */
595 int acquired = 0;
596
597 sw_param.up.crt.p.value = NULL;
598 sw_param.up.crt.q.value = NULL;
599 sw_param.up.crt.dmp1.value = NULL;
600 sw_param.up.crt.dmq1.value = NULL;
601 sw_param.up.crt.iqmp.value = NULL;
602
603 if(!get_context(&hac))
604 {
605 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_UNIT_FAILURE);
606 goto err;
607 }
608 acquired = 1;
609
610 /* Prepare the params */
611 argument = BN_new();
612 result = BN_new();
613 if(!result || !argument)
614 {
615 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_CTX_FULL);
616 goto err;
617 }
618
619
620 sw_param.type = SW_ALG_CRT;
621 /************************************************************************/
622 /* 04/02/2003 */
623 /* Modified by Frederic Giudicelli (deny-all.com) to overcome the */
624 /* limitation of cswift with values not a multiple of 32 */
625 /************************************************************************/
626 if(!cswift_bn_32copy(&sw_param.up.crt.p, p))
627 {
628 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
629 goto err;
630 }
631 if(!cswift_bn_32copy(&sw_param.up.crt.q, q))
632 {
633 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
634 goto err;
635 }
636 if(!cswift_bn_32copy(&sw_param.up.crt.dmp1, dmp1))
637 {
638 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
639 goto err;
640 }
641 if(!cswift_bn_32copy(&sw_param.up.crt.dmq1, dmq1))
642 {
643 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
644 goto err;
645 }
646 if(!cswift_bn_32copy(&sw_param.up.crt.iqmp, iqmp))
647 {
648 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
649 goto err;
650 }
651 if( !bn_wexpand(argument, a->top) ||
652 !bn_wexpand(result, p->top + q->top))
653 {
654 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BN_EXPAND_FAIL);
655 goto err;
656 }
657
658 /* Attach the key params */
659 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
660 switch(sw_status)
661 {
662 case SW_OK:
663 break;
664 case SW_ERR_INPUT_SIZE:
665 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_BAD_KEY_SIZE);
666 goto err;
667 default:
668 {
669 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
670 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED);
671 sprintf(tmpbuf, "%ld", sw_status);
672 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
673 }
674 goto err;
675 }
676 /* Prepare the argument and response */
677 arg.nbytes = BN_bn2bin(a, (unsigned char *)argument->d);
678 arg.value = (unsigned char *)argument->d;
679 res.nbytes = 2 * BN_num_bytes(p);
680 memset(result->d, 0, res.nbytes);
681 res.value = (unsigned char *)result->d;
682 /* Perform the operation */
683 if((sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_MODEXP_CRT, &arg, 1,
684 &res, 1)) != SW_OK)
685 {
686 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
687 CSWIFTerr(CSWIFT_F_CSWIFT_MOD_EXP_CRT,CSWIFT_R_REQUEST_FAILED);
688 sprintf(tmpbuf, "%ld", sw_status);
689 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
690 goto err;
691 }
692 /* Convert the response */
693 BN_bin2bn((unsigned char *)result->d, res.nbytes, r);
694 to_return = 1;
695err:
696 if(sw_param.up.crt.p.value)
697 OPENSSL_free(sw_param.up.crt.p.value);
698 if(sw_param.up.crt.q.value)
699 OPENSSL_free(sw_param.up.crt.q.value);
700 if(sw_param.up.crt.dmp1.value)
701 OPENSSL_free(sw_param.up.crt.dmp1.value);
702 if(sw_param.up.crt.dmq1.value)
703 OPENSSL_free(sw_param.up.crt.dmq1.value);
704 if(sw_param.up.crt.iqmp.value)
705 OPENSSL_free(sw_param.up.crt.iqmp.value);
706 if(result)
707 BN_free(result);
708 if(argument)
709 BN_free(argument);
710 if(acquired)
711 release_context(hac);
712 return to_return;
713 }
714
715#ifndef OPENSSL_NO_RSA
716static int cswift_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
717 {
718 BN_CTX *ctx;
719 int to_return = 0;
720 const RSA_METHOD * def_rsa_method;
721
722 /* Try the limits of RSA (2048 bits) */
723 if(BN_num_bytes(rsa->p) > 128 ||
724 BN_num_bytes(rsa->q) > 128 ||
725 BN_num_bytes(rsa->dmp1) > 128 ||
726 BN_num_bytes(rsa->dmq1) > 128 ||
727 BN_num_bytes(rsa->iqmp) > 128)
728 {
729#ifdef RSA_NULL
730 def_rsa_method=RSA_null_method();
731#else
732#if 0
733 def_rsa_method=RSA_PKCS1_RSAref();
734#else
735 def_rsa_method=RSA_PKCS1_SSLeay();
736#endif
737#endif
738 if(def_rsa_method)
739 return def_rsa_method->rsa_mod_exp(r0, I, rsa);
740 }
741
742 if((ctx = BN_CTX_new()) == NULL)
743 goto err;
744 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
745 {
746 CSWIFTerr(CSWIFT_F_CSWIFT_RSA_MOD_EXP,CSWIFT_R_MISSING_KEY_COMPONENTS);
747 goto err;
748 }
749 to_return = cswift_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
750 rsa->dmq1, rsa->iqmp, ctx);
751err:
752 if(ctx)
753 BN_CTX_free(ctx);
754 return to_return;
755 }
756#endif
757
758/* This function is aliased to mod_exp (with the mont stuff dropped). */
759static int cswift_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
760 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
761 {
762 const RSA_METHOD * def_rsa_method;
763
764 /* Try the limits of RSA (2048 bits) */
765 if(BN_num_bytes(r) > 256 ||
766 BN_num_bytes(a) > 256 ||
767 BN_num_bytes(m) > 256)
768 {
769#ifdef RSA_NULL
770 def_rsa_method=RSA_null_method();
771#else
772#if 0
773 def_rsa_method=RSA_PKCS1_RSAref();
774#else
775 def_rsa_method=RSA_PKCS1_SSLeay();
776#endif
777#endif
778 if(def_rsa_method)
779 return def_rsa_method->bn_mod_exp(r, a, p, m, ctx, m_ctx);
780 }
781
782 return cswift_mod_exp(r, a, p, m, ctx);
783 }
784
785#ifndef OPENSSL_NO_DSA
786static DSA_SIG *cswift_dsa_sign(const unsigned char *dgst, int dlen, DSA *dsa)
787 {
788 SW_CONTEXT_HANDLE hac;
789 SW_PARAM sw_param;
790 SW_STATUS sw_status;
791 SW_LARGENUMBER arg, res;
792 unsigned char *ptr;
793 BN_CTX *ctx;
794 BIGNUM *dsa_p = NULL;
795 BIGNUM *dsa_q = NULL;
796 BIGNUM *dsa_g = NULL;
797 BIGNUM *dsa_key = NULL;
798 BIGNUM *result = NULL;
799 DSA_SIG *to_return = NULL;
800 int acquired = 0;
801
802 if((ctx = BN_CTX_new()) == NULL)
803 goto err;
804 if(!get_context(&hac))
805 {
806 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_UNIT_FAILURE);
807 goto err;
808 }
809 acquired = 1;
810 /* Prepare the params */
811 BN_CTX_start(ctx);
812 dsa_p = BN_CTX_get(ctx);
813 dsa_q = BN_CTX_get(ctx);
814 dsa_g = BN_CTX_get(ctx);
815 dsa_key = BN_CTX_get(ctx);
816 result = BN_CTX_get(ctx);
817 if(!result)
818 {
819 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_CTX_FULL);
820 goto err;
821 }
822 if(!bn_wexpand(dsa_p, dsa->p->top) ||
823 !bn_wexpand(dsa_q, dsa->q->top) ||
824 !bn_wexpand(dsa_g, dsa->g->top) ||
825 !bn_wexpand(dsa_key, dsa->priv_key->top) ||
826 !bn_wexpand(result, dsa->p->top))
827 {
828 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BN_EXPAND_FAIL);
829 goto err;
830 }
831 sw_param.type = SW_ALG_DSA;
832 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
833 (unsigned char *)dsa_p->d);
834 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
835 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
836 (unsigned char *)dsa_q->d);
837 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
838 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
839 (unsigned char *)dsa_g->d);
840 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
841 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->priv_key,
842 (unsigned char *)dsa_key->d);
843 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
844 /* Attach the key params */
845 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
846 switch(sw_status)
847 {
848 case SW_OK:
849 break;
850 case SW_ERR_INPUT_SIZE:
851 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_BAD_KEY_SIZE);
852 goto err;
853 default:
854 {
855 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
856 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED);
857 sprintf(tmpbuf, "%ld", sw_status);
858 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
859 }
860 goto err;
861 }
862 /* Prepare the argument and response */
863 arg.nbytes = dlen;
864 arg.value = (unsigned char *)dgst;
865 res.nbytes = BN_num_bytes(dsa->p);
866 memset(result->d, 0, res.nbytes);
867 res.value = (unsigned char *)result->d;
868 /* Perform the operation */
869 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_SIGN, &arg, 1,
870 &res, 1);
871 if(sw_status != SW_OK)
872 {
873 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
874 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_SIGN,CSWIFT_R_REQUEST_FAILED);
875 sprintf(tmpbuf, "%ld", sw_status);
876 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
877 goto err;
878 }
879 /* Convert the response */
880 ptr = (unsigned char *)result->d;
881 if((to_return = DSA_SIG_new()) == NULL)
882 goto err;
883 to_return->r = BN_bin2bn((unsigned char *)result->d, 20, NULL);
884 to_return->s = BN_bin2bn((unsigned char *)result->d + 20, 20, NULL);
885
886err:
887 if(acquired)
888 release_context(hac);
889 if(ctx)
890 {
891 BN_CTX_end(ctx);
892 BN_CTX_free(ctx);
893 }
894 return to_return;
895 }
896
897static int cswift_dsa_verify(const unsigned char *dgst, int dgst_len,
898 DSA_SIG *sig, DSA *dsa)
899 {
900 SW_CONTEXT_HANDLE hac;
901 SW_PARAM sw_param;
902 SW_STATUS sw_status;
903 SW_LARGENUMBER arg[2], res;
904 unsigned long sig_result;
905 BN_CTX *ctx;
906 BIGNUM *dsa_p = NULL;
907 BIGNUM *dsa_q = NULL;
908 BIGNUM *dsa_g = NULL;
909 BIGNUM *dsa_key = NULL;
910 BIGNUM *argument = NULL;
911 int to_return = -1;
912 int acquired = 0;
913
914 if((ctx = BN_CTX_new()) == NULL)
915 goto err;
916 if(!get_context(&hac))
917 {
918 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_UNIT_FAILURE);
919 goto err;
920 }
921 acquired = 1;
922 /* Prepare the params */
923 BN_CTX_start(ctx);
924 dsa_p = BN_CTX_get(ctx);
925 dsa_q = BN_CTX_get(ctx);
926 dsa_g = BN_CTX_get(ctx);
927 dsa_key = BN_CTX_get(ctx);
928 argument = BN_CTX_get(ctx);
929 if(!argument)
930 {
931 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_CTX_FULL);
932 goto err;
933 }
934 if(!bn_wexpand(dsa_p, dsa->p->top) ||
935 !bn_wexpand(dsa_q, dsa->q->top) ||
936 !bn_wexpand(dsa_g, dsa->g->top) ||
937 !bn_wexpand(dsa_key, dsa->pub_key->top) ||
938 !bn_wexpand(argument, 40))
939 {
940 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BN_EXPAND_FAIL);
941 goto err;
942 }
943 sw_param.type = SW_ALG_DSA;
944 sw_param.up.dsa.p.nbytes = BN_bn2bin(dsa->p,
945 (unsigned char *)dsa_p->d);
946 sw_param.up.dsa.p.value = (unsigned char *)dsa_p->d;
947 sw_param.up.dsa.q.nbytes = BN_bn2bin(dsa->q,
948 (unsigned char *)dsa_q->d);
949 sw_param.up.dsa.q.value = (unsigned char *)dsa_q->d;
950 sw_param.up.dsa.g.nbytes = BN_bn2bin(dsa->g,
951 (unsigned char *)dsa_g->d);
952 sw_param.up.dsa.g.value = (unsigned char *)dsa_g->d;
953 sw_param.up.dsa.key.nbytes = BN_bn2bin(dsa->pub_key,
954 (unsigned char *)dsa_key->d);
955 sw_param.up.dsa.key.value = (unsigned char *)dsa_key->d;
956 /* Attach the key params */
957 sw_status = p_CSwift_AttachKeyParam(hac, &sw_param);
958 switch(sw_status)
959 {
960 case SW_OK:
961 break;
962 case SW_ERR_INPUT_SIZE:
963 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_BAD_KEY_SIZE);
964 goto err;
965 default:
966 {
967 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
968 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);
969 sprintf(tmpbuf, "%ld", sw_status);
970 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
971 }
972 goto err;
973 }
974 /* Prepare the argument and response */
975 arg[0].nbytes = dgst_len;
976 arg[0].value = (unsigned char *)dgst;
977 arg[1].nbytes = 40;
978 arg[1].value = (unsigned char *)argument->d;
979 memset(arg[1].value, 0, 40);
980 BN_bn2bin(sig->r, arg[1].value + 20 - BN_num_bytes(sig->r));
981 BN_bn2bin(sig->s, arg[1].value + 40 - BN_num_bytes(sig->s));
982 res.nbytes = 4; /* unsigned long */
983 res.value = (unsigned char *)(&sig_result);
984 /* Perform the operation */
985 sw_status = p_CSwift_SimpleRequest(hac, SW_CMD_DSS_VERIFY, arg, 2,
986 &res, 1);
987 if(sw_status != SW_OK)
988 {
989 char tmpbuf[DECIMAL_SIZE(sw_status)+1];
990 CSWIFTerr(CSWIFT_F_CSWIFT_DSA_VERIFY,CSWIFT_R_REQUEST_FAILED);
991 sprintf(tmpbuf, "%ld", sw_status);
992 ERR_add_error_data(2, "CryptoSwift error number is ",tmpbuf);
993 goto err;
994 }
995 /* Convert the response */
996 to_return = ((sig_result == 0) ? 0 : 1);
997
998err:
999 if(acquired)
1000 release_context(hac);
1001 if(ctx)
1002 {
1003 BN_CTX_end(ctx);
1004 BN_CTX_free(ctx);
1005 }
1006 return to_return;
1007 }
1008#endif
1009
1010#ifndef OPENSSL_NO_DH
1011/* This function is aliased to mod_exp (with the dh and mont dropped). */
1012static int cswift_mod_exp_dh(const DH *dh, BIGNUM *r,
1013 const BIGNUM *a, const BIGNUM *p,
1014 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1015 {
1016 return cswift_mod_exp(r, a, p, m, ctx);
1017 }
1018#endif
1019
1020/* Random bytes are good */
1021static int cswift_rand_bytes(unsigned char *buf, int num)
1022{
1023 SW_CONTEXT_HANDLE hac;
1024 SW_STATUS swrc;
1025 SW_LARGENUMBER largenum;
1026 int acquired = 0;
1027 int to_return = 0; /* assume failure */
1028 unsigned char buf32[1024];
1029
1030
1031 if (!get_context(&hac))
1032 {
1033 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_UNIT_FAILURE);
1034 goto err;
1035 }
1036 acquired = 1;
1037
1038 /************************************************************************/
1039 /* 04/02/2003 */
1040 /* Modified by Frederic Giudicelli (deny-all.com) to overcome the */
1041 /* limitation of cswift with values not a multiple of 32 */
1042 /************************************************************************/
1043
1044 while(num >= sizeof(buf32))
1045 {
1046 largenum.value = buf;
1047 largenum.nbytes = sizeof(buf32);
1048 /* tell CryptoSwift how many bytes we want and where we want it.
1049 * Note: - CryptoSwift cannot do more than 4096 bytes at a time.
1050 * - CryptoSwift can only do multiple of 32-bits. */
1051 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
1052 if (swrc != SW_OK)
1053 {
1054 char tmpbuf[20];
1055 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED);
1056 sprintf(tmpbuf, "%ld", swrc);
1057 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
1058 goto err;
1059 }
1060 buf += sizeof(buf32);
1061 num -= sizeof(buf32);
1062 }
1063 if(num)
1064 {
1065 largenum.nbytes = sizeof(buf32);
1066 largenum.value = buf32;
1067 swrc = p_CSwift_SimpleRequest(hac, SW_CMD_RAND, NULL, 0, &largenum, 1);
1068 if (swrc != SW_OK)
1069 {
1070 char tmpbuf[20];
1071 CSWIFTerr(CSWIFT_F_CSWIFT_CTRL, CSWIFT_R_REQUEST_FAILED);
1072 sprintf(tmpbuf, "%ld", swrc);
1073 ERR_add_error_data(2, "CryptoSwift error number is ", tmpbuf);
1074 goto err;
1075 }
1076 memcpy(buf, largenum.value, num);
1077 }
1078
1079 to_return = 1; /* success */
1080err:
1081 if (acquired)
1082 release_context(hac);
1083
1084 return to_return;
1085}
1086
1087static int cswift_rand_status(void)
1088{
1089 return 1;
1090}
1091
1092
1093/* This stuff is needed if this ENGINE is being compiled into a self-contained
1094 * shared-library. */
1095#ifdef ENGINE_DYNAMIC_SUPPORT
1096static int bind_fn(ENGINE *e, const char *id)
1097 {
1098 if(id && (strcmp(id, engine_cswift_id) != 0))
1099 return 0;
1100 if(!bind_helper(e))
1101 return 0;
1102 return 1;
1103 }
1104IMPLEMENT_DYNAMIC_CHECK_FN()
1105IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
1106#endif /* ENGINE_DYNAMIC_SUPPORT */
1107
1108#endif /* !OPENSSL_NO_HW_CSWIFT */
1109#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.c b/src/lib/libcrypto/engine/hw_cswift_err.c
new file mode 100644
index 0000000000..684f53bf27
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift_err.c
@@ -0,0 +1,149 @@
1/* hw_cswift_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_cswift_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA CSWIFT_str_functs[]=
68 {
69{ERR_PACK(0,CSWIFT_F_CSWIFT_CTRL,0), "CSWIFT_CTRL"},
70{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_SIGN,0), "CSWIFT_DSA_SIGN"},
71{ERR_PACK(0,CSWIFT_F_CSWIFT_DSA_VERIFY,0), "CSWIFT_DSA_VERIFY"},
72{ERR_PACK(0,CSWIFT_F_CSWIFT_FINISH,0), "CSWIFT_FINISH"},
73{ERR_PACK(0,CSWIFT_F_CSWIFT_INIT,0), "CSWIFT_INIT"},
74{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP,0), "CSWIFT_MOD_EXP"},
75{ERR_PACK(0,CSWIFT_F_CSWIFT_MOD_EXP_CRT,0), "CSWIFT_MOD_EXP_CRT"},
76{ERR_PACK(0,CSWIFT_F_CSWIFT_RSA_MOD_EXP,0), "CSWIFT_RSA_MOD_EXP"},
77{0,NULL}
78 };
79
80static ERR_STRING_DATA CSWIFT_str_reasons[]=
81 {
82{CSWIFT_R_ALREADY_LOADED ,"already loaded"},
83{CSWIFT_R_BAD_KEY_SIZE ,"bad key size"},
84{CSWIFT_R_BN_CTX_FULL ,"bn ctx full"},
85{CSWIFT_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{CSWIFT_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{CSWIFT_R_NOT_LOADED ,"not loaded"},
89{CSWIFT_R_REQUEST_FAILED ,"request failed"},
90{CSWIFT_R_UNIT_FAILURE ,"unit failure"},
91{0,NULL}
92 };
93
94#endif
95
96#ifdef CSWIFT_LIB_NAME
97static ERR_STRING_DATA CSWIFT_lib_name[]=
98 {
99{0 ,CSWIFT_LIB_NAME},
100{0,NULL}
101 };
102#endif
103
104
105static int CSWIFT_lib_error_code=0;
106static int CSWIFT_error_init=1;
107
108static void ERR_load_CSWIFT_strings(void)
109 {
110 if (CSWIFT_lib_error_code == 0)
111 CSWIFT_lib_error_code=ERR_get_next_error_library();
112
113 if (CSWIFT_error_init)
114 {
115 CSWIFT_error_init=0;
116#ifndef OPENSSL_NO_ERR
117 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
118 ERR_load_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
119#endif
120
121#ifdef CSWIFT_LIB_NAME
122 CSWIFT_lib_name->error = ERR_PACK(CSWIFT_lib_error_code,0,0);
123 ERR_load_strings(0,CSWIFT_lib_name);
124#endif
125 }
126 }
127
128static void ERR_unload_CSWIFT_strings(void)
129 {
130 if (CSWIFT_error_init == 0)
131 {
132#ifndef OPENSSL_NO_ERR
133 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_functs);
134 ERR_unload_strings(CSWIFT_lib_error_code,CSWIFT_str_reasons);
135#endif
136
137#ifdef CSWIFT_LIB_NAME
138 ERR_unload_strings(0,CSWIFT_lib_name);
139#endif
140 CSWIFT_error_init=1;
141 }
142 }
143
144static void ERR_CSWIFT_error(int function, int reason, char *file, int line)
145 {
146 if (CSWIFT_lib_error_code == 0)
147 CSWIFT_lib_error_code=ERR_get_next_error_library();
148 ERR_PUT_error(CSWIFT_lib_error_code,function,reason,file,line);
149 }
diff --git a/src/lib/libcrypto/engine/hw_cswift_err.h b/src/lib/libcrypto/engine/hw_cswift_err.h
new file mode 100644
index 0000000000..7120c3216f
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_cswift_err.h
@@ -0,0 +1,93 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_CSWIFT_ERR_H
56#define HEADER_CSWIFT_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_CSWIFT_strings(void);
63static void ERR_unload_CSWIFT_strings(void);
64static void ERR_CSWIFT_error(int function, int reason, char *file, int line);
65#define CSWIFTerr(f,r) ERR_CSWIFT_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the CSWIFT functions. */
68
69/* Function codes. */
70#define CSWIFT_F_CSWIFT_CTRL 100
71#define CSWIFT_F_CSWIFT_DSA_SIGN 101
72#define CSWIFT_F_CSWIFT_DSA_VERIFY 102
73#define CSWIFT_F_CSWIFT_FINISH 103
74#define CSWIFT_F_CSWIFT_INIT 104
75#define CSWIFT_F_CSWIFT_MOD_EXP 105
76#define CSWIFT_F_CSWIFT_MOD_EXP_CRT 106
77#define CSWIFT_F_CSWIFT_RSA_MOD_EXP 107
78
79/* Reason codes. */
80#define CSWIFT_R_ALREADY_LOADED 100
81#define CSWIFT_R_BAD_KEY_SIZE 101
82#define CSWIFT_R_BN_CTX_FULL 102
83#define CSWIFT_R_BN_EXPAND_FAIL 103
84#define CSWIFT_R_CTRL_COMMAND_NOT_IMPLEMENTED 104
85#define CSWIFT_R_MISSING_KEY_COMPONENTS 105
86#define CSWIFT_R_NOT_LOADED 106
87#define CSWIFT_R_REQUEST_FAILED 107
88#define CSWIFT_R_UNIT_FAILURE 108
89
90#ifdef __cplusplus
91}
92#endif
93#endif
diff --git a/src/lib/libcrypto/engine/hw_ncipher.c b/src/lib/libcrypto/engine/hw_ncipher.c
new file mode 100644
index 0000000000..0d1c6b8df0
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher.c
@@ -0,0 +1,1388 @@
1/* crypto/engine/hw_ncipher.c -*- mode: C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org), Geoff Thorpe
3 * (geoff@geoffthorpe.net) and Dr Stephen N Henson (shenson@bigfoot.com)
4 * for the OpenSSL project 2000.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * licensing@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <stdio.h>
61#include <string.h>
62#include "cryptlib.h"
63#include <openssl/crypto.h>
64#include <openssl/pem.h>
65#include <openssl/dso.h>
66#include <openssl/engine.h>
67#include <openssl/ui.h>
68
69#ifndef OPENSSL_NO_HW
70#ifndef OPENSSL_NO_HW_NCIPHER
71
72/* Attribution notice: nCipher have said several times that it's OK for
73 * us to implement a general interface to their boxes, and recently declared
74 * their HWCryptoHook to be public, and therefore available for us to use.
75 * Thanks, nCipher.
76 *
77 * The hwcryptohook.h included here is from May 2000.
78 * [Richard Levitte]
79 */
80#ifdef FLAT_INC
81#include "hwcryptohook.h"
82#else
83#include "vendor_defns/hwcryptohook.h"
84#endif
85
86#define HWCRHK_LIB_NAME "hwcrhk engine"
87#include "hw_ncipher_err.c"
88
89static int hwcrhk_destroy(ENGINE *e);
90static int hwcrhk_init(ENGINE *e);
91static int hwcrhk_finish(ENGINE *e);
92static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
93
94/* Functions to handle mutexes if have dynamic locks */
95static int hwcrhk_mutex_init(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext*);
96static int hwcrhk_mutex_lock(HWCryptoHook_Mutex*);
97static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex*);
98static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex*);
99#if 1 /* This is a HACK which will disappear in 0.9.8 */
100/* Functions to handle mutexes if only have static locks */
101static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m,
102 HWCryptoHook_CallerContext *c);
103static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m);
104static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m);
105static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m);
106#endif
107
108/* BIGNUM stuff */
109static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
110 const BIGNUM *m, BN_CTX *ctx);
111
112#ifndef OPENSSL_NO_RSA
113/* RSA stuff */
114static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa);
115#endif
116/* This function is aliased to mod_exp (with the mont stuff dropped). */
117static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
118 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
119
120#ifndef OPENSSL_NO_DH
121/* DH stuff */
122/* This function is alised to mod_exp (with the DH and mont dropped). */
123static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
124 const BIGNUM *a, const BIGNUM *p,
125 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
126#endif
127
128/* RAND stuff */
129static int hwcrhk_rand_bytes(unsigned char *buf, int num);
130static int hwcrhk_rand_status(void);
131
132/* KM stuff */
133static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
134 UI_METHOD *ui_method, void *callback_data);
135static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
136 UI_METHOD *ui_method, void *callback_data);
137static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
138 int ind,long argl, void *argp);
139
140/* Interaction stuff */
141static int hwcrhk_insert_card(const char *prompt_info,
142 const char *wrong_info,
143 HWCryptoHook_PassphraseContext *ppctx,
144 HWCryptoHook_CallerContext *cactx);
145static int hwcrhk_get_pass(const char *prompt_info,
146 int *len_io, char *buf,
147 HWCryptoHook_PassphraseContext *ppctx,
148 HWCryptoHook_CallerContext *cactx);
149static void hwcrhk_log_message(void *logstr, const char *message);
150
151/* The definitions for control commands specific to this engine */
152#define HWCRHK_CMD_SO_PATH ENGINE_CMD_BASE
153#define HWCRHK_CMD_FORK_CHECK (ENGINE_CMD_BASE + 1)
154#define HWCRHK_CMD_THREAD_LOCKING (ENGINE_CMD_BASE + 2)
155#define HWCRHK_CMD_SET_USER_INTERFACE (ENGINE_CMD_BASE + 3)
156#define HWCRHK_CMD_SET_CALLBACK_DATA (ENGINE_CMD_BASE + 4)
157static const ENGINE_CMD_DEFN hwcrhk_cmd_defns[] = {
158 {HWCRHK_CMD_SO_PATH,
159 "SO_PATH",
160 "Specifies the path to the 'hwcrhk' shared library",
161 ENGINE_CMD_FLAG_STRING},
162 {HWCRHK_CMD_FORK_CHECK,
163 "FORK_CHECK",
164 "Turns fork() checking on or off (boolean)",
165 ENGINE_CMD_FLAG_NUMERIC},
166 {HWCRHK_CMD_THREAD_LOCKING,
167 "THREAD_LOCKING",
168 "Turns thread-safe locking on or off (boolean)",
169 ENGINE_CMD_FLAG_NUMERIC},
170 {HWCRHK_CMD_SET_USER_INTERFACE,
171 "SET_USER_INTERFACE",
172 "Set the global user interface (internal)",
173 ENGINE_CMD_FLAG_INTERNAL},
174 {HWCRHK_CMD_SET_CALLBACK_DATA,
175 "SET_CALLBACK_DATA",
176 "Set the global user interface extra data (internal)",
177 ENGINE_CMD_FLAG_INTERNAL},
178 {0, NULL, NULL, 0}
179 };
180
181#ifndef OPENSSL_NO_RSA
182/* Our internal RSA_METHOD that we provide pointers to */
183static RSA_METHOD hwcrhk_rsa =
184 {
185 "nCipher RSA method",
186 NULL,
187 NULL,
188 NULL,
189 NULL,
190 hwcrhk_rsa_mod_exp,
191 hwcrhk_mod_exp_mont,
192 NULL,
193 NULL,
194 0,
195 NULL,
196 NULL,
197 NULL
198 };
199#endif
200
201#ifndef OPENSSL_NO_DH
202/* Our internal DH_METHOD that we provide pointers to */
203static DH_METHOD hwcrhk_dh =
204 {
205 "nCipher DH method",
206 NULL,
207 NULL,
208 hwcrhk_mod_exp_dh,
209 NULL,
210 NULL,
211 0,
212 NULL
213 };
214#endif
215
216static RAND_METHOD hwcrhk_rand =
217 {
218 /* "nCipher RAND method", */
219 NULL,
220 hwcrhk_rand_bytes,
221 NULL,
222 NULL,
223 hwcrhk_rand_bytes,
224 hwcrhk_rand_status,
225 };
226
227/* Constants used when creating the ENGINE */
228static const char *engine_hwcrhk_id = "chil";
229static const char *engine_hwcrhk_name = "nCipher hardware engine support";
230
231/* Internal stuff for HWCryptoHook */
232
233/* Some structures needed for proper use of thread locks */
234/* hwcryptohook.h has some typedefs that turn struct HWCryptoHook_MutexValue
235 into HWCryptoHook_Mutex */
236struct HWCryptoHook_MutexValue
237 {
238 int lockid;
239 };
240
241/* hwcryptohook.h has some typedefs that turn
242 struct HWCryptoHook_PassphraseContextValue
243 into HWCryptoHook_PassphraseContext */
244struct HWCryptoHook_PassphraseContextValue
245 {
246 UI_METHOD *ui_method;
247 void *callback_data;
248 };
249
250/* hwcryptohook.h has some typedefs that turn
251 struct HWCryptoHook_CallerContextValue
252 into HWCryptoHook_CallerContext */
253struct HWCryptoHook_CallerContextValue
254 {
255 pem_password_cb *password_callback; /* Deprecated! Only present for
256 backward compatibility! */
257 UI_METHOD *ui_method;
258 void *callback_data;
259 };
260
261/* The MPI structure in HWCryptoHook is pretty compatible with OpenSSL
262 BIGNUM's, so lets define a couple of conversion macros */
263#define BN2MPI(mp, bn) \
264 {mp.size = bn->top * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
265#define MPI2BN(bn, mp) \
266 {mp.size = bn->dmax * sizeof(BN_ULONG); mp.buf = (unsigned char *)bn->d;}
267
268static BIO *logstream = NULL;
269static int disable_mutex_callbacks = 0;
270
271/* One might wonder why these are needed, since one can pass down at least
272 a UI_METHOD and a pointer to callback data to the key-loading functions.
273 The thing is that the ModExp and RSAImmed functions can load keys as well,
274 if the data they get is in a special, nCipher-defined format (hint: if you
275 look at the private exponent of the RSA data as a string, you'll see this
276 string: "nCipher KM tool key id", followed by some bytes, followed a key
277 identity string, followed by more bytes. This happens when you use "embed"
278 keys instead of "hwcrhk" keys). Unfortunately, those functions do not take
279 any passphrase or caller context, and our functions can't really take any
280 callback data either. Still, the "insert_card" and "get_passphrase"
281 callbacks may be called down the line, and will need to know what user
282 interface callbacks to call, and having callback data from the application
283 may be a nice thing as well, so we need to keep track of that globally. */
284static HWCryptoHook_CallerContext password_context = { NULL, NULL, NULL };
285
286/* Stuff to pass to the HWCryptoHook library */
287static HWCryptoHook_InitInfo hwcrhk_globals = {
288 HWCryptoHook_InitFlags_SimpleForkCheck, /* Flags */
289 &logstream, /* logstream */
290 sizeof(BN_ULONG), /* limbsize */
291 0, /* mslimb first: false for BNs */
292 -1, /* msbyte first: use native */
293 0, /* Max mutexes, 0 = no small limit */
294 0, /* Max simultaneous, 0 = default */
295
296 /* The next few are mutex stuff: we write wrapper functions
297 around the OS mutex functions. We initialise them to 0
298 here, and change that to actual function pointers in hwcrhk_init()
299 if dynamic locks are supported (that is, if the application
300 programmer has made sure of setting up callbacks bafore starting
301 this engine) *and* if disable_mutex_callbacks hasn't been set by
302 a call to ENGINE_ctrl(ENGINE_CTRL_CHIL_NO_LOCKING). */
303 sizeof(HWCryptoHook_Mutex),
304 0,
305 0,
306 0,
307 0,
308
309 /* The next few are condvar stuff: we write wrapper functions
310 round the OS functions. Currently not implemented and not
311 and absolute necessity even in threaded programs, therefore
312 0'ed. Will hopefully be implemented some day, since it
313 enhances the efficiency of HWCryptoHook. */
314 0, /* sizeof(HWCryptoHook_CondVar), */
315 0, /* hwcrhk_cv_init, */
316 0, /* hwcrhk_cv_wait, */
317 0, /* hwcrhk_cv_signal, */
318 0, /* hwcrhk_cv_broadcast, */
319 0, /* hwcrhk_cv_destroy, */
320
321 hwcrhk_get_pass, /* pass phrase */
322 hwcrhk_insert_card, /* insert a card */
323 hwcrhk_log_message /* Log message */
324};
325
326
327/* Now, to our own code */
328
329/* This internal function is used by ENGINE_ncipher() and possibly by the
330 * "dynamic" ENGINE support too */
331static int bind_helper(ENGINE *e)
332 {
333#ifndef OPENSSL_NO_RSA
334 const RSA_METHOD *meth1;
335#endif
336#ifndef OPENSSL_NO_DH
337 const DH_METHOD *meth2;
338#endif
339 if(!ENGINE_set_id(e, engine_hwcrhk_id) ||
340 !ENGINE_set_name(e, engine_hwcrhk_name) ||
341#ifndef OPENSSL_NO_RSA
342 !ENGINE_set_RSA(e, &hwcrhk_rsa) ||
343#endif
344#ifndef OPENSSL_NO_DH
345 !ENGINE_set_DH(e, &hwcrhk_dh) ||
346#endif
347 !ENGINE_set_RAND(e, &hwcrhk_rand) ||
348 !ENGINE_set_destroy_function(e, hwcrhk_destroy) ||
349 !ENGINE_set_init_function(e, hwcrhk_init) ||
350 !ENGINE_set_finish_function(e, hwcrhk_finish) ||
351 !ENGINE_set_ctrl_function(e, hwcrhk_ctrl) ||
352 !ENGINE_set_load_privkey_function(e, hwcrhk_load_privkey) ||
353 !ENGINE_set_load_pubkey_function(e, hwcrhk_load_pubkey) ||
354 !ENGINE_set_cmd_defns(e, hwcrhk_cmd_defns))
355 return 0;
356
357#ifndef OPENSSL_NO_RSA
358 /* We know that the "PKCS1_SSLeay()" functions hook properly
359 * to the cswift-specific mod_exp and mod_exp_crt so we use
360 * those functions. NB: We don't use ENGINE_openssl() or
361 * anything "more generic" because something like the RSAref
362 * code may not hook properly, and if you own one of these
363 * cards then you have the right to do RSA operations on it
364 * anyway! */
365 meth1 = RSA_PKCS1_SSLeay();
366 hwcrhk_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
367 hwcrhk_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
368 hwcrhk_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
369 hwcrhk_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
370#endif
371
372#ifndef OPENSSL_NO_DH
373 /* Much the same for Diffie-Hellman */
374 meth2 = DH_OpenSSL();
375 hwcrhk_dh.generate_key = meth2->generate_key;
376 hwcrhk_dh.compute_key = meth2->compute_key;
377#endif
378
379 /* Ensure the hwcrhk error handling is set up */
380 ERR_load_HWCRHK_strings();
381 return 1;
382 }
383
384#ifndef ENGINE_DYNAMIC_SUPPORT
385static ENGINE *engine_ncipher(void)
386 {
387 ENGINE *ret = ENGINE_new();
388 if(!ret)
389 return NULL;
390 if(!bind_helper(ret))
391 {
392 ENGINE_free(ret);
393 return NULL;
394 }
395 return ret;
396 }
397
398void ENGINE_load_chil(void)
399 {
400 /* Copied from eng_[openssl|dyn].c */
401 ENGINE *toadd = engine_ncipher();
402 if(!toadd) return;
403 ENGINE_add(toadd);
404 ENGINE_free(toadd);
405 ERR_clear_error();
406 }
407#endif
408
409/* This is a process-global DSO handle used for loading and unloading
410 * the HWCryptoHook library. NB: This is only set (or unset) during an
411 * init() or finish() call (reference counts permitting) and they're
412 * operating with global locks, so this should be thread-safe
413 * implicitly. */
414static DSO *hwcrhk_dso = NULL;
415static HWCryptoHook_ContextHandle hwcrhk_context = 0;
416#ifndef OPENSSL_NO_RSA
417static int hndidx_rsa = -1; /* Index for KM handle. Not really used yet. */
418#endif
419
420/* These are the function pointers that are (un)set when the library has
421 * successfully (un)loaded. */
422static HWCryptoHook_Init_t *p_hwcrhk_Init = NULL;
423static HWCryptoHook_Finish_t *p_hwcrhk_Finish = NULL;
424static HWCryptoHook_ModExp_t *p_hwcrhk_ModExp = NULL;
425#ifndef OPENSSL_NO_RSA
426static HWCryptoHook_RSA_t *p_hwcrhk_RSA = NULL;
427#endif
428static HWCryptoHook_RandomBytes_t *p_hwcrhk_RandomBytes = NULL;
429#ifndef OPENSSL_NO_RSA
430static HWCryptoHook_RSALoadKey_t *p_hwcrhk_RSALoadKey = NULL;
431static HWCryptoHook_RSAGetPublicKey_t *p_hwcrhk_RSAGetPublicKey = NULL;
432static HWCryptoHook_RSAUnloadKey_t *p_hwcrhk_RSAUnloadKey = NULL;
433#endif
434static HWCryptoHook_ModExpCRT_t *p_hwcrhk_ModExpCRT = NULL;
435
436/* Used in the DSO operations. */
437static const char *HWCRHK_LIBNAME = NULL;
438static void free_HWCRHK_LIBNAME(void)
439 {
440 if(HWCRHK_LIBNAME)
441 OPENSSL_free((void*)HWCRHK_LIBNAME);
442 HWCRHK_LIBNAME = NULL;
443 }
444static const char *get_HWCRHK_LIBNAME(void)
445 {
446 if(HWCRHK_LIBNAME)
447 return HWCRHK_LIBNAME;
448 return "nfhwcrhk";
449 }
450static long set_HWCRHK_LIBNAME(const char *name)
451 {
452 free_HWCRHK_LIBNAME();
453 return (((HWCRHK_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
454 }
455static const char *n_hwcrhk_Init = "HWCryptoHook_Init";
456static const char *n_hwcrhk_Finish = "HWCryptoHook_Finish";
457static const char *n_hwcrhk_ModExp = "HWCryptoHook_ModExp";
458#ifndef OPENSSL_NO_RSA
459static const char *n_hwcrhk_RSA = "HWCryptoHook_RSA";
460#endif
461static const char *n_hwcrhk_RandomBytes = "HWCryptoHook_RandomBytes";
462#ifndef OPENSSL_NO_RSA
463static const char *n_hwcrhk_RSALoadKey = "HWCryptoHook_RSALoadKey";
464static const char *n_hwcrhk_RSAGetPublicKey = "HWCryptoHook_RSAGetPublicKey";
465static const char *n_hwcrhk_RSAUnloadKey = "HWCryptoHook_RSAUnloadKey";
466#endif
467static const char *n_hwcrhk_ModExpCRT = "HWCryptoHook_ModExpCRT";
468
469/* HWCryptoHook library functions and mechanics - these are used by the
470 * higher-level functions further down. NB: As and where there's no
471 * error checking, take a look lower down where these functions are
472 * called, the checking and error handling is probably down there. */
473
474/* utility function to obtain a context */
475static int get_context(HWCryptoHook_ContextHandle *hac,
476 HWCryptoHook_CallerContext *cac)
477 {
478 char tempbuf[1024];
479 HWCryptoHook_ErrMsgBuf rmsg;
480
481 rmsg.buf = tempbuf;
482 rmsg.size = sizeof(tempbuf);
483
484 *hac = p_hwcrhk_Init(&hwcrhk_globals, sizeof(hwcrhk_globals), &rmsg,
485 cac);
486 if (!*hac)
487 return 0;
488 return 1;
489 }
490
491/* similarly to release one. */
492static void release_context(HWCryptoHook_ContextHandle hac)
493 {
494 p_hwcrhk_Finish(hac);
495 }
496
497/* Destructor (complements the "ENGINE_ncipher()" constructor) */
498static int hwcrhk_destroy(ENGINE *e)
499 {
500 free_HWCRHK_LIBNAME();
501 ERR_unload_HWCRHK_strings();
502 return 1;
503 }
504
505/* (de)initialisation functions. */
506static int hwcrhk_init(ENGINE *e)
507 {
508 HWCryptoHook_Init_t *p1;
509 HWCryptoHook_Finish_t *p2;
510 HWCryptoHook_ModExp_t *p3;
511#ifndef OPENSSL_NO_RSA
512 HWCryptoHook_RSA_t *p4;
513 HWCryptoHook_RSALoadKey_t *p5;
514 HWCryptoHook_RSAGetPublicKey_t *p6;
515 HWCryptoHook_RSAUnloadKey_t *p7;
516#endif
517 HWCryptoHook_RandomBytes_t *p8;
518 HWCryptoHook_ModExpCRT_t *p9;
519
520 if(hwcrhk_dso != NULL)
521 {
522 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_ALREADY_LOADED);
523 goto err;
524 }
525 /* Attempt to load libnfhwcrhk.so/nfhwcrhk.dll/whatever. */
526 hwcrhk_dso = DSO_load(NULL, get_HWCRHK_LIBNAME(), NULL, 0);
527 if(hwcrhk_dso == NULL)
528 {
529 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
530 goto err;
531 }
532 if(!(p1 = (HWCryptoHook_Init_t *)
533 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Init)) ||
534 !(p2 = (HWCryptoHook_Finish_t *)
535 DSO_bind_func(hwcrhk_dso, n_hwcrhk_Finish)) ||
536 !(p3 = (HWCryptoHook_ModExp_t *)
537 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExp)) ||
538#ifndef OPENSSL_NO_RSA
539 !(p4 = (HWCryptoHook_RSA_t *)
540 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSA)) ||
541 !(p5 = (HWCryptoHook_RSALoadKey_t *)
542 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSALoadKey)) ||
543 !(p6 = (HWCryptoHook_RSAGetPublicKey_t *)
544 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAGetPublicKey)) ||
545 !(p7 = (HWCryptoHook_RSAUnloadKey_t *)
546 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RSAUnloadKey)) ||
547#endif
548 !(p8 = (HWCryptoHook_RandomBytes_t *)
549 DSO_bind_func(hwcrhk_dso, n_hwcrhk_RandomBytes)) ||
550 !(p9 = (HWCryptoHook_ModExpCRT_t *)
551 DSO_bind_func(hwcrhk_dso, n_hwcrhk_ModExpCRT)))
552 {
553 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DSO_FAILURE);
554 goto err;
555 }
556 /* Copy the pointers */
557 p_hwcrhk_Init = p1;
558 p_hwcrhk_Finish = p2;
559 p_hwcrhk_ModExp = p3;
560#ifndef OPENSSL_NO_RSA
561 p_hwcrhk_RSA = p4;
562 p_hwcrhk_RSALoadKey = p5;
563 p_hwcrhk_RSAGetPublicKey = p6;
564 p_hwcrhk_RSAUnloadKey = p7;
565#endif
566 p_hwcrhk_RandomBytes = p8;
567 p_hwcrhk_ModExpCRT = p9;
568
569 /* Check if the application decided to support dynamic locks,
570 and if it does, use them. */
571 if (disable_mutex_callbacks == 0)
572 {
573 if (CRYPTO_get_dynlock_create_callback() != NULL &&
574 CRYPTO_get_dynlock_lock_callback() != NULL &&
575 CRYPTO_get_dynlock_destroy_callback() != NULL)
576 {
577 hwcrhk_globals.mutex_init = hwcrhk_mutex_init;
578 hwcrhk_globals.mutex_acquire = hwcrhk_mutex_lock;
579 hwcrhk_globals.mutex_release = hwcrhk_mutex_unlock;
580 hwcrhk_globals.mutex_destroy = hwcrhk_mutex_destroy;
581 }
582 else if (CRYPTO_get_locking_callback() != NULL)
583 {
584 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_DYNAMIC_LOCKING_MISSING);
585 ERR_add_error_data(1,"You HAVE to add dynamic locking callbacks via CRYPTO_set_dynlock_{create,lock,destroy}_callback()");
586#if 1 /* This is a HACK which will disappear in 0.9.8 */
587 hwcrhk_globals.maxmutexes = 1; /* Only have one lock */
588 hwcrhk_globals.mutex_init = hwcrhk_static_mutex_init;
589 hwcrhk_globals.mutex_acquire = hwcrhk_static_mutex_lock;
590 hwcrhk_globals.mutex_release = hwcrhk_static_mutex_unlock;
591 hwcrhk_globals.mutex_destroy = hwcrhk_static_mutex_destroy;
592#else
593 goto err;
594#endif
595 }
596 }
597
598 /* Try and get a context - if not, we may have a DSO but no
599 * accelerator! */
600 if(!get_context(&hwcrhk_context, &password_context))
601 {
602 HWCRHKerr(HWCRHK_F_HWCRHK_INIT,HWCRHK_R_UNIT_FAILURE);
603 goto err;
604 }
605 /* Everything's fine. */
606#ifndef OPENSSL_NO_RSA
607 if (hndidx_rsa == -1)
608 hndidx_rsa = RSA_get_ex_new_index(0,
609 "nFast HWCryptoHook RSA key handle",
610 NULL, NULL, hwcrhk_ex_free);
611#endif
612 return 1;
613err:
614 if(hwcrhk_dso)
615 DSO_free(hwcrhk_dso);
616 hwcrhk_dso = NULL;
617 p_hwcrhk_Init = NULL;
618 p_hwcrhk_Finish = NULL;
619 p_hwcrhk_ModExp = NULL;
620#ifndef OPENSSL_NO_RSA
621 p_hwcrhk_RSA = NULL;
622 p_hwcrhk_RSALoadKey = NULL;
623 p_hwcrhk_RSAGetPublicKey = NULL;
624 p_hwcrhk_RSAUnloadKey = NULL;
625#endif
626 p_hwcrhk_ModExpCRT = NULL;
627 p_hwcrhk_RandomBytes = NULL;
628 return 0;
629 }
630
631static int hwcrhk_finish(ENGINE *e)
632 {
633 int to_return = 1;
634 free_HWCRHK_LIBNAME();
635 if(hwcrhk_dso == NULL)
636 {
637 HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_NOT_LOADED);
638 to_return = 0;
639 goto err;
640 }
641 release_context(hwcrhk_context);
642 if(!DSO_free(hwcrhk_dso))
643 {
644 HWCRHKerr(HWCRHK_F_HWCRHK_FINISH,HWCRHK_R_DSO_FAILURE);
645 to_return = 0;
646 goto err;
647 }
648 err:
649 if (logstream)
650 BIO_free(logstream);
651 hwcrhk_dso = NULL;
652 p_hwcrhk_Init = NULL;
653 p_hwcrhk_Finish = NULL;
654 p_hwcrhk_ModExp = NULL;
655#ifndef OPENSSL_NO_RSA
656 p_hwcrhk_RSA = NULL;
657 p_hwcrhk_RSALoadKey = NULL;
658 p_hwcrhk_RSAGetPublicKey = NULL;
659 p_hwcrhk_RSAUnloadKey = NULL;
660#endif
661 p_hwcrhk_ModExpCRT = NULL;
662 p_hwcrhk_RandomBytes = NULL;
663 return to_return;
664 }
665
666static int hwcrhk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
667 {
668 int to_return = 1;
669
670 switch(cmd)
671 {
672 case HWCRHK_CMD_SO_PATH:
673 if(hwcrhk_dso)
674 {
675 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_ALREADY_LOADED);
676 return 0;
677 }
678 if(p == NULL)
679 {
680 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,ERR_R_PASSED_NULL_PARAMETER);
681 return 0;
682 }
683 return set_HWCRHK_LIBNAME((const char *)p);
684 case ENGINE_CTRL_SET_LOGSTREAM:
685 {
686 BIO *bio = (BIO *)p;
687
688 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
689 if (logstream)
690 {
691 BIO_free(logstream);
692 logstream = NULL;
693 }
694 if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1)
695 logstream = bio;
696 else
697 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,HWCRHK_R_BIO_WAS_FREED);
698 }
699 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
700 break;
701 case ENGINE_CTRL_SET_PASSWORD_CALLBACK:
702 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
703 password_context.password_callback = (pem_password_cb *)f;
704 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
705 break;
706 case ENGINE_CTRL_SET_USER_INTERFACE:
707 case HWCRHK_CMD_SET_USER_INTERFACE:
708 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
709 password_context.ui_method = (UI_METHOD *)p;
710 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
711 break;
712 case ENGINE_CTRL_SET_CALLBACK_DATA:
713 case HWCRHK_CMD_SET_CALLBACK_DATA:
714 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
715 password_context.callback_data = p;
716 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
717 break;
718 /* this enables or disables the "SimpleForkCheck" flag used in the
719 * initialisation structure. */
720 case ENGINE_CTRL_CHIL_SET_FORKCHECK:
721 case HWCRHK_CMD_FORK_CHECK:
722 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
723 if(i)
724 hwcrhk_globals.flags |=
725 HWCryptoHook_InitFlags_SimpleForkCheck;
726 else
727 hwcrhk_globals.flags &=
728 ~HWCryptoHook_InitFlags_SimpleForkCheck;
729 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
730 break;
731 /* This will prevent the initialisation function from "installing"
732 * the mutex-handling callbacks, even if they are available from
733 * within the library (or were provided to the library from the
734 * calling application). This is to remove any baggage for
735 * applications not using multithreading. */
736 case ENGINE_CTRL_CHIL_NO_LOCKING:
737 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
738 disable_mutex_callbacks = 1;
739 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
740 break;
741 case HWCRHK_CMD_THREAD_LOCKING:
742 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
743 disable_mutex_callbacks = ((i == 0) ? 0 : 1);
744 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
745 break;
746
747 /* The command isn't understood by this engine */
748 default:
749 HWCRHKerr(HWCRHK_F_HWCRHK_CTRL,
750 HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED);
751 to_return = 0;
752 break;
753 }
754
755 return to_return;
756 }
757
758static EVP_PKEY *hwcrhk_load_privkey(ENGINE *eng, const char *key_id,
759 UI_METHOD *ui_method, void *callback_data)
760 {
761#ifndef OPENSSL_NO_RSA
762 RSA *rtmp = NULL;
763#endif
764 EVP_PKEY *res = NULL;
765#ifndef OPENSSL_NO_RSA
766 HWCryptoHook_MPI e, n;
767 HWCryptoHook_RSAKeyHandle *hptr;
768#endif
769#if !defined(OPENSSL_NO_RSA)
770 char tempbuf[1024];
771 HWCryptoHook_ErrMsgBuf rmsg;
772#endif
773 HWCryptoHook_PassphraseContext ppctx;
774
775#if !defined(OPENSSL_NO_RSA)
776 rmsg.buf = tempbuf;
777 rmsg.size = sizeof(tempbuf);
778#endif
779
780 if(!hwcrhk_context)
781 {
782 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
783 HWCRHK_R_NOT_INITIALISED);
784 goto err;
785 }
786#ifndef OPENSSL_NO_RSA
787 hptr = OPENSSL_malloc(sizeof(HWCryptoHook_RSAKeyHandle));
788 if (!hptr)
789 {
790 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
791 ERR_R_MALLOC_FAILURE);
792 goto err;
793 }
794 ppctx.ui_method = ui_method;
795 ppctx.callback_data = callback_data;
796 if (p_hwcrhk_RSALoadKey(hwcrhk_context, key_id, hptr,
797 &rmsg, &ppctx))
798 {
799 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
800 HWCRHK_R_CHIL_ERROR);
801 ERR_add_error_data(1,rmsg.buf);
802 goto err;
803 }
804 if (!*hptr)
805 {
806 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PRIVKEY,
807 HWCRHK_R_NO_KEY);
808 goto err;
809 }
810#endif
811#ifndef OPENSSL_NO_RSA
812 rtmp = RSA_new_method(eng);
813 RSA_set_ex_data(rtmp, hndidx_rsa, (char *)hptr);
814 rtmp->e = BN_new();
815 rtmp->n = BN_new();
816 rtmp->flags |= RSA_FLAG_EXT_PKEY;
817 MPI2BN(rtmp->e, e);
818 MPI2BN(rtmp->n, n);
819 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg)
820 != HWCRYPTOHOOK_ERROR_MPISIZE)
821 {
822 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,HWCRHK_R_CHIL_ERROR);
823 ERR_add_error_data(1,rmsg.buf);
824 goto err;
825 }
826
827 bn_expand2(rtmp->e, e.size/sizeof(BN_ULONG));
828 bn_expand2(rtmp->n, n.size/sizeof(BN_ULONG));
829 MPI2BN(rtmp->e, e);
830 MPI2BN(rtmp->n, n);
831
832 if (p_hwcrhk_RSAGetPublicKey(*hptr, &n, &e, &rmsg))
833 {
834 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,
835 HWCRHK_R_CHIL_ERROR);
836 ERR_add_error_data(1,rmsg.buf);
837 goto err;
838 }
839 rtmp->e->top = e.size / sizeof(BN_ULONG);
840 bn_fix_top(rtmp->e);
841 rtmp->n->top = n.size / sizeof(BN_ULONG);
842 bn_fix_top(rtmp->n);
843
844 res = EVP_PKEY_new();
845 EVP_PKEY_assign_RSA(res, rtmp);
846#endif
847
848 if (!res)
849 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,
850 HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED);
851
852 return res;
853 err:
854 if (res)
855 EVP_PKEY_free(res);
856#ifndef OPENSSL_NO_RSA
857 if (rtmp)
858 RSA_free(rtmp);
859#endif
860 return NULL;
861 }
862
863static EVP_PKEY *hwcrhk_load_pubkey(ENGINE *eng, const char *key_id,
864 UI_METHOD *ui_method, void *callback_data)
865 {
866 EVP_PKEY *res = NULL;
867
868#ifndef OPENSSL_NO_RSA
869 res = hwcrhk_load_privkey(eng, key_id,
870 ui_method, callback_data);
871#endif
872
873 if (res)
874 switch(res->type)
875 {
876#ifndef OPENSSL_NO_RSA
877 case EVP_PKEY_RSA:
878 {
879 RSA *rsa = NULL;
880
881 CRYPTO_w_lock(CRYPTO_LOCK_EVP_PKEY);
882 rsa = res->pkey.rsa;
883 res->pkey.rsa = RSA_new();
884 res->pkey.rsa->n = rsa->n;
885 res->pkey.rsa->e = rsa->e;
886 rsa->n = NULL;
887 rsa->e = NULL;
888 CRYPTO_w_unlock(CRYPTO_LOCK_EVP_PKEY);
889 RSA_free(rsa);
890 }
891 break;
892#endif
893 default:
894 HWCRHKerr(HWCRHK_F_HWCRHK_LOAD_PUBKEY,
895 HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED);
896 goto err;
897 }
898
899 return res;
900 err:
901 if (res)
902 EVP_PKEY_free(res);
903 return NULL;
904 }
905
906/* A little mod_exp */
907static int hwcrhk_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
908 const BIGNUM *m, BN_CTX *ctx)
909 {
910 char tempbuf[1024];
911 HWCryptoHook_ErrMsgBuf rmsg;
912 /* Since HWCryptoHook_MPI is pretty compatible with BIGNUM's,
913 we use them directly, plus a little macro magic. We only
914 thing we need to make sure of is that enough space is allocated. */
915 HWCryptoHook_MPI m_a, m_p, m_n, m_r;
916 int to_return, ret;
917
918 to_return = 0; /* expect failure */
919 rmsg.buf = tempbuf;
920 rmsg.size = sizeof(tempbuf);
921
922 if(!hwcrhk_context)
923 {
924 HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED);
925 goto err;
926 }
927 /* Prepare the params */
928 bn_expand2(r, m->top); /* Check for error !! */
929 BN2MPI(m_a, a);
930 BN2MPI(m_p, p);
931 BN2MPI(m_n, m);
932 MPI2BN(r, m_r);
933
934 /* Perform the operation */
935 ret = p_hwcrhk_ModExp(hwcrhk_context, m_a, m_p, m_n, &m_r, &rmsg);
936
937 /* Convert the response */
938 r->top = m_r.size / sizeof(BN_ULONG);
939 bn_fix_top(r);
940
941 if (ret < 0)
942 {
943 /* FIXME: When this error is returned, HWCryptoHook is
944 telling us that falling back to software computation
945 might be a good thing. */
946 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
947 {
948 HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FALLBACK);
949 }
950 else
951 {
952 HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_REQUEST_FAILED);
953 }
954 ERR_add_error_data(1,rmsg.buf);
955 goto err;
956 }
957
958 to_return = 1;
959err:
960 return to_return;
961 }
962
963#ifndef OPENSSL_NO_RSA
964static int hwcrhk_rsa_mod_exp(BIGNUM *r, const BIGNUM *I, RSA *rsa)
965 {
966 char tempbuf[1024];
967 HWCryptoHook_ErrMsgBuf rmsg;
968 HWCryptoHook_RSAKeyHandle *hptr;
969 int to_return = 0, ret;
970
971 rmsg.buf = tempbuf;
972 rmsg.size = sizeof(tempbuf);
973
974 if(!hwcrhk_context)
975 {
976 HWCRHKerr(HWCRHK_F_HWCRHK_MOD_EXP,HWCRHK_R_NOT_INITIALISED);
977 goto err;
978 }
979
980 /* This provides support for nForce keys. Since that's opaque data
981 all we do is provide a handle to the proper key and let HWCryptoHook
982 take care of the rest. */
983 if ((hptr = (HWCryptoHook_RSAKeyHandle *) RSA_get_ex_data(rsa, hndidx_rsa))
984 != NULL)
985 {
986 HWCryptoHook_MPI m_a, m_r;
987
988 if(!rsa->n)
989 {
990 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
991 HWCRHK_R_MISSING_KEY_COMPONENTS);
992 goto err;
993 }
994
995 /* Prepare the params */
996 bn_expand2(r, rsa->n->top); /* Check for error !! */
997 BN2MPI(m_a, I);
998 MPI2BN(r, m_r);
999
1000 /* Perform the operation */
1001 ret = p_hwcrhk_RSA(m_a, *hptr, &m_r, &rmsg);
1002
1003 /* Convert the response */
1004 r->top = m_r.size / sizeof(BN_ULONG);
1005 bn_fix_top(r);
1006
1007 if (ret < 0)
1008 {
1009 /* FIXME: When this error is returned, HWCryptoHook is
1010 telling us that falling back to software computation
1011 might be a good thing. */
1012 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
1013 {
1014 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
1015 HWCRHK_R_REQUEST_FALLBACK);
1016 }
1017 else
1018 {
1019 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
1020 HWCRHK_R_REQUEST_FAILED);
1021 }
1022 ERR_add_error_data(1,rmsg.buf);
1023 goto err;
1024 }
1025 }
1026 else
1027 {
1028 HWCryptoHook_MPI m_a, m_p, m_q, m_dmp1, m_dmq1, m_iqmp, m_r;
1029
1030 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
1031 {
1032 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
1033 HWCRHK_R_MISSING_KEY_COMPONENTS);
1034 goto err;
1035 }
1036
1037 /* Prepare the params */
1038 bn_expand2(r, rsa->n->top); /* Check for error !! */
1039 BN2MPI(m_a, I);
1040 BN2MPI(m_p, rsa->p);
1041 BN2MPI(m_q, rsa->q);
1042 BN2MPI(m_dmp1, rsa->dmp1);
1043 BN2MPI(m_dmq1, rsa->dmq1);
1044 BN2MPI(m_iqmp, rsa->iqmp);
1045 MPI2BN(r, m_r);
1046
1047 /* Perform the operation */
1048 ret = p_hwcrhk_ModExpCRT(hwcrhk_context, m_a, m_p, m_q,
1049 m_dmp1, m_dmq1, m_iqmp, &m_r, &rmsg);
1050
1051 /* Convert the response */
1052 r->top = m_r.size / sizeof(BN_ULONG);
1053 bn_fix_top(r);
1054
1055 if (ret < 0)
1056 {
1057 /* FIXME: When this error is returned, HWCryptoHook is
1058 telling us that falling back to software computation
1059 might be a good thing. */
1060 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
1061 {
1062 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
1063 HWCRHK_R_REQUEST_FALLBACK);
1064 }
1065 else
1066 {
1067 HWCRHKerr(HWCRHK_F_HWCRHK_RSA_MOD_EXP,
1068 HWCRHK_R_REQUEST_FAILED);
1069 }
1070 ERR_add_error_data(1,rmsg.buf);
1071 goto err;
1072 }
1073 }
1074 /* If we're here, we must be here with some semblance of success :-) */
1075 to_return = 1;
1076err:
1077 return to_return;
1078 }
1079#endif
1080
1081/* This function is aliased to mod_exp (with the mont stuff dropped). */
1082static int hwcrhk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1083 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1084 {
1085 return hwcrhk_mod_exp(r, a, p, m, ctx);
1086 }
1087
1088#ifndef OPENSSL_NO_DH
1089/* This function is aliased to mod_exp (with the dh and mont dropped). */
1090static int hwcrhk_mod_exp_dh(const DH *dh, BIGNUM *r,
1091 const BIGNUM *a, const BIGNUM *p,
1092 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
1093 {
1094 return hwcrhk_mod_exp(r, a, p, m, ctx);
1095 }
1096#endif
1097
1098/* Random bytes are good */
1099static int hwcrhk_rand_bytes(unsigned char *buf, int num)
1100 {
1101 char tempbuf[1024];
1102 HWCryptoHook_ErrMsgBuf rmsg;
1103 int to_return = 0; /* assume failure */
1104 int ret;
1105
1106 rmsg.buf = tempbuf;
1107 rmsg.size = sizeof(tempbuf);
1108
1109 if(!hwcrhk_context)
1110 {
1111 HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES,HWCRHK_R_NOT_INITIALISED);
1112 goto err;
1113 }
1114
1115 ret = p_hwcrhk_RandomBytes(hwcrhk_context, buf, num, &rmsg);
1116 if (ret < 0)
1117 {
1118 /* FIXME: When this error is returned, HWCryptoHook is
1119 telling us that falling back to software computation
1120 might be a good thing. */
1121 if(ret == HWCRYPTOHOOK_ERROR_FALLBACK)
1122 {
1123 HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES,
1124 HWCRHK_R_REQUEST_FALLBACK);
1125 }
1126 else
1127 {
1128 HWCRHKerr(HWCRHK_F_HWCRHK_RAND_BYTES,
1129 HWCRHK_R_REQUEST_FAILED);
1130 }
1131 ERR_add_error_data(1,rmsg.buf);
1132 goto err;
1133 }
1134 to_return = 1;
1135 err:
1136 return to_return;
1137 }
1138
1139static int hwcrhk_rand_status(void)
1140 {
1141 return 1;
1142 }
1143
1144/* This cleans up an RSA KM key, called when ex_data is freed */
1145
1146static void hwcrhk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
1147 int ind,long argl, void *argp)
1148{
1149 char tempbuf[1024];
1150 HWCryptoHook_ErrMsgBuf rmsg;
1151#ifndef OPENSSL_NO_RSA
1152 HWCryptoHook_RSAKeyHandle *hptr;
1153#endif
1154#if !defined(OPENSSL_NO_RSA)
1155 int ret;
1156#endif
1157
1158 rmsg.buf = tempbuf;
1159 rmsg.size = sizeof(tempbuf);
1160
1161#ifndef OPENSSL_NO_RSA
1162 hptr = (HWCryptoHook_RSAKeyHandle *) item;
1163 if(hptr)
1164 {
1165 ret = p_hwcrhk_RSAUnloadKey(*hptr, NULL);
1166 OPENSSL_free(hptr);
1167 }
1168#endif
1169}
1170
1171/* Mutex calls: since the HWCryptoHook model closely follows the POSIX model
1172 * these just wrap the POSIX functions and add some logging.
1173 */
1174
1175static int hwcrhk_mutex_init(HWCryptoHook_Mutex* mt,
1176 HWCryptoHook_CallerContext *cactx)
1177 {
1178 mt->lockid = CRYPTO_get_new_dynlockid();
1179 if (mt->lockid == 0)
1180 return 1; /* failure */
1181 return 0; /* success */
1182 }
1183
1184static int hwcrhk_mutex_lock(HWCryptoHook_Mutex *mt)
1185 {
1186 CRYPTO_w_lock(mt->lockid);
1187 return 0;
1188 }
1189
1190static void hwcrhk_mutex_unlock(HWCryptoHook_Mutex * mt)
1191 {
1192 CRYPTO_w_unlock(mt->lockid);
1193 }
1194
1195static void hwcrhk_mutex_destroy(HWCryptoHook_Mutex *mt)
1196 {
1197 CRYPTO_destroy_dynlockid(mt->lockid);
1198 }
1199
1200/* Mutex upcalls to use if the application does not support dynamic locks */
1201
1202static int hwcrhk_static_mutex_init(HWCryptoHook_Mutex *m,
1203 HWCryptoHook_CallerContext *c)
1204 {
1205 return 0;
1206 }
1207static int hwcrhk_static_mutex_lock(HWCryptoHook_Mutex *m)
1208 {
1209 CRYPTO_w_lock(CRYPTO_LOCK_HWCRHK);
1210 return 0;
1211 }
1212static void hwcrhk_static_mutex_unlock(HWCryptoHook_Mutex *m)
1213 {
1214 CRYPTO_w_unlock(CRYPTO_LOCK_HWCRHK);
1215 }
1216static void hwcrhk_static_mutex_destroy(HWCryptoHook_Mutex *m)
1217 {
1218 }
1219
1220static int hwcrhk_get_pass(const char *prompt_info,
1221 int *len_io, char *buf,
1222 HWCryptoHook_PassphraseContext *ppctx,
1223 HWCryptoHook_CallerContext *cactx)
1224 {
1225 pem_password_cb *callback = NULL;
1226 void *callback_data = NULL;
1227 UI_METHOD *ui_method = NULL;
1228
1229 if (cactx)
1230 {
1231 if (cactx->ui_method)
1232 ui_method = cactx->ui_method;
1233 if (cactx->password_callback)
1234 callback = cactx->password_callback;
1235 if (cactx->callback_data)
1236 callback_data = cactx->callback_data;
1237 }
1238 if (ppctx)
1239 {
1240 if (ppctx->ui_method)
1241 {
1242 ui_method = ppctx->ui_method;
1243 callback = NULL;
1244 }
1245 if (ppctx->callback_data)
1246 callback_data = ppctx->callback_data;
1247 }
1248 if (callback == NULL && ui_method == NULL)
1249 {
1250 HWCRHKerr(HWCRHK_F_HWCRHK_GET_PASS,HWCRHK_R_NO_CALLBACK);
1251 return -1;
1252 }
1253
1254 if (ui_method)
1255 {
1256 UI *ui = UI_new_method(ui_method);
1257 if (ui)
1258 {
1259 int ok;
1260 char *prompt = UI_construct_prompt(ui,
1261 "pass phrase", prompt_info);
1262
1263 ok = UI_add_input_string(ui,prompt,
1264 UI_INPUT_FLAG_DEFAULT_PWD,
1265 buf,0,(*len_io) - 1);
1266 UI_add_user_data(ui, callback_data);
1267 UI_ctrl(ui, UI_CTRL_PRINT_ERRORS, 1, 0, 0);
1268
1269 if (ok >= 0)
1270 do
1271 {
1272 ok=UI_process(ui);
1273 }
1274 while (ok < 0 && UI_ctrl(ui, UI_CTRL_IS_REDOABLE, 0, 0, 0));
1275
1276 if (ok >= 0)
1277 *len_io = strlen(buf);
1278
1279 UI_free(ui);
1280 OPENSSL_free(prompt);
1281 }
1282 }
1283 else
1284 {
1285 *len_io = callback(buf, *len_io, 0, callback_data);
1286 }
1287 if(!*len_io)
1288 return -1;
1289 return 0;
1290 }
1291
1292static int hwcrhk_insert_card(const char *prompt_info,
1293 const char *wrong_info,
1294 HWCryptoHook_PassphraseContext *ppctx,
1295 HWCryptoHook_CallerContext *cactx)
1296 {
1297 int ok = -1;
1298 UI *ui;
1299 void *callback_data = NULL;
1300 UI_METHOD *ui_method = NULL;
1301
1302 if (cactx)
1303 {
1304 if (cactx->ui_method)
1305 ui_method = cactx->ui_method;
1306 if (cactx->callback_data)
1307 callback_data = cactx->callback_data;
1308 }
1309 if (ppctx)
1310 {
1311 if (ppctx->ui_method)
1312 ui_method = ppctx->ui_method;
1313 if (ppctx->callback_data)
1314 callback_data = ppctx->callback_data;
1315 }
1316 if (ui_method == NULL)
1317 {
1318 HWCRHKerr(HWCRHK_F_HWCRHK_INSERT_CARD,
1319 HWCRHK_R_NO_CALLBACK);
1320 return -1;
1321 }
1322
1323 ui = UI_new_method(ui_method);
1324
1325 if (ui)
1326 {
1327 char answer;
1328 char buf[BUFSIZ];
1329
1330 if (wrong_info)
1331 BIO_snprintf(buf, sizeof(buf)-1,
1332 "Current card: \"%s\"\n", wrong_info);
1333 ok = UI_dup_info_string(ui, buf);
1334 if (ok >= 0 && prompt_info)
1335 {
1336 BIO_snprintf(buf, sizeof(buf)-1,
1337 "Insert card \"%s\"", prompt_info);
1338 ok = UI_dup_input_boolean(ui, buf,
1339 "\n then hit <enter> or C<enter> to cancel\n",
1340 "\r\n", "Cc", UI_INPUT_FLAG_ECHO, &answer);
1341 }
1342 UI_add_user_data(ui, callback_data);
1343
1344 if (ok >= 0)
1345 ok = UI_process(ui);
1346 UI_free(ui);
1347
1348 if (ok == -2 || (ok >= 0 && answer == 'C'))
1349 ok = 1;
1350 else if (ok < 0)
1351 ok = -1;
1352 else
1353 ok = 0;
1354 }
1355 return ok;
1356 }
1357
1358static void hwcrhk_log_message(void *logstr, const char *message)
1359 {
1360 BIO *lstream = NULL;
1361
1362 CRYPTO_w_lock(CRYPTO_LOCK_BIO);
1363 if (logstr)
1364 lstream=*(BIO **)logstr;
1365 if (lstream)
1366 {
1367 BIO_printf(lstream, "%s\n", message);
1368 }
1369 CRYPTO_w_unlock(CRYPTO_LOCK_BIO);
1370 }
1371
1372/* This stuff is needed if this ENGINE is being compiled into a self-contained
1373 * shared-library. */
1374#ifdef ENGINE_DYNAMIC_SUPPORT
1375static int bind_fn(ENGINE *e, const char *id)
1376 {
1377 if(id && (strcmp(id, engine_hwcrhk_id) != 0))
1378 return 0;
1379 if(!bind_helper(e))
1380 return 0;
1381 return 1;
1382 }
1383IMPLEMENT_DYNAMIC_CHECK_FN()
1384IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
1385#endif /* ENGINE_DYNAMIC_SUPPORT */
1386
1387#endif /* !OPENSSL_NO_HW_NCIPHER */
1388#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.c b/src/lib/libcrypto/engine/hw_ncipher_err.c
new file mode 100644
index 0000000000..5bc94581b7
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher_err.c
@@ -0,0 +1,157 @@
1/* hw_ncipher_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ncipher_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA HWCRHK_str_functs[]=
68 {
69{ERR_PACK(0,HWCRHK_F_HWCRHK_CTRL,0), "HWCRHK_CTRL"},
70{ERR_PACK(0,HWCRHK_F_HWCRHK_FINISH,0), "HWCRHK_FINISH"},
71{ERR_PACK(0,HWCRHK_F_HWCRHK_GET_PASS,0), "HWCRHK_GET_PASS"},
72{ERR_PACK(0,HWCRHK_F_HWCRHK_INIT,0), "HWCRHK_INIT"},
73{ERR_PACK(0,HWCRHK_F_HWCRHK_INSERT_CARD,0), "HWCRHK_INSERT_CARD"},
74{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PRIVKEY,0), "HWCRHK_LOAD_PRIVKEY"},
75{ERR_PACK(0,HWCRHK_F_HWCRHK_LOAD_PUBKEY,0), "HWCRHK_LOAD_PUBKEY"},
76{ERR_PACK(0,HWCRHK_F_HWCRHK_MOD_EXP,0), "HWCRHK_MOD_EXP"},
77{ERR_PACK(0,HWCRHK_F_HWCRHK_RAND_BYTES,0), "HWCRHK_RAND_BYTES"},
78{ERR_PACK(0,HWCRHK_F_HWCRHK_RSA_MOD_EXP,0), "HWCRHK_RSA_MOD_EXP"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA HWCRHK_str_reasons[]=
83 {
84{HWCRHK_R_ALREADY_LOADED ,"already loaded"},
85{HWCRHK_R_BIO_WAS_FREED ,"bio was freed"},
86{HWCRHK_R_CHIL_ERROR ,"chil error"},
87{HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
88{HWCRHK_R_DSO_FAILURE ,"dso failure"},
89{HWCRHK_R_DYNAMIC_LOCKING_MISSING ,"dynamic locking missing"},
90{HWCRHK_R_MISSING_KEY_COMPONENTS ,"missing key components"},
91{HWCRHK_R_NOT_INITIALISED ,"not initialised"},
92{HWCRHK_R_NOT_LOADED ,"not loaded"},
93{HWCRHK_R_NO_CALLBACK ,"no callback"},
94{HWCRHK_R_NO_KEY ,"no key"},
95{HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED,"private key algorithms disabled"},
96{HWCRHK_R_REQUEST_FAILED ,"request failed"},
97{HWCRHK_R_REQUEST_FALLBACK ,"request fallback"},
98{HWCRHK_R_UNIT_FAILURE ,"unit failure"},
99{0,NULL}
100 };
101
102#endif
103
104#ifdef HWCRHK_LIB_NAME
105static ERR_STRING_DATA HWCRHK_lib_name[]=
106 {
107{0 ,HWCRHK_LIB_NAME},
108{0,NULL}
109 };
110#endif
111
112
113static int HWCRHK_lib_error_code=0;
114static int HWCRHK_error_init=1;
115
116static void ERR_load_HWCRHK_strings(void)
117 {
118 if (HWCRHK_lib_error_code == 0)
119 HWCRHK_lib_error_code=ERR_get_next_error_library();
120
121 if (HWCRHK_error_init)
122 {
123 HWCRHK_error_init=0;
124#ifndef OPENSSL_NO_ERR
125 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
126 ERR_load_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
127#endif
128
129#ifdef HWCRHK_LIB_NAME
130 HWCRHK_lib_name->error = ERR_PACK(HWCRHK_lib_error_code,0,0);
131 ERR_load_strings(0,HWCRHK_lib_name);
132#endif
133 }
134 }
135
136static void ERR_unload_HWCRHK_strings(void)
137 {
138 if (HWCRHK_error_init == 0)
139 {
140#ifndef OPENSSL_NO_ERR
141 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_functs);
142 ERR_unload_strings(HWCRHK_lib_error_code,HWCRHK_str_reasons);
143#endif
144
145#ifdef HWCRHK_LIB_NAME
146 ERR_unload_strings(0,HWCRHK_lib_name);
147#endif
148 HWCRHK_error_init=1;
149 }
150 }
151
152static void ERR_HWCRHK_error(int function, int reason, char *file, int line)
153 {
154 if (HWCRHK_lib_error_code == 0)
155 HWCRHK_lib_error_code=ERR_get_next_error_library();
156 ERR_PUT_error(HWCRHK_lib_error_code,function,reason,file,line);
157 }
diff --git a/src/lib/libcrypto/engine/hw_ncipher_err.h b/src/lib/libcrypto/engine/hw_ncipher_err.h
new file mode 100644
index 0000000000..d232d02319
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ncipher_err.h
@@ -0,0 +1,101 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_HWCRHK_ERR_H
56#define HEADER_HWCRHK_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_HWCRHK_strings(void);
63static void ERR_unload_HWCRHK_strings(void);
64static void ERR_HWCRHK_error(int function, int reason, char *file, int line);
65#define HWCRHKerr(f,r) ERR_HWCRHK_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the HWCRHK functions. */
68
69/* Function codes. */
70#define HWCRHK_F_HWCRHK_CTRL 100
71#define HWCRHK_F_HWCRHK_FINISH 101
72#define HWCRHK_F_HWCRHK_GET_PASS 102
73#define HWCRHK_F_HWCRHK_INIT 103
74#define HWCRHK_F_HWCRHK_INSERT_CARD 104
75#define HWCRHK_F_HWCRHK_LOAD_PRIVKEY 105
76#define HWCRHK_F_HWCRHK_LOAD_PUBKEY 106
77#define HWCRHK_F_HWCRHK_MOD_EXP 107
78#define HWCRHK_F_HWCRHK_RAND_BYTES 108
79#define HWCRHK_F_HWCRHK_RSA_MOD_EXP 109
80
81/* Reason codes. */
82#define HWCRHK_R_ALREADY_LOADED 100
83#define HWCRHK_R_BIO_WAS_FREED 101
84#define HWCRHK_R_CHIL_ERROR 102
85#define HWCRHK_R_CTRL_COMMAND_NOT_IMPLEMENTED 103
86#define HWCRHK_R_DSO_FAILURE 104
87#define HWCRHK_R_DYNAMIC_LOCKING_MISSING 114
88#define HWCRHK_R_MISSING_KEY_COMPONENTS 105
89#define HWCRHK_R_NOT_INITIALISED 106
90#define HWCRHK_R_NOT_LOADED 107
91#define HWCRHK_R_NO_CALLBACK 108
92#define HWCRHK_R_NO_KEY 109
93#define HWCRHK_R_PRIVATE_KEY_ALGORITHMS_DISABLED 110
94#define HWCRHK_R_REQUEST_FAILED 111
95#define HWCRHK_R_REQUEST_FALLBACK 112
96#define HWCRHK_R_UNIT_FAILURE 113
97
98#ifdef __cplusplus
99}
100#endif
101#endif
diff --git a/src/lib/libcrypto/engine/hw_nuron.c b/src/lib/libcrypto/engine/hw_nuron.c
new file mode 100644
index 0000000000..fb9188bfe5
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron.c
@@ -0,0 +1,418 @@
1/* crypto/engine/hw_nuron.c */
2/* Written by Ben Laurie for the OpenSSL Project, leaning heavily on Geoff
3 * Thorpe's Atalla implementation.
4 */
5/* ====================================================================
6 * Copyright (c) 2000-2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include <openssl/crypto.h>
61#include "cryptlib.h"
62#include <openssl/dso.h>
63#include <openssl/engine.h>
64
65
66#ifndef OPENSSL_NO_HW
67#ifndef OPENSSL_NO_HW_NURON
68
69#define NURON_LIB_NAME "nuron engine"
70#include "hw_nuron_err.c"
71
72static const char *NURON_LIBNAME = NULL;
73static const char *get_NURON_LIBNAME(void)
74 {
75 if(NURON_LIBNAME)
76 return NURON_LIBNAME;
77 return "nuronssl";
78 }
79static void free_NURON_LIBNAME(void)
80 {
81 if(NURON_LIBNAME)
82 OPENSSL_free((void*)NURON_LIBNAME);
83 NURON_LIBNAME = NULL;
84 }
85static long set_NURON_LIBNAME(const char *name)
86 {
87 free_NURON_LIBNAME();
88 return (((NURON_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
89 }
90static const char *NURON_F1 = "nuron_mod_exp";
91
92/* The definitions for control commands specific to this engine */
93#define NURON_CMD_SO_PATH ENGINE_CMD_BASE
94static const ENGINE_CMD_DEFN nuron_cmd_defns[] = {
95 {NURON_CMD_SO_PATH,
96 "SO_PATH",
97 "Specifies the path to the 'nuronssl' shared library",
98 ENGINE_CMD_FLAG_STRING},
99 {0, NULL, NULL, 0}
100 };
101
102typedef int tfnModExp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,const BIGNUM *m);
103static tfnModExp *pfnModExp = NULL;
104
105static DSO *pvDSOHandle = NULL;
106
107static int nuron_destroy(ENGINE *e)
108 {
109 free_NURON_LIBNAME();
110 ERR_unload_NURON_strings();
111 return 1;
112 }
113
114static int nuron_init(ENGINE *e)
115 {
116 if(pvDSOHandle != NULL)
117 {
118 NURONerr(NURON_F_NURON_INIT,NURON_R_ALREADY_LOADED);
119 return 0;
120 }
121
122 pvDSOHandle = DSO_load(NULL, get_NURON_LIBNAME(), NULL,
123 DSO_FLAG_NAME_TRANSLATION_EXT_ONLY);
124 if(!pvDSOHandle)
125 {
126 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_NOT_FOUND);
127 return 0;
128 }
129
130 pfnModExp = (tfnModExp *)DSO_bind_func(pvDSOHandle, NURON_F1);
131 if(!pfnModExp)
132 {
133 NURONerr(NURON_F_NURON_INIT,NURON_R_DSO_FUNCTION_NOT_FOUND);
134 return 0;
135 }
136
137 return 1;
138 }
139
140static int nuron_finish(ENGINE *e)
141 {
142 free_NURON_LIBNAME();
143 if(pvDSOHandle == NULL)
144 {
145 NURONerr(NURON_F_NURON_FINISH,NURON_R_NOT_LOADED);
146 return 0;
147 }
148 if(!DSO_free(pvDSOHandle))
149 {
150 NURONerr(NURON_F_NURON_FINISH,NURON_R_DSO_FAILURE);
151 return 0;
152 }
153 pvDSOHandle=NULL;
154 pfnModExp=NULL;
155 return 1;
156 }
157
158static int nuron_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
159 {
160 int initialised = ((pvDSOHandle == NULL) ? 0 : 1);
161 switch(cmd)
162 {
163 case NURON_CMD_SO_PATH:
164 if(p == NULL)
165 {
166 NURONerr(NURON_F_NURON_CTRL,ERR_R_PASSED_NULL_PARAMETER);
167 return 0;
168 }
169 if(initialised)
170 {
171 NURONerr(NURON_F_NURON_CTRL,NURON_R_ALREADY_LOADED);
172 return 0;
173 }
174 return set_NURON_LIBNAME((const char *)p);
175 default:
176 break;
177 }
178 NURONerr(NURON_F_NURON_CTRL,NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED);
179 return 0;
180}
181
182static int nuron_mod_exp(BIGNUM *r,const BIGNUM *a,const BIGNUM *p,
183 const BIGNUM *m,BN_CTX *ctx)
184 {
185 if(!pvDSOHandle)
186 {
187 NURONerr(NURON_F_NURON_MOD_EXP,NURON_R_NOT_LOADED);
188 return 0;
189 }
190 return pfnModExp(r,a,p,m);
191 }
192
193#ifndef OPENSSL_NO_RSA
194static int nuron_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
195 {
196 return nuron_mod_exp(r0,I,rsa->d,rsa->n,NULL);
197 }
198#endif
199
200#ifndef OPENSSL_NO_DSA
201/* This code was liberated and adapted from the commented-out code in
202 * dsa_ossl.c. Because of the unoptimised form of the Atalla acceleration
203 * (it doesn't have a CRT form for RSA), this function means that an
204 * Atalla system running with a DSA server certificate can handshake
205 * around 5 or 6 times faster/more than an equivalent system running with
206 * RSA. Just check out the "signs" statistics from the RSA and DSA parts
207 * of "openssl speed -engine atalla dsa1024 rsa1024". */
208static int nuron_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
209 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
210 BN_CTX *ctx, BN_MONT_CTX *in_mont)
211 {
212 BIGNUM t;
213 int to_return = 0;
214
215 BN_init(&t);
216 /* let rr = a1 ^ p1 mod m */
217 if (!nuron_mod_exp(rr,a1,p1,m,ctx))
218 goto end;
219 /* let t = a2 ^ p2 mod m */
220 if (!nuron_mod_exp(&t,a2,p2,m,ctx))
221 goto end;
222 /* let rr = rr * t mod m */
223 if (!BN_mod_mul(rr,rr,&t,m,ctx))
224 goto end;
225 to_return = 1;
226end:
227 BN_free(&t);
228 return to_return;
229 }
230
231
232static int nuron_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
233 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
234 BN_MONT_CTX *m_ctx)
235 {
236 return nuron_mod_exp(r, a, p, m, ctx);
237 }
238#endif
239
240/* This function is aliased to mod_exp (with the mont stuff dropped). */
241static int nuron_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
242 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
243 {
244 return nuron_mod_exp(r, a, p, m, ctx);
245 }
246
247#ifndef OPENSSL_NO_DH
248/* This function is aliased to mod_exp (with the dh and mont dropped). */
249static int nuron_mod_exp_dh(const DH *dh, BIGNUM *r,
250 const BIGNUM *a, const BIGNUM *p,
251 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
252 {
253 return nuron_mod_exp(r, a, p, m, ctx);
254 }
255#endif
256
257#ifndef OPENSSL_NO_RSA
258static RSA_METHOD nuron_rsa =
259 {
260 "Nuron RSA method",
261 NULL,
262 NULL,
263 NULL,
264 NULL,
265 nuron_rsa_mod_exp,
266 nuron_mod_exp_mont,
267 NULL,
268 NULL,
269 0,
270 NULL,
271 NULL,
272 NULL
273 };
274#endif
275
276#ifndef OPENSSL_NO_DSA
277static DSA_METHOD nuron_dsa =
278 {
279 "Nuron DSA method",
280 NULL, /* dsa_do_sign */
281 NULL, /* dsa_sign_setup */
282 NULL, /* dsa_do_verify */
283 nuron_dsa_mod_exp, /* dsa_mod_exp */
284 nuron_mod_exp_dsa, /* bn_mod_exp */
285 NULL, /* init */
286 NULL, /* finish */
287 0, /* flags */
288 NULL /* app_data */
289 };
290#endif
291
292#ifndef OPENSSL_NO_DH
293static DH_METHOD nuron_dh =
294 {
295 "Nuron DH method",
296 NULL,
297 NULL,
298 nuron_mod_exp_dh,
299 NULL,
300 NULL,
301 0,
302 NULL
303 };
304#endif
305
306/* Constants used when creating the ENGINE */
307static const char *engine_nuron_id = "nuron";
308static const char *engine_nuron_name = "Nuron hardware engine support";
309
310/* This internal function is used by ENGINE_nuron() and possibly by the
311 * "dynamic" ENGINE support too */
312static int bind_helper(ENGINE *e)
313 {
314#ifndef OPENSSL_NO_RSA
315 const RSA_METHOD *meth1;
316#endif
317#ifndef OPENSSL_NO_DSA
318 const DSA_METHOD *meth2;
319#endif
320#ifndef OPENSSL_NO_DH
321 const DH_METHOD *meth3;
322#endif
323 if(!ENGINE_set_id(e, engine_nuron_id) ||
324 !ENGINE_set_name(e, engine_nuron_name) ||
325#ifndef OPENSSL_NO_RSA
326 !ENGINE_set_RSA(e, &nuron_rsa) ||
327#endif
328#ifndef OPENSSL_NO_DSA
329 !ENGINE_set_DSA(e, &nuron_dsa) ||
330#endif
331#ifndef OPENSSL_NO_DH
332 !ENGINE_set_DH(e, &nuron_dh) ||
333#endif
334 !ENGINE_set_destroy_function(e, nuron_destroy) ||
335 !ENGINE_set_init_function(e, nuron_init) ||
336 !ENGINE_set_finish_function(e, nuron_finish) ||
337 !ENGINE_set_ctrl_function(e, nuron_ctrl) ||
338 !ENGINE_set_cmd_defns(e, nuron_cmd_defns))
339 return 0;
340
341#ifndef OPENSSL_NO_RSA
342 /* We know that the "PKCS1_SSLeay()" functions hook properly
343 * to the nuron-specific mod_exp and mod_exp_crt so we use
344 * those functions. NB: We don't use ENGINE_openssl() or
345 * anything "more generic" because something like the RSAref
346 * code may not hook properly, and if you own one of these
347 * cards then you have the right to do RSA operations on it
348 * anyway! */
349 meth1=RSA_PKCS1_SSLeay();
350 nuron_rsa.rsa_pub_enc=meth1->rsa_pub_enc;
351 nuron_rsa.rsa_pub_dec=meth1->rsa_pub_dec;
352 nuron_rsa.rsa_priv_enc=meth1->rsa_priv_enc;
353 nuron_rsa.rsa_priv_dec=meth1->rsa_priv_dec;
354#endif
355
356#ifndef OPENSSL_NO_DSA
357 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
358 * bits. */
359 meth2=DSA_OpenSSL();
360 nuron_dsa.dsa_do_sign=meth2->dsa_do_sign;
361 nuron_dsa.dsa_sign_setup=meth2->dsa_sign_setup;
362 nuron_dsa.dsa_do_verify=meth2->dsa_do_verify;
363#endif
364
365#ifndef OPENSSL_NO_DH
366 /* Much the same for Diffie-Hellman */
367 meth3=DH_OpenSSL();
368 nuron_dh.generate_key=meth3->generate_key;
369 nuron_dh.compute_key=meth3->compute_key;
370#endif
371
372 /* Ensure the nuron error handling is set up */
373 ERR_load_NURON_strings();
374 return 1;
375 }
376
377#ifndef ENGINE_DYNAMIC_SUPPORT
378static ENGINE *engine_nuron(void)
379 {
380 ENGINE *ret = ENGINE_new();
381 if(!ret)
382 return NULL;
383 if(!bind_helper(ret))
384 {
385 ENGINE_free(ret);
386 return NULL;
387 }
388 return ret;
389 }
390
391void ENGINE_load_nuron(void)
392 {
393 /* Copied from eng_[openssl|dyn].c */
394 ENGINE *toadd = engine_nuron();
395 if(!toadd) return;
396 ENGINE_add(toadd);
397 ENGINE_free(toadd);
398 ERR_clear_error();
399 }
400#endif
401
402/* This stuff is needed if this ENGINE is being compiled into a self-contained
403 * shared-library. */
404#ifdef ENGINE_DYNAMIC_SUPPORT
405static int bind_fn(ENGINE *e, const char *id)
406 {
407 if(id && (strcmp(id, engine_nuron_id) != 0))
408 return 0;
409 if(!bind_helper(e))
410 return 0;
411 return 1;
412 }
413IMPLEMENT_DYNAMIC_CHECK_FN()
414IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
415#endif /* ENGINE_DYNAMIC_SUPPORT */
416
417#endif /* !OPENSSL_NO_HW_NURON */
418#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.c b/src/lib/libcrypto/engine/hw_nuron_err.c
new file mode 100644
index 0000000000..df9d7bde76
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron_err.c
@@ -0,0 +1,142 @@
1/* hw_nuron_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_nuron_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA NURON_str_functs[]=
68 {
69{ERR_PACK(0,NURON_F_NURON_CTRL,0), "NURON_CTRL"},
70{ERR_PACK(0,NURON_F_NURON_FINISH,0), "NURON_FINISH"},
71{ERR_PACK(0,NURON_F_NURON_INIT,0), "NURON_INIT"},
72{ERR_PACK(0,NURON_F_NURON_MOD_EXP,0), "NURON_MOD_EXP"},
73{0,NULL}
74 };
75
76static ERR_STRING_DATA NURON_str_reasons[]=
77 {
78{NURON_R_ALREADY_LOADED ,"already loaded"},
79{NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
80{NURON_R_DSO_FAILURE ,"dso failure"},
81{NURON_R_DSO_FUNCTION_NOT_FOUND ,"dso function not found"},
82{NURON_R_DSO_NOT_FOUND ,"dso not found"},
83{NURON_R_NOT_LOADED ,"not loaded"},
84{0,NULL}
85 };
86
87#endif
88
89#ifdef NURON_LIB_NAME
90static ERR_STRING_DATA NURON_lib_name[]=
91 {
92{0 ,NURON_LIB_NAME},
93{0,NULL}
94 };
95#endif
96
97
98static int NURON_lib_error_code=0;
99static int NURON_error_init=1;
100
101static void ERR_load_NURON_strings(void)
102 {
103 if (NURON_lib_error_code == 0)
104 NURON_lib_error_code=ERR_get_next_error_library();
105
106 if (NURON_error_init)
107 {
108 NURON_error_init=0;
109#ifndef OPENSSL_NO_ERR
110 ERR_load_strings(NURON_lib_error_code,NURON_str_functs);
111 ERR_load_strings(NURON_lib_error_code,NURON_str_reasons);
112#endif
113
114#ifdef NURON_LIB_NAME
115 NURON_lib_name->error = ERR_PACK(NURON_lib_error_code,0,0);
116 ERR_load_strings(0,NURON_lib_name);
117#endif
118 }
119 }
120
121static void ERR_unload_NURON_strings(void)
122 {
123 if (NURON_error_init == 0)
124 {
125#ifndef OPENSSL_NO_ERR
126 ERR_unload_strings(NURON_lib_error_code,NURON_str_functs);
127 ERR_unload_strings(NURON_lib_error_code,NURON_str_reasons);
128#endif
129
130#ifdef NURON_LIB_NAME
131 ERR_unload_strings(0,NURON_lib_name);
132#endif
133 NURON_error_init=1;
134 }
135 }
136
137static void ERR_NURON_error(int function, int reason, char *file, int line)
138 {
139 if (NURON_lib_error_code == 0)
140 NURON_lib_error_code=ERR_get_next_error_library();
141 ERR_PUT_error(NURON_lib_error_code,function,reason,file,line);
142 }
diff --git a/src/lib/libcrypto/engine/hw_nuron_err.h b/src/lib/libcrypto/engine/hw_nuron_err.h
new file mode 100644
index 0000000000..a56bfdf303
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_nuron_err.h
@@ -0,0 +1,86 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_NURON_ERR_H
56#define HEADER_NURON_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_NURON_strings(void);
63static void ERR_unload_NURON_strings(void);
64static void ERR_NURON_error(int function, int reason, char *file, int line);
65#define NURONerr(f,r) ERR_NURON_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the NURON functions. */
68
69/* Function codes. */
70#define NURON_F_NURON_CTRL 100
71#define NURON_F_NURON_FINISH 101
72#define NURON_F_NURON_INIT 102
73#define NURON_F_NURON_MOD_EXP 103
74
75/* Reason codes. */
76#define NURON_R_ALREADY_LOADED 100
77#define NURON_R_CTRL_COMMAND_NOT_IMPLEMENTED 101
78#define NURON_R_DSO_FAILURE 102
79#define NURON_R_DSO_FUNCTION_NOT_FOUND 103
80#define NURON_R_DSO_NOT_FOUND 104
81#define NURON_R_NOT_LOADED 105
82
83#ifdef __cplusplus
84}
85#endif
86#endif
diff --git a/src/lib/libcrypto/engine/hw_sureware.c b/src/lib/libcrypto/engine/hw_sureware.c
new file mode 100644
index 0000000000..fca467e690
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_sureware.c
@@ -0,0 +1,1039 @@
1/* Written by Corinne Dive-Reclus(cdive@baltimore.com)
2*
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* Written by Corinne Dive-Reclus(cdive@baltimore.com)
36*
37* Copyright@2001 Baltimore Technologies Ltd.
38* All right Reserved.
39* *
40* THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND *
41* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
42* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
43* ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE *
44* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
45* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
46* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
47* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
48* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
49* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
50* SUCH DAMAGE. *
51====================================================================*/
52
53#include <stdio.h>
54#include "cryptlib.h"
55#include <openssl/crypto.h>
56#include <openssl/pem.h>
57#include <openssl/dso.h>
58#include "eng_int.h"
59#include "engine.h"
60#include <openssl/engine.h>
61
62#ifndef OPENSSL_NO_HW
63#ifndef OPENSSL_NO_HW_SUREWARE
64
65#ifdef FLAT_INC
66#include "sureware.h"
67#else
68#include "vendor_defns/sureware.h"
69#endif
70
71#define SUREWARE_LIB_NAME "sureware engine"
72#include "hw_sureware_err.c"
73
74static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
75static int surewarehk_destroy(ENGINE *e);
76static int surewarehk_init(ENGINE *e);
77static int surewarehk_finish(ENGINE *e);
78static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
79 const BIGNUM *m, BN_CTX *ctx);
80
81/* RSA stuff */
82static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to,
83 RSA *rsa,int padding);
84static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to,
85 RSA *rsa,int padding);
86
87/* RAND stuff */
88static int surewarehk_rand_bytes(unsigned char *buf, int num);
89static void surewarehk_rand_seed(const void *buf, int num);
90static void surewarehk_rand_add(const void *buf, int num, double entropy);
91
92/* KM stuff */
93static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id,
94 UI_METHOD *ui_method, void *callback_data);
95static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id,
96 UI_METHOD *ui_method, void *callback_data);
97static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
98 int idx,long argl, void *argp);
99#if 0
100static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
101 int idx,long argl, void *argp);
102#endif
103
104#ifndef OPENSSL_NO_RSA
105/* This function is aliased to mod_exp (with the mont stuff dropped). */
106static int surewarehk_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
107 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
108{
109 return surewarehk_modexp(r, a, p, m, ctx);
110}
111
112/* Our internal RSA_METHOD that we provide pointers to */
113static RSA_METHOD surewarehk_rsa =
114 {
115 "SureWare RSA method",
116 NULL, /* pub_enc*/
117 NULL, /* pub_dec*/
118 surewarehk_rsa_sign, /* our rsa_sign is OpenSSL priv_enc*/
119 surewarehk_rsa_priv_dec, /* priv_dec*/
120 NULL, /*mod_exp*/
121 surewarehk_mod_exp_mont, /*mod_exp_mongomery*/
122 NULL, /* init*/
123 NULL, /* finish*/
124 0, /* RSA flag*/
125 NULL,
126 NULL, /* OpenSSL sign*/
127 NULL /* OpenSSL verify*/
128 };
129#endif
130
131#ifndef OPENSSL_NO_DH
132/* Our internal DH_METHOD that we provide pointers to */
133/* This function is aliased to mod_exp (with the dh and mont dropped). */
134static int surewarehk_modexp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
135 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
136{
137 return surewarehk_modexp(r, a, p, m, ctx);
138}
139
140static DH_METHOD surewarehk_dh =
141 {
142 "SureWare DH method",
143 NULL,/*gen_key*/
144 NULL,/*agree,*/
145 surewarehk_modexp_dh, /*dh mod exp*/
146 NULL, /* init*/
147 NULL, /* finish*/
148 0, /* flags*/
149 NULL
150 };
151#endif
152
153static RAND_METHOD surewarehk_rand =
154 {
155 /* "SureWare RAND method", */
156 surewarehk_rand_seed,
157 surewarehk_rand_bytes,
158 NULL,/*cleanup*/
159 surewarehk_rand_add,
160 surewarehk_rand_bytes,
161 NULL,/*rand_status*/
162 };
163
164#ifndef OPENSSL_NO_DSA
165/* DSA stuff */
166static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
167static int surewarehk_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
168 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
169 BN_CTX *ctx, BN_MONT_CTX *in_mont)
170{
171 BIGNUM t;
172 int to_return = 0;
173 BN_init(&t);
174 /* let rr = a1 ^ p1 mod m */
175 if (!surewarehk_modexp(rr,a1,p1,m,ctx)) goto end;
176 /* let t = a2 ^ p2 mod m */
177 if (!surewarehk_modexp(&t,a2,p2,m,ctx)) goto end;
178 /* let rr = rr * t mod m */
179 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
180 to_return = 1;
181end:
182 BN_free(&t);
183 return to_return;
184}
185
186static DSA_METHOD surewarehk_dsa =
187 {
188 "SureWare DSA method",
189 surewarehk_dsa_do_sign,
190 NULL,/*sign setup*/
191 NULL,/*verify,*/
192 surewarehk_dsa_mod_exp,/*mod exp*/
193 NULL,/*bn mod exp*/
194 NULL, /*init*/
195 NULL,/*finish*/
196 0,
197 NULL,
198 };
199#endif
200
201static const char *engine_sureware_id = "sureware";
202static const char *engine_sureware_name = "SureWare hardware engine support";
203
204/* Now, to our own code */
205
206/* As this is only ever called once, there's no need for locking
207 * (indeed - the lock will already be held by our caller!!!) */
208static int bind_sureware(ENGINE *e)
209{
210#ifndef OPENSSL_NO_RSA
211 const RSA_METHOD *meth1;
212#endif
213#ifndef OPENSSL_NO_DSA
214 const DSA_METHOD *meth2;
215#endif
216#ifndef OPENSSL_NO_DH
217 const DH_METHOD *meth3;
218#endif
219
220 if(!ENGINE_set_id(e, engine_sureware_id) ||
221 !ENGINE_set_name(e, engine_sureware_name) ||
222#ifndef OPENSSL_NO_RSA
223 !ENGINE_set_RSA(e, &surewarehk_rsa) ||
224#endif
225#ifndef OPENSSL_NO_DSA
226 !ENGINE_set_DSA(e, &surewarehk_dsa) ||
227#endif
228#ifndef OPENSSL_NO_DH
229 !ENGINE_set_DH(e, &surewarehk_dh) ||
230#endif
231 !ENGINE_set_RAND(e, &surewarehk_rand) ||
232 !ENGINE_set_destroy_function(e, surewarehk_destroy) ||
233 !ENGINE_set_init_function(e, surewarehk_init) ||
234 !ENGINE_set_finish_function(e, surewarehk_finish) ||
235 !ENGINE_set_ctrl_function(e, surewarehk_ctrl) ||
236 !ENGINE_set_load_privkey_function(e, surewarehk_load_privkey) ||
237 !ENGINE_set_load_pubkey_function(e, surewarehk_load_pubkey))
238 return 0;
239
240#ifndef OPENSSL_NO_RSA
241 /* We know that the "PKCS1_SSLeay()" functions hook properly
242 * to the cswift-specific mod_exp and mod_exp_crt so we use
243 * those functions. NB: We don't use ENGINE_openssl() or
244 * anything "more generic" because something like the RSAref
245 * code may not hook properly, and if you own one of these
246 * cards then you have the right to do RSA operations on it
247 * anyway! */
248 meth1 = RSA_PKCS1_SSLeay();
249 if (meth1)
250 {
251 surewarehk_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
252 surewarehk_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
253 }
254#endif
255
256#ifndef OPENSSL_NO_DSA
257 /* Use the DSA_OpenSSL() method and just hook the mod_exp-ish
258 * bits. */
259 meth2 = DSA_OpenSSL();
260 if (meth2)
261 {
262 surewarehk_dsa.dsa_do_verify = meth2->dsa_do_verify;
263 }
264#endif
265
266#ifndef OPENSSL_NO_DH
267 /* Much the same for Diffie-Hellman */
268 meth3 = DH_OpenSSL();
269 if (meth3)
270 {
271 surewarehk_dh.generate_key = meth3->generate_key;
272 surewarehk_dh.compute_key = meth3->compute_key;
273 }
274#endif
275
276 /* Ensure the sureware error handling is set up */
277 ERR_load_SUREWARE_strings();
278 return 1;
279}
280
281#ifdef ENGINE_DYNAMIC_SUPPORT
282static int bind_helper(ENGINE *e, const char *id)
283 {
284 if(id && (strcmp(id, engine_sureware_id) != 0))
285 return 0;
286 if(!bind_sureware(e))
287 return 0;
288 return 1;
289 }
290IMPLEMENT_DYNAMIC_CHECK_FN()
291IMPLEMENT_DYNAMIC_BIND_FN(bind_helper)
292#else
293static ENGINE *engine_sureware(void)
294 {
295 ENGINE *ret = ENGINE_new();
296 if(!ret)
297 return NULL;
298 if(!bind_sureware(ret))
299 {
300 ENGINE_free(ret);
301 return NULL;
302 }
303 return ret;
304 }
305
306void ENGINE_load_sureware(void)
307 {
308 /* Copied from eng_[openssl|dyn].c */
309 ENGINE *toadd = engine_sureware();
310 if(!toadd) return;
311 ENGINE_add(toadd);
312 ENGINE_free(toadd);
313 ERR_clear_error();
314 }
315#endif
316
317/* This is a process-global DSO handle used for loading and unloading
318 * the SureWareHook library. NB: This is only set (or unset) during an
319 * init() or finish() call (reference counts permitting) and they're
320 * operating with global locks, so this should be thread-safe
321 * implicitly. */
322static DSO *surewarehk_dso = NULL;
323#ifndef OPENSSL_NO_RSA
324static int rsaHndidx = -1; /* Index for KM handle. Not really used yet. */
325#endif
326#ifndef OPENSSL_NO_DSA
327static int dsaHndidx = -1; /* Index for KM handle. Not really used yet. */
328#endif
329
330/* These are the function pointers that are (un)set when the library has
331 * successfully (un)loaded. */
332static SureWareHook_Init_t *p_surewarehk_Init = NULL;
333static SureWareHook_Finish_t *p_surewarehk_Finish = NULL;
334static SureWareHook_Rand_Bytes_t *p_surewarehk_Rand_Bytes = NULL;
335static SureWareHook_Rand_Seed_t *p_surewarehk_Rand_Seed = NULL;
336static SureWareHook_Load_Privkey_t *p_surewarehk_Load_Privkey = NULL;
337static SureWareHook_Info_Pubkey_t *p_surewarehk_Info_Pubkey = NULL;
338static SureWareHook_Load_Rsa_Pubkey_t *p_surewarehk_Load_Rsa_Pubkey = NULL;
339static SureWareHook_Load_Dsa_Pubkey_t *p_surewarehk_Load_Dsa_Pubkey = NULL;
340static SureWareHook_Free_t *p_surewarehk_Free=NULL;
341static SureWareHook_Rsa_Priv_Dec_t *p_surewarehk_Rsa_Priv_Dec=NULL;
342static SureWareHook_Rsa_Sign_t *p_surewarehk_Rsa_Sign=NULL;
343static SureWareHook_Dsa_Sign_t *p_surewarehk_Dsa_Sign=NULL;
344static SureWareHook_Mod_Exp_t *p_surewarehk_Mod_Exp=NULL;
345
346/* Used in the DSO operations. */
347static const char *surewarehk_LIBNAME = "SureWareHook";
348static const char *n_surewarehk_Init = "SureWareHook_Init";
349static const char *n_surewarehk_Finish = "SureWareHook_Finish";
350static const char *n_surewarehk_Rand_Bytes="SureWareHook_Rand_Bytes";
351static const char *n_surewarehk_Rand_Seed="SureWareHook_Rand_Seed";
352static const char *n_surewarehk_Load_Privkey="SureWareHook_Load_Privkey";
353static const char *n_surewarehk_Info_Pubkey="SureWareHook_Info_Pubkey";
354static const char *n_surewarehk_Load_Rsa_Pubkey="SureWareHook_Load_Rsa_Pubkey";
355static const char *n_surewarehk_Load_Dsa_Pubkey="SureWareHook_Load_Dsa_Pubkey";
356static const char *n_surewarehk_Free="SureWareHook_Free";
357static const char *n_surewarehk_Rsa_Priv_Dec="SureWareHook_Rsa_Priv_Dec";
358static const char *n_surewarehk_Rsa_Sign="SureWareHook_Rsa_Sign";
359static const char *n_surewarehk_Dsa_Sign="SureWareHook_Dsa_Sign";
360static const char *n_surewarehk_Mod_Exp="SureWareHook_Mod_Exp";
361static BIO *logstream = NULL;
362
363/* SureWareHook library functions and mechanics - these are used by the
364 * higher-level functions further down. NB: As and where there's no
365 * error checking, take a look lower down where these functions are
366 * called, the checking and error handling is probably down there.
367*/
368static int threadsafe=1;
369static int surewarehk_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
370{
371 int to_return = 1;
372
373 switch(cmd)
374 {
375 case ENGINE_CTRL_SET_LOGSTREAM:
376 {
377 BIO *bio = (BIO *)p;
378 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
379 if (logstream)
380 {
381 BIO_free(logstream);
382 logstream = NULL;
383 }
384 if (CRYPTO_add(&bio->references,1,CRYPTO_LOCK_BIO) > 1)
385 logstream = bio;
386 else
387 SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL,SUREWARE_R_BIO_WAS_FREED);
388 }
389 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
390 break;
391 /* This will prevent the initialisation function from "installing"
392 * the mutex-handling callbacks, even if they are available from
393 * within the library (or were provided to the library from the
394 * calling application). This is to remove any baggage for
395 * applications not using multithreading. */
396 case ENGINE_CTRL_CHIL_NO_LOCKING:
397 CRYPTO_w_lock(CRYPTO_LOCK_ENGINE);
398 threadsafe = 0;
399 CRYPTO_w_unlock(CRYPTO_LOCK_ENGINE);
400 break;
401
402 /* The command isn't understood by this engine */
403 default:
404 SUREWAREerr(SUREWARE_F_SUREWAREHK_CTRL,
405 ENGINE_R_CTRL_COMMAND_NOT_IMPLEMENTED);
406 to_return = 0;
407 break;
408 }
409
410 return to_return;
411}
412
413/* Destructor (complements the "ENGINE_surewarehk()" constructor) */
414static int surewarehk_destroy(ENGINE *e)
415{
416 ERR_unload_SUREWARE_strings();
417 return 1;
418}
419
420/* (de)initialisation functions. */
421static int surewarehk_init(ENGINE *e)
422{
423 char msg[64]="ENGINE_init";
424 SureWareHook_Init_t *p1=NULL;
425 SureWareHook_Finish_t *p2=NULL;
426 SureWareHook_Rand_Bytes_t *p3=NULL;
427 SureWareHook_Rand_Seed_t *p4=NULL;
428 SureWareHook_Load_Privkey_t *p5=NULL;
429 SureWareHook_Load_Rsa_Pubkey_t *p6=NULL;
430 SureWareHook_Free_t *p7=NULL;
431 SureWareHook_Rsa_Priv_Dec_t *p8=NULL;
432 SureWareHook_Rsa_Sign_t *p9=NULL;
433 SureWareHook_Dsa_Sign_t *p12=NULL;
434 SureWareHook_Info_Pubkey_t *p13=NULL;
435 SureWareHook_Load_Dsa_Pubkey_t *p14=NULL;
436 SureWareHook_Mod_Exp_t *p15=NULL;
437
438 if(surewarehk_dso != NULL)
439 {
440 SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_ALREADY_LOADED);
441 goto err;
442 }
443 /* Attempt to load libsurewarehk.so/surewarehk.dll/whatever. */
444 surewarehk_dso = DSO_load(NULL, surewarehk_LIBNAME, NULL, 0);
445 if(surewarehk_dso == NULL)
446 {
447 SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE);
448 goto err;
449 }
450 if(!(p1=(SureWareHook_Init_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Init)) ||
451 !(p2=(SureWareHook_Finish_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Finish)) ||
452 !(p3=(SureWareHook_Rand_Bytes_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Bytes)) ||
453 !(p4=(SureWareHook_Rand_Seed_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rand_Seed)) ||
454 !(p5=(SureWareHook_Load_Privkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Privkey)) ||
455 !(p6=(SureWareHook_Load_Rsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Rsa_Pubkey)) ||
456 !(p7=(SureWareHook_Free_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Free)) ||
457 !(p8=(SureWareHook_Rsa_Priv_Dec_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Priv_Dec)) ||
458 !(p9=(SureWareHook_Rsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Rsa_Sign)) ||
459 !(p12=(SureWareHook_Dsa_Sign_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Dsa_Sign)) ||
460 !(p13=(SureWareHook_Info_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Info_Pubkey)) ||
461 !(p14=(SureWareHook_Load_Dsa_Pubkey_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Load_Dsa_Pubkey)) ||
462 !(p15=(SureWareHook_Mod_Exp_t*)DSO_bind_func(surewarehk_dso, n_surewarehk_Mod_Exp)))
463 {
464 SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,ENGINE_R_DSO_FAILURE);
465 goto err;
466 }
467 /* Copy the pointers */
468 p_surewarehk_Init = p1;
469 p_surewarehk_Finish = p2;
470 p_surewarehk_Rand_Bytes = p3;
471 p_surewarehk_Rand_Seed = p4;
472 p_surewarehk_Load_Privkey = p5;
473 p_surewarehk_Load_Rsa_Pubkey = p6;
474 p_surewarehk_Free = p7;
475 p_surewarehk_Rsa_Priv_Dec = p8;
476 p_surewarehk_Rsa_Sign = p9;
477 p_surewarehk_Dsa_Sign = p12;
478 p_surewarehk_Info_Pubkey = p13;
479 p_surewarehk_Load_Dsa_Pubkey = p14;
480 p_surewarehk_Mod_Exp = p15;
481 /* Contact the hardware and initialises it. */
482 if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE)
483 {
484 SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE);
485 goto err;
486 }
487 if(p_surewarehk_Init(msg,threadsafe)==SUREWAREHOOK_ERROR_UNIT_FAILURE)
488 {
489 SUREWAREerr(SUREWARE_F_SUREWAREHK_INIT,SUREWARE_R_UNIT_FAILURE);
490 goto err;
491 }
492 /* try to load the default private key, if failed does not return a failure but
493 wait for an explicit ENGINE_load_privakey */
494 surewarehk_load_privkey(e,NULL,NULL,NULL);
495
496 /* Everything's fine. */
497#ifndef OPENSSL_NO_RSA
498 if (rsaHndidx == -1)
499 rsaHndidx = RSA_get_ex_new_index(0,
500 "SureWareHook RSA key handle",
501 NULL, NULL, surewarehk_ex_free);
502#endif
503#ifndef OPENSSL_NO_DSA
504 if (dsaHndidx == -1)
505 dsaHndidx = DSA_get_ex_new_index(0,
506 "SureWareHook DSA key handle",
507 NULL, NULL, surewarehk_ex_free);
508#endif
509
510 return 1;
511err:
512 if(surewarehk_dso)
513 DSO_free(surewarehk_dso);
514 surewarehk_dso = NULL;
515 p_surewarehk_Init = NULL;
516 p_surewarehk_Finish = NULL;
517 p_surewarehk_Rand_Bytes = NULL;
518 p_surewarehk_Rand_Seed = NULL;
519 p_surewarehk_Load_Privkey = NULL;
520 p_surewarehk_Load_Rsa_Pubkey = NULL;
521 p_surewarehk_Free = NULL;
522 p_surewarehk_Rsa_Priv_Dec = NULL;
523 p_surewarehk_Rsa_Sign = NULL;
524 p_surewarehk_Dsa_Sign = NULL;
525 p_surewarehk_Info_Pubkey = NULL;
526 p_surewarehk_Load_Dsa_Pubkey = NULL;
527 p_surewarehk_Mod_Exp = NULL;
528 return 0;
529}
530
531static int surewarehk_finish(ENGINE *e)
532{
533 int to_return = 1;
534 if(surewarehk_dso == NULL)
535 {
536 SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_NOT_LOADED);
537 to_return = 0;
538 goto err;
539 }
540 p_surewarehk_Finish();
541 if(!DSO_free(surewarehk_dso))
542 {
543 SUREWAREerr(SUREWARE_F_SUREWAREHK_FINISH,ENGINE_R_DSO_FAILURE);
544 to_return = 0;
545 goto err;
546 }
547 err:
548 if (logstream)
549 BIO_free(logstream);
550 surewarehk_dso = NULL;
551 p_surewarehk_Init = NULL;
552 p_surewarehk_Finish = NULL;
553 p_surewarehk_Rand_Bytes = NULL;
554 p_surewarehk_Rand_Seed = NULL;
555 p_surewarehk_Load_Privkey = NULL;
556 p_surewarehk_Load_Rsa_Pubkey = NULL;
557 p_surewarehk_Free = NULL;
558 p_surewarehk_Rsa_Priv_Dec = NULL;
559 p_surewarehk_Rsa_Sign = NULL;
560 p_surewarehk_Dsa_Sign = NULL;
561 p_surewarehk_Info_Pubkey = NULL;
562 p_surewarehk_Load_Dsa_Pubkey = NULL;
563 p_surewarehk_Mod_Exp = NULL;
564 return to_return;
565}
566
567static void surewarehk_error_handling(char *const msg,int func,int ret)
568{
569 switch (ret)
570 {
571 case SUREWAREHOOK_ERROR_UNIT_FAILURE:
572 ENGINEerr(func,SUREWARE_R_UNIT_FAILURE);
573 break;
574 case SUREWAREHOOK_ERROR_FALLBACK:
575 ENGINEerr(func,SUREWARE_R_REQUEST_FALLBACK);
576 break;
577 case SUREWAREHOOK_ERROR_DATA_SIZE:
578 ENGINEerr(func,SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
579 break;
580 case SUREWAREHOOK_ERROR_INVALID_PAD:
581 ENGINEerr(func,RSA_R_PADDING_CHECK_FAILED);
582 break;
583 default:
584 ENGINEerr(func,SUREWARE_R_REQUEST_FAILED);
585 break;
586 case 1:/*nothing*/
587 msg[0]='\0';
588 }
589 if (*msg)
590 {
591 ERR_add_error_data(1,msg);
592 if (logstream)
593 {
594 CRYPTO_w_lock(CRYPTO_LOCK_BIO);
595 BIO_write(logstream, msg, strlen(msg));
596 CRYPTO_w_unlock(CRYPTO_LOCK_BIO);
597 }
598 }
599}
600
601static int surewarehk_rand_bytes(unsigned char *buf, int num)
602{
603 int ret=0;
604 char msg[64]="ENGINE_rand_bytes";
605 if(!p_surewarehk_Rand_Bytes)
606 {
607 SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_BYTES,ENGINE_R_NOT_INITIALISED);
608 }
609 else
610 {
611 ret = p_surewarehk_Rand_Bytes(msg,buf, num);
612 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_BYTES,ret);
613 }
614 return ret==1 ? 1 : 0;
615}
616
617static void surewarehk_rand_seed(const void *buf, int num)
618{
619 int ret=0;
620 char msg[64]="ENGINE_rand_seed";
621 if(!p_surewarehk_Rand_Seed)
622 {
623 SUREWAREerr(SUREWARE_F_SUREWAREHK_RAND_SEED,ENGINE_R_NOT_INITIALISED);
624 }
625 else
626 {
627 ret = p_surewarehk_Rand_Seed(msg,buf, num);
628 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RAND_SEED,ret);
629 }
630}
631
632static void surewarehk_rand_add(const void *buf, int num, double entropy)
633{
634 surewarehk_rand_seed(buf,num);
635}
636
637static EVP_PKEY* sureware_load_public(ENGINE *e,const char *key_id,char *hptr,unsigned long el,char keytype)
638{
639 EVP_PKEY *res = NULL;
640#ifndef OPENSSL_NO_RSA
641 RSA *rsatmp = NULL;
642#endif
643#ifndef OPENSSL_NO_DSA
644 DSA *dsatmp=NULL;
645#endif
646 char msg[64]="sureware_load_public";
647 int ret=0;
648 if(!p_surewarehk_Load_Rsa_Pubkey || !p_surewarehk_Load_Dsa_Pubkey)
649 {
650 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED);
651 goto err;
652 }
653 switch (keytype)
654 {
655#ifndef OPENSSL_NO_RSA
656 case 1: /*RSA*/
657 /* set private external reference */
658 rsatmp = RSA_new_method(e);
659 RSA_set_ex_data(rsatmp,rsaHndidx,hptr);
660 rsatmp->flags |= RSA_FLAG_EXT_PKEY;
661
662 /* set public big nums*/
663 rsatmp->e = BN_new();
664 rsatmp->n = BN_new();
665 bn_expand2(rsatmp->e, el/sizeof(BN_ULONG));
666 bn_expand2(rsatmp->n, el/sizeof(BN_ULONG));
667 if (!rsatmp->e || rsatmp->e->dmax!=(int)(el/sizeof(BN_ULONG))||
668 !rsatmp->n || rsatmp->n->dmax!=(int)(el/sizeof(BN_ULONG)))
669 goto err;
670 ret=p_surewarehk_Load_Rsa_Pubkey(msg,key_id,el,
671 (unsigned long *)rsatmp->n->d,
672 (unsigned long *)rsatmp->e->d);
673 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);
674 if (ret!=1)
675 {
676 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
677 goto err;
678 }
679 /* normalise pub e and pub n */
680 rsatmp->e->top=el/sizeof(BN_ULONG);
681 bn_fix_top(rsatmp->e);
682 rsatmp->n->top=el/sizeof(BN_ULONG);
683 bn_fix_top(rsatmp->n);
684 /* create an EVP object: engine + rsa key */
685 res = EVP_PKEY_new();
686 EVP_PKEY_assign_RSA(res, rsatmp);
687 break;
688#endif
689
690#ifndef OPENSSL_NO_DSA
691 case 2:/*DSA*/
692 /* set private/public external reference */
693 dsatmp = DSA_new_method(e);
694 DSA_set_ex_data(dsatmp,dsaHndidx,hptr);
695 /*dsatmp->flags |= DSA_FLAG_EXT_PKEY;*/
696
697 /* set public key*/
698 dsatmp->pub_key = BN_new();
699 dsatmp->p = BN_new();
700 dsatmp->q = BN_new();
701 dsatmp->g = BN_new();
702 bn_expand2(dsatmp->pub_key, el/sizeof(BN_ULONG));
703 bn_expand2(dsatmp->p, el/sizeof(BN_ULONG));
704 bn_expand2(dsatmp->q, 20/sizeof(BN_ULONG));
705 bn_expand2(dsatmp->g, el/sizeof(BN_ULONG));
706 if (!dsatmp->pub_key || dsatmp->pub_key->dmax!=(int)(el/sizeof(BN_ULONG))||
707 !dsatmp->p || dsatmp->p->dmax!=(int)(el/sizeof(BN_ULONG)) ||
708 !dsatmp->q || dsatmp->q->dmax!=20/sizeof(BN_ULONG) ||
709 !dsatmp->g || dsatmp->g->dmax!=(int)(el/sizeof(BN_ULONG)))
710 goto err;
711
712 ret=p_surewarehk_Load_Dsa_Pubkey(msg,key_id,el,
713 (unsigned long *)dsatmp->pub_key->d,
714 (unsigned long *)dsatmp->p->d,
715 (unsigned long *)dsatmp->q->d,
716 (unsigned long *)dsatmp->g->d);
717 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ret);
718 if (ret!=1)
719 {
720 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
721 goto err;
722 }
723 /* set parameters */
724 /* normalise pubkey and parameters in case of */
725 dsatmp->pub_key->top=el/sizeof(BN_ULONG);
726 bn_fix_top(dsatmp->pub_key);
727 dsatmp->p->top=el/sizeof(BN_ULONG);
728 bn_fix_top(dsatmp->p);
729 dsatmp->q->top=20/sizeof(BN_ULONG);
730 bn_fix_top(dsatmp->q);
731 dsatmp->g->top=el/sizeof(BN_ULONG);
732 bn_fix_top(dsatmp->g);
733
734 /* create an EVP object: engine + rsa key */
735 res = EVP_PKEY_new();
736 EVP_PKEY_assign_DSA(res, dsatmp);
737 break;
738#endif
739
740 default:
741 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
742 goto err;
743 }
744 return res;
745 err:
746 if (res)
747 EVP_PKEY_free(res);
748#ifndef OPENSSL_NO_RSA
749 if (rsatmp)
750 RSA_free(rsatmp);
751#endif
752#ifndef OPENSSL_NO_DSA
753 if (dsatmp)
754 DSA_free(dsatmp);
755#endif
756 return NULL;
757}
758
759static EVP_PKEY *surewarehk_load_privkey(ENGINE *e, const char *key_id,
760 UI_METHOD *ui_method, void *callback_data)
761{
762 EVP_PKEY *res = NULL;
763 int ret=0;
764 unsigned long el=0;
765 char *hptr=NULL;
766 char keytype=0;
767 char msg[64]="ENGINE_load_privkey";
768
769 if(!p_surewarehk_Load_Privkey)
770 {
771 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_NOT_INITIALISED);
772 }
773 else
774 {
775 ret=p_surewarehk_Load_Privkey(msg,key_id,&hptr,&el,&keytype);
776 if (ret!=1)
777 {
778 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,ENGINE_R_FAILED_LOADING_PRIVATE_KEY);
779 ERR_add_error_data(1,msg);
780 }
781 else
782 res=sureware_load_public(e,key_id,hptr,el,keytype);
783 }
784 return res;
785}
786
787static EVP_PKEY *surewarehk_load_pubkey(ENGINE *e, const char *key_id,
788 UI_METHOD *ui_method, void *callback_data)
789{
790 EVP_PKEY *res = NULL;
791 int ret=0;
792 unsigned long el=0;
793 char *hptr=NULL;
794 char keytype=0;
795 char msg[64]="ENGINE_load_pubkey";
796
797 if(!p_surewarehk_Info_Pubkey)
798 {
799 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_NOT_INITIALISED);
800 }
801 else
802 {
803 /* call once to identify if DSA or RSA */
804 ret=p_surewarehk_Info_Pubkey(msg,key_id,&el,&keytype);
805 if (ret!=1)
806 {
807 SUREWAREerr(SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,ENGINE_R_FAILED_LOADING_PUBLIC_KEY);
808 ERR_add_error_data(1,msg);
809 }
810 else
811 res=sureware_load_public(e,key_id,hptr,el,keytype);
812 }
813 return res;
814}
815
816/* This cleans up an RSA/DSA KM key(do not destroy the key into the hardware)
817, called when ex_data is freed */
818static void surewarehk_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
819 int idx,long argl, void *argp)
820{
821 if(!p_surewarehk_Free)
822 {
823 SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED);
824 }
825 else
826 p_surewarehk_Free((char *)item,0);
827}
828
829#if 0
830/* This cleans up an DH KM key (destroys the key into hardware),
831called when ex_data is freed */
832static void surewarehk_dh_ex_free(void *obj, void *item, CRYPTO_EX_DATA *ad,
833 int idx,long argl, void *argp)
834{
835 if(!p_surewarehk_Free)
836 {
837 SUREWAREerr(SUREWARE_F_SUREWAREHK_EX_FREE,ENGINE_R_NOT_INITIALISED);
838 }
839 else
840 p_surewarehk_Free((char *)item,1);
841}
842#endif
843
844/*
845* return number of decrypted bytes
846*/
847#ifndef OPENSSL_NO_RSA
848static int surewarehk_rsa_priv_dec(int flen,const unsigned char *from,unsigned char *to,
849 RSA *rsa,int padding)
850{
851 int ret=0,tlen;
852 char *buf=NULL,*hptr=NULL;
853 char msg[64]="ENGINE_rsa_priv_dec";
854 if (!p_surewarehk_Rsa_Priv_Dec)
855 {
856 SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ENGINE_R_NOT_INITIALISED);
857 }
858 /* extract ref to private key */
859 else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx)))
860 {
861 SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,SUREWARE_R_MISSING_KEY_COMPONENTS);
862 goto err;
863 }
864 /* analyse what padding we can do into the hardware */
865 if (padding==RSA_PKCS1_PADDING)
866 {
867 /* do it one shot */
868 ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD);
869 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret);
870 if (ret!=1)
871 goto err;
872 ret=tlen;
873 }
874 else /* do with no padding into hardware */
875 {
876 ret=p_surewarehk_Rsa_Priv_Dec(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_NO_PAD);
877 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ret);
878 if (ret!=1)
879 goto err;
880 /* intermediate buffer for padding */
881 if ((buf=OPENSSL_malloc(tlen)) == NULL)
882 {
883 RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,ERR_R_MALLOC_FAILURE);
884 goto err;
885 }
886 memcpy(buf,to,tlen);/* transfert to into buf */
887 switch (padding) /* check padding in software */
888 {
889#ifndef OPENSSL_NO_SHA
890 case RSA_PKCS1_OAEP_PADDING:
891 ret=RSA_padding_check_PKCS1_OAEP(to,tlen,(unsigned char *)buf,tlen,tlen,NULL,0);
892 break;
893#endif
894 case RSA_SSLV23_PADDING:
895 ret=RSA_padding_check_SSLv23(to,tlen,(unsigned char *)buf,flen,tlen);
896 break;
897 case RSA_NO_PADDING:
898 ret=RSA_padding_check_none(to,tlen,(unsigned char *)buf,flen,tlen);
899 break;
900 default:
901 RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_UNKNOWN_PADDING_TYPE);
902 goto err;
903 }
904 if (ret < 0)
905 RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,RSA_R_PADDING_CHECK_FAILED);
906 }
907err:
908 if (buf)
909 {
910 OPENSSL_cleanse(buf,tlen);
911 OPENSSL_free(buf);
912 }
913 return ret;
914}
915
916/*
917* Does what OpenSSL rsa_priv_enc does.
918*/
919static int surewarehk_rsa_sign(int flen,const unsigned char *from,unsigned char *to,
920 RSA *rsa,int padding)
921{
922 int ret=0,tlen;
923 char *hptr=NULL;
924 char msg[64]="ENGINE_rsa_sign";
925 if (!p_surewarehk_Rsa_Sign)
926 {
927 SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ENGINE_R_NOT_INITIALISED);
928 }
929 /* extract ref to private key */
930 else if (!(hptr=RSA_get_ex_data(rsa, rsaHndidx)))
931 {
932 SUREWAREerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,SUREWARE_R_MISSING_KEY_COMPONENTS);
933 }
934 else
935 {
936 switch (padding)
937 {
938 case RSA_PKCS1_PADDING: /* do it in one shot */
939 ret=p_surewarehk_Rsa_Sign(msg,flen,(unsigned char *)from,&tlen,to,hptr,SUREWARE_PKCS1_PAD);
940 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,ret);
941 break;
942 case RSA_NO_PADDING:
943 default:
944 RSAerr(SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,RSA_R_UNKNOWN_PADDING_TYPE);
945 }
946 }
947 return ret==1 ? tlen : ret;
948}
949
950#endif
951
952#ifndef OPENSSL_NO_DSA
953/* DSA sign and verify */
954static DSA_SIG * surewarehk_dsa_do_sign(const unsigned char *from, int flen, DSA *dsa)
955{
956 int ret=0;
957 char *hptr=NULL;
958 DSA_SIG *psign=NULL;
959 char msg[64]="ENGINE_dsa_do_sign";
960 if (!p_surewarehk_Dsa_Sign)
961 {
962 SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ENGINE_R_NOT_INITIALISED);
963 }
964 /* extract ref to private key */
965 else if (!(hptr=DSA_get_ex_data(dsa, dsaHndidx)))
966 {
967 SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,SUREWARE_R_MISSING_KEY_COMPONENTS);
968 }
969 else
970 {
971 if((psign = DSA_SIG_new()) == NULL)
972 {
973 SUREWAREerr(SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ERR_R_MALLOC_FAILURE);
974 goto err;
975 }
976 psign->r=BN_new();
977 psign->s=BN_new();
978 bn_expand2(psign->r, 20/sizeof(BN_ULONG));
979 bn_expand2(psign->s, 20/sizeof(BN_ULONG));
980 if (!psign->r || psign->r->dmax!=20/sizeof(BN_ULONG) ||
981 !psign->s || psign->s->dmax!=20/sizeof(BN_ULONG))
982 goto err;
983 ret=p_surewarehk_Dsa_Sign(msg,flen,from,
984 (unsigned long *)psign->r->d,
985 (unsigned long *)psign->s->d,
986 hptr);
987 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,ret);
988 }
989 psign->r->top=20/sizeof(BN_ULONG);
990 bn_fix_top(psign->r);
991 psign->s->top=20/sizeof(BN_ULONG);
992 bn_fix_top(psign->s);
993
994err:
995 if (psign)
996 {
997 DSA_SIG_free(psign);
998 psign=NULL;
999 }
1000 return psign;
1001}
1002#endif
1003
1004static int surewarehk_modexp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
1005 const BIGNUM *m, BN_CTX *ctx)
1006{
1007 int ret=0;
1008 char msg[64]="ENGINE_modexp";
1009 if (!p_surewarehk_Mod_Exp)
1010 {
1011 SUREWAREerr(SUREWARE_F_SUREWAREHK_MOD_EXP,ENGINE_R_NOT_INITIALISED);
1012 }
1013 else
1014 {
1015 bn_expand2(r,m->top);
1016 if (r && r->dmax==m->top)
1017 {
1018 /* do it*/
1019 ret=p_surewarehk_Mod_Exp(msg,
1020 m->top*sizeof(BN_ULONG),
1021 (unsigned long *)m->d,
1022 p->top*sizeof(BN_ULONG),
1023 (unsigned long *)p->d,
1024 a->top*sizeof(BN_ULONG),
1025 (unsigned long *)a->d,
1026 (unsigned long *)r->d);
1027 surewarehk_error_handling(msg,SUREWARE_F_SUREWAREHK_MOD_EXP,ret);
1028 if (ret==1)
1029 {
1030 /* normalise result */
1031 r->top=m->top;
1032 bn_fix_top(r);
1033 }
1034 }
1035 }
1036 return ret;
1037}
1038#endif /* !OPENSSL_NO_HW_SureWare */
1039#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.c b/src/lib/libcrypto/engine/hw_sureware_err.c
new file mode 100644
index 0000000000..69955dadbb
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_sureware_err.c
@@ -0,0 +1,150 @@
1/* hw_sureware_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_sureware_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA SUREWARE_str_functs[]=
68 {
69{ERR_PACK(0,SUREWARE_F_SUREWAREHK_CTRL,0), "SUREWAREHK_CTRL"},
70{ERR_PACK(0,SUREWARE_F_SUREWAREHK_DSA_DO_SIGN,0), "SUREWAREHK_DSA_DO_SIGN"},
71{ERR_PACK(0,SUREWARE_F_SUREWAREHK_EX_FREE,0), "SUREWAREHK_EX_FREE"},
72{ERR_PACK(0,SUREWARE_F_SUREWAREHK_FINISH,0), "SUREWAREHK_FINISH"},
73{ERR_PACK(0,SUREWARE_F_SUREWAREHK_INIT,0), "SUREWAREHK_INIT"},
74{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY,0), "SUREWAREHK_LOAD_PRIVATE_KEY"},
75{ERR_PACK(0,SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY,0), "SUREWAREHK_LOAD_PUBLIC_KEY"},
76{ERR_PACK(0,SUREWARE_F_SUREWAREHK_MOD_EXP,0), "SUREWAREHK_MOD_EXP"},
77{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_BYTES,0), "SUREWAREHK_RAND_BYTES"},
78{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RAND_SEED,0), "SUREWAREHK_RAND_SEED"},
79{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC,0), "SUREWAREHK_RSA_PRIV_DEC"},
80{ERR_PACK(0,SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC,0), "SUREWAREHK_RSA_PRIV_ENC"},
81{0,NULL}
82 };
83
84static ERR_STRING_DATA SUREWARE_str_reasons[]=
85 {
86{SUREWARE_R_BIO_WAS_FREED ,"bio was freed"},
87{SUREWARE_R_MISSING_KEY_COMPONENTS ,"missing key components"},
88{SUREWARE_R_REQUEST_FAILED ,"request failed"},
89{SUREWARE_R_REQUEST_FALLBACK ,"request fallback"},
90{SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
91{SUREWARE_R_UNIT_FAILURE ,"unit failure"},
92{0,NULL}
93 };
94
95#endif
96
97#ifdef SUREWARE_LIB_NAME
98static ERR_STRING_DATA SUREWARE_lib_name[]=
99 {
100{0 ,SUREWARE_LIB_NAME},
101{0,NULL}
102 };
103#endif
104
105
106static int SUREWARE_lib_error_code=0;
107static int SUREWARE_error_init=1;
108
109static void ERR_load_SUREWARE_strings(void)
110 {
111 if (SUREWARE_lib_error_code == 0)
112 SUREWARE_lib_error_code=ERR_get_next_error_library();
113
114 if (SUREWARE_error_init)
115 {
116 SUREWARE_error_init=0;
117#ifndef OPENSSL_NO_ERR
118 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
119 ERR_load_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
120#endif
121
122#ifdef SUREWARE_LIB_NAME
123 SUREWARE_lib_name->error = ERR_PACK(SUREWARE_lib_error_code,0,0);
124 ERR_load_strings(0,SUREWARE_lib_name);
125#endif
126 }
127 }
128
129static void ERR_unload_SUREWARE_strings(void)
130 {
131 if (SUREWARE_error_init == 0)
132 {
133#ifndef OPENSSL_NO_ERR
134 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_functs);
135 ERR_unload_strings(SUREWARE_lib_error_code,SUREWARE_str_reasons);
136#endif
137
138#ifdef SUREWARE_LIB_NAME
139 ERR_unload_strings(0,SUREWARE_lib_name);
140#endif
141 SUREWARE_error_init=1;
142 }
143 }
144
145static void ERR_SUREWARE_error(int function, int reason, char *file, int line)
146 {
147 if (SUREWARE_lib_error_code == 0)
148 SUREWARE_lib_error_code=ERR_get_next_error_library();
149 ERR_PUT_error(SUREWARE_lib_error_code,function,reason,file,line);
150 }
diff --git a/src/lib/libcrypto/engine/hw_sureware_err.h b/src/lib/libcrypto/engine/hw_sureware_err.h
new file mode 100644
index 0000000000..bc52af5e05
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_sureware_err.h
@@ -0,0 +1,94 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_SUREWARE_ERR_H
56#define HEADER_SUREWARE_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_SUREWARE_strings(void);
63static void ERR_unload_SUREWARE_strings(void);
64static void ERR_SUREWARE_error(int function, int reason, char *file, int line);
65#define SUREWAREerr(f,r) ERR_SUREWARE_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the SUREWARE functions. */
68
69/* Function codes. */
70#define SUREWARE_F_SUREWAREHK_CTRL 100
71#define SUREWARE_F_SUREWAREHK_DSA_DO_SIGN 101
72#define SUREWARE_F_SUREWAREHK_EX_FREE 102
73#define SUREWARE_F_SUREWAREHK_FINISH 103
74#define SUREWARE_F_SUREWAREHK_INIT 104
75#define SUREWARE_F_SUREWAREHK_LOAD_PRIVATE_KEY 105
76#define SUREWARE_F_SUREWAREHK_LOAD_PUBLIC_KEY 106
77#define SUREWARE_F_SUREWAREHK_MOD_EXP 107
78#define SUREWARE_F_SUREWAREHK_RAND_BYTES 108
79#define SUREWARE_F_SUREWAREHK_RAND_SEED 109
80#define SUREWARE_F_SUREWAREHK_RSA_PRIV_DEC 110
81#define SUREWARE_F_SUREWAREHK_RSA_PRIV_ENC 111
82
83/* Reason codes. */
84#define SUREWARE_R_BIO_WAS_FREED 100
85#define SUREWARE_R_MISSING_KEY_COMPONENTS 105
86#define SUREWARE_R_REQUEST_FAILED 101
87#define SUREWARE_R_REQUEST_FALLBACK 102
88#define SUREWARE_R_SIZE_TOO_LARGE_OR_TOO_SMALL 103
89#define SUREWARE_R_UNIT_FAILURE 104
90
91#ifdef __cplusplus
92}
93#endif
94#endif
diff --git a/src/lib/libcrypto/engine/hw_ubsec.c b/src/lib/libcrypto/engine/hw_ubsec.c
new file mode 100644
index 0000000000..8fb834af31
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec.c
@@ -0,0 +1,1061 @@
1/* crypto/engine/hw_ubsec.c */
2/* Written by Geoff Thorpe (geoff@geoffthorpe.net) for the OpenSSL
3 * project 2000.
4 *
5 * Cloned shamelessly by Joe Tardo.
6 */
7/* ====================================================================
8 * Copyright (c) 1999-2001 The OpenSSL Project. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 *
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 *
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in
19 * the documentation and/or other materials provided with the
20 * distribution.
21 *
22 * 3. All advertising materials mentioning features or use of this
23 * software must display the following acknowledgment:
24 * "This product includes software developed by the OpenSSL Project
25 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
26 *
27 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
28 * endorse or promote products derived from this software without
29 * prior written permission. For written permission, please contact
30 * licensing@OpenSSL.org.
31 *
32 * 5. Products derived from this software may not be called "OpenSSL"
33 * nor may "OpenSSL" appear in their names without prior written
34 * permission of the OpenSSL Project.
35 *
36 * 6. Redistributions of any form whatsoever must retain the following
37 * acknowledgment:
38 * "This product includes software developed by the OpenSSL Project
39 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
42 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
45 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 * ====================================================================
54 *
55 * This product includes cryptographic software written by Eric Young
56 * (eay@cryptsoft.com). This product includes software written by Tim
57 * Hudson (tjh@cryptsoft.com).
58 *
59 */
60
61#include <stdio.h>
62#include <openssl/crypto.h>
63#include "cryptlib.h"
64#include <openssl/dso.h>
65#include <openssl/engine.h>
66
67#ifndef OPENSSL_NO_HW
68#ifndef OPENSSL_NO_HW_UBSEC
69
70#ifdef FLAT_INC
71#include "hw_ubsec.h"
72#else
73#include "vendor_defns/hw_ubsec.h"
74#endif
75
76#define UBSEC_LIB_NAME "ubsec engine"
77#include "hw_ubsec_err.c"
78
79#define FAIL_TO_SOFTWARE -15
80
81static int ubsec_destroy(ENGINE *e);
82static int ubsec_init(ENGINE *e);
83static int ubsec_finish(ENGINE *e);
84static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)());
85static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
86 const BIGNUM *m, BN_CTX *ctx);
87static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
88 const BIGNUM *q, const BIGNUM *dp,
89 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx);
90#ifndef OPENSSL_NO_RSA
91static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa);
92#endif
93static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
94 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
95#ifndef OPENSSL_NO_DSA
96#ifdef NOT_USED
97static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
98 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
99 BN_CTX *ctx, BN_MONT_CTX *in_mont);
100static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
101 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
102 BN_MONT_CTX *m_ctx);
103#endif
104static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa);
105static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
106 DSA_SIG *sig, DSA *dsa);
107#endif
108#ifndef OPENSSL_NO_DH
109static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
110 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
111 BN_MONT_CTX *m_ctx);
112static int ubsec_dh_compute_key(unsigned char *key,const BIGNUM *pub_key,DH *dh);
113static int ubsec_dh_generate_key(DH *dh);
114#endif
115
116#ifdef NOT_USED
117static int ubsec_rand_bytes(unsigned char *buf, int num);
118static int ubsec_rand_status(void);
119#endif
120
121#define UBSEC_CMD_SO_PATH ENGINE_CMD_BASE
122static const ENGINE_CMD_DEFN ubsec_cmd_defns[] = {
123 {UBSEC_CMD_SO_PATH,
124 "SO_PATH",
125 "Specifies the path to the 'ubsec' shared library",
126 ENGINE_CMD_FLAG_STRING},
127 {0, NULL, NULL, 0}
128 };
129
130#ifndef OPENSSL_NO_RSA
131/* Our internal RSA_METHOD that we provide pointers to */
132static RSA_METHOD ubsec_rsa =
133 {
134 "UBSEC RSA method",
135 NULL,
136 NULL,
137 NULL,
138 NULL,
139 ubsec_rsa_mod_exp,
140 ubsec_mod_exp_mont,
141 NULL,
142 NULL,
143 0,
144 NULL,
145 NULL,
146 NULL
147 };
148#endif
149
150#ifndef OPENSSL_NO_DSA
151/* Our internal DSA_METHOD that we provide pointers to */
152static DSA_METHOD ubsec_dsa =
153 {
154 "UBSEC DSA method",
155 ubsec_dsa_do_sign, /* dsa_do_sign */
156 NULL, /* dsa_sign_setup */
157 ubsec_dsa_verify, /* dsa_do_verify */
158 NULL, /* ubsec_dsa_mod_exp */ /* dsa_mod_exp */
159 NULL, /* ubsec_mod_exp_dsa */ /* bn_mod_exp */
160 NULL, /* init */
161 NULL, /* finish */
162 0, /* flags */
163 NULL /* app_data */
164 };
165#endif
166
167#ifndef OPENSSL_NO_DH
168/* Our internal DH_METHOD that we provide pointers to */
169static DH_METHOD ubsec_dh =
170 {
171 "UBSEC DH method",
172 ubsec_dh_generate_key,
173 ubsec_dh_compute_key,
174 ubsec_mod_exp_dh,
175 NULL,
176 NULL,
177 0,
178 NULL
179 };
180#endif
181
182/* Constants used when creating the ENGINE */
183static const char *engine_ubsec_id = "ubsec";
184static const char *engine_ubsec_name = "UBSEC hardware engine support";
185
186/* This internal function is used by ENGINE_ubsec() and possibly by the
187 * "dynamic" ENGINE support too */
188static int bind_helper(ENGINE *e)
189 {
190#ifndef OPENSSL_NO_RSA
191 const RSA_METHOD *meth1;
192#endif
193#ifndef OPENSSL_NO_DH
194#ifndef HAVE_UBSEC_DH
195 const DH_METHOD *meth3;
196#endif /* HAVE_UBSEC_DH */
197#endif
198 if(!ENGINE_set_id(e, engine_ubsec_id) ||
199 !ENGINE_set_name(e, engine_ubsec_name) ||
200#ifndef OPENSSL_NO_RSA
201 !ENGINE_set_RSA(e, &ubsec_rsa) ||
202#endif
203#ifndef OPENSSL_NO_DSA
204 !ENGINE_set_DSA(e, &ubsec_dsa) ||
205#endif
206#ifndef OPENSSL_NO_DH
207 !ENGINE_set_DH(e, &ubsec_dh) ||
208#endif
209 !ENGINE_set_destroy_function(e, ubsec_destroy) ||
210 !ENGINE_set_init_function(e, ubsec_init) ||
211 !ENGINE_set_finish_function(e, ubsec_finish) ||
212 !ENGINE_set_ctrl_function(e, ubsec_ctrl) ||
213 !ENGINE_set_cmd_defns(e, ubsec_cmd_defns))
214 return 0;
215
216#ifndef OPENSSL_NO_RSA
217 /* We know that the "PKCS1_SSLeay()" functions hook properly
218 * to the Broadcom-specific mod_exp and mod_exp_crt so we use
219 * those functions. NB: We don't use ENGINE_openssl() or
220 * anything "more generic" because something like the RSAref
221 * code may not hook properly, and if you own one of these
222 * cards then you have the right to do RSA operations on it
223 * anyway! */
224 meth1 = RSA_PKCS1_SSLeay();
225 ubsec_rsa.rsa_pub_enc = meth1->rsa_pub_enc;
226 ubsec_rsa.rsa_pub_dec = meth1->rsa_pub_dec;
227 ubsec_rsa.rsa_priv_enc = meth1->rsa_priv_enc;
228 ubsec_rsa.rsa_priv_dec = meth1->rsa_priv_dec;
229#endif
230
231#ifndef OPENSSL_NO_DH
232#ifndef HAVE_UBSEC_DH
233 /* Much the same for Diffie-Hellman */
234 meth3 = DH_OpenSSL();
235 ubsec_dh.generate_key = meth3->generate_key;
236 ubsec_dh.compute_key = meth3->compute_key;
237#endif /* HAVE_UBSEC_DH */
238#endif
239
240 /* Ensure the ubsec error handling is set up */
241 ERR_load_UBSEC_strings();
242 return 1;
243 }
244
245#ifndef ENGINE_DYNAMIC_SUPPORT
246static ENGINE *engine_ubsec(void)
247 {
248 ENGINE *ret = ENGINE_new();
249 if(!ret)
250 return NULL;
251 if(!bind_helper(ret))
252 {
253 ENGINE_free(ret);
254 return NULL;
255 }
256 return ret;
257 }
258
259void ENGINE_load_ubsec(void)
260 {
261 /* Copied from eng_[openssl|dyn].c */
262 ENGINE *toadd = engine_ubsec();
263 if(!toadd) return;
264 ENGINE_add(toadd);
265 ENGINE_free(toadd);
266 ERR_clear_error();
267 }
268#endif
269
270/* This is a process-global DSO handle used for loading and unloading
271 * the UBSEC library. NB: This is only set (or unset) during an
272 * init() or finish() call (reference counts permitting) and they're
273 * operating with global locks, so this should be thread-safe
274 * implicitly. */
275
276static DSO *ubsec_dso = NULL;
277
278/* These are the function pointers that are (un)set when the library has
279 * successfully (un)loaded. */
280
281static t_UBSEC_ubsec_bytes_to_bits *p_UBSEC_ubsec_bytes_to_bits = NULL;
282static t_UBSEC_ubsec_bits_to_bytes *p_UBSEC_ubsec_bits_to_bytes = NULL;
283static t_UBSEC_ubsec_open *p_UBSEC_ubsec_open = NULL;
284static t_UBSEC_ubsec_close *p_UBSEC_ubsec_close = NULL;
285#ifndef OPENSSL_NO_DH
286static t_UBSEC_diffie_hellman_generate_ioctl
287 *p_UBSEC_diffie_hellman_generate_ioctl = NULL;
288static t_UBSEC_diffie_hellman_agree_ioctl *p_UBSEC_diffie_hellman_agree_ioctl = NULL;
289#endif
290/* #ifndef OPENSSL_NO_RSA */
291static t_UBSEC_rsa_mod_exp_ioctl *p_UBSEC_rsa_mod_exp_ioctl = NULL;
292static t_UBSEC_rsa_mod_exp_crt_ioctl *p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
293/* #endif */
294#ifndef OPENSSL_NO_DSA
295static t_UBSEC_dsa_sign_ioctl *p_UBSEC_dsa_sign_ioctl = NULL;
296static t_UBSEC_dsa_verify_ioctl *p_UBSEC_dsa_verify_ioctl = NULL;
297#endif
298static t_UBSEC_math_accelerate_ioctl *p_UBSEC_math_accelerate_ioctl = NULL;
299static t_UBSEC_rng_ioctl *p_UBSEC_rng_ioctl = NULL;
300static t_UBSEC_max_key_len_ioctl *p_UBSEC_max_key_len_ioctl = NULL;
301
302static int max_key_len = 1024; /* ??? */
303
304/*
305 * These are the static string constants for the DSO file name and the function
306 * symbol names to bind to.
307 */
308
309static const char *UBSEC_LIBNAME = NULL;
310static const char *get_UBSEC_LIBNAME(void)
311 {
312 if(UBSEC_LIBNAME)
313 return UBSEC_LIBNAME;
314 return "ubsec";
315 }
316static void free_UBSEC_LIBNAME(void)
317 {
318 if(UBSEC_LIBNAME)
319 OPENSSL_free((void*)UBSEC_LIBNAME);
320 UBSEC_LIBNAME = NULL;
321 }
322static long set_UBSEC_LIBNAME(const char *name)
323 {
324 free_UBSEC_LIBNAME();
325 return (((UBSEC_LIBNAME = BUF_strdup(name)) != NULL) ? 1 : 0);
326 }
327static const char *UBSEC_F1 = "ubsec_bytes_to_bits";
328static const char *UBSEC_F2 = "ubsec_bits_to_bytes";
329static const char *UBSEC_F3 = "ubsec_open";
330static const char *UBSEC_F4 = "ubsec_close";
331#ifndef OPENSSL_NO_DH
332static const char *UBSEC_F5 = "diffie_hellman_generate_ioctl";
333static const char *UBSEC_F6 = "diffie_hellman_agree_ioctl";
334#endif
335/* #ifndef OPENSSL_NO_RSA */
336static const char *UBSEC_F7 = "rsa_mod_exp_ioctl";
337static const char *UBSEC_F8 = "rsa_mod_exp_crt_ioctl";
338/* #endif */
339#ifndef OPENSSL_NO_DSA
340static const char *UBSEC_F9 = "dsa_sign_ioctl";
341static const char *UBSEC_F10 = "dsa_verify_ioctl";
342#endif
343static const char *UBSEC_F11 = "math_accelerate_ioctl";
344static const char *UBSEC_F12 = "rng_ioctl";
345static const char *UBSEC_F13 = "ubsec_max_key_len_ioctl";
346
347/* Destructor (complements the "ENGINE_ubsec()" constructor) */
348static int ubsec_destroy(ENGINE *e)
349 {
350 free_UBSEC_LIBNAME();
351 ERR_unload_UBSEC_strings();
352 return 1;
353 }
354
355/* (de)initialisation functions. */
356static int ubsec_init(ENGINE *e)
357 {
358 t_UBSEC_ubsec_bytes_to_bits *p1;
359 t_UBSEC_ubsec_bits_to_bytes *p2;
360 t_UBSEC_ubsec_open *p3;
361 t_UBSEC_ubsec_close *p4;
362#ifndef OPENSSL_NO_DH
363 t_UBSEC_diffie_hellman_generate_ioctl *p5;
364 t_UBSEC_diffie_hellman_agree_ioctl *p6;
365#endif
366/* #ifndef OPENSSL_NO_RSA */
367 t_UBSEC_rsa_mod_exp_ioctl *p7;
368 t_UBSEC_rsa_mod_exp_crt_ioctl *p8;
369/* #endif */
370#ifndef OPENSSL_NO_DSA
371 t_UBSEC_dsa_sign_ioctl *p9;
372 t_UBSEC_dsa_verify_ioctl *p10;
373#endif
374 t_UBSEC_math_accelerate_ioctl *p11;
375 t_UBSEC_rng_ioctl *p12;
376 t_UBSEC_max_key_len_ioctl *p13;
377 int fd = 0;
378
379 if(ubsec_dso != NULL)
380 {
381 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_ALREADY_LOADED);
382 goto err;
383 }
384 /*
385 * Attempt to load libubsec.so/ubsec.dll/whatever.
386 */
387 ubsec_dso = DSO_load(NULL, get_UBSEC_LIBNAME(), NULL, 0);
388 if(ubsec_dso == NULL)
389 {
390 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
391 goto err;
392 }
393
394 if (
395 !(p1 = (t_UBSEC_ubsec_bytes_to_bits *) DSO_bind_func(ubsec_dso, UBSEC_F1)) ||
396 !(p2 = (t_UBSEC_ubsec_bits_to_bytes *) DSO_bind_func(ubsec_dso, UBSEC_F2)) ||
397 !(p3 = (t_UBSEC_ubsec_open *) DSO_bind_func(ubsec_dso, UBSEC_F3)) ||
398 !(p4 = (t_UBSEC_ubsec_close *) DSO_bind_func(ubsec_dso, UBSEC_F4)) ||
399#ifndef OPENSSL_NO_DH
400 !(p5 = (t_UBSEC_diffie_hellman_generate_ioctl *)
401 DSO_bind_func(ubsec_dso, UBSEC_F5)) ||
402 !(p6 = (t_UBSEC_diffie_hellman_agree_ioctl *)
403 DSO_bind_func(ubsec_dso, UBSEC_F6)) ||
404#endif
405/* #ifndef OPENSSL_NO_RSA */
406 !(p7 = (t_UBSEC_rsa_mod_exp_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F7)) ||
407 !(p8 = (t_UBSEC_rsa_mod_exp_crt_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F8)) ||
408/* #endif */
409#ifndef OPENSSL_NO_DSA
410 !(p9 = (t_UBSEC_dsa_sign_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F9)) ||
411 !(p10 = (t_UBSEC_dsa_verify_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F10)) ||
412#endif
413 !(p11 = (t_UBSEC_math_accelerate_ioctl *)
414 DSO_bind_func(ubsec_dso, UBSEC_F11)) ||
415 !(p12 = (t_UBSEC_rng_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F12)) ||
416 !(p13 = (t_UBSEC_max_key_len_ioctl *) DSO_bind_func(ubsec_dso, UBSEC_F13)))
417 {
418 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_DSO_FAILURE);
419 goto err;
420 }
421
422 /* Copy the pointers */
423 p_UBSEC_ubsec_bytes_to_bits = p1;
424 p_UBSEC_ubsec_bits_to_bytes = p2;
425 p_UBSEC_ubsec_open = p3;
426 p_UBSEC_ubsec_close = p4;
427#ifndef OPENSSL_NO_DH
428 p_UBSEC_diffie_hellman_generate_ioctl = p5;
429 p_UBSEC_diffie_hellman_agree_ioctl = p6;
430#endif
431#ifndef OPENSSL_NO_RSA
432 p_UBSEC_rsa_mod_exp_ioctl = p7;
433 p_UBSEC_rsa_mod_exp_crt_ioctl = p8;
434#endif
435#ifndef OPENSSL_NO_DSA
436 p_UBSEC_dsa_sign_ioctl = p9;
437 p_UBSEC_dsa_verify_ioctl = p10;
438#endif
439 p_UBSEC_math_accelerate_ioctl = p11;
440 p_UBSEC_rng_ioctl = p12;
441 p_UBSEC_max_key_len_ioctl = p13;
442
443 /* Perform an open to see if there's actually any unit running. */
444 if (((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) > 0) && (p_UBSEC_max_key_len_ioctl(fd, &max_key_len) == 0))
445 {
446 p_UBSEC_ubsec_close(fd);
447 return 1;
448 }
449 else
450 {
451 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
452 }
453
454err:
455 if(ubsec_dso)
456 DSO_free(ubsec_dso);
457 ubsec_dso = NULL;
458 p_UBSEC_ubsec_bytes_to_bits = NULL;
459 p_UBSEC_ubsec_bits_to_bytes = NULL;
460 p_UBSEC_ubsec_open = NULL;
461 p_UBSEC_ubsec_close = NULL;
462#ifndef OPENSSL_NO_DH
463 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
464 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
465#endif
466#ifndef OPENSSL_NO_RSA
467 p_UBSEC_rsa_mod_exp_ioctl = NULL;
468 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
469#endif
470#ifndef OPENSSL_NO_DSA
471 p_UBSEC_dsa_sign_ioctl = NULL;
472 p_UBSEC_dsa_verify_ioctl = NULL;
473#endif
474 p_UBSEC_math_accelerate_ioctl = NULL;
475 p_UBSEC_rng_ioctl = NULL;
476 p_UBSEC_max_key_len_ioctl = NULL;
477
478 return 0;
479 }
480
481static int ubsec_finish(ENGINE *e)
482 {
483 free_UBSEC_LIBNAME();
484 if(ubsec_dso == NULL)
485 {
486 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_NOT_LOADED);
487 return 0;
488 }
489 if(!DSO_free(ubsec_dso))
490 {
491 UBSECerr(UBSEC_F_UBSEC_FINISH, UBSEC_R_DSO_FAILURE);
492 return 0;
493 }
494 ubsec_dso = NULL;
495 p_UBSEC_ubsec_bytes_to_bits = NULL;
496 p_UBSEC_ubsec_bits_to_bytes = NULL;
497 p_UBSEC_ubsec_open = NULL;
498 p_UBSEC_ubsec_close = NULL;
499#ifndef OPENSSL_NO_DH
500 p_UBSEC_diffie_hellman_generate_ioctl = NULL;
501 p_UBSEC_diffie_hellman_agree_ioctl = NULL;
502#endif
503#ifndef OPENSSL_NO_RSA
504 p_UBSEC_rsa_mod_exp_ioctl = NULL;
505 p_UBSEC_rsa_mod_exp_crt_ioctl = NULL;
506#endif
507#ifndef OPENSSL_NO_DSA
508 p_UBSEC_dsa_sign_ioctl = NULL;
509 p_UBSEC_dsa_verify_ioctl = NULL;
510#endif
511 p_UBSEC_math_accelerate_ioctl = NULL;
512 p_UBSEC_rng_ioctl = NULL;
513 p_UBSEC_max_key_len_ioctl = NULL;
514 return 1;
515 }
516
517static int ubsec_ctrl(ENGINE *e, int cmd, long i, void *p, void (*f)())
518 {
519 int initialised = ((ubsec_dso == NULL) ? 0 : 1);
520 switch(cmd)
521 {
522 case UBSEC_CMD_SO_PATH:
523 if(p == NULL)
524 {
525 UBSECerr(UBSEC_F_UBSEC_CTRL,ERR_R_PASSED_NULL_PARAMETER);
526 return 0;
527 }
528 if(initialised)
529 {
530 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_ALREADY_LOADED);
531 return 0;
532 }
533 return set_UBSEC_LIBNAME((const char *)p);
534 default:
535 break;
536 }
537 UBSECerr(UBSEC_F_UBSEC_CTRL,UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED);
538 return 0;
539 }
540
541static int ubsec_mod_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
542 const BIGNUM *m, BN_CTX *ctx)
543 {
544 int y_len = 0;
545 int fd;
546
547 if(ubsec_dso == NULL)
548 {
549 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_NOT_LOADED);
550 return 0;
551 }
552
553 /* Check if hardware can't handle this argument. */
554 y_len = BN_num_bits(m);
555 if (y_len > max_key_len) {
556 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
557 return BN_mod_exp(r, a, p, m, ctx);
558 }
559
560 if(!bn_wexpand(r, m->top))
561 {
562 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_BN_EXPAND_FAIL);
563 return 0;
564 }
565
566 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
567 fd = 0;
568 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
569 return BN_mod_exp(r, a, p, m, ctx);
570 }
571
572 if (p_UBSEC_rsa_mod_exp_ioctl(fd, (unsigned char *)a->d, BN_num_bits(a),
573 (unsigned char *)m->d, BN_num_bits(m), (unsigned char *)p->d,
574 BN_num_bits(p), (unsigned char *)r->d, &y_len) != 0)
575 {
576 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
577 p_UBSEC_ubsec_close(fd);
578
579 return BN_mod_exp(r, a, p, m, ctx);
580 }
581
582 p_UBSEC_ubsec_close(fd);
583
584 r->top = (BN_num_bits(m)+BN_BITS2-1)/BN_BITS2;
585 return 1;
586 }
587
588#ifndef OPENSSL_NO_RSA
589static int ubsec_rsa_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
590 {
591 BN_CTX *ctx;
592 int to_return = 0;
593
594 if((ctx = BN_CTX_new()) == NULL)
595 goto err;
596
597 if(!rsa->p || !rsa->q || !rsa->dmp1 || !rsa->dmq1 || !rsa->iqmp)
598 {
599 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP, UBSEC_R_MISSING_KEY_COMPONENTS);
600 goto err;
601 }
602
603 to_return = ubsec_mod_exp_crt(r0, I, rsa->p, rsa->q, rsa->dmp1,
604 rsa->dmq1, rsa->iqmp, ctx);
605 if (to_return == FAIL_TO_SOFTWARE)
606 {
607 /*
608 * Do in software as hardware failed.
609 */
610 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
611 to_return = (*meth->rsa_mod_exp)(r0, I, rsa);
612 }
613err:
614 if(ctx)
615 BN_CTX_free(ctx);
616 return to_return;
617 }
618#endif
619
620static int ubsec_mod_exp_crt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
621 const BIGNUM *q, const BIGNUM *dp,
622 const BIGNUM *dq, const BIGNUM *qinv, BN_CTX *ctx)
623 {
624 int y_len,
625 m_len,
626 fd;
627
628 m_len = BN_num_bytes(p) + BN_num_bytes(q) + 1;
629 y_len = BN_num_bits(p) + BN_num_bits(q);
630
631 /* Check if hardware can't handle this argument. */
632 if (y_len > max_key_len) {
633 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL);
634 return FAIL_TO_SOFTWARE;
635 }
636
637 if (!bn_wexpand(r, p->top + q->top + 1)) {
638 UBSECerr(UBSEC_F_UBSEC_RSA_MOD_EXP_CRT, UBSEC_R_BN_EXPAND_FAIL);
639 return 0;
640 }
641
642 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
643 fd = 0;
644 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
645 return FAIL_TO_SOFTWARE;
646 }
647
648 if (p_UBSEC_rsa_mod_exp_crt_ioctl(fd,
649 (unsigned char *)a->d, BN_num_bits(a),
650 (unsigned char *)qinv->d, BN_num_bits(qinv),
651 (unsigned char *)dp->d, BN_num_bits(dp),
652 (unsigned char *)p->d, BN_num_bits(p),
653 (unsigned char *)dq->d, BN_num_bits(dq),
654 (unsigned char *)q->d, BN_num_bits(q),
655 (unsigned char *)r->d, &y_len) != 0) {
656 UBSECerr(UBSEC_F_UBSEC_MOD_EXP, UBSEC_R_REQUEST_FAILED);
657 p_UBSEC_ubsec_close(fd);
658 return FAIL_TO_SOFTWARE;
659 }
660
661 p_UBSEC_ubsec_close(fd);
662
663 r->top = (BN_num_bits(p) + BN_num_bits(q) + BN_BITS2 - 1)/BN_BITS2;
664 return 1;
665}
666
667#ifndef OPENSSL_NO_DSA
668#ifdef NOT_USED
669static int ubsec_dsa_mod_exp(DSA *dsa, BIGNUM *rr, BIGNUM *a1,
670 BIGNUM *p1, BIGNUM *a2, BIGNUM *p2, BIGNUM *m,
671 BN_CTX *ctx, BN_MONT_CTX *in_mont)
672 {
673 BIGNUM t;
674 int to_return = 0;
675
676 BN_init(&t);
677 /* let rr = a1 ^ p1 mod m */
678 if (!ubsec_mod_exp(rr,a1,p1,m,ctx)) goto end;
679 /* let t = a2 ^ p2 mod m */
680 if (!ubsec_mod_exp(&t,a2,p2,m,ctx)) goto end;
681 /* let rr = rr * t mod m */
682 if (!BN_mod_mul(rr,rr,&t,m,ctx)) goto end;
683 to_return = 1;
684end:
685 BN_free(&t);
686 return to_return;
687 }
688
689static int ubsec_mod_exp_dsa(DSA *dsa, BIGNUM *r, BIGNUM *a,
690 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
691 BN_MONT_CTX *m_ctx)
692 {
693 return ubsec_mod_exp(r, a, p, m, ctx);
694 }
695#endif
696#endif
697
698/*
699 * This function is aliased to mod_exp (with the mont stuff dropped).
700 */
701static int ubsec_mod_exp_mont(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
702 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx)
703 {
704 int ret = 0;
705
706#ifndef OPENSSL_NO_RSA
707 /* Do in software if the key is too large for the hardware. */
708 if (BN_num_bits(m) > max_key_len)
709 {
710 const RSA_METHOD *meth = RSA_PKCS1_SSLeay();
711 ret = (*meth->bn_mod_exp)(r, a, p, m, ctx, m_ctx);
712 }
713 else
714#endif
715 {
716 ret = ubsec_mod_exp(r, a, p, m, ctx);
717 }
718
719 return ret;
720 }
721
722#ifndef OPENSSL_NO_DH
723/* This function is aliased to mod_exp (with the dh and mont dropped). */
724static int ubsec_mod_exp_dh(const DH *dh, BIGNUM *r, const BIGNUM *a,
725 const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx,
726 BN_MONT_CTX *m_ctx)
727 {
728 return ubsec_mod_exp(r, a, p, m, ctx);
729 }
730#endif
731
732#ifndef OPENSSL_NO_DSA
733static DSA_SIG *ubsec_dsa_do_sign(const unsigned char *dgst, int dlen, DSA *dsa)
734 {
735 DSA_SIG *to_return = NULL;
736 int s_len = 160, r_len = 160, d_len, fd;
737 BIGNUM m, *r=NULL, *s=NULL;
738
739 BN_init(&m);
740
741 s = BN_new();
742 r = BN_new();
743 if ((s == NULL) || (r==NULL))
744 goto err;
745
746 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dlen);
747
748 if(!bn_wexpand(r, (160+BN_BITS2-1)/BN_BITS2) ||
749 (!bn_wexpand(s, (160+BN_BITS2-1)/BN_BITS2))) {
750 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
751 goto err;
752 }
753
754 if (BN_bin2bn(dgst,dlen,&m) == NULL) {
755 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
756 goto err;
757 }
758
759 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
760 const DSA_METHOD *meth;
761 fd = 0;
762 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
763 meth = DSA_OpenSSL();
764 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
765 goto err;
766 }
767
768 if (p_UBSEC_dsa_sign_ioctl(fd, 0, /* compute hash before signing */
769 (unsigned char *)dgst, d_len,
770 NULL, 0, /* compute random value */
771 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
772 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
773 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
774 (unsigned char *)dsa->priv_key->d, BN_num_bits(dsa->priv_key),
775 (unsigned char *)r->d, &r_len,
776 (unsigned char *)s->d, &s_len ) != 0) {
777 const DSA_METHOD *meth;
778
779 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_REQUEST_FAILED);
780 p_UBSEC_ubsec_close(fd);
781 meth = DSA_OpenSSL();
782 to_return = meth->dsa_do_sign(dgst, dlen, dsa);
783
784 goto err;
785 }
786
787 p_UBSEC_ubsec_close(fd);
788
789 r->top = (160+BN_BITS2-1)/BN_BITS2;
790 s->top = (160+BN_BITS2-1)/BN_BITS2;
791
792 to_return = DSA_SIG_new();
793 if(to_return == NULL) {
794 UBSECerr(UBSEC_F_UBSEC_DSA_SIGN, UBSEC_R_BN_EXPAND_FAIL);
795 goto err;
796 }
797
798 to_return->r = r;
799 to_return->s = s;
800
801err:
802 if (!to_return) {
803 if (r) BN_free(r);
804 if (s) BN_free(s);
805 }
806 BN_clear_free(&m);
807 return to_return;
808}
809
810static int ubsec_dsa_verify(const unsigned char *dgst, int dgst_len,
811 DSA_SIG *sig, DSA *dsa)
812 {
813 int v_len, d_len;
814 int to_return = 0;
815 int fd;
816 BIGNUM v;
817
818 BN_init(&v);
819
820 if(!bn_wexpand(&v, dsa->p->top)) {
821 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY ,UBSEC_R_BN_EXPAND_FAIL);
822 goto err;
823 }
824
825 v_len = BN_num_bits(dsa->p);
826
827 d_len = p_UBSEC_ubsec_bytes_to_bits((unsigned char *)dgst, dgst_len);
828
829 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0) {
830 const DSA_METHOD *meth;
831 fd = 0;
832 UBSECerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
833 meth = DSA_OpenSSL();
834 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
835 goto err;
836 }
837
838 if (p_UBSEC_dsa_verify_ioctl(fd, 0, /* compute hash before signing */
839 (unsigned char *)dgst, d_len,
840 (unsigned char *)dsa->p->d, BN_num_bits(dsa->p),
841 (unsigned char *)dsa->q->d, BN_num_bits(dsa->q),
842 (unsigned char *)dsa->g->d, BN_num_bits(dsa->g),
843 (unsigned char *)dsa->pub_key->d, BN_num_bits(dsa->pub_key),
844 (unsigned char *)sig->r->d, BN_num_bits(sig->r),
845 (unsigned char *)sig->s->d, BN_num_bits(sig->s),
846 (unsigned char *)v.d, &v_len) != 0) {
847 const DSA_METHOD *meth;
848 UBSECerr(UBSEC_F_UBSEC_DSA_VERIFY , UBSEC_R_REQUEST_FAILED);
849 p_UBSEC_ubsec_close(fd);
850
851 meth = DSA_OpenSSL();
852 to_return = meth->dsa_do_verify(dgst, dgst_len, sig, dsa);
853
854 goto err;
855 }
856
857 p_UBSEC_ubsec_close(fd);
858
859 to_return = 1;
860err:
861 BN_clear_free(&v);
862 return to_return;
863 }
864#endif
865
866#ifndef OPENSSL_NO_DH
867static int ubsec_dh_compute_key (unsigned char *key,const BIGNUM *pub_key,DH *dh)
868 {
869 int ret = -1,
870 k_len,
871 fd;
872
873 k_len = BN_num_bits(dh->p);
874
875 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
876 {
877 const DH_METHOD *meth;
878 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
879 meth = DH_OpenSSL();
880 ret = meth->compute_key(key, pub_key, dh);
881 goto err;
882 }
883
884 if (p_UBSEC_diffie_hellman_agree_ioctl(fd,
885 (unsigned char *)dh->priv_key->d, BN_num_bits(dh->priv_key),
886 (unsigned char *)pub_key->d, BN_num_bits(pub_key),
887 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
888 key, &k_len) != 0)
889 {
890 /* Hardware's a no go, failover to software */
891 const DH_METHOD *meth;
892 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
893 p_UBSEC_ubsec_close(fd);
894
895 meth = DH_OpenSSL();
896 ret = meth->compute_key(key, pub_key, dh);
897
898 goto err;
899 }
900
901 p_UBSEC_ubsec_close(fd);
902
903 ret = p_UBSEC_ubsec_bits_to_bytes(k_len);
904err:
905 return ret;
906 }
907
908static int ubsec_dh_generate_key (DH *dh)
909 {
910 int ret = 0,
911 random_bits = 0,
912 pub_key_len = 0,
913 priv_key_len = 0,
914 fd;
915 BIGNUM *pub_key = NULL;
916 BIGNUM *priv_key = NULL;
917
918 /*
919 * How many bits should Random x be? dh_key.c
920 * sets the range from 0 to num_bits(modulus) ???
921 */
922
923 if (dh->priv_key == NULL)
924 {
925 priv_key = BN_new();
926 if (priv_key == NULL) goto err;
927 priv_key_len = BN_num_bits(dh->p);
928 bn_wexpand(priv_key, dh->p->top);
929 do
930 if (!BN_rand_range(priv_key, dh->p)) goto err;
931 while (BN_is_zero(priv_key));
932 random_bits = BN_num_bits(priv_key);
933 }
934 else
935 {
936 priv_key = dh->priv_key;
937 }
938
939 if (dh->pub_key == NULL)
940 {
941 pub_key = BN_new();
942 pub_key_len = BN_num_bits(dh->p);
943 bn_wexpand(pub_key, dh->p->top);
944 if(pub_key == NULL) goto err;
945 }
946 else
947 {
948 pub_key = dh->pub_key;
949 }
950
951 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
952 {
953 const DH_METHOD *meth;
954 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
955 meth = DH_OpenSSL();
956 ret = meth->generate_key(dh);
957 goto err;
958 }
959
960 if (p_UBSEC_diffie_hellman_generate_ioctl(fd,
961 (unsigned char *)priv_key->d, &priv_key_len,
962 (unsigned char *)pub_key->d, &pub_key_len,
963 (unsigned char *)dh->g->d, BN_num_bits(dh->g),
964 (unsigned char *)dh->p->d, BN_num_bits(dh->p),
965 0, 0, random_bits) != 0)
966 {
967 /* Hardware's a no go, failover to software */
968 const DH_METHOD *meth;
969
970 ENGINEerr(UBSEC_F_UBSEC_DH_COMPUTE_KEY, UBSEC_R_REQUEST_FAILED);
971 p_UBSEC_ubsec_close(fd);
972
973 meth = DH_OpenSSL();
974 ret = meth->generate_key(dh);
975
976 goto err;
977 }
978
979 p_UBSEC_ubsec_close(fd);
980
981 dh->pub_key = pub_key;
982 dh->pub_key->top = (pub_key_len + BN_BITS2-1) / BN_BITS2;
983 dh->priv_key = priv_key;
984 dh->priv_key->top = (priv_key_len + BN_BITS2-1) / BN_BITS2;
985
986 ret = 1;
987err:
988 return ret;
989 }
990#endif
991
992#ifdef NOT_USED
993static int ubsec_rand_bytes(unsigned char * buf,
994 int num)
995 {
996 int ret = 0,
997 fd;
998
999 if ((fd = p_UBSEC_ubsec_open(UBSEC_KEY_DEVICE_NAME)) <= 0)
1000 {
1001 const RAND_METHOD *meth;
1002 ENGINEerr(UBSEC_F_UBSEC_INIT, UBSEC_R_UNIT_FAILURE);
1003 num = p_UBSEC_ubsec_bits_to_bytes(num);
1004 meth = RAND_SSLeay();
1005 meth->seed(buf, num);
1006 ret = meth->bytes(buf, num);
1007 goto err;
1008 }
1009
1010 num *= 8; /* bytes to bits */
1011
1012 if (p_UBSEC_rng_ioctl(fd,
1013 UBSEC_RNG_DIRECT,
1014 buf,
1015 &num) != 0)
1016 {
1017 /* Hardware's a no go, failover to software */
1018 const RAND_METHOD *meth;
1019
1020 ENGINEerr(UBSEC_F_UBSEC_RNG_BYTES, UBSEC_R_REQUEST_FAILED);
1021 p_UBSEC_ubsec_close(fd);
1022
1023 num = p_UBSEC_ubsec_bits_to_bytes(num);
1024 meth = RAND_SSLeay();
1025 meth->seed(buf, num);
1026 ret = meth->bytes(buf, num);
1027
1028 goto err;
1029 }
1030
1031 p_UBSEC_ubsec_close(fd);
1032
1033 ret = 1;
1034err:
1035 return(ret);
1036 }
1037
1038
1039static int ubsec_rand_status(void)
1040 {
1041 return 0;
1042 }
1043#endif
1044
1045/* This stuff is needed if this ENGINE is being compiled into a self-contained
1046 * shared-library. */
1047#ifdef ENGINE_DYNAMIC_SUPPORT
1048static int bind_fn(ENGINE *e, const char *id)
1049 {
1050 if(id && (strcmp(id, engine_ubsec_id) != 0))
1051 return 0;
1052 if(!bind_helper(e))
1053 return 0;
1054 return 1;
1055 }
1056IMPLEMENT_DYNAMIC_CHECK_FN()
1057IMPLEMENT_DYNAMIC_BIND_FN(bind_fn)
1058#endif /* ENGINE_DYNAMIC_SUPPORT */
1059
1060#endif /* !OPENSSL_NO_HW_UBSEC */
1061#endif /* !OPENSSL_NO_HW */
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.c b/src/lib/libcrypto/engine/hw_ubsec_err.c
new file mode 100644
index 0000000000..d707331fc2
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec_err.c
@@ -0,0 +1,151 @@
1/* hw_ubsec_err.c */
2/* ====================================================================
3 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include "hw_ubsec_err.h"
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67static ERR_STRING_DATA UBSEC_str_functs[]=
68 {
69{ERR_PACK(0,UBSEC_F_UBSEC_CTRL,0), "UBSEC_CTRL"},
70{ERR_PACK(0,UBSEC_F_UBSEC_DH_COMPUTE_KEY,0), "UBSEC_DH_COMPUTE_KEY"},
71{ERR_PACK(0,UBSEC_F_UBSEC_DSA_SIGN,0), "UBSEC_DSA_SIGN"},
72{ERR_PACK(0,UBSEC_F_UBSEC_DSA_VERIFY,0), "UBSEC_DSA_VERIFY"},
73{ERR_PACK(0,UBSEC_F_UBSEC_FINISH,0), "UBSEC_FINISH"},
74{ERR_PACK(0,UBSEC_F_UBSEC_INIT,0), "UBSEC_INIT"},
75{ERR_PACK(0,UBSEC_F_UBSEC_MOD_EXP,0), "UBSEC_MOD_EXP"},
76{ERR_PACK(0,UBSEC_F_UBSEC_RNG_BYTES,0), "UBSEC_RNG_BYTES"},
77{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP,0), "UBSEC_RSA_MOD_EXP"},
78{ERR_PACK(0,UBSEC_F_UBSEC_RSA_MOD_EXP_CRT,0), "UBSEC_RSA_MOD_EXP_CRT"},
79{0,NULL}
80 };
81
82static ERR_STRING_DATA UBSEC_str_reasons[]=
83 {
84{UBSEC_R_ALREADY_LOADED ,"already loaded"},
85{UBSEC_R_BN_EXPAND_FAIL ,"bn expand fail"},
86{UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED ,"ctrl command not implemented"},
87{UBSEC_R_DSO_FAILURE ,"dso failure"},
88{UBSEC_R_MISSING_KEY_COMPONENTS ,"missing key components"},
89{UBSEC_R_NOT_LOADED ,"not loaded"},
90{UBSEC_R_REQUEST_FAILED ,"request failed"},
91{UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL ,"size too large or too small"},
92{UBSEC_R_UNIT_FAILURE ,"unit failure"},
93{0,NULL}
94 };
95
96#endif
97
98#ifdef UBSEC_LIB_NAME
99static ERR_STRING_DATA UBSEC_lib_name[]=
100 {
101{0 ,UBSEC_LIB_NAME},
102{0,NULL}
103 };
104#endif
105
106
107static int UBSEC_lib_error_code=0;
108static int UBSEC_error_init=1;
109
110static void ERR_load_UBSEC_strings(void)
111 {
112 if (UBSEC_lib_error_code == 0)
113 UBSEC_lib_error_code=ERR_get_next_error_library();
114
115 if (UBSEC_error_init)
116 {
117 UBSEC_error_init=0;
118#ifndef OPENSSL_NO_ERR
119 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_functs);
120 ERR_load_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
121#endif
122
123#ifdef UBSEC_LIB_NAME
124 UBSEC_lib_name->error = ERR_PACK(UBSEC_lib_error_code,0,0);
125 ERR_load_strings(0,UBSEC_lib_name);
126#endif
127 }
128 }
129
130static void ERR_unload_UBSEC_strings(void)
131 {
132 if (UBSEC_error_init == 0)
133 {
134#ifndef OPENSSL_NO_ERR
135 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_functs);
136 ERR_unload_strings(UBSEC_lib_error_code,UBSEC_str_reasons);
137#endif
138
139#ifdef UBSEC_LIB_NAME
140 ERR_unload_strings(0,UBSEC_lib_name);
141#endif
142 UBSEC_error_init=1;
143 }
144 }
145
146static void ERR_UBSEC_error(int function, int reason, char *file, int line)
147 {
148 if (UBSEC_lib_error_code == 0)
149 UBSEC_lib_error_code=ERR_get_next_error_library();
150 ERR_PUT_error(UBSEC_lib_error_code,function,reason,file,line);
151 }
diff --git a/src/lib/libcrypto/engine/hw_ubsec_err.h b/src/lib/libcrypto/engine/hw_ubsec_err.h
new file mode 100644
index 0000000000..023d3be771
--- /dev/null
+++ b/src/lib/libcrypto/engine/hw_ubsec_err.h
@@ -0,0 +1,95 @@
1/* ====================================================================
2 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 *
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
14 * distribution.
15 *
16 * 3. All advertising materials mentioning features or use of this
17 * software must display the following acknowledgment:
18 * "This product includes software developed by the OpenSSL Project
19 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
20 *
21 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
22 * endorse or promote products derived from this software without
23 * prior written permission. For written permission, please contact
24 * openssl-core@openssl.org.
25 *
26 * 5. Products derived from this software may not be called "OpenSSL"
27 * nor may "OpenSSL" appear in their names without prior written
28 * permission of the OpenSSL Project.
29 *
30 * 6. Redistributions of any form whatsoever must retain the following
31 * acknowledgment:
32 * "This product includes software developed by the OpenSSL Project
33 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
34 *
35 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
36 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
37 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
38 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
39 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
41 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
44 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
45 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
46 * OF THE POSSIBILITY OF SUCH DAMAGE.
47 * ====================================================================
48 *
49 * 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_UBSEC_ERR_H
56#define HEADER_UBSEC_ERR_H
57
58/* BEGIN ERROR CODES */
59/* The following lines are auto generated by the script mkerr.pl. Any changes
60 * made after this point may be overwritten when the script is next run.
61 */
62static void ERR_load_UBSEC_strings(void);
63static void ERR_unload_UBSEC_strings(void);
64static void ERR_UBSEC_error(int function, int reason, char *file, int line);
65#define UBSECerr(f,r) ERR_UBSEC_error((f),(r),__FILE__,__LINE__)
66
67/* Error codes for the UBSEC functions. */
68
69/* Function codes. */
70#define UBSEC_F_UBSEC_CTRL 100
71#define UBSEC_F_UBSEC_DH_COMPUTE_KEY 101
72#define UBSEC_F_UBSEC_DSA_SIGN 102
73#define UBSEC_F_UBSEC_DSA_VERIFY 103
74#define UBSEC_F_UBSEC_FINISH 104
75#define UBSEC_F_UBSEC_INIT 105
76#define UBSEC_F_UBSEC_MOD_EXP 106
77#define UBSEC_F_UBSEC_RNG_BYTES 107
78#define UBSEC_F_UBSEC_RSA_MOD_EXP 108
79#define UBSEC_F_UBSEC_RSA_MOD_EXP_CRT 109
80
81/* Reason codes. */
82#define UBSEC_R_ALREADY_LOADED 100
83#define UBSEC_R_BN_EXPAND_FAIL 101
84#define UBSEC_R_CTRL_COMMAND_NOT_IMPLEMENTED 102
85#define UBSEC_R_DSO_FAILURE 103
86#define UBSEC_R_MISSING_KEY_COMPONENTS 104
87#define UBSEC_R_NOT_LOADED 105
88#define UBSEC_R_REQUEST_FAILED 106
89#define UBSEC_R_SIZE_TOO_LARGE_OR_TOO_SMALL 107
90#define UBSEC_R_UNIT_FAILURE 108
91
92#ifdef __cplusplus
93}
94#endif
95#endif
diff --git a/src/lib/libcrypto/engine/tb_cipher.c b/src/lib/libcrypto/engine/tb_cipher.c
index 177fc1fb73..50b3cec1fa 100644
--- a/src/lib/libcrypto/engine/tb_cipher.c
+++ b/src/lib/libcrypto/engine/tb_cipher.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that 59/* If this symbol is defined then ENGINE_get_cipher_engine(), the function that
diff --git a/src/lib/libcrypto/engine/tb_dh.c b/src/lib/libcrypto/engine/tb_dh.c
index 6e9d428761..e290e1702b 100644
--- a/src/lib/libcrypto/engine/tb_dh.c
+++ b/src/lib/libcrypto/engine/tb_dh.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_default_DH(), the function that is 59/* If this symbol is defined then ENGINE_get_default_DH(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_digest.c b/src/lib/libcrypto/engine/tb_digest.c
index d3f4bb2747..e82d2a17c9 100644
--- a/src/lib/libcrypto/engine/tb_digest.c
+++ b/src/lib/libcrypto/engine/tb_digest.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_digest_engine(), the function that 59/* If this symbol is defined then ENGINE_get_digest_engine(), the function that
diff --git a/src/lib/libcrypto/engine/tb_dsa.c b/src/lib/libcrypto/engine/tb_dsa.c
index e4674f5f07..7efe181927 100644
--- a/src/lib/libcrypto/engine/tb_dsa.c
+++ b/src/lib/libcrypto/engine/tb_dsa.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is 59/* If this symbol is defined then ENGINE_get_default_DSA(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_rand.c b/src/lib/libcrypto/engine/tb_rand.c
index f36f67c0f6..69b67111bc 100644
--- a/src/lib/libcrypto/engine/tb_rand.c
+++ b/src/lib/libcrypto/engine/tb_rand.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is 59/* If this symbol is defined then ENGINE_get_default_RAND(), the function that is
diff --git a/src/lib/libcrypto/engine/tb_rsa.c b/src/lib/libcrypto/engine/tb_rsa.c
index fbc707fd26..fee4867f52 100644
--- a/src/lib/libcrypto/engine/tb_rsa.c
+++ b/src/lib/libcrypto/engine/tb_rsa.c
@@ -52,6 +52,8 @@
52 * 52 *
53 */ 53 */
54 54
55#include <openssl/evp.h>
56#include <openssl/engine.h>
55#include "eng_int.h" 57#include "eng_int.h"
56 58
57/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is 59/* If this symbol is defined then ENGINE_get_default_RSA(), the function that is
diff --git a/src/lib/libcrypto/engine/vendor_defns/aep.h b/src/lib/libcrypto/engine/vendor_defns/aep.h
new file mode 100644
index 0000000000..2b2792d2d6
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/aep.h
@@ -0,0 +1,178 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities, and rnd number generation of the AEP card.
3 *
4 */
5
6/*
7 *
8 * Some AEP defines
9 *
10 */
11
12/*Successful return value*/
13#define AEP_R_OK 0x00000000
14
15/*Miscelleanous unsuccessful return value*/
16#define AEP_R_GENERAL_ERROR 0x10000001
17
18/*Insufficient host memory*/
19#define AEP_R_HOST_MEMORY 0x10000002
20
21#define AEP_R_FUNCTION_FAILED 0x10000006
22
23/*Invalid arguments in function call*/
24#define AEP_R_ARGUMENTS_BAD 0x10020000
25
26#define AEP_R_NO_TARGET_RESOURCES 0x10030000
27
28/*Error occuring on socket operation*/
29#define AEP_R_SOCKERROR 0x10000010
30
31/*Socket has been closed from the other end*/
32#define AEP_R_SOCKEOF 0x10000011
33
34/*Invalid handles*/
35#define AEP_R_CONNECTION_HANDLE_INVALID 0x100000B3
36
37#define AEP_R_TRANSACTION_HANDLE_INVALID 0x10040000
38
39/*Transaction has not yet returned from accelerator*/
40#define AEP_R_TRANSACTION_NOT_READY 0x00010000
41
42/*There is already a thread waiting on this transaction*/
43#define AEP_R_TRANSACTION_CLAIMED 0x10050000
44
45/*The transaction timed out*/
46#define AEP_R_TIMED_OUT 0x10060000
47
48#define AEP_R_FXN_NOT_IMPLEMENTED 0x10070000
49
50#define AEP_R_TARGET_ERROR 0x10080000
51
52/*Error in the AEP daemon process*/
53#define AEP_R_DAEMON_ERROR 0x10090000
54
55/*Invalid ctx id*/
56#define AEP_R_INVALID_CTX_ID 0x10009000
57
58#define AEP_R_NO_KEY_MANAGER 0x1000a000
59
60/*Error obtaining a mutex*/
61#define AEP_R_MUTEX_BAD 0x000001A0
62
63/*Fxn call before AEP_Initialise ot after AEP_Finialise*/
64#define AEP_R_AEPAPI_NOT_INITIALIZED 0x10000190
65
66/*AEP_Initialise has already been called*/
67#define AEP_R_AEPAPI_ALREADY_INITIALIZED 0x10000191
68
69/*Maximum number of connections to daemon reached*/
70#define AEP_R_NO_MORE_CONNECTION_HNDLS 0x10000200
71
72/*
73 *
74 * Some AEP Type definitions
75 *
76 */
77
78/* an unsigned 8-bit value */
79typedef unsigned char AEP_U8;
80
81/* an unsigned 8-bit character */
82typedef char AEP_CHAR;
83
84/* a BYTE-sized Boolean flag */
85typedef AEP_U8 AEP_BBOOL;
86
87/*Unsigned value, at least 16 bits long*/
88typedef unsigned short AEP_U16;
89
90/* an unsigned value, at least 32 bits long */
91#ifdef SIXTY_FOUR_BIT_LONG
92typedef unsigned int AEP_U32;
93#else
94typedef unsigned long AEP_U32;
95#endif
96
97#ifdef SIXTY_FOUR_BIT_LONG
98typedef unsigned long AEP_U64;
99#else
100typedef struct { unsigned long l1, l2; } AEP_U64;
101#endif
102
103/* at least 32 bits; each bit is a Boolean flag */
104typedef AEP_U32 AEP_FLAGS;
105
106typedef AEP_U8 *AEP_U8_PTR;
107typedef AEP_CHAR *AEP_CHAR_PTR;
108typedef AEP_U32 *AEP_U32_PTR;
109typedef AEP_U64 *AEP_U64_PTR;
110typedef void *AEP_VOID_PTR;
111
112/* Pointer to a AEP_VOID_PTR-- i.e., pointer to pointer to void */
113typedef AEP_VOID_PTR *AEP_VOID_PTR_PTR;
114
115/*Used to identify an AEP connection handle*/
116typedef AEP_U32 AEP_CONNECTION_HNDL;
117
118/*Pointer to an AEP connection handle*/
119typedef AEP_CONNECTION_HNDL *AEP_CONNECTION_HNDL_PTR;
120
121/*Used by an application (in conjunction with the apps process id) to
122identify an individual transaction*/
123typedef AEP_U32 AEP_TRANSACTION_ID;
124
125/*Pointer to an applications transaction identifier*/
126typedef AEP_TRANSACTION_ID *AEP_TRANSACTION_ID_PTR;
127
128/*Return value type*/
129typedef AEP_U32 AEP_RV;
130
131#define MAX_PROCESS_CONNECTIONS 256
132
133#define RAND_BLK_SIZE 1024
134
135typedef enum{
136 NotConnected= 0,
137 Connected= 1,
138 InUse= 2
139} AEP_CONNECTION_STATE;
140
141
142typedef struct AEP_CONNECTION_ENTRY{
143 AEP_CONNECTION_STATE conn_state;
144 AEP_CONNECTION_HNDL conn_hndl;
145} AEP_CONNECTION_ENTRY;
146
147
148typedef AEP_RV t_AEP_OpenConnection(AEP_CONNECTION_HNDL_PTR phConnection);
149typedef AEP_RV t_AEP_CloseConnection(AEP_CONNECTION_HNDL hConnection);
150
151typedef AEP_RV t_AEP_ModExp(AEP_CONNECTION_HNDL hConnection,
152 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
153 AEP_VOID_PTR pN,
154 AEP_VOID_PTR pResult,
155 AEP_TRANSACTION_ID* pidTransID);
156
157typedef AEP_RV t_AEP_ModExpCrt(AEP_CONNECTION_HNDL hConnection,
158 AEP_VOID_PTR pA, AEP_VOID_PTR pP,
159 AEP_VOID_PTR pQ,
160 AEP_VOID_PTR pDmp1, AEP_VOID_PTR pDmq1,
161 AEP_VOID_PTR pIqmp,
162 AEP_VOID_PTR pResult,
163 AEP_TRANSACTION_ID* pidTransID);
164
165#ifdef AEPRAND
166typedef AEP_RV t_AEP_GenRandom(AEP_CONNECTION_HNDL hConnection,
167 AEP_U32 Len,
168 AEP_U32 Type,
169 AEP_VOID_PTR pResult,
170 AEP_TRANSACTION_ID* pidTransID);
171#endif
172
173typedef AEP_RV t_AEP_Initialize(AEP_VOID_PTR pInitArgs);
174typedef AEP_RV t_AEP_Finalize();
175typedef AEP_RV t_AEP_SetBNCallBacks(AEP_RV (*GetBigNumSizeFunc)(),
176 AEP_RV (*MakeAEPBigNumFunc)(),
177 AEP_RV (*ConverAEPBigNumFunc)());
178
diff --git a/src/lib/libcrypto/engine/vendor_defns/atalla.h b/src/lib/libcrypto/engine/vendor_defns/atalla.h
new file mode 100644
index 0000000000..149970d441
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/atalla.h
@@ -0,0 +1,48 @@
1/* This header declares the necessary definitions for using the exponentiation
2 * acceleration capabilities of Atalla cards. The only cryptographic operation
3 * is performed by "ASI_RSAPrivateKeyOpFn" and this takes a structure that
4 * defines an "RSA private key". However, it is really only performing a
5 * regular mod_exp using the supplied modulus and exponent - no CRT form is
6 * being used. Hence, it is a generic mod_exp function in disguise, and we use
7 * it as such.
8 *
9 * Thanks to the people at Atalla for letting me know these definitions are
10 * fine and that they can be reproduced here.
11 *
12 * Geoff.
13 */
14
15typedef struct ItemStr
16 {
17 unsigned char *data;
18 int len;
19 } Item;
20
21typedef struct RSAPrivateKeyStr
22 {
23 void *reserved;
24 Item version;
25 Item modulus;
26 Item publicExponent;
27 Item privateExponent;
28 Item prime[2];
29 Item exponent[2];
30 Item coefficient;
31 } RSAPrivateKey;
32
33/* Predeclare the function pointer types that we dynamically load from the DSO.
34 * These use the same names and form that Ben's original support code had (in
35 * crypto/bn/bn_exp.c) unless of course I've inadvertently changed the style
36 * somewhere along the way!
37 */
38
39typedef int tfnASI_GetPerformanceStatistics(int reset_flag,
40 unsigned int *ret_buf);
41
42typedef int tfnASI_GetHardwareConfig(long card_num, unsigned int *ret_buf);
43
44typedef int tfnASI_RSAPrivateKeyOpFn(RSAPrivateKey * rsaKey,
45 unsigned char *output,
46 unsigned char *input,
47 unsigned int modulus_len);
48
diff --git a/src/lib/libcrypto/engine/vendor_defns/cswift.h b/src/lib/libcrypto/engine/vendor_defns/cswift.h
new file mode 100644
index 0000000000..60079326bb
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/cswift.h
@@ -0,0 +1,234 @@
1/* Attribution notice: Rainbow have generously allowed me to reproduce
2 * the necessary definitions here from their API. This means the support
3 * can build independently of whether application builders have the
4 * API or hardware. This will allow developers to easily produce software
5 * that has latent hardware support for any users that have accelertors
6 * installed, without the developers themselves needing anything extra.
7 *
8 * I have only clipped the parts from the CryptoSwift header files that
9 * are (or seem) relevant to the CryptoSwift support code. This is
10 * simply to keep the file sizes reasonable.
11 * [Geoff]
12 */
13
14
15/* NB: These type widths do *not* seem right in general, in particular
16 * they're not terribly friendly to 64-bit architectures (unsigned long)
17 * will be 64-bit on IA-64 for a start. I'm leaving these alone as they
18 * agree with Rainbow's API and this will only be called into question
19 * on platforms with Rainbow support anyway! ;-) */
20
21#ifdef __cplusplus
22extern "C" {
23#endif /* __cplusplus */
24
25typedef long SW_STATUS; /* status */
26typedef unsigned char SW_BYTE; /* 8 bit byte */
27typedef unsigned short SW_U16; /* 16 bit number */
28#if defined(_IRIX)
29#include <sgidefs.h>
30typedef __uint32_t SW_U32;
31#else
32typedef unsigned long SW_U32; /* 32 bit integer */
33#endif
34
35#if defined(OPENSSL_SYS_WIN32)
36 typedef struct _SW_U64 {
37 SW_U32 low32;
38 SW_U32 high32;
39 } SW_U64; /* 64 bit integer */
40#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
41 typedef longlong SW_U64
42#else /* Unix variants */
43 typedef struct _SW_U64 {
44 SW_U32 low32;
45 SW_U32 high32;
46 } SW_U64; /* 64 bit integer */
47#endif
48
49/* status codes */
50#define SW_OK (0L)
51#define SW_ERR_BASE (-10000L)
52#define SW_ERR_NO_CARD (SW_ERR_BASE-1) /* The Card is not present */
53#define SW_ERR_CARD_NOT_READY (SW_ERR_BASE-2) /* The card has not powered */
54 /* up yet */
55#define SW_ERR_TIME_OUT (SW_ERR_BASE-3) /* Execution of a command */
56 /* time out */
57#define SW_ERR_NO_EXECUTE (SW_ERR_BASE-4) /* The Card failed to */
58 /* execute the command */
59#define SW_ERR_INPUT_NULL_PTR (SW_ERR_BASE-5) /* a required pointer is */
60 /* NULL */
61#define SW_ERR_INPUT_SIZE (SW_ERR_BASE-6) /* size is invalid, too */
62 /* small, too large. */
63#define SW_ERR_INVALID_HANDLE (SW_ERR_BASE-7) /* Invalid SW_ACC_CONTEXT */
64 /* handle */
65#define SW_ERR_PENDING (SW_ERR_BASE-8) /* A request is already out- */
66 /* standing at this */
67 /* context handle */
68#define SW_ERR_AVAILABLE (SW_ERR_BASE-9) /* A result is available. */
69#define SW_ERR_NO_PENDING (SW_ERR_BASE-10)/* No request is pending. */
70#define SW_ERR_NO_MEMORY (SW_ERR_BASE-11)/* Not enough memory */
71#define SW_ERR_BAD_ALGORITHM (SW_ERR_BASE-12)/* Invalid algorithm type */
72 /* in SW_PARAM structure */
73#define SW_ERR_MISSING_KEY (SW_ERR_BASE-13)/* No key is associated with */
74 /* context. */
75 /* swAttachKeyParam() is */
76 /* not called. */
77#define SW_ERR_KEY_CMD_MISMATCH \
78 (SW_ERR_BASE-14)/* Cannot perform requested */
79 /* SW_COMMAND_CODE since */
80 /* key attached via */
81 /* swAttachKeyParam() */
82 /* cannot be used for this*/
83 /* SW_COMMAND_CODE. */
84#define SW_ERR_NOT_IMPLEMENTED \
85 (SW_ERR_BASE-15)/* Not implemented */
86#define SW_ERR_BAD_COMMAND (SW_ERR_BASE-16)/* Bad command code */
87#define SW_ERR_BAD_ITEM_SIZE (SW_ERR_BASE-17)/* too small or too large in */
88 /* the "initems" or */
89 /* "outitems". */
90#define SW_ERR_BAD_ACCNUM (SW_ERR_BASE-18)/* Bad accelerator number */
91#define SW_ERR_SELFTEST_FAIL (SW_ERR_BASE-19)/* At least one of the self */
92 /* test fail, look at the */
93 /* selfTestBitmap in */
94 /* SW_ACCELERATOR_INFO for*/
95 /* details. */
96#define SW_ERR_MISALIGN (SW_ERR_BASE-20)/* Certain alogrithms require*/
97 /* key materials aligned */
98 /* in certain order, e.g. */
99 /* 128 bit for CRT */
100#define SW_ERR_OUTPUT_NULL_PTR \
101 (SW_ERR_BASE-21)/* a required pointer is */
102 /* NULL */
103#define SW_ERR_OUTPUT_SIZE \
104 (SW_ERR_BASE-22)/* size is invalid, too */
105 /* small, too large. */
106#define SW_ERR_FIRMWARE_CHECKSUM \
107 (SW_ERR_BASE-23)/* firmware checksum mismatch*/
108 /* download failed. */
109#define SW_ERR_UNKNOWN_FIRMWARE \
110 (SW_ERR_BASE-24)/* unknown firmware error */
111#define SW_ERR_INTERRUPT (SW_ERR_BASE-25)/* request is abort when */
112 /* it's waiting to be */
113 /* completed. */
114#define SW_ERR_NVWRITE_FAIL (SW_ERR_BASE-26)/* error in writing to Non- */
115 /* volatile memory */
116#define SW_ERR_NVWRITE_RANGE (SW_ERR_BASE-27)/* out of range error in */
117 /* writing to NV memory */
118#define SW_ERR_RNG_ERROR (SW_ERR_BASE-28)/* Random Number Generation */
119 /* failure */
120#define SW_ERR_DSS_FAILURE (SW_ERR_BASE-29)/* DSS Sign or Verify failure*/
121#define SW_ERR_MODEXP_FAILURE (SW_ERR_BASE-30)/* Failure in various math */
122 /* calculations */
123#define SW_ERR_ONBOARD_MEMORY (SW_ERR_BASE-31)/* Error in accessing on - */
124 /* board memory */
125#define SW_ERR_FIRMWARE_VERSION \
126 (SW_ERR_BASE-32)/* Wrong version in firmware */
127 /* update */
128#define SW_ERR_ZERO_WORKING_ACCELERATOR \
129 (SW_ERR_BASE-44)/* All accelerators are bad */
130
131
132 /* algorithm type */
133#define SW_ALG_CRT 1
134#define SW_ALG_EXP 2
135#define SW_ALG_DSA 3
136#define SW_ALG_NVDATA 4
137
138 /* command code */
139#define SW_CMD_MODEXP_CRT 1 /* perform Modular Exponentiation using */
140 /* Chinese Remainder Theorem (CRT) */
141#define SW_CMD_MODEXP 2 /* perform Modular Exponentiation */
142#define SW_CMD_DSS_SIGN 3 /* perform DSS sign */
143#define SW_CMD_DSS_VERIFY 4 /* perform DSS verify */
144#define SW_CMD_RAND 5 /* perform random number generation */
145#define SW_CMD_NVREAD 6 /* perform read to nonvolatile RAM */
146#define SW_CMD_NVWRITE 7 /* perform write to nonvolatile RAM */
147
148typedef SW_U32 SW_ALGTYPE; /* alogrithm type */
149typedef SW_U32 SW_STATE; /* state */
150typedef SW_U32 SW_COMMAND_CODE; /* command code */
151typedef SW_U32 SW_COMMAND_BITMAP[4]; /* bitmap */
152
153typedef struct _SW_LARGENUMBER {
154 SW_U32 nbytes; /* number of bytes in the buffer "value" */
155 SW_BYTE* value; /* the large integer as a string of */
156 /* bytes in network (big endian) order */
157} SW_LARGENUMBER;
158
159#if defined(OPENSSL_SYS_WIN32)
160 #include <windows.h>
161 typedef HANDLE SW_OSHANDLE; /* handle to kernel object */
162 #define SW_OS_INVALID_HANDLE INVALID_HANDLE_VALUE
163 #define SW_CALLCONV _stdcall
164#elif defined(OPENSSL_SYS_MACINTOSH_CLASSIC)
165 /* async callback mechanisms */
166 /* swiftCallbackLevel */
167 #define SW_MAC_CALLBACK_LEVEL_NO 0
168 #define SW_MAC_CALLBACK_LEVEL_HARDWARE 1 /* from the hardware ISR */
169 #define SW_MAC_CALLBACK_LEVEL_SECONDARY 2 /* as secondary ISR */
170 typedef int SW_MAC_CALLBACK_LEVEL;
171 typedef int SW_OSHANDLE;
172 #define SW_OS_INVALID_HANDLE (-1)
173 #define SW_CALLCONV
174#else /* Unix variants */
175 typedef int SW_OSHANDLE; /* handle to driver */
176 #define SW_OS_INVALID_HANDLE (-1)
177 #define SW_CALLCONV
178#endif
179
180typedef struct _SW_CRT {
181 SW_LARGENUMBER p; /* prime number p */
182 SW_LARGENUMBER q; /* prime number q */
183 SW_LARGENUMBER dmp1; /* exponent1 */
184 SW_LARGENUMBER dmq1; /* exponent2 */
185 SW_LARGENUMBER iqmp; /* CRT coefficient */
186} SW_CRT;
187
188typedef struct _SW_EXP {
189 SW_LARGENUMBER modulus; /* modulus */
190 SW_LARGENUMBER exponent;/* exponent */
191} SW_EXP;
192
193typedef struct _SW_DSA {
194 SW_LARGENUMBER p; /* */
195 SW_LARGENUMBER q; /* */
196 SW_LARGENUMBER g; /* */
197 SW_LARGENUMBER key; /* private/public key */
198} SW_DSA;
199
200typedef struct _SW_NVDATA {
201 SW_U32 accnum; /* accelerator board number */
202 SW_U32 offset; /* offset in byte */
203} SW_NVDATA;
204
205typedef struct _SW_PARAM {
206 SW_ALGTYPE type; /* type of the alogrithm */
207 union {
208 SW_CRT crt;
209 SW_EXP exp;
210 SW_DSA dsa;
211 SW_NVDATA nvdata;
212 } up;
213} SW_PARAM;
214
215typedef SW_U32 SW_CONTEXT_HANDLE; /* opaque context handle */
216
217
218/* Now the OpenSSL bits, these function types are the for the function
219 * pointers that will bound into the Rainbow shared libraries. */
220typedef SW_STATUS SW_CALLCONV t_swAcquireAccContext(SW_CONTEXT_HANDLE *hac);
221typedef SW_STATUS SW_CALLCONV t_swAttachKeyParam(SW_CONTEXT_HANDLE hac,
222 SW_PARAM *key_params);
223typedef SW_STATUS SW_CALLCONV t_swSimpleRequest(SW_CONTEXT_HANDLE hac,
224 SW_COMMAND_CODE cmd,
225 SW_LARGENUMBER pin[],
226 SW_U32 pin_count,
227 SW_LARGENUMBER pout[],
228 SW_U32 pout_count);
229typedef SW_STATUS SW_CALLCONV t_swReleaseAccContext(SW_CONTEXT_HANDLE hac);
230
231#ifdef __cplusplus
232}
233#endif /* __cplusplus */
234
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h
new file mode 100644
index 0000000000..296636e81a
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/hw_4758_cca.h
@@ -0,0 +1,149 @@
1/**********************************************************************/
2/* */
3/* Prototypes of the CCA verbs used by the 4758 CCA openssl driver */
4/* */
5/* Maurice Gittens <maurice@gittens.nl> */
6/* */
7/**********************************************************************/
8
9#ifndef __HW_4758_CCA__
10#define __HW_4758_CCA__
11
12/*
13 * Only WIN32 support for now
14 */
15#if defined(WIN32)
16
17 #define CCA_LIB_NAME "CSUNSAPI"
18
19 #define CSNDPKX "CSNDPKX_32"
20 #define CSNDKRR "CSNDKRR_32"
21 #define CSNDPKE "CSNDPKE_32"
22 #define CSNDPKD "CSNDPKD_32"
23 #define CSNDDSV "CSNDDSV_32"
24 #define CSNDDSG "CSNDDSG_32"
25 #define CSNBRNG "CSNBRNG_32"
26
27 #define SECURITYAPI __stdcall
28#else
29 /* Fixme!!
30 Find out the values of these constants for other platforms.
31 */
32 #define CCA_LIB_NAME "CSUNSAPI"
33
34 #define CSNDPKX "CSNDPKX"
35 #define CSNDKRR "CSNDKRR"
36 #define CSNDPKE "CSNDPKE"
37 #define CSNDPKD "CSNDPKD"
38 #define CSNDDSV "CSNDDSV"
39 #define CSNDDSG "CSNDDSG"
40 #define CSNBRNG "CSNBRNG"
41
42 #define SECURITYAPI
43#endif
44
45/*
46 * security API prototypes
47 */
48
49/* PKA Key Record Read */
50typedef void (SECURITYAPI *F_KEYRECORDREAD)
51 (long * return_code,
52 long * reason_code,
53 long * exit_data_length,
54 unsigned char * exit_data,
55 long * rule_array_count,
56 unsigned char * rule_array,
57 unsigned char * key_label,
58 long * key_token_length,
59 unsigned char * key_token);
60
61/* Random Number Generate */
62typedef void (SECURITYAPI *F_RANDOMNUMBERGENERATE)
63 (long * return_code,
64 long * reason_code,
65 long * exit_data_length,
66 unsigned char * exit_data,
67 unsigned char * form,
68 unsigned char * random_number);
69
70/* Digital Signature Generate */
71typedef void (SECURITYAPI *F_DIGITALSIGNATUREGENERATE)
72 (long * return_code,
73 long * reason_code,
74 long * exit_data_length,
75 unsigned char * exit_data,
76 long * rule_array_count,
77 unsigned char * rule_array,
78 long * PKA_private_key_id_length,
79 unsigned char * PKA_private_key_id,
80 long * hash_length,
81 unsigned char * hash,
82 long * signature_field_length,
83 long * signature_bit_length,
84 unsigned char * signature_field);
85
86/* Digital Signature Verify */
87typedef void (SECURITYAPI *F_DIGITALSIGNATUREVERIFY)(
88 long * return_code,
89 long * reason_code,
90 long * exit_data_length,
91 unsigned char * exit_data,
92 long * rule_array_count,
93 unsigned char * rule_array,
94 long * PKA_public_key_id_length,
95 unsigned char * PKA_public_key_id,
96 long * hash_length,
97 unsigned char * hash,
98 long * signature_field_length,
99 unsigned char * signature_field);
100
101/* PKA Public Key Extract */
102typedef void (SECURITYAPI *F_PUBLICKEYEXTRACT)(
103 long * return_code,
104 long * reason_code,
105 long * exit_data_length,
106 unsigned char * exit_data,
107 long * rule_array_count,
108 unsigned char * rule_array,
109 long * source_key_identifier_length,
110 unsigned char * source_key_identifier,
111 long * target_key_token_length,
112 unsigned char * target_key_token);
113
114/* PKA Encrypt */
115typedef void (SECURITYAPI *F_PKAENCRYPT)
116 (long * return_code,
117 long * reason_code,
118 long * exit_data_length,
119 unsigned char * exit_data,
120 long * rule_array_count,
121 unsigned char * rule_array,
122 long * key_value_length,
123 unsigned char * key_value,
124 long * data_struct_length,
125 unsigned char * data_struct,
126 long * RSA_public_key_length,
127 unsigned char * RSA_public_key,
128 long * RSA_encipher_length,
129 unsigned char * RSA_encipher );
130
131/* PKA Decrypt */
132typedef void (SECURITYAPI *F_PKADECRYPT)
133 (long * return_code,
134 long * reason_code,
135 long * exit_data_length,
136 unsigned char * exit_data,
137 long * rule_array_count,
138 unsigned char * rule_array,
139 long * enciphered_key_length,
140 unsigned char * enciphered_key,
141 long * data_struct_length,
142 unsigned char * data_struct,
143 long * RSA_private_key_length,
144 unsigned char * RSA_private_key,
145 long * key_value_length,
146 unsigned char * key_value );
147
148
149#endif
diff --git a/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h b/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h
new file mode 100644
index 0000000000..b6619d40f2
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/hw_ubsec.h
@@ -0,0 +1,100 @@
1/******************************************************************************
2 *
3 * Copyright 2000
4 * Broadcom Corporation
5 * 16215 Alton Parkway
6 * PO Box 57013
7 * Irvine CA 92619-7013
8 *
9 *****************************************************************************/
10/*
11 * Broadcom Corporation uBSec SDK
12 */
13/*
14 * Character device header file.
15 */
16/*
17 * Revision History:
18 *
19 * October 2000 JTT Created.
20 */
21
22#define MAX_PUBLIC_KEY_BITS (1024)
23#define MAX_PUBLIC_KEY_BYTES (1024/8)
24#define SHA_BIT_SIZE (160)
25#define MAX_CRYPTO_KEY_LENGTH 24
26#define MAX_MAC_KEY_LENGTH 64
27#define UBSEC_CRYPTO_DEVICE_NAME ((unsigned char *)"/dev/ubscrypt")
28#define UBSEC_KEY_DEVICE_NAME ((unsigned char *)"/dev/ubskey")
29
30/* Math command types. */
31#define UBSEC_MATH_MODADD 0x0001
32#define UBSEC_MATH_MODSUB 0x0002
33#define UBSEC_MATH_MODMUL 0x0004
34#define UBSEC_MATH_MODEXP 0x0008
35#define UBSEC_MATH_MODREM 0x0010
36#define UBSEC_MATH_MODINV 0x0020
37
38typedef long ubsec_MathCommand_t;
39typedef long ubsec_RNGCommand_t;
40
41typedef struct ubsec_crypto_context_s {
42 unsigned int flags;
43 unsigned char crypto[MAX_CRYPTO_KEY_LENGTH];
44 unsigned char auth[MAX_MAC_KEY_LENGTH];
45} ubsec_crypto_context_t, *ubsec_crypto_context_p;
46
47/*
48 * Predeclare the function pointer types that we dynamically load from the DSO.
49 */
50
51typedef int t_UBSEC_ubsec_bytes_to_bits(unsigned char *n, int bytes);
52
53typedef int t_UBSEC_ubsec_bits_to_bytes(int bits);
54
55typedef int t_UBSEC_ubsec_open(unsigned char *device);
56
57typedef int t_UBSEC_ubsec_close(int fd);
58
59typedef int t_UBSEC_diffie_hellman_generate_ioctl (int fd,
60 unsigned char *x, int *x_len, unsigned char *y, int *y_len,
61 unsigned char *g, int g_len, unsigned char *m, int m_len,
62 unsigned char *userX, int userX_len, int random_bits);
63
64typedef int t_UBSEC_diffie_hellman_agree_ioctl (int fd,
65 unsigned char *x, int x_len, unsigned char *y, int y_len,
66 unsigned char *m, int m_len, unsigned char *k, int *k_len);
67
68typedef int t_UBSEC_rsa_mod_exp_ioctl (int fd,
69 unsigned char *x, int x_len, unsigned char *m, int m_len,
70 unsigned char *e, int e_len, unsigned char *y, int *y_len);
71
72typedef int t_UBSEC_rsa_mod_exp_crt_ioctl (int fd,
73 unsigned char *x, int x_len, unsigned char *qinv, int qinv_len,
74 unsigned char *edq, int edq_len, unsigned char *q, int q_len,
75 unsigned char *edp, int edp_len, unsigned char *p, int p_len,
76 unsigned char *y, int *y_len);
77
78typedef int t_UBSEC_dsa_sign_ioctl (int fd,
79 int hash, unsigned char *data, int data_len,
80 unsigned char *rndom, int random_len,
81 unsigned char *p, int p_len, unsigned char *q, int q_len,
82 unsigned char *g, int g_len, unsigned char *key, int key_len,
83 unsigned char *r, int *r_len, unsigned char *s, int *s_len);
84
85typedef int t_UBSEC_dsa_verify_ioctl (int fd,
86 int hash, unsigned char *data, int data_len,
87 unsigned char *p, int p_len, unsigned char *q, int q_len,
88 unsigned char *g, int g_len, unsigned char *key, int key_len,
89 unsigned char *r, int r_len, unsigned char *s, int s_len,
90 unsigned char *v, int *v_len);
91
92typedef int t_UBSEC_math_accelerate_ioctl(int fd, ubsec_MathCommand_t command,
93 unsigned char *ModN, int *ModN_len, unsigned char *ExpE, int *ExpE_len,
94 unsigned char *ParamA, int *ParamA_len, unsigned char *ParamB, int *ParamB_len,
95 unsigned char *Result, int *Result_len);
96
97typedef int t_UBSEC_rng_ioctl(int fd, ubsec_RNGCommand_t command,
98 unsigned char *Result, int *Result_len);
99
100typedef int t_UBSEC_max_key_len_ioctl(int fd, int *max_key_len);
diff --git a/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h b/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h
new file mode 100644
index 0000000000..aaa4d4575e
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/hwcryptohook.h
@@ -0,0 +1,486 @@
1/*
2 * ModExp / RSA (with/without KM) plugin API
3 *
4 * The application will load a dynamic library which
5 * exports entrypoint(s) defined in this file.
6 *
7 * This set of entrypoints provides only a multithreaded,
8 * synchronous-within-each-thread, facility.
9 *
10 *
11 * This file is Copyright 1998-2000 nCipher Corporation Limited.
12 *
13 * Redistribution and use in source and binary forms, with opr without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 *
17 * 1. Redistributions of source code must retain the copyright notice,
18 * this list of conditions, and the following disclaimer.
19 *
20 * 2. Redistributions in binary form must reproduce the above
21 * copyright notice, this list of conditions, and the following
22 * disclaimer, in the documentation and/or other materials provided
23 * with the distribution
24 *
25 * IN NO EVENT SHALL NCIPHER CORPORATION LIMITED (`NCIPHER') AND/OR
26 * ANY OTHER AUTHORS OR DISTRIBUTORS OF THIS FILE BE LIABLE for any
27 * damages arising directly or indirectly from this file, its use or
28 * this licence. Without prejudice to the generality of the
29 * foregoing: all liability shall be excluded for direct, indirect,
30 * special, incidental, consequential or other damages or any loss of
31 * profits, business, revenue goodwill or anticipated savings;
32 * liability shall be excluded even if nCipher or anyone else has been
33 * advised of the possibility of damage. In any event, if the
34 * exclusion of liability is not effective, the liability of nCipher
35 * or any author or distributor shall be limited to the lesser of the
36 * price paid and 1,000 pounds sterling. This licence only fails to
37 * exclude or limit liability for death or personal injury arising out
38 * of negligence, and only to the extent that such an exclusion or
39 * limitation is not effective.
40 *
41 * NCIPHER AND THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ALL
42 * AND ANY WARRANTIES (WHETHER EXPRESS OR IMPLIED), including, but not
43 * limited to, any implied warranties of merchantability, fitness for
44 * a particular purpose, satisfactory quality, and/or non-infringement
45 * of any third party rights.
46 *
47 * US Government use: This software and documentation is Commercial
48 * Computer Software and Computer Software Documentation, as defined in
49 * sub-paragraphs (a)(1) and (a)(5) of DFAR 252.227-7014, "Rights in
50 * Noncommercial Computer Software and Noncommercial Computer Software
51 * Documentation." Use, duplication or disclosure by the Government is
52 * subject to the terms and conditions specified here.
53 *
54 * By using or distributing this file you will be accepting these
55 * terms and conditions, including the limitation of liability and
56 * lack of warranty. If you do not wish to accept these terms and
57 * conditions, DO NOT USE THE FILE.
58 *
59 *
60 * The actual dynamically loadable plugin, and the library files for
61 * static linking, which are also provided in some distributions, are
62 * not covered by the licence described above. You should have
63 * received a separate licence with terms and conditions for these
64 * library files; if you received the library files without a licence,
65 * please contact nCipher.
66 *
67 *
68 * $Id: hwcryptohook.h,v 1.1.1.1 2003/05/11 21:35:16 markus Exp $
69 */
70
71#ifndef HWCRYPTOHOOK_H
72#define HWCRYPTOHOOK_H
73
74#include <sys/types.h>
75#include <stdio.h>
76
77#ifndef HWCRYPTOHOOK_DECLARE_APPTYPES
78#define HWCRYPTOHOOK_DECLARE_APPTYPES 1
79#endif
80
81#define HWCRYPTOHOOK_ERROR_FAILED -1
82#define HWCRYPTOHOOK_ERROR_FALLBACK -2
83#define HWCRYPTOHOOK_ERROR_MPISIZE -3
84
85#if HWCRYPTOHOOK_DECLARE_APPTYPES
86
87/* These structs are defined by the application and opaque to the
88 * crypto plugin. The application may define these as it sees fit.
89 * Default declarations are provided here, but the application may
90 * #define HWCRYPTOHOOK_DECLARE_APPTYPES 0
91 * to prevent these declarations, and instead provide its own
92 * declarations of these types. (Pointers to them must still be
93 * ordinary pointers to structs or unions, or the resulting combined
94 * program will have a type inconsistency.)
95 */
96typedef struct HWCryptoHook_MutexValue HWCryptoHook_Mutex;
97typedef struct HWCryptoHook_CondVarValue HWCryptoHook_CondVar;
98typedef struct HWCryptoHook_PassphraseContextValue HWCryptoHook_PassphraseContext;
99typedef struct HWCryptoHook_CallerContextValue HWCryptoHook_CallerContext;
100
101#endif /* HWCRYPTOHOOK_DECLARE_APPTYPES */
102
103/* These next two structs are opaque to the application. The crypto
104 * plugin will return pointers to them; the caller simply manipulates
105 * the pointers.
106 */
107typedef struct HWCryptoHook_Context *HWCryptoHook_ContextHandle;
108typedef struct HWCryptoHook_RSAKey *HWCryptoHook_RSAKeyHandle;
109
110typedef struct {
111 char *buf;
112 size_t size;
113} HWCryptoHook_ErrMsgBuf;
114/* Used for error reporting. When a HWCryptoHook function fails it
115 * will return a sentinel value (0 for pointer-valued functions, or a
116 * negative number, usually HWCRYPTOHOOK_ERROR_FAILED, for
117 * integer-valued ones). It will, if an ErrMsgBuf is passed, also put
118 * an error message there.
119 *
120 * size is the size of the buffer, and will not be modified. If you
121 * pass 0 for size you must pass 0 for buf, and nothing will be
122 * recorded (just as if you passed 0 for the struct pointer).
123 * Messages written to the buffer will always be null-terminated, even
124 * when truncated to fit within size bytes.
125 *
126 * The contents of the buffer are not defined if there is no error.
127 */
128
129typedef struct HWCryptoHook_MPIStruct {
130 unsigned char *buf;
131 size_t size;
132} HWCryptoHook_MPI;
133/* When one of these is returned, a pointer is passed to the function.
134 * At call, size is the space available. Afterwards it is updated to
135 * be set to the actual length (which may be more than the space available,
136 * if there was not enough room and the result was truncated).
137 * buf (the pointer) is not updated.
138 *
139 * size is in bytes and may be zero at call or return, but must be a
140 * multiple of the limb size. Zero limbs at the MS end are not
141 * permitted.
142 */
143
144#define HWCryptoHook_InitFlags_FallbackModExp 0x0002UL
145#define HWCryptoHook_InitFlags_FallbackRSAImmed 0x0004UL
146/* Enable requesting fallback to software in case of problems with the
147 * hardware support. This indicates to the crypto provider that the
148 * application is prepared to fall back to software operation if the
149 * ModExp* or RSAImmed* functions return HWCRYPTOHOOK_ERROR_FALLBACK.
150 * Without this flag those calls will never return
151 * HWCRYPTOHOOK_ERROR_FALLBACK. The flag will also cause the crypto
152 * provider to avoid repeatedly attempting to contact dead hardware
153 * within a short interval, if appropriate.
154 */
155
156#define HWCryptoHook_InitFlags_SimpleForkCheck 0x0010UL
157/* Without _SimpleForkCheck the library is allowed to assume that the
158 * application will not fork and call the library in the child(ren).
159 *
160 * When it is specified, this is allowed. However, after a fork
161 * neither parent nor child may unload any loaded keys or call
162 * _Finish. Instead, they should call exit (or die with a signal)
163 * without calling _Finish. After all the children have died the
164 * parent may unload keys or call _Finish.
165 *
166 * This flag only has any effect on UN*X platforms.
167 */
168
169typedef struct {
170 unsigned long flags;
171 void *logstream; /* usually a FILE*. See below. */
172
173 size_t limbsize; /* bignum format - size of radix type, must be power of 2 */
174 int mslimbfirst; /* 0 or 1 */
175 int msbytefirst; /* 0 or 1; -1 = native */
176
177 /* All the callback functions should return 0 on success, or a
178 * nonzero integer (whose value will be visible in the error message
179 * put in the buffer passed to the call).
180 *
181 * If a callback is not available pass a null function pointer.
182 *
183 * The callbacks may not call down again into the crypto plugin.
184 */
185
186 /* For thread-safety. Set everything to 0 if you promise only to be
187 * singlethreaded. maxsimultaneous is the number of calls to
188 * ModExp[Crt]/RSAImmed{Priv,Pub}/RSA. If you don't know what to
189 * put there then say 0 and the hook library will use a default.
190 *
191 * maxmutexes is a small limit on the number of simultaneous mutexes
192 * which will be requested by the library. If there is no small
193 * limit, set it to 0. If the crypto plugin cannot create the
194 * advertised number of mutexes the calls to its functions may fail.
195 * If a low number of mutexes is advertised the plugin will try to
196 * do the best it can. Making larger numbers of mutexes available
197 * may improve performance and parallelism by reducing contention
198 * over critical sections. Unavailability of any mutexes, implying
199 * single-threaded operation, should be indicated by the setting
200 * mutex_init et al to 0.
201 */
202 int maxmutexes;
203 int maxsimultaneous;
204 size_t mutexsize;
205 int (*mutex_init)(HWCryptoHook_Mutex*, HWCryptoHook_CallerContext *cactx);
206 int (*mutex_acquire)(HWCryptoHook_Mutex*);
207 void (*mutex_release)(HWCryptoHook_Mutex*);
208 void (*mutex_destroy)(HWCryptoHook_Mutex*);
209
210 /* For greater efficiency, can use condition vars internally for
211 * synchronisation. In this case maxsimultaneous is ignored, but
212 * the other mutex stuff must be available. In singlethreaded
213 * programs, set everything to 0.
214 */
215 size_t condvarsize;
216 int (*condvar_init)(HWCryptoHook_CondVar*, HWCryptoHook_CallerContext *cactx);
217 int (*condvar_wait)(HWCryptoHook_CondVar*, HWCryptoHook_Mutex*);
218 void (*condvar_signal)(HWCryptoHook_CondVar*);
219 void (*condvar_broadcast)(HWCryptoHook_CondVar*);
220 void (*condvar_destroy)(HWCryptoHook_CondVar*);
221
222 /* The semantics of acquiring and releasing mutexes and broadcasting
223 * and waiting on condition variables are expected to be those from
224 * POSIX threads (pthreads). The mutexes may be (in pthread-speak)
225 * fast mutexes, recursive mutexes, or nonrecursive ones.
226 *
227 * The _release/_signal/_broadcast and _destroy functions must
228 * always succeed when given a valid argument; if they are given an
229 * invalid argument then the program (crypto plugin + application)
230 * has an internal error, and they should abort the program.
231 */
232
233 int (*getpassphrase)(const char *prompt_info,
234 int *len_io, char *buf,
235 HWCryptoHook_PassphraseContext *ppctx,
236 HWCryptoHook_CallerContext *cactx);
237 /* Passphrases and the prompt_info, if they contain high-bit-set
238 * characters, are UTF-8. The prompt_info may be a null pointer if
239 * no prompt information is available (it should not be an empty
240 * string). It will not contain text like `enter passphrase';
241 * instead it might say something like `Operator Card for John
242 * Smith' or `SmartCard in nFast Module #1, Slot #1'.
243 *
244 * buf points to a buffer in which to return the passphrase; on
245 * entry *len_io is the length of the buffer. It should be updated
246 * by the callback. The returned passphrase should not be
247 * null-terminated by the callback.
248 */
249
250 int (*getphystoken)(const char *prompt_info,
251 const char *wrong_info,
252 HWCryptoHook_PassphraseContext *ppctx,
253 HWCryptoHook_CallerContext *cactx);
254 /* Requests that the human user physically insert a different
255 * smartcard, DataKey, etc. The plugin should check whether the
256 * currently inserted token(s) are appropriate, and if they are it
257 * should not make this call.
258 *
259 * prompt_info is as before. wrong_info is a description of the
260 * currently inserted token(s) so that the user is told what
261 * something is. wrong_info, like prompt_info, may be null, but
262 * should not be an empty string. Its contents should be
263 * syntactically similar to that of prompt_info.
264 */
265
266 /* Note that a single LoadKey operation might cause several calls to
267 * getpassphrase and/or requestphystoken. If requestphystoken is
268 * not provided (ie, a null pointer is passed) then the plugin may
269 * not support loading keys for which authorisation by several cards
270 * is required. If getpassphrase is not provided then cards with
271 * passphrases may not be supported.
272 *
273 * getpassphrase and getphystoken do not need to check that the
274 * passphrase has been entered correctly or the correct token
275 * inserted; the crypto plugin will do that. If this is not the
276 * case then the crypto plugin is responsible for calling these
277 * routines again as appropriate until the correct token(s) and
278 * passphrase(s) are supplied as required, or until any retry limits
279 * implemented by the crypto plugin are reached.
280 *
281 * In either case, the application must allow the user to say `no'
282 * or `cancel' to indicate that they do not know the passphrase or
283 * have the appropriate token; this should cause the callback to
284 * return nonzero indicating error.
285 */
286
287 void (*logmessage)(void *logstream, const char *message);
288 /* A log message will be generated at least every time something goes
289 * wrong and an ErrMsgBuf is filled in (or would be if one was
290 * provided). Other diagnostic information may be written there too,
291 * including more detailed reasons for errors which are reported in an
292 * ErrMsgBuf.
293 *
294 * When a log message is generated, this callback is called. It
295 * should write a message to the relevant logging arrangements.
296 *
297 * The message string passed will be null-terminated and may be of arbitrary
298 * length. It will not be prefixed by the time and date, nor by the
299 * name of the library that is generating it - if this is required,
300 * the logmessage callback must do it. The message will not have a
301 * trailing newline (though it may contain internal newlines).
302 *
303 * If a null pointer is passed for logmessage a default function is
304 * used. The default function treats logstream as a FILE* which has
305 * been converted to a void*. If logstream is 0 it does nothing.
306 * Otherwise it prepends the date and time and library name and
307 * writes the message to logstream. Each line will be prefixed by a
308 * descriptive string containing the date, time and identity of the
309 * crypto plugin. Errors on the logstream are not reported
310 * anywhere, and the default function doesn't flush the stream, so
311 * the application must set the buffering how it wants it.
312 *
313 * The crypto plugin may also provide a facility to have copies of
314 * log messages sent elsewhere, and or for adjusting the verbosity
315 * of the log messages; any such facilities will be configured by
316 * external means.
317 */
318
319} HWCryptoHook_InitInfo;
320
321typedef
322HWCryptoHook_ContextHandle HWCryptoHook_Init_t(const HWCryptoHook_InitInfo *initinfo,
323 size_t initinfosize,
324 const HWCryptoHook_ErrMsgBuf *errors,
325 HWCryptoHook_CallerContext *cactx);
326extern HWCryptoHook_Init_t HWCryptoHook_Init;
327
328/* Caller should set initinfosize to the size of the HWCryptoHook struct,
329 * so it can be extended later.
330 *
331 * On success, a message for display or logging by the server,
332 * including the name and version number of the plugin, will be filled
333 * in into *errors; on failure *errors is used for error handling, as
334 * usual.
335 */
336
337/* All these functions return 0 on success, HWCRYPTOHOOK_ERROR_FAILED
338 * on most failures. HWCRYPTOHOOK_ERROR_MPISIZE means at least one of
339 * the output MPI buffer(s) was too small; the sizes of all have been
340 * set to the desired size (and for those where the buffer was large
341 * enough, the value may have been copied in), and no error message
342 * has been recorded.
343 *
344 * You may pass 0 for the errors struct. In any case, unless you set
345 * _NoStderr at init time then messages may be reported to stderr.
346 */
347
348/* The RSAImmed* functions (and key managed RSA) only work with
349 * modules which have an RSA patent licence - currently that means KM
350 * units; the ModExp* ones work with all modules, so you need a patent
351 * licence in the software in the US. They are otherwise identical.
352 */
353
354typedef
355void HWCryptoHook_Finish_t(HWCryptoHook_ContextHandle hwctx);
356extern HWCryptoHook_Finish_t HWCryptoHook_Finish;
357/* You must not have any calls going or keys loaded when you call this. */
358
359typedef
360int HWCryptoHook_RandomBytes_t(HWCryptoHook_ContextHandle hwctx,
361 unsigned char *buf, size_t len,
362 const HWCryptoHook_ErrMsgBuf *errors);
363extern HWCryptoHook_RandomBytes_t HWCryptoHook_RandomBytes;
364
365typedef
366int HWCryptoHook_ModExp_t(HWCryptoHook_ContextHandle hwctx,
367 HWCryptoHook_MPI a,
368 HWCryptoHook_MPI p,
369 HWCryptoHook_MPI n,
370 HWCryptoHook_MPI *r,
371 const HWCryptoHook_ErrMsgBuf *errors);
372extern HWCryptoHook_ModExp_t HWCryptoHook_ModExp;
373
374typedef
375int HWCryptoHook_RSAImmedPub_t(HWCryptoHook_ContextHandle hwctx,
376 HWCryptoHook_MPI m,
377 HWCryptoHook_MPI e,
378 HWCryptoHook_MPI n,
379 HWCryptoHook_MPI *r,
380 const HWCryptoHook_ErrMsgBuf *errors);
381extern HWCryptoHook_RSAImmedPub_t HWCryptoHook_RSAImmedPub;
382
383typedef
384int HWCryptoHook_ModExpCRT_t(HWCryptoHook_ContextHandle hwctx,
385 HWCryptoHook_MPI a,
386 HWCryptoHook_MPI p,
387 HWCryptoHook_MPI q,
388 HWCryptoHook_MPI dmp1,
389 HWCryptoHook_MPI dmq1,
390 HWCryptoHook_MPI iqmp,
391 HWCryptoHook_MPI *r,
392 const HWCryptoHook_ErrMsgBuf *errors);
393extern HWCryptoHook_ModExpCRT_t HWCryptoHook_ModExpCRT;
394
395typedef
396int HWCryptoHook_RSAImmedPriv_t(HWCryptoHook_ContextHandle hwctx,
397 HWCryptoHook_MPI m,
398 HWCryptoHook_MPI p,
399 HWCryptoHook_MPI q,
400 HWCryptoHook_MPI dmp1,
401 HWCryptoHook_MPI dmq1,
402 HWCryptoHook_MPI iqmp,
403 HWCryptoHook_MPI *r,
404 const HWCryptoHook_ErrMsgBuf *errors);
405extern HWCryptoHook_RSAImmedPriv_t HWCryptoHook_RSAImmedPriv;
406
407/* The RSAImmed* and ModExp* functions may return E_FAILED or
408 * E_FALLBACK for failure.
409 *
410 * E_FAILED means the failure is permanent and definite and there
411 * should be no attempt to fall back to software. (Eg, for some
412 * applications, which support only the acceleration-only
413 * functions, the `key material' may actually be an encoded key
414 * identifier, and doing the operation in software would give wrong
415 * answers.)
416 *
417 * E_FALLBACK means that doing the computation in software would seem
418 * reasonable. If an application pays attention to this and is
419 * able to fall back, it should also set the Fallback init flags.
420 */
421
422typedef
423int HWCryptoHook_RSALoadKey_t(HWCryptoHook_ContextHandle hwctx,
424 const char *key_ident,
425 HWCryptoHook_RSAKeyHandle *keyhandle_r,
426 const HWCryptoHook_ErrMsgBuf *errors,
427 HWCryptoHook_PassphraseContext *ppctx);
428extern HWCryptoHook_RSALoadKey_t HWCryptoHook_RSALoadKey;
429/* The key_ident is a null-terminated string configured by the
430 * user via the application's usual configuration mechanisms.
431 * It is provided to the user by the crypto provider's key management
432 * system. The user must be able to enter at least any string of between
433 * 1 and 1023 characters inclusive, consisting of printable 7-bit
434 * ASCII characters. The provider should avoid using
435 * any characters except alphanumerics and the punctuation
436 * characters _ - + . / @ ~ (the user is expected to be able
437 * to enter these without quoting). The string may be case-sensitive.
438 * The application may allow the user to enter other NULL-terminated strings,
439 * and the provider must cope (returning an error if the string is not
440 * valid).
441 *
442 * If the key does not exist, no error is recorded and 0 is returned;
443 * keyhandle_r will be set to 0 instead of to a key handle.
444 */
445
446typedef
447int HWCryptoHook_RSAGetPublicKey_t(HWCryptoHook_RSAKeyHandle k,
448 HWCryptoHook_MPI *n,
449 HWCryptoHook_MPI *e,
450 const HWCryptoHook_ErrMsgBuf *errors);
451extern HWCryptoHook_RSAGetPublicKey_t HWCryptoHook_RSAGetPublicKey;
452/* The crypto plugin will not store certificates.
453 *
454 * Although this function for acquiring the public key value is
455 * provided, it is not the purpose of this API to deal fully with the
456 * handling of the public key.
457 *
458 * It is expected that the crypto supplier's key generation program
459 * will provide general facilities for producing X.509
460 * self-certificates and certificate requests in PEM format. These
461 * will be given to the user so that they can configure them in the
462 * application, send them to CAs, or whatever.
463 *
464 * In case this kind of certificate handling is not appropriate, the
465 * crypto supplier's key generation program should be able to be
466 * configured not to generate such a self-certificate or certificate
467 * request. Then the application will need to do all of this, and
468 * will need to store and handle the public key and certificates
469 * itself.
470 */
471
472typedef
473int HWCryptoHook_RSAUnloadKey_t(HWCryptoHook_RSAKeyHandle k,
474 const HWCryptoHook_ErrMsgBuf *errors);
475extern HWCryptoHook_RSAUnloadKey_t HWCryptoHook_RSAUnloadKey;
476/* Might fail due to locking problems, or other serious internal problems. */
477
478typedef
479int HWCryptoHook_RSA_t(HWCryptoHook_MPI m,
480 HWCryptoHook_RSAKeyHandle k,
481 HWCryptoHook_MPI *r,
482 const HWCryptoHook_ErrMsgBuf *errors);
483extern HWCryptoHook_RSA_t HWCryptoHook_RSA;
484/* RSA private key operation (sign or decrypt) - raw, unpadded. */
485
486#endif /*HWCRYPTOHOOK_H*/
diff --git a/src/lib/libcrypto/engine/vendor_defns/sureware.h b/src/lib/libcrypto/engine/vendor_defns/sureware.h
new file mode 100644
index 0000000000..4bc22027f9
--- /dev/null
+++ b/src/lib/libcrypto/engine/vendor_defns/sureware.h
@@ -0,0 +1,239 @@
1/*
2* Written by Corinne Dive-Reclus(cdive@baltimore.com)
3*
4* Copyright@2001 Baltimore Technologies Ltd.
5* *
6* THIS FILE IS PROVIDED BY BALTIMORE TECHNOLOGIES ``AS IS'' AND *
7* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE *
8* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE *
9* ARE DISCLAIMED. IN NO EVENT SHALL BALTIMORE TECHNOLOGIES BE LIABLE *
10* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL *
11* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS *
12* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) *
13* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT *
14* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY *
15* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF *
16* SUCH DAMAGE. *
17*
18*
19*/
20#ifdef WIN32
21#define SW_EXPORT __declspec ( dllexport )
22#else
23#define SW_EXPORT
24#endif
25
26/*
27* List of exposed SureWare errors
28*/
29#define SUREWAREHOOK_ERROR_FAILED -1
30#define SUREWAREHOOK_ERROR_FALLBACK -2
31#define SUREWAREHOOK_ERROR_UNIT_FAILURE -3
32#define SUREWAREHOOK_ERROR_DATA_SIZE -4
33#define SUREWAREHOOK_ERROR_INVALID_PAD -5
34/*
35* -----------------WARNING-----------------------------------
36* In all the following functions:
37* msg is a string with at least 24 bytes free.
38* A 24 bytes string will be concatenated to the existing content of msg.
39*/
40/*
41* SureWare Initialisation function
42* in param threadsafe, if !=0, thread safe enabled
43* return SureWareHOOK_ERROR_UNIT_FAILURE if failure, 1 if success
44*/
45typedef int SureWareHook_Init_t(char*const msg,int threadsafe);
46extern SW_EXPORT SureWareHook_Init_t SureWareHook_Init;
47/*
48* SureWare Finish function
49*/
50typedef void SureWareHook_Finish_t();
51extern SW_EXPORT SureWareHook_Finish_t SureWareHook_Finish;
52/*
53* PRE_CONDITION:
54* DO NOT CALL ANY OF THE FOLLOWING FUNCTIONS IN CASE OF INIT FAILURE
55*/
56/*
57* SureWare RAND Bytes function
58* In case of failure, the content of buf is unpredictable.
59* return 1 if success
60* SureWareHOOK_ERROR_FALLBACK if function not available in hardware
61* SureWareHOOK_ERROR_FAILED if error while processing
62* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
63* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
64*
65* in/out param buf : a num bytes long buffer where random bytes will be put
66* in param num : the number of bytes into buf
67*/
68typedef int SureWareHook_Rand_Bytes_t(char*const msg,unsigned char *buf, int num);
69extern SW_EXPORT SureWareHook_Rand_Bytes_t SureWareHook_Rand_Bytes;
70
71/*
72* SureWare RAND Seed function
73* Adds some seed to the Hardware Random Number Generator
74* return 1 if success
75* SureWareHOOK_ERROR_FALLBACK if function not available in hardware
76* SureWareHOOK_ERROR_FAILED if error while processing
77* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
78* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
79*
80* in param buf : the seed to add into the HRNG
81* in param num : the number of bytes into buf
82*/
83typedef int SureWareHook_Rand_Seed_t(char*const msg,const void *buf, int num);
84extern SW_EXPORT SureWareHook_Rand_Seed_t SureWareHook_Rand_Seed;
85
86/*
87* SureWare Load Private Key function
88* return 1 if success
89* SureWareHOOK_ERROR_FAILED if error while processing
90* No hardware is contact for this function.
91*
92* in param key_id :the name of the private protected key file without the extension
93 ".sws"
94* out param hptr : a pointer to a buffer allocated by SureWare_Hook
95* out param num: the effective key length in bytes
96* out param keytype: 1 if RSA 2 if DSA
97*/
98typedef int SureWareHook_Load_Privkey_t(char*const msg,const char *key_id,char **hptr,unsigned long *num,char *keytype);
99extern SW_EXPORT SureWareHook_Load_Privkey_t SureWareHook_Load_Privkey;
100
101/*
102* SureWare Info Public Key function
103* return 1 if success
104* SureWareHOOK_ERROR_FAILED if error while processing
105* No hardware is contact for this function.
106*
107* in param key_id :the name of the private protected key file without the extension
108 ".swp"
109* out param hptr : a pointer to a buffer allocated by SureWare_Hook
110* out param num: the effective key length in bytes
111* out param keytype: 1 if RSA 2 if DSA
112*/
113typedef int SureWareHook_Info_Pubkey_t(char*const msg,const char *key_id,unsigned long *num,
114 char *keytype);
115extern SW_EXPORT SureWareHook_Info_Pubkey_t SureWareHook_Info_Pubkey;
116
117/*
118* SureWare Load Public Key function
119* return 1 if success
120* SureWareHOOK_ERROR_FAILED if error while processing
121* No hardware is contact for this function.
122*
123* in param key_id :the name of the public protected key file without the extension
124 ".swp"
125* in param num : the bytes size of n and e
126* out param n: where to write modulus in bn format
127* out param e: where to write exponent in bn format
128*/
129typedef int SureWareHook_Load_Rsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num,
130 unsigned long *n, unsigned long *e);
131extern SW_EXPORT SureWareHook_Load_Rsa_Pubkey_t SureWareHook_Load_Rsa_Pubkey;
132
133/*
134* SureWare Load DSA Public Key function
135* return 1 if success
136* SureWareHOOK_ERROR_FAILED if error while processing
137* No hardware is contact for this function.
138*
139* in param key_id :the name of the public protected key file without the extension
140 ".swp"
141* in param num : the bytes size of n and e
142* out param pub: where to write pub key in bn format
143* out param p: where to write prime in bn format
144* out param q: where to write sunprime (length 20 bytes) in bn format
145* out param g: where to write base in bn format
146*/
147typedef int SureWareHook_Load_Dsa_Pubkey_t(char*const msg,const char *key_id,unsigned long num,
148 unsigned long *pub, unsigned long *p,unsigned long*q,
149 unsigned long *g);
150extern SW_EXPORT SureWareHook_Load_Dsa_Pubkey_t SureWareHook_Load_Dsa_Pubkey;
151
152/*
153* SureWare Free function
154* Destroy the key into the hardware if destroy==1
155*/
156typedef void SureWareHook_Free_t(char *p,int destroy);
157extern SW_EXPORT SureWareHook_Free_t SureWareHook_Free;
158
159#define SUREWARE_PKCS1_PAD 1
160#define SUREWARE_ISO9796_PAD 2
161#define SUREWARE_NO_PAD 0
162/*
163* SureWare RSA Private Decryption
164* return 1 if success
165* SureWareHOOK_ERROR_FAILED if error while processing
166* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
167* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
168*
169* in param flen : byte size of from and to
170* in param from : encrypted data buffer, should be a not-null valid pointer
171* out param tlen: byte size of decrypted data, if error, unexpected value
172* out param to : decrypted data buffer, should be a not-null valid pointer
173* in param prsa: a protected key pointer, should be a not-null valid pointer
174* int padding: padding id as follow
175* SUREWARE_PKCS1_PAD
176* SUREWARE_NO_PAD
177*
178*/
179typedef int SureWareHook_Rsa_Priv_Dec_t(char*const msg,int flen,unsigned char *from,
180 int *tlen,unsigned char *to,
181 char *prsa,int padding);
182extern SW_EXPORT SureWareHook_Rsa_Priv_Dec_t SureWareHook_Rsa_Priv_Dec;
183/*
184* SureWare RSA Signature
185* return 1 if success
186* SureWareHOOK_ERROR_FAILED if error while processing
187* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
188* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
189*
190* in param flen : byte size of from and to
191* in param from : encrypted data buffer, should be a not-null valid pointer
192* out param tlen: byte size of decrypted data, if error, unexpected value
193* out param to : decrypted data buffer, should be a not-null valid pointer
194* in param prsa: a protected key pointer, should be a not-null valid pointer
195* int padding: padding id as follow
196* SUREWARE_PKCS1_PAD
197* SUREWARE_ISO9796_PAD
198*
199*/
200typedef int SureWareHook_Rsa_Sign_t(char*const msg,int flen,unsigned char *from,
201 int *tlen,unsigned char *to,
202 char *prsa,int padding);
203extern SW_EXPORT SureWareHook_Rsa_Sign_t SureWareHook_Rsa_Sign;
204/*
205* SureWare DSA Signature
206* return 1 if success
207* SureWareHOOK_ERROR_FAILED if error while processing
208* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
209* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
210*
211* in param flen : byte size of from and to
212* in param from : encrypted data buffer, should be a not-null valid pointer
213* out param to : decrypted data buffer, should be a 40bytes valid pointer
214* in param pdsa: a protected key pointer, should be a not-null valid pointer
215*
216*/
217typedef int SureWareHook_Dsa_Sign_t(char*const msg,int flen,const unsigned char *from,
218 unsigned long *r,unsigned long *s,char *pdsa);
219extern SW_EXPORT SureWareHook_Dsa_Sign_t SureWareHook_Dsa_Sign;
220
221
222/*
223* SureWare Mod Exp
224* return 1 if success
225* SureWareHOOK_ERROR_FAILED if error while processing
226* SureWareHOOK_ERROR_UNIT_FAILURE if hardware failure
227* SUREWAREHOOK_ERROR_DATA_SIZE wrong size for buf
228*
229* mod and res are mlen bytes long.
230* exp is elen bytes long
231* data is dlen bytes long
232* mlen,elen and dlen are all multiple of sizeof(unsigned long)
233*/
234typedef int SureWareHook_Mod_Exp_t(char*const msg,int mlen,const unsigned long *mod,
235 int elen,const unsigned long *exponent,
236 int dlen,unsigned long *data,
237 unsigned long *res);
238extern SW_EXPORT SureWareHook_Mod_Exp_t SureWareHook_Mod_Exp;
239
diff --git a/src/lib/libcrypto/err/Makefile b/src/lib/libcrypto/err/Makefile
new file mode 100644
index 0000000000..23e38409c8
--- /dev/null
+++ b/src/lib/libcrypto/err/Makefile
@@ -0,0 +1,109 @@
1#
2# OpenSSL/crypto/err/Makefile
3#
4
5DIR= err
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=err.c err_all.c err_prn.c
21LIBOBJ=err.o err_all.o err_prn.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= err.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77err.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/buffer.h
78err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
79err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
80err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
81err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
82err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
83err.o: ../cryptlib.h err.c
84err_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
85err_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
86err_all.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
87err_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
88err_all.o: ../../include/openssl/dso.h ../../include/openssl/e_os2.h
89err_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
90err_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
91err_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
92err_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
93err_all.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
94err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95err_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem2.h
96err_all.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
97err_all.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
98err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
99err_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
100err_all.o: ../../include/openssl/ui.h ../../include/openssl/x509.h
101err_all.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
102err_all.o: err_all.c
103err_prn.o: ../../e_os.h ../../include/openssl/bio.h
104err_prn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
105err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
106err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
107err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
108err_prn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
109err_prn.o: ../../include/openssl/symhacks.h ../cryptlib.h err_prn.c
diff --git a/src/lib/libcrypto/err/Makefile.ssl b/src/lib/libcrypto/err/Makefile.ssl
new file mode 100644
index 0000000000..b253061d07
--- /dev/null
+++ b/src/lib/libcrypto/err/Makefile.ssl
@@ -0,0 +1,119 @@
1#
2# SSLeay/crypto/err/Makefile
3#
4
5DIR= err
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=err.c err_all.c err_prn.c
27LIBOBJ=err.o err_all.o err_prn.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= err.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82err.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/buffer.h
83err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
84err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
85err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
86err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
87err.o: ../../include/openssl/symhacks.h ../cryptlib.h err.c
88err_all.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
89err_all.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
90err_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
91err_all.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
92err_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
93err_all.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
94err_all.o: ../../include/openssl/dsa.h ../../include/openssl/dso.h
95err_all.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
96err_all.o: ../../include/openssl/engine.h ../../include/openssl/err.h
97err_all.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
98err_all.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
99err_all.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
100err_all.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
101err_all.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
102err_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103err_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem2.h
104err_all.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
105err_all.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
106err_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
107err_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
108err_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
109err_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
110err_all.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
111err_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
112err_all.o: ../../include/openssl/x509v3.h err_all.c
113err_prn.o: ../../e_os.h ../../include/openssl/bio.h
114err_prn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
115err_prn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
116err_prn.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
117err_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
118err_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119err_prn.o: ../cryptlib.h err_prn.c
diff --git a/src/lib/libcrypto/err/err.c b/src/lib/libcrypto/err/err.c
index b6ff070e8f..53687d79ab 100644
--- a/src/lib/libcrypto/err/err.c
+++ b/src/lib/libcrypto/err/err.c
@@ -112,9 +112,9 @@
112#include <stdio.h> 112#include <stdio.h>
113#include <stdarg.h> 113#include <stdarg.h>
114#include <string.h> 114#include <string.h>
115#include "cryptlib.h"
116#include <openssl/lhash.h> 115#include <openssl/lhash.h>
117#include <openssl/crypto.h> 116#include <openssl/crypto.h>
117#include "cryptlib.h"
118#include <openssl/buffer.h> 118#include <openssl/buffer.h>
119#include <openssl/bio.h> 119#include <openssl/bio.h>
120#include <openssl/err.h> 120#include <openssl/err.h>
@@ -149,7 +149,7 @@ static ERR_STRING_DATA ERR_str_libraries[]=
149{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"}, 149{ERR_PACK(ERR_LIB_DSO,0,0) ,"DSO support routines"},
150{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"}, 150{ERR_PACK(ERR_LIB_ENGINE,0,0) ,"engine routines"},
151{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"}, 151{ERR_PACK(ERR_LIB_OCSP,0,0) ,"OCSP routines"},
152{ERR_PACK(ERR_LIB_CMS,0,0) ,"CMS routines"}, 152{ERR_PACK(ERR_LIB_FIPS,0,0) ,"FIPS routines"},
153{0,NULL}, 153{0,NULL},
154 }; 154 };
155 155
@@ -168,6 +168,7 @@ static ERR_STRING_DATA ERR_str_functs[]=
168#endif 168#endif
169 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"}, 169 {ERR_PACK(0,SYS_F_OPENDIR,0), "opendir"},
170 {ERR_PACK(0,SYS_F_FREAD,0), "fread"}, 170 {ERR_PACK(0,SYS_F_FREAD,0), "fread"},
171 {ERR_PACK(0,SYS_F_GETADDRINFO,0), "getaddrinfo"},
171 {0,NULL}, 172 {0,NULL},
172 }; 173 };
173 174
@@ -209,7 +210,6 @@ static ERR_STRING_DATA ERR_str_reasons[]=
209{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"}, 210{ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED ,"called a function you should not call"},
210{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"}, 211{ERR_R_PASSED_NULL_PARAMETER ,"passed a null parameter"},
211{ERR_R_INTERNAL_ERROR ,"internal error"}, 212{ERR_R_INTERNAL_ERROR ,"internal error"},
212{ERR_R_DISABLED ,"called a function that was disabled at compile-time"},
213 213
214{0,NULL}, 214{0,NULL},
215 }; 215 };
@@ -542,27 +542,16 @@ static ERR_STRING_DATA SYS_str_reasons[NUM_SYS_STR_REASONS + 1];
542 * will be returned for SYSerr(), which always gets an errno 542 * will be returned for SYSerr(), which always gets an errno
543 * value and never one of those 'standard' reason codes. */ 543 * value and never one of those 'standard' reason codes. */
544 544
545static void build_SYS_str_reasons(void) 545static void build_SYS_str_reasons()
546 { 546 {
547 /* OPENSSL_malloc cannot be used here, use static storage instead */ 547 /* OPENSSL_malloc cannot be used here, use static storage instead */
548 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON]; 548 static char strerror_tab[NUM_SYS_STR_REASONS][LEN_SYS_STR_REASON];
549 int i; 549 int i;
550 static int init = 1; 550 static int init = 1;
551 551
552 CRYPTO_r_lock(CRYPTO_LOCK_ERR); 552 if (!init) return;
553 if (!init) 553
554 {
555 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
556 return;
557 }
558
559 CRYPTO_r_unlock(CRYPTO_LOCK_ERR);
560 CRYPTO_w_lock(CRYPTO_LOCK_ERR); 554 CRYPTO_w_lock(CRYPTO_LOCK_ERR);
561 if (!init)
562 {
563 CRYPTO_w_unlock(CRYPTO_LOCK_ERR);
564 return;
565 }
566 555
567 for (i = 1; i <= NUM_SYS_STR_REASONS; i++) 556 for (i = 1; i <= NUM_SYS_STR_REASONS; i++)
568 { 557 {
@@ -594,24 +583,13 @@ static void build_SYS_str_reasons(void)
594#endif 583#endif
595 584
596#define err_clear_data(p,i) \ 585#define err_clear_data(p,i) \
597 do { \
598 if (((p)->err_data[i] != NULL) && \ 586 if (((p)->err_data[i] != NULL) && \
599 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \ 587 (p)->err_data_flags[i] & ERR_TXT_MALLOCED) \
600 { \ 588 { \
601 OPENSSL_free((p)->err_data[i]); \ 589 OPENSSL_free((p)->err_data[i]); \
602 (p)->err_data[i]=NULL; \ 590 (p)->err_data[i]=NULL; \
603 } \ 591 } \
604 (p)->err_data_flags[i]=0; \ 592 (p)->err_data_flags[i]=0;
605 } while(0)
606
607#define err_clear(p,i) \
608 do { \
609 (p)->err_flags[i]=0; \
610 (p)->err_buffer[i]=0; \
611 err_clear_data(p,i); \
612 (p)->err_file[i]=NULL; \
613 (p)->err_line[i]= -1; \
614 } while(0)
615 593
616static void ERR_STATE_free(ERR_STATE *s) 594static void ERR_STATE_free(ERR_STATE *s)
617 { 595 {
@@ -704,7 +682,6 @@ void ERR_put_error(int lib, int func, int reason, const char *file,
704 es->top=(es->top+1)%ERR_NUM_ERRORS; 682 es->top=(es->top+1)%ERR_NUM_ERRORS;
705 if (es->top == es->bottom) 683 if (es->top == es->bottom)
706 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS; 684 es->bottom=(es->bottom+1)%ERR_NUM_ERRORS;
707 es->err_flags[es->top]=0;
708 es->err_buffer[es->top]=ERR_PACK(lib,func,reason); 685 es->err_buffer[es->top]=ERR_PACK(lib,func,reason);
709 es->err_file[es->top]=file; 686 es->err_file[es->top]=file;
710 es->err_line[es->top]=line; 687 es->err_line[es->top]=line;
@@ -720,7 +697,10 @@ void ERR_clear_error(void)
720 697
721 for (i=0; i<ERR_NUM_ERRORS; i++) 698 for (i=0; i<ERR_NUM_ERRORS; i++)
722 { 699 {
723 err_clear(es,i); 700 es->err_buffer[i]=0;
701 err_clear_data(es,i);
702 es->err_file[i]=NULL;
703 es->err_line[i]= -1;
724 } 704 }
725 es->top=es->bottom=0; 705 es->top=es->bottom=0;
726 } 706 }
@@ -957,7 +937,7 @@ static unsigned long err_hash(const void *a_void)
957 { 937 {
958 unsigned long ret,l; 938 unsigned long ret,l;
959 939
960 l=((const ERR_STRING_DATA *)a_void)->error; 940 l=((ERR_STRING_DATA *)a_void)->error;
961 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l); 941 ret=l^ERR_GET_LIB(l)^ERR_GET_FUNC(l);
962 return(ret^ret%19*13); 942 return(ret^ret%19*13);
963 } 943 }
@@ -965,21 +945,21 @@ static unsigned long err_hash(const void *a_void)
965/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */ 945/* static int err_cmp(ERR_STRING_DATA *a, ERR_STRING_DATA *b) */
966static int err_cmp(const void *a_void, const void *b_void) 946static int err_cmp(const void *a_void, const void *b_void)
967 { 947 {
968 return((int)(((const ERR_STRING_DATA *)a_void)->error - 948 return((int)(((ERR_STRING_DATA *)a_void)->error -
969 ((const ERR_STRING_DATA *)b_void)->error)); 949 ((ERR_STRING_DATA *)b_void)->error));
970 } 950 }
971 951
972/* static unsigned long pid_hash(ERR_STATE *a) */ 952/* static unsigned long pid_hash(ERR_STATE *a) */
973static unsigned long pid_hash(const void *a_void) 953static unsigned long pid_hash(const void *a_void)
974 { 954 {
975 return(((const ERR_STATE *)a_void)->pid*13); 955 return(((ERR_STATE *)a_void)->pid*13);
976 } 956 }
977 957
978/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */ 958/* static int pid_cmp(ERR_STATE *a, ERR_STATE *b) */
979static int pid_cmp(const void *a_void, const void *b_void) 959static int pid_cmp(const void *a_void, const void *b_void)
980 { 960 {
981 return((int)((long)((const ERR_STATE *)a_void)->pid - 961 return((int)((long)((ERR_STATE *)a_void)->pid -
982 (long)((const ERR_STATE *)b_void)->pid)); 962 (long)((ERR_STATE *)b_void)->pid));
983 } 963 }
984 964
985void ERR_remove_state(unsigned long pid) 965void ERR_remove_state(unsigned long pid)
@@ -1089,7 +1069,7 @@ void ERR_add_error_data(int num, ...)
1089 else 1069 else
1090 str=p; 1070 str=p;
1091 } 1071 }
1092 BUF_strlcat(str,a,(size_t)s+1); 1072 BUF_strlcat(str,a,s+1);
1093 } 1073 }
1094 } 1074 }
1095 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING); 1075 ERR_set_error_data(str,ERR_TXT_MALLOCED|ERR_TXT_STRING);
@@ -1097,33 +1077,3 @@ void ERR_add_error_data(int num, ...)
1097err: 1077err:
1098 va_end(args); 1078 va_end(args);
1099 } 1079 }
1100
1101int ERR_set_mark(void)
1102 {
1103 ERR_STATE *es;
1104
1105 es=ERR_get_state();
1106
1107 if (es->bottom == es->top) return 0;
1108 es->err_flags[es->top]|=ERR_FLAG_MARK;
1109 return 1;
1110 }
1111
1112int ERR_pop_to_mark(void)
1113 {
1114 ERR_STATE *es;
1115
1116 es=ERR_get_state();
1117
1118 while(es->bottom != es->top
1119 && (es->err_flags[es->top] & ERR_FLAG_MARK) == 0)
1120 {
1121 err_clear(es,es->top);
1122 es->top-=1;
1123 if (es->top == -1) es->top=ERR_NUM_ERRORS-1;
1124 }
1125
1126 if (es->bottom == es->top) return 0;
1127 es->err_flags[es->top]&=~ERR_FLAG_MARK;
1128 return 1;
1129 }
diff --git a/src/lib/libcrypto/err/err.h b/src/lib/libcrypto/err/err.h
index bf28fce492..2efa18866a 100644
--- a/src/lib/libcrypto/err/err.h
+++ b/src/lib/libcrypto/err/err.h
@@ -59,14 +59,11 @@
59#ifndef HEADER_ERR_H 59#ifndef HEADER_ERR_H
60#define HEADER_ERR_H 60#define HEADER_ERR_H
61 61
62#include <openssl/e_os2.h>
63
64#ifndef OPENSSL_NO_FP_API 62#ifndef OPENSSL_NO_FP_API
65#include <stdio.h> 63#include <stdio.h>
66#include <stdlib.h> 64#include <stdlib.h>
67#endif 65#endif
68 66
69#include <openssl/ossl_typ.h>
70#ifndef OPENSSL_NO_BIO 67#ifndef OPENSSL_NO_BIO
71#include <openssl/bio.h> 68#include <openssl/bio.h>
72#endif 69#endif
@@ -89,13 +86,10 @@ extern "C" {
89#define ERR_TXT_MALLOCED 0x01 86#define ERR_TXT_MALLOCED 0x01
90#define ERR_TXT_STRING 0x02 87#define ERR_TXT_STRING 0x02
91 88
92#define ERR_FLAG_MARK 0x01
93
94#define ERR_NUM_ERRORS 16 89#define ERR_NUM_ERRORS 16
95typedef struct err_state_st 90typedef struct err_state_st
96 { 91 {
97 unsigned long pid; 92 unsigned long pid;
98 int err_flags[ERR_NUM_ERRORS];
99 unsigned long err_buffer[ERR_NUM_ERRORS]; 93 unsigned long err_buffer[ERR_NUM_ERRORS];
100 char *err_data[ERR_NUM_ERRORS]; 94 char *err_data[ERR_NUM_ERRORS];
101 int err_data_flags[ERR_NUM_ERRORS]; 95 int err_data_flags[ERR_NUM_ERRORS];
@@ -137,10 +131,7 @@ typedef struct err_state_st
137#define ERR_LIB_OCSP 39 131#define ERR_LIB_OCSP 39
138#define ERR_LIB_UI 40 132#define ERR_LIB_UI 40
139#define ERR_LIB_COMP 41 133#define ERR_LIB_COMP 41
140#define ERR_LIB_ECDSA 42 134#define ERR_LIB_FIPS 42
141#define ERR_LIB_ECDH 43
142#define ERR_LIB_STORE 44
143#define ERR_LIB_CMS 45
144 135
145#define ERR_LIB_USER 128 136#define ERR_LIB_USER 128
146 137
@@ -169,10 +160,7 @@ typedef struct err_state_st
169#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__) 160#define OCSPerr(f,r) ERR_PUT_error(ERR_LIB_OCSP,(f),(r),__FILE__,__LINE__)
170#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__) 161#define UIerr(f,r) ERR_PUT_error(ERR_LIB_UI,(f),(r),__FILE__,__LINE__)
171#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__) 162#define COMPerr(f,r) ERR_PUT_error(ERR_LIB_COMP,(f),(r),__FILE__,__LINE__)
172#define ECDSAerr(f,r) ERR_PUT_error(ERR_LIB_ECDSA,(f),(r),__FILE__,__LINE__) 163#define FIPSerr(f,r) ERR_PUT_error(ERR_LIB_FIPS,(f),(r),__FILE__,__LINE__)
173#define ECDHerr(f,r) ERR_PUT_error(ERR_LIB_ECDH,(f),(r),__FILE__,__LINE__)
174#define STOREerr(f,r) ERR_PUT_error(ERR_LIB_STORE,(f),(r),__FILE__,__LINE__)
175#define CMSerr(f,r) ERR_PUT_error(ERR_LIB_CMS,(f),(r),__FILE__,__LINE__)
176 164
177/* Borland C seems too stupid to be able to shift and do longs in 165/* Borland C seems too stupid to be able to shift and do longs in
178 * the pre-processor :-( */ 166 * the pre-processor :-( */
@@ -197,6 +185,7 @@ typedef struct err_state_st
197#define SYS_F_WSASTARTUP 9 /* Winsock stuff */ 185#define SYS_F_WSASTARTUP 9 /* Winsock stuff */
198#define SYS_F_OPENDIR 10 186#define SYS_F_OPENDIR 10
199#define SYS_F_FREAD 11 187#define SYS_F_FREAD 11
188#define SYS_F_GETADDRINFO 12
200 189
201 190
202/* reasons */ 191/* reasons */
@@ -225,9 +214,6 @@ typedef struct err_state_st
225#define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */ 214#define ERR_R_OCSP_LIB ERR_LIB_OCSP /* 39 */
226#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */ 215#define ERR_R_UI_LIB ERR_LIB_UI /* 40 */
227#define ERR_R_COMP_LIB ERR_LIB_COMP /* 41 */ 216#define ERR_R_COMP_LIB ERR_LIB_COMP /* 41 */
228#define ERR_R_ECDSA_LIB ERR_LIB_ECDSA /* 42 */
229#define ERR_R_ECDH_LIB ERR_LIB_ECDH /* 43 */
230#define ERR_R_STORE_LIB ERR_LIB_STORE /* 44 */
231 217
232#define ERR_R_NESTED_ASN1_ERROR 58 218#define ERR_R_NESTED_ASN1_ERROR 58
233#define ERR_R_BAD_ASN1_OBJECT_HEADER 59 219#define ERR_R_BAD_ASN1_OBJECT_HEADER 59
@@ -242,7 +228,6 @@ typedef struct err_state_st
242#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL) 228#define ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED (2|ERR_R_FATAL)
243#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL) 229#define ERR_R_PASSED_NULL_PARAMETER (3|ERR_R_FATAL)
244#define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL) 230#define ERR_R_INTERNAL_ERROR (4|ERR_R_FATAL)
245#define ERR_R_DISABLED (5|ERR_R_FATAL)
246 231
247/* 99 is the maximum possible ERR_R_... code, higher values 232/* 99 is the maximum possible ERR_R_... code, higher values
248 * are reserved for the individual libraries */ 233 * are reserved for the individual libraries */
@@ -301,11 +286,8 @@ void ERR_release_err_state_table(LHASH **hash);
301 286
302int ERR_get_next_error_library(void); 287int ERR_get_next_error_library(void);
303 288
304int ERR_set_mark(void); 289/* This opaque type encapsulates the low-level error-state functions */
305int ERR_pop_to_mark(void); 290typedef struct st_ERR_FNS ERR_FNS;
306
307/* Already defined in ossl_typ.h */
308/* typedef struct st_ERR_FNS ERR_FNS; */
309/* An application can use this function and provide the return value to loaded 291/* An application can use this function and provide the return value to loaded
310 * modules that should use the application's ERR state/functionality */ 292 * modules that should use the application's ERR state/functionality */
311const ERR_FNS *ERR_get_implementation(void); 293const ERR_FNS *ERR_get_implementation(void);
diff --git a/src/lib/libcrypto/err/err_all.c b/src/lib/libcrypto/err/err_all.c
index 5813060ce2..4dc9300892 100644
--- a/src/lib/libcrypto/err/err_all.c
+++ b/src/lib/libcrypto/err/err_all.c
@@ -73,12 +73,6 @@
73#ifndef OPENSSL_NO_DSA 73#ifndef OPENSSL_NO_DSA
74#include <openssl/dsa.h> 74#include <openssl/dsa.h>
75#endif 75#endif
76#ifndef OPENSSL_NO_ECDSA
77#include <openssl/ecdsa.h>
78#endif
79#ifndef OPENSSL_NO_ECDH
80#include <openssl/ecdh.h>
81#endif
82#include <openssl/evp.h> 76#include <openssl/evp.h>
83#include <openssl/objects.h> 77#include <openssl/objects.h>
84#include <openssl/pem2.h> 78#include <openssl/pem2.h>
@@ -91,15 +85,16 @@
91#ifndef OPENSSL_NO_ENGINE 85#ifndef OPENSSL_NO_ENGINE
92#include <openssl/engine.h> 86#include <openssl/engine.h>
93#endif 87#endif
94#include <openssl/ui.h>
95#include <openssl/ocsp.h> 88#include <openssl/ocsp.h>
96#include <openssl/err.h> 89#include <openssl/err.h>
97#ifndef OPENSSL_NO_CMS 90#include <openssl/fips.h>
98#include <openssl/cms.h>
99#endif
100 91
101void ERR_load_crypto_strings(void) 92void ERR_load_crypto_strings(void)
102 { 93 {
94 static int done=0;
95
96 if (done) return;
97 done=1;
103#ifndef OPENSSL_NO_ERR 98#ifndef OPENSSL_NO_ERR
104 ERR_load_ERR_strings(); /* include error strings for SYSerr */ 99 ERR_load_ERR_strings(); /* include error strings for SYSerr */
105 ERR_load_BN_strings(); 100 ERR_load_BN_strings();
@@ -123,12 +118,6 @@ void ERR_load_crypto_strings(void)
123#ifndef OPENSSL_NO_EC 118#ifndef OPENSSL_NO_EC
124 ERR_load_EC_strings(); 119 ERR_load_EC_strings();
125#endif 120#endif
126#ifndef OPENSSL_NO_ECDSA
127 ERR_load_ECDSA_strings();
128#endif
129#ifndef OPENSSL_NO_ECDH
130 ERR_load_ECDH_strings();
131#endif
132 /* skip ERR_load_SSL_strings() because it is not in this library */ 121 /* skip ERR_load_SSL_strings() because it is not in this library */
133 ERR_load_BIO_strings(); 122 ERR_load_BIO_strings();
134 ERR_load_PKCS7_strings(); 123 ERR_load_PKCS7_strings();
@@ -141,8 +130,8 @@ void ERR_load_crypto_strings(void)
141#endif 130#endif
142 ERR_load_OCSP_strings(); 131 ERR_load_OCSP_strings();
143 ERR_load_UI_strings(); 132 ERR_load_UI_strings();
144#ifndef OPENSSL_NO_CMS
145 ERR_load_CMS_strings();
146#endif 133#endif
134#ifdef OPENSSL_FIPS
135 ERR_load_FIPS_strings();
147#endif 136#endif
148 } 137 }
diff --git a/src/lib/libcrypto/err/err_prn.c b/src/lib/libcrypto/err/err_prn.c
index 2224a901e5..81e34bd6ce 100644
--- a/src/lib/libcrypto/err/err_prn.c
+++ b/src/lib/libcrypto/err/err_prn.c
@@ -57,9 +57,9 @@
57 */ 57 */
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/lhash.h> 60#include <openssl/lhash.h>
62#include <openssl/crypto.h> 61#include <openssl/crypto.h>
62#include "cryptlib.h"
63#include <openssl/buffer.h> 63#include <openssl/buffer.h>
64#include <openssl/err.h> 64#include <openssl/err.h>
65 65
@@ -86,12 +86,7 @@ void ERR_print_errors_cb(int (*cb)(const char *str, size_t len, void *u),
86#ifndef OPENSSL_NO_FP_API 86#ifndef OPENSSL_NO_FP_API
87static int print_fp(const char *str, size_t len, void *fp) 87static int print_fp(const char *str, size_t len, void *fp)
88 { 88 {
89 BIO bio; 89 return fprintf((FILE *)fp, "%s", str);
90
91 BIO_set(&bio,BIO_s_file());
92 BIO_set_fp(&bio,fp,BIO_NOCLOSE);
93
94 return BIO_printf(&bio, "%s", str);
95 } 90 }
96void ERR_print_errors_fp(FILE *fp) 91void ERR_print_errors_fp(FILE *fp)
97 { 92 {
diff --git a/src/lib/libcrypto/err/openssl.ec b/src/lib/libcrypto/err/openssl.ec
index 1938f081ac..f8cd6937e7 100644
--- a/src/lib/libcrypto/err/openssl.ec
+++ b/src/lib/libcrypto/err/openssl.ec
@@ -27,16 +27,11 @@ L DSO crypto/dso/dso.h crypto/dso/dso_err.c
27L ENGINE crypto/engine/engine.h crypto/engine/eng_err.c 27L ENGINE crypto/engine/engine.h crypto/engine/eng_err.c
28L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c 28L OCSP crypto/ocsp/ocsp.h crypto/ocsp/ocsp_err.c
29L UI crypto/ui/ui.h crypto/ui/ui_err.c 29L UI crypto/ui/ui.h crypto/ui/ui_err.c
30L COMP crypto/comp/comp.h crypto/comp/comp_err.c 30L FIPS fips-1.0/fips.h fips-1.0/fips_err.h
31L ECDSA crypto/ecdsa/ecdsa.h crypto/ecdsa/ecs_err.c
32L ECDH crypto/ecdh/ecdh.h crypto/ecdh/ech_err.c
33L STORE crypto/store/store.h crypto/store/str_err.c
34L CMS crypto/cms/cms.h crypto/cms/cms_err.c
35 31
36# additional header files to be scanned for function names 32# additional header files to be scanned for function names
37L NONE crypto/x509/x509_vfy.h NONE 33L NONE crypto/x509/x509_vfy.h NONE
38L NONE crypto/ec/ec_lcl.h NONE 34L NONE crypto/ec/ec_lcl.h NONE
39L NONE crypto/cms/cms_lcl.h NONE
40 35
41 36
42F RSAREF_F_RSA_BN2BIN 37F RSAREF_F_RSA_BN2BIN
diff --git a/src/lib/libcrypto/evp/Makefile b/src/lib/libcrypto/evp/Makefile
new file mode 100644
index 0000000000..8f2555c7e5
--- /dev/null
+++ b/src/lib/libcrypto/evp/Makefile
@@ -0,0 +1,646 @@
1#
2# OpenSSL/crypto/evp/Makefile
3#
4
5DIR= evp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=evp_test.c
17TESTDATA=evptests.txt
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC= encode.c digest.c evp_enc.c evp_key.c evp_acnf.c \
22 e_des.c e_bf.c e_idea.c e_des3.c e_camellia.c\
23 e_rc4.c e_aes.c names.c e_seed.c \
24 e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
25 m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
26 m_dss.c m_dss1.c m_mdc2.c m_ripemd.c m_ecdsa.c\
27 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
28 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
29 c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
30 evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c \
31 e_old.c
32
33LIBOBJ= encode.o digest.o evp_enc.o evp_key.o evp_acnf.o \
34 e_des.o e_bf.o e_idea.o e_des3.o e_camellia.o\
35 e_rc4.o e_aes.o names.o e_seed.o \
36 e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o \
37 m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
38 m_dss.o m_dss1.o m_mdc2.o m_ripemd.o m_ecdsa.o\
39 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
40 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
41 c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
42 evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o \
43 e_old.o
44
45SRC= $(LIBSRC)
46
47EXHEADER= evp.h
48HEADER= $(EXHEADER)
49
50ALL= $(GENERAL) $(SRC) $(HEADER)
51
52top:
53 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
54
55all: lib
56
57lib: $(LIBOBJ)
58 $(AR) $(LIB) $(LIBOBJ)
59 $(RANLIB) $(LIB) || echo Never mind.
60 @touch lib
61
62files:
63 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
64
65links:
66 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
67 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
68 cp $(TESTDATA) ../../test
69 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
70
71install:
72 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
73 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
74 do \
75 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
76 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
77 done;
78
79tags:
80 ctags $(SRC)
81
82tests:
83
84lint:
85 lint -DLINT $(INCLUDES) $(SRC)>fluff
86
87depend:
88 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
89 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
90
91dclean:
92 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
93 mv -f Makefile.new $(MAKEFILE)
94
95clean:
96 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
97
98# DO NOT DELETE THIS LINE -- make depend depends on it.
99
100bio_b64.o: ../../e_os.h ../../include/openssl/asn1.h
101bio_b64.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
102bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
103bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h
104bio_b64.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
105bio_b64.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
106bio_b64.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
107bio_b64.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
108bio_b64.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_b64.c
109bio_enc.o: ../../e_os.h ../../include/openssl/asn1.h
110bio_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
111bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
112bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
113bio_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
114bio_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
115bio_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
116bio_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
117bio_enc.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_enc.c
118bio_md.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
119bio_md.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
120bio_md.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
121bio_md.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
122bio_md.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
123bio_md.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
124bio_md.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
125bio_md.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
126bio_md.o: ../cryptlib.h bio_md.c
127bio_ok.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
128bio_ok.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
129bio_ok.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
130bio_ok.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
131bio_ok.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
132bio_ok.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
133bio_ok.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
134bio_ok.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
135bio_ok.o: ../../include/openssl/symhacks.h ../cryptlib.h bio_ok.c
136c_all.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
137c_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
138c_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
139c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
140c_all.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
141c_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
142c_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
143c_all.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
144c_all.o: ../../include/openssl/symhacks.h ../cryptlib.h c_all.c
145c_allc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
146c_allc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
147c_allc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
148c_allc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
149c_allc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
150c_allc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
151c_allc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
152c_allc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
153c_allc.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
154c_allc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
155c_allc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
156c_allc.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
157c_allc.o: ../cryptlib.h c_allc.c
158c_alld.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
159c_alld.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
160c_alld.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
161c_alld.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
162c_alld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
163c_alld.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
164c_alld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
165c_alld.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
166c_alld.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
167c_alld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
168c_alld.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
169c_alld.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
170c_alld.o: ../cryptlib.h c_alld.c
171digest.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
172digest.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
173digest.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
174digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
175digest.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
176digest.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
177digest.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
178digest.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
179digest.o: ../../include/openssl/symhacks.h ../cryptlib.h digest.c
180e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
181e_aes.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
182e_aes.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
183e_aes.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
184e_aes.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
185e_aes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
186e_aes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
187e_aes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h e_aes.c
188e_aes.o: evp_locl.h
189e_bf.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
190e_bf.o: ../../include/openssl/blowfish.h ../../include/openssl/buffer.h
191e_bf.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
192e_bf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
193e_bf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
194e_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
195e_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
196e_bf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
197e_bf.o: ../../include/openssl/symhacks.h ../cryptlib.h e_bf.c evp_locl.h
198e_camellia.o: ../../include/openssl/opensslconf.h e_camellia.c
199e_cast.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
200e_cast.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
201e_cast.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
202e_cast.o: ../../include/openssl/err.h ../../include/openssl/evp.h
203e_cast.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
204e_cast.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
205e_cast.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
206e_cast.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
207e_cast.o: ../../include/openssl/symhacks.h ../cryptlib.h e_cast.c evp_locl.h
208e_des.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
209e_des.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
210e_des.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
211e_des.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
212e_des.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
213e_des.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
214e_des.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
215e_des.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
216e_des.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
217e_des.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
218e_des.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des.c evp_locl.h
219e_des3.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
220e_des3.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
221e_des3.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
222e_des3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
223e_des3.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
224e_des3.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
225e_des3.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
226e_des3.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
227e_des3.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
228e_des3.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
229e_des3.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des3.c evp_locl.h
230e_idea.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
231e_idea.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
232e_idea.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
233e_idea.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
234e_idea.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
235e_idea.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
236e_idea.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
237e_idea.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
238e_idea.o: ../../include/openssl/symhacks.h ../cryptlib.h e_idea.c evp_locl.h
239e_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
240e_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
241e_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
242e_null.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
243e_null.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
244e_null.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
245e_null.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
246e_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
247e_null.o: ../cryptlib.h e_null.c
248e_old.o: e_old.c
249e_rc2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
250e_rc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
251e_rc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
252e_rc2.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
253e_rc2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
254e_rc2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
255e_rc2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
256e_rc2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
257e_rc2.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc2.c evp_locl.h
258e_rc4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
259e_rc4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
260e_rc4.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
261e_rc4.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
262e_rc4.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
263e_rc4.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
264e_rc4.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc4.h
265e_rc4.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
266e_rc4.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc4.c
267e_rc5.o: ../../e_os.h ../../include/openssl/bio.h
268e_rc5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
269e_rc5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
270e_rc5.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
271e_rc5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
272e_rc5.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
273e_rc5.o: ../../include/openssl/symhacks.h ../cryptlib.h e_rc5.c
274e_seed.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
275e_seed.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
276e_seed.o: ../../include/openssl/err.h ../../include/openssl/evp.h
277e_seed.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
278e_seed.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
279e_seed.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
280e_seed.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
281e_seed.o: ../../include/openssl/symhacks.h e_seed.c
282e_xcbc_d.o: ../../e_os.h ../../include/openssl/asn1.h
283e_xcbc_d.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
284e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
285e_xcbc_d.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
286e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
287e_xcbc_d.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
288e_xcbc_d.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
289e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
290e_xcbc_d.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
291e_xcbc_d.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
292e_xcbc_d.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_xcbc_d.c
293encode.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
294encode.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
295encode.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
296encode.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
297encode.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
298encode.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
299encode.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
300encode.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
301encode.o: ../cryptlib.h encode.c
302evp_acnf.o: ../../e_os.h ../../include/openssl/asn1.h
303evp_acnf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
304evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
305evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
306evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
307evp_acnf.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
308evp_acnf.o: ../../include/openssl/opensslconf.h
309evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
310evp_acnf.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
311evp_acnf.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_acnf.c
312evp_enc.o: ../../e_os.h ../../include/openssl/asn1.h
313evp_enc.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
314evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
315evp_enc.o: ../../include/openssl/engine.h ../../include/openssl/err.h
316evp_enc.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
317evp_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
318evp_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
319evp_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
320evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
321evp_enc.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_enc.c evp_locl.h
322evp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
323evp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
324evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
325evp_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
326evp_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
327evp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
328evp_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
329evp_err.o: ../../include/openssl/symhacks.h evp_err.c
330evp_key.o: ../../e_os.h ../../include/openssl/asn1.h
331evp_key.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
332evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
333evp_key.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
334evp_key.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
335evp_key.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
336evp_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
337evp_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
338evp_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
339evp_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
340evp_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
341evp_key.o: ../../include/openssl/ui.h ../../include/openssl/x509.h
342evp_key.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_key.c
343evp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
344evp_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
345evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
346evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
347evp_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
348evp_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
349evp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
350evp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
351evp_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h evp_lib.c
352evp_pbe.o: ../../e_os.h ../../include/openssl/asn1.h
353evp_pbe.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
354evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
355evp_pbe.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
356evp_pbe.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
357evp_pbe.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
358evp_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
359evp_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
360evp_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
361evp_pbe.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
362evp_pbe.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
363evp_pbe.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
364evp_pbe.o: ../cryptlib.h evp_pbe.c
365evp_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
366evp_pkey.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
367evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
368evp_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
369evp_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
370evp_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
371evp_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
372evp_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
373evp_pkey.o: ../../include/openssl/opensslconf.h
374evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
375evp_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
376evp_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
377evp_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
378evp_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
379evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pkey.c
380m_dss.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
381m_dss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
382m_dss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
383m_dss.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
384m_dss.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
385m_dss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
386m_dss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
387m_dss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
388m_dss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
389m_dss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
390m_dss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
391m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
392m_dss.o: ../cryptlib.h m_dss.c
393m_dss1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
394m_dss1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
395m_dss1.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
396m_dss1.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
397m_dss1.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
398m_dss1.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
399m_dss1.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
400m_dss1.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
401m_dss1.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
402m_dss1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
403m_dss1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
404m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
405m_dss1.o: ../cryptlib.h m_dss1.c
406m_ecdsa.o: ../../e_os.h ../../include/openssl/asn1.h
407m_ecdsa.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
408m_ecdsa.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
409m_ecdsa.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
410m_ecdsa.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
411m_ecdsa.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
412m_ecdsa.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
413m_ecdsa.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
414m_ecdsa.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
415m_ecdsa.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
416m_ecdsa.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
417m_ecdsa.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
418m_ecdsa.o: ../cryptlib.h m_ecdsa.c
419m_md2.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
420m_md2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
421m_md2.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
422m_md2.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
423m_md2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
424m_md2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
425m_md2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
426m_md2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
427m_md2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
428m_md2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
429m_md2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
430m_md2.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
431m_md2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md2.c
432m_md4.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
433m_md4.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
434m_md4.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
435m_md4.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
436m_md4.o: ../../include/openssl/err.h ../../include/openssl/evp.h
437m_md4.o: ../../include/openssl/lhash.h ../../include/openssl/md4.h
438m_md4.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
439m_md4.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
440m_md4.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
441m_md4.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
442m_md4.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
443m_md4.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
444m_md4.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md4.c
445m_md5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
446m_md5.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
447m_md5.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
448m_md5.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
449m_md5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
450m_md5.o: ../../include/openssl/lhash.h ../../include/openssl/md5.h
451m_md5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
452m_md5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
453m_md5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
454m_md5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
455m_md5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
456m_md5.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
457m_md5.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_md5.c
458m_mdc2.o: ../../e_os.h ../../include/openssl/bio.h
459m_mdc2.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
460m_mdc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
461m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
462m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
463m_mdc2.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
464m_mdc2.o: ../../include/openssl/symhacks.h ../cryptlib.h m_mdc2.c
465m_null.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
466m_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
467m_null.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
468m_null.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
469m_null.o: ../../include/openssl/err.h ../../include/openssl/evp.h
470m_null.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
471m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
472m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
473m_null.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
474m_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
475m_null.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
476m_null.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_null.c
477m_ripemd.o: ../../e_os.h ../../include/openssl/asn1.h
478m_ripemd.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
479m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
480m_ripemd.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
481m_ripemd.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
482m_ripemd.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
483m_ripemd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
484m_ripemd.o: ../../include/openssl/opensslconf.h
485m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
486m_ripemd.o: ../../include/openssl/pkcs7.h ../../include/openssl/ripemd.h
487m_ripemd.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
488m_ripemd.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
489m_ripemd.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
490m_ripemd.o: ../../include/openssl/x509_vfy.h ../cryptlib.h m_ripemd.c
491m_sha.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
492m_sha.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
493m_sha.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
494m_sha.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
495m_sha.o: ../../include/openssl/err.h ../../include/openssl/evp.h
496m_sha.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
497m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
498m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
499m_sha.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
500m_sha.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
501m_sha.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
502m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
503m_sha.o: ../cryptlib.h m_sha.c
504m_sha1.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
505m_sha1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
506m_sha1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
507m_sha1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
508m_sha1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
509m_sha1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
510m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
511m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
512m_sha1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
513m_sha1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
514m_sha1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
515m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
516m_sha1.o: ../cryptlib.h m_sha1.c
517names.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
518names.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
519names.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
520names.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
521names.o: ../../include/openssl/err.h ../../include/openssl/evp.h
522names.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
523names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
524names.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
525names.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
526names.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
527names.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
528names.o: ../../include/openssl/x509_vfy.h ../cryptlib.h names.c
529p5_crpt.o: ../../e_os.h ../../include/openssl/asn1.h
530p5_crpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
531p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
532p5_crpt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
533p5_crpt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
534p5_crpt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
535p5_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
536p5_crpt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
537p5_crpt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
538p5_crpt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
539p5_crpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
540p5_crpt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
541p5_crpt.o: ../cryptlib.h p5_crpt.c
542p5_crpt2.o: ../../e_os.h ../../include/openssl/asn1.h
543p5_crpt2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
544p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
545p5_crpt2.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
546p5_crpt2.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
547p5_crpt2.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
548p5_crpt2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
549p5_crpt2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
550p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
551p5_crpt2.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
552p5_crpt2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
553p5_crpt2.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
554p5_crpt2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt2.c
555p_dec.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
556p_dec.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
557p_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
558p_dec.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
559p_dec.o: ../../include/openssl/err.h ../../include/openssl/evp.h
560p_dec.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
561p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
562p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
563p_dec.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
564p_dec.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
565p_dec.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
566p_dec.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
567p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_dec.c
568p_enc.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
569p_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
570p_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
571p_enc.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
572p_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
573p_enc.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
574p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
575p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
576p_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
577p_enc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
578p_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
579p_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
580p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_enc.c
581p_lib.o: ../../e_os.h ../../include/openssl/asn1.h
582p_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
583p_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
584p_lib.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
585p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
586p_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
587p_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
588p_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
589p_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
590p_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
591p_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
592p_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
593p_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
594p_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
595p_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_lib.c
596p_open.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
597p_open.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
598p_open.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
599p_open.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
600p_open.o: ../../include/openssl/err.h ../../include/openssl/evp.h
601p_open.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
602p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
603p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
604p_open.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
605p_open.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
606p_open.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
607p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
608p_open.o: ../cryptlib.h p_open.c
609p_seal.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
610p_seal.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
611p_seal.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
612p_seal.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
613p_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
614p_seal.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
615p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
616p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
617p_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
618p_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
619p_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
620p_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
621p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_seal.c
622p_sign.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
623p_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
624p_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
625p_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
626p_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
627p_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
628p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
629p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
630p_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
631p_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
632p_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
633p_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_sign.c
634p_verify.o: ../../e_os.h ../../include/openssl/asn1.h
635p_verify.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
636p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
637p_verify.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
638p_verify.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
639p_verify.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
640p_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
641p_verify.o: ../../include/openssl/opensslconf.h
642p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
643p_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
644p_verify.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
645p_verify.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
646p_verify.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_verify.c
diff --git a/src/lib/libcrypto/evp/Makefile.ssl b/src/lib/libcrypto/evp/Makefile.ssl
new file mode 100644
index 0000000000..f33aebd33a
--- /dev/null
+++ b/src/lib/libcrypto/evp/Makefile.ssl
@@ -0,0 +1,1059 @@
1#
2# SSLeay/crypto/evp/Makefile
3#
4
5DIR= evp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=evp_test.c
23TESTDATA=evptests.txt
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= encode.c digest.c evp_enc.c evp_key.c evp_acnf.c \
28 e_des.c e_bf.c e_idea.c e_des3.c \
29 e_rc4.c e_aes.c names.c \
30 e_xcbc_d.c e_rc2.c e_cast.c e_rc5.c \
31 m_null.c m_md2.c m_md4.c m_md5.c m_sha.c m_sha1.c \
32 m_dss.c m_dss1.c m_mdc2.c m_ripemd.c \
33 p_open.c p_seal.c p_sign.c p_verify.c p_lib.c p_enc.c p_dec.c \
34 bio_md.c bio_b64.c bio_enc.c evp_err.c e_null.c \
35 c_all.c c_allc.c c_alld.c evp_lib.c bio_ok.c \
36 evp_pkey.c evp_pbe.c p5_crpt.c p5_crpt2.c
37
38LIBOBJ= encode.o digest.o evp_enc.o evp_key.o evp_acnf.o \
39 e_des.o e_bf.o e_idea.o e_des3.o \
40 e_rc4.o e_aes.o names.o \
41 e_xcbc_d.o e_rc2.o e_cast.o e_rc5.o \
42 m_null.o m_md2.o m_md4.o m_md5.o m_sha.o m_sha1.o \
43 m_dss.o m_dss1.o m_mdc2.o m_ripemd.o \
44 p_open.o p_seal.o p_sign.o p_verify.o p_lib.o p_enc.o p_dec.o \
45 bio_md.o bio_b64.o bio_enc.o evp_err.o e_null.o \
46 c_all.o c_allc.o c_alld.o evp_lib.o bio_ok.o \
47 evp_pkey.o evp_pbe.o p5_crpt.o p5_crpt2.o
48
49SRC= $(LIBSRC)
50
51EXHEADER= evp.h
52HEADER= $(EXHEADER)
53
54ALL= $(GENERAL) $(SRC) $(HEADER)
55
56top:
57 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
58
59all: lib
60
61lib: $(LIBOBJ)
62 $(AR) $(LIB) $(LIBOBJ)
63 $(RANLIB) $(LIB) || echo Never mind.
64 @touch lib
65
66files:
67 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
68
69links:
70 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
71 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
72 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
73 cp $(TESTDATA) ../../test
74 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75
76install:
77 @for i in $(EXHEADER) ; \
78 do \
79 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
80 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
81 done;
82
83tags:
84 ctags $(SRC)
85
86tests:
87
88lint:
89 lint -DLINT $(INCLUDES) $(SRC)>fluff
90
91depend:
92 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
93
94dclean:
95 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
96 mv -f Makefile.new $(MAKEFILE)
97
98clean:
99 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
100
101# DO NOT DELETE THIS LINE -- make depend depends on it.
102
103bio_b64.o: ../../e_os.h ../../include/openssl/aes.h
104bio_b64.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
105bio_b64.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
106bio_b64.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
107bio_b64.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
108bio_b64.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
109bio_b64.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
110bio_b64.o: ../../include/openssl/err.h ../../include/openssl/evp.h
111bio_b64.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
112bio_b64.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
113bio_b64.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
114bio_b64.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
115bio_b64.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
116bio_b64.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
117bio_b64.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
118bio_b64.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
119bio_b64.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
120bio_b64.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
121bio_b64.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
122bio_b64.o: ../cryptlib.h bio_b64.c
123bio_enc.o: ../../e_os.h ../../include/openssl/aes.h
124bio_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
125bio_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
126bio_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
127bio_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
128bio_enc.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
129bio_enc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
130bio_enc.o: ../../include/openssl/err.h ../../include/openssl/evp.h
131bio_enc.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
132bio_enc.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
133bio_enc.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
134bio_enc.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
135bio_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
136bio_enc.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
137bio_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
138bio_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
139bio_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
140bio_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
141bio_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
142bio_enc.o: ../cryptlib.h bio_enc.c
143bio_md.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
144bio_md.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
145bio_md.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
146bio_md.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
147bio_md.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
148bio_md.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
149bio_md.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
150bio_md.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
151bio_md.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
152bio_md.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
153bio_md.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
154bio_md.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
155bio_md.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
156bio_md.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
157bio_md.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
158bio_md.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
159bio_md.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
160bio_md.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
161bio_md.o: ../../include/openssl/ui_compat.h ../cryptlib.h bio_md.c
162bio_ok.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
163bio_ok.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
164bio_ok.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
165bio_ok.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
166bio_ok.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
167bio_ok.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
168bio_ok.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
169bio_ok.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
170bio_ok.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
171bio_ok.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
172bio_ok.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
173bio_ok.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
174bio_ok.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
175bio_ok.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
176bio_ok.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
177bio_ok.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
178bio_ok.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
179bio_ok.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
180bio_ok.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
181bio_ok.o: ../cryptlib.h bio_ok.c
182c_all.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
183c_all.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
184c_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
185c_all.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
186c_all.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
187c_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
188c_all.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
189c_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
190c_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
191c_all.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
192c_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
193c_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
194c_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
195c_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
196c_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
197c_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
198c_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
199c_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
200c_all.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
201c_all.o: ../../include/openssl/ui_compat.h ../cryptlib.h c_all.c
202c_allc.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
203c_allc.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
204c_allc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
205c_allc.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
206c_allc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
207c_allc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
208c_allc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
209c_allc.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
210c_allc.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
211c_allc.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
212c_allc.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
213c_allc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
214c_allc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
215c_allc.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
216c_allc.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
217c_allc.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
218c_allc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
219c_allc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
220c_allc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
221c_allc.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
222c_allc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_allc.c
223c_alld.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
224c_alld.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
225c_alld.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
226c_alld.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
227c_alld.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
228c_alld.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
229c_alld.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
230c_alld.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
231c_alld.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
232c_alld.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
233c_alld.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
234c_alld.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
235c_alld.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
236c_alld.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
237c_alld.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
238c_alld.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
239c_alld.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
240c_alld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
241c_alld.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
242c_alld.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
243c_alld.o: ../../include/openssl/x509_vfy.h ../cryptlib.h c_alld.c
244digest.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
245digest.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
246digest.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
247digest.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
248digest.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
249digest.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
250digest.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
251digest.o: ../../include/openssl/err.h ../../include/openssl/evp.h
252digest.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
253digest.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
254digest.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
255digest.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
256digest.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
257digest.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
258digest.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
259digest.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
260digest.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
261digest.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
262digest.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
263digest.o: ../../include/openssl/ui_compat.h ../cryptlib.h digest.c
264e_aes.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
265e_aes.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
266e_aes.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
267e_aes.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
268e_aes.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
269e_aes.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
270e_aes.o: ../../include/openssl/err.h ../../include/openssl/evp.h
271e_aes.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
272e_aes.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
273e_aes.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
274e_aes.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
275e_aes.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
276e_aes.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
277e_aes.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
278e_aes.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
279e_aes.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
280e_aes.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
281e_aes.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h e_aes.c
282e_aes.o: evp_locl.h
283e_bf.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
284e_bf.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
285e_bf.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
286e_bf.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
287e_bf.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
288e_bf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
289e_bf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
290e_bf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
291e_bf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
292e_bf.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
293e_bf.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
294e_bf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
295e_bf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
296e_bf.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
297e_bf.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
298e_bf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
299e_bf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
300e_bf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
301e_bf.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_bf.c evp_locl.h
302e_cast.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
303e_cast.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
304e_cast.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
305e_cast.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
306e_cast.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
307e_cast.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
308e_cast.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
309e_cast.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
310e_cast.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
311e_cast.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
312e_cast.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
313e_cast.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
314e_cast.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
315e_cast.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
316e_cast.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
317e_cast.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
318e_cast.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
319e_cast.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
320e_cast.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_cast.c evp_locl.h
321e_des.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
322e_des.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
323e_des.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
324e_des.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
325e_des.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
326e_des.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
327e_des.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
328e_des.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
329e_des.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
330e_des.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
331e_des.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
332e_des.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
333e_des.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
334e_des.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
335e_des.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
336e_des.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
337e_des.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
338e_des.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
339e_des.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des.c evp_locl.h
340e_des3.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
341e_des3.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
342e_des3.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
343e_des3.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
344e_des3.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
345e_des3.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
346e_des3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
347e_des3.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
348e_des3.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
349e_des3.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
350e_des3.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
351e_des3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
352e_des3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
353e_des3.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
354e_des3.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
355e_des3.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
356e_des3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
357e_des3.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
358e_des3.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_des3.c evp_locl.h
359e_idea.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
360e_idea.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
361e_idea.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
362e_idea.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
363e_idea.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
364e_idea.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
365e_idea.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
366e_idea.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
367e_idea.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
368e_idea.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
369e_idea.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
370e_idea.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
371e_idea.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
372e_idea.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
373e_idea.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
374e_idea.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
375e_idea.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
376e_idea.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
377e_idea.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_idea.c evp_locl.h
378e_null.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
379e_null.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
380e_null.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
381e_null.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
382e_null.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
383e_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
384e_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
385e_null.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
386e_null.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
387e_null.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
388e_null.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
389e_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
390e_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
391e_null.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
392e_null.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
393e_null.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
394e_null.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
395e_null.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
396e_null.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_null.c
397e_rc2.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
398e_rc2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
399e_rc2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
400e_rc2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
401e_rc2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
402e_rc2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
403e_rc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
404e_rc2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
405e_rc2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
406e_rc2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
407e_rc2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
408e_rc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
409e_rc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
410e_rc2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
411e_rc2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
412e_rc2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
413e_rc2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
414e_rc2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
415e_rc2.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_rc2.c evp_locl.h
416e_rc4.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
417e_rc4.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
418e_rc4.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
419e_rc4.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
420e_rc4.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
421e_rc4.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
422e_rc4.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
423e_rc4.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
424e_rc4.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
425e_rc4.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
426e_rc4.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
427e_rc4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
428e_rc4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
429e_rc4.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
430e_rc4.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
431e_rc4.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
432e_rc4.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
433e_rc4.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
434e_rc4.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_rc4.c
435e_rc5.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
436e_rc5.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
437e_rc5.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
438e_rc5.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
439e_rc5.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
440e_rc5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
441e_rc5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
442e_rc5.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
443e_rc5.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
444e_rc5.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
445e_rc5.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
446e_rc5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
447e_rc5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
448e_rc5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
449e_rc5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
450e_rc5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
451e_rc5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
452e_rc5.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
453e_rc5.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_rc5.c evp_locl.h
454e_xcbc_d.o: ../../e_os.h ../../include/openssl/aes.h
455e_xcbc_d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
456e_xcbc_d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
457e_xcbc_d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
458e_xcbc_d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
459e_xcbc_d.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
460e_xcbc_d.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
461e_xcbc_d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
462e_xcbc_d.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
463e_xcbc_d.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
464e_xcbc_d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
465e_xcbc_d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
466e_xcbc_d.o: ../../include/openssl/opensslconf.h
467e_xcbc_d.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
468e_xcbc_d.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
469e_xcbc_d.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
470e_xcbc_d.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
471e_xcbc_d.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
472e_xcbc_d.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
473e_xcbc_d.o: ../../include/openssl/ui_compat.h ../cryptlib.h e_xcbc_d.c
474encode.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
475encode.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
476encode.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
477encode.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
478encode.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
479encode.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
480encode.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
481encode.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
482encode.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
483encode.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
484encode.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
485encode.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
486encode.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
487encode.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
488encode.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
489encode.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
490encode.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
491encode.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
492encode.o: ../../include/openssl/ui_compat.h ../cryptlib.h encode.c
493evp_acnf.o: ../../e_os.h ../../include/openssl/aes.h
494evp_acnf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
495evp_acnf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
496evp_acnf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
497evp_acnf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
498evp_acnf.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
499evp_acnf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
500evp_acnf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
501evp_acnf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
502evp_acnf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
503evp_acnf.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
504evp_acnf.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
505evp_acnf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
506evp_acnf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
507evp_acnf.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
508evp_acnf.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
509evp_acnf.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
510evp_acnf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
511evp_acnf.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
512evp_acnf.o: ../../include/openssl/ui_compat.h ../cryptlib.h evp_acnf.c
513evp_enc.o: ../../e_os.h ../../include/openssl/aes.h
514evp_enc.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
515evp_enc.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
516evp_enc.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
517evp_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
518evp_enc.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
519evp_enc.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
520evp_enc.o: ../../include/openssl/engine.h ../../include/openssl/err.h
521evp_enc.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
522evp_enc.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
523evp_enc.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
524evp_enc.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
525evp_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
526evp_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
527evp_enc.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
528evp_enc.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
529evp_enc.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
530evp_enc.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
531evp_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
532evp_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
533evp_enc.o: ../cryptlib.h evp_enc.c evp_locl.h
534evp_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
535evp_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
536evp_err.o: ../../include/openssl/bn.h ../../include/openssl/cast.h
537evp_err.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
538evp_err.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
539evp_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
540evp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
541evp_err.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
542evp_err.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
543evp_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
544evp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
545evp_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
546evp_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
547evp_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
548evp_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
549evp_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
550evp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
551evp_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
552evp_err.o: evp_err.c
553evp_key.o: ../../e_os.h ../../include/openssl/aes.h
554evp_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
555evp_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
556evp_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
557evp_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
558evp_key.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
559evp_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
560evp_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
561evp_key.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
562evp_key.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
563evp_key.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
564evp_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
565evp_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
566evp_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
567evp_key.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
568evp_key.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
569evp_key.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
570evp_key.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
571evp_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
572evp_key.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
573evp_key.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_key.c
574evp_lib.o: ../../e_os.h ../../include/openssl/aes.h
575evp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
576evp_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
577evp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
578evp_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
579evp_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
580evp_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
581evp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
582evp_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
583evp_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
584evp_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
585evp_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
586evp_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
587evp_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
588evp_lib.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
589evp_lib.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
590evp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
591evp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
592evp_lib.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
593evp_lib.o: ../cryptlib.h evp_lib.c
594evp_pbe.o: ../../e_os.h ../../include/openssl/aes.h
595evp_pbe.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
596evp_pbe.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
597evp_pbe.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
598evp_pbe.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
599evp_pbe.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
600evp_pbe.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
601evp_pbe.o: ../../include/openssl/err.h ../../include/openssl/evp.h
602evp_pbe.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
603evp_pbe.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
604evp_pbe.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
605evp_pbe.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
606evp_pbe.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
607evp_pbe.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
608evp_pbe.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
609evp_pbe.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
610evp_pbe.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
611evp_pbe.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
612evp_pbe.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
613evp_pbe.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
614evp_pbe.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pbe.c
615evp_pkey.o: ../../e_os.h ../../include/openssl/aes.h
616evp_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
617evp_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
618evp_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
619evp_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
620evp_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
621evp_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
622evp_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
623evp_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
624evp_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
625evp_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
626evp_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
627evp_pkey.o: ../../include/openssl/opensslconf.h
628evp_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
629evp_pkey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
630evp_pkey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
631evp_pkey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
632evp_pkey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
633evp_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
634evp_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
635evp_pkey.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
636evp_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h evp_pkey.c
637m_dss.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
638m_dss.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
639m_dss.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
640m_dss.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
641m_dss.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
642m_dss.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
643m_dss.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
644m_dss.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
645m_dss.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
646m_dss.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
647m_dss.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
648m_dss.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
649m_dss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
650m_dss.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
651m_dss.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
652m_dss.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
653m_dss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
654m_dss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
655m_dss.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
656m_dss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
657m_dss.o: ../cryptlib.h m_dss.c
658m_dss1.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
659m_dss1.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
660m_dss1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
661m_dss1.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
662m_dss1.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
663m_dss1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
664m_dss1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
665m_dss1.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
666m_dss1.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
667m_dss1.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
668m_dss1.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
669m_dss1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
670m_dss1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
671m_dss1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
672m_dss1.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
673m_dss1.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
674m_dss1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
675m_dss1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
676m_dss1.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
677m_dss1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
678m_dss1.o: ../cryptlib.h m_dss1.c
679m_md2.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
680m_md2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
681m_md2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
682m_md2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
683m_md2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
684m_md2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
685m_md2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
686m_md2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
687m_md2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
688m_md2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
689m_md2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
690m_md2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
691m_md2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
692m_md2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
693m_md2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
694m_md2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
695m_md2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
696m_md2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
697m_md2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
698m_md2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
699m_md2.o: ../cryptlib.h m_md2.c
700m_md4.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
701m_md4.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
702m_md4.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
703m_md4.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
704m_md4.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
705m_md4.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
706m_md4.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
707m_md4.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
708m_md4.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
709m_md4.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
710m_md4.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
711m_md4.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
712m_md4.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
713m_md4.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
714m_md4.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
715m_md4.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
716m_md4.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
717m_md4.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
718m_md4.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
719m_md4.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
720m_md4.o: ../cryptlib.h m_md4.c
721m_md5.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
722m_md5.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
723m_md5.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
724m_md5.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
725m_md5.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
726m_md5.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
727m_md5.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
728m_md5.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
729m_md5.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
730m_md5.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
731m_md5.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
732m_md5.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
733m_md5.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
734m_md5.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
735m_md5.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
736m_md5.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
737m_md5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
738m_md5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
739m_md5.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
740m_md5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
741m_md5.o: ../cryptlib.h m_md5.c
742m_mdc2.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
743m_mdc2.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
744m_mdc2.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
745m_mdc2.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
746m_mdc2.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
747m_mdc2.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
748m_mdc2.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
749m_mdc2.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
750m_mdc2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
751m_mdc2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
752m_mdc2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
753m_mdc2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
754m_mdc2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
755m_mdc2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
756m_mdc2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
757m_mdc2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
758m_mdc2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
759m_mdc2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
760m_mdc2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
761m_mdc2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
762m_mdc2.o: ../cryptlib.h m_mdc2.c
763m_null.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
764m_null.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
765m_null.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
766m_null.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
767m_null.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
768m_null.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
769m_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
770m_null.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
771m_null.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
772m_null.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
773m_null.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
774m_null.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
775m_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
776m_null.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
777m_null.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
778m_null.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
779m_null.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
780m_null.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
781m_null.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
782m_null.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
783m_null.o: ../cryptlib.h m_null.c
784m_ripemd.o: ../../e_os.h ../../include/openssl/aes.h
785m_ripemd.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
786m_ripemd.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
787m_ripemd.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
788m_ripemd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
789m_ripemd.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
790m_ripemd.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
791m_ripemd.o: ../../include/openssl/err.h ../../include/openssl/evp.h
792m_ripemd.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
793m_ripemd.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
794m_ripemd.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
795m_ripemd.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
796m_ripemd.o: ../../include/openssl/opensslconf.h
797m_ripemd.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
798m_ripemd.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
799m_ripemd.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
800m_ripemd.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
801m_ripemd.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
802m_ripemd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
803m_ripemd.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
804m_ripemd.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
805m_ripemd.o: ../cryptlib.h m_ripemd.c
806m_sha.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
807m_sha.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
808m_sha.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
809m_sha.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
810m_sha.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
811m_sha.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
812m_sha.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
813m_sha.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
814m_sha.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
815m_sha.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
816m_sha.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
817m_sha.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
818m_sha.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
819m_sha.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
820m_sha.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
821m_sha.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
822m_sha.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
823m_sha.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
824m_sha.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
825m_sha.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
826m_sha.o: ../cryptlib.h m_sha.c
827m_sha1.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
828m_sha1.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
829m_sha1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
830m_sha1.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
831m_sha1.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
832m_sha1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
833m_sha1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
834m_sha1.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
835m_sha1.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
836m_sha1.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
837m_sha1.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
838m_sha1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
839m_sha1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
840m_sha1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
841m_sha1.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
842m_sha1.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
843m_sha1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
844m_sha1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
845m_sha1.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
846m_sha1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
847m_sha1.o: ../cryptlib.h m_sha1.c
848names.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
849names.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
850names.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
851names.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
852names.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
853names.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
854names.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
855names.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
856names.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
857names.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
858names.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
859names.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
860names.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
861names.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
862names.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
863names.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
864names.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
865names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
866names.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
867names.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
868names.o: ../cryptlib.h names.c
869p5_crpt.o: ../../e_os.h ../../include/openssl/aes.h
870p5_crpt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
871p5_crpt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
872p5_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
873p5_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
874p5_crpt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
875p5_crpt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
876p5_crpt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
877p5_crpt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
878p5_crpt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
879p5_crpt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
880p5_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
881p5_crpt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
882p5_crpt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
883p5_crpt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
884p5_crpt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
885p5_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
886p5_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
887p5_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
888p5_crpt.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
889p5_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p5_crpt.c
890p5_crpt2.o: ../../e_os.h ../../include/openssl/aes.h
891p5_crpt2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
892p5_crpt2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
893p5_crpt2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
894p5_crpt2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
895p5_crpt2.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
896p5_crpt2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
897p5_crpt2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
898p5_crpt2.o: ../../include/openssl/hmac.h ../../include/openssl/idea.h
899p5_crpt2.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
900p5_crpt2.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
901p5_crpt2.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
902p5_crpt2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
903p5_crpt2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
904p5_crpt2.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
905p5_crpt2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
906p5_crpt2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
907p5_crpt2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
908p5_crpt2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
909p5_crpt2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
910p5_crpt2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
911p5_crpt2.o: ../cryptlib.h p5_crpt2.c
912p_dec.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
913p_dec.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
914p_dec.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
915p_dec.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
916p_dec.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
917p_dec.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
918p_dec.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
919p_dec.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
920p_dec.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
921p_dec.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
922p_dec.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
923p_dec.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
924p_dec.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
925p_dec.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
926p_dec.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
927p_dec.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
928p_dec.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
929p_dec.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
930p_dec.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
931p_dec.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
932p_dec.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_dec.c
933p_enc.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
934p_enc.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
935p_enc.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
936p_enc.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
937p_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
938p_enc.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
939p_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
940p_enc.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
941p_enc.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
942p_enc.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
943p_enc.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
944p_enc.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
945p_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
946p_enc.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
947p_enc.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
948p_enc.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
949p_enc.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
950p_enc.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
951p_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
952p_enc.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
953p_enc.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_enc.c
954p_lib.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
955p_lib.o: ../../include/openssl/asn1_mac.h ../../include/openssl/bio.h
956p_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
957p_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
958p_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
959p_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
960p_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
961p_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
962p_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
963p_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
964p_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
965p_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
966p_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
967p_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
968p_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
969p_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
970p_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
971p_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
972p_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
973p_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
974p_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_lib.c
975p_open.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
976p_open.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
977p_open.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
978p_open.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
979p_open.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
980p_open.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
981p_open.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
982p_open.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
983p_open.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
984p_open.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
985p_open.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
986p_open.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
987p_open.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
988p_open.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
989p_open.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
990p_open.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
991p_open.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
992p_open.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
993p_open.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
994p_open.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
995p_open.o: ../cryptlib.h p_open.c
996p_seal.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
997p_seal.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
998p_seal.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
999p_seal.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1000p_seal.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1001p_seal.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1002p_seal.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1003p_seal.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1004p_seal.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1005p_seal.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1006p_seal.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1007p_seal.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1008p_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1009p_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
1010p_seal.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
1011p_seal.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
1012p_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
1013p_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
1014p_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
1015p_seal.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
1016p_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p_seal.c
1017p_sign.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
1018p_sign.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
1019p_sign.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
1020p_sign.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
1021p_sign.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
1022p_sign.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
1023p_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
1024p_sign.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
1025p_sign.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
1026p_sign.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
1027p_sign.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
1028p_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
1029p_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1030p_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1031p_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1032p_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1033p_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1034p_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1035p_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1036p_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1037p_sign.o: ../cryptlib.h p_sign.c
1038p_verify.o: ../../e_os.h ../../include/openssl/aes.h
1039p_verify.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
1040p_verify.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
1041p_verify.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
1042p_verify.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
1043p_verify.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
1044p_verify.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
1045p_verify.o: ../../include/openssl/err.h ../../include/openssl/evp.h
1046p_verify.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
1047p_verify.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
1048p_verify.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
1049p_verify.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
1050p_verify.o: ../../include/openssl/opensslconf.h
1051p_verify.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
1052p_verify.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
1053p_verify.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
1054p_verify.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
1055p_verify.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
1056p_verify.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
1057p_verify.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
1058p_verify.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
1059p_verify.o: ../cryptlib.h p_verify.c
diff --git a/src/lib/libcrypto/evp/bio_b64.c b/src/lib/libcrypto/evp/bio_b64.c
index fa5cbc7eb1..33349c2f98 100644
--- a/src/lib/libcrypto/evp/bio_b64.c
+++ b/src/lib/libcrypto/evp/bio_b64.c
@@ -165,7 +165,7 @@ static int b64_read(BIO *b, char *out, int outl)
165 { 165 {
166 i=ctx->buf_len-ctx->buf_off; 166 i=ctx->buf_len-ctx->buf_off;
167 if (i > outl) i=outl; 167 if (i > outl) i=outl;
168 OPENSSL_assert(ctx->buf_off+i < (int)sizeof(ctx->buf)); 168 OPENSSL_assert(ctx->buf_off+i < sizeof ctx->buf);
169 memcpy(out,&(ctx->buf[ctx->buf_off]),i); 169 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
170 ret=i; 170 ret=i;
171 out+=i; 171 out+=i;
diff --git a/src/lib/libcrypto/evp/bio_enc.c b/src/lib/libcrypto/evp/bio_enc.c
index f6ac94c6e1..b8cda1a9f0 100644
--- a/src/lib/libcrypto/evp/bio_enc.c
+++ b/src/lib/libcrypto/evp/bio_enc.c
@@ -405,8 +405,8 @@ EVP_CIPHER_ctx *c;
405 } 405 }
406*/ 406*/
407 407
408void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, const unsigned char *k, 408void BIO_set_cipher(BIO *b, const EVP_CIPHER *c, unsigned char *k,
409 const unsigned char *i, int e) 409 unsigned char *i, int e)
410 { 410 {
411 BIO_ENC_CTX *ctx; 411 BIO_ENC_CTX *ctx;
412 412
diff --git a/src/lib/libcrypto/evp/bio_md.c b/src/lib/libcrypto/evp/bio_md.c
index d648ac6da6..f4aa41ac4b 100644
--- a/src/lib/libcrypto/evp/bio_md.c
+++ b/src/lib/libcrypto/evp/bio_md.c
@@ -153,7 +153,7 @@ static int md_write(BIO *b, const char *in, int inl)
153 { 153 {
154 if (ret > 0) 154 if (ret > 0)
155 { 155 {
156 EVP_DigestUpdate(ctx,(const unsigned char *)in, 156 EVP_DigestUpdate(ctx,(unsigned char *)in,
157 (unsigned int)ret); 157 (unsigned int)ret);
158 } 158 }
159 } 159 }
@@ -192,13 +192,8 @@ static long md_ctrl(BIO *b, int cmd, long num, void *ptr)
192 ret=0; 192 ret=0;
193 break; 193 break;
194 case BIO_C_GET_MD_CTX: 194 case BIO_C_GET_MD_CTX:
195 if (b->init) 195 pctx=ptr;
196 { 196 *pctx=ctx;
197 pctx=ptr;
198 *pctx=ctx;
199 }
200 else
201 ret=0;
202 break; 197 break;
203 case BIO_C_SET_MD_CTX: 198 case BIO_C_SET_MD_CTX:
204 if (b->init) 199 if (b->init)
diff --git a/src/lib/libcrypto/evp/bio_ok.c b/src/lib/libcrypto/evp/bio_ok.c
new file mode 100644
index 0000000000..4e3f10141b
--- /dev/null
+++ b/src/lib/libcrypto/evp/bio_ok.c
@@ -0,0 +1,575 @@
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 existing 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 letting the application to read the data.
84
85 BIO_f_reliable tries to solve both problems, so that you can
86 read and write arbitrary 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 further 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 output
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 initially 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, const char *buf, int num);
129static int ok_read(BIO *h, char *buf, int size);
130static long ok_ctrl(BIO *h, int cmd, long arg1, void *arg2);
131static int ok_new(BIO *h);
132static int ok_free(BIO *data);
133static long ok_callback_ctrl(BIO *h, int cmd, bio_info_cb *fp);
134
135static void sig_out(BIO* b);
136static void sig_in(BIO* b);
137static void block_out(BIO* b);
138static void block_in(BIO* b);
139#define OK_BLOCK_SIZE (1024*4)
140#define OK_BLOCK_BLOCK 4
141#define IOBS (OK_BLOCK_SIZE+ OK_BLOCK_BLOCK+ 3*EVP_MAX_MD_SIZE)
142#define WELLKNOWN "The quick brown fox jumped over the lazy dog's back."
143
144#ifndef L_ENDIAN
145#define swapem(x) \
146 ((unsigned long int)((((unsigned long int)(x) & 0x000000ffU) << 24) | \
147 (((unsigned long int)(x) & 0x0000ff00U) << 8) | \
148 (((unsigned long int)(x) & 0x00ff0000U) >> 8) | \
149 (((unsigned long int)(x) & 0xff000000U) >> 24)))
150#else
151#define swapem(x) (x)
152#endif
153
154typedef struct ok_struct
155 {
156 int buf_len;
157 int buf_off;
158 int buf_len_save;
159 int buf_off_save;
160 int cont; /* <= 0 when finished */
161 int finished;
162 EVP_MD_CTX md;
163 int blockout; /* output block is ready */
164 int sigio; /* must process signature */
165 unsigned char buf[IOBS];
166 } BIO_OK_CTX;
167
168static BIO_METHOD methods_ok=
169 {
170 BIO_TYPE_CIPHER,"reliable",
171 ok_write,
172 ok_read,
173 NULL, /* ok_puts, */
174 NULL, /* ok_gets, */
175 ok_ctrl,
176 ok_new,
177 ok_free,
178 ok_callback_ctrl,
179 };
180
181BIO_METHOD *BIO_f_reliable(void)
182 {
183 return(&methods_ok);
184 }
185
186static int ok_new(BIO *bi)
187 {
188 BIO_OK_CTX *ctx;
189
190 ctx=(BIO_OK_CTX *)OPENSSL_malloc(sizeof(BIO_OK_CTX));
191 if (ctx == NULL) return(0);
192
193 ctx->buf_len=0;
194 ctx->buf_off=0;
195 ctx->buf_len_save=0;
196 ctx->buf_off_save=0;
197 ctx->cont=1;
198 ctx->finished=0;
199 ctx->blockout= 0;
200 ctx->sigio=1;
201
202 EVP_MD_CTX_init(&ctx->md);
203
204 bi->init=0;
205 bi->ptr=(char *)ctx;
206 bi->flags=0;
207 return(1);
208 }
209
210static int ok_free(BIO *a)
211 {
212 if (a == NULL) return(0);
213 EVP_MD_CTX_cleanup(&((BIO_OK_CTX *)a->ptr)->md);
214 OPENSSL_cleanse(a->ptr,sizeof(BIO_OK_CTX));
215 OPENSSL_free(a->ptr);
216 a->ptr=NULL;
217 a->init=0;
218 a->flags=0;
219 return(1);
220 }
221
222static int ok_read(BIO *b, char *out, int outl)
223 {
224 int ret=0,i,n;
225 BIO_OK_CTX *ctx;
226
227 if (out == NULL) return(0);
228 ctx=(BIO_OK_CTX *)b->ptr;
229
230 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
231
232 while(outl > 0)
233 {
234
235 /* copy clean bytes to output buffer */
236 if (ctx->blockout)
237 {
238 i=ctx->buf_len-ctx->buf_off;
239 if (i > outl) i=outl;
240 memcpy(out,&(ctx->buf[ctx->buf_off]),i);
241 ret+=i;
242 out+=i;
243 outl-=i;
244 ctx->buf_off+=i;
245
246 /* all clean bytes are out */
247 if (ctx->buf_len == ctx->buf_off)
248 {
249 ctx->buf_off=0;
250
251 /* copy start of the next block into proper place */
252 if(ctx->buf_len_save- ctx->buf_off_save > 0)
253 {
254 ctx->buf_len= ctx->buf_len_save- ctx->buf_off_save;
255 memmove(ctx->buf, &(ctx->buf[ctx->buf_off_save]),
256 ctx->buf_len);
257 }
258 else
259 {
260 ctx->buf_len=0;
261 }
262 ctx->blockout= 0;
263 }
264 }
265
266 /* output buffer full -- cancel */
267 if (outl == 0) break;
268
269 /* no clean bytes in buffer -- fill it */
270 n=IOBS- ctx->buf_len;
271 i=BIO_read(b->next_bio,&(ctx->buf[ctx->buf_len]),n);
272
273 if (i <= 0) break; /* nothing new */
274
275 ctx->buf_len+= i;
276
277 /* no signature yet -- check if we got one */
278 if (ctx->sigio == 1) sig_in(b);
279
280 /* signature ok -- check if we got block */
281 if (ctx->sigio == 0) block_in(b);
282
283 /* invalid block -- cancel */
284 if (ctx->cont <= 0) break;
285
286 }
287
288 BIO_clear_retry_flags(b);
289 BIO_copy_next_retry(b);
290 return(ret);
291 }
292
293static int ok_write(BIO *b, const char *in, int inl)
294 {
295 int ret=0,n,i;
296 BIO_OK_CTX *ctx;
297
298 ctx=(BIO_OK_CTX *)b->ptr;
299 ret=inl;
300
301 if ((ctx == NULL) || (b->next_bio == NULL) || (b->init == 0)) return(0);
302
303 if(ctx->sigio) sig_out(b);
304
305 do{
306 BIO_clear_retry_flags(b);
307 n=ctx->buf_len-ctx->buf_off;
308 while (ctx->blockout && 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 if(!BIO_should_retry(b))
315 ctx->cont= 0;
316 return(i);
317 }
318 ctx->buf_off+=i;
319 n-=i;
320 }
321
322 /* at this point all pending data has been written */
323 ctx->blockout= 0;
324 if (ctx->buf_len == ctx->buf_off)
325 {
326 ctx->buf_len=OK_BLOCK_BLOCK;
327 ctx->buf_off=0;
328 }
329
330 if ((in == NULL) || (inl <= 0)) return(0);
331
332 n= (inl+ ctx->buf_len > OK_BLOCK_SIZE+ OK_BLOCK_BLOCK) ?
333 OK_BLOCK_SIZE+ OK_BLOCK_BLOCK- ctx->buf_len : inl;
334
335 memcpy((unsigned char *)(&(ctx->buf[ctx->buf_len])),(unsigned char *)in,n);
336 ctx->buf_len+= n;
337 inl-=n;
338 in+=n;
339
340 if(ctx->buf_len >= OK_BLOCK_SIZE+ OK_BLOCK_BLOCK)
341 {
342 block_out(b);
343 }
344 }while(inl > 0);
345
346 BIO_clear_retry_flags(b);
347 BIO_copy_next_retry(b);
348 return(ret);
349 }
350
351static long ok_ctrl(BIO *b, int cmd, long num, void *ptr)
352 {
353 BIO_OK_CTX *ctx;
354 EVP_MD *md;
355 const EVP_MD **ppmd;
356 long ret=1;
357 int i;
358
359 ctx=b->ptr;
360
361 switch (cmd)
362 {
363 case BIO_CTRL_RESET:
364 ctx->buf_len=0;
365 ctx->buf_off=0;
366 ctx->buf_len_save=0;
367 ctx->buf_off_save=0;
368 ctx->cont=1;
369 ctx->finished=0;
370 ctx->blockout= 0;
371 ctx->sigio=1;
372 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
373 break;
374 case BIO_CTRL_EOF: /* More to read */
375 if (ctx->cont <= 0)
376 ret=1;
377 else
378 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
379 break;
380 case BIO_CTRL_PENDING: /* More to read in buffer */
381 case BIO_CTRL_WPENDING: /* More to read in buffer */
382 ret=ctx->blockout ? ctx->buf_len-ctx->buf_off : 0;
383 if (ret <= 0)
384 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
385 break;
386 case BIO_CTRL_FLUSH:
387 /* do a final write */
388 if(ctx->blockout == 0)
389 block_out(b);
390
391 while (ctx->blockout)
392 {
393 i=ok_write(b,NULL,0);
394 if (i < 0)
395 {
396 ret=i;
397 break;
398 }
399 }
400
401 ctx->finished=1;
402 ctx->buf_off=ctx->buf_len=0;
403 ctx->cont=(int)ret;
404
405 /* Finally flush the underlying BIO */
406 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
407 break;
408 case BIO_C_DO_STATE_MACHINE:
409 BIO_clear_retry_flags(b);
410 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
411 BIO_copy_next_retry(b);
412 break;
413 case BIO_CTRL_INFO:
414 ret=(long)ctx->cont;
415 break;
416 case BIO_C_SET_MD:
417 md=ptr;
418 EVP_DigestInit_ex(&ctx->md, md, NULL);
419 b->init=1;
420 break;
421 case BIO_C_GET_MD:
422 if (b->init)
423 {
424 ppmd=ptr;
425 *ppmd=ctx->md.digest;
426 }
427 else
428 ret=0;
429 break;
430 default:
431 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
432 break;
433 }
434 return(ret);
435 }
436
437static long ok_callback_ctrl(BIO *b, int cmd, bio_info_cb *fp)
438 {
439 long ret=1;
440
441 if (b->next_bio == NULL) return(0);
442 switch (cmd)
443 {
444 default:
445 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
446 break;
447 }
448 return(ret);
449 }
450
451static void longswap(void *_ptr, int len)
452{
453#ifndef L_ENDIAN
454 int i;
455 char *ptr=_ptr;
456
457 for(i= 0;i < len;i+= 4){
458 *((unsigned long *)&(ptr[i]))= swapem(*((unsigned long *)&(ptr[i])));
459 }
460#endif
461}
462
463static void sig_out(BIO* b)
464 {
465 BIO_OK_CTX *ctx;
466 EVP_MD_CTX *md;
467
468 ctx=b->ptr;
469 md=&ctx->md;
470
471 if(ctx->buf_len+ 2* md->digest->md_size > OK_BLOCK_SIZE) return;
472
473 EVP_DigestInit_ex(md, md->digest, NULL);
474 /* FIXME: there's absolutely no guarantee this makes any sense at all,
475 * particularly now EVP_MD_CTX has been restructured.
476 */
477 RAND_pseudo_bytes(md->md_data, md->digest->md_size);
478 memcpy(&(ctx->buf[ctx->buf_len]), md->md_data, md->digest->md_size);
479 longswap(&(ctx->buf[ctx->buf_len]), md->digest->md_size);
480 ctx->buf_len+= md->digest->md_size;
481
482 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
483 EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
484 ctx->buf_len+= md->digest->md_size;
485 ctx->blockout= 1;
486 ctx->sigio= 0;
487 }
488
489static void sig_in(BIO* b)
490 {
491 BIO_OK_CTX *ctx;
492 EVP_MD_CTX *md;
493 unsigned char tmp[EVP_MAX_MD_SIZE];
494 int ret= 0;
495
496 ctx=b->ptr;
497 md=&ctx->md;
498
499 if(ctx->buf_len- ctx->buf_off < 2* md->digest->md_size) return;
500
501 EVP_DigestInit_ex(md, md->digest, NULL);
502 memcpy(md->md_data, &(ctx->buf[ctx->buf_off]), md->digest->md_size);
503 longswap(md->md_data, md->digest->md_size);
504 ctx->buf_off+= md->digest->md_size;
505
506 EVP_DigestUpdate(md, WELLKNOWN, strlen(WELLKNOWN));
507 EVP_DigestFinal_ex(md, tmp, NULL);
508 ret= memcmp(&(ctx->buf[ctx->buf_off]), tmp, md->digest->md_size) == 0;
509 ctx->buf_off+= md->digest->md_size;
510 if(ret == 1)
511 {
512 ctx->sigio= 0;
513 if(ctx->buf_len != ctx->buf_off)
514 {
515 memmove(ctx->buf, &(ctx->buf[ctx->buf_off]), ctx->buf_len- ctx->buf_off);
516 }
517 ctx->buf_len-= ctx->buf_off;
518 ctx->buf_off= 0;
519 }
520 else
521 {
522 ctx->cont= 0;
523 }
524 }
525
526static void block_out(BIO* b)
527 {
528 BIO_OK_CTX *ctx;
529 EVP_MD_CTX *md;
530 unsigned long tl;
531
532 ctx=b->ptr;
533 md=&ctx->md;
534
535 tl= ctx->buf_len- OK_BLOCK_BLOCK;
536 tl= swapem(tl);
537 memcpy(ctx->buf, &tl, OK_BLOCK_BLOCK);
538 tl= swapem(tl);
539 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
540 EVP_DigestFinal_ex(md, &(ctx->buf[ctx->buf_len]), NULL);
541 ctx->buf_len+= md->digest->md_size;
542 ctx->blockout= 1;
543 }
544
545static void block_in(BIO* b)
546 {
547 BIO_OK_CTX *ctx;
548 EVP_MD_CTX *md;
549 long tl= 0;
550 unsigned char tmp[EVP_MAX_MD_SIZE];
551
552 ctx=b->ptr;
553 md=&ctx->md;
554
555 memcpy(&tl, ctx->buf, OK_BLOCK_BLOCK);
556 tl= swapem(tl);
557 if (ctx->buf_len < tl+ OK_BLOCK_BLOCK+ md->digest->md_size) return;
558
559 EVP_DigestUpdate(md, (unsigned char*) &(ctx->buf[OK_BLOCK_BLOCK]), tl);
560 EVP_DigestFinal_ex(md, tmp, NULL);
561 if(memcmp(&(ctx->buf[tl+ OK_BLOCK_BLOCK]), tmp, md->digest->md_size) == 0)
562 {
563 /* there might be parts from next block lurking around ! */
564 ctx->buf_off_save= tl+ OK_BLOCK_BLOCK+ md->digest->md_size;
565 ctx->buf_len_save= ctx->buf_len;
566 ctx->buf_off= OK_BLOCK_BLOCK;
567 ctx->buf_len= tl+ OK_BLOCK_BLOCK;
568 ctx->blockout= 1;
569 }
570 else
571 {
572 ctx->cont= 0;
573 }
574 }
575
diff --git a/src/lib/libcrypto/evp/c_all.c b/src/lib/libcrypto/evp/c_all.c
index a5da52e62d..fa60a73ead 100644
--- a/src/lib/libcrypto/evp/c_all.c
+++ b/src/lib/libcrypto/evp/c_all.c
@@ -74,12 +74,6 @@ void OpenSSL_add_all_algorithms(void)
74 74
75void OPENSSL_add_all_algorithms_noconf(void) 75void OPENSSL_add_all_algorithms_noconf(void)
76 { 76 {
77 /*
78 * For the moment OPENSSL_cpuid_setup does something
79 * only on IA-32, but we reserve the option for all
80 * platforms...
81 */
82 OPENSSL_cpuid_setup();
83 OpenSSL_add_all_ciphers(); 77 OpenSSL_add_all_ciphers();
84 OpenSSL_add_all_digests(); 78 OpenSSL_add_all_digests();
85#ifndef OPENSSL_NO_ENGINE 79#ifndef OPENSSL_NO_ENGINE
diff --git a/src/lib/libcrypto/evp/c_allc.c b/src/lib/libcrypto/evp/c_allc.c
new file mode 100644
index 0000000000..fc96812365
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_allc.c
@@ -0,0 +1,188 @@
1/* crypto/evp/c_allc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_ciphers(void)
66 {
67
68#ifndef OPENSSL_NO_DES
69 EVP_add_cipher(EVP_des_cfb());
70 EVP_add_cipher(EVP_des_cfb1());
71 EVP_add_cipher(EVP_des_cfb8());
72 EVP_add_cipher(EVP_des_ede_cfb());
73 EVP_add_cipher(EVP_des_ede3_cfb());
74
75 EVP_add_cipher(EVP_des_ofb());
76 EVP_add_cipher(EVP_des_ede_ofb());
77 EVP_add_cipher(EVP_des_ede3_ofb());
78
79 EVP_add_cipher(EVP_desx_cbc());
80 EVP_add_cipher_alias(SN_desx_cbc,"DESX");
81 EVP_add_cipher_alias(SN_desx_cbc,"desx");
82
83 EVP_add_cipher(EVP_des_cbc());
84 EVP_add_cipher_alias(SN_des_cbc,"DES");
85 EVP_add_cipher_alias(SN_des_cbc,"des");
86 EVP_add_cipher(EVP_des_ede_cbc());
87 EVP_add_cipher(EVP_des_ede3_cbc());
88 EVP_add_cipher_alias(SN_des_ede3_cbc,"DES3");
89 EVP_add_cipher_alias(SN_des_ede3_cbc,"des3");
90
91 EVP_add_cipher(EVP_des_ecb());
92 EVP_add_cipher(EVP_des_ede());
93 EVP_add_cipher(EVP_des_ede3());
94#endif
95
96#ifndef OPENSSL_NO_RC4
97 EVP_add_cipher(EVP_rc4());
98 EVP_add_cipher(EVP_rc4_40());
99#endif
100
101#ifndef OPENSSL_NO_IDEA
102 EVP_add_cipher(EVP_idea_ecb());
103 EVP_add_cipher(EVP_idea_cfb());
104 EVP_add_cipher(EVP_idea_ofb());
105 EVP_add_cipher(EVP_idea_cbc());
106 EVP_add_cipher_alias(SN_idea_cbc,"IDEA");
107 EVP_add_cipher_alias(SN_idea_cbc,"idea");
108#endif
109
110#ifndef OPENSSL_NO_RC2
111 EVP_add_cipher(EVP_rc2_ecb());
112 EVP_add_cipher(EVP_rc2_cfb());
113 EVP_add_cipher(EVP_rc2_ofb());
114 EVP_add_cipher(EVP_rc2_cbc());
115 EVP_add_cipher(EVP_rc2_40_cbc());
116 EVP_add_cipher(EVP_rc2_64_cbc());
117 EVP_add_cipher_alias(SN_rc2_cbc,"RC2");
118 EVP_add_cipher_alias(SN_rc2_cbc,"rc2");
119#endif
120
121#ifndef OPENSSL_NO_BF
122 EVP_add_cipher(EVP_bf_ecb());
123 EVP_add_cipher(EVP_bf_cfb());
124 EVP_add_cipher(EVP_bf_ofb());
125 EVP_add_cipher(EVP_bf_cbc());
126 EVP_add_cipher_alias(SN_bf_cbc,"BF");
127 EVP_add_cipher_alias(SN_bf_cbc,"bf");
128 EVP_add_cipher_alias(SN_bf_cbc,"blowfish");
129#endif
130
131#ifndef OPENSSL_NO_CAST
132 EVP_add_cipher(EVP_cast5_ecb());
133 EVP_add_cipher(EVP_cast5_cfb());
134 EVP_add_cipher(EVP_cast5_ofb());
135 EVP_add_cipher(EVP_cast5_cbc());
136 EVP_add_cipher_alias(SN_cast5_cbc,"CAST");
137 EVP_add_cipher_alias(SN_cast5_cbc,"cast");
138 EVP_add_cipher_alias(SN_cast5_cbc,"CAST-cbc");
139 EVP_add_cipher_alias(SN_cast5_cbc,"cast-cbc");
140#endif
141
142#ifndef OPENSSL_NO_RC5
143 EVP_add_cipher(EVP_rc5_32_12_16_ecb());
144 EVP_add_cipher(EVP_rc5_32_12_16_cfb());
145 EVP_add_cipher(EVP_rc5_32_12_16_ofb());
146 EVP_add_cipher(EVP_rc5_32_12_16_cbc());
147 EVP_add_cipher_alias(SN_rc5_cbc,"rc5");
148 EVP_add_cipher_alias(SN_rc5_cbc,"RC5");
149#endif
150
151#ifndef OPENSSL_NO_AES
152 EVP_add_cipher(EVP_aes_128_ecb());
153 EVP_add_cipher(EVP_aes_128_cbc());
154 EVP_add_cipher(EVP_aes_128_cfb());
155 EVP_add_cipher(EVP_aes_128_cfb1());
156 EVP_add_cipher(EVP_aes_128_cfb8());
157 EVP_add_cipher(EVP_aes_128_ofb());
158#if 0
159 EVP_add_cipher(EVP_aes_128_ctr());
160#endif
161 EVP_add_cipher_alias(SN_aes_128_cbc,"AES128");
162 EVP_add_cipher_alias(SN_aes_128_cbc,"aes128");
163 EVP_add_cipher(EVP_aes_192_ecb());
164 EVP_add_cipher(EVP_aes_192_cbc());
165 EVP_add_cipher(EVP_aes_192_cfb());
166 EVP_add_cipher(EVP_aes_192_cfb1());
167 EVP_add_cipher(EVP_aes_192_cfb8());
168 EVP_add_cipher(EVP_aes_192_ofb());
169#if 0
170 EVP_add_cipher(EVP_aes_192_ctr());
171#endif
172 EVP_add_cipher_alias(SN_aes_192_cbc,"AES192");
173 EVP_add_cipher_alias(SN_aes_192_cbc,"aes192");
174 EVP_add_cipher(EVP_aes_256_ecb());
175 EVP_add_cipher(EVP_aes_256_cbc());
176 EVP_add_cipher(EVP_aes_256_cfb());
177 EVP_add_cipher(EVP_aes_256_cfb1());
178 EVP_add_cipher(EVP_aes_256_cfb8());
179 EVP_add_cipher(EVP_aes_256_ofb());
180#if 0
181 EVP_add_cipher(EVP_aes_256_ctr());
182#endif
183 EVP_add_cipher_alias(SN_aes_256_cbc,"AES256");
184 EVP_add_cipher_alias(SN_aes_256_cbc,"aes256");
185#endif
186 PKCS12_PBE_add();
187 PKCS5_PBE_add();
188 }
diff --git a/src/lib/libcrypto/evp/c_alld.c b/src/lib/libcrypto/evp/c_alld.c
new file mode 100644
index 0000000000..929ea56a3e
--- /dev/null
+++ b/src/lib/libcrypto/evp/c_alld.c
@@ -0,0 +1,113 @@
1/* crypto/evp/c_alld.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/pkcs12.h>
63#include <openssl/objects.h>
64
65void OpenSSL_add_all_digests(void)
66 {
67#ifndef OPENSSL_NO_MD2
68 EVP_add_digest(EVP_md2());
69#endif
70#ifndef OPENSSL_NO_MD4
71 EVP_add_digest(EVP_md4());
72#endif
73#ifndef OPENSSL_NO_MD5
74 EVP_add_digest(EVP_md5());
75 EVP_add_digest_alias(SN_md5,"ssl2-md5");
76 EVP_add_digest_alias(SN_md5,"ssl3-md5");
77#endif
78#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
79 EVP_add_digest(EVP_sha());
80#ifndef OPENSSL_NO_DSA
81 EVP_add_digest(EVP_dss());
82#endif
83#endif
84#ifndef OPENSSL_NO_SHA
85 EVP_add_digest(EVP_sha1());
86 EVP_add_digest_alias(SN_sha1,"ssl3-sha1");
87 EVP_add_digest_alias(SN_sha1WithRSAEncryption,SN_sha1WithRSA);
88#ifndef OPENSSL_NO_DSA
89 EVP_add_digest(EVP_dss1());
90 EVP_add_digest_alias(SN_dsaWithSHA1,SN_dsaWithSHA1_2);
91 EVP_add_digest_alias(SN_dsaWithSHA1,"DSS1");
92 EVP_add_digest_alias(SN_dsaWithSHA1,"dss1");
93#endif
94#endif
95#if !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
96 EVP_add_digest(EVP_mdc2());
97#endif
98#ifndef OPENSSL_NO_RIPEMD
99 EVP_add_digest(EVP_ripemd160());
100 EVP_add_digest_alias(SN_ripemd160,"ripemd");
101 EVP_add_digest_alias(SN_ripemd160,"rmd160");
102#endif
103#ifdef OPENSSL_FIPS
104#ifndef OPENSSL_NO_SHA256
105 EVP_add_digest(EVP_sha224());
106 EVP_add_digest(EVP_sha256());
107#endif
108#ifndef OPENSSL_NO_SHA512
109 EVP_add_digest(EVP_sha384());
110 EVP_add_digest(EVP_sha512());
111#endif
112#endif
113 }
diff --git a/src/lib/libcrypto/evp/digest.c b/src/lib/libcrypto/evp/digest.c
index 762e6d3450..f21c63842c 100644
--- a/src/lib/libcrypto/evp/digest.c
+++ b/src/lib/libcrypto/evp/digest.c
@@ -137,6 +137,39 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
137 return EVP_DigestInit_ex(ctx, type, NULL); 137 return EVP_DigestInit_ex(ctx, type, NULL);
138 } 138 }
139 139
140#ifdef OPENSSL_FIPS
141
142/* The purpose of these is to trap programs that attempt to use non FIPS
143 * algorithms in FIPS mode and ignore the errors.
144 */
145
146static int bad_init(EVP_MD_CTX *ctx)
147 { FIPS_ERROR_IGNORED("Digest init"); return 0;}
148
149static int bad_update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
150 { FIPS_ERROR_IGNORED("Digest update"); return 0;}
151
152static int bad_final(EVP_MD_CTX *ctx,unsigned char *md)
153 { FIPS_ERROR_IGNORED("Digest Final"); return 0;}
154
155static const EVP_MD bad_md =
156 {
157 0,
158 0,
159 0,
160 0,
161 bad_init,
162 bad_update,
163 bad_final,
164 NULL,
165 NULL,
166 NULL,
167 0,
168 {0,0,0,0},
169 };
170
171#endif
172
140int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl) 173int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
141 { 174 {
142 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED); 175 EVP_MD_CTX_clear_flags(ctx,EVP_MD_CTX_FLAG_CLEANED);
@@ -159,7 +192,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
159 { 192 {
160 if (!ENGINE_init(impl)) 193 if (!ENGINE_init(impl))
161 { 194 {
162 EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_INITIALIZATION_ERROR); 195 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
163 return 0; 196 return 0;
164 } 197 }
165 } 198 }
@@ -173,7 +206,7 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
173 if(!d) 206 if(!d)
174 { 207 {
175 /* Same comment from evp_enc.c */ 208 /* Same comment from evp_enc.c */
176 EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_INITIALIZATION_ERROR); 209 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_INITIALIZATION_ERROR);
177 return 0; 210 return 0;
178 } 211 }
179 /* We'll use the ENGINE's private digest definition */ 212 /* We'll use the ENGINE's private digest definition */
@@ -189,12 +222,24 @@ int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
189 else 222 else
190 if(!ctx->digest) 223 if(!ctx->digest)
191 { 224 {
192 EVPerr(EVP_F_EVP_DIGESTINIT_EX,EVP_R_NO_DIGEST_SET); 225 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_NO_DIGEST_SET);
193 return 0; 226 return 0;
194 } 227 }
195#endif 228#endif
196 if (ctx->digest != type) 229 if (ctx->digest != type)
197 { 230 {
231#ifdef OPENSSL_FIPS
232 if (FIPS_mode())
233 {
234 if (!(type->flags & EVP_MD_FLAG_FIPS)
235 && !(ctx->flags & EVP_MD_CTX_FLAG_NON_FIPS_ALLOW))
236 {
237 EVPerr(EVP_F_EVP_DIGESTINIT, EVP_R_DISABLED_FOR_FIPS);
238 ctx->digest = &bad_md;
239 return 0;
240 }
241 }
242#endif
198 if (ctx->digest && ctx->digest->ctx_size) 243 if (ctx->digest && ctx->digest->ctx_size)
199 OPENSSL_free(ctx->md_data); 244 OPENSSL_free(ctx->md_data);
200 ctx->digest=type; 245 ctx->digest=type;
@@ -208,9 +253,9 @@ skip_to_init:
208 } 253 }
209 254
210int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, 255int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data,
211 size_t count) 256 unsigned int count)
212 { 257 {
213 return ctx->digest->update(ctx,data,count); 258 return ctx->digest->update(ctx,data,(unsigned long)count);
214 } 259 }
215 260
216/* The caller can assume that this removes any secret data from the context */ 261/* The caller can assume that this removes any secret data from the context */
@@ -251,14 +296,14 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
251 unsigned char *tmp_buf; 296 unsigned char *tmp_buf;
252 if ((in == NULL) || (in->digest == NULL)) 297 if ((in == NULL) || (in->digest == NULL))
253 { 298 {
254 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,EVP_R_INPUT_NOT_INITIALIZED); 299 EVPerr(EVP_F_EVP_MD_CTX_COPY,EVP_R_INPUT_NOT_INITIALIZED);
255 return 0; 300 return 0;
256 } 301 }
257#ifndef OPENSSL_NO_ENGINE 302#ifndef OPENSSL_NO_ENGINE
258 /* Make sure it's safe to copy a digest context using an ENGINE */ 303 /* Make sure it's safe to copy a digest context using an ENGINE */
259 if (in->engine && !ENGINE_init(in->engine)) 304 if (in->engine && !ENGINE_init(in->engine))
260 { 305 {
261 EVPerr(EVP_F_EVP_MD_CTX_COPY_EX,ERR_R_ENGINE_LIB); 306 EVPerr(EVP_F_EVP_MD_CTX_COPY,ERR_R_ENGINE_LIB);
262 return 0; 307 return 0;
263 } 308 }
264#endif 309#endif
@@ -285,7 +330,7 @@ int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
285 return 1; 330 return 1;
286 } 331 }
287 332
288int EVP_Digest(const void *data, size_t count, 333int EVP_Digest(void *data, unsigned int count,
289 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl) 334 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl)
290 { 335 {
291 EVP_MD_CTX ctx; 336 EVP_MD_CTX ctx;
diff --git a/src/lib/libcrypto/evp/e_acss.c b/src/lib/libcrypto/evp/e_acss.c
new file mode 100644
index 0000000000..a16b85c627
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_acss.c
@@ -0,0 +1,85 @@
1/* $Id: e_acss.c,v 1.2 2004/02/13 10:05:44 hshoexer Exp $ */
2/*
3 * Copyright (c) 2004 The OpenBSD project
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#ifndef OPENSSL_NO_ACSS
19
20#include "cryptlib.h"
21#include <openssl/evp.h>
22#include <openssl/objects.h>
23#include "evp_locl.h"
24#include <openssl/acss.h>
25
26typedef struct {
27 ACSS_KEY ks;
28} EVP_ACSS_KEY;
29
30#define data(ctx) EVP_C_DATA(EVP_ACSS_KEY,ctx)
31
32static int acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
33 const unsigned char *iv, int enc);
34static int acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out,
35 const unsigned char *in, unsigned int inl);
36static int acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
37static const EVP_CIPHER acss_cipher = {
38 NID_undef,
39 1,5,0,
40 0,
41 acss_init_key,
42 acss_ciph,
43 NULL,
44 sizeof(EVP_ACSS_KEY),
45 NULL,
46 NULL,
47 acss_ctrl,
48 NULL
49};
50
51const
52EVP_CIPHER *EVP_acss(void)
53{
54 return(&acss_cipher);
55}
56
57static int
58acss_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
59 const unsigned char *iv, int enc)
60{
61 acss_setkey(&data(ctx)->ks,key,enc,ACSS_MODE1);
62 return 1;
63}
64
65static int
66acss_ciph(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in,
67 unsigned int inl)
68{
69 acss(&data(ctx)->ks,inl,in,out);
70 return 1;
71}
72
73static int
74acss_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
75{
76 switch(type) {
77 case EVP_CTRL_SET_ACSS_MODE:
78 data(ctx)->ks.mode = arg;
79 return 1;
80
81 default:
82 return -1;
83 }
84}
85#endif
diff --git a/src/lib/libcrypto/evp/e_aes.c b/src/lib/libcrypto/evp/e_aes.c
index bd6c0a3a62..7b67984fa1 100644
--- a/src/lib/libcrypto/evp/e_aes.c
+++ b/src/lib/libcrypto/evp/e_aes.c
@@ -48,12 +48,10 @@
48 * 48 *
49 */ 49 */
50 50
51#include <openssl/opensslconf.h>
52#ifndef OPENSSL_NO_AES 51#ifndef OPENSSL_NO_AES
53#include <openssl/evp.h> 52#include <openssl/evp.h>
54#include <openssl/err.h> 53#include <openssl/err.h>
55#include <string.h> 54#include <string.h>
56#include <assert.h>
57#include <openssl/aes.h> 55#include <openssl/aes.h>
58#include "evp_locl.h" 56#include "evp_locl.h"
59 57
@@ -69,32 +67,32 @@ typedef struct
69 67
70IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY, 68IMPLEMENT_BLOCK_CIPHER(aes_128, ks, AES, EVP_AES_KEY,
71 NID_aes_128, 16, 16, 16, 128, 69 NID_aes_128, 16, 16, 16, 128,
72 0, aes_init_key, NULL, 70 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
73 EVP_CIPHER_set_asn1_iv, 71 EVP_CIPHER_set_asn1_iv,
74 EVP_CIPHER_get_asn1_iv, 72 EVP_CIPHER_get_asn1_iv,
75 NULL) 73 NULL)
76IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY, 74IMPLEMENT_BLOCK_CIPHER(aes_192, ks, AES, EVP_AES_KEY,
77 NID_aes_192, 16, 24, 16, 128, 75 NID_aes_192, 16, 24, 16, 128,
78 0, aes_init_key, NULL, 76 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
79 EVP_CIPHER_set_asn1_iv, 77 EVP_CIPHER_set_asn1_iv,
80 EVP_CIPHER_get_asn1_iv, 78 EVP_CIPHER_get_asn1_iv,
81 NULL) 79 NULL)
82IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY, 80IMPLEMENT_BLOCK_CIPHER(aes_256, ks, AES, EVP_AES_KEY,
83 NID_aes_256, 16, 32, 16, 128, 81 NID_aes_256, 16, 32, 16, 128,
84 0, aes_init_key, NULL, 82 EVP_CIPH_FLAG_FIPS, aes_init_key, NULL,
85 EVP_CIPHER_set_asn1_iv, 83 EVP_CIPHER_set_asn1_iv,
86 EVP_CIPHER_get_asn1_iv, 84 EVP_CIPHER_get_asn1_iv,
87 NULL) 85 NULL)
88 86
89#define IMPLEMENT_AES_CFBR(ksize,cbits) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16) 87#define IMPLEMENT_AES_CFBR(ksize,cbits,flags) IMPLEMENT_CFBR(aes,AES,EVP_AES_KEY,ks,ksize,cbits,16,flags)
90 88
91IMPLEMENT_AES_CFBR(128,1) 89IMPLEMENT_AES_CFBR(128,1,EVP_CIPH_FLAG_FIPS)
92IMPLEMENT_AES_CFBR(192,1) 90IMPLEMENT_AES_CFBR(192,1,EVP_CIPH_FLAG_FIPS)
93IMPLEMENT_AES_CFBR(256,1) 91IMPLEMENT_AES_CFBR(256,1,EVP_CIPH_FLAG_FIPS)
94 92
95IMPLEMENT_AES_CFBR(128,8) 93IMPLEMENT_AES_CFBR(128,8,EVP_CIPH_FLAG_FIPS)
96IMPLEMENT_AES_CFBR(192,8) 94IMPLEMENT_AES_CFBR(192,8,EVP_CIPH_FLAG_FIPS)
97IMPLEMENT_AES_CFBR(256,8) 95IMPLEMENT_AES_CFBR(256,8,EVP_CIPH_FLAG_FIPS)
98 96
99static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 97static int aes_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
100 const unsigned char *iv, int enc) 98 const unsigned char *iv, int enc)
diff --git a/src/lib/libcrypto/evp/e_bf.c b/src/lib/libcrypto/evp/e_bf.c
index cc224e5363..e74337567b 100644
--- a/src/lib/libcrypto/evp/e_bf.c
+++ b/src/lib/libcrypto/evp/e_bf.c
@@ -56,9 +56,9 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_BF
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#ifndef OPENSSL_NO_BF
62#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include "evp_locl.h" 63#include "evp_locl.h"
64#include <openssl/objects.h> 64#include <openssl/objects.h>
diff --git a/src/lib/libcrypto/evp/e_cast.c b/src/lib/libcrypto/evp/e_cast.c
index d77bcd9298..3400fef187 100644
--- a/src/lib/libcrypto/evp/e_cast.c
+++ b/src/lib/libcrypto/evp/e_cast.c
@@ -56,10 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_CAST
60
59#include <stdio.h> 61#include <stdio.h>
60#include "cryptlib.h" 62#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_CAST
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include "evp_locl.h" 65#include "evp_locl.h"
diff --git a/src/lib/libcrypto/evp/e_des.c b/src/lib/libcrypto/evp/e_des.c
index 856323648c..46e2899825 100644
--- a/src/lib/libcrypto/evp/e_des.c
+++ b/src/lib/libcrypto/evp/e_des.c
@@ -63,11 +63,9 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include "evp_locl.h" 64#include "evp_locl.h"
65#include <openssl/des.h> 65#include <openssl/des.h>
66#include <openssl/rand.h>
67 66
68static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 67static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv, int enc); 68 const unsigned char *iv, int enc);
70static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
71 69
72/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */ 70/* Because of various casts and different names can't use IMPLEMENT_BLOCK_CIPHER */
73 71
@@ -129,48 +127,28 @@ static int des_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
129 } 127 }
130 128
131BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64, 129BLOCK_CIPHER_defs(des, DES_key_schedule, NID_des, 8, 8, 8, 64,
132 EVP_CIPH_RAND_KEY, des_init_key, NULL, 130 EVP_CIPH_FLAG_FIPS, des_init_key, NULL,
133 EVP_CIPHER_set_asn1_iv, 131 EVP_CIPHER_set_asn1_iv,
134 EVP_CIPHER_get_asn1_iv, 132 EVP_CIPHER_get_asn1_iv,
135 des_ctrl) 133 NULL)
136 134
137BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1, 135BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,1,
138 EVP_CIPH_RAND_KEY, des_init_key,NULL, 136 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
139 EVP_CIPHER_set_asn1_iv, 137 EVP_CIPHER_set_asn1_iv,
140 EVP_CIPHER_get_asn1_iv,des_ctrl) 138 EVP_CIPHER_get_asn1_iv,NULL)
141 139
142BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8, 140BLOCK_CIPHER_def_cfb(des,DES_key_schedule,NID_des,8,8,8,
143 EVP_CIPH_RAND_KEY,des_init_key,NULL, 141 EVP_CIPH_FLAG_FIPS,des_init_key,NULL,
144 EVP_CIPHER_set_asn1_iv, 142 EVP_CIPHER_set_asn1_iv,
145 EVP_CIPHER_get_asn1_iv,des_ctrl) 143 EVP_CIPHER_get_asn1_iv,NULL)
146 144
147static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 145static int des_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
148 const unsigned char *iv, int enc) 146 const unsigned char *iv, int enc)
149 { 147 {
150 DES_cblock *deskey = (DES_cblock *)key; 148 DES_cblock *deskey = (DES_cblock *)key;
151#ifdef EVP_CHECK_DES_KEY 149
152 if(DES_set_key_checked(deskey,ctx->cipher_data) != 0)
153 return 0;
154#else
155 DES_set_key_unchecked(deskey,ctx->cipher_data); 150 DES_set_key_unchecked(deskey,ctx->cipher_data);
156#endif
157 return 1; 151 return 1;
158 } 152 }
159 153
160static int des_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
161 {
162
163 switch(type)
164 {
165 case EVP_CTRL_RAND_KEY:
166 if (RAND_bytes(ptr, 8) <= 0)
167 return 0;
168 DES_set_odd_parity((DES_cblock *)ptr);
169 return 1;
170
171 default:
172 return -1;
173 }
174 }
175
176#endif 154#endif
diff --git a/src/lib/libcrypto/evp/e_des3.c b/src/lib/libcrypto/evp/e_des3.c
index ac148efab2..677322bf02 100644
--- a/src/lib/libcrypto/evp/e_des3.c
+++ b/src/lib/libcrypto/evp/e_des3.c
@@ -63,7 +63,6 @@
63#include <openssl/objects.h> 63#include <openssl/objects.h>
64#include "evp_locl.h" 64#include "evp_locl.h"
65#include <openssl/des.h> 65#include <openssl/des.h>
66#include <openssl/rand.h>
67 66
68static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 67static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc); 68 const unsigned char *iv,int enc);
@@ -71,8 +70,6 @@ static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
71static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 70static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
72 const unsigned char *iv,int enc); 71 const unsigned char *iv,int enc);
73 72
74static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
75
76typedef struct 73typedef struct
77 { 74 {
78 DES_key_schedule ks1;/* key schedule */ 75 DES_key_schedule ks1;/* key schedule */
@@ -88,8 +85,7 @@ static int des_ede_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
88 const unsigned char *in, unsigned int inl) 85 const unsigned char *in, unsigned int inl)
89{ 86{
90 BLOCK_CIPHER_ecb_loop() 87 BLOCK_CIPHER_ecb_loop()
91 DES_ecb3_encrypt((const_DES_cblock *)(in + i), 88 DES_ecb3_encrypt(in + i,out + i,
92 (DES_cblock *)(out + i),
93 &data(ctx)->ks1, &data(ctx)->ks2, 89 &data(ctx)->ks1, &data(ctx)->ks2,
94 &data(ctx)->ks3, 90 &data(ctx)->ks3,
95 ctx->encrypt); 91 ctx->encrypt);
@@ -164,10 +160,10 @@ static int des_ede3_cfb8_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
164 } 160 }
165 161
166BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64, 162BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
167 EVP_CIPH_RAND_KEY, des_ede_init_key, NULL, 163 EVP_CIPH_FLAG_FIPS, des_ede_init_key, NULL,
168 EVP_CIPHER_set_asn1_iv, 164 EVP_CIPHER_set_asn1_iv,
169 EVP_CIPHER_get_asn1_iv, 165 EVP_CIPHER_get_asn1_iv,
170 des3_ctrl) 166 NULL)
171 167
172#define des_ede3_cfb64_cipher des_ede_cfb64_cipher 168#define des_ede3_cfb64_cipher des_ede_cfb64_cipher
173#define des_ede3_ofb_cipher des_ede_ofb_cipher 169#define des_ede3_ofb_cipher des_ede_ofb_cipher
@@ -175,35 +171,28 @@ BLOCK_CIPHER_defs(des_ede, DES_EDE_KEY, NID_des_ede, 8, 16, 8, 64,
175#define des_ede3_ecb_cipher des_ede_ecb_cipher 171#define des_ede3_ecb_cipher des_ede_ecb_cipher
176 172
177BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64, 173BLOCK_CIPHER_defs(des_ede3, DES_EDE_KEY, NID_des_ede3, 8, 24, 8, 64,
178 EVP_CIPH_RAND_KEY, des_ede3_init_key, NULL, 174 EVP_CIPH_FLAG_FIPS, des_ede3_init_key, NULL,
179 EVP_CIPHER_set_asn1_iv, 175 EVP_CIPHER_set_asn1_iv,
180 EVP_CIPHER_get_asn1_iv, 176 EVP_CIPHER_get_asn1_iv,
181 des3_ctrl) 177 NULL)
182 178
183BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1, 179BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,1,
184 EVP_CIPH_RAND_KEY, des_ede3_init_key,NULL, 180 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
185 EVP_CIPHER_set_asn1_iv, 181 EVP_CIPHER_set_asn1_iv,
186 EVP_CIPHER_get_asn1_iv, 182 EVP_CIPHER_get_asn1_iv,NULL)
187 des3_ctrl)
188 183
189BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8, 184BLOCK_CIPHER_def_cfb(des_ede3,DES_EDE_KEY,NID_des_ede3,24,8,8,
190 EVP_CIPH_RAND_KEY, des_ede3_init_key,NULL, 185 EVP_CIPH_FLAG_FIPS, des_ede3_init_key,NULL,
191 EVP_CIPHER_set_asn1_iv, 186 EVP_CIPHER_set_asn1_iv,
192 EVP_CIPHER_get_asn1_iv, 187 EVP_CIPHER_get_asn1_iv,NULL)
193 des3_ctrl)
194 188
195static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, 189static int des_ede_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
196 const unsigned char *iv, int enc) 190 const unsigned char *iv, int enc)
197 { 191 {
198 DES_cblock *deskey = (DES_cblock *)key; 192 DES_cblock *deskey = (DES_cblock *)key;
199#ifdef EVP_CHECK_DES_KEY 193
200 if (DES_set_key_checked(&deskey[0],&data(ctx)->ks1)
201 !! DES_set_key_checked(&deskey[1],&data(ctx)->ks2))
202 return 0;
203#else
204 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1); 194 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
205 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2); 195 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
206#endif
207 memcpy(&data(ctx)->ks3,&data(ctx)->ks1, 196 memcpy(&data(ctx)->ks3,&data(ctx)->ks1,
208 sizeof(data(ctx)->ks1)); 197 sizeof(data(ctx)->ks1));
209 return 1; 198 return 1;
@@ -224,39 +213,11 @@ static int des_ede3_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
224 } 213 }
225#endif /* KSSL_DEBUG */ 214#endif /* KSSL_DEBUG */
226 215
227#ifdef EVP_CHECK_DES_KEY
228 if (DES_set_key_checked(&deskey[0],&data(ctx)->ks1)
229 || DES_set_key_checked(&deskey[1],&data(ctx)->ks2)
230 || DES_set_key_checked(&deskey[2],&data(ctx)->ks3))
231 return 0;
232#else
233 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1); 216 DES_set_key_unchecked(&deskey[0],&data(ctx)->ks1);
234 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2); 217 DES_set_key_unchecked(&deskey[1],&data(ctx)->ks2);
235 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3); 218 DES_set_key_unchecked(&deskey[2],&data(ctx)->ks3);
236#endif
237 return 1;
238 }
239 219
240static int des3_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr) 220 return 1;
241 {
242
243 DES_cblock *deskey = ptr;
244
245 switch(type)
246 {
247 case EVP_CTRL_RAND_KEY:
248 if (RAND_bytes(ptr, c->key_len) <= 0)
249 return 0;
250 DES_set_odd_parity(deskey);
251 if (c->key_len >= 16)
252 DES_set_odd_parity(deskey + 1);
253 if (c->key_len >= 24)
254 DES_set_odd_parity(deskey + 2);
255 return 1;
256
257 default:
258 return -1;
259 }
260 } 221 }
261 222
262const EVP_CIPHER *EVP_des_ede(void) 223const EVP_CIPHER *EVP_des_ede(void)
diff --git a/src/lib/libcrypto/evp/e_dsa.c b/src/lib/libcrypto/evp/e_dsa.c
new file mode 100644
index 0000000000..b96f2738b3
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_dsa.c
@@ -0,0 +1,71 @@
1/* crypto/evp/e_dsa.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/objects.h>
63#include <openssl/x509.h>
64
65static EVP_PKEY_METHOD dss_method=
66 {
67 DSA_sign,
68 DSA_verify,
69 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3,NULL},
70 };
71
diff --git a/src/lib/libcrypto/evp/e_idea.c b/src/lib/libcrypto/evp/e_idea.c
index 48c33a774a..b9efa75ae7 100644
--- a/src/lib/libcrypto/evp/e_idea.c
+++ b/src/lib/libcrypto/evp/e_idea.c
@@ -56,10 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_IDEA
60
59#include <stdio.h> 61#include <stdio.h>
60#include "cryptlib.h" 62#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_IDEA
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include "evp_locl.h" 65#include "evp_locl.h"
diff --git a/src/lib/libcrypto/evp/e_null.c b/src/lib/libcrypto/evp/e_null.c
index 5205259f18..a84b0f14b1 100644
--- a/src/lib/libcrypto/evp/e_null.c
+++ b/src/lib/libcrypto/evp/e_null.c
@@ -69,14 +69,13 @@ static const EVP_CIPHER n_cipher=
69 { 69 {
70 NID_undef, 70 NID_undef,
71 1,0,0, 71 1,0,0,
72 0, 72 EVP_CIPH_FLAG_FIPS,
73 null_init_key, 73 null_init_key,
74 null_cipher, 74 null_cipher,
75 NULL, 75 NULL,
76 0, 76 0,
77 NULL, 77 NULL,
78 NULL, 78 NULL,
79 NULL,
80 NULL 79 NULL
81 }; 80 };
82 81
@@ -96,7 +95,7 @@ static int null_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl) 95 const unsigned char *in, unsigned int inl)
97 { 96 {
98 if (in != out) 97 if (in != out)
99 memcpy((char *)out,(const char *)in,(size_t)inl); 98 memcpy((char *)out,(char *)in,(int)inl);
100 return 1; 99 return 1;
101 } 100 }
102 101
diff --git a/src/lib/libcrypto/evp/e_rc2.c b/src/lib/libcrypto/evp/e_rc2.c
index d37726ffae..d42cbfd17e 100644
--- a/src/lib/libcrypto/evp/e_rc2.c
+++ b/src/lib/libcrypto/evp/e_rc2.c
@@ -56,11 +56,10 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RC2 59#ifndef OPENSSL_NO_RC2
63 60
61#include <stdio.h>
62#include "cryptlib.h"
64#include <openssl/evp.h> 63#include <openssl/evp.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include "evp_locl.h" 65#include "evp_locl.h"
@@ -168,17 +167,16 @@ static int rc2_magic_to_meth(int i)
168static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) 167static int rc2_get_asn1_type_and_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
169 { 168 {
170 long num=0; 169 long num=0;
171 int i=0; 170 int i=0,l;
172 int key_bits; 171 int key_bits;
173 unsigned int l;
174 unsigned char iv[EVP_MAX_IV_LENGTH]; 172 unsigned char iv[EVP_MAX_IV_LENGTH];
175 173
176 if (type != NULL) 174 if (type != NULL)
177 { 175 {
178 l=EVP_CIPHER_CTX_iv_length(c); 176 l=EVP_CIPHER_CTX_iv_length(c);
179 OPENSSL_assert(l <= sizeof(iv)); 177 OPENSSL_assert(l <= sizeof iv);
180 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l); 178 i=ASN1_TYPE_get_int_octetstring(type,&num,iv,l);
181 if (i != (int)l) 179 if (i != l)
182 return(-1); 180 return(-1);
183 key_bits =rc2_magic_to_meth((int)num); 181 key_bits =rc2_magic_to_meth((int)num);
184 if (!key_bits) 182 if (!key_bits)
diff --git a/src/lib/libcrypto/evp/e_rc4.c b/src/lib/libcrypto/evp/e_rc4.c
index 67af850bea..8aa70585b9 100644
--- a/src/lib/libcrypto/evp/e_rc4.c
+++ b/src/lib/libcrypto/evp/e_rc4.c
@@ -56,13 +56,13 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <stdio.h>
60#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RC4 59#ifndef OPENSSL_NO_RC4
63 60
61#include <stdio.h>
62#include "cryptlib.h"
64#include <openssl/evp.h> 63#include <openssl/evp.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc4.h> 66#include <openssl/rc4.h>
67 67
68/* FIXME: surely this is available elsewhere? */ 68/* FIXME: surely this is available elsewhere? */
@@ -90,7 +90,6 @@ static const EVP_CIPHER r4_cipher=
90 sizeof(EVP_RC4_KEY), 90 sizeof(EVP_RC4_KEY),
91 NULL, 91 NULL,
92 NULL, 92 NULL,
93 NULL,
94 NULL 93 NULL
95 }; 94 };
96 95
@@ -105,7 +104,6 @@ static const EVP_CIPHER r4_40_cipher=
105 sizeof(EVP_RC4_KEY), 104 sizeof(EVP_RC4_KEY),
106 NULL, 105 NULL,
107 NULL, 106 NULL,
108 NULL,
109 NULL 107 NULL
110 }; 108 };
111 109
diff --git a/src/lib/libcrypto/evp/e_rc5.c b/src/lib/libcrypto/evp/e_rc5.c
new file mode 100644
index 0000000000..3c7713b181
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_rc5.c
@@ -0,0 +1,125 @@
1/* crypto/evp/e_rc5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_RC5
60
61#include <stdio.h>
62#include "cryptlib.h"
63#include <openssl/evp.h>
64#include <openssl/objects.h>
65#include "evp_locl.h"
66#include <openssl/rc5.h>
67
68static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
69 const unsigned char *iv,int enc);
70static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr);
71
72typedef struct
73 {
74 int rounds; /* number of rounds */
75 RC5_32_KEY ks; /* key schedule */
76 } EVP_RC5_KEY;
77
78#define data(ctx) EVP_C_DATA(EVP_RC5_KEY,ctx)
79
80IMPLEMENT_BLOCK_CIPHER(rc5_32_12_16, ks, RC5_32, EVP_RC5_KEY, NID_rc5,
81 8, RC5_32_KEY_LENGTH, 8, 64,
82 EVP_CIPH_VARIABLE_LENGTH | EVP_CIPH_CTRL_INIT,
83 r_32_12_16_init_key, NULL,
84 NULL, NULL, rc5_ctrl)
85
86static int rc5_ctrl(EVP_CIPHER_CTX *c, int type, int arg, void *ptr)
87 {
88 switch(type)
89 {
90 case EVP_CTRL_INIT:
91 data(c)->rounds = RC5_12_ROUNDS;
92 return 1;
93
94 case EVP_CTRL_GET_RC5_ROUNDS:
95 *(int *)ptr = data(c)->rounds;
96 return 1;
97
98 case EVP_CTRL_SET_RC5_ROUNDS:
99 switch(arg)
100 {
101 case RC5_8_ROUNDS:
102 case RC5_12_ROUNDS:
103 case RC5_16_ROUNDS:
104 data(c)->rounds = arg;
105 return 1;
106
107 default:
108 EVPerr(EVP_F_RC5_CTRL, EVP_R_UNSUPORTED_NUMBER_OF_ROUNDS);
109 return 0;
110 }
111
112 default:
113 return -1;
114 }
115 }
116
117static int r_32_12_16_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
118 const unsigned char *iv, int enc)
119 {
120 RC5_32_set_key(&data(ctx)->ks,EVP_CIPHER_CTX_key_length(ctx),
121 key,data(ctx)->rounds);
122 return 1;
123 }
124
125#endif
diff --git a/src/lib/libcrypto/evp/e_seed.c b/src/lib/libcrypto/evp/e_seed.c
new file mode 100644
index 0000000000..8c1ec0d43a
--- /dev/null
+++ b/src/lib/libcrypto/evp/e_seed.c
@@ -0,0 +1,83 @@
1/* crypto/evp/e_seed.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/opensslconf.h>
57#include <openssl/evp.h>
58#include <openssl/err.h>
59#include <string.h>
60#include <assert.h>
61#ifndef OPENSSL_NO_SEED
62#include <openssl/seed.h>
63#include "evp_locl.h"
64
65static int seed_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc);
66
67typedef struct
68 {
69 SEED_KEY_SCHEDULE ks;
70 } EVP_SEED_KEY;
71
72IMPLEMENT_BLOCK_CIPHER(seed, ks, SEED, EVP_SEED_KEY, NID_seed,
73 16, 16, 16, 128,
74 0, seed_init_key, 0, 0, 0, 0)
75
76static int seed_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key,
77 const unsigned char *iv, int enc)
78 {
79 SEED_set_key(key, ctx->cipher_data);
80 return 1;
81 }
82
83#endif
diff --git a/src/lib/libcrypto/evp/e_xcbc_d.c b/src/lib/libcrypto/evp/e_xcbc_d.c
index 8832da2433..a6f849e93d 100644
--- a/src/lib/libcrypto/evp/e_xcbc_d.c
+++ b/src/lib/libcrypto/evp/e_xcbc_d.c
@@ -56,11 +56,9 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_DES
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_DES
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
65#include <openssl/objects.h> 63#include <openssl/objects.h>
66#include <openssl/des.h> 64#include <openssl/des.h>
@@ -91,7 +89,6 @@ static const EVP_CIPHER d_xcbc_cipher=
91 sizeof(DESX_CBC_KEY), 89 sizeof(DESX_CBC_KEY),
92 EVP_CIPHER_set_asn1_iv, 90 EVP_CIPHER_set_asn1_iv,
93 EVP_CIPHER_get_asn1_iv, 91 EVP_CIPHER_get_asn1_iv,
94 NULL,
95 NULL 92 NULL
96 }; 93 };
97 94
diff --git a/src/lib/libcrypto/evp/encode.c b/src/lib/libcrypto/evp/encode.c
index 5921f0d710..33e540087d 100644
--- a/src/lib/libcrypto/evp/encode.c
+++ b/src/lib/libcrypto/evp/encode.c
@@ -129,14 +129,14 @@ void EVP_EncodeInit(EVP_ENCODE_CTX *ctx)
129 } 129 }
130 130
131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, 131void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
132 const unsigned char *in, int inl) 132 unsigned char *in, int inl)
133 { 133 {
134 int i,j; 134 int i,j;
135 unsigned int total=0; 135 unsigned int total=0;
136 136
137 *outl=0; 137 *outl=0;
138 if (inl == 0) return; 138 if (inl == 0) return;
139 OPENSSL_assert(ctx->length <= (int)sizeof(ctx->enc_data)); 139 OPENSSL_assert(ctx->length <= sizeof ctx->enc_data);
140 if ((ctx->num+inl) < ctx->length) 140 if ((ctx->num+inl) < ctx->length)
141 { 141 {
142 memcpy(&(ctx->enc_data[ctx->num]),in,inl); 142 memcpy(&(ctx->enc_data[ctx->num]),in,inl);
@@ -233,7 +233,7 @@ void EVP_DecodeInit(EVP_ENCODE_CTX *ctx)
233 * 1 for full line 233 * 1 for full line
234 */ 234 */
235int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl, 235int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
236 const unsigned char *in, int inl) 236 unsigned char *in, int inl)
237 { 237 {
238 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl; 238 int seof= -1,eof=0,rv= -1,ret=0,i,v,tmp,n,ln,tmp2,exp_nl;
239 unsigned char *d; 239 unsigned char *d;
@@ -259,7 +259,7 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
259 /* only save the good data :-) */ 259 /* only save the good data :-) */
260 if (!B64_NOT_BASE64(v)) 260 if (!B64_NOT_BASE64(v))
261 { 261 {
262 OPENSSL_assert(n < (int)sizeof(ctx->enc_data)); 262 OPENSSL_assert(n < sizeof ctx->enc_data);
263 d[n++]=tmp; 263 d[n++]=tmp;
264 ln++; 264 ln++;
265 } 265 }
@@ -323,8 +323,8 @@ int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
323 if (n > 0) 323 if (n > 0)
324 { 324 {
325 v=EVP_DecodeBlock(out,d,n); 325 v=EVP_DecodeBlock(out,d,n);
326 n=0;
327 if (v < 0) { rv=0; goto end; } 326 if (v < 0) { rv=0; goto end; }
327 n=0;
328 ret+=(v-eof); 328 ret+=(v-eof);
329 } 329 }
330 else 330 else
diff --git a/src/lib/libcrypto/evp/evp.h b/src/lib/libcrypto/evp/evp.h
index bdd3b7ecaa..f29e0ba8f0 100644
--- a/src/lib/libcrypto/evp/evp.h
+++ b/src/lib/libcrypto/evp/evp.h
@@ -75,6 +75,10 @@
75#include <openssl/bio.h> 75#include <openssl/bio.h>
76#endif 76#endif
77 77
78#ifdef OPENSSL_FIPS
79#include <openssl/fips.h>
80#endif
81
78/* 82/*
79#define EVP_RC2_KEY_SIZE 16 83#define EVP_RC2_KEY_SIZE 16
80#define EVP_RC4_KEY_SIZE 16 84#define EVP_RC4_KEY_SIZE 16
@@ -82,7 +86,7 @@
82#define EVP_CAST5_KEY_SIZE 16 86#define EVP_CAST5_KEY_SIZE 16
83#define EVP_RC5_32_12_16_KEY_SIZE 16 87#define EVP_RC5_32_12_16_KEY_SIZE 16
84*/ 88*/
85#define EVP_MAX_MD_SIZE 64 /* longest known is SHA512 */ 89#define EVP_MAX_MD_SIZE 64 /* longest known SHA512 */
86#define EVP_MAX_KEY_LENGTH 32 90#define EVP_MAX_KEY_LENGTH 32
87#define EVP_MAX_IV_LENGTH 16 91#define EVP_MAX_IV_LENGTH 16
88#define EVP_MAX_BLOCK_LENGTH 32 92#define EVP_MAX_BLOCK_LENGTH 32
@@ -96,13 +100,11 @@
96#define EVP_PK_RSA 0x0001 100#define EVP_PK_RSA 0x0001
97#define EVP_PK_DSA 0x0002 101#define EVP_PK_DSA 0x0002
98#define EVP_PK_DH 0x0004 102#define EVP_PK_DH 0x0004
99#define EVP_PK_EC 0x0008
100#define EVP_PKT_SIGN 0x0010 103#define EVP_PKT_SIGN 0x0010
101#define EVP_PKT_ENC 0x0020 104#define EVP_PKT_ENC 0x0020
102#define EVP_PKT_EXCH 0x0040 105#define EVP_PKT_EXCH 0x0040
103#define EVP_PKS_RSA 0x0100 106#define EVP_PKS_RSA 0x0100
104#define EVP_PKS_DSA 0x0200 107#define EVP_PKS_DSA 0x0200
105#define EVP_PKS_EC 0x0400
106#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */ 108#define EVP_PKT_EXP 0x1000 /* <= 512 bit key */
107 109
108#define EVP_PKEY_NONE NID_undef 110#define EVP_PKEY_NONE NID_undef
@@ -114,7 +116,6 @@
114#define EVP_PKEY_DSA3 NID_dsaWithSHA1 116#define EVP_PKEY_DSA3 NID_dsaWithSHA1
115#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2 117#define EVP_PKEY_DSA4 NID_dsaWithSHA1_2
116#define EVP_PKEY_DH NID_dhKeyAgreement 118#define EVP_PKEY_DH NID_dhKeyAgreement
117#define EVP_PKEY_EC NID_X9_62_id_ecPublicKey
118 119
119#ifdef __cplusplus 120#ifdef __cplusplus
120extern "C" { 121extern "C" {
@@ -139,9 +140,6 @@ struct evp_pkey_st
139#ifndef OPENSSL_NO_DH 140#ifndef OPENSSL_NO_DH
140 struct dh_st *dh; /* DH */ 141 struct dh_st *dh; /* DH */
141#endif 142#endif
142#ifndef OPENSSL_NO_EC
143 struct ec_key_st *ec; /* ECC */
144#endif
145 } pkey; 143 } pkey;
146 int save_parameters; 144 int save_parameters;
147 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */ 145 STACK_OF(X509_ATTRIBUTE) *attributes; /* [ 0 ] */
@@ -227,58 +225,39 @@ struct env_md_st
227 int md_size; 225 int md_size;
228 unsigned long flags; 226 unsigned long flags;
229 int (*init)(EVP_MD_CTX *ctx); 227 int (*init)(EVP_MD_CTX *ctx);
230 int (*update)(EVP_MD_CTX *ctx,const void *data,size_t count); 228 int (*update)(EVP_MD_CTX *ctx,const void *data,unsigned long count);
231 int (*final)(EVP_MD_CTX *ctx,unsigned char *md); 229 int (*final)(EVP_MD_CTX *ctx,unsigned char *md);
232 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from); 230 int (*copy)(EVP_MD_CTX *to,const EVP_MD_CTX *from);
233 int (*cleanup)(EVP_MD_CTX *ctx); 231 int (*cleanup)(EVP_MD_CTX *ctx);
234 232
235 /* FIXME: prototype these some day */ 233 /* FIXME: prototype these some day */
236 int (*sign)(int type, const unsigned char *m, unsigned int m_length, 234 int (*sign)();
237 unsigned char *sigret, unsigned int *siglen, void *key); 235 int (*verify)();
238 int (*verify)(int type, const unsigned char *m, unsigned int m_length,
239 const unsigned char *sigbuf, unsigned int siglen,
240 void *key);
241 int required_pkey_type[5]; /*EVP_PKEY_xxx */ 236 int required_pkey_type[5]; /*EVP_PKEY_xxx */
242 int block_size; 237 int block_size;
243 int ctx_size; /* how big does the ctx->md_data need to be */ 238 int ctx_size; /* how big does the ctx->md_data need to be */
244 } /* EVP_MD */; 239 } /* EVP_MD */;
245 240
246typedef int evp_sign_method(int type,const unsigned char *m,
247 unsigned int m_length,unsigned char *sigret,
248 unsigned int *siglen, void *key);
249typedef int evp_verify_method(int type,const unsigned char *m,
250 unsigned int m_length,const unsigned char *sigbuf,
251 unsigned int siglen, void *key);
252
253#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single 241#define EVP_MD_FLAG_ONESHOT 0x0001 /* digest can only handle a single
254 * block */ 242 * block */
243#define EVP_MD_FLAG_FIPS 0x0400 /* Note if suitable for use in FIPS mode */
255 244
256#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0} 245#define EVP_PKEY_NULL_method NULL,NULL,{0,0,0,0}
257 246
258#ifndef OPENSSL_NO_DSA 247#ifndef OPENSSL_NO_DSA
259#define EVP_PKEY_DSA_method (evp_sign_method *)DSA_sign, \ 248#define EVP_PKEY_DSA_method DSA_sign,DSA_verify, \
260 (evp_verify_method *)DSA_verify, \
261 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \ 249 {EVP_PKEY_DSA,EVP_PKEY_DSA2,EVP_PKEY_DSA3, \
262 EVP_PKEY_DSA4,0} 250 EVP_PKEY_DSA4,0}
263#else 251#else
264#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method 252#define EVP_PKEY_DSA_method EVP_PKEY_NULL_method
265#endif 253#endif
266 254
267#ifndef OPENSSL_NO_ECDSA
268#define EVP_PKEY_ECDSA_method (evp_sign_method *)ECDSA_sign, \
269 (evp_verify_method *)ECDSA_verify, \
270 {EVP_PKEY_EC,0,0,0}
271#else
272#define EVP_PKEY_ECDSA_method EVP_PKEY_NULL_method
273#endif
274
275#ifndef OPENSSL_NO_RSA 255#ifndef OPENSSL_NO_RSA
276#define EVP_PKEY_RSA_method (evp_sign_method *)RSA_sign, \ 256#define EVP_PKEY_RSA_method RSA_sign,RSA_verify, \
277 (evp_verify_method *)RSA_verify, \
278 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} 257 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
279#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \ 258#define EVP_PKEY_RSA_ASN1_OCTET_STRING_method \
280 (evp_sign_method *)RSA_sign_ASN1_OCTET_STRING, \ 259 RSA_sign_ASN1_OCTET_STRING, \
281 (evp_verify_method *)RSA_verify_ASN1_OCTET_STRING, \ 260 RSA_verify_ASN1_OCTET_STRING, \
282 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0} 261 {EVP_PKEY_RSA,EVP_PKEY_RSA2,0,0}
283#else 262#else
284#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method 263#define EVP_PKEY_RSA_method EVP_PKEY_NULL_method
@@ -304,6 +283,9 @@ struct env_md_ctx_st
304#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data 283#define EVP_MD_CTX_FLAG_REUSE 0x0004 /* Don't free up ctx->md_data
305 * in EVP_MD_CTX_cleanup */ 284 * in EVP_MD_CTX_cleanup */
306 285
286#define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0x0008 /* Allow use of non FIPS digest
287 * in FIPS mode */
288
307struct evp_cipher_st 289struct evp_cipher_st
308 { 290 {
309 int nid; 291 int nid;
@@ -345,8 +327,10 @@ struct evp_cipher_st
345#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80 327#define EVP_CIPH_CUSTOM_KEY_LENGTH 0x80
346/* Don't use standard block padding */ 328/* Don't use standard block padding */
347#define EVP_CIPH_NO_PADDING 0x100 329#define EVP_CIPH_NO_PADDING 0x100
348/* cipher handles random key generation */ 330/* Note if suitable for use in FIPS mode */
349#define EVP_CIPH_RAND_KEY 0x200 331#define EVP_CIPH_FLAG_FIPS 0x400
332/* Allow non FIPS cipher in FIPS mode */
333#define EVP_CIPH_FLAG_NON_FIPS_ALLOW 0x800
350 334
351/* ctrl() values */ 335/* ctrl() values */
352 336
@@ -356,7 +340,7 @@ struct evp_cipher_st
356#define EVP_CTRL_SET_RC2_KEY_BITS 0x3 340#define EVP_CTRL_SET_RC2_KEY_BITS 0x3
357#define EVP_CTRL_GET_RC5_ROUNDS 0x4 341#define EVP_CTRL_GET_RC5_ROUNDS 0x4
358#define EVP_CTRL_SET_RC5_ROUNDS 0x5 342#define EVP_CTRL_SET_RC5_ROUNDS 0x5
359#define EVP_CTRL_RAND_KEY 0x6 343#define EVP_CTRL_SET_ACSS_MODE 0x6
360 344
361typedef struct evp_cipher_info_st 345typedef struct evp_cipher_info_st
362 { 346 {
@@ -418,47 +402,45 @@ typedef int (EVP_PBE_KEYGEN)(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
418 (char *)(dh)) 402 (char *)(dh))
419#endif 403#endif
420 404
421#ifndef OPENSSL_NO_EC
422#define EVP_PKEY_assign_EC_KEY(pkey,eckey) EVP_PKEY_assign((pkey),EVP_PKEY_EC,\
423 (char *)(eckey))
424#endif
425
426/* Add some extra combinations */ 405/* Add some extra combinations */
427#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a)) 406#define EVP_get_digestbynid(a) EVP_get_digestbyname(OBJ_nid2sn(a))
428#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a)) 407#define EVP_get_digestbyobj(a) EVP_get_digestbynid(OBJ_obj2nid(a))
429#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a)) 408#define EVP_get_cipherbynid(a) EVP_get_cipherbyname(OBJ_nid2sn(a))
430#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a)) 409#define EVP_get_cipherbyobj(a) EVP_get_cipherbynid(OBJ_obj2nid(a))
431 410
432int EVP_MD_type(const EVP_MD *md); 411#define EVP_MD_type(e) ((e)->type)
433#define EVP_MD_nid(e) EVP_MD_type(e) 412#define EVP_MD_nid(e) EVP_MD_type(e)
434#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e)) 413#define EVP_MD_name(e) OBJ_nid2sn(EVP_MD_nid(e))
435int EVP_MD_pkey_type(const EVP_MD *md); 414#define EVP_MD_pkey_type(e) ((e)->pkey_type)
436int EVP_MD_size(const EVP_MD *md); 415#define EVP_MD_size(e) ((e)->md_size)
437int EVP_MD_block_size(const EVP_MD *md); 416#define EVP_MD_block_size(e) ((e)->block_size)
438 417
439const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx); 418#define EVP_MD_CTX_md(e) ((e)->digest)
440#define EVP_MD_CTX_size(e) EVP_MD_size(EVP_MD_CTX_md(e)) 419#define EVP_MD_CTX_size(e) EVP_MD_size((e)->digest)
441#define EVP_MD_CTX_block_size(e) EVP_MD_block_size(EVP_MD_CTX_md(e)) 420#define EVP_MD_CTX_block_size(e) EVP_MD_block_size((e)->digest)
442#define EVP_MD_CTX_type(e) EVP_MD_type(EVP_MD_CTX_md(e)) 421#define EVP_MD_CTX_type(e) EVP_MD_type((e)->digest)
443 422
444int EVP_CIPHER_nid(const EVP_CIPHER *cipher); 423#define EVP_CIPHER_nid(e) ((e)->nid)
445#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e)) 424#define EVP_CIPHER_name(e) OBJ_nid2sn(EVP_CIPHER_nid(e))
446int EVP_CIPHER_block_size(const EVP_CIPHER *cipher); 425#define EVP_CIPHER_block_size(e) ((e)->block_size)
447int EVP_CIPHER_key_length(const EVP_CIPHER *cipher); 426#define EVP_CIPHER_key_length(e) ((e)->key_len)
448int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher); 427#define EVP_CIPHER_iv_length(e) ((e)->iv_len)
449unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher); 428#define EVP_CIPHER_flags(e) ((e)->flags)
450#define EVP_CIPHER_mode(e) (EVP_CIPHER_flags(e) & EVP_CIPH_MODE) 429#define EVP_CIPHER_mode(e) (((e)->flags) & EVP_CIPH_MODE)
451 430
452const EVP_CIPHER * EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx); 431#define EVP_CIPHER_CTX_cipher(e) ((e)->cipher)
453int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx); 432#define EVP_CIPHER_CTX_nid(e) ((e)->cipher->nid)
454int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx); 433#define EVP_CIPHER_CTX_block_size(e) ((e)->cipher->block_size)
455int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx); 434#define EVP_CIPHER_CTX_key_length(e) ((e)->key_len)
456int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx); 435#define EVP_CIPHER_CTX_iv_length(e) ((e)->cipher->iv_len)
457void * EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx); 436#define EVP_CIPHER_CTX_get_app_data(e) ((e)->app_data)
458void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data); 437#define EVP_CIPHER_CTX_set_app_data(e,d) ((e)->app_data=(char *)(d))
459#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c)) 438#define EVP_CIPHER_CTX_type(c) EVP_CIPHER_type(EVP_CIPHER_CTX_cipher(c))
460unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx); 439#define EVP_CIPHER_CTX_flags(e) ((e)->cipher->flags)
461#define EVP_CIPHER_CTX_mode(e) (EVP_CIPHER_CTX_flags(e) & EVP_CIPH_MODE) 440#define EVP_CIPHER_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
441#define EVP_CIPHER_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
442#define EVP_CIPHER_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
443#define EVP_CIPHER_CTX_mode(e) ((e)->cipher->flags & EVP_CIPH_MODE)
462 444
463#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80) 445#define EVP_ENCODE_LENGTH(l) (((l+2)/3*4)+(l/48+1)*2+80)
464#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80) 446#define EVP_DECODE_LENGTH(l) ((l+3)/4*3+80)
@@ -483,10 +465,7 @@ void BIO_set_md(BIO *,const EVP_MD *md);
483#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL) 465#define BIO_get_cipher_status(b) BIO_ctrl(b,BIO_C_GET_CIPHER_STATUS,0,NULL)
484#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp) 466#define BIO_get_cipher_ctx(b,c_pp) BIO_ctrl(b,BIO_C_GET_CIPHER_CTX,0,(char *)c_pp)
485 467
486int EVP_Cipher(EVP_CIPHER_CTX *c, 468#define EVP_Cipher(c,o,i,l) (c)->cipher->do_cipher((c),(o),(i),(l))
487 unsigned char *out,
488 const unsigned char *in,
489 unsigned int inl);
490 469
491#define EVP_add_cipher_alias(n,alias) \ 470#define EVP_add_cipher_alias(n,alias) \
492 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n)) 471 OBJ_NAME_add((alias),OBJ_NAME_TYPE_CIPHER_METH|OBJ_NAME_ALIAS,(n))
@@ -502,14 +481,14 @@ int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx);
502EVP_MD_CTX *EVP_MD_CTX_create(void); 481EVP_MD_CTX *EVP_MD_CTX_create(void);
503void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); 482void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx);
504int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in); 483int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out,const EVP_MD_CTX *in);
505void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags); 484#define EVP_MD_CTX_set_flags(ctx,flgs) ((ctx)->flags|=(flgs))
506void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags); 485#define EVP_MD_CTX_clear_flags(ctx,flgs) ((ctx)->flags&=~(flgs))
507int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx,int flags); 486#define EVP_MD_CTX_test_flags(ctx,flgs) ((ctx)->flags&(flgs))
508int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl); 487int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl);
509int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d, 488int EVP_DigestUpdate(EVP_MD_CTX *ctx,const void *d,
510 size_t cnt); 489 unsigned int cnt);
511int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); 490int EVP_DigestFinal_ex(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
512int EVP_Digest(const void *data, size_t count, 491int EVP_Digest(void *data, unsigned int count,
513 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl); 492 unsigned char *md, unsigned int *size, const EVP_MD *type, ENGINE *impl);
514 493
515int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in); 494int EVP_MD_CTX_copy(EVP_MD_CTX *out,const EVP_MD_CTX *in);
@@ -517,7 +496,7 @@ int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type);
517int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s); 496int EVP_DigestFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s);
518 497
519int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify); 498int EVP_read_pw_string(char *buf,int length,const char *prompt,int verify);
520void EVP_set_pw_prompt(const char *prompt); 499void EVP_set_pw_prompt(char *prompt);
521char * EVP_get_pw_prompt(void); 500char * EVP_get_pw_prompt(void);
522 501
523int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md, 502int EVP_BytesToKey(const EVP_CIPHER *type,const EVP_MD *md,
@@ -556,48 +535,43 @@ int EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *outm, int *outl);
556int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s, 535int EVP_SignFinal(EVP_MD_CTX *ctx,unsigned char *md,unsigned int *s,
557 EVP_PKEY *pkey); 536 EVP_PKEY *pkey);
558 537
559int EVP_VerifyFinal(EVP_MD_CTX *ctx,const unsigned char *sigbuf, 538int EVP_VerifyFinal(EVP_MD_CTX *ctx,unsigned char *sigbuf,
560 unsigned int siglen,EVP_PKEY *pkey); 539 unsigned int siglen,EVP_PKEY *pkey);
561 540
562int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type, 541int EVP_OpenInit(EVP_CIPHER_CTX *ctx,const EVP_CIPHER *type,unsigned char *ek,
563 const unsigned char *ek, int ekl, const unsigned char *iv, 542 int ekl,unsigned char *iv,EVP_PKEY *priv);
564 EVP_PKEY *priv);
565int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl); 543int EVP_OpenFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl);
566 544
567int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 545int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek,
568 unsigned char **ek, int *ekl, unsigned char *iv, 546 int *ekl, unsigned char *iv,EVP_PKEY **pubk, int npubk);
569 EVP_PKEY **pubk, int npubk);
570int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl); 547int EVP_SealFinal(EVP_CIPHER_CTX *ctx,unsigned char *out,int *outl);
571 548
572void EVP_EncodeInit(EVP_ENCODE_CTX *ctx); 549void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
573void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, 550void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,
574 const unsigned char *in,int inl); 551 int *outl,unsigned char *in,int inl);
575void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl); 552void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl);
576int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n); 553int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
577 554
578void EVP_DecodeInit(EVP_ENCODE_CTX *ctx); 555void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
579int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl, 556int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx,unsigned char *out,int *outl,
580 const unsigned char *in, int inl); 557 unsigned char *in, int inl);
581int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned 558int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
582 char *out, int *outl); 559 char *out, int *outl);
583int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n); 560int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
584 561
585void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a); 562void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *a);
586int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a); 563int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *a);
587EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void);
588void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *a);
589int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen); 564int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *x, int keylen);
590int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad); 565int EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *c, int pad);
591int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr); 566int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr);
592int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key);
593 567
594#ifndef OPENSSL_NO_BIO 568#ifndef OPENSSL_NO_BIO
595BIO_METHOD *BIO_f_md(void); 569BIO_METHOD *BIO_f_md(void);
596BIO_METHOD *BIO_f_base64(void); 570BIO_METHOD *BIO_f_base64(void);
597BIO_METHOD *BIO_f_cipher(void); 571BIO_METHOD *BIO_f_cipher(void);
598BIO_METHOD *BIO_f_reliable(void); 572BIO_METHOD *BIO_f_reliable(void);
599void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,const unsigned char *k, 573void BIO_set_cipher(BIO *b,const EVP_CIPHER *c,unsigned char *k,
600 const unsigned char *i, int enc); 574 unsigned char *i, int enc);
601#endif 575#endif
602 576
603const EVP_MD *EVP_md_null(void); 577const EVP_MD *EVP_md_null(void);
@@ -615,8 +589,7 @@ const EVP_MD *EVP_sha(void);
615const EVP_MD *EVP_sha1(void); 589const EVP_MD *EVP_sha1(void);
616const EVP_MD *EVP_dss(void); 590const EVP_MD *EVP_dss(void);
617const EVP_MD *EVP_dss1(void); 591const EVP_MD *EVP_dss1(void);
618const EVP_MD *EVP_ecdsa(void); 592#ifdef OPENSSL_FIPS
619#endif
620#ifndef OPENSSL_NO_SHA256 593#ifndef OPENSSL_NO_SHA256
621const EVP_MD *EVP_sha224(void); 594const EVP_MD *EVP_sha224(void);
622const EVP_MD *EVP_sha256(void); 595const EVP_MD *EVP_sha256(void);
@@ -625,6 +598,8 @@ const EVP_MD *EVP_sha256(void);
625const EVP_MD *EVP_sha384(void); 598const EVP_MD *EVP_sha384(void);
626const EVP_MD *EVP_sha512(void); 599const EVP_MD *EVP_sha512(void);
627#endif 600#endif
601#endif
602#endif
628#ifndef OPENSSL_NO_MDC2 603#ifndef OPENSSL_NO_MDC2
629const EVP_MD *EVP_mdc2(void); 604const EVP_MD *EVP_mdc2(void);
630#endif 605#endif
@@ -742,36 +717,8 @@ const EVP_CIPHER *EVP_aes_256_ofb(void);
742const EVP_CIPHER *EVP_aes_256_ctr(void); 717const EVP_CIPHER *EVP_aes_256_ctr(void);
743#endif 718#endif
744#endif 719#endif
745#ifndef OPENSSL_NO_CAMELLIA 720#ifndef OPENSSL_NO_ACSS
746const EVP_CIPHER *EVP_camellia_128_ecb(void); 721const EVP_CIPHER *EVP_acss(void);
747const EVP_CIPHER *EVP_camellia_128_cbc(void);
748const EVP_CIPHER *EVP_camellia_128_cfb1(void);
749const EVP_CIPHER *EVP_camellia_128_cfb8(void);
750const EVP_CIPHER *EVP_camellia_128_cfb128(void);
751# define EVP_camellia_128_cfb EVP_camellia_128_cfb128
752const EVP_CIPHER *EVP_camellia_128_ofb(void);
753const EVP_CIPHER *EVP_camellia_192_ecb(void);
754const EVP_CIPHER *EVP_camellia_192_cbc(void);
755const EVP_CIPHER *EVP_camellia_192_cfb1(void);
756const EVP_CIPHER *EVP_camellia_192_cfb8(void);
757const EVP_CIPHER *EVP_camellia_192_cfb128(void);
758# define EVP_camellia_192_cfb EVP_camellia_192_cfb128
759const EVP_CIPHER *EVP_camellia_192_ofb(void);
760const EVP_CIPHER *EVP_camellia_256_ecb(void);
761const EVP_CIPHER *EVP_camellia_256_cbc(void);
762const EVP_CIPHER *EVP_camellia_256_cfb1(void);
763const EVP_CIPHER *EVP_camellia_256_cfb8(void);
764const EVP_CIPHER *EVP_camellia_256_cfb128(void);
765# define EVP_camellia_256_cfb EVP_camellia_256_cfb128
766const EVP_CIPHER *EVP_camellia_256_ofb(void);
767#endif
768
769#ifndef OPENSSL_NO_SEED
770const EVP_CIPHER *EVP_seed_ecb(void);
771const EVP_CIPHER *EVP_seed_cbc(void);
772const EVP_CIPHER *EVP_seed_cfb128(void);
773# define EVP_seed_cfb EVP_seed_cfb128
774const EVP_CIPHER *EVP_seed_ofb(void);
775#endif 722#endif
776 723
777void OPENSSL_add_all_algorithms_noconf(void); 724void OPENSSL_add_all_algorithms_noconf(void);
@@ -798,12 +745,10 @@ const EVP_CIPHER *EVP_get_cipherbyname(const char *name);
798const EVP_MD *EVP_get_digestbyname(const char *name); 745const EVP_MD *EVP_get_digestbyname(const char *name);
799void EVP_cleanup(void); 746void EVP_cleanup(void);
800 747
801int EVP_PKEY_decrypt(unsigned char *dec_key, 748int EVP_PKEY_decrypt(unsigned char *dec_key,unsigned char *enc_key,
802 const unsigned char *enc_key,int enc_key_len, 749 int enc_key_len,EVP_PKEY *private_key);
803 EVP_PKEY *private_key);
804int EVP_PKEY_encrypt(unsigned char *enc_key, 750int EVP_PKEY_encrypt(unsigned char *enc_key,
805 const unsigned char *key,int key_len, 751 unsigned char *key,int key_len,EVP_PKEY *pub_key);
806 EVP_PKEY *pub_key);
807int EVP_PKEY_type(int type); 752int EVP_PKEY_type(int type);
808int EVP_PKEY_bits(EVP_PKEY *pkey); 753int EVP_PKEY_bits(EVP_PKEY *pkey);
809int EVP_PKEY_size(EVP_PKEY *pkey); 754int EVP_PKEY_size(EVP_PKEY *pkey);
@@ -824,31 +769,24 @@ struct dh_st;
824int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key); 769int EVP_PKEY_set1_DH(EVP_PKEY *pkey,struct dh_st *key);
825struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey); 770struct dh_st *EVP_PKEY_get1_DH(EVP_PKEY *pkey);
826#endif 771#endif
827#ifndef OPENSSL_NO_EC 772
828struct ec_key_st;
829int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey,struct ec_key_st *key);
830struct ec_key_st *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey);
831#endif
832 773
833EVP_PKEY * EVP_PKEY_new(void); 774EVP_PKEY * EVP_PKEY_new(void);
834void EVP_PKEY_free(EVP_PKEY *pkey); 775void EVP_PKEY_free(EVP_PKEY *pkey);
835 776EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, unsigned char **pp,
836EVP_PKEY * d2i_PublicKey(int type,EVP_PKEY **a, const unsigned char **pp,
837 long length); 777 long length);
838int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp); 778int i2d_PublicKey(EVP_PKEY *a, unsigned char **pp);
839 779
840EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, const unsigned char **pp, 780EVP_PKEY * d2i_PrivateKey(int type,EVP_PKEY **a, unsigned char **pp,
841 long length); 781 long length);
842EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, 782EVP_PKEY * d2i_AutoPrivateKey(EVP_PKEY **a, unsigned char **pp,
843 long length); 783 long length);
844int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp); 784int i2d_PrivateKey(EVP_PKEY *a, unsigned char **pp);
845 785
846int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from); 786int EVP_PKEY_copy_parameters(EVP_PKEY *to,EVP_PKEY *from);
847int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey); 787int EVP_PKEY_missing_parameters(EVP_PKEY *pkey);
848int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode); 788int EVP_PKEY_save_parameters(EVP_PKEY *pkey,int mode);
849int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b); 789int EVP_PKEY_cmp_parameters(EVP_PKEY *a,EVP_PKEY *b);
850
851int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b);
852 790
853int EVP_CIPHER_type(const EVP_CIPHER *ctx); 791int EVP_CIPHER_type(const EVP_CIPHER *ctx);
854 792
@@ -865,7 +803,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
865 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, 803 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
866 int en_de); 804 int en_de);
867int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, 805int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
868 const unsigned char *salt, int saltlen, int iter, 806 unsigned char *salt, int saltlen, int iter,
869 int keylen, unsigned char *out); 807 int keylen, unsigned char *out);
870int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 808int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
871 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, 809 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md,
@@ -888,32 +826,30 @@ void ERR_load_EVP_strings(void);
888/* Error codes for the EVP functions. */ 826/* Error codes for the EVP functions. */
889 827
890/* Function codes. */ 828/* Function codes. */
891#define EVP_F_AES_INIT_KEY 133 829#define EVP_F_AES_INIT_KEY 129
892#define EVP_F_CAMELLIA_INIT_KEY 159
893#define EVP_F_D2I_PKEY 100 830#define EVP_F_D2I_PKEY 100
894#define EVP_F_DSAPKEY2PKCS8 134 831#define EVP_F_EVP_ADD_CIPHER 130
895#define EVP_F_DSA_PKEY2PKCS8 135 832#define EVP_F_EVP_ADD_DIGEST 131
896#define EVP_F_ECDSA_PKEY2PKCS8 129 833#define EVP_F_EVP_CIPHERINIT 123
897#define EVP_F_ECKEY_PKEY2PKCS8 132
898#define EVP_F_EVP_CIPHERINIT_EX 123
899#define EVP_F_EVP_CIPHER_CTX_CTRL 124 834#define EVP_F_EVP_CIPHER_CTX_CTRL 124
900#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122 835#define EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH 122
901#define EVP_F_EVP_DECRYPTFINAL_EX 101 836#define EVP_F_EVP_DECRYPTFINAL 101
902#define EVP_F_EVP_DIGESTINIT_EX 128 837#define EVP_F_EVP_DIGESTINIT 128
903#define EVP_F_EVP_ENCRYPTFINAL_EX 127 838#define EVP_F_EVP_ENCRYPTFINAL 127
904#define EVP_F_EVP_MD_CTX_COPY_EX 110 839#define EVP_F_EVP_GET_CIPHERBYNAME 132
840#define EVP_F_EVP_GET_DIGESTBYNAME 133
841#define EVP_F_EVP_MD_CTX_COPY 110
905#define EVP_F_EVP_OPENINIT 102 842#define EVP_F_EVP_OPENINIT 102
906#define EVP_F_EVP_PBE_ALG_ADD 115 843#define EVP_F_EVP_PBE_ALG_ADD 115
907#define EVP_F_EVP_PBE_CIPHERINIT 116 844#define EVP_F_EVP_PBE_CIPHERINIT 116
908#define EVP_F_EVP_PKCS82PKEY 111 845#define EVP_F_EVP_PKCS82PKEY 111
909#define EVP_F_EVP_PKEY2PKCS8_BROKEN 113 846#define EVP_F_EVP_PKCS8_SET_BROKEN 112
847#define EVP_F_EVP_PKEY2PKCS8 113
910#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103 848#define EVP_F_EVP_PKEY_COPY_PARAMETERS 103
911#define EVP_F_EVP_PKEY_DECRYPT 104 849#define EVP_F_EVP_PKEY_DECRYPT 104
912#define EVP_F_EVP_PKEY_ENCRYPT 105 850#define EVP_F_EVP_PKEY_ENCRYPT 105
913#define EVP_F_EVP_PKEY_GET1_DH 119 851#define EVP_F_EVP_PKEY_GET1_DH 119
914#define EVP_F_EVP_PKEY_GET1_DSA 120 852#define EVP_F_EVP_PKEY_GET1_DSA 120
915#define EVP_F_EVP_PKEY_GET1_ECDSA 130
916#define EVP_F_EVP_PKEY_GET1_EC_KEY 131
917#define EVP_F_EVP_PKEY_GET1_RSA 121 853#define EVP_F_EVP_PKEY_GET1_RSA 121
918#define EVP_F_EVP_PKEY_NEW 106 854#define EVP_F_EVP_PKEY_NEW 106
919#define EVP_F_EVP_RIJNDAEL 126 855#define EVP_F_EVP_RIJNDAEL 126
@@ -921,32 +857,28 @@ void ERR_load_EVP_strings(void);
921#define EVP_F_EVP_VERIFYFINAL 108 857#define EVP_F_EVP_VERIFYFINAL 108
922#define EVP_F_PKCS5_PBE_KEYIVGEN 117 858#define EVP_F_PKCS5_PBE_KEYIVGEN 117
923#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118 859#define EVP_F_PKCS5_V2_PBE_KEYIVGEN 118
924#define EVP_F_PKCS8_SET_BROKEN 112
925#define EVP_F_RC2_MAGIC_TO_METH 109 860#define EVP_F_RC2_MAGIC_TO_METH 109
926#define EVP_F_RC5_CTRL 125 861#define EVP_F_RC5_CTRL 125
927 862
928/* Reason codes. */ 863/* Reason codes. */
929#define EVP_R_AES_KEY_SETUP_FAILED 143 864#define EVP_R_AES_KEY_SETUP_FAILED 140
930#define EVP_R_ASN1_LIB 140
931#define EVP_R_BAD_BLOCK_LENGTH 136 865#define EVP_R_BAD_BLOCK_LENGTH 136
932#define EVP_R_BAD_DECRYPT 100 866#define EVP_R_BAD_DECRYPT 100
933#define EVP_R_BAD_KEY_LENGTH 137 867#define EVP_R_BAD_KEY_LENGTH 137
934#define EVP_R_BN_DECODE_ERROR 112 868#define EVP_R_BN_DECODE_ERROR 112
935#define EVP_R_BN_PUBKEY_ERROR 113 869#define EVP_R_BN_PUBKEY_ERROR 113
936#define EVP_R_CAMELLIA_KEY_SETUP_FAILED 157
937#define EVP_R_CIPHER_PARAMETER_ERROR 122 870#define EVP_R_CIPHER_PARAMETER_ERROR 122
938#define EVP_R_CTRL_NOT_IMPLEMENTED 132 871#define EVP_R_CTRL_NOT_IMPLEMENTED 132
939#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133 872#define EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED 133
940#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138 873#define EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH 138
941#define EVP_R_DECODE_ERROR 114 874#define EVP_R_DECODE_ERROR 114
942#define EVP_R_DIFFERENT_KEY_TYPES 101 875#define EVP_R_DIFFERENT_KEY_TYPES 101
876#define EVP_R_DISABLED_FOR_FIPS 141
943#define EVP_R_ENCODE_ERROR 115 877#define EVP_R_ENCODE_ERROR 115
944#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119 878#define EVP_R_EVP_PBE_CIPHERINIT_ERROR 119
945#define EVP_R_EXPECTING_AN_RSA_KEY 127 879#define EVP_R_EXPECTING_AN_RSA_KEY 127
946#define EVP_R_EXPECTING_A_DH_KEY 128 880#define EVP_R_EXPECTING_A_DH_KEY 128
947#define EVP_R_EXPECTING_A_DSA_KEY 129 881#define EVP_R_EXPECTING_A_DSA_KEY 129
948#define EVP_R_EXPECTING_A_ECDSA_KEY 141
949#define EVP_R_EXPECTING_A_EC_KEY 142
950#define EVP_R_INITIALIZATION_ERROR 134 882#define EVP_R_INITIALIZATION_ERROR 134
951#define EVP_R_INPUT_NOT_INITIALIZED 111 883#define EVP_R_INPUT_NOT_INITIALIZED 111
952#define EVP_R_INVALID_KEY_LENGTH 130 884#define EVP_R_INVALID_KEY_LENGTH 130
@@ -971,7 +903,6 @@ void ERR_load_EVP_strings(void);
971#define EVP_R_UNSUPPORTED_SALT_TYPE 126 903#define EVP_R_UNSUPPORTED_SALT_TYPE 126
972#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109 904#define EVP_R_WRONG_FINAL_BLOCK_LENGTH 109
973#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110 905#define EVP_R_WRONG_PUBLIC_KEY_TYPE 110
974#define EVP_R_SEED_KEY_SETUP_FAILED 162
975 906
976#ifdef __cplusplus 907#ifdef __cplusplus
977} 908}
diff --git a/src/lib/libcrypto/evp/evp_acnf.c b/src/lib/libcrypto/evp/evp_acnf.c
new file mode 100644
index 0000000000..ff3e311cc5
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_acnf.c
@@ -0,0 +1,73 @@
1/* evp_acnf.c */
2/* Written by Stephen Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2001.
4 */
5/* ====================================================================
6 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include "cryptlib.h"
60#include <openssl/evp.h>
61#include <openssl/conf.h>
62
63
64/* Load all algorithms and configure OpenSSL.
65 * This function is called automatically when
66 * OPENSSL_LOAD_CONF is set.
67 */
68
69void OPENSSL_add_all_algorithms_conf(void)
70 {
71 OPENSSL_add_all_algorithms_noconf();
72 OPENSSL_config(NULL);
73 }
diff --git a/src/lib/libcrypto/evp/evp_enc.c b/src/lib/libcrypto/evp/evp_enc.c
index a1904993bf..f549eeb437 100644
--- a/src/lib/libcrypto/evp/evp_enc.c
+++ b/src/lib/libcrypto/evp/evp_enc.c
@@ -60,13 +60,12 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/err.h> 62#include <openssl/err.h>
63#include <openssl/rand.h>
64#ifndef OPENSSL_NO_ENGINE 63#ifndef OPENSSL_NO_ENGINE
65#include <openssl/engine.h> 64#include <openssl/engine.h>
66#endif 65#endif
67#include "evp_locl.h" 66#include "evp_locl.h"
68 67
69const char EVP_version[]="EVP" OPENSSL_VERSION_PTEXT; 68const char *EVP_version="EVP" OPENSSL_VERSION_PTEXT;
70 69
71void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx) 70void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
72 { 71 {
@@ -74,13 +73,6 @@ void EVP_CIPHER_CTX_init(EVP_CIPHER_CTX *ctx)
74 /* ctx->cipher=NULL; */ 73 /* ctx->cipher=NULL; */
75 } 74 }
76 75
77EVP_CIPHER_CTX *EVP_CIPHER_CTX_new(void)
78 {
79 EVP_CIPHER_CTX *ctx=OPENSSL_malloc(sizeof *ctx);
80 if (ctx)
81 EVP_CIPHER_CTX_init(ctx);
82 return ctx;
83 }
84 76
85int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, 77int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
86 const unsigned char *key, const unsigned char *iv, int enc) 78 const unsigned char *key, const unsigned char *iv, int enc)
@@ -90,6 +82,48 @@ int EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
90 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc); 82 return EVP_CipherInit_ex(ctx,cipher,NULL,key,iv,enc);
91 } 83 }
92 84
85#ifdef OPENSSL_FIPS
86
87/* The purpose of these is to trap programs that attempt to use non FIPS
88 * algorithms in FIPS mode and ignore the errors.
89 */
90
91int bad_init(EVP_CIPHER_CTX *ctx, const unsigned char *key,
92 const unsigned char *iv, int enc)
93 { FIPS_ERROR_IGNORED("Cipher init"); return 0;}
94
95int bad_do_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out,
96 const unsigned char *in, unsigned int inl)
97 { FIPS_ERROR_IGNORED("Cipher update"); return 0;}
98
99/* NB: no cleanup because it is allowed after failed init */
100
101int bad_set_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
102 { FIPS_ERROR_IGNORED("Cipher set_asn1"); return 0;}
103int bad_get_asn1(EVP_CIPHER_CTX *ctx, ASN1_TYPE *typ)
104 { FIPS_ERROR_IGNORED("Cipher get_asn1"); return 0;}
105int bad_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
106 { FIPS_ERROR_IGNORED("Cipher ctrl"); return 0;}
107
108static const EVP_CIPHER bad_cipher =
109 {
110 0,
111 0,
112 0,
113 0,
114 0,
115 bad_init,
116 bad_do_cipher,
117 NULL,
118 0,
119 bad_set_asn1,
120 bad_get_asn1,
121 bad_ctrl,
122 NULL
123 };
124
125#endif
126
93int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl, 127int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *impl,
94 const unsigned char *key, const unsigned char *iv, int enc) 128 const unsigned char *key, const unsigned char *iv, int enc)
95 { 129 {
@@ -124,7 +158,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
124 { 158 {
125 if (!ENGINE_init(impl)) 159 if (!ENGINE_init(impl))
126 { 160 {
127 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); 161 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
128 return 0; 162 return 0;
129 } 163 }
130 } 164 }
@@ -141,7 +175,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
141 * control history, is that we should at least 175 * control history, is that we should at least
142 * be able to avoid using US mispellings of 176 * be able to avoid using US mispellings of
143 * "initialisation"? */ 177 * "initialisation"? */
144 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); 178 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
145 return 0; 179 return 0;
146 } 180 }
147 /* We'll use the ENGINE's private cipher definition */ 181 /* We'll use the ENGINE's private cipher definition */
@@ -154,14 +188,13 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
154 else 188 else
155 ctx->engine = NULL; 189 ctx->engine = NULL;
156#endif 190#endif
157
158 ctx->cipher=cipher; 191 ctx->cipher=cipher;
159 if (ctx->cipher->ctx_size) 192 if (ctx->cipher->ctx_size)
160 { 193 {
161 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size); 194 ctx->cipher_data=OPENSSL_malloc(ctx->cipher->ctx_size);
162 if (!ctx->cipher_data) 195 if (!ctx->cipher_data)
163 { 196 {
164 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE); 197 EVPerr(EVP_F_EVP_CIPHERINIT, ERR_R_MALLOC_FAILURE);
165 return 0; 198 return 0;
166 } 199 }
167 } 200 }
@@ -175,14 +208,14 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher, ENGINE *imp
175 { 208 {
176 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL)) 209 if(!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_INIT, 0, NULL))
177 { 210 {
178 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_INITIALIZATION_ERROR); 211 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_INITIALIZATION_ERROR);
179 return 0; 212 return 0;
180 } 213 }
181 } 214 }
182 } 215 }
183 else if(!ctx->cipher) 216 else if(!ctx->cipher)
184 { 217 {
185 EVPerr(EVP_F_EVP_CIPHERINIT_EX, EVP_R_NO_CIPHER_SET); 218 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_NO_CIPHER_SET);
186 return 0; 219 return 0;
187 } 220 }
188#ifndef OPENSSL_NO_ENGINE 221#ifndef OPENSSL_NO_ENGINE
@@ -207,8 +240,7 @@ skip_to_init:
207 240
208 case EVP_CIPH_CBC_MODE: 241 case EVP_CIPH_CBC_MODE:
209 242
210 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= 243 OPENSSL_assert(EVP_CIPHER_CTX_iv_length(ctx) <= sizeof ctx->iv);
211 (int)sizeof(ctx->iv));
212 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx)); 244 if(iv) memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_iv_length(ctx));
213 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx)); 245 memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_iv_length(ctx));
214 break; 246 break;
@@ -219,6 +251,24 @@ skip_to_init:
219 } 251 }
220 } 252 }
221 253
254#ifdef OPENSSL_FIPS
255 /* After 'key' is set no further parameters changes are permissible.
256 * So only check for non FIPS enabling at this point.
257 */
258 if (key && FIPS_mode())
259 {
260 if (!(ctx->cipher->flags & EVP_CIPH_FLAG_FIPS)
261 & !(ctx->flags & EVP_CIPH_FLAG_NON_FIPS_ALLOW))
262 {
263 EVPerr(EVP_F_EVP_CIPHERINIT, EVP_R_DISABLED_FOR_FIPS);
264 ERR_add_error_data(2, "cipher=",
265 EVP_CIPHER_name(ctx->cipher));
266 ctx->cipher = &bad_cipher;
267 return 0;
268 }
269 }
270#endif
271
222 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) { 272 if(key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
223 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0; 273 if(!ctx->cipher->init(ctx,key,iv,enc)) return 0;
224 } 274 }
@@ -295,7 +345,7 @@ int EVP_EncryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
295 } 345 }
296 i=ctx->buf_len; 346 i=ctx->buf_len;
297 bl=ctx->cipher->block_size; 347 bl=ctx->cipher->block_size;
298 OPENSSL_assert(bl <= (int)sizeof(ctx->buf)); 348 OPENSSL_assert(bl <= sizeof ctx->buf);
299 if (i != 0) 349 if (i != 0)
300 { 350 {
301 if (i+inl < bl) 351 if (i+inl < bl)
@@ -341,8 +391,7 @@ int EVP_EncryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
341 391
342int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) 392int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
343 { 393 {
344 int n,ret; 394 int i,n,b,bl,ret;
345 unsigned int i, b, bl;
346 395
347 b=ctx->cipher->block_size; 396 b=ctx->cipher->block_size;
348 OPENSSL_assert(b <= sizeof ctx->buf); 397 OPENSSL_assert(b <= sizeof ctx->buf);
@@ -356,7 +405,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
356 { 405 {
357 if(bl) 406 if(bl)
358 { 407 {
359 EVPerr(EVP_F_EVP_ENCRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); 408 EVPerr(EVP_F_EVP_ENCRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
360 return 0; 409 return 0;
361 } 410 }
362 *outl = 0; 411 *outl = 0;
@@ -378,8 +427,7 @@ int EVP_EncryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
378int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, 427int EVP_DecryptUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl,
379 const unsigned char *in, int inl) 428 const unsigned char *in, int inl)
380 { 429 {
381 int fix_len; 430 int b, fix_len;
382 unsigned int b;
383 431
384 if (inl == 0) 432 if (inl == 0)
385 { 433 {
@@ -432,8 +480,8 @@ int EVP_DecryptFinal(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
432 480
433int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl) 481int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
434 { 482 {
435 int i,n; 483 int i,b;
436 unsigned int b; 484 int n;
437 485
438 *outl=0; 486 *outl=0;
439 b=ctx->cipher->block_size; 487 b=ctx->cipher->block_size;
@@ -441,7 +489,7 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
441 { 489 {
442 if(ctx->buf_len) 490 if(ctx->buf_len)
443 { 491 {
444 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH); 492 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH);
445 return 0; 493 return 0;
446 } 494 }
447 *outl = 0; 495 *outl = 0;
@@ -451,21 +499,21 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
451 { 499 {
452 if (ctx->buf_len || !ctx->final_used) 500 if (ctx->buf_len || !ctx->final_used)
453 { 501 {
454 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_WRONG_FINAL_BLOCK_LENGTH); 502 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_WRONG_FINAL_BLOCK_LENGTH);
455 return(0); 503 return(0);
456 } 504 }
457 OPENSSL_assert(b <= sizeof ctx->final); 505 OPENSSL_assert(b <= sizeof ctx->final);
458 n=ctx->final[b-1]; 506 n=ctx->final[b-1];
459 if (n == 0 || n > (int)b) 507 if (n > b)
460 { 508 {
461 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT); 509 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
462 return(0); 510 return(0);
463 } 511 }
464 for (i=0; i<n; i++) 512 for (i=0; i<n; i++)
465 { 513 {
466 if (ctx->final[--b] != n) 514 if (ctx->final[--b] != n)
467 { 515 {
468 EVPerr(EVP_F_EVP_DECRYPTFINAL_EX,EVP_R_BAD_DECRYPT); 516 EVPerr(EVP_F_EVP_DECRYPTFINAL,EVP_R_BAD_DECRYPT);
469 return(0); 517 return(0);
470 } 518 }
471 } 519 }
@@ -479,15 +527,6 @@ int EVP_DecryptFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
479 return(1); 527 return(1);
480 } 528 }
481 529
482void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
483 {
484 if (ctx)
485 {
486 EVP_CIPHER_CTX_cleanup(ctx);
487 OPENSSL_free(ctx);
488 }
489 }
490
491int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c) 530int EVP_CIPHER_CTX_cleanup(EVP_CIPHER_CTX *c)
492 { 531 {
493 if (c->cipher != NULL) 532 if (c->cipher != NULL)
@@ -551,13 +590,3 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
551 } 590 }
552 return ret; 591 return ret;
553} 592}
554
555int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
556 {
557 if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
558 return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key);
559 if (RAND_bytes(key, ctx->key_len) <= 0)
560 return 0;
561 return 1;
562 }
563
diff --git a/src/lib/libcrypto/evp/evp_err.c b/src/lib/libcrypto/evp/evp_err.c
index e8c9e8de9c..77eee070d3 100644
--- a/src/lib/libcrypto/evp/evp_err.c
+++ b/src/lib/libcrypto/evp/evp_err.c
@@ -71,31 +71,29 @@
71static ERR_STRING_DATA EVP_str_functs[]= 71static ERR_STRING_DATA EVP_str_functs[]=
72 { 72 {
73{ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"}, 73{ERR_FUNC(EVP_F_AES_INIT_KEY), "AES_INIT_KEY"},
74{ERR_FUNC(EVP_F_CAMELLIA_INIT_KEY), "CAMELLIA_INIT_KEY"},
75{ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"}, 74{ERR_FUNC(EVP_F_D2I_PKEY), "D2I_PKEY"},
76{ERR_FUNC(EVP_F_DSAPKEY2PKCS8), "DSAPKEY2PKCS8"}, 75{ERR_FUNC(EVP_F_EVP_ADD_CIPHER), "EVP_add_cipher"},
77{ERR_FUNC(EVP_F_DSA_PKEY2PKCS8), "DSA_PKEY2PKCS8"}, 76{ERR_FUNC(EVP_F_EVP_ADD_DIGEST), "EVP_add_digest"},
78{ERR_FUNC(EVP_F_ECDSA_PKEY2PKCS8), "ECDSA_PKEY2PKCS8"}, 77{ERR_FUNC(EVP_F_EVP_CIPHERINIT), "EVP_CipherInit"},
79{ERR_FUNC(EVP_F_ECKEY_PKEY2PKCS8), "ECKEY_PKEY2PKCS8"},
80{ERR_FUNC(EVP_F_EVP_CIPHERINIT_EX), "EVP_CipherInit_ex"},
81{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL), "EVP_CIPHER_CTX_ctrl"}, 78{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_CTRL), "EVP_CIPHER_CTX_ctrl"},
82{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH), "EVP_CIPHER_CTX_set_key_length"}, 79{ERR_FUNC(EVP_F_EVP_CIPHER_CTX_SET_KEY_LENGTH), "EVP_CIPHER_CTX_set_key_length"},
83{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL_EX), "EVP_DecryptFinal_ex"}, 80{ERR_FUNC(EVP_F_EVP_DECRYPTFINAL), "EVP_DecryptFinal"},
84{ERR_FUNC(EVP_F_EVP_DIGESTINIT_EX), "EVP_DigestInit_ex"}, 81{ERR_FUNC(EVP_F_EVP_DIGESTINIT), "EVP_DigestInit"},
85{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL_EX), "EVP_EncryptFinal_ex"}, 82{ERR_FUNC(EVP_F_EVP_ENCRYPTFINAL), "EVP_EncryptFinal"},
86{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY_EX), "EVP_MD_CTX_copy_ex"}, 83{ERR_FUNC(EVP_F_EVP_GET_CIPHERBYNAME), "EVP_get_cipherbyname"},
84{ERR_FUNC(EVP_F_EVP_GET_DIGESTBYNAME), "EVP_get_digestbyname"},
85{ERR_FUNC(EVP_F_EVP_MD_CTX_COPY), "EVP_MD_CTX_copy"},
87{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"}, 86{ERR_FUNC(EVP_F_EVP_OPENINIT), "EVP_OpenInit"},
88{ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD), "EVP_PBE_alg_add"}, 87{ERR_FUNC(EVP_F_EVP_PBE_ALG_ADD), "EVP_PBE_alg_add"},
89{ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT), "EVP_PBE_CipherInit"}, 88{ERR_FUNC(EVP_F_EVP_PBE_CIPHERINIT), "EVP_PBE_CipherInit"},
90{ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"}, 89{ERR_FUNC(EVP_F_EVP_PKCS82PKEY), "EVP_PKCS82PKEY"},
91{ERR_FUNC(EVP_F_EVP_PKEY2PKCS8_BROKEN), "EVP_PKEY2PKCS8_broken"}, 90{ERR_FUNC(EVP_F_EVP_PKCS8_SET_BROKEN), "EVP_PKCS8_SET_BROKEN"},
91{ERR_FUNC(EVP_F_EVP_PKEY2PKCS8), "EVP_PKEY2PKCS8"},
92{ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"}, 92{ERR_FUNC(EVP_F_EVP_PKEY_COPY_PARAMETERS), "EVP_PKEY_copy_parameters"},
93{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"}, 93{ERR_FUNC(EVP_F_EVP_PKEY_DECRYPT), "EVP_PKEY_decrypt"},
94{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT), "EVP_PKEY_encrypt"}, 94{ERR_FUNC(EVP_F_EVP_PKEY_ENCRYPT), "EVP_PKEY_encrypt"},
95{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH), "EVP_PKEY_get1_DH"}, 95{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DH), "EVP_PKEY_get1_DH"},
96{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA), "EVP_PKEY_get1_DSA"}, 96{ERR_FUNC(EVP_F_EVP_PKEY_GET1_DSA), "EVP_PKEY_get1_DSA"},
97{ERR_FUNC(EVP_F_EVP_PKEY_GET1_ECDSA), "EVP_PKEY_GET1_ECDSA"},
98{ERR_FUNC(EVP_F_EVP_PKEY_GET1_EC_KEY), "EVP_PKEY_get1_EC_KEY"},
99{ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA), "EVP_PKEY_get1_RSA"}, 97{ERR_FUNC(EVP_F_EVP_PKEY_GET1_RSA), "EVP_PKEY_get1_RSA"},
100{ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"}, 98{ERR_FUNC(EVP_F_EVP_PKEY_NEW), "EVP_PKEY_new"},
101{ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"}, 99{ERR_FUNC(EVP_F_EVP_RIJNDAEL), "EVP_RIJNDAEL"},
@@ -103,7 +101,6 @@ static ERR_STRING_DATA EVP_str_functs[]=
103{ERR_FUNC(EVP_F_EVP_VERIFYFINAL), "EVP_VerifyFinal"}, 101{ERR_FUNC(EVP_F_EVP_VERIFYFINAL), "EVP_VerifyFinal"},
104{ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN), "PKCS5_PBE_keyivgen"}, 102{ERR_FUNC(EVP_F_PKCS5_PBE_KEYIVGEN), "PKCS5_PBE_keyivgen"},
105{ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN), "PKCS5_v2_PBE_keyivgen"}, 103{ERR_FUNC(EVP_F_PKCS5_V2_PBE_KEYIVGEN), "PKCS5_v2_PBE_keyivgen"},
106{ERR_FUNC(EVP_F_PKCS8_SET_BROKEN), "PKCS8_set_broken"},
107{ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"}, 104{ERR_FUNC(EVP_F_RC2_MAGIC_TO_METH), "RC2_MAGIC_TO_METH"},
108{ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"}, 105{ERR_FUNC(EVP_F_RC5_CTRL), "RC5_CTRL"},
109{0,NULL} 106{0,NULL}
@@ -112,26 +109,23 @@ static ERR_STRING_DATA EVP_str_functs[]=
112static ERR_STRING_DATA EVP_str_reasons[]= 109static ERR_STRING_DATA EVP_str_reasons[]=
113 { 110 {
114{ERR_REASON(EVP_R_AES_KEY_SETUP_FAILED) ,"aes key setup failed"}, 111{ERR_REASON(EVP_R_AES_KEY_SETUP_FAILED) ,"aes key setup failed"},
115{ERR_REASON(EVP_R_ASN1_LIB) ,"asn1 lib"},
116{ERR_REASON(EVP_R_BAD_BLOCK_LENGTH) ,"bad block length"}, 112{ERR_REASON(EVP_R_BAD_BLOCK_LENGTH) ,"bad block length"},
117{ERR_REASON(EVP_R_BAD_DECRYPT) ,"bad decrypt"}, 113{ERR_REASON(EVP_R_BAD_DECRYPT) ,"bad decrypt"},
118{ERR_REASON(EVP_R_BAD_KEY_LENGTH) ,"bad key length"}, 114{ERR_REASON(EVP_R_BAD_KEY_LENGTH) ,"bad key length"},
119{ERR_REASON(EVP_R_BN_DECODE_ERROR) ,"bn decode error"}, 115{ERR_REASON(EVP_R_BN_DECODE_ERROR) ,"bn decode error"},
120{ERR_REASON(EVP_R_BN_PUBKEY_ERROR) ,"bn pubkey error"}, 116{ERR_REASON(EVP_R_BN_PUBKEY_ERROR) ,"bn pubkey error"},
121{ERR_REASON(EVP_R_CAMELLIA_KEY_SETUP_FAILED),"camellia key setup failed"},
122{ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"}, 117{ERR_REASON(EVP_R_CIPHER_PARAMETER_ERROR),"cipher parameter error"},
123{ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED) ,"ctrl not implemented"}, 118{ERR_REASON(EVP_R_CTRL_NOT_IMPLEMENTED) ,"ctrl not implemented"},
124{ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"}, 119{ERR_REASON(EVP_R_CTRL_OPERATION_NOT_IMPLEMENTED),"ctrl operation not implemented"},
125{ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"}, 120{ERR_REASON(EVP_R_DATA_NOT_MULTIPLE_OF_BLOCK_LENGTH),"data not multiple of block length"},
126{ERR_REASON(EVP_R_DECODE_ERROR) ,"decode error"}, 121{ERR_REASON(EVP_R_DECODE_ERROR) ,"decode error"},
127{ERR_REASON(EVP_R_DIFFERENT_KEY_TYPES) ,"different key types"}, 122{ERR_REASON(EVP_R_DIFFERENT_KEY_TYPES) ,"different key types"},
123{ERR_REASON(EVP_R_DISABLED_FOR_FIPS) ,"disabled for fips"},
128{ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"}, 124{ERR_REASON(EVP_R_ENCODE_ERROR) ,"encode error"},
129{ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"}, 125{ERR_REASON(EVP_R_EVP_PBE_CIPHERINIT_ERROR),"evp pbe cipherinit error"},
130{ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"}, 126{ERR_REASON(EVP_R_EXPECTING_AN_RSA_KEY) ,"expecting an rsa key"},
131{ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"}, 127{ERR_REASON(EVP_R_EXPECTING_A_DH_KEY) ,"expecting a dh key"},
132{ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"}, 128{ERR_REASON(EVP_R_EXPECTING_A_DSA_KEY) ,"expecting a dsa key"},
133{ERR_REASON(EVP_R_EXPECTING_A_ECDSA_KEY) ,"expecting a ecdsa key"},
134{ERR_REASON(EVP_R_EXPECTING_A_EC_KEY) ,"expecting a ec key"},
135{ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"}, 129{ERR_REASON(EVP_R_INITIALIZATION_ERROR) ,"initialization error"},
136{ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"}, 130{ERR_REASON(EVP_R_INPUT_NOT_INITIALIZED) ,"input not initialized"},
137{ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"}, 131{ERR_REASON(EVP_R_INVALID_KEY_LENGTH) ,"invalid key length"},
@@ -163,12 +157,15 @@ static ERR_STRING_DATA EVP_str_reasons[]=
163 157
164void ERR_load_EVP_strings(void) 158void ERR_load_EVP_strings(void)
165 { 159 {
166#ifndef OPENSSL_NO_ERR 160 static int init=1;
167 161
168 if (ERR_func_error_string(EVP_str_functs[0].error) == NULL) 162 if (init)
169 { 163 {
164 init=0;
165#ifndef OPENSSL_NO_ERR
170 ERR_load_strings(0,EVP_str_functs); 166 ERR_load_strings(0,EVP_str_functs);
171 ERR_load_strings(0,EVP_str_reasons); 167 ERR_load_strings(0,EVP_str_reasons);
172 }
173#endif 168#endif
169
170 }
174 } 171 }
diff --git a/src/lib/libcrypto/evp/evp_key.c b/src/lib/libcrypto/evp/evp_key.c
index 361ea69ab6..f8650d5df6 100644
--- a/src/lib/libcrypto/evp/evp_key.c
+++ b/src/lib/libcrypto/evp/evp_key.c
@@ -66,7 +66,7 @@
66/* should be init to zeros. */ 66/* should be init to zeros. */
67static char prompt_string[80]; 67static char prompt_string[80];
68 68
69void EVP_set_pw_prompt(const char *prompt) 69void EVP_set_pw_prompt(char *prompt)
70 { 70 {
71 if (prompt == NULL) 71 if (prompt == NULL)
72 prompt_string[0]='\0'; 72 prompt_string[0]='\0';
diff --git a/src/lib/libcrypto/evp/evp_lib.c b/src/lib/libcrypto/evp/evp_lib.c
index edb28ef38e..a63ba19317 100644
--- a/src/lib/libcrypto/evp/evp_lib.c
+++ b/src/lib/libcrypto/evp/evp_lib.c
@@ -68,7 +68,7 @@ int EVP_CIPHER_param_to_asn1(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
68 if (c->cipher->set_asn1_parameters != NULL) 68 if (c->cipher->set_asn1_parameters != NULL)
69 ret=c->cipher->set_asn1_parameters(c,type); 69 ret=c->cipher->set_asn1_parameters(c,type);
70 else 70 else
71 ret=-1; 71 return -1;
72 return(ret); 72 return(ret);
73 } 73 }
74 74
@@ -79,21 +79,20 @@ int EVP_CIPHER_asn1_to_param(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
79 if (c->cipher->get_asn1_parameters != NULL) 79 if (c->cipher->get_asn1_parameters != NULL)
80 ret=c->cipher->get_asn1_parameters(c,type); 80 ret=c->cipher->get_asn1_parameters(c,type);
81 else 81 else
82 ret=-1; 82 return -1;
83 return(ret); 83 return(ret);
84 } 84 }
85 85
86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) 86int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
87 { 87 {
88 int i=0; 88 int i=0,l;
89 unsigned int l;
90 89
91 if (type != NULL) 90 if (type != NULL)
92 { 91 {
93 l=EVP_CIPHER_CTX_iv_length(c); 92 l=EVP_CIPHER_CTX_iv_length(c);
94 OPENSSL_assert(l <= sizeof(c->iv)); 93 OPENSSL_assert(l <= sizeof c->iv);
95 i=ASN1_TYPE_get_octetstring(type,c->oiv,l); 94 i=ASN1_TYPE_get_octetstring(type,c->oiv,l);
96 if (i != (int)l) 95 if (i != l)
97 return(-1); 96 return(-1);
98 else if (i > 0) 97 else if (i > 0)
99 memcpy(c->iv,c->oiv,l); 98 memcpy(c->iv,c->oiv,l);
@@ -103,13 +102,12 @@ int EVP_CIPHER_get_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
103 102
104int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type) 103int EVP_CIPHER_set_asn1_iv(EVP_CIPHER_CTX *c, ASN1_TYPE *type)
105 { 104 {
106 int i=0; 105 int i=0,j;
107 unsigned int j;
108 106
109 if (type != NULL) 107 if (type != NULL)
110 { 108 {
111 j=EVP_CIPHER_CTX_iv_length(c); 109 j=EVP_CIPHER_CTX_iv_length(c);
112 OPENSSL_assert(j <= sizeof(c->iv)); 110 OPENSSL_assert(j <= sizeof c->iv);
113 i=ASN1_TYPE_set_octetstring(type,c->oiv,j); 111 i=ASN1_TYPE_set_octetstring(type,c->oiv,j);
114 } 112 }
115 return(i); 113 return(i);
@@ -168,112 +166,3 @@ int EVP_CIPHER_type(const EVP_CIPHER *ctx)
168 } 166 }
169} 167}
170 168
171int EVP_CIPHER_block_size(const EVP_CIPHER *e)
172 {
173 return e->block_size;
174 }
175
176int EVP_CIPHER_CTX_block_size(const EVP_CIPHER_CTX *ctx)
177 {
178 return ctx->cipher->block_size;
179 }
180
181int EVP_Cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl)
182 {
183 return ctx->cipher->do_cipher(ctx,out,in,inl);
184 }
185
186const EVP_CIPHER *EVP_CIPHER_CTX_cipher(const EVP_CIPHER_CTX *ctx)
187 {
188 return ctx->cipher;
189 }
190
191unsigned long EVP_CIPHER_flags(const EVP_CIPHER *cipher)
192 {
193 return cipher->flags;
194 }
195
196unsigned long EVP_CIPHER_CTX_flags(const EVP_CIPHER_CTX *ctx)
197 {
198 return ctx->cipher->flags;
199 }
200
201void *EVP_CIPHER_CTX_get_app_data(const EVP_CIPHER_CTX *ctx)
202 {
203 return ctx->app_data;
204 }
205
206void EVP_CIPHER_CTX_set_app_data(EVP_CIPHER_CTX *ctx, void *data)
207 {
208 ctx->app_data = data;
209 }
210
211int EVP_CIPHER_iv_length(const EVP_CIPHER *cipher)
212 {
213 return cipher->iv_len;
214 }
215
216int EVP_CIPHER_CTX_iv_length(const EVP_CIPHER_CTX *ctx)
217 {
218 return ctx->cipher->iv_len;
219 }
220
221int EVP_CIPHER_key_length(const EVP_CIPHER *cipher)
222 {
223 return cipher->key_len;
224 }
225
226int EVP_CIPHER_CTX_key_length(const EVP_CIPHER_CTX *ctx)
227 {
228 return ctx->key_len;
229 }
230
231int EVP_CIPHER_nid(const EVP_CIPHER *cipher)
232 {
233 return cipher->nid;
234 }
235
236int EVP_CIPHER_CTX_nid(const EVP_CIPHER_CTX *ctx)
237 {
238 return ctx->cipher->nid;
239 }
240
241int EVP_MD_block_size(const EVP_MD *md)
242 {
243 return md->block_size;
244 }
245
246int EVP_MD_type(const EVP_MD *md)
247 {
248 return md->type;
249 }
250
251int EVP_MD_pkey_type(const EVP_MD *md)
252 {
253 return md->pkey_type;
254 }
255
256int EVP_MD_size(const EVP_MD *md)
257 {
258 return md->md_size;
259 }
260
261const EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
262 {
263 return ctx->digest;
264 }
265
266void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
267 {
268 ctx->flags |= flags;
269 }
270
271void EVP_MD_CTX_clear_flags(EVP_MD_CTX *ctx, int flags)
272 {
273 ctx->flags &= ~flags;
274 }
275
276int EVP_MD_CTX_test_flags(const EVP_MD_CTX *ctx, int flags)
277 {
278 return (ctx->flags & flags);
279 }
diff --git a/src/lib/libcrypto/evp/evp_locl.h b/src/lib/libcrypto/evp/evp_locl.h
index 073b0adcff..f8c5343620 100644
--- a/src/lib/libcrypto/evp/evp_locl.h
+++ b/src/lib/libcrypto/evp/evp_locl.h
@@ -65,7 +65,7 @@
65 bl = ctx->cipher->block_size;\ 65 bl = ctx->cipher->block_size;\
66 if(inl < bl) return 1;\ 66 if(inl < bl) return 1;\
67 inl -= bl; \ 67 inl -= bl; \
68 for(i=0; i <= inl; i+=bl) 68 for(i=0; i <= inl; i+=bl) \
69 69
70#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \ 70#define BLOCK_CIPHER_func_ecb(cname, cprefix, kstruct, ksched) \
71static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ 71static int cname##_ecb_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
@@ -92,7 +92,7 @@ static int cname##_cbc_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const uns
92#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \ 92#define BLOCK_CIPHER_func_cfb(cname, cprefix, cbits, kstruct, ksched) \
93static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \ 93static int cname##_cfb##cbits##_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, unsigned int inl) \
94{\ 94{\
95 cprefix##_cfb##cbits##_encrypt(in, out, (long)(cbits==1?inl*8:inl), &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\ 95 cprefix##_cfb##cbits##_encrypt(in, out, (long)inl, &((kstruct *)ctx->cipher_data)->ksched, ctx->iv, &ctx->num, ctx->encrypt);\
96 return 1;\ 96 return 1;\
97} 97}
98 98
@@ -226,11 +226,27 @@ const EVP_CIPHER *EVP_##cname##_ecb(void) { return &cname##_ecb; }
226 226
227#define EVP_C_DATA(kstruct, ctx) ((kstruct *)(ctx)->cipher_data) 227#define EVP_C_DATA(kstruct, ctx) ((kstruct *)(ctx)->cipher_data)
228 228
229#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len) \ 229#define IMPLEMENT_CFBR(cipher,cprefix,kstruct,ksched,keysize,cbits,iv_len,flags) \
230 BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \ 230 BLOCK_CIPHER_func_cfb(cipher##_##keysize,cprefix,cbits,kstruct,ksched) \
231 BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \ 231 BLOCK_CIPHER_def_cfb(cipher##_##keysize,kstruct, \
232 NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \ 232 NID_##cipher##_##keysize, keysize/8, iv_len, cbits, \
233 0, cipher##_init_key, NULL, \ 233 flags, cipher##_init_key, NULL, \
234 EVP_CIPHER_set_asn1_iv, \ 234 EVP_CIPHER_set_asn1_iv, \
235 EVP_CIPHER_get_asn1_iv, \ 235 EVP_CIPHER_get_asn1_iv, \
236 NULL) 236 NULL)
237
238#ifdef OPENSSL_FIPS
239#define RC2_set_key private_RC2_set_key
240#define RC4_set_key private_RC4_set_key
241#define CAST_set_key private_CAST_set_key
242#define RC5_32_set_key private_RC5_32_set_key
243#define BF_set_key private_BF_set_key
244#define idea_set_encrypt_key private_idea_set_encrypt_key
245
246#define MD5_Init private_MD5_Init
247#define MD4_Init private_MD4_Init
248#define MD2_Init private_MD2_Init
249#define MDC2_Init private_MDC2_Init
250#define SHA_Init private_SHA_Init
251
252#endif
diff --git a/src/lib/libcrypto/evp/evp_pbe.c b/src/lib/libcrypto/evp/evp_pbe.c
index c26d2de0f3..91e545a141 100644
--- a/src/lib/libcrypto/evp/evp_pbe.c
+++ b/src/lib/libcrypto/evp/evp_pbe.c
@@ -74,7 +74,7 @@ const EVP_MD *md;
74EVP_PBE_KEYGEN *keygen; 74EVP_PBE_KEYGEN *keygen;
75} EVP_PBE_CTL; 75} EVP_PBE_CTL;
76 76
77int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen, 77int EVP_PBE_CipherInit (ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de) 78 ASN1_TYPE *param, EVP_CIPHER_CTX *ctx, int en_de)
79{ 79{
80 80
@@ -106,8 +106,7 @@ int EVP_PBE_CipherInit(ASN1_OBJECT *pbe_obj, const char *pass, int passlen,
106 106
107static int pbe_cmp(const char * const *a, const char * const *b) 107static int pbe_cmp(const char * const *a, const char * const *b)
108{ 108{
109 const EVP_PBE_CTL * const *pbe1 = (const EVP_PBE_CTL * const *) a, 109 EVP_PBE_CTL **pbe1 = (EVP_PBE_CTL **) a, **pbe2 = (EVP_PBE_CTL **)b;
110 * const *pbe2 = (const EVP_PBE_CTL * const *)b;
111 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid); 110 return ((*pbe1)->pbe_nid - (*pbe2)->pbe_nid);
112} 111}
113 112
diff --git a/src/lib/libcrypto/evp/evp_pkey.c b/src/lib/libcrypto/evp/evp_pkey.c
index 0147f3e02a..47a69932a5 100644
--- a/src/lib/libcrypto/evp/evp_pkey.c
+++ b/src/lib/libcrypto/evp/evp_pkey.c
@@ -3,7 +3,7 @@
3 * project 1999. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -61,24 +61,14 @@
61#include "cryptlib.h" 61#include "cryptlib.h"
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63#include <openssl/rand.h> 63#include <openssl/rand.h>
64#ifndef OPENSSL_NO_RSA
65#include <openssl/rsa.h>
66#endif
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70#include <openssl/bn.h>
71 64
72#ifndef OPENSSL_NO_DSA 65#ifndef OPENSSL_NO_DSA
73static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey); 66static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
74#endif 67#endif
75#ifndef OPENSSL_NO_EC
76static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8inf, EVP_PKEY *pkey);
77#endif
78 68
79/* Extract a private key from a PKCS8 structure */ 69/* Extract a private key from a PKCS8 structure */
80 70
81EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8) 71EVP_PKEY *EVP_PKCS82PKEY (PKCS8_PRIV_KEY_INFO *p8)
82{ 72{
83 EVP_PKEY *pkey = NULL; 73 EVP_PKEY *pkey = NULL;
84#ifndef OPENSSL_NO_RSA 74#ifndef OPENSSL_NO_RSA
@@ -86,24 +76,16 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
86#endif 76#endif
87#ifndef OPENSSL_NO_DSA 77#ifndef OPENSSL_NO_DSA
88 DSA *dsa = NULL; 78 DSA *dsa = NULL;
89 ASN1_TYPE *t1, *t2;
90 ASN1_INTEGER *privkey; 79 ASN1_INTEGER *privkey;
80 ASN1_TYPE *t1, *t2, *param = NULL;
91 STACK_OF(ASN1_TYPE) *ndsa = NULL; 81 STACK_OF(ASN1_TYPE) *ndsa = NULL;
92#endif
93#ifndef OPENSSL_NO_EC
94 EC_KEY *eckey = NULL;
95 const unsigned char *p_tmp;
96#endif
97#if !defined(OPENSSL_NO_DSA) || !defined(OPENSSL_NO_EC)
98 ASN1_TYPE *param = NULL;
99 BN_CTX *ctx = NULL; 82 BN_CTX *ctx = NULL;
100 int plen; 83 int plen;
101#endif 84#endif
102 X509_ALGOR *a; 85 X509_ALGOR *a;
103 const unsigned char *p; 86 unsigned char *p;
104 const unsigned char *cp; 87 const unsigned char *cp;
105 int pkeylen; 88 int pkeylen;
106 int nid;
107 char obj_tmp[80]; 89 char obj_tmp[80];
108 90
109 if(p8->pkey->type == V_ASN1_OCTET_STRING) { 91 if(p8->pkey->type == V_ASN1_OCTET_STRING) {
@@ -120,8 +102,7 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
120 return NULL; 102 return NULL;
121 } 103 }
122 a = p8->pkeyalg; 104 a = p8->pkeyalg;
123 nid = OBJ_obj2nid(a->algorithm); 105 switch (OBJ_obj2nid(a->algorithm))
124 switch(nid)
125 { 106 {
126#ifndef OPENSSL_NO_RSA 107#ifndef OPENSSL_NO_RSA
127 case NID_rsaEncryption: 108 case NID_rsaEncryption:
@@ -227,112 +208,6 @@ EVP_PKEY *EVP_PKCS82PKEY(PKCS8_PRIV_KEY_INFO *p8)
227 return NULL; 208 return NULL;
228 break; 209 break;
229#endif 210#endif
230#ifndef OPENSSL_NO_EC
231 case NID_X9_62_id_ecPublicKey:
232 p_tmp = p;
233 /* extract the ec parameters */
234 param = p8->pkeyalg->parameter;
235
236 if (!param || ((param->type != V_ASN1_SEQUENCE) &&
237 (param->type != V_ASN1_OBJECT)))
238 {
239 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
240 goto ecerr;
241 }
242
243 if (param->type == V_ASN1_SEQUENCE)
244 {
245 cp = p = param->value.sequence->data;
246 plen = param->value.sequence->length;
247
248 if (!(eckey = d2i_ECParameters(NULL, &cp, plen)))
249 {
250 EVPerr(EVP_F_EVP_PKCS82PKEY,
251 EVP_R_DECODE_ERROR);
252 goto ecerr;
253 }
254 }
255 else
256 {
257 EC_GROUP *group;
258 cp = p = param->value.object->data;
259 plen = param->value.object->length;
260
261 /* type == V_ASN1_OBJECT => the parameters are given
262 * by an asn1 OID
263 */
264 if ((eckey = EC_KEY_new()) == NULL)
265 {
266 EVPerr(EVP_F_EVP_PKCS82PKEY,
267 ERR_R_MALLOC_FAILURE);
268 goto ecerr;
269 }
270 group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(a->parameter->value.object));
271 if (group == NULL)
272 goto ecerr;
273 EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);
274 if (EC_KEY_set_group(eckey, group) == 0)
275 goto ecerr;
276 EC_GROUP_free(group);
277 }
278
279 /* We have parameters now set private key */
280 if (!d2i_ECPrivateKey(&eckey, &p_tmp, pkeylen))
281 {
282 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_DECODE_ERROR);
283 goto ecerr;
284 }
285
286 /* calculate public key (if necessary) */
287 if (EC_KEY_get0_public_key(eckey) == NULL)
288 {
289 const BIGNUM *priv_key;
290 const EC_GROUP *group;
291 EC_POINT *pub_key;
292 /* the public key was not included in the SEC1 private
293 * key => calculate the public key */
294 group = EC_KEY_get0_group(eckey);
295 pub_key = EC_POINT_new(group);
296 if (pub_key == NULL)
297 {
298 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
299 goto ecerr;
300 }
301 if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group)))
302 {
303 EC_POINT_free(pub_key);
304 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
305 goto ecerr;
306 }
307 priv_key = EC_KEY_get0_private_key(eckey);
308 if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, ctx))
309 {
310 EC_POINT_free(pub_key);
311 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
312 goto ecerr;
313 }
314 if (EC_KEY_set_public_key(eckey, pub_key) == 0)
315 {
316 EC_POINT_free(pub_key);
317 EVPerr(EVP_F_EVP_PKCS82PKEY, ERR_R_EC_LIB);
318 goto ecerr;
319 }
320 EC_POINT_free(pub_key);
321 }
322
323 EVP_PKEY_assign_EC_KEY(pkey, eckey);
324 if (ctx)
325 BN_CTX_free(ctx);
326 break;
327ecerr:
328 if (ctx)
329 BN_CTX_free(ctx);
330 if (eckey)
331 EC_KEY_free(eckey);
332 if (pkey)
333 EVP_PKEY_free(pkey);
334 return NULL;
335#endif
336 default: 211 default:
337 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); 212 EVPerr(EVP_F_EVP_PKCS82PKEY, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
338 if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp); 213 if (!a->algorithm) BUF_strlcpy (obj_tmp, "NULL", sizeof obj_tmp);
@@ -356,17 +231,17 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
356 PKCS8_PRIV_KEY_INFO *p8; 231 PKCS8_PRIV_KEY_INFO *p8;
357 232
358 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) { 233 if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {
359 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE); 234 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
360 return NULL; 235 return NULL;
361 } 236 }
362 p8->broken = broken; 237 p8->broken = broken;
363 if (!ASN1_INTEGER_set(p8->version, 0)) { 238 if (!ASN1_INTEGER_set(p8->version, 0)) {
364 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE); 239 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
365 PKCS8_PRIV_KEY_INFO_free (p8); 240 PKCS8_PRIV_KEY_INFO_free (p8);
366 return NULL; 241 return NULL;
367 } 242 }
368 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) { 243 if (!(p8->pkeyalg->parameter = ASN1_TYPE_new ())) {
369 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE); 244 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
370 PKCS8_PRIV_KEY_INFO_free (p8); 245 PKCS8_PRIV_KEY_INFO_free (p8);
371 return NULL; 246 return NULL;
372 } 247 }
@@ -379,9 +254,9 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
379 254
380 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption); 255 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_rsaEncryption);
381 p8->pkeyalg->parameter->type = V_ASN1_NULL; 256 p8->pkeyalg->parameter->type = V_ASN1_NULL;
382 if (!ASN1_pack_string_of (EVP_PKEY,pkey, i2d_PrivateKey, 257 if (!ASN1_pack_string ((char *)pkey, i2d_PrivateKey,
383 &p8->pkey->value.octet_string)) { 258 &p8->pkey->value.octet_string)) {
384 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE); 259 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
385 PKCS8_PRIV_KEY_INFO_free (p8); 260 PKCS8_PRIV_KEY_INFO_free (p8);
386 return NULL; 261 return NULL;
387 } 262 }
@@ -396,22 +271,13 @@ PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
396 271
397 break; 272 break;
398#endif 273#endif
399#ifndef OPENSSL_NO_EC
400 case EVP_PKEY_EC:
401 if (!eckey_pkey2pkcs8(p8, pkey))
402 {
403 PKCS8_PRIV_KEY_INFO_free(p8);
404 return(NULL);
405 }
406 break;
407#endif
408 default: 274 default:
409 EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM); 275 EVPerr(EVP_F_EVP_PKEY2PKCS8, EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
410 PKCS8_PRIV_KEY_INFO_free (p8); 276 PKCS8_PRIV_KEY_INFO_free (p8);
411 return NULL; 277 return NULL;
412 } 278 }
413 RAND_add(p8->pkey->value.octet_string->data, 279 RAND_add(p8->pkey->value.octet_string->data,
414 p8->pkey->value.octet_string->length, 0.0); 280 p8->pkey->value.octet_string->length, 0);
415 return p8; 281 return p8;
416} 282}
417 283
@@ -431,8 +297,10 @@ PKCS8_PRIV_KEY_INFO *PKCS8_set_broken(PKCS8_PRIV_KEY_INFO *p8, int broken)
431 break; 297 break;
432 298
433 default: 299 default:
434 EVPerr(EVP_F_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE); 300 EVPerr(EVP_F_EVP_PKCS8_SET_BROKEN,EVP_R_PKCS8_UNKNOWN_BROKEN_TYPE);
435 return NULL; 301 return NULL;
302 break;
303
436 } 304 }
437} 305}
438 306
@@ -449,24 +317,24 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
449 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa); 317 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);
450 len = i2d_DSAparams (pkey->pkey.dsa, NULL); 318 len = i2d_DSAparams (pkey->pkey.dsa, NULL);
451 if (!(p = OPENSSL_malloc(len))) { 319 if (!(p = OPENSSL_malloc(len))) {
452 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 320 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
453 goto err; 321 goto err;
454 } 322 }
455 q = p; 323 q = p;
456 i2d_DSAparams (pkey->pkey.dsa, &q); 324 i2d_DSAparams (pkey->pkey.dsa, &q);
457 if (!(params = ASN1_STRING_new())) { 325 if (!(params = ASN1_STRING_new())) {
458 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 326 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
459 goto err; 327 goto err;
460 } 328 }
461 if (!ASN1_STRING_set(params, p, len)) { 329 if (!ASN1_STRING_set(params, p, len)) {
462 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 330 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
463 goto err; 331 goto err;
464 } 332 }
465 OPENSSL_free(p); 333 OPENSSL_free(p);
466 p = NULL; 334 p = NULL;
467 /* Get private key into integer */ 335 /* Get private key into integer */
468 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) { 336 if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {
469 EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR); 337 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
470 goto err; 338 goto err;
471 } 339 }
472 340
@@ -475,9 +343,9 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
475 case PKCS8_OK: 343 case PKCS8_OK:
476 case PKCS8_NO_OCTET: 344 case PKCS8_NO_OCTET:
477 345
478 if (!ASN1_pack_string_of(ASN1_INTEGER,prkey, i2d_ASN1_INTEGER, 346 if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,
479 &p8->pkey->value.octet_string)) { 347 &p8->pkey->value.octet_string)) {
480 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 348 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
481 goto err; 349 goto err;
482 } 350 }
483 351
@@ -495,39 +363,39 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
495 params = NULL; 363 params = NULL;
496 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE; 364 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
497 if (!(ndsa = sk_ASN1_TYPE_new_null())) { 365 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
498 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 366 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
499 goto err; 367 goto err;
500 } 368 }
501 if (!(ttmp = ASN1_TYPE_new())) { 369 if (!(ttmp = ASN1_TYPE_new())) {
502 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 370 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
503 goto err; 371 goto err;
504 } 372 }
505 if (!(ttmp->value.integer = 373 if (!(ttmp->value.integer =
506 BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) { 374 BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {
507 EVPerr(EVP_F_DSA_PKEY2PKCS8,EVP_R_ENCODE_ERROR); 375 EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
508 goto err; 376 goto err;
509 } 377 }
510 ttmp->type = V_ASN1_INTEGER; 378 ttmp->type = V_ASN1_INTEGER;
511 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) { 379 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
512 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 380 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
513 goto err; 381 goto err;
514 } 382 }
515 383
516 if (!(ttmp = ASN1_TYPE_new())) { 384 if (!(ttmp = ASN1_TYPE_new())) {
517 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 385 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
518 goto err; 386 goto err;
519 } 387 }
520 ttmp->value.integer = prkey; 388 ttmp->value.integer = prkey;
521 prkey = NULL; 389 prkey = NULL;
522 ttmp->type = V_ASN1_INTEGER; 390 ttmp->type = V_ASN1_INTEGER;
523 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) { 391 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
524 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 392 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
525 goto err; 393 goto err;
526 } 394 }
527 ttmp = NULL; 395 ttmp = NULL;
528 396
529 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) { 397 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
530 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 398 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
531 goto err; 399 goto err;
532 } 400 }
533 401
@@ -535,7 +403,7 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
535 &p8->pkey->value.octet_string->data, 403 &p8->pkey->value.octet_string->data,
536 &p8->pkey->value.octet_string->length)) { 404 &p8->pkey->value.octet_string->length)) {
537 405
538 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 406 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
539 goto err; 407 goto err;
540 } 408 }
541 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); 409 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
@@ -545,36 +413,36 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
545 413
546 p8->pkeyalg->parameter->type = V_ASN1_NULL; 414 p8->pkeyalg->parameter->type = V_ASN1_NULL;
547 if (!(ndsa = sk_ASN1_TYPE_new_null())) { 415 if (!(ndsa = sk_ASN1_TYPE_new_null())) {
548 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 416 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
549 goto err; 417 goto err;
550 } 418 }
551 if (!(ttmp = ASN1_TYPE_new())) { 419 if (!(ttmp = ASN1_TYPE_new())) {
552 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 420 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
553 goto err; 421 goto err;
554 } 422 }
555 ttmp->value.sequence = params; 423 ttmp->value.sequence = params;
556 params = NULL; 424 params = NULL;
557 ttmp->type = V_ASN1_SEQUENCE; 425 ttmp->type = V_ASN1_SEQUENCE;
558 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) { 426 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
559 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 427 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
560 goto err; 428 goto err;
561 } 429 }
562 430
563 if (!(ttmp = ASN1_TYPE_new())) { 431 if (!(ttmp = ASN1_TYPE_new())) {
564 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 432 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
565 goto err; 433 goto err;
566 } 434 }
567 ttmp->value.integer = prkey; 435 ttmp->value.integer = prkey;
568 prkey = NULL; 436 prkey = NULL;
569 ttmp->type = V_ASN1_INTEGER; 437 ttmp->type = V_ASN1_INTEGER;
570 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) { 438 if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {
571 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 439 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
572 goto err; 440 goto err;
573 } 441 }
574 ttmp = NULL; 442 ttmp = NULL;
575 443
576 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) { 444 if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {
577 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 445 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
578 goto err; 446 goto err;
579 } 447 }
580 448
@@ -582,7 +450,7 @@ static int dsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
582 &p8->pkey->value.octet_string->data, 450 &p8->pkey->value.octet_string->data,
583 &p8->pkey->value.octet_string->length)) { 451 &p8->pkey->value.octet_string->length)) {
584 452
585 EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE); 453 EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
586 goto err; 454 goto err;
587 } 455 }
588 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free); 456 sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);
@@ -598,197 +466,3 @@ err:
598 return 0; 466 return 0;
599} 467}
600#endif 468#endif
601
602#ifndef OPENSSL_NO_EC
603static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey)
604{
605 EC_KEY *ec_key;
606 const EC_GROUP *group;
607 unsigned char *p, *pp;
608 int nid, i, ret = 0;
609 unsigned int tmp_flags, old_flags;
610
611 ec_key = pkey->pkey.ec;
612 if (ec_key == NULL || (group = EC_KEY_get0_group(ec_key)) == NULL)
613 {
614 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, EVP_R_MISSING_PARAMETERS);
615 return 0;
616 }
617
618 /* set the ec parameters OID */
619 if (p8->pkeyalg->algorithm)
620 ASN1_OBJECT_free(p8->pkeyalg->algorithm);
621
622 p8->pkeyalg->algorithm = OBJ_nid2obj(NID_X9_62_id_ecPublicKey);
623
624 /* set the ec parameters */
625
626 if (p8->pkeyalg->parameter)
627 {
628 ASN1_TYPE_free(p8->pkeyalg->parameter);
629 p8->pkeyalg->parameter = NULL;
630 }
631
632 if ((p8->pkeyalg->parameter = ASN1_TYPE_new()) == NULL)
633 {
634 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
635 return 0;
636 }
637
638 if (EC_GROUP_get_asn1_flag(group)
639 && (nid = EC_GROUP_get_curve_name(group)))
640 {
641 /* we have a 'named curve' => just set the OID */
642 p8->pkeyalg->parameter->type = V_ASN1_OBJECT;
643 p8->pkeyalg->parameter->value.object = OBJ_nid2obj(nid);
644 }
645 else /* explicit parameters */
646 {
647 if ((i = i2d_ECParameters(ec_key, NULL)) == 0)
648 {
649 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
650 return 0;
651 }
652 if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
653 {
654 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
655 return 0;
656 }
657 pp = p;
658 if (!i2d_ECParameters(ec_key, &pp))
659 {
660 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
661 OPENSSL_free(p);
662 return 0;
663 }
664 p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;
665 if ((p8->pkeyalg->parameter->value.sequence
666 = ASN1_STRING_new()) == NULL)
667 {
668 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_ASN1_LIB);
669 OPENSSL_free(p);
670 return 0;
671 }
672 ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, i);
673 OPENSSL_free(p);
674 }
675
676 /* set the private key */
677
678 /* do not include the parameters in the SEC1 private key
679 * see PKCS#11 12.11 */
680 old_flags = EC_KEY_get_enc_flags(pkey->pkey.ec);
681 tmp_flags = old_flags | EC_PKEY_NO_PARAMETERS;
682 EC_KEY_set_enc_flags(pkey->pkey.ec, tmp_flags);
683 i = i2d_ECPrivateKey(pkey->pkey.ec, NULL);
684 if (!i)
685 {
686 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
687 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
688 return 0;
689 }
690 p = (unsigned char *) OPENSSL_malloc(i);
691 if (!p)
692 {
693 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
694 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
695 return 0;
696 }
697 pp = p;
698 if (!i2d_ECPrivateKey(pkey->pkey.ec, &pp))
699 {
700 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
701 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_EC_LIB);
702 OPENSSL_free(p);
703 return 0;
704 }
705 /* restore old encoding flags */
706 EC_KEY_set_enc_flags(pkey->pkey.ec, old_flags);
707
708 switch(p8->broken) {
709
710 case PKCS8_OK:
711 p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();
712 if (!p8->pkey->value.octet_string ||
713 !M_ASN1_OCTET_STRING_set(p8->pkey->value.octet_string,
714 (const void *)p, i))
715
716 {
717 EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
718 }
719 else
720 ret = 1;
721 break;
722 case PKCS8_NO_OCTET: /* RSA specific */
723 case PKCS8_NS_DB: /* DSA specific */
724 case PKCS8_EMBEDDED_PARAM: /* DSA specific */
725 default:
726 EVPerr(EVP_F_ECKEY_PKEY2PKCS8,EVP_R_ENCODE_ERROR);
727 }
728 OPENSSL_cleanse(p, (size_t)i);
729 OPENSSL_free(p);
730 return ret;
731}
732#endif
733
734/* EVP_PKEY attribute functions */
735
736int EVP_PKEY_get_attr_count(const EVP_PKEY *key)
737{
738 return X509at_get_attr_count(key->attributes);
739}
740
741int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
742 int lastpos)
743{
744 return X509at_get_attr_by_NID(key->attributes, nid, lastpos);
745}
746
747int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
748 int lastpos)
749{
750 return X509at_get_attr_by_OBJ(key->attributes, obj, lastpos);
751}
752
753X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc)
754{
755 return X509at_get_attr(key->attributes, loc);
756}
757
758X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc)
759{
760 return X509at_delete_attr(key->attributes, loc);
761}
762
763int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr)
764{
765 if(X509at_add1_attr(&key->attributes, attr)) return 1;
766 return 0;
767}
768
769int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
770 const ASN1_OBJECT *obj, int type,
771 const unsigned char *bytes, int len)
772{
773 if(X509at_add1_attr_by_OBJ(&key->attributes, obj,
774 type, bytes, len)) return 1;
775 return 0;
776}
777
778int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
779 int nid, int type,
780 const unsigned char *bytes, int len)
781{
782 if(X509at_add1_attr_by_NID(&key->attributes, nid,
783 type, bytes, len)) return 1;
784 return 0;
785}
786
787int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
788 const char *attrname, int type,
789 const unsigned char *bytes, int len)
790{
791 if(X509at_add1_attr_by_txt(&key->attributes, attrname,
792 type, bytes, len)) return 1;
793 return 0;
794}
diff --git a/src/lib/libcrypto/evp/evp_test.c b/src/lib/libcrypto/evp/evp_test.c
new file mode 100644
index 0000000000..a624cfd248
--- /dev/null
+++ b/src/lib/libcrypto/evp/evp_test.c
@@ -0,0 +1,422 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <stdio.h>
51#include <string.h>
52
53#include "../e_os.h"
54
55#include <openssl/evp.h>
56#ifndef OPENSSL_NO_ENGINE
57#include <openssl/engine.h>
58#endif
59#include <openssl/err.h>
60#include <openssl/conf.h>
61
62static void hexdump(FILE *f,const char *title,const unsigned char *s,int l)
63 {
64 int n=0;
65
66 fprintf(f,"%s",title);
67 for( ; n < l ; ++n)
68 {
69 if((n%16) == 0)
70 fprintf(f,"\n%04x",n);
71 fprintf(f," %02x",s[n]);
72 }
73 fprintf(f,"\n");
74 }
75
76static int convert(unsigned char *s)
77 {
78 unsigned char *d;
79
80 for(d=s ; *s ; s+=2,++d)
81 {
82 unsigned int n;
83
84 if(!s[1])
85 {
86 fprintf(stderr,"Odd number of hex digits!");
87 EXIT(4);
88 }
89 sscanf((char *)s,"%2x",&n);
90 *d=(unsigned char)n;
91 }
92 return s-d;
93 }
94
95static char *sstrsep(char **string, const char *delim)
96 {
97 char isdelim[256];
98 char *token = *string;
99
100 if (**string == 0)
101 return NULL;
102
103 memset(isdelim, 0, 256);
104 isdelim[0] = 1;
105
106 while (*delim)
107 {
108 isdelim[(unsigned char)(*delim)] = 1;
109 delim++;
110 }
111
112 while (!isdelim[(unsigned char)(**string)])
113 {
114 (*string)++;
115 }
116
117 if (**string)
118 {
119 **string = 0;
120 (*string)++;
121 }
122
123 return token;
124 }
125
126static unsigned char *ustrsep(char **p,const char *sep)
127 { return (unsigned char *)sstrsep(p,sep); }
128
129static int test1_exit(int ec)
130 {
131 EXIT(ec);
132 return(0); /* To keep some compilers quiet */
133 }
134
135static void test1(const EVP_CIPHER *c,const unsigned char *key,int kn,
136 const unsigned char *iv,int in,
137 const unsigned char *plaintext,int pn,
138 const unsigned char *ciphertext,int cn,
139 int encdec,int multiplier)
140 {
141 EVP_CIPHER_CTX ctx;
142 unsigned char out[4096];
143 int outl,outl2;
144
145 printf("Testing cipher %s%s\n",EVP_CIPHER_name(c),
146 (encdec == 1 ? "(encrypt)" : (encdec == 0 ? "(decrypt)" : "(encrypt/decrypt)")));
147 hexdump(stdout,"Key",key,kn);
148 if(in)
149 hexdump(stdout,"IV",iv,in);
150 hexdump(stdout,"Plaintext",plaintext,pn);
151 hexdump(stdout,"Ciphertext",ciphertext,cn);
152
153 if(kn != c->key_len)
154 {
155 fprintf(stderr,"Key length doesn't match, got %d expected %d\n",kn,
156 c->key_len);
157 test1_exit(5);
158 }
159 EVP_CIPHER_CTX_init(&ctx);
160 if (encdec != 0)
161 {
162 if(!EVP_EncryptInit_ex(&ctx,c,NULL,key,iv))
163 {
164 fprintf(stderr,"EncryptInit failed\n");
165 ERR_print_errors_fp(stderr);
166 test1_exit(10);
167 }
168 EVP_CIPHER_CTX_set_padding(&ctx,0);
169
170 if(!EVP_EncryptUpdate(&ctx,out,&outl,plaintext,pn*multiplier))
171 {
172 fprintf(stderr,"Encrypt failed\n");
173 ERR_print_errors_fp(stderr);
174 test1_exit(6);
175 }
176 if(!EVP_EncryptFinal_ex(&ctx,out+outl,&outl2))
177 {
178 fprintf(stderr,"EncryptFinal failed\n");
179 ERR_print_errors_fp(stderr);
180 test1_exit(7);
181 }
182
183 if(outl+outl2 != cn*multiplier)
184 {
185 fprintf(stderr,"Ciphertext length mismatch got %d expected %d\n",
186 outl+outl2,cn);
187 test1_exit(8);
188 }
189
190 if(memcmp(out,ciphertext,cn))
191 {
192 fprintf(stderr,"Ciphertext mismatch\n");
193 hexdump(stderr,"Got",out,cn);
194 hexdump(stderr,"Expected",ciphertext,cn);
195 test1_exit(9);
196 }
197 }
198
199 if (encdec <= 0)
200 {
201 if(!EVP_DecryptInit_ex(&ctx,c,NULL,key,iv))
202 {
203 fprintf(stderr,"DecryptInit failed\n");
204 ERR_print_errors_fp(stderr);
205 test1_exit(11);
206 }
207 EVP_CIPHER_CTX_set_padding(&ctx,0);
208
209 if(!EVP_DecryptUpdate(&ctx,out,&outl,ciphertext,cn*multiplier))
210 {
211 fprintf(stderr,"Decrypt failed\n");
212 ERR_print_errors_fp(stderr);
213 test1_exit(6);
214 }
215 if(!EVP_DecryptFinal_ex(&ctx,out+outl,&outl2))
216 {
217 fprintf(stderr,"DecryptFinal failed\n");
218 ERR_print_errors_fp(stderr);
219 test1_exit(7);
220 }
221
222 if(outl+outl2 != cn*multiplier)
223 {
224 fprintf(stderr,"Plaintext length mismatch got %d expected %d\n",
225 outl+outl2,cn);
226 test1_exit(8);
227 }
228
229 if(memcmp(out,plaintext,cn))
230 {
231 fprintf(stderr,"Plaintext mismatch\n");
232 hexdump(stderr,"Got",out,cn);
233 hexdump(stderr,"Expected",plaintext,cn);
234 test1_exit(9);
235 }
236 }
237
238 EVP_CIPHER_CTX_cleanup(&ctx);
239
240 printf("\n");
241 }
242
243static int test_cipher(const char *cipher,const unsigned char *key,int kn,
244 const unsigned char *iv,int in,
245 const unsigned char *plaintext,int pn,
246 const unsigned char *ciphertext,int cn,
247 int encdec,int multiplier)
248 {
249 const EVP_CIPHER *c;
250
251 c=EVP_get_cipherbyname(cipher);
252 if(!c)
253 return 0;
254
255 test1(c,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,multiplier);
256
257 return 1;
258 }
259
260static int test_digest(const char *digest,
261 const unsigned char *plaintext,int pn,
262 const unsigned char *ciphertext, unsigned int cn)
263 {
264 const EVP_MD *d;
265 EVP_MD_CTX ctx;
266 unsigned char md[EVP_MAX_MD_SIZE];
267 unsigned int mdn;
268
269 d=EVP_get_digestbyname(digest);
270 if(!d)
271 return 0;
272
273 printf("Testing digest %s\n",EVP_MD_name(d));
274 hexdump(stdout,"Plaintext",plaintext,pn);
275 hexdump(stdout,"Digest",ciphertext,cn);
276
277 EVP_MD_CTX_init(&ctx);
278 if(!EVP_DigestInit_ex(&ctx,d, NULL))
279 {
280 fprintf(stderr,"DigestInit failed\n");
281 ERR_print_errors_fp(stderr);
282 EXIT(100);
283 }
284 if(!EVP_DigestUpdate(&ctx,plaintext,pn))
285 {
286 fprintf(stderr,"DigestUpdate failed\n");
287 ERR_print_errors_fp(stderr);
288 EXIT(101);
289 }
290 if(!EVP_DigestFinal_ex(&ctx,md,&mdn))
291 {
292 fprintf(stderr,"DigestFinal failed\n");
293 ERR_print_errors_fp(stderr);
294 EXIT(101);
295 }
296 EVP_MD_CTX_cleanup(&ctx);
297
298 if(mdn != cn)
299 {
300 fprintf(stderr,"Digest length mismatch, got %d expected %d\n",mdn,cn);
301 EXIT(102);
302 }
303
304 if(memcmp(md,ciphertext,cn))
305 {
306 fprintf(stderr,"Digest mismatch\n");
307 hexdump(stderr,"Got",md,cn);
308 hexdump(stderr,"Expected",ciphertext,cn);
309 EXIT(103);
310 }
311
312 printf("\n");
313
314 EVP_MD_CTX_cleanup(&ctx);
315
316 return 1;
317 }
318
319int main(int argc,char **argv)
320 {
321 const char *szTestFile;
322 FILE *f;
323
324 if(argc != 2)
325 {
326 fprintf(stderr,"%s <test file>\n",argv[0]);
327 EXIT(1);
328 }
329 CRYPTO_malloc_debug_init();
330 CRYPTO_set_mem_debug_options(V_CRYPTO_MDEBUG_ALL);
331 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
332
333 szTestFile=argv[1];
334
335 f=fopen(szTestFile,"r");
336 if(!f)
337 {
338 perror(szTestFile);
339 EXIT(2);
340 }
341
342 /* Load up the software EVP_CIPHER and EVP_MD definitions */
343 OpenSSL_add_all_ciphers();
344 OpenSSL_add_all_digests();
345#ifndef OPENSSL_NO_ENGINE
346 /* Load all compiled-in ENGINEs */
347 ENGINE_load_builtin_engines();
348#endif
349#if 0
350 OPENSSL_config();
351#endif
352#ifndef OPENSSL_NO_ENGINE
353 /* Register all available ENGINE implementations of ciphers and digests.
354 * This could perhaps be changed to "ENGINE_register_all_complete()"? */
355 ENGINE_register_all_ciphers();
356 ENGINE_register_all_digests();
357 /* If we add command-line options, this statement should be switchable.
358 * It'll prevent ENGINEs being ENGINE_init()ialised for cipher/digest use if
359 * they weren't already initialised. */
360 /* ENGINE_set_cipher_flags(ENGINE_CIPHER_FLAG_NOINIT); */
361#endif
362
363 for( ; ; )
364 {
365 char line[4096];
366 char *p;
367 char *cipher;
368 unsigned char *iv,*key,*plaintext,*ciphertext;
369 int encdec;
370 int kn,in,pn,cn;
371 int multiplier=1;
372
373 if(!fgets((char *)line,sizeof line,f))
374 break;
375 if(line[0] == '#' || line[0] == '\n')
376 continue;
377 p=line;
378 cipher=sstrsep(&p,":");
379 key=ustrsep(&p,":");
380 iv=ustrsep(&p,":");
381 plaintext=ustrsep(&p,":");
382 ciphertext=ustrsep(&p,":");
383 if (p[-1] == '\n') {
384 p[-1] = '\0';
385 encdec = -1;
386 } else {
387 encdec = atoi(sstrsep(&p,"\n"));
388 }
389
390
391 kn=convert(key);
392 in=convert(iv);
393 pn=convert(plaintext);
394 cn=convert(ciphertext);
395
396 if(strchr(cipher,'*'))
397 {
398 p=cipher;
399 sstrsep(&p,"*");
400 multiplier=atoi(sstrsep(&p,"*"));
401 }
402
403 if(!test_cipher(cipher,key,kn,iv,in,plaintext,pn,ciphertext,cn,encdec,
404 multiplier)
405 && !test_digest(cipher,plaintext,pn,ciphertext,cn))
406 {
407 fprintf(stderr,"Can't find %s\n",cipher);
408 EXIT(3);
409 }
410 }
411
412#ifndef OPENSSL_NO_ENGINE
413 ENGINE_cleanup();
414#endif
415 EVP_cleanup();
416 CRYPTO_cleanup_all_ex_data();
417 ERR_remove_state(0);
418 ERR_free_strings();
419 CRYPTO_mem_leaks_fp(stderr);
420
421 return 0;
422 }
diff --git a/src/lib/libcrypto/evp/evptests.txt b/src/lib/libcrypto/evp/evptests.txt
new file mode 100644
index 0000000000..dfe91a5bc0
--- /dev/null
+++ b/src/lib/libcrypto/evp/evptests.txt
@@ -0,0 +1,288 @@
1#cipher:key:iv:plaintext:ciphertext:0/1(decrypt/encrypt)
2#digest:::input:output
3
4# SHA(1) tests (from shatest.c)
5SHA1:::616263:a9993e364706816aba3e25717850c26c9cd0d89d
6
7# MD5 tests (from md5test.c)
8MD5::::d41d8cd98f00b204e9800998ecf8427e
9MD5:::61:0cc175b9c0f1b6a831c399e269772661
10MD5:::616263:900150983cd24fb0d6963f7d28e17f72
11MD5:::6d65737361676520646967657374:f96b697d7cb7938d525a2f31aaf161d0
12MD5:::6162636465666768696a6b6c6d6e6f707172737475767778797a:c3fcd3d76192e4007dfb496cca67e13b
13MD5:::4142434445464748494a4b4c4d4e4f505152535455565758595a6162636465666768696a6b6c6d6e6f707172737475767778797a30313233343536373839:d174ab98d277d9f5a5611c2c9f419d9f
14MD5:::3132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930313233343536373839303132333435363738393031323334353637383930:57edf4a22be3c955ac49da2e2107b67a
15
16# AES 128 ECB tests (from FIPS-197 test vectors, encrypt)
17
18AES-128-ECB:000102030405060708090A0B0C0D0E0F::00112233445566778899AABBCCDDEEFF:69C4E0D86A7B0430D8CDB78070B4C55A:1
19
20# AES 192 ECB tests (from FIPS-197 test vectors, encrypt)
21
22AES-192-ECB:000102030405060708090A0B0C0D0E0F1011121314151617::00112233445566778899AABBCCDDEEFF:DDA97CA4864CDFE06EAF70A0EC0D7191:1
23
24# AES 256 ECB tests (from FIPS-197 test vectors, encrypt)
25
26AES-256-ECB:000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F::00112233445566778899AABBCCDDEEFF:8EA2B7CA516745BFEAFC49904B496089:1
27
28# AES 128 ECB tests (from NIST test vectors, encrypt)
29
30#AES-128-ECB:00000000000000000000000000000000::00000000000000000000000000000000:C34C052CC0DA8D73451AFE5F03BE297F:1
31
32# AES 128 ECB tests (from NIST test vectors, decrypt)
33
34#AES-128-ECB:00000000000000000000000000000000::44416AC2D1F53C583303917E6BE9EBE0:00000000000000000000000000000000:0
35
36# AES 192 ECB tests (from NIST test vectors, decrypt)
37
38#AES-192-ECB:000000000000000000000000000000000000000000000000::48E31E9E256718F29229319C19F15BA4:00000000000000000000000000000000:0
39
40# AES 256 ECB tests (from NIST test vectors, decrypt)
41
42#AES-256-ECB:0000000000000000000000000000000000000000000000000000000000000000::058CCFFDBBCB382D1F6F56585D8A4ADE:00000000000000000000000000000000:0
43
44# AES 128 CBC tests (from NIST test vectors, encrypt)
45
46#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:8A05FC5E095AF4848A08D328D3688E3D:1
47
48# AES 192 CBC tests (from NIST test vectors, encrypt)
49
50#AES-192-CBC:000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:7BD966D53AD8C1BB85D2ADFAE87BB104:1
51
52# AES 256 CBC tests (from NIST test vectors, encrypt)
53
54#AES-256-CBC:0000000000000000000000000000000000000000000000000000000000000000:00000000000000000000000000000000:00000000000000000000000000000000:FE3C53653E2F45B56FCD88B2CC898FF0:1
55
56# AES 128 CBC tests (from NIST test vectors, decrypt)
57
58#AES-128-CBC:00000000000000000000000000000000:00000000000000000000000000000000:FACA37E0B0C85373DF706E73F7C9AF86:00000000000000000000000000000000:0
59
60# AES tests from NIST document SP800-38A
61# For all ECB encrypts and decrypts, the transformed sequence is
62# AES-bits-ECB:key::plaintext:ciphertext:encdec
63# ECB-AES128.Encrypt and ECB-AES128.Decrypt
64AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::6BC1BEE22E409F96E93D7E117393172A:3AD77BB40D7A3660A89ECAF32466EF97
65AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::AE2D8A571E03AC9C9EB76FAC45AF8E51:F5D3D58503B9699DE785895A96FDBAAF
66AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::30C81C46A35CE411E5FBC1191A0A52EF:43B1CD7F598ECE23881B00E3ED030688
67AES-128-ECB:2B7E151628AED2A6ABF7158809CF4F3C::F69F2445DF4F9B17AD2B417BE66C3710:7B0C785E27E8AD3F8223207104725DD4
68# ECB-AES192.Encrypt and ECB-AES192.Decrypt
69AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::6BC1BEE22E409F96E93D7E117393172A:BD334F1D6E45F25FF712A214571FA5CC
70AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::AE2D8A571E03AC9C9EB76FAC45AF8E51:974104846D0AD3AD7734ECB3ECEE4EEF
71AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::30C81C46A35CE411E5FBC1191A0A52EF:EF7AFD2270E2E60ADCE0BA2FACE6444E
72AES-192-ECB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B::F69F2445DF4F9B17AD2B417BE66C3710:9A4B41BA738D6C72FB16691603C18E0E
73# ECB-AES256.Encrypt and ECB-AES256.Decrypt
74AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::6BC1BEE22E409F96E93D7E117393172A:F3EED1BDB5D2A03C064B5A7E3DB181F8
75AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::AE2D8A571E03AC9C9EB76FAC45AF8E51:591CCB10D410ED26DC5BA74A31362870
76AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::30C81C46A35CE411E5FBC1191A0A52EF:B6ED21B99CA6F4F9F153E7B1BEAFED1D
77AES-256-ECB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4::F69F2445DF4F9B17AD2B417BE66C3710:23304B7A39F9F3FF067D8D8F9E24ECC7
78# For all CBC encrypts and decrypts, the transformed sequence is
79# AES-bits-CBC:key:IV/ciphertext':plaintext:ciphertext:encdec
80# CBC-AES128.Encrypt and CBC-AES128.Decrypt
81AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:7649ABAC8119B246CEE98E9B12E9197D
82AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:7649ABAC8119B246CEE98E9B12E9197D:AE2D8A571E03AC9C9EB76FAC45AF8E51:5086CB9B507219EE95DB113A917678B2
83AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:5086CB9B507219EE95DB113A917678B2:30C81C46A35CE411E5FBC1191A0A52EF:73BED6B8E3C1743B7116E69E22229516
84AES-128-CBC:2B7E151628AED2A6ABF7158809CF4F3C:73BED6B8E3C1743B7116E69E22229516:F69F2445DF4F9B17AD2B417BE66C3710:3FF1CAA1681FAC09120ECA307586E1A7
85# CBC-AES192.Encrypt and CBC-AES192.Decrypt
86AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:4F021DB243BC633D7178183A9FA071E8
87AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:4F021DB243BC633D7178183A9FA071E8:AE2D8A571E03AC9C9EB76FAC45AF8E51:B4D9ADA9AD7DEDF4E5E738763F69145A
88AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:B4D9ADA9AD7DEDF4E5E738763F69145A:30C81C46A35CE411E5FBC1191A0A52EF:571B242012FB7AE07FA9BAAC3DF102E0
89AES-192-CBC:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:571B242012FB7AE07FA9BAAC3DF102E0:F69F2445DF4F9B17AD2B417BE66C3710:08B0E27988598881D920A9E64F5615CD
90# CBC-AES256.Encrypt and CBC-AES256.Decrypt
91AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:F58C4C04D6E5F1BA779EABFB5F7BFBD6
92AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:F58C4C04D6E5F1BA779EABFB5F7BFBD6:AE2D8A571E03AC9C9EB76FAC45AF8E51:9CFC4E967EDB808D679F777BC6702C7D
93AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:9CFC4E967EDB808D679F777BC6702C7D:30C81C46A35CE411E5FBC1191A0A52EF:39F23369A9D9BACFA530E26304231461
94AES-256-CBC:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39F23369A9D9BACFA530E26304231461:F69F2445DF4F9B17AD2B417BE66C3710:B2EB05E2C39BE9FCDA6C19078C6A9D1B
95
96# CFB1-AES128.Encrypt
97
98AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:00:00:1
99AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:00020406080a0c0e10121416181a1c1e:80:80:1
100AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0004080c1014181c2024282c3034383d:80:80:1
101AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0008101820283038404850586068707b:00:00:1
102AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:00102030405060708090a0b0c0d0e0f6:80:80:1
103AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0020406080a0c0e10121416181a1c1ed:00:00:1
104AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:004080c1014181c2024282c3034383da:80:00:1
105AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:008101820283038404850586068707b4:80:00:1
106AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0102030405060708090a0b0c0d0e0f68:80:80:1
107AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:020406080a0c0e10121416181a1c1ed1:80:00:1
108AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:04080c1014181c2024282c3034383da2:00:80:1
109AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:08101820283038404850586068707b45:00:80:1
110AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:102030405060708090a0b0c0d0e0f68b:00:00:1
111AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:20406080a0c0e10121416181a1c1ed16:00:00:1
112AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:4080c1014181c2024282c3034383da2c:00:80:1
113AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:8101820283038404850586068707b459:80:80:1
114# all of the above packed into one...
115# in: 0110 1011 1100 0001 = 6bc1
116# out: 0110 1000 1011 0011 = 68b3
117AES-128-CFB1*8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6bc1:68b3:1
118
119# CFB1-AES128.Decrypt
120AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:00:00:0
121AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:00020406080a0c0e10121416181a1c1e:80:80:0
122AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0004080c1014181c2024282c3034383d:80:80:0
123AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0008101820283038404850586068707b:00:00:0
124AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:00102030405060708090a0b0c0d0e0f6:80:80:0
125AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0020406080a0c0e10121416181a1c1ed:00:00:0
126AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:004080c1014181c2024282c3034383da:80:00:0
127AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:008101820283038404850586068707b4:80:00:0
128AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:0102030405060708090a0b0c0d0e0f68:80:80:0
129AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:020406080a0c0e10121416181a1c1ed1:80:00:0
130AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:04080c1014181c2024282c3034383da2:00:80:0
131AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:08101820283038404850586068707b45:00:80:0
132AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:102030405060708090a0b0c0d0e0f68b:00:00:0
133AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:20406080a0c0e10121416181a1c1ed16:00:00:0
134AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:4080c1014181c2024282c3034383da2c:00:80:0
135AES-128-CFB1:2b7e151628aed2a6abf7158809cf4f3c:8101820283038404850586068707b459:80:80:0
136# all of the above packed into one...
137# in: 0110 1000 1011 0011 = 68b3
138# out: 0110 1011 1100 0001 = 6bc1
139AES-128-CFB1*8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6bc1:68b3:0
140
141# TODO: CFB1-AES192 and 256
142
143# CFB8-AES128.Encrypt
144
145AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6b:3b:1
146AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0102030405060708090a0b0c0d0e0f3b:c1:79:1
147AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:02030405060708090a0b0c0d0e0f3b79:be:42:1
148AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:030405060708090a0b0c0d0e0f3b7942:e2:4c:1
149AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0405060708090a0b0c0d0e0f3b79424c:2e:9c:1
150AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:05060708090a0b0c0d0e0f3b79424c9c:40:0d:1
151AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:060708090a0b0c0d0e0f3b79424c9c0d:9f:d4:1
152AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0708090a0b0c0d0e0f3b79424c9c0dd4:96:36:1
153AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:08090a0b0c0d0e0f3b79424c9c0dd436:e9:ba:1
154AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:090a0b0c0d0e0f3b79424c9c0dd436ba:3d:ce:1
155AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0a0b0c0d0e0f3b79424c9c0dd436bace:7e:9e:1
156AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0b0c0d0e0f3b79424c9c0dd436bace9e:11:0e:1
157AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0c0d0e0f3b79424c9c0dd436bace9e0e:73:d4:1
158AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0d0e0f3b79424c9c0dd436bace9e0ed4:93:58:1
159AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0e0f3b79424c9c0dd436bace9e0ed458:17:6a:1
160AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0f3b79424c9c0dd436bace9e0ed4586a:2a:4f:1
161AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:3b79424c9c0dd436bace9e0ed4586a4f:ae:32:1
162AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:79424c9c0dd436bace9e0ed4586a4f32:2d:b9:1
163# all of the above packed into one
164AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6bc1bee22e409f96e93d7e117393172aae2d:3b79424c9c0dd436bace9e0ed4586a4f32b9:1
165
166# CFB8-AES128.Decrypt
167
168AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6b:3b:0
169AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0102030405060708090a0b0c0d0e0f3b:c1:79:0
170AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:02030405060708090a0b0c0d0e0f3b79:be:42:0
171AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:030405060708090a0b0c0d0e0f3b7942:e2:4c:0
172AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0405060708090a0b0c0d0e0f3b79424c:2e:9c:0
173AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:05060708090a0b0c0d0e0f3b79424c9c:40:0d:0
174AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:060708090a0b0c0d0e0f3b79424c9c0d:9f:d4:0
175AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0708090a0b0c0d0e0f3b79424c9c0dd4:96:36:0
176AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:08090a0b0c0d0e0f3b79424c9c0dd436:e9:ba:0
177AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:090a0b0c0d0e0f3b79424c9c0dd436ba:3d:ce:0
178AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0a0b0c0d0e0f3b79424c9c0dd436bace:7e:9e:0
179AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0b0c0d0e0f3b79424c9c0dd436bace9e:11:0e:0
180AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0c0d0e0f3b79424c9c0dd436bace9e0e:73:d4:0
181AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0d0e0f3b79424c9c0dd436bace9e0ed4:93:58:0
182AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0e0f3b79424c9c0dd436bace9e0ed458:17:6a:0
183AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:0f3b79424c9c0dd436bace9e0ed4586a:2a:4f:0
184AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:3b79424c9c0dd436bace9e0ed4586a4f:ae:32:0
185AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:79424c9c0dd436bace9e0ed4586a4f32:2d:b9:0
186# all of the above packed into one
187AES-128-CFB8:2b7e151628aed2a6abf7158809cf4f3c:000102030405060708090a0b0c0d0e0f:6bc1bee22e409f96e93d7e117393172aae2d:3b79424c9c0dd436bace9e0ed4586a4f32b9:0
188
189# TODO: 192 and 256 bit keys
190
191# For all CFB128 encrypts and decrypts, the transformed sequence is
192# AES-bits-CFB:key:IV/ciphertext':plaintext:ciphertext:encdec
193# CFB128-AES128.Encrypt
194AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1
195AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:1
196AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:1
197AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:1
198# CFB128-AES128.Decrypt
199AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
200AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:3B3FD92EB72DAD20333449F8E83CFB4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:C8A64537A0B3A93FCDE3CDAD9F1CE58B:0
201AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:C8A64537A0B3A93FCDE3CDAD9F1CE58B:30C81C46A35CE411E5FBC1191A0A52EF:26751F67A3CBB140B1808CF187A4F4DF:0
202AES-128-CFB:2B7E151628AED2A6ABF7158809CF4F3C:26751F67A3CBB140B1808CF187A4F4DF:F69F2445DF4F9B17AD2B417BE66C3710:C04B05357C5D1C0EEAC4C66F9FF7F2E6:0
203# CFB128-AES192.Encrypt
204AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1
205AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:1
206AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:1
207AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:1
208# CFB128-AES192.Decrypt
209AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0
210AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:CDC80D6FDDF18CAB34C25909C99A4174:AE2D8A571E03AC9C9EB76FAC45AF8E51:67CE7F7F81173621961A2B70171D3D7A:0
211AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:67CE7F7F81173621961A2B70171D3D7A:30C81C46A35CE411E5FBC1191A0A52EF:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:0
212AES-192-CFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:2E1E8A1DD59B88B1C8E60FED1EFAC4C9:F69F2445DF4F9B17AD2B417BE66C3710:C05F9F9CA9834FA042AE8FBA584B09FF:0
213# CFB128-AES256.Encrypt
214AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
215AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:1
216AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:1
217AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:1
218# CFB128-AES256.Decrypt
219AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
220AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DC7E84BFDA79164B7ECD8486985D3860:AE2D8A571E03AC9C9EB76FAC45AF8E51:39FFED143B28B1C832113C6331E5407B:0
221AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:39FFED143B28B1C832113C6331E5407B:30C81C46A35CE411E5FBC1191A0A52EF:DF10132415E54B92A13ED0A8267AE2F9:0
222AES-256-CFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:DF10132415E54B92A13ED0A8267AE2F9:F69F2445DF4F9B17AD2B417BE66C3710:75A385741AB9CEF82031623D55B1E471:0
223# For all OFB encrypts and decrypts, the transformed sequence is
224# AES-bits-CFB:key:IV/output':plaintext:ciphertext:encdec
225# OFB-AES128.Encrypt
226AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:1
227AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:1
228AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:1
229AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:1
230# OFB-AES128.Decrypt
231AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:3B3FD92EB72DAD20333449F8E83CFB4A:0
232AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:50FE67CC996D32B6DA0937E99BAFEC60:AE2D8A571E03AC9C9EB76FAC45AF8E51:7789508D16918F03F53C52DAC54ED825:0
233AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:D9A4DADA0892239F6B8B3D7680E15674:30C81C46A35CE411E5FBC1191A0A52EF:9740051E9C5FECF64344F7A82260EDCC:0
234AES-128-OFB:2B7E151628AED2A6ABF7158809CF4F3C:A78819583F0308E7A6BF36B1386ABF23:F69F2445DF4F9B17AD2B417BE66C3710:304C6528F659C77866A510D9C1D6AE5E:0
235# OFB-AES192.Encrypt
236AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:1
237AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:1
238AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:1
239AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:1
240# OFB-AES192.Decrypt
241AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:CDC80D6FDDF18CAB34C25909C99A4174:0
242AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:A609B38DF3B1133DDDFF2718BA09565E:AE2D8A571E03AC9C9EB76FAC45AF8E51:FCC28B8D4C63837C09E81700C1100401:0
243AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:52EF01DA52602FE0975F78AC84BF8A50:30C81C46A35CE411E5FBC1191A0A52EF:8D9A9AEAC0F6596F559C6D4DAF59A5F2:0
244AES-192-OFB:8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B:BD5286AC63AABD7EB067AC54B553F71D:F69F2445DF4F9B17AD2B417BE66C3710:6D9F200857CA6C3E9CAC524BD9ACC92A:0
245# OFB-AES256.Encrypt
246AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:1
247AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:1
248AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:1
249AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:1
250# OFB-AES256.Decrypt
251AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:000102030405060708090A0B0C0D0E0F:6BC1BEE22E409F96E93D7E117393172A:DC7E84BFDA79164B7ECD8486985D3860:0
252AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:B7BF3A5DF43989DD97F0FA97EBCE2F4A:AE2D8A571E03AC9C9EB76FAC45AF8E51:4FEBDC6740D20B3AC88F6AD82A4FB08D:0
253AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:E1C656305ED1A7A6563805746FE03EDC:30C81C46A35CE411E5FBC1191A0A52EF:71AB47A086E86EEDF39D1C5BBA97C408:0
254AES-256-OFB:603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4:41635BE625B48AFC1666DD42A09D96E7:F69F2445DF4F9B17AD2B417BE66C3710:0126141D67F37BE8538F5A8BE740E484:0
255
256# DES ECB tests (from destest)
257
258DES-ECB:0000000000000000::0000000000000000:8CA64DE9C1B123A7
259DES-ECB:FFFFFFFFFFFFFFFF::FFFFFFFFFFFFFFFF:7359B2163E4EDC58
260DES-ECB:3000000000000000::1000000000000001:958E6E627A05557B
261DES-ECB:1111111111111111::1111111111111111:F40379AB9E0EC533
262DES-ECB:0123456789ABCDEF::1111111111111111:17668DFC7292532D
263DES-ECB:1111111111111111::0123456789ABCDEF:8A5AE1F81AB8F2DD
264DES-ECB:FEDCBA9876543210::0123456789ABCDEF:ED39D950FA74BCC4
265
266# DESX-CBC tests (from destest)
267DESX-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:846B2914851E9A2954732F8AA0A611C115CDC2D7951B1053A63C5E03B21AA3C4
268
269# DES EDE3 CBC tests (from destest)
270DES-EDE3-CBC:0123456789abcdeff1e0d3c2b5a49786fedcba9876543210:fedcba9876543210:37363534333231204E6F77206973207468652074696D6520666F722000000000:3FE301C962AC01D02213763C1CBD4CDC799657C064ECF5D41C673812CFDE9675
271
272# DES CFB1 from FIPS 81
273# plaintext: 0100 1110 0110 1111 0111 0111 = 4e6f77
274# ciphertext: 1100 1101 0001 1110 1100 1001 = cd1ec9
275
276DES-CFB1*8:0123456789abcdef:1234567890abcdef:4e6f77:cd1ec9
277
278# DES CFB8 from FIPS 81
279
280DES-CFB8:0123456789abcdef:1234567890abcdef:4e6f7720697320746865:f31fda07011462ee187f
281
282# RC4 tests (from rc4test)
283RC4:0123456789abcdef0123456789abcdef::0123456789abcdef:75b7878099e0c596
284RC4:0123456789abcdef0123456789abcdef::0000000000000000:7494c2e7104b0879
285RC4:00000000000000000000000000000000::0000000000000000:de188941a3375d3a
286RC4:ef012345ef012345ef012345ef012345::0000000000000000000000000000000000000000:d6a141a7ec3c38dfbd615a1162e1c7ba36b67858
287RC4:0123456789abcdef0123456789abcdef::123456789ABCDEF0123456789ABCDEF0123456789ABCDEF012345678:66a0949f8af7d6891f7f832ba833c00c892ebe30143ce28740011ecf
288RC4:ef012345ef012345ef012345ef012345::00000000000000000000:d6a141a7ec3c38dfbd61
diff --git a/src/lib/libcrypto/evp/m_dss.c b/src/lib/libcrypto/evp/m_dss.c
index a948c77fa4..d393eb3400 100644
--- a/src/lib/libcrypto/evp/m_dss.c
+++ b/src/lib/libcrypto/evp/m_dss.c
@@ -61,16 +61,12 @@
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64#ifndef OPENSSL_NO_DSA
65#include <openssl/dsa.h>
66#endif
67 64
68#ifndef OPENSSL_NO_SHA 65#ifndef OPENSSL_NO_SHA
69
70static int init(EVP_MD_CTX *ctx) 66static int init(EVP_MD_CTX *ctx)
71 { return SHA1_Init(ctx->md_data); } 67 { return SHA1_Init(ctx->md_data); }
72 68
73static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
74 { return SHA1_Update(ctx->md_data,data,count); } 70 { return SHA1_Update(ctx->md_data,data,count); }
75 71
76static int final(EVP_MD_CTX *ctx,unsigned char *md) 72static int final(EVP_MD_CTX *ctx,unsigned char *md)
@@ -81,7 +77,7 @@ static const EVP_MD dsa_md=
81 NID_dsaWithSHA, 77 NID_dsaWithSHA,
82 NID_dsaWithSHA, 78 NID_dsaWithSHA,
83 SHA_DIGEST_LENGTH, 79 SHA_DIGEST_LENGTH,
84 0, 80 EVP_MD_FLAG_FIPS,
85 init, 81 init,
86 update, 82 update,
87 final, 83 final,
diff --git a/src/lib/libcrypto/evp/m_dss1.c b/src/lib/libcrypto/evp/m_dss1.c
index c12e13972b..23b90d0538 100644
--- a/src/lib/libcrypto/evp/m_dss1.c
+++ b/src/lib/libcrypto/evp/m_dss1.c
@@ -56,23 +56,25 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_SHA
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
65#include <openssl/objects.h> 63#include <openssl/objects.h>
66#include <openssl/x509.h> 64#include <openssl/x509.h>
67#ifndef OPENSSL_NO_DSA
68#include <openssl/dsa.h>
69#endif
70 65
71static int init(EVP_MD_CTX *ctx) 66static int init(EVP_MD_CTX *ctx)
72 { return SHA1_Init(ctx->md_data); } 67 { return SHA1_Init(ctx->md_data); }
73 68
74static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70#ifndef OPENSSL_FIPS
75 { return SHA1_Update(ctx->md_data,data,count); } 71 { return SHA1_Update(ctx->md_data,data,count); }
72#else
73 {
74 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
75 return SHA1_Update(ctx->md_data,data,count);
76 }
77#endif
76 78
77static int final(EVP_MD_CTX *ctx,unsigned char *md) 79static int final(EVP_MD_CTX *ctx,unsigned char *md)
78 { return SHA1_Final(md,ctx->md_data); } 80 { return SHA1_Final(md,ctx->md_data); }
@@ -82,7 +84,7 @@ static const EVP_MD dss1_md=
82 NID_dsa, 84 NID_dsa,
83 NID_dsaWithSHA1, 85 NID_dsaWithSHA1,
84 SHA_DIGEST_LENGTH, 86 SHA_DIGEST_LENGTH,
85 0, 87 EVP_MD_FLAG_FIPS,
86 init, 88 init,
87 update, 89 update,
88 final, 90 final,
diff --git a/src/lib/libcrypto/evp/m_md2.c b/src/lib/libcrypto/evp/m_md2.c
new file mode 100644
index 0000000000..0df48e5199
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_md2.c
@@ -0,0 +1,97 @@
1/* crypto/evp/m_md2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_MD2
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/md2.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MD2_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MD2_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MD2_Final(md,ctx->md_data); }
76
77static const EVP_MD md2_md=
78 {
79 NID_md2,
80 NID_md2WithRSAEncryption,
81 MD2_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_method,
89 MD2_BLOCK,
90 sizeof(EVP_MD *)+sizeof(MD2_CTX),
91 };
92
93const EVP_MD *EVP_md2(void)
94 {
95 return(&md2_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_md4.c b/src/lib/libcrypto/evp/m_md4.c
index 1e0b7c5b42..0605e4b707 100644
--- a/src/lib/libcrypto/evp/m_md4.c
+++ b/src/lib/libcrypto/evp/m_md4.c
@@ -56,23 +56,19 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_MD4
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_MD4
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include "evp_locl.h"
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67#include <openssl/md4.h> 66#include <openssl/md4.h>
68#ifndef OPENSSL_NO_RSA
69#include <openssl/rsa.h>
70#endif
71 67
72static int init(EVP_MD_CTX *ctx) 68static int init(EVP_MD_CTX *ctx)
73 { return MD4_Init(ctx->md_data); } 69 { return MD4_Init(ctx->md_data); }
74 70
75static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
76 { return MD4_Update(ctx->md_data,data,count); } 72 { return MD4_Update(ctx->md_data,data,count); }
77 73
78static int final(EVP_MD_CTX *ctx,unsigned char *md) 74static int final(EVP_MD_CTX *ctx,unsigned char *md)
diff --git a/src/lib/libcrypto/evp/m_md5.c b/src/lib/libcrypto/evp/m_md5.c
index 63c142119e..752615d473 100644
--- a/src/lib/libcrypto/evp/m_md5.c
+++ b/src/lib/libcrypto/evp/m_md5.c
@@ -56,23 +56,19 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_MD5
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_MD5
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
63#include "evp_locl.h"
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67#include <openssl/md5.h> 66#include <openssl/md5.h>
68#ifndef OPENSSL_NO_RSA
69#include <openssl/rsa.h>
70#endif
71 67
72static int init(EVP_MD_CTX *ctx) 68static int init(EVP_MD_CTX *ctx)
73 { return MD5_Init(ctx->md_data); } 69 { return MD5_Init(ctx->md_data); }
74 70
75static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
76 { return MD5_Update(ctx->md_data,data,count); } 72 { return MD5_Update(ctx->md_data,data,count); }
77 73
78static int final(EVP_MD_CTX *ctx,unsigned char *md) 74static int final(EVP_MD_CTX *ctx,unsigned char *md)
diff --git a/src/lib/libcrypto/evp/m_mdc2.c b/src/lib/libcrypto/evp/m_mdc2.c
new file mode 100644
index 0000000000..62de1336b8
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_mdc2.c
@@ -0,0 +1,97 @@
1/* crypto/evp/m_mdc2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef OPENSSL_NO_MDC2
60#include <stdio.h>
61#include "cryptlib.h"
62#include <openssl/evp.h>
63#include "evp_locl.h"
64#include <openssl/objects.h>
65#include <openssl/x509.h>
66#include <openssl/mdc2.h>
67
68static int init(EVP_MD_CTX *ctx)
69 { return MDC2_Init(ctx->md_data); }
70
71static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
72 { return MDC2_Update(ctx->md_data,data,count); }
73
74static int final(EVP_MD_CTX *ctx,unsigned char *md)
75 { return MDC2_Final(md,ctx->md_data); }
76
77static const EVP_MD mdc2_md=
78 {
79 NID_mdc2,
80 NID_mdc2WithRSA,
81 MDC2_DIGEST_LENGTH,
82 0,
83 init,
84 update,
85 final,
86 NULL,
87 NULL,
88 EVP_PKEY_RSA_ASN1_OCTET_STRING_method,
89 MDC2_BLOCK,
90 sizeof(EVP_MD *)+sizeof(MDC2_CTX),
91 };
92
93const EVP_MD *EVP_mdc2(void)
94 {
95 return(&mdc2_md);
96 }
97#endif
diff --git a/src/lib/libcrypto/evp/m_null.c b/src/lib/libcrypto/evp/m_null.c
index cb0721699d..f6f0a1d2c0 100644
--- a/src/lib/libcrypto/evp/m_null.c
+++ b/src/lib/libcrypto/evp/m_null.c
@@ -65,7 +65,7 @@
65static int init(EVP_MD_CTX *ctx) 65static int init(EVP_MD_CTX *ctx)
66 { return 1; } 66 { return 1; }
67 67
68static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 68static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
69 { return 1; } 69 { return 1; }
70 70
71static int final(EVP_MD_CTX *ctx,unsigned char *md) 71static int final(EVP_MD_CTX *ctx,unsigned char *md)
diff --git a/src/lib/libcrypto/evp/m_ripemd.c b/src/lib/libcrypto/evp/m_ripemd.c
index a1d60ee78d..64725528dc 100644
--- a/src/lib/libcrypto/evp/m_ripemd.c
+++ b/src/lib/libcrypto/evp/m_ripemd.c
@@ -56,23 +56,18 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_RIPEMD
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RIPEMD
63
64#include <openssl/ripemd.h> 62#include <openssl/ripemd.h>
65#include <openssl/evp.h> 63#include <openssl/evp.h>
66#include <openssl/objects.h> 64#include <openssl/objects.h>
67#include <openssl/x509.h> 65#include <openssl/x509.h>
68#ifndef OPENSSL_NO_RSA
69#include <openssl/rsa.h>
70#endif
71 66
72static int init(EVP_MD_CTX *ctx) 67static int init(EVP_MD_CTX *ctx)
73 { return RIPEMD160_Init(ctx->md_data); } 68 { return RIPEMD160_Init(ctx->md_data); }
74 69
75static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 70static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
76 { return RIPEMD160_Update(ctx->md_data,data,count); } 71 { return RIPEMD160_Update(ctx->md_data,data,count); }
77 72
78static int final(EVP_MD_CTX *ctx,unsigned char *md) 73static int final(EVP_MD_CTX *ctx,unsigned char *md)
diff --git a/src/lib/libcrypto/evp/m_sha.c b/src/lib/libcrypto/evp/m_sha.c
new file mode 100644
index 0000000000..ed54909b16
--- /dev/null
+++ b/src/lib/libcrypto/evp/m_sha.c
@@ -0,0 +1,99 @@
1/* crypto/evp/m_sha.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA0)
60#include <stdio.h>
61#include "cryptlib.h"
62/* Including sha.h prior evp.h masks FIPS SHA declarations, but that's
63 * exactly what we want to achieve here... */
64#include <openssl/sha.h>
65#include <openssl/evp.h>
66#include "evp_locl.h"
67#include <openssl/objects.h>
68#include <openssl/x509.h>
69
70static int init(EVP_MD_CTX *ctx)
71 { return SHA_Init(ctx->md_data); }
72
73static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
74 { return SHA_Update(ctx->md_data,data,count); }
75
76static int final(EVP_MD_CTX *ctx,unsigned char *md)
77 { return SHA_Final(md,ctx->md_data); }
78
79static const EVP_MD sha_md=
80 {
81 NID_sha,
82 NID_shaWithRSAEncryption,
83 SHA_DIGEST_LENGTH,
84 0,
85 init,
86 update,
87 final,
88 NULL,
89 NULL,
90 EVP_PKEY_RSA_method,
91 SHA_CBLOCK,
92 sizeof(EVP_MD *)+sizeof(SHA_CTX),
93 };
94
95const EVP_MD *EVP_sha(void)
96 {
97 return(&sha_md);
98 }
99#endif
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
index 4679b1c463..60da93873c 100644
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -56,23 +56,25 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#ifndef OPENSSL_NO_SHA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_SHA
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
65#include <openssl/objects.h> 63#include <openssl/objects.h>
66#include <openssl/x509.h> 64#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70 65
71static int init(EVP_MD_CTX *ctx) 66static int init(EVP_MD_CTX *ctx)
72 { return SHA1_Init(ctx->md_data); } 67 { return SHA1_Init(ctx->md_data); }
73 68
74static int update(EVP_MD_CTX *ctx,const void *data,size_t count) 69static int update(EVP_MD_CTX *ctx,const void *data,unsigned long count)
70#ifndef OPENSSL_FIPS
75 { return SHA1_Update(ctx->md_data,data,count); } 71 { return SHA1_Update(ctx->md_data,data,count); }
72#else
73 {
74 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
75 return SHA1_Update(ctx->md_data,data,count);
76 }
77#endif
76 78
77static int final(EVP_MD_CTX *ctx,unsigned char *md) 79static int final(EVP_MD_CTX *ctx,unsigned char *md)
78 { return SHA1_Final(md,ctx->md_data); } 80 { return SHA1_Final(md,ctx->md_data); }
@@ -82,7 +84,7 @@ static const EVP_MD sha1_md=
82 NID_sha1, 84 NID_sha1,
83 NID_sha1WithRSAEncryption, 85 NID_sha1WithRSAEncryption,
84 SHA_DIGEST_LENGTH, 86 SHA_DIGEST_LENGTH,
85 0, 87 EVP_MD_FLAG_FIPS,
86 init, 88 init,
87 update, 89 update,
88 final, 90 final,
@@ -99,6 +101,7 @@ const EVP_MD *EVP_sha1(void)
99 } 101 }
100#endif 102#endif
101 103
104#ifdef OPENSSL_FIPS
102#ifndef OPENSSL_NO_SHA256 105#ifndef OPENSSL_NO_SHA256
103static int init224(EVP_MD_CTX *ctx) 106static int init224(EVP_MD_CTX *ctx)
104 { return SHA224_Init(ctx->md_data); } 107 { return SHA224_Init(ctx->md_data); }
@@ -109,8 +112,11 @@ static int init256(EVP_MD_CTX *ctx)
109 * SHA256 functions even in SHA224 context. This is what happens 112 * SHA256 functions even in SHA224 context. This is what happens
110 * there anyway, so we can spare few CPU cycles:-) 113 * there anyway, so we can spare few CPU cycles:-)
111 */ 114 */
112static int update256(EVP_MD_CTX *ctx,const void *data,size_t count) 115static int update256(EVP_MD_CTX *ctx,const void *data,unsigned long count)
113 { return SHA256_Update(ctx->md_data,data,count); } 116 {
117 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
118 return SHA256_Update(ctx->md_data,data,count);
119 }
114static int final256(EVP_MD_CTX *ctx,unsigned char *md) 120static int final256(EVP_MD_CTX *ctx,unsigned char *md)
115 { return SHA256_Final(md,ctx->md_data); } 121 { return SHA256_Final(md,ctx->md_data); }
116 122
@@ -119,7 +125,7 @@ static const EVP_MD sha224_md=
119 NID_sha224, 125 NID_sha224,
120 NID_sha224WithRSAEncryption, 126 NID_sha224WithRSAEncryption,
121 SHA224_DIGEST_LENGTH, 127 SHA224_DIGEST_LENGTH,
122 0, 128 EVP_MD_FLAG_FIPS,
123 init224, 129 init224,
124 update256, 130 update256,
125 final256, 131 final256,
@@ -138,7 +144,7 @@ static const EVP_MD sha256_md=
138 NID_sha256, 144 NID_sha256,
139 NID_sha256WithRSAEncryption, 145 NID_sha256WithRSAEncryption,
140 SHA256_DIGEST_LENGTH, 146 SHA256_DIGEST_LENGTH,
141 0, 147 EVP_MD_FLAG_FIPS,
142 init256, 148 init256,
143 update256, 149 update256,
144 final256, 150 final256,
@@ -151,7 +157,7 @@ static const EVP_MD sha256_md=
151 157
152const EVP_MD *EVP_sha256(void) 158const EVP_MD *EVP_sha256(void)
153 { return(&sha256_md); } 159 { return(&sha256_md); }
154#endif /* ifndef OPENSSL_NO_SHA256 */ 160#endif /* ifndef OPENSSL_NO_SHA256 */
155 161
156#ifndef OPENSSL_NO_SHA512 162#ifndef OPENSSL_NO_SHA512
157static int init384(EVP_MD_CTX *ctx) 163static int init384(EVP_MD_CTX *ctx)
@@ -159,8 +165,11 @@ static int init384(EVP_MD_CTX *ctx)
159static int init512(EVP_MD_CTX *ctx) 165static int init512(EVP_MD_CTX *ctx)
160 { return SHA512_Init(ctx->md_data); } 166 { return SHA512_Init(ctx->md_data); }
161/* See comment in SHA224/256 section */ 167/* See comment in SHA224/256 section */
162static int update512(EVP_MD_CTX *ctx,const void *data,size_t count) 168static int update512(EVP_MD_CTX *ctx,const void *data,unsigned long count)
163 { return SHA512_Update(ctx->md_data,data,count); } 169 {
170 OPENSSL_assert(sizeof(count)<=sizeof(size_t));
171 return SHA512_Update(ctx->md_data,data,count);
172 }
164static int final512(EVP_MD_CTX *ctx,unsigned char *md) 173static int final512(EVP_MD_CTX *ctx,unsigned char *md)
165 { return SHA512_Final(md,ctx->md_data); } 174 { return SHA512_Final(md,ctx->md_data); }
166 175
@@ -169,7 +178,7 @@ static const EVP_MD sha384_md=
169 NID_sha384, 178 NID_sha384,
170 NID_sha384WithRSAEncryption, 179 NID_sha384WithRSAEncryption,
171 SHA384_DIGEST_LENGTH, 180 SHA384_DIGEST_LENGTH,
172 0, 181 EVP_MD_FLAG_FIPS,
173 init384, 182 init384,
174 update512, 183 update512,
175 final512, 184 final512,
@@ -188,7 +197,7 @@ static const EVP_MD sha512_md=
188 NID_sha512, 197 NID_sha512,
189 NID_sha512WithRSAEncryption, 198 NID_sha512WithRSAEncryption,
190 SHA512_DIGEST_LENGTH, 199 SHA512_DIGEST_LENGTH,
191 0, 200 EVP_MD_FLAG_FIPS,
192 init512, 201 init512,
193 update512, 202 update512,
194 final512, 203 final512,
@@ -201,4 +210,5 @@ static const EVP_MD sha512_md=
201 210
202const EVP_MD *EVP_sha512(void) 211const EVP_MD *EVP_sha512(void)
203 { return(&sha512_md); } 212 { return(&sha512_md); }
204#endif /* ifndef OPENSSL_NO_SHA512 */ 213#endif /* ifndef OPENSSL_NO_SHA512 */
214#endif /* ifdef OPENSSL_FIPS */
diff --git a/src/lib/libcrypto/evp/names.c b/src/lib/libcrypto/evp/names.c
index 88c1e780dd..7712453046 100644
--- a/src/lib/libcrypto/evp/names.c
+++ b/src/lib/libcrypto/evp/names.c
@@ -61,14 +61,17 @@
61#include <openssl/evp.h> 61#include <openssl/evp.h>
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64#ifdef OPENSSL_FIPS
65#include <openssl/fips.h>
66#endif
64 67
65int EVP_add_cipher(const EVP_CIPHER *c) 68int EVP_add_cipher(const EVP_CIPHER *c)
66 { 69 {
67 int r; 70 int r;
68 71
69 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c); 72 r=OBJ_NAME_add(OBJ_nid2sn(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
70 if (r == 0) return(0); 73 if (r == 0) return(0);
71 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(const char *)c); 74 r=OBJ_NAME_add(OBJ_nid2ln(c->nid),OBJ_NAME_TYPE_CIPHER_METH,(char *)c);
72 return(r); 75 return(r);
73 } 76 }
74 77
@@ -78,9 +81,9 @@ int EVP_add_digest(const EVP_MD *md)
78 const char *name; 81 const char *name;
79 82
80 name=OBJ_nid2sn(md->type); 83 name=OBJ_nid2sn(md->type);
81 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(const char *)md); 84 r=OBJ_NAME_add(name,OBJ_NAME_TYPE_MD_METH,(char *)md);
82 if (r == 0) return(0); 85 if (r == 0) return(0);
83 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(const char *)md); 86 r=OBJ_NAME_add(OBJ_nid2ln(md->type),OBJ_NAME_TYPE_MD_METH,(char *)md);
84 if (r == 0) return(0); 87 if (r == 0) return(0);
85 88
86 if (md->type != md->pkey_type) 89 if (md->type != md->pkey_type)
diff --git a/src/lib/libcrypto/evp/openbsd_hw.c b/src/lib/libcrypto/evp/openbsd_hw.c
new file mode 100644
index 0000000000..3831a5731e
--- /dev/null
+++ b/src/lib/libcrypto/evp/openbsd_hw.c
@@ -0,0 +1,446 @@
1/* Written by Ben Laurie, 2001 */
2/*
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 */
49
50#include <openssl/evp.h>
51#include <openssl/objects.h>
52#include <openssl/rsa.h>
53#include "evp_locl.h"
54
55/* This stuff should now all be supported through
56 * crypto/engine/hw_openbsd_dev_crypto.c unless I botched it up */
57static void *dummy=&dummy;
58
59#if 0
60
61/* check flag after OpenSSL headers to ensure make depend works */
62#ifdef OPENSSL_OPENBSD_DEV_CRYPTO
63
64#include <fcntl.h>
65#include <stdio.h>
66#include <errno.h>
67#include <sys/ioctl.h>
68#include <crypto/cryptodev.h>
69#include <unistd.h>
70#include <assert.h>
71
72/* longest key supported in hardware */
73#define MAX_HW_KEY 24
74#define MAX_HW_IV 8
75
76#define MD5_DIGEST_LENGTH 16
77#define MD5_CBLOCK 64
78
79static int fd;
80static int dev_failed;
81
82typedef struct session_op session_op;
83
84#define CDATA(ctx) EVP_C_DATA(session_op,ctx)
85
86static void err(const char *str)
87 {
88 fprintf(stderr,"%s: errno %d\n",str,errno);
89 }
90
91static int dev_crypto_init(session_op *ses)
92 {
93 if(dev_failed)
94 return 0;
95 if(!fd)
96 {
97 int cryptodev_fd;
98
99 if ((cryptodev_fd=open("/dev/crypto",O_RDWR,0)) < 0)
100 {
101 err("/dev/crypto");
102 dev_failed=1;
103 return 0;
104 }
105 if (ioctl(cryptodev_fd,CRIOGET,&fd) == -1)
106 {
107 err("CRIOGET failed");
108 close(cryptodev_fd);
109 dev_failed=1;
110 return 0;
111 }
112 close(cryptodev_fd);
113 }
114 assert(ses);
115 memset(ses,'\0',sizeof *ses);
116
117 return 1;
118 }
119
120static int dev_crypto_cleanup(EVP_CIPHER_CTX *ctx)
121 {
122 if(ioctl(fd,CIOCFSESSION,&CDATA(ctx)->ses) == -1)
123 err("CIOCFSESSION failed");
124
125 OPENSSL_free(CDATA(ctx)->key);
126
127 return 1;
128 }
129
130static int dev_crypto_init_key(EVP_CIPHER_CTX *ctx,int cipher,
131 const unsigned char *key,int klen)
132 {
133 if(!dev_crypto_init(CDATA(ctx)))
134 return 0;
135
136 CDATA(ctx)->key=OPENSSL_malloc(MAX_HW_KEY);
137
138 assert(ctx->cipher->iv_len <= MAX_HW_IV);
139
140 memcpy(CDATA(ctx)->key,key,klen);
141
142 CDATA(ctx)->cipher=cipher;
143 CDATA(ctx)->keylen=klen;
144
145 if (ioctl(fd,CIOCGSESSION,CDATA(ctx)) == -1)
146 {
147 err("CIOCGSESSION failed");
148 return 0;
149 }
150 return 1;
151 }
152
153static int dev_crypto_cipher(EVP_CIPHER_CTX *ctx,unsigned char *out,
154 const unsigned char *in,unsigned int inl)
155 {
156 struct crypt_op cryp;
157 unsigned char lb[MAX_HW_IV];
158
159 if(!inl)
160 return 1;
161
162 assert(CDATA(ctx));
163 assert(!dev_failed);
164
165 memset(&cryp,'\0',sizeof cryp);
166 cryp.ses=CDATA(ctx)->ses;
167 cryp.op=ctx->encrypt ? COP_ENCRYPT : COP_DECRYPT;
168 cryp.flags=0;
169 cryp.len=inl;
170 assert((inl&(ctx->cipher->block_size-1)) == 0);
171 cryp.src=(caddr_t)in;
172 cryp.dst=(caddr_t)out;
173 cryp.mac=0;
174 if(ctx->cipher->iv_len)
175 cryp.iv=(caddr_t)ctx->iv;
176
177 if(!ctx->encrypt)
178 memcpy(lb,&in[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
179
180 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
181 {
182 if(errno == EINVAL) /* buffers are misaligned */
183 {
184 unsigned int cinl=0;
185 char *cin=NULL;
186 char *cout=NULL;
187
188 /* NB: this can only make cinl != inl with stream ciphers */
189 cinl=(inl+3)/4*4;
190
191 if(((unsigned long)in&3) || cinl != inl)
192 {
193 cin=OPENSSL_malloc(cinl);
194 memcpy(cin,in,inl);
195 cryp.src=cin;
196 }
197
198 if(((unsigned long)out&3) || cinl != inl)
199 {
200 cout=OPENSSL_malloc(cinl);
201 cryp.dst=cout;
202 }
203
204 cryp.len=cinl;
205
206 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
207 {
208 err("CIOCCRYPT(2) failed");
209 printf("src=%p dst=%p\n",cryp.src,cryp.dst);
210 abort();
211 return 0;
212 }
213
214 if(cout)
215 {
216 memcpy(out,cout,inl);
217 OPENSSL_free(cout);
218 }
219 if(cin)
220 OPENSSL_free(cin);
221 }
222 else
223 {
224 err("CIOCCRYPT failed");
225 abort();
226 return 0;
227 }
228 }
229
230 if(ctx->encrypt)
231 memcpy(ctx->iv,&out[cryp.len-ctx->cipher->iv_len],ctx->cipher->iv_len);
232 else
233 memcpy(ctx->iv,lb,ctx->cipher->iv_len);
234
235 return 1;
236 }
237
238static int dev_crypto_des_ede3_init_key(EVP_CIPHER_CTX *ctx,
239 const unsigned char *key,
240 const unsigned char *iv, int enc)
241 { return dev_crypto_init_key(ctx,CRYPTO_3DES_CBC,key,24); }
242
243#define dev_crypto_des_ede3_cbc_cipher dev_crypto_cipher
244
245BLOCK_CIPHER_def_cbc(dev_crypto_des_ede3, session_op, NID_des_ede3, 8, 24, 8,
246 0, dev_crypto_des_ede3_init_key,
247 dev_crypto_cleanup,
248 EVP_CIPHER_set_asn1_iv,
249 EVP_CIPHER_get_asn1_iv,
250 NULL)
251
252static int dev_crypto_rc4_init_key(EVP_CIPHER_CTX *ctx,
253 const unsigned char *key,
254 const unsigned char *iv, int enc)
255 { return dev_crypto_init_key(ctx,CRYPTO_ARC4,key,16); }
256
257static const EVP_CIPHER r4_cipher=
258 {
259 NID_rc4,
260 1,16,0, /* FIXME: key should be up to 256 bytes */
261 EVP_CIPH_VARIABLE_LENGTH,
262 dev_crypto_rc4_init_key,
263 dev_crypto_cipher,
264 dev_crypto_cleanup,
265 sizeof(session_op),
266 NULL,
267 NULL,
268 NULL
269 };
270
271const EVP_CIPHER *EVP_dev_crypto_rc4(void)
272 { return &r4_cipher; }
273
274typedef struct
275 {
276 session_op sess;
277 char *data;
278 int len;
279 unsigned char md[EVP_MAX_MD_SIZE];
280 } MD_DATA;
281
282static int dev_crypto_init_digest(MD_DATA *md_data,int mac)
283 {
284 if(!dev_crypto_init(&md_data->sess))
285 return 0;
286
287 md_data->len=0;
288 md_data->data=NULL;
289
290 md_data->sess.mac=mac;
291
292 if (ioctl(fd,CIOCGSESSION,&md_data->sess) == -1)
293 {
294 err("CIOCGSESSION failed");
295 return 0;
296 }
297 return 1;
298 }
299
300static int dev_crypto_cleanup_digest(MD_DATA *md_data)
301 {
302 if (ioctl(fd,CIOCFSESSION,&md_data->sess.ses) == -1)
303 {
304 err("CIOCFSESSION failed");
305 return 0;
306 }
307
308 return 1;
309 }
310
311/* FIXME: if device can do chained MACs, then don't accumulate */
312/* FIXME: move accumulation to the framework */
313static int dev_crypto_md5_init(EVP_MD_CTX *ctx)
314 { return dev_crypto_init_digest(ctx->md_data,CRYPTO_MD5); }
315
316static int do_digest(int ses,unsigned char *md,const void *data,int len)
317 {
318 struct crypt_op cryp;
319 static unsigned char md5zero[16]=
320 {
321 0xd4,0x1d,0x8c,0xd9,0x8f,0x00,0xb2,0x04,
322 0xe9,0x80,0x09,0x98,0xec,0xf8,0x42,0x7e
323 };
324
325 /* some cards can't do zero length */
326 if(!len)
327 {
328 memcpy(md,md5zero,16);
329 return 1;
330 }
331
332 memset(&cryp,'\0',sizeof cryp);
333 cryp.ses=ses;
334 cryp.op=COP_ENCRYPT;/* required to do the MAC rather than check it */
335 cryp.len=len;
336 cryp.src=(caddr_t)data;
337 cryp.dst=(caddr_t)data; // FIXME!!!
338 cryp.mac=(caddr_t)md;
339
340 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
341 {
342 if(errno == EINVAL) /* buffer is misaligned */
343 {
344 char *dcopy;
345
346 dcopy=OPENSSL_malloc(len);
347 memcpy(dcopy,data,len);
348 cryp.src=dcopy;
349 cryp.dst=cryp.src; // FIXME!!!
350
351 if(ioctl(fd, CIOCCRYPT, &cryp) == -1)
352 {
353 err("CIOCCRYPT(MAC2) failed");
354 abort();
355 return 0;
356 }
357 OPENSSL_free(dcopy);
358 }
359 else
360 {
361 err("CIOCCRYPT(MAC) failed");
362 abort();
363 return 0;
364 }
365 }
366 // printf("done\n");
367
368 return 1;
369 }
370
371static int dev_crypto_md5_update(EVP_MD_CTX *ctx,const void *data,
372 unsigned long len)
373 {
374 MD_DATA *md_data=ctx->md_data;
375
376 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
377 return do_digest(md_data->sess.ses,md_data->md,data,len);
378
379 md_data->data=OPENSSL_realloc(md_data->data,md_data->len+len);
380 memcpy(md_data->data+md_data->len,data,len);
381 md_data->len+=len;
382
383 return 1;
384 }
385
386static int dev_crypto_md5_final(EVP_MD_CTX *ctx,unsigned char *md)
387 {
388 int ret;
389 MD_DATA *md_data=ctx->md_data;
390
391 if(ctx->flags&EVP_MD_CTX_FLAG_ONESHOT)
392 {
393 memcpy(md,md_data->md,MD5_DIGEST_LENGTH);
394 ret=1;
395 }
396 else
397 {
398 ret=do_digest(md_data->sess.ses,md,md_data->data,md_data->len);
399 OPENSSL_free(md_data->data);
400 md_data->data=NULL;
401 md_data->len=0;
402 }
403
404 return ret;
405 }
406
407static int dev_crypto_md5_copy(EVP_MD_CTX *to,const EVP_MD_CTX *from)
408 {
409 const MD_DATA *from_md=from->md_data;
410 MD_DATA *to_md=to->md_data;
411
412 // How do we copy sessions?
413 assert(from->digest->flags&EVP_MD_FLAG_ONESHOT);
414
415 to_md->data=OPENSSL_malloc(from_md->len);
416 memcpy(to_md->data,from_md->data,from_md->len);
417
418 return 1;
419 }
420
421static int dev_crypto_md5_cleanup(EVP_MD_CTX *ctx)
422 {
423 return dev_crypto_cleanup_digest(ctx->md_data);
424 }
425
426static const EVP_MD md5_md=
427 {
428 NID_md5,
429 NID_md5WithRSAEncryption,
430 MD5_DIGEST_LENGTH,
431 EVP_MD_FLAG_ONESHOT, // XXX: set according to device info...
432 dev_crypto_md5_init,
433 dev_crypto_md5_update,
434 dev_crypto_md5_final,
435 dev_crypto_md5_copy,
436 dev_crypto_md5_cleanup,
437 EVP_PKEY_RSA_method,
438 MD5_CBLOCK,
439 sizeof(MD_DATA),
440 };
441
442const EVP_MD *EVP_dev_crypto_md5(void)
443 { return &md5_md; }
444
445#endif
446#endif
diff --git a/src/lib/libcrypto/evp/p5_crpt.c b/src/lib/libcrypto/evp/p5_crpt.c
index 48d50014a0..a1874e83b2 100644
--- a/src/lib/libcrypto/evp/p5_crpt.c
+++ b/src/lib/libcrypto/evp/p5_crpt.c
@@ -110,18 +110,12 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
110 int i; 110 int i;
111 PBEPARAM *pbe; 111 PBEPARAM *pbe;
112 int saltlen, iter; 112 int saltlen, iter;
113 unsigned char *salt; 113 unsigned char *salt, *pbuf;
114 const unsigned char *pbuf;
115 114
116 /* Extract useful info from parameter */ 115 /* Extract useful info from parameter */
117 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
118 param->value.sequence == NULL) {
119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
120 return 0;
121 }
122
123 pbuf = param->value.sequence->data; 116 pbuf = param->value.sequence->data;
124 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) { 117 if (!param || (param->type != V_ASN1_SEQUENCE) ||
118 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
125 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); 119 EVPerr(EVP_F_PKCS5_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
126 return 0; 120 return 0;
127 } 121 }
@@ -146,7 +140,7 @@ int PKCS5_PBE_keyivgen(EVP_CIPHER_CTX *cctx, const char *pass, int passlen,
146 EVP_DigestFinal_ex (&ctx, md_tmp, NULL); 140 EVP_DigestFinal_ex (&ctx, md_tmp, NULL);
147 } 141 }
148 EVP_MD_CTX_cleanup(&ctx); 142 EVP_MD_CTX_cleanup(&ctx);
149 OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= (int)sizeof(md_tmp)); 143 OPENSSL_assert(EVP_CIPHER_key_length(cipher) <= sizeof md_tmp);
150 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher)); 144 memcpy(key, md_tmp, EVP_CIPHER_key_length(cipher));
151 OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16); 145 OPENSSL_assert(EVP_CIPHER_iv_length(cipher) <= 16);
152 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)), 146 memcpy(iv, md_tmp + (16 - EVP_CIPHER_iv_length(cipher)),
diff --git a/src/lib/libcrypto/evp/p5_crpt2.c b/src/lib/libcrypto/evp/p5_crpt2.c
index c969d5a206..1d5fabc4b2 100644
--- a/src/lib/libcrypto/evp/p5_crpt2.c
+++ b/src/lib/libcrypto/evp/p5_crpt2.c
@@ -55,10 +55,10 @@
55 * Hudson (tjh@cryptsoft.com). 55 * Hudson (tjh@cryptsoft.com).
56 * 56 *
57 */ 57 */
58#if !defined(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
58#include <stdio.h> 59#include <stdio.h>
59#include <stdlib.h> 60#include <stdlib.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61#if !defined(OPENSSL_NO_HMAC) && !defined(OPENSSL_NO_SHA)
62#include <openssl/x509.h> 62#include <openssl/x509.h>
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/hmac.h> 64#include <openssl/hmac.h>
@@ -77,7 +77,7 @@
77 */ 77 */
78 78
79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen, 79int PKCS5_PBKDF2_HMAC_SHA1(const char *pass, int passlen,
80 const unsigned char *salt, int saltlen, int iter, 80 unsigned char *salt, int saltlen, int iter,
81 int keylen, unsigned char *out) 81 int keylen, unsigned char *out)
82{ 82{
83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4]; 83 unsigned char digtmp[SHA_DIGEST_LENGTH], *p, itmp[4];
@@ -148,23 +148,16 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
148 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md, 148 ASN1_TYPE *param, const EVP_CIPHER *c, const EVP_MD *md,
149 int en_de) 149 int en_de)
150{ 150{
151 unsigned char *salt, key[EVP_MAX_KEY_LENGTH]; 151 unsigned char *pbuf, *salt, key[EVP_MAX_KEY_LENGTH];
152 const unsigned char *pbuf; 152 int saltlen, keylen, iter, plen;
153 int saltlen, iter, plen;
154 unsigned int keylen;
155 PBE2PARAM *pbe2 = NULL; 153 PBE2PARAM *pbe2 = NULL;
156 const EVP_CIPHER *cipher; 154 const EVP_CIPHER *cipher;
157 PBKDF2PARAM *kdf = NULL; 155 PBKDF2PARAM *kdf = NULL;
158 156
159 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
160 param->value.sequence == NULL) {
161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
162 return 0;
163 }
164
165 pbuf = param->value.sequence->data; 157 pbuf = param->value.sequence->data;
166 plen = param->value.sequence->length; 158 plen = param->value.sequence->length;
167 if(!(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) { 159 if(!param || (param->type != V_ASN1_SEQUENCE) ||
160 !(pbe2 = d2i_PBE2PARAM(NULL, &pbuf, plen))) {
168 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR); 161 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
169 return 0; 162 return 0;
170 } 163 }
@@ -220,7 +213,7 @@ int PKCS5_v2_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
220 213
221 /* Now check the parameters of the kdf */ 214 /* Now check the parameters of the kdf */
222 215
223 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != (int)keylen)){ 216 if(kdf->keylength && (ASN1_INTEGER_get(kdf->keylength) != keylen)){
224 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN, 217 EVPerr(EVP_F_PKCS5_V2_PBE_KEYIVGEN,
225 EVP_R_UNSUPPORTED_KEYLENGTH); 218 EVP_R_UNSUPPORTED_KEYLENGTH);
226 goto err; 219 goto err;
diff --git a/src/lib/libcrypto/evp/p_dec.c b/src/lib/libcrypto/evp/p_dec.c
index f64901f653..8af620400e 100644
--- a/src/lib/libcrypto/evp/p_dec.c
+++ b/src/lib/libcrypto/evp/p_dec.c
@@ -66,7 +66,7 @@
66#include <openssl/objects.h> 66#include <openssl/objects.h>
67#include <openssl/x509.h> 67#include <openssl/x509.h>
68 68
69int EVP_PKEY_decrypt(unsigned char *key, const unsigned char *ek, int ekl, 69int EVP_PKEY_decrypt(unsigned char *key, unsigned char *ek, int ekl,
70 EVP_PKEY *priv) 70 EVP_PKEY *priv)
71 { 71 {
72 int ret= -1; 72 int ret= -1;
diff --git a/src/lib/libcrypto/evp/p_enc.c b/src/lib/libcrypto/evp/p_enc.c
index c2dfdc52ad..656883b996 100644
--- a/src/lib/libcrypto/evp/p_enc.c
+++ b/src/lib/libcrypto/evp/p_enc.c
@@ -66,7 +66,7 @@
66#include <openssl/objects.h> 66#include <openssl/objects.h>
67#include <openssl/x509.h> 67#include <openssl/x509.h>
68 68
69int EVP_PKEY_encrypt(unsigned char *ek, const unsigned char *key, int key_len, 69int EVP_PKEY_encrypt(unsigned char *ek, unsigned char *key, int key_len,
70 EVP_PKEY *pubk) 70 EVP_PKEY *pubk)
71 { 71 {
72 int ret=0; 72 int ret=0;
diff --git a/src/lib/libcrypto/evp/p_lib.c b/src/lib/libcrypto/evp/p_lib.c
index 22155ecf62..215b94292a 100644
--- a/src/lib/libcrypto/evp/p_lib.c
+++ b/src/lib/libcrypto/evp/p_lib.c
@@ -58,60 +58,24 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/err.h>
63#include <openssl/objects.h> 61#include <openssl/objects.h>
64#include <openssl/evp.h> 62#include <openssl/evp.h>
65#include <openssl/asn1_mac.h> 63#include <openssl/asn1_mac.h>
66#include <openssl/x509.h> 64#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DSA
71#include <openssl/dsa.h>
72#endif
73#ifndef OPENSSL_NO_DH
74#include <openssl/dh.h>
75#endif
76 65
77static void EVP_PKEY_free_it(EVP_PKEY *x); 66static void EVP_PKEY_free_it(EVP_PKEY *x);
78 67
79int EVP_PKEY_bits(EVP_PKEY *pkey) 68int EVP_PKEY_bits(EVP_PKEY *pkey)
80 { 69 {
81 if (0)
82 return 0;
83#ifndef OPENSSL_NO_RSA 70#ifndef OPENSSL_NO_RSA
84 else if (pkey->type == EVP_PKEY_RSA) 71 if (pkey->type == EVP_PKEY_RSA)
85 return(BN_num_bits(pkey->pkey.rsa->n)); 72 return(BN_num_bits(pkey->pkey.rsa->n));
73 else
86#endif 74#endif
87#ifndef OPENSSL_NO_DSA 75#ifndef OPENSSL_NO_DSA
88 else if (pkey->type == EVP_PKEY_DSA) 76 if (pkey->type == EVP_PKEY_DSA)
89 return(BN_num_bits(pkey->pkey.dsa->p)); 77 return(BN_num_bits(pkey->pkey.dsa->p));
90#endif 78#endif
91#ifndef OPENSSL_NO_EC
92 else if (pkey->type == EVP_PKEY_EC)
93 {
94 BIGNUM *order = BN_new();
95 const EC_GROUP *group;
96 int ret;
97
98 if (!order)
99 {
100 ERR_clear_error();
101 return 0;
102 }
103 group = EC_KEY_get0_group(pkey->pkey.ec);
104 if (!EC_GROUP_get_order(group, order, NULL))
105 {
106 ERR_clear_error();
107 return 0;
108 }
109
110 ret = BN_num_bits(order);
111 BN_free(order);
112 return ret;
113 }
114#endif
115 return(0); 79 return(0);
116 } 80 }
117 81
@@ -128,11 +92,6 @@ int EVP_PKEY_size(EVP_PKEY *pkey)
128 if (pkey->type == EVP_PKEY_DSA) 92 if (pkey->type == EVP_PKEY_DSA)
129 return(DSA_size(pkey->pkey.dsa)); 93 return(DSA_size(pkey->pkey.dsa));
130#endif 94#endif
131#ifndef OPENSSL_NO_ECDSA
132 if (pkey->type == EVP_PKEY_EC)
133 return(ECDSA_size(pkey->pkey.ec));
134#endif
135
136 return(0); 95 return(0);
137 } 96 }
138 97
@@ -148,20 +107,10 @@ int EVP_PKEY_save_parameters(EVP_PKEY *pkey, int mode)
148 return(ret); 107 return(ret);
149 } 108 }
150#endif 109#endif
151#ifndef OPENSSL_NO_EC
152 if (pkey->type == EVP_PKEY_EC)
153 {
154 int ret = pkey->save_parameters;
155
156 if (mode >= 0)
157 pkey->save_parameters = mode;
158 return(ret);
159 }
160#endif
161 return(0); 110 return(0);
162 } 111 }
163 112
164int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from) 113int EVP_PKEY_copy_parameters(EVP_PKEY *to, EVP_PKEY *from)
165 { 114 {
166 if (to->type != from->type) 115 if (to->type != from->type)
167 { 116 {
@@ -192,23 +141,12 @@ int EVP_PKEY_copy_parameters(EVP_PKEY *to, const EVP_PKEY *from)
192 to->pkey.dsa->g=a; 141 to->pkey.dsa->g=a;
193 } 142 }
194#endif 143#endif
195#ifndef OPENSSL_NO_EC
196 if (to->type == EVP_PKEY_EC)
197 {
198 EC_GROUP *group = EC_GROUP_dup(EC_KEY_get0_group(from->pkey.ec));
199 if (group == NULL)
200 goto err;
201 if (EC_KEY_set_group(to->pkey.ec, group) == 0)
202 goto err;
203 EC_GROUP_free(group);
204 }
205#endif
206 return(1); 144 return(1);
207err: 145err:
208 return(0); 146 return(0);
209 } 147 }
210 148
211int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey) 149int EVP_PKEY_missing_parameters(EVP_PKEY *pkey)
212 { 150 {
213#ifndef OPENSSL_NO_DSA 151#ifndef OPENSSL_NO_DSA
214 if (pkey->type == EVP_PKEY_DSA) 152 if (pkey->type == EVP_PKEY_DSA)
@@ -220,18 +158,10 @@ int EVP_PKEY_missing_parameters(const EVP_PKEY *pkey)
220 return(1); 158 return(1);
221 } 159 }
222#endif 160#endif
223#ifndef OPENSSL_NO_EC
224 if (pkey->type == EVP_PKEY_EC)
225 {
226 if (EC_KEY_get0_group(pkey->pkey.ec) == NULL)
227 return(1);
228 }
229#endif
230
231 return(0); 161 return(0);
232 } 162 }
233 163
234int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b) 164int EVP_PKEY_cmp_parameters(EVP_PKEY *a, EVP_PKEY *b)
235 { 165 {
236#ifndef OPENSSL_NO_DSA 166#ifndef OPENSSL_NO_DSA
237 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA)) 167 if ((a->type == EVP_PKEY_DSA) && (b->type == EVP_PKEY_DSA))
@@ -244,72 +174,9 @@ int EVP_PKEY_cmp_parameters(const EVP_PKEY *a, const EVP_PKEY *b)
244 return(1); 174 return(1);
245 } 175 }
246#endif 176#endif
247#ifndef OPENSSL_NO_EC
248 if (a->type == EVP_PKEY_EC && b->type == EVP_PKEY_EC)
249 {
250 const EC_GROUP *group_a = EC_KEY_get0_group(a->pkey.ec),
251 *group_b = EC_KEY_get0_group(b->pkey.ec);
252 if (EC_GROUP_cmp(group_a, group_b, NULL))
253 return 0;
254 else
255 return 1;
256 }
257#endif
258 return(-1); 177 return(-1);
259 } 178 }
260 179
261int EVP_PKEY_cmp(const EVP_PKEY *a, const EVP_PKEY *b)
262 {
263 if (a->type != b->type)
264 return -1;
265
266 if (EVP_PKEY_cmp_parameters(a, b) == 0)
267 return 0;
268
269 switch (a->type)
270 {
271#ifndef OPENSSL_NO_RSA
272 case EVP_PKEY_RSA:
273 if (BN_cmp(b->pkey.rsa->n,a->pkey.rsa->n) != 0
274 || BN_cmp(b->pkey.rsa->e,a->pkey.rsa->e) != 0)
275 return 0;
276 break;
277#endif
278#ifndef OPENSSL_NO_DSA
279 case EVP_PKEY_DSA:
280 if (BN_cmp(b->pkey.dsa->pub_key,a->pkey.dsa->pub_key) != 0)
281 return 0;
282 break;
283#endif
284#ifndef OPENSSL_NO_EC
285 case EVP_PKEY_EC:
286 {
287 int r;
288 const EC_GROUP *group = EC_KEY_get0_group(b->pkey.ec);
289 const EC_POINT *pa = EC_KEY_get0_public_key(a->pkey.ec),
290 *pb = EC_KEY_get0_public_key(b->pkey.ec);
291 r = EC_POINT_cmp(group, pa, pb, NULL);
292 if (r != 0)
293 {
294 if (r == 1)
295 return 0;
296 else
297 return -2;
298 }
299 }
300 break;
301#endif
302#ifndef OPENSSL_NO_DH
303 case EVP_PKEY_DH:
304 return -2;
305#endif
306 default:
307 return -2;
308 }
309
310 return 1;
311 }
312
313EVP_PKEY *EVP_PKEY_new(void) 180EVP_PKEY *EVP_PKEY_new(void)
314 { 181 {
315 EVP_PKEY *ret; 182 EVP_PKEY *ret;
@@ -379,29 +246,6 @@ DSA *EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
379} 246}
380#endif 247#endif
381 248
382#ifndef OPENSSL_NO_EC
383
384int EVP_PKEY_set1_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
385{
386 int ret = EVP_PKEY_assign_EC_KEY(pkey,key);
387 if (ret)
388 EC_KEY_up_ref(key);
389 return ret;
390}
391
392EC_KEY *EVP_PKEY_get1_EC_KEY(EVP_PKEY *pkey)
393{
394 if (pkey->type != EVP_PKEY_EC)
395 {
396 EVPerr(EVP_F_EVP_PKEY_GET1_EC_KEY, EVP_R_EXPECTING_A_EC_KEY);
397 return NULL;
398 }
399 EC_KEY_up_ref(pkey->pkey.ec);
400 return pkey->pkey.ec;
401}
402#endif
403
404
405#ifndef OPENSSL_NO_DH 249#ifndef OPENSSL_NO_DH
406 250
407int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key) 251int EVP_PKEY_set1_DH(EVP_PKEY *pkey, DH *key)
@@ -438,8 +282,6 @@ int EVP_PKEY_type(int type)
438 return(EVP_PKEY_DSA); 282 return(EVP_PKEY_DSA);
439 case EVP_PKEY_DH: 283 case EVP_PKEY_DH:
440 return(EVP_PKEY_DH); 284 return(EVP_PKEY_DH);
441 case EVP_PKEY_EC:
442 return(EVP_PKEY_EC);
443 default: 285 default:
444 return(NID_undef); 286 return(NID_undef);
445 } 287 }
@@ -464,8 +306,6 @@ void EVP_PKEY_free(EVP_PKEY *x)
464 } 306 }
465#endif 307#endif
466 EVP_PKEY_free_it(x); 308 EVP_PKEY_free_it(x);
467 if (x->attributes)
468 sk_X509_ATTRIBUTE_pop_free(x->attributes, X509_ATTRIBUTE_free);
469 OPENSSL_free(x); 309 OPENSSL_free(x);
470 } 310 }
471 311
@@ -487,11 +327,6 @@ static void EVP_PKEY_free_it(EVP_PKEY *x)
487 DSA_free(x->pkey.dsa); 327 DSA_free(x->pkey.dsa);
488 break; 328 break;
489#endif 329#endif
490#ifndef OPENSSL_NO_EC
491 case EVP_PKEY_EC:
492 EC_KEY_free(x->pkey.ec);
493 break;
494#endif
495#ifndef OPENSSL_NO_DH 330#ifndef OPENSSL_NO_DH
496 case EVP_PKEY_DH: 331 case EVP_PKEY_DH:
497 DH_free(x->pkey.dh); 332 DH_free(x->pkey.dh);
diff --git a/src/lib/libcrypto/evp/p_open.c b/src/lib/libcrypto/evp/p_open.c
index 9935206d0f..5a933d1cda 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 OPENSSL_NO_RSA
59#include <stdio.h> 60#include <stdio.h>
60#include "cryptlib.h" 61#include "cryptlib.h"
61
62#ifndef OPENSSL_NO_RSA
63
64#include <openssl/evp.h> 62#include <openssl/evp.h>
65#include <openssl/objects.h> 63#include <openssl/objects.h>
66#include <openssl/x509.h> 64#include <openssl/x509.h>
67#include <openssl/rsa.h>
68 65
69int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, 66int EVP_OpenInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char *ek,
70 const unsigned char *ek, int ekl, const unsigned char *iv, 67 int ekl, unsigned char *iv, EVP_PKEY *priv)
71 EVP_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;
diff --git a/src/lib/libcrypto/evp/p_seal.c b/src/lib/libcrypto/evp/p_seal.c
index 8cc8fcb0bd..37e547fe72 100644
--- a/src/lib/libcrypto/evp/p_seal.c
+++ b/src/lib/libcrypto/evp/p_seal.c
@@ -78,7 +78,7 @@ int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, unsigned char **ek
78 } 78 }
79 if ((npubk <= 0) || !pubk) 79 if ((npubk <= 0) || !pubk)
80 return 1; 80 return 1;
81 if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) 81 if (RAND_bytes(key,EVP_MAX_KEY_LENGTH) <= 0)
82 return 0; 82 return 0;
83 if (EVP_CIPHER_CTX_iv_length(ctx)) 83 if (EVP_CIPHER_CTX_iv_length(ctx))
84 RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx)); 84 RAND_pseudo_bytes(iv,EVP_CIPHER_CTX_iv_length(ctx));
diff --git a/src/lib/libcrypto/evp/p_verify.c b/src/lib/libcrypto/evp/p_verify.c
index 21a40a375e..d854d743a5 100644
--- a/src/lib/libcrypto/evp/p_verify.c
+++ b/src/lib/libcrypto/evp/p_verify.c
@@ -62,7 +62,7 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64 64
65int EVP_VerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sigbuf, 65int EVP_VerifyFinal(EVP_MD_CTX *ctx, unsigned char *sigbuf,
66 unsigned int siglen, EVP_PKEY *pkey) 66 unsigned int siglen, EVP_PKEY *pkey)
67 { 67 {
68 unsigned char m[EVP_MAX_MD_SIZE]; 68 unsigned char m[EVP_MAX_MD_SIZE];
diff --git a/src/lib/libcrypto/ex_data.c b/src/lib/libcrypto/ex_data.c
index 3b11e7a556..5b2e345c27 100644
--- a/src/lib/libcrypto/ex_data.c
+++ b/src/lib/libcrypto/ex_data.c
@@ -138,8 +138,12 @@
138 * 138 *
139 */ 139 */
140 140
141#include "cryptlib.h" 141#include <stdio.h>
142#include <stdlib.h>
143#include <openssl/buffer.h>
144#include <openssl/bio.h>
142#include <openssl/lhash.h> 145#include <openssl/lhash.h>
146#include "cryptlib.h"
143 147
144/* What an "implementation of ex_data functionality" looks like */ 148/* What an "implementation of ex_data functionality" looks like */
145struct st_CRYPTO_EX_DATA_IMPL 149struct st_CRYPTO_EX_DATA_IMPL
@@ -283,7 +287,7 @@ static void def_cleanup_util_cb(CRYPTO_EX_DATA_FUNCS *funcs)
283/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from 287/* This callback is used in lh_doall to destroy all EX_CLASS_ITEM values from
284 * "ex_data" prior to the ex_data hash table being itself destroyed. Doesn't do 288 * "ex_data" prior to the ex_data hash table being itself destroyed. Doesn't do
285 * any locking. */ 289 * any locking. */
286static void def_cleanup_cb(void *a_void) 290static void def_cleanup_cb(const void *a_void)
287 { 291 {
288 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void; 292 EX_CLASS_ITEM *item = (EX_CLASS_ITEM *)a_void;
289 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb); 293 sk_CRYPTO_EX_DATA_FUNCS_pop_free(item->meth, def_cleanup_util_cb);
@@ -354,7 +358,7 @@ static int def_add_index(EX_CLASS_ITEM *item, long argl, void *argp,
354 } 358 }
355 } 359 }
356 toret = item->meth_num++; 360 toret = item->meth_num++;
357 (void)sk_CRYPTO_EX_DATA_FUNCS_set(item->meth, toret, a); 361 sk_CRYPTO_EX_DATA_FUNCS_set(item->meth, toret, a);
358err: 362err:
359 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA); 363 CRYPTO_w_unlock(CRYPTO_LOCK_EX_DATA);
360 return toret; 364 return toret;
diff --git a/src/lib/libcrypto/hmac/Makefile b/src/lib/libcrypto/hmac/Makefile
new file mode 100644
index 0000000000..01f10c396f
--- /dev/null
+++ b/src/lib/libcrypto/hmac/Makefile
@@ -0,0 +1,85 @@
1#
2# OpenSSL/crypto/md/Makefile
3#
4
5DIR= hmac
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=hmactest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=hmac.c
21LIBOBJ=hmac.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= hmac.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77hmac.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
78hmac.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
79hmac.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
81hmac.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
82hmac.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
83hmac.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
84hmac.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
85hmac.o: ../../include/openssl/symhacks.h ../cryptlib.h hmac.c
diff --git a/src/lib/libcrypto/hmac/Makefile.ssl b/src/lib/libcrypto/hmac/Makefile.ssl
new file mode 100644
index 0000000000..f1c07322c4
--- /dev/null
+++ b/src/lib/libcrypto/hmac/Makefile.ssl
@@ -0,0 +1,101 @@
1#
2# SSLeay/crypto/md/Makefile
3#
4
5DIR= hmac
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=hmactest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=hmac.c
27LIBOBJ=hmac.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= hmac.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82hmac.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
83hmac.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
84hmac.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
85hmac.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
86hmac.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
87hmac.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
88hmac.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
89hmac.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
90hmac.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
91hmac.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
92hmac.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
93hmac.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
94hmac.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95hmac.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rc2.h
96hmac.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
97hmac.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
98hmac.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
99hmac.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
100hmac.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
101hmac.o: ../cryptlib.h hmac.c
diff --git a/src/lib/libcrypto/hmac/hmac.c b/src/lib/libcrypto/hmac/hmac.c
index c45e001492..6c110bd52b 100644
--- a/src/lib/libcrypto/hmac/hmac.c
+++ b/src/lib/libcrypto/hmac/hmac.c
@@ -58,8 +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 "cryptlib.h"
62#include <openssl/hmac.h> 61#include <openssl/hmac.h>
62#include "cryptlib.h"
63
64#ifndef OPENSSL_FIPS
63 65
64void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 66void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
65 const EVP_MD *md, ENGINE *impl) 67 const EVP_MD *md, ENGINE *impl)
@@ -79,7 +81,7 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
79 { 81 {
80 reset=1; 82 reset=1;
81 j=EVP_MD_block_size(md); 83 j=EVP_MD_block_size(md);
82 OPENSSL_assert(j <= (int)sizeof(ctx->key)); 84 OPENSSL_assert(j <= sizeof ctx->key);
83 if (j < len) 85 if (j < len)
84 { 86 {
85 EVP_DigestInit_ex(&ctx->md_ctx,md, impl); 87 EVP_DigestInit_ex(&ctx->md_ctx,md, impl);
@@ -89,7 +91,7 @@ void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
89 } 91 }
90 else 92 else
91 { 93 {
92 OPENSSL_assert(len>=0 && len<=(int)sizeof(ctx->key)); 94 OPENSSL_assert(len <= sizeof ctx->key);
93 memcpy(ctx->key,key,len); 95 memcpy(ctx->key,key,len);
94 ctx->key_length=len; 96 ctx->key_length=len;
95 } 97 }
@@ -121,7 +123,7 @@ void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
121 HMAC_Init_ex(ctx,key,len,md, NULL); 123 HMAC_Init_ex(ctx,key,len,md, NULL);
122 } 124 }
123 125
124void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len) 126void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len)
125 { 127 {
126 EVP_DigestUpdate(&ctx->md_ctx,data,len); 128 EVP_DigestUpdate(&ctx->md_ctx,data,len);
127 } 129 }
@@ -156,7 +158,7 @@ void HMAC_CTX_cleanup(HMAC_CTX *ctx)
156 } 158 }
157 159
158unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 160unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
159 const unsigned char *d, size_t n, unsigned char *md, 161 const unsigned char *d, int n, unsigned char *md,
160 unsigned int *md_len) 162 unsigned int *md_len)
161 { 163 {
162 HMAC_CTX c; 164 HMAC_CTX c;
@@ -171,3 +173,11 @@ unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
171 return(md); 173 return(md);
172 } 174 }
173 175
176void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags)
177 {
178 EVP_MD_CTX_set_flags(&ctx->i_ctx, flags);
179 EVP_MD_CTX_set_flags(&ctx->o_ctx, flags);
180 EVP_MD_CTX_set_flags(&ctx->md_ctx, flags);
181 }
182
183#endif
diff --git a/src/lib/libcrypto/hmac/hmac.h b/src/lib/libcrypto/hmac/hmac.h
index 719fc408ac..c6489c04c8 100644
--- a/src/lib/libcrypto/hmac/hmac.h
+++ b/src/lib/libcrypto/hmac/hmac.h
@@ -58,15 +58,17 @@
58#ifndef HEADER_HMAC_H 58#ifndef HEADER_HMAC_H
59#define HEADER_HMAC_H 59#define HEADER_HMAC_H
60 60
61#include <openssl/opensslconf.h>
62
63#ifdef OPENSSL_NO_HMAC 61#ifdef OPENSSL_NO_HMAC
64#error HMAC is disabled. 62#error HMAC is disabled.
65#endif 63#endif
66 64
67#include <openssl/evp.h> 65#include <openssl/evp.h>
68 66
69#define HMAC_MAX_MD_CBLOCK 128 /* largest known is SHA512 */ 67#ifdef OPENSSL_FIPS
68#define HMAC_MAX_MD_CBLOCK 128
69#else
70#define HMAC_MAX_MD_CBLOCK 64
71#endif
70 72
71#ifdef __cplusplus 73#ifdef __cplusplus
72extern "C" { 74extern "C" {
@@ -94,12 +96,13 @@ void HMAC_Init(HMAC_CTX *ctx, const void *key, int len,
94 const EVP_MD *md); /* deprecated */ 96 const EVP_MD *md); /* deprecated */
95void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, 97void HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len,
96 const EVP_MD *md, ENGINE *impl); 98 const EVP_MD *md, ENGINE *impl);
97void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, size_t len); 99void HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len);
98void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len); 100void HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len);
99unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len, 101unsigned char *HMAC(const EVP_MD *evp_md, const void *key, int key_len,
100 const unsigned char *d, size_t n, unsigned char *md, 102 const unsigned char *d, int n, unsigned char *md,
101 unsigned int *md_len); 103 unsigned int *md_len);
102 104
105void HMAC_CTX_set_flags(HMAC_CTX *ctx, unsigned long flags);
103 106
104#ifdef __cplusplus 107#ifdef __cplusplus
105} 108}
diff --git a/src/lib/libcrypto/hmac/hmactest.c b/src/lib/libcrypto/hmac/hmactest.c
new file mode 100644
index 0000000000..1b906b81af
--- /dev/null
+++ b/src/lib/libcrypto/hmac/hmactest.c
@@ -0,0 +1,175 @@
1/* crypto/hmac/hmactest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_HMAC
66int main(int argc, char *argv[])
67{
68 printf("No HMAC support\n");
69 return(0);
70}
71#else
72#include <openssl/hmac.h>
73#ifndef OPENSSL_NO_MD5
74#include <openssl/md5.h>
75#endif
76
77#ifdef CHARSET_EBCDIC
78#include <openssl/ebcdic.h>
79#endif
80
81#ifndef OPENSSL_NO_MD5
82static struct test_st
83 {
84 unsigned char key[16];
85 int key_len;
86 unsigned char data[64];
87 int data_len;
88 unsigned char *digest;
89 } test[4]={
90 { "",
91 0,
92 "More text test vectors to stuff up EBCDIC machines :-)",
93 54,
94 (unsigned char *)"e9139d1e6ee064ef8cf514fc7dc83e86",
95 },{ {0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,
96 0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,0x0b,},
97 16,
98 "Hi There",
99 8,
100 (unsigned char *)"9294727a3638bb1c13f48ef8158bfc9d",
101 },{ "Jefe",
102 4,
103 "what do ya want for nothing?",
104 28,
105 (unsigned char *)"750c783e6ab0b503eaa86e310a5db738",
106 },{
107 {0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,
108 0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,},
109 16,
110 {0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
111 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
112 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
113 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
114 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
115 0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,
116 0xdd,0xdd},
117 50,
118 (unsigned char *)"56be34521d144c88dbb8c733f0e8b3f6",
119 },
120 };
121#endif
122
123static char *pt(unsigned char *md);
124int main(int argc, char *argv[])
125 {
126#ifndef OPENSSL_NO_MD5
127 int i;
128 char *p;
129#endif
130 int err=0;
131
132#ifdef OPENSSL_NO_MD5
133 printf("test skipped: MD5 disabled\n");
134#else
135
136#ifdef CHARSET_EBCDIC
137 ebcdic2ascii(test[0].data, test[0].data, test[0].data_len);
138 ebcdic2ascii(test[1].data, test[1].data, test[1].data_len);
139 ebcdic2ascii(test[2].key, test[2].key, test[2].key_len);
140 ebcdic2ascii(test[2].data, test[2].data, test[2].data_len);
141#endif
142
143 for (i=0; i<4; i++)
144 {
145 p=pt(HMAC(EVP_md5(),
146 test[i].key, test[i].key_len,
147 test[i].data, test[i].data_len,
148 NULL,NULL));
149
150 if (strcmp(p,(char *)test[i].digest) != 0)
151 {
152 printf("error calculating HMAC on %d entry'\n",i);
153 printf("got %s instead of %s\n",p,test[i].digest);
154 err++;
155 }
156 else
157 printf("test %d ok\n",i);
158 }
159#endif /* OPENSSL_NO_MD5 */
160 EXIT(err);
161 return(0);
162 }
163
164#ifndef OPENSSL_NO_MD5
165static char *pt(unsigned char *md)
166 {
167 int i;
168 static char buf[80];
169
170 for (i=0; i<MD5_DIGEST_LENGTH; i++)
171 sprintf(&(buf[i*2]),"%02x",md[i]);
172 return(buf);
173 }
174#endif
175#endif
diff --git a/src/lib/libcrypto/idea/Makefile b/src/lib/libcrypto/idea/Makefile
new file mode 100644
index 0000000000..b2e7add666
--- /dev/null
+++ b/src/lib/libcrypto/idea/Makefile
@@ -0,0 +1,86 @@
1#
2# OpenSSL/crypto/idea/Makefile
3#
4
5DIR= idea
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=ideatest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c i_skey.c
21LIBOBJ=i_cbc.o i_cfb64.o i_ofb64.o i_ecb.o i_skey.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= idea.h
26HEADER= idea_lcl.h $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77i_cbc.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
78i_cbc.o: i_cbc.c idea_lcl.h
79i_cfb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
80i_cfb64.o: i_cfb64.c idea_lcl.h
81i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
82i_ecb.o: ../../include/openssl/opensslv.h i_ecb.c idea_lcl.h
83i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
84i_ofb64.o: i_ofb64.c idea_lcl.h
85i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
86i_skey.o: i_skey.c idea_lcl.h
diff --git a/src/lib/libcrypto/idea/Makefile.ssl b/src/lib/libcrypto/idea/Makefile.ssl
new file mode 100644
index 0000000000..fa016ea399
--- /dev/null
+++ b/src/lib/libcrypto/idea/Makefile.ssl
@@ -0,0 +1,91 @@
1#
2# SSLeay/crypto/idea/Makefile
3#
4
5DIR= idea
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=ideatest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=i_cbc.c i_cfb64.c i_ofb64.c i_ecb.c i_skey.c
27LIBOBJ=i_cbc.o i_cfb64.o i_ofb64.o i_ecb.o i_skey.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= idea.h
32HEADER= idea_lcl.h $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82i_cbc.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
83i_cbc.o: i_cbc.c idea_lcl.h
84i_cfb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
85i_cfb64.o: i_cfb64.c idea_lcl.h
86i_ecb.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
87i_ecb.o: ../../include/openssl/opensslv.h i_ecb.c idea_lcl.h
88i_ofb64.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
89i_ofb64.o: i_ofb64.c idea_lcl.h
90i_skey.o: ../../include/openssl/idea.h ../../include/openssl/opensslconf.h
91i_skey.o: i_skey.c idea_lcl.h
diff --git a/src/lib/libcrypto/idea/idea.h b/src/lib/libcrypto/idea/idea.h
index bf97a37e39..bf41844fd7 100644
--- a/src/lib/libcrypto/idea/idea.h
+++ b/src/lib/libcrypto/idea/idea.h
@@ -59,8 +59,6 @@
59#ifndef HEADER_IDEA_H 59#ifndef HEADER_IDEA_H
60#define HEADER_IDEA_H 60#define HEADER_IDEA_H
61 61
62#include <openssl/opensslconf.h> /* IDEA_INT, OPENSSL_NO_IDEA */
63
64#ifdef OPENSSL_NO_IDEA 62#ifdef OPENSSL_NO_IDEA
65#error IDEA is disabled. 63#error IDEA is disabled.
66#endif 64#endif
@@ -68,6 +66,7 @@
68#define IDEA_ENCRYPT 1 66#define IDEA_ENCRYPT 1
69#define IDEA_DECRYPT 0 67#define IDEA_DECRYPT 0
70 68
69#include <openssl/opensslconf.h> /* IDEA_INT */
71#define IDEA_BLOCK 8 70#define IDEA_BLOCK 8
72#define IDEA_KEY_LENGTH 16 71#define IDEA_KEY_LENGTH 16
73 72
@@ -83,8 +82,12 @@ typedef struct idea_key_st
83const char *idea_options(void); 82const char *idea_options(void);
84void idea_ecb_encrypt(const unsigned char *in, unsigned char *out, 83void idea_ecb_encrypt(const unsigned char *in, unsigned char *out,
85 IDEA_KEY_SCHEDULE *ks); 84 IDEA_KEY_SCHEDULE *ks);
85#ifdef OPENSSL_FIPS
86void private_idea_set_encrypt_key(const unsigned char *key,
87 IDEA_KEY_SCHEDULE *ks);
88#endif
86void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks); 89void idea_set_encrypt_key(const unsigned char *key, IDEA_KEY_SCHEDULE *ks);
87void idea_set_decrypt_key(const IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk); 90void idea_set_decrypt_key(IDEA_KEY_SCHEDULE *ek, IDEA_KEY_SCHEDULE *dk);
88void idea_cbc_encrypt(const unsigned char *in, unsigned char *out, 91void idea_cbc_encrypt(const unsigned char *in, unsigned char *out,
89 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc); 92 long length, IDEA_KEY_SCHEDULE *ks, unsigned char *iv,int enc);
90void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out, 93void idea_cfb64_encrypt(const unsigned char *in, unsigned char *out,
diff --git a/src/lib/libcrypto/idea/ideatest.c b/src/lib/libcrypto/idea/ideatest.c
new file mode 100644
index 0000000000..e6ffc7025e
--- /dev/null
+++ b/src/lib/libcrypto/idea/ideatest.c
@@ -0,0 +1,235 @@
1/* crypto/idea/ideatest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_IDEA
66int main(int argc, char *argv[])
67{
68 printf("No IDEA support\n");
69 return(0);
70}
71#else
72#include <openssl/idea.h>
73
74unsigned char k[16]={
75 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
76 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
77
78unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
79unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
80unsigned char out[80];
81
82char *text="Hello to all people out there";
83
84static unsigned char cfb_key[16]={
85 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
86 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
87 };
88static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
89static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
90#define CFB_TEST_SIZE 24
91static unsigned char plain[CFB_TEST_SIZE]=
92 {
93 0x4e,0x6f,0x77,0x20,0x69,0x73,
94 0x20,0x74,0x68,0x65,0x20,0x74,
95 0x69,0x6d,0x65,0x20,0x66,0x6f,
96 0x72,0x20,0x61,0x6c,0x6c,0x20
97 };
98static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
99 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
100 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
101 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
102
103/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
104 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
105 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
106 };
107
108static int cfb64_test(unsigned char *cfb_cipher);
109static char *pt(unsigned char *p);
110int main(int argc, char *argv[])
111 {
112 int i,err=0;
113 IDEA_KEY_SCHEDULE key,dkey;
114 unsigned char iv[8];
115
116 idea_set_encrypt_key(k,&key);
117 idea_ecb_encrypt(in,out,&key);
118 if (memcmp(out,c,8) != 0)
119 {
120 printf("ecb idea error encrypting\n");
121 printf("got :");
122 for (i=0; i<8; i++)
123 printf("%02X ",out[i]);
124 printf("\n");
125 printf("expected:");
126 for (i=0; i<8; i++)
127 printf("%02X ",c[i]);
128 err=20;
129 printf("\n");
130 }
131
132 idea_set_decrypt_key(&key,&dkey);
133 idea_ecb_encrypt(c,out,&dkey);
134 if (memcmp(out,in,8) != 0)
135 {
136 printf("ecb idea error decrypting\n");
137 printf("got :");
138 for (i=0; i<8; i++)
139 printf("%02X ",out[i]);
140 printf("\n");
141 printf("expected:");
142 for (i=0; i<8; i++)
143 printf("%02X ",in[i]);
144 printf("\n");
145 err=3;
146 }
147
148 if (err == 0) printf("ecb idea ok\n");
149
150 memcpy(iv,k,8);
151 idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1);
152 memcpy(iv,k,8);
153 idea_cbc_encrypt(out,out,8,&dkey,iv,0);
154 idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0);
155 if (memcmp(text,out,strlen(text)+1) != 0)
156 {
157 printf("cbc idea bad\n");
158 err=4;
159 }
160 else
161 printf("cbc idea ok\n");
162
163 printf("cfb64 idea ");
164 if (cfb64_test(cfb_cipher64))
165 {
166 printf("bad\n");
167 err=5;
168 }
169 else
170 printf("ok\n");
171
172#ifdef OPENSSL_SYS_NETWARE
173 if (err) printf("ERROR: %d\n", err);
174#endif
175 EXIT(err);
176 return(err);
177 }
178
179static int cfb64_test(unsigned char *cfb_cipher)
180 {
181 IDEA_KEY_SCHEDULE eks,dks;
182 int err=0,i,n;
183
184 idea_set_encrypt_key(cfb_key,&eks);
185 idea_set_decrypt_key(&eks,&dks);
186 memcpy(cfb_tmp,cfb_iv,8);
187 n=0;
188 idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
189 cfb_tmp,&n,IDEA_ENCRYPT);
190 idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
191 (long)CFB_TEST_SIZE-12,&eks,
192 cfb_tmp,&n,IDEA_ENCRYPT);
193 if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
194 {
195 err=1;
196 printf("idea_cfb64_encrypt encrypt error\n");
197 for (i=0; i<CFB_TEST_SIZE; i+=8)
198 printf("%s\n",pt(&(cfb_buf1[i])));
199 }
200 memcpy(cfb_tmp,cfb_iv,8);
201 n=0;
202 idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
203 cfb_tmp,&n,IDEA_DECRYPT);
204 idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
205 (long)CFB_TEST_SIZE-17,&dks,
206 cfb_tmp,&n,IDEA_DECRYPT);
207 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
208 {
209 err=1;
210 printf("idea_cfb_encrypt decrypt error\n");
211 for (i=0; i<24; i+=8)
212 printf("%s\n",pt(&(cfb_buf2[i])));
213 }
214 return(err);
215 }
216
217static char *pt(unsigned char *p)
218 {
219 static char bufs[10][20];
220 static int bnum=0;
221 char *ret;
222 int i;
223 static char *f="0123456789ABCDEF";
224
225 ret= &(bufs[bnum++][0]);
226 bnum%=10;
227 for (i=0; i<8; i++)
228 {
229 ret[i*2]=f[(p[i]>>4)&0xf];
230 ret[i*2+1]=f[p[i]&0xf];
231 }
232 ret[16]='\0';
233 return(ret);
234 }
235#endif
diff --git a/src/lib/libcrypto/idea/version b/src/lib/libcrypto/idea/version
new file mode 100644
index 0000000000..3f22293795
--- /dev/null
+++ b/src/lib/libcrypto/idea/version
@@ -0,0 +1,12 @@
11.1 07/12/95 - eay
2 Many thanks to Rhys Weatherley <rweather@us.oracle.com>
3 for pointing out that I was assuming little endian byte
4 order for all quantities what idea actually used
5 bigendian. No where in the spec does it mention
6 this, it is all in terms of 16 bit numbers and even the example
7 does not use byte streams for the input example :-(.
8 If you byte swap each pair of input, keys and iv, the functions
9 would produce the output as the old version :-(.
10
111.0 ??/??/95 - eay
12 First version.
diff --git a/src/lib/libcrypto/install.com b/src/lib/libcrypto/install.com
new file mode 100644
index 0000000000..b3d155e964
--- /dev/null
+++ b/src/lib/libcrypto/install.com
@@ -0,0 +1,138 @@
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,MD4,MD5,SHA,MDC2,HMAC,RIPEMD,-
36 DES,RC2,RC4,RC5,IDEA,BF,CAST,-
37 BN,EC,RSA,DSA,DH,DSO,ENGINE,AES,-
38 BUFFER,BIO,STACK,LHASH,RAND,ERR,OBJECTS,-
39 EVP,ASN1,PEM,X509,X509V3,CONF,TXT_DB,PKCS7,PKCS12,COMP,OCSP,-
40 UI,KRB5
41$ EXHEADER_ := crypto.h,tmdiff.h,opensslv.h,opensslconf.h,ebcdic.h,-
42 symhacks.h,ossl_typ.h
43$ EXHEADER_MD2 := md2.h
44$ EXHEADER_MD4 := md4.h
45$ EXHEADER_MD5 := md5.h
46$ EXHEADER_SHA := sha.h
47$ EXHEADER_MDC2 := mdc2.h
48$ EXHEADER_HMAC := hmac.h
49$ EXHEADER_RIPEMD := ripemd.h
50$ EXHEADER_DES := des.h,des_old.h
51$ EXHEADER_RC2 := rc2.h
52$ EXHEADER_RC4 := rc4.h
53$ EXHEADER_RC5 := rc5.h
54$ EXHEADER_IDEA := idea.h
55$ EXHEADER_BF := blowfish.h
56$ EXHEADER_CAST := cast.h
57$ EXHEADER_BN := bn.h
58$ EXHEADER_EC := ec.h
59$ EXHEADER_RSA := rsa.h
60$ EXHEADER_DSA := dsa.h
61$ EXHEADER_DH := dh.h
62$ EXHEADER_DSO := dso.h
63$ EXHEADER_ENGINE := engine.h
64$ EXHEADER_AES := aes.h
65$ EXHEADER_BUFFER := buffer.h
66$ EXHEADER_BIO := bio.h
67$ EXHEADER_STACK := stack.h,safestack.h
68$ EXHEADER_LHASH := lhash.h
69$ EXHEADER_RAND := rand.h
70$ EXHEADER_ERR := err.h
71$ EXHEADER_OBJECTS := objects.h,obj_mac.h
72$ EXHEADER_EVP := evp.h
73$ EXHEADER_ASN1 := asn1.h,asn1_mac.h,asn1t.h
74$ EXHEADER_PEM := pem.h,pem2.h
75$ EXHEADER_X509 := x509.h,x509_vfy.h
76$ EXHEADER_X509V3 := x509v3.h
77$ EXHEADER_CONF := conf.h,conf_api.h
78$ EXHEADER_TXT_DB := txt_db.h
79$ EXHEADER_PKCS7 := pkcs7.h
80$ EXHEADER_PKCS12 := pkcs12.h
81$ EXHEADER_COMP := comp.h
82$ EXHEADER_OCSP := ocsp.h
83$ EXHEADER_UI := ui.h,ui_compat.h
84$ EXHEADER_KRB5 := krb5_asn.h
85$ LIBS := LIBCRYPTO
86$
87$ VEXE_DIR := [-.VAX.EXE.CRYPTO]
88$ AEXE_DIR := [-.AXP.EXE.CRYPTO]
89$
90$ I = 0
91$ LOOP_SDIRS:
92$ D = F$EDIT(F$ELEMENT(I, ",", SDIRS),"TRIM")
93$ I = I + 1
94$ IF D .EQS. "," THEN GOTO LOOP_SDIRS_END
95$ tmp = EXHEADER_'D'
96$ IF D .EQS. ""
97$ THEN
98$ COPY 'tmp' WRK_SSLINCLUDE: /LOG
99$ ELSE
100$ COPY [.'D']'tmp' WRK_SSLINCLUDE: /LOG
101$ ENDIF
102$ SET FILE/PROT=WORLD:RE WRK_SSLINCLUDE:'tmp'
103$ GOTO LOOP_SDIRS
104$ LOOP_SDIRS_END:
105$
106$ I = 0
107$ LOOP_LIB:
108$ E = F$EDIT(F$ELEMENT(I, ",", LIBS),"TRIM")
109$ I = I + 1
110$ IF E .EQS. "," THEN GOTO LOOP_LIB_END
111$ SET NOON
112$ IF F$SEARCH(VEXE_DIR+E+".OLB") .NES. ""
113$ THEN
114$ COPY 'VEXE_DIR''E'.OLB WRK_SSLVLIB:'E'.OLB/log
115$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.OLB
116$ ENDIF
117$ ! Preparing for the time when we have shareable images
118$ IF F$SEARCH(VEXE_DIR+E+".EXE") .NES. ""
119$ THEN
120$ COPY 'VEXE_DIR''E'.EXE WRK_SSLVLIB:'E'.EXE/log
121$ SET FILE/PROT=W:RE WRK_SSLVLIB:'E'.EXE
122$ ENDIF
123$ IF F$SEARCH(AEXE_DIR+E+".OLB") .NES. ""
124$ THEN
125$ COPY 'AEXE_DIR''E'.OLB WRK_SSLALIB:'E'.OLB/log
126$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.OLB
127$ ENDIF
128$ ! Preparing for the time when we have shareable images
129$ IF F$SEARCH(AEXE_DIR+E+".EXE") .NES. ""
130$ THEN
131$ COPY 'AEXE_DIR''E'.EXE WRK_SSLALIB:'E'.EXE/log
132$ SET FILE/PROT=W:RE WRK_SSLALIB:'E'.EXE
133$ ENDIF
134$ SET ON
135$ GOTO LOOP_LIB
136$ LOOP_LIB_END:
137$
138$ EXIT
diff --git a/src/lib/libcrypto/krb5/Makefile b/src/lib/libcrypto/krb5/Makefile
new file mode 100644
index 0000000000..14077390d6
--- /dev/null
+++ b/src/lib/libcrypto/krb5/Makefile
@@ -0,0 +1,84 @@
1#
2# OpenSSL/krb5/Makefile
3#
4
5DIR= krb5
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile README
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= krb5_asn.c
21
22LIBOBJ= krb5_asn.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= krb5_asn.h
27HEADER= $(EXHEADER)
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41files:
42 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
43
44links:
45 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
46 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
47 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
48
49install:
50 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
51 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
52 do \
53 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
54 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
55 done;
56
57tags:
58 ctags $(SRC)
59
60tests:
61
62lint:
63 lint -DLINT $(INCLUDES) $(SRC)>fluff
64
65depend:
66 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
67 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
68
69dclean:
70 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
71 mv -f Makefile.new $(MAKEFILE)
72
73clean:
74 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78krb5_asn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
79krb5_asn.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
80krb5_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/krb5_asn.h
81krb5_asn.o: ../../include/openssl/opensslconf.h
82krb5_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
83krb5_asn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
84krb5_asn.o: ../../include/openssl/symhacks.h krb5_asn.c
diff --git a/src/lib/libcrypto/krb5/Makefile.ssl b/src/lib/libcrypto/krb5/Makefile.ssl
new file mode 100644
index 0000000000..d9224c0f09
--- /dev/null
+++ b/src/lib/libcrypto/krb5/Makefile.ssl
@@ -0,0 +1,90 @@
1#
2# OpenSSL/krb5/Makefile.ssl
3#
4
5DIR= krb5
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= krb5_asn.c
27
28LIBOBJ= krb5_asn.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= krb5_asn.h
33HEADER= $(EXHEADER)
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47files:
48 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
49
50links:
51 @sh $(TOP)/util/point.sh Makefile.ssl Makefile ;
52 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
53 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
54 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
55
56install:
57 @for i in $(EXHEADER) ; \
58 do \
59 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
60 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
61 done;
62
63tags:
64 ctags $(SRC)
65
66tests:
67
68lint:
69 lint -DLINT $(INCLUDES) $(SRC)>fluff
70
71depend:
72 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
73
74dclean:
75 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
76 mv -f Makefile.new $(MAKEFILE)
77
78clean:
79 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
80
81# DO NOT DELETE THIS LINE -- make depend depends on it.
82
83krb5_asn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
84krb5_asn.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
85krb5_asn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
86krb5_asn.o: ../../include/openssl/krb5_asn.h
87krb5_asn.o: ../../include/openssl/opensslconf.h
88krb5_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
89krb5_asn.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90krb5_asn.o: ../../include/openssl/symhacks.h krb5_asn.c
diff --git a/src/lib/libcrypto/krb5/krb5_asn.h b/src/lib/libcrypto/krb5/krb5_asn.h
index 41725d0dc4..3329477b07 100644
--- a/src/lib/libcrypto/krb5/krb5_asn.h
+++ b/src/lib/libcrypto/krb5/krb5_asn.h
@@ -225,7 +225,7 @@ DECLARE_STACK_OF(KRB5_AUTHENTBODY)
225** void name##_free(type *a); 225** void name##_free(type *a);
226** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) = 226** DECLARE_ASN1_ENCODE_FUNCTIONS(type, name, name) =
227** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) = 227** DECLARE_ASN1_ENCODE_FUNCTIONS(type, itname, name) =
228** type *d2i_##name(type **a, const unsigned char **in, long len); 228** type *d2i_##name(type **a, unsigned char **in, long len);
229** int i2d_##name(type *a, unsigned char **out); 229** int i2d_##name(type *a, unsigned char **out);
230** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it 230** DECLARE_ASN1_ITEM(itname) = OPENSSL_EXTERN const ASN1_ITEM itname##_it
231*/ 231*/
diff --git a/src/lib/libcrypto/lhash/Makefile b/src/lib/libcrypto/lhash/Makefile
new file mode 100644
index 0000000000..82bddac474
--- /dev/null
+++ b/src/lib/libcrypto/lhash/Makefile
@@ -0,0 +1,88 @@
1#
2# OpenSSL/crypto/lhash/Makefile
3#
4
5DIR= lhash
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=lhash.c lh_stats.c
21LIBOBJ=lhash.o lh_stats.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= lhash.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77lh_stats.o: ../../e_os.h ../../include/openssl/bio.h
78lh_stats.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
79lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
81lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
82lh_stats.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
83lh_stats.o: ../../include/openssl/symhacks.h ../cryptlib.h lh_stats.c
84lhash.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
85lhash.o: ../../include/openssl/e_os2.h ../../include/openssl/lhash.h
86lhash.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
87lhash.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
88lhash.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h lhash.c
diff --git a/src/lib/libcrypto/lhash/Makefile.ssl b/src/lib/libcrypto/lhash/Makefile.ssl
new file mode 100644
index 0000000000..60e7ee3393
--- /dev/null
+++ b/src/lib/libcrypto/lhash/Makefile.ssl
@@ -0,0 +1,93 @@
1#
2# SSLeay/crypto/lhash/Makefile
3#
4
5DIR= lhash
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=lhash.c lh_stats.c
27LIBOBJ=lhash.o lh_stats.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= lhash.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82lh_stats.o: ../../e_os.h ../../include/openssl/bio.h
83lh_stats.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84lh_stats.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85lh_stats.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
86lh_stats.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87lh_stats.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88lh_stats.o: ../cryptlib.h lh_stats.c
89lhash.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
90lhash.o: ../../include/openssl/e_os2.h ../../include/openssl/lhash.h
91lhash.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
92lhash.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
93lhash.o: ../../include/openssl/symhacks.h lhash.c
diff --git a/src/lib/libcrypto/lhash/lh_test.c b/src/lib/libcrypto/lhash/lh_test.c
new file mode 100644
index 0000000000..85700c859b
--- /dev/null
+++ b/src/lib/libcrypto/lhash/lh_test.c
@@ -0,0 +1,88 @@
1/* crypto/lhash/lh_test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/lhash.h>
63
64main()
65 {
66 LHASH *conf;
67 char buf[256];
68 int i;
69
70 conf=lh_new(lh_strhash,strcmp);
71 for (;;)
72 {
73 char *p;
74
75 buf[0]='\0';
76 fgets(buf,256,stdin);
77 if (buf[0] == '\0') break;
78 i=strlen(buf);
79 p=OPENSSL_malloc(i+1);
80 memcpy(p,buf,i+1);
81 lh_insert(conf,p);
82 }
83
84 lh_node_stats(conf,stdout);
85 lh_stats(conf,stdout);
86 lh_node_usage_stats(conf,stdout);
87 exit(0);
88 }
diff --git a/src/lib/libcrypto/lhash/lhash.c b/src/lib/libcrypto/lhash/lhash.c
index 04ea80203c..0a16fcf27d 100644
--- a/src/lib/libcrypto/lhash/lhash.c
+++ b/src/lib/libcrypto/lhash/lhash.c
@@ -100,7 +100,7 @@
100#include <openssl/crypto.h> 100#include <openssl/crypto.h>
101#include <openssl/lhash.h> 101#include <openssl/lhash.h>
102 102
103const char lh_version[]="lhash" OPENSSL_VERSION_PTEXT; 103const char *lh_version="lhash" OPENSSL_VERSION_PTEXT;
104 104
105#undef MIN_NODES 105#undef MIN_NODES
106#define MIN_NODES 16 106#define MIN_NODES 16
@@ -176,11 +176,11 @@ void lh_free(LHASH *lh)
176 OPENSSL_free(lh); 176 OPENSSL_free(lh);
177 } 177 }
178 178
179void *lh_insert(LHASH *lh, void *data) 179void *lh_insert(LHASH *lh, const void *data)
180 { 180 {
181 unsigned long hash; 181 unsigned long hash;
182 LHASH_NODE *nn,**rn; 182 LHASH_NODE *nn,**rn;
183 void *ret; 183 const void *ret;
184 184
185 lh->error=0; 185 lh->error=0;
186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)) 186 if (lh->up_load <= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))
@@ -211,14 +211,14 @@ void *lh_insert(LHASH *lh, void *data)
211 (*rn)->data=data; 211 (*rn)->data=data;
212 lh->num_replace++; 212 lh->num_replace++;
213 } 213 }
214 return(ret); 214 return((void *)ret);
215 } 215 }
216 216
217void *lh_delete(LHASH *lh, const void *data) 217void *lh_delete(LHASH *lh, const void *data)
218 { 218 {
219 unsigned long hash; 219 unsigned long hash;
220 LHASH_NODE *nn,**rn; 220 LHASH_NODE *nn,**rn;
221 void *ret; 221 const void *ret;
222 222
223 lh->error=0; 223 lh->error=0;
224 rn=getrn(lh,data,&hash); 224 rn=getrn(lh,data,&hash);
@@ -242,14 +242,14 @@ void *lh_delete(LHASH *lh, const void *data)
242 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes))) 242 (lh->down_load >= (lh->num_items*LH_LOAD_MULT/lh->num_nodes)))
243 contract(lh); 243 contract(lh);
244 244
245 return(ret); 245 return((void *)ret);
246 } 246 }
247 247
248void *lh_retrieve(LHASH *lh, const void *data) 248void *lh_retrieve(LHASH *lh, const void *data)
249 { 249 {
250 unsigned long hash; 250 unsigned long hash;
251 LHASH_NODE **rn; 251 LHASH_NODE **rn;
252 void *ret; 252 const void *ret;
253 253
254 lh->error=0; 254 lh->error=0;
255 rn=getrn(lh,data,&hash); 255 rn=getrn(lh,data,&hash);
@@ -264,7 +264,7 @@ void *lh_retrieve(LHASH *lh, const void *data)
264 ret= (*rn)->data; 264 ret= (*rn)->data;
265 lh->num_retrieve++; 265 lh->num_retrieve++;
266 } 266 }
267 return(ret); 267 return((void *)ret);
268 } 268 }
269 269
270static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, 270static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func,
@@ -339,7 +339,7 @@ static void expand(LHASH *lh)
339 { 339 {
340 j=(int)lh->num_alloc_nodes*2; 340 j=(int)lh->num_alloc_nodes*2;
341 n=(LHASH_NODE **)OPENSSL_realloc(lh->b, 341 n=(LHASH_NODE **)OPENSSL_realloc(lh->b,
342 (int)(sizeof(LHASH_NODE *)*j)); 342 (unsigned int)sizeof(LHASH_NODE *)*j);
343 if (n == NULL) 343 if (n == NULL)
344 { 344 {
345/* fputs("realloc error in lhash",stderr); */ 345/* fputs("realloc error in lhash",stderr); */
@@ -401,7 +401,7 @@ static LHASH_NODE **getrn(LHASH *lh, const void *data, unsigned long *rhash)
401 { 401 {
402 LHASH_NODE **ret,*n1; 402 LHASH_NODE **ret,*n1;
403 unsigned long hash,nn; 403 unsigned long hash,nn;
404 LHASH_COMP_FN_TYPE cf; 404 int (*cf)();
405 405
406 hash=(*(lh->hash))(data); 406 hash=(*(lh->hash))(data);
407 lh->num_hash_calls++; 407 lh->num_hash_calls++;
diff --git a/src/lib/libcrypto/lhash/lhash.h b/src/lib/libcrypto/lhash/lhash.h
index d392d0cd80..dee8207333 100644
--- a/src/lib/libcrypto/lhash/lhash.h
+++ b/src/lib/libcrypto/lhash/lhash.h
@@ -63,7 +63,6 @@
63#ifndef HEADER_LHASH_H 63#ifndef HEADER_LHASH_H
64#define HEADER_LHASH_H 64#define HEADER_LHASH_H
65 65
66#include <openssl/e_os2.h>
67#ifndef OPENSSL_NO_FP_API 66#ifndef OPENSSL_NO_FP_API
68#include <stdio.h> 67#include <stdio.h>
69#endif 68#endif
@@ -78,7 +77,7 @@ extern "C" {
78 77
79typedef struct lhash_node_st 78typedef struct lhash_node_st
80 { 79 {
81 void *data; 80 const void *data;
82 struct lhash_node_st *next; 81 struct lhash_node_st *next;
83#ifndef OPENSSL_NO_HASH_COMP 82#ifndef OPENSSL_NO_HASH_COMP
84 unsigned long hash; 83 unsigned long hash;
@@ -87,8 +86,8 @@ typedef struct lhash_node_st
87 86
88typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *); 87typedef int (*LHASH_COMP_FN_TYPE)(const void *, const void *);
89typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *); 88typedef unsigned long (*LHASH_HASH_FN_TYPE)(const void *);
90typedef void (*LHASH_DOALL_FN_TYPE)(void *); 89typedef void (*LHASH_DOALL_FN_TYPE)(const void *);
91typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *); 90typedef void (*LHASH_DOALL_ARG_FN_TYPE)(const void *, void *);
92 91
93/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks. 92/* Macros for declaring and implementing type-safe wrappers for LHASH callbacks.
94 * This way, callbacks can be provided to LHASH structures without function 93 * This way, callbacks can be provided to LHASH structures without function
@@ -118,18 +117,18 @@ typedef void (*LHASH_DOALL_ARG_FN_TYPE)(void *, void *);
118 117
119/* Third: "doall" functions */ 118/* Third: "doall" functions */
120#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \ 119#define DECLARE_LHASH_DOALL_FN(f_name,o_type) \
121 void f_name##_LHASH_DOALL(void *); 120 void f_name##_LHASH_DOALL(const void *);
122#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \ 121#define IMPLEMENT_LHASH_DOALL_FN(f_name,o_type) \
123 void f_name##_LHASH_DOALL(void *arg) { \ 122 void f_name##_LHASH_DOALL(const void *arg) { \
124 o_type a = (o_type)arg; \ 123 o_type a = (o_type)arg; \
125 f_name(a); } 124 f_name(a); }
126#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL 125#define LHASH_DOALL_FN(f_name) f_name##_LHASH_DOALL
127 126
128/* Fourth: "doall_arg" functions */ 127/* Fourth: "doall_arg" functions */
129#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ 128#define DECLARE_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
130 void f_name##_LHASH_DOALL_ARG(void *, void *); 129 void f_name##_LHASH_DOALL_ARG(const void *, void *);
131#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \ 130#define IMPLEMENT_LHASH_DOALL_ARG_FN(f_name,o_type,a_type) \
132 void f_name##_LHASH_DOALL_ARG(void *arg1, void *arg2) { \ 131 void f_name##_LHASH_DOALL_ARG(const void *arg1, void *arg2) { \
133 o_type a = (o_type)arg1; \ 132 o_type a = (o_type)arg1; \
134 a_type b = (a_type)arg2; \ 133 a_type b = (a_type)arg2; \
135 f_name(a,b); } 134 f_name(a,b); }
@@ -173,7 +172,7 @@ typedef struct lhash_st
173 172
174LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c); 173LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c);
175void lh_free(LHASH *lh); 174void lh_free(LHASH *lh);
176void *lh_insert(LHASH *lh, void *data); 175void *lh_insert(LHASH *lh, const void *data);
177void *lh_delete(LHASH *lh, const void *data); 176void *lh_delete(LHASH *lh, const void *data);
178void *lh_retrieve(LHASH *lh, const void *data); 177void *lh_retrieve(LHASH *lh, const void *data);
179void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func); 178void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func);
diff --git a/src/lib/libcrypto/lhash/num.pl b/src/lib/libcrypto/lhash/num.pl
new file mode 100644
index 0000000000..30fedf9cd5
--- /dev/null
+++ b/src/lib/libcrypto/lhash/num.pl
@@ -0,0 +1,17 @@
1#!/usr/local/bin/perl
2
3#node 10 -> 4
4
5while (<>)
6 {
7 next unless /^node/;
8 chop;
9 @a=split;
10 $num{$a[3]}++;
11 }
12
13@a=sort {$a <=> $b } keys %num;
14foreach (0 .. $a[$#a])
15 {
16 printf "%4d:%4d\n",$_,$num{$_};
17 }
diff --git a/src/lib/libcrypto/md2/Makefile b/src/lib/libcrypto/md2/Makefile
new file mode 100644
index 0000000000..17f878aeb7
--- /dev/null
+++ b/src/lib/libcrypto/md2/Makefile
@@ -0,0 +1,89 @@
1#
2# OpenSSL/crypto/md/Makefile
3#
4
5DIR= md2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=md2test.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=md2_dgst.c md2_one.c
21LIBOBJ=md2_dgst.o md2_one.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= md2.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77md2_dgst.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
78md2_dgst.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
79md2_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
80md2_dgst.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
81md2_dgst.o: ../../include/openssl/symhacks.h md2_dgst.c
82md2_one.o: ../../e_os.h ../../include/openssl/bio.h
83md2_one.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85md2_one.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
86md2_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
87md2_one.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
88md2_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
89md2_one.o: ../cryptlib.h md2_one.c
diff --git a/src/lib/libcrypto/md2/Makefile.ssl b/src/lib/libcrypto/md2/Makefile.ssl
new file mode 100644
index 0000000000..3206924c90
--- /dev/null
+++ b/src/lib/libcrypto/md2/Makefile.ssl
@@ -0,0 +1,93 @@
1#
2# SSLeay/crypto/md/Makefile
3#
4
5DIR= md2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=md2test.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=md2_dgst.c md2_one.c
27LIBOBJ=md2_dgst.o md2_one.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= md2.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82md2_dgst.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
83md2_dgst.o: ../../include/openssl/md2.h ../../include/openssl/opensslconf.h
84md2_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
85md2_dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
86md2_dgst.o: md2_dgst.c
87md2_one.o: ../../e_os.h ../../include/openssl/bio.h
88md2_one.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89md2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
90md2_one.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
91md2_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
92md2_one.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
93md2_one.o: ../../include/openssl/symhacks.h ../cryptlib.h md2_one.c
diff --git a/src/lib/libcrypto/md2/md2.c b/src/lib/libcrypto/md2/md2.c
new file mode 100644
index 0000000000..f4d6f62264
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2.c
@@ -0,0 +1,124 @@
1/* crypto/md2/md2.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/md2.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67int read(int, void *, unsigned int);
68void exit(int);
69int main(int argc, char *argv[])
70 {
71 int i,err=0;
72 FILE *IN;
73
74 if (argc == 1)
75 {
76 do_fp(stdin);
77 }
78 else
79 {
80 for (i=1; i<argc; i++)
81 {
82 IN=fopen(argv[i],"r");
83 if (IN == NULL)
84 {
85 perror(argv[i]);
86 err++;
87 continue;
88 }
89 printf("MD2(%s)= ",argv[i]);
90 do_fp(IN);
91 fclose(IN);
92 }
93 }
94 exit(err);
95 return(err);
96 }
97
98void do_fp(FILE *f)
99 {
100 MD2_CTX c;
101 unsigned char md[MD2_DIGEST_LENGTH];
102 int fd,i;
103 static unsigned char buf[BUFSIZE];
104
105 fd=fileno(f);
106 MD2_Init(&c);
107 for (;;)
108 {
109 i=read(fd,buf,BUFSIZE);
110 if (i <= 0) break;
111 MD2_Update(&c,buf,(unsigned long)i);
112 }
113 MD2_Final(&(md[0]),&c);
114 pt(md);
115 }
116
117void pt(unsigned char *md)
118 {
119 int i;
120
121 for (i=0; i<MD2_DIGEST_LENGTH; i++)
122 printf("%02x",md[i]);
123 printf("\n");
124 }
diff --git a/src/lib/libcrypto/md2/md2.h b/src/lib/libcrypto/md2/md2.h
new file mode 100644
index 0000000000..d0ef9da08e
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2.h
@@ -0,0 +1,94 @@
1/* crypto/md/md2.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_MD2_H
60#define HEADER_MD2_H
61
62#ifdef OPENSSL_NO_MD2
63#error MD2 is disabled.
64#endif
65
66#define MD2_DIGEST_LENGTH 16
67#define MD2_BLOCK 16
68#include <openssl/opensslconf.h> /* MD2_INT */
69
70#ifdef __cplusplus
71extern "C" {
72#endif
73
74typedef struct MD2state_st
75 {
76 int num;
77 unsigned char data[MD2_BLOCK];
78 MD2_INT cksm[MD2_BLOCK];
79 MD2_INT state[MD2_BLOCK];
80 } MD2_CTX;
81
82const char *MD2_options(void);
83#ifdef OPENSSL_FIPS
84int private_MD2_Init(MD2_CTX *c);
85#endif
86int MD2_Init(MD2_CTX *c);
87int MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len);
88int MD2_Final(unsigned char *md, MD2_CTX *c);
89unsigned char *MD2(const unsigned char *d, unsigned long n,unsigned char *md);
90#ifdef __cplusplus
91}
92#endif
93
94#endif
diff --git a/src/lib/libcrypto/md2/md2_dgst.c b/src/lib/libcrypto/md2/md2_dgst.c
new file mode 100644
index 0000000000..8124acd687
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2_dgst.c
@@ -0,0 +1,229 @@
1/* crypto/md2/md2_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/md2.h>
63#include <openssl/opensslv.h>
64#include <openssl/crypto.h>
65#include <openssl/fips.h>
66#include <openssl/err.h>
67
68const char *MD2_version="MD2" OPENSSL_VERSION_PTEXT;
69
70/* Implemented from RFC1319 The MD2 Message-Digest Algorithm
71 */
72
73#define UCHAR unsigned char
74
75static void md2_block(MD2_CTX *c, const unsigned char *d);
76/* The magic S table - I have converted it to hex since it is
77 * basically just a random byte string. */
78static MD2_INT S[256]={
79 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01,
80 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13,
81 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C,
82 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA,
83 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16,
84 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12,
85 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49,
86 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A,
87 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F,
88 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21,
89 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27,
90 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03,
91 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1,
92 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6,
93 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6,
94 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1,
95 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20,
96 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02,
97 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6,
98 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F,
99 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A,
100 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26,
101 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09,
102 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52,
103 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA,
104 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A,
105 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D,
106 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39,
107 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4,
108 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A,
109 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A,
110 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14,
111 };
112
113const char *MD2_options(void)
114 {
115 if (sizeof(MD2_INT) == 1)
116 return("md2(char)");
117 else
118 return("md2(int)");
119 }
120
121FIPS_NON_FIPS_MD_Init(MD2)
122 {
123 c->num=0;
124 memset(c->state,0,sizeof c->state);
125 memset(c->cksm,0,sizeof c->cksm);
126 memset(c->data,0,sizeof c->data);
127 return 1;
128 }
129
130int MD2_Update(MD2_CTX *c, const unsigned char *data, unsigned long len)
131 {
132 register UCHAR *p;
133
134 if (len == 0) return 1;
135
136 p=c->data;
137 if (c->num != 0)
138 {
139 if ((c->num+len) >= MD2_BLOCK)
140 {
141 memcpy(&(p[c->num]),data,MD2_BLOCK-c->num);
142 md2_block(c,c->data);
143 data+=(MD2_BLOCK - c->num);
144 len-=(MD2_BLOCK - c->num);
145 c->num=0;
146 /* drop through and do the rest */
147 }
148 else
149 {
150 memcpy(&(p[c->num]),data,(int)len);
151 /* data+=len; */
152 c->num+=(int)len;
153 return 1;
154 }
155 }
156 /* we now can process the input data in blocks of MD2_BLOCK
157 * chars and save the leftovers to c->data. */
158 while (len >= MD2_BLOCK)
159 {
160 md2_block(c,data);
161 data+=MD2_BLOCK;
162 len-=MD2_BLOCK;
163 }
164 memcpy(p,data,(int)len);
165 c->num=(int)len;
166 return 1;
167 }
168
169static void md2_block(MD2_CTX *c, const unsigned char *d)
170 {
171 register MD2_INT t,*sp1,*sp2;
172 register int i,j;
173 MD2_INT state[48];
174
175 sp1=c->state;
176 sp2=c->cksm;
177 j=sp2[MD2_BLOCK-1];
178 for (i=0; i<16; i++)
179 {
180 state[i]=sp1[i];
181 state[i+16]=t=d[i];
182 state[i+32]=(t^sp1[i]);
183 j=sp2[i]^=S[t^j];
184 }
185 t=0;
186 for (i=0; i<18; i++)
187 {
188 for (j=0; j<48; j+=8)
189 {
190 t= state[j+ 0]^=S[t];
191 t= state[j+ 1]^=S[t];
192 t= state[j+ 2]^=S[t];
193 t= state[j+ 3]^=S[t];
194 t= state[j+ 4]^=S[t];
195 t= state[j+ 5]^=S[t];
196 t= state[j+ 6]^=S[t];
197 t= state[j+ 7]^=S[t];
198 }
199 t=(t+i)&0xff;
200 }
201 memcpy(sp1,state,16*sizeof(MD2_INT));
202 OPENSSL_cleanse(state,48*sizeof(MD2_INT));
203 }
204
205int MD2_Final(unsigned char *md, MD2_CTX *c)
206 {
207 int i,v;
208 register UCHAR *cp;
209 register MD2_INT *p1,*p2;
210
211 cp=c->data;
212 p1=c->state;
213 p2=c->cksm;
214 v=MD2_BLOCK-c->num;
215 for (i=c->num; i<MD2_BLOCK; i++)
216 cp[i]=(UCHAR)v;
217
218 md2_block(c,cp);
219
220 for (i=0; i<MD2_BLOCK; i++)
221 cp[i]=(UCHAR)p2[i];
222 md2_block(c,cp);
223
224 for (i=0; i<16; i++)
225 md[i]=(UCHAR)(p1[i]&0xff);
226 memset((char *)&c,0,sizeof(c));
227 return 1;
228 }
229
diff --git a/src/lib/libcrypto/md2/md2_one.c b/src/lib/libcrypto/md2/md2_one.c
new file mode 100644
index 0000000000..8c36ba5779
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2_one.c
@@ -0,0 +1,94 @@
1/* crypto/md2/md2_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/md2.h>
62
63/* This is a separate file so that #defines in cryptlib.h can
64 * map my MD functions to different names */
65
66unsigned char *MD2(const unsigned char *d, unsigned long n, unsigned char *md)
67 {
68 MD2_CTX c;
69 static unsigned char m[MD2_DIGEST_LENGTH];
70
71 if (md == NULL) md=m;
72 if (!MD2_Init(&c))
73 return NULL;
74#ifndef CHARSET_EBCDIC
75 MD2_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 MD2_Update(&c,temp,chunk);
86 n -= chunk;
87 d += chunk;
88 }
89 }
90#endif
91 MD2_Final(md,&c);
92 OPENSSL_cleanse(&c,sizeof(c)); /* Security consideration */
93 return(md);
94 }
diff --git a/src/lib/libcrypto/md2/md2test.c b/src/lib/libcrypto/md2/md2test.c
new file mode 100644
index 0000000000..9c1e28b6ce
--- /dev/null
+++ b/src/lib/libcrypto/md2/md2test.c
@@ -0,0 +1,139 @@
1/* crypto/md2/md2test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_MD2
66int main(int argc, char *argv[])
67{
68 printf("No MD2 support\n");
69 return(0);
70}
71#else
72#include <openssl/evp.h>
73#include <openssl/md2.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
78
79static char *test[]={
80 "",
81 "a",
82 "abc",
83 "message digest",
84 "abcdefghijklmnopqrstuvwxyz",
85 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
86 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
87 NULL,
88 };
89
90static char *ret[]={
91 "8350e5a3e24c153df2275c9f80692773",
92 "32ec01ec4a6dac72c0ab96fb34c0b5d1",
93 "da853b0d3f88d99b30283a69e6ded6bb",
94 "ab4f496bfb2a530b219ff33031fe06b0",
95 "4e8ddff3650292ab5a4108c3aa47940b",
96 "da33def2a42df13975352846c30338cd",
97 "d5976f79d83d3a0dc9806c3c66f3efd8",
98 };
99
100static char *pt(unsigned char *md);
101int main(int argc, char *argv[])
102 {
103 int i,err=0;
104 char **P,**R;
105 char *p;
106 unsigned char md[MD2_DIGEST_LENGTH];
107
108 P=test;
109 R=ret;
110 i=1;
111 while (*P != NULL)
112 {
113 EVP_Digest((unsigned char *)*P,(unsigned long)strlen(*P),md,NULL,EVP_md2(), NULL);
114 p=pt(md);
115 if (strcmp(p,*R) != 0)
116 {
117 printf("error calculating MD2 on '%s'\n",*P);
118 printf("got %s instead of %s\n",p,*R);
119 err++;
120 }
121 else
122 printf("test %d ok\n",i);
123 i++;
124 R++;
125 P++;
126 }
127 EXIT(err);
128 }
129
130static char *pt(unsigned char *md)
131 {
132 int i;
133 static char buf[80];
134
135 for (i=0; i<MD2_DIGEST_LENGTH; i++)
136 sprintf(&(buf[i*2]),"%02x",md[i]);
137 return(buf);
138 }
139#endif
diff --git a/src/lib/libcrypto/md32_common.h b/src/lib/libcrypto/md32_common.h
index 089c450290..733da6acaf 100644
--- a/src/lib/libcrypto/md32_common.h
+++ b/src/lib/libcrypto/md32_common.h
@@ -1,6 +1,6 @@
1/* crypto/md32_common.h */ 1/* crypto/md32_common.h */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -47,6 +47,10 @@
47 * OF THE POSSIBILITY OF SUCH DAMAGE. 47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ==================================================================== 48 * ====================================================================
49 * 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 *
50 */ 54 */
51 55
52/* 56/*
@@ -72,27 +76,40 @@
72 * typedef struct { 76 * typedef struct {
73 * ... 77 * ...
74 * HASH_LONG Nl,Nh; 78 * HASH_LONG Nl,Nh;
75 * either {
76 * HASH_LONG data[HASH_LBLOCK]; 79 * HASH_LONG data[HASH_LBLOCK];
77 * unsigned char data[HASH_CBLOCK]; 80 * int num;
78 * };
79 * unsigned int num;
80 * ... 81 * ...
81 * } HASH_CTX; 82 * } HASH_CTX;
82 * data[] vector is expected to be zeroed upon first call to
83 * HASH_UPDATE.
84 * HASH_UPDATE 83 * HASH_UPDATE
85 * name of "Update" function, implemented here. 84 * name of "Update" function, implemented here.
86 * HASH_TRANSFORM 85 * HASH_TRANSFORM
87 * name of "Transform" function, implemented here. 86 * name of "Transform" function, implemented here.
88 * HASH_FINAL 87 * HASH_FINAL
89 * name of "Final" function, implemented here. 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.
90 * HASH_BLOCK_DATA_ORDER 92 * HASH_BLOCK_DATA_ORDER
91 * name of "block" function capable of treating *unaligned* input 93 * name of "block" function treating *unaligned* input message
92 * message in original (data) byte order, implemented externally. 94 * in original (data) byte order, implemented externally (it
95 * actually is optional if data and host are of the same
96 * "endianess").
93 * HASH_MAKE_STRING 97 * HASH_MAKE_STRING
94 * macro convering context variables to an ASCII hash string. 98 * macro convering context variables to an ASCII hash string.
95 * 99 *
100 * Optional macros:
101 *
102 * B_ENDIAN or L_ENDIAN
103 * defines host byte-order.
104 * HASH_LONG_LOG2
105 * defaults to 2 if not states otherwise.
106 * HASH_LBLOCK
107 * assumed to be HASH_CBLOCK/4 if not stated otherwise.
108 * HASH_BLOCK_DATA_ORDER_ALIGNED
109 * alternative "block" function capable of treating
110 * aligned input message in original (data) order,
111 * implemented externally.
112 *
96 * MD5 example: 113 * MD5 example:
97 * 114 *
98 * #define DATA_ORDER_IS_LITTLE_ENDIAN 115 * #define DATA_ORDER_IS_LITTLE_ENDIAN
@@ -101,14 +118,20 @@
101 * #define HASH_LONG_LOG2 MD5_LONG_LOG2 118 * #define HASH_LONG_LOG2 MD5_LONG_LOG2
102 * #define HASH_CTX MD5_CTX 119 * #define HASH_CTX MD5_CTX
103 * #define HASH_CBLOCK MD5_CBLOCK 120 * #define HASH_CBLOCK MD5_CBLOCK
121 * #define HASH_LBLOCK MD5_LBLOCK
104 * #define HASH_UPDATE MD5_Update 122 * #define HASH_UPDATE MD5_Update
105 * #define HASH_TRANSFORM MD5_Transform 123 * #define HASH_TRANSFORM MD5_Transform
106 * #define HASH_FINAL MD5_Final 124 * #define HASH_FINAL MD5_Final
125 * #define HASH_BLOCK_HOST_ORDER md5_block_host_order
107 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order 126 * #define HASH_BLOCK_DATA_ORDER md5_block_data_order
108 * 127 *
109 * <appro@fy.chalmers.se> 128 * <appro@fy.chalmers.se>
110 */ 129 */
111 130
131#include <openssl/crypto.h>
132#include <openssl/fips.h>
133#include <openssl/err.h>
134
112#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN) 135#if !defined(DATA_ORDER_IS_BIG_ENDIAN) && !defined(DATA_ORDER_IS_LITTLE_ENDIAN)
113#error "DATA_ORDER must be defined!" 136#error "DATA_ORDER must be defined!"
114#endif 137#endif
@@ -133,16 +156,34 @@
133#error "HASH_FINAL must be defined!" 156#error "HASH_FINAL must be defined!"
134#endif 157#endif
135 158
159#ifndef HASH_BLOCK_HOST_ORDER
160#error "HASH_BLOCK_HOST_ORDER must be defined!"
161#endif
162
163#if 0
164/*
165 * Moved below as it's required only if HASH_BLOCK_DATA_ORDER_ALIGNED
166 * isn't defined.
167 */
136#ifndef HASH_BLOCK_DATA_ORDER 168#ifndef HASH_BLOCK_DATA_ORDER
137#error "HASH_BLOCK_DATA_ORDER must be defined!" 169#error "HASH_BLOCK_DATA_ORDER must be defined!"
138#endif 170#endif
171#endif
172
173#ifndef HASH_LBLOCK
174#define HASH_LBLOCK (HASH_CBLOCK/4)
175#endif
176
177#ifndef HASH_LONG_LOG2
178#define HASH_LONG_LOG2 2
179#endif
139 180
140/* 181/*
141 * Engage compiler specific rotate intrinsic function if available. 182 * Engage compiler specific rotate intrinsic function if available.
142 */ 183 */
143#undef ROTATE 184#undef ROTATE
144#ifndef PEDANTIC 185#ifndef PEDANTIC
145# if defined(_MSC_VER) || defined(__ICC) 186# if 0 /* defined(_MSC_VER) */
146# define ROTATE(a,n) _lrotl(a,n) 187# define ROTATE(a,n) _lrotl(a,n)
147# elif defined(__MWERKS__) 188# elif defined(__MWERKS__)
148# if defined(__POWERPC__) 189# if defined(__POWERPC__)
@@ -158,6 +199,7 @@
158 * Some GNU C inline assembler templates. Note that these are 199 * Some GNU C inline assembler templates. Note that these are
159 * rotates by *constant* number of bits! But that's exactly 200 * rotates by *constant* number of bits! But that's exactly
160 * what we need here... 201 * what we need here...
202 *
161 * <appro@fy.chalmers.se> 203 * <appro@fy.chalmers.se>
162 */ 204 */
163# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) 205# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
@@ -169,8 +211,7 @@
169 : "cc"); \ 211 : "cc"); \
170 ret; \ 212 ret; \
171 }) 213 })
172# elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \ 214# elif defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
173 defined(__powerpc) || defined(__ppc__) || defined(__powerpc64__)
174# define ROTATE(a,n) ({ register unsigned int ret; \ 215# define ROTATE(a,n) ({ register unsigned int ret; \
175 asm ( \ 216 asm ( \
176 "rlwinm %0,%1,%2,0,31" \ 217 "rlwinm %0,%1,%2,0,31" \
@@ -178,100 +219,194 @@
178 : "r"(a), "I"(n)); \ 219 : "r"(a), "I"(n)); \
179 ret; \ 220 ret; \
180 }) 221 })
181# elif defined(__s390x__) 222# endif
182# define ROTATE(a,n) ({ register unsigned int ret; \ 223# endif
183 asm ("rll %0,%1,%2" \ 224
184 : "=r"(ret) \ 225/*
185 : "r"(a), "I"(n)); \ 226 * Engage compiler specific "fetch in reverse byte order"
186 ret; \ 227 * intrinsic function if available.
228 */
229# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
230 /* some GNU C inline assembler templates by <appro@fy.chalmers.se> */
231# if (defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)) && !defined(I386_ONLY)
232# define BE_FETCH32(a) ({ register unsigned int l=(a);\
233 asm ( \
234 "bswapl %0" \
235 : "=r"(l) : "0"(l)); \
236 l; \
237 })
238# elif defined(__powerpc)
239# define LE_FETCH32(a) ({ register unsigned int l; \
240 asm ( \
241 "lwbrx %0,0,%1" \
242 : "=r"(l) \
243 : "r"(a)); \
244 l; \
245 })
246
247# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC)
248# define LE_FETCH32(a) ({ register unsigned int l; \
249 asm ( \
250 "lda [%1]#ASI_PRIMARY_LITTLE,%0"\
251 : "=r"(l) \
252 : "r"(a)); \
253 l; \
187 }) 254 })
188# endif 255# endif
189# endif 256# endif
190#endif /* PEDANTIC */ 257#endif /* PEDANTIC */
191 258
259#if HASH_LONG_LOG2==2 /* Engage only if sizeof(HASH_LONG)== 4 */
260/* A nice byte order reversal from Wei Dai <weidai@eskimo.com> */
261#ifdef ROTATE
262/* 5 instructions with rotate instruction, else 9 */
263#define REVERSE_FETCH32(a,l) ( \
264 l=*(const HASH_LONG *)(a), \
265 ((ROTATE(l,8)&0x00FF00FF)|(ROTATE((l&0x00FF00FF),24))) \
266 )
267#else
268/* 6 instructions with rotate instruction, else 8 */
269#define REVERSE_FETCH32(a,l) ( \
270 l=*(const HASH_LONG *)(a), \
271 l=(((l>>8)&0x00FF00FF)|((l&0x00FF00FF)<<8)), \
272 ROTATE(l,16) \
273 )
274/*
275 * Originally the middle line started with l=(((l&0xFF00FF00)>>8)|...
276 * It's rewritten as above for two reasons:
277 * - RISCs aren't good at long constants and have to explicitely
278 * compose 'em with several (well, usually 2) instructions in a
279 * register before performing the actual operation and (as you
280 * already realized:-) having same constant should inspire the
281 * compiler to permanently allocate the only register for it;
282 * - most modern CPUs have two ALUs, but usually only one has
283 * circuitry for shifts:-( this minor tweak inspires compiler
284 * to schedule shift instructions in a better way...
285 *
286 * <appro@fy.chalmers.se>
287 */
288#endif
289#endif
290
192#ifndef ROTATE 291#ifndef ROTATE
193#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n)))) 292#define ROTATE(a,n) (((a)<<(n))|(((a)&0xffffffff)>>(32-(n))))
194#endif 293#endif
195 294
196#if defined(DATA_ORDER_IS_BIG_ENDIAN) 295/*
197 296 * Make some obvious choices. E.g., HASH_BLOCK_DATA_ORDER_ALIGNED
198#ifndef PEDANTIC 297 * and HASH_BLOCK_HOST_ORDER ought to be the same if input data
199# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) 298 * and host are of the same "endianess". It's possible to mask
200# if ((defined(__i386) || defined(__i386__)) && !defined(I386_ONLY)) || \ 299 * this with blank #define HASH_BLOCK_DATA_ORDER though...
201 (defined(__x86_64) || defined(__x86_64__)) 300 *
202# if !defined(B_ENDIAN) 301 * <appro@fy.chalmers.se>
203 /* 302 */
204 * This gives ~30-40% performance improvement in SHA-256 compiled 303#if defined(B_ENDIAN)
205 * with gcc [on P4]. Well, first macro to be frank. We can pull 304# if defined(DATA_ORDER_IS_BIG_ENDIAN)
206 * this trick on x86* platforms only, because these CPUs can fetch 305# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
207 * unaligned data without raising an exception. 306# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
208 */ 307# endif
209# define HOST_c2l(c,l) ({ unsigned int r=*((const unsigned int *)(c)); \ 308# elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
210 asm ("bswapl %0":"=r"(r):"0"(r)); \ 309# ifndef HOST_FETCH32
211 (c)+=4; (l)=r; }) 310# ifdef LE_FETCH32
212# define HOST_l2c(l,c) ({ unsigned int r=(l); \ 311# define HOST_FETCH32(p,l) LE_FETCH32(p)
213 asm ("bswapl %0":"=r"(r):"0"(r)); \ 312# elif defined(REVERSE_FETCH32)
214 *((unsigned int *)(c))=r; (c)+=4; r; }) 313# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
215# endif 314# endif
315# endif
216# endif 316# endif
217# endif 317#elif defined(L_ENDIAN)
318# if defined(DATA_ORDER_IS_LITTLE_ENDIAN)
319# if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED) && HASH_LONG_LOG2==2
320# define HASH_BLOCK_DATA_ORDER_ALIGNED HASH_BLOCK_HOST_ORDER
321# endif
322# elif defined(DATA_ORDER_IS_BIG_ENDIAN)
323# ifndef HOST_FETCH32
324# ifdef BE_FETCH32
325# define HOST_FETCH32(p,l) BE_FETCH32(p)
326# elif defined(REVERSE_FETCH32)
327# define HOST_FETCH32(p,l) REVERSE_FETCH32(p,l)
328# endif
329# endif
330# endif
331#endif
332
333#if !defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
334#ifndef HASH_BLOCK_DATA_ORDER
335#error "HASH_BLOCK_DATA_ORDER must be defined!"
218#endif 336#endif
219#if defined(__s390__) || defined(__s390x__)
220# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, (l))
221# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, (l))
222#endif 337#endif
223 338
224#ifndef HOST_c2l 339#if defined(DATA_ORDER_IS_BIG_ENDIAN)
340
225#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \ 341#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++)))<<24), \
226 l|=(((unsigned long)(*((c)++)))<<16), \ 342 l|=(((unsigned long)(*((c)++)))<<16), \
227 l|=(((unsigned long)(*((c)++)))<< 8), \ 343 l|=(((unsigned long)(*((c)++)))<< 8), \
228 l|=(((unsigned long)(*((c)++))) ), \ 344 l|=(((unsigned long)(*((c)++))) ), \
229 l) 345 l)
230#endif 346#define HOST_p_c2l(c,l,n) { \
231#ifndef HOST_l2c 347 switch (n) { \
348 case 0: l =((unsigned long)(*((c)++)))<<24; \
349 case 1: l|=((unsigned long)(*((c)++)))<<16; \
350 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
351 case 3: l|=((unsigned long)(*((c)++))); \
352 } }
353#define HOST_p_c2l_p(c,l,sc,len) { \
354 switch (sc) { \
355 case 0: l =((unsigned long)(*((c)++)))<<24; \
356 if (--len == 0) break; \
357 case 1: l|=((unsigned long)(*((c)++)))<<16; \
358 if (--len == 0) break; \
359 case 2: l|=((unsigned long)(*((c)++)))<< 8; \
360 } }
361/* NOTE the pointer is not incremented at the end of this */
362#define HOST_c2l_p(c,l,n) { \
363 l=0; (c)+=n; \
364 switch (n) { \
365 case 3: l =((unsigned long)(*(--(c))))<< 8; \
366 case 2: l|=((unsigned long)(*(--(c))))<<16; \
367 case 1: l|=((unsigned long)(*(--(c))))<<24; \
368 } }
232#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \ 369#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l)>>24)&0xff), \
233 *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 370 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
234 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 371 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
235 *((c)++)=(unsigned char)(((l) )&0xff), \ 372 *((c)++)=(unsigned char)(((l) )&0xff), \
236 l) 373 l)
237#endif
238 374
239#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) 375#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
240 376
241#ifndef PEDANTIC
242# if defined(__GNUC__) && __GNUC__>=2 && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM)
243# if defined(__s390x__)
244# define HOST_c2l(c,l) ({ asm ("lrv %0,0(%1)" \
245 :"=r"(l) : "r"(c)); \
246 (c)+=4; (l); })
247# define HOST_l2c(l,c) ({ asm ("strv %0,0(%1)" \
248 : : "r"(l),"r"(c) : "memory"); \
249 (c)+=4; (l); })
250# endif
251# endif
252#endif
253#if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
254# ifndef B_ENDIAN
255 /* See comment in DATA_ORDER_IS_BIG_ENDIAN section. */
256# define HOST_c2l(c,l) ((l)=*((const unsigned int *)(c)), (c)+=4, l)
257# define HOST_l2c(l,c) (*((unsigned int *)(c))=(l), (c)+=4, l)
258# endif
259#endif
260
261#ifndef HOST_c2l
262#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \ 377#define HOST_c2l(c,l) (l =(((unsigned long)(*((c)++))) ), \
263 l|=(((unsigned long)(*((c)++)))<< 8), \ 378 l|=(((unsigned long)(*((c)++)))<< 8), \
264 l|=(((unsigned long)(*((c)++)))<<16), \ 379 l|=(((unsigned long)(*((c)++)))<<16), \
265 l|=(((unsigned long)(*((c)++)))<<24), \ 380 l|=(((unsigned long)(*((c)++)))<<24), \
266 l) 381 l)
267#endif 382#define HOST_p_c2l(c,l,n) { \
268#ifndef HOST_l2c 383 switch (n) { \
384 case 0: l =((unsigned long)(*((c)++))); \
385 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
386 case 2: l|=((unsigned long)(*((c)++)))<<16; \
387 case 3: l|=((unsigned long)(*((c)++)))<<24; \
388 } }
389#define HOST_p_c2l_p(c,l,sc,len) { \
390 switch (sc) { \
391 case 0: l =((unsigned long)(*((c)++))); \
392 if (--len == 0) break; \
393 case 1: l|=((unsigned long)(*((c)++)))<< 8; \
394 if (--len == 0) break; \
395 case 2: l|=((unsigned long)(*((c)++)))<<16; \
396 } }
397/* NOTE the pointer is not incremented at the end of this */
398#define HOST_c2l_p(c,l,n) { \
399 l=0; (c)+=n; \
400 switch (n) { \
401 case 3: l =((unsigned long)(*(--(c))))<<16; \
402 case 2: l|=((unsigned long)(*(--(c))))<< 8; \
403 case 1: l|=((unsigned long)(*(--(c)))); \
404 } }
269#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ 405#define HOST_l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
270 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \ 406 *((c)++)=(unsigned char)(((l)>> 8)&0xff), \
271 *((c)++)=(unsigned char)(((l)>>16)&0xff), \ 407 *((c)++)=(unsigned char)(((l)>>16)&0xff), \
272 *((c)++)=(unsigned char)(((l)>>24)&0xff), \ 408 *((c)++)=(unsigned char)(((l)>>24)&0xff), \
273 l) 409 l)
274#endif
275 410
276#endif 411#endif
277 412
@@ -279,60 +414,118 @@
279 * Time for some action:-) 414 * Time for some action:-)
280 */ 415 */
281 416
282int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len) 417int HASH_UPDATE (HASH_CTX *c, const void *data_, unsigned long len)
283 { 418 {
284 const unsigned char *data=data_; 419 const unsigned char *data=data_;
285 unsigned char *p; 420 register HASH_LONG * p;
286 HASH_LONG l; 421 register unsigned long l;
287 size_t n; 422 int sw,sc,ew,ec;
288 423
289 if (len==0) return 1; 424 if (len==0) return 1;
290 425
291 l=(c->Nl+(((HASH_LONG)len)<<3))&0xffffffffUL; 426 l=(c->Nl+(len<<3))&0xffffffffL;
292 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to 427 /* 95-05-24 eay Fixed a bug with the overflow handling, thanks to
293 * Wei Dai <weidai@eskimo.com> for pointing it out. */ 428 * Wei Dai <weidai@eskimo.com> for pointing it out. */
294 if (l < c->Nl) /* overflow */ 429 if (l < c->Nl) /* overflow */
295 c->Nh++; 430 c->Nh++;
296 c->Nh+=(len>>29); /* might cause compiler warning on 16-bit */ 431 c->Nh+=(len>>29);
297 c->Nl=l; 432 c->Nl=l;
298 433
299 n = c->num; 434 if (c->num != 0)
300 if (n != 0)
301 { 435 {
302 p=(unsigned char *)c->data; 436 p=c->data;
437 sw=c->num>>2;
438 sc=c->num&0x03;
303 439
304 if ((n+len) >= HASH_CBLOCK) 440 if ((c->num+len) >= HASH_CBLOCK)
305 { 441 {
306 memcpy (p+n,data,HASH_CBLOCK-n); 442 l=p[sw]; HOST_p_c2l(data,l,sc); p[sw++]=l;
307 HASH_BLOCK_DATA_ORDER (c,p,1); 443 for (; sw<HASH_LBLOCK; sw++)
308 n = HASH_CBLOCK-n; 444 {
309 data += n; 445 HOST_c2l(data,l); p[sw]=l;
310 len -= n; 446 }
311 c->num = 0; 447 HASH_BLOCK_HOST_ORDER (c,p,1);
312 memset (p,0,HASH_CBLOCK); /* keep it zeroed */ 448 len-=(HASH_CBLOCK-c->num);
449 c->num=0;
450 /* drop through and do the rest */
313 } 451 }
314 else 452 else
315 { 453 {
316 memcpy (p+n,data,len); 454 c->num+=len;
317 c->num += (unsigned int)len; 455 if ((sc+len) < 4) /* ugly, add char's to a word */
456 {
457 l=p[sw]; HOST_p_c2l_p(data,l,sc,len); p[sw]=l;
458 }
459 else
460 {
461 ew=(c->num>>2);
462 ec=(c->num&0x03);
463 if (sc)
464 l=p[sw];
465 HOST_p_c2l(data,l,sc);
466 p[sw++]=l;
467 for (; sw < ew; sw++)
468 {
469 HOST_c2l(data,l); p[sw]=l;
470 }
471 if (ec)
472 {
473 HOST_c2l_p(data,l,ec); p[sw]=l;
474 }
475 }
318 return 1; 476 return 1;
319 } 477 }
320 } 478 }
321 479
322 n = len/HASH_CBLOCK; 480 sw=len/HASH_CBLOCK;
323 if (n > 0) 481 if (sw > 0)
324 { 482 {
325 HASH_BLOCK_DATA_ORDER (c,data,n); 483#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
326 n *= HASH_CBLOCK; 484 /*
327 data += n; 485 * Note that HASH_BLOCK_DATA_ORDER_ALIGNED gets defined
328 len -= n; 486 * only if sizeof(HASH_LONG)==4.
487 */
488 if ((((unsigned long)data)%4) == 0)
489 {
490 /* data is properly aligned so that we can cast it: */
491 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,sw);
492 sw*=HASH_CBLOCK;
493 data+=sw;
494 len-=sw;
495 }
496 else
497#if !defined(HASH_BLOCK_DATA_ORDER)
498 while (sw--)
499 {
500 memcpy (p=c->data,data,HASH_CBLOCK);
501 HASH_BLOCK_DATA_ORDER_ALIGNED(c,p,1);
502 data+=HASH_CBLOCK;
503 len-=HASH_CBLOCK;
504 }
505#endif
506#endif
507#if defined(HASH_BLOCK_DATA_ORDER)
508 {
509 HASH_BLOCK_DATA_ORDER(c,data,sw);
510 sw*=HASH_CBLOCK;
511 data+=sw;
512 len-=sw;
513 }
514#endif
329 } 515 }
330 516
331 if (len != 0) 517 if (len!=0)
332 { 518 {
333 p = (unsigned char *)c->data; 519 p = c->data;
334 c->num = len; 520 c->num = len;
335 memcpy (p,data,len); 521 ew=len>>2; /* words to copy */
522 ec=len&0x03;
523 for (; ew; ew--,p++)
524 {
525 HOST_c2l(data,l); *p=l;
526 }
527 HOST_c2l_p(data,l,ec);
528 *p=l;
336 } 529 }
337 return 1; 530 return 1;
338 } 531 }
@@ -340,38 +533,81 @@ int HASH_UPDATE (HASH_CTX *c, const void *data_, size_t len)
340 533
341void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data) 534void HASH_TRANSFORM (HASH_CTX *c, const unsigned char *data)
342 { 535 {
536#if defined(HASH_BLOCK_DATA_ORDER_ALIGNED)
537 if ((((unsigned long)data)%4) == 0)
538 /* data is properly aligned so that we can cast it: */
539 HASH_BLOCK_DATA_ORDER_ALIGNED (c,(HASH_LONG *)data,1);
540 else
541#if !defined(HASH_BLOCK_DATA_ORDER)
542 {
543 memcpy (c->data,data,HASH_CBLOCK);
544 HASH_BLOCK_DATA_ORDER_ALIGNED (c,c->data,1);
545 }
546#endif
547#endif
548#if defined(HASH_BLOCK_DATA_ORDER)
343 HASH_BLOCK_DATA_ORDER (c,data,1); 549 HASH_BLOCK_DATA_ORDER (c,data,1);
550#endif
344 } 551 }
345 552
346 553
347int HASH_FINAL (unsigned char *md, HASH_CTX *c) 554int HASH_FINAL (unsigned char *md, HASH_CTX *c)
348 { 555 {
349 unsigned char *p = (unsigned char *)c->data; 556 register HASH_LONG *p;
350 size_t n = c->num; 557 register unsigned long l;
558 register int i,j;
559 static const unsigned char end[4]={0x80,0x00,0x00,0x00};
560 const unsigned char *cp=end;
561
562#if 0
563 if(FIPS_mode() && !FIPS_md5_allowed())
564 {
565 FIPSerr(FIPS_F_HASH_FINAL,FIPS_R_NON_FIPS_METHOD);
566 return 0;
567 }
568#endif
351 569
352 p[n] = 0x80; /* there is always room for one */ 570 /* c->num should definitly have room for at least one more byte. */
353 n++; 571 p=c->data;
572 i=c->num>>2;
573 j=c->num&0x03;
574
575#if 0
576 /* purify often complains about the following line as an
577 * Uninitialized Memory Read. While this can be true, the
578 * following p_c2l macro will reset l when that case is true.
579 * This is because j&0x03 contains the number of 'valid' bytes
580 * already in p[i]. If and only if j&0x03 == 0, the UMR will
581 * occur but this is also the only time p_c2l will do
582 * l= *(cp++) instead of l|= *(cp++)
583 * Many thanks to Alex Tang <altitude@cic.net> for pickup this
584 * 'potential bug' */
585#ifdef PURIFY
586 if (j==0) p[i]=0; /* Yeah, but that's not the way to fix it:-) */
587#endif
588 l=p[i];
589#else
590 l = (j==0) ? 0 : p[i];
591#endif
592 HOST_p_c2l(cp,l,j); p[i++]=l; /* i is the next 'undefined word' */
354 593
355 if (n > (HASH_CBLOCK-8)) 594 if (i>(HASH_LBLOCK-2)) /* save room for Nl and Nh */
356 { 595 {
357 memset (p+n,0,HASH_CBLOCK-n); 596 if (i<HASH_LBLOCK) p[i]=0;
358 n=0; 597 HASH_BLOCK_HOST_ORDER (c,p,1);
359 HASH_BLOCK_DATA_ORDER (c,p,1); 598 i=0;
360 } 599 }
361 memset (p+n,0,HASH_CBLOCK-8-n); 600 for (; i<(HASH_LBLOCK-2); i++)
601 p[i]=0;
362 602
363 p += HASH_CBLOCK-8;
364#if defined(DATA_ORDER_IS_BIG_ENDIAN) 603#if defined(DATA_ORDER_IS_BIG_ENDIAN)
365 (void)HOST_l2c(c->Nh,p); 604 p[HASH_LBLOCK-2]=c->Nh;
366 (void)HOST_l2c(c->Nl,p); 605 p[HASH_LBLOCK-1]=c->Nl;
367#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN) 606#elif defined(DATA_ORDER_IS_LITTLE_ENDIAN)
368 (void)HOST_l2c(c->Nl,p); 607 p[HASH_LBLOCK-2]=c->Nl;
369 (void)HOST_l2c(c->Nh,p); 608 p[HASH_LBLOCK-1]=c->Nh;
370#endif 609#endif
371 p -= HASH_CBLOCK; 610 HASH_BLOCK_HOST_ORDER (c,p,1);
372 HASH_BLOCK_DATA_ORDER (c,p,1);
373 c->num=0;
374 memset (p,0,HASH_CBLOCK);
375 611
376#ifndef HASH_MAKE_STRING 612#ifndef HASH_MAKE_STRING
377#error "HASH_MAKE_STRING must be defined!" 613#error "HASH_MAKE_STRING must be defined!"
@@ -379,6 +615,11 @@ int HASH_FINAL (unsigned char *md, HASH_CTX *c)
379 HASH_MAKE_STRING(c,md); 615 HASH_MAKE_STRING(c,md);
380#endif 616#endif
381 617
618 c->num=0;
619 /* clear stuff, HASH_BLOCK may be leaving some stuff on the stack
620 * but I'm not worried :-)
621 OPENSSL_cleanse((void *)c,sizeof(HASH_CTX));
622 */
382 return 1; 623 return 1;
383 } 624 }
384 625
diff --git a/src/lib/libcrypto/md4/Makefile b/src/lib/libcrypto/md4/Makefile
new file mode 100644
index 0000000000..ef97bb0cbe
--- /dev/null
+++ b/src/lib/libcrypto/md4/Makefile
@@ -0,0 +1,86 @@
1#
2# OpenSSL/crypto/md4/Makefile
3#
4
5DIR= md4
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14CFLAGS= $(INCLUDES) $(CFLAG)
15
16GENERAL=Makefile
17TEST=md4test.c
18APPS=md4.c
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC=md4_dgst.c md4_one.c
22LIBOBJ=md4_dgst.o md4_one.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= md4.h
27HEADER= md4_locl.h $(EXHEADER)
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41files:
42 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
43
44links:
45 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
46 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
47 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
48
49install:
50 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
51 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
52 do \
53 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
54 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
55 done;
56
57tags:
58 ctags $(SRC)
59
60tests:
61
62lint:
63 lint -DLINT $(INCLUDES) $(SRC)>fluff
64
65depend:
66 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
67 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
68
69dclean:
70 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
71 mv -f Makefile.new $(MAKEFILE)
72
73clean:
74 rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78md4_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md4.h
79md4_dgst.o: ../../include/openssl/opensslconf.h
80md4_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md4_dgst.c
81md4_dgst.o: md4_locl.h
82md4_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
83md4_one.o: ../../include/openssl/md4.h ../../include/openssl/opensslconf.h
84md4_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
85md4_one.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
86md4_one.o: ../../include/openssl/symhacks.h md4_one.c
diff --git a/src/lib/libcrypto/md4/Makefile.ssl b/src/lib/libcrypto/md4/Makefile.ssl
new file mode 100644
index 0000000000..7d2e8d8d3b
--- /dev/null
+++ b/src/lib/libcrypto/md4/Makefile.ssl
@@ -0,0 +1,91 @@
1#
2# SSLeay/crypto/md4/Makefile
3#
4
5DIR= md4
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20CFLAGS= $(INCLUDES) $(CFLAG)
21
22GENERAL=Makefile
23TEST=md4test.c
24APPS=md4.c
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC=md4_dgst.c md4_one.c
28LIBOBJ=md4_dgst.o md4_one.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= md4.h
33HEADER= md4_locl.h $(EXHEADER)
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47files:
48 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
49
50links:
51 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
52 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
53 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
54 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
55
56install:
57 @for i in $(EXHEADER) ; \
58 do \
59 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
60 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
61 done;
62
63tags:
64 ctags $(SRC)
65
66tests:
67
68lint:
69 lint -DLINT $(INCLUDES) $(SRC)>fluff
70
71depend:
72 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
73
74dclean:
75 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
76 mv -f Makefile.new $(MAKEFILE)
77
78clean:
79 rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
80
81# DO NOT DELETE THIS LINE -- make depend depends on it.
82
83md4_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md4.h
84md4_dgst.o: ../../include/openssl/opensslconf.h
85md4_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md4_dgst.c
86md4_dgst.o: md4_locl.h
87md4_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88md4_one.o: ../../include/openssl/md4.h ../../include/openssl/opensslconf.h
89md4_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
90md4_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
91md4_one.o: md4_one.c
diff --git a/src/lib/libcrypto/md4/md4.c b/src/lib/libcrypto/md4/md4.c
new file mode 100644
index 0000000000..141415ad4d
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4.c
@@ -0,0 +1,127 @@
1/* crypto/md4/md4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/md4.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#if !defined(_OSD_POSIX) && !defined(__DJGPP__)
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("MD4(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 MD4_CTX c;
102 unsigned char md[MD4_DIGEST_LENGTH];
103 int fd;
104 int i;
105 static unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 MD4_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,sizeof buf);
112 if (i <= 0) break;
113 MD4_Update(&c,buf,(unsigned long)i);
114 }
115 MD4_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<MD4_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libcrypto/md4/md4.h b/src/lib/libcrypto/md4/md4.h
index 5598c93a4f..7e761efb62 100644
--- a/src/lib/libcrypto/md4/md4.h
+++ b/src/lib/libcrypto/md4/md4.h
@@ -60,7 +60,6 @@
60#define HEADER_MD4_H 60#define HEADER_MD4_H
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63#include <stddef.h>
64 63
65#ifdef __cplusplus 64#ifdef __cplusplus
66extern "C" { 65extern "C" {
@@ -102,13 +101,16 @@ typedef struct MD4state_st
102 MD4_LONG A,B,C,D; 101 MD4_LONG A,B,C,D;
103 MD4_LONG Nl,Nh; 102 MD4_LONG Nl,Nh;
104 MD4_LONG data[MD4_LBLOCK]; 103 MD4_LONG data[MD4_LBLOCK];
105 unsigned int num; 104 int num;
106 } MD4_CTX; 105 } MD4_CTX;
107 106
107#ifdef OPENSSL_FIPS
108int private_MD4_Init(MD4_CTX *c);
109#endif
108int MD4_Init(MD4_CTX *c); 110int MD4_Init(MD4_CTX *c);
109int MD4_Update(MD4_CTX *c, const void *data, size_t len); 111int MD4_Update(MD4_CTX *c, const void *data, unsigned long len);
110int MD4_Final(unsigned char *md, MD4_CTX *c); 112int MD4_Final(unsigned char *md, MD4_CTX *c);
111unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md); 113unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md);
112void MD4_Transform(MD4_CTX *c, const unsigned char *b); 114void MD4_Transform(MD4_CTX *c, const unsigned char *b);
113#ifdef __cplusplus 115#ifdef __cplusplus
114} 116}
diff --git a/src/lib/libcrypto/md4/md4_dgst.c b/src/lib/libcrypto/md4/md4_dgst.c
index cfef94af39..ee7cc72262 100644
--- a/src/lib/libcrypto/md4/md4_dgst.c
+++ b/src/lib/libcrypto/md4/md4_dgst.c
@@ -60,7 +60,7 @@
60#include "md4_locl.h" 60#include "md4_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT; 63const char *MD4_version="MD4" OPENSSL_VERSION_PTEXT;
64 64
65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm 65/* Implemented from RFC1186 The MD4 Message-Digest Algorithm
66 */ 66 */
@@ -70,7 +70,7 @@ const char MD4_version[]="MD4" OPENSSL_VERSION_PTEXT;
70#define INIT_DATA_C (unsigned long)0x98badcfeL 70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L 71#define INIT_DATA_D (unsigned long)0x10325476L
72 72
73int MD4_Init(MD4_CTX *c) 73FIPS_NON_FIPS_MD_Init(MD4)
74 { 74 {
75 c->A=INIT_DATA_A; 75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B; 76 c->B=INIT_DATA_B;
@@ -82,11 +82,84 @@ int MD4_Init(MD4_CTX *c)
82 return 1; 82 return 1;
83 } 83 }
84 84
85#ifndef md4_block_host_order
86void md4_block_host_order (MD4_CTX *c, const void *data, int num)
87 {
88 const MD4_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 3,0);
100 R0(D,A,B,C,X[ 1], 7,0);
101 R0(C,D,A,B,X[ 2],11,0);
102 R0(B,C,D,A,X[ 3],19,0);
103 R0(A,B,C,D,X[ 4], 3,0);
104 R0(D,A,B,C,X[ 5], 7,0);
105 R0(C,D,A,B,X[ 6],11,0);
106 R0(B,C,D,A,X[ 7],19,0);
107 R0(A,B,C,D,X[ 8], 3,0);
108 R0(D,A,B,C,X[ 9], 7,0);
109 R0(C,D,A,B,X[10],11,0);
110 R0(B,C,D,A,X[11],19,0);
111 R0(A,B,C,D,X[12], 3,0);
112 R0(D,A,B,C,X[13], 7,0);
113 R0(C,D,A,B,X[14],11,0);
114 R0(B,C,D,A,X[15],19,0);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 0], 3,0x5A827999L);
117 R1(D,A,B,C,X[ 4], 5,0x5A827999L);
118 R1(C,D,A,B,X[ 8], 9,0x5A827999L);
119 R1(B,C,D,A,X[12],13,0x5A827999L);
120 R1(A,B,C,D,X[ 1], 3,0x5A827999L);
121 R1(D,A,B,C,X[ 5], 5,0x5A827999L);
122 R1(C,D,A,B,X[ 9], 9,0x5A827999L);
123 R1(B,C,D,A,X[13],13,0x5A827999L);
124 R1(A,B,C,D,X[ 2], 3,0x5A827999L);
125 R1(D,A,B,C,X[ 6], 5,0x5A827999L);
126 R1(C,D,A,B,X[10], 9,0x5A827999L);
127 R1(B,C,D,A,X[14],13,0x5A827999L);
128 R1(A,B,C,D,X[ 3], 3,0x5A827999L);
129 R1(D,A,B,C,X[ 7], 5,0x5A827999L);
130 R1(C,D,A,B,X[11], 9,0x5A827999L);
131 R1(B,C,D,A,X[15],13,0x5A827999L);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 0], 3,0x6ED9EBA1);
134 R2(D,A,B,C,X[ 8], 9,0x6ED9EBA1);
135 R2(C,D,A,B,X[ 4],11,0x6ED9EBA1);
136 R2(B,C,D,A,X[12],15,0x6ED9EBA1);
137 R2(A,B,C,D,X[ 2], 3,0x6ED9EBA1);
138 R2(D,A,B,C,X[10], 9,0x6ED9EBA1);
139 R2(C,D,A,B,X[ 6],11,0x6ED9EBA1);
140 R2(B,C,D,A,X[14],15,0x6ED9EBA1);
141 R2(A,B,C,D,X[ 1], 3,0x6ED9EBA1);
142 R2(D,A,B,C,X[ 9], 9,0x6ED9EBA1);
143 R2(C,D,A,B,X[ 5],11,0x6ED9EBA1);
144 R2(B,C,D,A,X[13],15,0x6ED9EBA1);
145 R2(A,B,C,D,X[ 3], 3,0x6ED9EBA1);
146 R2(D,A,B,C,X[11], 9,0x6ED9EBA1);
147 R2(C,D,A,B,X[ 7],11,0x6ED9EBA1);
148 R2(B,C,D,A,X[15],15,0x6ED9EBA1);
149
150 A = c->A += A;
151 B = c->B += B;
152 C = c->C += C;
153 D = c->D += D;
154 }
155 }
156#endif
157
85#ifndef md4_block_data_order 158#ifndef md4_block_data_order
86#ifdef X 159#ifdef X
87#undef X 160#undef X
88#endif 161#endif
89void md4_block_data_order (MD4_CTX *c, const void *data_, size_t num) 162void md4_block_data_order (MD4_CTX *c, const void *data_, int num)
90 { 163 {
91 const unsigned char *data=data_; 164 const unsigned char *data=data_;
92 register unsigned MD32_REG_T A,B,C,D,l; 165 register unsigned MD32_REG_T A,B,C,D,l;
@@ -167,3 +240,19 @@ void md4_block_data_order (MD4_CTX *c, const void *data_, size_t num)
167 } 240 }
168 } 241 }
169#endif 242#endif
243
244#ifdef undef
245int printit(unsigned long *l)
246 {
247 int i,ii;
248
249 for (i=0; i<2; i++)
250 {
251 for (ii=0; ii<8; ii++)
252 {
253 fprintf(stderr,"%08lx ",l[i*8+ii]);
254 }
255 fprintf(stderr,"\n");
256 }
257 }
258#endif
diff --git a/src/lib/libcrypto/md4/md4_locl.h b/src/lib/libcrypto/md4/md4_locl.h
index c8085b0ead..a8d31d7a73 100644
--- a/src/lib/libcrypto/md4/md4_locl.h
+++ b/src/lib/libcrypto/md4/md4_locl.h
@@ -65,13 +65,41 @@
65#define MD4_LONG_LOG2 2 /* default to 32 bits */ 65#define MD4_LONG_LOG2 2 /* default to 32 bits */
66#endif 66#endif
67 67
68void md4_block_data_order (MD4_CTX *c, const void *p,size_t num); 68void md4_block_host_order (MD4_CTX *c, const void *p,int num);
69void md4_block_data_order (MD4_CTX *c, const void *p,int num);
70
71#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
72/*
73 * *_block_host_order is expected to handle aligned data while
74 * *_block_data_order - unaligned. As algorithm and host (x86)
75 * are in this case of the same "endianness" these two are
76 * otherwise indistinguishable. But normally you don't want to
77 * call the same function because unaligned access in places
78 * where alignment is expected is usually a "Bad Thing". Indeed,
79 * on RISCs you get punished with BUS ERROR signal or *severe*
80 * performance degradation. Intel CPUs are in turn perfectly
81 * capable of loading unaligned data without such drastic side
82 * effect. Yes, they say it's slower than aligned load, but no
83 * exception is generated and therefore performance degradation
84 * is *incomparable* with RISCs. What we should weight here is
85 * costs of unaligned access against costs of aligning data.
86 * According to my measurements allowing unaligned access results
87 * in ~9% performance improvement on Pentium II operating at
88 * 266MHz. I won't be surprised if the difference will be higher
89 * on faster systems:-)
90 *
91 * <appro@fy.chalmers.se>
92 */
93#define md4_block_data_order md4_block_host_order
94#endif
69 95
70#define DATA_ORDER_IS_LITTLE_ENDIAN 96#define DATA_ORDER_IS_LITTLE_ENDIAN
71 97
72#define HASH_LONG MD4_LONG 98#define HASH_LONG MD4_LONG
99#define HASH_LONG_LOG2 MD4_LONG_LOG2
73#define HASH_CTX MD4_CTX 100#define HASH_CTX MD4_CTX
74#define HASH_CBLOCK MD4_CBLOCK 101#define HASH_CBLOCK MD4_CBLOCK
102#define HASH_LBLOCK MD4_LBLOCK
75#define HASH_UPDATE MD4_Update 103#define HASH_UPDATE MD4_Update
76#define HASH_TRANSFORM MD4_Transform 104#define HASH_TRANSFORM MD4_Transform
77#define HASH_FINAL MD4_Final 105#define HASH_FINAL MD4_Final
@@ -82,7 +110,21 @@ void md4_block_data_order (MD4_CTX *c, const void *p,size_t num);
82 ll=(c)->C; HOST_l2c(ll,(s)); \ 110 ll=(c)->C; HOST_l2c(ll,(s)); \
83 ll=(c)->D; HOST_l2c(ll,(s)); \ 111 ll=(c)->D; HOST_l2c(ll,(s)); \
84 } while (0) 112 } while (0)
113#define HASH_BLOCK_HOST_ORDER md4_block_host_order
114#if !defined(L_ENDIAN) || defined(md4_block_data_order)
85#define HASH_BLOCK_DATA_ORDER md4_block_data_order 115#define HASH_BLOCK_DATA_ORDER md4_block_data_order
116/*
117 * Little-endians (Intel and Alpha) feel better without this.
118 * It looks like memcpy does better job than generic
119 * md4_block_data_order on copying-n-aligning input data.
120 * But frankly speaking I didn't expect such result on Alpha.
121 * On the other hand I've got this with egcs-1.0.2 and if
122 * program is compiled with another (better?) compiler it
123 * might turn out other way around.
124 *
125 * <appro@fy.chalmers.se>
126 */
127#endif
86 128
87#include "md32_common.h" 129#include "md32_common.h"
88 130
diff --git a/src/lib/libcrypto/md4/md4_one.c b/src/lib/libcrypto/md4/md4_one.c
index bb64362638..50f79352f6 100644
--- a/src/lib/libcrypto/md4/md4_one.c
+++ b/src/lib/libcrypto/md4/md4_one.c
@@ -65,7 +65,7 @@
65#include <openssl/ebcdic.h> 65#include <openssl/ebcdic.h>
66#endif 66#endif
67 67
68unsigned char *MD4(const unsigned char *d, size_t n, unsigned char *md) 68unsigned char *MD4(const unsigned char *d, unsigned long n, unsigned char *md)
69 { 69 {
70 MD4_CTX c; 70 MD4_CTX c;
71 static unsigned char m[MD4_DIGEST_LENGTH]; 71 static unsigned char m[MD4_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/md4/md4s.cpp b/src/lib/libcrypto/md4/md4s.cpp
new file mode 100644
index 0000000000..c0ec97fc9f
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4s.cpp
@@ -0,0 +1,78 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/md4.h>
36
37extern "C" {
38void md4_block_x86(MD4_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD4_CTX ctx;
45 unsigned long s1,s2,e1,e2;
46 unsigned char k[16];
47 unsigned long data[2];
48 unsigned char iv[8];
49 int i,num=0,numm;
50 int j=0;
51
52 if (argc >= 2)
53 num=atoi(argv[1]);
54
55 if (num == 0) num=16;
56 if (num > 250) num=16;
57 numm=num+2;
58 num*=64;
59 numm*=64;
60
61 for (j=0; j<6; j++)
62 {
63 for (i=0; i<10; i++) /**/
64 {
65 md4_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md4_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md4_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md4_block_x86(&ctx,buffer,num);
73 }
74 printf("md4 (%d bytes) %d %d (%.2f)\n",num,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 }
77 }
78
diff --git a/src/lib/libcrypto/md4/md4test.c b/src/lib/libcrypto/md4/md4test.c
new file mode 100644
index 0000000000..21a77d96f7
--- /dev/null
+++ b/src/lib/libcrypto/md4/md4test.c
@@ -0,0 +1,136 @@
1/* crypto/md4/md4test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_MD4
66int main(int argc, char *argv[])
67{
68 printf("No MD4 support\n");
69 return(0);
70}
71#else
72#include <openssl/evp.h>
73#include <openssl/md4.h>
74
75static char *test[]={
76 "",
77 "a",
78 "abc",
79 "message digest",
80 "abcdefghijklmnopqrstuvwxyz",
81 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
82 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
83 NULL,
84 };
85
86static char *ret[]={
87"31d6cfe0d16ae931b73c59d7e0c089c0",
88"bde52cb31de33e46245e05fbdbd6fb24",
89"a448017aaf21d8525fc10ae87aa6729d",
90"d9130a8164549fe818874806e1c7014b",
91"d79e1c308aa5bbcdeea8ed63df412da9",
92"043f8582f241db351ce627e153e7f0e4",
93"e33b4ddc9c38f2199c3e7b164fcc0536",
94};
95
96static char *pt(unsigned char *md);
97int main(int argc, char *argv[])
98 {
99 int i,err=0;
100 unsigned char **P,**R;
101 char *p;
102 unsigned char md[MD4_DIGEST_LENGTH];
103
104 P=(unsigned char **)test;
105 R=(unsigned char **)ret;
106 i=1;
107 while (*P != NULL)
108 {
109 EVP_Digest(&(P[0][0]),(unsigned long)strlen((char *)*P),md,NULL,EVP_md4(), NULL);
110 p=pt(md);
111 if (strcmp(p,(char *)*R) != 0)
112 {
113 printf("error calculating MD4 on '%s'\n",*P);
114 printf("got %s instead of %s\n",p,*R);
115 err++;
116 }
117 else
118 printf("test %d ok\n",i);
119 i++;
120 R++;
121 P++;
122 }
123 EXIT(err);
124 return(0);
125 }
126
127static char *pt(unsigned char *md)
128 {
129 int i;
130 static char buf[80];
131
132 for (i=0; i<MD4_DIGEST_LENGTH; i++)
133 sprintf(&(buf[i*2]),"%02x",md[i]);
134 return(buf);
135 }
136#endif
diff --git a/src/lib/libcrypto/md5/Makefile b/src/lib/libcrypto/md5/Makefile
new file mode 100644
index 0000000000..ceb00e8956
--- /dev/null
+++ b/src/lib/libcrypto/md5/Makefile
@@ -0,0 +1,102 @@
1#
2# OpenSSL/crypto/md5/Makefile
3#
4
5DIR= md5
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I.. -I$(TOP) -I../../include
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14MD5_ASM_OBJ=
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21TEST=md5test.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=md5_dgst.c md5_one.c
26LIBOBJ=md5_dgst.o md5_one.o $(MD5_ASM_OBJ)
27
28SRC= $(LIBSRC)
29
30EXHEADER= md5.h
31HEADER= md5_locl.h $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45# ELF
46mx86-elf.s: asm/md5-586.pl ../perlasm/x86asm.pl
47 (cd asm; $(PERL) md5-586.pl elf $(CFLAGS) > ../$@)
48# COFF
49mx86-cof.s: asm/md5-586.pl ../perlasm/x86asm.pl
50 (cd asm; $(PERL) md5-586.pl coff $(CFLAGS) > ../$@)
51# a.out
52mx86-out.s: asm/md5-586.pl ../perlasm/x86asm.pl
53 (cd asm; $(PERL) md5-586.pl a.out $(CFLAGS) > ../$@)
54
55md5-x86_64.s: asm/md5-x86_64.pl; $(PERL) asm/md5-x86_64.pl $@
56
57files:
58 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
59
60links:
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65install:
66 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
67 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
68 do \
69 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
70 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
71 done;
72
73tags:
74 ctags $(SRC)
75
76tests:
77
78lint:
79 lint -DLINT $(INCLUDES) $(SRC)>fluff
80
81depend:
82 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
83 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
84
85dclean:
86 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
87 mv -f Makefile.new $(MAKEFILE)
88
89clean:
90 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
91
92# DO NOT DELETE THIS LINE -- make depend depends on it.
93
94md5_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md5.h
95md5_dgst.o: ../../include/openssl/opensslconf.h
96md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_dgst.c
97md5_dgst.o: md5_locl.h
98md5_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
99md5_one.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h
100md5_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101md5_one.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
102md5_one.o: ../../include/openssl/symhacks.h md5_one.c
diff --git a/src/lib/libcrypto/md5/Makefile.ssl b/src/lib/libcrypto/md5/Makefile.ssl
new file mode 100644
index 0000000000..2361775a2d
--- /dev/null
+++ b/src/lib/libcrypto/md5/Makefile.ssl
@@ -0,0 +1,127 @@
1#
2# SSLeay/crypto/md5/Makefile
3#
4
5DIR= md5
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=-I.. -I$(TOP) -I../../include
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20MD5_ASM_OBJ=
21
22CFLAGS= $(INCLUDES) $(CFLAG)
23ASFLAGS= $(INCLUDES) $(ASFLAG)
24
25GENERAL=Makefile
26TEST=md5test.c
27APPS=
28
29LIB=$(TOP)/libcrypto.a
30LIBSRC=md5_dgst.c md5_one.c
31LIBOBJ=md5_dgst.o md5_one.o $(MD5_ASM_OBJ)
32
33SRC= $(LIBSRC)
34
35EXHEADER= md5.h
36HEADER= md5_locl.h $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50# elf
51asm/mx86-elf.s: asm/md5-586.pl ../perlasm/x86asm.pl
52 (cd asm; $(PERL) md5-586.pl elf $(CFLAGS) > mx86-elf.s)
53
54# a.out
55asm/mx86-out.o: asm/mx86unix.cpp
56 $(CPP) -DOUT asm/mx86unix.cpp | as -o asm/mx86-out.o
57
58# bsdi
59asm/mx86bsdi.o: asm/mx86unix.cpp
60 $(CPP) -DBSDI asm/mx86unix.cpp | sed 's/ :/:/' | as -o asm/mx86bsdi.o
61
62asm/mx86unix.cpp: asm/md5-586.pl ../perlasm/x86asm.pl
63 (cd asm; $(PERL) md5-586.pl cpp >mx86unix.cpp)
64
65asm/md5-sparcv8plus.o: asm/md5-sparcv9.S
66 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \
67 -o asm/md5-sparcv8plus.o asm/md5-sparcv9.S
68
69# Old GNU assembler doesn't understand V9 instructions, so we
70# hire /usr/ccs/bin/as to do the job. Note that option is called
71# *-gcc27, but even gcc 2>=8 users may experience similar problem
72# if they didn't bother to upgrade GNU assembler. Such users should
73# not choose this option, but be adviced to *remove* GNU assembler
74# or upgrade it.
75asm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S
76 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \
77 /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o
78
79asm/md5-sparcv9.o: asm/md5-sparcv9.S
80 $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \
81 -o asm/md5-sparcv9.o asm/md5-sparcv9.S
82
83files:
84 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
85
86links:
87 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
88 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
89 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
90 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
91
92install:
93 @for i in $(EXHEADER) ; \
94 do \
95 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
96 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
97 done;
98
99tags:
100 ctags $(SRC)
101
102tests:
103
104lint:
105 lint -DLINT $(INCLUDES) $(SRC)>fluff
106
107depend:
108 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
109
110dclean:
111 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
112 mv -f Makefile.new $(MAKEFILE)
113
114clean:
115 rm -f asm/mx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
116
117# DO NOT DELETE THIS LINE -- make depend depends on it.
118
119md5_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/md5.h
120md5_dgst.o: ../../include/openssl/opensslconf.h
121md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_dgst.c
122md5_dgst.o: md5_locl.h
123md5_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
124md5_one.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h
125md5_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
126md5_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
127md5_one.o: md5_one.c
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl
index 76ac235f7d..fa3fa3bed5 100644
--- a/src/lib/libcrypto/md5/asm/md5-586.pl
+++ b/src/lib/libcrypto/md5/asm/md5-586.pl
@@ -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_asm_data_order"); 32&md5_block("md5_block_asm_host_order");
33&asm_finish(); 33&asm_finish();
34 34
35sub Np 35sub Np
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..db45aa4c97
--- /dev/null
+++ b/src/lib/libcrypto/md5/asm/md5-sparcv9.S
@@ -0,0 +1,1031 @@
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] -DOPENSSL_SYSNAME_ULTRASPARC -DMD5_BLOCK_DATA_ORDER \
28 * -c md5-sparcv9.S
29 *
30 * and with gcc:
31 *
32 * gcc -mcpu=ultrasparc -DOPENSSL_SYSNAME_ULTRASPARC -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 -DOPENSSL_SYSNAMEULTRASPARC -DMD5_BLOCK_DATA_ORDER md5_block.sparc.S | \
38 * as -xarch=v8plus /dev/fd/0 -o md5-sparcv9.o
39 */
40
41#include <openssl/e_os2.h>
42
43#define A %o0
44#define B %o1
45#define C %o2
46#define D %o3
47#define T1 %o4
48#define T2 %o5
49
50#define R0 %l0
51#define R1 %l1
52#define R2 %l2
53#define R3 %l3
54#define R4 %l4
55#define R5 %l5
56#define R6 %l6
57#define R7 %l7
58#define R8 %i3
59#define R9 %i4
60#define R10 %i5
61#define R11 %g1
62#define R12 %g2
63#define R13 %g3
64#define RX %g4
65
66#define Aptr %i0+0
67#define Bptr %i0+4
68#define Cptr %i0+8
69#define Dptr %i0+12
70
71#define Aval R5 /* those not used at the end of the last round */
72#define Bval R6
73#define Cval R7
74#define Dval R8
75
76#if defined(MD5_BLOCK_DATA_ORDER)
77# if defined(OPENSSL_SYSNAME_ULTRASPARC)
78# define LOAD lda
79# define X(i) [%i1+i*4]%asi
80# define md5_block md5_block_asm_data_order_aligned
81# define ASI_PRIMARY_LITTLE 0x88
82# else
83# error "MD5_BLOCK_DATA_ORDER is supported only on UltraSPARC!"
84# endif
85#else
86# define LOAD ld
87# define X(i) [%i1+i*4]
88# define md5_block md5_block_asm_host_order
89#endif
90
91.section ".text",#alloc,#execinstr
92
93#if defined(__SUNPRO_C) && defined(__sparcv9)
94 /* They've said -xarch=v9 at command line */
95 .register %g2,#scratch
96 .register %g3,#scratch
97# define FRAME -192
98#elif defined(__GNUC__) && defined(__arch64__)
99 /* They've said -m64 at command line */
100 .register %g2,#scratch
101 .register %g3,#scratch
102# define FRAME -192
103#else
104# define FRAME -96
105#endif
106
107.align 32
108
109.global md5_block
110md5_block:
111 save %sp,FRAME,%sp
112
113 ld [Dptr],D
114 ld [Cptr],C
115 ld [Bptr],B
116 ld [Aptr],A
117#ifdef ASI_PRIMARY_LITTLE
118 rd %asi,%o7 ! How dare I? Well, I just do:-)
119 wr %g0,ASI_PRIMARY_LITTLE,%asi
120#endif
121 LOAD X(0),R0
122
123.Lmd5_block_loop:
124
125!!!!!!!!Round 0
126
127 xor C,D,T1
128 sethi %hi(0xd76aa478),T2
129 and T1,B,T1
130 or T2,%lo(0xd76aa478),T2 !=
131 xor T1,D,T1
132 add T1,R0,T1
133 LOAD X(1),R1
134 add T1,T2,T1 !=
135 add A,T1,A
136 sll A,7,T2
137 srl A,32-7,A
138 or A,T2,A !=
139 xor B,C,T1
140 add A,B,A
141
142 sethi %hi(0xe8c7b756),T2
143 and T1,A,T1 !=
144 or T2,%lo(0xe8c7b756),T2
145 xor T1,C,T1
146 LOAD X(2),R2
147 add T1,R1,T1 !=
148 add T1,T2,T1
149 add D,T1,D
150 sll D,12,T2
151 srl D,32-12,D !=
152 or D,T2,D
153 xor A,B,T1
154 add D,A,D
155
156 sethi %hi(0x242070db),T2 !=
157 and T1,D,T1
158 or T2,%lo(0x242070db),T2
159 xor T1,B,T1
160 add T1,R2,T1 !=
161 LOAD X(3),R3
162 add T1,T2,T1
163 add C,T1,C
164 sll C,17,T2 !=
165 srl C,32-17,C
166 or C,T2,C
167 xor D,A,T1
168 add C,D,C !=
169
170 sethi %hi(0xc1bdceee),T2
171 and T1,C,T1
172 or T2,%lo(0xc1bdceee),T2
173 xor T1,A,T1 !=
174 add T1,R3,T1
175 LOAD X(4),R4
176 add T1,T2,T1
177 add B,T1,B !=
178 sll B,22,T2
179 srl B,32-22,B
180 or B,T2,B
181 xor C,D,T1 !=
182 add B,C,B
183
184 sethi %hi(0xf57c0faf),T2
185 and T1,B,T1
186 or T2,%lo(0xf57c0faf),T2 !=
187 xor T1,D,T1
188 add T1,R4,T1
189 LOAD X(5),R5
190 add T1,T2,T1 !=
191 add A,T1,A
192 sll A,7,T2
193 srl A,32-7,A
194 or A,T2,A !=
195 xor B,C,T1
196 add A,B,A
197
198 sethi %hi(0x4787c62a),T2
199 and T1,A,T1 !=
200 or T2,%lo(0x4787c62a),T2
201 xor T1,C,T1
202 LOAD X(6),R6
203 add T1,R5,T1 !=
204 add T1,T2,T1
205 add D,T1,D
206 sll D,12,T2
207 srl D,32-12,D !=
208 or D,T2,D
209 xor A,B,T1
210 add D,A,D
211
212 sethi %hi(0xa8304613),T2 !=
213 and T1,D,T1
214 or T2,%lo(0xa8304613),T2
215 xor T1,B,T1
216 add T1,R6,T1 !=
217 LOAD X(7),R7
218 add T1,T2,T1
219 add C,T1,C
220 sll C,17,T2 !=
221 srl C,32-17,C
222 or C,T2,C
223 xor D,A,T1
224 add C,D,C !=
225
226 sethi %hi(0xfd469501),T2
227 and T1,C,T1
228 or T2,%lo(0xfd469501),T2
229 xor T1,A,T1 !=
230 add T1,R7,T1
231 LOAD X(8),R8
232 add T1,T2,T1
233 add B,T1,B !=
234 sll B,22,T2
235 srl B,32-22,B
236 or B,T2,B
237 xor C,D,T1 !=
238 add B,C,B
239
240 sethi %hi(0x698098d8),T2
241 and T1,B,T1
242 or T2,%lo(0x698098d8),T2 !=
243 xor T1,D,T1
244 add T1,R8,T1
245 LOAD X(9),R9
246 add T1,T2,T1 !=
247 add A,T1,A
248 sll A,7,T2
249 srl A,32-7,A
250 or A,T2,A !=
251 xor B,C,T1
252 add A,B,A
253
254 sethi %hi(0x8b44f7af),T2
255 and T1,A,T1 !=
256 or T2,%lo(0x8b44f7af),T2
257 xor T1,C,T1
258 LOAD X(10),R10
259 add T1,R9,T1 !=
260 add T1,T2,T1
261 add D,T1,D
262 sll D,12,T2
263 srl D,32-12,D !=
264 or D,T2,D
265 xor A,B,T1
266 add D,A,D
267
268 sethi %hi(0xffff5bb1),T2 !=
269 and T1,D,T1
270 or T2,%lo(0xffff5bb1),T2
271 xor T1,B,T1
272 add T1,R10,T1 !=
273 LOAD X(11),R11
274 add T1,T2,T1
275 add C,T1,C
276 sll C,17,T2 !=
277 srl C,32-17,C
278 or C,T2,C
279 xor D,A,T1
280 add C,D,C !=
281
282 sethi %hi(0x895cd7be),T2
283 and T1,C,T1
284 or T2,%lo(0x895cd7be),T2
285 xor T1,A,T1 !=
286 add T1,R11,T1
287 LOAD X(12),R12
288 add T1,T2,T1
289 add B,T1,B !=
290 sll B,22,T2
291 srl B,32-22,B
292 or B,T2,B
293 xor C,D,T1 !=
294 add B,C,B
295
296 sethi %hi(0x6b901122),T2
297 and T1,B,T1
298 or T2,%lo(0x6b901122),T2 !=
299 xor T1,D,T1
300 add T1,R12,T1
301 LOAD X(13),R13
302 add T1,T2,T1 !=
303 add A,T1,A
304 sll A,7,T2
305 srl A,32-7,A
306 or A,T2,A !=
307 xor B,C,T1
308 add A,B,A
309
310 sethi %hi(0xfd987193),T2
311 and T1,A,T1 !=
312 or T2,%lo(0xfd987193),T2
313 xor T1,C,T1
314 LOAD X(14),RX
315 add T1,R13,T1 !=
316 add T1,T2,T1
317 add D,T1,D
318 sll D,12,T2
319 srl D,32-12,D !=
320 or D,T2,D
321 xor A,B,T1
322 add D,A,D
323
324 sethi %hi(0xa679438e),T2 !=
325 and T1,D,T1
326 or T2,%lo(0xa679438e),T2
327 xor T1,B,T1
328 add T1,RX,T1 !=
329 LOAD X(15),RX
330 add T1,T2,T1
331 add C,T1,C
332 sll C,17,T2 !=
333 srl C,32-17,C
334 or C,T2,C
335 xor D,A,T1
336 add C,D,C !=
337
338 sethi %hi(0x49b40821),T2
339 and T1,C,T1
340 or T2,%lo(0x49b40821),T2
341 xor T1,A,T1 !=
342 add T1,RX,T1
343 !pre-LOADed X(1),R1
344 add T1,T2,T1
345 add B,T1,B
346 sll B,22,T2 !=
347 srl B,32-22,B
348 or B,T2,B
349 add B,C,B
350
351!!!!!!!!Round 1
352
353 xor B,C,T1 !=
354 sethi %hi(0xf61e2562),T2
355 and T1,D,T1
356 or T2,%lo(0xf61e2562),T2
357 xor T1,C,T1 !=
358 add T1,R1,T1
359 !pre-LOADed X(6),R6
360 add T1,T2,T1
361 add A,T1,A
362 sll A,5,T2 !=
363 srl A,32-5,A
364 or A,T2,A
365 add A,B,A
366
367 xor A,B,T1 !=
368 sethi %hi(0xc040b340),T2
369 and T1,C,T1
370 or T2,%lo(0xc040b340),T2
371 xor T1,B,T1 !=
372 add T1,R6,T1
373 !pre-LOADed X(11),R11
374 add T1,T2,T1
375 add D,T1,D
376 sll D,9,T2 !=
377 srl D,32-9,D
378 or D,T2,D
379 add D,A,D
380
381 xor D,A,T1 !=
382 sethi %hi(0x265e5a51),T2
383 and T1,B,T1
384 or T2,%lo(0x265e5a51),T2
385 xor T1,A,T1 !=
386 add T1,R11,T1
387 !pre-LOADed X(0),R0
388 add T1,T2,T1
389 add C,T1,C
390 sll C,14,T2 !=
391 srl C,32-14,C
392 or C,T2,C
393 add C,D,C
394
395 xor C,D,T1 !=
396 sethi %hi(0xe9b6c7aa),T2
397 and T1,A,T1
398 or T2,%lo(0xe9b6c7aa),T2
399 xor T1,D,T1 !=
400 add T1,R0,T1
401 !pre-LOADed X(5),R5
402 add T1,T2,T1
403 add B,T1,B
404 sll B,20,T2 !=
405 srl B,32-20,B
406 or B,T2,B
407 add B,C,B
408
409 xor B,C,T1 !=
410 sethi %hi(0xd62f105d),T2
411 and T1,D,T1
412 or T2,%lo(0xd62f105d),T2
413 xor T1,C,T1 !=
414 add T1,R5,T1
415 !pre-LOADed X(10),R10
416 add T1,T2,T1
417 add A,T1,A
418 sll A,5,T2 !=
419 srl A,32-5,A
420 or A,T2,A
421 add A,B,A
422
423 xor A,B,T1 !=
424 sethi %hi(0x02441453),T2
425 and T1,C,T1
426 or T2,%lo(0x02441453),T2
427 xor T1,B,T1 !=
428 add T1,R10,T1
429 LOAD X(15),RX
430 add T1,T2,T1
431 add D,T1,D !=
432 sll D,9,T2
433 srl D,32-9,D
434 or D,T2,D
435 add D,A,D !=
436
437 xor D,A,T1
438 sethi %hi(0xd8a1e681),T2
439 and T1,B,T1
440 or T2,%lo(0xd8a1e681),T2 !=
441 xor T1,A,T1
442 add T1,RX,T1
443 !pre-LOADed X(4),R4
444 add T1,T2,T1
445 add C,T1,C !=
446 sll C,14,T2
447 srl C,32-14,C
448 or C,T2,C
449 add C,D,C !=
450
451 xor C,D,T1
452 sethi %hi(0xe7d3fbc8),T2
453 and T1,A,T1
454 or T2,%lo(0xe7d3fbc8),T2 !=
455 xor T1,D,T1
456 add T1,R4,T1
457 !pre-LOADed X(9),R9
458 add T1,T2,T1
459 add B,T1,B !=
460 sll B,20,T2
461 srl B,32-20,B
462 or B,T2,B
463 add B,C,B !=
464
465 xor B,C,T1
466 sethi %hi(0x21e1cde6),T2
467 and T1,D,T1
468 or T2,%lo(0x21e1cde6),T2 !=
469 xor T1,C,T1
470 add T1,R9,T1
471 LOAD X(14),RX
472 add T1,T2,T1 !=
473 add A,T1,A
474 sll A,5,T2
475 srl A,32-5,A
476 or A,T2,A !=
477 add A,B,A
478
479 xor A,B,T1
480 sethi %hi(0xc33707d6),T2
481 and T1,C,T1 !=
482 or T2,%lo(0xc33707d6),T2
483 xor T1,B,T1
484 add T1,RX,T1
485 !pre-LOADed X(3),R3
486 add T1,T2,T1 !=
487 add D,T1,D
488 sll D,9,T2
489 srl D,32-9,D
490 or D,T2,D !=
491 add D,A,D
492
493 xor D,A,T1
494 sethi %hi(0xf4d50d87),T2
495 and T1,B,T1 !=
496 or T2,%lo(0xf4d50d87),T2
497 xor T1,A,T1
498 add T1,R3,T1
499 !pre-LOADed X(8),R8
500 add T1,T2,T1 !=
501 add C,T1,C
502 sll C,14,T2
503 srl C,32-14,C
504 or C,T2,C !=
505 add C,D,C
506
507 xor C,D,T1
508 sethi %hi(0x455a14ed),T2
509 and T1,A,T1 !=
510 or T2,%lo(0x455a14ed),T2
511 xor T1,D,T1
512 add T1,R8,T1
513 !pre-LOADed X(13),R13
514 add T1,T2,T1 !=
515 add B,T1,B
516 sll B,20,T2
517 srl B,32-20,B
518 or B,T2,B !=
519 add B,C,B
520
521 xor B,C,T1
522 sethi %hi(0xa9e3e905),T2
523 and T1,D,T1 !=
524 or T2,%lo(0xa9e3e905),T2
525 xor T1,C,T1
526 add T1,R13,T1
527 !pre-LOADed X(2),R2
528 add T1,T2,T1 !=
529 add A,T1,A
530 sll A,5,T2
531 srl A,32-5,A
532 or A,T2,A !=
533 add A,B,A
534
535 xor A,B,T1
536 sethi %hi(0xfcefa3f8),T2
537 and T1,C,T1 !=
538 or T2,%lo(0xfcefa3f8),T2
539 xor T1,B,T1
540 add T1,R2,T1
541 !pre-LOADed X(7),R7
542 add T1,T2,T1 !=
543 add D,T1,D
544 sll D,9,T2
545 srl D,32-9,D
546 or D,T2,D !=
547 add D,A,D
548
549 xor D,A,T1
550 sethi %hi(0x676f02d9),T2
551 and T1,B,T1 !=
552 or T2,%lo(0x676f02d9),T2
553 xor T1,A,T1
554 add T1,R7,T1
555 !pre-LOADed X(12),R12
556 add T1,T2,T1 !=
557 add C,T1,C
558 sll C,14,T2
559 srl C,32-14,C
560 or C,T2,C !=
561 add C,D,C
562
563 xor C,D,T1
564 sethi %hi(0x8d2a4c8a),T2
565 and T1,A,T1 !=
566 or T2,%lo(0x8d2a4c8a),T2
567 xor T1,D,T1
568 add T1,R12,T1
569 !pre-LOADed X(5),R5
570 add T1,T2,T1 !=
571 add B,T1,B
572 sll B,20,T2
573 srl B,32-20,B
574 or B,T2,B !=
575 add B,C,B
576
577!!!!!!!!Round 2
578
579 xor B,C,T1
580 sethi %hi(0xfffa3942),T2
581 xor T1,D,T1 !=
582 or T2,%lo(0xfffa3942),T2
583 add T1,R5,T1
584 !pre-LOADed X(8),R8
585 add T1,T2,T1
586 add A,T1,A !=
587 sll A,4,T2
588 srl A,32-4,A
589 or A,T2,A
590 add A,B,A !=
591
592 xor A,B,T1
593 sethi %hi(0x8771f681),T2
594 xor T1,C,T1
595 or T2,%lo(0x8771f681),T2 !=
596 add T1,R8,T1
597 !pre-LOADed X(11),R11
598 add T1,T2,T1
599 add D,T1,D
600 sll D,11,T2 !=
601 srl D,32-11,D
602 or D,T2,D
603 add D,A,D
604
605 xor D,A,T1 !=
606 sethi %hi(0x6d9d6122),T2
607 xor T1,B,T1
608 or T2,%lo(0x6d9d6122),T2
609 add T1,R11,T1 !=
610 LOAD X(14),RX
611 add T1,T2,T1
612 add C,T1,C
613 sll C,16,T2 !=
614 srl C,32-16,C
615 or C,T2,C
616 add C,D,C
617
618 xor C,D,T1 !=
619 sethi %hi(0xfde5380c),T2
620 xor T1,A,T1
621 or T2,%lo(0xfde5380c),T2
622 add T1,RX,T1 !=
623 !pre-LOADed X(1),R1
624 add T1,T2,T1
625 add B,T1,B
626 sll B,23,T2
627 srl B,32-23,B !=
628 or B,T2,B
629 add B,C,B
630
631 xor B,C,T1
632 sethi %hi(0xa4beea44),T2 !=
633 xor T1,D,T1
634 or T2,%lo(0xa4beea44),T2
635 add T1,R1,T1
636 !pre-LOADed X(4),R4
637 add T1,T2,T1 !=
638 add A,T1,A
639 sll A,4,T2
640 srl A,32-4,A
641 or A,T2,A !=
642 add A,B,A
643
644 xor A,B,T1
645 sethi %hi(0x4bdecfa9),T2
646 xor T1,C,T1 !=
647 or T2,%lo(0x4bdecfa9),T2
648 add T1,R4,T1
649 !pre-LOADed X(7),R7
650 add T1,T2,T1
651 add D,T1,D !=
652 sll D,11,T2
653 srl D,32-11,D
654 or D,T2,D
655 add D,A,D !=
656
657 xor D,A,T1
658 sethi %hi(0xf6bb4b60),T2
659 xor T1,B,T1
660 or T2,%lo(0xf6bb4b60),T2 !=
661 add T1,R7,T1
662 !pre-LOADed X(10),R10
663 add T1,T2,T1
664 add C,T1,C
665 sll C,16,T2 !=
666 srl C,32-16,C
667 or C,T2,C
668 add C,D,C
669
670 xor C,D,T1 !=
671 sethi %hi(0xbebfbc70),T2
672 xor T1,A,T1
673 or T2,%lo(0xbebfbc70),T2
674 add T1,R10,T1 !=
675 !pre-LOADed X(13),R13
676 add T1,T2,T1
677 add B,T1,B
678 sll B,23,T2
679 srl B,32-23,B !=
680 or B,T2,B
681 add B,C,B
682
683 xor B,C,T1
684 sethi %hi(0x289b7ec6),T2 !=
685 xor T1,D,T1
686 or T2,%lo(0x289b7ec6),T2
687 add T1,R13,T1
688 !pre-LOADed X(0),R0
689 add T1,T2,T1 !=
690 add A,T1,A
691 sll A,4,T2
692 srl A,32-4,A
693 or A,T2,A !=
694 add A,B,A
695
696 xor A,B,T1
697 sethi %hi(0xeaa127fa),T2
698 xor T1,C,T1 !=
699 or T2,%lo(0xeaa127fa),T2
700 add T1,R0,T1
701 !pre-LOADed X(3),R3
702 add T1,T2,T1
703 add D,T1,D !=
704 sll D,11,T2
705 srl D,32-11,D
706 or D,T2,D
707 add D,A,D !=
708
709 xor D,A,T1
710 sethi %hi(0xd4ef3085),T2
711 xor T1,B,T1
712 or T2,%lo(0xd4ef3085),T2 !=
713 add T1,R3,T1
714 !pre-LOADed X(6),R6
715 add T1,T2,T1
716 add C,T1,C
717 sll C,16,T2 !=
718 srl C,32-16,C
719 or C,T2,C
720 add C,D,C
721
722 xor C,D,T1 !=
723 sethi %hi(0x04881d05),T2
724 xor T1,A,T1
725 or T2,%lo(0x04881d05),T2
726 add T1,R6,T1 !=
727 !pre-LOADed X(9),R9
728 add T1,T2,T1
729 add B,T1,B
730 sll B,23,T2
731 srl B,32-23,B !=
732 or B,T2,B
733 add B,C,B
734
735 xor B,C,T1
736 sethi %hi(0xd9d4d039),T2 !=
737 xor T1,D,T1
738 or T2,%lo(0xd9d4d039),T2
739 add T1,R9,T1
740 !pre-LOADed X(12),R12
741 add T1,T2,T1 !=
742 add A,T1,A
743 sll A,4,T2
744 srl A,32-4,A
745 or A,T2,A !=
746 add A,B,A
747
748 xor A,B,T1
749 sethi %hi(0xe6db99e5),T2
750 xor T1,C,T1 !=
751 or T2,%lo(0xe6db99e5),T2
752 add T1,R12,T1
753 LOAD X(15),RX
754 add T1,T2,T1 !=
755 add D,T1,D
756 sll D,11,T2
757 srl D,32-11,D
758 or D,T2,D !=
759 add D,A,D
760
761 xor D,A,T1
762 sethi %hi(0x1fa27cf8),T2
763 xor T1,B,T1 !=
764 or T2,%lo(0x1fa27cf8),T2
765 add T1,RX,T1
766 !pre-LOADed X(2),R2
767 add T1,T2,T1
768 add C,T1,C !=
769 sll C,16,T2
770 srl C,32-16,C
771 or C,T2,C
772 add C,D,C !=
773
774 xor C,D,T1
775 sethi %hi(0xc4ac5665),T2
776 xor T1,A,T1
777 or T2,%lo(0xc4ac5665),T2 !=
778 add T1,R2,T1
779 !pre-LOADed X(0),R0
780 add T1,T2,T1
781 add B,T1,B
782 sll B,23,T2 !=
783 srl B,32-23,B
784 or B,T2,B
785 add B,C,B
786
787!!!!!!!!Round 3
788
789 orn B,D,T1 !=
790 sethi %hi(0xf4292244),T2
791 xor T1,C,T1
792 or T2,%lo(0xf4292244),T2
793 add T1,R0,T1 !=
794 !pre-LOADed X(7),R7
795 add T1,T2,T1
796 add A,T1,A
797 sll A,6,T2
798 srl A,32-6,A !=
799 or A,T2,A
800 add A,B,A
801
802 orn A,C,T1
803 sethi %hi(0x432aff97),T2 !=
804 xor T1,B,T1
805 or T2,%lo(0x432aff97),T2
806 LOAD X(14),RX
807 add T1,R7,T1 !=
808 add T1,T2,T1
809 add D,T1,D
810 sll D,10,T2
811 srl D,32-10,D !=
812 or D,T2,D
813 add D,A,D
814
815 orn D,B,T1
816 sethi %hi(0xab9423a7),T2 !=
817 xor T1,A,T1
818 or T2,%lo(0xab9423a7),T2
819 add T1,RX,T1
820 !pre-LOADed X(5),R5
821 add T1,T2,T1 !=
822 add C,T1,C
823 sll C,15,T2
824 srl C,32-15,C
825 or C,T2,C !=
826 add C,D,C
827
828 orn C,A,T1
829 sethi %hi(0xfc93a039),T2
830 xor T1,D,T1 !=
831 or T2,%lo(0xfc93a039),T2
832 add T1,R5,T1
833 !pre-LOADed X(12),R12
834 add T1,T2,T1
835 add B,T1,B !=
836 sll B,21,T2
837 srl B,32-21,B
838 or B,T2,B
839 add B,C,B !=
840
841 orn B,D,T1
842 sethi %hi(0x655b59c3),T2
843 xor T1,C,T1
844 or T2,%lo(0x655b59c3),T2 !=
845 add T1,R12,T1
846 !pre-LOADed X(3),R3
847 add T1,T2,T1
848 add A,T1,A
849 sll A,6,T2 !=
850 srl A,32-6,A
851 or A,T2,A
852 add A,B,A
853
854 orn A,C,T1 !=
855 sethi %hi(0x8f0ccc92),T2
856 xor T1,B,T1
857 or T2,%lo(0x8f0ccc92),T2
858 add T1,R3,T1 !=
859 !pre-LOADed X(10),R10
860 add T1,T2,T1
861 add D,T1,D
862 sll D,10,T2
863 srl D,32-10,D !=
864 or D,T2,D
865 add D,A,D
866
867 orn D,B,T1
868 sethi %hi(0xffeff47d),T2 !=
869 xor T1,A,T1
870 or T2,%lo(0xffeff47d),T2
871 add T1,R10,T1
872 !pre-LOADed X(1),R1
873 add T1,T2,T1 !=
874 add C,T1,C
875 sll C,15,T2
876 srl C,32-15,C
877 or C,T2,C !=
878 add C,D,C
879
880 orn C,A,T1
881 sethi %hi(0x85845dd1),T2
882 xor T1,D,T1 !=
883 or T2,%lo(0x85845dd1),T2
884 add T1,R1,T1
885 !pre-LOADed X(8),R8
886 add T1,T2,T1
887 add B,T1,B !=
888 sll B,21,T2
889 srl B,32-21,B
890 or B,T2,B
891 add B,C,B !=
892
893 orn B,D,T1
894 sethi %hi(0x6fa87e4f),T2
895 xor T1,C,T1
896 or T2,%lo(0x6fa87e4f),T2 !=
897 add T1,R8,T1
898 LOAD X(15),RX
899 add T1,T2,T1
900 add A,T1,A !=
901 sll A,6,T2
902 srl A,32-6,A
903 or A,T2,A
904 add A,B,A !=
905
906 orn A,C,T1
907 sethi %hi(0xfe2ce6e0),T2
908 xor T1,B,T1
909 or T2,%lo(0xfe2ce6e0),T2 !=
910 add T1,RX,T1
911 !pre-LOADed X(6),R6
912 add T1,T2,T1
913 add D,T1,D
914 sll D,10,T2 !=
915 srl D,32-10,D
916 or D,T2,D
917 add D,A,D
918
919 orn D,B,T1 !=
920 sethi %hi(0xa3014314),T2
921 xor T1,A,T1
922 or T2,%lo(0xa3014314),T2
923 add T1,R6,T1 !=
924 !pre-LOADed X(13),R13
925 add T1,T2,T1
926 add C,T1,C
927 sll C,15,T2
928 srl C,32-15,C !=
929 or C,T2,C
930 add C,D,C
931
932 orn C,A,T1
933 sethi %hi(0x4e0811a1),T2 !=
934 xor T1,D,T1
935 or T2,%lo(0x4e0811a1),T2
936 !pre-LOADed X(4),R4
937 ld [Aptr],Aval
938 add T1,R13,T1 !=
939 add T1,T2,T1
940 add B,T1,B
941 sll B,21,T2
942 srl B,32-21,B !=
943 or B,T2,B
944 add B,C,B
945
946 orn B,D,T1
947 sethi %hi(0xf7537e82),T2 !=
948 xor T1,C,T1
949 or T2,%lo(0xf7537e82),T2
950 !pre-LOADed X(11),R11
951 ld [Dptr],Dval
952 add T1,R4,T1 !=
953 add T1,T2,T1
954 add A,T1,A
955 sll A,6,T2
956 srl A,32-6,A !=
957 or A,T2,A
958 add A,B,A
959
960 orn A,C,T1
961 sethi %hi(0xbd3af235),T2 !=
962 xor T1,B,T1
963 or T2,%lo(0xbd3af235),T2
964 !pre-LOADed X(2),R2
965 ld [Cptr],Cval
966 add T1,R11,T1 !=
967 add T1,T2,T1
968 add D,T1,D
969 sll D,10,T2
970 srl D,32-10,D !=
971 or D,T2,D
972 add D,A,D
973
974 orn D,B,T1
975 sethi %hi(0x2ad7d2bb),T2 !=
976 xor T1,A,T1
977 or T2,%lo(0x2ad7d2bb),T2
978 !pre-LOADed X(9),R9
979 ld [Bptr],Bval
980 add T1,R2,T1 !=
981 add Aval,A,Aval
982 add T1,T2,T1
983 st Aval,[Aptr]
984 add C,T1,C !=
985 sll C,15,T2
986 add Dval,D,Dval
987 srl C,32-15,C
988 or C,T2,C !=
989 st Dval,[Dptr]
990 add C,D,C
991
992 orn C,A,T1
993 sethi %hi(0xeb86d391),T2 !=
994 xor T1,D,T1
995 or T2,%lo(0xeb86d391),T2
996 add T1,R9,T1
997 !pre-LOADed X(0),R0
998 mov Aval,A !=
999 add T1,T2,T1
1000 mov Dval,D
1001 add B,T1,B
1002 sll B,21,T2 !=
1003 add Cval,C,Cval
1004 srl B,32-21,B
1005 st Cval,[Cptr]
1006 or B,T2,B !=
1007 add B,C,B
1008
1009 deccc %i2
1010 mov Cval,C
1011 add B,Bval,B !=
1012 inc 64,%i1
1013 nop
1014 st B,[Bptr]
1015 nop !=
1016
1017#ifdef OPENSSL_SYSNAME_ULTRASPARC
1018 bg,a,pt %icc,.Lmd5_block_loop
1019#else
1020 bg,a .Lmd5_block_loop
1021#endif
1022 LOAD X(0),R0
1023
1024#ifdef ASI_PRIMARY_LITTLE
1025 wr %g0,%o7,%asi
1026#endif
1027 ret
1028 restore %g0,0,%o0
1029
1030.type md5_block,#function
1031.size md5_block,(.-md5_block)
diff --git a/src/lib/libcrypto/md5/md5.c b/src/lib/libcrypto/md5/md5.c
new file mode 100644
index 0000000000..563733abc5
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5.c
@@ -0,0 +1,127 @@
1/* crypto/md5/md5.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/md5.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#if !defined(_OSD_POSIX) && !defined(__DJGPP__)
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("MD5(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 MD5_CTX c;
102 unsigned char md[MD5_DIGEST_LENGTH];
103 int fd;
104 int i;
105 static unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 MD5_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,BUFSIZE);
112 if (i <= 0) break;
113 MD5_Update(&c,buf,(unsigned long)i);
114 }
115 MD5_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<MD5_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h
index dbdc0e1abc..c663dd1816 100644
--- a/src/lib/libcrypto/md5/md5.h
+++ b/src/lib/libcrypto/md5/md5.h
@@ -60,7 +60,6 @@
60#define HEADER_MD5_H 60#define HEADER_MD5_H
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63#include <stddef.h>
64 63
65#ifdef __cplusplus 64#ifdef __cplusplus
66extern "C" { 65extern "C" {
@@ -102,13 +101,16 @@ typedef struct MD5state_st
102 MD5_LONG A,B,C,D; 101 MD5_LONG A,B,C,D;
103 MD5_LONG Nl,Nh; 102 MD5_LONG Nl,Nh;
104 MD5_LONG data[MD5_LBLOCK]; 103 MD5_LONG data[MD5_LBLOCK];
105 unsigned int num; 104 int num;
106 } MD5_CTX; 105 } MD5_CTX;
107 106
107#ifdef OPENSSL_FIPS
108int private_MD5_Init(MD5_CTX *c);
109#endif
108int MD5_Init(MD5_CTX *c); 110int MD5_Init(MD5_CTX *c);
109int MD5_Update(MD5_CTX *c, const void *data, size_t len); 111int MD5_Update(MD5_CTX *c, const void *data, unsigned long len);
110int MD5_Final(unsigned char *md, MD5_CTX *c); 112int MD5_Final(unsigned char *md, MD5_CTX *c);
111unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md); 113unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md);
112void MD5_Transform(MD5_CTX *c, const unsigned char *b); 114void MD5_Transform(MD5_CTX *c, const unsigned char *b);
113#ifdef __cplusplus 115#ifdef __cplusplus
114} 116}
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c
index b96e332ba4..54b33c6509 100644
--- a/src/lib/libcrypto/md5/md5_dgst.c
+++ b/src/lib/libcrypto/md5/md5_dgst.c
@@ -60,7 +60,7 @@
60#include "md5_locl.h" 60#include "md5_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT; 63const char *MD5_version="MD5" OPENSSL_VERSION_PTEXT;
64 64
65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm 65/* Implemented from RFC1321 The MD5 Message-Digest Algorithm
66 */ 66 */
@@ -70,7 +70,7 @@ const char MD5_version[]="MD5" OPENSSL_VERSION_PTEXT;
70#define INIT_DATA_C (unsigned long)0x98badcfeL 70#define INIT_DATA_C (unsigned long)0x98badcfeL
71#define INIT_DATA_D (unsigned long)0x10325476L 71#define INIT_DATA_D (unsigned long)0x10325476L
72 72
73int MD5_Init(MD5_CTX *c) 73FIPS_NON_FIPS_MD_Init(MD5)
74 { 74 {
75 c->A=INIT_DATA_A; 75 c->A=INIT_DATA_A;
76 c->B=INIT_DATA_B; 76 c->B=INIT_DATA_B;
@@ -82,11 +82,101 @@ int MD5_Init(MD5_CTX *c)
82 return 1; 82 return 1;
83 } 83 }
84 84
85#ifndef md5_block_host_order
86void md5_block_host_order (MD5_CTX *c, const void *data, int num)
87 {
88 const MD5_LONG *X=data;
89 register unsigned MD32_REG_T A,B,C,D;
90
91 A=c->A;
92 B=c->B;
93 C=c->C;
94 D=c->D;
95
96 for (;num--;X+=HASH_LBLOCK)
97 {
98 /* Round 0 */
99 R0(A,B,C,D,X[ 0], 7,0xd76aa478L);
100 R0(D,A,B,C,X[ 1],12,0xe8c7b756L);
101 R0(C,D,A,B,X[ 2],17,0x242070dbL);
102 R0(B,C,D,A,X[ 3],22,0xc1bdceeeL);
103 R0(A,B,C,D,X[ 4], 7,0xf57c0fafL);
104 R0(D,A,B,C,X[ 5],12,0x4787c62aL);
105 R0(C,D,A,B,X[ 6],17,0xa8304613L);
106 R0(B,C,D,A,X[ 7],22,0xfd469501L);
107 R0(A,B,C,D,X[ 8], 7,0x698098d8L);
108 R0(D,A,B,C,X[ 9],12,0x8b44f7afL);
109 R0(C,D,A,B,X[10],17,0xffff5bb1L);
110 R0(B,C,D,A,X[11],22,0x895cd7beL);
111 R0(A,B,C,D,X[12], 7,0x6b901122L);
112 R0(D,A,B,C,X[13],12,0xfd987193L);
113 R0(C,D,A,B,X[14],17,0xa679438eL);
114 R0(B,C,D,A,X[15],22,0x49b40821L);
115 /* Round 1 */
116 R1(A,B,C,D,X[ 1], 5,0xf61e2562L);
117 R1(D,A,B,C,X[ 6], 9,0xc040b340L);
118 R1(C,D,A,B,X[11],14,0x265e5a51L);
119 R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL);
120 R1(A,B,C,D,X[ 5], 5,0xd62f105dL);
121 R1(D,A,B,C,X[10], 9,0x02441453L);
122 R1(C,D,A,B,X[15],14,0xd8a1e681L);
123 R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L);
124 R1(A,B,C,D,X[ 9], 5,0x21e1cde6L);
125 R1(D,A,B,C,X[14], 9,0xc33707d6L);
126 R1(C,D,A,B,X[ 3],14,0xf4d50d87L);
127 R1(B,C,D,A,X[ 8],20,0x455a14edL);
128 R1(A,B,C,D,X[13], 5,0xa9e3e905L);
129 R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L);
130 R1(C,D,A,B,X[ 7],14,0x676f02d9L);
131 R1(B,C,D,A,X[12],20,0x8d2a4c8aL);
132 /* Round 2 */
133 R2(A,B,C,D,X[ 5], 4,0xfffa3942L);
134 R2(D,A,B,C,X[ 8],11,0x8771f681L);
135 R2(C,D,A,B,X[11],16,0x6d9d6122L);
136 R2(B,C,D,A,X[14],23,0xfde5380cL);
137 R2(A,B,C,D,X[ 1], 4,0xa4beea44L);
138 R2(D,A,B,C,X[ 4],11,0x4bdecfa9L);
139 R2(C,D,A,B,X[ 7],16,0xf6bb4b60L);
140 R2(B,C,D,A,X[10],23,0xbebfbc70L);
141 R2(A,B,C,D,X[13], 4,0x289b7ec6L);
142 R2(D,A,B,C,X[ 0],11,0xeaa127faL);
143 R2(C,D,A,B,X[ 3],16,0xd4ef3085L);
144 R2(B,C,D,A,X[ 6],23,0x04881d05L);
145 R2(A,B,C,D,X[ 9], 4,0xd9d4d039L);
146 R2(D,A,B,C,X[12],11,0xe6db99e5L);
147 R2(C,D,A,B,X[15],16,0x1fa27cf8L);
148 R2(B,C,D,A,X[ 2],23,0xc4ac5665L);
149 /* Round 3 */
150 R3(A,B,C,D,X[ 0], 6,0xf4292244L);
151 R3(D,A,B,C,X[ 7],10,0x432aff97L);
152 R3(C,D,A,B,X[14],15,0xab9423a7L);
153 R3(B,C,D,A,X[ 5],21,0xfc93a039L);
154 R3(A,B,C,D,X[12], 6,0x655b59c3L);
155 R3(D,A,B,C,X[ 3],10,0x8f0ccc92L);
156 R3(C,D,A,B,X[10],15,0xffeff47dL);
157 R3(B,C,D,A,X[ 1],21,0x85845dd1L);
158 R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL);
159 R3(D,A,B,C,X[15],10,0xfe2ce6e0L);
160 R3(C,D,A,B,X[ 6],15,0xa3014314L);
161 R3(B,C,D,A,X[13],21,0x4e0811a1L);
162 R3(A,B,C,D,X[ 4], 6,0xf7537e82L);
163 R3(D,A,B,C,X[11],10,0xbd3af235L);
164 R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL);
165 R3(B,C,D,A,X[ 9],21,0xeb86d391L);
166
167 A = c->A += A;
168 B = c->B += B;
169 C = c->C += C;
170 D = c->D += D;
171 }
172 }
173#endif
174
85#ifndef md5_block_data_order 175#ifndef md5_block_data_order
86#ifdef X 176#ifdef X
87#undef X 177#undef X
88#endif 178#endif
89void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num) 179void md5_block_data_order (MD5_CTX *c, const void *data_, int num)
90 { 180 {
91 const unsigned char *data=data_; 181 const unsigned char *data=data_;
92 register unsigned MD32_REG_T A,B,C,D,l; 182 register unsigned MD32_REG_T A,B,C,D,l;
@@ -184,3 +274,19 @@ void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num)
184 } 274 }
185 } 275 }
186#endif 276#endif
277
278#ifdef undef
279int printit(unsigned long *l)
280 {
281 int i,ii;
282
283 for (i=0; i<2; i++)
284 {
285 for (ii=0; ii<8; ii++)
286 {
287 fprintf(stderr,"%08lx ",l[i*8+ii]);
288 }
289 fprintf(stderr,"\n");
290 }
291 }
292#endif
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h
index 84e81b960d..9e360da732 100644
--- a/src/lib/libcrypto/md5/md5_locl.h
+++ b/src/lib/libcrypto/md5/md5_locl.h
@@ -66,19 +66,49 @@
66#endif 66#endif
67 67
68#ifdef MD5_ASM 68#ifdef MD5_ASM
69# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) || \ 69# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
70 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) 70# define md5_block_host_order md5_block_asm_host_order
71# define md5_block_data_order md5_block_asm_data_order 71# elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC)
72 void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num);
73# define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned
72# endif 74# endif
73#endif 75#endif
74 76
75void md5_block_data_order (MD5_CTX *c, const void *p,size_t num); 77void md5_block_host_order (MD5_CTX *c, const void *p,int num);
78void md5_block_data_order (MD5_CTX *c, const void *p,int num);
79
80#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
81/*
82 * *_block_host_order is expected to handle aligned data while
83 * *_block_data_order - unaligned. As algorithm and host (x86)
84 * are in this case of the same "endianness" these two are
85 * otherwise indistinguishable. But normally you don't want to
86 * call the same function because unaligned access in places
87 * where alignment is expected is usually a "Bad Thing". Indeed,
88 * on RISCs you get punished with BUS ERROR signal or *severe*
89 * performance degradation. Intel CPUs are in turn perfectly
90 * capable of loading unaligned data without such drastic side
91 * effect. Yes, they say it's slower than aligned load, but no
92 * exception is generated and therefore performance degradation
93 * is *incomparable* with RISCs. What we should weight here is
94 * costs of unaligned access against costs of aligning data.
95 * According to my measurements allowing unaligned access results
96 * in ~9% performance improvement on Pentium II operating at
97 * 266MHz. I won't be surprised if the difference will be higher
98 * on faster systems:-)
99 *
100 * <appro@fy.chalmers.se>
101 */
102#define md5_block_data_order md5_block_host_order
103#endif
76 104
77#define DATA_ORDER_IS_LITTLE_ENDIAN 105#define DATA_ORDER_IS_LITTLE_ENDIAN
78 106
79#define HASH_LONG MD5_LONG 107#define HASH_LONG MD5_LONG
108#define HASH_LONG_LOG2 MD5_LONG_LOG2
80#define HASH_CTX MD5_CTX 109#define HASH_CTX MD5_CTX
81#define HASH_CBLOCK MD5_CBLOCK 110#define HASH_CBLOCK MD5_CBLOCK
111#define HASH_LBLOCK MD5_LBLOCK
82#define HASH_UPDATE MD5_Update 112#define HASH_UPDATE MD5_Update
83#define HASH_TRANSFORM MD5_Transform 113#define HASH_TRANSFORM MD5_Transform
84#define HASH_FINAL MD5_Final 114#define HASH_FINAL MD5_Final
@@ -89,7 +119,21 @@ void md5_block_data_order (MD5_CTX *c, const void *p,size_t num);
89 ll=(c)->C; HOST_l2c(ll,(s)); \ 119 ll=(c)->C; HOST_l2c(ll,(s)); \
90 ll=(c)->D; HOST_l2c(ll,(s)); \ 120 ll=(c)->D; HOST_l2c(ll,(s)); \
91 } while (0) 121 } while (0)
122#define HASH_BLOCK_HOST_ORDER md5_block_host_order
123#if !defined(L_ENDIAN) || defined(md5_block_data_order)
92#define HASH_BLOCK_DATA_ORDER md5_block_data_order 124#define HASH_BLOCK_DATA_ORDER md5_block_data_order
125/*
126 * Little-endians (Intel and Alpha) feel better without this.
127 * It looks like memcpy does better job than generic
128 * md5_block_data_order on copying-n-aligning input data.
129 * But frankly speaking I didn't expect such result on Alpha.
130 * On the other hand I've got this with egcs-1.0.2 and if
131 * program is compiled with another (better?) compiler it
132 * might turn out other way around.
133 *
134 * <appro@fy.chalmers.se>
135 */
136#endif
93 137
94#include "md32_common.h" 138#include "md32_common.h"
95 139
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c
index 43fee89379..44c6c455d1 100644
--- a/src/lib/libcrypto/md5/md5_one.c
+++ b/src/lib/libcrypto/md5/md5_one.c
@@ -65,7 +65,7 @@
65#include <openssl/ebcdic.h> 65#include <openssl/ebcdic.h>
66#endif 66#endif
67 67
68unsigned char *MD5(const unsigned char *d, size_t n, unsigned char *md) 68unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md)
69 { 69 {
70 MD5_CTX c; 70 MD5_CTX c;
71 static unsigned char m[MD5_DIGEST_LENGTH]; 71 static unsigned char m[MD5_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/md5/md5s.cpp b/src/lib/libcrypto/md5/md5s.cpp
new file mode 100644
index 0000000000..dd343fd4e6
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5s.cpp
@@ -0,0 +1,78 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/md5.h>
36
37extern "C" {
38void md5_block_x86(MD5_CTX *ctx, unsigned char *buffer,int num);
39}
40
41void main(int argc,char *argv[])
42 {
43 unsigned char buffer[64*256];
44 MD5_CTX ctx;
45 unsigned long s1,s2,e1,e2;
46 unsigned char k[16];
47 unsigned long data[2];
48 unsigned char iv[8];
49 int i,num=0,numm;
50 int j=0;
51
52 if (argc >= 2)
53 num=atoi(argv[1]);
54
55 if (num == 0) num=16;
56 if (num > 250) num=16;
57 numm=num+2;
58 num*=64;
59 numm*=64;
60
61 for (j=0; j<6; j++)
62 {
63 for (i=0; i<10; i++) /**/
64 {
65 md5_block_x86(&ctx,buffer,numm);
66 GetTSC(s1);
67 md5_block_x86(&ctx,buffer,numm);
68 GetTSC(e1);
69 GetTSC(s2);
70 md5_block_x86(&ctx,buffer,num);
71 GetTSC(e2);
72 md5_block_x86(&ctx,buffer,num);
73 }
74 printf("md5 (%d bytes) %d %d (%.2f)\n",num,
75 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
76 }
77 }
78
diff --git a/src/lib/libcrypto/md5/md5test.c b/src/lib/libcrypto/md5/md5test.c
new file mode 100644
index 0000000000..bfd62629ed
--- /dev/null
+++ b/src/lib/libcrypto/md5/md5test.c
@@ -0,0 +1,136 @@
1/* crypto/md5/md5test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_MD5
66int main(int argc, char *argv[])
67{
68 printf("No MD5 support\n");
69 return(0);
70}
71#else
72#include <openssl/evp.h>
73#include <openssl/md5.h>
74
75static char *test[]={
76 "",
77 "a",
78 "abc",
79 "message digest",
80 "abcdefghijklmnopqrstuvwxyz",
81 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
82 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
83 NULL,
84 };
85
86static char *ret[]={
87 "d41d8cd98f00b204e9800998ecf8427e",
88 "0cc175b9c0f1b6a831c399e269772661",
89 "900150983cd24fb0d6963f7d28e17f72",
90 "f96b697d7cb7938d525a2f31aaf161d0",
91 "c3fcd3d76192e4007dfb496cca67e13b",
92 "d174ab98d277d9f5a5611c2c9f419d9f",
93 "57edf4a22be3c955ac49da2e2107b67a",
94 };
95
96static char *pt(unsigned char *md);
97int main(int argc, char *argv[])
98 {
99 int i,err=0;
100 unsigned char **P,**R;
101 char *p;
102 unsigned char md[MD5_DIGEST_LENGTH];
103
104 P=(unsigned char **)test;
105 R=(unsigned char **)ret;
106 i=1;
107 while (*P != NULL)
108 {
109 EVP_Digest(&(P[0][0]),(unsigned long)strlen((char *)*P),md,NULL,EVP_md5(), NULL);
110 p=pt(md);
111 if (strcmp(p,(char *)*R) != 0)
112 {
113 printf("error calculating MD5 on '%s'\n",*P);
114 printf("got %s instead of %s\n",p,*R);
115 err++;
116 }
117 else
118 printf("test %d ok\n",i);
119 i++;
120 R++;
121 P++;
122 }
123 EXIT(err);
124 return(0);
125 }
126
127static char *pt(unsigned char *md)
128 {
129 int i;
130 static char buf[80];
131
132 for (i=0; i<MD5_DIGEST_LENGTH; i++)
133 sprintf(&(buf[i*2]),"%02x",md[i]);
134 return(buf);
135 }
136#endif
diff --git a/src/lib/libcrypto/mdc2/Makefile b/src/lib/libcrypto/mdc2/Makefile
new file mode 100644
index 0000000000..b8e9a9a4fa
--- /dev/null
+++ b/src/lib/libcrypto/mdc2/Makefile
@@ -0,0 +1,98 @@
1#
2# OpenSSL/crypto/mdc2/Makefile
3#
4
5DIR= mdc2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKEDEPPROG= makedepend
14MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
15MAKEFILE= Makefile
16AR= ar r
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19
20GENERAL=Makefile
21TEST= mdc2test.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=mdc2dgst.c mdc2_one.c
26LIBOBJ=mdc2dgst.o mdc2_one.o
27
28SRC= $(LIBSRC)
29
30EXHEADER= mdc2.h
31HEADER= $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45files:
46 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
47
48links:
49 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
50 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
51 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
52
53install:
54 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
55 do \
56 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done;
59
60tags:
61 ctags $(SRC)
62
63tests:
64
65lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff
67
68depend:
69 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
70
71dclean:
72 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE)
74
75clean:
76 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78# DO NOT DELETE THIS LINE -- make depend depends on it.
79
80mdc2_one.o: ../../e_os.h ../../include/openssl/bio.h
81mdc2_one.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
82mdc2_one.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
83mdc2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
84mdc2_one.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h
85mdc2_one.o: ../../include/openssl/opensslconf.h
86mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87mdc2_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88mdc2_one.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
89mdc2_one.o: ../cryptlib.h mdc2_one.c
90mdc2dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
91mdc2dgst.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
92mdc2dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
93mdc2dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h
94mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h
95mdc2dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
96mdc2dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97mdc2dgst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
98mdc2dgst.o: mdc2dgst.c
diff --git a/src/lib/libcrypto/mdc2/Makefile.ssl b/src/lib/libcrypto/mdc2/Makefile.ssl
new file mode 100644
index 0000000000..33f366fb08
--- /dev/null
+++ b/src/lib/libcrypto/mdc2/Makefile.ssl
@@ -0,0 +1,98 @@
1#
2# SSLeay/crypto/mdc2/Makefile
3#
4
5DIR= mdc2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST= mdc2test.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=mdc2dgst.c mdc2_one.c
27LIBOBJ=mdc2dgst.o mdc2_one.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= mdc2.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82mdc2_one.o: ../../e_os.h ../../include/openssl/bio.h
83mdc2_one.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84mdc2_one.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
85mdc2_one.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
86mdc2_one.o: ../../include/openssl/lhash.h ../../include/openssl/mdc2.h
87mdc2_one.o: ../../include/openssl/opensslconf.h
88mdc2_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
89mdc2_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
90mdc2_one.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
91mdc2_one.o: ../cryptlib.h mdc2_one.c
92mdc2dgst.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
93mdc2dgst.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
94mdc2dgst.o: ../../include/openssl/mdc2.h ../../include/openssl/opensslconf.h
95mdc2dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
96mdc2dgst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97mdc2dgst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
98mdc2dgst.o: mdc2dgst.c
diff --git a/src/lib/libcrypto/mdc2/mdc2.h b/src/lib/libcrypto/mdc2/mdc2.h
new file mode 100644
index 0000000000..4cba101f37
--- /dev/null
+++ b/src/lib/libcrypto/mdc2/mdc2.h
@@ -0,0 +1,97 @@
1/* crypto/mdc2/mdc2.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_MDC2_H
60#define HEADER_MDC2_H
61
62#include <openssl/des.h>
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68#ifdef OPENSSL_NO_MDC2
69#error MDC2 is disabled.
70#endif
71
72#define MDC2_BLOCK 8
73#define MDC2_DIGEST_LENGTH 16
74
75typedef struct mdc2_ctx_st
76 {
77 int num;
78 unsigned char data[MDC2_BLOCK];
79 DES_cblock h,hh;
80 int pad_type; /* either 1 or 2, default 1 */
81 } MDC2_CTX;
82
83#ifdef OPENSSL_FIPS
84int private_MDC2_Init(MDC2_CTX *c);
85#endif
86int MDC2_Init(MDC2_CTX *c);
87int MDC2_Update(MDC2_CTX *c, const unsigned char *data, unsigned long len);
88int MDC2_Final(unsigned char *md, MDC2_CTX *c);
89unsigned char *MDC2(const unsigned char *d, unsigned long n,
90 unsigned char *md);
91
92#ifdef __cplusplus
93}
94#endif
95
96#endif
97
diff --git a/src/lib/libcrypto/mdc2/mdc2test.c b/src/lib/libcrypto/mdc2/mdc2test.c
new file mode 100644
index 0000000000..017b31add2
--- /dev/null
+++ b/src/lib/libcrypto/mdc2/mdc2test.c
@@ -0,0 +1,149 @@
1/* crypto/mdc2/mdc2test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "../e_os.h"
64
65#if defined(OPENSSL_NO_DES) && !defined(OPENSSL_NO_MDC2)
66#define OPENSSL_NO_MDC2
67#endif
68
69#ifdef OPENSSL_NO_MDC2
70int main(int argc, char *argv[])
71{
72 printf("No MDC2 support\n");
73 return(0);
74}
75#else
76#include <openssl/evp.h>
77#include <openssl/mdc2.h>
78
79#ifdef CHARSET_EBCDIC
80#include <openssl/ebcdic.h>
81#endif
82
83static unsigned char pad1[16]={
84 0x42,0xE5,0x0C,0xD2,0x24,0xBA,0xCE,0xBA,
85 0x76,0x0B,0xDD,0x2B,0xD4,0x09,0x28,0x1A
86 };
87
88static unsigned char pad2[16]={
89 0x2E,0x46,0x79,0xB5,0xAD,0xD9,0xCA,0x75,
90 0x35,0xD8,0x7A,0xFE,0xAB,0x33,0xBE,0xE2
91 };
92
93int main(int argc, char *argv[])
94 {
95 int ret=0;
96 unsigned char md[MDC2_DIGEST_LENGTH];
97 int i;
98 EVP_MD_CTX c;
99 static char *text="Now is the time for all ";
100
101#ifdef CHARSET_EBCDIC
102 ebcdic2ascii(text,text,strlen(text));
103#endif
104
105 EVP_MD_CTX_init(&c);
106 EVP_DigestInit_ex(&c,EVP_mdc2(), NULL);
107 EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text));
108 EVP_DigestFinal_ex(&c,&(md[0]),NULL);
109
110 if (memcmp(md,pad1,MDC2_DIGEST_LENGTH) != 0)
111 {
112 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
113 printf("%02X",md[i]);
114 printf(" <- generated\n");
115 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
116 printf("%02X",pad1[i]);
117 printf(" <- correct\n");
118 ret=1;
119 }
120 else
121 printf("pad1 - ok\n");
122
123 EVP_DigestInit_ex(&c,EVP_mdc2(), NULL);
124 /* FIXME: use a ctl function? */
125 ((MDC2_CTX *)c.md_data)->pad_type=2;
126 EVP_DigestUpdate(&c,(unsigned char *)text,strlen(text));
127 EVP_DigestFinal_ex(&c,&(md[0]),NULL);
128
129 if (memcmp(md,pad2,MDC2_DIGEST_LENGTH) != 0)
130 {
131 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
132 printf("%02X",md[i]);
133 printf(" <- generated\n");
134 for (i=0; i<MDC2_DIGEST_LENGTH; i++)
135 printf("%02X",pad2[i]);
136 printf(" <- correct\n");
137 ret=1;
138 }
139 else
140 printf("pad2 - ok\n");
141
142 EVP_MD_CTX_cleanup(&c);
143#ifdef OPENSSL_SYS_NETWARE
144 if (ret) printf("ERROR: %d\n", ret);
145#endif
146 EXIT(ret);
147 return(ret);
148 }
149#endif
diff --git a/src/lib/libcrypto/mem.c b/src/lib/libcrypto/mem.c
new file mode 100644
index 0000000000..dd86733b77
--- /dev/null
+++ b/src/lib/libcrypto/mem.c
@@ -0,0 +1,401 @@
1/* crypto/mem.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/crypto.h>
62#include "cryptlib.h"
63
64
65static int allow_customize = 1; /* we provide flexible functions for */
66static int allow_customize_debug = 1;/* exchanging memory-related functions at
67 * run-time, but this must be done
68 * before any blocks are actually
69 * allocated; or we'll run into huge
70 * problems when malloc/free pairs
71 * don't match etc. */
72
73
74
75/* the following pointers may be changed as long as 'allow_customize' is set */
76
77static void *(*malloc_func)(size_t) = malloc;
78static void *default_malloc_ex(size_t num, const char *file, int line)
79 { return malloc_func(num); }
80static void *(*malloc_ex_func)(size_t, const char *file, int line)
81 = default_malloc_ex;
82
83static void *(*realloc_func)(void *, size_t)= realloc;
84static void *default_realloc_ex(void *str, size_t num,
85 const char *file, int line)
86 { return realloc_func(str,num); }
87static void *(*realloc_ex_func)(void *, size_t, const char *file, int line)
88 = default_realloc_ex;
89
90static void (*free_func)(void *) = free;
91
92static void *(*malloc_locked_func)(size_t) = malloc;
93static void *default_malloc_locked_ex(size_t num, const char *file, int line)
94 { return malloc_locked_func(num); }
95static void *(*malloc_locked_ex_func)(size_t, const char *file, int line)
96 = default_malloc_locked_ex;
97
98static void (*free_locked_func)(void *) = free;
99
100
101
102/* may be changed as long as 'allow_customize_debug' is set */
103/* XXX use correct function pointer types */
104#ifdef CRYPTO_MDEBUG
105/* use default functions from mem_dbg.c */
106static void (*malloc_debug_func)(void *,int,const char *,int,int)
107 = CRYPTO_dbg_malloc;
108static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
109 = CRYPTO_dbg_realloc;
110static void (*free_debug_func)(void *,int) = CRYPTO_dbg_free;
111static void (*set_debug_options_func)(long) = CRYPTO_dbg_set_options;
112static long (*get_debug_options_func)(void) = CRYPTO_dbg_get_options;
113#else
114/* applications can use CRYPTO_malloc_debug_init() to select above case
115 * at run-time */
116static void (*malloc_debug_func)(void *,int,const char *,int,int) = NULL;
117static void (*realloc_debug_func)(void *,void *,int,const char *,int,int)
118 = NULL;
119static void (*free_debug_func)(void *,int) = NULL;
120static void (*set_debug_options_func)(long) = NULL;
121static long (*get_debug_options_func)(void) = NULL;
122#endif
123
124
125int CRYPTO_set_mem_functions(void *(*m)(size_t), void *(*r)(void *, size_t),
126 void (*f)(void *))
127 {
128 if (!allow_customize)
129 return 0;
130 if ((m == 0) || (r == 0) || (f == 0))
131 return 0;
132 malloc_func=m; malloc_ex_func=default_malloc_ex;
133 realloc_func=r; realloc_ex_func=default_realloc_ex;
134 free_func=f;
135 malloc_locked_func=m; malloc_locked_ex_func=default_malloc_locked_ex;
136 free_locked_func=f;
137 return 1;
138 }
139
140int CRYPTO_set_mem_ex_functions(
141 void *(*m)(size_t,const char *,int),
142 void *(*r)(void *, size_t,const char *,int),
143 void (*f)(void *))
144 {
145 if (!allow_customize)
146 return 0;
147 if ((m == 0) || (r == 0) || (f == 0))
148 return 0;
149 malloc_func=0; malloc_ex_func=m;
150 realloc_func=0; realloc_ex_func=r;
151 free_func=f;
152 malloc_locked_func=0; malloc_locked_ex_func=m;
153 free_locked_func=f;
154 return 1;
155 }
156
157int CRYPTO_set_locked_mem_functions(void *(*m)(size_t), void (*f)(void *))
158 {
159 if (!allow_customize)
160 return 0;
161 if ((m == NULL) || (f == NULL))
162 return 0;
163 malloc_locked_func=m; malloc_locked_ex_func=default_malloc_locked_ex;
164 free_locked_func=f;
165 return 1;
166 }
167
168int CRYPTO_set_locked_mem_ex_functions(
169 void *(*m)(size_t,const char *,int),
170 void (*f)(void *))
171 {
172 if (!allow_customize)
173 return 0;
174 if ((m == NULL) || (f == NULL))
175 return 0;
176 malloc_locked_func=0; malloc_locked_ex_func=m;
177 free_func=f;
178 return 1;
179 }
180
181int CRYPTO_set_mem_debug_functions(void (*m)(void *,int,const char *,int,int),
182 void (*r)(void *,void *,int,const char *,int,int),
183 void (*f)(void *,int),
184 void (*so)(long),
185 long (*go)(void))
186 {
187 if (!allow_customize_debug)
188 return 0;
189 malloc_debug_func=m;
190 realloc_debug_func=r;
191 free_debug_func=f;
192 set_debug_options_func=so;
193 get_debug_options_func=go;
194 return 1;
195 }
196
197
198void CRYPTO_get_mem_functions(void *(**m)(size_t), void *(**r)(void *, size_t),
199 void (**f)(void *))
200 {
201 if (m != NULL) *m = (malloc_ex_func == default_malloc_ex) ?
202 malloc_func : 0;
203 if (r != NULL) *r = (realloc_ex_func == default_realloc_ex) ?
204 realloc_func : 0;
205 if (f != NULL) *f=free_func;
206 }
207
208void CRYPTO_get_mem_ex_functions(
209 void *(**m)(size_t,const char *,int),
210 void *(**r)(void *, size_t,const char *,int),
211 void (**f)(void *))
212 {
213 if (m != NULL) *m = (malloc_ex_func != default_malloc_ex) ?
214 malloc_ex_func : 0;
215 if (r != NULL) *r = (realloc_ex_func != default_realloc_ex) ?
216 realloc_ex_func : 0;
217 if (f != NULL) *f=free_func;
218 }
219
220void CRYPTO_get_locked_mem_functions(void *(**m)(size_t), void (**f)(void *))
221 {
222 if (m != NULL) *m = (malloc_locked_ex_func == default_malloc_locked_ex) ?
223 malloc_locked_func : 0;
224 if (f != NULL) *f=free_locked_func;
225 }
226
227void CRYPTO_get_locked_mem_ex_functions(
228 void *(**m)(size_t,const char *,int),
229 void (**f)(void *))
230 {
231 if (m != NULL) *m = (malloc_locked_ex_func != default_malloc_locked_ex) ?
232 malloc_locked_ex_func : 0;
233 if (f != NULL) *f=free_locked_func;
234 }
235
236void CRYPTO_get_mem_debug_functions(void (**m)(void *,int,const char *,int,int),
237 void (**r)(void *,void *,int,const char *,int,int),
238 void (**f)(void *,int),
239 void (**so)(long),
240 long (**go)(void))
241 {
242 if (m != NULL) *m=malloc_debug_func;
243 if (r != NULL) *r=realloc_debug_func;
244 if (f != NULL) *f=free_debug_func;
245 if (so != NULL) *so=set_debug_options_func;
246 if (go != NULL) *go=get_debug_options_func;
247 }
248
249
250void *CRYPTO_malloc_locked(int num, const char *file, int line)
251 {
252 void *ret = NULL;
253 extern unsigned char cleanse_ctr;
254
255 if (num <= 0) return NULL;
256
257 allow_customize = 0;
258 if (malloc_debug_func != NULL)
259 {
260 allow_customize_debug = 0;
261 malloc_debug_func(NULL, num, file, line, 0);
262 }
263 ret = malloc_locked_ex_func(num,file,line);
264#ifdef LEVITTE_DEBUG_MEM
265 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
266#endif
267 if (malloc_debug_func != NULL)
268 malloc_debug_func(ret, num, file, line, 1);
269
270 /* Create a dependency on the value of 'cleanse_ctr' so our memory
271 * sanitisation function can't be optimised out. NB: We only do
272 * this for >2Kb so the overhead doesn't bother us. */
273 if(ret && (num > 2048))
274 ((unsigned char *)ret)[0] = cleanse_ctr;
275
276 return ret;
277 }
278
279void CRYPTO_free_locked(void *str)
280 {
281 if (free_debug_func != NULL)
282 free_debug_func(str, 0);
283#ifdef LEVITTE_DEBUG_MEM
284 fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\n", str);
285#endif
286 free_locked_func(str);
287 if (free_debug_func != NULL)
288 free_debug_func(NULL, 1);
289 }
290
291void *CRYPTO_malloc(int num, const char *file, int line)
292 {
293 void *ret = NULL;
294 extern unsigned char cleanse_ctr;
295
296 if (num <= 0) return NULL;
297
298 allow_customize = 0;
299 if (malloc_debug_func != NULL)
300 {
301 allow_customize_debug = 0;
302 malloc_debug_func(NULL, num, file, line, 0);
303 }
304 ret = malloc_ex_func(num,file,line);
305#ifdef LEVITTE_DEBUG_MEM
306 fprintf(stderr, "LEVITTE_DEBUG_MEM: > 0x%p (%d)\n", ret, num);
307#endif
308 if (malloc_debug_func != NULL)
309 malloc_debug_func(ret, num, file, line, 1);
310
311 /* Create a dependency on the value of 'cleanse_ctr' so our memory
312 * sanitisation function can't be optimised out. NB: We only do
313 * this for >2Kb so the overhead doesn't bother us. */
314 if(ret && (num > 2048))
315 ((unsigned char *)ret)[0] = cleanse_ctr;
316
317 return ret;
318 }
319
320void *CRYPTO_realloc(void *str, int num, const char *file, int line)
321 {
322 void *ret = NULL;
323
324 if (str == NULL)
325 return CRYPTO_malloc(num, file, line);
326
327 if (num <= 0) return NULL;
328
329 if (realloc_debug_func != NULL)
330 realloc_debug_func(str, NULL, num, file, line, 0);
331 ret = realloc_ex_func(str,num,file,line);
332#ifdef LEVITTE_DEBUG_MEM
333 fprintf(stderr, "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n", str, ret, num);
334#endif
335 if (realloc_debug_func != NULL)
336 realloc_debug_func(str, ret, num, file, line, 1);
337
338 return ret;
339 }
340
341void *CRYPTO_realloc_clean(void *str, int old_len, int num, const char *file,
342 int line)
343 {
344 void *ret = NULL;
345
346 if (str == NULL)
347 return CRYPTO_malloc(num, file, line);
348
349 if (num <= 0) return NULL;
350
351 if (realloc_debug_func != NULL)
352 realloc_debug_func(str, NULL, num, file, line, 0);
353 ret=malloc_ex_func(num,file,line);
354 if(ret)
355 {
356 memcpy(ret,str,old_len);
357 OPENSSL_cleanse(str,old_len);
358 free_func(str);
359 }
360#ifdef LEVITTE_DEBUG_MEM
361 fprintf(stderr,
362 "LEVITTE_DEBUG_MEM: | 0x%p -> 0x%p (%d)\n",
363 str, ret, num);
364#endif
365 if (realloc_debug_func != NULL)
366 realloc_debug_func(str, ret, num, file, line, 1);
367
368 return ret;
369 }
370
371void CRYPTO_free(void *str)
372 {
373 if (free_debug_func != NULL)
374 free_debug_func(str, 0);
375#ifdef LEVITTE_DEBUG_MEM
376 fprintf(stderr, "LEVITTE_DEBUG_MEM: < 0x%p\n", str);
377#endif
378 free_func(str);
379 if (free_debug_func != NULL)
380 free_debug_func(NULL, 1);
381 }
382
383void *CRYPTO_remalloc(void *a, int num, const char *file, int line)
384 {
385 if (a != NULL) OPENSSL_free(a);
386 a=(char *)OPENSSL_malloc(num);
387 return(a);
388 }
389
390void CRYPTO_set_mem_debug_options(long bits)
391 {
392 if (set_debug_options_func != NULL)
393 set_debug_options_func(bits);
394 }
395
396long CRYPTO_get_mem_debug_options(void)
397 {
398 if (get_debug_options_func != NULL)
399 return get_debug_options_func();
400 return 0;
401 }
diff --git a/src/lib/libcrypto/mem_dbg.c b/src/lib/libcrypto/mem_dbg.c
index 8316485217..e212de27e4 100644
--- a/src/lib/libcrypto/mem_dbg.c
+++ b/src/lib/libcrypto/mem_dbg.c
@@ -59,11 +59,11 @@
59#include <stdio.h> 59#include <stdio.h>
60#include <stdlib.h> 60#include <stdlib.h>
61#include <time.h> 61#include <time.h>
62#include "cryptlib.h"
63#include <openssl/crypto.h> 62#include <openssl/crypto.h>
64#include <openssl/buffer.h> 63#include <openssl/buffer.h>
65#include <openssl/bio.h> 64#include <openssl/bio.h>
66#include <openssl/lhash.h> 65#include <openssl/lhash.h>
66#include "cryptlib.h"
67 67
68static int mh_mode=CRYPTO_MEM_CHECK_OFF; 68static int mh_mode=CRYPTO_MEM_CHECK_OFF;
69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE 69/* The state changes to CRYPTO_MEM_CHECK_ON | CRYPTO_MEM_CHECK_ENABLE
@@ -252,16 +252,8 @@ long CRYPTO_dbg_get_options(void)
252/* static int mem_cmp(MEM *a, MEM *b) */ 252/* static int mem_cmp(MEM *a, MEM *b) */
253static int mem_cmp(const void *a_void, const void *b_void) 253static int mem_cmp(const void *a_void, const void *b_void)
254 { 254 {
255#ifdef _WIN64
256 const char *a=(const char *)((const MEM *)a_void)->addr,
257 *b=(const char *)((const MEM *)b_void)->addr;
258 if (a==b) return 0;
259 else if (a>b) return 1;
260 else return -1;
261#else
262 return((const char *)((const MEM *)a_void)->addr 255 return((const char *)((const MEM *)a_void)->addr
263 - (const char *)((const MEM *)b_void)->addr); 256 - (const char *)((const MEM *)b_void)->addr);
264#endif
265 } 257 }
266 258
267/* static unsigned long mem_hash(MEM *a) */ 259/* static unsigned long mem_hash(MEM *a) */
diff --git a/src/lib/libcrypto/o_dir.c b/src/lib/libcrypto/o_dir.c
new file mode 100644
index 0000000000..42891ea459
--- /dev/null
+++ b/src/lib/libcrypto/o_dir.c
@@ -0,0 +1,83 @@
1/* crypto/o_dir.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2004.
4 */
5/* ====================================================================
6 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <errno.h>
60#include <e_os.h>
61
62/* The routines really come from the Levitte Programming, so to make
63 life simple, let's just use the raw files and hack the symbols to
64 fit our namespace. */
65#define LP_DIR_CTX OPENSSL_DIR_CTX
66#define LP_dir_context_st OPENSSL_dir_context_st
67#define LP_find_file OPENSSL_DIR_read
68#define LP_find_file_end OPENSSL_DIR_end
69
70#include "o_dir.h"
71
72#define LPDIR_H
73#if defined OPENSSL_SYS_UNIX || defined DJGPP
74#include "LPdir_unix.c"
75#elif defined OPENSSL_SYS_VMS
76#include "LPdir_vms.c"
77#elif defined OPENSSL_SYS_WIN32
78#include "LPdir_win32.c"
79#elif defined OPENSSL_SYS_WINCE
80#include "LPdir_wince.c"
81#else
82#include "LPdir_nyi.c"
83#endif
diff --git a/src/lib/libcrypto/o_dir.h b/src/lib/libcrypto/o_dir.h
new file mode 100644
index 0000000000..4b725c0312
--- /dev/null
+++ b/src/lib/libcrypto/o_dir.h
@@ -0,0 +1,53 @@
1/* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */
2/* Copied from Richard Levitte's (richard@levitte.org) LP library. All
3 * symbol names have been changed, with permission from the author.
4 */
5
6/* $LP: LPlib/source/LPdir.h,v 1.1 2004/06/14 08:56:04 _cvs_levitte Exp $ */
7/*
8 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33
34#ifndef O_DIR_H
35#define O_DIR_H
36
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41 typedef struct OPENSSL_dir_context_st OPENSSL_DIR_CTX;
42
43 /* returns NULL on error or end-of-directory.
44 If it is end-of-directory, errno will be zero */
45 const char *OPENSSL_DIR_read(OPENSSL_DIR_CTX **ctx, const char *directory);
46 /* returns 1 on success, 0 on error */
47 int OPENSSL_DIR_end(OPENSSL_DIR_CTX **ctx);
48
49#ifdef __cplusplus
50}
51#endif
52
53#endif /* LPDIR_H */
diff --git a/src/lib/libcrypto/o_dir_test.c b/src/lib/libcrypto/o_dir_test.c
new file mode 100644
index 0000000000..3d75ecb005
--- /dev/null
+++ b/src/lib/libcrypto/o_dir_test.c
@@ -0,0 +1,70 @@
1/* crypto/o_dir.h -*- mode:C; c-file-style: "eay" -*- */
2/* Copied from Richard Levitte's (richard@levitte.org) LP library. All
3 * symbol names have been changed, with permission from the author.
4 */
5
6/* $LP: LPlib/test/test_dir.c,v 1.1 2004/06/16 22:59:47 _cvs_levitte Exp $ */
7/*
8 * Copyright (c) 2004, Richard Levitte <richard@levitte.org>
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#include <stddef.h>
34#include <stdlib.h>
35#include <stdio.h>
36#include <errno.h>
37#include "e_os2.h"
38#include "o_dir.h"
39
40#if defined OPENSSL_SYS_UNIX || defined OPENSSL_SYS_WIN32 || defined OPENSSL_SYS_WINCE
41#define CURRDIR "."
42#elif defined OPENSSL_SYS_VMS
43#define CURRDIR "SYS$DISK:[]"
44#else
45#error "No supported platform defined!"
46#endif
47
48int main()
49{
50 OPENSSL_DIR_CTX *ctx = NULL;
51 const char *result;
52
53 while((result = OPENSSL_DIR_read(&ctx, CURRDIR)) != NULL)
54 {
55 printf("%s\n", result);
56 }
57
58 if (errno)
59 {
60 perror("test_dir");
61 exit(1);
62 }
63
64 if (!OPENSSL_DIR_end(&ctx))
65 {
66 perror("test_dir");
67 exit(2);
68 }
69 exit(0);
70}
diff --git a/src/lib/libcrypto/o_str.h b/src/lib/libcrypto/o_str.h
new file mode 100644
index 0000000000..dfc98494c6
--- /dev/null
+++ b/src/lib/libcrypto/o_str.h
@@ -0,0 +1,68 @@
1/* crypto/o_str.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_O_STR_H
60#define HEADER_O_STR_H
61
62#include <stddef.h> /* to get size_t */
63
64int OPENSSL_strcasecmp(const char *str1, const char *str2);
65int OPENSSL_strncasecmp(const char *str1, const char *str2, size_t n);
66int OPENSSL_memcmp(const void *p1,const void *p2,size_t n);
67
68#endif
diff --git a/src/lib/libcrypto/objects/Makefile b/src/lib/libcrypto/objects/Makefile
new file mode 100644
index 0000000000..9c5615099c
--- /dev/null
+++ b/src/lib/libcrypto/objects/Makefile
@@ -0,0 +1,119 @@
1#
2# OpenSSL/crypto/objects/Makefile
3#
4
5DIR= objects
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12PERL= perl
13
14CFLAGS= $(INCLUDES) $(CFLAG)
15
16GENERAL=Makefile README
17TEST=
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c
22LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= objects.h obj_mac.h
27HEADER= $(EXHEADER) obj_dat.h
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: obj_dat.h lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41obj_dat.h: obj_dat.pl obj_mac.h
42 $(PERL) obj_dat.pl obj_mac.h obj_dat.h
43
44# objects.pl both reads and writes obj_mac.num
45obj_mac.h: objects.pl objects.txt obj_mac.num
46 $(PERL) objects.pl objects.txt obj_mac.num obj_mac.h
47 @sleep 1; touch obj_mac.h; sleep 1
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
51
52links:
53 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
54 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
55 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
56
57install:
58 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
59 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
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 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
75 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
76
77dclean:
78 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
79 mv -f Makefile.new $(MAKEFILE)
80
81clean:
82 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
83
84# DO NOT DELETE THIS LINE -- make depend depends on it.
85
86o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87o_names.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
88o_names.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
89o_names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
90o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
91o_names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
92o_names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
93o_names.o: o_names.c
94obj_dat.o: ../../e_os.h ../../include/openssl/asn1.h
95obj_dat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
96obj_dat.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
97obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
98obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
99obj_dat.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
100obj_dat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
102obj_dat.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_dat.c obj_dat.h
103obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
104obj_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
105obj_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
106obj_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
107obj_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
108obj_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
109obj_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
110obj_err.o: obj_err.c
111obj_lib.o: ../../e_os.h ../../include/openssl/asn1.h
112obj_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
113obj_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
114obj_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
115obj_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
116obj_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
117obj_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
118obj_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
119obj_lib.o: ../cryptlib.h obj_lib.c
diff --git a/src/lib/libcrypto/objects/Makefile.ssl b/src/lib/libcrypto/objects/Makefile.ssl
new file mode 100644
index 0000000000..3e7a194cf9
--- /dev/null
+++ b/src/lib/libcrypto/objects/Makefile.ssl
@@ -0,0 +1,123 @@
1#
2# SSLeay/crypto/objects/Makefile
3#
4
5DIR= objects
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18PERL= perl
19
20CFLAGS= $(INCLUDES) $(CFLAG)
21
22GENERAL=Makefile README
23TEST=
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC= o_names.c obj_dat.c obj_lib.c obj_err.c
28LIBOBJ= o_names.o obj_dat.o obj_lib.o obj_err.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= objects.h obj_mac.h
33HEADER= $(EXHEADER) obj_dat.h
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: obj_dat.h lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47obj_dat.h: obj_dat.pl obj_mac.h
48 $(PERL) obj_dat.pl obj_mac.h obj_dat.h
49
50# objects.pl both reads and writes obj_mac.num
51obj_mac.h: objects.pl objects.txt obj_mac.num
52 $(PERL) objects.pl objects.txt obj_mac.num obj_mac.h
53
54files:
55 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
56
57links:
58 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
59 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
60 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
61 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
62
63install:
64 @for i in $(EXHEADER) ; \
65 do \
66 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
67 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
68 done;
69
70tags:
71 ctags $(SRC)
72
73tests:
74
75lint:
76 lint -DLINT $(INCLUDES) $(SRC)>fluff
77
78depend:
79 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
80
81dclean:
82 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
83 mv -f Makefile.new $(MAKEFILE)
84
85clean:
86 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
87
88# DO NOT DELETE THIS LINE -- make depend depends on it.
89
90o_names.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
91o_names.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
92o_names.o: ../../include/openssl/e_os2.h ../../include/openssl/lhash.h
93o_names.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
94o_names.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95o_names.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
96o_names.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97o_names.o: o_names.c
98obj_dat.o: ../../e_os.h ../../include/openssl/asn1.h
99obj_dat.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
100obj_dat.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101obj_dat.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102obj_dat.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
103obj_dat.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104obj_dat.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105obj_dat.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
106obj_dat.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_dat.c obj_dat.h
107obj_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
108obj_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
109obj_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
110obj_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
111obj_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
112obj_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113obj_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
114obj_err.o: ../../include/openssl/symhacks.h obj_err.c
115obj_lib.o: ../../e_os.h ../../include/openssl/asn1.h
116obj_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
117obj_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
118obj_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
119obj_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
120obj_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
121obj_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122obj_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123obj_lib.o: ../../include/openssl/symhacks.h ../cryptlib.h obj_lib.c
diff --git a/src/lib/libcrypto/objects/o_names.c b/src/lib/libcrypto/objects/o_names.c
index adb5731f76..28c9370ca3 100644
--- a/src/lib/libcrypto/objects/o_names.c
+++ b/src/lib/libcrypto/objects/o_names.c
@@ -111,8 +111,8 @@ int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
111static int obj_name_cmp(const void *a_void, const void *b_void) 111static int obj_name_cmp(const void *a_void, const void *b_void)
112 { 112 {
113 int ret; 113 int ret;
114 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 114 OBJ_NAME *a = (OBJ_NAME *)a_void;
115 const OBJ_NAME *b = (const OBJ_NAME *)b_void; 115 OBJ_NAME *b = (OBJ_NAME *)b_void;
116 116
117 ret=a->type-b->type; 117 ret=a->type-b->type;
118 if (ret == 0) 118 if (ret == 0)
@@ -133,7 +133,7 @@ static int obj_name_cmp(const void *a_void, const void *b_void)
133static unsigned long obj_name_hash(const void *a_void) 133static unsigned long obj_name_hash(const void *a_void)
134 { 134 {
135 unsigned long ret; 135 unsigned long ret;
136 const OBJ_NAME *a = (const OBJ_NAME *)a_void; 136 OBJ_NAME *a = (OBJ_NAME *)a_void;
137 137
138 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) 138 if ((name_funcs_stack != NULL) && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
139 { 139 {
diff --git a/src/lib/libcrypto/objects/obj_dat.c b/src/lib/libcrypto/objects/obj_dat.c
index 7fd7433241..f549d078ef 100644
--- a/src/lib/libcrypto/objects/obj_dat.c
+++ b/src/lib/libcrypto/objects/obj_dat.c
@@ -58,12 +58,10 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include <ctype.h> 60#include <ctype.h>
61#include <limits.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
63#include <openssl/lhash.h> 62#include <openssl/lhash.h>
64#include <openssl/asn1.h> 63#include <openssl/asn1.h>
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/bn.h>
67 65
68/* 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 */
69#ifndef OPENSSL_NO_OBJECT 67#ifndef OPENSSL_NO_OBJECT
@@ -117,7 +115,7 @@ static unsigned long add_hash(const void *ca_void)
117 int i; 115 int i;
118 unsigned long ret=0; 116 unsigned long ret=0;
119 unsigned char *p; 117 unsigned char *p;
120 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void; 118 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
121 119
122 a=ca->obj; 120 a=ca->obj;
123 switch (ca->type) 121 switch (ca->type)
@@ -151,8 +149,8 @@ static int add_cmp(const void *ca_void, const void *cb_void)
151 { 149 {
152 ASN1_OBJECT *a,*b; 150 ASN1_OBJECT *a,*b;
153 int i; 151 int i;
154 const ADDED_OBJ *ca = (const ADDED_OBJ *)ca_void; 152 ADDED_OBJ *ca = (ADDED_OBJ *)ca_void;
155 const ADDED_OBJ *cb = (const ADDED_OBJ *)cb_void; 153 ADDED_OBJ *cb = (ADDED_OBJ *)cb_void;
156 154
157 i=ca->type-cb->type; 155 i=ca->type-cb->type;
158 if (i) return(i); 156 if (i) return(i);
@@ -163,7 +161,7 @@ static int add_cmp(const void *ca_void, const void *cb_void)
163 case ADDED_DATA: 161 case ADDED_DATA:
164 i=(a->length - b->length); 162 i=(a->length - b->length);
165 if (i) return(i); 163 if (i) return(i);
166 return(memcmp(a->data,b->data,(size_t)a->length)); 164 return(memcmp(a->data,b->data,a->length));
167 case ADDED_SNAME: 165 case ADDED_SNAME:
168 if (a->sn == NULL) return(-1); 166 if (a->sn == NULL) return(-1);
169 else if (b->sn == NULL) return(1); 167 else if (b->sn == NULL) return(1);
@@ -384,8 +382,8 @@ int OBJ_obj2nid(const ASN1_OBJECT *a)
384 adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 382 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
385 if (adp != NULL) return (adp->obj->nid); 383 if (adp != NULL) return (adp->obj->nid);
386 } 384 }
387 op=(ASN1_OBJECT **)OBJ_bsearch((const char *)&a,(const char *)obj_objs, 385 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&a,(char *)obj_objs,NUM_OBJ,
388 NUM_OBJ, sizeof(ASN1_OBJECT *),obj_cmp); 386 sizeof(ASN1_OBJECT *),obj_cmp);
389 if (op == NULL) 387 if (op == NULL)
390 return(NID_undef); 388 return(NID_undef);
391 return((*op)->nid); 389 return((*op)->nid);
@@ -401,9 +399,7 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
401 { 399 {
402 int nid = NID_undef; 400 int nid = NID_undef;
403 ASN1_OBJECT *op=NULL; 401 ASN1_OBJECT *op=NULL;
404 unsigned char *buf; 402 unsigned char *buf,*p;
405 unsigned char *p;
406 const unsigned char *cp;
407 int i, j; 403 int i, j;
408 404
409 if(!no_name) { 405 if(!no_name) {
@@ -415,8 +411,8 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
415 /* Work out size of content octets */ 411 /* Work out size of content octets */
416 i=a2d_ASN1_OBJECT(NULL,0,s,-1); 412 i=a2d_ASN1_OBJECT(NULL,0,s,-1);
417 if (i <= 0) { 413 if (i <= 0) {
418 /* Don't clear the error */ 414 /* Clear the error */
419 /*ERR_clear_error();*/ 415 ERR_get_error();
420 return NULL; 416 return NULL;
421 } 417 }
422 /* Work out total size */ 418 /* Work out total size */
@@ -429,170 +425,75 @@ ASN1_OBJECT *OBJ_txt2obj(const char *s, int no_name)
429 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL); 425 ASN1_put_object(&p,0,i,V_ASN1_OBJECT,V_ASN1_UNIVERSAL);
430 /* Write out contents */ 426 /* Write out contents */
431 a2d_ASN1_OBJECT(p,i,s,-1); 427 a2d_ASN1_OBJECT(p,i,s,-1);
432 428
433 cp=buf; 429 p=buf;
434 op=d2i_ASN1_OBJECT(NULL,&cp,j); 430 op=d2i_ASN1_OBJECT(NULL,&p,j);
435 OPENSSL_free(buf); 431 OPENSSL_free(buf);
436 return op; 432 return op;
437 } 433 }
438 434
439int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name) 435int OBJ_obj2txt(char *buf, int buf_len, const ASN1_OBJECT *a, int no_name)
440{ 436{
441 int i,n=0,len,nid, first, use_bn; 437 int i,idx=0,n=0,len,nid;
442 BIGNUM *bl;
443 unsigned long l; 438 unsigned long l;
444 unsigned char *p; 439 unsigned char *p;
440 const char *s;
445 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2]; 441 char tbuf[DECIMAL_SIZE(i)+DECIMAL_SIZE(l)+2];
446 442
443 if (buf_len <= 0) return(0);
444
447 if ((a == NULL) || (a->data == NULL)) { 445 if ((a == NULL) || (a->data == NULL)) {
448 buf[0]='\0'; 446 buf[0]='\0';
449 return(0); 447 return(0);
450 } 448 }
451 449
450 if (no_name || (nid=OBJ_obj2nid(a)) == NID_undef) {
451 len=a->length;
452 p=a->data;
452 453
453 if (!no_name && (nid=OBJ_obj2nid(a)) != NID_undef) 454 idx=0;
454 { 455 l=0;
455 const char *s; 456 while (idx < a->length) {
456 s=OBJ_nid2ln(nid); 457 l|=(p[idx]&0x7f);
457 if (s == NULL) 458 if (!(p[idx] & 0x80)) break;
458 s=OBJ_nid2sn(nid); 459 l<<=7L;
459 if (buf) 460 idx++;
460 BUF_strlcpy(buf,s,buf_len);
461 n=strlen(s);
462 return n;
463 } 461 }
462 idx++;
463 i=(int)(l/40);
464 if (i > 2) i=2;
465 l-=(long)(i*40);
466
467 BIO_snprintf(tbuf,sizeof tbuf,"%d.%lu",i,l);
468 i=strlen(tbuf);
469 BUF_strlcpy(buf,tbuf,buf_len);
470 buf_len-=i;
471 buf+=i;
472 n+=i;
464 473
465
466 len=a->length;
467 p=a->data;
468
469 first = 1;
470 bl = NULL;
471
472 while (len > 0)
473 {
474 l=0; 474 l=0;
475 use_bn = 0; 475 for (; idx<len; idx++) {
476 for (;;) 476 l|=p[idx]&0x7f;
477 { 477 if (!(p[idx] & 0x80)) {
478 unsigned char c = *p++; 478 BIO_snprintf(tbuf,sizeof tbuf,".%lu",l);
479 len--; 479 i=strlen(tbuf);
480 if ((len == 0) && (c & 0x80))
481 goto err;
482 if (use_bn)
483 {
484 if (!BN_add_word(bl, c & 0x7f))
485 goto err;
486 }
487 else
488 l |= c & 0x7f;
489 if (!(c & 0x80))
490 break;
491 if (!use_bn && (l > (ULONG_MAX >> 7L)))
492 {
493 if (!bl && !(bl = BN_new()))
494 goto err;
495 if (!BN_set_word(bl, l))
496 goto err;
497 use_bn = 1;
498 }
499 if (use_bn)
500 {
501 if (!BN_lshift(bl, bl, 7))
502 goto err;
503 }
504 else
505 l<<=7L;
506 }
507
508 if (first)
509 {
510 first = 0;
511 if (l >= 80)
512 {
513 i = 2;
514 if (use_bn)
515 {
516 if (!BN_sub_word(bl, 80))
517 goto err;
518 }
519 else
520 l -= 80;
521 }
522 else
523 {
524 i=(int)(l/40);
525 l-=(long)(i*40);
526 }
527 if (buf && (buf_len > 0))
528 {
529 *buf++ = i + '0';
530 buf_len--;
531 }
532 n++;
533 }
534
535 if (use_bn)
536 {
537 char *bndec;
538 bndec = BN_bn2dec(bl);
539 if (!bndec)
540 goto err;
541 i = strlen(bndec);
542 if (buf)
543 {
544 if (buf_len > 0) 480 if (buf_len > 0)
545 { 481 BUF_strlcpy(buf,tbuf,buf_len);
546 *buf++ = '.'; 482 buf_len-=i;
547 buf_len--; 483 buf+=i;
548 } 484 n+=i;
549 BUF_strlcpy(buf,bndec,buf_len); 485 l=0;
550 if (i > buf_len)
551 {
552 buf += buf_len;
553 buf_len = 0;
554 }
555 else
556 {
557 buf+=i;
558 buf_len-=i;
559 }
560 }
561 n++;
562 n += i;
563 OPENSSL_free(bndec);
564 }
565 else
566 {
567 BIO_snprintf(tbuf,sizeof tbuf,".%lu",l);
568 i=strlen(tbuf);
569 if (buf && (buf_len > 0))
570 {
571 BUF_strlcpy(buf,tbuf,buf_len);
572 if (i > buf_len)
573 {
574 buf += buf_len;
575 buf_len = 0;
576 }
577 else
578 {
579 buf+=i;
580 buf_len-=i;
581 }
582 }
583 n+=i;
584 l=0;
585 } 486 }
487 l<<=7L;
586 } 488 }
587 489 } else {
588 if (bl) 490 s=OBJ_nid2ln(nid);
589 BN_free(bl); 491 if (s == NULL)
590 return n; 492 s=OBJ_nid2sn(nid);
591 493 BUF_strlcpy(buf,s,buf_len);
592 err: 494 n=strlen(s);
593 if (bl) 495 }
594 BN_free(bl); 496 return(n);
595 return -1;
596} 497}
597 498
598int OBJ_txt2nid(const char *s) 499int OBJ_txt2nid(const char *s)
@@ -618,7 +519,7 @@ int OBJ_ln2nid(const char *s)
618 adp=(ADDED_OBJ *)lh_retrieve(added,&ad); 519 adp=(ADDED_OBJ *)lh_retrieve(added,&ad);
619 if (adp != NULL) return (adp->obj->nid); 520 if (adp != NULL) return (adp->obj->nid);
620 } 521 }
621 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs, NUM_LN, 522 op=(ASN1_OBJECT **)OBJ_bsearch((char *)&oo,(char *)ln_objs,NUM_LN,
622 sizeof(ASN1_OBJECT *),ln_cmp); 523 sizeof(ASN1_OBJECT *),ln_cmp);
623 if (op == NULL) return(NID_undef); 524 if (op == NULL) return(NID_undef);
624 return((*op)->nid); 525 return((*op)->nid);
@@ -646,8 +547,8 @@ int OBJ_sn2nid(const char *s)
646static int obj_cmp(const void *ap, const void *bp) 547static int obj_cmp(const void *ap, const void *bp)
647 { 548 {
648 int j; 549 int j;
649 const ASN1_OBJECT *a= *(ASN1_OBJECT * const *)ap; 550 ASN1_OBJECT *a= *(ASN1_OBJECT **)ap;
650 const ASN1_OBJECT *b= *(ASN1_OBJECT * const *)bp; 551 ASN1_OBJECT *b= *(ASN1_OBJECT **)bp;
651 552
652 j=(a->length - b->length); 553 j=(a->length - b->length);
653 if (j) return(j); 554 if (j) return(j);
@@ -657,14 +558,8 @@ static int obj_cmp(const void *ap, const void *bp)
657const char *OBJ_bsearch(const char *key, const char *base, int num, int size, 558const char *OBJ_bsearch(const char *key, const char *base, int num, int size,
658 int (*cmp)(const void *, const void *)) 559 int (*cmp)(const void *, const void *))
659 { 560 {
660 return OBJ_bsearch_ex(key, base, num, size, cmp, 0); 561 int l,h,i,c;
661 } 562 const char *p;
662
663const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
664 int size, int (*cmp)(const void *, const void *), int flags)
665 {
666 int l,h,i=0,c=0;
667 const char *p = NULL;
668 563
669 if (num == 0) return(NULL); 564 if (num == 0) return(NULL);
670 l=0; 565 l=0;
@@ -679,33 +574,20 @@ const char *OBJ_bsearch_ex(const char *key, const char *base, int num,
679 else if (c > 0) 574 else if (c > 0)
680 l=i+1; 575 l=i+1;
681 else 576 else
682 break; 577 return(p);
683 } 578 }
684#ifdef CHARSET_EBCDIC 579#ifdef CHARSET_EBCDIC
685/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and 580/* THIS IS A KLUDGE - Because the *_obj is sorted in ASCII order, and
686 * I don't have perl (yet), we revert to a *LINEAR* search 581 * I don't have perl (yet), we revert to a *LINEAR* search
687 * when the object wasn't found in the binary search. 582 * when the object wasn't found in the binary search.
688 */ 583 */
689 if (c != 0) 584 for (i=0; i<num; ++i) {
690 { 585 p= &(base[i*size]);
691 for (i=0; i<num; ++i) 586 if ((*cmp)(key,p) == 0)
692 { 587 return p;
693 p= &(base[i*size]); 588 }
694 c = (*cmp)(key,p);
695 if (c == 0 || (c < 0 && (flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)))
696 return p;
697 }
698 }
699#endif 589#endif
700 if (c != 0 && !(flags & OBJ_BSEARCH_VALUE_ON_NOMATCH)) 590 return(NULL);
701 p = NULL;
702 else if (c == 0 && (flags & OBJ_BSEARCH_FIRST_VALUE_ON_MATCH))
703 {
704 while(i > 0 && (*cmp)(key,&(base[(i-1)*size])) == 0)
705 i--;
706 p = &(base[i*size]);
707 }
708 return(p);
709 } 591 }
710 592
711int OBJ_create_objects(BIO *in) 593int OBJ_create_objects(BIO *in)
diff --git a/src/lib/libcrypto/objects/obj_dat.pl b/src/lib/libcrypto/objects/obj_dat.pl
index 8a09a46ee6..d0371661f9 100644
--- a/src/lib/libcrypto/objects/obj_dat.pl
+++ b/src/lib/libcrypto/objects/obj_dat.pl
@@ -94,7 +94,7 @@ for ($i=0; $i<$n; $i++)
94 { 94 {
95 if (!defined($nid{$i})) 95 if (!defined($nid{$i}))
96 { 96 {
97 push(@out,"{NULL,NULL,NID_undef,0,NULL,0},\n"); 97 push(@out,"{NULL,NULL,NID_undef,0,NULL},\n");
98 } 98 }
99 else 99 else
100 { 100 {
@@ -138,7 +138,7 @@ for ($i=0; $i<$n; $i++)
138 } 138 }
139 else 139 else
140 { 140 {
141 $out.="0,NULL,0"; 141 $out.="0,NULL";
142 } 142 }
143 $out.="},\n"; 143 $out.="},\n";
144 push(@out,$out); 144 push(@out,$out);
diff --git a/src/lib/libcrypto/objects/obj_err.c b/src/lib/libcrypto/objects/obj_err.c
index 12b48850c6..0682979b38 100644
--- a/src/lib/libcrypto/objects/obj_err.c
+++ b/src/lib/libcrypto/objects/obj_err.c
@@ -91,12 +91,15 @@ static ERR_STRING_DATA OBJ_str_reasons[]=
91 91
92void ERR_load_OBJ_strings(void) 92void ERR_load_OBJ_strings(void)
93 { 93 {
94#ifndef OPENSSL_NO_ERR 94 static int init=1;
95 95
96 if (ERR_func_error_string(OBJ_str_functs[0].error) == NULL) 96 if (init)
97 { 97 {
98 init=0;
99#ifndef OPENSSL_NO_ERR
98 ERR_load_strings(0,OBJ_str_functs); 100 ERR_load_strings(0,OBJ_str_functs);
99 ERR_load_strings(0,OBJ_str_reasons); 101 ERR_load_strings(0,OBJ_str_reasons);
100 }
101#endif 102#endif
103
104 }
102 } 105 }
diff --git a/src/lib/libcrypto/objects/obj_lib.c b/src/lib/libcrypto/objects/obj_lib.c
index 706fa0b0e7..b0b0f2ff24 100644
--- a/src/lib/libcrypto/objects/obj_lib.c
+++ b/src/lib/libcrypto/objects/obj_lib.c
@@ -82,8 +82,7 @@ ASN1_OBJECT *OBJ_dup(const ASN1_OBJECT *o)
82 r->data=OPENSSL_malloc(o->length); 82 r->data=OPENSSL_malloc(o->length);
83 if (r->data == NULL) 83 if (r->data == NULL)
84 goto err; 84 goto err;
85 if (o->data != NULL) 85 memcpy(r->data,o->data,o->length);
86 memcpy(r->data,o->data,o->length);
87 r->length=o->length; 86 r->length=o->length;
88 r->nid=o->nid; 87 r->nid=o->nid;
89 r->ln=r->sn=NULL; 88 r->ln=r->sn=NULL;
diff --git a/src/lib/libcrypto/objects/obj_mac.num b/src/lib/libcrypto/objects/obj_mac.num
index 47815b1e4e..84555d936e 100644
--- a/src/lib/libcrypto/objects/obj_mac.num
+++ b/src/lib/libcrypto/objects/obj_mac.num
@@ -673,118 +673,3 @@ sha256 672
673sha384 673 673sha384 673
674sha512 674 674sha512 674
675sha224 675 675sha224 675
676identified_organization 676
677certicom_arc 677
678wap 678
679wap_wsg 679
680X9_62_id_characteristic_two_basis 680
681X9_62_onBasis 681
682X9_62_tpBasis 682
683X9_62_ppBasis 683
684X9_62_c2pnb163v1 684
685X9_62_c2pnb163v2 685
686X9_62_c2pnb163v3 686
687X9_62_c2pnb176v1 687
688X9_62_c2tnb191v1 688
689X9_62_c2tnb191v2 689
690X9_62_c2tnb191v3 690
691X9_62_c2onb191v4 691
692X9_62_c2onb191v5 692
693X9_62_c2pnb208w1 693
694X9_62_c2tnb239v1 694
695X9_62_c2tnb239v2 695
696X9_62_c2tnb239v3 696
697X9_62_c2onb239v4 697
698X9_62_c2onb239v5 698
699X9_62_c2pnb272w1 699
700X9_62_c2pnb304w1 700
701X9_62_c2tnb359v1 701
702X9_62_c2pnb368w1 702
703X9_62_c2tnb431r1 703
704secp112r1 704
705secp112r2 705
706secp128r1 706
707secp128r2 707
708secp160k1 708
709secp160r1 709
710secp160r2 710
711secp192k1 711
712secp224k1 712
713secp224r1 713
714secp256k1 714
715secp384r1 715
716secp521r1 716
717sect113r1 717
718sect113r2 718
719sect131r1 719
720sect131r2 720
721sect163k1 721
722sect163r1 722
723sect163r2 723
724sect193r1 724
725sect193r2 725
726sect233k1 726
727sect233r1 727
728sect239k1 728
729sect283k1 729
730sect283r1 730
731sect409k1 731
732sect409r1 732
733sect571k1 733
734sect571r1 734
735wap_wsg_idm_ecid_wtls1 735
736wap_wsg_idm_ecid_wtls3 736
737wap_wsg_idm_ecid_wtls4 737
738wap_wsg_idm_ecid_wtls5 738
739wap_wsg_idm_ecid_wtls6 739
740wap_wsg_idm_ecid_wtls7 740
741wap_wsg_idm_ecid_wtls8 741
742wap_wsg_idm_ecid_wtls9 742
743wap_wsg_idm_ecid_wtls10 743
744wap_wsg_idm_ecid_wtls11 744
745wap_wsg_idm_ecid_wtls12 745
746any_policy 746
747policy_mappings 747
748inhibit_any_policy 748
749ipsec3 749
750ipsec4 750
751camellia_128_cbc 751
752camellia_192_cbc 752
753camellia_256_cbc 753
754camellia_128_ecb 754
755camellia_192_ecb 755
756camellia_256_ecb 756
757camellia_128_cfb128 757
758camellia_192_cfb128 758
759camellia_256_cfb128 759
760camellia_128_cfb1 760
761camellia_192_cfb1 761
762camellia_256_cfb1 762
763camellia_128_cfb8 763
764camellia_192_cfb8 764
765camellia_256_cfb8 765
766camellia_128_ofb128 766
767camellia_192_ofb128 767
768camellia_256_ofb128 768
769subject_directory_attributes 769
770issuing_distribution_point 770
771certificate_issuer 771
772korea 772
773kisa 773
774kftc 774
775npki_alg 775
776seed_ecb 776
777seed_cbc 777
778seed_ofb128 778
779seed_cfb128 779
780hmac_md5 780
781hmac_sha1 781
782id_PasswordBasedMAC 782
783id_DHBasedMac 783
784id_it_suppLangTags 784
785caRepository 785
786id_smime_ct_compressedData 786
787id_ct_asciiTextWithCRLF 787
788id_aes128_wrap 788
789id_aes192_wrap 789
790id_aes256_wrap 790
diff --git a/src/lib/libcrypto/objects/objects.h b/src/lib/libcrypto/objects/objects.h
index 7242f76fb0..f859d859b8 100644
--- a/src/lib/libcrypto/objects/objects.h
+++ b/src/lib/libcrypto/objects/objects.h
@@ -966,10 +966,7 @@
966#define OBJ_NAME_TYPE_COMP_METH 0x04 966#define OBJ_NAME_TYPE_COMP_METH 0x04
967#define OBJ_NAME_TYPE_NUM 0x05 967#define OBJ_NAME_TYPE_NUM 0x05
968 968
969#define OBJ_NAME_ALIAS 0x8000 969#define OBJ_NAME_ALIAS 0x8000
970
971#define OBJ_BSEARCH_VALUE_ON_NOMATCH 0x01
972#define OBJ_BSEARCH_FIRST_VALUE_ON_MATCH 0x02
973 970
974 971
975#ifdef __cplusplus 972#ifdef __cplusplus
@@ -1013,8 +1010,6 @@ int OBJ_sn2nid(const char *s);
1013int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b); 1010int OBJ_cmp(const ASN1_OBJECT *a,const ASN1_OBJECT *b);
1014const char * OBJ_bsearch(const char *key,const char *base,int num,int size, 1011const char * OBJ_bsearch(const char *key,const char *base,int num,int size,
1015 int (*cmp)(const void *, const void *)); 1012 int (*cmp)(const void *, const void *));
1016const char * OBJ_bsearch_ex(const char *key,const char *base,int num,
1017 int size, int (*cmp)(const void *, const void *), int flags);
1018 1013
1019int OBJ_new_nid(int num); 1014int OBJ_new_nid(int num);
1020int OBJ_add_object(const ASN1_OBJECT *obj); 1015int OBJ_add_object(const ASN1_OBJECT *obj);
diff --git a/src/lib/libcrypto/objects/objects.pl b/src/lib/libcrypto/objects/objects.pl
index 76c06cc8f9..76bb8da677 100644
--- a/src/lib/libcrypto/objects/objects.pl
+++ b/src/lib/libcrypto/objects/objects.pl
@@ -107,12 +107,13 @@ while (<IN>)
107 } 107 }
108close IN; 108close IN;
109 109
110open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]"; 110#XXX don't modify input files
111foreach (sort { $a <=> $b } keys %nidn) 111#open (NUMOUT,">$ARGV[1]") || die "Can't open output file $ARGV[1]";
112 { 112#foreach (sort { $a <=> $b } keys %nidn)
113 print NUMOUT $nidn{$_},"\t\t",$_,"\n"; 113# {
114 } 114# print NUMOUT $nidn{$_},"\t\t",$_,"\n";
115close NUMOUT; 115# }
116#close NUMOUT;
116 117
117open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]"; 118open (OUT,">$ARGV[2]") || die "Can't open output file $ARGV[2]";
118print OUT <<'EOF'; 119print OUT <<'EOF';
diff --git a/src/lib/libcrypto/objects/objects.txt b/src/lib/libcrypto/objects/objects.txt
index 34c8d1d647..2635c4e667 100644
--- a/src/lib/libcrypto/objects/objects.txt
+++ b/src/lib/libcrypto/objects/objects.txt
@@ -1,28 +1,12 @@
1# CCITT was renamed to ITU-T quite some time ago 10 : CCITT : ccitt
20 : ITU-T : itu-t
3!Alias ccitt itu-t
4 2
51 : ISO : iso 31 : ISO : iso
6 4
72 : JOINT-ISO-ITU-T : joint-iso-itu-t 52 : JOINT-ISO-CCITT : joint-iso-ccitt
8!Alias joint-iso-ccitt joint-iso-itu-t
9 6
10iso 2 : member-body : ISO Member Body 7iso 2 : member-body : ISO Member Body
11 8
12iso 3 : identified-organization 9joint-iso-ccitt 5 1 5 : selected-attribute-types : Selected Attribute Types
13
14# HMAC OIDs
15identified-organization 6 1 5 5 8 1 1 : HMAC-MD5 : hmac-md5
16identified-organization 6 1 5 5 8 1 2 : HMAC-SHA1 : hmac-sha1
17
18identified-organization 132 : certicom-arc
19
20joint-iso-itu-t 23 : international-organizations : International Organizations
21
22international-organizations 43 : wap
23wap 13 : wap-wsg
24
25joint-iso-itu-t 5 1 5 : selected-attribute-types : Selected Attribute Types
26 10
27selected-attribute-types 55 : clearance 11selected-attribute-types 55 : clearance
28 12
@@ -40,34 +24,12 @@ ISO-US 10045 : ansi-X9-62 : ANSI X9.62
40!Alias id-fieldType ansi-X9-62 1 24!Alias id-fieldType ansi-X9-62 1
41X9-62_id-fieldType 1 : prime-field 25X9-62_id-fieldType 1 : prime-field
42X9-62_id-fieldType 2 : characteristic-two-field 26X9-62_id-fieldType 2 : characteristic-two-field
43X9-62_characteristic-two-field 3 : id-characteristic-two-basis 27# ... characteristic-two-field OID subtree
44X9-62_id-characteristic-two-basis 1 : onBasis
45X9-62_id-characteristic-two-basis 2 : tpBasis
46X9-62_id-characteristic-two-basis 3 : ppBasis
47!Alias id-publicKeyType ansi-X9-62 2 28!Alias id-publicKeyType ansi-X9-62 2
48X9-62_id-publicKeyType 1 : id-ecPublicKey 29X9-62_id-publicKeyType 1 : id-ecPublicKey
49!Alias ellipticCurve ansi-X9-62 3 30!Alias ellipticCurve ansi-X9-62 3
50!Alias c-TwoCurve X9-62_ellipticCurve 0 31!Alias c-TwoCurve X9-62_ellipticCurve 0
51X9-62_c-TwoCurve 1 : c2pnb163v1 32# ... characteristic 2 curve OIDs
52X9-62_c-TwoCurve 2 : c2pnb163v2
53X9-62_c-TwoCurve 3 : c2pnb163v3
54X9-62_c-TwoCurve 4 : c2pnb176v1
55X9-62_c-TwoCurve 5 : c2tnb191v1
56X9-62_c-TwoCurve 6 : c2tnb191v2
57X9-62_c-TwoCurve 7 : c2tnb191v3
58X9-62_c-TwoCurve 8 : c2onb191v4
59X9-62_c-TwoCurve 9 : c2onb191v5
60X9-62_c-TwoCurve 10 : c2pnb208w1
61X9-62_c-TwoCurve 11 : c2tnb239v1
62X9-62_c-TwoCurve 12 : c2tnb239v2
63X9-62_c-TwoCurve 13 : c2tnb239v3
64X9-62_c-TwoCurve 14 : c2onb239v4
65X9-62_c-TwoCurve 15 : c2onb239v5
66X9-62_c-TwoCurve 16 : c2pnb272w1
67X9-62_c-TwoCurve 17 : c2pnb304w1
68X9-62_c-TwoCurve 18 : c2tnb359v1
69X9-62_c-TwoCurve 19 : c2pnb368w1
70X9-62_c-TwoCurve 20 : c2tnb431r1
71!Alias primeCurve X9-62_ellipticCurve 1 33!Alias primeCurve X9-62_ellipticCurve 1
72X9-62_primeCurve 1 : prime192v1 34X9-62_primeCurve 1 : prime192v1
73X9-62_primeCurve 2 : prime192v2 35X9-62_primeCurve 2 : prime192v2
@@ -80,60 +42,6 @@ X9-62_primeCurve 7 : prime256v1
80!global 42!global
81X9-62_id-ecSigType 1 : ecdsa-with-SHA1 43X9-62_id-ecSigType 1 : ecdsa-with-SHA1
82 44
83# SECG curve OIDs from "SEC 2: Recommended Elliptic Curve Domain Parameters"
84# (http://www.secg.org/)
85!Alias secg_ellipticCurve certicom-arc 0
86# SECG prime curves OIDs
87secg-ellipticCurve 6 : secp112r1
88secg-ellipticCurve 7 : secp112r2
89secg-ellipticCurve 28 : secp128r1
90secg-ellipticCurve 29 : secp128r2
91secg-ellipticCurve 9 : secp160k1
92secg-ellipticCurve 8 : secp160r1
93secg-ellipticCurve 30 : secp160r2
94secg-ellipticCurve 31 : secp192k1
95# NOTE: the curve secp192r1 is the same as prime192v1 defined above
96# and is therefore omitted
97secg-ellipticCurve 32 : secp224k1
98secg-ellipticCurve 33 : secp224r1
99secg-ellipticCurve 10 : secp256k1
100# NOTE: the curve secp256r1 is the same as prime256v1 defined above
101# and is therefore omitted
102secg-ellipticCurve 34 : secp384r1
103secg-ellipticCurve 35 : secp521r1
104# SECG characteristic two curves OIDs
105secg-ellipticCurve 4 : sect113r1
106secg-ellipticCurve 5 : sect113r2
107secg-ellipticCurve 22 : sect131r1
108secg-ellipticCurve 23 : sect131r2
109secg-ellipticCurve 1 : sect163k1
110secg-ellipticCurve 2 : sect163r1
111secg-ellipticCurve 15 : sect163r2
112secg-ellipticCurve 24 : sect193r1
113secg-ellipticCurve 25 : sect193r2
114secg-ellipticCurve 26 : sect233k1
115secg-ellipticCurve 27 : sect233r1
116secg-ellipticCurve 3 : sect239k1
117secg-ellipticCurve 16 : sect283k1
118secg-ellipticCurve 17 : sect283r1
119secg-ellipticCurve 36 : sect409k1
120secg-ellipticCurve 37 : sect409r1
121secg-ellipticCurve 38 : sect571k1
122secg-ellipticCurve 39 : sect571r1
123
124# WAP/TLS curve OIDs (http://www.wapforum.org/)
125!Alias wap-wsg-idm-ecid wap-wsg 4
126wap-wsg-idm-ecid 1 : wap-wsg-idm-ecid-wtls1
127wap-wsg-idm-ecid 3 : wap-wsg-idm-ecid-wtls3
128wap-wsg-idm-ecid 4 : wap-wsg-idm-ecid-wtls4
129wap-wsg-idm-ecid 5 : wap-wsg-idm-ecid-wtls5
130wap-wsg-idm-ecid 6 : wap-wsg-idm-ecid-wtls6
131wap-wsg-idm-ecid 7 : wap-wsg-idm-ecid-wtls7
132wap-wsg-idm-ecid 8 : wap-wsg-idm-ecid-wtls8
133wap-wsg-idm-ecid 9 : wap-wsg-idm-ecid-wtls9
134wap-wsg-idm-ecid 10 : wap-wsg-idm-ecid-wtls10
135wap-wsg-idm-ecid 11 : wap-wsg-idm-ecid-wtls11
136wap-wsg-idm-ecid 12 : wap-wsg-idm-ecid-wtls12
137 45
138 46
139ISO-US 113533 7 66 10 : CAST5-CBC : cast5-cbc 47ISO-US 113533 7 66 10 : CAST5-CBC : cast5-cbc
@@ -145,10 +53,6 @@ ISO-US 113533 7 66 10 : CAST5-CBC : cast5-cbc
145!Cname pbeWithMD5AndCast5-CBC 53!Cname pbeWithMD5AndCast5-CBC
146ISO-US 113533 7 66 12 : : pbeWithMD5AndCast5CBC 54ISO-US 113533 7 66 12 : : pbeWithMD5AndCast5CBC
147 55
148# Macs for CMP and CRMF
149ISO-US 113533 7 66 13 : id-PasswordBasedMAC : password based MAC
150ISO-US 113533 7 66 30 : id-DHBasedMac : Diffie-Hellman based MAC
151
152ISO-US 113549 : rsadsi : RSA Data Security, Inc. 56ISO-US 113549 : rsadsi : RSA Data Security, Inc.
153 57
154rsadsi 1 : pkcs : RSA Data Security, Inc. PKCS 58rsadsi 1 : pkcs : RSA Data Security, Inc. PKCS
@@ -245,8 +149,6 @@ id-smime-ct 5 : id-smime-ct-TDTInfo
245id-smime-ct 6 : id-smime-ct-contentInfo 149id-smime-ct 6 : id-smime-ct-contentInfo
246id-smime-ct 7 : id-smime-ct-DVCSRequestData 150id-smime-ct 7 : id-smime-ct-DVCSRequestData
247id-smime-ct 8 : id-smime-ct-DVCSResponseData 151id-smime-ct 8 : id-smime-ct-DVCSResponseData
248id-smime-ct 9 : id-smime-ct-compressedData
249id-smime-ct 27 : id-ct-asciiTextWithCRLF
250 152
251# S/MIME Attributes 153# S/MIME Attributes
252id-smime-aa 1 : id-smime-aa-receiptRequest 154id-smime-aa 1 : id-smime-aa-receiptRequest
@@ -494,7 +396,6 @@ id-it 12 : id-it-revPassphrase
494id-it 13 : id-it-implicitConfirm 396id-it 13 : id-it-implicitConfirm
495id-it 14 : id-it-confirmWaitTime 397id-it 14 : id-it-confirmWaitTime
496id-it 15 : id-it-origPKIMessage 398id-it 15 : id-it-origPKIMessage
497id-it 16 : id-it-suppLangTags
498 399
499# CRMF registration 400# CRMF registration
500id-pkip 1 : id-regCtrl 401id-pkip 1 : id-regCtrl
@@ -581,7 +482,6 @@ id-ad 2 : caIssuers : CA Issuers
581id-ad 3 : ad_timestamping : AD Time Stamping 482id-ad 3 : ad_timestamping : AD Time Stamping
582!Cname ad-dvcs 483!Cname ad-dvcs
583id-ad 4 : AD_DVCS : ad dvcs 484id-ad 4 : AD_DVCS : ad dvcs
584id-ad 5 : caRepository : CA Repository
585 485
586 486
587!Alias id-pkix-OCSP ad-OCSP 487!Alias id-pkix-OCSP ad-OCSP
@@ -669,8 +569,6 @@ X500algorithms 3 100 : RSA-MDC2 : mdc2WithRSA
669X500algorithms 3 101 : MDC2 : mdc2 569X500algorithms 3 101 : MDC2 : mdc2
670 570
671X500 29 : id-ce 571X500 29 : id-ce
672!Cname subject-directory-attributes
673id-ce 9 : subjectDirectoryAttributes : X509v3 Subject Directory Attributes
674!Cname subject-key-identifier 572!Cname subject-key-identifier
675id-ce 14 : subjectKeyIdentifier : X509v3 Subject Key Identifier 573id-ce 14 : subjectKeyIdentifier : X509v3 Subject Key Identifier
676!Cname key-usage 574!Cname key-usage
@@ -691,28 +589,18 @@ id-ce 21 : CRLReason : X509v3 CRL Reason Code
691id-ce 24 : invalidityDate : Invalidity Date 589id-ce 24 : invalidityDate : Invalidity Date
692!Cname delta-crl 590!Cname delta-crl
693id-ce 27 : deltaCRL : X509v3 Delta CRL Indicator 591id-ce 27 : deltaCRL : X509v3 Delta CRL Indicator
694!Cname issuing-distribution-point
695id-ce 28 : issuingDistributionPoint : X509v3 Issuing Distrubution Point
696!Cname certificate-issuer
697id-ce 29 : certificateIssuer : X509v3 Certificate Issuer
698!Cname name-constraints 592!Cname name-constraints
699id-ce 30 : nameConstraints : X509v3 Name Constraints 593id-ce 30 : nameConstraints : X509v3 Name Constraints
700!Cname crl-distribution-points 594!Cname crl-distribution-points
701id-ce 31 : crlDistributionPoints : X509v3 CRL Distribution Points 595id-ce 31 : crlDistributionPoints : X509v3 CRL Distribution Points
702!Cname certificate-policies 596!Cname certificate-policies
703id-ce 32 : certificatePolicies : X509v3 Certificate Policies 597id-ce 32 : certificatePolicies : X509v3 Certificate Policies
704!Cname any-policy
705certificate-policies 0 : anyPolicy : X509v3 Any Policy
706!Cname policy-mappings
707id-ce 33 : policyMappings : X509v3 Policy Mappings
708!Cname authority-key-identifier 598!Cname authority-key-identifier
709id-ce 35 : authorityKeyIdentifier : X509v3 Authority Key Identifier 599id-ce 35 : authorityKeyIdentifier : X509v3 Authority Key Identifier
710!Cname policy-constraints 600!Cname policy-constraints
711id-ce 36 : policyConstraints : X509v3 Policy Constraints 601id-ce 36 : policyConstraints : X509v3 Policy Constraints
712!Cname ext-key-usage 602!Cname ext-key-usage
713id-ce 37 : extendedKeyUsage : X509v3 Extended Key Usage 603id-ce 37 : extendedKeyUsage : X509v3 Extended Key Usage
714!Cname inhibit-any-policy
715id-ce 54 : inhibitAnyPolicy : X509v3 Inhibit Any Policy
716!Cname target-information 604!Cname target-information
717id-ce 55 : targetInformation : X509v3 AC Targeting 605id-ce 55 : targetInformation : X509v3 AC Targeting
718!Cname no-rev-avail 606!Cname no-rev-avail
@@ -780,7 +668,7 @@ mime-mhs-headings 2 : id-hex-multipart-message : id-hex-multipart-message
780!Cname rle-compression 668!Cname rle-compression
7811 1 1 1 666 1 : RLE : run length compression 6691 1 1 1 666 1 : RLE : run length compression
782!Cname zlib-compression 670!Cname zlib-compression
783id-smime-alg 8 : ZLIB : zlib compression 6711 1 1 1 666 2 : ZLIB : zlib compression
784 672
785# AES aka Rijndael 673# AES aka Rijndael
786 674
@@ -822,10 +710,6 @@ aes 44 : AES-256-CFB : aes-256-cfb
822 : DES-EDE3-CFB1 : des-ede3-cfb1 710 : DES-EDE3-CFB1 : des-ede3-cfb1
823 : DES-EDE3-CFB8 : des-ede3-cfb8 711 : DES-EDE3-CFB8 : des-ede3-cfb8
824 712
825aes 5 : id-aes128-wrap
826aes 25 : id-aes192-wrap
827aes 45 : id-aes256-wrap
828
829# OIDs for SHA224, SHA256, SHA385 and SHA512, according to x9.84. 713# OIDs for SHA224, SHA256, SHA385 and SHA512, according to x9.84.
830!Alias nist_hashalgs nistAlgorithms 2 714!Alias nist_hashalgs nistAlgorithms 2
831nist_hashalgs 1 : SHA256 : sha256 715nist_hashalgs 1 : SHA256 : sha256
@@ -844,9 +728,9 @@ holdInstruction 2 : holdInstructionCallIssuer : Hold Instruction Call Issuer
844!Cname hold-instruction-reject 728!Cname hold-instruction-reject
845holdInstruction 3 : holdInstructionReject : Hold Instruction Reject 729holdInstruction 3 : holdInstructionReject : Hold Instruction Reject
846 730
847# OID's from ITU-T. Most of this is defined in RFC 1274. A couple of 731# OID's from CCITT. Most of this is defined in RFC 1274. A couple of
848# them are also mentioned in RFC 2247 732# them are also mentioned in RFC 2247
849itu-t 9 : data 733ccitt 9 : data
850data 2342 : pss 734data 2342 : pss
851pss 19200300 : ucl 735pss 19200300 : ucl
852ucl 100 : pilot 736ucl 100 : pilot
@@ -920,7 +804,7 @@ pilotAttributeType 54 : : dITRedirect
920pilotAttributeType 55 : audio 804pilotAttributeType 55 : audio
921pilotAttributeType 56 : : documentPublisher 805pilotAttributeType 56 : : documentPublisher
922 806
923international-organizations 42 : id-set : Secure Electronic Transactions 8072 23 42 : id-set : Secure Electronic Transactions
924 808
925id-set 0 : set-ctype : content types 809id-set 0 : set-ctype : content types
926id-set 1 : set-msgExt : message extensions 810id-set 1 : set-msgExt : message extensions
@@ -1066,54 +950,3 @@ set-brand 6011 : set-brand-Novus
1066 950
1067rsadsi 3 10 : DES-CDMF : des-cdmf 951rsadsi 3 10 : DES-CDMF : des-cdmf
1068rsadsi 1 1 6 : rsaOAEPEncryptionSET 952rsadsi 1 1 6 : rsaOAEPEncryptionSET
1069
1070 : Oakley-EC2N-3 : ipsec3
1071 : Oakley-EC2N-4 : ipsec4
1072
1073
1074# Definitions for Camellia cipher - CBC MODE
10751 2 392 200011 61 1 1 1 2 : CAMELLIA-128-CBC : camellia-128-cbc
10761 2 392 200011 61 1 1 1 3 : CAMELLIA-192-CBC : camellia-192-cbc
10771 2 392 200011 61 1 1 1 4 : CAMELLIA-256-CBC : camellia-256-cbc
1078
1079# Definitions for Camellia cipher - ECB, CFB, OFB MODE
1080!Alias ntt-ds 0 3 4401 5
1081!Alias camellia ntt-ds 3 1 9
1082
1083camellia 1 : CAMELLIA-128-ECB : camellia-128-ecb
1084!Cname camellia-128-ofb128
1085camellia 3 : CAMELLIA-128-OFB : camellia-128-ofb
1086!Cname camellia-128-cfb128
1087camellia 4 : CAMELLIA-128-CFB : camellia-128-cfb
1088
1089camellia 21 : CAMELLIA-192-ECB : camellia-192-ecb
1090!Cname camellia-192-ofb128
1091camellia 23 : CAMELLIA-192-OFB : camellia-192-ofb
1092!Cname camellia-192-cfb128
1093camellia 24 : CAMELLIA-192-CFB : camellia-192-cfb
1094
1095camellia 41 : CAMELLIA-256-ECB : camellia-256-ecb
1096!Cname camellia-256-ofb128
1097camellia 43 : CAMELLIA-256-OFB : camellia-256-ofb
1098!Cname camellia-256-cfb128
1099camellia 44 : CAMELLIA-256-CFB : camellia-256-cfb
1100
1101# There are no OIDs for these modes...
1102
1103 : CAMELLIA-128-CFB1 : camellia-128-cfb1
1104 : CAMELLIA-192-CFB1 : camellia-192-cfb1
1105 : CAMELLIA-256-CFB1 : camellia-256-cfb1
1106 : CAMELLIA-128-CFB8 : camellia-128-cfb8
1107 : CAMELLIA-192-CFB8 : camellia-192-cfb8
1108 : CAMELLIA-256-CFB8 : camellia-256-cfb8
1109
1110
1111# Definitions for SEED cipher - ECB, CBC, OFB mode
1112
1113member-body 410 200004 : KISA : kisa
1114kisa 1 3 : SEED-ECB : seed-ecb
1115kisa 1 4 : SEED-CBC : seed-cbc
1116!Cname seed-cfb128
1117kisa 1 5 : SEED-CFB : seed-cfb
1118!Cname seed-ofb128
1119kisa 1 6 : SEED-OFB : seed-ofb
diff --git a/src/lib/libcrypto/ocsp/Makefile b/src/lib/libcrypto/ocsp/Makefile
new file mode 100644
index 0000000000..0fe028960e
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/Makefile
@@ -0,0 +1,213 @@
1#
2# OpenSSL/ocsp/Makefile
3#
4
5DIR= ocsp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile README
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= ocsp_asn.c ocsp_ext.c ocsp_ht.c ocsp_lib.c ocsp_cl.c \
21 ocsp_srv.c ocsp_prn.c ocsp_vfy.c ocsp_err.c
22
23LIBOBJ= ocsp_asn.o ocsp_ext.o ocsp_ht.o ocsp_lib.o ocsp_cl.o \
24 ocsp_srv.o ocsp_prn.o ocsp_vfy.o ocsp_err.o
25
26SRC= $(LIBSRC)
27
28EXHEADER= ocsp.h
29HEADER= $(EXHEADER)
30
31ALL= $(GENERAL) $(SRC) $(HEADER)
32
33top:
34 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
35
36all: lib
37
38lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ)
40 $(RANLIB) $(LIB) || echo Never mind.
41 @touch lib
42
43files:
44 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
45
46links:
47 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
48 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
49 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
50
51install:
52 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
53 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
54 do \
55 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
56 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
57 done;
58
59tags:
60 ctags $(SRC)
61
62tests:
63
64lint:
65 lint -DLINT $(INCLUDES) $(SRC)>fluff
66
67depend:
68 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
69 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
70
71dclean:
72 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE)
74
75clean:
76 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78# DO NOT DELETE THIS LINE -- make depend depends on it.
79
80ocsp_asn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
81ocsp_asn.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82ocsp_asn.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
83ocsp_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
84ocsp_asn.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
85ocsp_asn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
86ocsp_asn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
87ocsp_asn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
88ocsp_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
89ocsp_asn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
90ocsp_asn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
91ocsp_asn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
92ocsp_asn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
93ocsp_asn.o: ocsp_asn.c
94ocsp_cl.o: ../../e_os.h ../../include/openssl/asn1.h
95ocsp_cl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
96ocsp_cl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
97ocsp_cl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
98ocsp_cl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
99ocsp_cl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
100ocsp_cl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
101ocsp_cl.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
102ocsp_cl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
103ocsp_cl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
104ocsp_cl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
105ocsp_cl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
106ocsp_cl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
107ocsp_cl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
108ocsp_cl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
109ocsp_cl.o: ../cryptlib.h ocsp_cl.c
110ocsp_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
111ocsp_err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
112ocsp_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
113ocsp_err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
114ocsp_err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
115ocsp_err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
116ocsp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
117ocsp_err.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
118ocsp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
119ocsp_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
120ocsp_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
121ocsp_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
122ocsp_err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
123ocsp_err.o: ocsp_err.c
124ocsp_ext.o: ../../e_os.h ../../include/openssl/asn1.h
125ocsp_ext.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
126ocsp_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
127ocsp_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
128ocsp_ext.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
129ocsp_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h
130ocsp_ext.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
131ocsp_ext.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
132ocsp_ext.o: ../../include/openssl/opensslconf.h
133ocsp_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
134ocsp_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
135ocsp_ext.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
136ocsp_ext.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
137ocsp_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
138ocsp_ext.o: ../../include/openssl/x509v3.h ../cryptlib.h ocsp_ext.c
139ocsp_ht.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
140ocsp_ht.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
141ocsp_ht.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
142ocsp_ht.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
143ocsp_ht.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
144ocsp_ht.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
145ocsp_ht.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
146ocsp_ht.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
147ocsp_ht.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
148ocsp_ht.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
149ocsp_ht.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
150ocsp_ht.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
151ocsp_ht.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
152ocsp_ht.o: ocsp_ht.c
153ocsp_lib.o: ../../e_os.h ../../include/openssl/asn1.h
154ocsp_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
155ocsp_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
156ocsp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
157ocsp_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
158ocsp_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
159ocsp_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
160ocsp_lib.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
161ocsp_lib.o: ../../include/openssl/opensslconf.h
162ocsp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
163ocsp_lib.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
164ocsp_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
165ocsp_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
166ocsp_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
167ocsp_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
168ocsp_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ocsp_lib.c
169ocsp_prn.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
170ocsp_prn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
171ocsp_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
172ocsp_prn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
173ocsp_prn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
174ocsp_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
175ocsp_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
176ocsp_prn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
177ocsp_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
178ocsp_prn.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
179ocsp_prn.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
180ocsp_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
181ocsp_prn.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
182ocsp_prn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
183ocsp_prn.o: ocsp_prn.c
184ocsp_srv.o: ../../e_os.h ../../include/openssl/asn1.h
185ocsp_srv.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
186ocsp_srv.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
187ocsp_srv.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
188ocsp_srv.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
189ocsp_srv.o: ../../include/openssl/err.h ../../include/openssl/evp.h
190ocsp_srv.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
191ocsp_srv.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
192ocsp_srv.o: ../../include/openssl/opensslconf.h
193ocsp_srv.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
194ocsp_srv.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
195ocsp_srv.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
196ocsp_srv.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
197ocsp_srv.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
198ocsp_srv.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
199ocsp_srv.o: ../../include/openssl/x509v3.h ../cryptlib.h ocsp_srv.c
200ocsp_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
201ocsp_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
202ocsp_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
203ocsp_vfy.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
204ocsp_vfy.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
205ocsp_vfy.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
206ocsp_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
207ocsp_vfy.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
208ocsp_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
209ocsp_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
210ocsp_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
211ocsp_vfy.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
212ocsp_vfy.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
213ocsp_vfy.o: ocsp_vfy.c
diff --git a/src/lib/libcrypto/ocsp/Makefile.ssl b/src/lib/libcrypto/ocsp/Makefile.ssl
new file mode 100644
index 0000000000..02477be538
--- /dev/null
+++ b/src/lib/libcrypto/ocsp/Makefile.ssl
@@ -0,0 +1,293 @@
1#
2# OpenSSL/ocsp/Makefile.ssl
3#
4
5DIR= ocsp
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= ocsp_asn.c ocsp_ext.c ocsp_ht.c ocsp_lib.c ocsp_cl.c \
27 ocsp_srv.c ocsp_prn.c ocsp_vfy.c ocsp_err.c
28
29LIBOBJ= ocsp_asn.o ocsp_ext.o ocsp_ht.o ocsp_lib.o ocsp_cl.o \
30 ocsp_srv.o ocsp_prn.o ocsp_vfy.o ocsp_err.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= ocsp.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) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links:
53 @sh $(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) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(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
85ocsp_asn.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
86ocsp_asn.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
87ocsp_asn.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
88ocsp_asn.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
89ocsp_asn.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
90ocsp_asn.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
91ocsp_asn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
92ocsp_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/evp.h
93ocsp_asn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
94ocsp_asn.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
95ocsp_asn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
96ocsp_asn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
97ocsp_asn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
98ocsp_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
99ocsp_asn.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
100ocsp_asn.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
101ocsp_asn.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
102ocsp_asn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
103ocsp_asn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
104ocsp_asn.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
105ocsp_asn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
106ocsp_asn.o: ../../include/openssl/x509v3.h ocsp_asn.c
107ocsp_cl.o: ../../e_os.h ../../include/openssl/aes.h
108ocsp_cl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
109ocsp_cl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
110ocsp_cl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
111ocsp_cl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
112ocsp_cl.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
113ocsp_cl.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
114ocsp_cl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
115ocsp_cl.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
116ocsp_cl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
117ocsp_cl.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
118ocsp_cl.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
119ocsp_cl.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
120ocsp_cl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
121ocsp_cl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
122ocsp_cl.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
123ocsp_cl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
124ocsp_cl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
125ocsp_cl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
126ocsp_cl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
127ocsp_cl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
128ocsp_cl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
129ocsp_cl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
130ocsp_cl.o: ../../include/openssl/x509v3.h ../cryptlib.h ocsp_cl.c
131ocsp_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
132ocsp_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
133ocsp_err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
134ocsp_err.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
135ocsp_err.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
136ocsp_err.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
137ocsp_err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
138ocsp_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
139ocsp_err.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
140ocsp_err.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
141ocsp_err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
142ocsp_err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
143ocsp_err.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
144ocsp_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
145ocsp_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
146ocsp_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
147ocsp_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
148ocsp_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
149ocsp_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
150ocsp_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
151ocsp_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
152ocsp_err.o: ../../include/openssl/x509v3.h ocsp_err.c
153ocsp_ext.o: ../../e_os.h ../../include/openssl/aes.h
154ocsp_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
155ocsp_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
156ocsp_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
157ocsp_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
158ocsp_ext.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
159ocsp_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
160ocsp_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
161ocsp_ext.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
162ocsp_ext.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
163ocsp_ext.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
164ocsp_ext.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
165ocsp_ext.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
166ocsp_ext.o: ../../include/openssl/opensslconf.h
167ocsp_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
168ocsp_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
169ocsp_ext.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
170ocsp_ext.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
171ocsp_ext.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
172ocsp_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
173ocsp_ext.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
174ocsp_ext.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
175ocsp_ext.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
176ocsp_ext.o: ../cryptlib.h ocsp_ext.c
177ocsp_ht.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
178ocsp_ht.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
179ocsp_ht.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
180ocsp_ht.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
181ocsp_ht.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
182ocsp_ht.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
183ocsp_ht.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
184ocsp_ht.o: ../../include/openssl/err.h ../../include/openssl/evp.h
185ocsp_ht.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
186ocsp_ht.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
187ocsp_ht.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
188ocsp_ht.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
189ocsp_ht.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
190ocsp_ht.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
191ocsp_ht.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
192ocsp_ht.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
193ocsp_ht.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
194ocsp_ht.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
195ocsp_ht.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
196ocsp_ht.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
197ocsp_ht.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
198ocsp_ht.o: ../../include/openssl/x509v3.h ocsp_ht.c
199ocsp_lib.o: ../../e_os.h ../../include/openssl/aes.h
200ocsp_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
201ocsp_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
202ocsp_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
203ocsp_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
204ocsp_lib.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
205ocsp_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
206ocsp_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
207ocsp_lib.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
208ocsp_lib.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
209ocsp_lib.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
210ocsp_lib.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
211ocsp_lib.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
212ocsp_lib.o: ../../include/openssl/opensslconf.h
213ocsp_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
214ocsp_lib.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
215ocsp_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
216ocsp_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
217ocsp_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
218ocsp_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
219ocsp_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
220ocsp_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
221ocsp_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
222ocsp_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
223ocsp_lib.o: ../cryptlib.h ocsp_lib.c
224ocsp_prn.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
225ocsp_prn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
226ocsp_prn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
227ocsp_prn.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
228ocsp_prn.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
229ocsp_prn.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
230ocsp_prn.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
231ocsp_prn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
232ocsp_prn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
233ocsp_prn.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
234ocsp_prn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
235ocsp_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
236ocsp_prn.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
237ocsp_prn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
238ocsp_prn.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
239ocsp_prn.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
240ocsp_prn.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
241ocsp_prn.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
242ocsp_prn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
243ocsp_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
244ocsp_prn.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
245ocsp_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
246ocsp_prn.o: ../../include/openssl/x509v3.h ocsp_prn.c
247ocsp_srv.o: ../../e_os.h ../../include/openssl/aes.h
248ocsp_srv.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
249ocsp_srv.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
250ocsp_srv.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
251ocsp_srv.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
252ocsp_srv.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
253ocsp_srv.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
254ocsp_srv.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
255ocsp_srv.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
256ocsp_srv.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
257ocsp_srv.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
258ocsp_srv.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
259ocsp_srv.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
260ocsp_srv.o: ../../include/openssl/opensslconf.h
261ocsp_srv.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
262ocsp_srv.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
263ocsp_srv.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
264ocsp_srv.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
265ocsp_srv.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
266ocsp_srv.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
267ocsp_srv.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
268ocsp_srv.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
269ocsp_srv.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
270ocsp_srv.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
271ocsp_srv.o: ../cryptlib.h ocsp_srv.c
272ocsp_vfy.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
273ocsp_vfy.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
274ocsp_vfy.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
275ocsp_vfy.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
276ocsp_vfy.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
277ocsp_vfy.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
278ocsp_vfy.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
279ocsp_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h
280ocsp_vfy.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
281ocsp_vfy.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
282ocsp_vfy.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
283ocsp_vfy.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
284ocsp_vfy.o: ../../include/openssl/ocsp.h ../../include/openssl/opensslconf.h
285ocsp_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
286ocsp_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
287ocsp_vfy.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
288ocsp_vfy.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
289ocsp_vfy.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
290ocsp_vfy.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
291ocsp_vfy.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
292ocsp_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
293ocsp_vfy.o: ../../include/openssl/x509v3.h ocsp_vfy.c
diff --git a/src/lib/libcrypto/ocsp/ocsp.h b/src/lib/libcrypto/ocsp/ocsp.h
index a0577a717e..fab3c03182 100644
--- a/src/lib/libcrypto/ocsp/ocsp.h
+++ b/src/lib/libcrypto/ocsp/ocsp.h
@@ -186,11 +186,11 @@ typedef struct ocsp_resp_bytes_st
186 * responseStatus OCSPResponseStatus, 186 * responseStatus OCSPResponseStatus,
187 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } 187 * responseBytes [0] EXPLICIT ResponseBytes OPTIONAL }
188 */ 188 */
189struct ocsp_response_st 189typedef struct ocsp_response_st
190 { 190 {
191 ASN1_ENUMERATED *responseStatus; 191 ASN1_ENUMERATED *responseStatus;
192 OCSP_RESPBYTES *responseBytes; 192 OCSP_RESPBYTES *responseBytes;
193 }; 193 } OCSP_RESPONSE;
194 194
195/* ResponderID ::= CHOICE { 195/* ResponderID ::= CHOICE {
196 * byName [1] Name, 196 * byName [1] Name,
@@ -198,18 +198,14 @@ struct ocsp_response_st
198 */ 198 */
199#define V_OCSP_RESPID_NAME 0 199#define V_OCSP_RESPID_NAME 0
200#define V_OCSP_RESPID_KEY 1 200#define V_OCSP_RESPID_KEY 1
201struct ocsp_responder_id_st 201typedef struct ocsp_responder_id_st
202 { 202 {
203 int type; 203 int type;
204 union { 204 union {
205 X509_NAME* byName; 205 X509_NAME* byName;
206 ASN1_OCTET_STRING *byKey; 206 ASN1_OCTET_STRING *byKey;
207 } value; 207 } value;
208 }; 208 } OCSP_RESPID;
209
210DECLARE_STACK_OF(OCSP_RESPID)
211DECLARE_ASN1_FUNCTIONS(OCSP_RESPID)
212
213/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key 209/* KeyHash ::= OCTET STRING --SHA-1 hash of responder's public key
214 * --(excluding the tag and length fields) 210 * --(excluding the tag and length fields)
215 */ 211 */
@@ -353,9 +349,13 @@ typedef struct ocsp_service_locator_st
353#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST" 349#define PEM_STRING_OCSP_REQUEST "OCSP REQUEST"
354#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE" 350#define PEM_STRING_OCSP_RESPONSE "OCSP RESPONSE"
355 351
356#define d2i_OCSP_REQUEST_bio(bp,p) ASN1_d2i_bio_of(OCSP_REQUEST,OCSP_REQUEST_new,d2i_OCSP_REQUEST,bp,p) 352#define d2i_OCSP_REQUEST_bio(bp,p) (OCSP_REQUEST*)ASN1_d2i_bio((char*(*)()) \
353 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_REQUEST, (bp),\
354 (unsigned char **)(p))
357 355
358#define d2i_OCSP_RESPONSE_bio(bp,p) ASN1_d2i_bio_of(OCSP_RESPONSE,OCSP_RESPONSE_new,d2i_OCSP_RESPONSE,bp,p) 356#define d2i_OCSP_RESPONSE_bio(bp,p) (OCSP_RESPONSE*)ASN1_d2i_bio((char*(*)())\
357 OCSP_REQUEST_new,(char *(*)())d2i_OCSP_RESPONSE, (bp),\
358 (unsigned char **)(p))
359 359
360#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \ 360#define PEM_read_bio_OCSP_REQUEST(bp,x,cb) (OCSP_REQUEST *)PEM_ASN1_read_bio( \
361 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL) 361 (char *(*)())d2i_OCSP_REQUEST,PEM_STRING_OCSP_REQUEST,bp,(char **)x,cb,NULL)
@@ -371,9 +371,11 @@ typedef struct ocsp_service_locator_st
371 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\ 371 PEM_ASN1_write_bio((int (*)())i2d_OCSP_RESPONSE,PEM_STRING_OCSP_RESPONSE,\
372 bp,(char *)o, NULL,NULL,0,NULL,NULL) 372 bp,(char *)o, NULL,NULL,0,NULL,NULL)
373 373
374#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio_of(OCSP_RESPONSE,i2d_OCSP_RESPONSE,bp,o) 374#define i2d_OCSP_RESPONSE_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_RESPONSE,bp,\
375 (unsigned char *)o)
375 376
376#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio_of(OCSP_REQUEST,i2d_OCSP_REQUEST,bp,o) 377#define i2d_OCSP_REQUEST_bio(bp,o) ASN1_i2d_bio(i2d_OCSP_REQUEST,bp,\
378 (unsigned char *)o)
377 379
378#define OCSP_REQUEST_sign(o,pkey,md) \ 380#define OCSP_REQUEST_sign(o,pkey,md) \
379 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\ 381 ASN1_item_sign(ASN1_ITEM_rptr(OCSP_REQINFO),\
@@ -394,17 +396,14 @@ typedef struct ocsp_service_locator_st
394#define ASN1_BIT_STRING_digest(data,type,md,len) \ 396#define ASN1_BIT_STRING_digest(data,type,md,len) \
395 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len) 397 ASN1_item_digest(ASN1_ITEM_rptr(ASN1_BIT_STRING),type,data,md,len)
396 398
397#define OCSP_CERTID_dup(cid) ASN1_dup_of(OCSP_CERTID,i2d_OCSP_CERTID,d2i_OCSP_CERTID,cid) 399#define OCSP_CERTID_dup(cid) (OCSP_CERTID*)ASN1_dup((int(*)())i2d_OCSP_CERTID,\
400 (char *(*)())d2i_OCSP_CERTID,(char *)(cid))
398 401
399#define OCSP_CERTSTATUS_dup(cs)\ 402#define OCSP_CERTSTATUS_dup(cs)\
400 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\ 403 (OCSP_CERTSTATUS*)ASN1_dup((int(*)())i2d_OCSP_CERTSTATUS,\
401 (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs)) 404 (char *(*)())d2i_OCSP_CERTSTATUS,(char *)(cs))
402 405
403OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req); 406OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req);
404OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req,
405 int maxline);
406int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx);
407void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx);
408 407
409OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer); 408OCSP_CERTID *OCSP_cert_to_id(const EVP_MD *dgst, X509 *subject, X509 *issuer);
410 409
@@ -474,10 +473,8 @@ int OCSP_basic_sign(OCSP_BASICRESP *brsp,
474 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst, 473 X509 *signer, EVP_PKEY *key, const EVP_MD *dgst,
475 STACK_OF(X509) *certs, unsigned long flags); 474 STACK_OF(X509) *certs, unsigned long flags);
476 475
477ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d, 476ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
478 void *data, STACK_OF(ASN1_OBJECT) *sk); 477 char *data, STACK_OF(ASN1_OBJECT) *sk);
479#define ASN1_STRING_encode_of(type,s,i2d,data,sk) \
480 ASN1_STRING_encode(s, CHECKED_I2D_OF(type, i2d), data, sk)
481 478
482X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim); 479X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim);
483 480
@@ -567,11 +564,11 @@ void ERR_load_OCSP_strings(void);
567 564
568/* Function codes. */ 565/* Function codes. */
569#define OCSP_F_ASN1_STRING_ENCODE 100 566#define OCSP_F_ASN1_STRING_ENCODE 100
567#define OCSP_F_CERT_ID_NEW 101
570#define OCSP_F_D2I_OCSP_NONCE 102 568#define OCSP_F_D2I_OCSP_NONCE 102
571#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103 569#define OCSP_F_OCSP_BASIC_ADD1_STATUS 103
572#define OCSP_F_OCSP_BASIC_SIGN 104 570#define OCSP_F_OCSP_BASIC_SIGN 104
573#define OCSP_F_OCSP_BASIC_VERIFY 105 571#define OCSP_F_OCSP_BASIC_VERIFY 105
574#define OCSP_F_OCSP_CERT_ID_NEW 101
575#define OCSP_F_OCSP_CHECK_DELEGATED 106 572#define OCSP_F_OCSP_CHECK_DELEGATED 106
576#define OCSP_F_OCSP_CHECK_IDS 107 573#define OCSP_F_OCSP_CHECK_IDS 107
577#define OCSP_F_OCSP_CHECK_ISSUER 108 574#define OCSP_F_OCSP_CHECK_ISSUER 108
@@ -582,7 +579,6 @@ void ERR_load_OCSP_strings(void);
582#define OCSP_F_OCSP_REQUEST_VERIFY 116 579#define OCSP_F_OCSP_REQUEST_VERIFY 116
583#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111 580#define OCSP_F_OCSP_RESPONSE_GET1_BASIC 111
584#define OCSP_F_OCSP_SENDREQ_BIO 112 581#define OCSP_F_OCSP_SENDREQ_BIO 112
585#define OCSP_F_PARSE_HTTP_LINE1 117
586#define OCSP_F_REQUEST_VERIFY 113 582#define OCSP_F_REQUEST_VERIFY 113
587 583
588/* Reason codes. */ 584/* Reason codes. */
diff --git a/src/lib/libcrypto/ocsp/ocsp_asn.c b/src/lib/libcrypto/ocsp/ocsp_asn.c
index 39b7a1c568..6a3a360d54 100644
--- a/src/lib/libcrypto/ocsp/ocsp_asn.c
+++ b/src/lib/libcrypto/ocsp/ocsp_asn.c
@@ -62,7 +62,7 @@
62ASN1_SEQUENCE(OCSP_SIGNATURE) = { 62ASN1_SEQUENCE(OCSP_SIGNATURE) = {
63 ASN1_SIMPLE(OCSP_SIGNATURE, signatureAlgorithm, X509_ALGOR), 63 ASN1_SIMPLE(OCSP_SIGNATURE, signatureAlgorithm, X509_ALGOR),
64 ASN1_SIMPLE(OCSP_SIGNATURE, signature, ASN1_BIT_STRING), 64 ASN1_SIMPLE(OCSP_SIGNATURE, signature, ASN1_BIT_STRING),
65 ASN1_EXP_SEQUENCE_OF_OPT(OCSP_SIGNATURE, certs, X509, 0) 65 ASN1_EXP_SEQUENCE_OF(OCSP_SIGNATURE, certs, X509, 0)
66} ASN1_SEQUENCE_END(OCSP_SIGNATURE) 66} ASN1_SEQUENCE_END(OCSP_SIGNATURE)
67 67
68IMPLEMENT_ASN1_FUNCTIONS(OCSP_SIGNATURE) 68IMPLEMENT_ASN1_FUNCTIONS(OCSP_SIGNATURE)
diff --git a/src/lib/libcrypto/ocsp/ocsp_cl.c b/src/lib/libcrypto/ocsp/ocsp_cl.c
index 17bab5fc59..9b3e6dd8ca 100644
--- a/src/lib/libcrypto/ocsp/ocsp_cl.c
+++ b/src/lib/libcrypto/ocsp/ocsp_cl.c
@@ -101,8 +101,6 @@ int OCSP_request_set1_name(OCSP_REQUEST *req, X509_NAME *nm)
101 { 101 {
102 GENERAL_NAME *gen; 102 GENERAL_NAME *gen;
103 gen = GENERAL_NAME_new(); 103 gen = GENERAL_NAME_new();
104 if (gen == NULL)
105 return 0;
106 if (!X509_NAME_set(&gen->d.directoryName, nm)) 104 if (!X509_NAME_set(&gen->d.directoryName, nm))
107 { 105 {
108 GENERAL_NAME_free(gen); 106 GENERAL_NAME_free(gen);
diff --git a/src/lib/libcrypto/ocsp/ocsp_err.c b/src/lib/libcrypto/ocsp/ocsp_err.c
index d2f2e79f44..65e6093fbc 100644
--- a/src/lib/libcrypto/ocsp/ocsp_err.c
+++ b/src/lib/libcrypto/ocsp/ocsp_err.c
@@ -1,6 +1,6 @@
1/* crypto/ocsp/ocsp_err.c */ 1/* crypto/ocsp/ocsp_err.c */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1999-2007 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
@@ -71,11 +71,11 @@
71static ERR_STRING_DATA OCSP_str_functs[]= 71static ERR_STRING_DATA OCSP_str_functs[]=
72 { 72 {
73{ERR_FUNC(OCSP_F_ASN1_STRING_ENCODE), "ASN1_STRING_encode"}, 73{ERR_FUNC(OCSP_F_ASN1_STRING_ENCODE), "ASN1_STRING_encode"},
74{ERR_FUNC(OCSP_F_CERT_ID_NEW), "CERT_ID_NEW"},
74{ERR_FUNC(OCSP_F_D2I_OCSP_NONCE), "D2I_OCSP_NONCE"}, 75{ERR_FUNC(OCSP_F_D2I_OCSP_NONCE), "D2I_OCSP_NONCE"},
75{ERR_FUNC(OCSP_F_OCSP_BASIC_ADD1_STATUS), "OCSP_basic_add1_status"}, 76{ERR_FUNC(OCSP_F_OCSP_BASIC_ADD1_STATUS), "OCSP_basic_add1_status"},
76{ERR_FUNC(OCSP_F_OCSP_BASIC_SIGN), "OCSP_basic_sign"}, 77{ERR_FUNC(OCSP_F_OCSP_BASIC_SIGN), "OCSP_basic_sign"},
77{ERR_FUNC(OCSP_F_OCSP_BASIC_VERIFY), "OCSP_basic_verify"}, 78{ERR_FUNC(OCSP_F_OCSP_BASIC_VERIFY), "OCSP_basic_verify"},
78{ERR_FUNC(OCSP_F_OCSP_CERT_ID_NEW), "OCSP_cert_id_new"},
79{ERR_FUNC(OCSP_F_OCSP_CHECK_DELEGATED), "OCSP_CHECK_DELEGATED"}, 79{ERR_FUNC(OCSP_F_OCSP_CHECK_DELEGATED), "OCSP_CHECK_DELEGATED"},
80{ERR_FUNC(OCSP_F_OCSP_CHECK_IDS), "OCSP_CHECK_IDS"}, 80{ERR_FUNC(OCSP_F_OCSP_CHECK_IDS), "OCSP_CHECK_IDS"},
81{ERR_FUNC(OCSP_F_OCSP_CHECK_ISSUER), "OCSP_CHECK_ISSUER"}, 81{ERR_FUNC(OCSP_F_OCSP_CHECK_ISSUER), "OCSP_CHECK_ISSUER"},
@@ -86,7 +86,6 @@ static ERR_STRING_DATA OCSP_str_functs[]=
86{ERR_FUNC(OCSP_F_OCSP_REQUEST_VERIFY), "OCSP_request_verify"}, 86{ERR_FUNC(OCSP_F_OCSP_REQUEST_VERIFY), "OCSP_request_verify"},
87{ERR_FUNC(OCSP_F_OCSP_RESPONSE_GET1_BASIC), "OCSP_response_get1_basic"}, 87{ERR_FUNC(OCSP_F_OCSP_RESPONSE_GET1_BASIC), "OCSP_response_get1_basic"},
88{ERR_FUNC(OCSP_F_OCSP_SENDREQ_BIO), "OCSP_sendreq_bio"}, 88{ERR_FUNC(OCSP_F_OCSP_SENDREQ_BIO), "OCSP_sendreq_bio"},
89{ERR_FUNC(OCSP_F_PARSE_HTTP_LINE1), "PARSE_HTTP_LINE1"},
90{ERR_FUNC(OCSP_F_REQUEST_VERIFY), "REQUEST_VERIFY"}, 89{ERR_FUNC(OCSP_F_REQUEST_VERIFY), "REQUEST_VERIFY"},
91{0,NULL} 90{0,NULL}
92 }; 91 };
@@ -130,12 +129,15 @@ static ERR_STRING_DATA OCSP_str_reasons[]=
130 129
131void ERR_load_OCSP_strings(void) 130void ERR_load_OCSP_strings(void)
132 { 131 {
133#ifndef OPENSSL_NO_ERR 132 static int init=1;
134 133
135 if (ERR_func_error_string(OCSP_str_functs[0].error) == NULL) 134 if (init)
136 { 135 {
136 init=0;
137#ifndef OPENSSL_NO_ERR
137 ERR_load_strings(0,OCSP_str_functs); 138 ERR_load_strings(0,OCSP_str_functs);
138 ERR_load_strings(0,OCSP_str_reasons); 139 ERR_load_strings(0,OCSP_str_reasons);
139 }
140#endif 140#endif
141
142 }
141 } 143 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_ext.c b/src/lib/libcrypto/ocsp/ocsp_ext.c
index 815cc29d58..57399433fc 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ext.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ext.c
@@ -265,8 +265,8 @@ int OCSP_SINGLERESP_add_ext(OCSP_SINGLERESP *x, X509_EXTENSION *ex, int loc)
265 265
266/* also CRL Entry Extensions */ 266/* also CRL Entry Extensions */
267 267
268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d, 268ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, int (*i2d)(),
269 void *data, STACK_OF(ASN1_OBJECT) *sk) 269 char *data, STACK_OF(ASN1_OBJECT) *sk)
270 { 270 {
271 int i; 271 int i;
272 unsigned char *p, *b = NULL; 272 unsigned char *p, *b = NULL;
@@ -274,23 +274,18 @@ ASN1_STRING *ASN1_STRING_encode(ASN1_STRING *s, i2d_of_void *i2d,
274 if (data) 274 if (data)
275 { 275 {
276 if ((i=i2d(data,NULL)) <= 0) goto err; 276 if ((i=i2d(data,NULL)) <= 0) goto err;
277 if (!(b=p=OPENSSL_malloc((unsigned int)i))) 277 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
278 goto err; 278 goto err;
279 if (i2d(data, &p) <= 0) goto err; 279 if (i2d(data, &p) <= 0) goto err;
280 } 280 }
281 else if (sk) 281 else if (sk)
282 { 282 {
283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL, 283 if ((i=i2d_ASN1_SET_OF_ASN1_OBJECT(sk,NULL,i2d,V_ASN1_SEQUENCE,
284 (I2D_OF(ASN1_OBJECT))i2d, 284 V_ASN1_UNIVERSAL,IS_SEQUENCE))<=0) goto err;
285 V_ASN1_SEQUENCE, 285 if (!(b=p=(unsigned char*)OPENSSL_malloc((unsigned int)i)))
286 V_ASN1_UNIVERSAL,
287 IS_SEQUENCE))<=0) goto err;
288 if (!(b=p=OPENSSL_malloc((unsigned int)i)))
289 goto err; 286 goto err;
290 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,(I2D_OF(ASN1_OBJECT))i2d, 287 if (i2d_ASN1_SET_OF_ASN1_OBJECT(sk,&p,i2d,V_ASN1_SEQUENCE,
291 V_ASN1_SEQUENCE, 288 V_ASN1_UNIVERSAL,IS_SEQUENCE)<=0) goto err;
292 V_ASN1_UNIVERSAL,
293 IS_SEQUENCE)<=0) goto err;
294 } 289 }
295 else 290 else
296 { 291 {
@@ -444,8 +439,7 @@ X509_EXTENSION *OCSP_crlID_new(char *url, long *n, char *tim)
444 } 439 }
445 if (!(x = X509_EXTENSION_new())) goto err; 440 if (!(x = X509_EXTENSION_new())) goto err;
446 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err; 441 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_CrlID))) goto err;
447 if (!(ASN1_STRING_encode_of(OCSP_CRLID,x->value,i2d_OCSP_CRLID,cid, 442 if (!(ASN1_STRING_encode(x->value,i2d_OCSP_CRLID,(char*)cid,NULL)))
448 NULL)))
449 goto err; 443 goto err;
450 OCSP_CRLID_free(cid); 444 OCSP_CRLID_free(cid);
451 return x; 445 return x;
@@ -473,8 +467,7 @@ X509_EXTENSION *OCSP_accept_responses_new(char **oids)
473 if (!(x = X509_EXTENSION_new())) goto err; 467 if (!(x = X509_EXTENSION_new())) goto err;
474 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses))) 468 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_acceptableResponses)))
475 goto err; 469 goto err;
476 if (!(ASN1_STRING_encode_of(ASN1_OBJECT,x->value,i2d_ASN1_OBJECT,NULL, 470 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_OBJECT,NULL,sk)))
477 sk)))
478 goto err; 471 goto err;
479 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free); 472 sk_ASN1_OBJECT_pop_free(sk, ASN1_OBJECT_free);
480 return x; 473 return x;
@@ -494,8 +487,8 @@ X509_EXTENSION *OCSP_archive_cutoff_new(char* tim)
494 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err; 487 if (!(ASN1_GENERALIZEDTIME_set_string(gt, tim))) goto err;
495 if (!(x = X509_EXTENSION_new())) goto err; 488 if (!(x = X509_EXTENSION_new())) goto err;
496 if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err; 489 if (!(x->object=OBJ_nid2obj(NID_id_pkix_OCSP_archiveCutoff)))goto err;
497 if (!(ASN1_STRING_encode_of(ASN1_GENERALIZEDTIME,x->value, 490 if (!(ASN1_STRING_encode(x->value,i2d_ASN1_GENERALIZEDTIME,
498 i2d_ASN1_GENERALIZEDTIME,gt,NULL))) goto err; 491 (char*)gt,NULL))) goto err;
499 ASN1_GENERALIZEDTIME_free(gt); 492 ASN1_GENERALIZEDTIME_free(gt);
500 return x; 493 return x;
501err: 494err:
@@ -533,8 +526,8 @@ X509_EXTENSION *OCSP_url_svcloc_new(X509_NAME* issuer, char **urls)
533 if (!(x = X509_EXTENSION_new())) goto err; 526 if (!(x = X509_EXTENSION_new())) goto err;
534 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator))) 527 if (!(x->object = OBJ_nid2obj(NID_id_pkix_OCSP_serviceLocator)))
535 goto err; 528 goto err;
536 if (!(ASN1_STRING_encode_of(OCSP_SERVICELOC,x->value, 529 if (!(ASN1_STRING_encode(x->value, i2d_OCSP_SERVICELOC,
537 i2d_OCSP_SERVICELOC,sloc,NULL))) goto err; 530 (char*)sloc, NULL))) goto err;
538 OCSP_SERVICELOC_free(sloc); 531 OCSP_SERVICELOC_free(sloc);
539 return x; 532 return x;
540err: 533err:
diff --git a/src/lib/libcrypto/ocsp/ocsp_ht.c b/src/lib/libcrypto/ocsp/ocsp_ht.c
index a8e569b74a..2c48171883 100644
--- a/src/lib/libcrypto/ocsp/ocsp_ht.c
+++ b/src/lib/libcrypto/ocsp/ocsp_ht.c
@@ -1,9 +1,9 @@
1/* ocsp_ht.c */ 1/* ocsp_ht.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 2006. 3 * project 2000.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 2006 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 2000 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -68,404 +68,106 @@
68#define strtoul (unsigned long)strtol 68#define strtoul (unsigned long)strtol
69#endif /* OPENSSL_SYS_SUNOS */ 69#endif /* OPENSSL_SYS_SUNOS */
70 70
71/* Stateful OCSP request code, supporting non-blocking I/O */ 71/* Quick and dirty HTTP OCSP request handler.
72 72 * Could make this a bit cleverer by adding
73/* Opaque OCSP request status structure */ 73 * support for non blocking BIOs and a few
74 74 * other refinements.
75struct ocsp_req_ctx_st { 75 */
76 int state; /* Current I/O state */
77 unsigned char *iobuf; /* Line buffer */
78 int iobuflen; /* Line buffer length */
79 BIO *io; /* BIO to perform I/O with */
80 BIO *mem; /* Memory BIO response is built into */
81 unsigned long asn1_len; /* ASN1 length of response */
82 };
83
84#define OCSP_MAX_REQUEST_LENGTH (100 * 1024)
85#define OCSP_MAX_LINE_LEN 4096;
86
87/* OCSP states */
88
89/* If set no reading should be performed */
90#define OHS_NOREAD 0x1000
91/* Error condition */
92#define OHS_ERROR (0 | OHS_NOREAD)
93/* First line being read */
94#define OHS_FIRSTLINE 1
95/* MIME headers being read */
96#define OHS_HEADERS 2
97/* OCSP initial header (tag + length) being read */
98#define OHS_ASN1_HEADER 3
99/* OCSP content octets being read */
100#define OHS_ASN1_CONTENT 4
101/* Request being sent */
102#define OHS_ASN1_WRITE (6 | OHS_NOREAD)
103/* Request being flushed */
104#define OHS_ASN1_FLUSH (7 | OHS_NOREAD)
105/* Completed */
106#define OHS_DONE (8 | OHS_NOREAD)
107
108
109static int parse_http_line1(char *line);
110 76
111void OCSP_REQ_CTX_free(OCSP_REQ_CTX *rctx) 77OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req)
112 { 78{
113 if (rctx->mem) 79 BIO *mem = NULL;
114 BIO_free(rctx->mem); 80 char tmpbuf[1024];
115 if (rctx->iobuf) 81 OCSP_RESPONSE *resp = NULL;
116 OPENSSL_free(rctx->iobuf); 82 char *p, *q, *r;
117 OPENSSL_free(rctx); 83 int len, retcode;
84 static char req_txt[] =
85"POST %s HTTP/1.0\r\n\
86Content-Type: application/ocsp-request\r\n\
87Content-Length: %d\r\n\r\n";
88
89 len = i2d_OCSP_REQUEST(req, NULL);
90 if(BIO_printf(b, req_txt, path, len) < 0) {
91 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
92 goto err;
118 } 93 }
119 94 if(i2d_OCSP_REQUEST_bio(b, req) <= 0) {
120OCSP_REQ_CTX *OCSP_sendreq_new(BIO *io, char *path, OCSP_REQUEST *req, 95 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_WRITE_ERROR);
121 int maxline) 96 goto err;
122 { 97 }
123 static char post_hdr[] = "POST %s HTTP/1.0\r\n" 98 if(!(mem = BIO_new(BIO_s_mem()))) goto err;
124 "Content-Type: application/ocsp-request\r\n" 99 /* Copy response to a memory BIO: socket bios can't do gets! */
125 "Content-Length: %d\r\n\r\n"; 100 while ((len = BIO_read(b, tmpbuf, sizeof tmpbuf))) {
126 101 if(len < 0) {
127 OCSP_REQ_CTX *rctx; 102 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_READ_ERROR);
128 rctx = OPENSSL_malloc(sizeof(OCSP_REQ_CTX)); 103 goto err;
129 rctx->state = OHS_FIRSTLINE;
130 rctx->mem = BIO_new(BIO_s_mem());
131 rctx->io = io;
132 if (maxline > 0)
133 rctx->iobuflen = maxline;
134 else
135 rctx->iobuflen = OCSP_MAX_LINE_LEN;
136 rctx->iobuf = OPENSSL_malloc(rctx->iobuflen);
137 if (!path)
138 path = "/";
139
140 if (BIO_printf(rctx->mem, post_hdr, path,
141 i2d_OCSP_REQUEST(req, NULL)) <= 0)
142 {
143 rctx->state = OHS_ERROR;
144 return 0;
145 }
146 if (i2d_OCSP_REQUEST_bio(rctx->mem, req) <= 0)
147 {
148 rctx->state = OHS_ERROR;
149 return 0;
150 } 104 }
151 rctx->state = OHS_ASN1_WRITE; 105 BIO_write(mem, tmpbuf, len);
152 rctx->asn1_len = BIO_get_mem_data(rctx->mem, NULL);
153
154 return rctx;
155 } 106 }
107 if(BIO_gets(mem, tmpbuf, 512) <= 0) {
108 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
109 goto err;
110 }
111 /* Parse the HTTP response. This will look like this:
112 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
113 * (optional) informational message.
114 */
156 115
157/* Parse the HTTP response. This will look like this:
158 * "HTTP/1.0 200 OK". We need to obtain the numeric code and
159 * (optional) informational message.
160 */
161
162static int parse_http_line1(char *line)
163 {
164 int retcode;
165 char *p, *q, *r;
166 /* Skip to first white space (passed protocol info) */ 116 /* Skip to first white space (passed protocol info) */
167 117 for(p = tmpbuf; *p && !isspace((unsigned char)*p); p++) continue;
168 for(p = line; *p && !isspace((unsigned char)*p); p++) 118 if(!*p) {
169 continue; 119 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
170 if(!*p) 120 goto err;
171 { 121 }
172 OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
173 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
174 return 0;
175 }
176
177 /* Skip past white space to start of response code */ 122 /* Skip past white space to start of response code */
178 while(*p && isspace((unsigned char)*p)) 123 while(isspace((unsigned char)*p)) p++;
179 p++; 124 if(!*p) {
180 125 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
181 if(!*p) 126 goto err;
182 { 127 }
183 OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
184 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
185 return 0;
186 }
187
188 /* Find end of response code: first whitespace after start of code */ 128 /* Find end of response code: first whitespace after start of code */
189 for(q = p; *q && !isspace((unsigned char)*q); q++) 129 for(q = p; *q && !isspace((unsigned char)*q); q++) continue;
190 continue; 130 if(!*q) {
191 131 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
192 if(!*q) 132 goto err;
193 { 133 }
194 OCSPerr(OCSP_F_PARSE_HTTP_LINE1,
195 OCSP_R_SERVER_RESPONSE_PARSE_ERROR);
196 return 0;
197 }
198
199 /* Set end of response code and start of message */ 134 /* Set end of response code and start of message */
200 *q++ = 0; 135 *q++ = 0;
201
202 /* Attempt to parse numeric code */ 136 /* Attempt to parse numeric code */
203 retcode = strtoul(p, &r, 10); 137 retcode = strtoul(p, &r, 10);
204 138 if(*r) goto err;
205 if(*r)
206 return 0;
207
208 /* Skip over any leading white space in message */ 139 /* Skip over any leading white space in message */
209 while(*q && isspace((unsigned char)*q)) 140 while(isspace((unsigned char)*q)) q++;
210 q++; 141 if(*q) {
211 142 /* Finally zap any trailing white space in message (include CRLF) */
212 if(*q) 143 /* We know q has a non white space character so this is OK */
213 { 144 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--) *r = 0;
214 /* Finally zap any trailing white space in message (include 145 }
215 * CRLF) */ 146 if(retcode != 200) {
216 147 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_SERVER_RESPONSE_ERROR);
217 /* We know q has a non white space character so this is OK */ 148 if(!*q) {
218 for(r = q + strlen(q) - 1; isspace((unsigned char)*r); r--)
219 *r = 0;
220 }
221 if(retcode != 200)
222 {
223 OCSPerr(OCSP_F_PARSE_HTTP_LINE1, OCSP_R_SERVER_RESPONSE_ERROR);
224 if(!*q)
225 ERR_add_error_data(2, "Code=", p); 149 ERR_add_error_data(2, "Code=", p);
226 else 150 }
151 else {
227 ERR_add_error_data(4, "Code=", p, ",Reason=", q); 152 ERR_add_error_data(4, "Code=", p, ",Reason=", q);
228 return 0;
229 } 153 }
230 154 goto err;
231
232 return 1;
233
234 } 155 }
235 156 /* Find blank line marking beginning of content */
236int OCSP_sendreq_nbio(OCSP_RESPONSE **presp, OCSP_REQ_CTX *rctx) 157 while(BIO_gets(mem, tmpbuf, 512) > 0)
237 { 158 {
238 int i, n; 159 for(p = tmpbuf; isspace((unsigned char)*p); p++) continue;
239 const unsigned char *p; 160 if(!*p) break;
240 next_io:
241 if (!(rctx->state & OHS_NOREAD))
242 {
243 n = BIO_read(rctx->io, rctx->iobuf, rctx->iobuflen);
244
245 if (n <= 0)
246 {
247 if (BIO_should_retry(rctx->io))
248 return -1;
249 return 0;
250 }
251
252 /* Write data to memory BIO */
253
254 if (BIO_write(rctx->mem, rctx->iobuf, n) != n)
255 return 0;
256 }
257
258 switch(rctx->state)
259 {
260
261 case OHS_ASN1_WRITE:
262 n = BIO_get_mem_data(rctx->mem, &p);
263
264 i = BIO_write(rctx->io,
265 p + (n - rctx->asn1_len), rctx->asn1_len);
266
267 if (i <= 0)
268 {
269 if (BIO_should_retry(rctx->io))
270 return -1;
271 rctx->state = OHS_ERROR;
272 return 0;
273 }
274
275 rctx->asn1_len -= i;
276
277 if (rctx->asn1_len > 0)
278 goto next_io;
279
280 rctx->state = OHS_ASN1_FLUSH;
281
282 (void)BIO_reset(rctx->mem);
283
284 case OHS_ASN1_FLUSH:
285
286 i = BIO_flush(rctx->io);
287
288 if (i > 0)
289 {
290 rctx->state = OHS_FIRSTLINE;
291 goto next_io;
292 }
293
294 if (BIO_should_retry(rctx->io))
295 return -1;
296
297 rctx->state = OHS_ERROR;
298 return 0;
299
300 case OHS_ERROR:
301 return 0;
302
303 case OHS_FIRSTLINE:
304 case OHS_HEADERS:
305
306 /* Attempt to read a line in */
307
308 next_line:
309 /* Due to &%^*$" memory BIO behaviour with BIO_gets we
310 * have to check there's a complete line in there before
311 * calling BIO_gets or we'll just get a partial read.
312 */
313 n = BIO_get_mem_data(rctx->mem, &p);
314 if ((n <= 0) || !memchr(p, '\n', n))
315 {
316 if (n >= rctx->iobuflen)
317 {
318 rctx->state = OHS_ERROR;
319 return 0;
320 }
321 goto next_io;
322 }
323 n = BIO_gets(rctx->mem, (char *)rctx->iobuf, rctx->iobuflen);
324
325 if (n <= 0)
326 {
327 if (BIO_should_retry(rctx->mem))
328 goto next_io;
329 rctx->state = OHS_ERROR;
330 return 0;
331 }
332
333 /* Don't allow excessive lines */
334 if (n == rctx->iobuflen)
335 {
336 rctx->state = OHS_ERROR;
337 return 0;
338 }
339
340 /* First line */
341 if (rctx->state == OHS_FIRSTLINE)
342 {
343 if (parse_http_line1((char *)rctx->iobuf))
344 {
345 rctx->state = OHS_HEADERS;
346 goto next_line;
347 }
348 else
349 {
350 rctx->state = OHS_ERROR;
351 return 0;
352 }
353 }
354 else
355 {
356 /* Look for blank line: end of headers */
357 for (p = rctx->iobuf; *p; p++)
358 {
359 if ((*p != '\r') && (*p != '\n'))
360 break;
361 }
362 if (*p)
363 goto next_line;
364
365 rctx->state = OHS_ASN1_HEADER;
366
367 }
368
369 /* Fall thru */
370
371
372 case OHS_ASN1_HEADER:
373 /* Now reading ASN1 header: can read at least 6 bytes which
374 * is more than enough for any valid ASN1 SEQUENCE header
375 */
376 n = BIO_get_mem_data(rctx->mem, &p);
377 if (n < 6)
378 goto next_io;
379
380 /* Check it is an ASN1 SEQUENCE */
381 if (*p++ != (V_ASN1_SEQUENCE|V_ASN1_CONSTRUCTED))
382 {
383 rctx->state = OHS_ERROR;
384 return 0;
385 }
386
387 /* Check out length field */
388 if (*p & 0x80)
389 {
390 n = *p & 0x7F;
391 /* Not NDEF or excessive length */
392 if (!n || (n > 4))
393 {
394 rctx->state = OHS_ERROR;
395 return 0;
396 }
397 p++;
398 rctx->asn1_len = 0;
399 for (i = 0; i < n; i++)
400 {
401 rctx->asn1_len <<= 8;
402 rctx->asn1_len |= *p++;
403 }
404
405 if (rctx->asn1_len > OCSP_MAX_REQUEST_LENGTH)
406 {
407 rctx->state = OHS_ERROR;
408 return 0;
409 }
410
411 rctx->asn1_len += n + 2;
412 }
413 else
414 rctx->asn1_len = *p + 2;
415
416 rctx->state = OHS_ASN1_CONTENT;
417
418 /* Fall thru */
419
420 case OHS_ASN1_CONTENT:
421 n = BIO_get_mem_data(rctx->mem, &p);
422 if (n < (int)rctx->asn1_len)
423 goto next_io;
424
425
426 *presp = d2i_OCSP_RESPONSE(NULL, &p, rctx->asn1_len);
427 if (*presp)
428 {
429 rctx->state = OHS_DONE;
430 return 1;
431 }
432
433 rctx->state = OHS_ERROR;
434 return 0;
435
436 break;
437
438 case OHS_DONE:
439 return 1;
440
441 }
442
443
444
445 return 0;
446
447
448 } 161 }
449 162 if(*p) {
450/* Blocking OCSP request handler: now a special case of non-blocking I/O */ 163 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,OCSP_R_NO_CONTENT);
451 164 goto err;
452OCSP_RESPONSE *OCSP_sendreq_bio(BIO *b, char *path, OCSP_REQUEST *req) 165 }
453 { 166 if(!(resp = d2i_OCSP_RESPONSE_bio(mem, NULL))) {
454 OCSP_RESPONSE *resp = NULL; 167 OCSPerr(OCSP_F_OCSP_SENDREQ_BIO,ERR_R_NESTED_ASN1_ERROR);
455 OCSP_REQ_CTX *ctx; 168 goto err;
456 int rv;
457
458 ctx = OCSP_sendreq_new(b, path, req, -1);
459
460 do
461 {
462 rv = OCSP_sendreq_nbio(&resp, ctx);
463 } while ((rv == -1) && BIO_should_retry(b));
464
465 OCSP_REQ_CTX_free(ctx);
466
467 if (rv)
468 return resp;
469
470 return NULL;
471 } 169 }
170 err:
171 BIO_free(mem);
172 return resp;
173}
diff --git a/src/lib/libcrypto/ocsp/ocsp_lib.c b/src/lib/libcrypto/ocsp/ocsp_lib.c
index 27450811d7..9e87fc7895 100644
--- a/src/lib/libcrypto/ocsp/ocsp_lib.c
+++ b/src/lib/libcrypto/ocsp/ocsp_lib.c
@@ -112,7 +112,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
112 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm); 112 if (alg->algorithm != NULL) ASN1_OBJECT_free(alg->algorithm);
113 if ((nid = EVP_MD_type(dgst)) == NID_undef) 113 if ((nid = EVP_MD_type(dgst)) == NID_undef)
114 { 114 {
115 OCSPerr(OCSP_F_OCSP_CERT_ID_NEW,OCSP_R_UNKNOWN_NID); 115 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_UNKNOWN_NID);
116 goto err; 116 goto err;
117 } 117 }
118 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err; 118 if (!(alg->algorithm=OBJ_nid2obj(nid))) goto err;
@@ -134,7 +134,7 @@ OCSP_CERTID *OCSP_cert_id_new(const EVP_MD *dgst,
134 } 134 }
135 return cid; 135 return cid;
136digerr: 136digerr:
137 OCSPerr(OCSP_F_OCSP_CERT_ID_NEW,OCSP_R_DIGEST_ERR); 137 OCSPerr(OCSP_F_CERT_ID_NEW,OCSP_R_DIGEST_ERR);
138err: 138err:
139 if (cid) OCSP_CERTID_free(cid); 139 if (cid) OCSP_CERTID_free(cid);
140 return NULL; 140 return NULL;
diff --git a/src/lib/libcrypto/ocsp/ocsp_prn.c b/src/lib/libcrypto/ocsp/ocsp_prn.c
index 3dfb51c1e4..4b7bc28769 100644
--- a/src/lib/libcrypto/ocsp/ocsp_prn.c
+++ b/src/lib/libcrypto/ocsp/ocsp_prn.c
@@ -194,7 +194,7 @@ int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
194 194
195 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err; 195 if (BIO_puts(bp,"OCSP Response Data:\n") <= 0) goto err;
196 l=ASN1_ENUMERATED_get(o->responseStatus); 196 l=ASN1_ENUMERATED_get(o->responseStatus);
197 if (BIO_printf(bp," OCSP Response Status: %s (0x%lx)\n", 197 if (BIO_printf(bp," OCSP Response Status: %s (0x%x)\n",
198 OCSP_response_status_str(l), l) <= 0) goto err; 198 OCSP_response_status_str(l), l) <= 0) goto err;
199 if (rb == NULL) return 1; 199 if (rb == NULL) return 1;
200 if (BIO_puts(bp," Response Type: ") <= 0) 200 if (BIO_puts(bp," Response Type: ") <= 0)
@@ -252,7 +252,7 @@ int OCSP_RESPONSE_print(BIO *bp, OCSP_RESPONSE* o, unsigned long flags)
252 { 252 {
253 l=ASN1_ENUMERATED_get(rev->revocationReason); 253 l=ASN1_ENUMERATED_get(rev->revocationReason);
254 if (BIO_printf(bp, 254 if (BIO_printf(bp,
255 "\n Revocation Reason: %s (0x%lx)", 255 "\n Revocation Reason: %s (0x%x)",
256 OCSP_crl_reason_str(l), l) <= 0) 256 OCSP_crl_reason_str(l), l) <= 0)
257 goto err; 257 goto err;
258 } 258 }
diff --git a/src/lib/libcrypto/ocsp/ocsp_vfy.c b/src/lib/libcrypto/ocsp/ocsp_vfy.c
index 23ea41c847..3d58dfb06c 100644
--- a/src/lib/libcrypto/ocsp/ocsp_vfy.c
+++ b/src/lib/libcrypto/ocsp/ocsp_vfy.c
@@ -367,7 +367,7 @@ int OCSP_request_verify(OCSP_REQUEST *req, STACK_OF(X509) *certs, X509_STORE *st
367 return 0; 367 return 0;
368 } 368 }
369 gen = req->tbsRequest->requestorName; 369 gen = req->tbsRequest->requestorName;
370 if (!gen || gen->type != GEN_DIRNAME) 370 if (gen->type != GEN_DIRNAME)
371 { 371 {
372 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE); 372 OCSPerr(OCSP_F_OCSP_REQUEST_VERIFY, OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE);
373 return 0; 373 return 0;
diff --git a/src/lib/libcrypto/opensslconf.h.in b/src/lib/libcrypto/opensslconf.h.in
new file mode 100644
index 0000000000..685e83b7a3
--- /dev/null
+++ b/src/lib/libcrypto/opensslconf.h.in
@@ -0,0 +1,158 @@
1/* crypto/opensslconf.h.in */
2
3/* Generate 80386 code? */
4#undef I386_ONLY
5
6#if !(defined(VMS) || defined(__VMS)) /* VMS uses logical names instead */
7#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
8#define OPENSSLDIR "/usr/local/ssl"
9#endif
10#endif
11
12#undef OPENSSL_UNISTD
13#define OPENSSL_UNISTD <unistd.h>
14
15#undef OPENSSL_EXPORT_VAR_AS_FUNCTION
16
17#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
18#define IDEA_INT unsigned int
19#endif
20
21#if defined(HEADER_MD2_H) && !defined(MD2_INT)
22#define MD2_INT unsigned int
23#endif
24
25#if defined(HEADER_RC2_H) && !defined(RC2_INT)
26/* I need to put in a mod for the alpha - eay */
27#define RC2_INT unsigned int
28#endif
29
30#if defined(HEADER_RC4_H)
31#if !defined(RC4_INT)
32/* using int types make the structure larger but make the code faster
33 * on most boxes I have tested - up to %20 faster. */
34/*
35 * I don't know what does "most" mean, but declaring "int" is a must on:
36 * - Intel P6 because partial register stalls are very expensive;
37 * - elder Alpha because it lacks byte load/store instructions;
38 */
39#define RC4_INT unsigned int
40#endif
41#if !defined(RC4_CHUNK)
42/*
43 * This enables code handling data aligned at natural CPU word
44 * boundary. See crypto/rc4/rc4_enc.c for further details.
45 */
46#undef RC4_CHUNK
47#endif
48#endif
49
50#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
51/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
52 * %20 speed up (longs are 8 bytes, int's are 4). */
53#ifndef DES_LONG
54#define DES_LONG unsigned long
55#endif
56#endif
57
58#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
59#define CONFIG_HEADER_BN_H
60#undef BN_LLONG
61
62/* Should we define BN_DIV2W here? */
63
64/* Only one for the following should be defined */
65/* The prime number generation stuff may not work when
66 * EIGHT_BIT but I don't care since I've only used this mode
67 * for debuging the bignum libraries */
68#undef SIXTY_FOUR_BIT_LONG
69#undef SIXTY_FOUR_BIT
70#define THIRTY_TWO_BIT
71#undef SIXTEEN_BIT
72#undef EIGHT_BIT
73#endif
74
75#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
76#define CONFIG_HEADER_RC4_LOCL_H
77/* if this is defined data[i] is used instead of *data, this is a %20
78 * speedup on x86 */
79#undef RC4_INDEX
80#endif
81
82#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
83#define CONFIG_HEADER_BF_LOCL_H
84#undef BF_PTR
85#endif /* HEADER_BF_LOCL_H */
86
87#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
88#define CONFIG_HEADER_DES_LOCL_H
89#ifndef DES_DEFAULT_OPTIONS
90/* the following is tweaked from a config script, that is why it is a
91 * protected undef/define */
92#ifndef DES_PTR
93#undef DES_PTR
94#endif
95
96/* This helps C compiler generate the correct code for multiple functional
97 * units. It reduces register dependancies at the expense of 2 more
98 * registers */
99#ifndef DES_RISC1
100#undef DES_RISC1
101#endif
102
103#ifndef DES_RISC2
104#undef DES_RISC2
105#endif
106
107#if defined(DES_RISC1) && defined(DES_RISC2)
108YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
109#endif
110
111/* Unroll the inner loop, this sometimes helps, sometimes hinders.
112 * Very mucy CPU dependant */
113#ifndef DES_UNROLL
114#undef DES_UNROLL
115#endif
116
117/* These default values were supplied by
118 * Peter Gutman <pgut001@cs.auckland.ac.nz>
119 * They are only used if nothing else has been defined */
120#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
121/* Special defines which change the way the code is built depending on the
122 CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
123 even newer MIPS CPU's, but at the moment one size fits all for
124 optimization options. Older Sparc's work better with only UNROLL, but
125 there's no way to tell at compile time what it is you're running on */
126
127#if defined( sun ) /* Newer Sparc's */
128# define DES_PTR
129# define DES_RISC1
130# define DES_UNROLL
131#elif defined( __ultrix ) /* Older MIPS */
132# define DES_PTR
133# define DES_RISC2
134# define DES_UNROLL
135#elif defined( __osf1__ ) /* Alpha */
136# define DES_PTR
137# define DES_RISC2
138#elif defined ( _AIX ) /* RS6000 */
139 /* Unknown */
140#elif defined( __hpux ) /* HP-PA */
141 /* Unknown */
142#elif defined( __aux ) /* 68K */
143 /* Unknown */
144#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
145# define DES_UNROLL
146#elif defined( __sgi ) /* Newer MIPS */
147# define DES_PTR
148# define DES_RISC2
149# define DES_UNROLL
150#elif defined(i386) || defined(__i386__) /* x86 boxes, should be gcc */
151# define DES_PTR
152# define DES_RISC1
153# define DES_UNROLL
154#endif /* Systems-specific speed defines */
155#endif
156
157#endif /* DES_DEFAULT_OPTIONS */
158#endif /* HEADER_DES_LOCL_H */
diff --git a/src/lib/libcrypto/opensslv.h b/src/lib/libcrypto/opensslv.h
index b308894f18..e50c1baf00 100644
--- a/src/lib/libcrypto/opensslv.h
+++ b/src/lib/libcrypto/opensslv.h
@@ -12,7 +12,7 @@
12 * 0.9.3-beta2 0x00903002 (same as ...beta2-dev) 12 * 0.9.3-beta2 0x00903002 (same as ...beta2-dev)
13 * 0.9.3 0x0090300f 13 * 0.9.3 0x0090300f
14 * 0.9.3a 0x0090301f 14 * 0.9.3a 0x0090301f
15 * 0.9.4 0x0090400f 15 * 0.9.4 0x0090400f
16 * 1.2.3z 0x102031af 16 * 1.2.3z 0x102031af
17 * 17 *
18 * For continuity reasons (because 0.9.5 is already out, and is coded 18 * For continuity reasons (because 0.9.5 is already out, and is coded
@@ -25,11 +25,11 @@
25 * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for 25 * (Prior to 0.9.5a beta1, a different scheme was used: MMNNFFRBB for
26 * major minor fix final patch/beta) 26 * major minor fix final patch/beta)
27 */ 27 */
28#define OPENSSL_VERSION_NUMBER 0x0090808fL 28#define OPENSSL_VERSION_NUMBER 0x009070afL
29#ifdef OPENSSL_FIPS 29#ifdef OPENSSL_FIPS
30#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.8h-fips 28 May 2008" 30#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7j-fips 04 May 2006"
31#else 31#else
32#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.8h 28 May 2008" 32#define OPENSSL_VERSION_TEXT "OpenSSL 0.9.7j 04 May 2006"
33#endif 33#endif
34#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT 34#define OPENSSL_VERSION_PTEXT " part of " OPENSSL_VERSION_TEXT
35 35
@@ -83,7 +83,7 @@
83 * should only keep the versions that are binary compatible with the current. 83 * should only keep the versions that are binary compatible with the current.
84 */ 84 */
85#define SHLIB_VERSION_HISTORY "" 85#define SHLIB_VERSION_HISTORY ""
86#define SHLIB_VERSION_NUMBER "0.9.8" 86#define SHLIB_VERSION_NUMBER "0.9.7"
87 87
88 88
89#endif /* HEADER_OPENSSLV_H */ 89#endif /* HEADER_OPENSSLV_H */
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h
index 345fb1dc4d..285fd0b1d9 100644
--- a/src/lib/libcrypto/ossl_typ.h
+++ b/src/lib/libcrypto/ossl_typ.h
@@ -97,43 +97,15 @@ typedef int ASN1_NULL;
97 97
98#ifdef OPENSSL_SYS_WIN32 98#ifdef OPENSSL_SYS_WIN32
99#undef X509_NAME 99#undef X509_NAME
100#undef X509_EXTENSIONS
101#undef X509_CERT_PAIR
102#undef PKCS7_ISSUER_AND_SERIAL 100#undef PKCS7_ISSUER_AND_SERIAL
103#endif 101#endif
104 102
105#ifdef BIGNUM
106#undef BIGNUM
107#endif
108typedef struct bignum_st BIGNUM;
109typedef struct bignum_ctx BN_CTX;
110typedef struct bn_blinding_st BN_BLINDING;
111typedef struct bn_mont_ctx_st BN_MONT_CTX;
112typedef struct bn_recp_ctx_st BN_RECP_CTX;
113typedef struct bn_gencb_st BN_GENCB;
114
115typedef struct buf_mem_st BUF_MEM;
116
117typedef struct evp_cipher_st EVP_CIPHER; 103typedef struct evp_cipher_st EVP_CIPHER;
118typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX; 104typedef struct evp_cipher_ctx_st EVP_CIPHER_CTX;
119typedef struct env_md_st EVP_MD; 105typedef struct env_md_st EVP_MD;
120typedef struct env_md_ctx_st EVP_MD_CTX; 106typedef struct env_md_ctx_st EVP_MD_CTX;
121typedef struct evp_pkey_st EVP_PKEY; 107typedef struct evp_pkey_st EVP_PKEY;
122 108
123typedef struct dh_st DH;
124typedef struct dh_method DH_METHOD;
125
126typedef struct dsa_st DSA;
127typedef struct dsa_method DSA_METHOD;
128
129typedef struct rsa_st RSA;
130typedef struct rsa_meth_st RSA_METHOD;
131
132typedef struct rand_meth_st RAND_METHOD;
133
134typedef struct ecdh_method ECDH_METHOD;
135typedef struct ecdsa_method ECDSA_METHOD;
136
137typedef struct x509_st X509; 109typedef struct x509_st X509;
138typedef struct X509_algor_st X509_ALGOR; 110typedef struct X509_algor_st X509_ALGOR;
139typedef struct X509_crl_st X509_CRL; 111typedef struct X509_crl_st X509_CRL;
@@ -141,39 +113,10 @@ typedef struct X509_name_st X509_NAME;
141typedef struct x509_store_st X509_STORE; 113typedef struct x509_store_st X509_STORE;
142typedef struct x509_store_ctx_st X509_STORE_CTX; 114typedef struct x509_store_ctx_st X509_STORE_CTX;
143 115
144typedef struct v3_ext_ctx X509V3_CTX;
145typedef struct conf_st CONF;
146
147typedef struct store_st STORE;
148typedef struct store_method_st STORE_METHOD;
149
150typedef struct ui_st UI;
151typedef struct ui_method_st UI_METHOD;
152
153typedef struct st_ERR_FNS ERR_FNS;
154
155typedef struct engine_st ENGINE; 116typedef struct engine_st ENGINE;
156 117
157typedef struct X509_POLICY_NODE_st X509_POLICY_NODE;
158typedef struct X509_POLICY_LEVEL_st X509_POLICY_LEVEL;
159typedef struct X509_POLICY_TREE_st X509_POLICY_TREE;
160typedef struct X509_POLICY_CACHE_st X509_POLICY_CACHE;
161
162 /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */ 118 /* If placed in pkcs12.h, we end up with a circular depency with pkcs7.h */
163#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */ 119#define DECLARE_PKCS12_STACK_OF(type) /* Nothing */
164#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */ 120#define IMPLEMENT_PKCS12_STACK_OF(type) /* Nothing */
165 121
166typedef struct crypto_ex_data_st CRYPTO_EX_DATA;
167/* Callback types for crypto.h */
168typedef int CRYPTO_EX_new(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
169 int idx, long argl, void *argp);
170typedef void CRYPTO_EX_free(void *parent, void *ptr, CRYPTO_EX_DATA *ad,
171 int idx, long argl, void *argp);
172typedef int CRYPTO_EX_dup(CRYPTO_EX_DATA *to, CRYPTO_EX_DATA *from, void *from_d,
173 int idx, long argl, void *argp);
174
175typedef struct ocsp_req_ctx_st OCSP_REQ_CTX;
176typedef struct ocsp_response_st OCSP_RESPONSE;
177typedef struct ocsp_responder_id_st OCSP_RESPID;
178
179#endif /* def HEADER_OPENSSL_TYPES_H */ 122#endif /* def HEADER_OPENSSL_TYPES_H */
diff --git a/src/lib/libcrypto/pem/Makefile b/src/lib/libcrypto/pem/Makefile
new file mode 100644
index 0000000000..742194fd24
--- /dev/null
+++ b/src/lib/libcrypto/pem/Makefile
@@ -0,0 +1,241 @@
1#
2# OpenSSL/crypto/pem/Makefile
3#
4
5DIR= pem
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c \
21 pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c
22
23LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o \
24 pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o
25
26SRC= $(LIBSRC)
27
28EXHEADER= pem.h pem2.h
29HEADER= $(EXHEADER)
30
31ALL= $(GENERAL) $(SRC) $(HEADER)
32
33top:
34 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
35
36all: lib
37
38lib: $(LIBOBJ)
39 $(AR) $(LIB) $(LIBOBJ)
40 $(RANLIB) $(LIB) || echo Never mind.
41 @touch lib
42
43files:
44 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
45
46links: $(EXHEADER)
47 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
48 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
49 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
50
51install:
52 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
53 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
54 do \
55 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
56 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
57 done;
58
59tags:
60 ctags $(SRC)
61
62tests:
63
64lint:
65 lint -DLINT $(INCLUDES) $(SRC)>fluff
66
67depend:
68 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
69 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(LIBSRC)
70
71dclean:
72 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
73 mv -f Makefile.new $(MAKEFILE)
74
75clean:
76 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
77
78# DO NOT DELETE THIS LINE -- make depend depends on it.
79
80pem_all.o: ../../e_os.h ../../include/openssl/asn1.h
81pem_all.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
82pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/dh.h
83pem_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
84pem_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
85pem_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
86pem_all.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
87pem_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
88pem_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
89pem_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
90pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
91pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
92pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
93pem_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
94pem_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_all.c
95pem_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
96pem_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
97pem_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
98pem_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
99pem_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
100pem_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
101pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
102pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
103pem_err.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
104pem_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
105pem_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
106pem_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
107pem_err.o: ../../include/openssl/x509_vfy.h pem_err.c
108pem_info.o: ../../e_os.h ../../include/openssl/asn1.h
109pem_info.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
110pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/dsa.h
111pem_info.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
112pem_info.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
113pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
114pem_info.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
115pem_info.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
116pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
117pem_info.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
118pem_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
119pem_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
120pem_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
121pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
122pem_info.o: ../cryptlib.h pem_info.c
123pem_lib.o: ../../e_os.h ../../include/openssl/asn1.h
124pem_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
125pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
126pem_lib.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h
127pem_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
128pem_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
129pem_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
130pem_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
131pem_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
132pem_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
133pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
134pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
135pem_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
136pem_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
137pem_lib.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
138pem_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
139pem_lib.o: ../cryptlib.h pem_lib.c
140pem_oth.o: ../../e_os.h ../../include/openssl/asn1.h
141pem_oth.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
142pem_oth.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
143pem_oth.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
144pem_oth.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
145pem_oth.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
146pem_oth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
147pem_oth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
148pem_oth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
149pem_oth.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
150pem_oth.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
151pem_oth.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
152pem_oth.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
153pem_oth.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_oth.c
154pem_pk8.o: ../../e_os.h ../../include/openssl/asn1.h
155pem_pk8.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
156pem_pk8.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
157pem_pk8.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
158pem_pk8.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
159pem_pk8.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
160pem_pk8.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
161pem_pk8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
162pem_pk8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
163pem_pk8.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
164pem_pk8.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
165pem_pk8.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
166pem_pk8.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
167pem_pk8.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
168pem_pk8.o: ../cryptlib.h pem_pk8.c
169pem_pkey.o: ../../e_os.h ../../include/openssl/asn1.h
170pem_pkey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
171pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
172pem_pkey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
173pem_pkey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
174pem_pkey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
175pem_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
176pem_pkey.o: ../../include/openssl/opensslconf.h
177pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
178pem_pkey.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
179pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
180pem_pkey.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
181pem_pkey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
182pem_pkey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
183pem_pkey.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pkey.c
184pem_seal.o: ../../e_os.h ../../include/openssl/asn1.h
185pem_seal.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
186pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
187pem_seal.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
188pem_seal.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
189pem_seal.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
190pem_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
191pem_seal.o: ../../include/openssl/opensslconf.h
192pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
193pem_seal.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
194pem_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
195pem_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
196pem_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
197pem_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
198pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_seal.c
199pem_sign.o: ../../e_os.h ../../include/openssl/asn1.h
200pem_sign.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
201pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
202pem_sign.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
203pem_sign.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
204pem_sign.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
205pem_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
206pem_sign.o: ../../include/openssl/opensslconf.h
207pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
208pem_sign.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
209pem_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
210pem_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
211pem_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
212pem_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
213pem_sign.o: ../cryptlib.h pem_sign.c
214pem_x509.o: ../../e_os.h ../../include/openssl/asn1.h
215pem_x509.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
216pem_x509.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
217pem_x509.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
218pem_x509.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
219pem_x509.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
220pem_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
221pem_x509.o: ../../include/openssl/opensslconf.h
222pem_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
223pem_x509.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
224pem_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
225pem_x509.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
226pem_x509.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
227pem_x509.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_x509.c
228pem_xaux.o: ../../e_os.h ../../include/openssl/asn1.h
229pem_xaux.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
230pem_xaux.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
231pem_xaux.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
232pem_xaux.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
233pem_xaux.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
234pem_xaux.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
235pem_xaux.o: ../../include/openssl/opensslconf.h
236pem_xaux.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
237pem_xaux.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
238pem_xaux.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
239pem_xaux.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
240pem_xaux.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
241pem_xaux.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_xaux.c
diff --git a/src/lib/libcrypto/pem/Makefile.ssl b/src/lib/libcrypto/pem/Makefile.ssl
new file mode 100644
index 0000000000..d3043eb401
--- /dev/null
+++ b/src/lib/libcrypto/pem/Makefile.ssl
@@ -0,0 +1,336 @@
1#
2# SSLeay/crypto/pem/Makefile
3#
4
5DIR= pem
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= pem_sign.c pem_seal.c pem_info.c pem_lib.c pem_all.c pem_err.c \
27 pem_x509.c pem_xaux.c pem_oth.c pem_pk8.c pem_pkey.c
28
29LIBOBJ= pem_sign.o pem_seal.o pem_info.o pem_lib.o pem_all.o pem_err.o \
30 pem_x509.o pem_xaux.o pem_oth.o pem_pk8.o pem_pkey.o
31
32SRC= $(LIBSRC)
33
34EXHEADER= pem.h pem2.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) || echo Never mind.
47 @touch lib
48
49files:
50 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
51
52links: $(EXHEADER)
53 @sh $(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) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(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
85pem_all.o: ../../e_os.h ../../include/openssl/aes.h
86pem_all.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87pem_all.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
88pem_all.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
89pem_all.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
90pem_all.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
91pem_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
92pem_all.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93pem_all.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
94pem_all.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
95pem_all.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
96pem_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
97pem_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
98pem_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
99pem_all.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
100pem_all.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
101pem_all.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
102pem_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
103pem_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
104pem_all.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
105pem_all.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
106pem_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_all.c
107pem_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
108pem_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
109pem_err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
110pem_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
111pem_err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
112pem_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
113pem_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
114pem_err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
115pem_err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
116pem_err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
117pem_err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
118pem_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
119pem_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
120pem_err.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
121pem_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
122pem_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
123pem_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
124pem_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
125pem_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
126pem_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
127pem_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
128pem_err.o: pem_err.c
129pem_info.o: ../../e_os.h ../../include/openssl/aes.h
130pem_info.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
131pem_info.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
132pem_info.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
133pem_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
134pem_info.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
135pem_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
136pem_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
137pem_info.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
138pem_info.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
139pem_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
140pem_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
141pem_info.o: ../../include/openssl/opensslconf.h
142pem_info.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
143pem_info.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
144pem_info.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
145pem_info.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
146pem_info.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
147pem_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
148pem_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
149pem_info.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
150pem_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
151pem_info.o: ../cryptlib.h pem_info.c
152pem_lib.o: ../../e_os.h ../../include/openssl/aes.h
153pem_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
154pem_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
155pem_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
156pem_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
157pem_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
158pem_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
159pem_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
160pem_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
161pem_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
162pem_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
163pem_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
164pem_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
165pem_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
166pem_lib.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
167pem_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
168pem_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
169pem_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
170pem_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
171pem_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
172pem_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
173pem_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
174pem_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_lib.c
175pem_oth.o: ../../e_os.h ../../include/openssl/aes.h
176pem_oth.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
177pem_oth.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
178pem_oth.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
179pem_oth.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
180pem_oth.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
181pem_oth.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
182pem_oth.o: ../../include/openssl/err.h ../../include/openssl/evp.h
183pem_oth.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
184pem_oth.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
185pem_oth.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
186pem_oth.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
187pem_oth.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
188pem_oth.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
189pem_oth.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
190pem_oth.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
191pem_oth.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
192pem_oth.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
193pem_oth.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
194pem_oth.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
195pem_oth.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
196pem_oth.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
197pem_oth.o: ../cryptlib.h pem_oth.c
198pem_pk8.o: ../../e_os.h ../../include/openssl/aes.h
199pem_pk8.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
200pem_pk8.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
201pem_pk8.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
202pem_pk8.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
203pem_pk8.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
204pem_pk8.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
205pem_pk8.o: ../../include/openssl/err.h ../../include/openssl/evp.h
206pem_pk8.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
207pem_pk8.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
208pem_pk8.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
209pem_pk8.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
210pem_pk8.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
211pem_pk8.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
212pem_pk8.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs12.h
213pem_pk8.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
214pem_pk8.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
215pem_pk8.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
216pem_pk8.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
217pem_pk8.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
218pem_pk8.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
219pem_pk8.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
220pem_pk8.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_pk8.c
221pem_pkey.o: ../../e_os.h ../../include/openssl/aes.h
222pem_pkey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
223pem_pkey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
224pem_pkey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
225pem_pkey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
226pem_pkey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
227pem_pkey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
228pem_pkey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
229pem_pkey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
230pem_pkey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
231pem_pkey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
232pem_pkey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
233pem_pkey.o: ../../include/openssl/opensslconf.h
234pem_pkey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
235pem_pkey.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
236pem_pkey.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
237pem_pkey.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
238pem_pkey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
239pem_pkey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
240pem_pkey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
241pem_pkey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
242pem_pkey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
243pem_pkey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
244pem_pkey.o: ../cryptlib.h pem_pkey.c
245pem_seal.o: ../../e_os.h ../../include/openssl/aes.h
246pem_seal.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
247pem_seal.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
248pem_seal.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
249pem_seal.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
250pem_seal.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
251pem_seal.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
252pem_seal.o: ../../include/openssl/err.h ../../include/openssl/evp.h
253pem_seal.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
254pem_seal.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
255pem_seal.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
256pem_seal.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
257pem_seal.o: ../../include/openssl/opensslconf.h
258pem_seal.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
259pem_seal.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
260pem_seal.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
261pem_seal.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
262pem_seal.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
263pem_seal.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
264pem_seal.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
265pem_seal.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
266pem_seal.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
267pem_seal.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_seal.c
268pem_sign.o: ../../e_os.h ../../include/openssl/aes.h
269pem_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
270pem_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
271pem_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
272pem_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
273pem_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
274pem_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
275pem_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
276pem_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
277pem_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
278pem_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
279pem_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
280pem_sign.o: ../../include/openssl/opensslconf.h
281pem_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
282pem_sign.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
283pem_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
284pem_sign.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
285pem_sign.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
286pem_sign.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
287pem_sign.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
288pem_sign.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
289pem_sign.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
290pem_sign.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pem_sign.c
291pem_x509.o: ../../e_os.h ../../include/openssl/aes.h
292pem_x509.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
293pem_x509.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
294pem_x509.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
295pem_x509.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
296pem_x509.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
297pem_x509.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
298pem_x509.o: ../../include/openssl/err.h ../../include/openssl/evp.h
299pem_x509.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
300pem_x509.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
301pem_x509.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
302pem_x509.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
303pem_x509.o: ../../include/openssl/opensslconf.h
304pem_x509.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
305pem_x509.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
306pem_x509.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
307pem_x509.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
308pem_x509.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
309pem_x509.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
310pem_x509.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
311pem_x509.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
312pem_x509.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
313pem_x509.o: ../cryptlib.h pem_x509.c
314pem_xaux.o: ../../e_os.h ../../include/openssl/aes.h
315pem_xaux.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
316pem_xaux.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
317pem_xaux.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
318pem_xaux.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
319pem_xaux.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
320pem_xaux.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
321pem_xaux.o: ../../include/openssl/err.h ../../include/openssl/evp.h
322pem_xaux.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
323pem_xaux.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
324pem_xaux.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
325pem_xaux.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
326pem_xaux.o: ../../include/openssl/opensslconf.h
327pem_xaux.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
328pem_xaux.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
329pem_xaux.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
330pem_xaux.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
331pem_xaux.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
332pem_xaux.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
333pem_xaux.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
334pem_xaux.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
335pem_xaux.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
336pem_xaux.o: ../cryptlib.h pem_xaux.c
diff --git a/src/lib/libcrypto/pem/pem.h b/src/lib/libcrypto/pem/pem.h
index 670afa670b..d330cbf9a3 100644
--- a/src/lib/libcrypto/pem/pem.h
+++ b/src/lib/libcrypto/pem/pem.h
@@ -59,7 +59,6 @@
59#ifndef HEADER_PEM_H 59#ifndef HEADER_PEM_H
60#define HEADER_PEM_H 60#define HEADER_PEM_H
61 61
62#include <openssl/e_os2.h>
63#ifndef OPENSSL_NO_BIO 62#ifndef OPENSSL_NO_BIO
64#include <openssl/bio.h> 63#include <openssl/bio.h>
65#endif 64#endif
@@ -69,6 +68,7 @@
69#include <openssl/evp.h> 68#include <openssl/evp.h>
70#include <openssl/x509.h> 69#include <openssl/x509.h>
71#include <openssl/pem2.h> 70#include <openssl/pem2.h>
71#include <openssl/e_os2.h>
72 72
73#ifdef __cplusplus 73#ifdef __cplusplus
74extern "C" { 74extern "C" {
@@ -91,9 +91,6 @@ extern "C" {
91#define PEM_OBJ_DHPARAMS 17 91#define PEM_OBJ_DHPARAMS 17
92#define PEM_OBJ_DSAPARAMS 18 92#define PEM_OBJ_DSAPARAMS 18
93#define PEM_OBJ_PRIV_RSA_PUBLIC 19 93#define PEM_OBJ_PRIV_RSA_PUBLIC 19
94#define PEM_OBJ_PRIV_ECDSA 20
95#define PEM_OBJ_PUB_ECDSA 21
96#define PEM_OBJ_ECPARAMETERS 22
97 94
98#define PEM_ERROR 30 95#define PEM_ERROR 30
99#define PEM_DEK_DES_CBC 40 96#define PEM_DEK_DES_CBC 40
@@ -113,7 +110,6 @@ extern "C" {
113 110
114#define PEM_STRING_X509_OLD "X509 CERTIFICATE" 111#define PEM_STRING_X509_OLD "X509 CERTIFICATE"
115#define PEM_STRING_X509 "CERTIFICATE" 112#define PEM_STRING_X509 "CERTIFICATE"
116#define PEM_STRING_X509_PAIR "CERTIFICATE PAIR"
117#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE" 113#define PEM_STRING_X509_TRUSTED "TRUSTED CERTIFICATE"
118#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST" 114#define PEM_STRING_X509_REQ_OLD "NEW CERTIFICATE REQUEST"
119#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST" 115#define PEM_STRING_X509_REQ "CERTIFICATE REQUEST"
@@ -130,10 +126,6 @@ extern "C" {
130#define PEM_STRING_DHPARAMS "DH PARAMETERS" 126#define PEM_STRING_DHPARAMS "DH PARAMETERS"
131#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS" 127#define PEM_STRING_SSL_SESSION "SSL SESSION PARAMETERS"
132#define PEM_STRING_DSAPARAMS "DSA PARAMETERS" 128#define PEM_STRING_DSAPARAMS "DSA PARAMETERS"
133#define PEM_STRING_ECDSA_PUBLIC "ECDSA PUBLIC KEY"
134#define PEM_STRING_ECPARAMETERS "EC PARAMETERS"
135#define PEM_STRING_ECPRIVATEKEY "EC PRIVATE KEY"
136#define PEM_STRING_CMS "CMS"
137 129
138 /* Note that this structure is initialised by PEM_SealInit and cleaned up 130 /* Note that this structure is initialised by PEM_SealInit and cleaned up
139 by PEM_SealFinal (at least for now) */ 131 by PEM_SealFinal (at least for now) */
@@ -221,50 +213,24 @@ typedef struct pem_ctx_st
221#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \ 213#define IMPLEMENT_PEM_read_fp(name, type, str, asn1) \
222type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\ 214type *PEM_read_##name(FILE *fp, type **x, pem_password_cb *cb, void *u)\
223{ \ 215{ \
224 return (type*)PEM_ASN1_read(CHECKED_D2I_OF(type, d2i_##asn1), \ 216return((type *)PEM_ASN1_read((char *(*)())d2i_##asn1, str,fp,(char **)x,\
225 str, fp, \ 217 cb,u)); \
226 CHECKED_PPTR_OF(type, x), \ 218} \
227 cb, u); \
228}
229 219
230#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \ 220#define IMPLEMENT_PEM_write_fp(name, type, str, asn1) \
231int PEM_write_##name(FILE *fp, type *x) \ 221int PEM_write_##name(FILE *fp, type *x) \
232{ \ 222{ \
233 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 223return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, (char *)x, \
234 str, fp, \ 224 NULL,NULL,0,NULL,NULL)); \
235 CHECKED_PTR_OF(type, x), \ 225}
236 NULL, NULL, 0, NULL, NULL); \
237}
238
239#define IMPLEMENT_PEM_write_fp_const(name, type, str, asn1) \
240int PEM_write_##name(FILE *fp, const type *x) \
241{ \
242 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \
243 str, fp, \
244 CHECKED_PTR_OF(const type, x), \
245 NULL, NULL, 0, NULL, NULL); \
246}
247 226
248#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \ 227#define IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) \
249int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 228int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
250 unsigned char *kstr, int klen, pem_password_cb *cb, \ 229 unsigned char *kstr, int klen, pem_password_cb *cb, \
251 void *u) \ 230 void *u) \
252 { \ 231 { \
253 return PEM_ASN1_write(CHECKED_I2D_OF(type, i2d_##asn1), \ 232 return(PEM_ASN1_write((int (*)())i2d_##asn1,str,fp, \
254 str, fp, \ 233 (char *)x,enc,kstr,klen,cb,u)); \
255 CHECKED_PTR_OF(type, x), \
256 enc, kstr, klen, cb, u); \
257 }
258
259#define IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1) \
260int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
261 unsigned char *kstr, int klen, pem_password_cb *cb, \
262 void *u) \
263 { \
264 return PEM_ASN1_write(CHECKED_I2D_OF(const type, i2d_##asn1), \
265 str, fp, \
266 CHECKED_PTR_OF(const type, x), \
267 enc, kstr, klen, cb, u); \
268 } 234 }
269 235
270#endif 236#endif
@@ -272,66 +238,33 @@ int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
272#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 238#define IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
273type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\ 239type *PEM_read_bio_##name(BIO *bp, type **x, pem_password_cb *cb, void *u)\
274{ \ 240{ \
275 return (type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i_##asn1), \ 241return((type *)PEM_ASN1_read_bio((char *(*)())d2i_##asn1, str,bp,\
276 str, bp, \ 242 (char **)x,cb,u)); \
277 CHECKED_PPTR_OF(type, x), \
278 cb, u); \
279} 243}
280 244
281#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 245#define IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
282int PEM_write_bio_##name(BIO *bp, type *x) \ 246int PEM_write_bio_##name(BIO *bp, type *x) \
283{ \ 247{ \
284 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 248return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, (char *)x, \
285 str, bp, \ 249 NULL,NULL,0,NULL,NULL)); \
286 CHECKED_PTR_OF(type, x), \
287 NULL, NULL, 0, NULL, NULL); \
288}
289
290#define IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
291int PEM_write_bio_##name(BIO *bp, const type *x) \
292{ \
293 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \
294 str, bp, \
295 CHECKED_PTR_OF(const type, x), \
296 NULL, NULL, 0, NULL, NULL); \
297} 250}
298 251
299#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 252#define IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
300int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 253int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
301 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \ 254 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
302 { \ 255 { \
303 return PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d_##asn1), \ 256 return(PEM_ASN1_write_bio((int (*)())i2d_##asn1,str,bp, \
304 str, bp, \ 257 (char *)x,enc,kstr,klen,cb,u)); \
305 CHECKED_PTR_OF(type, x), \
306 enc, kstr, klen, cb, u); \
307 }
308
309#define IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
310int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
311 unsigned char *kstr, int klen, pem_password_cb *cb, void *u) \
312 { \
313 return PEM_ASN1_write_bio(CHECKED_I2D_OF(const type, i2d_##asn1), \
314 str, bp, \
315 CHECKED_PTR_OF(const type, x), \
316 enc, kstr, klen, cb, u); \
317 } 258 }
318 259
319#define IMPLEMENT_PEM_write(name, type, str, asn1) \ 260#define IMPLEMENT_PEM_write(name, type, str, asn1) \
320 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \ 261 IMPLEMENT_PEM_write_bio(name, type, str, asn1) \
321 IMPLEMENT_PEM_write_fp(name, type, str, asn1) 262 IMPLEMENT_PEM_write_fp(name, type, str, asn1)
322 263
323#define IMPLEMENT_PEM_write_const(name, type, str, asn1) \
324 IMPLEMENT_PEM_write_bio_const(name, type, str, asn1) \
325 IMPLEMENT_PEM_write_fp_const(name, type, str, asn1)
326
327#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \ 264#define IMPLEMENT_PEM_write_cb(name, type, str, asn1) \
328 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \ 265 IMPLEMENT_PEM_write_cb_bio(name, type, str, asn1) \
329 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1) 266 IMPLEMENT_PEM_write_cb_fp(name, type, str, asn1)
330 267
331#define IMPLEMENT_PEM_write_cb_const(name, type, str, asn1) \
332 IMPLEMENT_PEM_write_cb_bio_const(name, type, str, asn1) \
333 IMPLEMENT_PEM_write_cb_fp_const(name, type, str, asn1)
334
335#define IMPLEMENT_PEM_read(name, type, str, asn1) \ 268#define IMPLEMENT_PEM_read(name, type, str, asn1) \
336 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \ 269 IMPLEMENT_PEM_read_bio(name, type, str, asn1) \
337 IMPLEMENT_PEM_read_fp(name, type, str, asn1) 270 IMPLEMENT_PEM_read_fp(name, type, str, asn1)
@@ -340,10 +273,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
340 IMPLEMENT_PEM_read(name, type, str, asn1) \ 273 IMPLEMENT_PEM_read(name, type, str, asn1) \
341 IMPLEMENT_PEM_write(name, type, str, asn1) 274 IMPLEMENT_PEM_write(name, type, str, asn1)
342 275
343#define IMPLEMENT_PEM_rw_const(name, type, str, asn1) \
344 IMPLEMENT_PEM_read(name, type, str, asn1) \
345 IMPLEMENT_PEM_write_const(name, type, str, asn1)
346
347#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \ 276#define IMPLEMENT_PEM_rw_cb(name, type, str, asn1) \
348 IMPLEMENT_PEM_read(name, type, str, asn1) \ 277 IMPLEMENT_PEM_read(name, type, str, asn1) \
349 IMPLEMENT_PEM_write_cb(name, type, str, asn1) 278 IMPLEMENT_PEM_write_cb(name, type, str, asn1)
@@ -364,9 +293,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
364#define DECLARE_PEM_write_fp(name, type) \ 293#define DECLARE_PEM_write_fp(name, type) \
365 int PEM_write_##name(FILE *fp, type *x); 294 int PEM_write_##name(FILE *fp, type *x);
366 295
367#define DECLARE_PEM_write_fp_const(name, type) \
368 int PEM_write_##name(FILE *fp, const type *x);
369
370#define DECLARE_PEM_write_cb_fp(name, type) \ 296#define DECLARE_PEM_write_cb_fp(name, type) \
371 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \ 297 int PEM_write_##name(FILE *fp, type *x, const EVP_CIPHER *enc, \
372 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 298 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
@@ -380,9 +306,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
380#define DECLARE_PEM_write_bio(name, type) \ 306#define DECLARE_PEM_write_bio(name, type) \
381 int PEM_write_bio_##name(BIO *bp, type *x); 307 int PEM_write_bio_##name(BIO *bp, type *x);
382 308
383#define DECLARE_PEM_write_bio_const(name, type) \
384 int PEM_write_bio_##name(BIO *bp, const type *x);
385
386#define DECLARE_PEM_write_cb_bio(name, type) \ 309#define DECLARE_PEM_write_cb_bio(name, type) \
387 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \ 310 int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
388 unsigned char *kstr, int klen, pem_password_cb *cb, void *u); 311 unsigned char *kstr, int klen, pem_password_cb *cb, void *u);
@@ -399,10 +322,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
399 DECLARE_PEM_write_bio(name, type) \ 322 DECLARE_PEM_write_bio(name, type) \
400 DECLARE_PEM_write_fp(name, type) 323 DECLARE_PEM_write_fp(name, type)
401 324
402#define DECLARE_PEM_write_const(name, type) \
403 DECLARE_PEM_write_bio_const(name, type) \
404 DECLARE_PEM_write_fp_const(name, type)
405
406#define DECLARE_PEM_write_cb(name, type) \ 325#define DECLARE_PEM_write_cb(name, type) \
407 DECLARE_PEM_write_cb_bio(name, type) \ 326 DECLARE_PEM_write_cb_bio(name, type) \
408 DECLARE_PEM_write_cb_fp(name, type) 327 DECLARE_PEM_write_cb_fp(name, type)
@@ -415,10 +334,6 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
415 DECLARE_PEM_read(name, type) \ 334 DECLARE_PEM_read(name, type) \
416 DECLARE_PEM_write(name, type) 335 DECLARE_PEM_write(name, type)
417 336
418#define DECLARE_PEM_rw_const(name, type) \
419 DECLARE_PEM_read(name, type) \
420 DECLARE_PEM_write_const(name, type)
421
422#define DECLARE_PEM_rw_cb(name, type) \ 337#define DECLARE_PEM_rw_cb(name, type) \
423 DECLARE_PEM_read(name, type) \ 338 DECLARE_PEM_read(name, type) \
424 DECLARE_PEM_write_cb(name, type) 339 DECLARE_PEM_write_cb(name, type)
@@ -488,6 +403,9 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
488 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\ 403 (char *(*)())d2i_NETSCAPE_CERT_SEQUENCE,PEM_STRING_X509,fp,\
489 (char **)x,cb,u) 404 (char **)x,cb,u)
490 405
406#define PEM_write_bio_SSL_SESSION(bp,x) \
407 PEM_ASN1_write_bio((int (*)())i2d_SSL_SESSION, \
408 PEM_STRING_SSL_SESSION,bp, (char *)x, NULL,NULL,0,NULL,NULL)
491#define PEM_write_bio_X509(bp,x) \ 409#define PEM_write_bio_X509(bp,x) \
492 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \ 410 PEM_ASN1_write_bio((int (*)())i2d_X509,PEM_STRING_X509,bp, \
493 (char *)x, NULL,NULL,0,NULL,NULL) 411 (char *)x, NULL,NULL,0,NULL,NULL)
@@ -526,6 +444,8 @@ int PEM_write_bio_##name(BIO *bp, type *x, const EVP_CIPHER *enc, \
526 PEM_STRING_X509,bp, \ 444 PEM_STRING_X509,bp, \
527 (char *)x, NULL,NULL,0,NULL,NULL) 445 (char *)x, NULL,NULL,0,NULL,NULL)
528 446
447#define PEM_read_bio_SSL_SESSION(bp,x,cb,u) (SSL_SESSION *)PEM_ASN1_read_bio( \
448 (char *(*)())d2i_SSL_SESSION,PEM_STRING_SSL_SESSION,bp,(char **)x,cb,u)
529#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \ 449#define PEM_read_bio_X509(bp,x,cb,u) (X509 *)PEM_ASN1_read_bio( \
530 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u) 450 (char *(*)())d2i_X509,PEM_STRING_X509,bp,(char **)x,cb,u)
531#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \ 451#define PEM_read_bio_X509_REQ(bp,x,cb,u) (X509_REQ *)PEM_ASN1_read_bio( \
@@ -574,25 +494,11 @@ int PEM_write_bio(BIO *bp,const char *name,char *hdr,unsigned char *data,
574 long len); 494 long len);
575int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp, 495int PEM_bytes_read_bio(unsigned char **pdata, long *plen, char **pnm, const char *name, BIO *bp,
576 pem_password_cb *cb, void *u); 496 pem_password_cb *cb, void *u);
577void * PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, 497char * PEM_ASN1_read_bio(char *(*d2i)(),const char *name,BIO *bp,char **x,
578 void **x, pem_password_cb *cb, void *u); 498 pem_password_cb *cb, void *u);
579 499int PEM_ASN1_write_bio(int (*i2d)(),const char *name,BIO *bp,char *x,
580#define PEM_ASN1_read_bio_of(type,d2i,name,bp,x,cb,u) \
581 ((type*)PEM_ASN1_read_bio(CHECKED_D2I_OF(type, d2i), \
582 name, bp, \
583 CHECKED_PPTR_OF(type, x), \
584 cb, u))
585
586int PEM_ASN1_write_bio(i2d_of_void *i2d,const char *name,BIO *bp,char *x,
587 const EVP_CIPHER *enc,unsigned char *kstr,int klen, 500 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
588 pem_password_cb *cb, void *u); 501 pem_password_cb *cb, void *u);
589
590#define PEM_ASN1_write_bio_of(type,i2d,name,bp,x,enc,kstr,klen,cb,u) \
591 (PEM_ASN1_write_bio(CHECKED_I2D_OF(type, i2d), \
592 name, bp, \
593 CHECKED_PTR_OF(type, x), \
594 enc, kstr, klen, cb, u))
595
596STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u); 502STACK_OF(X509_INFO) * PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u);
597int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc, 503int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
598 unsigned char *kstr, int klen, pem_password_cb *cd, void *u); 504 unsigned char *kstr, int klen, pem_password_cb *cd, void *u);
@@ -602,11 +508,11 @@ int PEM_X509_INFO_write_bio(BIO *bp,X509_INFO *xi, EVP_CIPHER *enc,
602int PEM_read(FILE *fp, char **name, char **header, 508int PEM_read(FILE *fp, char **name, char **header,
603 unsigned char **data,long *len); 509 unsigned char **data,long *len);
604int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len); 510int PEM_write(FILE *fp,char *name,char *hdr,unsigned char *data,long len);
605void * PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 511char * PEM_ASN1_read(char *(*d2i)(),const char *name,FILE *fp,char **x,
606 pem_password_cb *cb, void *u); 512 pem_password_cb *cb, void *u);
607int PEM_ASN1_write(i2d_of_void *i2d,const char *name,FILE *fp, 513int PEM_ASN1_write(int (*i2d)(),const char *name,FILE *fp,char *x,
608 char *x,const EVP_CIPHER *enc,unsigned char *kstr, 514 const EVP_CIPHER *enc,unsigned char *kstr,int klen,
609 int klen,pem_password_cb *callback, void *u); 515 pem_password_cb *callback, void *u);
610STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, 516STACK_OF(X509_INFO) * PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk,
611 pem_password_cb *cb, void *u); 517 pem_password_cb *cb, void *u);
612#endif 518#endif
@@ -636,8 +542,6 @@ DECLARE_PEM_rw(X509, X509)
636 542
637DECLARE_PEM_rw(X509_AUX, X509) 543DECLARE_PEM_rw(X509_AUX, X509)
638 544
639DECLARE_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR)
640
641DECLARE_PEM_rw(X509_REQ, X509_REQ) 545DECLARE_PEM_rw(X509_REQ, X509_REQ)
642DECLARE_PEM_write(X509_REQ_NEW, X509_REQ) 546DECLARE_PEM_write(X509_REQ_NEW, X509_REQ)
643 547
@@ -655,7 +559,7 @@ DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO, PKCS8_PRIV_KEY_INFO)
655 559
656DECLARE_PEM_rw_cb(RSAPrivateKey, RSA) 560DECLARE_PEM_rw_cb(RSAPrivateKey, RSA)
657 561
658DECLARE_PEM_rw_const(RSAPublicKey, RSA) 562DECLARE_PEM_rw(RSAPublicKey, RSA)
659DECLARE_PEM_rw(RSA_PUBKEY, RSA) 563DECLARE_PEM_rw(RSA_PUBKEY, RSA)
660 564
661#endif 565#endif
@@ -666,19 +570,13 @@ DECLARE_PEM_rw_cb(DSAPrivateKey, DSA)
666 570
667DECLARE_PEM_rw(DSA_PUBKEY, DSA) 571DECLARE_PEM_rw(DSA_PUBKEY, DSA)
668 572
669DECLARE_PEM_rw_const(DSAparams, DSA) 573DECLARE_PEM_rw(DSAparams, DSA)
670
671#endif
672 574
673#ifndef OPENSSL_NO_EC
674DECLARE_PEM_rw_const(ECPKParameters, EC_GROUP)
675DECLARE_PEM_rw_cb(ECPrivateKey, EC_KEY)
676DECLARE_PEM_rw(EC_PUBKEY, EC_KEY)
677#endif 575#endif
678 576
679#ifndef OPENSSL_NO_DH 577#ifndef OPENSSL_NO_DH
680 578
681DECLARE_PEM_rw_const(DHparams, DH) 579DECLARE_PEM_rw(DHparams, DH)
682 580
683#endif 581#endif
684 582
@@ -728,27 +626,24 @@ void ERR_load_PEM_strings(void);
728/* Function codes. */ 626/* Function codes. */
729#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120 627#define PEM_F_D2I_PKCS8PRIVATEKEY_BIO 120
730#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121 628#define PEM_F_D2I_PKCS8PRIVATEKEY_FP 121
731#define PEM_F_DO_PK8PKEY 126 629#define PEM_F_DEF_CALLBACK 100
732#define PEM_F_DO_PK8PKEY_FP 125
733#define PEM_F_LOAD_IV 101 630#define PEM_F_LOAD_IV 101
734#define PEM_F_PEM_ASN1_READ 102 631#define PEM_F_PEM_ASN1_READ 102
735#define PEM_F_PEM_ASN1_READ_BIO 103 632#define PEM_F_PEM_ASN1_READ_BIO 103
736#define PEM_F_PEM_ASN1_WRITE 104 633#define PEM_F_PEM_ASN1_WRITE 104
737#define PEM_F_PEM_ASN1_WRITE_BIO 105 634#define PEM_F_PEM_ASN1_WRITE_BIO 105
738#define PEM_F_PEM_DEF_CALLBACK 100
739#define PEM_F_PEM_DO_HEADER 106 635#define PEM_F_PEM_DO_HEADER 106
636#define PEM_F_PEM_F_DO_PK8KEY_FP 122
740#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118 637#define PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY 118
741#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107 638#define PEM_F_PEM_GET_EVP_CIPHER_INFO 107
742#define PEM_F_PEM_PK8PKEY 119
743#define PEM_F_PEM_READ 108 639#define PEM_F_PEM_READ 108
744#define PEM_F_PEM_READ_BIO 109 640#define PEM_F_PEM_READ_BIO 109
745#define PEM_F_PEM_READ_BIO_PRIVATEKEY 123
746#define PEM_F_PEM_READ_PRIVATEKEY 124
747#define PEM_F_PEM_SEALFINAL 110 641#define PEM_F_PEM_SEALFINAL 110
748#define PEM_F_PEM_SEALINIT 111 642#define PEM_F_PEM_SEALINIT 111
749#define PEM_F_PEM_SIGNFINAL 112 643#define PEM_F_PEM_SIGNFINAL 112
750#define PEM_F_PEM_WRITE 113 644#define PEM_F_PEM_WRITE 113
751#define PEM_F_PEM_WRITE_BIO 114 645#define PEM_F_PEM_WRITE_BIO 114
646#define PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY 119
752#define PEM_F_PEM_X509_INFO_READ 115 647#define PEM_F_PEM_X509_INFO_READ 115
753#define PEM_F_PEM_X509_INFO_READ_BIO 116 648#define PEM_F_PEM_X509_INFO_READ_BIO 116
754#define PEM_F_PEM_X509_INFO_WRITE_BIO 117 649#define PEM_F_PEM_X509_INFO_WRITE_BIO 117
diff --git a/src/lib/libcrypto/pem/pem_all.c b/src/lib/libcrypto/pem/pem_all.c
index 66cbc7eb82..07963314c9 100644
--- a/src/lib/libcrypto/pem/pem_all.c
+++ b/src/lib/libcrypto/pem/pem_all.c
@@ -55,59 +55,6 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111 58
112#include <stdio.h> 59#include <stdio.h>
113#undef SSLEAY_MACROS 60#undef SSLEAY_MACROS
@@ -117,15 +64,7 @@
117#include <openssl/x509.h> 64#include <openssl/x509.h>
118#include <openssl/pkcs7.h> 65#include <openssl/pkcs7.h>
119#include <openssl/pem.h> 66#include <openssl/pem.h>
120#ifndef OPENSSL_NO_RSA 67#include <openssl/fips.h>
121#include <openssl/rsa.h>
122#endif
123#ifndef OPENSSL_NO_DSA
124#include <openssl/dsa.h>
125#endif
126#ifndef OPENSSL_NO_DH
127#include <openssl/dh.h>
128#endif
129 68
130#ifndef OPENSSL_NO_RSA 69#ifndef OPENSSL_NO_RSA
131static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa); 70static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
@@ -134,10 +73,6 @@ static RSA *pkey_get_rsa(EVP_PKEY *key, RSA **rsa);
134static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa); 73static DSA *pkey_get_dsa(EVP_PKEY *key, DSA **dsa);
135#endif 74#endif
136 75
137#ifndef OPENSSL_NO_EC
138static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey);
139#endif
140
141IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ) 76IMPLEMENT_PEM_rw(X509_REQ, X509_REQ, PEM_STRING_X509_REQ, X509_REQ)
142 77
143IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ) 78IMPLEMENT_PEM_write(X509_REQ_NEW, X509_REQ, PEM_STRING_X509_REQ_OLD, X509_REQ)
@@ -194,8 +129,50 @@ RSA *PEM_read_RSAPrivateKey(FILE *fp, RSA **rsa, pem_password_cb *cb,
194 129
195#endif 130#endif
196 131
197IMPLEMENT_PEM_write_cb_const(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey) 132#ifdef OPENSSL_FIPS
198IMPLEMENT_PEM_rw_const(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey) 133
134int PEM_write_bio_RSAPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
135 unsigned char *kstr, int klen,
136 pem_password_cb *cb, void *u)
137{
138 EVP_PKEY *k;
139 int ret;
140 k = EVP_PKEY_new();
141 if (!k)
142 return 0;
143 EVP_PKEY_set1_RSA(k, x);
144
145 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
146 EVP_PKEY_free(k);
147 return ret;
148}
149
150#ifndef OPENSSL_NO_FP_API
151int PEM_write_RSAPrivateKey(FILE *fp, RSA *x, const EVP_CIPHER *enc,
152 unsigned char *kstr, int klen,
153 pem_password_cb *cb, void *u)
154{
155 EVP_PKEY *k;
156 int ret;
157 k = EVP_PKEY_new();
158 if (!k)
159 return 0;
160
161 EVP_PKEY_set1_RSA(k, x);
162
163 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
164 EVP_PKEY_free(k);
165 return ret;
166}
167#endif
168
169#else
170
171IMPLEMENT_PEM_write_cb(RSAPrivateKey, RSA, PEM_STRING_RSA, RSAPrivateKey)
172
173#endif
174
175IMPLEMENT_PEM_rw(RSAPublicKey, RSA, PEM_STRING_RSA_PUBLIC, RSAPublicKey)
199IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY) 176IMPLEMENT_PEM_rw(RSA_PUBKEY, RSA, PEM_STRING_PUBLIC, RSA_PUBKEY)
200 177
201#endif 178#endif
@@ -224,73 +201,69 @@ DSA *PEM_read_bio_DSAPrivateKey(BIO *bp, DSA **dsa, pem_password_cb *cb,
224 return pkey_get_dsa(pktmp, dsa); 201 return pkey_get_dsa(pktmp, dsa);
225} 202}
226 203
227IMPLEMENT_PEM_write_cb_const(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
228IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
229 204
230#ifndef OPENSSL_NO_FP_API 205#ifdef OPENSSL_FIPS
231 206
232DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb, 207int PEM_write_bio_DSAPrivateKey(BIO *bp, DSA *x, const EVP_CIPHER *enc,
233 void *u) 208 unsigned char *kstr, int klen,
209 pem_password_cb *cb, void *u)
234{ 210{
235 EVP_PKEY *pktmp; 211 EVP_PKEY *k;
236 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 212 int ret;
237 return pkey_get_dsa(pktmp, dsa); 213 k = EVP_PKEY_new();
214 if (!k)
215 return 0;
216 EVP_PKEY_set1_DSA(k, x);
217
218 ret = PEM_write_bio_PrivateKey(bp, k, enc, kstr, klen, cb, u);
219 EVP_PKEY_free(k);
220 return ret;
238} 221}
239 222
240#endif 223#ifndef OPENSSL_NO_FP_API
241 224int PEM_write_DSAPrivateKey(FILE *fp, DSA *x, const EVP_CIPHER *enc,
242IMPLEMENT_PEM_rw_const(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams) 225 unsigned char *kstr, int klen,
243 226 pem_password_cb *cb, void *u)
244#endif
245
246
247#ifndef OPENSSL_NO_EC
248static EC_KEY *pkey_get_eckey(EVP_PKEY *key, EC_KEY **eckey)
249{ 227{
250 EC_KEY *dtmp; 228 EVP_PKEY *k;
251 if(!key) return NULL; 229 int ret;
252 dtmp = EVP_PKEY_get1_EC_KEY(key); 230 k = EVP_PKEY_new();
253 EVP_PKEY_free(key); 231 if (!k)
254 if(!dtmp) return NULL; 232 return 0;
255 if(eckey) 233 EVP_PKEY_set1_DSA(k, x);
256 { 234 ret = PEM_write_PrivateKey(fp, k, enc, kstr, klen, cb, u);
257 EC_KEY_free(*eckey); 235 EVP_PKEY_free(k);
258 *eckey = dtmp; 236 return ret;
259 }
260 return dtmp;
261} 237}
238#endif
262 239
263EC_KEY *PEM_read_bio_ECPrivateKey(BIO *bp, EC_KEY **key, pem_password_cb *cb, 240#else
264 void *u)
265{
266 EVP_PKEY *pktmp;
267 pktmp = PEM_read_bio_PrivateKey(bp, NULL, cb, u);
268 return pkey_get_eckey(pktmp, key);
269}
270 241
271IMPLEMENT_PEM_rw_const(ECPKParameters, EC_GROUP, PEM_STRING_ECPARAMETERS, ECPKParameters) 242IMPLEMENT_PEM_write_cb(DSAPrivateKey, DSA, PEM_STRING_DSA, DSAPrivateKey)
272 243
273IMPLEMENT_PEM_write_cb(ECPrivateKey, EC_KEY, PEM_STRING_ECPRIVATEKEY, ECPrivateKey) 244#endif
274 245
275IMPLEMENT_PEM_rw(EC_PUBKEY, EC_KEY, PEM_STRING_PUBLIC, EC_PUBKEY) 246IMPLEMENT_PEM_rw(DSA_PUBKEY, DSA, PEM_STRING_PUBLIC, DSA_PUBKEY)
276 247
277#ifndef OPENSSL_NO_FP_API 248#ifndef OPENSSL_NO_FP_API
278 249
279EC_KEY *PEM_read_ECPrivateKey(FILE *fp, EC_KEY **eckey, pem_password_cb *cb, 250DSA *PEM_read_DSAPrivateKey(FILE *fp, DSA **dsa, pem_password_cb *cb,
280 void *u) 251 void *u)
281{ 252{
282 EVP_PKEY *pktmp; 253 EVP_PKEY *pktmp;
283 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u); 254 pktmp = PEM_read_PrivateKey(fp, NULL, cb, u);
284 return pkey_get_eckey(pktmp, eckey); 255 return pkey_get_dsa(pktmp, dsa);
285} 256}
286 257
287#endif 258#endif
288 259
260IMPLEMENT_PEM_rw(DSAparams, DSA, PEM_STRING_DSAPARAMS, DSAparams)
261
289#endif 262#endif
290 263
291#ifndef OPENSSL_NO_DH 264#ifndef OPENSSL_NO_DH
292 265
293IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams) 266IMPLEMENT_PEM_rw(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
294 267
295#endif 268#endif
296 269
@@ -301,8 +274,42 @@ IMPLEMENT_PEM_rw_const(DHparams, DH, PEM_STRING_DHPARAMS, DHparams)
301 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything 274 * (When reading, parameter PEM_STRING_EVP_PKEY is a wildcard for anything
302 * appropriate.) 275 * appropriate.)
303 */ 276 */
304IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:\ 277
305 (x->type == EVP_PKEY_RSA)?PEM_STRING_RSA:PEM_STRING_ECPRIVATEKEY), PrivateKey) 278#ifdef OPENSSL_FIPS
279
280int PEM_write_bio_PrivateKey(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
281 unsigned char *kstr, int klen,
282 pem_password_cb *cb, void *u)
283 {
284 if (FIPS_mode())
285 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc,
286 (char *)kstr, klen, cb, u);
287 else
288 return PEM_ASN1_write_bio((int (*)())i2d_PrivateKey,
289 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
290 bp,(char *)x,enc,kstr,klen,cb,u);
291 }
292
293#ifndef OPENSSL_NO_FP_API
294int PEM_write_PrivateKey(FILE *fp, EVP_PKEY *x, const EVP_CIPHER *enc,
295 unsigned char *kstr, int klen,
296 pem_password_cb *cb, void *u)
297 {
298 if (FIPS_mode())
299 return PEM_write_PKCS8PrivateKey(fp, x, enc,
300 (char *)kstr, klen, cb, u);
301 else
302 return PEM_ASN1_write((int (*)())i2d_PrivateKey,
303 (((x)->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA),
304 fp,(char *)x,enc,kstr,klen,cb,u);
305 }
306#endif
307
308#else
309
310IMPLEMENT_PEM_write_cb(PrivateKey, EVP_PKEY, ((x->type == EVP_PKEY_DSA)?PEM_STRING_DSA:PEM_STRING_RSA), PrivateKey)
311
312#endif
306 313
307IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY) 314IMPLEMENT_PEM_rw(PUBKEY, EVP_PKEY, PEM_STRING_PUBLIC, PUBKEY)
308 315
diff --git a/src/lib/libcrypto/pem/pem_err.c b/src/lib/libcrypto/pem/pem_err.c
index 3133563d77..8527028ebc 100644
--- a/src/lib/libcrypto/pem/pem_err.c
+++ b/src/lib/libcrypto/pem/pem_err.c
@@ -72,27 +72,24 @@ static ERR_STRING_DATA PEM_str_functs[]=
72 { 72 {
73{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"}, 73{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_BIO), "d2i_PKCS8PrivateKey_bio"},
74{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"}, 74{ERR_FUNC(PEM_F_D2I_PKCS8PRIVATEKEY_FP), "d2i_PKCS8PrivateKey_fp"},
75{ERR_FUNC(PEM_F_DO_PK8PKEY), "DO_PK8PKEY"}, 75{ERR_FUNC(PEM_F_DEF_CALLBACK), "DEF_CALLBACK"},
76{ERR_FUNC(PEM_F_DO_PK8PKEY_FP), "DO_PK8PKEY_FP"},
77{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"}, 76{ERR_FUNC(PEM_F_LOAD_IV), "LOAD_IV"},
78{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"}, 77{ERR_FUNC(PEM_F_PEM_ASN1_READ), "PEM_ASN1_read"},
79{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"}, 78{ERR_FUNC(PEM_F_PEM_ASN1_READ_BIO), "PEM_ASN1_read_bio"},
80{ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"}, 79{ERR_FUNC(PEM_F_PEM_ASN1_WRITE), "PEM_ASN1_write"},
81{ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"}, 80{ERR_FUNC(PEM_F_PEM_ASN1_WRITE_BIO), "PEM_ASN1_write_bio"},
82{ERR_FUNC(PEM_F_PEM_DEF_CALLBACK), "PEM_def_callback"},
83{ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"}, 81{ERR_FUNC(PEM_F_PEM_DO_HEADER), "PEM_do_header"},
82{ERR_FUNC(PEM_F_PEM_F_DO_PK8KEY_FP), "PEM_F_DO_PK8KEY_FP"},
84{ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"}, 83{ERR_FUNC(PEM_F_PEM_F_PEM_WRITE_PKCS8PRIVATEKEY), "PEM_F_PEM_WRITE_PKCS8PRIVATEKEY"},
85{ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"}, 84{ERR_FUNC(PEM_F_PEM_GET_EVP_CIPHER_INFO), "PEM_get_EVP_CIPHER_INFO"},
86{ERR_FUNC(PEM_F_PEM_PK8PKEY), "PEM_PK8PKEY"},
87{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"}, 85{ERR_FUNC(PEM_F_PEM_READ), "PEM_read"},
88{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"}, 86{ERR_FUNC(PEM_F_PEM_READ_BIO), "PEM_read_bio"},
89{ERR_FUNC(PEM_F_PEM_READ_BIO_PRIVATEKEY), "PEM_READ_BIO_PRIVATEKEY"},
90{ERR_FUNC(PEM_F_PEM_READ_PRIVATEKEY), "PEM_READ_PRIVATEKEY"},
91{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"}, 87{ERR_FUNC(PEM_F_PEM_SEALFINAL), "PEM_SealFinal"},
92{ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"}, 88{ERR_FUNC(PEM_F_PEM_SEALINIT), "PEM_SealInit"},
93{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"}, 89{ERR_FUNC(PEM_F_PEM_SIGNFINAL), "PEM_SignFinal"},
94{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"}, 90{ERR_FUNC(PEM_F_PEM_WRITE), "PEM_write"},
95{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"}, 91{ERR_FUNC(PEM_F_PEM_WRITE_BIO), "PEM_write_bio"},
92{ERR_FUNC(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY), "PEM_write_bio_PKCS8PrivateKey"},
96{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"}, 93{ERR_FUNC(PEM_F_PEM_X509_INFO_READ), "PEM_X509_INFO_read"},
97{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"}, 94{ERR_FUNC(PEM_F_PEM_X509_INFO_READ_BIO), "PEM_X509_INFO_read_bio"},
98{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"}, 95{ERR_FUNC(PEM_F_PEM_X509_INFO_WRITE_BIO), "PEM_X509_INFO_write_bio"},
@@ -124,12 +121,15 @@ static ERR_STRING_DATA PEM_str_reasons[]=
124 121
125void ERR_load_PEM_strings(void) 122void ERR_load_PEM_strings(void)
126 { 123 {
127#ifndef OPENSSL_NO_ERR 124 static int init=1;
128 125
129 if (ERR_func_error_string(PEM_str_functs[0].error) == NULL) 126 if (init)
130 { 127 {
128 init=0;
129#ifndef OPENSSL_NO_ERR
131 ERR_load_strings(0,PEM_str_functs); 130 ERR_load_strings(0,PEM_str_functs);
132 ERR_load_strings(0,PEM_str_reasons); 131 ERR_load_strings(0,PEM_str_reasons);
133 }
134#endif 132#endif
133
134 }
135 } 135 }
diff --git a/src/lib/libcrypto/pem/pem_info.c b/src/lib/libcrypto/pem/pem_info.c
index 3a273f6f70..9e4af29c95 100644
--- a/src/lib/libcrypto/pem/pem_info.c
+++ b/src/lib/libcrypto/pem/pem_info.c
@@ -63,12 +63,6 @@
63#include <openssl/evp.h> 63#include <openssl/evp.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65#include <openssl/pem.h> 65#include <openssl/pem.h>
66#ifndef OPENSSL_NO_RSA
67#include <openssl/rsa.h>
68#endif
69#ifndef OPENSSL_NO_DSA
70#include <openssl/dsa.h>
71#endif
72 66
73#ifndef OPENSSL_NO_FP_API 67#ifndef OPENSSL_NO_FP_API
74STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) 68STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
@@ -91,15 +85,13 @@ STACK_OF(X509_INFO) *PEM_X509_INFO_read(FILE *fp, STACK_OF(X509_INFO) *sk, pem_p
91STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u) 85STACK_OF(X509_INFO) *PEM_X509_INFO_read_bio(BIO *bp, STACK_OF(X509_INFO) *sk, pem_password_cb *cb, void *u)
92 { 86 {
93 X509_INFO *xi=NULL; 87 X509_INFO *xi=NULL;
94 char *name=NULL,*header=NULL; 88 char *name=NULL,*header=NULL,**pp;
95 void *pp; 89 unsigned char *data=NULL,*p;
96 unsigned char *data=NULL;
97 const unsigned char *p;
98 long len,error=0; 90 long len,error=0;
99 int ok=0; 91 int ok=0;
100 STACK_OF(X509_INFO) *ret=NULL; 92 STACK_OF(X509_INFO) *ret=NULL;
101 unsigned int i,raw; 93 unsigned int i,raw;
102 d2i_of_void *d2i; 94 char *(*d2i)();
103 95
104 if (sk == NULL) 96 if (sk == NULL)
105 { 97 {
@@ -131,42 +123,42 @@ start:
131 if ( (strcmp(name,PEM_STRING_X509) == 0) || 123 if ( (strcmp(name,PEM_STRING_X509) == 0) ||
132 (strcmp(name,PEM_STRING_X509_OLD) == 0)) 124 (strcmp(name,PEM_STRING_X509_OLD) == 0))
133 { 125 {
134 d2i=(D2I_OF(void))d2i_X509; 126 d2i=(char *(*)())d2i_X509;
135 if (xi->x509 != NULL) 127 if (xi->x509 != NULL)
136 { 128 {
137 if (!sk_X509_INFO_push(ret,xi)) goto err; 129 if (!sk_X509_INFO_push(ret,xi)) goto err;
138 if ((xi=X509_INFO_new()) == NULL) goto err; 130 if ((xi=X509_INFO_new()) == NULL) goto err;
139 goto start; 131 goto start;
140 } 132 }
141 pp=&(xi->x509); 133 pp=(char **)&(xi->x509);
142 } 134 }
143 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0)) 135 else if ((strcmp(name,PEM_STRING_X509_TRUSTED) == 0))
144 { 136 {
145 d2i=(D2I_OF(void))d2i_X509_AUX; 137 d2i=(char *(*)())d2i_X509_AUX;
146 if (xi->x509 != NULL) 138 if (xi->x509 != NULL)
147 { 139 {
148 if (!sk_X509_INFO_push(ret,xi)) goto err; 140 if (!sk_X509_INFO_push(ret,xi)) goto err;
149 if ((xi=X509_INFO_new()) == NULL) goto err; 141 if ((xi=X509_INFO_new()) == NULL) goto err;
150 goto start; 142 goto start;
151 } 143 }
152 pp=&(xi->x509); 144 pp=(char **)&(xi->x509);
153 } 145 }
154 else if (strcmp(name,PEM_STRING_X509_CRL) == 0) 146 else if (strcmp(name,PEM_STRING_X509_CRL) == 0)
155 { 147 {
156 d2i=(D2I_OF(void))d2i_X509_CRL; 148 d2i=(char *(*)())d2i_X509_CRL;
157 if (xi->crl != NULL) 149 if (xi->crl != NULL)
158 { 150 {
159 if (!sk_X509_INFO_push(ret,xi)) goto err; 151 if (!sk_X509_INFO_push(ret,xi)) goto err;
160 if ((xi=X509_INFO_new()) == NULL) goto err; 152 if ((xi=X509_INFO_new()) == NULL) goto err;
161 goto start; 153 goto start;
162 } 154 }
163 pp=&(xi->crl); 155 pp=(char **)&(xi->crl);
164 } 156 }
165 else 157 else
166#ifndef OPENSSL_NO_RSA 158#ifndef OPENSSL_NO_RSA
167 if (strcmp(name,PEM_STRING_RSA) == 0) 159 if (strcmp(name,PEM_STRING_RSA) == 0)
168 { 160 {
169 d2i=(D2I_OF(void))d2i_RSAPrivateKey; 161 d2i=(char *(*)())d2i_RSAPrivateKey;
170 if (xi->x_pkey != NULL) 162 if (xi->x_pkey != NULL)
171 { 163 {
172 if (!sk_X509_INFO_push(ret,xi)) goto err; 164 if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -181,7 +173,7 @@ start:
181 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 173 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
182 goto err; 174 goto err;
183 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA; 175 xi->x_pkey->dec_pkey->type=EVP_PKEY_RSA;
184 pp=&(xi->x_pkey->dec_pkey->pkey.rsa); 176 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.rsa);
185 if ((int)strlen(header) > 10) /* assume encrypted */ 177 if ((int)strlen(header) > 10) /* assume encrypted */
186 raw=1; 178 raw=1;
187 } 179 }
@@ -190,7 +182,7 @@ start:
190#ifndef OPENSSL_NO_DSA 182#ifndef OPENSSL_NO_DSA
191 if (strcmp(name,PEM_STRING_DSA) == 0) 183 if (strcmp(name,PEM_STRING_DSA) == 0)
192 { 184 {
193 d2i=(D2I_OF(void))d2i_DSAPrivateKey; 185 d2i=(char *(*)())d2i_DSAPrivateKey;
194 if (xi->x_pkey != NULL) 186 if (xi->x_pkey != NULL)
195 { 187 {
196 if (!sk_X509_INFO_push(ret,xi)) goto err; 188 if (!sk_X509_INFO_push(ret,xi)) goto err;
@@ -205,36 +197,12 @@ start:
205 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL) 197 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
206 goto err; 198 goto err;
207 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA; 199 xi->x_pkey->dec_pkey->type=EVP_PKEY_DSA;
208 pp=&xi->x_pkey->dec_pkey->pkey.dsa; 200 pp=(char **)&(xi->x_pkey->dec_pkey->pkey.dsa);
209 if ((int)strlen(header) > 10) /* assume encrypted */ 201 if ((int)strlen(header) > 10) /* assume encrypted */
210 raw=1; 202 raw=1;
211 } 203 }
212 else 204 else
213#endif 205#endif
214#ifndef OPENSSL_NO_EC
215 if (strcmp(name,PEM_STRING_ECPRIVATEKEY) == 0)
216 {
217 d2i=(D2I_OF(void))d2i_ECPrivateKey;
218 if (xi->x_pkey != NULL)
219 {
220 if (!sk_X509_INFO_push(ret,xi)) goto err;
221 if ((xi=X509_INFO_new()) == NULL) goto err;
222 goto start;
223 }
224
225 xi->enc_data=NULL;
226 xi->enc_len=0;
227
228 xi->x_pkey=X509_PKEY_new();
229 if ((xi->x_pkey->dec_pkey=EVP_PKEY_new()) == NULL)
230 goto err;
231 xi->x_pkey->dec_pkey->type=EVP_PKEY_EC;
232 pp=&(xi->x_pkey->dec_pkey->pkey.ec);
233 if ((int)strlen(header) > 10) /* assume encrypted */
234 raw=1;
235 }
236 else
237#endif
238 { 206 {
239 d2i=NULL; 207 d2i=NULL;
240 pp=NULL; 208 pp=NULL;
diff --git a/src/lib/libcrypto/pem/pem_lib.c b/src/lib/libcrypto/pem/pem_lib.c
index 9bae4c8850..82815067b3 100644
--- a/src/lib/libcrypto/pem/pem_lib.c
+++ b/src/lib/libcrypto/pem/pem_lib.c
@@ -69,7 +69,7 @@
69#include <openssl/des.h> 69#include <openssl/des.h>
70#endif 70#endif
71 71
72const char PEM_version[]="PEM" OPENSSL_VERSION_PTEXT; 72const char *PEM_version="PEM" OPENSSL_VERSION_PTEXT;
73 73
74#define MIN_LENGTH 4 74#define MIN_LENGTH 4
75 75
@@ -81,7 +81,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
81#ifdef OPENSSL_NO_FP_API 81#ifdef OPENSSL_NO_FP_API
82 /* We should not ever call the default callback routine from 82 /* We should not ever call the default callback routine from
83 * windows. */ 83 * windows. */
84 PEMerr(PEM_F_PEM_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED); 84 PEMerr(PEM_F_DEF_CALLBACK,ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);
85 return(-1); 85 return(-1);
86#else 86#else
87 int i,j; 87 int i,j;
@@ -102,7 +102,7 @@ int PEM_def_callback(char *buf, int num, int w, void *key)
102 i=EVP_read_pw_string(buf,num,prompt,w); 102 i=EVP_read_pw_string(buf,num,prompt,w);
103 if (i != 0) 103 if (i != 0)
104 { 104 {
105 PEMerr(PEM_F_PEM_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD); 105 PEMerr(PEM_F_DEF_CALLBACK,PEM_R_PROBLEMS_GETTING_PASSWORD);
106 memset(buf,0,(unsigned int)num); 106 memset(buf,0,(unsigned int)num);
107 return(-1); 107 return(-1);
108 } 108 }
@@ -158,11 +158,11 @@ void PEM_dek_info(char *buf, const char *type, int len, char *str)
158 } 158 }
159 159
160#ifndef OPENSSL_NO_FP_API 160#ifndef OPENSSL_NO_FP_API
161void *PEM_ASN1_read(d2i_of_void *d2i, const char *name, FILE *fp, void **x, 161char *PEM_ASN1_read(char *(*d2i)(), const char *name, FILE *fp, char **x,
162 pem_password_cb *cb, void *u) 162 pem_password_cb *cb, void *u)
163 { 163 {
164 BIO *b; 164 BIO *b;
165 void *ret; 165 char *ret;
166 166
167 if ((b=BIO_new(BIO_s_file())) == NULL) 167 if ((b=BIO_new(BIO_s_file())) == NULL)
168 { 168 {
@@ -195,8 +195,6 @@ static int check_pem(const char *nm, const char *name)
195 if(!strcmp(nm,PEM_STRING_DSA) && 195 if(!strcmp(nm,PEM_STRING_DSA) &&
196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1; 196 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
197 197
198 if(!strcmp(nm,PEM_STRING_ECPRIVATEKEY) &&
199 !strcmp(name,PEM_STRING_EVP_PKEY)) return 1;
200 /* Permit older strings */ 198 /* Permit older strings */
201 199
202 if(!strcmp(nm,PEM_STRING_X509_OLD) && 200 if(!strcmp(nm,PEM_STRING_X509_OLD) &&
@@ -260,9 +258,9 @@ err:
260 } 258 }
261 259
262#ifndef OPENSSL_NO_FP_API 260#ifndef OPENSSL_NO_FP_API
263int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp, 261int PEM_ASN1_write(int (*i2d)(), const char *name, FILE *fp, char *x,
264 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 262 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
265 int klen, pem_password_cb *callback, void *u) 263 pem_password_cb *callback, void *u)
266 { 264 {
267 BIO *b; 265 BIO *b;
268 int ret; 266 int ret;
@@ -279,9 +277,9 @@ int PEM_ASN1_write(i2d_of_void *i2d, const char *name, FILE *fp,
279 } 277 }
280#endif 278#endif
281 279
282int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp, 280int PEM_ASN1_write_bio(int (*i2d)(), const char *name, BIO *bp, char *x,
283 char *x, const EVP_CIPHER *enc, unsigned char *kstr, 281 const EVP_CIPHER *enc, unsigned char *kstr, int klen,
284 int klen, pem_password_cb *callback, void *u) 282 pem_password_cb *callback, void *u)
285 { 283 {
286 EVP_CIPHER_CTX ctx; 284 EVP_CIPHER_CTX ctx;
287 int dsize=0,i,j,ret=0; 285 int dsize=0,i,j,ret=0;
@@ -338,7 +336,7 @@ int PEM_ASN1_write_bio(i2d_of_void *i2d, const char *name, BIO *bp,
338 kstr=(unsigned char *)buf; 336 kstr=(unsigned char *)buf;
339 } 337 }
340 RAND_add(data,i,0);/* put in the RSA key. */ 338 RAND_add(data,i,0);/* put in the RSA key. */
341 OPENSSL_assert(enc->iv_len <= (int)sizeof(iv)); 339 OPENSSL_assert(enc->iv_len <= sizeof iv);
342 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */ 340 if (RAND_pseudo_bytes(iv,enc->iv_len) < 0) /* Generate a salt */
343 goto err; 341 goto err;
344 /* The 'iv' is used as the iv and as a salt. It is 342 /* The 'iv' is used as the iv and as a salt. It is
@@ -579,7 +577,6 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
579 } 577 }
580 EVP_EncodeFinal(&ctx,buf,&outl); 578 EVP_EncodeFinal(&ctx,buf,&outl);
581 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err; 579 if ((outl > 0) && (BIO_write(bp,(char *)buf,outl) != outl)) goto err;
582 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
583 OPENSSL_free(buf); 580 OPENSSL_free(buf);
584 buf = NULL; 581 buf = NULL;
585 if ( (BIO_write(bp,"-----END ",9) != 9) || 582 if ( (BIO_write(bp,"-----END ",9) != 9) ||
@@ -588,10 +585,8 @@ int PEM_write_bio(BIO *bp, const char *name, char *header, unsigned char *data,
588 goto err; 585 goto err;
589 return(i+outl); 586 return(i+outl);
590err: 587err:
591 if (buf) { 588 if (buf)
592 OPENSSL_cleanse(buf, PEM_BUFSIZE*8);
593 OPENSSL_free(buf); 589 OPENSSL_free(buf);
594 }
595 PEMerr(PEM_F_PEM_WRITE_BIO,reason); 590 PEMerr(PEM_F_PEM_WRITE_BIO,reason);
596 return(0); 591 return(0);
597 } 592 }
diff --git a/src/lib/libcrypto/pem/pem_oth.c b/src/lib/libcrypto/pem/pem_oth.c
index b33868d25a..8d9064ea7c 100644
--- a/src/lib/libcrypto/pem/pem_oth.c
+++ b/src/lib/libcrypto/pem/pem_oth.c
@@ -67,11 +67,10 @@
67 67
68/* Handle 'other' PEMs: not private keys */ 68/* Handle 'other' PEMs: not private keys */
69 69
70void *PEM_ASN1_read_bio(d2i_of_void *d2i, const char *name, BIO *bp, void **x, 70char *PEM_ASN1_read_bio(char *(*d2i)(), const char *name, BIO *bp, char **x,
71 pem_password_cb *cb, void *u) 71 pem_password_cb *cb, void *u)
72 { 72 {
73 const unsigned char *p=NULL; 73 unsigned char *p=NULL,*data=NULL;
74 unsigned char *data=NULL;
75 long len; 74 long len;
76 char *ret=NULL; 75 char *ret=NULL;
77 76
diff --git a/src/lib/libcrypto/pem/pem_pk8.c b/src/lib/libcrypto/pem/pem_pk8.c
index 6deab8c338..db38a2a79d 100644
--- a/src/lib/libcrypto/pem/pem_pk8.c
+++ b/src/lib/libcrypto/pem/pem_pk8.c
@@ -118,7 +118,7 @@ static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER
118 char buf[PEM_BUFSIZE]; 118 char buf[PEM_BUFSIZE];
119 int ret; 119 int ret;
120 if(!(p8inf = EVP_PKEY2PKCS8(x))) { 120 if(!(p8inf = EVP_PKEY2PKCS8(x))) {
121 PEMerr(PEM_F_DO_PK8PKEY, 121 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY); 122 PEM_R_ERROR_CONVERTING_PRIVATE_KEY);
123 return 0; 123 return 0;
124 } 124 }
@@ -127,7 +127,8 @@ static int do_pk8pkey(BIO *bp, EVP_PKEY *x, int isder, int nid, const EVP_CIPHER
127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u); 127 if(!cb) klen = PEM_def_callback(buf, PEM_BUFSIZE, 1, u);
128 else klen = cb(buf, PEM_BUFSIZE, 1, u); 128 else klen = cb(buf, PEM_BUFSIZE, 1, u);
129 if(klen <= 0) { 129 if(klen <= 0) {
130 PEMerr(PEM_F_DO_PK8PKEY,PEM_R_READ_KEY); 130 PEMerr(PEM_F_PEM_WRITE_BIO_PKCS8PRIVATEKEY,
131 PEM_R_READ_KEY);
131 PKCS8_PRIV_KEY_INFO_free(p8inf); 132 PKCS8_PRIV_KEY_INFO_free(p8inf);
132 return 0; 133 return 0;
133 } 134 }
@@ -214,7 +215,7 @@ static int do_pk8pkey_fp(FILE *fp, EVP_PKEY *x, int isder, int nid, const EVP_CI
214 BIO *bp; 215 BIO *bp;
215 int ret; 216 int ret;
216 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) { 217 if(!(bp = BIO_new_fp(fp, BIO_NOCLOSE))) {
217 PEMerr(PEM_F_DO_PK8PKEY_FP,ERR_R_BUF_LIB); 218 PEMerr(PEM_F_PEM_F_DO_PK8KEY_FP,ERR_R_BUF_LIB);
218 return(0); 219 return(0);
219 } 220 }
220 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u); 221 ret = do_pk8pkey(bp, x, isder, nid, enc, kstr, klen, cb, u);
diff --git a/src/lib/libcrypto/pem/pem_pkey.c b/src/lib/libcrypto/pem/pem_pkey.c
index 4da4c31ce5..9ecdbd5419 100644
--- a/src/lib/libcrypto/pem/pem_pkey.c
+++ b/src/lib/libcrypto/pem/pem_pkey.c
@@ -70,8 +70,7 @@
70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u) 70EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, void *u)
71 { 71 {
72 char *nm=NULL; 72 char *nm=NULL;
73 const unsigned char *p=NULL; 73 unsigned char *p=NULL,*data=NULL;
74 unsigned char *data=NULL;
75 long len; 74 long len;
76 EVP_PKEY *ret=NULL; 75 EVP_PKEY *ret=NULL;
77 76
@@ -83,8 +82,6 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
83 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len); 82 ret=d2i_PrivateKey(EVP_PKEY_RSA,x,&p,len);
84 else if (strcmp(nm,PEM_STRING_DSA) == 0) 83 else if (strcmp(nm,PEM_STRING_DSA) == 0)
85 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len); 84 ret=d2i_PrivateKey(EVP_PKEY_DSA,x,&p,len);
86 else if (strcmp(nm,PEM_STRING_ECPRIVATEKEY) == 0)
87 ret=d2i_PrivateKey(EVP_PKEY_EC,x,&p,len);
88 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) { 85 else if (strcmp(nm,PEM_STRING_PKCS8INF) == 0) {
89 PKCS8_PRIV_KEY_INFO *p8inf; 86 PKCS8_PRIV_KEY_INFO *p8inf;
90 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len); 87 p8inf=d2i_PKCS8_PRIV_KEY_INFO(NULL, &p, len);
@@ -105,7 +102,7 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
105 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u); 102 if (cb) klen=cb(psbuf,PEM_BUFSIZE,0,u);
106 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u); 103 else klen=PEM_def_callback(psbuf,PEM_BUFSIZE,0,u);
107 if (klen <= 0) { 104 if (klen <= 0) {
108 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY, 105 PEMerr(PEM_F_PEM_ASN1_READ_BIO,
109 PEM_R_BAD_PASSWORD_READ); 106 PEM_R_BAD_PASSWORD_READ);
110 X509_SIG_free(p8); 107 X509_SIG_free(p8);
111 goto err; 108 goto err;
@@ -122,10 +119,9 @@ EVP_PKEY *PEM_read_bio_PrivateKey(BIO *bp, EVP_PKEY **x, pem_password_cb *cb, vo
122 } 119 }
123p8err: 120p8err:
124 if (ret == NULL) 121 if (ret == NULL)
125 PEMerr(PEM_F_PEM_READ_BIO_PRIVATEKEY,ERR_R_ASN1_LIB); 122 PEMerr(PEM_F_PEM_ASN1_READ_BIO,ERR_R_ASN1_LIB);
126err: 123err:
127 OPENSSL_free(nm); 124 OPENSSL_free(nm);
128 OPENSSL_cleanse(data, len);
129 OPENSSL_free(data); 125 OPENSSL_free(data);
130 return(ret); 126 return(ret);
131 } 127 }
@@ -138,7 +134,7 @@ EVP_PKEY *PEM_read_PrivateKey(FILE *fp, EVP_PKEY **x, pem_password_cb *cb, void
138 134
139 if ((b=BIO_new(BIO_s_file())) == NULL) 135 if ((b=BIO_new(BIO_s_file())) == NULL)
140 { 136 {
141 PEMerr(PEM_F_PEM_READ_PRIVATEKEY,ERR_R_BUF_LIB); 137 PEMerr(PEM_F_PEM_ASN1_READ,ERR_R_BUF_LIB);
142 return(0); 138 return(0);
143 } 139 }
144 BIO_set_fp(b,fp,BIO_NOCLOSE); 140 BIO_set_fp(b,fp,BIO_NOCLOSE);
diff --git a/src/lib/libcrypto/pem/pem_seal.c b/src/lib/libcrypto/pem/pem_seal.c
index 4e554e5481..56e08abd70 100644
--- a/src/lib/libcrypto/pem/pem_seal.c
+++ b/src/lib/libcrypto/pem/pem_seal.c
@@ -56,7 +56,6 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <openssl/opensslconf.h> /* for OPENSSL_NO_RSA */
60#ifndef OPENSSL_NO_RSA 59#ifndef OPENSSL_NO_RSA
61#include <stdio.h> 60#include <stdio.h>
62#include "cryptlib.h" 61#include "cryptlib.h"
@@ -65,7 +64,6 @@
65#include <openssl/objects.h> 64#include <openssl/objects.h>
66#include <openssl/x509.h> 65#include <openssl/x509.h>
67#include <openssl/pem.h> 66#include <openssl/pem.h>
68#include <openssl/rsa.h>
69 67
70int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type, 68int PEM_SealInit(PEM_ENCODE_SEAL_CTX *ctx, EVP_CIPHER *type, EVP_MD *md_type,
71 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk, 69 unsigned char **ek, int *ekl, unsigned char *iv, EVP_PKEY **pubk,
diff --git a/src/lib/libcrypto/pem/pem_xaux.c b/src/lib/libcrypto/pem/pem_xaux.c
index 63ce660cf1..2f579b5421 100644
--- a/src/lib/libcrypto/pem/pem_xaux.c
+++ b/src/lib/libcrypto/pem/pem_xaux.c
@@ -66,4 +66,3 @@
66#include <openssl/pem.h> 66#include <openssl/pem.h>
67 67
68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX) 68IMPLEMENT_PEM_rw(X509_AUX, X509, PEM_STRING_X509_TRUSTED, X509_AUX)
69IMPLEMENT_PEM_rw(X509_CERT_PAIR, X509_CERT_PAIR, PEM_STRING_X509_PAIR, X509_CERT_PAIR)
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 e43dc9ae15..22149c680e 100644
--- a/src/lib/libcrypto/perlasm/cbc.pl
+++ b/src/lib/libcrypto/perlasm/cbc.pl
@@ -322,8 +322,7 @@ sub cbc
322 322
323 &function_end_A($name); 323 &function_end_A($name);
324 324
325 &align(64); 325 &set_label("cbc_enc_jmp_table",1);
326 &set_label("cbc_enc_jmp_table");
327 &data_word("0"); 326 &data_word("0");
328 &data_word(&label("ej1")."-".&label("PIC_point")); 327 &data_word(&label("ej1")."-".&label("PIC_point"));
329 &data_word(&label("ej2")."-".&label("PIC_point")); 328 &data_word(&label("ej2")."-".&label("PIC_point"));
@@ -342,7 +341,6 @@ sub cbc
342 #&data_word(&label("dj5")."-".&label("PIC_point")); 341 #&data_word(&label("dj5")."-".&label("PIC_point"));
343 #&data_word(&label("dj6")."-".&label("PIC_point")); 342 #&data_word(&label("dj6")."-".&label("PIC_point"));
344 #&data_word(&label("dj7")."-".&label("PIC_point")); 343 #&data_word(&label("dj7")."-".&label("PIC_point"));
345 &align(64);
346 344
347 &function_end_B($name); 345 &function_end_B($name);
348 346
diff --git a/src/lib/libcrypto/perlasm/x86asm.pl b/src/lib/libcrypto/perlasm/x86asm.pl
index 5979122158..c3de90c65d 100644
--- a/src/lib/libcrypto/perlasm/x86asm.pl
+++ b/src/lib/libcrypto/perlasm/x86asm.pl
@@ -18,34 +18,37 @@ sub main'asm_init
18 ($type,$fn,$i386)=@_; 18 ($type,$fn,$i386)=@_;
19 $filename=$fn; 19 $filename=$fn;
20 20
21 $elf=$cpp=$coff=$aout=$win32=$netware=$mwerks=0; 21 $elf=$cpp=$sol=$aout=$win32=$gaswin=$openbsd=0;
22 if ( ($type eq "elf")) 22 if ( ($type eq "elf"))
23 { $elf=1; require "x86unix.pl"; } 23 { $elf=1; require "x86unix.pl"; }
24 elsif ( ($type eq "openbsd-elf"))
25 { $openbsd=$elf=1; require "x86unix.pl"; }
26 elsif ( ($type eq "openbsd-a.out"))
27 { $openbsd=1; require "x86unix.pl"; }
24 elsif ( ($type eq "a.out")) 28 elsif ( ($type eq "a.out"))
25 { $aout=1; require "x86unix.pl"; } 29 { $aout=1; require "x86unix.pl"; }
26 elsif ( ($type eq "coff" or $type eq "gaswin")) 30 elsif ( ($type eq "gaswin"))
27 { $coff=1; require "x86unix.pl"; } 31 { $gaswin=1; $aout=1; require "x86unix.pl"; }
32 elsif ( ($type eq "sol"))
33 { $sol=1; require "x86unix.pl"; }
28 elsif ( ($type eq "cpp")) 34 elsif ( ($type eq "cpp"))
29 { $cpp=1; require "x86unix.pl"; } 35 { $cpp=1; require "x86unix.pl"; }
30 elsif ( ($type eq "win32")) 36 elsif ( ($type eq "win32"))
31 { $win32=1; require "x86ms.pl"; } 37 { $win32=1; require "x86ms.pl"; }
32 elsif ( ($type eq "win32n")) 38 elsif ( ($type eq "win32n"))
33 { $win32=1; require "x86nasm.pl"; } 39 { $win32=1; require "x86nasm.pl"; }
34 elsif ( ($type eq "nw-nasm"))
35 { $netware=1; require "x86nasm.pl"; }
36 elsif ( ($type eq "nw-mwasm"))
37 { $netware=1; $mwerks=1; require "x86nasm.pl"; }
38 else 40 else
39 { 41 {
40 print STDERR <<"EOF"; 42 print STDERR <<"EOF";
41Pick one target type from 43Pick one target type from
42 elf - Linux, FreeBSD, Solaris x86, etc. 44 elf - linux, FreeBSD etc
43 a.out - OpenBSD, DJGPP, etc. 45 a.out - old linux
44 coff - GAS/COFF such as Win32 targets 46 sol - x86 solaris
47 cpp - format so x86unix.cpp can be used
45 win32 - Windows 95/Windows NT 48 win32 - Windows 95/Windows NT
46 win32n - Windows 95/Windows NT NASM format 49 win32n - Windows 95/Windows NT NASM format
47 nw-nasm - NetWare NASM format 50 openbsd-elf - OpenBSD elf
48 nw-mwasm- NetWare Metrowerks Assembler 51 openbsd-a.out - OpenBSD a.out
49EOF 52EOF
50 exit(1); 53 exit(1);
51 } 54 }
@@ -58,7 +61,7 @@ EOF
58&comment("Don't even think of reading this code"); 61&comment("Don't even think of reading this code");
59&comment("It was automatically generated by $filename"); 62&comment("It was automatically generated by $filename");
60&comment("Which is a perl program used to generate the x86 assember for"); 63&comment("Which is a perl program used to generate the x86 assember for");
61&comment("any of ELF, a.out, COFF, Win32, ..."); 64&comment("any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris");
62&comment("eric <eay\@cryptsoft.com>"); 65&comment("eric <eay\@cryptsoft.com>");
63&comment(""); 66&comment("");
64 67
@@ -93,7 +96,7 @@ $tmp
93#ifdef OUT 96#ifdef OUT
94#define OK 1 97#define OK 1
95#define ALIGN 4 98#define ALIGN 4
96#if defined(__CYGWIN__) || defined(__DJGPP__) || (__MINGW32__) 99#if defined(__CYGWIN__) || defined(__DJGPP__) || defined(__MINGW32__)
97#undef SIZE 100#undef SIZE
98#undef TYPE 101#undef TYPE
99#define SIZE(a,b) 102#define SIZE(a,b)
@@ -127,4 +130,6 @@ BSDI - a.out with a very primative version of as.
127EOF 130EOF
128 } 131 }
129 132
133sub main'align() {} # swallow align statements in 0.9.7 context
134
1301; 1351;
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
new file mode 100644
index 0000000000..b6bd744057
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86ms.pl
@@ -0,0 +1,380 @@
1#!/usr/local/bin/perl
2
3package x86ms;
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); }
30sub main'external_label { push(@labels,@_); }
31
32sub main'LB
33 {
34 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
35 return($lb{$_[0]});
36 }
37
38sub main'HB
39 {
40 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
41 return($hb{$_[0]});
42 }
43
44sub main'BP
45 {
46 &get_mem("BYTE",@_);
47 }
48
49sub main'DWP
50 {
51 &get_mem("DWORD",@_);
52 }
53
54sub main'BC
55 {
56 return @_;
57 }
58
59sub main'DWC
60 {
61 return @_;
62 }
63
64sub main'stack_push
65 {
66 local($num)=@_;
67 $stack+=$num*4;
68 &main'sub("esp",$num*4);
69 }
70
71sub main'stack_pop
72 {
73 local($num)=@_;
74 $stack-=$num*4;
75 &main'add("esp",$num*4);
76 }
77
78sub get_mem
79 {
80 local($size,$addr,$reg1,$reg2,$idx)=@_;
81 local($t,$post);
82 local($ret)="$size PTR ";
83
84 $addr =~ s/^\s+//;
85 if ($addr =~ /^(.+)\+(.+)$/)
86 {
87 $reg2=&conv($1);
88 $addr="_$2";
89 }
90 elsif ($addr =~ /^[_a-zA-Z]/)
91 {
92 $addr="_$addr";
93 }
94
95 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
96
97 $reg1="$regs{$reg1}" if defined($regs{$reg1});
98 $reg2="$regs{$reg2}" if defined($regs{$reg2});
99 if (($addr ne "") && ($addr ne 0))
100 {
101 if ($addr !~ /^-/)
102 { $ret.=$addr; }
103 else { $post=$addr; }
104 }
105 if ($reg2 ne "")
106 {
107 $t="";
108 $t="*$idx" if ($idx != 0);
109 $reg1="+".$reg1 if ("$reg1$post" ne "");
110 $ret.="[$reg2$t$reg1$post]";
111 }
112 else
113 {
114 $ret.="[$reg1$post]"
115 }
116 $ret =~ s/\[\]//; # in case $addr was the only argument
117 return($ret);
118 }
119
120sub main'mov { &out2("mov",@_); }
121sub main'movb { &out2("mov",@_); }
122sub main'and { &out2("and",@_); }
123sub main'or { &out2("or",@_); }
124sub main'shl { &out2("shl",@_); }
125sub main'shr { &out2("shr",@_); }
126sub main'xor { &out2("xor",@_); }
127sub main'xorb { &out2("xor",@_); }
128sub main'add { &out2("add",@_); }
129sub main'adc { &out2("adc",@_); }
130sub main'sub { &out2("sub",@_); }
131sub main'rotl { &out2("rol",@_); }
132sub main'rotr { &out2("ror",@_); }
133sub main'exch { &out2("xchg",@_); }
134sub main'cmp { &out2("cmp",@_); }
135sub main'lea { &out2("lea",@_); }
136sub main'mul { &out1("mul",@_); }
137sub main'div { &out1("div",@_); }
138sub main'dec { &out1("dec",@_); }
139sub main'inc { &out1("inc",@_); }
140sub main'jmp { &out1("jmp",@_); }
141sub main'jmp_ptr { &out1p("jmp",@_); }
142sub main'je { &out1("je",@_); }
143sub main'jle { &out1("jle",@_); }
144sub main'jz { &out1("jz",@_); }
145sub main'jge { &out1("jge",@_); }
146sub main'jl { &out1("jl",@_); }
147sub main'ja { &out1("ja",@_); }
148sub main'jae { &out1("jae",@_); }
149sub main'jb { &out1("jb",@_); }
150sub main'jbe { &out1("jbe",@_); }
151sub main'jc { &out1("jc",@_); }
152sub main'jnc { &out1("jnc",@_); }
153sub main'jnz { &out1("jnz",@_); }
154sub main'jne { &out1("jne",@_); }
155sub main'jno { &out1("jno",@_); }
156sub main'push { &out1("push",@_); $stack+=4; }
157sub main'pop { &out1("pop",@_); $stack-=4; }
158sub main'bswap { &out1("bswap",@_); &using486(); }
159sub main'not { &out1("not",@_); }
160sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
161sub main'ret { &out0("ret"); }
162sub main'nop { &out0("nop"); }
163sub main'movz { &out2("movzx",@_); }
164
165sub out2
166 {
167 local($name,$p1,$p2)=@_;
168 local($l,$t);
169
170 push(@out,"\t$name\t");
171 $t=&conv($p1).",";
172 $l=length($t);
173 push(@out,$t);
174 $l=4-($l+9)/8;
175 push(@out,"\t" x $l);
176 push(@out,&conv($p2));
177 push(@out,"\n");
178 }
179
180sub out0
181 {
182 local($name)=@_;
183
184 push(@out,"\t$name\n");
185 }
186
187sub out1
188 {
189 local($name,$p1)=@_;
190 local($l,$t);
191
192 push(@out,"\t$name\t".&conv($p1)."\n");
193 }
194
195sub conv
196 {
197 local($p)=@_;
198
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 local($file)=@_;
213
214 local($tmp)=<<"EOF";
215 TITLE $file.asm
216 .386
217.model FLAT
218EOF
219 push(@out,$tmp);
220 }
221
222sub main'function_begin
223 {
224 local($func,$extra)=@_;
225
226 push(@labels,$func);
227
228 local($tmp)=<<"EOF";
229_TEXT SEGMENT
230PUBLIC _$func
231$extra
232_$func PROC NEAR
233 push ebp
234 push ebx
235 push esi
236 push edi
237EOF
238 push(@out,$tmp);
239 $stack=20;
240 }
241
242sub main'function_begin_B
243 {
244 local($func,$extra)=@_;
245
246 local($tmp)=<<"EOF";
247_TEXT SEGMENT
248PUBLIC _$func
249$extra
250_$func PROC NEAR
251EOF
252 push(@out,$tmp);
253 $stack=4;
254 }
255
256sub main'function_end
257 {
258 local($func)=@_;
259
260 local($tmp)=<<"EOF";
261 pop edi
262 pop esi
263 pop ebx
264 pop ebp
265 ret
266_$func ENDP
267_TEXT ENDS
268EOF
269 push(@out,$tmp);
270 $stack=0;
271 %label=();
272 }
273
274sub main'function_end_B
275 {
276 local($func)=@_;
277
278 local($tmp)=<<"EOF";
279_$func ENDP
280_TEXT ENDS
281EOF
282 push(@out,$tmp);
283 $stack=0;
284 %label=();
285 }
286
287sub main'function_end_A
288 {
289 local($func)=@_;
290
291 local($tmp)=<<"EOF";
292 pop edi
293 pop esi
294 pop ebx
295 pop ebp
296 ret
297EOF
298 push(@out,$tmp);
299 }
300
301sub main'file_end
302 {
303 push(@out,"END\n");
304 }
305
306sub main'wparam
307 {
308 local($num)=@_;
309
310 return(&main'DWP($stack+$num*4,"esp","",0));
311 }
312
313sub main'swtmp
314 {
315 return(&main'DWP($_[0]*4,"esp","",0));
316 }
317
318# Should use swtmp, which is above esp. Linix can trash the stack above esp
319#sub main'wtmp
320# {
321# local($num)=@_;
322#
323# return(&main'DWP(-(($num+1)*4),"esp","",0));
324# }
325
326sub main'comment
327 {
328 foreach (@_)
329 {
330 push(@out,"\t; $_\n");
331 }
332 }
333
334sub main'label
335 {
336 if (!defined($label{$_[0]}))
337 {
338 $label{$_[0]}="\$${label}${_[0]}";
339 $label++;
340 }
341 return($label{$_[0]});
342 }
343
344sub main'set_label
345 {
346 if (!defined($label{$_[0]}))
347 {
348 $label{$_[0]}="\$${label}${_[0]}";
349 $label++;
350 }
351 if((defined $_[2]) && ($_[2] == 1))
352 {
353 push(@out,"$label{$_[0]}::\n");
354 }
355 else
356 {
357 push(@out,"$label{$_[0]}:\n");
358 }
359 }
360
361sub main'data_word
362 {
363 push(@out,"\tDD\t$_[0]\n");
364 }
365
366sub out1p
367 {
368 local($name,$p1)=@_;
369 local($l,$t);
370
371 push(@out,"\t$name\t ".&conv($p1)."\n");
372 }
373
374sub main'picmeup
375 {
376 local($dst,$sym)=@_;
377 &main'lea($dst,&main'DWP($sym));
378 }
379
380sub main'blindpop { &out1("pop",@_); }
diff --git a/src/lib/libcrypto/perlasm/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl
new file mode 100644
index 0000000000..4bdb3fe180
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86nasm.pl
@@ -0,0 +1,370 @@
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)="$size [";
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 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
102
103 $reg1="$regs{$reg1}" if defined($regs{$reg1});
104 $reg2="$regs{$reg2}" if defined($regs{$reg2});
105 if (($addr ne "") && ($addr ne 0))
106 {
107 if ($addr !~ /^-/)
108 { $ret.="${addr}+"; }
109 else { $post=$addr; }
110 }
111 if ($reg2 ne "")
112 {
113 $t="";
114 $t="*$idx" if ($idx != 0);
115 $reg1="+".$reg1 if ("$reg1$post" ne "");
116 $ret.="$reg2$t$reg1$post]";
117 }
118 else
119 {
120 $ret.="$reg1$post]"
121 }
122 $ret =~ s/\+\]/]/; # in case $addr was the only argument
123 return($ret);
124 }
125
126sub main'mov { &out2("mov",@_); }
127sub main'movb { &out2("mov",@_); }
128sub main'and { &out2("and",@_); }
129sub main'or { &out2("or",@_); }
130sub main'shl { &out2("shl",@_); }
131sub main'shr { &out2("shr",@_); }
132sub main'xor { &out2("xor",@_); }
133sub main'xorb { &out2("xor",@_); }
134sub main'add { &out2("add",@_); }
135sub main'adc { &out2("adc",@_); }
136sub main'sub { &out2("sub",@_); }
137sub main'rotl { &out2("rol",@_); }
138sub main'rotr { &out2("ror",@_); }
139sub main'exch { &out2("xchg",@_); }
140sub main'cmp { &out2("cmp",@_); }
141sub main'lea { &out2("lea",@_); }
142sub main'mul { &out1("mul",@_); }
143sub main'div { &out1("div",@_); }
144sub main'dec { &out1("dec",@_); }
145sub main'inc { &out1("inc",@_); }
146sub main'jmp { &out1("jmp",@_); }
147sub main'jmp_ptr { &out1p("jmp",@_); }
148
149# This is a bit of a kludge: declare all branches as NEAR.
150sub main'je { &out1("je NEAR",@_); }
151sub main'jle { &out1("jle NEAR",@_); }
152sub main'jz { &out1("jz NEAR",@_); }
153sub main'jge { &out1("jge NEAR",@_); }
154sub main'jl { &out1("jl NEAR",@_); }
155sub main'ja { &out1("ja NEAR",@_); }
156sub main'jae { &out1("jae NEAR",@_); }
157sub main'jb { &out1("jb NEAR",@_); }
158sub main'jbe { &out1("jbe NEAR",@_); }
159sub main'jc { &out1("jc NEAR",@_); }
160sub main'jnc { &out1("jnc NEAR",@_); }
161sub main'jnz { &out1("jnz NEAR",@_); }
162sub main'jne { &out1("jne NEAR",@_); }
163sub main'jno { &out1("jno NEAR",@_); }
164
165sub main'push { &out1("push",@_); $stack+=4; }
166sub main'pop { &out1("pop",@_); $stack-=4; }
167sub main'bswap { &out1("bswap",@_); &using486(); }
168sub main'not { &out1("not",@_); }
169sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
170sub main'ret { &out0("ret"); }
171sub main'nop { &out0("nop"); }
172sub main'movz { &out2("movzx",@_); }
173
174sub out2
175 {
176 my($name,$p1,$p2)=@_;
177 my($l,$t);
178
179 push(@out,"\t$name\t");
180 if ($name eq "lea")
181 {
182 $p1 =~ s/^[^\[]*\[/\[/;
183 $p2 =~ s/^[^\[]*\[/\[/;
184 }
185 $t=&conv($p1).",";
186 $l=length($t);
187 push(@out,$t);
188 $l=4-($l+9)/8;
189 push(@out,"\t" x $l);
190 push(@out,&conv($p2));
191 push(@out,"\n");
192 }
193
194sub out0
195 {
196 my($name)=@_;
197
198 push(@out,"\t$name\n");
199 }
200
201sub out1
202 {
203 my($name,$p1)=@_;
204 my($l,$t);
205 push(@out,"\t$name\t".&conv($p1)."\n");
206 }
207
208sub conv
209 {
210 my($p)=@_;
211 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
212 return $p;
213 }
214
215sub using486
216 {
217 return if $using486;
218 $using486++;
219 grep(s/\.386/\.486/,@out);
220 }
221
222sub main'file
223 {
224 local $tmp;
225 $tmp=<<___;
226%ifdef __omf__
227section code use32 class=code
228%else
229section .text
230%endif
231___
232 push(@out,$tmp);
233 }
234
235sub main'function_begin
236 {
237 my($func,$extra)=@_;
238
239 push(@labels,$func);
240 my($tmp)=<<"EOF";
241global _$func
242_$func:
243 push ebp
244 push ebx
245 push esi
246 push edi
247EOF
248 push(@out,$tmp);
249 $stack=20;
250 }
251
252sub main'function_begin_B
253 {
254 my($func,$extra)=@_;
255 my($tmp)=<<"EOF";
256global _$func
257_$func:
258EOF
259 push(@out,$tmp);
260 $stack=4;
261 }
262
263sub main'function_end
264 {
265 my($func)=@_;
266
267 my($tmp)=<<"EOF";
268 pop edi
269 pop esi
270 pop ebx
271 pop ebp
272 ret
273EOF
274 push(@out,$tmp);
275 $stack=0;
276 %label=();
277 }
278
279sub main'function_end_B
280 {
281 $stack=0;
282 %label=();
283 }
284
285sub main'function_end_A
286 {
287 my($func)=@_;
288
289 my($tmp)=<<"EOF";
290 pop edi
291 pop esi
292 pop ebx
293 pop ebp
294 ret
295EOF
296 push(@out,$tmp);
297 }
298
299sub main'file_end
300 {
301 }
302
303sub main'wparam
304 {
305 my($num)=@_;
306
307 return(&main'DWP($stack+$num*4,"esp","",0));
308 }
309
310sub main'swtmp
311 {
312 return(&main'DWP($_[0]*4,"esp","",0));
313 }
314
315# Should use swtmp, which is above esp. Linix can trash the stack above esp
316#sub main'wtmp
317# {
318# my($num)=@_;
319#
320# return(&main'DWP(-(($num+1)*4),"esp","",0));
321# }
322
323sub main'comment
324 {
325 foreach (@_)
326 {
327 push(@out,"\t; $_\n");
328 }
329 }
330
331sub main'label
332 {
333 if (!defined($label{$_[0]}))
334 {
335 $label{$_[0]}="\$${label}${_[0]}";
336 $label++;
337 }
338 return($label{$_[0]});
339 }
340
341sub main'set_label
342 {
343 if (!defined($label{$_[0]}))
344 {
345 $label{$_[0]}="\$${label}${_[0]}";
346 $label++;
347 }
348 push(@out,"$label{$_[0]}:\n");
349 }
350
351sub main'data_word
352 {
353 push(@out,"\tDD\t$_[0]\n");
354 }
355
356sub out1p
357 {
358 my($name,$p1)=@_;
359 my($l,$t);
360
361 push(@out,"\t$name\t ".&conv($p1)."\n");
362 }
363
364sub main'picmeup
365 {
366 local($dst,$sym)=@_;
367 &main'lea($dst,&main'DWP($sym));
368 }
369
370sub main'blindpop { &out1("pop",@_); }
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
new file mode 100644
index 0000000000..b61425e951
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -0,0 +1,628 @@
1#!/usr/local/bin/perl
2
3package x86unix;
4
5$label="L000";
6$const="";
7$constl=0;
8
9$align=($main'aout)?"4":"16";
10$under=($main'aout)?"_":"";
11$com_start=($main'sol)?"/":"#";
12
13sub main'asm_init_output { @out=(); }
14sub main'asm_get_output { return(@out); }
15sub main'get_labels { return(@labels); }
16sub main'external_label { push(@labels,@_); }
17
18if ($main'openbsd)
19 {
20 $com_start='/*';
21 $com_end='*/';
22 }
23
24if ($main'cpp)
25 {
26 $align="ALIGN";
27 $under="";
28 $com_start='/*';
29 $com_end='*/';
30 }
31
32%lb=( 'eax', '%al',
33 'ebx', '%bl',
34 'ecx', '%cl',
35 'edx', '%dl',
36 'ax', '%al',
37 'bx', '%bl',
38 'cx', '%cl',
39 'dx', '%dl',
40 );
41
42%hb=( 'eax', '%ah',
43 'ebx', '%bh',
44 'ecx', '%ch',
45 'edx', '%dh',
46 'ax', '%ah',
47 'bx', '%bh',
48 'cx', '%ch',
49 'dx', '%dh',
50 );
51
52%regs=( 'eax', '%eax',
53 'ebx', '%ebx',
54 'ecx', '%ecx',
55 'edx', '%edx',
56 'esi', '%esi',
57 'edi', '%edi',
58 'ebp', '%ebp',
59 'esp', '%esp',
60 );
61
62%reg_val=(
63 'eax', 0x00,
64 'ebx', 0x03,
65 'ecx', 0x01,
66 'edx', 0x02,
67 'esi', 0x06,
68 'edi', 0x07,
69 'ebp', 0x05,
70 'esp', 0x04,
71 );
72
73sub main'LB
74 {
75 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
76 return($lb{$_[0]});
77 }
78
79sub main'HB
80 {
81 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
82 return($hb{$_[0]});
83 }
84
85sub main'DWP
86 {
87 local($addr,$reg1,$reg2,$idx)=@_;
88
89 $ret="";
90 $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/;
91 $reg1="$regs{$reg1}" if defined($regs{$reg1});
92 $reg2="$regs{$reg2}" if defined($regs{$reg2});
93 $ret.=$addr if ($addr ne "") && ($addr ne 0);
94 if ($reg2 ne "")
95 {
96 if($idx ne "" && $idx != 0)
97 { $ret.="($reg1,$reg2,$idx)"; }
98 else
99 { $ret.="($reg1,$reg2)"; }
100 }
101 elsif ($reg1 ne "")
102 { $ret.="($reg1)" }
103 return($ret);
104 }
105
106sub main'BP
107 {
108 return(&main'DWP(@_));
109 }
110
111sub main'BC
112 {
113 return @_;
114 }
115
116sub main'DWC
117 {
118 return @_;
119 }
120
121#sub main'BP
122# {
123# local($addr,$reg1,$reg2,$idx)=@_;
124#
125# $ret="";
126#
127# $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
128# $reg1="$regs{$reg1}" if defined($regs{$reg1});
129# $reg2="$regs{$reg2}" if defined($regs{$reg2});
130# $ret.=$addr if ($addr ne "") && ($addr ne 0);
131# if ($reg2 ne "")
132# { $ret.="($reg1,$reg2,$idx)"; }
133# else
134# { $ret.="($reg1)" }
135# return($ret);
136# }
137
138sub main'mov { &out2("movl",@_); }
139sub main'movb { &out2("movb",@_); }
140sub main'and { &out2("andl",@_); }
141sub main'or { &out2("orl",@_); }
142sub main'shl { &out2("sall",@_); }
143sub main'shr { &out2("shrl",@_); }
144sub main'xor { &out2("xorl",@_); }
145sub main'xorb { &out2("xorb",@_); }
146sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
147sub main'adc { &out2("adcl",@_); }
148sub main'sub { &out2("subl",@_); }
149sub main'rotl { &out2("roll",@_); }
150sub main'rotr { &out2("rorl",@_); }
151sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
152sub main'cmp { &out2("cmpl",@_); }
153sub main'lea { &out2("leal",@_); }
154sub main'mul { &out1("mull",@_); }
155sub main'div { &out1("divl",@_); }
156sub main'jmp { &out1("jmp",@_); }
157sub main'jmp_ptr { &out1p("jmp",@_); }
158sub main'je { &out1("je",@_); }
159sub main'jle { &out1("jle",@_); }
160sub main'jne { &out1("jne",@_); }
161sub main'jnz { &out1("jnz",@_); }
162sub main'jz { &out1("jz",@_); }
163sub main'jge { &out1("jge",@_); }
164sub main'jl { &out1("jl",@_); }
165sub main'ja { &out1("ja",@_); }
166sub main'jae { &out1("jae",@_); }
167sub main'jb { &out1("jb",@_); }
168sub main'jbe { &out1("jbe",@_); }
169sub main'jc { &out1("jc",@_); }
170sub main'jnc { &out1("jnc",@_); }
171sub main'jno { &out1("jno",@_); }
172sub main'dec { &out1("decl",@_); }
173sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
174sub main'push { &out1("pushl",@_); $stack+=4; }
175sub main'pop { &out1("popl",@_); $stack-=4; }
176sub main'pushf { &out0("pushf"); $stack+=4; }
177sub main'popf { &out0("popf"); $stack-=4; }
178sub main'not { &out1("notl",@_); }
179sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); }
180sub main'ret { &out0("ret"); }
181sub main'nop { &out0("nop"); }
182sub main'test { &out2("testl",@_); }
183sub main'movz { &out2("movzbl",@_); }
184sub main'neg { &out1("negl",@_); }
185
186# The bswapl instruction is new for the 486. Emulate if i386.
187sub main'bswap
188 {
189 if ($main'i386)
190 {
191 &main'comment("bswapl @_");
192 &main'exch(main'HB(@_),main'LB(@_));
193 &main'rotr(@_,16);
194 &main'exch(main'HB(@_),main'LB(@_));
195 }
196 else
197 {
198 &out1("bswapl",@_);
199 }
200 }
201
202sub out2
203 {
204 local($name,$p1,$p2)=@_;
205 local($l,$ll,$t);
206 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
207 "rcll",0xD1D0,"rcrl",0xD1D8,
208 "shll",0xD1E0,"shrl",0xD1E8,
209 "sarl",0xD1F8);
210
211 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
212 {
213 $op=$special{$name}|$reg_val{$p1};
214 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
215 $tmp2=sprintf(".byte %d\t",$op &0xff);
216 push(@out,$tmp1);
217 push(@out,$tmp2);
218
219 $p2=&conv($p2);
220 $p1=&conv($p1);
221 &main'comment("$name $p2 $p1");
222 return;
223 }
224
225 push(@out,"\t$name\t");
226 $t=&conv($p2).",";
227 $l=length($t);
228 push(@out,$t);
229 $ll=4-($l+9)/8;
230 $tmp1=sprintf("\t" x $ll);
231 push(@out,$tmp1);
232 push(@out,&conv($p1)."\n");
233 }
234
235sub out1
236 {
237 local($name,$p1)=@_;
238 local($l,$t);
239 local(%special)=("bswapl",0x0FC8);
240
241 if ((defined($special{$name})) && defined($regs{$p1}))
242 {
243 $op=$special{$name}|$reg_val{$p1};
244 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
245 $tmp2=sprintf(".byte %d\t",$op &0xff);
246 push(@out,$tmp1);
247 push(@out,$tmp2);
248
249 $p2=&conv($p2);
250 $p1=&conv($p1);
251 &main'comment("$name $p2 $p1");
252 return;
253 }
254
255 push(@out,"\t$name\t".&conv($p1)."\n");
256 }
257
258sub out1p
259 {
260 local($name,$p1)=@_;
261 local($l,$t);
262
263 push(@out,"\t$name\t*".&conv($p1)."\n");
264 }
265
266sub out0
267 {
268 push(@out,"\t$_[0]\n");
269 }
270
271sub conv
272 {
273 local($p)=@_;
274
275# $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
276
277 $p=$regs{$p} if (defined($regs{$p}));
278
279 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
280 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
281 return $p;
282 }
283
284sub main'file
285 {
286 local($file)=@_;
287
288 if ($main'openbsd)
289 { push(@out,"#include <machine/asm.h>\n"); return; }
290
291 local($tmp)=<<"EOF";
292 .file "$file.s"
293 .version "01.01"
294gcc2_compiled.:
295EOF
296 push(@out,$tmp);
297 }
298
299sub main'function_begin
300 {
301 local($func)=@_;
302
303 &main'external_label($func);
304 $func=$under.$func;
305
306 if ($main'openbsd)
307 { push (@out, "\nENTRY($func)\n"); goto skip; }
308
309 local($tmp)=<<"EOF";
310.text
311 .align $align
312.globl $func
313EOF
314 push(@out,$tmp);
315 if ($main'cpp)
316 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
317 elsif ($main'gaswin)
318 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
319 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
320 push(@out,"$func:\n");
321skip:
322 $tmp=<<"EOF";
323 pushl %ebp
324 pushl %ebx
325 pushl %esi
326 pushl %edi
327
328EOF
329 push(@out,$tmp);
330 $stack=20;
331 }
332
333sub main'function_begin_B
334 {
335 local($func,$extra)=@_;
336
337 &main'external_label($func);
338 $func=$under.$func;
339
340 if ($main'openbsd)
341 { push(@out, "\nENTRY($func)\n"); goto skip; }
342
343 local($tmp)=<<"EOF";
344.text
345 .align $align
346.globl $func
347EOF
348 push(@out,$tmp);
349 if ($main'cpp)
350 { push(@out,"\tTYPE($func,\@function)\n"); }
351 elsif ($main'gaswin)
352 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
353 else { push(@out,"\t.type $func,\@function\n"); }
354 push(@out,"$func:\n");
355skip:
356 $stack=4;
357 }
358
359sub main'function_end
360 {
361 local($func)=@_;
362
363 $func=$under.$func;
364
365 local($tmp)=<<"EOF";
366 popl %edi
367 popl %esi
368 popl %ebx
369 popl %ebp
370 ret
371.L_${func}_end:
372EOF
373 push(@out,$tmp);
374
375 if ($main'cpp)
376 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
377 elsif ($main'gaswin)
378 { $tmp=push(@out,"\t.align 4\n"); }
379 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
380 push(@out,".ident \"$func\"\n");
381 $stack=0;
382 %label=();
383 }
384
385sub main'function_end_A
386 {
387 local($func)=@_;
388
389 local($tmp)=<<"EOF";
390 popl %edi
391 popl %esi
392 popl %ebx
393 popl %ebp
394 ret
395EOF
396 push(@out,$tmp);
397 }
398
399sub main'function_end_B
400 {
401 local($func)=@_;
402
403 $func=$under.$func;
404
405 push(@out,".L_${func}_end:\n");
406 if ($main'cpp)
407 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
408 elsif ($main'gaswin)
409 { push(@out,"\t.align 4\n"); }
410 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
411 push(@out,".ident \"desasm.pl\"\n");
412 $stack=0;
413 %label=();
414 }
415
416sub main'wparam
417 {
418 local($num)=@_;
419
420 return(&main'DWP($stack+$num*4,"esp","",0));
421 }
422
423sub main'stack_push
424 {
425 local($num)=@_;
426 $stack+=$num*4;
427 &main'sub("esp",$num*4);
428 }
429
430sub main'stack_pop
431 {
432 local($num)=@_;
433 $stack-=$num*4;
434 &main'add("esp",$num*4);
435 }
436
437sub main'swtmp
438 {
439 return(&main'DWP($_[0]*4,"esp","",0));
440 }
441
442# Should use swtmp, which is above esp. Linix can trash the stack above esp
443#sub main'wtmp
444# {
445# local($num)=@_;
446#
447# return(&main'DWP(-($num+1)*4,"esp","",0));
448# }
449
450sub main'comment
451 {
452 if (!$main'openbsd && $main'elf)
453 # GNU and SVR4 as'es use different comment delimiters,
454 { # so we just skip comments...
455 push(@out,"\n");
456 return;
457 }
458 foreach (@_)
459 {
460 if (/^\s*$/)
461 { push(@out,"\n"); }
462 else
463 { push(@out,"\t$com_start $_ $com_end\n"); }
464 }
465 }
466
467sub main'public_label
468 {
469 $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
470 push(@out,".globl\t$label{$_[0]}\n");
471 }
472
473sub main'label
474 {
475 if (!defined($label{$_[0]}))
476 {
477 $label{$_[0]}=".${label}${_[0]}";
478 $label++;
479 }
480 return($label{$_[0]});
481 }
482
483sub main'set_label
484 {
485 if (!defined($label{$_[0]}))
486 {
487 $label{$_[0]}=".${label}${_[0]}";
488 $label++;
489 }
490 if ($main'openbsd)
491 { push(@out,"_ALIGN_TEXT\n") if ($_[1] != 0); }
492 else
493 { push(@out,".align $align\n") if ($_[1] != 0); }
494 push(@out,"$label{$_[0]}:\n");
495 }
496
497sub main'file_end
498 {
499 if ($const ne "")
500 {
501 push(@out,".section .rodata\n");
502 push(@out,$const);
503 $const="";
504 }
505 }
506
507sub main'data_word
508 {
509 push(@out,"\t.long\t".join(',',@_)."\n");
510 }
511
512# debug output functions: puts, putx, printf
513
514sub main'puts
515 {
516 &pushvars();
517 &main'push('$Lstring' . ++$constl);
518 &main'call('puts');
519 $stack-=4;
520 &main'add("esp",4);
521 &popvars();
522
523 $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
524 }
525
526sub main'putx
527 {
528 &pushvars();
529 &main'push($_[0]);
530 &main'push('$Lstring' . ++$constl);
531 &main'call('printf');
532 &main'add("esp",8);
533 $stack-=8;
534 &popvars();
535
536 $const .= "Lstring$constl:\n\t.string \"\%X\"\n";
537 }
538
539sub main'printf
540 {
541 $ostack = $stack;
542 &pushvars();
543 for ($i = @_ - 1; $i >= 0; $i--)
544 {
545 if ($i == 0) # change this to support %s format strings
546 {
547 &main'push('$Lstring' . ++$constl);
548 $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
549 }
550 else
551 {
552 if ($_[$i] =~ /([0-9]*)\(%esp\)/)
553 {
554 &main'push(($1 + $stack - $ostack) . '(%esp)');
555 }
556 else
557 {
558 &main'push($_[$i]);
559 }
560 }
561 }
562 &main'call('printf');
563 $stack-=4*@_;
564 &main'add("esp",4*@_);
565 &popvars();
566 }
567
568sub pushvars
569 {
570 &main'pushf();
571 &main'push("edx");
572 &main'push("ecx");
573 &main'push("eax");
574 }
575
576sub popvars
577 {
578 &main'pop("eax");
579 &main'pop("ecx");
580 &main'pop("edx");
581 &main'popf();
582 }
583
584sub main'picmeup
585 {
586 local($dst,$sym)=@_;
587 if ($main'cpp)
588 {
589 local($tmp)=<<___;
590#if (defined(ELF) || defined(SOL)) && defined(PIC)
591 .align 8
592 call 1f
5931: popl $regs{$dst}
594 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
595 movl $sym\@GOT($regs{$dst}),$regs{$dst}
596#else
597 leal $sym,$regs{$dst}
598#endif
599___
600 push(@out,$tmp);
601 }
602 elsif ($main'openbsd)
603 {
604 push(@out, "#ifdef PIC\n");
605 push(@out, "\tPIC_PROLOGUE\n");
606 &main'mov($dst,"PIC_GOT($sym)");
607 push(@out, "\tPIC_EPILOGUE\n");
608 push(@out, "#else\n");
609 &main'lea($dst,&main'DWP($sym));
610 push(@out, "#endif\n");
611 }
612 elsif ($main'pic && ($main'elf || $main'aout))
613 {
614 push(@out,"\t.align\t8\n");
615 &main'call(&main'label("PIC_me_up"));
616 &main'set_label("PIC_me_up");
617 &main'blindpop($dst);
618 &main'add($dst,"\$$under"."_GLOBAL_OFFSET_TABLE_+[.-".
619 &main'label("PIC_me_up") . "]");
620 &main'mov($dst,&main'DWP($sym."\@GOT",$dst));
621 }
622 else
623 {
624 &main'lea($dst,&main'DWP($sym));
625 }
626 }
627
628sub main'blindpop { &out1("popl",@_); }
diff --git a/src/lib/libcrypto/pkcs12/Makefile b/src/lib/libcrypto/pkcs12/Makefile
new file mode 100644
index 0000000000..3a7498fe7a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/Makefile
@@ -0,0 +1,286 @@
1#
2# OpenSSL/crypto/pkcs12/Makefile
3#
4
5DIR= pkcs12
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= p12_add.c p12_asn.c p12_attr.c p12_crpt.c p12_crt.c p12_decr.c \
21 p12_init.c p12_key.c p12_kiss.c p12_mutl.c\
22 p12_utl.c p12_npas.c pk12err.c p12_p8d.c p12_p8e.c
23LIBOBJ= p12_add.o p12_asn.o p12_attr.o p12_crpt.o p12_crt.o p12_decr.o \
24 p12_init.o p12_key.o p12_kiss.o p12_mutl.o\
25 p12_utl.o p12_npas.o pk12err.o p12_p8d.o p12_p8e.o
26
27SRC= $(LIBSRC)
28
29EXHEADER= pkcs12.h
30HEADER= $(EXHEADER)
31
32ALL= $(GENERAL) $(SRC) $(HEADER)
33
34top:
35 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
36
37test:
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
48
49links:
50 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
51 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
52 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
53
54install:
55 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
56 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
72 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
73
74dclean:
75 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
76 mv -f Makefile.new $(MAKEFILE)
77
78clean:
79 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
80
81# DO NOT DELETE THIS LINE -- make depend depends on it.
82
83p12_add.o: ../../e_os.h ../../include/openssl/asn1.h
84p12_add.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
85p12_add.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
86p12_add.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
87p12_add.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
88p12_add.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
89p12_add.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
90p12_add.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
91p12_add.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
92p12_add.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
93p12_add.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
94p12_add.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
95p12_add.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_add.c
96p12_asn.o: ../../e_os.h ../../include/openssl/asn1.h
97p12_asn.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
98p12_asn.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
99p12_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
100p12_asn.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
101p12_asn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
102p12_asn.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
103p12_asn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104p12_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105p12_asn.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
106p12_asn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
107p12_asn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
108p12_asn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
109p12_asn.o: ../cryptlib.h p12_asn.c
110p12_attr.o: ../../e_os.h ../../include/openssl/asn1.h
111p12_attr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
112p12_attr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
113p12_attr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
114p12_attr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
115p12_attr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
116p12_attr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
117p12_attr.o: ../../include/openssl/opensslconf.h
118p12_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
119p12_attr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
120p12_attr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
121p12_attr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
122p12_attr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
123p12_attr.o: ../cryptlib.h p12_attr.c
124p12_crpt.o: ../../e_os.h ../../include/openssl/asn1.h
125p12_crpt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
126p12_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
127p12_crpt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
128p12_crpt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
129p12_crpt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
130p12_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
131p12_crpt.o: ../../include/openssl/opensslconf.h
132p12_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
133p12_crpt.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
134p12_crpt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
135p12_crpt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
136p12_crpt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
137p12_crpt.o: ../cryptlib.h p12_crpt.c
138p12_crt.o: ../../e_os.h ../../include/openssl/asn1.h
139p12_crt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
140p12_crt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
141p12_crt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
142p12_crt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
143p12_crt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
144p12_crt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
145p12_crt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
146p12_crt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
147p12_crt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
148p12_crt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
149p12_crt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
150p12_crt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_crt.c
151p12_decr.o: ../../e_os.h ../../include/openssl/asn1.h
152p12_decr.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
153p12_decr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
154p12_decr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
155p12_decr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
156p12_decr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
157p12_decr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
158p12_decr.o: ../../include/openssl/opensslconf.h
159p12_decr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
160p12_decr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
161p12_decr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
162p12_decr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
163p12_decr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
164p12_decr.o: ../cryptlib.h p12_decr.c
165p12_init.o: ../../e_os.h ../../include/openssl/asn1.h
166p12_init.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
167p12_init.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
168p12_init.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
169p12_init.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
170p12_init.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
171p12_init.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
172p12_init.o: ../../include/openssl/opensslconf.h
173p12_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
174p12_init.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
175p12_init.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
176p12_init.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
177p12_init.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
178p12_init.o: ../cryptlib.h p12_init.c
179p12_key.o: ../../e_os.h ../../include/openssl/asn1.h
180p12_key.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
181p12_key.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
182p12_key.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
183p12_key.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
184p12_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
185p12_key.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
186p12_key.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
187p12_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
188p12_key.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
189p12_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
190p12_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
191p12_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
192p12_key.o: ../cryptlib.h p12_key.c
193p12_kiss.o: ../../e_os.h ../../include/openssl/asn1.h
194p12_kiss.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
195p12_kiss.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
196p12_kiss.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
197p12_kiss.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
198p12_kiss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
199p12_kiss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
200p12_kiss.o: ../../include/openssl/opensslconf.h
201p12_kiss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
202p12_kiss.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
203p12_kiss.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
204p12_kiss.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
205p12_kiss.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
206p12_kiss.o: ../cryptlib.h p12_kiss.c
207p12_mutl.o: ../../e_os.h ../../include/openssl/asn1.h
208p12_mutl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
209p12_mutl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
210p12_mutl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
211p12_mutl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
212p12_mutl.o: ../../include/openssl/evp.h ../../include/openssl/hmac.h
213p12_mutl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
214p12_mutl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
215p12_mutl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
216p12_mutl.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
217p12_mutl.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
218p12_mutl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
219p12_mutl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
220p12_mutl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_mutl.c
221p12_npas.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
222p12_npas.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
223p12_npas.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
224p12_npas.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
225p12_npas.o: ../../include/openssl/err.h ../../include/openssl/evp.h
226p12_npas.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
227p12_npas.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
228p12_npas.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
229p12_npas.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
230p12_npas.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
231p12_npas.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
232p12_npas.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
233p12_npas.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
234p12_npas.o: p12_npas.c
235p12_p8d.o: ../../e_os.h ../../include/openssl/asn1.h
236p12_p8d.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
237p12_p8d.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
238p12_p8d.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
239p12_p8d.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
240p12_p8d.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
241p12_p8d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
242p12_p8d.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
243p12_p8d.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
244p12_p8d.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
245p12_p8d.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
246p12_p8d.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
247p12_p8d.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_p8d.c
248p12_p8e.o: ../../e_os.h ../../include/openssl/asn1.h
249p12_p8e.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
250p12_p8e.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
251p12_p8e.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
252p12_p8e.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
253p12_p8e.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
254p12_p8e.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
255p12_p8e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
256p12_p8e.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
257p12_p8e.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
258p12_p8e.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
259p12_p8e.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
260p12_p8e.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_p8e.c
261p12_utl.o: ../../e_os.h ../../include/openssl/asn1.h
262p12_utl.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
263p12_utl.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
264p12_utl.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
265p12_utl.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
266p12_utl.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
267p12_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
268p12_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
269p12_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
270p12_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
271p12_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
272p12_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
273p12_utl.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_utl.c
274pk12err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
275pk12err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
276pk12err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
277pk12err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
278pk12err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
279pk12err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
280pk12err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
281pk12err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
282pk12err.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
283pk12err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
284pk12err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
285pk12err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
286pk12err.o: pk12err.c
diff --git a/src/lib/libcrypto/pkcs12/Makefile.ssl b/src/lib/libcrypto/pkcs12/Makefile.ssl
new file mode 100644
index 0000000000..a6e47b4085
--- /dev/null
+++ b/src/lib/libcrypto/pkcs12/Makefile.ssl
@@ -0,0 +1,417 @@
1#
2# SSLeay/crypto/pkcs12/Makefile
3#
4
5DIR= pkcs12
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= p12_add.c p12_asn.c p12_attr.c p12_crpt.c p12_crt.c p12_decr.c \
27 p12_init.c p12_key.c p12_kiss.c p12_mutl.c\
28 p12_utl.c p12_npas.c pk12err.c p12_p8d.c p12_p8e.c
29LIBOBJ= p12_add.o p12_asn.o p12_attr.o p12_crpt.o p12_crt.o p12_decr.o \
30 p12_init.o p12_key.o p12_kiss.o p12_mutl.o\
31 p12_utl.o p12_npas.o pk12err.o p12_p8d.o p12_p8e.o
32
33SRC= $(LIBSRC)
34
35EXHEADER= pkcs12.h
36HEADER= $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43test:
44
45all: lib
46
47lib: $(LIBOBJ)
48 $(AR) $(LIB) $(LIBOBJ)
49 $(RANLIB) $(LIB) || echo Never mind.
50 @touch lib
51
52files:
53 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
54
55links:
56 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
57 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
58 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
59 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
60
61install:
62 @for i in $(EXHEADER) ; \
63 do \
64 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
65 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
66 done;
67
68tags:
69 ctags $(SRC)
70
71tests:
72
73lint:
74 lint -DLINT $(INCLUDES) $(SRC)>fluff
75
76depend:
77 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
78
79dclean:
80 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
81 mv -f Makefile.new $(MAKEFILE)
82
83clean:
84 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
85
86# DO NOT DELETE THIS LINE -- make depend depends on it.
87
88p12_add.o: ../../e_os.h ../../include/openssl/aes.h
89p12_add.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
90p12_add.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
91p12_add.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
92p12_add.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
93p12_add.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
94p12_add.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
95p12_add.o: ../../include/openssl/err.h ../../include/openssl/evp.h
96p12_add.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
97p12_add.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
98p12_add.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
99p12_add.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
100p12_add.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
101p12_add.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
102p12_add.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
103p12_add.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
104p12_add.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
105p12_add.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
106p12_add.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
107p12_add.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
108p12_add.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
109p12_add.o: ../cryptlib.h p12_add.c
110p12_asn.o: ../../e_os.h ../../include/openssl/aes.h
111p12_asn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
112p12_asn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
113p12_asn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
114p12_asn.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
115p12_asn.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
116p12_asn.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
117p12_asn.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
118p12_asn.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
119p12_asn.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
120p12_asn.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
121p12_asn.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
122p12_asn.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
123p12_asn.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
124p12_asn.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
125p12_asn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
126p12_asn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
127p12_asn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
128p12_asn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
129p12_asn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
130p12_asn.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
131p12_asn.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_asn.c
132p12_attr.o: ../../e_os.h ../../include/openssl/aes.h
133p12_attr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
134p12_attr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
135p12_attr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
136p12_attr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
137p12_attr.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
138p12_attr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
139p12_attr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
140p12_attr.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
141p12_attr.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
142p12_attr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
143p12_attr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
144p12_attr.o: ../../include/openssl/opensslconf.h
145p12_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
146p12_attr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
147p12_attr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
148p12_attr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
149p12_attr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
150p12_attr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151p12_attr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
152p12_attr.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
153p12_attr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_attr.c
154p12_crpt.o: ../../e_os.h ../../include/openssl/aes.h
155p12_crpt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
156p12_crpt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
157p12_crpt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
158p12_crpt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
159p12_crpt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
160p12_crpt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
161p12_crpt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
162p12_crpt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
163p12_crpt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
164p12_crpt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
165p12_crpt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
166p12_crpt.o: ../../include/openssl/opensslconf.h
167p12_crpt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
168p12_crpt.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
169p12_crpt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
170p12_crpt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
171p12_crpt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
172p12_crpt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
173p12_crpt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
174p12_crpt.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
175p12_crpt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_crpt.c
176p12_crt.o: ../../e_os.h ../../include/openssl/aes.h
177p12_crt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
178p12_crt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
179p12_crt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
180p12_crt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
181p12_crt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
182p12_crt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
183p12_crt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
184p12_crt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
185p12_crt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
186p12_crt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
187p12_crt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
188p12_crt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
189p12_crt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
190p12_crt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
191p12_crt.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
192p12_crt.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
193p12_crt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
194p12_crt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
195p12_crt.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
196p12_crt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
197p12_crt.o: ../cryptlib.h p12_crt.c
198p12_decr.o: ../../e_os.h ../../include/openssl/aes.h
199p12_decr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
200p12_decr.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
201p12_decr.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
202p12_decr.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
203p12_decr.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
204p12_decr.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
205p12_decr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
206p12_decr.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
207p12_decr.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
208p12_decr.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
209p12_decr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
210p12_decr.o: ../../include/openssl/opensslconf.h
211p12_decr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
212p12_decr.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
213p12_decr.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
214p12_decr.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
215p12_decr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
216p12_decr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
217p12_decr.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
218p12_decr.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
219p12_decr.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_decr.c
220p12_init.o: ../../e_os.h ../../include/openssl/aes.h
221p12_init.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
222p12_init.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
223p12_init.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
224p12_init.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
225p12_init.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
226p12_init.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
227p12_init.o: ../../include/openssl/err.h ../../include/openssl/evp.h
228p12_init.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
229p12_init.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
230p12_init.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
231p12_init.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
232p12_init.o: ../../include/openssl/opensslconf.h
233p12_init.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
234p12_init.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
235p12_init.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
236p12_init.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
237p12_init.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
238p12_init.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
239p12_init.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
240p12_init.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
241p12_init.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_init.c
242p12_key.o: ../../e_os.h ../../include/openssl/aes.h
243p12_key.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
244p12_key.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
245p12_key.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
246p12_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
247p12_key.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
248p12_key.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
249p12_key.o: ../../include/openssl/err.h ../../include/openssl/evp.h
250p12_key.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
251p12_key.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
252p12_key.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
253p12_key.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
254p12_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
255p12_key.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
256p12_key.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
257p12_key.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
258p12_key.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
259p12_key.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
260p12_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
261p12_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
262p12_key.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
263p12_key.o: ../cryptlib.h p12_key.c
264p12_kiss.o: ../../e_os.h ../../include/openssl/aes.h
265p12_kiss.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
266p12_kiss.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
267p12_kiss.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
268p12_kiss.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
269p12_kiss.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
270p12_kiss.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
271p12_kiss.o: ../../include/openssl/err.h ../../include/openssl/evp.h
272p12_kiss.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
273p12_kiss.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
274p12_kiss.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
275p12_kiss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
276p12_kiss.o: ../../include/openssl/opensslconf.h
277p12_kiss.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
278p12_kiss.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
279p12_kiss.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
280p12_kiss.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
281p12_kiss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
282p12_kiss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
283p12_kiss.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
284p12_kiss.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
285p12_kiss.o: ../../include/openssl/x509_vfy.h ../cryptlib.h p12_kiss.c
286p12_mutl.o: ../../e_os.h ../../include/openssl/aes.h
287p12_mutl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
288p12_mutl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
289p12_mutl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
290p12_mutl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
291p12_mutl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
292p12_mutl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
293p12_mutl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
294p12_mutl.o: ../../include/openssl/hmac.h ../../include/openssl/idea.h
295p12_mutl.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
296p12_mutl.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
297p12_mutl.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
298p12_mutl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
299p12_mutl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
300p12_mutl.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
301p12_mutl.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
302p12_mutl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
303p12_mutl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
304p12_mutl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
305p12_mutl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
306p12_mutl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
307p12_mutl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
308p12_mutl.o: ../cryptlib.h p12_mutl.c
309p12_npas.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
310p12_npas.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
311p12_npas.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
312p12_npas.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
313p12_npas.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
314p12_npas.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
315p12_npas.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
316p12_npas.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
317p12_npas.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
318p12_npas.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
319p12_npas.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
320p12_npas.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
321p12_npas.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
322p12_npas.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
323p12_npas.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
324p12_npas.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
325p12_npas.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
326p12_npas.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
327p12_npas.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
328p12_npas.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
329p12_npas.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
330p12_npas.o: ../../include/openssl/x509_vfy.h p12_npas.c
331p12_p8d.o: ../../e_os.h ../../include/openssl/aes.h
332p12_p8d.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
333p12_p8d.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
334p12_p8d.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
335p12_p8d.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
336p12_p8d.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
337p12_p8d.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
338p12_p8d.o: ../../include/openssl/err.h ../../include/openssl/evp.h
339p12_p8d.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
340p12_p8d.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
341p12_p8d.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
342p12_p8d.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
343p12_p8d.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
344p12_p8d.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
345p12_p8d.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
346p12_p8d.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
347p12_p8d.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
348p12_p8d.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
349p12_p8d.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
350p12_p8d.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
351p12_p8d.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
352p12_p8d.o: ../cryptlib.h p12_p8d.c
353p12_p8e.o: ../../e_os.h ../../include/openssl/aes.h
354p12_p8e.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
355p12_p8e.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
356p12_p8e.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
357p12_p8e.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
358p12_p8e.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
359p12_p8e.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
360p12_p8e.o: ../../include/openssl/err.h ../../include/openssl/evp.h
361p12_p8e.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
362p12_p8e.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
363p12_p8e.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
364p12_p8e.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
365p12_p8e.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
366p12_p8e.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
367p12_p8e.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
368p12_p8e.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
369p12_p8e.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
370p12_p8e.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
371p12_p8e.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
372p12_p8e.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
373p12_p8e.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
374p12_p8e.o: ../cryptlib.h p12_p8e.c
375p12_utl.o: ../../e_os.h ../../include/openssl/aes.h
376p12_utl.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
377p12_utl.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
378p12_utl.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
379p12_utl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
380p12_utl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
381p12_utl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
382p12_utl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
383p12_utl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
384p12_utl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
385p12_utl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
386p12_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
387p12_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
388p12_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs12.h
389p12_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
390p12_utl.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
391p12_utl.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
392p12_utl.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
393p12_utl.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
394p12_utl.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
395p12_utl.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
396p12_utl.o: ../cryptlib.h p12_utl.c
397pk12err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
398pk12err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
399pk12err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
400pk12err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
401pk12err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
402pk12err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
403pk12err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
404pk12err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
405pk12err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
406pk12err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
407pk12err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
408pk12err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
409pk12err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
410pk12err.o: ../../include/openssl/pkcs12.h ../../include/openssl/pkcs7.h
411pk12err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
412pk12err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
413pk12err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
414pk12err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
415pk12err.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
416pk12err.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
417pk12err.o: ../../include/openssl/x509_vfy.h pk12err.c
diff --git a/src/lib/libcrypto/pkcs12/p12_add.c b/src/lib/libcrypto/pkcs12/p12_add.c
index 41bdc00551..27015dd8c3 100644
--- a/src/lib/libcrypto/pkcs12/p12_add.c
+++ b/src/lib/libcrypto/pkcs12/p12_add.c
@@ -68,16 +68,16 @@ PKCS12_SAFEBAG *PKCS12_item_pack_safebag(void *obj, const ASN1_ITEM *it, int nid
68 PKCS12_BAGS *bag; 68 PKCS12_BAGS *bag;
69 PKCS12_SAFEBAG *safebag; 69 PKCS12_SAFEBAG *safebag;
70 if (!(bag = PKCS12_BAGS_new())) { 70 if (!(bag = PKCS12_BAGS_new())) {
71 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); 71 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
72 return NULL; 72 return NULL;
73 } 73 }
74 bag->type = OBJ_nid2obj(nid1); 74 bag->type = OBJ_nid2obj(nid1);
75 if (!ASN1_item_pack(obj, it, &bag->value.octet)) { 75 if (!ASN1_item_pack(obj, it, &bag->value.octet)) {
76 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); 76 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
77 return NULL; 77 return NULL;
78 } 78 }
79 if (!(safebag = PKCS12_SAFEBAG_new())) { 79 if (!(safebag = PKCS12_SAFEBAG_new())) {
80 PKCS12err(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE); 80 PKCS12err(PKCS12_F_PKCS12_PACK_SAFEBAG, ERR_R_MALLOC_FAILURE);
81 return NULL; 81 return NULL;
82 } 82 }
83 safebag->value.bag = bag; 83 safebag->value.bag = bag;
diff --git a/src/lib/libcrypto/pkcs12/p12_crpt.c b/src/lib/libcrypto/pkcs12/p12_crpt.c
index 3ad33c49d8..003ec7a33e 100644
--- a/src/lib/libcrypto/pkcs12/p12_crpt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crpt.c
@@ -84,25 +84,19 @@ EVP_PBE_alg_add(NID_pbe_WithSHA1And40BitRC2_CBC, EVP_rc2_40_cbc(),
84#endif 84#endif
85} 85}
86 86
87int PKCS12_PBE_keyivgen(EVP_CIPHER_CTX *ctx, const char *pass, int passlen, 87int PKCS12_PBE_keyivgen (EVP_CIPHER_CTX *ctx, const char *pass, int passlen,
88 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de) 88 ASN1_TYPE *param, const EVP_CIPHER *cipher, const EVP_MD *md, int en_de)
89{ 89{
90 PBEPARAM *pbe; 90 PBEPARAM *pbe;
91 int saltlen, iter, ret; 91 int saltlen, iter, ret;
92 unsigned char *salt; 92 unsigned char *salt, *pbuf;
93 const unsigned char *pbuf;
94 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH]; 93 unsigned char key[EVP_MAX_KEY_LENGTH], iv[EVP_MAX_IV_LENGTH];
95 94
96 /* Extract useful info from parameter */ 95 /* Extract useful info from parameter */
97 if (param == NULL || param->type != V_ASN1_SEQUENCE ||
98 param->value.sequence == NULL) {
99 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_DECODE_ERROR);
100 return 0;
101 }
102
103 pbuf = param->value.sequence->data; 96 pbuf = param->value.sequence->data;
104 if (!(pbe = d2i_PBEPARAM(NULL, &pbuf, param->value.sequence->length))) { 97 if (!param || (param->type != V_ASN1_SEQUENCE) ||
105 PKCS12err(PKCS12_F_PKCS12_PBE_KEYIVGEN,PKCS12_R_DECODE_ERROR); 98 !(pbe = d2i_PBEPARAM (NULL, &pbuf, param->value.sequence->length))) {
99 EVPerr(PKCS12_F_PKCS12_PBE_KEYIVGEN,EVP_R_DECODE_ERROR);
106 return 0; 100 return 0;
107 } 101 }
108 102
diff --git a/src/lib/libcrypto/pkcs12/p12_crt.c b/src/lib/libcrypto/pkcs12/p12_crt.c
index dbafda17b6..40340a7bef 100644
--- a/src/lib/libcrypto/pkcs12/p12_crt.c
+++ b/src/lib/libcrypto/pkcs12/p12_crt.c
@@ -1,9 +1,9 @@
1/* p12_crt.c */ 1/* p12_crt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -60,289 +60,113 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/pkcs12.h> 61#include <openssl/pkcs12.h>
62 62
63
64static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag);
65
66PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, 63PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
67 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, int mac_iter, 64 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, int mac_iter,
68 int keytype) 65 int keytype)
69{ 66{
70 PKCS12 *p12 = NULL; 67 PKCS12 *p12;
71 STACK_OF(PKCS7) *safes = NULL; 68 STACK_OF(PKCS12_SAFEBAG) *bags;
72 STACK_OF(PKCS12_SAFEBAG) *bags = NULL; 69 STACK_OF(PKCS7) *safes;
73 PKCS12_SAFEBAG *bag = NULL; 70 PKCS12_SAFEBAG *bag;
71 PKCS8_PRIV_KEY_INFO *p8;
72 PKCS7 *authsafe;
73 X509 *tcert;
74 int i; 74 int i;
75 unsigned char keyid[EVP_MAX_MD_SIZE]; 75 unsigned char keyid[EVP_MAX_MD_SIZE];
76 unsigned int keyidlen = 0; 76 unsigned int keyidlen;
77 77
78 /* Set defaults */ 78 /* Set defaults */
79 if (!nid_cert) 79 if(!nid_cert)
80 nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
81 if (!nid_key)
82 nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
83 if (!iter)
84 iter = PKCS12_DEFAULT_ITER;
85 if (!mac_iter)
86 mac_iter = 1;
87
88 if(!pkey && !cert && !ca)
89 {
90 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
91 return NULL;
92 }
93
94 if (pkey && cert)
95 {
96 if(!X509_check_private_key(cert, pkey))
97 return NULL;
98 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
99 }
100
101 if (cert)
102 {
103 bag = PKCS12_add_cert(&bags, cert);
104 if(name && !PKCS12_add_friendlyname(bag, name, -1))
105 goto err;
106 if(keyidlen && !PKCS12_add_localkeyid(bag, keyid, keyidlen))
107 goto err;
108 }
109
110 /* Add all other certificates */
111 for(i = 0; i < sk_X509_num(ca); i++)
112 { 80 {
113 if (!PKCS12_add_cert(&bags, sk_X509_value(ca, i))) 81#ifdef OPENSSL_FIPS
114 goto err; 82 if (FIPS_mode())
115 } 83 nid_cert = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
116 84 else
117 if (bags && !PKCS12_add_safe(&safes, bags, nid_cert, iter, pass)) 85#endif
118 goto err; 86 nid_cert = NID_pbe_WithSHA1And40BitRC2_CBC;
119
120 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
121 bags = NULL;
122
123 if (pkey)
124 {
125 int cspidx;
126 bag = PKCS12_add_key(&bags, pkey, keytype, iter, nid_key, pass);
127
128 if (!bag)
129 goto err;
130
131 cspidx = EVP_PKEY_get_attr_by_NID(pkey, NID_ms_csp_name, -1);
132 if (cspidx >= 0)
133 {
134 X509_ATTRIBUTE *cspattr;
135 cspattr = EVP_PKEY_get_attr(pkey, cspidx);
136 if (!X509at_add1_attr(&bag->attrib, cspattr))
137 goto err;
138 }
139
140 if(name && !PKCS12_add_friendlyname(bag, name, -1))
141 goto err;
142 if(keyidlen && !PKCS12_add_localkeyid(bag, keyid, keyidlen))
143 goto err;
144 } 87 }
88 if(!nid_key) nid_key = NID_pbe_WithSHA1And3_Key_TripleDES_CBC;
89 if(!iter) iter = PKCS12_DEFAULT_ITER;
90 if(!mac_iter) mac_iter = 1;
145 91
146 if (bags && !PKCS12_add_safe(&safes, bags, -1, 0, NULL)) 92 if(!pkey || !cert) {
147 goto err; 93 PKCS12err(PKCS12_F_PKCS12_CREATE,PKCS12_R_INVALID_NULL_ARGUMENT);
148 94 return NULL;
149 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free); 95 }
150 bags = NULL;
151
152 p12 = PKCS12_add_safes(safes, 0);
153
154 sk_PKCS7_pop_free(safes, PKCS7_free);
155
156 safes = NULL;
157
158 if ((mac_iter != -1) &&
159 !PKCS12_set_mac(p12, pass, -1, NULL, 0, mac_iter, NULL))
160 goto err;
161
162 return p12;
163
164 err:
165
166 if (p12)
167 PKCS12_free(p12);
168 if (safes)
169 sk_PKCS7_pop_free(safes, PKCS7_free);
170 if (bags)
171 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
172 return NULL;
173 96
174} 97 if(!X509_check_private_key(cert, pkey)) return NULL;
175 98
176PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert) 99 if(!(bags = sk_PKCS12_SAFEBAG_new_null ())) {
177 { 100 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
178 PKCS12_SAFEBAG *bag = NULL; 101 return NULL;
179 char *name; 102 }
180 int namelen = -1;
181 unsigned char *keyid;
182 int keyidlen = -1;
183 103
184 /* Add user certificate */ 104 /* Add user certificate */
185 if(!(bag = PKCS12_x5092certbag(cert))) 105 if(!(bag = PKCS12_x5092certbag(cert))) return NULL;
186 goto err; 106 if(name && !PKCS12_add_friendlyname(bag, name, -1)) return NULL;
187 107 X509_digest(cert, EVP_sha1(), keyid, &keyidlen);
188 /* Use friendlyName and localKeyID in certificate. 108 if(!PKCS12_add_localkeyid(bag, keyid, keyidlen)) return NULL;
189 * (if present)
190 */
191
192 name = (char *)X509_alias_get0(cert, &namelen);
193
194 if(name && !PKCS12_add_friendlyname(bag, name, namelen))
195 goto err;
196
197 keyid = X509_keyid_get0(cert, &keyidlen);
198
199 if(keyid && !PKCS12_add_localkeyid(bag, keyid, keyidlen))
200 goto err;
201
202 if (!pkcs12_add_bag(pbags, bag))
203 goto err;
204
205 return bag;
206
207 err:
208
209 if (bag)
210 PKCS12_SAFEBAG_free(bag);
211
212 return NULL;
213 109
110 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
111 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
112 return NULL;
214 } 113 }
215 114
216PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key, 115 /* Add all other certificates */
217 int key_usage, int iter, 116 if(ca) {
218 int nid_key, char *pass) 117 for(i = 0; i < sk_X509_num(ca); i++) {
219 { 118 tcert = sk_X509_value(ca, i);
220 119 if(!(bag = PKCS12_x5092certbag(tcert))) return NULL;
221 PKCS12_SAFEBAG *bag = NULL; 120 if(!sk_PKCS12_SAFEBAG_push(bags, bag)) {
222 PKCS8_PRIV_KEY_INFO *p8 = NULL; 121 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
223 122 return NULL;
224 /* Make a PKCS#8 structure */ 123 }
225 if(!(p8 = EVP_PKEY2PKCS8(key)))
226 goto err;
227 if(key_usage && !PKCS8_add_keyusage(p8, key_usage))
228 goto err;
229 if (nid_key != -1)
230 {
231 bag = PKCS12_MAKE_SHKEYBAG(nid_key, pass, -1, NULL, 0, iter, p8);
232 PKCS8_PRIV_KEY_INFO_free(p8);
233 } 124 }
234 else
235 bag = PKCS12_MAKE_KEYBAG(p8);
236
237 if(!bag)
238 goto err;
239
240 if (!pkcs12_add_bag(pbags, bag))
241 goto err;
242
243 return bag;
244
245 err:
246
247 if (bag)
248 PKCS12_SAFEBAG_free(bag);
249
250 return NULL;
251
252 } 125 }
253 126
254int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags, 127 /* Turn certbags into encrypted authsafe */
255 int nid_safe, int iter, char *pass) 128 authsafe = PKCS12_pack_p7encdata (nid_cert, pass, -1, NULL, 0,
256 {
257 PKCS7 *p7 = NULL;
258 int free_safes = 0;
259
260 if (!*psafes)
261 {
262 *psafes = sk_PKCS7_new_null();
263 if (!*psafes)
264 return 0;
265 free_safes = 1;
266 }
267 else
268 free_safes = 0;
269
270 if (nid_safe == 0)
271 nid_safe = NID_pbe_WithSHA1And40BitRC2_CBC;
272
273 if (nid_safe == -1)
274 p7 = PKCS12_pack_p7data(bags);
275 else
276 p7 = PKCS12_pack_p7encdata(nid_safe, pass, -1, NULL, 0,
277 iter, bags); 129 iter, bags);
278 if (!p7) 130 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
279 goto err;
280
281 if (!sk_PKCS7_push(*psafes, p7))
282 goto err;
283
284 return 1;
285
286 err:
287 if (free_safes)
288 {
289 sk_PKCS7_free(*psafes);
290 *psafes = NULL;
291 }
292
293 if (p7)
294 PKCS7_free(p7);
295 131
296 return 0; 132 if (!authsafe) return NULL;
297 133
134 if(!(safes = sk_PKCS7_new_null ())
135 || !sk_PKCS7_push(safes, authsafe)) {
136 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
137 return NULL;
298 } 138 }
299 139
300static int pkcs12_add_bag(STACK_OF(PKCS12_SAFEBAG) **pbags, PKCS12_SAFEBAG *bag) 140 /* Make a shrouded key bag */
301 { 141 if(!(p8 = EVP_PKEY2PKCS8 (pkey))) return NULL;
302 int free_bags; 142 if(keytype && !PKCS8_add_keyusage(p8, keytype)) return NULL;
303 if (!pbags) 143 bag = PKCS12_MAKE_SHKEYBAG (nid_key, pass, -1, NULL, 0, iter, p8);
304 return 1; 144 if(!bag) return NULL;
305 if (!*pbags) 145 PKCS8_PRIV_KEY_INFO_free(p8);
306 { 146 if (name && !PKCS12_add_friendlyname (bag, name, -1)) return NULL;
307 *pbags = sk_PKCS12_SAFEBAG_new_null(); 147 if(!PKCS12_add_localkeyid (bag, keyid, keyidlen)) return NULL;
308 if (!*pbags) 148 if(!(bags = sk_PKCS12_SAFEBAG_new_null())
309 return 0; 149 || !sk_PKCS12_SAFEBAG_push (bags, bag)) {
310 free_bags = 1; 150 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
311 } 151 return NULL;
312 else 152 }
313 free_bags = 0; 153 /* Turn it into unencrypted safe bag */
314 154 if(!(authsafe = PKCS12_pack_p7data (bags))) return NULL;
315 if (!sk_PKCS12_SAFEBAG_push(*pbags, bag)) 155 sk_PKCS12_SAFEBAG_pop_free(bags, PKCS12_SAFEBAG_free);
316 { 156 if(!sk_PKCS7_push(safes, authsafe)) {
317 if (free_bags) 157 PKCS12err(PKCS12_F_PKCS12_CREATE,ERR_R_MALLOC_FAILURE);
318 { 158 return NULL;
319 sk_PKCS12_SAFEBAG_free(*pbags);
320 *pbags = NULL;
321 }
322 return 0;
323 }
324
325 return 1;
326
327 } 159 }
328
329 160
330PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int nid_p7) 161 if(!(p12 = PKCS12_init (NID_pkcs7_data))) return NULL;
331 {
332 PKCS12 *p12;
333 if (nid_p7 <= 0)
334 nid_p7 = NID_pkcs7_data;
335 p12 = PKCS12_init(nid_p7);
336 162
337 if (!p12) 163 if(!PKCS12_pack_authsafes (p12, safes)) return NULL;
338 return NULL;
339 164
340 if(!PKCS12_pack_authsafes(p12, safes)) 165 sk_PKCS7_pop_free(safes, PKCS7_free);
341 { 166
342 PKCS12_free(p12); 167 if(!PKCS12_set_mac (p12, pass, -1, NULL, 0, mac_iter, NULL))
343 return NULL; 168 return NULL;
344 }
345 169
346 return p12; 170 return p12;
347 171
348 } 172}
diff --git a/src/lib/libcrypto/pkcs12/p12_decr.c b/src/lib/libcrypto/pkcs12/p12_decr.c
index 74c961a92b..b5684a83ba 100644
--- a/src/lib/libcrypto/pkcs12/p12_decr.c
+++ b/src/lib/libcrypto/pkcs12/p12_decr.c
@@ -113,14 +113,13 @@ unsigned char * PKCS12_pbe_crypt(X509_ALGOR *algor, const char *pass,
113void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it, 113void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
114 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf) 114 const char *pass, int passlen, ASN1_OCTET_STRING *oct, int zbuf)
115{ 115{
116 unsigned char *out; 116 unsigned char *out, *p;
117 const unsigned char *p;
118 void *ret; 117 void *ret;
119 int outlen; 118 int outlen;
120 119
121 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length, 120 if (!PKCS12_pbe_crypt(algor, pass, passlen, oct->data, oct->length,
122 &out, &outlen, 0)) { 121 &out, &outlen, 0)) {
123 PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR); 122 PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_PKCS12_PBE_CRYPT_ERROR);
124 return NULL; 123 return NULL;
125 } 124 }
126 p = out; 125 p = out;
@@ -138,7 +137,7 @@ void * PKCS12_item_decrypt_d2i(X509_ALGOR *algor, const ASN1_ITEM *it,
138#endif 137#endif
139 ret = ASN1_item_d2i(NULL, &p, outlen, it); 138 ret = ASN1_item_d2i(NULL, &p, outlen, it);
140 if (zbuf) OPENSSL_cleanse(out, outlen); 139 if (zbuf) OPENSSL_cleanse(out, outlen);
141 if(!ret) PKCS12err(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I,PKCS12_R_DECODE_ERROR); 140 if(!ret) PKCS12err(PKCS12_F_PKCS12_DECRYPT_D2I,PKCS12_R_DECODE_ERROR);
142 OPENSSL_free(out); 141 OPENSSL_free(out);
143 return ret; 142 return ret;
144} 143}
@@ -155,17 +154,17 @@ ASN1_OCTET_STRING *PKCS12_item_i2d_encrypt(X509_ALGOR *algor, const ASN1_ITEM *i
155 unsigned char *in = NULL; 154 unsigned char *in = NULL;
156 int inlen; 155 int inlen;
157 if (!(oct = M_ASN1_OCTET_STRING_new ())) { 156 if (!(oct = M_ASN1_OCTET_STRING_new ())) {
158 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE); 157 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,ERR_R_MALLOC_FAILURE);
159 return NULL; 158 return NULL;
160 } 159 }
161 inlen = ASN1_item_i2d(obj, &in, it); 160 inlen = ASN1_item_i2d(obj, &in, it);
162 if (!in) { 161 if (!in) {
163 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR); 162 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCODE_ERROR);
164 return NULL; 163 return NULL;
165 } 164 }
166 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data, 165 if (!PKCS12_pbe_crypt(algor, pass, passlen, in, inlen, &oct->data,
167 &oct->length, 1)) { 166 &oct->length, 1)) {
168 PKCS12err(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR); 167 PKCS12err(PKCS12_F_PKCS12_I2D_ENCRYPT,PKCS12_R_ENCRYPT_ERROR);
169 OPENSSL_free(in); 168 OPENSSL_free(in);
170 return NULL; 169 return NULL;
171 } 170 }
diff --git a/src/lib/libcrypto/pkcs12/p12_init.c b/src/lib/libcrypto/pkcs12/p12_init.c
index 6bdc132631..5276b12669 100644
--- a/src/lib/libcrypto/pkcs12/p12_init.c
+++ b/src/lib/libcrypto/pkcs12/p12_init.c
@@ -62,7 +62,7 @@
62 62
63/* Initialise a PKCS12 structure to take data */ 63/* Initialise a PKCS12 structure to take data */
64 64
65PKCS12 *PKCS12_init(int mode) 65PKCS12 *PKCS12_init (int mode)
66{ 66{
67 PKCS12 *pkcs12; 67 PKCS12 *pkcs12;
68 if (!(pkcs12 = PKCS12_new())) { 68 if (!(pkcs12 = PKCS12_new())) {
diff --git a/src/lib/libcrypto/pkcs12/p12_key.c b/src/lib/libcrypto/pkcs12/p12_key.c
index 18e72d0a1b..9196a34b4a 100644
--- a/src/lib/libcrypto/pkcs12/p12_key.c
+++ b/src/lib/libcrypto/pkcs12/p12_key.c
@@ -59,7 +59,7 @@
59#include <stdio.h> 59#include <stdio.h>
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/pkcs12.h> 61#include <openssl/pkcs12.h>
62#include <openssl/bn.h> 62
63 63
64/* Uncomment out this line to get debugging info about key generation */ 64/* Uncomment out this line to get debugging info about key generation */
65/*#define DEBUG_KEYGEN*/ 65/*#define DEBUG_KEYGEN*/
diff --git a/src/lib/libcrypto/pkcs12/p12_kiss.c b/src/lib/libcrypto/pkcs12/p12_kiss.c
index c2ee2cc6f3..2b31999e11 100644
--- a/src/lib/libcrypto/pkcs12/p12_kiss.c
+++ b/src/lib/libcrypto/pkcs12/p12_kiss.c
@@ -80,7 +80,7 @@ static int parse_bag( PKCS12_SAFEBAG *bag, const char *pass, int passlen,
80 * passed unitialised. 80 * passed unitialised.
81 */ 81 */
82 82
83int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert, 83int PKCS12_parse (PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
84 STACK_OF(X509) **ca) 84 STACK_OF(X509) **ca)
85{ 85{
86 86
@@ -141,7 +141,7 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
141 141
142/* Parse the outer PKCS#12 structure */ 142/* Parse the outer PKCS#12 structure */
143 143
144static int parse_pk12(PKCS12 *p12, const char *pass, int passlen, 144static int parse_pk12 (PKCS12 *p12, const char *pass, int passlen,
145 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca) 145 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca)
146{ 146{
147 STACK_OF(PKCS7) *asafes; 147 STACK_OF(PKCS7) *asafes;
@@ -178,10 +178,10 @@ static int parse_pk12(PKCS12 *p12, const char *pass, int passlen,
178} 178}
179 179
180 180
181static int parse_bags(STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass, 181static int parse_bags (STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
182 int passlen, EVP_PKEY **pkey, X509 **cert, 182 int passlen, EVP_PKEY **pkey, X509 **cert,
183 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid, 183 STACK_OF(X509) **ca, ASN1_OCTET_STRING **keyid,
184 char *keymatch) 184 char *keymatch)
185{ 185{
186 int i; 186 int i;
187 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) { 187 for (i = 0; i < sk_PKCS12_SAFEBAG_num(bags); i++) {
@@ -197,9 +197,9 @@ static int parse_bags(STACK_OF(PKCS12_SAFEBAG) *bags, const char *pass,
197#define MATCH_ALL 0x3 197#define MATCH_ALL 0x3
198 198
199static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen, 199static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
200 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca, 200 EVP_PKEY **pkey, X509 **cert, STACK_OF(X509) **ca,
201 ASN1_OCTET_STRING **keyid, 201 ASN1_OCTET_STRING **keyid,
202 char *keymatch) 202 char *keymatch)
203{ 203{
204 PKCS8_PRIV_KEY_INFO *p8; 204 PKCS8_PRIV_KEY_INFO *p8;
205 X509 *x509; 205 X509 *x509;
@@ -221,7 +221,7 @@ static int parse_bag(PKCS12_SAFEBAG *bag, const char *pass, int passlen,
221 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL; 221 if (M_ASN1_OCTET_STRING_cmp(*keyid, lkey)) lkey = NULL;
222 } else { 222 } else {
223 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) { 223 if (!(*keyid = M_ASN1_OCTET_STRING_dup(lkey))) {
224 PKCS12err(PKCS12_F_PARSE_BAG,ERR_R_MALLOC_FAILURE); 224 PKCS12err(PKCS12_F_PARSE_BAGS,ERR_R_MALLOC_FAILURE);
225 return 0; 225 return 0;
226 } 226 }
227 } 227 }
diff --git a/src/lib/libcrypto/pkcs12/p12_mutl.c b/src/lib/libcrypto/pkcs12/p12_mutl.c
index c408cc8ab8..140d21155e 100644
--- a/src/lib/libcrypto/pkcs12/p12_mutl.c
+++ b/src/lib/libcrypto/pkcs12/p12_mutl.c
@@ -64,12 +64,12 @@
64#include <openssl/pkcs12.h> 64#include <openssl/pkcs12.h>
65 65
66/* Generate a MAC */ 66/* Generate a MAC */
67int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen, 67int PKCS12_gen_mac (PKCS12 *p12, const char *pass, int passlen,
68 unsigned char *mac, unsigned int *maclen) 68 unsigned char *mac, unsigned int *maclen)
69{ 69{
70 const EVP_MD *md_type; 70 const EVP_MD *md_type;
71 HMAC_CTX hmac; 71 HMAC_CTX hmac;
72 unsigned char key[EVP_MAX_MD_SIZE], *salt; 72 unsigned char key[PKCS12_MAC_KEY_LENGTH], *salt;
73 int saltlen, iter; 73 int saltlen, iter;
74 74
75 if (!PKCS7_type_is_data(p12->authsafes)) 75 if (!PKCS7_type_is_data(p12->authsafes))
@@ -88,12 +88,12 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
88 return 0; 88 return 0;
89 } 89 }
90 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter, 90 if(!PKCS12_key_gen (pass, passlen, salt, saltlen, PKCS12_MAC_ID, iter,
91 EVP_MD_size(md_type), key, md_type)) { 91 PKCS12_MAC_KEY_LENGTH, key, md_type)) {
92 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR); 92 PKCS12err(PKCS12_F_PKCS12_GEN_MAC,PKCS12_R_KEY_GEN_ERROR);
93 return 0; 93 return 0;
94 } 94 }
95 HMAC_CTX_init(&hmac); 95 HMAC_CTX_init(&hmac);
96 HMAC_Init_ex(&hmac, key, EVP_MD_size(md_type), md_type, NULL); 96 HMAC_Init_ex(&hmac, key, PKCS12_MAC_KEY_LENGTH, md_type, NULL);
97 HMAC_Update(&hmac, p12->authsafes->d.data->data, 97 HMAC_Update(&hmac, p12->authsafes->d.data->data,
98 p12->authsafes->d.data->length); 98 p12->authsafes->d.data->length);
99 HMAC_Final(&hmac, mac, maclen); 99 HMAC_Final(&hmac, mac, maclen);
@@ -102,16 +102,16 @@ int PKCS12_gen_mac(PKCS12 *p12, const char *pass, int passlen,
102} 102}
103 103
104/* Verify the mac */ 104/* Verify the mac */
105int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen) 105int PKCS12_verify_mac (PKCS12 *p12, const char *pass, int passlen)
106{ 106{
107 unsigned char mac[EVP_MAX_MD_SIZE]; 107 unsigned char mac[EVP_MAX_MD_SIZE];
108 unsigned int maclen; 108 unsigned int maclen;
109 if(p12->mac == NULL) { 109 if(p12->mac == NULL) {
110 PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC,PKCS12_R_MAC_ABSENT); 110 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_ABSENT);
111 return 0; 111 return 0;
112 } 112 }
113 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) { 113 if (!PKCS12_gen_mac (p12, pass, passlen, mac, &maclen)) {
114 PKCS12err(PKCS12_F_PKCS12_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR); 114 PKCS12err(PKCS12_F_VERIFY_MAC,PKCS12_R_MAC_GENERATION_ERROR);
115 return 0; 115 return 0;
116 } 116 }
117 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length) 117 if ((maclen != (unsigned int)p12->mac->dinfo->digest->length)
@@ -121,7 +121,7 @@ int PKCS12_verify_mac(PKCS12 *p12, const char *pass, int passlen)
121 121
122/* Set a mac */ 122/* Set a mac */
123 123
124int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen, 124int PKCS12_set_mac (PKCS12 *p12, const char *pass, int passlen,
125 unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type) 125 unsigned char *salt, int saltlen, int iter, const EVP_MD *md_type)
126{ 126{
127 unsigned char mac[EVP_MAX_MD_SIZE]; 127 unsigned char mac[EVP_MAX_MD_SIZE];
@@ -145,7 +145,7 @@ int PKCS12_set_mac(PKCS12 *p12, const char *pass, int passlen,
145} 145}
146 146
147/* Set up a mac structure */ 147/* Set up a mac structure */
148int PKCS12_setup_mac(PKCS12 *p12, int iter, unsigned char *salt, int saltlen, 148int PKCS12_setup_mac (PKCS12 *p12, int iter, unsigned char *salt, int saltlen,
149 const EVP_MD *md_type) 149 const EVP_MD *md_type)
150{ 150{
151 if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR; 151 if (!(p12->mac = PKCS12_MAC_DATA_new())) return PKCS12_ERROR;
diff --git a/src/lib/libcrypto/pkcs12/p12_npas.c b/src/lib/libcrypto/pkcs12/p12_npas.c
index 48eacc5c49..af708a2743 100644
--- a/src/lib/libcrypto/pkcs12/p12_npas.c
+++ b/src/lib/libcrypto/pkcs12/p12_npas.c
@@ -77,26 +77,28 @@ static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen);
77 77
78int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass) 78int PKCS12_newpass(PKCS12 *p12, char *oldpass, char *newpass)
79{ 79{
80 /* Check for NULL PKCS12 structure */
81 80
82 if(!p12) { 81/* Check for NULL PKCS12 structure */
83 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
84 return 0;
85 }
86 82
87 /* Check the mac */ 83if(!p12) {
88 84 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_INVALID_NULL_PKCS12_POINTER);
89 if (!PKCS12_verify_mac(p12, oldpass, -1)) { 85 return 0;
90 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE); 86}
91 return 0;
92 }
93 87
94 if (!newpass_p12(p12, oldpass, newpass)) { 88/* Check the mac */
95 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR); 89
96 return 0; 90if (!PKCS12_verify_mac(p12, oldpass, -1)) {
97 } 91 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_MAC_VERIFY_FAILURE);
92 return 0;
93}
94
95if (!newpass_p12(p12, oldpass, newpass)) {
96 PKCS12err(PKCS12_F_PKCS12_NEWPASS,PKCS12_R_PARSE_ERROR);
97 return 0;
98}
99
100return 1;
98 101
99 return 1;
100} 102}
101 103
102/* Parse the outer PKCS#12 structure */ 104/* Parse the outer PKCS#12 structure */
@@ -204,8 +206,7 @@ static int newpass_bag(PKCS12_SAFEBAG *bag, char *oldpass, char *newpass)
204static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen) 206static int alg_get(X509_ALGOR *alg, int *pnid, int *piter, int *psaltlen)
205{ 207{
206 PBEPARAM *pbe; 208 PBEPARAM *pbe;
207 const unsigned char *p; 209 unsigned char *p;
208
209 p = alg->parameter->value.sequence->data; 210 p = alg->parameter->value.sequence->data;
210 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length); 211 pbe = d2i_PBEPARAM(NULL, &p, alg->parameter->value.sequence->length);
211 *pnid = OBJ_obj2nid(alg->algorithm); 212 *pnid = OBJ_obj2nid(alg->algorithm);
diff --git a/src/lib/libcrypto/pkcs12/pk12err.c b/src/lib/libcrypto/pkcs12/pk12err.c
index 07a1fb6907..a33b37b1c7 100644
--- a/src/lib/libcrypto/pkcs12/pk12err.c
+++ b/src/lib/libcrypto/pkcs12/pk12err.c
@@ -70,18 +70,16 @@
70 70
71static ERR_STRING_DATA PKCS12_str_functs[]= 71static ERR_STRING_DATA PKCS12_str_functs[]=
72 { 72 {
73{ERR_FUNC(PKCS12_F_PARSE_BAG), "PARSE_BAG"},
74{ERR_FUNC(PKCS12_F_PARSE_BAGS), "PARSE_BAGS"}, 73{ERR_FUNC(PKCS12_F_PARSE_BAGS), "PARSE_BAGS"},
75{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME), "PKCS12_ADD_FRIENDLYNAME"}, 74{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME), "PKCS12_ADD_FRIENDLYNAME"},
76{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC), "PKCS12_add_friendlyname_asc"}, 75{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC), "PKCS12_add_friendlyname_asc"},
77{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI), "PKCS12_add_friendlyname_uni"}, 76{ERR_FUNC(PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI), "PKCS12_add_friendlyname_uni"},
78{ERR_FUNC(PKCS12_F_PKCS12_ADD_LOCALKEYID), "PKCS12_add_localkeyid"}, 77{ERR_FUNC(PKCS12_F_PKCS12_ADD_LOCALKEYID), "PKCS12_add_localkeyid"},
79{ERR_FUNC(PKCS12_F_PKCS12_CREATE), "PKCS12_create"}, 78{ERR_FUNC(PKCS12_F_PKCS12_CREATE), "PKCS12_create"},
79{ERR_FUNC(PKCS12_F_PKCS12_DECRYPT_D2I), "PKCS12_DECRYPT_D2I"},
80{ERR_FUNC(PKCS12_F_PKCS12_GEN_MAC), "PKCS12_gen_mac"}, 80{ERR_FUNC(PKCS12_F_PKCS12_GEN_MAC), "PKCS12_gen_mac"},
81{ERR_FUNC(PKCS12_F_PKCS12_I2D_ENCRYPT), "PKCS12_I2D_ENCRYPT"},
81{ERR_FUNC(PKCS12_F_PKCS12_INIT), "PKCS12_init"}, 82{ERR_FUNC(PKCS12_F_PKCS12_INIT), "PKCS12_init"},
82{ERR_FUNC(PKCS12_F_PKCS12_ITEM_DECRYPT_D2I), "PKCS12_item_decrypt_d2i"},
83{ERR_FUNC(PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT), "PKCS12_item_i2d_encrypt"},
84{ERR_FUNC(PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG), "PKCS12_item_pack_safebag"},
85{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_ASC), "PKCS12_key_gen_asc"}, 83{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_ASC), "PKCS12_key_gen_asc"},
86{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_UNI), "PKCS12_key_gen_uni"}, 84{ERR_FUNC(PKCS12_F_PKCS12_KEY_GEN_UNI), "PKCS12_key_gen_uni"},
87{ERR_FUNC(PKCS12_F_PKCS12_MAKE_KEYBAG), "PKCS12_MAKE_KEYBAG"}, 85{ERR_FUNC(PKCS12_F_PKCS12_MAKE_KEYBAG), "PKCS12_MAKE_KEYBAG"},
@@ -89,6 +87,7 @@ static ERR_STRING_DATA PKCS12_str_functs[]=
89{ERR_FUNC(PKCS12_F_PKCS12_NEWPASS), "PKCS12_newpass"}, 87{ERR_FUNC(PKCS12_F_PKCS12_NEWPASS), "PKCS12_newpass"},
90{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7DATA), "PKCS12_pack_p7data"}, 88{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7DATA), "PKCS12_pack_p7data"},
91{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7ENCDATA), "PKCS12_pack_p7encdata"}, 89{ERR_FUNC(PKCS12_F_PKCS12_PACK_P7ENCDATA), "PKCS12_pack_p7encdata"},
90{ERR_FUNC(PKCS12_F_PKCS12_PACK_SAFEBAG), "PKCS12_PACK_SAFEBAG"},
92{ERR_FUNC(PKCS12_F_PKCS12_PARSE), "PKCS12_parse"}, 91{ERR_FUNC(PKCS12_F_PKCS12_PARSE), "PKCS12_parse"},
93{ERR_FUNC(PKCS12_F_PKCS12_PBE_CRYPT), "PKCS12_pbe_crypt"}, 92{ERR_FUNC(PKCS12_F_PKCS12_PBE_CRYPT), "PKCS12_pbe_crypt"},
94{ERR_FUNC(PKCS12_F_PKCS12_PBE_KEYIVGEN), "PKCS12_PBE_keyivgen"}, 93{ERR_FUNC(PKCS12_F_PKCS12_PBE_KEYIVGEN), "PKCS12_PBE_keyivgen"},
@@ -96,9 +95,9 @@ static ERR_STRING_DATA PKCS12_str_functs[]=
96{ERR_FUNC(PKCS12_F_PKCS12_SET_MAC), "PKCS12_set_mac"}, 95{ERR_FUNC(PKCS12_F_PKCS12_SET_MAC), "PKCS12_set_mac"},
97{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_AUTHSAFES), "PKCS12_unpack_authsafes"}, 96{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_AUTHSAFES), "PKCS12_unpack_authsafes"},
98{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_P7DATA), "PKCS12_unpack_p7data"}, 97{ERR_FUNC(PKCS12_F_PKCS12_UNPACK_P7DATA), "PKCS12_unpack_p7data"},
99{ERR_FUNC(PKCS12_F_PKCS12_VERIFY_MAC), "PKCS12_verify_mac"},
100{ERR_FUNC(PKCS12_F_PKCS8_ADD_KEYUSAGE), "PKCS8_add_keyusage"}, 98{ERR_FUNC(PKCS12_F_PKCS8_ADD_KEYUSAGE), "PKCS8_add_keyusage"},
101{ERR_FUNC(PKCS12_F_PKCS8_ENCRYPT), "PKCS8_encrypt"}, 99{ERR_FUNC(PKCS12_F_PKCS8_ENCRYPT), "PKCS8_encrypt"},
100{ERR_FUNC(PKCS12_F_VERIFY_MAC), "VERIFY_MAC"},
102{0,NULL} 101{0,NULL}
103 }; 102 };
104 103
@@ -133,12 +132,15 @@ static ERR_STRING_DATA PKCS12_str_reasons[]=
133 132
134void ERR_load_PKCS12_strings(void) 133void ERR_load_PKCS12_strings(void)
135 { 134 {
136#ifndef OPENSSL_NO_ERR 135 static int init=1;
137 136
138 if (ERR_func_error_string(PKCS12_str_functs[0].error) == NULL) 137 if (init)
139 { 138 {
139 init=0;
140#ifndef OPENSSL_NO_ERR
140 ERR_load_strings(0,PKCS12_str_functs); 141 ERR_load_strings(0,PKCS12_str_functs);
141 ERR_load_strings(0,PKCS12_str_reasons); 142 ERR_load_strings(0,PKCS12_str_reasons);
142 }
143#endif 143#endif
144
145 }
144 } 146 }
diff --git a/src/lib/libcrypto/pkcs12/pkcs12.h b/src/lib/libcrypto/pkcs12/pkcs12.h
index a2d7e359a0..fb8af82d4f 100644
--- a/src/lib/libcrypto/pkcs12/pkcs12.h
+++ b/src/lib/libcrypto/pkcs12/pkcs12.h
@@ -249,15 +249,6 @@ int PKCS12_parse(PKCS12 *p12, const char *pass, EVP_PKEY **pkey, X509 **cert,
249PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert, 249PKCS12 *PKCS12_create(char *pass, char *name, EVP_PKEY *pkey, X509 *cert,
250 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter, 250 STACK_OF(X509) *ca, int nid_key, int nid_cert, int iter,
251 int mac_iter, int keytype); 251 int mac_iter, int keytype);
252
253PKCS12_SAFEBAG *PKCS12_add_cert(STACK_OF(PKCS12_SAFEBAG) **pbags, X509 *cert);
254PKCS12_SAFEBAG *PKCS12_add_key(STACK_OF(PKCS12_SAFEBAG) **pbags, EVP_PKEY *key,
255 int key_usage, int iter,
256 int key_nid, char *pass);
257int PKCS12_add_safe(STACK_OF(PKCS7) **psafes, STACK_OF(PKCS12_SAFEBAG) *bags,
258 int safe_nid, int iter, char *pass);
259PKCS12 *PKCS12_add_safes(STACK_OF(PKCS7) *safes, int p7_nid);
260
261int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12); 252int i2d_PKCS12_bio(BIO *bp, PKCS12 *p12);
262int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12); 253int i2d_PKCS12_fp(FILE *fp, PKCS12 *p12);
263PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12); 254PKCS12 *d2i_PKCS12_bio(BIO *bp, PKCS12 **p12);
@@ -273,18 +264,16 @@ void ERR_load_PKCS12_strings(void);
273/* Error codes for the PKCS12 functions. */ 264/* Error codes for the PKCS12 functions. */
274 265
275/* Function codes. */ 266/* Function codes. */
276#define PKCS12_F_PARSE_BAG 129
277#define PKCS12_F_PARSE_BAGS 103 267#define PKCS12_F_PARSE_BAGS 103
278#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100 268#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME 100
279#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127 269#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_ASC 127
280#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102 270#define PKCS12_F_PKCS12_ADD_FRIENDLYNAME_UNI 102
281#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104 271#define PKCS12_F_PKCS12_ADD_LOCALKEYID 104
282#define PKCS12_F_PKCS12_CREATE 105 272#define PKCS12_F_PKCS12_CREATE 105
273#define PKCS12_F_PKCS12_DECRYPT_D2I 106
283#define PKCS12_F_PKCS12_GEN_MAC 107 274#define PKCS12_F_PKCS12_GEN_MAC 107
275#define PKCS12_F_PKCS12_I2D_ENCRYPT 108
284#define PKCS12_F_PKCS12_INIT 109 276#define PKCS12_F_PKCS12_INIT 109
285#define PKCS12_F_PKCS12_ITEM_DECRYPT_D2I 106
286#define PKCS12_F_PKCS12_ITEM_I2D_ENCRYPT 108
287#define PKCS12_F_PKCS12_ITEM_PACK_SAFEBAG 117
288#define PKCS12_F_PKCS12_KEY_GEN_ASC 110 277#define PKCS12_F_PKCS12_KEY_GEN_ASC 110
289#define PKCS12_F_PKCS12_KEY_GEN_UNI 111 278#define PKCS12_F_PKCS12_KEY_GEN_UNI 111
290#define PKCS12_F_PKCS12_MAKE_KEYBAG 112 279#define PKCS12_F_PKCS12_MAKE_KEYBAG 112
@@ -292,16 +281,17 @@ void ERR_load_PKCS12_strings(void);
292#define PKCS12_F_PKCS12_NEWPASS 128 281#define PKCS12_F_PKCS12_NEWPASS 128
293#define PKCS12_F_PKCS12_PACK_P7DATA 114 282#define PKCS12_F_PKCS12_PACK_P7DATA 114
294#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115 283#define PKCS12_F_PKCS12_PACK_P7ENCDATA 115
284#define PKCS12_F_PKCS12_PACK_SAFEBAG 117
295#define PKCS12_F_PKCS12_PARSE 118 285#define PKCS12_F_PKCS12_PARSE 118
296#define PKCS12_F_PKCS12_PBE_CRYPT 119 286#define PKCS12_F_PKCS12_PBE_CRYPT 119
297#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120 287#define PKCS12_F_PKCS12_PBE_KEYIVGEN 120
298#define PKCS12_F_PKCS12_SETUP_MAC 122 288#define PKCS12_F_PKCS12_SETUP_MAC 122
299#define PKCS12_F_PKCS12_SET_MAC 123 289#define PKCS12_F_PKCS12_SET_MAC 123
300#define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 130 290#define PKCS12_F_PKCS12_UNPACK_AUTHSAFES 129
301#define PKCS12_F_PKCS12_UNPACK_P7DATA 131 291#define PKCS12_F_PKCS12_UNPACK_P7DATA 130
302#define PKCS12_F_PKCS12_VERIFY_MAC 126
303#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124 292#define PKCS12_F_PKCS8_ADD_KEYUSAGE 124
304#define PKCS12_F_PKCS8_ENCRYPT 125 293#define PKCS12_F_PKCS8_ENCRYPT 125
294#define PKCS12_F_VERIFY_MAC 126
305 295
306/* Reason codes. */ 296/* Reason codes. */
307#define PKCS12_R_CANT_PACK_STRUCTURE 100 297#define PKCS12_R_CANT_PACK_STRUCTURE 100
diff --git a/src/lib/libcrypto/pkcs7/Makefile b/src/lib/libcrypto/pkcs7/Makefile
new file mode 100644
index 0000000000..3f7e88b40f
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/Makefile
@@ -0,0 +1,187 @@
1#
2# OpenSSL/crypto/pkcs7/Makefile
3#
4
5DIR= pkcs7
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13PEX_LIBS=
14EX_LIBS=
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17
18GENERAL=Makefile README
19TEST=
20APPS=
21
22LIB=$(TOP)/libcrypto.a
23LIBSRC= pk7_asn1.c pk7_lib.c pkcs7err.c pk7_doit.c pk7_smime.c pk7_attr.c \
24 pk7_mime.c
25LIBOBJ= pk7_asn1.o pk7_lib.o pkcs7err.o pk7_doit.o pk7_smime.o pk7_attr.o \
26 pk7_mime.o
27
28SRC= $(LIBSRC)
29
30EXHEADER= pkcs7.h
31HEADER= $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38test:
39
40all: lib
41
42testapps: enc dec sign verify
43
44enc: enc.o lib
45 $(CC) $(CFLAGS) -o enc enc.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
46
47dec: dec.o lib
48 $(CC) $(CFLAGS) -o dec dec.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
49
50sign: sign.o lib
51 $(CC) $(CFLAGS) -o sign sign.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
52
53verify: verify.o example.o lib
54 $(CC) $(CFLAGS) -o verify verify.o $(PEX_LIBS) example.o $(LIB) $(EX_LIBS)
55
56lib: $(LIBOBJ)
57 $(AR) $(LIB) $(LIBOBJ)
58 $(RANLIB) $(LIB) || echo Never mind.
59 @touch lib
60
61files:
62 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
63
64links:
65 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
66 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
67 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
68
69install:
70 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
71 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
72 do \
73 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
74 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
75 done;
76
77tags:
78 ctags $(SRC)
79
80tests:
81
82lint:
83 lint -DLINT $(INCLUDES) $(SRC)>fluff
84
85depend:
86 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
87 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
88
89dclean:
90 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
91 mv -f Makefile.new $(MAKEFILE)
92
93clean:
94 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff enc dec sign verify
95
96# DO NOT DELETE THIS LINE -- make depend depends on it.
97
98pk7_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
99pk7_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
100pk7_asn1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101pk7_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
102pk7_asn1.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
103pk7_asn1.o: ../../include/openssl/err.h ../../include/openssl/evp.h
104pk7_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
105pk7_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
106pk7_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
107pk7_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
108pk7_asn1.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
109pk7_asn1.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
110pk7_asn1.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pk7_asn1.c
111pk7_attr.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
112pk7_attr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
113pk7_attr.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
114pk7_attr.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
115pk7_attr.o: ../../include/openssl/err.h ../../include/openssl/evp.h
116pk7_attr.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
117pk7_attr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
118pk7_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
119pk7_attr.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
120pk7_attr.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
121pk7_attr.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
122pk7_attr.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
123pk7_attr.o: ../../include/openssl/x509_vfy.h pk7_attr.c
124pk7_doit.o: ../../e_os.h ../../include/openssl/asn1.h
125pk7_doit.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
126pk7_doit.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
127pk7_doit.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
128pk7_doit.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
129pk7_doit.o: ../../include/openssl/err.h ../../include/openssl/evp.h
130pk7_doit.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
131pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
132pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
133pk7_doit.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
134pk7_doit.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
135pk7_doit.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
136pk7_doit.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
137pk7_doit.o: ../../include/openssl/x509v3.h ../cryptlib.h pk7_doit.c
138pk7_lib.o: ../../e_os.h ../../include/openssl/asn1.h
139pk7_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
140pk7_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
141pk7_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
142pk7_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
143pk7_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
144pk7_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
145pk7_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
146pk7_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
147pk7_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
148pk7_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
149pk7_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
150pk7_lib.o: ../cryptlib.h pk7_lib.c
151pk7_mime.o: ../../e_os.h ../../include/openssl/asn1.h
152pk7_mime.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
153pk7_mime.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
154pk7_mime.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
155pk7_mime.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
156pk7_mime.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
157pk7_mime.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
158pk7_mime.o: ../../include/openssl/opensslconf.h
159pk7_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
160pk7_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
161pk7_mime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
162pk7_mime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
163pk7_mime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
164pk7_mime.o: ../cryptlib.h pk7_mime.c
165pk7_smime.o: ../../e_os.h ../../include/openssl/asn1.h
166pk7_smime.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
167pk7_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
168pk7_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
169pk7_smime.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
170pk7_smime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
171pk7_smime.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
172pk7_smime.o: ../../include/openssl/objects.h
173pk7_smime.o: ../../include/openssl/opensslconf.h
174pk7_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
175pk7_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
176pk7_smime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
177pk7_smime.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
178pk7_smime.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
179pk7_smime.o: ../cryptlib.h pk7_smime.c
180pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
181pkcs7err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
182pkcs7err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
183pkcs7err.o: ../../include/openssl/opensslconf.h
184pkcs7err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
185pkcs7err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
186pkcs7err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
187pkcs7err.o: pkcs7err.c
diff --git a/src/lib/libcrypto/pkcs7/Makefile.ssl b/src/lib/libcrypto/pkcs7/Makefile.ssl
new file mode 100644
index 0000000000..c3bfc7d560
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/Makefile.ssl
@@ -0,0 +1,243 @@
1#
2# SSLeay/crypto/pkcs7/Makefile
3#
4
5DIR= pkcs7
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19PEX_LIBS=
20EX_LIBS=
21
22CFLAGS= $(INCLUDES) $(CFLAG)
23
24GENERAL=Makefile README
25TEST=
26APPS=
27
28LIB=$(TOP)/libcrypto.a
29LIBSRC= pk7_asn1.c pk7_lib.c pkcs7err.c pk7_doit.c pk7_smime.c pk7_attr.c \
30 pk7_mime.c
31LIBOBJ= pk7_asn1.o pk7_lib.o pkcs7err.o pk7_doit.o pk7_smime.o pk7_attr.o \
32 pk7_mime.o
33
34SRC= $(LIBSRC)
35
36EXHEADER= pkcs7.h
37HEADER= $(EXHEADER)
38
39ALL= $(GENERAL) $(SRC) $(HEADER)
40
41top:
42 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
43
44test:
45
46all: lib
47
48testapps: enc dec sign verify
49
50enc: enc.o lib
51 $(CC) $(CFLAGS) -o enc enc.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
52
53dec: dec.o lib
54 $(CC) $(CFLAGS) -o dec dec.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
55
56sign: sign.o lib
57 $(CC) $(CFLAGS) -o sign sign.o $(PEX_LIBS) $(LIB) $(EX_LIBS)
58
59verify: verify.o example.o lib
60 $(CC) $(CFLAGS) -o verify verify.o $(PEX_LIBS) example.o $(LIB) $(EX_LIBS)
61
62lib: $(LIBOBJ)
63 $(AR) $(LIB) $(LIBOBJ)
64 $(RANLIB) $(LIB) || echo Never mind.
65 @touch lib
66
67files:
68 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69
70links:
71 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
72 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
73 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
74 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75
76install:
77 @for i in $(EXHEADER) ; \
78 do \
79 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
80 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
81 done;
82
83tags:
84 ctags $(SRC)
85
86tests:
87
88lint:
89 lint -DLINT $(INCLUDES) $(SRC)>fluff
90
91depend:
92 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
93
94dclean:
95 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
96 mv -f Makefile.new $(MAKEFILE)
97
98clean:
99 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff enc dec sign verify
100
101# DO NOT DELETE THIS LINE -- make depend depends on it.
102
103pk7_asn1.o: ../../e_os.h ../../include/openssl/aes.h
104pk7_asn1.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
105pk7_asn1.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
106pk7_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
107pk7_asn1.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
108pk7_asn1.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
109pk7_asn1.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
110pk7_asn1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
111pk7_asn1.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
112pk7_asn1.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
113pk7_asn1.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
114pk7_asn1.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
115pk7_asn1.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
116pk7_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
117pk7_asn1.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
118pk7_asn1.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
119pk7_asn1.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
120pk7_asn1.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
121pk7_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
122pk7_asn1.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
123pk7_asn1.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
124pk7_asn1.o: ../cryptlib.h pk7_asn1.c
125pk7_attr.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
126pk7_attr.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
127pk7_attr.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
128pk7_attr.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
129pk7_attr.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
130pk7_attr.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
131pk7_attr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
132pk7_attr.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
133pk7_attr.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
134pk7_attr.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
135pk7_attr.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
136pk7_attr.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
137pk7_attr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
138pk7_attr.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
139pk7_attr.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
140pk7_attr.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
141pk7_attr.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
142pk7_attr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
143pk7_attr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
144pk7_attr.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
145pk7_attr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
146pk7_attr.o: pk7_attr.c
147pk7_doit.o: ../../e_os.h ../../include/openssl/aes.h
148pk7_doit.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
149pk7_doit.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
150pk7_doit.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
151pk7_doit.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
152pk7_doit.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
153pk7_doit.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
154pk7_doit.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
155pk7_doit.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
156pk7_doit.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
157pk7_doit.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
158pk7_doit.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
159pk7_doit.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
160pk7_doit.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
161pk7_doit.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
162pk7_doit.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
163pk7_doit.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
164pk7_doit.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
165pk7_doit.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
166pk7_doit.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
167pk7_doit.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
168pk7_doit.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
169pk7_doit.o: ../cryptlib.h pk7_doit.c
170pk7_lib.o: ../../e_os.h ../../include/openssl/aes.h
171pk7_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
172pk7_lib.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
173pk7_lib.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
174pk7_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
175pk7_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
176pk7_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
177pk7_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
178pk7_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
179pk7_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
180pk7_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
181pk7_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
182pk7_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
183pk7_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
184pk7_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
185pk7_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
186pk7_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
187pk7_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
188pk7_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
189pk7_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
190pk7_lib.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pk7_lib.c
191pk7_mime.o: ../../e_os.h ../../include/openssl/aes.h
192pk7_mime.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
193pk7_mime.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
194pk7_mime.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
195pk7_mime.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
196pk7_mime.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
197pk7_mime.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
198pk7_mime.o: ../../include/openssl/err.h ../../include/openssl/evp.h
199pk7_mime.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
200pk7_mime.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
201pk7_mime.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
202pk7_mime.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
203pk7_mime.o: ../../include/openssl/opensslconf.h
204pk7_mime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
205pk7_mime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rand.h
206pk7_mime.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
207pk7_mime.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
208pk7_mime.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
209pk7_mime.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
210pk7_mime.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
211pk7_mime.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
212pk7_mime.o: ../../include/openssl/x509_vfy.h ../cryptlib.h pk7_mime.c
213pk7_smime.o: ../../e_os.h ../../include/openssl/aes.h
214pk7_smime.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
215pk7_smime.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
216pk7_smime.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
217pk7_smime.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
218pk7_smime.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
219pk7_smime.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
220pk7_smime.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
221pk7_smime.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
222pk7_smime.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
223pk7_smime.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
224pk7_smime.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
225pk7_smime.o: ../../include/openssl/objects.h
226pk7_smime.o: ../../include/openssl/opensslconf.h
227pk7_smime.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
228pk7_smime.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
229pk7_smime.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
230pk7_smime.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
231pk7_smime.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
232pk7_smime.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
233pk7_smime.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
234pk7_smime.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
235pk7_smime.o: ../../include/openssl/x509v3.h ../cryptlib.h pk7_smime.c
236pkcs7err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
237pkcs7err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
238pkcs7err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
239pkcs7err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
240pkcs7err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
241pkcs7err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
242pkcs7err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
243pkcs7err.o: pkcs7err.c
diff --git a/src/lib/libcrypto/pkcs7/bio_ber.c b/src/lib/libcrypto/pkcs7/bio_ber.c
new file mode 100644
index 0000000000..895a91177b
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/bio_ber.c
@@ -0,0 +1,466 @@
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);
72static long ber_callback_ctrl(BIO *h,int cmd,void *(*fp)());
73#define BER_BUF_SIZE (32)
74
75/* This is used to hold the state of the BER objects being read. */
76typedef struct ber_struct
77 {
78 int tag;
79 int class;
80 long length;
81 int inf;
82 int num_left;
83 int depth;
84 } BER_CTX;
85
86typedef struct bio_ber_struct
87 {
88 int tag;
89 int class;
90 long length;
91 int inf;
92
93 /* most of the following are used when doing non-blocking IO */
94 /* reading */
95 long num_left; /* number of bytes still to read/write in block */
96 int depth; /* used with indefinite encoding. */
97 int finished; /* No more read data */
98
99 /* writting */
100 char *w_addr;
101 int w_offset;
102 int w_left;
103
104 int buf_len;
105 int buf_off;
106 unsigned char buf[BER_BUF_SIZE];
107 } BIO_BER_CTX;
108
109static BIO_METHOD methods_ber=
110 {
111 BIO_TYPE_CIPHER,"cipher",
112 ber_write,
113 ber_read,
114 NULL, /* ber_puts, */
115 NULL, /* ber_gets, */
116 ber_ctrl,
117 ber_new,
118 ber_free,
119 ber_callback_ctrl,
120 };
121
122BIO_METHOD *BIO_f_ber(void)
123 {
124 return(&methods_ber);
125 }
126
127static int ber_new(BIO *bi)
128 {
129 BIO_BER_CTX *ctx;
130
131 ctx=(BIO_BER_CTX *)OPENSSL_malloc(sizeof(BIO_BER_CTX));
132 if (ctx == NULL) return(0);
133
134 memset((char *)ctx,0,sizeof(BIO_BER_CTX));
135
136 bi->init=0;
137 bi->ptr=(char *)ctx;
138 bi->flags=0;
139 return(1);
140 }
141
142static int ber_free(BIO *a)
143 {
144 BIO_BER_CTX *b;
145
146 if (a == NULL) return(0);
147 b=(BIO_BER_CTX *)a->ptr;
148 OPENSSL_cleanse(a->ptr,sizeof(BIO_BER_CTX));
149 OPENSSL_free(a->ptr);
150 a->ptr=NULL;
151 a->init=0;
152 a->flags=0;
153 return(1);
154 }
155
156int bio_ber_get_header(BIO *bio, BIO_BER_CTX *ctx)
157 {
158 char buf[64];
159 int i,j,n;
160 int ret;
161 unsigned char *p;
162 unsigned long length
163 int tag;
164 int class;
165 long max;
166
167 BIO_clear_retry_flags(b);
168
169 /* Pack the buffer down if there is a hole at the front */
170 if (ctx->buf_off != 0)
171 {
172 p=ctx->buf;
173 j=ctx->buf_off;
174 n=ctx->buf_len-j;
175 for (i=0; i<n; i++)
176 {
177 p[0]=p[j];
178 p++;
179 }
180 ctx->buf_len-j;
181 ctx->buf_off=0;
182 }
183
184 /* If there is more room, read some more data */
185 i=BER_BUF_SIZE-ctx->buf_len;
186 if (i)
187 {
188 i=BIO_read(bio->next_bio,&(ctx->buf[ctx->buf_len]),i);
189 if (i <= 0)
190 {
191 BIO_copy_next_retry(b);
192 return(i);
193 }
194 else
195 ctx->buf_len+=i;
196 }
197
198 max=ctx->buf_len;
199 p=ctx->buf;
200 ret=ASN1_get_object(&p,&length,&tag,&class,max);
201
202 if (ret & 0x80)
203 {
204 if ((ctx->buf_len < BER_BUF_SIZE) &&
205 (ERR_GET_REASON(ERR_peek_error()) == ASN1_R_TOO_LONG))
206 {
207 ERR_get_error(); /* clear the error */
208 BIO_set_retry_read(b);
209 }
210 return(-1);
211 }
212
213 /* We have no error, we have a header, so make use of it */
214
215 if ((ctx->tag >= 0) && (ctx->tag != tag))
216 {
217 BIOerr(BIO_F_BIO_BER_GET_HEADER,BIO_R_TAG_MISMATCH);
218 sprintf(buf,"tag=%d, got %d",ctx->tag,tag);
219 ERR_add_error_data(1,buf);
220 return(-1);
221 }
222 if (ret & 0x01)
223 if (ret & V_ASN1_CONSTRUCTED)
224 }
225
226static int ber_read(BIO *b, char *out, int outl)
227 {
228 int ret=0,i,n;
229 BIO_BER_CTX *ctx;
230
231 BIO_clear_retry_flags(b);
232
233 if (out == NULL) return(0);
234 ctx=(BIO_BER_CTX *)b->ptr;
235
236 if ((ctx == NULL) || (b->next_bio == NULL)) return(0);
237
238 if (ctx->finished) return(0);
239
240again:
241 /* First see if we are half way through reading a block */
242 if (ctx->num_left > 0)
243 {
244 if (ctx->num_left < outl)
245 n=ctx->num_left;
246 else
247 n=outl;
248 i=BIO_read(b->next_bio,out,n);
249 if (i <= 0)
250 {
251 BIO_copy_next_retry(b);
252 return(i);
253 }
254 ctx->num_left-=i;
255 outl-=i;
256 ret+=i;
257 if (ctx->num_left <= 0)
258 {
259 ctx->depth--;
260 if (ctx->depth <= 0)
261 ctx->finished=1;
262 }
263 if (outl <= 0)
264 return(ret);
265 else
266 goto again;
267 }
268 else /* we need to read another BER header */
269 {
270 }
271 }
272
273static int ber_write(BIO *b, char *in, int inl)
274 {
275 int ret=0,n,i;
276 BIO_ENC_CTX *ctx;
277
278 ctx=(BIO_ENC_CTX *)b->ptr;
279 ret=inl;
280
281 BIO_clear_retry_flags(b);
282 n=ctx->buf_len-ctx->buf_off;
283 while (n > 0)
284 {
285 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
286 if (i <= 0)
287 {
288 BIO_copy_next_retry(b);
289 return(i);
290 }
291 ctx->buf_off+=i;
292 n-=i;
293 }
294 /* at this point all pending data has been written */
295
296 if ((in == NULL) || (inl <= 0)) return(0);
297
298 ctx->buf_off=0;
299 while (inl > 0)
300 {
301 n=(inl > ENC_BLOCK_SIZE)?ENC_BLOCK_SIZE:inl;
302 EVP_CipherUpdate(&(ctx->cipher),
303 (unsigned char *)ctx->buf,&ctx->buf_len,
304 (unsigned char *)in,n);
305 inl-=n;
306 in+=n;
307
308 ctx->buf_off=0;
309 n=ctx->buf_len;
310 while (n > 0)
311 {
312 i=BIO_write(b->next_bio,&(ctx->buf[ctx->buf_off]),n);
313 if (i <= 0)
314 {
315 BIO_copy_next_retry(b);
316 return(i);
317 }
318 n-=i;
319 ctx->buf_off+=i;
320 }
321 ctx->buf_len=0;
322 ctx->buf_off=0;
323 }
324 BIO_copy_next_retry(b);
325 return(ret);
326 }
327
328static long ber_ctrl(BIO *b, int cmd, long num, char *ptr)
329 {
330 BIO *dbio;
331 BIO_ENC_CTX *ctx,*dctx;
332 long ret=1;
333 int i;
334
335 ctx=(BIO_ENC_CTX *)b->ptr;
336
337 switch (cmd)
338 {
339 case BIO_CTRL_RESET:
340 ctx->ok=1;
341 ctx->finished=0;
342 EVP_CipherInit_ex(&(ctx->cipher),NULL,NULL,NULL,NULL,
343 ctx->cipher.berrypt);
344 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
345 break;
346 case BIO_CTRL_EOF: /* More to read */
347 if (ctx->cont <= 0)
348 ret=1;
349 else
350 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
351 break;
352 case BIO_CTRL_WPENDING:
353 ret=ctx->buf_len-ctx->buf_off;
354 if (ret <= 0)
355 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
356 break;
357 case BIO_CTRL_PENDING: /* More to read in buffer */
358 ret=ctx->buf_len-ctx->buf_off;
359 if (ret <= 0)
360 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
361 break;
362 case BIO_CTRL_FLUSH:
363 /* do a final write */
364again:
365 while (ctx->buf_len != ctx->buf_off)
366 {
367 i=ber_write(b,NULL,0);
368 if (i < 0)
369 {
370 ret=i;
371 break;
372 }
373 }
374
375 if (!ctx->finished)
376 {
377 ctx->finished=1;
378 ctx->buf_off=0;
379 ret=EVP_CipherFinal_ex(&(ctx->cipher),
380 (unsigned char *)ctx->buf,
381 &(ctx->buf_len));
382 ctx->ok=(int)ret;
383 if (ret <= 0) break;
384
385 /* push out the bytes */
386 goto again;
387 }
388
389 /* Finally flush the underlying BIO */
390 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
391 break;
392 case BIO_C_GET_CIPHER_STATUS:
393 ret=(long)ctx->ok;
394 break;
395 case BIO_C_DO_STATE_MACHINE:
396 BIO_clear_retry_flags(b);
397 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
398 BIO_copy_next_retry(b);
399 break;
400
401 case BIO_CTRL_DUP:
402 dbio=(BIO *)ptr;
403 dctx=(BIO_ENC_CTX *)dbio->ptr;
404 memcpy(&(dctx->cipher),&(ctx->cipher),sizeof(ctx->cipher));
405 dbio->init=1;
406 break;
407 default:
408 ret=BIO_ctrl(b->next_bio,cmd,num,ptr);
409 break;
410 }
411 return(ret);
412 }
413
414static long ber_callback_ctrl(BIO *b, int cmd, void *(*fp)())
415 {
416 long ret=1;
417
418 if (b->next_bio == NULL) return(0);
419 switch (cmd)
420 {
421 default:
422 ret=BIO_callback_ctrl(b->next_bio,cmd,fp);
423 break;
424 }
425 return(ret);
426 }
427
428/*
429void BIO_set_cipher_ctx(b,c)
430BIO *b;
431EVP_CIPHER_ctx *c;
432 {
433 if (b == NULL) return;
434
435 if ((b->callback != NULL) &&
436 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
437 return;
438
439 b->init=1;
440 ctx=(BIO_ENC_CTX *)b->ptr;
441 memcpy(ctx->cipher,c,sizeof(EVP_CIPHER_CTX));
442
443 if (b->callback != NULL)
444 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
445 }
446*/
447
448void BIO_set_cipher(BIO *b, EVP_CIPHER *c, unsigned char *k, unsigned char *i,
449 int e)
450 {
451 BIO_ENC_CTX *ctx;
452
453 if (b == NULL) return;
454
455 if ((b->callback != NULL) &&
456 (b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,0L) <= 0))
457 return;
458
459 b->init=1;
460 ctx=(BIO_ENC_CTX *)b->ptr;
461 EVP_CipherInit_ex(&(ctx->cipher),c,NULL,k,i,e);
462
463 if (b->callback != NULL)
464 b->callback(b,BIO_CB_CTRL,(char *)c,BIO_CTRL_SET,e,1L);
465 }
466
diff --git a/src/lib/libcrypto/pkcs7/dec.c b/src/lib/libcrypto/pkcs7/dec.c
new file mode 100644
index 0000000000..6752ec568a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/dec.c
@@ -0,0 +1,248 @@
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 <string.h>
61#include <openssl/bio.h>
62#include <openssl/x509.h>
63#include <openssl/pem.h>
64#include <openssl/err.h>
65#include <openssl/asn1.h>
66
67int verify_callback(int ok, X509_STORE_CTX *ctx);
68
69BIO *bio_err=NULL;
70
71int main(argc,argv)
72int argc;
73char *argv[];
74 {
75 char *keyfile=NULL;
76 BIO *in;
77 EVP_PKEY *pkey;
78 X509 *x509;
79 PKCS7 *p7;
80 PKCS7_SIGNER_INFO *si;
81 X509_STORE_CTX cert_ctx;
82 X509_STORE *cert_store=NULL;
83 BIO *data,*detached=NULL,*p7bio=NULL;
84 char buf[1024*4];
85 unsigned char *pp;
86 int i,printit=0;
87 STACK_OF(PKCS7_SIGNER_INFO) *sk;
88
89 OpenSSL_add_all_algorithms();
90 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
91
92 data=BIO_new(BIO_s_file());
93 pp=NULL;
94 while (argc > 1)
95 {
96 argc--;
97 argv++;
98 if (strcmp(argv[0],"-p") == 0)
99 {
100 printit=1;
101 }
102 else if ((strcmp(argv[0],"-k") == 0) && (argc >= 2)) {
103 keyfile = argv[1];
104 argc-=1;
105 argv+=1;
106 } else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
107 {
108 detached=BIO_new(BIO_s_file());
109 if (!BIO_read_filename(detached,argv[1]))
110 goto err;
111 argc-=1;
112 argv+=1;
113 }
114 else break;
115 }
116
117 if (!BIO_read_filename(data,argv[0])) goto err;
118
119 if(!keyfile) {
120 fprintf(stderr, "No private key file specified\n");
121 goto err;
122 }
123
124 if ((in=BIO_new_file(keyfile,"r")) == NULL) goto err;
125 if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
126 BIO_reset(in);
127 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL)
128 goto err;
129 BIO_free(in);
130
131 if (pp == NULL)
132 BIO_set_fp(data,stdin,BIO_NOCLOSE);
133
134
135 /* Load the PKCS7 object from a file */
136 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err;
137
138
139
140 /* This stuff is being setup for certificate verification.
141 * When using SSL, it could be replaced with a
142 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
143 cert_store=X509_STORE_new();
144 X509_STORE_set_default_paths(cert_store);
145 X509_STORE_load_locations(cert_store,NULL,"../../certs");
146 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
147
148 ERR_clear_error();
149
150 /* We need to process the data */
151 /* We cannot support detached encryption */
152 p7bio=PKCS7_dataDecode(p7,pkey,detached,x509);
153
154 if (p7bio == NULL)
155 {
156 printf("problems decoding\n");
157 goto err;
158 }
159
160 /* We now have to 'read' from p7bio to calculate digests etc. */
161 for (;;)
162 {
163 i=BIO_read(p7bio,buf,sizeof(buf));
164 /* print it? */
165 if (i <= 0) break;
166 fwrite(buf,1, i, stdout);
167 }
168
169 /* We can now verify signatures */
170 sk=PKCS7_get_signer_info(p7);
171 if (sk == NULL)
172 {
173 fprintf(stderr, "there are no signatures on this data\n");
174 }
175 else
176 {
177 /* Ok, first we need to, for each subject entry,
178 * see if we can verify */
179 ERR_clear_error();
180 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
181 {
182 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
183 i=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
184 if (i <= 0)
185 goto err;
186 else
187 fprintf(stderr,"Signature verified\n");
188 }
189 }
190 X509_STORE_free(cert_store);
191
192 exit(0);
193err:
194 ERR_load_crypto_strings();
195 ERR_print_errors_fp(stderr);
196 exit(1);
197 }
198
199/* should be X509 * but we can just have them as char *. */
200int verify_callback(int ok, X509_STORE_CTX *ctx)
201 {
202 char buf[256];
203 X509 *err_cert;
204 int err,depth;
205
206 err_cert=X509_STORE_CTX_get_current_cert(ctx);
207 err= X509_STORE_CTX_get_error(ctx);
208 depth= X509_STORE_CTX_get_error_depth(ctx);
209
210 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
211 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
212 if (!ok)
213 {
214 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
215 X509_verify_cert_error_string(err));
216 if (depth < 6)
217 {
218 ok=1;
219 X509_STORE_CTX_set_error(ctx,X509_V_OK);
220 }
221 else
222 {
223 ok=0;
224 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
225 }
226 }
227 switch (ctx->error)
228 {
229 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
230 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
231 BIO_printf(bio_err,"issuer= %s\n",buf);
232 break;
233 case X509_V_ERR_CERT_NOT_YET_VALID:
234 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
235 BIO_printf(bio_err,"notBefore=");
236 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
237 BIO_printf(bio_err,"\n");
238 break;
239 case X509_V_ERR_CERT_HAS_EXPIRED:
240 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
241 BIO_printf(bio_err,"notAfter=");
242 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
243 BIO_printf(bio_err,"\n");
244 break;
245 }
246 BIO_printf(bio_err,"verify return:%d\n",ok);
247 return(ok);
248 }
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/doc b/src/lib/libcrypto/pkcs7/doc
new file mode 100644
index 0000000000..d2e8b7b2a3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/doc
@@ -0,0 +1,24 @@
1int PKCS7_set_content_type(PKCS7 *p7, int type);
2Call to set the type of PKCS7 object we are working on
3
4int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
5 EVP_MD *dgst);
6Use this to setup a signer info
7There will also be functions to add signed and unsigned attributes.
8
9int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *p7i);
10Add a signer info to the content.
11
12int PKCS7_add_certificae(PKCS7 *p7, X509 *x509);
13int PKCS7_add_crl(PKCS7 *p7, X509_CRL *x509);
14
15----
16
17p7=PKCS7_new();
18PKCS7_set_content_type(p7,NID_pkcs7_signed);
19
20signer=PKCS7_SINGNER_INFO_new();
21PKCS7_SIGNER_INFO_set(signer,x509,pkey,EVP_md5());
22PKCS7_add_signer(py,signer);
23
24we are now setup.
diff --git a/src/lib/libcrypto/pkcs7/enc.c b/src/lib/libcrypto/pkcs7/enc.c
new file mode 100644
index 0000000000..7417f8a4e0
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/enc.c
@@ -0,0 +1,174 @@
1/* crypto/pkcs7/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#include <stdio.h>
59#include <string.h>
60#include <openssl/bio.h>
61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64
65int main(argc,argv)
66int argc;
67char *argv[];
68 {
69 X509 *x509;
70 PKCS7 *p7;
71 BIO *in;
72 BIO *data,*p7bio;
73 char buf[1024*4];
74 int i;
75 int nodetach=1;
76 char *keyfile = NULL;
77 const EVP_CIPHER *cipher=NULL;
78 STACK_OF(X509) *recips=NULL;
79
80 OpenSSL_add_all_algorithms();
81
82 data=BIO_new(BIO_s_file());
83 while(argc > 1)
84 {
85 if (strcmp(argv[1],"-nd") == 0)
86 {
87 nodetach=1;
88 argv++; argc--;
89 }
90 else if ((strcmp(argv[1],"-c") == 0) && (argc >= 2)) {
91 if(!(cipher = EVP_get_cipherbyname(argv[2]))) {
92 fprintf(stderr, "Unknown cipher %s\n", argv[2]);
93 goto err;
94 }
95 argc-=2;
96 argv+=2;
97 } else if ((strcmp(argv[1],"-k") == 0) && (argc >= 2)) {
98 keyfile = argv[2];
99 argc-=2;
100 argv+=2;
101 if (!(in=BIO_new_file(keyfile,"r"))) goto err;
102 if (!(x509=PEM_read_bio_X509(in,NULL,NULL,NULL)))
103 goto err;
104 if(!recips) recips = sk_X509_new_null();
105 sk_X509_push(recips, x509);
106 BIO_free(in);
107 } else break;
108 }
109
110 if(!recips) {
111 fprintf(stderr, "No recipients\n");
112 goto err;
113 }
114
115 if (!BIO_read_filename(data,argv[1])) goto err;
116
117 p7=PKCS7_new();
118#if 0
119 BIO_reset(in);
120 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL)) == NULL) goto err;
121 BIO_free(in);
122 PKCS7_set_type(p7,NID_pkcs7_signedAndEnveloped);
123
124 if (PKCS7_add_signature(p7,x509,pkey,EVP_sha1()) == NULL) goto err;
125 /* we may want to add more */
126 PKCS7_add_certificate(p7,x509);
127#else
128 PKCS7_set_type(p7,NID_pkcs7_enveloped);
129#endif
130 if(!cipher) {
131#ifndef OPENSSL_NO_DES
132 cipher = EVP_des_ede3_cbc();
133#else
134 fprintf(stderr, "No cipher selected\n");
135 goto err;
136#endif
137 }
138
139 if (!PKCS7_set_cipher(p7,cipher)) goto err;
140 for(i = 0; i < sk_X509_num(recips); i++) {
141 if (!PKCS7_add_recipient(p7,sk_X509_value(recips, i))) goto err;
142 }
143 sk_X509_pop_free(recips, X509_free);
144
145 /* Set the content of the signed to 'data' */
146 /* PKCS7_content_new(p7,NID_pkcs7_data); not used in envelope */
147
148 /* could be used, but not in this version :-)
149 if (!nodetach) PKCS7_set_detached(p7,1);
150 */
151
152 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
153
154 for (;;)
155 {
156 i=BIO_read(data,buf,sizeof(buf));
157 if (i <= 0) break;
158 BIO_write(p7bio,buf,i);
159 }
160 BIO_flush(p7bio);
161
162 if (!PKCS7_dataFinal(p7,p7bio)) goto err;
163 BIO_free(p7bio);
164
165 PEM_write_PKCS7(stdout,p7);
166 PKCS7_free(p7);
167
168 exit(0);
169err:
170 ERR_load_crypto_strings();
171 ERR_print_errors_fp(stderr);
172 exit(1);
173 }
174
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..c993947cc3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/example.c
@@ -0,0 +1,329 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4#include <openssl/pkcs7.h>
5#include <openssl/asn1_mac.h>
6#include <openssl/x509.h>
7
8int add_signed_time(PKCS7_SIGNER_INFO *si)
9 {
10 ASN1_UTCTIME *sign_time;
11
12 /* The last parameter is the amount to add/subtract from the current
13 * time (in seconds) */
14 sign_time=X509_gmtime_adj(NULL,0);
15 PKCS7_add_signed_attribute(si,NID_pkcs9_signingTime,
16 V_ASN1_UTCTIME,(char *)sign_time);
17 return(1);
18 }
19
20ASN1_UTCTIME *get_signed_time(PKCS7_SIGNER_INFO *si)
21 {
22 ASN1_TYPE *so;
23
24 so=PKCS7_get_signed_attribute(si,NID_pkcs9_signingTime);
25 if (so->type == V_ASN1_UTCTIME)
26 return so->value.utctime;
27 return NULL;
28 }
29
30static int signed_string_nid= -1;
31
32void add_signed_string(PKCS7_SIGNER_INFO *si, char *str)
33 {
34 ASN1_OCTET_STRING *os;
35
36 /* To a an object of OID 1.2.3.4.5, which is an octet string */
37 if (signed_string_nid == -1)
38 signed_string_nid=
39 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
40 os=ASN1_OCTET_STRING_new();
41 ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
42 /* When we add, we do not free */
43 PKCS7_add_signed_attribute(si,signed_string_nid,
44 V_ASN1_OCTET_STRING,(char *)os);
45 }
46
47int get_signed_string(PKCS7_SIGNER_INFO *si, char *buf, int len)
48 {
49 ASN1_TYPE *so;
50 ASN1_OCTET_STRING *os;
51 int i;
52
53 if (signed_string_nid == -1)
54 signed_string_nid=
55 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
56 /* To retrieve */
57 so=PKCS7_get_signed_attribute(si,signed_string_nid);
58 if (so != NULL)
59 {
60 if (so->type == V_ASN1_OCTET_STRING)
61 {
62 os=so->value.octet_string;
63 i=os->length;
64 if ((i+1) > len)
65 i=len-1;
66 memcpy(buf,os->data,i);
67 return(i);
68 }
69 }
70 return(0);
71 }
72
73static int signed_seq2string_nid= -1;
74/* ########################################### */
75int add_signed_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
76 {
77 /* To add an object of OID 1.9.999, which is a sequence containing
78 * 2 octet strings */
79 unsigned char *p;
80 ASN1_OCTET_STRING *os1,*os2;
81 ASN1_STRING *seq;
82 unsigned char *data;
83 int i,total;
84
85 if (signed_seq2string_nid == -1)
86 signed_seq2string_nid=
87 OBJ_create("1.9.9999","OID_example","Our example OID");
88
89 os1=ASN1_OCTET_STRING_new();
90 os2=ASN1_OCTET_STRING_new();
91 ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
92 ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
93 i =i2d_ASN1_OCTET_STRING(os1,NULL);
94 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
95 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
96
97 data=malloc(total);
98 p=data;
99 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
100 i2d_ASN1_OCTET_STRING(os1,&p);
101 i2d_ASN1_OCTET_STRING(os2,&p);
102
103 seq=ASN1_STRING_new();
104 ASN1_STRING_set(seq,data,total);
105 free(data);
106 ASN1_OCTET_STRING_free(os1);
107 ASN1_OCTET_STRING_free(os2);
108
109 PKCS7_add_signed_attribute(si,signed_seq2string_nid,
110 V_ASN1_SEQUENCE,(char *)seq);
111 return(1);
112 }
113
114/* For this case, I will malloc the return strings */
115int get_signed_seq2string(PKCS7_SIGNER_INFO *si, char **str1, char **str2)
116 {
117 ASN1_TYPE *so;
118
119 if (signed_seq2string_nid == -1)
120 signed_seq2string_nid=
121 OBJ_create("1.9.9999","OID_example","Our example OID");
122 /* To retrieve */
123 so=PKCS7_get_signed_attribute(si,signed_seq2string_nid);
124 if (so && (so->type == V_ASN1_SEQUENCE))
125 {
126 ASN1_CTX c;
127 ASN1_STRING *s;
128 long length;
129 ASN1_OCTET_STRING *os1,*os2;
130
131 s=so->value.sequence;
132 c.p=ASN1_STRING_data(s);
133 c.max=c.p+ASN1_STRING_length(s);
134 if (!asn1_GetSequence(&c,&length)) goto err;
135 /* Length is the length of the seqence */
136
137 c.q=c.p;
138 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
139 goto err;
140 c.slen-=(c.p-c.q);
141
142 c.q=c.p;
143 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
144 goto err;
145 c.slen-=(c.p-c.q);
146
147 if (!asn1_Finish(&c)) goto err;
148 *str1=malloc(os1->length+1);
149 *str2=malloc(os2->length+1);
150 memcpy(*str1,os1->data,os1->length);
151 memcpy(*str2,os2->data,os2->length);
152 (*str1)[os1->length]='\0';
153 (*str2)[os2->length]='\0';
154 ASN1_OCTET_STRING_free(os1);
155 ASN1_OCTET_STRING_free(os2);
156 return(1);
157 }
158err:
159 return(0);
160 }
161
162
163/* #######################################
164 * THE OTHER WAY TO DO THINGS
165 * #######################################
166 */
167X509_ATTRIBUTE *create_time(void)
168 {
169 ASN1_UTCTIME *sign_time;
170 X509_ATTRIBUTE *ret;
171
172 /* The last parameter is the amount to add/subtract from the current
173 * time (in seconds) */
174 sign_time=X509_gmtime_adj(NULL,0);
175 ret=X509_ATTRIBUTE_create(NID_pkcs9_signingTime,
176 V_ASN1_UTCTIME,(char *)sign_time);
177 return(ret);
178 }
179
180ASN1_UTCTIME *sk_get_time(STACK_OF(X509_ATTRIBUTE) *sk)
181 {
182 ASN1_TYPE *so;
183 PKCS7_SIGNER_INFO si;
184
185 si.auth_attr=sk;
186 so=PKCS7_get_signed_attribute(&si,NID_pkcs9_signingTime);
187 if (so->type == V_ASN1_UTCTIME)
188 return so->value.utctime;
189 return NULL;
190 }
191
192X509_ATTRIBUTE *create_string(char *str)
193 {
194 ASN1_OCTET_STRING *os;
195 X509_ATTRIBUTE *ret;
196
197 /* To a an object of OID 1.2.3.4.5, which is an octet string */
198 if (signed_string_nid == -1)
199 signed_string_nid=
200 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
201 os=ASN1_OCTET_STRING_new();
202 ASN1_OCTET_STRING_set(os,(unsigned char*)str,strlen(str));
203 /* When we add, we do not free */
204 ret=X509_ATTRIBUTE_create(signed_string_nid,
205 V_ASN1_OCTET_STRING,(char *)os);
206 return(ret);
207 }
208
209int sk_get_string(STACK_OF(X509_ATTRIBUTE) *sk, char *buf, int len)
210 {
211 ASN1_TYPE *so;
212 ASN1_OCTET_STRING *os;
213 int i;
214 PKCS7_SIGNER_INFO si;
215
216 si.auth_attr=sk;
217
218 if (signed_string_nid == -1)
219 signed_string_nid=
220 OBJ_create("1.2.3.4.5","OID_example","Our example OID");
221 /* To retrieve */
222 so=PKCS7_get_signed_attribute(&si,signed_string_nid);
223 if (so != NULL)
224 {
225 if (so->type == V_ASN1_OCTET_STRING)
226 {
227 os=so->value.octet_string;
228 i=os->length;
229 if ((i+1) > len)
230 i=len-1;
231 memcpy(buf,os->data,i);
232 return(i);
233 }
234 }
235 return(0);
236 }
237
238X509_ATTRIBUTE *add_seq2string(PKCS7_SIGNER_INFO *si, char *str1, char *str2)
239 {
240 /* To add an object of OID 1.9.999, which is a sequence containing
241 * 2 octet strings */
242 unsigned char *p;
243 ASN1_OCTET_STRING *os1,*os2;
244 ASN1_STRING *seq;
245 X509_ATTRIBUTE *ret;
246 unsigned char *data;
247 int i,total;
248
249 if (signed_seq2string_nid == -1)
250 signed_seq2string_nid=
251 OBJ_create("1.9.9999","OID_example","Our example OID");
252
253 os1=ASN1_OCTET_STRING_new();
254 os2=ASN1_OCTET_STRING_new();
255 ASN1_OCTET_STRING_set(os1,(unsigned char*)str1,strlen(str1));
256 ASN1_OCTET_STRING_set(os2,(unsigned char*)str1,strlen(str1));
257 i =i2d_ASN1_OCTET_STRING(os1,NULL);
258 i+=i2d_ASN1_OCTET_STRING(os2,NULL);
259 total=ASN1_object_size(1,i,V_ASN1_SEQUENCE);
260
261 data=malloc(total);
262 p=data;
263 ASN1_put_object(&p,1,i,V_ASN1_SEQUENCE,V_ASN1_UNIVERSAL);
264 i2d_ASN1_OCTET_STRING(os1,&p);
265 i2d_ASN1_OCTET_STRING(os2,&p);
266
267 seq=ASN1_STRING_new();
268 ASN1_STRING_set(seq,data,total);
269 free(data);
270 ASN1_OCTET_STRING_free(os1);
271 ASN1_OCTET_STRING_free(os2);
272
273 ret=X509_ATTRIBUTE_create(signed_seq2string_nid,
274 V_ASN1_SEQUENCE,(char *)seq);
275 return(ret);
276 }
277
278/* For this case, I will malloc the return strings */
279int sk_get_seq2string(STACK_OF(X509_ATTRIBUTE) *sk, char **str1, char **str2)
280 {
281 ASN1_TYPE *so;
282 PKCS7_SIGNER_INFO si;
283
284 if (signed_seq2string_nid == -1)
285 signed_seq2string_nid=
286 OBJ_create("1.9.9999","OID_example","Our example OID");
287
288 si.auth_attr=sk;
289 /* To retrieve */
290 so=PKCS7_get_signed_attribute(&si,signed_seq2string_nid);
291 if (so->type == V_ASN1_SEQUENCE)
292 {
293 ASN1_CTX c;
294 ASN1_STRING *s;
295 long length;
296 ASN1_OCTET_STRING *os1,*os2;
297
298 s=so->value.sequence;
299 c.p=ASN1_STRING_data(s);
300 c.max=c.p+ASN1_STRING_length(s);
301 if (!asn1_GetSequence(&c,&length)) goto err;
302 /* Length is the length of the seqence */
303
304 c.q=c.p;
305 if ((os1=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
306 goto err;
307 c.slen-=(c.p-c.q);
308
309 c.q=c.p;
310 if ((os2=d2i_ASN1_OCTET_STRING(NULL,&c.p,c.slen)) == NULL)
311 goto err;
312 c.slen-=(c.p-c.q);
313
314 if (!asn1_Finish(&c)) goto err;
315 *str1=malloc(os1->length+1);
316 *str2=malloc(os2->length+1);
317 memcpy(*str1,os1->data,os1->length);
318 memcpy(*str2,os2->data,os2->length);
319 (*str1)[os1->length]='\0';
320 (*str2)[os2->length]='\0';
321 ASN1_OCTET_STRING_free(os1);
322 ASN1_OCTET_STRING_free(os2);
323 return(1);
324 }
325err:
326 return(0);
327 }
328
329
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/p7/a1 b/src/lib/libcrypto/pkcs7/p7/a1
new file mode 100644
index 0000000000..56ca943762
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/a1
@@ -0,0 +1,2 @@
1j,H>_æá_­DôzEîLœ VJ³ß觬¤””E3ûáYäx%_Àk
23ê)DLScñ8% ôM \ No newline at end of file
diff --git a/src/lib/libcrypto/pkcs7/p7/a2 b/src/lib/libcrypto/pkcs7/p7/a2
new file mode 100644
index 0000000000..23d8fb5e93
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/a2
@@ -0,0 +1 @@
k~@a”,NâM͹¼ <O( KP—騠¤K²>­×U¿o_½BqrmÎ?Ù t?t÷ÏéId2‰Š \ No newline at end of file
diff --git a/src/lib/libcrypto/pkcs7/p7/cert.p7c b/src/lib/libcrypto/pkcs7/p7/cert.p7c
new file mode 100644
index 0000000000..2b75ec05f7
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/cert.p7c
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7m b/src/lib/libcrypto/pkcs7/p7/smime.p7m
new file mode 100644
index 0000000000..2b6e6f82ba
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/smime.p7m
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/p7/smime.p7s b/src/lib/libcrypto/pkcs7/p7/smime.p7s
new file mode 100644
index 0000000000..2b5d4fb0e3
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/p7/smime.p7s
Binary files differ
diff --git a/src/lib/libcrypto/pkcs7/pk7_asn1.c b/src/lib/libcrypto/pkcs7/pk7_asn1.c
index 77931feeb4..46f0fc9375 100644
--- a/src/lib/libcrypto/pkcs7/pk7_asn1.c
+++ b/src/lib/libcrypto/pkcs7/pk7_asn1.c
@@ -69,31 +69,30 @@
69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0); 69ASN1_ADB_TEMPLATE(p7default) = ASN1_EXP_OPT(PKCS7, d.other, ASN1_ANY, 0);
70 70
71ASN1_ADB(PKCS7) = { 71ASN1_ADB(PKCS7) = {
72 ADB_ENTRY(NID_pkcs7_data, ASN1_NDEF_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING_NDEF, 0)), 72 ADB_ENTRY(NID_pkcs7_data, ASN1_EXP_OPT(PKCS7, d.data, ASN1_OCTET_STRING, 0)),
73 ADB_ENTRY(NID_pkcs7_signed, ASN1_NDEF_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)), 73 ADB_ENTRY(NID_pkcs7_signed, ASN1_EXP_OPT(PKCS7, d.sign, PKCS7_SIGNED, 0)),
74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_NDEF_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)), 74 ADB_ENTRY(NID_pkcs7_enveloped, ASN1_EXP_OPT(PKCS7, d.enveloped, PKCS7_ENVELOPE, 0)),
75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_NDEF_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)), 75 ADB_ENTRY(NID_pkcs7_signedAndEnveloped, ASN1_EXP_OPT(PKCS7, d.signed_and_enveloped, PKCS7_SIGN_ENVELOPE, 0)),
76 ADB_ENTRY(NID_pkcs7_digest, ASN1_NDEF_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)), 76 ADB_ENTRY(NID_pkcs7_digest, ASN1_EXP_OPT(PKCS7, d.digest, PKCS7_DIGEST, 0)),
77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_NDEF_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0)) 77 ADB_ENTRY(NID_pkcs7_encrypted, ASN1_EXP_OPT(PKCS7, d.encrypted, PKCS7_ENCRYPT, 0))
78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL); 78} ASN1_ADB_END(PKCS7, 0, type, 0, &p7default_tt, NULL);
79 79
80ASN1_NDEF_SEQUENCE(PKCS7) = { 80ASN1_SEQUENCE(PKCS7) = {
81 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT), 81 ASN1_SIMPLE(PKCS7, type, ASN1_OBJECT),
82 ASN1_ADB_OBJECT(PKCS7) 82 ASN1_ADB_OBJECT(PKCS7)
83}ASN1_NDEF_SEQUENCE_END(PKCS7) 83}ASN1_SEQUENCE_END(PKCS7)
84 84
85IMPLEMENT_ASN1_FUNCTIONS(PKCS7) 85IMPLEMENT_ASN1_FUNCTIONS(PKCS7)
86IMPLEMENT_ASN1_NDEF_FUNCTION(PKCS7)
87IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7) 86IMPLEMENT_ASN1_DUP_FUNCTION(PKCS7)
88 87
89ASN1_NDEF_SEQUENCE(PKCS7_SIGNED) = { 88ASN1_SEQUENCE(PKCS7_SIGNED) = {
90 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER), 89 ASN1_SIMPLE(PKCS7_SIGNED, version, ASN1_INTEGER),
91 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR), 90 ASN1_SET_OF(PKCS7_SIGNED, md_algs, X509_ALGOR),
92 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7), 91 ASN1_SIMPLE(PKCS7_SIGNED, contents, PKCS7),
93 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0), 92 ASN1_IMP_SEQUENCE_OF_OPT(PKCS7_SIGNED, cert, X509, 0),
94 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1), 93 ASN1_IMP_SET_OF_OPT(PKCS7_SIGNED, crl, X509_CRL, 1),
95 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO) 94 ASN1_SET_OF(PKCS7_SIGNED, signer_info, PKCS7_SIGNER_INFO)
96} ASN1_NDEF_SEQUENCE_END(PKCS7_SIGNED) 95} ASN1_SEQUENCE_END(PKCS7_SIGNED)
97 96
98IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED) 97IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGNED)
99 98
@@ -131,11 +130,11 @@ ASN1_SEQUENCE(PKCS7_ISSUER_AND_SERIAL) = {
131 130
132IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL) 131IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ISSUER_AND_SERIAL)
133 132
134ASN1_NDEF_SEQUENCE(PKCS7_ENVELOPE) = { 133ASN1_SEQUENCE(PKCS7_ENVELOPE) = {
135 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER), 134 ASN1_SIMPLE(PKCS7_ENVELOPE, version, ASN1_INTEGER),
136 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO), 135 ASN1_SET_OF(PKCS7_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
137 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT) 136 ASN1_SIMPLE(PKCS7_ENVELOPE, enc_data, PKCS7_ENC_CONTENT)
138} ASN1_NDEF_SEQUENCE_END(PKCS7_ENVELOPE) 137} ASN1_SEQUENCE_END(PKCS7_ENVELOPE)
139 138
140IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE) 139IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENVELOPE)
141 140
@@ -158,15 +157,15 @@ ASN1_SEQUENCE_cb(PKCS7_RECIP_INFO, ri_cb) = {
158 157
159IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO) 158IMPLEMENT_ASN1_FUNCTIONS(PKCS7_RECIP_INFO)
160 159
161ASN1_NDEF_SEQUENCE(PKCS7_ENC_CONTENT) = { 160ASN1_SEQUENCE(PKCS7_ENC_CONTENT) = {
162 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT), 161 ASN1_SIMPLE(PKCS7_ENC_CONTENT, content_type, ASN1_OBJECT),
163 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR), 162 ASN1_SIMPLE(PKCS7_ENC_CONTENT, algorithm, X509_ALGOR),
164 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0) 163 ASN1_IMP_OPT(PKCS7_ENC_CONTENT, enc_data, ASN1_OCTET_STRING, 0)
165} ASN1_NDEF_SEQUENCE_END(PKCS7_ENC_CONTENT) 164} ASN1_SEQUENCE_END(PKCS7_ENC_CONTENT)
166 165
167IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT) 166IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENC_CONTENT)
168 167
169ASN1_NDEF_SEQUENCE(PKCS7_SIGN_ENVELOPE) = { 168ASN1_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
170 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER), 169 ASN1_SIMPLE(PKCS7_SIGN_ENVELOPE, version, ASN1_INTEGER),
171 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO), 170 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, recipientinfo, PKCS7_RECIP_INFO),
172 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR), 171 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, md_algs, X509_ALGOR),
@@ -174,23 +173,23 @@ ASN1_NDEF_SEQUENCE(PKCS7_SIGN_ENVELOPE) = {
174 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0), 173 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, cert, X509, 0),
175 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1), 174 ASN1_IMP_SET_OF_OPT(PKCS7_SIGN_ENVELOPE, crl, X509_CRL, 1),
176 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO) 175 ASN1_SET_OF(PKCS7_SIGN_ENVELOPE, signer_info, PKCS7_SIGNER_INFO)
177} ASN1_NDEF_SEQUENCE_END(PKCS7_SIGN_ENVELOPE) 176} ASN1_SEQUENCE_END(PKCS7_SIGN_ENVELOPE)
178 177
179IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE) 178IMPLEMENT_ASN1_FUNCTIONS(PKCS7_SIGN_ENVELOPE)
180 179
181ASN1_NDEF_SEQUENCE(PKCS7_ENCRYPT) = { 180ASN1_SEQUENCE(PKCS7_ENCRYPT) = {
182 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER), 181 ASN1_SIMPLE(PKCS7_ENCRYPT, version, ASN1_INTEGER),
183 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT) 182 ASN1_SIMPLE(PKCS7_ENCRYPT, enc_data, PKCS7_ENC_CONTENT)
184} ASN1_NDEF_SEQUENCE_END(PKCS7_ENCRYPT) 183} ASN1_SEQUENCE_END(PKCS7_ENCRYPT)
185 184
186IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT) 185IMPLEMENT_ASN1_FUNCTIONS(PKCS7_ENCRYPT)
187 186
188ASN1_NDEF_SEQUENCE(PKCS7_DIGEST) = { 187ASN1_SEQUENCE(PKCS7_DIGEST) = {
189 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER), 188 ASN1_SIMPLE(PKCS7_DIGEST, version, ASN1_INTEGER),
190 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR), 189 ASN1_SIMPLE(PKCS7_DIGEST, md, X509_ALGOR),
191 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7), 190 ASN1_SIMPLE(PKCS7_DIGEST, contents, PKCS7),
192 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING) 191 ASN1_SIMPLE(PKCS7_DIGEST, digest, ASN1_OCTET_STRING)
193} ASN1_NDEF_SEQUENCE_END(PKCS7_DIGEST) 192} ASN1_SEQUENCE_END(PKCS7_DIGEST)
194 193
195IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST) 194IMPLEMENT_ASN1_FUNCTIONS(PKCS7_DIGEST)
196 195
diff --git a/src/lib/libcrypto/pkcs7/pk7_attr.c b/src/lib/libcrypto/pkcs7/pk7_attr.c
index 735c8800e1..039141027a 100644
--- a/src/lib/libcrypto/pkcs7/pk7_attr.c
+++ b/src/lib/libcrypto/pkcs7/pk7_attr.c
@@ -96,8 +96,7 @@ int PKCS7_add_attrib_smimecap(PKCS7_SIGNER_INFO *si, STACK_OF(X509_ALGOR) *cap)
96STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si) 96STACK_OF(X509_ALGOR) *PKCS7_get_smimecap(PKCS7_SIGNER_INFO *si)
97 { 97 {
98 ASN1_TYPE *cap; 98 ASN1_TYPE *cap;
99 const unsigned char *p; 99 unsigned char *p;
100
101 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities); 100 cap = PKCS7_get_signed_attribute(si, NID_SMIMECapabilities);
102 if (!cap || (cap->type != V_ASN1_SEQUENCE)) 101 if (!cap || (cap->type != V_ASN1_SEQUENCE))
103 return NULL; 102 return NULL;
diff --git a/src/lib/libcrypto/pkcs7/pk7_dgst.c b/src/lib/libcrypto/pkcs7/pk7_dgst.c
new file mode 100644
index 0000000000..90edfa5001
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_dgst.c
@@ -0,0 +1,66 @@
1/* crypto/pkcs7/pk7_dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/rand.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66
diff --git a/src/lib/libcrypto/pkcs7/pk7_doit.c b/src/lib/libcrypto/pkcs7/pk7_doit.c
index a03d7ebedf..4ac29ae14d 100644
--- a/src/lib/libcrypto/pkcs7/pk7_doit.c
+++ b/src/lib/libcrypto/pkcs7/pk7_doit.c
@@ -62,7 +62,6 @@
62#include <openssl/objects.h> 62#include <openssl/objects.h>
63#include <openssl/x509.h> 63#include <openssl/x509.h>
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65#include <openssl/err.h>
66 65
67static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype, 66static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
68 void *value); 67 void *value);
@@ -102,54 +101,18 @@ static ASN1_OCTET_STRING *PKCS7_get_octet_string(PKCS7 *p7)
102 return NULL; 101 return NULL;
103 } 102 }
104 103
105static int PKCS7_bio_add_digest(BIO **pbio, X509_ALGOR *alg)
106 {
107 BIO *btmp;
108 const EVP_MD *md;
109 if ((btmp=BIO_new(BIO_f_md())) == NULL)
110 {
111 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,ERR_R_BIO_LIB);
112 goto err;
113 }
114
115 md=EVP_get_digestbyobj(alg->algorithm);
116 if (md == NULL)
117 {
118 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,PKCS7_R_UNKNOWN_DIGEST_TYPE);
119 goto err;
120 }
121
122 BIO_set_md(btmp,md);
123 if (*pbio == NULL)
124 *pbio=btmp;
125 else if (!BIO_push(*pbio,btmp))
126 {
127 PKCS7err(PKCS7_F_PKCS7_BIO_ADD_DIGEST,ERR_R_BIO_LIB);
128 goto err;
129 }
130 btmp=NULL;
131
132 return 1;
133
134 err:
135 if (btmp)
136 BIO_free(btmp);
137 return 0;
138
139 }
140
141BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio) 104BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
142 { 105 {
143 int i; 106 int i;
144 BIO *out=NULL,*btmp=NULL; 107 BIO *out=NULL,*btmp=NULL;
145 X509_ALGOR *xa = NULL; 108 X509_ALGOR *xa;
109 const EVP_MD *evp_md;
146 const EVP_CIPHER *evp_cipher=NULL; 110 const EVP_CIPHER *evp_cipher=NULL;
147 STACK_OF(X509_ALGOR) *md_sk=NULL; 111 STACK_OF(X509_ALGOR) *md_sk=NULL;
148 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL; 112 STACK_OF(PKCS7_RECIP_INFO) *rsk=NULL;
149 X509_ALGOR *xalg=NULL; 113 X509_ALGOR *xalg=NULL;
150 PKCS7_RECIP_INFO *ri=NULL; 114 PKCS7_RECIP_INFO *ri=NULL;
151 EVP_PKEY *pkey; 115 EVP_PKEY *pkey;
152 ASN1_OCTET_STRING *os=NULL;
153 116
154 i=OBJ_obj2nid(p7->type); 117 i=OBJ_obj2nid(p7->type);
155 p7->state=PKCS7_S_HEADER; 118 p7->state=PKCS7_S_HEADER;
@@ -158,7 +121,6 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
158 { 121 {
159 case NID_pkcs7_signed: 122 case NID_pkcs7_signed:
160 md_sk=p7->d.sign->md_algs; 123 md_sk=p7->d.sign->md_algs;
161 os = PKCS7_get_octet_string(p7->d.sign->contents);
162 break; 124 break;
163 case NID_pkcs7_signedAndEnveloped: 125 case NID_pkcs7_signedAndEnveloped:
164 rsk=p7->d.signed_and_enveloped->recipientinfo; 126 rsk=p7->d.signed_and_enveloped->recipientinfo;
@@ -183,21 +145,37 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
183 goto err; 145 goto err;
184 } 146 }
185 break; 147 break;
186 case NID_pkcs7_digest:
187 xa = p7->d.digest->md;
188 os = PKCS7_get_octet_string(p7->d.digest->contents);
189 break;
190 default: 148 default:
191 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); 149 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
192 goto err; 150 goto err;
193 } 151 }
194 152
195 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++) 153 if (md_sk != NULL)
196 if (!PKCS7_bio_add_digest(&out, sk_X509_ALGOR_value(md_sk, i))) 154 {
197 goto err; 155 for (i=0; i<sk_X509_ALGOR_num(md_sk); i++)
156 {
157 xa=sk_X509_ALGOR_value(md_sk,i);
158 if ((btmp=BIO_new(BIO_f_md())) == NULL)
159 {
160 PKCS7err(PKCS7_F_PKCS7_DATAINIT,ERR_R_BIO_LIB);
161 goto err;
162 }
198 163
199 if (xa && !PKCS7_bio_add_digest(&out, xa)) 164 evp_md=EVP_get_digestbyobj(xa->algorithm);
200 goto err; 165 if (evp_md == NULL)
166 {
167 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_UNKNOWN_DIGEST_TYPE);
168 goto err;
169 }
170
171 BIO_set_md(btmp,evp_md);
172 if (out == NULL)
173 out=btmp;
174 else
175 BIO_push(out,btmp);
176 btmp=NULL;
177 }
178 }
201 179
202 if (evp_cipher != NULL) 180 if (evp_cipher != NULL)
203 { 181 {
@@ -216,25 +194,17 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
216 BIO_get_cipher_ctx(btmp, &ctx); 194 BIO_get_cipher_ctx(btmp, &ctx);
217 keylen=EVP_CIPHER_key_length(evp_cipher); 195 keylen=EVP_CIPHER_key_length(evp_cipher);
218 ivlen=EVP_CIPHER_iv_length(evp_cipher); 196 ivlen=EVP_CIPHER_iv_length(evp_cipher);
219 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher)); 197 if (RAND_bytes(key,keylen) <= 0)
220 if (ivlen > 0)
221 if (RAND_pseudo_bytes(iv,ivlen) <= 0)
222 goto err;
223 if (EVP_CipherInit_ex(ctx, evp_cipher, NULL, NULL, NULL, 1)<=0)
224 goto err;
225 if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0)
226 goto err;
227 if (EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, 1) <= 0)
228 goto err; 198 goto err;
199 xalg->algorithm = OBJ_nid2obj(EVP_CIPHER_type(evp_cipher));
200 if (ivlen > 0) RAND_pseudo_bytes(iv,ivlen);
201 EVP_CipherInit_ex(ctx, evp_cipher, NULL, key, iv, 1);
229 202
230 if (ivlen > 0) { 203 if (ivlen > 0) {
231 if (xalg->parameter == NULL) { 204 if (xalg->parameter == NULL)
232 xalg->parameter = ASN1_TYPE_new(); 205 xalg->parameter=ASN1_TYPE_new();
233 if (xalg->parameter == NULL)
234 goto err;
235 }
236 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0) 206 if(EVP_CIPHER_param_to_asn1(ctx, xalg->parameter) < 0)
237 goto err; 207 goto err;
238 } 208 }
239 209
240 /* Lets do the pub key stuff :-) */ 210 /* Lets do the pub key stuff :-) */
@@ -247,8 +217,7 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
247 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO); 217 PKCS7err(PKCS7_F_PKCS7_DATAINIT,PKCS7_R_MISSING_CERIPEND_INFO);
248 goto err; 218 goto err;
249 } 219 }
250 if ((pkey=X509_get_pubkey(ri->cert)) == NULL) 220 pkey=X509_get_pubkey(ri->cert);
251 goto err;
252 jj=EVP_PKEY_size(pkey); 221 jj=EVP_PKEY_size(pkey);
253 EVP_PKEY_free(pkey); 222 EVP_PKEY_free(pkey);
254 if (max < jj) max=jj; 223 if (max < jj) max=jj;
@@ -261,8 +230,7 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
261 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) 230 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
262 { 231 {
263 ri=sk_PKCS7_RECIP_INFO_value(rsk,i); 232 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
264 if ((pkey=X509_get_pubkey(ri->cert)) == NULL) 233 pkey=X509_get_pubkey(ri->cert);
265 goto err;
266 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey); 234 jj=EVP_PKEY_encrypt(tmp,key,keylen,pkey);
267 EVP_PKEY_free(pkey); 235 EVP_PKEY_free(pkey);
268 if (jj <= 0) 236 if (jj <= 0)
@@ -293,16 +261,24 @@ BIO *PKCS7_dataInit(PKCS7 *p7, BIO *bio)
293 { 261 {
294 if (PKCS7_is_detached(p7)) 262 if (PKCS7_is_detached(p7))
295 bio=BIO_new(BIO_s_null()); 263 bio=BIO_new(BIO_s_null());
296 else if (os && os->length > 0) 264 else
297 bio = BIO_new_mem_buf(os->data, os->length);
298 if(bio == NULL)
299 { 265 {
300 bio=BIO_new(BIO_s_mem()); 266 if (PKCS7_type_is_signed(p7))
301 if (bio == NULL) 267 {
302 goto err; 268 ASN1_OCTET_STRING *os;
303 BIO_set_mem_eof_return(bio,0); 269 os = PKCS7_get_octet_string(
270 p7->d.sign->contents);
271 if (os && os->length > 0)
272 bio = BIO_new_mem_buf(os->data,
273 os->length);
274 }
275 if(bio == NULL)
276 {
277 bio=BIO_new(BIO_s_mem());
278 BIO_set_mem_eof_return(bio,0);
279 }
304 } 280 }
305 } 281 }
306 BIO_push(out,bio); 282 BIO_push(out,bio);
307 bio=NULL; 283 bio=NULL;
308 if (0) 284 if (0)
@@ -317,17 +293,6 @@ err:
317 return(out); 293 return(out);
318 } 294 }
319 295
320static int pkcs7_cmp_ri(PKCS7_RECIP_INFO *ri, X509 *pcert)
321 {
322 int ret;
323 ret = X509_NAME_cmp(ri->issuer_and_serial->issuer,
324 pcert->cert_info->issuer);
325 if (ret)
326 return ret;
327 return M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
328 ri->issuer_and_serial->serial);
329 }
330
331/* int */ 296/* int */
332BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert) 297BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
333 { 298 {
@@ -438,18 +403,18 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
438 * (if any) 403 * (if any)
439 */ 404 */
440 405
441 if (pcert) { 406 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) {
442 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++) { 407 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
443 ri=sk_PKCS7_RECIP_INFO_value(rsk,i); 408 if(!X509_NAME_cmp(ri->issuer_and_serial->issuer,
444 if (!pkcs7_cmp_ri(ri, pcert)) 409 pcert->cert_info->issuer) &&
445 break; 410 !M_ASN1_INTEGER_cmp(pcert->cert_info->serialNumber,
446 ri=NULL; 411 ri->issuer_and_serial->serial)) break;
447 } 412 ri=NULL;
448 if (ri == NULL) { 413 }
449 PKCS7err(PKCS7_F_PKCS7_DATADECODE, 414 if (ri == NULL) {
450 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE); 415 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
451 goto err; 416 PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE);
452 } 417 goto err;
453 } 418 }
454 419
455 jj=EVP_PKEY_size(pkey); 420 jj=EVP_PKEY_size(pkey);
@@ -460,46 +425,17 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
460 goto err; 425 goto err;
461 } 426 }
462 427
463 /* If we haven't got a certificate try each ri in turn */ 428 jj=EVP_PKEY_decrypt(tmp, M_ASN1_STRING_data(ri->enc_key),
464 429 M_ASN1_STRING_length(ri->enc_key), pkey);
465 if (pcert == NULL) 430 if (jj <= 0)
466 {
467 for (i=0; i<sk_PKCS7_RECIP_INFO_num(rsk); i++)
468 {
469 ri=sk_PKCS7_RECIP_INFO_value(rsk,i);
470 jj=EVP_PKEY_decrypt(tmp,
471 M_ASN1_STRING_data(ri->enc_key),
472 M_ASN1_STRING_length(ri->enc_key),
473 pkey);
474 if (jj > 0)
475 break;
476 ERR_clear_error();
477 ri = NULL;
478 }
479 if (ri == NULL)
480 {
481 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
482 PKCS7_R_NO_RECIPIENT_MATCHES_KEY);
483 goto err;
484 }
485 }
486 else
487 { 431 {
488 jj=EVP_PKEY_decrypt(tmp, 432 PKCS7err(PKCS7_F_PKCS7_DATADECODE,ERR_R_EVP_LIB);
489 M_ASN1_STRING_data(ri->enc_key), 433 goto err;
490 M_ASN1_STRING_length(ri->enc_key), pkey);
491 if (jj <= 0)
492 {
493 PKCS7err(PKCS7_F_PKCS7_DATADECODE,
494 ERR_R_EVP_LIB);
495 goto err;
496 }
497 } 434 }
498 435
499 evp_ctx=NULL; 436 evp_ctx=NULL;
500 BIO_get_cipher_ctx(etmp,&evp_ctx); 437 BIO_get_cipher_ctx(etmp,&evp_ctx);
501 if (EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0) <= 0) 438 EVP_CipherInit_ex(evp_ctx,evp_cipher,NULL,NULL,NULL,0);
502 goto err;
503 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0) 439 if (EVP_CIPHER_asn1_to_param(evp_ctx,enc_alg->parameter) < 0)
504 goto err; 440 goto err;
505 441
@@ -515,8 +451,7 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
515 goto err; 451 goto err;
516 } 452 }
517 } 453 }
518 if (EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0) <= 0) 454 EVP_CipherInit_ex(evp_ctx,NULL,NULL,tmp,NULL,0);
519 goto err;
520 455
521 OPENSSL_cleanse(tmp,jj); 456 OPENSSL_cleanse(tmp,jj);
522 457
@@ -550,8 +485,6 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert)
550 bio=BIO_new(BIO_s_mem()); 485 bio=BIO_new(BIO_s_mem());
551 BIO_set_mem_eof_return(bio,0); 486 BIO_set_mem_eof_return(bio,0);
552 } 487 }
553 if (bio == NULL)
554 goto err;
555#endif 488#endif
556 } 489 }
557 BIO_push(out,bio); 490 BIO_push(out,bio);
@@ -571,29 +504,6 @@ err:
571 return(out); 504 return(out);
572 } 505 }
573 506
574static BIO *PKCS7_find_digest(EVP_MD_CTX **pmd, BIO *bio, int nid)
575 {
576 for (;;)
577 {
578 bio=BIO_find_type(bio,BIO_TYPE_MD);
579 if (bio == NULL)
580 {
581 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
582 return NULL;
583 }
584 BIO_get_md_ctx(bio,pmd);
585 if (*pmd == NULL)
586 {
587 PKCS7err(PKCS7_F_PKCS7_FIND_DIGEST,ERR_R_INTERNAL_ERROR);
588 return NULL;
589 }
590 if (EVP_MD_CTX_type(*pmd) == nid)
591 return bio;
592 bio=BIO_next(bio);
593 }
594 return NULL;
595 }
596
597int PKCS7_dataFinal(PKCS7 *p7, BIO *bio) 507int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
598 { 508 {
599 int ret=0; 509 int ret=0;
@@ -618,7 +528,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
618 si_sk=p7->d.signed_and_enveloped->signer_info; 528 si_sk=p7->d.signed_and_enveloped->signer_info;
619 if (!(os=M_ASN1_OCTET_STRING_new())) 529 if (!(os=M_ASN1_OCTET_STRING_new()))
620 { 530 {
621 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE); 531 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
622 goto err; 532 goto err;
623 } 533 }
624 p7->d.signed_and_enveloped->enc_data->enc_data=os; 534 p7->d.signed_and_enveloped->enc_data->enc_data=os;
@@ -627,7 +537,7 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
627 /* XXXXXXXXXXXXXXXX */ 537 /* XXXXXXXXXXXXXXXX */
628 if (!(os=M_ASN1_OCTET_STRING_new())) 538 if (!(os=M_ASN1_OCTET_STRING_new()))
629 { 539 {
630 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_MALLOC_FAILURE); 540 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_MALLOC_FAILURE);
631 goto err; 541 goto err;
632 } 542 }
633 p7->d.enveloped->enc_data->enc_data=os; 543 p7->d.enveloped->enc_data->enc_data=os;
@@ -641,24 +551,13 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
641 p7->d.sign->contents->d.data = NULL; 551 p7->d.sign->contents->d.data = NULL;
642 } 552 }
643 break; 553 break;
644
645 case NID_pkcs7_digest:
646 os=PKCS7_get_octet_string(p7->d.digest->contents);
647 /* If detached data then the content is excluded */
648 if(PKCS7_type_is_data(p7->d.digest->contents) && p7->detached)
649 {
650 M_ASN1_OCTET_STRING_free(os);
651 p7->d.digest->contents->d.data = NULL;
652 }
653 break;
654
655 } 554 }
656 555
657 if (si_sk != NULL) 556 if (si_sk != NULL)
658 { 557 {
659 if ((buf=BUF_MEM_new()) == NULL) 558 if ((buf=BUF_MEM_new()) == NULL)
660 { 559 {
661 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB); 560 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
662 goto err; 561 goto err;
663 } 562 }
664 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++) 563 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(si_sk); i++)
@@ -669,18 +568,32 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
669 j=OBJ_obj2nid(si->digest_alg->algorithm); 568 j=OBJ_obj2nid(si->digest_alg->algorithm);
670 569
671 btmp=bio; 570 btmp=bio;
672 571 for (;;)
673 btmp = PKCS7_find_digest(&mdc, btmp, j); 572 {
674 573 if ((btmp=BIO_find_type(btmp,BIO_TYPE_MD))
675 if (btmp == NULL) 574 == NULL)
676 goto err; 575 {
677 576 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MESSAGE_DIGEST);
577 goto err;
578 }
579 BIO_get_md_ctx(btmp,&mdc);
580 if (mdc == NULL)
581 {
582 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_INTERNAL_ERROR);
583 goto err;
584 }
585 if (EVP_MD_CTX_type(mdc) == j)
586 break;
587 else
588 btmp=BIO_next(btmp);
589 }
590
678 /* We now have the EVP_MD_CTX, lets do the 591 /* We now have the EVP_MD_CTX, lets do the
679 * signing. */ 592 * signing. */
680 EVP_MD_CTX_copy_ex(&ctx_tmp,mdc); 593 EVP_MD_CTX_copy_ex(&ctx_tmp,mdc);
681 if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey))) 594 if (!BUF_MEM_grow_clean(buf,EVP_PKEY_size(si->pkey)))
682 { 595 {
683 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_BIO_LIB); 596 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_BIO_LIB);
684 goto err; 597 goto err;
685 } 598 }
686 599
@@ -702,17 +615,13 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
702 { 615 {
703 if (!(sign_time=X509_gmtime_adj(NULL,0))) 616 if (!(sign_time=X509_gmtime_adj(NULL,0)))
704 { 617 {
705 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 618 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
706 ERR_R_MALLOC_FAILURE); 619 ERR_R_MALLOC_FAILURE);
707 goto err; 620 goto err;
708 } 621 }
709 if (!PKCS7_add_signed_attribute(si, 622 PKCS7_add_signed_attribute(si,
710 NID_pkcs9_signingTime, 623 NID_pkcs9_signingTime,
711 V_ASN1_UTCTIME,sign_time)) 624 V_ASN1_UTCTIME,sign_time);
712 {
713 M_ASN1_UTCTIME_free(sign_time);
714 goto err;
715 }
716 } 625 }
717 626
718 /* Add digest */ 627 /* Add digest */
@@ -720,25 +629,20 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
720 EVP_DigestFinal_ex(&ctx_tmp,md_data,&md_len); 629 EVP_DigestFinal_ex(&ctx_tmp,md_data,&md_len);
721 if (!(digest=M_ASN1_OCTET_STRING_new())) 630 if (!(digest=M_ASN1_OCTET_STRING_new()))
722 { 631 {
723 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 632 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
724 ERR_R_MALLOC_FAILURE); 633 ERR_R_MALLOC_FAILURE);
725 goto err; 634 goto err;
726 } 635 }
727 if (!M_ASN1_OCTET_STRING_set(digest,md_data, 636 if (!M_ASN1_OCTET_STRING_set(digest,md_data,
728 md_len)) 637 md_len))
729 { 638 {
730 PKCS7err(PKCS7_F_PKCS7_DATAFINAL, 639 PKCS7err(PKCS7_F_PKCS7_DATASIGN,
731 ERR_R_MALLOC_FAILURE); 640 ERR_R_MALLOC_FAILURE);
732 M_ASN1_OCTET_STRING_free(digest);
733 goto err; 641 goto err;
734 } 642 }
735 if (!PKCS7_add_signed_attribute(si, 643 PKCS7_add_signed_attribute(si,
736 NID_pkcs9_messageDigest, 644 NID_pkcs9_messageDigest,
737 V_ASN1_OCTET_STRING,digest)) 645 V_ASN1_OCTET_STRING,digest);
738 {
739 M_ASN1_OCTET_STRING_free(digest);
740 goto err;
741 }
742 646
743 /* Now sign the attributes */ 647 /* Now sign the attributes */
744 EVP_SignInit_ex(&ctx_tmp,md_tmp,NULL); 648 EVP_SignInit_ex(&ctx_tmp,md_tmp,NULL);
@@ -753,42 +657,28 @@ int PKCS7_dataFinal(PKCS7 *p7, BIO *bio)
753 if (si->pkey->type == EVP_PKEY_DSA) 657 if (si->pkey->type == EVP_PKEY_DSA)
754 ctx_tmp.digest=EVP_dss1(); 658 ctx_tmp.digest=EVP_dss1();
755#endif 659#endif
756#ifndef OPENSSL_NO_ECDSA
757 if (si->pkey->type == EVP_PKEY_EC)
758 ctx_tmp.digest=EVP_ecdsa();
759#endif
760 660
761 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data, 661 if (!EVP_SignFinal(&ctx_tmp,(unsigned char *)buf->data,
762 (unsigned int *)&buf->length,si->pkey)) 662 (unsigned int *)&buf->length,si->pkey))
763 { 663 {
764 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_EVP_LIB); 664 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_EVP_LIB);
765 goto err; 665 goto err;
766 } 666 }
767 if (!ASN1_STRING_set(si->enc_digest, 667 if (!ASN1_STRING_set(si->enc_digest,
768 (unsigned char *)buf->data,buf->length)) 668 (unsigned char *)buf->data,buf->length))
769 { 669 {
770 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,ERR_R_ASN1_LIB); 670 PKCS7err(PKCS7_F_PKCS7_DATASIGN,ERR_R_ASN1_LIB);
771 goto err; 671 goto err;
772 } 672 }
773 } 673 }
774 } 674 }
775 else if (i == NID_pkcs7_digest)
776 {
777 unsigned char md_data[EVP_MAX_MD_SIZE];
778 unsigned int md_len;
779 if (!PKCS7_find_digest(&mdc, bio,
780 OBJ_obj2nid(p7->d.digest->md->algorithm)))
781 goto err;
782 EVP_DigestFinal_ex(mdc,md_data,&md_len);
783 M_ASN1_OCTET_STRING_set(p7->d.digest->digest, md_data, md_len);
784 }
785 675
786 if (!PKCS7_is_detached(p7)) 676 if (!PKCS7_is_detached(p7))
787 { 677 {
788 btmp=BIO_find_type(bio,BIO_TYPE_MEM); 678 btmp=BIO_find_type(bio,BIO_TYPE_MEM);
789 if (btmp == NULL) 679 if (btmp == NULL)
790 { 680 {
791 PKCS7err(PKCS7_F_PKCS7_DATAFINAL,PKCS7_R_UNABLE_TO_FIND_MEM_BIO); 681 PKCS7err(PKCS7_F_PKCS7_DATASIGN,PKCS7_R_UNABLE_TO_FIND_MEM_BIO);
792 goto err; 682 goto err;
793 } 683 }
794 BIO_get_mem_ptr(btmp,&buf_mem); 684 BIO_get_mem_ptr(btmp,&buf_mem);
@@ -969,9 +859,6 @@ for (ii=0; ii<md_len; ii++) printf("%02X",md_dat[ii]); printf(" calc\n");
969#ifndef OPENSSL_NO_DSA 859#ifndef OPENSSL_NO_DSA
970 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1(); 860 if(pkey->type == EVP_PKEY_DSA) mdc_tmp.digest=EVP_dss1();
971#endif 861#endif
972#ifndef OPENSSL_NO_ECDSA
973 if (pkey->type == EVP_PKEY_EC) mdc_tmp.digest=EVP_ecdsa();
974#endif
975 862
976 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey); 863 i=EVP_VerifyFinal(&mdc_tmp,os->data,os->length, pkey);
977 EVP_PKEY_free(pkey); 864 EVP_PKEY_free(pkey);
@@ -996,13 +883,8 @@ PKCS7_ISSUER_AND_SERIAL *PKCS7_get_issuer_and_serial(PKCS7 *p7, int idx)
996 int i; 883 int i;
997 884
998 i=OBJ_obj2nid(p7->type); 885 i=OBJ_obj2nid(p7->type);
999 if (i != NID_pkcs7_signedAndEnveloped) 886 if (i != NID_pkcs7_signedAndEnveloped) return(NULL);
1000 return NULL;
1001 if (p7->d.signed_and_enveloped == NULL)
1002 return NULL;
1003 rsk=p7->d.signed_and_enveloped->recipientinfo; 887 rsk=p7->d.signed_and_enveloped->recipientinfo;
1004 if (rsk == NULL)
1005 return NULL;
1006 ri=sk_PKCS7_RECIP_INFO_value(rsk,0); 888 ri=sk_PKCS7_RECIP_INFO_value(rsk,0);
1007 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL); 889 if (sk_PKCS7_RECIP_INFO_num(rsk) <= idx) return(NULL);
1008 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx); 890 ri=sk_PKCS7_RECIP_INFO_value(rsk,idx);
@@ -1056,8 +938,6 @@ int PKCS7_set_signed_attributes(PKCS7_SIGNER_INFO *p7si,
1056 if (p7si->auth_attr != NULL) 938 if (p7si->auth_attr != NULL)
1057 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free); 939 sk_X509_ATTRIBUTE_pop_free(p7si->auth_attr,X509_ATTRIBUTE_free);
1058 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk); 940 p7si->auth_attr=sk_X509_ATTRIBUTE_dup(sk);
1059 if (p7si->auth_attr == NULL)
1060 return 0;
1061 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) 941 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
1062 { 942 {
1063 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i, 943 if ((sk_X509_ATTRIBUTE_set(p7si->auth_attr,i,
@@ -1076,8 +956,6 @@ int PKCS7_set_attributes(PKCS7_SIGNER_INFO *p7si, STACK_OF(X509_ATTRIBUTE) *sk)
1076 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr, 956 sk_X509_ATTRIBUTE_pop_free(p7si->unauth_attr,
1077 X509_ATTRIBUTE_free); 957 X509_ATTRIBUTE_free);
1078 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk); 958 p7si->unauth_attr=sk_X509_ATTRIBUTE_dup(sk);
1079 if (p7si->unauth_attr == NULL)
1080 return 0;
1081 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++) 959 for (i=0; i<sk_X509_ATTRIBUTE_num(sk); i++)
1082 { 960 {
1083 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i, 961 if ((sk_X509_ATTRIBUTE_set(p7si->unauth_attr,i,
@@ -1107,16 +985,10 @@ static int add_attribute(STACK_OF(X509_ATTRIBUTE) **sk, int nid, int atrtype,
1107 985
1108 if (*sk == NULL) 986 if (*sk == NULL)
1109 { 987 {
1110 if (!(*sk = sk_X509_ATTRIBUTE_new_null())) 988 *sk = sk_X509_ATTRIBUTE_new_null();
1111 return 0;
1112new_attrib: 989new_attrib:
1113 if (!(attr=X509_ATTRIBUTE_create(nid,atrtype,value))) 990 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
1114 return 0; 991 sk_X509_ATTRIBUTE_push(*sk,attr);
1115 if (!sk_X509_ATTRIBUTE_push(*sk,attr))
1116 {
1117 X509_ATTRIBUTE_free(attr);
1118 return 0;
1119 }
1120 } 992 }
1121 else 993 else
1122 { 994 {
@@ -1129,13 +1001,7 @@ new_attrib:
1129 { 1001 {
1130 X509_ATTRIBUTE_free(attr); 1002 X509_ATTRIBUTE_free(attr);
1131 attr=X509_ATTRIBUTE_create(nid,atrtype,value); 1003 attr=X509_ATTRIBUTE_create(nid,atrtype,value);
1132 if (attr == NULL) 1004 sk_X509_ATTRIBUTE_set(*sk,i,attr);
1133 return 0;
1134 if (!sk_X509_ATTRIBUTE_set(*sk,i,attr))
1135 {
1136 X509_ATTRIBUTE_free(attr);
1137 return 0;
1138 }
1139 goto end; 1005 goto end;
1140 } 1006 }
1141 } 1007 }
diff --git a/src/lib/libcrypto/pkcs7/pk7_enc.c b/src/lib/libcrypto/pkcs7/pk7_enc.c
new file mode 100644
index 0000000000..acbb189c59
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/pk7_enc.c
@@ -0,0 +1,76 @@
1/* crypto/pkcs7/pk7_enc.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/evp.h>
62#include <openssl/rand.h>
63#include <openssl/objects.h>
64#include <openssl/x509.h>
65#include <openssl/pkcs7.h>
66
67PKCS7_in_bio(PKCS7 *p7,BIO *in);
68PKCS7_out_bio(PKCS7 *p7,BIO *out);
69
70PKCS7_add_signer(PKCS7 *p7,X509 *cert,EVP_PKEY *key);
71PKCS7_cipher(PKCS7 *p7,EVP_CIPHER *cipher);
72
73PKCS7_Init(PKCS7 *p7);
74PKCS7_Update(PKCS7 *p7);
75PKCS7_Finish(PKCS7 *p7);
76
diff --git a/src/lib/libcrypto/pkcs7/pk7_lib.c b/src/lib/libcrypto/pkcs7/pk7_lib.c
index f2490941a3..ee1817c7af 100644
--- a/src/lib/libcrypto/pkcs7/pk7_lib.c
+++ b/src/lib/libcrypto/pkcs7/pk7_lib.c
@@ -138,10 +138,6 @@ int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data)
138 p7->d.sign->contents=p7_data; 138 p7->d.sign->contents=p7_data;
139 break; 139 break;
140 case NID_pkcs7_digest: 140 case NID_pkcs7_digest:
141 if (p7->d.digest->contents != NULL)
142 PKCS7_free(p7->d.digest->contents);
143 p7->d.digest->contents=p7_data;
144 break;
145 case NID_pkcs7_data: 141 case NID_pkcs7_data:
146 case NID_pkcs7_enveloped: 142 case NID_pkcs7_enveloped:
147 case NID_pkcs7_signedAndEnveloped: 143 case NID_pkcs7_signedAndEnveloped:
@@ -210,12 +206,6 @@ int PKCS7_set_type(PKCS7 *p7, int type)
210 break; 206 break;
211 207
212 case NID_pkcs7_digest: 208 case NID_pkcs7_digest:
213 p7->type=obj;
214 if ((p7->d.digest=PKCS7_DIGEST_new())
215 == NULL) goto err;
216 if (!ASN1_INTEGER_set(p7->d.digest->version,0))
217 goto err;
218 break;
219 default: 209 default:
220 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE); 210 PKCS7err(PKCS7_F_PKCS7_SET_TYPE,PKCS7_R_UNSUPPORTED_CONTENT_TYPE);
221 goto err; 211 goto err;
@@ -225,13 +215,6 @@ err:
225 return(0); 215 return(0);
226 } 216 }
227 217
228int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other)
229 {
230 p7->type = OBJ_nid2obj(type);
231 p7->d.other = other;
232 return 1;
233 }
234
235int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi) 218int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
236 { 219 {
237 int i,j,nid; 220 int i,j,nid;
@@ -271,23 +254,16 @@ int PKCS7_add_signer(PKCS7 *p7, PKCS7_SIGNER_INFO *psi)
271 if (!j) /* we need to add another algorithm */ 254 if (!j) /* we need to add another algorithm */
272 { 255 {
273 if(!(alg=X509_ALGOR_new()) 256 if(!(alg=X509_ALGOR_new())
274 || !(alg->parameter = ASN1_TYPE_new())) 257 || !(alg->parameter = ASN1_TYPE_new())) {
275 {
276 X509_ALGOR_free(alg);
277 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE); 258 PKCS7err(PKCS7_F_PKCS7_ADD_SIGNER,ERR_R_MALLOC_FAILURE);
278 return(0); 259 return(0);
279 } 260 }
280 alg->algorithm=OBJ_nid2obj(nid); 261 alg->algorithm=OBJ_nid2obj(nid);
281 alg->parameter->type = V_ASN1_NULL; 262 alg->parameter->type = V_ASN1_NULL;
282 if (!sk_X509_ALGOR_push(md_sk,alg)) 263 sk_X509_ALGOR_push(md_sk,alg);
283 {
284 X509_ALGOR_free(alg);
285 return 0;
286 }
287 } 264 }
288 265
289 if (!sk_PKCS7_SIGNER_INFO_push(signer_sk,psi)) 266 sk_PKCS7_SIGNER_INFO_push(signer_sk,psi);
290 return 0;
291 return(1); 267 return(1);
292 } 268 }
293 269
@@ -312,17 +288,8 @@ int PKCS7_add_certificate(PKCS7 *p7, X509 *x509)
312 288
313 if (*sk == NULL) 289 if (*sk == NULL)
314 *sk=sk_X509_new_null(); 290 *sk=sk_X509_new_null();
315 if (*sk == NULL)
316 {
317 PKCS7err(PKCS7_F_PKCS7_ADD_CERTIFICATE,ERR_R_MALLOC_FAILURE);
318 return 0;
319 }
320 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509); 291 CRYPTO_add(&x509->references,1,CRYPTO_LOCK_X509);
321 if (!sk_X509_push(*sk,x509)) 292 sk_X509_push(*sk,x509);
322 {
323 X509_free(x509);
324 return 0;
325 }
326 return(1); 293 return(1);
327 } 294 }
328 295
@@ -347,31 +314,18 @@ int PKCS7_add_crl(PKCS7 *p7, X509_CRL *crl)
347 314
348 if (*sk == NULL) 315 if (*sk == NULL)
349 *sk=sk_X509_CRL_new_null(); 316 *sk=sk_X509_CRL_new_null();
350 if (*sk == NULL)
351 {
352 PKCS7err(PKCS7_F_PKCS7_ADD_CRL,ERR_R_MALLOC_FAILURE);
353 return 0;
354 }
355 317
356 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL); 318 CRYPTO_add(&crl->references,1,CRYPTO_LOCK_X509_CRL);
357 if (!sk_X509_CRL_push(*sk,crl)) 319 sk_X509_CRL_push(*sk,crl);
358 {
359 X509_CRL_free(crl);
360 return 0;
361 }
362 return(1); 320 return(1);
363 } 321 }
364 322
365int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, 323int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
366 const EVP_MD *dgst) 324 const EVP_MD *dgst)
367 { 325 {
368 int nid;
369 char is_dsa; 326 char is_dsa;
370 327 if (pkey->type == EVP_PKEY_DSA) is_dsa = 1;
371 if (pkey->type == EVP_PKEY_DSA || pkey->type == EVP_PKEY_EC) 328 else is_dsa = 0;
372 is_dsa = 1;
373 else
374 is_dsa = 0;
375 /* We now need to add another PKCS7_SIGNER_INFO entry */ 329 /* We now need to add another PKCS7_SIGNER_INFO entry */
376 if (!ASN1_INTEGER_set(p7i->version,1)) 330 if (!ASN1_INTEGER_set(p7i->version,1))
377 goto err; 331 goto err;
@@ -401,38 +355,16 @@ int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
401 goto err; 355 goto err;
402 p7i->digest_alg->parameter->type=V_ASN1_NULL; 356 p7i->digest_alg->parameter->type=V_ASN1_NULL;
403 357
358 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(EVP_PKEY_type(pkey->type));
359
404 if (p7i->digest_enc_alg->parameter != NULL) 360 if (p7i->digest_enc_alg->parameter != NULL)
405 ASN1_TYPE_free(p7i->digest_enc_alg->parameter); 361 ASN1_TYPE_free(p7i->digest_enc_alg->parameter);
406 nid = EVP_PKEY_type(pkey->type); 362 if(is_dsa) p7i->digest_enc_alg->parameter = NULL;
407 if (nid == EVP_PKEY_RSA) 363 else {
408 {
409 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_rsaEncryption);
410 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
411 goto err;
412 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
413 }
414 else if (nid == EVP_PKEY_DSA)
415 {
416#if 1
417 /* use 'dsaEncryption' OID for compatibility with other software
418 * (PKCS #7 v1.5 does specify how to handle DSA) ... */
419 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_dsa);
420#else
421 /* ... although the 'dsaWithSHA1' OID (as required by RFC 2630 for CMS)
422 * would make more sense. */
423 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_dsaWithSHA1);
424#endif
425 p7i->digest_enc_alg->parameter = NULL; /* special case for DSA: omit 'parameter'! */
426 }
427 else if (nid == EVP_PKEY_EC)
428 {
429 p7i->digest_enc_alg->algorithm=OBJ_nid2obj(NID_ecdsa_with_SHA1);
430 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new())) 364 if (!(p7i->digest_enc_alg->parameter=ASN1_TYPE_new()))
431 goto err; 365 goto err;
432 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL; 366 p7i->digest_enc_alg->parameter->type=V_ASN1_NULL;
433 } 367 }
434 else
435 return(0);
436 368
437 return(1); 369 return(1);
438err: 370err:
@@ -449,28 +381,9 @@ PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, EVP_PKEY *pkey,
449 if (!PKCS7_add_signer(p7,si)) goto err; 381 if (!PKCS7_add_signer(p7,si)) goto err;
450 return(si); 382 return(si);
451err: 383err:
452 PKCS7_SIGNER_INFO_free(si);
453 return(NULL); 384 return(NULL);
454 } 385 }
455 386
456int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md)
457 {
458 if (PKCS7_type_is_digest(p7))
459 {
460 if(!(p7->d.digest->md->parameter = ASN1_TYPE_new()))
461 {
462 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST,ERR_R_MALLOC_FAILURE);
463 return 0;
464 }
465 p7->d.digest->md->parameter->type = V_ASN1_NULL;
466 p7->d.digest->md->algorithm = OBJ_nid2obj(EVP_MD_nid(md));
467 return 1;
468 }
469
470 PKCS7err(PKCS7_F_PKCS7_SET_DIGEST,PKCS7_R_WRONG_CONTENT_TYPE);
471 return 1;
472 }
473
474STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7) 387STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7)
475 { 388 {
476 if (PKCS7_type_is_signed(p7)) 389 if (PKCS7_type_is_signed(p7))
@@ -494,7 +407,6 @@ PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509)
494 if (!PKCS7_add_recipient_info(p7,ri)) goto err; 407 if (!PKCS7_add_recipient_info(p7,ri)) goto err;
495 return(ri); 408 return(ri);
496err: 409err:
497 PKCS7_RECIP_INFO_free(ri);
498 return(NULL); 410 return(NULL);
499 } 411 }
500 412
@@ -517,8 +429,7 @@ int PKCS7_add_recipient_info(PKCS7 *p7, PKCS7_RECIP_INFO *ri)
517 return(0); 429 return(0);
518 } 430 }
519 431
520 if (!sk_PKCS7_RECIP_INFO_push(sk,ri)) 432 sk_PKCS7_RECIP_INFO_push(sk,ri);
521 return 0;
522 return(1); 433 return(1);
523 } 434 }
524 435
diff --git a/src/lib/libcrypto/pkcs7/pk7_mime.c b/src/lib/libcrypto/pkcs7/pk7_mime.c
index 17b68992f7..927b88c3e7 100644
--- a/src/lib/libcrypto/pkcs7/pk7_mime.c
+++ b/src/lib/libcrypto/pkcs7/pk7_mime.c
@@ -1,6 +1,6 @@
1/* pk7_mime.c */ 1/* pk7_mime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
@@ -86,7 +86,6 @@ STACK_OF(MIME_PARAM) *params; /* Zero or more parameters */
86DECLARE_STACK_OF(MIME_HEADER) 86DECLARE_STACK_OF(MIME_HEADER)
87IMPLEMENT_STACK_OF(MIME_HEADER) 87IMPLEMENT_STACK_OF(MIME_HEADER)
88 88
89static int pkcs7_output_data(BIO *bio, BIO *data, PKCS7 *p7, int flags);
90static int B64_write_PKCS7(BIO *bio, PKCS7 *p7); 89static int B64_write_PKCS7(BIO *bio, PKCS7 *p7);
91static PKCS7 *B64_read_PKCS7(BIO *bio); 90static PKCS7 *B64_read_PKCS7(BIO *bio);
92static char * strip_ends(char *name); 91static char * strip_ends(char *name);
@@ -110,6 +109,9 @@ static void mime_hdr_free(MIME_HEADER *hdr);
110#define MAX_SMLEN 1024 109#define MAX_SMLEN 1024
111#define mime_debug(x) /* x */ 110#define mime_debug(x) /* x */
112 111
112
113typedef void (*stkfree)();
114
113/* Base 64 read and write of PKCS#7 structure */ 115/* Base 64 read and write of PKCS#7 structure */
114 116
115static int B64_write_PKCS7(BIO *bio, PKCS7 *p7) 117static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
@@ -121,7 +123,7 @@ static int B64_write_PKCS7(BIO *bio, PKCS7 *p7)
121 } 123 }
122 bio = BIO_push(b64, bio); 124 bio = BIO_push(b64, bio);
123 i2d_PKCS7_bio(bio, p7); 125 i2d_PKCS7_bio(bio, p7);
124 (void)BIO_flush(bio); 126 BIO_flush(bio);
125 bio = BIO_pop(bio); 127 bio = BIO_pop(bio);
126 BIO_free(b64); 128 BIO_free(b64);
127 return 1; 129 return 1;
@@ -138,7 +140,7 @@ static PKCS7 *B64_read_PKCS7(BIO *bio)
138 bio = BIO_push(b64, bio); 140 bio = BIO_push(b64, bio);
139 if(!(p7 = d2i_PKCS7_bio(bio, NULL))) 141 if(!(p7 = d2i_PKCS7_bio(bio, NULL)))
140 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR); 142 PKCS7err(PKCS7_F_B64_READ_PKCS7,PKCS7_R_DECODE_ERROR);
141 (void)BIO_flush(bio); 143 BIO_flush(bio);
142 bio = BIO_pop(bio); 144 bio = BIO_pop(bio);
143 BIO_free(b64); 145 BIO_free(b64);
144 return p7; 146 return p7;
@@ -180,7 +182,7 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
180 mime_eol, mime_eol); 182 mime_eol, mime_eol);
181 /* Now write out the first part */ 183 /* Now write out the first part */
182 BIO_printf(bio, "------%s%s", bound, mime_eol); 184 BIO_printf(bio, "------%s%s", bound, mime_eol);
183 pkcs7_output_data(bio, data, p7, flags); 185 SMIME_crlf_copy(data, bio, flags);
184 BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol); 186 BIO_printf(bio, "%s------%s%s", mime_eol, bound, mime_eol);
185 187
186 /* Headers for signature */ 188 /* Headers for signature */
@@ -194,7 +196,7 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
194 mime_eol, mime_eol); 196 mime_eol, mime_eol);
195 B64_write_PKCS7(bio, p7); 197 B64_write_PKCS7(bio, p7);
196 BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound, 198 BIO_printf(bio,"%s------%s--%s%s", mime_eol, bound,
197 mime_eol, mime_eol); 199 mime_eol, mime_eol);
198 return 1; 200 return 1;
199 } 201 }
200 202
@@ -229,46 +231,6 @@ int SMIME_write_PKCS7(BIO *bio, PKCS7 *p7, BIO *data, int flags)
229 return 1; 231 return 1;
230} 232}
231 233
232/* Handle output of PKCS#7 data */
233
234
235static int pkcs7_output_data(BIO *out, BIO *data, PKCS7 *p7, int flags)
236 {
237 BIO *tmpbio, *p7bio;
238
239 if (!(flags & PKCS7_STREAM))
240 {
241 SMIME_crlf_copy(data, out, flags);
242 return 1;
243 }
244
245 /* Partial sign operation */
246
247 /* Initialize sign operation */
248 p7bio = PKCS7_dataInit(p7, out);
249
250 /* Copy data across, computing digests etc */
251 SMIME_crlf_copy(data, p7bio, flags);
252
253 /* Must be detached */
254 PKCS7_set_detached(p7, 1);
255
256 /* Finalize signatures */
257 PKCS7_dataFinal(p7, p7bio);
258
259 /* Now remove any digests prepended to the BIO */
260
261 while (p7bio != out)
262 {
263 tmpbio = BIO_pop(p7bio);
264 BIO_free(p7bio);
265 p7bio = tmpbio;
266 }
267
268 return 1;
269
270 }
271
272/* SMIME reader: handle multipart/signed and opaque signing. 234/* SMIME reader: handle multipart/signed and opaque signing.
273 * in multipart case the content is placed in a memory BIO 235 * in multipart case the content is placed in a memory BIO
274 * pointed to by "bcont". In opaque this is set to NULL 236 * pointed to by "bcont". In opaque this is set to NULL
@@ -377,6 +339,56 @@ PKCS7 *SMIME_read_PKCS7(BIO *bio, BIO **bcont)
377 339
378} 340}
379 341
342/* Copy text from one BIO to another making the output CRLF at EOL */
343int SMIME_crlf_copy(BIO *in, BIO *out, int flags)
344{
345 char eol;
346 int len;
347 char linebuf[MAX_SMLEN];
348 if(flags & PKCS7_BINARY) {
349 while((len = BIO_read(in, linebuf, MAX_SMLEN)) > 0)
350 BIO_write(out, linebuf, len);
351 return 1;
352 }
353 if(flags & PKCS7_TEXT) BIO_printf(out, "Content-Type: text/plain\r\n\r\n");
354 while ((len = BIO_gets(in, linebuf, MAX_SMLEN)) > 0) {
355 eol = strip_eol(linebuf, &len);
356 if (len)
357 BIO_write(out, linebuf, len);
358 if(eol) BIO_write(out, "\r\n", 2);
359 }
360 return 1;
361}
362
363/* Strip off headers if they are text/plain */
364int SMIME_text(BIO *in, BIO *out)
365{
366 char iobuf[4096];
367 int len;
368 STACK_OF(MIME_HEADER) *headers;
369 MIME_HEADER *hdr;
370
371 if (!(headers = mime_parse_hdr(in))) {
372 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_PARSE_ERROR);
373 return 0;
374 }
375 if(!(hdr = mime_hdr_find(headers, "content-type")) || !hdr->value) {
376 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_MIME_NO_CONTENT_TYPE);
377 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
378 return 0;
379 }
380 if (strcmp (hdr->value, "text/plain")) {
381 PKCS7err(PKCS7_F_SMIME_TEXT,PKCS7_R_INVALID_MIME_TYPE);
382 ERR_add_error_data(2, "type: ", hdr->value);
383 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
384 return 0;
385 }
386 sk_MIME_HEADER_pop_free(headers, mime_hdr_free);
387 while ((len = BIO_read(in, iobuf, sizeof(iobuf))) > 0)
388 BIO_write(out, iobuf, len);
389 return 1;
390}
391
380/* Split a multipart/XXX message body into component parts: result is 392/* Split a multipart/XXX message body into component parts: result is
381 * canonical parts in a STACK of bios 393 * canonical parts in a STACK of bios
382 */ 394 */
diff --git a/src/lib/libcrypto/pkcs7/pk7_smime.c b/src/lib/libcrypto/pkcs7/pk7_smime.c
index 5c6b0fe24b..99a0d63f38 100644
--- a/src/lib/libcrypto/pkcs7/pk7_smime.c
+++ b/src/lib/libcrypto/pkcs7/pk7_smime.c
@@ -1,9 +1,9 @@
1/* pk7_smime.c */ 1/* pk7_smime.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -66,10 +66,10 @@
66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs, 66PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
67 BIO *data, int flags) 67 BIO *data, int flags)
68{ 68{
69 PKCS7 *p7 = NULL; 69 PKCS7 *p7;
70 PKCS7_SIGNER_INFO *si; 70 PKCS7_SIGNER_INFO *si;
71 BIO *p7bio = NULL; 71 BIO *p7bio;
72 STACK_OF(X509_ALGOR) *smcap = NULL; 72 STACK_OF(X509_ALGOR) *smcap;
73 int i; 73 int i;
74 74
75 if(!X509_check_private_key(signcert, pkey)) { 75 if(!X509_check_private_key(signcert, pkey)) {
@@ -82,87 +82,66 @@ PKCS7 *PKCS7_sign(X509 *signcert, EVP_PKEY *pkey, STACK_OF(X509) *certs,
82 return NULL; 82 return NULL;
83 } 83 }
84 84
85 if (!PKCS7_set_type(p7, NID_pkcs7_signed)) 85 PKCS7_set_type(p7, NID_pkcs7_signed);
86 goto err;
87 86
88 if (!PKCS7_content_new(p7, NID_pkcs7_data)) 87 PKCS7_content_new(p7, NID_pkcs7_data);
89 goto err;
90 88
91 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) { 89 if (!(si = PKCS7_add_signature(p7,signcert,pkey,EVP_sha1()))) {
92 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR); 90 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR);
93 goto err; 91 return NULL;
94 } 92 }
95 93
96 if(!(flags & PKCS7_NOCERTS)) { 94 if(!(flags & PKCS7_NOCERTS)) {
97 if (!PKCS7_add_certificate(p7, signcert)) 95 PKCS7_add_certificate(p7, signcert);
98 goto err;
99 if(certs) for(i = 0; i < sk_X509_num(certs); i++) 96 if(certs) for(i = 0; i < sk_X509_num(certs); i++)
100 if (!PKCS7_add_certificate(p7, sk_X509_value(certs, i))) 97 PKCS7_add_certificate(p7, sk_X509_value(certs, i));
101 goto err; 98 }
99
100 if(!(p7bio = PKCS7_dataInit(p7, NULL))) {
101 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
102 return NULL;
102 } 103 }
103 104
105
106 SMIME_crlf_copy(data, p7bio, flags);
107
104 if(!(flags & PKCS7_NOATTR)) { 108 if(!(flags & PKCS7_NOATTR)) {
105 if (!PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, 109 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType,
106 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data))) 110 V_ASN1_OBJECT, OBJ_nid2obj(NID_pkcs7_data));
107 goto err;
108 /* Add SMIMECapabilities */ 111 /* Add SMIMECapabilities */
109 if(!(flags & PKCS7_NOSMIMECAP)) 112 if(!(flags & PKCS7_NOSMIMECAP))
110 { 113 {
111 if(!(smcap = sk_X509_ALGOR_new_null())) { 114 if(!(smcap = sk_X509_ALGOR_new_null())) {
112 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE); 115 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
113 goto err; 116 return NULL;
114 } 117 }
115#ifndef OPENSSL_NO_DES 118#ifndef OPENSSL_NO_DES
116 if (!PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1)) 119 PKCS7_simple_smimecap (smcap, NID_des_ede3_cbc, -1);
117 goto err;
118#endif 120#endif
119#ifndef OPENSSL_NO_RC2 121#ifndef OPENSSL_NO_RC2
120 if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128)) 122 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 128);
121 goto err; 123 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64);
122 if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 64))
123 goto err;
124#endif 124#endif
125#ifndef OPENSSL_NO_DES 125#ifndef OPENSSL_NO_DES
126 if (!PKCS7_simple_smimecap (smcap, NID_des_cbc, -1)) 126 PKCS7_simple_smimecap (smcap, NID_des_cbc, -1);
127 goto err;
128#endif 127#endif
129#ifndef OPENSSL_NO_RC2 128#ifndef OPENSSL_NO_RC2
130 if (!PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40)) 129 PKCS7_simple_smimecap (smcap, NID_rc2_cbc, 40);
131 goto err;
132#endif 130#endif
133 if (!PKCS7_add_attrib_smimecap (si, smcap)) 131 PKCS7_add_attrib_smimecap (si, smcap);
134 goto err;
135 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free); 132 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
136 smcap = NULL;
137 } 133 }
138 } 134 }
139 135
140 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1); 136 if(flags & PKCS7_DETACHED)PKCS7_set_detached(p7, 1);
141 137
142 if (flags & PKCS7_STREAM) 138 if (!PKCS7_dataFinal(p7,p7bio)) {
143 return p7;
144
145
146 if (!(p7bio = PKCS7_dataInit(p7, NULL))) {
147 PKCS7err(PKCS7_F_PKCS7_SIGN,ERR_R_MALLOC_FAILURE);
148 goto err;
149 }
150
151 SMIME_crlf_copy(data, p7bio, flags);
152
153
154 if (!PKCS7_dataFinal(p7,p7bio)) {
155 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN); 139 PKCS7err(PKCS7_F_PKCS7_SIGN,PKCS7_R_PKCS7_DATASIGN);
156 goto err; 140 return NULL;
157 } 141 }
158 142
159 BIO_free_all(p7bio); 143 BIO_free_all(p7bio);
160 return p7; 144 return p7;
161err:
162 sk_X509_ALGOR_pop_free(smcap, X509_ALGOR_free);
163 BIO_free_all(p7bio);
164 PKCS7_free(p7);
165 return NULL;
166} 145}
167 146
168int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, 147int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
@@ -236,8 +215,6 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
236 sk_X509_free(signers); 215 sk_X509_free(signers);
237 return 0; 216 return 0;
238 } 217 }
239 if (!(flags & PKCS7_NOCRL))
240 X509_STORE_CTX_set0_crls(&cert_ctx, p7->d.sign->crl);
241 i = X509_verify_cert(&cert_ctx); 218 i = X509_verify_cert(&cert_ctx);
242 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx); 219 if (i <= 0) j = X509_STORE_CTX_get_error(&cert_ctx);
243 X509_STORE_CTX_cleanup(&cert_ctx); 220 X509_STORE_CTX_cleanup(&cert_ctx);
@@ -274,8 +251,7 @@ int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
274 tmpin = indata; 251 tmpin = indata;
275 252
276 253
277 if (!(p7bio=PKCS7_dataInit(p7,tmpin))) 254 p7bio=PKCS7_dataInit(p7,tmpin);
278 goto err;
279 255
280 if(flags & PKCS7_TEXT) { 256 if(flags & PKCS7_TEXT) {
281 if(!(tmpout = BIO_new(BIO_s_mem()))) { 257 if(!(tmpout = BIO_new(BIO_s_mem()))) {
@@ -354,7 +330,7 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
354 330
355 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) { 331 if(sk_PKCS7_SIGNER_INFO_num(sinfos) <= 0) {
356 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS); 332 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_NO_SIGNERS);
357 return NULL; 333 return 0;
358 } 334 }
359 335
360 if(!(signers = sk_X509_new_null())) { 336 if(!(signers = sk_X509_new_null())) {
@@ -377,13 +353,10 @@ STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags)
377 if (!signer) { 353 if (!signer) {
378 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND); 354 PKCS7err(PKCS7_F_PKCS7_GET0_SIGNERS,PKCS7_R_SIGNER_CERTIFICATE_NOT_FOUND);
379 sk_X509_free(signers); 355 sk_X509_free(signers);
380 return NULL; 356 return 0;
381 } 357 }
382 358
383 if (!sk_X509_push(signers, signer)) { 359 sk_X509_push(signers, signer);
384 sk_X509_free(signers);
385 return NULL;
386 }
387 } 360 }
388 return signers; 361 return signers;
389} 362}
@@ -403,8 +376,7 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
403 return NULL; 376 return NULL;
404 } 377 }
405 378
406 if (!PKCS7_set_type(p7, NID_pkcs7_enveloped)) 379 PKCS7_set_type(p7, NID_pkcs7_enveloped);
407 goto err;
408 if(!PKCS7_set_cipher(p7, cipher)) { 380 if(!PKCS7_set_cipher(p7, cipher)) {
409 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER); 381 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_ERROR_SETTING_CIPHER);
410 goto err; 382 goto err;
@@ -426,7 +398,7 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
426 398
427 SMIME_crlf_copy(in, p7bio, flags); 399 SMIME_crlf_copy(in, p7bio, flags);
428 400
429 (void)BIO_flush(p7bio); 401 BIO_flush(p7bio);
430 402
431 if (!PKCS7_dataFinal(p7,p7bio)) { 403 if (!PKCS7_dataFinal(p7,p7bio)) {
432 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR); 404 PKCS7err(PKCS7_F_PKCS7_ENCRYPT,PKCS7_R_PKCS7_DATAFINAL_ERROR);
@@ -438,7 +410,7 @@ PKCS7 *PKCS7_encrypt(STACK_OF(X509) *certs, BIO *in, const EVP_CIPHER *cipher,
438 410
439 err: 411 err:
440 412
441 BIO_free_all(p7bio); 413 BIO_free(p7bio);
442 PKCS7_free(p7); 414 PKCS7_free(p7);
443 return NULL; 415 return NULL;
444 416
@@ -460,7 +432,7 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
460 return 0; 432 return 0;
461 } 433 }
462 434
463 if(cert && !X509_check_private_key(cert, pkey)) { 435 if(!X509_check_private_key(cert, pkey)) {
464 PKCS7err(PKCS7_F_PKCS7_DECRYPT, 436 PKCS7err(PKCS7_F_PKCS7_DECRYPT,
465 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE); 437 PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE);
466 return 0; 438 return 0;
@@ -476,13 +448,10 @@ int PKCS7_decrypt(PKCS7 *p7, EVP_PKEY *pkey, X509 *cert, BIO *data, int flags)
476 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */ 448 /* Encrypt BIOs can't do BIO_gets() so add a buffer BIO */
477 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) { 449 if(!(tmpbuf = BIO_new(BIO_f_buffer()))) {
478 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); 450 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
479 BIO_free_all(tmpmem);
480 return 0; 451 return 0;
481 } 452 }
482 if(!(bread = BIO_push(tmpbuf, tmpmem))) { 453 if(!(bread = BIO_push(tmpbuf, tmpmem))) {
483 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE); 454 PKCS7err(PKCS7_F_PKCS7_DECRYPT, ERR_R_MALLOC_FAILURE);
484 BIO_free_all(tmpbuf);
485 BIO_free_all(tmpmem);
486 return 0; 455 return 0;
487 } 456 }
488 ret = SMIME_text(bread, data); 457 ret = SMIME_text(bread, data);
diff --git a/src/lib/libcrypto/pkcs7/pkcs7.h b/src/lib/libcrypto/pkcs7/pkcs7.h
index cc092d262d..15372e18f8 100644
--- a/src/lib/libcrypto/pkcs7/pkcs7.h
+++ b/src/lib/libcrypto/pkcs7/pkcs7.h
@@ -233,8 +233,6 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
233 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped) 233 (OBJ_obj2nid((a)->type) == NID_pkcs7_signedAndEnveloped)
234#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data) 234#define PKCS7_type_is_data(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_data)
235 235
236#define PKCS7_type_is_digest(a) (OBJ_obj2nid((a)->type) == NID_pkcs7_digest)
237
238#define PKCS7_set_detached(p,v) \ 236#define PKCS7_set_detached(p,v) \
239 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL) 237 PKCS7_ctrl(p,PKCS7_OP_SET_DETACHED_SIGNATURE,v,NULL)
240#define PKCS7_get_detached(p) \ 238#define PKCS7_get_detached(p) \
@@ -264,8 +262,6 @@ DECLARE_PKCS12_STACK_OF(PKCS7)
264#define PKCS7_NOSMIMECAP 0x200 262#define PKCS7_NOSMIMECAP 0x200
265#define PKCS7_NOOLDMIMETYPE 0x400 263#define PKCS7_NOOLDMIMETYPE 0x400
266#define PKCS7_CRLFEOL 0x800 264#define PKCS7_CRLFEOL 0x800
267#define PKCS7_STREAM 0x1000
268#define PKCS7_NOCRL 0x2000
269 265
270/* Flags: for compatibility with older code */ 266/* Flags: for compatibility with older code */
271 267
@@ -306,12 +302,10 @@ DECLARE_ASN1_FUNCTIONS(PKCS7)
306DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN) 302DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
307DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY) 303DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
308 304
309DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
310 305
311long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg); 306long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);
312 307
313int PKCS7_set_type(PKCS7 *p7, int type); 308int PKCS7_set_type(PKCS7 *p7, int type);
314int PKCS7_set0_type_other(PKCS7 *p7, int type, ASN1_TYPE *other);
315int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data); 309int PKCS7_set_content(PKCS7 *p7, PKCS7 *p7_data);
316int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey, 310int PKCS7_SIGNER_INFO_set(PKCS7_SIGNER_INFO *p7i, X509 *x509, EVP_PKEY *pkey,
317 const EVP_MD *dgst); 311 const EVP_MD *dgst);
@@ -332,7 +326,6 @@ BIO *PKCS7_dataDecode(PKCS7 *p7, EVP_PKEY *pkey, BIO *in_bio, X509 *pcert);
332PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509, 326PKCS7_SIGNER_INFO *PKCS7_add_signature(PKCS7 *p7, X509 *x509,
333 EVP_PKEY *pkey, const EVP_MD *dgst); 327 EVP_PKEY *pkey, const EVP_MD *dgst);
334X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si); 328X509 *PKCS7_cert_from_signer_info(PKCS7 *p7, PKCS7_SIGNER_INFO *si);
335int PKCS7_set_digest(PKCS7 *p7, const EVP_MD *md);
336STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7); 329STACK_OF(PKCS7_SIGNER_INFO) *PKCS7_get_signer_info(PKCS7 *p7);
337 330
338PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509); 331PKCS7_RECIP_INFO *PKCS7_add_recipient(PKCS7 *p7, X509 *x509);
@@ -388,20 +381,16 @@ void ERR_load_PKCS7_strings(void);
388#define PKCS7_F_PKCS7_ADD_CRL 101 381#define PKCS7_F_PKCS7_ADD_CRL 101
389#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102 382#define PKCS7_F_PKCS7_ADD_RECIPIENT_INFO 102
390#define PKCS7_F_PKCS7_ADD_SIGNER 103 383#define PKCS7_F_PKCS7_ADD_SIGNER 103
391#define PKCS7_F_PKCS7_BIO_ADD_DIGEST 125
392#define PKCS7_F_PKCS7_CTRL 104 384#define PKCS7_F_PKCS7_CTRL 104
393#define PKCS7_F_PKCS7_DATADECODE 112 385#define PKCS7_F_PKCS7_DATADECODE 112
394#define PKCS7_F_PKCS7_DATAFINAL 128
395#define PKCS7_F_PKCS7_DATAINIT 105 386#define PKCS7_F_PKCS7_DATAINIT 105
396#define PKCS7_F_PKCS7_DATASIGN 106 387#define PKCS7_F_PKCS7_DATASIGN 106
397#define PKCS7_F_PKCS7_DATAVERIFY 107 388#define PKCS7_F_PKCS7_DATAVERIFY 107
398#define PKCS7_F_PKCS7_DECRYPT 114 389#define PKCS7_F_PKCS7_DECRYPT 114
399#define PKCS7_F_PKCS7_ENCRYPT 115 390#define PKCS7_F_PKCS7_ENCRYPT 115
400#define PKCS7_F_PKCS7_FIND_DIGEST 127
401#define PKCS7_F_PKCS7_GET0_SIGNERS 124 391#define PKCS7_F_PKCS7_GET0_SIGNERS 124
402#define PKCS7_F_PKCS7_SET_CIPHER 108 392#define PKCS7_F_PKCS7_SET_CIPHER 108
403#define PKCS7_F_PKCS7_SET_CONTENT 109 393#define PKCS7_F_PKCS7_SET_CONTENT 109
404#define PKCS7_F_PKCS7_SET_DIGEST 126
405#define PKCS7_F_PKCS7_SET_TYPE 110 394#define PKCS7_F_PKCS7_SET_TYPE 110
406#define PKCS7_F_PKCS7_SIGN 116 395#define PKCS7_F_PKCS7_SIGN 116
407#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113 396#define PKCS7_F_PKCS7_SIGNATUREVERIFY 113
@@ -432,15 +421,13 @@ void ERR_load_PKCS7_strings(void);
432#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136 421#define PKCS7_R_NO_MULTIPART_BODY_FAILURE 136
433#define PKCS7_R_NO_MULTIPART_BOUNDARY 137 422#define PKCS7_R_NO_MULTIPART_BOUNDARY 137
434#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115 423#define PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE 115
435#define PKCS7_R_NO_RECIPIENT_MATCHES_KEY 146
436#define PKCS7_R_NO_SIGNATURES_ON_DATA 123 424#define PKCS7_R_NO_SIGNATURES_ON_DATA 123
437#define PKCS7_R_NO_SIGNERS 142 425#define PKCS7_R_NO_SIGNERS 142
438#define PKCS7_R_NO_SIG_CONTENT_TYPE 138 426#define PKCS7_R_NO_SIG_CONTENT_TYPE 138
439#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104 427#define PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE 104
440#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124 428#define PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR 124
441#define PKCS7_R_PKCS7_DATAFINAL 126
442#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125 429#define PKCS7_R_PKCS7_DATAFINAL_ERROR 125
443#define PKCS7_R_PKCS7_DATASIGN 145 430#define PKCS7_R_PKCS7_DATASIGN 126
444#define PKCS7_R_PKCS7_PARSE_ERROR 139 431#define PKCS7_R_PKCS7_PARSE_ERROR 139
445#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140 432#define PKCS7_R_PKCS7_SIG_PARSE_ERROR 140
446#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127 433#define PKCS7_R_PRIVATE_KEY_DOES_NOT_MATCH_CERTIFICATE 127
diff --git a/src/lib/libcrypto/pkcs7/pkcs7err.c b/src/lib/libcrypto/pkcs7/pkcs7err.c
index c0e3d4cd33..19894c80a4 100644
--- a/src/lib/libcrypto/pkcs7/pkcs7err.c
+++ b/src/lib/libcrypto/pkcs7/pkcs7err.c
@@ -77,20 +77,16 @@ static ERR_STRING_DATA PKCS7_str_functs[]=
77{ERR_FUNC(PKCS7_F_PKCS7_ADD_CRL), "PKCS7_add_crl"}, 77{ERR_FUNC(PKCS7_F_PKCS7_ADD_CRL), "PKCS7_add_crl"},
78{ERR_FUNC(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO), "PKCS7_add_recipient_info"}, 78{ERR_FUNC(PKCS7_F_PKCS7_ADD_RECIPIENT_INFO), "PKCS7_add_recipient_info"},
79{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNER), "PKCS7_add_signer"}, 79{ERR_FUNC(PKCS7_F_PKCS7_ADD_SIGNER), "PKCS7_add_signer"},
80{ERR_FUNC(PKCS7_F_PKCS7_BIO_ADD_DIGEST), "PKCS7_BIO_ADD_DIGEST"},
81{ERR_FUNC(PKCS7_F_PKCS7_CTRL), "PKCS7_ctrl"}, 80{ERR_FUNC(PKCS7_F_PKCS7_CTRL), "PKCS7_ctrl"},
82{ERR_FUNC(PKCS7_F_PKCS7_DATADECODE), "PKCS7_dataDecode"}, 81{ERR_FUNC(PKCS7_F_PKCS7_DATADECODE), "PKCS7_dataDecode"},
83{ERR_FUNC(PKCS7_F_PKCS7_DATAFINAL), "PKCS7_dataFinal"},
84{ERR_FUNC(PKCS7_F_PKCS7_DATAINIT), "PKCS7_dataInit"}, 82{ERR_FUNC(PKCS7_F_PKCS7_DATAINIT), "PKCS7_dataInit"},
85{ERR_FUNC(PKCS7_F_PKCS7_DATASIGN), "PKCS7_DATASIGN"}, 83{ERR_FUNC(PKCS7_F_PKCS7_DATASIGN), "PKCS7_DATASIGN"},
86{ERR_FUNC(PKCS7_F_PKCS7_DATAVERIFY), "PKCS7_dataVerify"}, 84{ERR_FUNC(PKCS7_F_PKCS7_DATAVERIFY), "PKCS7_dataVerify"},
87{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT), "PKCS7_decrypt"}, 85{ERR_FUNC(PKCS7_F_PKCS7_DECRYPT), "PKCS7_decrypt"},
88{ERR_FUNC(PKCS7_F_PKCS7_ENCRYPT), "PKCS7_encrypt"}, 86{ERR_FUNC(PKCS7_F_PKCS7_ENCRYPT), "PKCS7_encrypt"},
89{ERR_FUNC(PKCS7_F_PKCS7_FIND_DIGEST), "PKCS7_FIND_DIGEST"},
90{ERR_FUNC(PKCS7_F_PKCS7_GET0_SIGNERS), "PKCS7_get0_signers"}, 87{ERR_FUNC(PKCS7_F_PKCS7_GET0_SIGNERS), "PKCS7_get0_signers"},
91{ERR_FUNC(PKCS7_F_PKCS7_SET_CIPHER), "PKCS7_set_cipher"}, 88{ERR_FUNC(PKCS7_F_PKCS7_SET_CIPHER), "PKCS7_set_cipher"},
92{ERR_FUNC(PKCS7_F_PKCS7_SET_CONTENT), "PKCS7_set_content"}, 89{ERR_FUNC(PKCS7_F_PKCS7_SET_CONTENT), "PKCS7_set_content"},
93{ERR_FUNC(PKCS7_F_PKCS7_SET_DIGEST), "PKCS7_set_digest"},
94{ERR_FUNC(PKCS7_F_PKCS7_SET_TYPE), "PKCS7_set_type"}, 90{ERR_FUNC(PKCS7_F_PKCS7_SET_TYPE), "PKCS7_set_type"},
95{ERR_FUNC(PKCS7_F_PKCS7_SIGN), "PKCS7_sign"}, 91{ERR_FUNC(PKCS7_F_PKCS7_SIGN), "PKCS7_sign"},
96{ERR_FUNC(PKCS7_F_PKCS7_SIGNATUREVERIFY), "PKCS7_signatureVerify"}, 92{ERR_FUNC(PKCS7_F_PKCS7_SIGNATUREVERIFY), "PKCS7_signatureVerify"},
@@ -124,13 +120,11 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
124{ERR_REASON(PKCS7_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"}, 120{ERR_REASON(PKCS7_R_NO_MULTIPART_BODY_FAILURE),"no multipart body failure"},
125{ERR_REASON(PKCS7_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"}, 121{ERR_REASON(PKCS7_R_NO_MULTIPART_BOUNDARY),"no multipart boundary"},
126{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE),"no recipient matches certificate"}, 122{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_CERTIFICATE),"no recipient matches certificate"},
127{ERR_REASON(PKCS7_R_NO_RECIPIENT_MATCHES_KEY),"no recipient matches key"},
128{ERR_REASON(PKCS7_R_NO_SIGNATURES_ON_DATA),"no signatures on data"}, 123{ERR_REASON(PKCS7_R_NO_SIGNATURES_ON_DATA),"no signatures on data"},
129{ERR_REASON(PKCS7_R_NO_SIGNERS) ,"no signers"}, 124{ERR_REASON(PKCS7_R_NO_SIGNERS) ,"no signers"},
130{ERR_REASON(PKCS7_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"}, 125{ERR_REASON(PKCS7_R_NO_SIG_CONTENT_TYPE) ,"no sig content type"},
131{ERR_REASON(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE),"operation not supported on this type"}, 126{ERR_REASON(PKCS7_R_OPERATION_NOT_SUPPORTED_ON_THIS_TYPE),"operation not supported on this type"},
132{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"}, 127{ERR_REASON(PKCS7_R_PKCS7_ADD_SIGNATURE_ERROR),"pkcs7 add signature error"},
133{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL) ,"pkcs7 datafinal"},
134{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL_ERROR),"pkcs7 datafinal error"}, 128{ERR_REASON(PKCS7_R_PKCS7_DATAFINAL_ERROR),"pkcs7 datafinal error"},
135{ERR_REASON(PKCS7_R_PKCS7_DATASIGN) ,"pkcs7 datasign"}, 129{ERR_REASON(PKCS7_R_PKCS7_DATASIGN) ,"pkcs7 datasign"},
136{ERR_REASON(PKCS7_R_PKCS7_PARSE_ERROR) ,"pkcs7 parse error"}, 130{ERR_REASON(PKCS7_R_PKCS7_PARSE_ERROR) ,"pkcs7 parse error"},
@@ -156,12 +150,15 @@ static ERR_STRING_DATA PKCS7_str_reasons[]=
156 150
157void ERR_load_PKCS7_strings(void) 151void ERR_load_PKCS7_strings(void)
158 { 152 {
159#ifndef OPENSSL_NO_ERR 153 static int init=1;
160 154
161 if (ERR_func_error_string(PKCS7_str_functs[0].error) == NULL) 155 if (init)
162 { 156 {
157 init=0;
158#ifndef OPENSSL_NO_ERR
163 ERR_load_strings(0,PKCS7_str_functs); 159 ERR_load_strings(0,PKCS7_str_functs);
164 ERR_load_strings(0,PKCS7_str_reasons); 160 ERR_load_strings(0,PKCS7_str_reasons);
165 }
166#endif 161#endif
162
163 }
167 } 164 }
diff --git a/src/lib/libcrypto/pkcs7/server.pem b/src/lib/libcrypto/pkcs7/server.pem
new file mode 100644
index 0000000000..750aac2094
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/server.pem
@@ -0,0 +1,24 @@
1issuer= /C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Test CA (1024 bit)
2subject=/C=AU/ST=Queensland/O=CryptSoft Pty Ltd/CN=Server test cert (512 bit)
3-----BEGIN CERTIFICATE-----
4MIIB6TCCAVICAQAwDQYJKoZIhvcNAQEEBQAwWzELMAkGA1UEBhMCQVUxEzARBgNV
5BAgTClF1ZWVuc2xhbmQxGjAYBgNVBAoTEUNyeXB0U29mdCBQdHkgTHRkMRswGQYD
6VQQDExJUZXN0IENBICgxMDI0IGJpdCkwHhcNOTcwNjA5MTM1NzQ2WhcNOTgwNjA5
7MTM1NzQ2WjBjMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDEaMBgG
8A1UEChMRQ3J5cHRTb2Z0IFB0eSBMdGQxIzAhBgNVBAMTGlNlcnZlciB0ZXN0IGNl
9cnQgKDUxMiBiaXQpMFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ+zw4Qnlf8SMVIP
10Fe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVDTGiXav6ooKXfX3j/7tdkuD8Ey2//
11Kv7+ue0CAwEAATANBgkqhkiG9w0BAQQFAAOBgQB4TMR2CvacKE9wAsu9jyCX8YiW
12mgCM+YoP6kt4Zkj2z5IRfm7WrycKsnpnOR+tGeqAjkCeZ6/36o9l91RvPnN1VJ/i
13xQv2df0KFeMr00IkDdTNAdIWqFkSsZTAY2QAdgenb7MB1joejquYzO2DQIO7+wpH
14irObpESxAZLySCmPPg==
15-----END CERTIFICATE-----
16-----BEGIN RSA PRIVATE KEY-----
17MIIBPAIBAAJBAJ+zw4Qnlf8SMVIPFe9GEcStgOY2Ww/dgNdhjeD8ckUJNP5VZkVD
18TGiXav6ooKXfX3j/7tdkuD8Ey2//Kv7+ue0CAwEAAQJAN6W31vDEP2DjdqhzCDDu
19OA4NACqoiFqyblo7yc2tM4h4xMbC3Yx5UKMN9ZkCtX0gzrz6DyF47bdKcWBzNWCj
20gQIhANEoojVt7hq+SQ6MCN6FTAysGgQf56Q3TYoJMoWvdiXVAiEAw3e3rc+VJpOz
21rHuDo6bgpjUAAXM+v3fcpsfZSNO6V7kCIQCtbVjanpUwvZkMI9by02oUk9taki3b
22PzPfAfNPYAbCJQIhAJXNQDWyqwn/lGmR11cqY2y9nZ1+5w3yHGatLrcDnQHxAiEA
23vnlEGo8K85u+KwIOimM48ZG8oTk7iFdkqLJR1utT3aU=
24-----END RSA PRIVATE KEY-----
diff --git a/src/lib/libcrypto/pkcs7/sign.c b/src/lib/libcrypto/pkcs7/sign.c
new file mode 100644
index 0000000000..8b59885f7e
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/sign.c
@@ -0,0 +1,154 @@
1/* crypto/pkcs7/sign.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58#include <stdio.h>
59#include <string.h>
60#include <openssl/bio.h>
61#include <openssl/x509.h>
62#include <openssl/pem.h>
63#include <openssl/err.h>
64
65int main(argc,argv)
66int argc;
67char *argv[];
68 {
69 X509 *x509;
70 EVP_PKEY *pkey;
71 PKCS7 *p7;
72 PKCS7_SIGNER_INFO *si;
73 BIO *in;
74 BIO *data,*p7bio;
75 char buf[1024*4];
76 int i;
77 int nodetach=0;
78
79#ifndef OPENSSL_NO_MD2
80 EVP_add_digest(EVP_md2());
81#endif
82#ifndef OPENSSL_NO_MD5
83 EVP_add_digest(EVP_md5());
84#endif
85#ifndef OPENSSL_NO_SHA1
86 EVP_add_digest(EVP_sha1());
87#endif
88#ifndef OPENSSL_NO_MDC2
89 EVP_add_digest(EVP_mdc2());
90#endif
91
92 data=BIO_new(BIO_s_file());
93again:
94 if (argc > 1)
95 {
96 if (strcmp(argv[1],"-nd") == 0)
97 {
98 nodetach=1;
99 argv++; argc--;
100 goto again;
101 }
102 if (!BIO_read_filename(data,argv[1]))
103 goto err;
104 }
105 else
106 BIO_set_fp(data,stdin,BIO_NOCLOSE);
107
108 if ((in=BIO_new_file("server.pem","r")) == NULL) goto err;
109 if ((x509=PEM_read_bio_X509(in,NULL,NULL,NULL)) == NULL) goto err;
110 BIO_reset(in);
111 if ((pkey=PEM_read_bio_PrivateKey(in,NULL,NULL,NULL)) == NULL) goto err;
112 BIO_free(in);
113
114 p7=PKCS7_new();
115 PKCS7_set_type(p7,NID_pkcs7_signed);
116
117 si=PKCS7_add_signature(p7,x509,pkey,EVP_sha1());
118 if (si == NULL) goto err;
119
120 /* If you do this then you get signing time automatically added */
121 PKCS7_add_signed_attribute(si, NID_pkcs9_contentType, V_ASN1_OBJECT,
122 OBJ_nid2obj(NID_pkcs7_data));
123
124 /* we may want to add more */
125 PKCS7_add_certificate(p7,x509);
126
127 /* Set the content of the signed to 'data' */
128 PKCS7_content_new(p7,NID_pkcs7_data);
129
130 if (!nodetach)
131 PKCS7_set_detached(p7,1);
132
133 if ((p7bio=PKCS7_dataInit(p7,NULL)) == NULL) goto err;
134
135 for (;;)
136 {
137 i=BIO_read(data,buf,sizeof(buf));
138 if (i <= 0) break;
139 BIO_write(p7bio,buf,i);
140 }
141
142 if (!PKCS7_dataFinal(p7,p7bio)) goto err;
143 BIO_free(p7bio);
144
145 PEM_write_PKCS7(stdout,p7);
146 PKCS7_free(p7);
147
148 exit(0);
149err:
150 ERR_load_crypto_strings();
151 ERR_print_errors_fp(stderr);
152 exit(1);
153 }
154
diff --git a/src/lib/libcrypto/pkcs7/t/3des.pem b/src/lib/libcrypto/pkcs7/t/3des.pem
new file mode 100644
index 0000000000..b2b5081a10
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/3des.pem
@@ -0,0 +1,16 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
3A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
4dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
5ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEC2vXI1xQDW6lUHM3zQ
6/9uBEBOO5A3TtkrklAXq7v01gsIC21t52qSk36REXY+slhNZ0OQ349tgkTsoETHFLoEwMIHw
7AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
8QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
9UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR9MA0G
10CSqGSIb3DQEBAQUABEB8ujxbabxXUYJhopuDm3oDq4JNqX6Io4p3ro+ShqfIndsXTZ1v5a2N
11WtLLCWlHn/habjBwZ/DgQgcKASbZ7QxNMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
12oAQIbsL5v1wX98KggAQoAaJ4WHm68fXY1WE5OIjfVBIDpO1K+i8dmKhjnAjrjoyZ9Bwc8rDL
13lgQg4CXb805h5xl+GfvSwUaHJayte1m2mcOhs3J2YyqbQ+MEIMIiJQccmhO3oDKm36CFvYR8
145PjpclVcZyX2ngbwPFMnBAgy0clOAE6UKAAAAAAAAAAAAAA=
15-----END PKCS7-----
16
diff --git a/src/lib/libcrypto/pkcs7/t/3dess.pem b/src/lib/libcrypto/pkcs7/t/3dess.pem
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/3dess.pem
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
4BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
5ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
6AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
7gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
8ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
9A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
10dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
11hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
12hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
13igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
14syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
15A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
16dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
17ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
18kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/c.pem b/src/lib/libcrypto/pkcs7/t/c.pem
new file mode 100644
index 0000000000..a4b55e321a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/c.pem
@@ -0,0 +1,48 @@
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
diff --git a/src/lib/libcrypto/pkcs7/t/ff b/src/lib/libcrypto/pkcs7/t/ff
new file mode 100644
index 0000000000..23f013516a
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/ff
@@ -0,0 +1,32 @@
1-----BEGIN PKCS7-----
2MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
3BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
4BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
5ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
6AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
7gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
8ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
9A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
10dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
11hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
12hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
13igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
14syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
15A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
16dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
17ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
18kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
19MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
20TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
21BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
22mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
238o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
24ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
25BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
26REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
27AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
28CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
29SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
30BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
319CWR6g==
32-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-e b/src/lib/libcrypto/pkcs7/t/msie-e
new file mode 100644
index 0000000000..aafae69fc9
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-e
@@ -0,0 +1,20 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABECMzu8y
5wQ/qZbO8cAGMRBF+mPruv3+Dvb9aWNZ2k8njUgqF6mcdhVB2MkGcsG3memRXJBixvMYWVkU3qK4Z
6VuKsMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABEBcWwYFHJbJGhiztt7lzue3Lc9CH5WAbyR+2BZ3uv+JxZfRs1PuaWPOwRa0Vgs3
10YwSJoRfxQj2Gk0wFqG1qt6d1MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQI8vRlP/Nx
112iSggASCAZhR5srxyspy7DfomRJ9ff8eMCtaNwEoEx7G25PZRonC57hBvGoScLtEPU3Wp9FEbPN7
12oJESeC+AqMTyTLNy8aQsyC5s53E9UkoIvg62ekYZBbXZqXsrxx4PhiiX3NH8GVh42phB0Chjw0nK
13HZeRDmxGY3Cmk+J+l0uVKxbNIfJIKOguLBnhqmnKH/PrnzDt591u0ULy2aTLqRm+4/1Yat/QPb6J
14eoKGwNPBbS9ogBdrCNCp9ZFg3Xar2AtQHzyTQIfYeH3SRQUpKmRm5U5o9p5emgEdT+ZfJm/J4tSH
15OmbgAFsbHQakA4MBZ4J5qfDJhOA2g5lWk1hIeu5Dn/AaLRZd0yz3oY0Ieo/erPWx/bCqtBzYbMe9
16qSFTedKlbc9EGe3opOTdBZVzK8KH3w3zsy5luxKdOUG59YYb5F1IZiWGiDyuo/HuacX+griu5LeD
17bEzOtZnko+TZXvWIko30fD79j3T4MRRhWXbgj2HKza+4vJ0mzcC/1+GPsJjAEAA/JgIEDU4w6/DI
18/HQHhLAO3G+9xKD7MvmrzkoAAAAAAAAAAAAA
19
20
diff --git a/src/lib/libcrypto/pkcs7/t/msie-e.pem b/src/lib/libcrypto/pkcs7/t/msie-e.pem
new file mode 100644
index 0000000000..a2a5e24e74
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-e.pem
@@ -0,0 +1,22 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIIDkAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQIzO7zLBD+pls7xwAYxEEX6Y+u6/f4O9
6v1pY1naTyeNSCoXqZx2FUHYyQZywbeZ6ZFckGLG8xhZWRTeorhlW4qwwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQFxbBgUclskaGLO23uXO57ctz0If
11lYBvJH7YFne6/4nFl9GzU+5pY87BFrRWCzdjBImhF/FCPYaTTAWobWq3p3UwggHD
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECPL0ZT/zcdokgIIBmFHmyvHK
13ynLsN+iZEn19/x4wK1o3ASgTHsbbk9lGicLnuEG8ahJwu0Q9Tdan0URs83ugkRJ4
14L4CoxPJMs3LxpCzILmzncT1SSgi+DrZ6RhkFtdmpeyvHHg+GKJfc0fwZWHjamEHQ
15KGPDScodl5EObEZjcKaT4n6XS5UrFs0h8kgo6C4sGeGqacof8+ufMO3n3W7RQvLZ
16pMupGb7j/Vhq39A9vol6gobA08FtL2iAF2sI0Kn1kWDddqvYC1AfPJNAh9h4fdJF
17BSkqZGblTmj2nl6aAR1P5l8mb8ni1Ic6ZuAAWxsdBqQDgwFngnmp8MmE4DaDmVaT
18WEh67kOf8BotFl3TLPehjQh6j96s9bH9sKq0HNhsx72pIVN50qVtz0QZ7eik5N0F
19lXMrwoffDfOzLmW7Ep05Qbn1hhvkXUhmJYaIPK6j8e5pxf6CuK7kt4NsTM61meSj
205Nle9YiSjfR8Pv2PdPgxFGFZduCPYcrNr7i8nSbNwL/X4Y+wmMAQAD8mAgQNTjDr
218Mj8dAeEsA7cb73EoPsy+avOSgAAAAA=
22-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-01 b/src/lib/libcrypto/pkcs7/t/msie-enc-01
new file mode 100644
index 0000000000..2c93ab6462
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-01
@@ -0,0 +1,62 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxgfMwgfACAQAwgZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYD
3VQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0
4IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMT
5EkRFTU8gWkVSTyBWQUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQKvMaW8xh6oF/X+CJivz
6IZV7yHxlp4O3NHQtWG0A8MOZB+CtKlU7/6g5e/a9Du/TOqxRMqtYRp63pa2Q/mM4IYMwgAYJ
7KoZIhvcNAQcBMBoGCCqGSIb3DQMCMA4CAgCgBAifz6RvzOPYlKCABIGwxtGA/FLBBRs1wbBP
8gDCbSG0yCwjJNsFg89/k6xuXo8c5YTwsw8+XlIVq03navpew6XxxzY090rD2OJ0t6HA6GqrI
9pd8WiSh/Atqn0yfLFmkLqgIAPRfzxUxqUocxLpQsLIFp2YNUGE+yps+UZmIjw/WHfdqrcWTm
10STSvKuy3UkIJZCkGDBpTvqk4BFaHh4oTXEpgpNY+GKxjf9TDN9GQPqQZR7sgQki4t2g4/Saq
11Kl4EMISgluk6swdND0tiHY7v5d6YR29ePCl2/STJ98eJpWkEEC22GNNvOy7ru/Rv2He4MgQg
12optd7sk9MMd9xhJppg7CcH/yDx//HrtgpOcWmn6VxpgECFqon4uXkQtIBIH4PaNclFn7/hLx
13Pw2VmBGaC0SYF3U1jyN96EBxdjqy8Aa6ByMXYDW5BcfqniD5mYXfw+b81lh1kutxaPaV4YJ9
14ZlRUW752N7VHo/fG0/fukoe5W9a8kIhgLpygllb/GP4oSF4wM6n1/OgRzZj2IWFiobKO4d/t
15Mnh+C+PoEVAuFZcxQwi9GqvsK5OoIjVwNx0XcVSOl1TTYS9SwC7ugMBCab73JiruC24pL78Y
16M+NaIpIQ3On4DokJA2ZHtjBjZIxF4tKA144RvFN6pBd6TVE5XM6KD/Vh9bjSmujtEAfdQ3Te
17dvKJsbZuu0stErbvWcRy11I328l557EECAJT7d44OJ3rBBBj6bnnx6dDU2SRqp2CEoQaBAhK
18RBuyhNxkygQIOY9/NhwqAJAECOvX0Zd0DqgoBAjobPpMHhVV3gQQWLU2vEoZ51BwzxdzCmxO
19wwQI4oKfudaNqoAESKzBNAqv5kGumHOlMKsRfrs7jZCcSaOuEj97pYx08FLEgF23cav39MOQ
20NUEM1dNU+EYslL4o3RoSHRjUgPU+2t9c0prS9A/bPARIEOP94PynaTNxwHi3VTK7SzuQmgzA
214n942E9joSiqsQPlsKAb3sPUaLC3SuUxSjNBgfpvD0bmrA/5h+WZoYXvIogFpwjkSmnFBEie
220lh5Ov1aRrvCw5/j3Q/W/4ZtN5U+aeVBJMtA8n0Mxd5kPxHbNVh4oGprZ6wEegV8ht3voyZa
23mZ5Cyxc8ffMYnM/JJI6/oEYEUEMyyiS5FnYyvxKzfMtyn2lZ2st9nZGNNgMc9N62r5HgNbdD
24FHuRdKKzV+8kQfuMc3mOPpK1t9TFY+QgrxiB5p6S7VooI97YtP3PbfknszCEBEh4PdXYbbaR
253AacN3Q5kYYmWsq3WW6xgrg0mmEGosGvwSQxBBuiXZrxScCa4ivEq05UZwyShePvKduOvnUE
262zDO6IXFLZxhTZAESEm9/FovLgGAiJ7iMGmYvsISLJScwG4n+wrSaQNQXizs9N3ykys54wBN
27d/+BQ4F7pncHhDQ2Dyt5MekB8Y8iNOocUTFCu524vQRIaWCXmXP3vU7D21dp0XnAMzRQJ565
28JV3aHRoY7XDa4LePa7PP9ywyafOE5yCW7ndqx3J+2JhTDvSFsW8/q3H3iyeFhykuJVS6BFDK
296CmKbnyyjOfE2iLGJmTFa905V2KrVDCmlEu/xyGMs80yTyZC+ySzM83FMVvLEQmSzcTNUZVp
30DfA1kNXbXkPouBXXT6g8r8JCRljaKKABmgRIlMheOJQRUUU4cgvhMreXPayhq5Ao4VMSCkA5
31hYRCBczm4Di/MMohF0SxIsdRY6gY9CPnrBXAsY6h1RbR7Tw0iQZmeXi52DCiBEj0by+SYMAa
329z0CReIzl8JLL6EVIFz8kFxlkGWjr4dnOzhhPOq/mCpp0WxbavDfdhE87MdXJZBnLwoT62QG
33955HlAoEQBOGJbcESCgd5XSirZ9Y3AbCfuKOqoMBvEUGn+w/pMaqnGvnr5FZhuBDKrhRXqtx
34QsxA//drGUxsrZOuSL/0+fbvo7n2h1Z8Ny86jOvVZAQIAjw2l1Yc5RAESNc9i3I8pKEOVQf/
35UBczJ0NR9aTEF80dRg2lpXwD0ho4N0AvSiVbgxC7cPZHQwIqvq9LHRUs/4n+Vu3SVYU3cAxo
36lUTiCGUSlARIF+TD57SI5+RI+MNtnD9rs4E1ml51YoHGWFj3UPriDmY0FKEwIgqtMXMY3fZ9
37Kq8d83bjDzxwbDX7WwR7KbSeJWT42pCz7kM+BEjjPsOnZHuusXT3x2rrsBnYtYsbt98mSFiS
38KzTtFmXfkOBbCQdit1P76QnYJ1aXMGs6zP6GypQTadK/zYWvlm38QkVwueaJ0woESKW2pqKA
3970h2UMDHOrpepU1lj0YMzmotDHSTU3L909VvUMNg9uqfrQ6mSkb9j5Tl8oF2otOw5EzA1Yda
40KPmgsv62RWLYl80wXQRQwG0e/mgG75jp9lOhJdVXqcYbQpS9viwVaVkwH+69mu/bQI4gjoEs
41UYX6O71Re2z+cYhcm9UrK+DXuSFBXQOIlAFxKMW4B0apd6fU84FsZLMESOorXE5OE0A2B2ji
42J8QI0Exk4hUvWrMNJfUZwFyS7E05xV9ORuX1xmsKqkT4tVR5Nqln4vhvAY860VBoloz0CDkd
438seSBEjeMgRI9FvpYuflIeHg9urkwp6N+1f0DrJJhJY9ZQ0HTQhziJmIfvbEjNqCl7hEC28+
44F8I5tuViLgfSwcFFCvnS6WFoN4X6QdFdqMCbBEjdlI1c+IQGA/IuTDMJYCuQ/v+8BG5ZeWVH
45icPZmXfRat9eFK1dGKAJef6+Tf9HPuDjSpDyffrifsp7Dc34lmm7GN1+ON3ZMtwEUNm6epb8
461RKWjoI7jIKUV/M2p/0eeGSqs4b06KF/VR6dBwsJVL5DpnTsp3MV4j/CAOlRdSPZ5++tsKbM
47aplk+ceqQtpEFz1MYTtVV4+rlrWaBEA1okJyNZ5/tNOwM7B+XfOZ0xw+uyVi9v4byTZM2Qds
48J+d3YGYLAugTGHISLqQEerD8/gGK+/SL06b2gNedXPHtBAiBKX+Mdy3wFQQIqE9gVgvrFNUE
49CKKoTFoMGqnPBAjDPgLCklNfrwQI3Ek1vSq68w8ECBodu2FOZJVkBAgzwjfSr2N9WQQQTCoQ
50KkAbrS9tnjXn1I3+ZwQIrPx3eINo/YUECIeYWCFskxlYBAiDUdvZXwD3vgQIkEyZbbZWbUUE
51CH4+odl1Isk3BBj68fkqJ0fKJRWVLWuW/O3VE4BOPKwFlaIECFseVTdDUho8BAj+cOKvV2WA
52hgQgaXr+wwq+ItblG0Qxz8IVUXX6PV2mIdHwz4SCCvnCsaIECJhBYxdfLI/XBCDswamPn9MR
53yXi2HVQBineV+GtWVkIoZ2dCLFB9mQRMoAQI0nUR5a5AOJoECA+AunKlAlx8BAi5RtFeF4g1
54FQQIz/ie+16LlQcECOmNuVg5DXjMBAjH2nkfpXZgWwQIVdLuO/+kuHAECO/5rEHmyI9vBBD4
5516BU4Rd3YerDQnHtrwOQBCCkho1XxK5Maz8KLCNi20wvcGt8wsIXlj2h5q9ITBq7IgQQvKVY
564OfJ7bKbItP2dylwQgQYPIGxwkkbRXNraONYvN19G8UdF35rFOuIBAjf0sKz/618ZQQIxObr
57xJkRe0sECIC+ssnjEb2NBBBI+XM4OntVWGsRV9Td3sFgBAinGwIroo8O0gQQMGAwgc9PaLaG
58gBCiwSTrYQQIVHjfCQgOtygEUIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/g0thR0lM
59+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy043GNZBAhOqjyB2JbD
60NwQoR23XCYD9x6E20ChHJRXmaHwyMdYXKl5CUxypl7ois+sy2D7jDukS3wQIsTyyPgJi0GsA
61AAAAAAAAAAAA
62
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem b/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem
new file mode 100644
index 0000000000..9abf00b2f2
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-01.pem
@@ -0,0 +1,66 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIILyAIBADGB8zCB8AIBADCBmTCBkjELMAkGA1UEBhMC
3QVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYD
4VQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
5TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBAgIEbjANBgkq
6hkiG9w0BAQEFAARAq8xpbzGHqgX9f4ImK/MhlXvIfGWng7c0dC1YbQDww5kH4K0q
7VTv/qDl79r0O79M6rFEyq1hGnrelrZD+YzghgzCCCssGCSqGSIb3DQEHATAaBggq
8hkiG9w0DAjAOAgIAoAQIn8+kb8zj2JSAggqgxtGA/FLBBRs1wbBPgDCbSG0yCwjJ
9NsFg89/k6xuXo8c5YTwsw8+XlIVq03navpew6XxxzY090rD2OJ0t6HA6GqrIpd8W
10iSh/Atqn0yfLFmkLqgIAPRfzxUxqUocxLpQsLIFp2YNUGE+yps+UZmIjw/WHfdqr
11cWTmSTSvKuy3UkIJZCkGDBpTvqk4BFaHh4oTXEpgpNY+GKxjf9TDN9GQPqQZR7sg
12Qki4t2g4/SaqKl6EoJbpOrMHTQ9LYh2O7+XemEdvXjwpdv0kyffHiaVpBBAtthjT
13bzsu67v0b9h3uDKim13uyT0wx33GEmmmDsJwf/IPH/8eu2Ck5xaafpXGmFqon4uX
14kQtIPaNclFn7/hLxPw2VmBGaC0SYF3U1jyN96EBxdjqy8Aa6ByMXYDW5BcfqniD5
15mYXfw+b81lh1kutxaPaV4YJ9ZlRUW752N7VHo/fG0/fukoe5W9a8kIhgLpygllb/
16GP4oSF4wM6n1/OgRzZj2IWFiobKO4d/tMnh+C+PoEVAuFZcxQwi9GqvsK5OoIjVw
17Nx0XcVSOl1TTYS9SwC7ugMBCab73JiruC24pL78YM+NaIpIQ3On4DokJA2ZHtjBj
18ZIxF4tKA144RvFN6pBd6TVE5XM6KD/Vh9bjSmujtEAfdQ3TedvKJsbZuu0stErbv
19WcRy11I328l557ECU+3eODid62PpuefHp0NTZJGqnYIShBpKRBuyhNxkyjmPfzYc
20KgCQ69fRl3QOqCjobPpMHhVV3li1NrxKGedQcM8XcwpsTsPigp+51o2qgKzBNAqv
215kGumHOlMKsRfrs7jZCcSaOuEj97pYx08FLEgF23cav39MOQNUEM1dNU+EYslL4o
223RoSHRjUgPU+2t9c0prS9A/bPBDj/eD8p2kzccB4t1Uyu0s7kJoMwOJ/eNhPY6Eo
23qrED5bCgG97D1Giwt0rlMUozQYH6bw9G5qwP+YflmaGF7yKIBacI5EppxZ7SWHk6
24/VpGu8LDn+PdD9b/hm03lT5p5UEky0DyfQzF3mQ/Eds1WHigamtnrAR6BXyG3e+j
25JlqZnkLLFzx98xicz8kkjr+gRkMyyiS5FnYyvxKzfMtyn2lZ2st9nZGNNgMc9N62
26r5HgNbdDFHuRdKKzV+8kQfuMc3mOPpK1t9TFY+QgrxiB5p6S7VooI97YtP3Pbfkn
27szCEeD3V2G22kdwGnDd0OZGGJlrKt1lusYK4NJphBqLBr8EkMQQbol2a8UnAmuIr
28xKtOVGcMkoXj7ynbjr51BNswzuiFxS2cYU2QSb38Wi8uAYCInuIwaZi+whIslJzA
29bif7CtJpA1BeLOz03fKTKznjAE13/4FDgXumdweENDYPK3kx6QHxjyI06hxRMUK7
30nbi9aWCXmXP3vU7D21dp0XnAMzRQJ565JV3aHRoY7XDa4LePa7PP9ywyafOE5yCW
317ndqx3J+2JhTDvSFsW8/q3H3iyeFhykuJVS6yugpim58soznxNoixiZkxWvdOVdi
32q1QwppRLv8chjLPNMk8mQvskszPNxTFbyxEJks3EzVGVaQ3wNZDV215D6LgV10+o
33PK/CQkZY2iigAZqUyF44lBFRRThyC+Eyt5c9rKGrkCjhUxIKQDmFhEIFzObgOL8w
34yiEXRLEix1FjqBj0I+esFcCxjqHVFtHtPDSJBmZ5eLnYMKL0by+SYMAa9z0CReIz
35l8JLL6EVIFz8kFxlkGWjr4dnOzhhPOq/mCpp0WxbavDfdhE87MdXJZBnLwoT62QG
36955HlAoEQBOGJbcoHeV0oq2fWNwGwn7ijqqDAbxFBp/sP6TGqpxr56+RWYbgQyq4
37UV6rcULMQP/3axlMbK2Trki/9Pn276O59odWfDcvOozr1WQCPDaXVhzlENc9i3I8
38pKEOVQf/UBczJ0NR9aTEF80dRg2lpXwD0ho4N0AvSiVbgxC7cPZHQwIqvq9LHRUs
39/4n+Vu3SVYU3cAxolUTiCGUSlBfkw+e0iOfkSPjDbZw/a7OBNZpedWKBxlhY91D6
404g5mNBShMCIKrTFzGN32fSqvHfN24w88cGw1+1sEeym0niVk+NqQs+5DPuM+w6dk
41e66xdPfHauuwGdi1ixu33yZIWJIrNO0WZd+Q4FsJB2K3U/vpCdgnVpcwazrM/obK
42lBNp0r/Nha+WbfxCRXC55onTCqW2pqKA70h2UMDHOrpepU1lj0YMzmotDHSTU3L9
4309VvUMNg9uqfrQ6mSkb9j5Tl8oF2otOw5EzA1YdaKPmgsv62RWLYl80wXcBtHv5o
44Bu+Y6fZToSXVV6nGG0KUvb4sFWlZMB/uvZrv20COII6BLFGF+ju9UXts/nGIXJvV
45Kyvg17khQV0DiJQBcSjFuAdGqXen1POBbGSz6itcTk4TQDYHaOInxAjQTGTiFS9a
46sw0l9RnAXJLsTTnFX05G5fXGawqqRPi1VHk2qWfi+G8BjzrRUGiWjPQIOR3yx5IE
47SN4y9FvpYuflIeHg9urkwp6N+1f0DrJJhJY9ZQ0HTQhziJmIfvbEjNqCl7hEC28+
48F8I5tuViLgfSwcFFCvnS6WFoN4X6QdFdqMCb3ZSNXPiEBgPyLkwzCWArkP7/vARu
49WXllR4nD2Zl30WrfXhStXRigCXn+vk3/Rz7g40qQ8n364n7Kew3N+JZpuxjdfjjd
502TLc2bp6lvzVEpaOgjuMgpRX8zan/R54ZKqzhvTooX9VHp0HCwlUvkOmdOyncxXi
51P8IA6VF1I9nn762wpsxqmWT5x6pC2kQXPUxhO1VXj6uWtZo1okJyNZ5/tNOwM7B+
52XfOZ0xw+uyVi9v4byTZM2QdsJ+d3YGYLAugTGHISLqQEerD8/gGK+/SL06b2gNed
53XPHtgSl/jHct8BWoT2BWC+sU1aKoTFoMGqnPwz4CwpJTX6/cSTW9KrrzDxodu2FO
54ZJVkM8I30q9jfVlMKhAqQButL22eNefUjf5nrPx3eINo/YWHmFghbJMZWINR29lf
55APe+kEyZbbZWbUV+PqHZdSLJN/rx+SonR8olFZUta5b87dUTgE48rAWVolseVTdD
56Uho8/nDir1dlgIZpev7DCr4i1uUbRDHPwhVRdfo9XaYh0fDPhIIK+cKxophBYxdf
57LI/X7MGpj5/TEcl4th1UAYp3lfhrVlZCKGdnQixQfZkETKDSdRHlrkA4mg+AunKl
58Alx8uUbRXheINRXP+J77XouVB+mNuVg5DXjMx9p5H6V2YFtV0u47/6S4cO/5rEHm
59yI9v+NegVOEXd2Hqw0Jx7a8DkKSGjVfErkxrPwosI2LbTC9wa3zCwheWPaHmr0hM
60GrsivKVY4OfJ7bKbItP2dylwQjyBscJJG0Vza2jjWLzdfRvFHRd+axTriN/SwrP/
61rXxlxObrxJkRe0uAvrLJ4xG9jUj5czg6e1VYaxFX1N3ewWCnGwIroo8O0jBgMIHP
62T2i2hoAQosEk62FUeN8JCA63KIoraFoANfhZgIShpOd/RRxFU4/7xZR5tMdGoYz/
63g0thR0lM+Hi88FtFD4mAh/Oat4Ri8B7bv04aokjN2UHz6nPbHHjZ8zIqpbYTCy04
643GNZTqo8gdiWwzdHbdcJgP3HoTbQKEclFeZofDIx1hcqXkJTHKmXuiKz6zLYPuMO
656RLfsTyyPgJi0GsAAAAA
66-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-02 b/src/lib/libcrypto/pkcs7/t/msie-enc-02
new file mode 100644
index 0000000000..7017055965
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-02
@@ -0,0 +1,90 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABEACr4tn
5kSzvo3aIlHfJLGbfokNCV6FjdDP1vQhL+kdXONqcFCEf9ReETCvaHslIr/Wepc5j2hjZselzgqLn
6rM1ZMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABEBanBxKOvUoRn3DiFY55lly2TPu2Cv+dI/GLrzW6qvnUMZPWGPGaUlPyWLMZrXJ
10xGXZUiRJKTBwDu91fnodUEK9MIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQImxKZEDWP
11EuOggASCBACBi1bX/qc3geqFyfRpX7JyIo/g4CDr62GlwvassAGlIO8zJ5Z/UDIIooeV6QS4D4OW
12PymKd0WXhwcJI0yBcJTWEoxND27LM7CWFJpA07AoxVCRHTOPgm794NynLecNUOqVTFyS4CRuLhVG
13PAk0nFZG/RE2yMtx4rAkSiVgOexES7wq/xWuoDSSmuTMNQOTbKfkEKqdFLkM/d62gD2wnaph7vKk
14PPK82wdZP8rF3nUUC5c4ahbNoa8g+5B3tIF/Jz3ZZK3vGLU0IWO+i7W451dna13MglDDjXOeikNl
15XLsQdAVo0nsjfGu+f66besJojPzysNA+IEZl6gNWUetl9lim4SqrxubUExdS2rmXnXXmEuEW/HC7
16dlTAeYq5Clqx5id6slhC2C2oegMww3XH9yxHw6OqzvXY6pVPEScEtBMQLgaKFQT+m2SRtbTVFG7c
17QcnUODyVB1IbpQTF1DHeeOX1W/HfpWZym8dzkti6SCyeumHmqO406xDiIMVKtHOqM86nEHuAMZsr
18cLy+ey6TEJvR6S4N8QRzng8JJDZDTJXQN6q84aEudsnOrw2KyOVwPpI6ey4qBsHUgQ8kAFy5lsQa
19WV45h6exgUwbBcKLgPZGFj+OdD2RKJsTb83/UqbJS5Q/lGXhzBlnaYucyJxEprRxbntmcnOEPFJe
20+tRDUwOTd7qlJljdhIJL+uDcooL9Ahgo6Cwep6tduekv2cSEohJeTE8Dvy34YRhMbLvnFNdmnpNy
21rNZDYVVxxaKoyd2AfB8NPFZh1VdAYfI3R1QAQ2kXEef5NNIfVQfMzD9akJn4RP+Kv32Qaxm4FrnK
22xmwRyGJShavIBc2ax+F1r1+NZXuSBHn5vfoRTxOk0ST4dXsw74dnlYUMRaSu4qqUdM9jsXSyeX4Z
23gQgkR2bkaYO6ezFgenFIa7QWVw8rXZAEZ5aibCxbnY1VE41PYIvhlLdbFJhH9gY22s+fFAuwnzyA
24SRjC40A9aAEItRlaPStWSGiqlLRgNkBBwdpv2l2YPBd2QzHx6ek6XGrvRJuAC+Nh62rtQKwpNH54
25YAOHW55maBFW2SQ3TF+cZ6NbbqhCmHTyyR7mcSYc9sXSVDWEhYKQ1iyU870zhHWVpvglZizZetJC
26ZFjYex3b1ngVdcgargOvpPq9urCKKi2mbkqv/EFpzSWGXkKSpfCG/XfMnEOtkNrB8S06vnk2JcJB
27OBqJot+uuSH5hOg0vTpxX2DuONJSiWSWyfRE/lTfJJFXwhod7SXclUyXPeSyibcSic2hVAzDmwjD
2831js/j2k02PI/agPhr3UQ8cMgcNAiaoCKbNaWfn6BGbCAbTchxzUlo2cSJiLlrX2IDZmfXbXmZCo
29m1smWIG+BIIEALiuAxDb6dWLAYyVBoN9hYI4AiPeZAY9MtvQ6AV8o2/EFm6PvYGXy3Hei5830CH0
30PBeX7Kdd6ff1y33TW/l5qSkIL1ULTGR7okFfJePHDmq1dFt6/JOMptiQ8WSu7CsJQvZ9VTFXeYFc
31ZqCPPZc1NrPegNK70Zf9QxWIbDAevJ5KLBf1c6j8pU2/6LnvDY6VjaTvYSgr7vTR8eVzH4Rm77W0
32iOHxg5VcODv6cGSVyuvbX8UAGo8Cmb58ERDtBDJBQXVpWKLNAuDJ9GX8n2zNkpjZLbPSkcmuhqGa
33BJBE/BaCTkUQWlY9dIbRtEnxIU1mfbPPdx1Ppa8DqGDjSOsQdKcKYNNZtayEw++EIpmpdBNsKphC
34fB8UEK2Wkk4ZVW+qyGoi/r0MFsvO1NmSOOZ0o/jy/YHmoeURHhPy97AO3eVTkEAa5CfJEJybmo56
357CDw/FwoGAUCgsoz7rlxzMudr/IhHIH+APinncxXlHO2ecvHD9i8DaHGA8tVifgsUhqQoZieULut
36eF94O5UAxOkv41UZssYTwN4nYrN1QkesZl3BX4ORS4EE30/PQ23ARf3WZptZrCJevGm2ZYzGeh8x
37g17mCDfiLO+bff4qP/4mC96Pu4ia6j4to5BwKIJS/+DCuoD8WeSKF4pugXQkMUiHdQnNnVP9Sp2O
38/4ly5mO8JzrQC59V2bnTNBqPhpno8kfJvK5TypPSVC+bTzern3rJ6UceB3srcn9zxKx9GdNydJQj
39yWjv8ec3n3d1nuQwhz5Q053NBhIjwoGg3Go7LO6i78ZOlpF7dcoAO13NfHLyNjnyHCaiWtVRTct9
40rLf5vN00urSn8YJngHk1eTKK8nHGIcOg6YdYDOD2nE5XwRijKmieG8Xa3eKRzfbL06GrBQENle6J
41mC131bp3cRVxpjq+o6RAbGoMm4yICsL4eTarCQrsyHmoPHqr91UHo91avyxU7knWmEhX27ybmsrs
428aeZwPHixL14TeyhruCqRVvkf1Ks7P+z8MPUboGNqQe2WLN8ktCGEr15O8MJR/em86G03Jfo4oaw
43/DVUH5RwLT6acedOGuzMh/2r8BcmemhVQ8/cWvV4YJ0tOW4hzyVHC5hQf8sZ3LzxXLH6Ohnrbprh
44xvrdbaSdChWZDDP0bCCbxEhkwuBkBeKZrMbwRTP+TPTPYLVTH/CmKLzKh/114tkGkyO3hHS4qExU
45V39F2Sj4mylx+hD0+20D9pntpNi7htccGlOm6yNM69at/3+kLgJJyoIlaxLcCUYHNMifDt+T3p/t
465U4XmD53uUQ6M8dvj/udqPekNSUfse15yrd9pjOt5PcJuqW28q0sFHf9pHIgz3XZFMe5PD7ppw6r
47S+C6Ir4PrYIEggQA7ZDVtiCm+BbtNNB/UJm79/OQ5mp5bTI0kPmDeycaWTa0Ojpum+c/dpG/iJOB
48DICj7jHOXSHT7JlGyX6aSFJUltucAnZvwzhPDmdDaIDiKSk85GqgdDWVfGosSCX9Ph/T3WpIxnwf
49WSDRtIHkWTjly+pe4yy5K6/XISy/L5Zh/fhiI5fjHjgzmlibs2ru4nVw6hBhUvlSSe2BEs5d9h/y
50NH8Wy3qvb2D3jh7hkepFtZJGNTHp8ZUC7Ns2JIpQYObsaxdI65i3mMOu7fRwI+0/4ejsWhP6KCEi
51LgwvLg0qM82ma6YB7qHAHboaczRVEffDcJUG4a5uycB0DoZFn+uEaEFyili20hCn4hVfsqUQk2PT
528Mo1tSl5e30xI1YJZrRgiJm9nHRX6fLizngP+ILJLPHZsPvlSVIfY+/v/FR8feKOjaGhyGF51BAx
53aM2NIQ4jMP5/X+U5gQybi0E6u7rroDhaHsKmCMgXqszwXWCpedA/sEbeHpiTC59YlPPSlIOMc9vP
54Ko/mQCfWy/9icUaIfKQldvkllUxxNkqu6AbIpHVscbAEzSPs5xbQXU8EZNNCDisFnnpY3nQ3eLnl
55m89saTJxRb7NWHRMlmPv7qgD7uMIq3vdOGA7i5wT9MeoNIgK1/DsgH30s6RWjJy4YyyLmRTXPzbj
56hbQVpEmiMRbEidIvUx2OjKVxVQIcgtLsa2lvHQ4XL1cpLr5GVtOgy0fMg5OCDUUDsvjgjgLQ3P2U
57p2nVY5FM6/QpPc5DTLuuR9ekI2/c9Biz09RtcYDUQK2ajdo8h1IyKqHFoB7h48OXxXKKY94DY0TG
58x6PonB/epj8orAw4QKmm5M0vXYwBOqRymCTHTqOJGObdLx1euFFyqguzHJOU2gAGZI0z9Lg1yRuF
59yhdPZyuniIcmtLNxRZ1duYHErcAyX56qndmLXt7UVkATai/rIMuoJLfAsUnVuTUS5p7tJM754UZT
607lTcXvDJgOUNnBRaIcxC3pxvbrYDJ2iFJ72xkxUP2p74gucqg25XnCVmQuLg6zDDxF6CLuw9isxy
61Xg4pkneMN//7fpp8GYl9nyZm2yqYYM+jcw0fcVc64L+X4w/gL3H2UMGgxIHSJp7HIG7VKHtXrNyj
62dPXXPVUsMsAAimqOr0Lr2sZWirfuivLaPTqhbkvG5PF7K3gT80AOIcd/6EIHBy2hZ7ukfjHmdP4L
63yQOhTQklaKzGHI0mypq0uFLWJOUlZnVrMiLP1xrWkpC8Ro9eo6mfjjQ45z8adC43a47klwTEzvod
643rNEFIGJJUEjAN3mbqie7IxoSJknBBJK0D9lZEQ8lZWlq7vuN8JdqPM6xh155jMVsPwjLK6Tzkj5
65BpRD9Tgm3u6HPQSCBADgkWEN75Mu9TGosXY0xm1k6K6sPv8L949CrLWo4r1I2LA072bTGvQP28Vs
66hUA76jgcT1ocC++9PoktIK10YCq5w+FfMAQ04KeCXuAdmiY2iAT4Slea61PMCMta3mVGyLUZCLEm
67P+I0UKR5mlO0fGEcjU9j8TmbjZqxNFqloLsU7oSi7Os0EtYHkdAVrExUyOc/ZDie6fBjdLTmLdCm
68bE9JNwjlbXypdTZupGgLNhKGDIskUAAMwZYayI6YfSIMkNCeAYTnjOuGZZ1msCXGXsfMBR1sfUIj
699UeGjwD8gq+UVVHX/oeoH/m0eJ5ppqi3+nUlgc9DvpYsC/Fg0G2KuYb9B+VJ+a4GMzQSPREoFtQp
70B9dtLkBb7Ha/hpGWTIdqzW0eAo5llyN8FNvl2Fu2IcLaNmWFO69gLjRKQopp0dvFOuwAVI6fvGDj
71p1WigoNbFZl8N+iiWmzKOjoG2ZLbez1clZCms/JPJrXhEMMOxWpVzkQyN336VWHmGgMcjaKCGSeA
722nnESIGuiCXMrkHlGfabYIsKcHFCo2t13uXyZPf0zSPTkuD0Eh92wqC9pvA3gvrrCUfo9Mn3bs+e
73KWKmDlpcs8mDn032oIg+zrQhIduMqXVn3evzeVM3B5MBOGMvg51/SXg7R+MC/463juQQEb9IVe/I
74YGnO//oWm9lw/377Af/qH+FnN02obJw1FvesQIs9e5RHNQykKbO+vmVJQl1nd9DZWrHDNO7/80Yz
752hCm7Tws5nSRN2iFlyRaYJHr7ypxkU2rCak2r6ua7XDwu1qU2RT3+qPjT1RuxQ2oTlHyGkKPMZGC
76Rc+CSWz5aeeCmHZVwdb3nC8YpfsujMiYqygLeuQ82pjKuR7DIKGmnfcOLdv5F+Ek2Wyy0D98iSgk
77+aoQGYLhL9llU13pn21uRsDY5uGcXiIw1IETFlTdgENEv8futZuJsegrp7fmFXyNoNyFNyypeDrM
786ZqR4vKxFjg3tKKeVpkw/W4EAklzMxmNiazGNDBHsnYV3rwPlKa+HeeE2YxnsKwGLCNgRYUXTaJk
79461vS160z3dvh/mLfdZ7MYCkmO3bNE3ELUDAw7YQkSuo9ujzdFKte9LC34sjg9fOex3ThAg5Y50n
80wYm4zBmGM7yEqL8O6QgnM6tIDFS9XryDaLNzcGhMWqMvhzO6sC/AA2WfLgwS517Cp03IkJQWqG9q
81w52+E+GAtpioJfczEhlv9BrhjttdugRSjJrG8SYVYE4zG3Aur5eNBoGaALIOHOtPw8+JovQmIWcF
82oaJ/WQuglFrWtew51IK6F8RiHAOBVavZOuZcO7tV+5enVfreOd0rX8ZOy4hYmHhmF1hOrrWOn+Ee
83E0SYKonXN01BM9xMBIIBSLCvNAppnGPTUGjwbMJRg1VJ2KMiBWH5oJp8tyfIAxMuWFdtaLYbRSOD
84XbOAshPVK8JAY8DQDkzqaCTAkLTfSRAt9yY6SbUpMsRv7xa8nMZNJBJzJT9b/wNjgiOJgaGuJMkV
852g/DX2jfP3PrMM/Sbnz7edORXHj1Pa5XTT8nG5MS0FuZgvevdq3o/gVVAz+ZCKOH3ShMzZvfp01l
86SX5gaJTflmU6cdNwtn2yZ6IScF7OrjUeA9iEoSVR9dQcA+4lB3RAG3LMwcnxXY35D7+PMJzHIZdF
87cSnq+n03ACY2/E/T31iijRH29rvYHGI+mP/ieYs45iq4fTWo6i1HofeWLdP0fX7xW3XO0/hWYFiw
88BxKu66whAbRhaib3XJNvetVs25ToYXyiDpjG+cd5rCMei8sGQwTBj9Zeh0URoeMW1inTP0JvCmMU
89rZgAAAAAAAAAAAAA
90
diff --git a/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem b/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem
new file mode 100644
index 0000000000..279c5d830b
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-enc-02.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITQAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQAKvi2eRLO+jdoiUd8ksZt+iQ0JXoWN0
6M/W9CEv6R1c42pwUIR/1F4RMK9oeyUiv9Z6lzmPaGNmx6XOCoueszVkwgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQFqcHEo69ShGfcOIVjnmWXLZM+7Y
11K/50j8YuvNbqq+dQxk9YY8ZpSU/JYsxmtcnEZdlSJEkpMHAO73V+eh1QQr0wghFz
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECJsSmRA1jxLjgIIRSIGLVtf+
13pzeB6oXJ9GlfsnIij+DgIOvrYaXC9qywAaUg7zMnln9QMgiih5XpBLgPg5Y/KYp3
14RZeHBwkjTIFwlNYSjE0PbsszsJYUmkDTsCjFUJEdM4+Cbv3g3Kct5w1Q6pVMXJLg
15JG4uFUY8CTScVkb9ETbIy3HisCRKJWA57ERLvCr/Fa6gNJKa5Mw1A5Nsp+QQqp0U
16uQz93raAPbCdqmHu8qQ88rzbB1k/ysXedRQLlzhqFs2hryD7kHe0gX8nPdlkre8Y
17tTQhY76LtbjnV2drXcyCUMONc56KQ2VcuxB0BWjSeyN8a75/rpt6wmiM/PKw0D4g
18RmXqA1ZR62X2WKbhKqvG5tQTF1LauZeddeYS4Rb8cLt2VMB5irkKWrHmJ3qyWELY
19Lah6AzDDdcf3LEfDo6rO9djqlU8RJwS0ExAuBooVBP6bZJG1tNUUbtxBydQ4PJUH
20UhulBMXUMd545fVb8d+lZnKbx3OS2LpILJ66Yeao7jTrEOIgxUq0c6ozzqcQe4Ax
21mytwvL57LpMQm9HpLg3xBHOeDwkkNkNMldA3qrzhoS52yc6vDYrI5XA+kjp7LioG
22wdSBDyQAXLmWxBpZXjmHp7GBTBsFwouA9kYWP450PZEomxNvzf9SpslLlD+UZeHM
23GWdpi5zInESmtHFue2Zyc4Q8Ul761ENTA5N3uqUmWN2Egkv64Nyigv0CGCjoLB6n
24q1256S/ZxISiEl5MTwO/LfhhGExsu+cU12aek3Ks1kNhVXHFoqjJ3YB8Hw08VmHV
25V0Bh8jdHVABDaRcR5/k00h9VB8zMP1qQmfhE/4q/fZBrGbgWucrGbBHIYlKFq8gF
26zZrH4XWvX41le5IEefm9+hFPE6TRJPh1ezDvh2eVhQxFpK7iqpR0z2OxdLJ5fhmB
27CCRHZuRpg7p7MWB6cUhrtBZXDytdkARnlqJsLFudjVUTjU9gi+GUt1sUmEf2Bjba
28z58UC7CfPIBJGMLjQD1oAQi1GVo9K1ZIaKqUtGA2QEHB2m/aXZg8F3ZDMfHp6Tpc
29au9Em4AL42Hrau1ArCk0fnhgA4dbnmZoEVbZJDdMX5xno1tuqEKYdPLJHuZxJhz2
30xdJUNYSFgpDWLJTzvTOEdZWm+CVmLNl60kJkWNh7HdvWeBV1yBquA6+k+r26sIoq
31LaZuSq/8QWnNJYZeQpKl8Ib9d8ycQ62Q2sHxLTq+eTYlwkE4Gomi3665IfmE6DS9
32OnFfYO440lKJZJbJ9ET+VN8kkVfCGh3tJdyVTJc95LKJtxKJzaFUDMObCMPfWOz+
33PaTTY8j9qA+GvdRDxwyBw0CJqgIps1pZ+foEZsIBtNyHHNSWjZxImIuWtfYgNmZ9
34dteZkKibWyZYgb64rgMQ2+nViwGMlQaDfYWCOAIj3mQGPTLb0OgFfKNvxBZuj72B
35l8tx3oufN9Ah9DwXl+ynXen39ct901v5eakpCC9VC0xke6JBXyXjxw5qtXRbevyT
36jKbYkPFkruwrCUL2fVUxV3mBXGagjz2XNTaz3oDSu9GX/UMViGwwHryeSiwX9XOo
37/KVNv+i57w2OlY2k72EoK+700fHlcx+EZu+1tIjh8YOVXDg7+nBklcrr21/FABqP
38Apm+fBEQ7QQyQUF1aViizQLgyfRl/J9szZKY2S2z0pHJroahmgSQRPwWgk5FEFpW
39PXSG0bRJ8SFNZn2zz3cdT6WvA6hg40jrEHSnCmDTWbWshMPvhCKZqXQTbCqYQnwf
40FBCtlpJOGVVvqshqIv69DBbLztTZkjjmdKP48v2B5qHlER4T8vewDt3lU5BAGuQn
41yRCcm5qOeuwg8PxcKBgFAoLKM+65cczLna/yIRyB/gD4p53MV5RztnnLxw/YvA2h
42xgPLVYn4LFIakKGYnlC7rXhfeDuVAMTpL+NVGbLGE8DeJ2KzdUJHrGZdwV+DkUuB
43BN9Pz0NtwEX91mabWawiXrxptmWMxnofMYNe5gg34izvm33+Kj/+Jgvej7uImuo+
44LaOQcCiCUv/gwrqA/FnkiheKboF0JDFIh3UJzZ1T/Uqdjv+JcuZjvCc60AufVdm5
450zQaj4aZ6PJHybyuU8qT0lQvm083q596yelHHgd7K3J/c8SsfRnTcnSUI8lo7/Hn
46N593dZ7kMIc+UNOdzQYSI8KBoNxqOyzuou/GTpaRe3XKADtdzXxy8jY58hwmolrV
47UU3Lfay3+bzdNLq0p/GCZ4B5NXkyivJxxiHDoOmHWAzg9pxOV8EYoyponhvF2t3i
48kc32y9OhqwUBDZXuiZgtd9W6d3EVcaY6vqOkQGxqDJuMiArC+Hk2qwkK7Mh5qDx6
49q/dVB6PdWr8sVO5J1phIV9u8m5rK7PGnmcDx4sS9eE3soa7gqkVb5H9SrOz/s/DD
501G6BjakHtlizfJLQhhK9eTvDCUf3pvOhtNyX6OKGsPw1VB+UcC0+mnHnThrszIf9
51q/AXJnpoVUPP3Fr1eGCdLTluIc8lRwuYUH/LGdy88Vyx+joZ626a4cb63W2knQoV
52mQwz9Gwgm8RIZMLgZAXimazG8EUz/kz0z2C1Ux/wpii8yof9deLZBpMjt4R0uKhM
53VFd/Rdko+JspcfoQ9PttA/aZ7aTYu4bXHBpTpusjTOvWrf9/pC4CScqCJWsS3AlG
54BzTInw7fk96f7eVOF5g+d7lEOjPHb4/7naj3pDUlH7Htecq3faYzreT3CbqltvKt
55LBR3/aRyIM912RTHuTw+6acOq0vguiK+D62C7ZDVtiCm+BbtNNB/UJm79/OQ5mp5
56bTI0kPmDeycaWTa0Ojpum+c/dpG/iJOBDICj7jHOXSHT7JlGyX6aSFJUltucAnZv
57wzhPDmdDaIDiKSk85GqgdDWVfGosSCX9Ph/T3WpIxnwfWSDRtIHkWTjly+pe4yy5
58K6/XISy/L5Zh/fhiI5fjHjgzmlibs2ru4nVw6hBhUvlSSe2BEs5d9h/yNH8Wy3qv
59b2D3jh7hkepFtZJGNTHp8ZUC7Ns2JIpQYObsaxdI65i3mMOu7fRwI+0/4ejsWhP6
60KCEiLgwvLg0qM82ma6YB7qHAHboaczRVEffDcJUG4a5uycB0DoZFn+uEaEFyili2
610hCn4hVfsqUQk2PT8Mo1tSl5e30xI1YJZrRgiJm9nHRX6fLizngP+ILJLPHZsPvl
62SVIfY+/v/FR8feKOjaGhyGF51BAxaM2NIQ4jMP5/X+U5gQybi0E6u7rroDhaHsKm
63CMgXqszwXWCpedA/sEbeHpiTC59YlPPSlIOMc9vPKo/mQCfWy/9icUaIfKQldvkl
64lUxxNkqu6AbIpHVscbAEzSPs5xbQXU8EZNNCDisFnnpY3nQ3eLnlm89saTJxRb7N
65WHRMlmPv7qgD7uMIq3vdOGA7i5wT9MeoNIgK1/DsgH30s6RWjJy4YyyLmRTXPzbj
66hbQVpEmiMRbEidIvUx2OjKVxVQIcgtLsa2lvHQ4XL1cpLr5GVtOgy0fMg5OCDUUD
67svjgjgLQ3P2Up2nVY5FM6/QpPc5DTLuuR9ekI2/c9Biz09RtcYDUQK2ajdo8h1Iy
68KqHFoB7h48OXxXKKY94DY0TGx6PonB/epj8orAw4QKmm5M0vXYwBOqRymCTHTqOJ
69GObdLx1euFFyqguzHJOU2gAGZI0z9Lg1yRuFyhdPZyuniIcmtLNxRZ1duYHErcAy
70X56qndmLXt7UVkATai/rIMuoJLfAsUnVuTUS5p7tJM754UZT7lTcXvDJgOUNnBRa
71IcxC3pxvbrYDJ2iFJ72xkxUP2p74gucqg25XnCVmQuLg6zDDxF6CLuw9isxyXg4p
72kneMN//7fpp8GYl9nyZm2yqYYM+jcw0fcVc64L+X4w/gL3H2UMGgxIHSJp7HIG7V
73KHtXrNyjdPXXPVUsMsAAimqOr0Lr2sZWirfuivLaPTqhbkvG5PF7K3gT80AOIcd/
746EIHBy2hZ7ukfjHmdP4LyQOhTQklaKzGHI0mypq0uFLWJOUlZnVrMiLP1xrWkpC8
75Ro9eo6mfjjQ45z8adC43a47klwTEzvod3rNEFIGJJUEjAN3mbqie7IxoSJknBBJK
760D9lZEQ8lZWlq7vuN8JdqPM6xh155jMVsPwjLK6Tzkj5BpRD9Tgm3u6HPeCRYQ3v
77ky71MaixdjTGbWTorqw+/wv3j0KstajivUjYsDTvZtMa9A/bxWyFQDvqOBxPWhwL
78770+iS0grXRgKrnD4V8wBDTgp4Je4B2aJjaIBPhKV5rrU8wIy1reZUbItRkIsSY/
794jRQpHmaU7R8YRyNT2PxOZuNmrE0WqWguxTuhKLs6zQS1geR0BWsTFTI5z9kOJ7p
808GN0tOYt0KZsT0k3COVtfKl1Nm6kaAs2EoYMiyRQAAzBlhrIjph9IgyQ0J4BhOeM
8164ZlnWawJcZex8wFHWx9QiP1R4aPAPyCr5RVUdf+h6gf+bR4nmmmqLf6dSWBz0O+
82liwL8WDQbYq5hv0H5Un5rgYzNBI9ESgW1CkH120uQFvsdr+GkZZMh2rNbR4CjmWX
83I3wU2+XYW7Yhwto2ZYU7r2AuNEpCimnR28U67ABUjp+8YOOnVaKCg1sVmXw36KJa
84bMo6OgbZktt7PVyVkKaz8k8mteEQww7FalXORDI3ffpVYeYaAxyNooIZJ4DaecRI
85ga6IJcyuQeUZ9ptgiwpwcUKja3Xe5fJk9/TNI9OS4PQSH3bCoL2m8DeC+usJR+j0
86yfduz54pYqYOWlyzyYOfTfagiD7OtCEh24ypdWfd6/N5UzcHkwE4Yy+DnX9JeDtH
874wL/jreO5BARv0hV78hgac7/+hab2XD/fvsB/+of4Wc3TahsnDUW96xAiz17lEc1
88DKQps76+ZUlCXWd30NlascM07v/zRjPaEKbtPCzmdJE3aIWXJFpgkevvKnGRTasJ
89qTavq5rtcPC7WpTZFPf6o+NPVG7FDahOUfIaQo8xkYJFz4JJbPlp54KYdlXB1vec
90Lxil+y6MyJirKAt65DzamMq5HsMgoaad9w4t2/kX4STZbLLQP3yJKCT5qhAZguEv
912WVTXemfbW5GwNjm4ZxeIjDUgRMWVN2AQ0S/x+61m4mx6Cunt+YVfI2g3IU3LKl4
92OszpmpHi8rEWODe0op5WmTD9bgQCSXMzGY2JrMY0MEeydhXevA+Upr4d54TZjGew
93rAYsI2BFhRdNomTjrW9LXrTPd2+H+Yt91nsxgKSY7ds0TcQtQMDDthCRK6j26PN0
94Uq170sLfiyOD1857HdOECDljnSfBibjMGYYzvISovw7pCCczq0gMVL1evINos3Nw
95aExaoy+HM7qwL8ADZZ8uDBLnXsKnTciQlBaob2rDnb4T4YC2mKgl9zMSGW/0GuGO
962126BFKMmsbxJhVgTjMbcC6vl40GgZoAsg4c60/Dz4mi9CYhZwWhon9ZC6CUWta1
977DnUgroXxGIcA4FVq9k65lw7u1X7l6dV+t453Stfxk7LiFiYeGYXWE6utY6f4R4T
98RJgqidc3TUEz3EywrzQKaZxj01Bo8GzCUYNVSdijIgVh+aCafLcnyAMTLlhXbWi2
99G0Ujg12zgLIT1SvCQGPA0A5M6mgkwJC030kQLfcmOkm1KTLEb+8WvJzGTSQScyU/
100W/8DY4IjiYGhriTJFdoPw19o3z9z6zDP0m58+3nTkVx49T2uV00/JxuTEtBbmYL3
101r3at6P4FVQM/mQijh90oTM2b36dNZUl+YGiU35ZlOnHTcLZ9smeiEnBezq41HgPY
102hKElUfXUHAPuJQd0QBtyzMHJ8V2N+Q+/jzCcxyGXRXEp6vp9NwAmNvxP099Yoo0R
1039va72BxiPpj/4nmLOOYquH01qOotR6H3li3T9H1+8Vt1ztP4VmBYsAcSruusIQG0
104YWom91yTb3rVbNuU6GF8og6YxvnHeawjHovLBkMEwY/WXodFEaHjFtYp0z9Cbwpj
105FK2YAAAAAA==
106-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/msie-s-a-e b/src/lib/libcrypto/pkcs7/t/msie-s-a-e
new file mode 100644
index 0000000000..0067794d70
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-s-a-e
@@ -0,0 +1,91 @@
1
2MIAGCSqGSIb3DQEHA6CAMIACAQAxggHCMIHMAgEAMHYwYjERMA8GA1UEBxMISW50ZXJuZXQxFzAV
3BgNVBAoTDlZlcmlTaWduLCBJbmMuMTQwMgYDVQQLEytWZXJpU2lnbiBDbGFzcyAxIENBIC0gSW5k
4aXZpZHVhbCBTdWJzY3JpYmVyAhBgQJiC3qfbCbjdj5INYLnKMA0GCSqGSIb3DQEBAQUABECjscaS
5G0U299fqiEAgTqTFQBp8Ai6zzjl557cVb3k6z4QZ7CbqBjSXAjLbh5e7S5Hd/FrFcDnxl1Ka06ha
6VHGPMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UE
7BxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
8UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0GCSqG
9SIb3DQEBAQUABECsyHXZ1xaiv0UQRvOmVYsaF38AL2XX75wxbCsz5/wOg7g3RP4aicZxaR4sBog0
10f2G1o9om/hu+A0rIYF/L4/GUMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIAoAQIsozQrnwj
11cc2ggASCBAAQz/LPoJe/+iYWeTwSebz6Q9UeKZzQ2UWm7GLtEM3s3c9SCvpmkwIRdEhLjWaBJMyI
12DiL7t1I1vMf9inB8LXgAcIEYkpNScjS8ERA9Ebb7ieNKSBg7w7B8ATHFxLSlDADqRgoZrB1Ctfgf
13ximp3EgxTgnhtyQhZxXW7kBQyFRwumplrJXOp7albP7IothrOKncw30IJT1fwPxWNMItI9juXF0U
14CbWVSjPzGBo4+XNXMvUO6MplOQEz/ywEQ9E8OZAQex1Zw9qq5ppsXB2pMsYV5sLJGikukMYKquiz
153YK+tN6J8ahLcDUs+VGwqvZi17gpBTlbEP+ZmXJpnO63t1yTEB0V5AZcRKWUOhzlCBM5YUagqNoY
16cpsmSvOK6bYzkUKOrzWpDCAtGZ/Dvul5dTZZmxs2WpM+iyeHXMxO3huy8K1brPTqt1f1sHhuq1jD
171eXedaCjIgUW9qV18vNAQCof/Yb6T/1fxztf/jD7pPLQJ+7LJkKCAEHGcaizpoKqhYcttaEhLq1G
18O+Ohqf7yFegMdTJ3wwP324w5ZYSU5fLo2Z34/Edf6EGvXyTIqVfAmEBALd6JGVdN5GlYYTxrL+eO
19P80Z4ao4YKoxwEmRp5bmQsQ8B29QhOFKmC6eiG5B96qLMtp7Zmu1grDNxTd6OXShWVwYARD0/B1P
20Sy0PAfk9Gb4fAkO9fZJDQYZ7s0mM5iOPEeSR7820TolOb+KfRabLA9d714jsc2jEykKlpP66Bh4j
21aCsyqJ0uUQcE8SnzrKAqGwgWiCGQpiTa+HBiP6eRlRGOKQj5Y06vcNx6Ija4cGe6+yCN8HV8tCY0
22okZK98NQCl5t79R/ZB2c3NvBJH+/g3ulU48ikT3tVmDxE3mOZofZyGFEM99P+YCMScLDxTl3hzGy
230YkI8U855P7qOAbcFfh2T5n+LSELwLhbkymEfZT917GWTfmypBWMvJx0WHeDhKwQYPdzbKgWETnc
24yeKasaCW+oLdhBwrd6Ws2r4MA8cwiYXDLbwYmCxJA8VF++8kubF2HJOjSyMBS+QT2PSV/0D9UWoi
25Vfk7R4OvWBJVvq7nV+lXS0O5igjExxlmx1OaBfg7+Cr/MbK4zVNrKSJn82NnKKt6LC6RaTmvFYay
260sDFxQ7Xo+Th6tDNKmKWJt6Kegfjc+qTWJTKb3kL+UI8vS0zTLy1+M/rZ4ekos/JiS5rYIcAswvg
2758kBgp/0rc6upBeWjBaK5O0aLAeBQfLulo1axWX04OSVKmYeoAltyR6UO9ME3acurQyg7Ta24yqO
28whi/PrIaEiO7dsWvFtzsshVzBLic02NlAkPkMUzliPYnZHWQglDAVxL5K2qhvK1OFCkQpIgBsBDM
296KYRL/mkBIIEALIl927rIkaN37/BQIcxLcSa05YfC0Hl3mxWESt1A0D4lA37A9S8EbYmDfAYlMc0
303HhZGdZEtawfpJFyDHzNZceNWBch6nxeNZCY4YFdsbzuGS0RKpwNA9S/czOJ4p9ymBCxuhGepI3U
31PKbC8C749Www1/wMdAot1n+K7M/PBGR8hWmaH5SS7U3yMwAB1fq2NDjx4ur+Um+MclSdN01MDXzG
32EO+eAo1pdAY8479234l8dB2YVAhZ1ZlJ4KmbqMKJrGJXnQUEYS6/cTDRjsUocsoW7uGg1ci2GiHa
33qjlkfpBfie3SdhFW/K8hwAH0HALs56oFN66wUkP/AaJAPfIUNhR6RpHKzZ9zCC42oB2mNawQRMnF
34ETBl1s/SwMxLKRp7jAfKs4NZxSY6I9z/2dTpzS3tsHMjxVDuxkolvRNWBILEMeL1CBvip2HhmoUw
35/Sz5NDgyzk1aQLV6DQNJ2RZLMZDRCtSwZSBu6lhhSgTJGazP0+NbqXXC5aQTrqrFIcWyDXz+ADle
36kszzYM/gSaQTCALTwfDDaU9Ek3xVgW+XBtExtJ3U+0AN3l0j86rUIdIvp6eWdxWQqv9LtpoorKMD
37KfUc5PYV09Z1JgsT4X51Zzq+74l5dz7udIM7UNbdTpmRm9PDj3TUbGCvNR9hqOEGTLbkvb1ZR24a
38h6uGRl2znB25IpDAGRhNRb9is/pO2tvHwHTDMOjrgvZG/pNvXgSUxz0pRjUjXIcqBe2X2gcQfeal
39r8gY76o83WEGL6ODryV9vTQVHt52+izgpYoBZaVlpgqbZl54c+OE0Zxf9RwXwDbcYu5Ku5E0MPL0
40qUjc0y2+Y6E4P5bAWaZGMGT+ORkyVUzcaWmM/+XlO7PER5wrWlCIMZCX1L/nvioY0q0CKqALn7DJ
41QU+qenbwrb6uwS7uNZY6V86s0aDYpU7yRyqxC5SbuyNJb02gdxUCgpIscFaMUjMVRml4M4BIjX/b
42U+HgHoVMUm8SnN9gRcT2izPrgOGVcMTJjfenzoCKoCPo9RjgGMctgB4DvKamErNU7OrilIfuoqzE
43PNSeP9SPw/zkDmNvMebM499We9CVnsHUWqF00/ZJWoua77+0f1bLS/tmci1JBvIcMo/4SJvgH+KF
44o0gijP9gqAPd5iCOnpnJlHUqRIym42SmyKEDuzdSwXKjAR6j7uXda39JyMJr8gGzEsu0jYRkAmj1
45YdiqwKXUcLMkcj1AKeU/PxTUVw0YKsv/rowrPYww3xQUWqNivrXB7GCHE3BzsYNdHsmziaGIXQbA
46+EBHdkuKrM8BcC+fxhF/l/KUxngsD1E75IcUv8zFDF+sk4CBYHqks9S4JYlcubuizqsILbdGzIMN
47Z7w34k0XT+sEggQAyzr8MHeIJGsT+AYnZr08PeTbyr01JEoT7lPYT6PzX4F63QKKDl+mB+PwLMzY
48CXrxZcUmuay6/MV8w/f5T6vQXdoSw5puWodBYwVReYh1IaEN+jiTapm9YBVmcIsJPO6abHowknSV
49OWSvST0AtAX57fFOTckm+facfBK9s9T1lUUgF44Bh5e8f9qKqfOV44nqdCOEyUm0Dao497ieN4Eg
50XBLNvOZY9+irMiXjp0lcyFvhrJOczfyCr9EiiaiH1TfSzKGKsf2W84iKn/JH6x2eOo7xjwJ40BQD
51c6S1cUNEuqBhP6by0FioOXYOKVyifpxk84Eb+F/4CNdTJTvCPwsiegdfsX/Q53DvKVtXp9Ycam5J
52TmKRHXK/bMHF4ONv3p/O/kn/BqRx+fbbP2eMX8Z1F/ltHKfp6B+06HljUwQLBJs9XtCfqH5Zgdz9
53gad5WZF5ykFArmHDgeFlgggvbZ7z9vqnjN/TH68TxJzauYQ5vLHQ6wGXik4/4uq7/TqNmhxlQEM4
54zVkwsn203bUmKLyz+yl1zItDpn5zy1uXfGo99rBdUzdbdE9LmEFPMaFsaHd4a8oDaUroD7FgCbeD
55JJVld3ac6F8+3QbExPs48OrgA1kI3/UwXr52ldjiYzTLfAGR9BjqNFTw45FUHuMf8TEM5hcHx56w
5695eKAqraDk28o9k+M2UKpcmrdlWoWzdqVVFeWGpM8x9Y9Nt0lf/4VUQgrXjqTkUCQkJyqTeTeGgH
57rn3QBk2XAgpxZhaJs3InW0BkAlBmK99cMinUiJeFt5a4p5wPeXrVuh6V9m7Mpl9hzpogg++EZqah
58fzzNnDgxOZfW342DX052PdgXo0NnkhCk005LvFt6M2mRn0fLgNVfyUZZoOp8cO5ZWbhXXlrhrgUt
59j2zKPK6Q94Zj4kdXHBGpAkrB8ZQ4EGGODE0Dqusm8WPXzB+9236IMHPU7lFbyjBrFNI7O4jg+qRI
60Ipi+7tX0FsilqEbmjG+OPwhZXrdqUqyF+rjKQuSRq7lOeDB4c6S2dq4OOny01i5HCbbyc9UvSHRm
61hOhGqUlzHyHLo3W7j+26V/MhkDXJ+Tx+qfylv4pbliwTteJJj+CZwzjv29qb6lxYi+38Bw10ERap
62m8UCRFBecVN7xXlcIfyeAl666Vi7EBJZv3EdFNrx1nlLwM65nYya7uj6L7IwJWotIUx8E0XH0/cU
63xS/dG8bxf9L/8652h5gq3LI+wTNGuEX0DMuz7BGQG+NtgabrZ6SsKGthGa7eULTpz0McWTLRU0y/
64/tkckpm5pDnXSFbIMskwwjECz82UZBSPpigdN/Pjg5d+0yWu7s3VJxw4ENWPPpzZ+j7sOXmdvn9P
65O1tQd60EO+3awASCBAAZQvWV3/yJ6FxPttbP+qeURpJoPEZfpN2UYZmd8HqtR0YbaOZ6Rln9nvpd
66K9fylXdw9z2xeCbjDWUttJB4VqZxGJM8eCTC1VDVyAOsQ5n7SY55dMkQbU+o4Z/4J5m8+wz50BBI
67LfruL1eZ6/CF6CdvxVRiJ10sXc0Tn2sVMXqkw7Adp1GYoCI9c6VFSFK74+n+y7LVFQ5HBnbQyKJc
68dvdLOXwZOPaFHC5UNXRmOpcwdPqyXUe+xIsOMYbzdlAnI9eGDNeRDktUa/Rh0CbZCxjmJzoZEYOE
69ZjsYZlEfp1Kb61t8z4m28hGLEg88T1Ihmxa2HeUWes1RpmgIOP+/2Lb3smj/l/fpSu4gabFgyCAV
70H5HdCYMScUv8SVu55+tpeO8ELoHHQUXV4rr084O4budzhgNSOPyLGDl5sfDUXiyusPCxS4JVO/KY
716V2Qrtg/q2wtmXpEkZnGT+Qi3WDzwt4W81alztnYMP17oGLmxX71KV9OEiMZjI4WaaGt+OOINLtR
72qefioZ1NI2L1s5M0tybwTsyU9WERM+3pUwXIfJVsbMZRlNaO2OogcHbaR4UWvhOj+3CTG1sThiYQ
73MxMnp1Rpqx3nhyzqLO3TRrkYvxnA3cdPBn9EeqpgBMg7X3hCiMV3Fl5cj/WOMhtHYgY7BgeCXo46
74EFVZ4+WroGZ46xGiRDiIblo8bzLd7QCxvukzxy3mUDgsZQ8pds4N28weSUhBk5MAPbfBpRvXUVJx
75MhKqXucQU1Md1qSGLbuuIQuz9pAGp1JFUx/vEkCgm74daSoVWCZuB+1ZE4f48clvrBj51xMNf8CP
76EFE7vySzVb6X2H1i5X3Z+Y3DdIcWw4Y2FClfcJk4Mwq8Cq2GALGFEge9YSEE9YmyuU6OFeU0ICon
77iXAgZ72SM8fBwJPruLFbdsNYKW+oAfmPisXSWMcZmdSbfk0GYv+vKtu3eegSbWw1UsCVtZOh9E5Z
78uQ83l59CBqO9sV/SFU3WrrJ0qNWxrmXu9nJn5Qf5iCRoFGYNHYHkIG5FS6N00GEDZxGkxmro2d++
79Adj5LVHc/b1cYWmrux+jEqI8ZK8cyTB0XMbBA/HYbx9NXazr7znP4/Mlv3pZToEcYt+lgLHAArtU
80AdhybhbLIwNMq0gr6EwtDklBa3ns4Wx/rJU8H7LGs6gV8uqeaSketv+nz+sQhfctxZ1rx+5qzXfy
81FOQVpO23KDQunBi1Bl9k61Di4q9JWcyADBXPHXJzp7mL8Fk7zdvMAEfuED1phdRm6GgDYoYUs4yQ
82IrhSjFlWyk7hT8475xk3BIv++obvWSAv/3+pF6A6U2RXDChVmnG0JnPa9wYYtdzBmLfZKBjX+DjD
83yEMsuhPsCzuN4R6tBIIBWCVRKmKwdkatmpsQBgDw48u0/Arffl5/DRlS9ee+QffFecUitDdCK+kt
84X5L2fGYrL5g6SltncMIeV1ptx4nuSjC/O944q1KYtqvQiPFWJqEXIRMNbbYOC47sjLza0tEFrimN
85wxcrWGSzsy5R9beFQ1aHPcMrDWfCoviNRk2qPtxuKIC5Qk2ZuOmJLjCiLwUGEb0/1Mpzv3MqQa7d
86mRayXg3DZWJPajxNZv6eS357ElMvwGQmqafb2mlQJwWLsg9m9PG7uqEoyrqSc6MiuY+icLEFib9j
87OfRQrx70rTSKUfTr4MtP0aZZAefjCrpVIyTekhFDOk0Nmx057eonlyGgmGpl5/Uo+t1J1Z11Ya/l
88bNbfmebRISJeTVW0I8FhseAZMI1GSwp/ludJxSLYOgyRkh+GX134MexNo7O9F1SxLCfWaSG9Fc3s
895ify04ua9/t8SGrYZPm/l3MkAAAAAAAAAAAAAA==
90
91
diff --git a/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem b/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem
new file mode 100644
index 0000000000..55dbd8f80b
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/msie-s-a-e.pem
@@ -0,0 +1,106 @@
1-----BEGIN PKCS7-----
2MIAGCSqGSIb3DQEHA6CAMIITUAIBADGCAcIwgcwCAQAwdjBiMREwDwYDVQQHEwhJ
3bnRlcm5ldDEXMBUGA1UEChMOVmVyaVNpZ24sIEluYy4xNDAyBgNVBAsTK1ZlcmlT
4aWduIENsYXNzIDEgQ0EgLSBJbmRpdmlkdWFsIFN1YnNjcmliZXICEGBAmILep9sJ
5uN2Pkg1gucowDQYJKoZIhvcNAQEBBQAEQKOxxpIbRTb31+qIQCBOpMVAGnwCLrPO
6OXnntxVveTrPhBnsJuoGNJcCMtuHl7tLkd38WsVwOfGXUprTqFpUcY8wgfACAQAw
7gZkwgZIxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQH
8EwhCcmlzYmFuZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsT
9GURFTU9OU1RSQVRJT04gQU5EIFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBW
10QUxVRSBDQQICBG4wDQYJKoZIhvcNAQEBBQAEQKzIddnXFqK/RRBG86ZVixoXfwAv
11ZdfvnDFsKzPn/A6DuDdE/hqJxnFpHiwGiDR/YbWj2ib+G74DSshgX8vj8ZQwghGD
12BgkqhkiG9w0BBwEwGgYIKoZIhvcNAwIwDgICAKAECLKM0K58I3HNgIIRWBDP8s+g
13l7/6JhZ5PBJ5vPpD1R4pnNDZRabsYu0Qzezdz1IK+maTAhF0SEuNZoEkzIgOIvu3
14UjW8x/2KcHwteABwgRiSk1JyNLwRED0RtvuJ40pIGDvDsHwBMcXEtKUMAOpGChms
15HUK1+B/GKancSDFOCeG3JCFnFdbuQFDIVHC6amWslc6ntqVs/sii2Gs4qdzDfQgl
16PV/A/FY0wi0j2O5cXRQJtZVKM/MYGjj5c1cy9Q7oymU5ATP/LARD0Tw5kBB7HVnD
172qrmmmxcHakyxhXmwskaKS6Qxgqq6LPdgr603onxqEtwNSz5UbCq9mLXuCkFOVsQ
18/5mZcmmc7re3XJMQHRXkBlxEpZQ6HOUIEzlhRqCo2hhymyZK84rptjORQo6vNakM
19IC0Zn8O+6Xl1NlmbGzZakz6LJ4dczE7eG7LwrVus9Oq3V/WweG6rWMPV5d51oKMi
20BRb2pXXy80BAKh/9hvpP/V/HO1/+MPuk8tAn7ssmQoIAQcZxqLOmgqqFhy21oSEu
21rUY746Gp/vIV6Ax1MnfDA/fbjDllhJTl8ujZnfj8R1/oQa9fJMipV8CYQEAt3okZ
22V03kaVhhPGsv544/zRnhqjhgqjHASZGnluZCxDwHb1CE4UqYLp6IbkH3qosy2ntm
23a7WCsM3FN3o5dKFZXBgBEPT8HU9LLQ8B+T0Zvh8CQ719kkNBhnuzSYzmI48R5JHv
24zbROiU5v4p9FpssD13vXiOxzaMTKQqWk/roGHiNoKzKonS5RBwTxKfOsoCobCBaI
25IZCmJNr4cGI/p5GVEY4pCPljTq9w3HoiNrhwZ7r7II3wdXy0JjSiRkr3w1AKXm3v
261H9kHZzc28Ekf7+De6VTjyKRPe1WYPETeY5mh9nIYUQz30/5gIxJwsPFOXeHMbLR
27iQjxTznk/uo4BtwV+HZPmf4tIQvAuFuTKYR9lP3XsZZN+bKkFYy8nHRYd4OErBBg
2893NsqBYROdzJ4pqxoJb6gt2EHCt3pazavgwDxzCJhcMtvBiYLEkDxUX77yS5sXYc
29k6NLIwFL5BPY9JX/QP1RaiJV+TtHg69YElW+rudX6VdLQ7mKCMTHGWbHU5oF+Dv4
30Kv8xsrjNU2spImfzY2coq3osLpFpOa8VhrLSwMXFDtej5OHq0M0qYpYm3op6B+Nz
316pNYlMpveQv5Qjy9LTNMvLX4z+tnh6Siz8mJLmtghwCzC+DnyQGCn/Stzq6kF5aM
32Fork7RosB4FB8u6WjVrFZfTg5JUqZh6gCW3JHpQ70wTdpy6tDKDtNrbjKo7CGL8+
33shoSI7t2xa8W3OyyFXMEuJzTY2UCQ+QxTOWI9idkdZCCUMBXEvkraqG8rU4UKRCk
34iAGwEMzophEv+aSyJfdu6yJGjd+/wUCHMS3EmtOWHwtB5d5sVhErdQNA+JQN+wPU
35vBG2Jg3wGJTHNNx4WRnWRLWsH6SRcgx8zWXHjVgXIep8XjWQmOGBXbG87hktESqc
36DQPUv3MzieKfcpgQsboRnqSN1DymwvAu+PVsMNf8DHQKLdZ/iuzPzwRkfIVpmh+U
37ku1N8jMAAdX6tjQ48eLq/lJvjHJUnTdNTA18xhDvngKNaXQGPOO/dt+JfHQdmFQI
38WdWZSeCpm6jCiaxiV50FBGEuv3Ew0Y7FKHLKFu7hoNXIthoh2qo5ZH6QX4nt0nYR
39VvyvIcAB9BwC7OeqBTeusFJD/wGiQD3yFDYUekaRys2fcwguNqAdpjWsEETJxREw
40ZdbP0sDMSykae4wHyrODWcUmOiPc/9nU6c0t7bBzI8VQ7sZKJb0TVgSCxDHi9Qgb
414qdh4ZqFMP0s+TQ4Ms5NWkC1eg0DSdkWSzGQ0QrUsGUgbupYYUoEyRmsz9PjW6l1
42wuWkE66qxSHFsg18/gA5XpLM82DP4EmkEwgC08Hww2lPRJN8VYFvlwbRMbSd1PtA
43Dd5dI/Oq1CHSL6enlncVkKr/S7aaKKyjAyn1HOT2FdPWdSYLE+F+dWc6vu+JeXc+
447nSDO1DW3U6ZkZvTw4901GxgrzUfYajhBky25L29WUduGoerhkZds5wduSKQwBkY
45TUW/YrP6Ttrbx8B0wzDo64L2Rv6Tb14ElMc9KUY1I1yHKgXtl9oHEH3mpa/IGO+q
46PN1hBi+jg68lfb00FR7edvos4KWKAWWlZaYKm2ZeeHPjhNGcX/UcF8A23GLuSruR
47NDDy9KlI3NMtvmOhOD+WwFmmRjBk/jkZMlVM3GlpjP/l5TuzxEecK1pQiDGQl9S/
48574qGNKtAiqgC5+wyUFPqnp28K2+rsEu7jWWOlfOrNGg2KVO8kcqsQuUm7sjSW9N
49oHcVAoKSLHBWjFIzFUZpeDOASI1/21Ph4B6FTFJvEpzfYEXE9osz64DhlXDEyY33
50p86AiqAj6PUY4BjHLYAeA7ymphKzVOzq4pSH7qKsxDzUnj/Uj8P85A5jbzHmzOPf
51VnvQlZ7B1FqhdNP2SVqLmu+/tH9Wy0v7ZnItSQbyHDKP+Eib4B/ihaNIIoz/YKgD
523eYgjp6ZyZR1KkSMpuNkpsihA7s3UsFyowEeo+7l3Wt/ScjCa/IBsxLLtI2EZAJo
539WHYqsCl1HCzJHI9QCnlPz8U1FcNGCrL/66MKz2MMN8UFFqjYr61wexghxNwc7GD
54XR7Js4mhiF0GwPhAR3ZLiqzPAXAvn8YRf5fylMZ4LA9RO+SHFL/MxQxfrJOAgWB6
55pLPUuCWJXLm7os6rCC23RsyDDWe8N+JNF0/ryzr8MHeIJGsT+AYnZr08PeTbyr01
56JEoT7lPYT6PzX4F63QKKDl+mB+PwLMzYCXrxZcUmuay6/MV8w/f5T6vQXdoSw5pu
57WodBYwVReYh1IaEN+jiTapm9YBVmcIsJPO6abHowknSVOWSvST0AtAX57fFOTckm
58+facfBK9s9T1lUUgF44Bh5e8f9qKqfOV44nqdCOEyUm0Dao497ieN4EgXBLNvOZY
599+irMiXjp0lcyFvhrJOczfyCr9EiiaiH1TfSzKGKsf2W84iKn/JH6x2eOo7xjwJ4
600BQDc6S1cUNEuqBhP6by0FioOXYOKVyifpxk84Eb+F/4CNdTJTvCPwsiegdfsX/Q
6153DvKVtXp9Ycam5JTmKRHXK/bMHF4ONv3p/O/kn/BqRx+fbbP2eMX8Z1F/ltHKfp
626B+06HljUwQLBJs9XtCfqH5Zgdz9gad5WZF5ykFArmHDgeFlgggvbZ7z9vqnjN/T
63H68TxJzauYQ5vLHQ6wGXik4/4uq7/TqNmhxlQEM4zVkwsn203bUmKLyz+yl1zItD
64pn5zy1uXfGo99rBdUzdbdE9LmEFPMaFsaHd4a8oDaUroD7FgCbeDJJVld3ac6F8+
653QbExPs48OrgA1kI3/UwXr52ldjiYzTLfAGR9BjqNFTw45FUHuMf8TEM5hcHx56w
6695eKAqraDk28o9k+M2UKpcmrdlWoWzdqVVFeWGpM8x9Y9Nt0lf/4VUQgrXjqTkUC
67QkJyqTeTeGgHrn3QBk2XAgpxZhaJs3InW0BkAlBmK99cMinUiJeFt5a4p5wPeXrV
68uh6V9m7Mpl9hzpogg++EZqahfzzNnDgxOZfW342DX052PdgXo0NnkhCk005LvFt6
69M2mRn0fLgNVfyUZZoOp8cO5ZWbhXXlrhrgUtj2zKPK6Q94Zj4kdXHBGpAkrB8ZQ4
70EGGODE0Dqusm8WPXzB+9236IMHPU7lFbyjBrFNI7O4jg+qRIIpi+7tX0FsilqEbm
71jG+OPwhZXrdqUqyF+rjKQuSRq7lOeDB4c6S2dq4OOny01i5HCbbyc9UvSHRmhOhG
72qUlzHyHLo3W7j+26V/MhkDXJ+Tx+qfylv4pbliwTteJJj+CZwzjv29qb6lxYi+38
73Bw10ERapm8UCRFBecVN7xXlcIfyeAl666Vi7EBJZv3EdFNrx1nlLwM65nYya7uj6
74L7IwJWotIUx8E0XH0/cUxS/dG8bxf9L/8652h5gq3LI+wTNGuEX0DMuz7BGQG+Nt
75gabrZ6SsKGthGa7eULTpz0McWTLRU0y//tkckpm5pDnXSFbIMskwwjECz82UZBSP
76pigdN/Pjg5d+0yWu7s3VJxw4ENWPPpzZ+j7sOXmdvn9PO1tQd60EO+3awBlC9ZXf
77/InoXE+21s/6p5RGkmg8Rl+k3ZRhmZ3weq1HRhto5npGWf2e+l0r1/KVd3D3PbF4
78JuMNZS20kHhWpnEYkzx4JMLVUNXIA6xDmftJjnl0yRBtT6jhn/gnmbz7DPnQEEgt
79+u4vV5nr8IXoJ2/FVGInXSxdzROfaxUxeqTDsB2nUZigIj1zpUVIUrvj6f7LstUV
80DkcGdtDIolx290s5fBk49oUcLlQ1dGY6lzB0+rJdR77Eiw4xhvN2UCcj14YM15EO
81S1Rr9GHQJtkLGOYnOhkRg4RmOxhmUR+nUpvrW3zPibbyEYsSDzxPUiGbFrYd5RZ6
82zVGmaAg4/7/YtveyaP+X9+lK7iBpsWDIIBUfkd0JgxJxS/xJW7nn62l47wQugcdB
83RdXiuvTzg7hu53OGA1I4/IsYOXmx8NReLK6w8LFLglU78pjpXZCu2D+rbC2ZekSR
84mcZP5CLdYPPC3hbzVqXO2dgw/XugYubFfvUpX04SIxmMjhZpoa3444g0u1Gp5+Kh
85nU0jYvWzkzS3JvBOzJT1YREz7elTBch8lWxsxlGU1o7Y6iBwdtpHhRa+E6P7cJMb
86WxOGJhAzEyenVGmrHeeHLOos7dNGuRi/GcDdx08Gf0R6qmAEyDtfeEKIxXcWXlyP
879Y4yG0diBjsGB4JejjoQVVnj5augZnjrEaJEOIhuWjxvMt3tALG+6TPHLeZQOCxl
88Dyl2zg3bzB5JSEGTkwA9t8GlG9dRUnEyEqpe5xBTUx3WpIYtu64hC7P2kAanUkVT
89H+8SQKCbvh1pKhVYJm4H7VkTh/jxyW+sGPnXEw1/wI8QUTu/JLNVvpfYfWLlfdn5
90jcN0hxbDhjYUKV9wmTgzCrwKrYYAsYUSB71hIQT1ibK5To4V5TQgKieJcCBnvZIz
91x8HAk+u4sVt2w1gpb6gB+Y+KxdJYxxmZ1Jt+TQZi/68q27d56BJtbDVSwJW1k6H0
92Tlm5DzeXn0IGo72xX9IVTdausnSo1bGuZe72cmflB/mIJGgUZg0dgeQgbkVLo3TQ
93YQNnEaTGaujZ374B2PktUdz9vVxhaau7H6MSojxkrxzJMHRcxsED8dhvH01drOvv
94Oc/j8yW/ellOgRxi36WAscACu1QB2HJuFssjA0yrSCvoTC0OSUFreezhbH+slTwf
95ssazqBXy6p5pKR62/6fP6xCF9y3FnWvH7mrNd/IU5BWk7bcoNC6cGLUGX2TrUOLi
96r0lZzIAMFc8dcnOnuYvwWTvN28wAR+4QPWmF1GboaANihhSzjJAiuFKMWVbKTuFP
97zjvnGTcEi/76hu9ZIC//f6kXoDpTZFcMKFWacbQmc9r3Bhi13MGYt9koGNf4OMPI
98Qyy6E+wLO43hHq0lUSpisHZGrZqbEAYA8OPLtPwK335efw0ZUvXnvkH3xXnFIrQ3
99QivpLV+S9nxmKy+YOkpbZ3DCHldabceJ7kowvzveOKtSmLar0IjxViahFyETDW22
100DguO7Iy82tLRBa4pjcMXK1hks7MuUfW3hUNWhz3DKw1nwqL4jUZNqj7cbiiAuUJN
101mbjpiS4woi8FBhG9P9TKc79zKkGu3ZkWsl4Nw2ViT2o8TWb+nkt+exJTL8BkJqmn
10229ppUCcFi7IPZvTxu7qhKMq6knOjIrmPonCxBYm/Yzn0UK8e9K00ilH06+DLT9Gm
103WQHn4wq6VSMk3pIRQzpNDZsdOe3qJ5choJhqZef1KPrdSdWddWGv5WzW35nm0SEi
104Xk1VtCPBYbHgGTCNRksKf5bnScUi2DoMkZIfhl9d+DHsTaOzvRdUsSwn1mkhvRXN
1057OYn8tOLmvf7fEhq2GT5v5dzJAAAAAA=
106-----END PKCS7-----
diff --git a/src/lib/libcrypto/pkcs7/t/nav-smime b/src/lib/libcrypto/pkcs7/t/nav-smime
new file mode 100644
index 0000000000..6ee4b597a1
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/nav-smime
@@ -0,0 +1,157 @@
1From angela@c2.net.au Thu May 14 13:32:27 1998
2X-UIDL: 83c94dd550e54329bf9571b72038b8c8
3Return-Path: angela@c2.net.au
4Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27838 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:32:26 +1000 (EST)
5Message-ID: <355A6779.4B63E64C@cryptsoft.com>
6Date: Thu, 14 May 1998 13:39:37 +1000
7From: Angela van Lent <angela@c2.net.au>
8X-Mailer: Mozilla 4.03 [en] (Win95; U)
9MIME-Version: 1.0
10To: tjh@cryptsoft.com
11Subject: signed
12Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------ms9A58844C95949ECC78A1C54C"
13Content-Length: 2604
14Status: OR
15
16This is a cryptographically signed message in MIME format.
17
18--------------ms9A58844C95949ECC78A1C54C
19Content-Type: text/plain; charset=us-ascii
20Content-Transfer-Encoding: 7bit
21
22signed body
23
24--------------ms9A58844C95949ECC78A1C54C
25Content-Type: application/x-pkcs7-signature; name="smime.p7s"
26Content-Transfer-Encoding: base64
27Content-Disposition: attachment; filename="smime.p7s"
28Content-Description: S/MIME Cryptographic Signature
29
30MIIGHgYJKoZIhvcNAQcCoIIGDzCCBgsCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
31BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
32BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
33ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
34AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
35gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
36ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
37A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
38dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
39hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
40hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
41igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
42syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
43A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
44dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
45ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
46kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
47MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
48TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
49BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
50mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
518o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
52ggF7MIIBdwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
53BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
54REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
55AgIEfjAJBgUrDgMCGgUAoHowGAYJKoZIhvcNAQkDMQsGCSqGSIb3DQEHATAbBgkqhkiG9w0B
56CQ8xDjAMMAoGCCqGSIb3DQMHMBwGCSqGSIb3DQEJBTEPFw05ODA1MTQwMzM5MzdaMCMGCSqG
57SIb3DQEJBDEWBBQstNMnSV26ba8PapQEDhO21yNFrjANBgkqhkiG9w0BAQEFAARAW9Xb9YXv
58BfcNkutgFX9Gr8iXhBVsNtGEVrjrpkQwpKa7jHI8SjAlLhk/4RFwDHf+ISB9Np3Z1WDWnLcA
599CWR6g==
60--------------ms9A58844C95949ECC78A1C54C--
61
62
63From angela@c2.net.au Thu May 14 13:33:16 1998
64X-UIDL: 8f076c44ff7c5967fd5b00c4588a8731
65Return-Path: angela@c2.net.au
66Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id NAA27847 for <tjh@cryptsoft.com>; Thu, 14 May 1998 13:33:15 +1000 (EST)
67Message-ID: <355A67AB.2AF38806@cryptsoft.com>
68Date: Thu, 14 May 1998 13:40:27 +1000
69From: Angela van Lent <angela@c2.net.au>
70X-Mailer: Mozilla 4.03 [en] (Win95; U)
71MIME-Version: 1.0
72To: tjh@cryptsoft.com
73Subject: signed
74Content-Type: multipart/signed; protocol="application/x-pkcs7-signature"; micalg=sha1; boundary="------------msD7863B84BD61E02C407F2F5E"
75Content-Length: 2679
76Status: OR
77
78This is a cryptographically signed message in MIME format.
79
80--------------msD7863B84BD61E02C407F2F5E
81Content-Type: text/plain; charset=us-ascii
82Content-Transfer-Encoding: 7bit
83
84signed body 2
85
86--------------msD7863B84BD61E02C407F2F5E
87Content-Type: application/x-pkcs7-signature; name="smime.p7s"
88Content-Transfer-Encoding: base64
89Content-Disposition: attachment; filename="smime.p7s"
90Content-Description: S/MIME Cryptographic Signature
91
92MIIGVgYJKoZIhvcNAQcCoIIGRzCCBkMCAQExCzAJBgUrDgMCGgUAMAsGCSqGSIb3DQEHAaCC
93BGswggJTMIIB/aADAgECAgIEfjANBgkqhkiG9w0BAQQFADCBkjELMAkGA1UEBhMCQVUxEzAR
94BgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNv
95ZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UE
96AxMSREVNTyBaRVJPIFZBTFVFIENBMB4XDTk4MDUxMzA2MjY1NloXDTAwMDUxMjA2MjY1Nlow
97gaUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFu
98ZTEaMBgGA1UEChMRQ3J5cHRzb2Z0IFB0eSBMdGQxEjAQBgNVBAsTCVNNSU1FIDAwMzEZMBcG
99A1UEAxMQQW5nZWxhIHZhbiBMZWVudDEjMCEGCSqGSIb3DQEJARYUYW5nZWxhQGNyeXB0c29m
100dC5jb20wXDANBgkqhkiG9w0BAQEFAANLADBIAkEAuC3+7dAb2LhuO7gt2cTM8vsNjhG5JfDh
101hX1Vl/wVGbKEEj0MA6vWEolvefQlxB+EzwCtR0YZ7eEC/T/4JoCyeQIDAQABoygwJjAkBglg
102hkgBhvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EAUnSP
103igs6TMFISTjw8cBtJYb98czgAVkVFjKyJQwYMH8FbDnCyx6NocM555nsyDstaw8fKR11Khds
104syd3ikkrhDCCAhAwggG6AgEDMA0GCSqGSIb3DQEBBAUAMIGSMQswCQYDVQQGEwJBVTETMBEG
105A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
106dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
107ExJERU1PIFpFUk8gVkFMVUUgQ0EwHhcNOTgwMzAzMDc0MTMyWhcNMDgwMjI5MDc0MTMyWjCB
108kjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAPBgNVBAcTCEJyaXNiYW5l
109MRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZREVNT05TVFJBVElPTiBB
110TkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENBMFwwDQYJKoZIhvcNAQEB
111BQADSwAwSAJBAL+0E2fLej3FSCwe2A2iRnMuC3z12qHIp6Ky1wo2zZcxft7AI+RfkrWrSGtf
112mfzBEuPrLdfulncC5Y1pNcM8RTUCAwEAATANBgkqhkiG9w0BAQQFAANBAGSbLMphL6F5pp3s
1138o0Xyh86FHFdpVOwYx09ELLkuG17V/P9pgIc0Eo/gDMbN+KT3IdgECf8S//pCRA6RrNjcXIx
114ggGzMIIBrwIBATCBmTCBkjELMAkGA1UEBhMCQVUxEzARBgNVBAgTClF1ZWVuc2xhbmQxETAP
115BgNVBAcTCEJyaXNiYW5lMRowGAYDVQQKExFDcnlwdHNvZnQgUHR5IEx0ZDEiMCAGA1UECxMZ
116REVNT05TVFJBVElPTiBBTkQgVEVTVElORzEbMBkGA1UEAxMSREVNTyBaRVJPIFZBTFVFIENB
117AgIEfjAJBgUrDgMCGgUAoIGxMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEwHAYJKoZIhvcN
118AQkFMQ8XDTk4MDUxNDAzNDAyN1owIwYJKoZIhvcNAQkEMRYEFOKcV8mNYJnM8rHQajcSEqJN
119rwdDMFIGCSqGSIb3DQEJDzFFMEMwCgYIKoZIhvcNAwcwDgYIKoZIhvcNAwICAgCAMAcGBSsO
120AwIHMA0GCCqGSIb3DQMCAgFAMA0GCCqGSIb3DQMCAgEoMA0GCSqGSIb3DQEBAQUABEADPE/N
121coH+zTFuX5YpolupTKxKK8eEjc48TuADuO8bIHHDE/fEYaWunlwDuTlcFJl1ig0idffPB1qC
122Zp8SSVVY
123--------------msD7863B84BD61E02C407F2F5E--
124
125
126From angela@c2.net.au Thu May 14 14:05:32 1998
127X-UIDL: a7d629b4b9acacaee8b39371b860a32a
128Return-Path: angela@c2.net.au
129Received: from cryptsoft.com (play.cryptsoft.com [203.56.44.3]) by pandora.cryptsoft.com (8.8.3/8.7.3) with ESMTP id OAA28033 for <tjh@cryptsoft.com>; Thu, 14 May 1998 14:05:32 +1000 (EST)
130Message-ID: <355A6F3B.AC385981@cryptsoft.com>
131Date: Thu, 14 May 1998 14:12:43 +1000
132From: Angela van Lent <angela@c2.net.au>
133X-Mailer: Mozilla 4.03 [en] (Win95; U)
134MIME-Version: 1.0
135To: tjh@cryptsoft.com
136Subject: encrypted
137Content-Type: application/x-pkcs7-mime; name="smime.p7m"
138Content-Transfer-Encoding: base64
139Content-Disposition: attachment; filename="smime.p7m"
140Content-Description: S/MIME Encrypted Message
141Content-Length: 905
142Status: OR
143
144MIAGCSqGSIb3DQEHA6CAMIACAQAxggHmMIHwAgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEG
145A1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
146dCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNUUkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQD
147ExJERU1PIFpFUk8gVkFMVUUgQ0ECAgR+MA0GCSqGSIb3DQEBAQUABEA92N29Yk39RUY2tIVd
148exGT2MFX3J6H8LB8aDRJjw7843ALgJ5zXpM5+f80QkAWwEN2A6Pl3VxiCeKLi435zXVyMIHw
149AgEAMIGZMIGSMQswCQYDVQQGEwJBVTETMBEGA1UECBMKUXVlZW5zbGFuZDERMA8GA1UEBxMI
150QnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29mdCBQdHkgTHRkMSIwIAYDVQQLExlERU1PTlNU
151UkFUSU9OIEFORCBURVNUSU5HMRswGQYDVQQDExJERU1PIFpFUk8gVkFMVUUgQ0ECAgRuMA0G
152CSqGSIb3DQEBAQUABECR9IfyHtvnjFmZ8B2oUCEs1vxMsG0u1kxKE4RMPFyDqDCEARq7zXMg
153nzSUI7Wgv5USSKDqcLRJeW+jvYURv/nJMIAGCSqGSIb3DQEHATAaBggqhkiG9w0DAjAOAgIA
154oAQIrLqrij2ZMpeggAQoibtn6reRZWuWk5Iv5IAhgitr8EYE4w4ySQ7EMB6mTlBoFpccUMWX
155BwQgQn1UoWCvYAlhDzURdbui64Dc0rS2wtj+kE/InS6y25EEEPe4NUKaF8/UlE+lo3LtILQE
156CL3uV8k7m0iqAAAAAAAAAAAAAA==
157
diff --git a/src/lib/libcrypto/pkcs7/t/s.pem b/src/lib/libcrypto/pkcs7/t/s.pem
new file mode 100644
index 0000000000..4fa925b182
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/s.pem
@@ -0,0 +1,57 @@
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-----
10issuer :/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=DEMONSTRATION AND TESTING/CN=DEMO ZERO VALUE CA
11subject:/C=AU/SP=Queensland/L=Brisbane/O=Cryptsoft Pty Ltd/OU=SMIME 003/CN=Information/Email=info@cryptsoft.com
12serial :047D
13
14Certificate:
15 Data:
16 Version: 3 (0x2)
17 Serial Number: 1149 (0x47d)
18 Signature Algorithm: md5withRSAEncryption
19 Issuer: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=DEMONSTRATION AND TESTING, CN=DEMO ZERO VALUE CA
20 Validity
21 Not Before: May 13 05:40:58 1998 GMT
22 Not After : May 12 05:40:58 2000 GMT
23 Subject: C=AU, SP=Queensland, L=Brisbane, O=Cryptsoft Pty Ltd, OU=SMIME 003, CN=Information/Email=info@cryptsoft.com
24 Subject Public Key Info:
25 Public Key Algorithm: rsaEncryption
26 Modulus:
27 00:ad:e7:23:89:ee:0d:87:b7:9c:32:44:4b:95:81:
28 73:dd:22:80:4b:2d:c5:60:b8:fe:1e:18:63:ef:dc:
29 89:89:22:df:95:3c:7a:db:3d:9a:06:a8:08:d6:29:
30 fd:ef:41:09:91:ed:bc:ad:98:f9:f6:28:90:62:6f:
31 e7:e7:0c:4d:0b
32 Exponent: 65537 (0x10001)
33 X509v3 extensions:
34 Netscape Comment:
35 Generated with SSLeay
36 Signature Algorithm: md5withRSAEncryption
37 52:15:ea:88:f4:f0:f9:0b:ef:ce:d5:f8:83:40:61:16:5e:55:
38 f9:ce:2d:d1:8b:31:5c:03:c6:2d:10:7c:61:d5:5c:0a:42:97:
39 d1:fd:65:b6:b6:84:a5:39:ec:46:ec:fc:e0:0d:d9:22:da:1b:
40 50:74:ad:92:cb:4e:90:e5:fa:7d
41
42-----BEGIN CERTIFICATE-----
43MIICTDCCAfagAwIBAgICBH0wDQYJKoZIhvcNAQEEBQAwgZIxCzAJBgNVBAYTAkFV
44MRMwEQYDVQQIEwpRdWVlbnNsYW5kMREwDwYDVQQHEwhCcmlzYmFuZTEaMBgGA1UE
45ChMRQ3J5cHRzb2Z0IFB0eSBMdGQxIjAgBgNVBAsTGURFTU9OU1RSQVRJT04gQU5E
46IFRFU1RJTkcxGzAZBgNVBAMTEkRFTU8gWkVSTyBWQUxVRSBDQTAeFw05ODA1MTMw
47NTQwNThaFw0wMDA1MTIwNTQwNThaMIGeMQswCQYDVQQGEwJBVTETMBEGA1UECBMK
48UXVlZW5zbGFuZDERMA8GA1UEBxMIQnJpc2JhbmUxGjAYBgNVBAoTEUNyeXB0c29m
49dCBQdHkgTHRkMRIwEAYDVQQLEwlTTUlNRSAwMDMxFDASBgNVBAMTC0luZm9ybWF0
50aW9uMSEwHwYJKoZIhvcNAQkBFhJpbmZvQGNyeXB0c29mdC5jb20wXDANBgkqhkiG
519w0BAQEFAANLADBIAkEArecjie4Nh7ecMkRLlYFz3SKASy3FYLj+Hhhj79yJiSLf
52lTx62z2aBqgI1in970EJke28rZj59iiQYm/n5wxNCwIDAQABoygwJjAkBglghkgB
53hvhCAQ0EFxYVR2VuZXJhdGVkIHdpdGggU1NMZWF5MA0GCSqGSIb3DQEBBAUAA0EA
54UhXqiPTw+QvvztX4g0BhFl5V+c4t0YsxXAPGLRB8YdVcCkKX0f1ltraEpTnsRuz8
554A3ZItobUHStkstOkOX6fQ==
56-----END CERTIFICATE-----
57
diff --git a/src/lib/libcrypto/pkcs7/t/server.pem b/src/lib/libcrypto/pkcs7/t/server.pem
new file mode 100644
index 0000000000..989baf8709
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/t/server.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/verify.c b/src/lib/libcrypto/pkcs7/verify.c
new file mode 100644
index 0000000000..b40f26032e
--- /dev/null
+++ b/src/lib/libcrypto/pkcs7/verify.c
@@ -0,0 +1,263 @@
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 <string.h>
60#include <openssl/bio.h>
61#include <openssl/asn1.h>
62#include <openssl/x509.h>
63#include <openssl/pem.h>
64#include <openssl/err.h>
65#include "example.h"
66
67int verify_callback(int ok, X509_STORE_CTX *ctx);
68
69BIO *bio_err=NULL;
70BIO *bio_out=NULL;
71
72int main(argc,argv)
73int argc;
74char *argv[];
75 {
76 PKCS7 *p7;
77 PKCS7_SIGNER_INFO *si;
78 X509_STORE_CTX cert_ctx;
79 X509_STORE *cert_store=NULL;
80 BIO *data,*detached=NULL,*p7bio=NULL;
81 char buf[1024*4];
82 char *pp;
83 int i,printit=0;
84 STACK_OF(PKCS7_SIGNER_INFO) *sk;
85
86 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
87 bio_out=BIO_new_fp(stdout,BIO_NOCLOSE);
88#ifndef OPENSSL_NO_MD2
89 EVP_add_digest(EVP_md2());
90#endif
91#ifndef OPENSSL_NO_MD5
92 EVP_add_digest(EVP_md5());
93#endif
94#ifndef OPENSSL_NO_SHA1
95 EVP_add_digest(EVP_sha1());
96#endif
97#ifndef OPENSSL_NO_MDC2
98 EVP_add_digest(EVP_mdc2());
99#endif
100
101 data=BIO_new(BIO_s_file());
102
103 pp=NULL;
104 while (argc > 1)
105 {
106 argc--;
107 argv++;
108 if (strcmp(argv[0],"-p") == 0)
109 {
110 printit=1;
111 }
112 else if ((strcmp(argv[0],"-d") == 0) && (argc >= 2))
113 {
114 detached=BIO_new(BIO_s_file());
115 if (!BIO_read_filename(detached,argv[1]))
116 goto err;
117 argc--;
118 argv++;
119 }
120 else
121 {
122 pp=argv[0];
123 if (!BIO_read_filename(data,argv[0]))
124 goto err;
125 }
126 }
127
128 if (pp == NULL)
129 BIO_set_fp(data,stdin,BIO_NOCLOSE);
130
131
132 /* Load the PKCS7 object from a file */
133 if ((p7=PEM_read_bio_PKCS7(data,NULL,NULL,NULL)) == NULL) goto err;
134
135 /* This stuff is being setup for certificate verification.
136 * When using SSL, it could be replaced with a
137 * cert_stre=SSL_CTX_get_cert_store(ssl_ctx); */
138 cert_store=X509_STORE_new();
139 X509_STORE_set_default_paths(cert_store);
140 X509_STORE_load_locations(cert_store,NULL,"../../certs");
141 X509_STORE_set_verify_cb_func(cert_store,verify_callback);
142
143 ERR_clear_error();
144
145 /* We need to process the data */
146 if ((PKCS7_get_detached(p7) || detached))
147 {
148 if (detached == NULL)
149 {
150 printf("no data to verify the signature on\n");
151 exit(1);
152 }
153 else
154 p7bio=PKCS7_dataInit(p7,detached);
155 }
156 else
157 {
158 p7bio=PKCS7_dataInit(p7,NULL);
159 }
160
161 /* We now have to 'read' from p7bio to calculate digests etc. */
162 for (;;)
163 {
164 i=BIO_read(p7bio,buf,sizeof(buf));
165 /* print it? */
166 if (i <= 0) break;
167 }
168
169 /* We can now verify signatures */
170 sk=PKCS7_get_signer_info(p7);
171 if (sk == NULL)
172 {
173 printf("there are no signatures on this data\n");
174 exit(1);
175 }
176
177 /* Ok, first we need to, for each subject entry, see if we can verify */
178 for (i=0; i<sk_PKCS7_SIGNER_INFO_num(sk); i++)
179 {
180 ASN1_UTCTIME *tm;
181 char *str1,*str2;
182 int rc;
183
184 si=sk_PKCS7_SIGNER_INFO_value(sk,i);
185 rc=PKCS7_dataVerify(cert_store,&cert_ctx,p7bio,p7,si);
186 if (rc <= 0)
187 goto err;
188 printf("signer info\n");
189 if ((tm=get_signed_time(si)) != NULL)
190 {
191 BIO_printf(bio_out,"Signed time:");
192 ASN1_UTCTIME_print(bio_out,tm);
193 ASN1_UTCTIME_free(tm);
194 BIO_printf(bio_out,"\n");
195 }
196 if (get_signed_seq2string(si,&str1,&str2))
197 {
198 BIO_printf(bio_out,"String 1 is %s\n",str1);
199 BIO_printf(bio_out,"String 2 is %s\n",str2);
200 }
201
202 }
203
204 X509_STORE_free(cert_store);
205
206 printf("done\n");
207 exit(0);
208err:
209 ERR_load_crypto_strings();
210 ERR_print_errors_fp(stderr);
211 exit(1);
212 }
213
214/* should be X509 * but we can just have them as char *. */
215int verify_callback(int ok, X509_STORE_CTX *ctx)
216 {
217 char buf[256];
218 X509 *err_cert;
219 int err,depth;
220
221 err_cert=X509_STORE_CTX_get_current_cert(ctx);
222 err= X509_STORE_CTX_get_error(ctx);
223 depth= X509_STORE_CTX_get_error_depth(ctx);
224
225 X509_NAME_oneline(X509_get_subject_name(err_cert),buf,256);
226 BIO_printf(bio_err,"depth=%d %s\n",depth,buf);
227 if (!ok)
228 {
229 BIO_printf(bio_err,"verify error:num=%d:%s\n",err,
230 X509_verify_cert_error_string(err));
231 if (depth < 6)
232 {
233 ok=1;
234 X509_STORE_CTX_set_error(ctx,X509_V_OK);
235 }
236 else
237 {
238 ok=0;
239 X509_STORE_CTX_set_error(ctx,X509_V_ERR_CERT_CHAIN_TOO_LONG);
240 }
241 }
242 switch (ctx->error)
243 {
244 case X509_V_ERR_UNABLE_TO_GET_ISSUER_CERT:
245 X509_NAME_oneline(X509_get_issuer_name(ctx->current_cert),buf,256);
246 BIO_printf(bio_err,"issuer= %s\n",buf);
247 break;
248 case X509_V_ERR_CERT_NOT_YET_VALID:
249 case X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD:
250 BIO_printf(bio_err,"notBefore=");
251 ASN1_UTCTIME_print(bio_err,X509_get_notBefore(ctx->current_cert));
252 BIO_printf(bio_err,"\n");
253 break;
254 case X509_V_ERR_CERT_HAS_EXPIRED:
255 case X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD:
256 BIO_printf(bio_err,"notAfter=");
257 ASN1_UTCTIME_print(bio_err,X509_get_notAfter(ctx->current_cert));
258 BIO_printf(bio_err,"\n");
259 break;
260 }
261 BIO_printf(bio_err,"verify return:%d\n",ok);
262 return(ok);
263 }
diff --git a/src/lib/libcrypto/pqueue/Makefile b/src/lib/libcrypto/pqueue/Makefile
new file mode 100644
index 0000000000..d0c39d25ce
--- /dev/null
+++ b/src/lib/libcrypto/pqueue/Makefile
@@ -0,0 +1,84 @@
1#
2# OpenSSL/crypto/pqueue/Makefile
3#
4
5DIR= pqueue
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=pqueue.c
21LIBOBJ=pqueue.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= pqueue.h pq_compat.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77pqueue.o: ../../e_os.h ../../include/openssl/bio.h ../../include/openssl/bn.h
78pqueue.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
79pqueue.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80pqueue.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
81pqueue.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
82pqueue.o: ../../include/openssl/pq_compat.h ../../include/openssl/safestack.h
83pqueue.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
84pqueue.o: ../cryptlib.h pqueue.c pqueue.h
diff --git a/src/lib/libcrypto/pqueue/pq_compat.h b/src/lib/libcrypto/pqueue/pq_compat.h
new file mode 100644
index 0000000000..fd36578882
--- /dev/null
+++ b/src/lib/libcrypto/pqueue/pq_compat.h
@@ -0,0 +1,147 @@
1/* crypto/pqueue/pqueue_compat.h */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include <openssl/opensslconf.h>
61#include <openssl/bn.h>
62
63/*
64 * The purpose of this header file is for supporting 64-bit integer
65 * manipulation on 32-bit (and lower) machines. Currently the only
66 * such environment is VMS, Utrix and those with smaller default integer
67 * sizes than 32 bits. For all such environment, we fall back to using
68 * BIGNUM. We may need to fine tune the conditions for systems that
69 * are incorrectly configured.
70 *
71 * The only clients of this code are (1) pqueue for priority, and
72 * (2) DTLS, for sequence number manipulation.
73 */
74
75#if (defined(THIRTY_TWO_BIT) && !defined(BN_LLONG)) || defined(SIXTEEN_BIT) || defined(EIGHT_BIT)
76
77#define PQ_64BIT_IS_INTEGER 0
78#define PQ_64BIT_IS_BIGNUM 1
79
80#define PQ_64BIT BIGNUM
81#define PQ_64BIT_CTX BN_CTX
82
83#define pq_64bit_init(x) BN_init(x)
84#define pq_64bit_free(x) BN_free(x)
85
86#define pq_64bit_ctx_new(ctx) BN_CTX_new()
87#define pq_64bit_ctx_free(x) BN_CTX_free(x)
88
89#define pq_64bit_assign(x, y) BN_copy(x, y)
90#define pq_64bit_assign_word(x, y) BN_set_word(x, y)
91#define pq_64bit_gt(x, y) BN_ucmp(x, y) >= 1 ? 1 : 0
92#define pq_64bit_eq(x, y) BN_ucmp(x, y) == 0 ? 1 : 0
93#define pq_64bit_add_word(x, w) BN_add_word(x, w)
94#define pq_64bit_sub(r, x, y) BN_sub(r, x, y)
95#define pq_64bit_sub_word(x, w) BN_sub_word(x, w)
96#define pq_64bit_mod(r, x, n, ctx) BN_mod(r, x, n, ctx)
97
98#define pq_64bit_bin2num(bn, bytes, len) BN_bin2bn(bytes, len, bn)
99#define pq_64bit_num2bin(bn, bytes) BN_bn2bin(bn, bytes)
100#define pq_64bit_get_word(x) BN_get_word(x)
101#define pq_64bit_is_bit_set(x, offset) BN_is_bit_set(x, offset)
102#define pq_64bit_lshift(r, x, shift) BN_lshift(r, x, shift)
103#define pq_64bit_set_bit(x, num) BN_set_bit(x, num)
104#define pq_64bit_get_length(x) BN_num_bits((x))
105
106#else
107
108#define PQ_64BIT_IS_INTEGER 1
109#define PQ_64BIT_IS_BIGNUM 0
110
111#if defined(SIXTY_FOUR_BIT)
112#define PQ_64BIT BN_ULONG
113#define PQ_64BIT_PRINT "%lld"
114#elif defined(SIXTY_FOUR_BIT_LONG)
115#define PQ_64BIT BN_ULONG
116#define PQ_64BIT_PRINT "%ld"
117#elif defined(THIRTY_TWO_BIT)
118#define PQ_64BIT BN_ULLONG
119#define PQ_64BIT_PRINT "%lld"
120#endif
121
122#define PQ_64BIT_CTX void
123
124#define pq_64bit_init(x)
125#define pq_64bit_free(x)
126#define pq_64bit_ctx_new(ctx) (ctx)
127#define pq_64bit_ctx_free(x)
128
129#define pq_64bit_assign(x, y) (*(x) = *(y))
130#define pq_64bit_assign_word(x, y) (*(x) = y)
131#define pq_64bit_gt(x, y) (*(x) > *(y))
132#define pq_64bit_eq(x, y) (*(x) == *(y))
133#define pq_64bit_add_word(x, w) (*(x) = (*(x) + (w)))
134#define pq_64bit_sub(r, x, y) (*(r) = (*(x) - *(y)))
135#define pq_64bit_sub_word(x, w) (*(x) = (*(x) - (w)))
136#define pq_64bit_mod(r, x, n, ctx)
137
138#define pq_64bit_bin2num(num, bytes, len) bytes_to_long_long(bytes, num)
139#define pq_64bit_num2bin(num, bytes) long_long_to_bytes(num, bytes)
140#define pq_64bit_get_word(x) *(x)
141#define pq_64bit_lshift(r, x, shift) (*(r) = (*(x) << (shift)))
142#define pq_64bit_set_bit(x, num) do { \
143 PQ_64BIT mask = 1; \
144 mask = mask << (num); \
145 *(x) |= mask; \
146 } while(0)
147#endif /* OPENSSL_SYS_VMS */
diff --git a/src/lib/libcrypto/pqueue/pq_test.c b/src/lib/libcrypto/pqueue/pq_test.c
new file mode 100644
index 0000000000..8d496dfc65
--- /dev/null
+++ b/src/lib/libcrypto/pqueue/pq_test.c
@@ -0,0 +1,95 @@
1/* crypto/pqueue/pq_test.c */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include "pqueue.h"
61
62int
63main(void)
64 {
65 pitem *item;
66 pqueue pq;
67
68 pq = pqueue_new();
69
70 item = pitem_new(3, NULL);
71 pqueue_insert(pq, item);
72
73 item = pitem_new(1, NULL);
74 pqueue_insert(pq, item);
75
76 item = pitem_new(2, NULL);
77 pqueue_insert(pq, item);
78
79 item = pqueue_find(pq, 1);
80 fprintf(stderr, "found %ld\n", item->priority);
81
82 item = pqueue_find(pq, 2);
83 fprintf(stderr, "found %ld\n", item->priority);
84
85 item = pqueue_find(pq, 3);
86 fprintf(stderr, "found %ld\n", item ? item->priority: 0);
87
88 pqueue_print(pq);
89
90 for(item = pqueue_pop(pq); item != NULL; item = pqueue_pop(pq))
91 pitem_free(item);
92
93 pqueue_free(pq);
94 return 0;
95 }
diff --git a/src/lib/libcrypto/pqueue/pqueue.c b/src/lib/libcrypto/pqueue/pqueue.c
new file mode 100644
index 0000000000..5cc18527f8
--- /dev/null
+++ b/src/lib/libcrypto/pqueue/pqueue.c
@@ -0,0 +1,236 @@
1/* crypto/pqueue/pqueue.c */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include "pqueue.h"
63
64typedef struct _pqueue
65 {
66 pitem *items;
67 int count;
68 } pqueue_s;
69
70pitem *
71pitem_new(PQ_64BIT priority, void *data)
72 {
73 pitem *item = (pitem *) OPENSSL_malloc(sizeof(pitem));
74 if (item == NULL) return NULL;
75
76 pq_64bit_init(&(item->priority));
77 pq_64bit_assign(&item->priority, &priority);
78
79 item->data = data;
80 item->next = NULL;
81
82 return item;
83 }
84
85void
86pitem_free(pitem *item)
87 {
88 if (item == NULL) return;
89
90 pq_64bit_free(&(item->priority));
91 OPENSSL_free(item);
92 }
93
94pqueue_s *
95pqueue_new()
96 {
97 pqueue_s *pq = (pqueue_s *) OPENSSL_malloc(sizeof(pqueue_s));
98 if (pq == NULL) return NULL;
99
100 memset(pq, 0x00, sizeof(pqueue_s));
101 return pq;
102 }
103
104void
105pqueue_free(pqueue_s *pq)
106 {
107 if (pq == NULL) return;
108
109 OPENSSL_free(pq);
110 }
111
112pitem *
113pqueue_insert(pqueue_s *pq, pitem *item)
114 {
115 pitem *curr, *next;
116
117 if (pq->items == NULL)
118 {
119 pq->items = item;
120 return item;
121 }
122
123 for(curr = NULL, next = pq->items;
124 next != NULL;
125 curr = next, next = next->next)
126 {
127 if (pq_64bit_gt(&(next->priority), &(item->priority)))
128 {
129 item->next = next;
130
131 if (curr == NULL)
132 pq->items = item;
133 else
134 curr->next = item;
135
136 return item;
137 }
138 /* duplicates not allowed */
139 if (pq_64bit_eq(&(item->priority), &(next->priority)))
140 return NULL;
141 }
142
143 item->next = NULL;
144 curr->next = item;
145
146 return item;
147 }
148
149pitem *
150pqueue_peek(pqueue_s *pq)
151 {
152 return pq->items;
153 }
154
155pitem *
156pqueue_pop(pqueue_s *pq)
157 {
158 pitem *item = pq->items;
159
160 if (pq->items != NULL)
161 pq->items = pq->items->next;
162
163 return item;
164 }
165
166pitem *
167pqueue_find(pqueue_s *pq, PQ_64BIT priority)
168 {
169 pitem *next, *prev = NULL;
170 pitem *found = NULL;
171
172 if ( pq->items == NULL)
173 return NULL;
174
175 for ( next = pq->items; next->next != NULL;
176 prev = next, next = next->next)
177 {
178 if ( pq_64bit_eq(&(next->priority), &priority))
179 {
180 found = next;
181 break;
182 }
183 }
184
185 /* check the one last node */
186 if ( pq_64bit_eq(&(next->priority), &priority))
187 found = next;
188
189 if ( ! found)
190 return NULL;
191
192#if 0 /* find works in peek mode */
193 if ( prev == NULL)
194 pq->items = next->next;
195 else
196 prev->next = next->next;
197#endif
198
199 return found;
200 }
201
202#if PQ_64BIT_IS_INTEGER
203void
204pqueue_print(pqueue_s *pq)
205 {
206 pitem *item = pq->items;
207
208 while(item != NULL)
209 {
210 printf("item\t" PQ_64BIT_PRINT "\n", item->priority);
211 item = item->next;
212 }
213 }
214#endif
215
216pitem *
217pqueue_iterator(pqueue_s *pq)
218 {
219 return pqueue_peek(pq);
220 }
221
222pitem *
223pqueue_next(pitem **item)
224 {
225 pitem *ret;
226
227 if ( item == NULL || *item == NULL)
228 return NULL;
229
230
231 /* *item != NULL */
232 ret = *item;
233 *item = (*item)->next;
234
235 return ret;
236 }
diff --git a/src/lib/libcrypto/pqueue/pqueue.h b/src/lib/libcrypto/pqueue/pqueue.h
new file mode 100644
index 0000000000..02386d130e
--- /dev/null
+++ b/src/lib/libcrypto/pqueue/pqueue.h
@@ -0,0 +1,95 @@
1/* crypto/pqueue/pqueue.h */
2/*
3 * DTLS implementation written by Nagendra Modadugu
4 * (nagendra@cs.stanford.edu) for the OpenSSL project 2005.
5 */
6/* ====================================================================
7 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in
18 * the documentation and/or other materials provided with the
19 * distribution.
20 *
21 * 3. All advertising materials mentioning features or use of this
22 * software must display the following acknowledgment:
23 * "This product includes software developed by the OpenSSL Project
24 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 *
26 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
27 * endorse or promote products derived from this software without
28 * prior written permission. For written permission, please contact
29 * openssl-core@OpenSSL.org.
30 *
31 * 5. Products derived from this software may not be called "OpenSSL"
32 * nor may "OpenSSL" appear in their names without prior written
33 * permission of the OpenSSL Project.
34 *
35 * 6. Redistributions of any form whatsoever must retain the following
36 * acknowledgment:
37 * "This product includes software developed by the OpenSSL Project
38 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
41 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
43 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
44 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
45 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
46 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
47 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
49 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
50 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
51 * OF THE POSSIBILITY OF SUCH DAMAGE.
52 * ====================================================================
53 *
54 * This product includes cryptographic software written by Eric Young
55 * (eay@cryptsoft.com). This product includes software written by Tim
56 * Hudson (tjh@cryptsoft.com).
57 *
58 */
59
60#ifndef HEADER_PQUEUE_H
61#define HEADER_PQUEUE_H
62
63#include <stdio.h>
64#include <stdlib.h>
65#include <string.h>
66
67#include <openssl/pq_compat.h>
68
69typedef struct _pqueue *pqueue;
70
71typedef struct _pitem
72 {
73 PQ_64BIT priority;
74 void *data;
75 struct _pitem *next;
76 } pitem;
77
78typedef struct _pitem *piterator;
79
80pitem *pitem_new(PQ_64BIT priority, void *data);
81void pitem_free(pitem *item);
82
83pqueue pqueue_new(void);
84void pqueue_free(pqueue pq);
85
86pitem *pqueue_insert(pqueue pq, pitem *item);
87pitem *pqueue_peek(pqueue pq);
88pitem *pqueue_pop(pqueue pq);
89pitem *pqueue_find(pqueue pq, PQ_64BIT priority);
90pitem *pqueue_iterator(pqueue pq);
91pitem *pqueue_next(piterator *iter);
92
93void pqueue_print(pqueue pq);
94
95#endif /* ! HEADER_PQUEUE_H */
diff --git a/src/lib/libcrypto/rand/Makefile b/src/lib/libcrypto/rand/Makefile
new file mode 100644
index 0000000000..3c1ab5bbae
--- /dev/null
+++ b/src/lib/libcrypto/rand/Makefile
@@ -0,0 +1,159 @@
1#
2# OpenSSL/crypto/rand/Makefile
3#
4
5DIR= rand
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST= randtest.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \
21 rand_win.c rand_unix.c rand_os2.c rand_nw.c
22LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o \
23 rand_win.o rand_unix.o rand_os2.o rand_nw.o
24
25SRC= $(LIBSRC)
26
27EXHEADER= rand.h
28HEADER= $(EXHEADER)
29
30ALL= $(GENERAL) $(SRC) $(HEADER)
31
32top:
33 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
34
35all: lib
36
37lib: $(LIBOBJ)
38 $(AR) $(LIB) $(LIBOBJ)
39 $(RANLIB) $(LIB) || echo Never mind.
40 @touch lib
41
42files:
43 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
44
45links:
46 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
47 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
48 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
49
50install:
51 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
52 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
53 do \
54 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
55 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
56 done;
57
58tags:
59 ctags $(SRC)
60
61tests:
62
63lint:
64 lint -DLINT $(INCLUDES) $(SRC)>fluff
65
66depend:
67 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
68 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
69
70dclean:
71 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
72 mv -f Makefile.new $(MAKEFILE)
73
74clean:
75 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
76
77# DO NOT DELETE THIS LINE -- make depend depends on it.
78
79md_rand.o: ../../e_os.h ../../include/openssl/asn1.h
80md_rand.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
81md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
82md_rand.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
83md_rand.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
84md_rand.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
85md_rand.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
86md_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
87md_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88md_rand.o: md_rand.c rand_lcl.h
89rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h
90rand_egd.o: ../../include/openssl/opensslconf.h
91rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
92rand_egd.o: rand_egd.c
93rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
94rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
95rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
96rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
97rand_err.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
98rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
99rand_err.o: rand_err.c
100rand_lib.o: ../../e_os.h ../../include/openssl/bio.h
101rand_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102rand_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
103rand_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
104rand_lib.o: ../../include/openssl/opensslconf.h
105rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
106rand_lib.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
107rand_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
108rand_lib.o: ../cryptlib.h rand_lib.c
109rand_nw.o: ../../e_os.h ../../include/openssl/asn1.h
110rand_nw.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
111rand_nw.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
112rand_nw.o: ../../include/openssl/err.h ../../include/openssl/evp.h
113rand_nw.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
114rand_nw.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
115rand_nw.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
116rand_nw.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
117rand_nw.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
118rand_nw.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h rand_nw.c
119rand_os2.o: ../../e_os.h ../../include/openssl/asn1.h
120rand_os2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
121rand_os2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
122rand_os2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
123rand_os2.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
124rand_os2.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
125rand_os2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
126rand_os2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
127rand_os2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
128rand_os2.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h
129rand_os2.o: rand_os2.c
130rand_unix.o: ../../e_os.h ../../include/openssl/asn1.h
131rand_unix.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
132rand_unix.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
133rand_unix.o: ../../include/openssl/err.h ../../include/openssl/evp.h
134rand_unix.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
135rand_unix.o: ../../include/openssl/objects.h
136rand_unix.o: ../../include/openssl/opensslconf.h
137rand_unix.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
138rand_unix.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
139rand_unix.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
140rand_unix.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h
141rand_unix.o: rand_unix.c
142rand_win.o: ../../e_os.h ../../include/openssl/asn1.h
143rand_win.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
144rand_win.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
145rand_win.o: ../../include/openssl/err.h ../../include/openssl/evp.h
146rand_win.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
147rand_win.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
148rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149rand_win.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
150rand_win.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
151rand_win.o: ../../include/openssl/symhacks.h ../cryptlib.h rand_lcl.h
152rand_win.o: rand_win.c
153randfile.o: ../../e_os.h ../../include/openssl/buffer.h
154randfile.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
155randfile.o: ../../include/openssl/opensslconf.h
156randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
157randfile.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
158randfile.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
159randfile.o: randfile.c
diff --git a/src/lib/libcrypto/rand/Makefile.ssl b/src/lib/libcrypto/rand/Makefile.ssl
new file mode 100644
index 0000000000..e5cbe5319c
--- /dev/null
+++ b/src/lib/libcrypto/rand/Makefile.ssl
@@ -0,0 +1,196 @@
1#
2# SSLeay/crypto/rand/Makefile
3#
4
5DIR= rand
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST= randtest.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=md_rand.c randfile.c rand_lib.c rand_err.c rand_egd.c \
27 rand_win.c rand_unix.c rand_os2.c
28LIBOBJ=md_rand.o randfile.o rand_lib.o rand_err.o rand_egd.o \
29 rand_win.o rand_unix.o rand_os2.o
30
31SRC= $(LIBSRC)
32
33EXHEADER= rand.h
34HEADER= $(EXHEADER)
35
36ALL= $(GENERAL) $(SRC) $(HEADER)
37
38top:
39 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
40
41all: lib
42
43lib: $(LIBOBJ)
44 $(AR) $(LIB) $(LIBOBJ)
45 $(RANLIB) $(LIB) || echo Never mind.
46 @touch lib
47
48files:
49 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
50
51links:
52 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
53 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
54 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
55 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
56
57install:
58 @for i in $(EXHEADER) ; \
59 do \
60 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
61 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
62 done;
63
64tags:
65 ctags $(SRC)
66
67tests:
68
69lint:
70 lint -DLINT $(INCLUDES) $(SRC)>fluff
71
72depend:
73 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
74
75dclean:
76 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
77 mv -f Makefile.new $(MAKEFILE)
78
79clean:
80 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
81
82# DO NOT DELETE THIS LINE -- make depend depends on it.
83
84md_rand.o: ../../e_os.h ../../include/openssl/aes.h
85md_rand.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
86md_rand.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
87md_rand.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
88md_rand.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
89md_rand.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
90md_rand.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
91md_rand.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
92md_rand.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
93md_rand.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
94md_rand.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
95md_rand.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
96md_rand.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
97md_rand.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
98md_rand.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
99md_rand.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
100md_rand.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
101md_rand.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
102md_rand.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
103md_rand.o: md_rand.c rand_lcl.h
104rand_egd.o: ../../include/openssl/buffer.h ../../include/openssl/e_os2.h
105rand_egd.o: ../../include/openssl/opensslconf.h
106rand_egd.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
107rand_egd.o: rand_egd.c
108rand_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
109rand_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
110rand_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
111rand_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
112rand_err.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
113rand_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
114rand_err.o: rand_err.c
115rand_lib.o: ../../e_os.h ../../include/openssl/asn1.h
116rand_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
117rand_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
118rand_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
119rand_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
120rand_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
121rand_lib.o: ../../include/openssl/opensslconf.h
122rand_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
123rand_lib.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
124rand_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
125rand_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
126rand_lib.o: ../cryptlib.h rand_lib.c
127rand_os2.o: ../../e_os.h ../../include/openssl/aes.h
128rand_os2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
129rand_os2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
130rand_os2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
131rand_os2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
132rand_os2.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
133rand_os2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
134rand_os2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
135rand_os2.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
136rand_os2.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
137rand_os2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
138rand_os2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
139rand_os2.o: ../../include/openssl/opensslconf.h
140rand_os2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
141rand_os2.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
142rand_os2.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
143rand_os2.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
144rand_os2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
145rand_os2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
146rand_os2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
147rand_os2.o: ../cryptlib.h rand_lcl.h rand_os2.c
148rand_unix.o: ../../e_os.h ../../include/openssl/aes.h
149rand_unix.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
150rand_unix.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
151rand_unix.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
152rand_unix.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
153rand_unix.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
154rand_unix.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
155rand_unix.o: ../../include/openssl/err.h ../../include/openssl/evp.h
156rand_unix.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
157rand_unix.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
158rand_unix.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
159rand_unix.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
160rand_unix.o: ../../include/openssl/opensslconf.h
161rand_unix.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
162rand_unix.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
163rand_unix.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
164rand_unix.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
165rand_unix.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
166rand_unix.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
167rand_unix.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
168rand_unix.o: ../cryptlib.h rand_lcl.h rand_unix.c
169rand_win.o: ../../e_os.h ../../include/openssl/aes.h
170rand_win.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
171rand_win.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
172rand_win.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
173rand_win.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
174rand_win.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
175rand_win.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
176rand_win.o: ../../include/openssl/err.h ../../include/openssl/evp.h
177rand_win.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
178rand_win.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
179rand_win.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
180rand_win.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
181rand_win.o: ../../include/openssl/opensslconf.h
182rand_win.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
183rand_win.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
184rand_win.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
185rand_win.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
186rand_win.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
187rand_win.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
188rand_win.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
189rand_win.o: ../cryptlib.h rand_lcl.h rand_win.c
190randfile.o: ../../e_os.h ../../include/openssl/buffer.h
191randfile.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
192randfile.o: ../../include/openssl/opensslconf.h
193randfile.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
194randfile.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h
195randfile.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
196randfile.o: randfile.c
diff --git a/src/lib/libcrypto/rand/md_rand.c b/src/lib/libcrypto/rand/md_rand.c
new file mode 100644
index 0000000000..c84968df88
--- /dev/null
+++ b/src/lib/libcrypto/rand/md_rand.c
@@ -0,0 +1,581 @@
1/* crypto/rand/md_rand.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifdef MD_RAND_DEBUG
113# ifndef NDEBUG
114# define NDEBUG
115# endif
116#endif
117
118#include <assert.h>
119#include <stdio.h>
120#include <string.h>
121
122#include "e_os.h"
123
124#include <openssl/rand.h>
125#include "rand_lcl.h"
126
127#include <openssl/crypto.h>
128#include <openssl/err.h>
129#include <openssl/fips.h>
130
131#ifdef BN_DEBUG
132# define PREDICT
133#endif
134
135/* #define PREDICT 1 */
136
137#define STATE_SIZE 1023
138static int state_num=0,state_index=0;
139static unsigned char state[STATE_SIZE+MD_DIGEST_LENGTH];
140static unsigned char md[MD_DIGEST_LENGTH];
141static long md_count[2]={0,0};
142static double entropy=0;
143static int initialized=0;
144
145static unsigned int crypto_lock_rand = 0; /* may be set only when a thread
146 * holds CRYPTO_LOCK_RAND
147 * (to prevent double locking) */
148/* access to lockin_thread is synchronized by CRYPTO_LOCK_RAND2 */
149static unsigned long locking_thread = 0; /* valid iff crypto_lock_rand is set */
150
151
152#ifdef PREDICT
153int rand_predictable=0;
154#endif
155
156const char *RAND_version="RAND" OPENSSL_VERSION_PTEXT;
157
158static void ssleay_rand_cleanup(void);
159static void ssleay_rand_seed(const void *buf, int num);
160static void ssleay_rand_add(const void *buf, int num, double add_entropy);
161static int ssleay_rand_bytes(unsigned char *buf, int num);
162static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num);
163static int ssleay_rand_status(void);
164
165RAND_METHOD rand_ssleay_meth={
166 ssleay_rand_seed,
167 ssleay_rand_bytes,
168 ssleay_rand_cleanup,
169 ssleay_rand_add,
170 ssleay_rand_pseudo_bytes,
171 ssleay_rand_status
172 };
173
174RAND_METHOD *RAND_SSLeay(void)
175 {
176 return(&rand_ssleay_meth);
177 }
178
179static void ssleay_rand_cleanup(void)
180 {
181 OPENSSL_cleanse(state,sizeof(state));
182 state_num=0;
183 state_index=0;
184 OPENSSL_cleanse(md,MD_DIGEST_LENGTH);
185 md_count[0]=0;
186 md_count[1]=0;
187 entropy=0;
188 initialized=0;
189 }
190
191static void ssleay_rand_add(const void *buf, int num, double add)
192 {
193 int i,j,k,st_idx;
194 long md_c[2];
195 unsigned char local_md[MD_DIGEST_LENGTH];
196 EVP_MD_CTX m;
197 int do_not_lock;
198
199 /*
200 * (Based on the rand(3) manpage)
201 *
202 * The input is chopped up into units of 20 bytes (or less for
203 * the last block). Each of these blocks is run through the hash
204 * function as follows: The data passed to the hash function
205 * is the current 'md', the same number of bytes from the 'state'
206 * (the location determined by in incremented looping index) as
207 * the current 'block', the new key data 'block', and 'count'
208 * (which is incremented after each use).
209 * The result of this is kept in 'md' and also xored into the
210 * 'state' at the same locations that were used as input into the
211 * hash function.
212 */
213
214 /* check if we already have the lock */
215 if (crypto_lock_rand)
216 {
217 CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
218 do_not_lock = (locking_thread == CRYPTO_thread_id());
219 CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
220 }
221 else
222 do_not_lock = 0;
223
224 if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);
225 st_idx=state_index;
226
227 /* use our own copies of the counters so that even
228 * if a concurrent thread seeds with exactly the
229 * same data and uses the same subarray there's _some_
230 * difference */
231 md_c[0] = md_count[0];
232 md_c[1] = md_count[1];
233
234 memcpy(local_md, md, sizeof md);
235
236 /* state_index <= state_num <= STATE_SIZE */
237 state_index += num;
238 if (state_index >= STATE_SIZE)
239 {
240 state_index%=STATE_SIZE;
241 state_num=STATE_SIZE;
242 }
243 else if (state_num < STATE_SIZE)
244 {
245 if (state_index > state_num)
246 state_num=state_index;
247 }
248 /* state_index <= state_num <= STATE_SIZE */
249
250 /* state[st_idx], ..., state[(st_idx + num - 1) % STATE_SIZE]
251 * are what we will use now, but other threads may use them
252 * as well */
253
254 md_count[1] += (num / MD_DIGEST_LENGTH) + (num % MD_DIGEST_LENGTH > 0);
255
256 if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
257
258 EVP_MD_CTX_init(&m);
259 for (i=0; i<num; i+=MD_DIGEST_LENGTH)
260 {
261 j=(num-i);
262 j=(j > MD_DIGEST_LENGTH)?MD_DIGEST_LENGTH:j;
263
264 MD_Init(&m);
265 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
266 k=(st_idx+j)-STATE_SIZE;
267 if (k > 0)
268 {
269 MD_Update(&m,&(state[st_idx]),j-k);
270 MD_Update(&m,&(state[0]),k);
271 }
272 else
273 MD_Update(&m,&(state[st_idx]),j);
274
275 MD_Update(&m,buf,j);
276 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
277 MD_Final(&m,local_md);
278 md_c[1]++;
279
280 buf=(const char *)buf + j;
281
282 for (k=0; k<j; k++)
283 {
284 /* Parallel threads may interfere with this,
285 * but always each byte of the new state is
286 * the XOR of some previous value of its
287 * and local_md (itermediate values may be lost).
288 * Alway using locking could hurt performance more
289 * than necessary given that conflicts occur only
290 * when the total seeding is longer than the random
291 * state. */
292 state[st_idx++]^=local_md[k];
293 if (st_idx >= STATE_SIZE)
294 st_idx=0;
295 }
296 }
297 EVP_MD_CTX_cleanup(&m);
298
299 if (!do_not_lock) CRYPTO_w_lock(CRYPTO_LOCK_RAND);
300 /* Don't just copy back local_md into md -- this could mean that
301 * other thread's seeding remains without effect (except for
302 * the incremented counter). By XORing it we keep at least as
303 * much entropy as fits into md. */
304 for (k = 0; k < sizeof md; k++)
305 {
306 md[k] ^= local_md[k];
307 }
308 if (entropy < ENTROPY_NEEDED) /* stop counting when we have enough */
309 entropy += add;
310 if (!do_not_lock) CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
311
312#if !defined(OPENSSL_THREADS) && !defined(OPENSSL_SYS_WIN32)
313 assert(md_c[1] == md_count[1]);
314#endif
315 }
316
317static void ssleay_rand_seed(const void *buf, int num)
318 {
319 ssleay_rand_add(buf, num, num);
320 }
321
322static int ssleay_rand_bytes(unsigned char *buf, int num)
323 {
324 static volatile int stirred_pool = 0;
325 int i,j,k,st_num,st_idx;
326 int num_ceil;
327 int ok;
328 long md_c[2];
329 unsigned char local_md[MD_DIGEST_LENGTH];
330 EVP_MD_CTX m;
331#ifndef GETPID_IS_MEANINGLESS
332 pid_t curr_pid = getpid();
333#endif
334 int do_stir_pool = 0;
335
336#ifdef OPENSSL_FIPS
337 if(FIPS_mode())
338 {
339 FIPSerr(FIPS_F_SSLEAY_RAND_BYTES,FIPS_R_NON_FIPS_METHOD);
340 return 0;
341 }
342#endif
343
344#ifdef PREDICT
345 if (rand_predictable)
346 {
347 static unsigned char val=0;
348
349 for (i=0; i<num; i++)
350 buf[i]=val++;
351 return(1);
352 }
353#endif
354
355 if (num <= 0)
356 return 1;
357
358 EVP_MD_CTX_init(&m);
359 /* round upwards to multiple of MD_DIGEST_LENGTH/2 */
360 num_ceil = (1 + (num-1)/(MD_DIGEST_LENGTH/2)) * (MD_DIGEST_LENGTH/2);
361
362 /*
363 * (Based on the rand(3) manpage:)
364 *
365 * For each group of 10 bytes (or less), we do the following:
366 *
367 * Input into the hash function the local 'md' (which is initialized from
368 * the global 'md' before any bytes are generated), the bytes that are to
369 * be overwritten by the random bytes, and bytes from the 'state'
370 * (incrementing looping index). From this digest output (which is kept
371 * in 'md'), the top (up to) 10 bytes are returned to the caller and the
372 * bottom 10 bytes are xored into the 'state'.
373 *
374 * Finally, after we have finished 'num' random bytes for the
375 * caller, 'count' (which is incremented) and the local and global 'md'
376 * are fed into the hash function and the results are kept in the
377 * global 'md'.
378 */
379
380 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
381
382 /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
383 CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
384 locking_thread = CRYPTO_thread_id();
385 CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
386 crypto_lock_rand = 1;
387
388 if (!initialized)
389 {
390 RAND_poll();
391 initialized = 1;
392 }
393
394 if (!stirred_pool)
395 do_stir_pool = 1;
396
397 ok = (entropy >= ENTROPY_NEEDED);
398 if (!ok)
399 {
400 /* If the PRNG state is not yet unpredictable, then seeing
401 * the PRNG output may help attackers to determine the new
402 * state; thus we have to decrease the entropy estimate.
403 * Once we've had enough initial seeding we don't bother to
404 * adjust the entropy count, though, because we're not ambitious
405 * to provide *information-theoretic* randomness.
406 *
407 * NOTE: This approach fails if the program forks before
408 * we have enough entropy. Entropy should be collected
409 * in a separate input pool and be transferred to the
410 * output pool only when the entropy limit has been reached.
411 */
412 entropy -= num;
413 if (entropy < 0)
414 entropy = 0;
415 }
416
417 if (do_stir_pool)
418 {
419 /* In the output function only half of 'md' remains secret,
420 * so we better make sure that the required entropy gets
421 * 'evenly distributed' through 'state', our randomness pool.
422 * The input function (ssleay_rand_add) chains all of 'md',
423 * which makes it more suitable for this purpose.
424 */
425
426 int n = STATE_SIZE; /* so that the complete pool gets accessed */
427 while (n > 0)
428 {
429#if MD_DIGEST_LENGTH > 20
430# error "Please adjust DUMMY_SEED."
431#endif
432#define DUMMY_SEED "...................." /* at least MD_DIGEST_LENGTH */
433 /* Note that the seed does not matter, it's just that
434 * ssleay_rand_add expects to have something to hash. */
435 ssleay_rand_add(DUMMY_SEED, MD_DIGEST_LENGTH, 0.0);
436 n -= MD_DIGEST_LENGTH;
437 }
438 if (ok)
439 stirred_pool = 1;
440 }
441
442 st_idx=state_index;
443 st_num=state_num;
444 md_c[0] = md_count[0];
445 md_c[1] = md_count[1];
446 memcpy(local_md, md, sizeof md);
447
448 state_index+=num_ceil;
449 if (state_index > state_num)
450 state_index %= state_num;
451
452 /* state[st_idx], ..., state[(st_idx + num_ceil - 1) % st_num]
453 * are now ours (but other threads may use them too) */
454
455 md_count[0] += 1;
456
457 /* before unlocking, we must clear 'crypto_lock_rand' */
458 crypto_lock_rand = 0;
459 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
460
461 while (num > 0)
462 {
463 /* num_ceil -= MD_DIGEST_LENGTH/2 */
464 j=(num >= MD_DIGEST_LENGTH/2)?MD_DIGEST_LENGTH/2:num;
465 num-=j;
466 MD_Init(&m);
467#ifndef GETPID_IS_MEANINGLESS
468 if (curr_pid) /* just in the first iteration to save time */
469 {
470 MD_Update(&m,(unsigned char*)&curr_pid,sizeof curr_pid);
471 curr_pid = 0;
472 }
473#endif
474 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
475 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
476#ifndef PURIFY
477 MD_Update(&m,buf,j); /* purify complains */
478#endif
479 k=(st_idx+MD_DIGEST_LENGTH/2)-st_num;
480 if (k > 0)
481 {
482 MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2-k);
483 MD_Update(&m,&(state[0]),k);
484 }
485 else
486 MD_Update(&m,&(state[st_idx]),MD_DIGEST_LENGTH/2);
487 MD_Final(&m,local_md);
488
489 for (i=0; i<MD_DIGEST_LENGTH/2; i++)
490 {
491 state[st_idx++]^=local_md[i]; /* may compete with other threads */
492 if (st_idx >= st_num)
493 st_idx=0;
494 if (i < j)
495 *(buf++)=local_md[i+MD_DIGEST_LENGTH/2];
496 }
497 }
498
499 MD_Init(&m);
500 MD_Update(&m,(unsigned char *)&(md_c[0]),sizeof(md_c));
501 MD_Update(&m,local_md,MD_DIGEST_LENGTH);
502 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
503 MD_Update(&m,md,MD_DIGEST_LENGTH);
504 MD_Final(&m,md);
505 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
506
507 EVP_MD_CTX_cleanup(&m);
508 if (ok)
509 return(1);
510 else
511 {
512 RANDerr(RAND_F_SSLEAY_RAND_BYTES,RAND_R_PRNG_NOT_SEEDED);
513 ERR_add_error_data(1, "You need to read the OpenSSL FAQ, "
514 "http://www.openssl.org/support/faq.html");
515 return(0);
516 }
517 }
518
519/* pseudo-random bytes that are guaranteed to be unique but not
520 unpredictable */
521static int ssleay_rand_pseudo_bytes(unsigned char *buf, int num)
522 {
523 int ret;
524 unsigned long err;
525
526 ret = RAND_bytes(buf, num);
527 if (ret == 0)
528 {
529 err = ERR_peek_error();
530 if (ERR_GET_LIB(err) == ERR_LIB_RAND &&
531 ERR_GET_REASON(err) == RAND_R_PRNG_NOT_SEEDED)
532 (void)ERR_get_error();
533 }
534 return (ret);
535 }
536
537static int ssleay_rand_status(void)
538 {
539 int ret;
540 int do_not_lock;
541
542 /* check if we already have the lock
543 * (could happen if a RAND_poll() implementation calls RAND_status()) */
544 if (crypto_lock_rand)
545 {
546 CRYPTO_r_lock(CRYPTO_LOCK_RAND2);
547 do_not_lock = (locking_thread == CRYPTO_thread_id());
548 CRYPTO_r_unlock(CRYPTO_LOCK_RAND2);
549 }
550 else
551 do_not_lock = 0;
552
553 if (!do_not_lock)
554 {
555 CRYPTO_w_lock(CRYPTO_LOCK_RAND);
556
557 /* prevent ssleay_rand_bytes() from trying to obtain the lock again */
558 CRYPTO_w_lock(CRYPTO_LOCK_RAND2);
559 locking_thread = CRYPTO_thread_id();
560 CRYPTO_w_unlock(CRYPTO_LOCK_RAND2);
561 crypto_lock_rand = 1;
562 }
563
564 if (!initialized)
565 {
566 RAND_poll();
567 initialized = 1;
568 }
569
570 ret = entropy >= ENTROPY_NEEDED;
571
572 if (!do_not_lock)
573 {
574 /* before unlocking, we must clear 'crypto_lock_rand' */
575 crypto_lock_rand = 0;
576
577 CRYPTO_w_unlock(CRYPTO_LOCK_RAND);
578 }
579
580 return ret;
581 }
diff --git a/src/lib/libcrypto/rand/rand.h b/src/lib/libcrypto/rand/rand.h
index ac6c021763..604df9be6c 100644
--- a/src/lib/libcrypto/rand/rand.h
+++ b/src/lib/libcrypto/rand/rand.h
@@ -72,13 +72,10 @@ extern "C" {
72#endif 72#endif
73 73
74#if defined(OPENSSL_FIPS) 74#if defined(OPENSSL_FIPS)
75#define FIPS_RAND_SIZE_T size_t 75#define FIPS_RAND_SIZE_T int
76#endif 76#endif
77 77
78/* Already defined in ossl_typ.h */ 78typedef struct rand_meth_st
79/* typedef struct rand_meth_st RAND_METHOD; */
80
81struct rand_meth_st
82 { 79 {
83 void (*seed)(const void *buf, int num); 80 void (*seed)(const void *buf, int num);
84 int (*bytes)(unsigned char *buf, int num); 81 int (*bytes)(unsigned char *buf, int num);
@@ -86,7 +83,7 @@ struct rand_meth_st
86 void (*add)(const void *buf, int num, double entropy); 83 void (*add)(const void *buf, int num, double entropy);
87 int (*pseudorand)(unsigned char *buf, int num); 84 int (*pseudorand)(unsigned char *buf, int num);
88 int (*status)(void); 85 int (*status)(void);
89 }; 86 } RAND_METHOD;
90 87
91#ifdef BN_DEBUG 88#ifdef BN_DEBUG
92extern int rand_predictable; 89extern int rand_predictable;
@@ -128,11 +125,17 @@ void ERR_load_RAND_strings(void);
128/* Error codes for the RAND functions. */ 125/* Error codes for the RAND functions. */
129 126
130/* Function codes. */ 127/* Function codes. */
128#define RAND_F_FIPS_RAND_BYTES 102
131#define RAND_F_RAND_GET_RAND_METHOD 101 129#define RAND_F_RAND_GET_RAND_METHOD 101
132#define RAND_F_SSLEAY_RAND_BYTES 100 130#define RAND_F_SSLEAY_RAND_BYTES 100
133 131
134/* Reason codes. */ 132/* Reason codes. */
133#define RAND_R_NON_FIPS_METHOD 101
134#define RAND_R_PRNG_ASKING_FOR_TOO_MUCH 105
135#define RAND_R_PRNG_NOT_REKEYED 103
136#define RAND_R_PRNG_NOT_RESEEDED 104
135#define RAND_R_PRNG_NOT_SEEDED 100 137#define RAND_R_PRNG_NOT_SEEDED 100
138#define RAND_R_PRNG_STUCK 102
136 139
137#ifdef __cplusplus 140#ifdef __cplusplus
138} 141}
diff --git a/src/lib/libcrypto/rand/rand_egd.c b/src/lib/libcrypto/rand/rand_egd.c
new file mode 100644
index 0000000000..cd666abfcb
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_egd.c
@@ -0,0 +1,303 @@
1/* crypto/rand/rand_egd.c */
2/* Written by Ulf Moeller and Lutz Jaenicke for the OpenSSL project. */
3/* ====================================================================
4 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 *
18 * 3. All advertising materials mentioning features or use of this
19 * software must display the following acknowledgment:
20 * "This product includes software developed by the OpenSSL Project
21 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
22 *
23 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
24 * endorse or promote products derived from this software without
25 * prior written permission. For written permission, please contact
26 * openssl-core@openssl.org.
27 *
28 * 5. Products derived from this software may not be called "OpenSSL"
29 * nor may "OpenSSL" appear in their names without prior written
30 * permission of the OpenSSL Project.
31 *
32 * 6. Redistributions of any form whatsoever must retain the following
33 * acknowledgment:
34 * "This product includes software developed by the OpenSSL Project
35 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
36 *
37 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
38 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
39 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
40 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
41 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
43 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
44 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
45 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
46 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
47 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 * OF THE POSSIBILITY OF SUCH DAMAGE.
49 * ====================================================================
50 *
51 * This product includes cryptographic software written by Eric Young
52 * (eay@cryptsoft.com). This product includes software written by Tim
53 * Hudson (tjh@cryptsoft.com).
54 *
55 */
56
57#include <openssl/e_os2.h>
58#include <openssl/rand.h>
59#include <openssl/buffer.h>
60
61/*
62 * Query the EGD <URL: http://www.lothar.com/tech/crypto/>.
63 *
64 * This module supplies three routines:
65 *
66 * RAND_query_egd_bytes(path, buf, bytes)
67 * will actually query "bytes" bytes of entropy form the egd-socket located
68 * at path and will write them to buf (if supplied) or will directly feed
69 * it to RAND_seed() if buf==NULL.
70 * The number of bytes is not limited by the maximum chunk size of EGD,
71 * which is 255 bytes. If more than 255 bytes are wanted, several chunks
72 * of entropy bytes are requested. The connection is left open until the
73 * query is competed.
74 * RAND_query_egd_bytes() returns with
75 * -1 if an error occured during connection or communication.
76 * num the number of bytes read from the EGD socket. This number is either
77 * the number of bytes requested or smaller, if the EGD pool is
78 * drained and the daemon signals that the pool is empty.
79 * This routine does not touch any RAND_status(). This is necessary, since
80 * PRNG functions may call it during initialization.
81 *
82 * RAND_egd_bytes(path, bytes) will query "bytes" bytes and have them
83 * used to seed the PRNG.
84 * RAND_egd_bytes() is a wrapper for RAND_query_egd_bytes() with buf=NULL.
85 * Unlike RAND_query_egd_bytes(), RAND_status() is used to test the
86 * seed status so that the return value can reflect the seed state:
87 * -1 if an error occured during connection or communication _or_
88 * if the PRNG has still not received the required seeding.
89 * num the number of bytes read from the EGD socket. This number is either
90 * the number of bytes requested or smaller, if the EGD pool is
91 * drained and the daemon signals that the pool is empty.
92 *
93 * RAND_egd(path) will query 255 bytes and use the bytes retreived to seed
94 * the PRNG.
95 * RAND_egd() is a wrapper for RAND_egd_bytes() with numbytes=255.
96 */
97
98#if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_MSDOS) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_VOS)
99int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
100 {
101 return(-1);
102 }
103int RAND_egd(const char *path)
104 {
105 return(-1);
106 }
107
108int RAND_egd_bytes(const char *path,int bytes)
109 {
110 return(-1);
111 }
112#else
113#include <openssl/opensslconf.h>
114#include OPENSSL_UNISTD
115#include <sys/types.h>
116#include <sys/socket.h>
117#ifndef NO_SYS_UN_H
118# ifdef OPENSSL_SYS_VXWORKS
119# include <streams/un.h>
120# else
121# include <sys/un.h>
122# endif
123#else
124struct sockaddr_un {
125 short sun_family; /* AF_UNIX */
126 char sun_path[108]; /* path name (gag) */
127};
128#endif /* NO_SYS_UN_H */
129#include <string.h>
130#include <errno.h>
131
132#ifndef offsetof
133# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
134#endif
135
136int RAND_query_egd_bytes(const char *path, unsigned char *buf, int bytes)
137 {
138 int ret = 0;
139 struct sockaddr_un addr;
140 int len, num, numbytes;
141 int fd = -1;
142 int success;
143 unsigned char egdbuf[2], tempbuf[255], *retrievebuf;
144
145 memset(&addr, 0, sizeof(addr));
146 addr.sun_family = AF_UNIX;
147 if (strlen(path) >= sizeof(addr.sun_path))
148 return (-1);
149 BUF_strlcpy(addr.sun_path,path,sizeof addr.sun_path);
150 len = offsetof(struct sockaddr_un, sun_path) + strlen(path);
151 fd = socket(AF_UNIX, SOCK_STREAM, 0);
152 if (fd == -1) return (-1);
153 success = 0;
154 while (!success)
155 {
156 if (connect(fd, (struct sockaddr *)&addr, len) == 0)
157 success = 1;
158 else
159 {
160 switch (errno)
161 {
162#ifdef EINTR
163 case EINTR:
164#endif
165#ifdef EAGAIN
166 case EAGAIN:
167#endif
168#ifdef EINPROGRESS
169 case EINPROGRESS:
170#endif
171#ifdef EALREADY
172 case EALREADY:
173#endif
174 /* No error, try again */
175 break;
176#ifdef EISCONN
177 case EISCONN:
178 success = 1;
179 break;
180#endif
181 default:
182 goto err; /* failure */
183 }
184 }
185 }
186
187 while(bytes > 0)
188 {
189 egdbuf[0] = 1;
190 egdbuf[1] = bytes < 255 ? bytes : 255;
191 numbytes = 0;
192 while (numbytes != 2)
193 {
194 num = write(fd, egdbuf + numbytes, 2 - numbytes);
195 if (num >= 0)
196 numbytes += num;
197 else
198 {
199 switch (errno)
200 {
201#ifdef EINTR
202 case EINTR:
203#endif
204#ifdef EAGAIN
205 case EAGAIN:
206#endif
207 /* No error, try again */
208 break;
209 default:
210 ret = -1;
211 goto err; /* failure */
212 }
213 }
214 }
215 numbytes = 0;
216 while (numbytes != 1)
217 {
218 num = read(fd, egdbuf, 1);
219 if (num == 0)
220 goto err; /* descriptor closed */
221 else if (num > 0)
222 numbytes += num;
223 else
224 {
225 switch (errno)
226 {
227#ifdef EINTR
228 case EINTR:
229#endif
230#ifdef EAGAIN
231 case EAGAIN:
232#endif
233 /* No error, try again */
234 break;
235 default:
236 ret = -1;
237 goto err; /* failure */
238 }
239 }
240 }
241 if(egdbuf[0] == 0)
242 goto err;
243 if (buf)
244 retrievebuf = buf + ret;
245 else
246 retrievebuf = tempbuf;
247 numbytes = 0;
248 while (numbytes != egdbuf[0])
249 {
250 num = read(fd, retrievebuf + numbytes, egdbuf[0] - numbytes);
251 if (num == 0)
252 goto err; /* descriptor closed */
253 else if (num > 0)
254 numbytes += num;
255 else
256 {
257 switch (errno)
258 {
259#ifdef EINTR
260 case EINTR:
261#endif
262#ifdef EAGAIN
263 case EAGAIN:
264#endif
265 /* No error, try again */
266 break;
267 default:
268 ret = -1;
269 goto err; /* failure */
270 }
271 }
272 }
273 ret += egdbuf[0];
274 bytes -= egdbuf[0];
275 if (!buf)
276 RAND_seed(tempbuf, egdbuf[0]);
277 }
278 err:
279 if (fd != -1) close(fd);
280 return(ret);
281 }
282
283
284int RAND_egd_bytes(const char *path, int bytes)
285 {
286 int num, ret = 0;
287
288 num = RAND_query_egd_bytes(path, NULL, bytes);
289 if (num < 1) goto err;
290 if (RAND_status() == 1)
291 ret = num;
292 err:
293 return(ret);
294 }
295
296
297int RAND_egd(const char *path)
298 {
299 return (RAND_egd_bytes(path, 255));
300 }
301
302
303#endif
diff --git a/src/lib/libcrypto/rand/rand_err.c b/src/lib/libcrypto/rand/rand_err.c
index 386934dcd1..97f96e1aee 100644
--- a/src/lib/libcrypto/rand/rand_err.c
+++ b/src/lib/libcrypto/rand/rand_err.c
@@ -70,6 +70,7 @@
70 70
71static ERR_STRING_DATA RAND_str_functs[]= 71static ERR_STRING_DATA RAND_str_functs[]=
72 { 72 {
73{ERR_FUNC(RAND_F_FIPS_RAND_BYTES), "FIPS_RAND_BYTES"},
73{ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"}, 74{ERR_FUNC(RAND_F_RAND_GET_RAND_METHOD), "RAND_get_rand_method"},
74{ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"}, 75{ERR_FUNC(RAND_F_SSLEAY_RAND_BYTES), "SSLEAY_RAND_BYTES"},
75{0,NULL} 76{0,NULL}
@@ -77,7 +78,12 @@ static ERR_STRING_DATA RAND_str_functs[]=
77 78
78static ERR_STRING_DATA RAND_str_reasons[]= 79static ERR_STRING_DATA RAND_str_reasons[]=
79 { 80 {
81{ERR_REASON(RAND_R_NON_FIPS_METHOD) ,"non fips method"},
82{ERR_REASON(RAND_R_PRNG_ASKING_FOR_TOO_MUCH),"prng asking for too much"},
83{ERR_REASON(RAND_R_PRNG_NOT_REKEYED) ,"prng not rekeyed"},
84{ERR_REASON(RAND_R_PRNG_NOT_RESEEDED) ,"prng not reseeded"},
80{ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"}, 85{ERR_REASON(RAND_R_PRNG_NOT_SEEDED) ,"PRNG not seeded"},
86{ERR_REASON(RAND_R_PRNG_STUCK) ,"prng stuck"},
81{0,NULL} 87{0,NULL}
82 }; 88 };
83 89
@@ -85,12 +91,15 @@ static ERR_STRING_DATA RAND_str_reasons[]=
85 91
86void ERR_load_RAND_strings(void) 92void ERR_load_RAND_strings(void)
87 { 93 {
88#ifndef OPENSSL_NO_ERR 94 static int init=1;
89 95
90 if (ERR_func_error_string(RAND_str_functs[0].error) == NULL) 96 if (init)
91 { 97 {
98 init=0;
99#ifndef OPENSSL_NO_ERR
92 ERR_load_strings(0,RAND_str_functs); 100 ERR_load_strings(0,RAND_str_functs);
93 ERR_load_strings(0,RAND_str_reasons); 101 ERR_load_strings(0,RAND_str_reasons);
94 }
95#endif 102#endif
103
104 }
96 } 105 }
diff --git a/src/lib/libcrypto/rand/rand_lcl.h b/src/lib/libcrypto/rand/rand_lcl.h
new file mode 100644
index 0000000000..618a8ec899
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_lcl.h
@@ -0,0 +1,158 @@
1/* crypto/rand/rand_lcl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#ifndef HEADER_RAND_LCL_H
113#define HEADER_RAND_LCL_H
114
115#define ENTROPY_NEEDED 32 /* require 256 bits = 32 bytes of randomness */
116
117
118#if !defined(USE_MD5_RAND) && !defined(USE_SHA1_RAND) && !defined(USE_MDC2_RAND) && !defined(USE_MD2_RAND)
119#if !defined(OPENSSL_NO_SHA) && !defined(OPENSSL_NO_SHA1)
120#define USE_SHA1_RAND
121#elif !defined(OPENSSL_NO_MD5)
122#define USE_MD5_RAND
123#elif !defined(OPENSSL_NO_MDC2) && !defined(OPENSSL_NO_DES)
124#define USE_MDC2_RAND
125#elif !defined(OPENSSL_NO_MD2)
126#define USE_MD2_RAND
127#else
128#error No message digest algorithm available
129#endif
130#endif
131
132#include <openssl/evp.h>
133#define MD_Update(a,b,c) EVP_DigestUpdate(a,b,c)
134#define MD_Final(a,b) EVP_DigestFinal_ex(a,b,NULL)
135#if defined(USE_MD5_RAND)
136#include <openssl/md5.h>
137#define MD_DIGEST_LENGTH MD5_DIGEST_LENGTH
138#define MD_Init(a) EVP_DigestInit_ex(a,EVP_md5(), NULL)
139#define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_md5(), NULL)
140#elif defined(USE_SHA1_RAND)
141#include <openssl/sha.h>
142#define MD_DIGEST_LENGTH SHA_DIGEST_LENGTH
143#define MD_Init(a) EVP_DigestInit_ex(a,EVP_sha1(), NULL)
144#define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_sha1(), NULL)
145#elif defined(USE_MDC2_RAND)
146#include <openssl/mdc2.h>
147#define MD_DIGEST_LENGTH MDC2_DIGEST_LENGTH
148#define MD_Init(a) EVP_DigestInit_ex(a,EVP_mdc2(), NULL)
149#define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_mdc2(), NULL)
150#elif defined(USE_MD2_RAND)
151#include <openssl/md2.h>
152#define MD_DIGEST_LENGTH MD2_DIGEST_LENGTH
153#define MD_Init(a) EVP_DigestInit_ex(a,EVP_md2(), NULL)
154#define MD(a,b,c) EVP_Digest(a,b,c,NULL,EVP_md2(), NULL)
155#endif
156
157
158#endif
diff --git a/src/lib/libcrypto/rand/rand_lib.c b/src/lib/libcrypto/rand/rand_lib.c
index 513e338985..a21bde79de 100644
--- a/src/lib/libcrypto/rand/rand_lib.c
+++ b/src/lib/libcrypto/rand/rand_lib.c
@@ -63,6 +63,8 @@
63#ifndef OPENSSL_NO_ENGINE 63#ifndef OPENSSL_NO_ENGINE
64#include <openssl/engine.h> 64#include <openssl/engine.h>
65#endif 65#endif
66#include <openssl/fips.h>
67#include <openssl/fips_rand.h>
66 68
67#ifndef OPENSSL_NO_ENGINE 69#ifndef OPENSSL_NO_ENGINE
68/* non-NULL if default_RAND_meth is ENGINE-provided */ 70/* non-NULL if default_RAND_meth is ENGINE-provided */
@@ -102,8 +104,22 @@ const RAND_METHOD *RAND_get_rand_method(void)
102 funct_ref = e; 104 funct_ref = e;
103 else 105 else
104#endif 106#endif
105 default_RAND_meth = RAND_SSLeay(); 107#ifdef OPENSSL_FIPS
108 if(FIPS_mode())
109 default_RAND_meth=FIPS_rand_method();
110 else
111#endif
112 default_RAND_meth = RAND_SSLeay();
106 } 113 }
114
115#ifdef OPENSSL_FIPS
116 if(FIPS_mode()
117 && default_RAND_meth != FIPS_rand_check())
118 {
119 RANDerr(RAND_F_RAND_GET_RAND_METHOD,RAND_R_NON_FIPS_METHOD);
120 return 0;
121 }
122#endif
107 return default_RAND_meth; 123 return default_RAND_meth;
108 } 124 }
109 125
diff --git a/src/lib/libcrypto/rand/rand_nw.c b/src/lib/libcrypto/rand/rand_nw.c
new file mode 100644
index 0000000000..f177ffbe82
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_nw.c
@@ -0,0 +1,183 @@
1/* crypto/rand/rand_nw.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if defined (OPENSSL_SYS_NETWARE)
117
118#if defined(NETWARE_LIBC)
119#include <nks/thread.h>
120#else
121#include <nwthread.h>
122#endif
123
124extern int GetProcessSwitchCount(void);
125#if !defined(NETWARE_LIBC) || (CURRENT_NDK_THRESHOLD < 509220000)
126extern void *RunningProcess; /* declare here same as found in newer NDKs */
127extern unsigned long GetSuperHighResolutionTimer(void);
128#endif
129
130 /* the FAQ indicates we need to provide at least 20 bytes (160 bits) of seed
131 */
132int RAND_poll(void)
133{
134 unsigned long l;
135 unsigned long tsc;
136 int i;
137
138 /* There are several options to gather miscellaneous data
139 * but for now we will loop checking the time stamp counter (rdtsc) and
140 * the SuperHighResolutionTimer. Each iteration will collect 8 bytes
141 * of data but it is treated as only 1 byte of entropy. The call to
142 * ThreadSwitchWithDelay() will introduce additional variability into
143 * the data returned by rdtsc.
144 *
145 * Applications can agument the seed material by adding additional
146 * stuff with RAND_add() and should probably do so.
147 */
148 l = GetProcessSwitchCount();
149 RAND_add(&l,sizeof(l),1);
150
151 /* need to cast the void* to unsigned long here */
152 l = (unsigned long)RunningProcess;
153 RAND_add(&l,sizeof(l),1);
154
155 for( i=2; i<ENTROPY_NEEDED; i++)
156 {
157#ifdef __MWERKS__
158 asm
159 {
160 rdtsc
161 mov tsc, eax
162 }
163#else
164 asm volatile("rdtsc":"=A" (tsc));
165#endif
166
167 RAND_add(&tsc, sizeof(tsc), 1);
168
169 l = GetSuperHighResolutionTimer();
170 RAND_add(&l, sizeof(l), 0);
171
172# if defined(NETWARE_LIBC)
173 NXThreadYield();
174# else /* NETWARE_CLIB */
175 ThreadSwitchWithDelay();
176# endif
177 }
178
179 return 1;
180}
181
182#endif
183
diff --git a/src/lib/libcrypto/rand/rand_os2.c b/src/lib/libcrypto/rand/rand_os2.c
new file mode 100644
index 0000000000..c3e36d4e5e
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_os2.c
@@ -0,0 +1,147 @@
1/* crypto/rand/rand_os2.c */
2/* ====================================================================
3 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include "cryptlib.h"
57#include <openssl/rand.h>
58#include "rand_lcl.h"
59
60#ifdef OPENSSL_SYS_OS2
61
62#define INCL_DOSPROCESS
63#define INCL_DOSPROFILE
64#define INCL_DOSMISC
65#define INCL_DOSMODULEMGR
66#include <os2.h>
67
68#define CMD_KI_RDCNT (0x63)
69
70typedef struct _CPUUTIL {
71 ULONG ulTimeLow; /* Low 32 bits of time stamp */
72 ULONG ulTimeHigh; /* High 32 bits of time stamp */
73 ULONG ulIdleLow; /* Low 32 bits of idle time */
74 ULONG ulIdleHigh; /* High 32 bits of idle time */
75 ULONG ulBusyLow; /* Low 32 bits of busy time */
76 ULONG ulBusyHigh; /* High 32 bits of busy time */
77 ULONG ulIntrLow; /* Low 32 bits of interrupt time */
78 ULONG ulIntrHigh; /* High 32 bits of interrupt time */
79} CPUUTIL;
80
81APIRET APIENTRY(*DosPerfSysCall) (ULONG ulCommand, ULONG ulParm1, ULONG ulParm2, ULONG ulParm3) = NULL;
82APIRET APIENTRY(*DosQuerySysState) (ULONG func, ULONG arg1, ULONG pid, ULONG _res_, PVOID buf, ULONG bufsz) = NULL;
83HMODULE hDoscalls = 0;
84
85int RAND_poll(void)
86{
87 char failed_module[20];
88 QWORD qwTime;
89 ULONG SysVars[QSV_FOREGROUND_PROCESS];
90
91 if (hDoscalls == 0) {
92 ULONG rc = DosLoadModule(failed_module, sizeof(failed_module), "DOSCALLS", &hDoscalls);
93
94 if (rc == 0) {
95 rc = DosQueryProcAddr(hDoscalls, 976, NULL, (PFN *)&DosPerfSysCall);
96
97 if (rc)
98 DosPerfSysCall = NULL;
99
100 rc = DosQueryProcAddr(hDoscalls, 368, NULL, (PFN *)&DosQuerySysState);
101
102 if (rc)
103 DosQuerySysState = NULL;
104 }
105 }
106
107 /* Sample the hi-res timer, runs at around 1.1 MHz */
108 DosTmrQueryTime(&qwTime);
109 RAND_add(&qwTime, sizeof(qwTime), 2);
110
111 /* Sample a bunch of system variables, includes various process & memory statistics */
112 DosQuerySysInfo(1, QSV_FOREGROUND_PROCESS, SysVars, sizeof(SysVars));
113 RAND_add(SysVars, sizeof(SysVars), 4);
114
115 /* If available, sample CPU registers that count at CPU MHz
116 * Only fairly new CPUs (PPro & K6 onwards) & OS/2 versions support this
117 */
118 if (DosPerfSysCall) {
119 CPUUTIL util;
120
121 if (DosPerfSysCall(CMD_KI_RDCNT, (ULONG)&util, 0, 0) == 0) {
122 RAND_add(&util, sizeof(util), 10);
123 }
124 else {
125 DosPerfSysCall = NULL;
126 }
127 }
128
129 /* DosQuerySysState() gives us a huge quantity of process, thread, memory & handle stats */
130 if (DosQuerySysState) {
131 char *buffer = OPENSSL_malloc(256 * 1024);
132
133 if (DosQuerySysState(0x1F, 0, 0, 0, buffer, 256 * 1024) == 0) {
134 /* First 4 bytes in buffer is a pointer to the thread count
135 * there should be at least 1 byte of entropy per thread
136 */
137 RAND_add(buffer, 256 * 1024, **(ULONG **)buffer);
138 }
139
140 OPENSSL_free(buffer);
141 return 1;
142 }
143
144 return 0;
145}
146
147#endif /* OPENSSL_SYS_OS2 */
diff --git a/src/lib/libcrypto/rand/rand_unix.c b/src/lib/libcrypto/rand/rand_unix.c
new file mode 100644
index 0000000000..9376554fae
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_unix.c
@@ -0,0 +1,281 @@
1/* crypto/rand/rand_unix.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#define USE_SOCKETS
113#include "e_os.h"
114#include "cryptlib.h"
115#include <openssl/rand.h>
116#include "rand_lcl.h"
117
118#if !(defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2) || defined(OPENSSL_SYS_VXWORKS))
119
120#include <sys/types.h>
121#include <sys/time.h>
122#include <sys/times.h>
123#include <sys/stat.h>
124#include <fcntl.h>
125#include <unistd.h>
126#include <time.h>
127
128#ifdef __OpenBSD__
129int RAND_poll(void)
130{
131 u_int32_t rnd = 0, i;
132 unsigned char buf[ENTROPY_NEEDED];
133
134 for (i = 0; i < sizeof(buf); i++) {
135 if (i % 4 == 0)
136 rnd = arc4random();
137 buf[i] = rnd;
138 rnd >>= 8;
139 }
140 RAND_add(buf, sizeof(buf), ENTROPY_NEEDED);
141 memset(buf, 0, sizeof(buf));
142
143 return 1;
144}
145#else
146int RAND_poll(void)
147{
148 unsigned long l;
149 pid_t curr_pid = getpid();
150#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
151 unsigned char tmpbuf[ENTROPY_NEEDED];
152 int n = 0;
153#endif
154#ifdef DEVRANDOM
155 static const char *randomfiles[] = { DEVRANDOM };
156 struct stat randomstats[sizeof(randomfiles)/sizeof(randomfiles[0])];
157 int fd,i;
158#endif
159#ifdef DEVRANDOM_EGD
160 static const char *egdsockets[] = { DEVRANDOM_EGD, NULL };
161 const char **egdsocket = NULL;
162#endif
163
164#ifdef DEVRANDOM
165 memset(randomstats,0,sizeof(randomstats));
166 /* Use a random entropy pool device. Linux, FreeBSD and OpenBSD
167 * have this. Use /dev/urandom if you can as /dev/random may block
168 * if it runs out of random entries. */
169
170 for (i=0; i<sizeof(randomfiles)/sizeof(randomfiles[0]) && n < ENTROPY_NEEDED; i++)
171 {
172 if ((fd = open(randomfiles[i], O_RDONLY
173#ifdef O_NONBLOCK
174 |O_NONBLOCK
175#endif
176#ifdef O_BINARY
177 |O_BINARY
178#endif
179#ifdef O_NOCTTY /* If it happens to be a TTY (god forbid), do not make it
180 our controlling tty */
181 |O_NOCTTY
182#endif
183 )) >= 0)
184 {
185 struct timeval t = { 0, 10*1000 }; /* Spend 10ms on
186 each file. */
187 int r,j;
188 fd_set fset;
189 struct stat *st=&randomstats[i];
190
191 /* Avoid using same input... Used to be O_NOFOLLOW
192 * above, but it's not universally appropriate... */
193 if (fstat(fd,st) != 0) { close(fd); continue; }
194 for (j=0;j<i;j++)
195 {
196 if (randomstats[j].st_ino==st->st_ino &&
197 randomstats[j].st_dev==st->st_dev)
198 break;
199 }
200 if (j<i) { close(fd); continue; }
201
202 do
203 {
204 FD_ZERO(&fset);
205 FD_SET(fd, &fset);
206 r = -1;
207
208 if (select(fd+1,&fset,NULL,NULL,&t) < 0)
209 t.tv_usec=0;
210 else if (FD_ISSET(fd, &fset))
211 {
212 r=read(fd,(unsigned char *)tmpbuf+n,
213 ENTROPY_NEEDED-n);
214 if (r > 0)
215 n += r;
216 }
217
218 /* Some Unixen will update t, some
219 won't. For those who won't, give
220 up here, otherwise, we will do
221 this once again for the remaining
222 time. */
223 if (t.tv_usec == 10*1000)
224 t.tv_usec=0;
225 }
226 while ((r > 0 || (errno == EINTR || errno == EAGAIN))
227 && t.tv_usec != 0 && n < ENTROPY_NEEDED);
228
229 close(fd);
230 }
231 }
232#endif
233
234#ifdef DEVRANDOM_EGD
235 /* Use an EGD socket to read entropy from an EGD or PRNGD entropy
236 * collecting daemon. */
237
238 for (egdsocket = egdsockets; *egdsocket && n < ENTROPY_NEEDED; egdsocket++)
239 {
240 int r;
241
242 r = RAND_query_egd_bytes(*egdsocket, (unsigned char *)tmpbuf+n,
243 ENTROPY_NEEDED-n);
244 if (r > 0)
245 n += r;
246 }
247#endif
248
249#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
250 if (n > 0)
251 {
252 RAND_add(tmpbuf,sizeof tmpbuf,n);
253 OPENSSL_cleanse(tmpbuf,n);
254 }
255#endif
256
257 /* put in some default random data, we need more than just this */
258 l=curr_pid;
259 RAND_add(&l,sizeof(l),0);
260 l=getuid();
261 RAND_add(&l,sizeof(l),0);
262
263 l=time(NULL);
264 RAND_add(&l,sizeof(l),0);
265
266#if defined(DEVRANDOM) || defined(DEVRANDOM_EGD)
267 return 1;
268#else
269 return 0;
270#endif
271}
272
273#endif
274#endif
275
276#if defined(OPENSSL_SYS_VXWORKS)
277int RAND_poll(void)
278{
279 return 0;
280}
281#endif
diff --git a/src/lib/libcrypto/rand/rand_vms.c b/src/lib/libcrypto/rand/rand_vms.c
new file mode 100644
index 0000000000..1267a3acae
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_vms.c
@@ -0,0 +1,136 @@
1/* crypto/rand/rand_vms.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte <richard@levitte.org> for the OpenSSL
3 * project 2000.
4 */
5/* ====================================================================
6 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <openssl/rand.h>
60#include "rand_lcl.h"
61
62#if defined(OPENSSL_SYS_VMS)
63
64#include <descrip.h>
65#include <jpidef.h>
66#include <ssdef.h>
67#include <starlet.h>
68#ifdef __DECC
69# pragma message disable DOLLARID
70#endif
71
72static struct items_data_st
73 {
74 short length, code; /* length is amount of bytes */
75 } items_data[] =
76 { { 4, JPI$_BUFIO },
77 { 4, JPI$_CPUTIM },
78 { 4, JPI$_DIRIO },
79 { 8, JPI$_LOGINTIM },
80 { 4, JPI$_PAGEFLTS },
81 { 4, JPI$_PID },
82 { 4, JPI$_WSSIZE },
83 { 0, 0 }
84 };
85
86int RAND_poll(void)
87 {
88 long pid, iosb[2];
89 int status = 0;
90 struct
91 {
92 short length, code;
93 long *buffer;
94 int *retlen;
95 } item[32], *pitem;
96 unsigned char data_buffer[256];
97 short total_length = 0;
98 struct items_data_st *pitems_data;
99
100 pitems_data = items_data;
101 pitem = item;
102
103 /* Setup */
104 while (pitems_data->length
105 && (total_length + pitems_data->length <= 256))
106 {
107 pitem->length = pitems_data->length;
108 pitem->code = pitems_data->code;
109 pitem->buffer = (long *)&data_buffer[total_length];
110 pitem->retlen = 0;
111 total_length += pitems_data->length;
112 pitems_data++;
113 pitem++;
114 }
115 pitem->length = pitem->code = 0;
116
117 /*
118 * Scan through all the processes in the system and add entropy with
119 * results from the processes that were possible to look at.
120 * However, view the information as only half trustable.
121 */
122 pid = -1; /* search context */
123 while ((status = sys$getjpiw(0, &pid, 0, item, iosb, 0, 0))
124 != SS$_NOMOREPROC)
125 {
126 if (status == SS$_NORMAL)
127 {
128 RAND_add(data_buffer, total_length, total_length/2);
129 }
130 }
131 sys$gettim(iosb);
132 RAND_add((unsigned char *)iosb, sizeof(iosb), sizeof(iosb)/2);
133 return 1;
134}
135
136#endif
diff --git a/src/lib/libcrypto/rand/rand_win.c b/src/lib/libcrypto/rand/rand_win.c
new file mode 100644
index 0000000000..30c69161ef
--- /dev/null
+++ b/src/lib/libcrypto/rand/rand_win.c
@@ -0,0 +1,747 @@
1/* crypto/rand/rand_win.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58/* ====================================================================
59 * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved.
60 *
61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions
63 * are met:
64 *
65 * 1. Redistributions of source code must retain the above copyright
66 * notice, this list of conditions and the following disclaimer.
67 *
68 * 2. Redistributions in binary form must reproduce the above copyright
69 * notice, this list of conditions and the following disclaimer in
70 * the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3. All advertising materials mentioning features or use of this
74 * software must display the following acknowledgment:
75 * "This product includes software developed by the OpenSSL Project
76 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
77 *
78 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
79 * endorse or promote products derived from this software without
80 * prior written permission. For written permission, please contact
81 * openssl-core@openssl.org.
82 *
83 * 5. Products derived from this software may not be called "OpenSSL"
84 * nor may "OpenSSL" appear in their names without prior written
85 * permission of the OpenSSL Project.
86 *
87 * 6. Redistributions of any form whatsoever must retain the following
88 * acknowledgment:
89 * "This product includes software developed by the OpenSSL Project
90 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
91 *
92 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
93 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
94 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
95 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
96 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
97 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
98 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
99 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
100 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
101 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
102 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
103 * OF THE POSSIBILITY OF SUCH DAMAGE.
104 * ====================================================================
105 *
106 * This product includes cryptographic software written by Eric Young
107 * (eay@cryptsoft.com). This product includes software written by Tim
108 * Hudson (tjh@cryptsoft.com).
109 *
110 */
111
112#include "cryptlib.h"
113#include <openssl/rand.h>
114#include "rand_lcl.h"
115
116#if defined(OPENSSL_SYS_WINDOWS) || defined(OPENSSL_SYS_WIN32)
117#include <windows.h>
118#ifndef _WIN32_WINNT
119# define _WIN32_WINNT 0x0400
120#endif
121#include <wincrypt.h>
122#include <tlhelp32.h>
123
124/* Intel hardware RNG CSP -- available from
125 * http://developer.intel.com/design/security/rng/redist_license.htm
126 */
127#define PROV_INTEL_SEC 22
128#define INTEL_DEF_PROV L"Intel Hardware Cryptographic Service Provider"
129
130static void readtimer(void);
131static void readscreen(void);
132
133/* It appears like CURSORINFO, PCURSORINFO and LPCURSORINFO are only defined
134 when WINVER is 0x0500 and up, which currently only happens on Win2000.
135 Unfortunately, those are typedefs, so they're a little bit difficult to
136 detect properly. On the other hand, the macro CURSOR_SHOWING is defined
137 within the same conditional, so it can be use to detect the absence of said
138 typedefs. */
139
140#ifndef CURSOR_SHOWING
141/*
142 * Information about the global cursor.
143 */
144typedef struct tagCURSORINFO
145{
146 DWORD cbSize;
147 DWORD flags;
148 HCURSOR hCursor;
149 POINT ptScreenPos;
150} CURSORINFO, *PCURSORINFO, *LPCURSORINFO;
151
152#define CURSOR_SHOWING 0x00000001
153#endif /* CURSOR_SHOWING */
154
155typedef BOOL (WINAPI *CRYPTACQUIRECONTEXTW)(HCRYPTPROV *, LPCWSTR, LPCWSTR,
156 DWORD, DWORD);
157typedef BOOL (WINAPI *CRYPTGENRANDOM)(HCRYPTPROV, DWORD, BYTE *);
158typedef BOOL (WINAPI *CRYPTRELEASECONTEXT)(HCRYPTPROV, DWORD);
159
160typedef HWND (WINAPI *GETFOREGROUNDWINDOW)(VOID);
161typedef BOOL (WINAPI *GETCURSORINFO)(PCURSORINFO);
162typedef DWORD (WINAPI *GETQUEUESTATUS)(UINT);
163
164typedef HANDLE (WINAPI *CREATETOOLHELP32SNAPSHOT)(DWORD, DWORD);
165typedef BOOL (WINAPI *CLOSETOOLHELP32SNAPSHOT)(HANDLE);
166typedef BOOL (WINAPI *HEAP32FIRST)(LPHEAPENTRY32, DWORD, DWORD);
167typedef BOOL (WINAPI *HEAP32NEXT)(LPHEAPENTRY32);
168typedef BOOL (WINAPI *HEAP32LIST)(HANDLE, LPHEAPLIST32);
169typedef BOOL (WINAPI *PROCESS32)(HANDLE, LPPROCESSENTRY32);
170typedef BOOL (WINAPI *THREAD32)(HANDLE, LPTHREADENTRY32);
171typedef BOOL (WINAPI *MODULE32)(HANDLE, LPMODULEENTRY32);
172
173#include <lmcons.h>
174#ifndef OPENSSL_SYS_WINCE
175#include <lmstats.h>
176#endif
177#if 1 /* The NET API is Unicode only. It requires the use of the UNICODE
178 * macro. When UNICODE is defined LPTSTR becomes LPWSTR. LMSTR was
179 * was added to the Platform SDK to allow the NET API to be used in
180 * non-Unicode applications provided that Unicode strings were still
181 * used for input. LMSTR is defined as LPWSTR.
182 */
183typedef NET_API_STATUS (NET_API_FUNCTION * NETSTATGET)
184 (LPWSTR, LPWSTR, DWORD, DWORD, LPBYTE*);
185typedef NET_API_STATUS (NET_API_FUNCTION * NETFREE)(LPBYTE);
186#endif /* 1 */
187
188int RAND_poll(void)
189{
190 MEMORYSTATUS m;
191 HCRYPTPROV hProvider = 0;
192 BYTE buf[64];
193 DWORD w;
194 HWND h;
195
196 HMODULE advapi, kernel, user, netapi;
197 CRYPTACQUIRECONTEXTW acquire = 0;
198 CRYPTGENRANDOM gen = 0;
199 CRYPTRELEASECONTEXT release = 0;
200#if 1 /* There was previously a problem with NETSTATGET. Currently, this
201 * section is still experimental, but if all goes well, this conditional
202 * will be removed
203 */
204 NETSTATGET netstatget = 0;
205 NETFREE netfree = 0;
206#endif /* 1 */
207
208 /* Determine the OS version we are on so we can turn off things
209 * that do not work properly.
210 */
211 OSVERSIONINFO osverinfo ;
212 osverinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO) ;
213 GetVersionEx( &osverinfo ) ;
214
215#if defined(OPENSSL_SYS_WINCE) && WCEPLATFORM!=MS_HPC_PRO
216#ifndef CryptAcquireContext
217#define CryptAcquireContext CryptAcquireContextW
218#endif
219 /* poll the CryptoAPI PRNG */
220 /* The CryptoAPI returns sizeof(buf) bytes of randomness */
221 if (CryptAcquireContext(&hProvider, 0, 0, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT))
222 {
223 if (CryptGenRandom(hProvider, sizeof(buf), buf))
224 RAND_add(buf, sizeof(buf), sizeof(buf));
225 CryptReleaseContext(hProvider, 0);
226 }
227#endif
228
229#ifndef OPENSSL_SYS_WINCE
230 /*
231 * None of below libraries are present on Windows CE, which is
232 * why we #ifndef the whole section. This also excuses us from
233 * handling the GetProcAddress issue. The trouble is that in
234 * real Win32 API GetProcAddress is available in ANSI flavor
235 * only. In WinCE on the other hand GetProcAddress is a macro
236 * most commonly defined as GetProcAddressW, which accepts
237 * Unicode argument. If we were to call GetProcAddress under
238 * WinCE, I'd recommend to either redefine GetProcAddress as
239 * GetProcAddressA (there seem to be one in common CE spec) or
240 * implement own shim routine, which would accept ANSI argument
241 * and expand it to Unicode.
242 */
243
244 /* load functions dynamically - not available on all systems */
245 advapi = LoadLibrary(TEXT("ADVAPI32.DLL"));
246 kernel = LoadLibrary(TEXT("KERNEL32.DLL"));
247 user = LoadLibrary(TEXT("USER32.DLL"));
248 netapi = LoadLibrary(TEXT("NETAPI32.DLL"));
249
250#if 1 /* There was previously a problem with NETSTATGET. Currently, this
251 * section is still experimental, but if all goes well, this conditional
252 * will be removed
253 */
254 if (netapi)
255 {
256 netstatget = (NETSTATGET) GetProcAddress(netapi,"NetStatisticsGet");
257 netfree = (NETFREE) GetProcAddress(netapi,"NetApiBufferFree");
258 }
259
260 if (netstatget && netfree)
261 {
262 LPBYTE outbuf;
263 /* NetStatisticsGet() is a Unicode only function
264 * STAT_WORKSTATION_0 contains 45 fields and STAT_SERVER_0
265 * contains 17 fields. We treat each field as a source of
266 * one byte of entropy.
267 */
268
269 if (netstatget(NULL, L"LanmanWorkstation", 0, 0, &outbuf) == 0)
270 {
271 RAND_add(outbuf, sizeof(STAT_WORKSTATION_0), 45);
272 netfree(outbuf);
273 }
274 if (netstatget(NULL, L"LanmanServer", 0, 0, &outbuf) == 0)
275 {
276 RAND_add(outbuf, sizeof(STAT_SERVER_0), 17);
277 netfree(outbuf);
278 }
279 }
280
281 if (netapi)
282 FreeLibrary(netapi);
283#endif /* 1 */
284
285 /* It appears like this can cause an exception deep within ADVAPI32.DLL
286 * at random times on Windows 2000. Reported by Jeffrey Altman.
287 * Only use it on NT.
288 */
289 /* Wolfgang Marczy <WMarczy@topcall.co.at> reports that
290 * the RegQueryValueEx call below can hang on NT4.0 (SP6).
291 * So we don't use this at all for now. */
292#if 0
293 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
294 osverinfo.dwMajorVersion < 5)
295 {
296 /* Read Performance Statistics from NT/2000 registry
297 * The size of the performance data can vary from call
298 * to call so we must guess the size of the buffer to use
299 * and increase its size if we get an ERROR_MORE_DATA
300 * return instead of ERROR_SUCCESS.
301 */
302 LONG rc=ERROR_MORE_DATA;
303 char * buf=NULL;
304 DWORD bufsz=0;
305 DWORD length;
306
307 while (rc == ERROR_MORE_DATA)
308 {
309 buf = realloc(buf,bufsz+8192);
310 if (!buf)
311 break;
312 bufsz += 8192;
313
314 length = bufsz;
315 rc = RegQueryValueEx(HKEY_PERFORMANCE_DATA, TEXT("Global"),
316 NULL, NULL, buf, &length);
317 }
318 if (rc == ERROR_SUCCESS)
319 {
320 /* For entropy count assume only least significant
321 * byte of each DWORD is random.
322 */
323 RAND_add(&length, sizeof(length), 0);
324 RAND_add(buf, length, length / 4.0);
325
326 /* Close the Registry Key to allow Windows to cleanup/close
327 * the open handle
328 * Note: The 'HKEY_PERFORMANCE_DATA' key is implicitly opened
329 * when the RegQueryValueEx above is done. However, if
330 * it is not explicitly closed, it can cause disk
331 * partition manipulation problems.
332 */
333 RegCloseKey(HKEY_PERFORMANCE_DATA);
334 }
335 if (buf)
336 free(buf);
337 }
338#endif
339
340 if (advapi)
341 {
342 /*
343 * If it's available, then it's available in both ANSI
344 * and UNICODE flavors even in Win9x, documentation says.
345 * We favor Unicode...
346 */
347 acquire = (CRYPTACQUIRECONTEXTW) GetProcAddress(advapi,
348 "CryptAcquireContextW");
349 gen = (CRYPTGENRANDOM) GetProcAddress(advapi,
350 "CryptGenRandom");
351 release = (CRYPTRELEASECONTEXT) GetProcAddress(advapi,
352 "CryptReleaseContext");
353 }
354
355 if (acquire && gen && release)
356 {
357 /* poll the CryptoAPI PRNG */
358 /* The CryptoAPI returns sizeof(buf) bytes of randomness */
359 if (acquire(&hProvider, 0, 0, PROV_RSA_FULL,
360 CRYPT_VERIFYCONTEXT))
361 {
362 if (gen(hProvider, sizeof(buf), buf) != 0)
363 {
364 RAND_add(buf, sizeof(buf), 0);
365#if 0
366 printf("randomness from PROV_RSA_FULL\n");
367#endif
368 }
369 release(hProvider, 0);
370 }
371
372 /* poll the Pentium PRG with CryptoAPI */
373 if (acquire(&hProvider, 0, INTEL_DEF_PROV, PROV_INTEL_SEC, 0))
374 {
375 if (gen(hProvider, sizeof(buf), buf) != 0)
376 {
377 RAND_add(buf, sizeof(buf), sizeof(buf));
378#if 0
379 printf("randomness from PROV_INTEL_SEC\n");
380#endif
381 }
382 release(hProvider, 0);
383 }
384 }
385
386 if (advapi)
387 FreeLibrary(advapi);
388
389 if (user)
390 {
391 GETCURSORINFO cursor;
392 GETFOREGROUNDWINDOW win;
393 GETQUEUESTATUS queue;
394
395 win = (GETFOREGROUNDWINDOW) GetProcAddress(user, "GetForegroundWindow");
396 cursor = (GETCURSORINFO) GetProcAddress(user, "GetCursorInfo");
397 queue = (GETQUEUESTATUS) GetProcAddress(user, "GetQueueStatus");
398
399 if (win)
400 {
401 /* window handle */
402 h = win();
403 RAND_add(&h, sizeof(h), 0);
404 }
405 if (cursor)
406 {
407 /* unfortunately, its not safe to call GetCursorInfo()
408 * on NT4 even though it exists in SP3 (or SP6) and
409 * higher.
410 */
411 if ( osverinfo.dwPlatformId == VER_PLATFORM_WIN32_NT &&
412 osverinfo.dwMajorVersion < 5)
413 cursor = 0;
414 }
415 if (cursor)
416 {
417 /* cursor position */
418 /* assume 2 bytes of entropy */
419 CURSORINFO ci;
420 ci.cbSize = sizeof(CURSORINFO);
421 if (cursor(&ci))
422 RAND_add(&ci, ci.cbSize, 2);
423 }
424
425 if (queue)
426 {
427 /* message queue status */
428 /* assume 1 byte of entropy */
429 w = queue(QS_ALLEVENTS);
430 RAND_add(&w, sizeof(w), 1);
431 }
432
433 FreeLibrary(user);
434 }
435
436 /* Toolhelp32 snapshot: enumerate processes, threads, modules and heap
437 * http://msdn.microsoft.com/library/psdk/winbase/toolhelp_5pfd.htm
438 * (Win 9x and 2000 only, not available on NT)
439 *
440 * This seeding method was proposed in Peter Gutmann, Software
441 * Generation of Practically Strong Random Numbers,
442 * http://www.usenix.org/publications/library/proceedings/sec98/gutmann.html
443 * revised version at http://www.cryptoengines.com/~peter/06_random.pdf
444 * (The assignment of entropy estimates below is arbitrary, but based
445 * on Peter's analysis the full poll appears to be safe. Additional
446 * interactive seeding is encouraged.)
447 */
448
449 if (kernel)
450 {
451 CREATETOOLHELP32SNAPSHOT snap;
452 CLOSETOOLHELP32SNAPSHOT close_snap;
453 HANDLE handle;
454
455 HEAP32FIRST heap_first;
456 HEAP32NEXT heap_next;
457 HEAP32LIST heaplist_first, heaplist_next;
458 PROCESS32 process_first, process_next;
459 THREAD32 thread_first, thread_next;
460 MODULE32 module_first, module_next;
461
462 HEAPLIST32 hlist;
463 HEAPENTRY32 hentry;
464 PROCESSENTRY32 p;
465 THREADENTRY32 t;
466 MODULEENTRY32 m;
467
468 snap = (CREATETOOLHELP32SNAPSHOT)
469 GetProcAddress(kernel, "CreateToolhelp32Snapshot");
470 close_snap = (CLOSETOOLHELP32SNAPSHOT)
471 GetProcAddress(kernel, "CloseToolhelp32Snapshot");
472 heap_first = (HEAP32FIRST) GetProcAddress(kernel, "Heap32First");
473 heap_next = (HEAP32NEXT) GetProcAddress(kernel, "Heap32Next");
474 heaplist_first = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListFirst");
475 heaplist_next = (HEAP32LIST) GetProcAddress(kernel, "Heap32ListNext");
476 process_first = (PROCESS32) GetProcAddress(kernel, "Process32First");
477 process_next = (PROCESS32) GetProcAddress(kernel, "Process32Next");
478 thread_first = (THREAD32) GetProcAddress(kernel, "Thread32First");
479 thread_next = (THREAD32) GetProcAddress(kernel, "Thread32Next");
480 module_first = (MODULE32) GetProcAddress(kernel, "Module32First");
481 module_next = (MODULE32) GetProcAddress(kernel, "Module32Next");
482
483 if (snap && heap_first && heap_next && heaplist_first &&
484 heaplist_next && process_first && process_next &&
485 thread_first && thread_next && module_first &&
486 module_next && (handle = snap(TH32CS_SNAPALL,0))
487 != INVALID_HANDLE_VALUE)
488 {
489 /* heap list and heap walking */
490 /* HEAPLIST32 contains 3 fields that will change with
491 * each entry. Consider each field a source of 1 byte
492 * of entropy.
493 * HEAPENTRY32 contains 5 fields that will change with
494 * each entry. Consider each field a source of 1 byte
495 * of entropy.
496 */
497 hlist.dwSize = sizeof(HEAPLIST32);
498 if (heaplist_first(handle, &hlist))
499 do
500 {
501 RAND_add(&hlist, hlist.dwSize, 3);
502 hentry.dwSize = sizeof(HEAPENTRY32);
503 if (heap_first(&hentry,
504 hlist.th32ProcessID,
505 hlist.th32HeapID))
506 {
507 int entrycnt = 80;
508 do
509 RAND_add(&hentry,
510 hentry.dwSize, 5);
511 while (heap_next(&hentry)
512 && --entrycnt > 0);
513 }
514 } while (heaplist_next(handle,
515 &hlist));
516
517 /* process walking */
518 /* PROCESSENTRY32 contains 9 fields that will change
519 * with each entry. Consider each field a source of
520 * 1 byte of entropy.
521 */
522 p.dwSize = sizeof(PROCESSENTRY32);
523 if (process_first(handle, &p))
524 do
525 RAND_add(&p, p.dwSize, 9);
526 while (process_next(handle, &p));
527
528 /* thread walking */
529 /* THREADENTRY32 contains 6 fields that will change
530 * with each entry. Consider each field a source of
531 * 1 byte of entropy.
532 */
533 t.dwSize = sizeof(THREADENTRY32);
534 if (thread_first(handle, &t))
535 do
536 RAND_add(&t, t.dwSize, 6);
537 while (thread_next(handle, &t));
538
539 /* module walking */
540 /* MODULEENTRY32 contains 9 fields that will change
541 * with each entry. Consider each field a source of
542 * 1 byte of entropy.
543 */
544 m.dwSize = sizeof(MODULEENTRY32);
545 if (module_first(handle, &m))
546 do
547 RAND_add(&m, m.dwSize, 9);
548 while (module_next(handle, &m));
549 if (close_snap)
550 close_snap(handle);
551 else
552 CloseHandle(handle);
553 }
554
555 FreeLibrary(kernel);
556 }
557#endif /* !OPENSSL_SYS_WINCE */
558
559 /* timer data */
560 readtimer();
561
562 /* memory usage statistics */
563 GlobalMemoryStatus(&m);
564 RAND_add(&m, sizeof(m), 1);
565
566 /* process ID */
567 w = GetCurrentProcessId();
568 RAND_add(&w, sizeof(w), 1);
569
570#if 0
571 printf("Exiting RAND_poll\n");
572#endif
573
574 return(1);
575}
576
577int RAND_event(UINT iMsg, WPARAM wParam, LPARAM lParam)
578 {
579 double add_entropy=0;
580
581 switch (iMsg)
582 {
583 case WM_KEYDOWN:
584 {
585 static WPARAM key;
586 if (key != wParam)
587 add_entropy = 0.05;
588 key = wParam;
589 }
590 break;
591 case WM_MOUSEMOVE:
592 {
593 static int lastx,lasty,lastdx,lastdy;
594 int x,y,dx,dy;
595
596 x=LOWORD(lParam);
597 y=HIWORD(lParam);
598 dx=lastx-x;
599 dy=lasty-y;
600 if (dx != 0 && dy != 0 && dx-lastdx != 0 && dy-lastdy != 0)
601 add_entropy=.2;
602 lastx=x, lasty=y;
603 lastdx=dx, lastdy=dy;
604 }
605 break;
606 }
607
608 readtimer();
609 RAND_add(&iMsg, sizeof(iMsg), add_entropy);
610 RAND_add(&wParam, sizeof(wParam), 0);
611 RAND_add(&lParam, sizeof(lParam), 0);
612
613 return (RAND_status());
614 }
615
616
617void RAND_screen(void) /* function available for backward compatibility */
618{
619 RAND_poll();
620 readscreen();
621}
622
623
624/* feed timing information to the PRNG */
625static void readtimer(void)
626{
627 DWORD w;
628 LARGE_INTEGER l;
629 static int have_perfc = 1;
630#if defined(_MSC_VER) && defined(_M_X86)
631 static int have_tsc = 1;
632 DWORD cyclecount;
633
634 if (have_tsc) {
635 __try {
636 __asm {
637 _emit 0x0f
638 _emit 0x31
639 mov cyclecount, eax
640 }
641 RAND_add(&cyclecount, sizeof(cyclecount), 1);
642 } __except(EXCEPTION_EXECUTE_HANDLER) {
643 have_tsc = 0;
644 }
645 }
646#else
647# define have_tsc 0
648#endif
649
650 if (have_perfc) {
651 if (QueryPerformanceCounter(&l) == 0)
652 have_perfc = 0;
653 else
654 RAND_add(&l, sizeof(l), 0);
655 }
656
657 if (!have_tsc && !have_perfc) {
658 w = GetTickCount();
659 RAND_add(&w, sizeof(w), 0);
660 }
661}
662
663/* feed screen contents to PRNG */
664/*****************************************************************************
665 *
666 * Created 960901 by Gertjan van Oosten, gertjan@West.NL, West Consulting B.V.
667 *
668 * Code adapted from
669 * <URL:http://support.microsoft.com/default.aspx?scid=kb;[LN];97193>;
670 * the original copyright message is:
671 *
672 * (C) Copyright Microsoft Corp. 1993. All rights reserved.
673 *
674 * You have a royalty-free right to use, modify, reproduce and
675 * distribute the Sample Files (and/or any modified version) in
676 * any way you find useful, provided that you agree that
677 * Microsoft has no warranty obligations or liability for any
678 * Sample Application Files which are modified.
679 */
680
681static void readscreen(void)
682{
683#if !defined(OPENSSL_SYS_WINCE) && !defined(OPENSSL_SYS_WIN32_CYGWIN)
684 HDC hScrDC; /* screen DC */
685 HDC hMemDC; /* memory DC */
686 HBITMAP hBitmap; /* handle for our bitmap */
687 HBITMAP hOldBitmap; /* handle for previous bitmap */
688 BITMAP bm; /* bitmap properties */
689 unsigned int size; /* size of bitmap */
690 char *bmbits; /* contents of bitmap */
691 int w; /* screen width */
692 int h; /* screen height */
693 int y; /* y-coordinate of screen lines to grab */
694 int n = 16; /* number of screen lines to grab at a time */
695
696 /* Create a screen DC and a memory DC compatible to screen DC */
697 hScrDC = CreateDC(TEXT("DISPLAY"), NULL, NULL, NULL);
698 hMemDC = CreateCompatibleDC(hScrDC);
699
700 /* Get screen resolution */
701 w = GetDeviceCaps(hScrDC, HORZRES);
702 h = GetDeviceCaps(hScrDC, VERTRES);
703
704 /* Create a bitmap compatible with the screen DC */
705 hBitmap = CreateCompatibleBitmap(hScrDC, w, n);
706
707 /* Select new bitmap into memory DC */
708 hOldBitmap = SelectObject(hMemDC, hBitmap);
709
710 /* Get bitmap properties */
711 GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm);
712 size = (unsigned int)bm.bmWidthBytes * bm.bmHeight * bm.bmPlanes;
713
714 bmbits = OPENSSL_malloc(size);
715 if (bmbits) {
716 /* Now go through the whole screen, repeatedly grabbing n lines */
717 for (y = 0; y < h-n; y += n)
718 {
719 unsigned char md[MD_DIGEST_LENGTH];
720
721 /* Bitblt screen DC to memory DC */
722 BitBlt(hMemDC, 0, 0, w, n, hScrDC, 0, y, SRCCOPY);
723
724 /* Copy bitmap bits from memory DC to bmbits */
725 GetBitmapBits(hBitmap, size, bmbits);
726
727 /* Get the hash of the bitmap */
728 MD(bmbits,size,md);
729
730 /* Seed the random generator with the hash value */
731 RAND_add(md, MD_DIGEST_LENGTH, 0);
732 }
733
734 OPENSSL_free(bmbits);
735 }
736
737 /* Select old bitmap back into memory DC */
738 hBitmap = SelectObject(hMemDC, hOldBitmap);
739
740 /* Clean up */
741 DeleteObject(hBitmap);
742 DeleteDC(hMemDC);
743 DeleteDC(hScrDC);
744#endif /* !OPENSSL_SYS_WINCE */
745}
746
747#endif
diff --git a/src/lib/libcrypto/rand/randfile.c b/src/lib/libcrypto/rand/randfile.c
index 6c0ec9a41c..d847d8ebdf 100644
--- a/src/lib/libcrypto/rand/randfile.c
+++ b/src/lib/libcrypto/rand/randfile.c
@@ -102,8 +102,10 @@ int RAND_load_file(const char *file, long bytes)
102 102
103 if (file == NULL) return(0); 103 if (file == NULL) return(0);
104 104
105 if (stat(file,&sb) < 0) return(0); 105 i=stat(file,&sb);
106 RAND_add(&sb,sizeof(sb),0.0); 106 /* If the state fails, put some crap in anyway */
107 RAND_add(&sb,sizeof(sb),0);
108 if (i < 0) return(0);
107 if (bytes == 0) return(ret); 109 if (bytes == 0) return(ret);
108 110
109 in=fopen(file,"rb"); 111 in=fopen(file,"rb");
@@ -126,12 +128,8 @@ int RAND_load_file(const char *file, long bytes)
126 n = BUFSIZE; 128 n = BUFSIZE;
127 i=fread(buf,1,n,in); 129 i=fread(buf,1,n,in);
128 if (i <= 0) break; 130 if (i <= 0) break;
129#ifdef PURIFY
130 RAND_add(buf,i,(double)i);
131#else
132 /* even if n != i, use the full array */ 131 /* even if n != i, use the full array */
133 RAND_add(buf,n,(double)i); 132 RAND_add(buf,n,i);
134#endif
135 ret+=i; 133 ret+=i;
136 if (bytes > 0) 134 if (bytes > 0)
137 { 135 {
@@ -235,7 +233,7 @@ const char *RAND_file_name(char *buf, size_t size)
235 struct stat sb; 233 struct stat sb;
236#endif 234#endif
237 235
238 if (OPENSSL_issetugid() == 0) 236 if (issetugid() == 0)
239 s=getenv("RANDFILE"); 237 s=getenv("RANDFILE");
240 if (s != NULL && *s && strlen(s) + 1 < size) 238 if (s != NULL && *s && strlen(s) + 1 < size)
241 { 239 {
@@ -244,7 +242,7 @@ const char *RAND_file_name(char *buf, size_t size)
244 } 242 }
245 else 243 else
246 { 244 {
247 if (OPENSSL_issetugid() == 0) 245 if (issetugid() == 0)
248 s=getenv("HOME"); 246 s=getenv("HOME");
249#ifdef DEFAULT_HOME 247#ifdef DEFAULT_HOME
250 if (s == NULL) 248 if (s == NULL)
diff --git a/src/lib/libcrypto/rand/randtest.c b/src/lib/libcrypto/rand/randtest.c
new file mode 100644
index 0000000000..701932e6ee
--- /dev/null
+++ b/src/lib/libcrypto/rand/randtest.c
@@ -0,0 +1,216 @@
1/* crypto/rand/randtest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/rand.h>
62
63#include "../e_os.h"
64
65/* some FIPS 140-1 random number test */
66/* some simple tests */
67
68int main()
69 {
70 unsigned char buf[2500];
71 int i,j,k,s,sign,nsign,err=0;
72 unsigned long n1;
73 unsigned long n2[16];
74 unsigned long runs[2][34];
75 /*double d; */
76 long d;
77
78 i = RAND_pseudo_bytes(buf,2500);
79 if (i < 0)
80 {
81 printf ("init failed, the rand method is not properly installed\n");
82 err++;
83 goto err;
84 }
85
86 n1=0;
87 for (i=0; i<16; i++) n2[i]=0;
88 for (i=0; i<34; i++) runs[0][i]=runs[1][i]=0;
89
90 /* test 1 and 2 */
91 sign=0;
92 nsign=0;
93 for (i=0; i<2500; i++)
94 {
95 j=buf[i];
96
97 n2[j&0x0f]++;
98 n2[(j>>4)&0x0f]++;
99
100 for (k=0; k<8; k++)
101 {
102 s=(j&0x01);
103 if (s == sign)
104 nsign++;
105 else
106 {
107 if (nsign > 34) nsign=34;
108 if (nsign != 0)
109 {
110 runs[sign][nsign-1]++;
111 if (nsign > 6)
112 runs[sign][5]++;
113 }
114 sign=s;
115 nsign=1;
116 }
117
118 if (s) n1++;
119 j>>=1;
120 }
121 }
122 if (nsign > 34) nsign=34;
123 if (nsign != 0) runs[sign][nsign-1]++;
124
125 /* test 1 */
126 if (!((9654 < n1) && (n1 < 10346)))
127 {
128 printf("test 1 failed, X=%lu\n",n1);
129 err++;
130 }
131 printf("test 1 done\n");
132
133 /* test 2 */
134#ifdef undef
135 d=0;
136 for (i=0; i<16; i++)
137 d+=n2[i]*n2[i];
138 d=d*16.0/5000.0-5000.0;
139 if (!((1.03 < d) && (d < 57.4)))
140 {
141 printf("test 2 failed, X=%.2f\n",d);
142 err++;
143 }
144#endif
145 d=0;
146 for (i=0; i<16; i++)
147 d+=n2[i]*n2[i];
148 d=(d*8)/25-500000;
149 if (!((103 < d) && (d < 5740)))
150 {
151 printf("test 2 failed, X=%ld.%02ld\n",d/100L,d%100L);
152 err++;
153 }
154 printf("test 2 done\n");
155
156 /* test 3 */
157 for (i=0; i<2; i++)
158 {
159 if (!((2267 < runs[i][0]) && (runs[i][0] < 2733)))
160 {
161 printf("test 3 failed, bit=%d run=%d num=%lu\n",
162 i,1,runs[i][0]);
163 err++;
164 }
165 if (!((1079 < runs[i][1]) && (runs[i][1] < 1421)))
166 {
167 printf("test 3 failed, bit=%d run=%d num=%lu\n",
168 i,2,runs[i][1]);
169 err++;
170 }
171 if (!(( 502 < runs[i][2]) && (runs[i][2] < 748)))
172 {
173 printf("test 3 failed, bit=%d run=%d num=%lu\n",
174 i,3,runs[i][2]);
175 err++;
176 }
177 if (!(( 223 < runs[i][3]) && (runs[i][3] < 402)))
178 {
179 printf("test 3 failed, bit=%d run=%d num=%lu\n",
180 i,4,runs[i][3]);
181 err++;
182 }
183 if (!(( 90 < runs[i][4]) && (runs[i][4] < 223)))
184 {
185 printf("test 3 failed, bit=%d run=%d num=%lu\n",
186 i,5,runs[i][4]);
187 err++;
188 }
189 if (!(( 90 < runs[i][5]) && (runs[i][5] < 223)))
190 {
191 printf("test 3 failed, bit=%d run=%d num=%lu\n",
192 i,6,runs[i][5]);
193 err++;
194 }
195 }
196 printf("test 3 done\n");
197
198 /* test 4 */
199 if (runs[0][33] != 0)
200 {
201 printf("test 4 failed, bit=%d run=%d num=%lu\n",
202 0,34,runs[0][33]);
203 err++;
204 }
205 if (runs[1][33] != 0)
206 {
207 printf("test 4 failed, bit=%d run=%d num=%lu\n",
208 1,34,runs[1][33]);
209 err++;
210 }
211 printf("test 4 done\n");
212 err:
213 err=((err)?1:0);
214 EXIT(err);
215 return(err);
216 }
diff --git a/src/lib/libcrypto/rc2/Makefile b/src/lib/libcrypto/rc2/Makefile
new file mode 100644
index 0000000000..73eac347e7
--- /dev/null
+++ b/src/lib/libcrypto/rc2/Makefile
@@ -0,0 +1,86 @@
1#
2# OpenSSL/crypto/rc2/Makefile
3#
4
5DIR= rc2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=rc2test.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c rc2ofb64.c
21LIBOBJ=rc2_ecb.o rc2_skey.o rc2_cbc.o rc2cfb64.o rc2ofb64.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= rc2.h
26HEADER= rc2_locl.h $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77rc2_cbc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
78rc2_cbc.o: rc2_cbc.c rc2_locl.h
79rc2_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
80rc2_ecb.o: ../../include/openssl/rc2.h rc2_ecb.c rc2_locl.h
81rc2_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
82rc2_skey.o: rc2_locl.h rc2_skey.c
83rc2cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
84rc2cfb64.o: rc2_locl.h rc2cfb64.c
85rc2ofb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
86rc2ofb64.o: rc2_locl.h rc2ofb64.c
diff --git a/src/lib/libcrypto/rc2/Makefile.ssl b/src/lib/libcrypto/rc2/Makefile.ssl
new file mode 100644
index 0000000000..98d5960d5d
--- /dev/null
+++ b/src/lib/libcrypto/rc2/Makefile.ssl
@@ -0,0 +1,91 @@
1#
2# SSLeay/crypto/rc2/Makefile
3#
4
5DIR= rc2
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=rc2test.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=rc2_ecb.c rc2_skey.c rc2_cbc.c rc2cfb64.c rc2ofb64.c
27LIBOBJ=rc2_ecb.o rc2_skey.o rc2_cbc.o rc2cfb64.o rc2ofb64.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= rc2.h
32HEADER= rc2_locl.h $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82rc2_cbc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
83rc2_cbc.o: rc2_cbc.c rc2_locl.h
84rc2_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
85rc2_ecb.o: ../../include/openssl/rc2.h rc2_ecb.c rc2_locl.h
86rc2_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
87rc2_skey.o: rc2_locl.h rc2_skey.c
88rc2cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
89rc2cfb64.o: rc2_locl.h rc2cfb64.c
90rc2ofb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc2.h
91rc2ofb64.o: rc2_locl.h rc2ofb64.c
diff --git a/src/lib/libcrypto/rc2/rc2.h b/src/lib/libcrypto/rc2/rc2.h
index 34c8362317..71788158d8 100644
--- a/src/lib/libcrypto/rc2/rc2.h
+++ b/src/lib/libcrypto/rc2/rc2.h
@@ -59,7 +59,6 @@
59#ifndef HEADER_RC2_H 59#ifndef HEADER_RC2_H
60#define HEADER_RC2_H 60#define HEADER_RC2_H
61 61
62#include <openssl/opensslconf.h> /* OPENSSL_NO_RC2, RC2_INT */
63#ifdef OPENSSL_NO_RC2 62#ifdef OPENSSL_NO_RC2
64#error RC2 is disabled. 63#error RC2 is disabled.
65#endif 64#endif
@@ -67,6 +66,7 @@
67#define RC2_ENCRYPT 1 66#define RC2_ENCRYPT 1
68#define RC2_DECRYPT 0 67#define RC2_DECRYPT 0
69 68
69#include <openssl/opensslconf.h> /* RC2_INT */
70#define RC2_BLOCK 8 70#define RC2_BLOCK 8
71#define RC2_KEY_LENGTH 16 71#define RC2_KEY_LENGTH 16
72 72
@@ -79,7 +79,10 @@ typedef struct rc2_key_st
79 RC2_INT data[64]; 79 RC2_INT data[64];
80 } RC2_KEY; 80 } RC2_KEY;
81 81
82 82#ifdef OPENSSL_FIPS
83void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
84 int bits);
85#endif
83void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits); 86void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,int bits);
84void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key, 87void RC2_ecb_encrypt(const unsigned char *in,unsigned char *out,RC2_KEY *key,
85 int enc); 88 int enc);
diff --git a/src/lib/libcrypto/rc2/rc2_ecb.c b/src/lib/libcrypto/rc2/rc2_ecb.c
index fff86c7af8..d3e8c2718a 100644
--- a/src/lib/libcrypto/rc2/rc2_ecb.c
+++ b/src/lib/libcrypto/rc2/rc2_ecb.c
@@ -60,7 +60,7 @@
60#include "rc2_locl.h" 60#include "rc2_locl.h"
61#include <openssl/opensslv.h> 61#include <openssl/opensslv.h>
62 62
63const char RC2_version[]="RC2" OPENSSL_VERSION_PTEXT; 63const char *RC2_version="RC2" OPENSSL_VERSION_PTEXT;
64 64
65/* RC2 as implemented frm a posting from 65/* RC2 as implemented frm a posting from
66 * Newsgroups: sci.crypt 66 * Newsgroups: sci.crypt
diff --git a/src/lib/libcrypto/rc2/rc2_skey.c b/src/lib/libcrypto/rc2/rc2_skey.c
index 4953642056..9652865188 100644
--- a/src/lib/libcrypto/rc2/rc2_skey.c
+++ b/src/lib/libcrypto/rc2/rc2_skey.c
@@ -57,6 +57,8 @@
57 */ 57 */
58 58
59#include <openssl/rc2.h> 59#include <openssl/rc2.h>
60#include <openssl/crypto.h>
61#include <openssl/fips.h>
60#include "rc2_locl.h" 62#include "rc2_locl.h"
61 63
62static unsigned char key_table[256]={ 64static unsigned char key_table[256]={
@@ -84,17 +86,25 @@ static unsigned char key_table[256]={
84 0xfe,0x7f,0xc1,0xad, 86 0xfe,0x7f,0xc1,0xad,
85 }; 87 };
86 88
87#if defined(_MSC_VER) && defined(_ARM_)
88#pragma optimize("g",off)
89#endif
90
91/* It has come to my attention that there are 2 versions of the RC2 89/* It has come to my attention that there are 2 versions of the RC2
92 * key schedule. One which is normal, and anther which has a hook to 90 * key schedule. One which is normal, and anther which has a hook to
93 * use a reduced key length. 91 * use a reduced key length.
94 * BSAFE uses the 'retarded' version. What I previously shipped is 92 * BSAFE uses the 'retarded' version. What I previously shipped is
95 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses 93 * the same as specifying 1024 for the 'bits' parameter. Bsafe uses
96 * a version where the bits parameter is the same as len*8 */ 94 * a version where the bits parameter is the same as len*8 */
95
96#ifdef OPENSSL_FIPS
97void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
98 {
99 if (FIPS_mode())
100 FIPS_BAD_ABORT(RC2)
101 private_RC2_set_key(key, len, data, bits);
102 }
103void private_RC2_set_key(RC2_KEY *key, int len, const unsigned char *data,
104 int bits)
105#else
97void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits) 106void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
107#endif
98 { 108 {
99 int i,j; 109 int i,j;
100 unsigned char *k; 110 unsigned char *k;
@@ -140,6 +150,3 @@ void RC2_set_key(RC2_KEY *key, int len, const unsigned char *data, int bits)
140 *(ki--)=((k[i]<<8)|k[i-1])&0xffff; 150 *(ki--)=((k[i]<<8)|k[i-1])&0xffff;
141 } 151 }
142 152
143#if defined(_MSC_VER)
144#pragma optimize("",on)
145#endif
diff --git a/src/lib/libcrypto/rc2/rc2speed.c b/src/lib/libcrypto/rc2/rc2speed.c
new file mode 100644
index 0000000000..4d0e1242ea
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2speed.c
@@ -0,0 +1,274 @@
1/* crypto/rc2/rc2speed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
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 */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/rc2.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103#ifndef CLK_TCK
104#define HZ 100.0
105#else /* CLK_TCK */
106#define HZ ((double)CLK_TCK)
107#endif /* CLK_TCK */
108#endif /* HZ */
109
110#define BUFSIZE ((long)1024)
111long run=0;
112
113double Time_F(int s);
114#ifdef SIGALRM
115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
116#define SIGRETTYPE void
117#else
118#define SIGRETTYPE int
119#endif
120
121SIGRETTYPE sig_done(int sig);
122SIGRETTYPE sig_done(int sig)
123 {
124 signal(SIGALRM,sig_done);
125 run=0;
126#ifdef LINT
127 sig=sig;
128#endif
129 }
130#endif
131
132#define START 0
133#define STOP 1
134
135double Time_F(int s)
136 {
137 double ret;
138#ifdef TIMES
139 static struct tms tstart,tend;
140
141 if (s == START)
142 {
143 times(&tstart);
144 return(0);
145 }
146 else
147 {
148 times(&tend);
149 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
150 return((ret == 0.0)?1e-6:ret);
151 }
152#else /* !times() */
153 static struct timeb tstart,tend;
154 long i;
155
156 if (s == START)
157 {
158 ftime(&tstart);
159 return(0);
160 }
161 else
162 {
163 ftime(&tend);
164 i=(long)tend.millitm-(long)tstart.millitm;
165 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
166 return((ret == 0.0)?1e-6:ret);
167 }
168#endif
169 }
170
171int main(int argc, char **argv)
172 {
173 long count;
174 static unsigned char buf[BUFSIZE];
175 static unsigned char key[] ={
176 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
177 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
178 };
179 RC2_KEY sch;
180 double a,b,c,d;
181#ifndef SIGALRM
182 long ca,cb,cc;
183#endif
184
185#ifndef TIMES
186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n");
188#endif
189
190#ifndef SIGALRM
191 printf("First we calculate the approximate speed ...\n");
192 RC2_set_key(&sch,16,key,128);
193 count=10;
194 do {
195 long i;
196 unsigned long data[2];
197
198 count*=2;
199 Time_F(START);
200 for (i=count; i; i--)
201 RC2_encrypt(data,&sch);
202 d=Time_F(STOP);
203 } while (d < 3.0);
204 ca=count/512;
205 cb=count;
206 cc=count*8/BUFSIZE+1;
207 printf("Doing RC2_set_key %ld times\n",ca);
208#define COND(d) (count != (d))
209#define COUNT(d) (d)
210#else
211#define COND(c) (run)
212#define COUNT(d) (count)
213 signal(SIGALRM,sig_done);
214 printf("Doing RC2_set_key for 10 seconds\n");
215 alarm(10);
216#endif
217
218 Time_F(START);
219 for (count=0,run=1; COND(ca); count+=4)
220 {
221 RC2_set_key(&sch,16,key,128);
222 RC2_set_key(&sch,16,key,128);
223 RC2_set_key(&sch,16,key,128);
224 RC2_set_key(&sch,16,key,128);
225 }
226 d=Time_F(STOP);
227 printf("%ld RC2_set_key's in %.2f seconds\n",count,d);
228 a=((double)COUNT(ca))/d;
229
230#ifdef SIGALRM
231 printf("Doing RC2_encrypt's for 10 seconds\n");
232 alarm(10);
233#else
234 printf("Doing RC2_encrypt %ld times\n",cb);
235#endif
236 Time_F(START);
237 for (count=0,run=1; COND(cb); count+=4)
238 {
239 unsigned long data[2];
240
241 RC2_encrypt(data,&sch);
242 RC2_encrypt(data,&sch);
243 RC2_encrypt(data,&sch);
244 RC2_encrypt(data,&sch);
245 }
246 d=Time_F(STOP);
247 printf("%ld RC2_encrypt's in %.2f second\n",count,d);
248 b=((double)COUNT(cb)*8)/d;
249
250#ifdef SIGALRM
251 printf("Doing RC2_cbc_encrypt on %ld byte blocks for 10 seconds\n",
252 BUFSIZE);
253 alarm(10);
254#else
255 printf("Doing RC2_cbc_encrypt %ld times on %ld byte blocks\n",cc,
256 BUFSIZE);
257#endif
258 Time_F(START);
259 for (count=0,run=1; COND(cc); count++)
260 RC2_cbc_encrypt(buf,buf,BUFSIZE,&sch,
261 &(key[0]),RC2_ENCRYPT);
262 d=Time_F(STOP);
263 printf("%ld RC2_cbc_encrypt's of %ld byte blocks in %.2f second\n",
264 count,BUFSIZE,d);
265 c=((double)COUNT(cc)*BUFSIZE)/d;
266
267 printf("RC2 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
268 printf("RC2 raw ecb bytes per sec = %12.2f (%9.3fuS)\n",b,8.0e6/b);
269 printf("RC2 cbc bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
270 exit(0);
271#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
272 return(0);
273#endif
274 }
diff --git a/src/lib/libcrypto/rc2/rc2test.c b/src/lib/libcrypto/rc2/rc2test.c
new file mode 100644
index 0000000000..b67bafb49f
--- /dev/null
+++ b/src/lib/libcrypto/rc2/rc2test.c
@@ -0,0 +1,271 @@
1/* crypto/rc2/rc2test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. 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 has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC2 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65
66#include "../e_os.h"
67
68#ifdef OPENSSL_NO_RC2
69int main(int argc, char *argv[])
70{
71 printf("No RC2 support\n");
72 return(0);
73}
74#else
75#include <openssl/rc2.h>
76
77static unsigned char RC2key[4][16]={
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
81 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
82 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
84 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
85 0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F},
86 };
87
88static unsigned char RC2plain[4][8]={
89 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
90 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
91 {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF},
92 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
93 };
94
95static unsigned char RC2cipher[4][8]={
96 {0x1C,0x19,0x8A,0x83,0x8D,0xF0,0x28,0xB7},
97 {0x21,0x82,0x9C,0x78,0xA9,0xF9,0xC0,0x74},
98 {0x13,0xDB,0x35,0x17,0xD3,0x21,0x86,0x9E},
99 {0x50,0xDC,0x01,0x62,0xBD,0x75,0x7F,0x31},
100 };
101/************/
102#ifdef undef
103unsigned char k[16]={
104 0x00,0x01,0x00,0x02,0x00,0x03,0x00,0x04,
105 0x00,0x05,0x00,0x06,0x00,0x07,0x00,0x08};
106
107unsigned char in[8]={0x00,0x00,0x00,0x01,0x00,0x02,0x00,0x03};
108unsigned char c[8]={0x11,0xFB,0xED,0x2B,0x01,0x98,0x6D,0xE5};
109unsigned char out[80];
110
111char *text="Hello to all people out there";
112
113static unsigned char cfb_key[16]={
114 0xe1,0xf0,0xc3,0xd2,0xa5,0xb4,0x87,0x96,
115 0x69,0x78,0x4b,0x5a,0x2d,0x3c,0x0f,0x1e,
116 };
117static unsigned char cfb_iv[80]={0x34,0x12,0x78,0x56,0xab,0x90,0xef,0xcd};
118static unsigned char cfb_buf1[40],cfb_buf2[40],cfb_tmp[8];
119#define CFB_TEST_SIZE 24
120static unsigned char plain[CFB_TEST_SIZE]=
121 {
122 0x4e,0x6f,0x77,0x20,0x69,0x73,
123 0x20,0x74,0x68,0x65,0x20,0x74,
124 0x69,0x6d,0x65,0x20,0x66,0x6f,
125 0x72,0x20,0x61,0x6c,0x6c,0x20
126 };
127static unsigned char cfb_cipher64[CFB_TEST_SIZE]={
128 0x59,0xD8,0xE2,0x65,0x00,0x58,0x6C,0x3F,
129 0x2C,0x17,0x25,0xD0,0x1A,0x38,0xB7,0x2A,
130 0x39,0x61,0x37,0xDC,0x79,0xFB,0x9F,0x45
131
132/* 0xF9,0x78,0x32,0xB5,0x42,0x1A,0x6B,0x38,
133 0x9A,0x44,0xD6,0x04,0x19,0x43,0xC4,0xD9,
134 0x3D,0x1E,0xAE,0x47,0xFC,0xCF,0x29,0x0B,*/
135 };
136
137
138/*static int cfb64_test(unsigned char *cfb_cipher);*/
139static char *pt(unsigned char *p);
140#endif
141
142int main(int argc, char *argv[])
143 {
144 int i,n,err=0;
145 RC2_KEY key;
146 unsigned char buf[8],buf2[8];
147
148 for (n=0; n<4; n++)
149 {
150 RC2_set_key(&key,16,&(RC2key[n][0]),0 /* or 1024 */);
151
152 RC2_ecb_encrypt(&(RC2plain[n][0]),buf,&key,RC2_ENCRYPT);
153 if (memcmp(&(RC2cipher[n][0]),buf,8) != 0)
154 {
155 printf("ecb rc2 error encrypting\n");
156 printf("got :");
157 for (i=0; i<8; i++)
158 printf("%02X ",buf[i]);
159 printf("\n");
160 printf("expected:");
161 for (i=0; i<8; i++)
162 printf("%02X ",RC2cipher[n][i]);
163 err=20;
164 printf("\n");
165 }
166
167 RC2_ecb_encrypt(buf,buf2,&key,RC2_DECRYPT);
168 if (memcmp(&(RC2plain[n][0]),buf2,8) != 0)
169 {
170 printf("ecb RC2 error decrypting\n");
171 printf("got :");
172 for (i=0; i<8; i++)
173 printf("%02X ",buf[i]);
174 printf("\n");
175 printf("expected:");
176 for (i=0; i<8; i++)
177 printf("%02X ",RC2plain[n][i]);
178 printf("\n");
179 err=3;
180 }
181 }
182
183 if (err == 0) printf("ecb RC2 ok\n");
184#ifdef undef
185 memcpy(iv,k,8);
186 idea_cbc_encrypt((unsigned char *)text,out,strlen(text)+1,&key,iv,1);
187 memcpy(iv,k,8);
188 idea_cbc_encrypt(out,out,8,&dkey,iv,0);
189 idea_cbc_encrypt(&(out[8]),&(out[8]),strlen(text)+1-8,&dkey,iv,0);
190 if (memcmp(text,out,strlen(text)+1) != 0)
191 {
192 printf("cbc idea bad\n");
193 err=4;
194 }
195 else
196 printf("cbc idea ok\n");
197
198 printf("cfb64 idea ");
199 if (cfb64_test(cfb_cipher64))
200 {
201 printf("bad\n");
202 err=5;
203 }
204 else
205 printf("ok\n");
206#endif
207
208 EXIT(err);
209 return(err);
210 }
211
212#ifdef undef
213static int cfb64_test(unsigned char *cfb_cipher)
214 {
215 IDEA_KEY_SCHEDULE eks,dks;
216 int err=0,i,n;
217
218 idea_set_encrypt_key(cfb_key,&eks);
219 idea_set_decrypt_key(&eks,&dks);
220 memcpy(cfb_tmp,cfb_iv,8);
221 n=0;
222 idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
223 cfb_tmp,&n,IDEA_ENCRYPT);
224 idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
225 (long)CFB_TEST_SIZE-12,&eks,
226 cfb_tmp,&n,IDEA_ENCRYPT);
227 if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
228 {
229 err=1;
230 printf("idea_cfb64_encrypt encrypt error\n");
231 for (i=0; i<CFB_TEST_SIZE; i+=8)
232 printf("%s\n",pt(&(cfb_buf1[i])));
233 }
234 memcpy(cfb_tmp,cfb_iv,8);
235 n=0;
236 idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
237 cfb_tmp,&n,IDEA_DECRYPT);
238 idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
239 (long)CFB_TEST_SIZE-17,&dks,
240 cfb_tmp,&n,IDEA_DECRYPT);
241 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
242 {
243 err=1;
244 printf("idea_cfb_encrypt decrypt error\n");
245 for (i=0; i<24; i+=8)
246 printf("%s\n",pt(&(cfb_buf2[i])));
247 }
248 return(err);
249 }
250
251static char *pt(unsigned char *p)
252 {
253 static char bufs[10][20];
254 static int bnum=0;
255 char *ret;
256 int i;
257 static char *f="0123456789ABCDEF";
258
259 ret= &(bufs[bnum++][0]);
260 bnum%=10;
261 for (i=0; i<8; i++)
262 {
263 ret[i*2]=f[(p[i]>>4)&0xf];
264 ret[i*2+1]=f[p[i]&0xf];
265 }
266 ret[16]='\0';
267 return(ret);
268 }
269
270#endif
271#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 b/src/lib/libcrypto/rc4/Makefile
new file mode 100644
index 0000000000..187ed5c668
--- /dev/null
+++ b/src/lib/libcrypto/rc4/Makefile
@@ -0,0 +1,115 @@
1#
2# OpenSSL/crypto/rc4/Makefile
3#
4
5DIR= rc4
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11AR= ar r
12
13RC4_ENC=rc4_enc.o rc4_skey.o
14
15CFLAGS= $(INCLUDES) $(CFLAG)
16ASFLAGS= $(INCLUDES) $(ASFLAG)
17AFLAGS= $(ASFLAGS)
18
19GENERAL=Makefile
20TEST=rc4test.c
21APPS=
22
23LIB=$(TOP)/libcrypto.a
24LIBSRC=rc4_skey.c rc4_enc.c
25LIBOBJ=$(RC4_ENC)
26
27SRC= $(LIBSRC)
28
29EXHEADER= rc4.h
30HEADER= $(EXHEADER) rc4_locl.h
31
32ALL= $(GENERAL) $(SRC) $(HEADER)
33
34top:
35 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
36
37all: lib
38
39lib: $(LIBOBJ)
40 $(AR) $(LIB) $(LIBOBJ)
41 $(RANLIB) $(LIB) || echo Never mind.
42 @touch lib
43
44# ELF
45rx86-elf.s: asm/rc4-586.pl ../perlasm/x86asm.pl
46 (cd asm; $(PERL) rc4-586.pl elf $(CFLAGS) > ../$@)
47# COFF
48rx86-cof.s: asm/rc4-586.pl ../perlasm/x86asm.pl
49 (cd asm; $(PERL) rc4-586.pl coff $(CFLAGS) > ../$@)
50# a.out
51rx86-out.s: asm/rc4-586.pl ../perlasm/x86asm.pl
52 (cd asm; $(PERL) rc4-586.pl a.out $(CFLAGS) > ../$@)
53
54rc4-x86_64.s: asm/rc4-x86_64.pl; $(PERL) asm/rc4-x86_64.pl $@
55
56rc4-ia64.s: asm/rc4-ia64.S
57 @case `awk '/^#define RC4_INT/{print$$NF}' $(TOP)/include/openssl/opensslconf.h` in \
58 int) set -x; $(CC) $(CFLAGS) -DSZ=4 -E asm/rc4-ia64.S > $@ ;; \
59 char) set -x; $(CC) $(CFLAGS) -DSZ=1 -E asm/rc4-ia64.S > $@ ;; \
60 *) exit 1 ;; \
61 esac
62
63files:
64 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
65
66links:
67 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
68 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
69 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
70
71install:
72 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
73 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
74 do \
75 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
76 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
77 done;
78
79tags:
80 ctags $(SRC)
81
82tests:
83
84lint:
85 lint -DLINT $(INCLUDES) $(SRC)>fluff
86
87depend:
88 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
89 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
90
91dclean:
92 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
93 mv -f Makefile.new $(MAKEFILE)
94
95clean:
96 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
97
98# DO NOT DELETE THIS LINE -- make depend depends on it.
99
100rc4_enc.o: ../../e_os.h ../../include/openssl/bio.h
101rc4_enc.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102rc4_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
103rc4_enc.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
104rc4_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105rc4_enc.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
106rc4_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
107rc4_enc.o: ../cryptlib.h rc4_enc.c rc4_locl.h
108rc4_skey.o: ../../e_os.h ../../include/openssl/bio.h
109rc4_skey.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
110rc4_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
111rc4_skey.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
112rc4_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113rc4_skey.o: ../../include/openssl/rc4.h ../../include/openssl/safestack.h
114rc4_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
115rc4_skey.o: ../cryptlib.h rc4_locl.h rc4_skey.c
diff --git a/src/lib/libcrypto/rc4/Makefile.ssl b/src/lib/libcrypto/rc4/Makefile.ssl
new file mode 100644
index 0000000000..3e602662be
--- /dev/null
+++ b/src/lib/libcrypto/rc4/Makefile.ssl
@@ -0,0 +1,110 @@
1#
2# SSLeay/crypto/rc4/Makefile
3#
4
5DIR= rc4
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20RC4_ENC=rc4_enc.o
21# or use
22#RC4_ENC=asm/rx86-elf.o
23#RC4_ENC=asm/rx86-out.o
24#RC4_ENC=asm/rx86-sol.o
25#RC4_ENC=asm/rx86bdsi.o
26
27CFLAGS= $(INCLUDES) $(CFLAG)
28ASFLAGS= $(INCLUDES) $(ASFLAG)
29
30GENERAL=Makefile
31TEST=rc4test.c
32APPS=
33
34LIB=$(TOP)/libcrypto.a
35LIBSRC=rc4_skey.c rc4_enc.c
36LIBOBJ=rc4_skey.o $(RC4_ENC)
37
38SRC= $(LIBSRC)
39
40EXHEADER= rc4.h
41HEADER= $(EXHEADER) rc4_locl.h
42
43ALL= $(GENERAL) $(SRC) $(HEADER)
44
45top:
46 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
47
48all: lib
49
50lib: $(LIBOBJ)
51 $(AR) $(LIB) $(LIBOBJ)
52 $(RANLIB) $(LIB) || echo Never mind.
53 @touch lib
54
55# elf
56asm/rx86-elf.s: asm/rc4-586.pl ../perlasm/x86asm.pl
57 (cd asm; $(PERL) rc4-586.pl elf $(CFLAGS) > rx86-elf.s)
58
59# a.out
60asm/rx86-out.o: asm/rx86unix.cpp
61 $(CPP) -DOUT asm/rx86unix.cpp | as -o asm/rx86-out.o
62
63# bsdi
64asm/rx86bsdi.o: asm/rx86unix.cpp
65 $(CPP) -DBSDI asm/rx86unix.cpp | sed 's/ :/:/' | as -o asm/rx86bsdi.o
66
67asm/rx86unix.cpp: asm/rc4-586.pl ../perlasm/x86asm.pl
68 (cd asm; $(PERL) rc4-586.pl cpp >rx86unix.cpp)
69
70files:
71 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
72
73links:
74 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
75 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
76 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
77 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
78
79install:
80 @for i in $(EXHEADER) ; \
81 do \
82 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
83 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
84 done;
85
86tags:
87 ctags $(SRC)
88
89tests:
90
91lint:
92 lint -DLINT $(INCLUDES) $(SRC)>fluff
93
94depend:
95 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
96
97dclean:
98 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
99 mv -f Makefile.new $(MAKEFILE)
100
101clean:
102 rm -f asm/rx86unix.cpp asm/*-elf.* *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o
103
104# DO NOT DELETE THIS LINE -- make depend depends on it.
105
106rc4_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc4.h
107rc4_enc.o: rc4_enc.c rc4_locl.h
108rc4_skey.o: ../../include/openssl/opensslconf.h
109rc4_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/rc4.h
110rc4_skey.o: rc4_locl.h rc4_skey.c
diff --git a/src/lib/libcrypto/rc4/asm/rc4-586.pl b/src/lib/libcrypto/rc4/asm/rc4-586.pl
index ef7eee766c..d6e98f0811 100644
--- a/src/lib/libcrypto/rc4/asm/rc4-586.pl
+++ b/src/lib/libcrypto/rc4/asm/rc4-586.pl
@@ -200,23 +200,22 @@ sub RC4
200 200
201 &lea ($ty,&DWP(0,$in,$ty)); 201 &lea ($ty,&DWP(0,$in,$ty));
202 &mov (&swtmp(2),$ty); 202 &mov (&swtmp(2),$ty);
203 &movz ($tx,&BP(0,$d,$x));
204 203
205 # strangely enough unrolled loop performs over 20% slower... 204 # strangely enough unrolled loop performs over 20% slower...
206 &set_label("RC4_CHAR_loop"); 205 &set_label("RC4_CHAR_loop");
206 &movz ($tx,&BP(0,$d,$x));
207 &add (&LB($y),&LB($tx)); 207 &add (&LB($y),&LB($tx));
208 &movz ($ty,&BP(0,$d,$y)); 208 &movz ($ty,&BP(0,$d,$y));
209 &movb (&BP(0,$d,$y),&LB($tx)); 209 &movb (&BP(0,$d,$y),&LB($tx));
210 &movb (&BP(0,$d,$x),&LB($ty)); 210 &movb (&BP(0,$d,$x),&LB($ty));
211 &add (&LB($ty),&LB($tx)); 211 &add (&LB($ty),&LB($tx));
212 &movz ($ty,&BP(0,$d,$ty)); 212 &movz ($ty,&BP(0,$d,$ty));
213 &add (&LB($x),1);
214 &xorb (&LB($ty),&BP(0,$in)); 213 &xorb (&LB($ty),&BP(0,$in));
215 &lea ($in,&DWP(1,$in));
216 &movz ($tx,&BP(0,$d,$x));
217 &cmp ($in,&swtmp(2));
218 &movb (&BP(0,$out),&LB($ty)); 214 &movb (&BP(0,$out),&LB($ty));
219 &lea ($out,&DWP(1,$out)); 215 &inc (&LB($x));
216 &inc ($in);
217 &inc ($out);
218 &cmp ($in,&swtmp(2));
220 &jb (&label("RC4_CHAR_loop")); 219 &jb (&label("RC4_CHAR_loop"));
221 220
222 &set_label("finished"); 221 &set_label("finished");
diff --git a/src/lib/libcrypto/rc4/asm/rc4-amd64.pl b/src/lib/libcrypto/rc4/asm/rc4-amd64.pl
new file mode 100755
index 0000000000..9e0da8af99
--- /dev/null
+++ b/src/lib/libcrypto/rc4/asm/rc4-amd64.pl
@@ -0,0 +1,227 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# 2.22x RC4 tune-up:-) It should be noted though that my hand [as in
10# "hand-coded assembler"] doesn't stand for the whole improvement
11# coefficient. It turned out that eliminating RC4_CHAR from config
12# line results in ~40% improvement (yes, even for C implementation).
13# Presumably it has everything to do with AMD cache architecture and
14# RAW or whatever penalties. Once again! The module *requires* config
15# line *without* RC4_CHAR! As for coding "secret," I bet on partial
16# register arithmetics. For example instead of 'inc %r8; and $255,%r8'
17# I simply 'inc %r8b'. Even though optimization manual discourages
18# to operate on partial registers, it turned out to be the best bet.
19# At least for AMD... How IA32E would perform remains to be seen...
20
21# As was shown by Marc Bevand reordering of couple of load operations
22# results in even higher performance gain of 3.3x:-) At least on
23# Opteron... For reference, 1x in this case is RC4_CHAR C-code
24# compiled with gcc 3.3.2, which performs at ~54MBps per 1GHz clock.
25# Latter means that if you want to *estimate* what to expect from
26# *your* CPU, then multiply 54 by 3.3 and clock frequency in GHz.
27
28# Intel P4 EM64T core was found to run the AMD64 code really slow...
29# The only way to achieve comparable performance on P4 is to keep
30# RC4_CHAR. Kind of ironic, huh? As it's apparently impossible to
31# compose blended code, which would perform even within 30% marginal
32# on either AMD and Intel platforms, I implement both cases. See
33# rc4_skey.c for further details... This applies to 0.9.8 and later.
34# In 0.9.7 context RC4_CHAR codepath is never engaged and ~70 bytes
35# of code remain redundant.
36
37$output=shift;
38
39$win64a=1 if ($output =~ /win64a.[s|asm]/);
40
41open STDOUT,">$output" || die "can't open $output: $!";
42
43if (defined($win64a)) {
44 $dat="%rcx"; # arg1
45 $len="%rdx"; # arg2
46 $inp="%rsi"; # r8, arg3 moves here
47 $out="%rdi"; # r9, arg4 moves here
48} else {
49 $dat="%rdi"; # arg1
50 $len="%rsi"; # arg2
51 $inp="%rdx"; # arg3
52 $out="%rcx"; # arg4
53}
54
55$XX="%r10";
56$TX="%r8";
57$YY="%r11";
58$TY="%r9";
59
60sub PTR() {
61 my $ret=shift;
62 if (defined($win64a)) {
63 $ret =~ s/\[([\S]+)\+([\S]+)\]/[$2+$1]/g; # [%rN+%rM*4]->[%rM*4+%rN]
64 $ret =~ s/:([^\[]+)\[([^\]]+)\]/:[$2+$1]/g; # :off[ea]->:[ea+off]
65 } else {
66 $ret =~ s/[\+\*]/,/g; # [%rN+%rM*4]->[%rN,%rM,4]
67 $ret =~ s/\[([^\]]+)\]/($1)/g; # [%rN]->(%rN)
68 }
69 $ret;
70}
71
72$code=<<___ if (!defined($win64a));
73.text
74
75.globl RC4
76.type RC4,\@function
77.align 16
78RC4: or $len,$len
79 jne .Lentry
80 repret
81.Lentry:
82___
83$code=<<___ if (defined($win64a));
84_TEXT SEGMENT
85PUBLIC RC4
86ALIGN 16
87RC4 PROC
88 or $len,$len
89 jne .Lentry
90 repret
91.Lentry:
92 push %rdi
93 push %rsi
94 sub \$40,%rsp
95 mov %r8,$inp
96 mov %r9,$out
97___
98$code.=<<___;
99 add \$8,$dat
100 movl `&PTR("DWORD:-8[$dat]")`,$XX#d
101 movl `&PTR("DWORD:-4[$dat]")`,$YY#d
102 cmpl \$-1,`&PTR("DWORD:256[$dat]")`
103 je .LRC4_CHAR
104 test \$-8,$len
105 jz .Lloop1
106.align 16
107.Lloop8:
108 inc $XX#b
109 movl `&PTR("DWORD:[$dat+$XX*4]")`,$TX#d
110 add $TX#b,$YY#b
111 movl `&PTR("DWORD:[$dat+$YY*4]")`,$TY#d
112 movl $TX#d,`&PTR("DWORD:[$dat+$YY*4]")`
113 movl $TY#d,`&PTR("DWORD:[$dat+$XX*4]")`
114 add $TX#b,$TY#b
115 inc $XX#b
116 movl `&PTR("DWORD:[$dat+$XX*4]")`,$TX#d
117 movb `&PTR("BYTE:[$dat+$TY*4]")`,%al
118___
119for ($i=1;$i<=6;$i++) {
120$code.=<<___;
121 add $TX#b,$YY#b
122 ror \$8,%rax
123 movl `&PTR("DWORD:[$dat+$YY*4]")`,$TY#d
124 movl $TX#d,`&PTR("DWORD:[$dat+$YY*4]")`
125 movl $TY#d,`&PTR("DWORD:[$dat+$XX*4]")`
126 add $TX#b,$TY#b
127 inc $XX#b
128 movl `&PTR("DWORD:[$dat+$XX*4]")`,$TX#d
129 movb `&PTR("BYTE:[$dat+$TY*4]")`,%al
130___
131}
132$code.=<<___;
133 add $TX#b,$YY#b
134 ror \$8,%rax
135 movl `&PTR("DWORD:[$dat+$YY*4]")`,$TY#d
136 movl $TX#d,`&PTR("DWORD:[$dat+$YY*4]")`
137 movl $TY#d,`&PTR("DWORD:[$dat+$XX*4]")`
138 sub \$8,$len
139 add $TY#b,$TX#b
140 movb `&PTR("BYTE:[$dat+$TX*4]")`,%al
141 ror \$8,%rax
142 add \$8,$inp
143 add \$8,$out
144
145 xor `&PTR("QWORD:-8[$inp]")`,%rax
146 mov %rax,`&PTR("QWORD:-8[$out]")`
147
148 test \$-8,$len
149 jnz .Lloop8
150 cmp \$0,$len
151 jne .Lloop1
152.Lexit:
153 movl $XX#d,`&PTR("DWORD:-8[$dat]")`
154 movl $YY#d,`&PTR("DWORD:-4[$dat]")`
155___
156$code.=<<___ if (defined($win64a));
157 add \$40,%rsp
158 pop %rsi
159 pop %rdi
160___
161$code.=<<___;
162 repret
163.align 16
164.Lloop1:
165 movzb `&PTR("BYTE:[$inp]")`,%eax
166 inc $XX#b
167 movl `&PTR("DWORD:[$dat+$XX*4]")`,$TX#d
168 add $TX#b,$YY#b
169 movl `&PTR("DWORD:[$dat+$YY*4]")`,$TY#d
170 movl $TX#d,`&PTR("DWORD:[$dat+$YY*4]")`
171 movl $TY#d,`&PTR("DWORD:[$dat+$XX*4]")`
172 add $TY#b,$TX#b
173 movl `&PTR("DWORD:[$dat+$TX*4]")`,$TY#d
174 xor $TY,%rax
175 inc $inp
176 movb %al,`&PTR("BYTE:[$out]")`
177 inc $out
178 dec $len
179 jnz .Lloop1
180 jmp .Lexit
181
182.align 16
183.LRC4_CHAR:
184 inc $XX#b
185 movzb `&PTR("BYTE:[$dat+$XX]")`,$TX#d
186 add $TX#b,$YY#b
187 movzb `&PTR("BYTE:[$dat+$YY]")`,$TY#d
188 movb $TX#b,`&PTR("BYTE:[$dat+$YY]")`
189 movb $TY#b,`&PTR("BYTE:[$dat+$XX]")`
190 add $TX#b,$TY#b
191 movzb `&PTR("BYTE:[$dat+$TY]")`,$TY#d
192 xorb `&PTR("BYTE:[$inp]")`,$TY#b
193 movb $TY#b,`&PTR("BYTE:[$out]")`
194 inc $inp
195 inc $out
196 dec $len
197 jnz .LRC4_CHAR
198 jmp .Lexit
199___
200$code.=<<___ if (defined($win64a));
201RC4 ENDP
202_TEXT ENDS
203END
204___
205$code.=<<___ if (!defined($win64a));
206.size RC4,.-RC4
207___
208
209$code =~ s/#([bwd])/$1/gm;
210$code =~ s/\`([^\`]*)\`/eval $1/gem;
211
212if (defined($win64a)) {
213 $code =~ s/\.align/ALIGN/gm;
214 $code =~ s/[\$%]//gm;
215 $code =~ s/\.L/\$L/gm;
216 $code =~ s/([\w]+)([\s]+)([\S]+),([\S]+)/$1$2$4,$3/gm;
217 $code =~ s/([QD]*WORD|BYTE):/$1 PTR/gm;
218 $code =~ s/mov[bwlq]/mov/gm;
219 $code =~ s/movzb/movzx/gm;
220 $code =~ s/repret/DB\t0F3h,0C3h/gm;
221 $code =~ s/cmpl/cmp/gm;
222 $code =~ s/xorb/xor/gm;
223} else {
224 $code =~ s/([QD]*WORD|BYTE)://gm;
225 $code =~ s/repret/.byte\t0xF3,0xC3/gm;
226}
227print $code;
diff --git a/src/lib/libcrypto/rc4/asm/rc4-ia64.S b/src/lib/libcrypto/rc4/asm/rc4-ia64.S
new file mode 100644
index 0000000000..8210c47d04
--- /dev/null
+++ b/src/lib/libcrypto/rc4/asm/rc4-ia64.S
@@ -0,0 +1,159 @@
1// ====================================================================
2// Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
3// project.
4//
5// Rights for redistribution and usage in source and binary forms are
6// granted according to the OpenSSL license. Warranty of any kind is
7// disclaimed.
8// ====================================================================
9
10.ident "rc4-ia64.S, Version 2.0"
11.ident "IA-64 ISA artwork by Andy Polyakov <appro@fy.chalmers.se>"
12
13// What's wrong with compiler generated code? Because of the nature of
14// C language, compiler doesn't [dare to] reorder load and stores. But
15// being memory-bound, RC4 should benefit from reorder [on in-order-
16// execution core such as IA-64]. But what can we reorder? At the very
17// least we can safely reorder references to key schedule in respect
18// to input and output streams. Secondly, from the first [close] glance
19// it appeared that it's possible to pull up some references to
20// elements of the key schedule itself. Original rationale ["prior
21// loads are not safe only for "degenerated" key schedule, when some
22// elements equal to the same value"] was kind of sloppy. I should have
23// formulated as it really was: if we assume that pulling up reference
24// to key[x+1] is not safe, then it would mean that key schedule would
25// "degenerate," which is never the case. The problem is that this
26// holds true in respect to references to key[x], but not to key[y].
27// Legitimate "collisions" do occur within every 256^2 bytes window.
28// Fortunately there're enough free instruction slots to keep prior
29// reference to key[x+1], detect "collision" and compensate for it.
30// All this without sacrificing a single clock cycle:-) Throughput is
31// ~210MBps on 900MHz CPU, which is is >3x faster than gcc generated
32// code and +30% - if compared to HP-UX C. Unrolling loop below should
33// give >30% on top of that...
34
35.text
36.explicit
37
38#if defined(_HPUX_SOURCE) && !defined(_LP64)
39# define ADDP addp4
40#else
41# define ADDP add
42#endif
43
44#ifndef SZ
45#define SZ 4 // this is set to sizeof(RC4_INT)
46#endif
47// SZ==4 seems to be optimal. At least SZ==8 is not any faster, not for
48// assembler implementation, while SZ==1 code is ~30% slower.
49#if SZ==1 // RC4_INT is unsigned char
50# define LDKEY ld1
51# define STKEY st1
52# define OFF 0
53#elif SZ==4 // RC4_INT is unsigned int
54# define LDKEY ld4
55# define STKEY st4
56# define OFF 2
57#elif SZ==8 // RC4_INT is unsigned long
58# define LDKEY ld8
59# define STKEY st8
60# define OFF 3
61#endif
62
63out=r8; // [expanded] output pointer
64inp=r9; // [expanded] output pointer
65prsave=r10;
66key=r28; // [expanded] pointer to RC4_KEY
67ksch=r29; // (key->data+255)[&~(sizeof(key->data)-1)]
68xx=r30;
69yy=r31;
70
71// void RC4(RC4_KEY *key,size_t len,const void *inp,void *out);
72.global RC4#
73.proc RC4#
74.align 32
75.skip 16
76RC4:
77 .prologue
78 .save ar.pfs,r2
79{ .mii; alloc r2=ar.pfs,4,12,0,16
80 .save pr,prsave
81 mov prsave=pr
82 ADDP key=0,in0 };;
83{ .mib; cmp.eq p6,p0=0,in1 // len==0?
84 .save ar.lc,r3
85 mov r3=ar.lc
86(p6) br.ret.spnt.many b0 };; // emergency exit
87
88 .body
89 .rotr dat[4],key_x[4],tx[2],rnd[2],key_y[2],ty[1];
90
91{ .mib; LDKEY xx=[key],SZ // load key->x
92 add in1=-1,in1 // adjust len for loop counter
93 nop.b 0 }
94{ .mib; ADDP inp=0,in2
95 ADDP out=0,in3
96 brp.loop.imp .Ltop,.Lexit-16 };;
97{ .mmi; LDKEY yy=[key] // load key->y
98 add ksch=SZ,key
99 mov ar.lc=in1 }
100{ .mmi; mov key_y[1]=r0 // guarantee inequality
101 // in first iteration
102 add xx=1,xx
103 mov pr.rot=1<<16 };;
104{ .mii; nop.m 0
105 dep key_x[1]=xx,r0,OFF,8
106 mov ar.ec=3 };; // note that epilogue counter
107 // is off by 1. I compensate
108 // for this at exit...
109.Ltop:
110// The loop is scheduled for 4*(n+2) spin-rate on Itanium 2, which
111// theoretically gives asymptotic performance of clock frequency
112// divided by 4 bytes per seconds, or 400MBps on 1.6GHz CPU. This is
113// for sizeof(RC4_INT)==4. For smaller RC4_INT STKEY inadvertently
114// splits the last bundle and you end up with 5*n spin-rate:-(
115// Originally the loop was scheduled for 3*n and relied on key
116// schedule to be aligned at 256*sizeof(RC4_INT) boundary. But
117// *(out++)=dat, which maps to st1, had same effect [inadvertent
118// bundle split] and holded the loop back. Rescheduling for 4*n
119// made it possible to eliminate dependence on specific alignment
120// and allow OpenSSH keep "abusing" our API. Reaching for 3*n would
121// require unrolling, sticking to variable shift instruction for
122// collecting output [to avoid starvation for integer shifter] and
123// copying of key schedule to controlled place in stack [so that
124// deposit instruction can serve as substitute for whole
125// key->data+((x&255)<<log2(sizeof(key->data[0])))]...
126{ .mmi; (p19) st1 [out]=dat[3],1 // *(out++)=dat
127 (p16) add xx=1,xx // x++
128 (p18) dep rnd[1]=rnd[1],r0,OFF,8 } // ((tx+ty)&255)<<OFF
129{ .mmi; (p16) add key_x[1]=ksch,key_x[1] // &key[xx&255]
130 (p17) add key_y[1]=ksch,key_y[1] };; // &key[yy&255]
131{ .mmi; (p16) LDKEY tx[0]=[key_x[1]] // tx=key[xx]
132 (p17) LDKEY ty[0]=[key_y[1]] // ty=key[yy]
133 (p16) dep key_x[0]=xx,r0,OFF,8 } // (xx&255)<<OFF
134{ .mmi; (p18) add rnd[1]=ksch,rnd[1] // &key[(tx+ty)&255]
135 (p16) cmp.ne.unc p20,p21=key_x[1],key_y[1] };;
136{ .mmi; (p18) LDKEY rnd[1]=[rnd[1]] // rnd=key[(tx+ty)&255]
137 (p16) ld1 dat[0]=[inp],1 } // dat=*(inp++)
138.pred.rel "mutex",p20,p21
139{ .mmi; (p21) add yy=yy,tx[1] // (p16)
140 (p20) add yy=yy,tx[0] // (p16) y+=tx
141 (p21) mov tx[0]=tx[1] };; // (p16)
142{ .mmi; (p17) STKEY [key_y[1]]=tx[1] // key[yy]=tx
143 (p17) STKEY [key_x[2]]=ty[0] // key[xx]=ty
144 (p16) dep key_y[0]=yy,r0,OFF,8 } // &key[yy&255]
145{ .mmb; (p17) add rnd[0]=tx[1],ty[0] // tx+=ty
146 (p18) xor dat[2]=dat[2],rnd[1] // dat^=rnd
147 br.ctop.sptk .Ltop };;
148.Lexit:
149{ .mib; STKEY [key]=yy,-SZ // save key->y
150 mov pr=prsave,0x1ffff
151 nop.b 0 }
152{ .mib; st1 [out]=dat[3],1 // compensate for truncated
153 // epilogue counter
154 add xx=-1,xx
155 nop.b 0 };;
156{ .mib; STKEY [key]=xx // save key->x
157 mov ar.lc=r3
158 br.ret.sptk.many b0 };;
159.endp RC4#
diff --git a/src/lib/libcrypto/rc4/rc4.c b/src/lib/libcrypto/rc4/rc4.c
new file mode 100644
index 0000000000..b39c070292
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4.c
@@ -0,0 +1,192 @@
1/* crypto/rc4/rc4.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <openssl/rc4.h>
63
64char *usage[]={
65"usage: rc4 args\n",
66"\n",
67" -in arg - input file - default stdin\n",
68" -out arg - output file - default stdout\n",
69" -key key - password\n",
70NULL
71};
72
73int main(int argc, char *argv[])
74 {
75 FILE *in=NULL,*out=NULL;
76 char *infile=NULL,*outfile=NULL,*keystr=NULL;
77 RC4_KEY key;
78 char buf[BUFSIZ];
79 int badops=0,i;
80 char **pp;
81 unsigned char md[MD5_DIGEST_LENGTH];
82
83 argc--;
84 argv++;
85 while (argc >= 1)
86 {
87 if (strcmp(*argv,"-in") == 0)
88 {
89 if (--argc < 1) goto bad;
90 infile= *(++argv);
91 }
92 else if (strcmp(*argv,"-out") == 0)
93 {
94 if (--argc < 1) goto bad;
95 outfile= *(++argv);
96 }
97 else if (strcmp(*argv,"-key") == 0)
98 {
99 if (--argc < 1) goto bad;
100 keystr= *(++argv);
101 }
102 else
103 {
104 fprintf(stderr,"unknown option %s\n",*argv);
105 badops=1;
106 break;
107 }
108 argc--;
109 argv++;
110 }
111
112 if (badops)
113 {
114bad:
115 for (pp=usage; (*pp != NULL); pp++)
116 fprintf(stderr,"%s",*pp);
117 exit(1);
118 }
119
120 if (infile == NULL)
121 in=stdin;
122 else
123 {
124 in=fopen(infile,"r");
125 if (in == NULL)
126 {
127 perror("open");
128 exit(1);
129 }
130
131 }
132 if (outfile == NULL)
133 out=stdout;
134 else
135 {
136 out=fopen(outfile,"w");
137 if (out == NULL)
138 {
139 perror("open");
140 exit(1);
141 }
142 }
143
144#ifdef OPENSSL_SYS_MSDOS
145 /* This should set the file to binary mode. */
146 {
147#include <fcntl.h>
148 setmode(fileno(in),O_BINARY);
149 setmode(fileno(out),O_BINARY);
150 }
151#endif
152
153 if (keystr == NULL)
154 { /* get key */
155 i=EVP_read_pw_string(buf,BUFSIZ,"Enter RC4 password:",0);
156 if (i != 0)
157 {
158 OPENSSL_cleanse(buf,BUFSIZ);
159 fprintf(stderr,"bad password read\n");
160 exit(1);
161 }
162 keystr=buf;
163 }
164
165 EVP_Digest((unsigned char *)keystr,(unsigned long)strlen(keystr),md,NULL,EVP_md5());
166 OPENSSL_cleanse(keystr,strlen(keystr));
167 RC4_set_key(&key,MD5_DIGEST_LENGTH,md);
168
169 for(;;)
170 {
171 i=fread(buf,1,BUFSIZ,in);
172 if (i == 0) break;
173 if (i < 0)
174 {
175 perror("read");
176 exit(1);
177 }
178 RC4(&key,(unsigned int)i,(unsigned char *)buf,
179 (unsigned char *)buf);
180 i=fwrite(buf,(unsigned int)i,1,out);
181 if (i != 1)
182 {
183 perror("write");
184 exit(1);
185 }
186 }
187 fclose(out);
188 fclose(in);
189 exit(0);
190 return(1);
191 }
192
diff --git a/src/lib/libcrypto/rc4/rc4.h b/src/lib/libcrypto/rc4/rc4.h
index 7aec04fe93..ae0cea75b8 100644
--- a/src/lib/libcrypto/rc4/rc4.h
+++ b/src/lib/libcrypto/rc4/rc4.h
@@ -59,11 +59,12 @@
59#ifndef HEADER_RC4_H 59#ifndef HEADER_RC4_H
60#define HEADER_RC4_H 60#define HEADER_RC4_H
61 61
62#include <openssl/opensslconf.h> /* OPENSSL_NO_RC4, RC4_INT */
63#ifdef OPENSSL_NO_RC4 62#ifdef OPENSSL_NO_RC4
64#error RC4 is disabled. 63#error RC4 is disabled.
65#endif 64#endif
66 65
66#include <openssl/opensslconf.h> /* RC4_INT */
67
67#ifdef __cplusplus 68#ifdef __cplusplus
68extern "C" { 69extern "C" {
69#endif 70#endif
@@ -76,6 +77,9 @@ typedef struct rc4_key_st
76 77
77 78
78const char *RC4_options(void); 79const char *RC4_options(void);
80#ifdef OPENSSL_FIPS
81void private_RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
82#endif
79void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data); 83void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data);
80void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata, 84void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
81 unsigned char *outdata); 85 unsigned char *outdata);
diff --git a/src/lib/libcrypto/rc4/rc4_enc.c b/src/lib/libcrypto/rc4/rc4_enc.c
index 0660ea60a2..d5f18a3a70 100644
--- a/src/lib/libcrypto/rc4/rc4_enc.c
+++ b/src/lib/libcrypto/rc4/rc4_enc.c
@@ -157,7 +157,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
157 if (!is_endian.little) 157 if (!is_endian.little)
158 { /* BIG-ENDIAN CASE */ 158 { /* BIG-ENDIAN CASE */
159# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1)) 159# define BESHFT(c) (((sizeof(RC4_CHUNK)-(c)-1)*8)&(sizeof(RC4_CHUNK)*8-1))
160 for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) 160 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
161 { 161 {
162 ichunk = *(RC4_CHUNK *)indata; 162 ichunk = *(RC4_CHUNK *)indata;
163 otp = RC4_STEP<<BESHFT(0); 163 otp = RC4_STEP<<BESHFT(0);
@@ -210,7 +210,7 @@ void RC4(RC4_KEY *key, unsigned long len, const unsigned char *indata,
210 else 210 else
211 { /* LITTLE-ENDIAN CASE */ 211 { /* LITTLE-ENDIAN CASE */
212# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1)) 212# define LESHFT(c) (((c)*8)&(sizeof(RC4_CHUNK)*8-1))
213 for (;len&~(sizeof(RC4_CHUNK)-1);len-=sizeof(RC4_CHUNK)) 213 for (;len&-sizeof(RC4_CHUNK);len-=sizeof(RC4_CHUNK))
214 { 214 {
215 ichunk = *(RC4_CHUNK *)indata; 215 ichunk = *(RC4_CHUNK *)indata;
216 otp = RC4_STEP; 216 otp = RC4_STEP;
diff --git a/src/lib/libcrypto/rc4/rc4_skey.c b/src/lib/libcrypto/rc4/rc4_skey.c
index 46b77ec321..60510624fd 100644
--- a/src/lib/libcrypto/rc4/rc4_skey.c
+++ b/src/lib/libcrypto/rc4/rc4_skey.c
@@ -57,10 +57,12 @@
57 */ 57 */
58 58
59#include <openssl/rc4.h> 59#include <openssl/rc4.h>
60#include <openssl/crypto.h>
61#include <openssl/fips.h>
60#include "rc4_locl.h" 62#include "rc4_locl.h"
61#include <openssl/opensslv.h> 63#include <openssl/opensslv.h>
62 64
63const char RC4_version[]="RC4" OPENSSL_VERSION_PTEXT; 65const char *RC4_version="RC4" OPENSSL_VERSION_PTEXT;
64 66
65const char *RC4_options(void) 67const char *RC4_options(void)
66 { 68 {
@@ -85,7 +87,7 @@ const char *RC4_options(void)
85 * Date: Wed, 14 Sep 1994 06:35:31 GMT 87 * Date: Wed, 14 Sep 1994 06:35:31 GMT
86 */ 88 */
87 89
88void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data) 90FIPS_NON_FIPS_VCIPHER_Init(RC4)
89 { 91 {
90 register RC4_INT tmp; 92 register RC4_INT tmp;
91 register int id1,id2; 93 register int id1,id2;
@@ -93,59 +95,26 @@ void RC4_set_key(RC4_KEY *key, int len, const unsigned char *data)
93 unsigned int i; 95 unsigned int i;
94 96
95 d= &(key->data[0]); 97 d= &(key->data[0]);
98
99 for (i=0; i<256; i++)
100 d[i]=i;
96 key->x = 0; 101 key->x = 0;
97 key->y = 0; 102 key->y = 0;
98 id1=id2=0; 103 id1=id2=0;
99 104
100#define SK_LOOP(d,n) { \ 105#define SK_LOOP(n) { \
101 tmp=d[(n)]; \ 106 tmp=d[(n)]; \
102 id2 = (data[id1] + tmp + id2) & 0xff; \ 107 id2 = (data[id1] + tmp + id2) & 0xff; \
103 if (++id1 == len) id1=0; \ 108 if (++id1 == len) id1=0; \
104 d[(n)]=d[id2]; \ 109 d[(n)]=d[id2]; \
105 d[id2]=tmp; } 110 d[id2]=tmp; }
106 111
107#if defined(OPENSSL_CPUID_OBJ) && !defined(OPENSSL_NO_ASM)
108# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
109 defined(__INTEL__) || \
110 defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64)
111 if (sizeof(RC4_INT) > 1) {
112 /*
113 * Unlike all other x86 [and x86_64] implementations,
114 * Intel P4 core [including EM64T] was found to perform
115 * poorly with wider RC4_INT. Performance improvement
116 * for IA-32 hand-coded assembler turned out to be 2.8x
117 * if re-coded for RC4_CHAR! It's however inappropriate
118 * to just switch to RC4_CHAR for x86[_64], as non-P4
119 * implementations suffer from significant performance
120 * losses then, e.g. PIII exhibits >2x deterioration,
121 * and so does Opteron. In order to assure optimal
122 * all-round performance, we detect P4 at run-time by
123 * checking upon reserved bit 20 in CPU capability
124 * vector and set up compressed key schedule, which is
125 * recognized by correspondingly updated assembler
126 * module... Bit 20 is set up by OPENSSL_ia32_cpuid.
127 *
128 * <appro@fy.chalmers.se>
129 */
130 if (OPENSSL_ia32cap_P & (1<<20)) {
131 unsigned char *cp=(unsigned char *)d;
132
133 for (i=0;i<256;i++) cp[i]=i;
134 for (i=0;i<256;i++) SK_LOOP(cp,i);
135 /* mark schedule as compressed! */
136 d[256/sizeof(RC4_INT)]=-1;
137 return;
138 }
139 }
140# endif
141#endif
142 for (i=0; i < 256; i++) d[i]=i;
143 for (i=0; i < 256; i+=4) 112 for (i=0; i < 256; i+=4)
144 { 113 {
145 SK_LOOP(d,i+0); 114 SK_LOOP(i+0);
146 SK_LOOP(d,i+1); 115 SK_LOOP(i+1);
147 SK_LOOP(d,i+2); 116 SK_LOOP(i+2);
148 SK_LOOP(d,i+3); 117 SK_LOOP(i+3);
149 } 118 }
150 } 119 }
151 120
diff --git a/src/lib/libcrypto/rc4/rc4s.cpp b/src/lib/libcrypto/rc4/rc4s.cpp
new file mode 100644
index 0000000000..3814fde997
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4s.cpp
@@ -0,0 +1,73 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/rc4.h>
36
37void main(int argc,char *argv[])
38 {
39 unsigned char buffer[1024];
40 RC4_KEY ctx;
41 unsigned long s1,s2,e1,e2;
42 unsigned char k[16];
43 unsigned long data[2];
44 unsigned char iv[8];
45 int i,num=64,numm;
46 int j=0;
47
48 if (argc >= 2)
49 num=atoi(argv[1]);
50
51 if (num == 0) num=256;
52 if (num > 1024-16) num=1024-16;
53 numm=num+8;
54
55 for (j=0; j<6; j++)
56 {
57 for (i=0; i<10; i++) /**/
58 {
59 RC4(&ctx,numm,buffer,buffer);
60 GetTSC(s1);
61 RC4(&ctx,numm,buffer,buffer);
62 GetTSC(e1);
63 GetTSC(s2);
64 RC4(&ctx,num,buffer,buffer);
65 GetTSC(e2);
66 RC4(&ctx,num,buffer,buffer);
67 }
68
69 printf("RC4 (%d bytes) %d %d (%d) - 8 bytes\n",num,
70 e1-s1,e2-s2,(e1-s1)-(e2-s2));
71 }
72 }
73
diff --git a/src/lib/libcrypto/rc4/rc4speed.c b/src/lib/libcrypto/rc4/rc4speed.c
new file mode 100644
index 0000000000..ced98c52df
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4speed.c
@@ -0,0 +1,250 @@
1/* crypto/rc4/rc4speed.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
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 */
61
62#if !defined(OPENSSL_SYS_MSDOS) && (!defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX)
63#define TIMES
64#endif
65
66#include <stdio.h>
67
68#include <openssl/e_os2.h>
69#include OPENSSL_UNISTD_IO
70OPENSSL_DECLARE_EXIT
71
72#include <signal.h>
73#ifndef _IRIX
74#include <time.h>
75#endif
76#ifdef TIMES
77#include <sys/types.h>
78#include <sys/times.h>
79#endif
80
81/* Depending on the VMS version, the tms structure is perhaps defined.
82 The __TMS macro will show if it was. If it wasn't defined, we should
83 undefine TIMES, since that tells the rest of the program how things
84 should be handled. -- Richard Levitte */
85#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
86#undef TIMES
87#endif
88
89#ifndef TIMES
90#include <sys/timeb.h>
91#endif
92
93#if defined(sun) || defined(__ultrix)
94#define _POSIX_SOURCE
95#include <limits.h>
96#include <sys/param.h>
97#endif
98
99#include <openssl/rc4.h>
100
101/* The following if from times(3) man page. It may need to be changed */
102#ifndef HZ
103#ifndef CLK_TCK
104#define HZ 100.0
105#else /* CLK_TCK */
106#define HZ ((double)CLK_TCK)
107#endif
108#endif
109
110#define BUFSIZE ((long)1024)
111long run=0;
112
113double Time_F(int s);
114#ifdef SIGALRM
115#if defined(__STDC__) || defined(sgi) || defined(_AIX)
116#define SIGRETTYPE void
117#else
118#define SIGRETTYPE int
119#endif
120
121SIGRETTYPE sig_done(int sig);
122SIGRETTYPE sig_done(int sig)
123 {
124 signal(SIGALRM,sig_done);
125 run=0;
126#ifdef LINT
127 sig=sig;
128#endif
129 }
130#endif
131
132#define START 0
133#define STOP 1
134
135double Time_F(int s)
136 {
137 double ret;
138#ifdef TIMES
139 static struct tms tstart,tend;
140
141 if (s == START)
142 {
143 times(&tstart);
144 return(0);
145 }
146 else
147 {
148 times(&tend);
149 ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
150 return((ret == 0.0)?1e-6:ret);
151 }
152#else /* !times() */
153 static struct timeb tstart,tend;
154 long i;
155
156 if (s == START)
157 {
158 ftime(&tstart);
159 return(0);
160 }
161 else
162 {
163 ftime(&tend);
164 i=(long)tend.millitm-(long)tstart.millitm;
165 ret=((double)(tend.time-tstart.time))+((double)i)/1e3;
166 return((ret == 0.0)?1e-6:ret);
167 }
168#endif
169 }
170
171int main(int argc, char **argv)
172 {
173 long count;
174 static unsigned char buf[BUFSIZE];
175 static unsigned char key[] ={
176 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
177 0xfe,0xdc,0xba,0x98,0x76,0x54,0x32,0x10,
178 };
179 RC4_KEY sch;
180 double a,b,c,d;
181#ifndef SIGALRM
182 long ca,cb,cc;
183#endif
184
185#ifndef TIMES
186 printf("To get the most accurate results, try to run this\n");
187 printf("program when this computer is idle.\n");
188#endif
189
190#ifndef SIGALRM
191 printf("First we calculate the approximate speed ...\n");
192 RC4_set_key(&sch,16,key);
193 count=10;
194 do {
195 long i;
196 unsigned long data[2];
197
198 count*=2;
199 Time_F(START);
200 for (i=count; i; i--)
201 RC4(&sch,8,buf,buf);
202 d=Time_F(STOP);
203 } while (d < 3.0);
204 ca=count/512;
205 cc=count*8/BUFSIZE+1;
206 printf("Doing RC4_set_key %ld times\n",ca);
207#define COND(d) (count != (d))
208#define COUNT(d) (d)
209#else
210#define COND(c) (run)
211#define COUNT(d) (count)
212 signal(SIGALRM,sig_done);
213 printf("Doing RC4_set_key for 10 seconds\n");
214 alarm(10);
215#endif
216
217 Time_F(START);
218 for (count=0,run=1; COND(ca); count+=4)
219 {
220 RC4_set_key(&sch,16,key);
221 RC4_set_key(&sch,16,key);
222 RC4_set_key(&sch,16,key);
223 RC4_set_key(&sch,16,key);
224 }
225 d=Time_F(STOP);
226 printf("%ld RC4_set_key's in %.2f seconds\n",count,d);
227 a=((double)COUNT(ca))/d;
228
229#ifdef SIGALRM
230 printf("Doing RC4 on %ld byte blocks for 10 seconds\n",BUFSIZE);
231 alarm(10);
232#else
233 printf("Doing RC4 %ld times on %ld byte blocks\n",cc,BUFSIZE);
234#endif
235 Time_F(START);
236 for (count=0,run=1; COND(cc); count++)
237 RC4(&sch,BUFSIZE,buf,buf);
238 d=Time_F(STOP);
239 printf("%ld RC4's of %ld byte blocks in %.2f second\n",
240 count,BUFSIZE,d);
241 c=((double)COUNT(cc)*BUFSIZE)/d;
242
243 printf("RC4 set_key per sec = %12.2f (%9.3fuS)\n",a,1.0e6/a);
244 printf("RC4 bytes per sec = %12.2f (%9.3fuS)\n",c,8.0e6/c);
245 exit(0);
246#if defined(LINT) || defined(OPENSSL_SYS_MSDOS)
247 return(0);
248#endif
249 }
250
diff --git a/src/lib/libcrypto/rc4/rc4test.c b/src/lib/libcrypto/rc4/rc4test.c
new file mode 100644
index 0000000000..b9d8f20975
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rc4test.c
@@ -0,0 +1,203 @@
1/* crypto/rc4/rc4test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_RC4
66int main(int argc, char *argv[])
67{
68 printf("No RC4 support\n");
69 return(0);
70}
71#else
72#include <openssl/rc4.h>
73
74static unsigned char keys[7][30]={
75 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
76 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
77 {8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
78 {4,0xef,0x01,0x23,0x45},
79 {8,0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef},
80 {4,0xef,0x01,0x23,0x45},
81 };
82
83static unsigned char data_len[7]={8,8,8,20,28,10};
84static unsigned char data[7][30]={
85 {0x01,0x23,0x45,0x67,0x89,0xab,0xcd,0xef,0xff},
86 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
87 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
88 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
89 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
90 0x00,0x00,0x00,0x00,0xff},
91 {0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
92 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
93 0x12,0x34,0x56,0x78,0x9A,0xBC,0xDE,0xF0,
94 0x12,0x34,0x56,0x78,0xff},
95 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff},
96 {0},
97 };
98
99static unsigned char output[7][30]={
100 {0x75,0xb7,0x87,0x80,0x99,0xe0,0xc5,0x96,0x00},
101 {0x74,0x94,0xc2,0xe7,0x10,0x4b,0x08,0x79,0x00},
102 {0xde,0x18,0x89,0x41,0xa3,0x37,0x5d,0x3a,0x00},
103 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,
104 0xbd,0x61,0x5a,0x11,0x62,0xe1,0xc7,0xba,
105 0x36,0xb6,0x78,0x58,0x00},
106 {0x66,0xa0,0x94,0x9f,0x8a,0xf7,0xd6,0x89,
107 0x1f,0x7f,0x83,0x2b,0xa8,0x33,0xc0,0x0c,
108 0x89,0x2e,0xbe,0x30,0x14,0x3c,0xe2,0x87,
109 0x40,0x01,0x1e,0xcf,0x00},
110 {0xd6,0xa1,0x41,0xa7,0xec,0x3c,0x38,0xdf,0xbd,0x61,0x00},
111 {0},
112 };
113
114int main(int argc, char *argv[])
115 {
116 int i,err=0;
117 int j;
118 unsigned char *p;
119 RC4_KEY key;
120 unsigned char buf[512],obuf[512];
121
122 for (i=0; i<512; i++) buf[i]=0x01;
123
124 for (i=0; i<6; i++)
125 {
126 RC4_set_key(&key,keys[i][0],&(keys[i][1]));
127 memset(obuf,0x00,sizeof(obuf));
128 RC4(&key,data_len[i],&(data[i][0]),obuf);
129 if (memcmp(obuf,output[i],data_len[i]+1) != 0)
130 {
131 printf("error calculating RC4\n");
132 printf("output:");
133 for (j=0; j<data_len[i]+1; j++)
134 printf(" %02x",obuf[j]);
135 printf("\n");
136 printf("expect:");
137 p= &(output[i][0]);
138 for (j=0; j<data_len[i]+1; j++)
139 printf(" %02x",*(p++));
140 printf("\n");
141 err++;
142 }
143 else
144 printf("test %d ok\n",i);
145 }
146 printf("test end processing ");
147 for (i=0; i<data_len[3]; i++)
148 {
149 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
150 memset(obuf,0x00,sizeof(obuf));
151 RC4(&key,i,&(data[3][0]),obuf);
152 if ((memcmp(obuf,output[3],i) != 0) || (obuf[i] != 0))
153 {
154 printf("error in RC4 length processing\n");
155 printf("output:");
156 for (j=0; j<i+1; j++)
157 printf(" %02x",obuf[j]);
158 printf("\n");
159 printf("expect:");
160 p= &(output[3][0]);
161 for (j=0; j<i; j++)
162 printf(" %02x",*(p++));
163 printf(" 00\n");
164 err++;
165 }
166 else
167 {
168 printf(".");
169 fflush(stdout);
170 }
171 }
172 printf("done\n");
173 printf("test multi-call ");
174 for (i=0; i<data_len[3]; i++)
175 {
176 RC4_set_key(&key,keys[3][0],&(keys[3][1]));
177 memset(obuf,0x00,sizeof(obuf));
178 RC4(&key,i,&(data[3][0]),obuf);
179 RC4(&key,data_len[3]-i,&(data[3][i]),&(obuf[i]));
180 if (memcmp(obuf,output[3],data_len[3]+1) != 0)
181 {
182 printf("error in RC4 multi-call processing\n");
183 printf("output:");
184 for (j=0; j<data_len[3]+1; j++)
185 printf(" %02x",obuf[j]);
186 printf("\n");
187 printf("expect:");
188 p= &(output[3][0]);
189 for (j=0; j<data_len[3]+1; j++)
190 printf(" %02x",*(p++));
191 err++;
192 }
193 else
194 {
195 printf(".");
196 fflush(stdout);
197 }
198 }
199 printf("done\n");
200 EXIT(err);
201 return(0);
202 }
203#endif
diff --git a/src/lib/libcrypto/rc4/rrc4.doc b/src/lib/libcrypto/rc4/rrc4.doc
new file mode 100644
index 0000000000..2f9a953c12
--- /dev/null
+++ b/src/lib/libcrypto/rc4/rrc4.doc
@@ -0,0 +1,278 @@
1Newsgroups: sci.crypt,alt.security,comp.security.misc,alt.privacy
2Path: ghost.dsi.unimi.it!univ-lyon1.fr!jussieu.fr!zaphod.crihan.fr!warwick!clyde.open.ac.uk!strath-cs!bnr.co.uk!bt!pipex!howland.reston.ans.net!europa.eng.gtefsd.com!MathWorks.Com!yeshua.marcam.com!charnel.ecst.csuchico.edu!csusac!csus.edu!netcom.com!sterndark
3From: sterndark@netcom.com (David Sterndark)
4Subject: RC4 Algorithm revealed.
5Message-ID: <sternCvKL4B.Hyy@netcom.com>
6Sender: sterndark@netcom.com
7Organization: NETCOM On-line Communication Services (408 261-4700 guest)
8X-Newsreader: TIN [version 1.2 PL1]
9Date: Wed, 14 Sep 1994 06:35:31 GMT
10Lines: 263
11Xref: ghost.dsi.unimi.it sci.crypt:27332 alt.security:14732 comp.security.misc:11701 alt.privacy:16026
12
13I am shocked, shocked, I tell you, shocked, to discover
14that the cypherpunks have illegaly and criminally revealed
15a crucial RSA trade secret and harmed the security of
16America by reverse engineering the RC4 algorithm and
17publishing it to the world.
18
19On Saturday morning an anonymous cypherpunk wrote:
20
21
22 SUBJECT: RC4 Source Code
23
24
25 I've tested this. It is compatible with the RC4 object module
26 that comes in the various RSA toolkits.
27
28 /* rc4.h */
29 typedef struct rc4_key
30 {
31 unsigned char state[256];
32 unsigned char x;
33 unsigned char y;
34 } rc4_key;
35 void prepare_key(unsigned char *key_data_ptr,int key_data_len,
36 rc4_key *key);
37 void rc4(unsigned char *buffer_ptr,int buffer_len,rc4_key * key);
38
39
40 /*rc4.c */
41 #include "rc4.h"
42 static void swap_byte(unsigned char *a, unsigned char *b);
43 void prepare_key(unsigned char *key_data_ptr, int key_data_len,
44 rc4_key *key)
45 {
46 unsigned char swapByte;
47 unsigned char index1;
48 unsigned char index2;
49 unsigned char* state;
50 short counter;
51
52 state = &key->state[0];
53 for(counter = 0; counter < 256; counter++)
54 state[counter] = counter;
55 key->x = 0;
56 key->y = 0;
57 index1 = 0;
58 index2 = 0;
59 for(counter = 0; counter < 256; counter++)
60 {
61 index2 = (key_data_ptr[index1] + state[counter] +
62 index2) % 256;
63 swap_byte(&state[counter], &state[index2]);
64
65 index1 = (index1 + 1) % key_data_len;
66 }
67 }
68
69 void rc4(unsigned char *buffer_ptr, int buffer_len, rc4_key *key)
70 {
71 unsigned char x;
72 unsigned char y;
73 unsigned char* state;
74 unsigned char xorIndex;
75 short counter;
76
77 x = key->x;
78 y = key->y;
79
80 state = &key->state[0];
81 for(counter = 0; counter < buffer_len; counter ++)
82 {
83 x = (x + 1) % 256;
84 y = (state[x] + y) % 256;
85 swap_byte(&state[x], &state[y]);
86
87 xorIndex = (state[x] + state[y]) % 256;
88
89 buffer_ptr[counter] ^= state[xorIndex];
90 }
91 key->x = x;
92 key->y = y;
93 }
94
95 static void swap_byte(unsigned char *a, unsigned char *b)
96 {
97 unsigned char swapByte;
98
99 swapByte = *a;
100 *a = *b;
101 *b = swapByte;
102 }
103
104
105
106Another cypherpunk, this one not anonymous, tested the
107output from this algorithm against the output from
108official RC4 object code
109
110
111 Date: Tue, 13 Sep 94 18:37:56 PDT
112 From: ekr@eit.COM (Eric Rescorla)
113 Message-Id: <9409140137.AA17743@eitech.eit.com>
114 Subject: RC4 compatibility testing
115 Cc: cypherpunks@toad.com
116
117 One data point:
118
119 I can't say anything about the internals of RC4 versus the
120 algorithm that Bill Sommerfeld is rightly calling 'Alleged RC4',
121 since I don't know anything about RC4's internals.
122
123 However, I do have a (legitimately acquired) copy of BSAFE2 and
124 so I'm able to compare the output of this algorithm to the output
125 of genuine RC4 as found in BSAFE. I chose a set of test vectors
126 and ran them through both algorithms. The algorithms appear to
127 give identical results, at least with these key/plaintext pairs.
128
129 I note that this is the algorithm _without_ Hal Finney's
130 proposed modification
131
132 (see <199409130605.XAA24133@jobe.shell.portal.com>).
133
134 The vectors I used (together with the ciphertext they produce)
135 follow at the end of this message.
136
137 -Ekr
138
139 Disclaimer: This posting does not reflect the opinions of EIT.
140
141 --------------------results follow--------------
142 Test vector 0
143 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
144 Input: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
145 0 Output: 0x75 0xb7 0x87 0x80 0x99 0xe0 0xc5 0x96
146
147 Test vector 1
148 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
149 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
150 0 Output: 0x74 0x94 0xc2 0xe7 0x10 0x4b 0x08 0x79
151
152 Test vector 2
153 Key: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
154 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
155 0 Output: 0xde 0x18 0x89 0x41 0xa3 0x37 0x5d 0x3a
156
157 Test vector 3
158 Key: 0xef 0x01 0x23 0x45
159 Input: 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00 0x00
160 0 Output: 0xd6 0xa1 0x41 0xa7 0xec 0x3c 0x38 0xdf 0xbd 0x61
161
162 Test vector 4
163 Key: 0x01 0x23 0x45 0x67 0x89 0xab 0xcd 0xef
164 Input: 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
165 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
166 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
167 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
168 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
169 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
170 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
171 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
172 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
173 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
174 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
175 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
176 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
177 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
178 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
179 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
180 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
181 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
182 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
183 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
184 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
185 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
186 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
187 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
188 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
189 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
190 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
191 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
192 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
193 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
194 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
195 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
196 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
197 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
198 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
199 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
200 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
201 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
202 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
203 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
204 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
205 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
206 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
207 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
208 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
209 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
210 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
211 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
212 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
213 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
214 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01 0x01
215 0x01
216 0 Output: 0x75 0x95 0xc3 0xe6 0x11 0x4a 0x09 0x78 0x0c 0x4a 0xd4
217 0x52 0x33 0x8e 0x1f 0xfd 0x9a 0x1b 0xe9 0x49 0x8f
218 0x81 0x3d 0x76 0x53 0x34 0x49 0xb6 0x77 0x8d 0xca
219 0xd8 0xc7 0x8a 0x8d 0x2b 0xa9 0xac 0x66 0x08 0x5d
220 0x0e 0x53 0xd5 0x9c 0x26 0xc2 0xd1 0xc4 0x90 0xc1
221 0xeb 0xbe 0x0c 0xe6 0x6d 0x1b 0x6b 0x1b 0x13 0xb6
222 0xb9 0x19 0xb8 0x47 0xc2 0x5a 0x91 0x44 0x7a 0x95
223 0xe7 0x5e 0x4e 0xf1 0x67 0x79 0xcd 0xe8 0xbf 0x0a
224 0x95 0x85 0x0e 0x32 0xaf 0x96 0x89 0x44 0x4f 0xd3
225 0x77 0x10 0x8f 0x98 0xfd 0xcb 0xd4 0xe7 0x26 0x56
226 0x75 0x00 0x99 0x0b 0xcc 0x7e 0x0c 0xa3 0xc4 0xaa
227 0xa3 0x04 0xa3 0x87 0xd2 0x0f 0x3b 0x8f 0xbb 0xcd
228 0x42 0xa1 0xbd 0x31 0x1d 0x7a 0x43 0x03 0xdd 0xa5
229 0xab 0x07 0x88 0x96 0xae 0x80 0xc1 0x8b 0x0a 0xf6
230 0x6d 0xff 0x31 0x96 0x16 0xeb 0x78 0x4e 0x49 0x5a
231 0xd2 0xce 0x90 0xd7 0xf7 0x72 0xa8 0x17 0x47 0xb6
232 0x5f 0x62 0x09 0x3b 0x1e 0x0d 0xb9 0xe5 0xba 0x53
233 0x2f 0xaf 0xec 0x47 0x50 0x83 0x23 0xe6 0x71 0x32
234 0x7d 0xf9 0x44 0x44 0x32 0xcb 0x73 0x67 0xce 0xc8
235 0x2f 0x5d 0x44 0xc0 0xd0 0x0b 0x67 0xd6 0x50 0xa0
236 0x75 0xcd 0x4b 0x70 0xde 0xdd 0x77 0xeb 0x9b 0x10
237 0x23 0x1b 0x6b 0x5b 0x74 0x13 0x47 0x39 0x6d 0x62
238 0x89 0x74 0x21 0xd4 0x3d 0xf9 0xb4 0x2e 0x44 0x6e
239 0x35 0x8e 0x9c 0x11 0xa9 0xb2 0x18 0x4e 0xcb 0xef
240 0x0c 0xd8 0xe7 0xa8 0x77 0xef 0x96 0x8f 0x13 0x90
241 0xec 0x9b 0x3d 0x35 0xa5 0x58 0x5c 0xb0 0x09 0x29
242 0x0e 0x2f 0xcd 0xe7 0xb5 0xec 0x66 0xd9 0x08 0x4b
243 0xe4 0x40 0x55 0xa6 0x19 0xd9 0xdd 0x7f 0xc3 0x16
244 0x6f 0x94 0x87 0xf7 0xcb 0x27 0x29 0x12 0x42 0x64
245 0x45 0x99 0x85 0x14 0xc1 0x5d 0x53 0xa1 0x8c 0x86
246 0x4c 0xe3 0xa2 0xb7 0x55 0x57 0x93 0x98 0x81 0x26
247 0x52 0x0e 0xac 0xf2 0xe3 0x06 0x6e 0x23 0x0c 0x91
248 0xbe 0xe4 0xdd 0x53 0x04 0xf5 0xfd 0x04 0x05 0xb3
249 0x5b 0xd9 0x9c 0x73 0x13 0x5d 0x3d 0x9b 0xc3 0x35
250 0xee 0x04 0x9e 0xf6 0x9b 0x38 0x67 0xbf 0x2d 0x7b
251 0xd1 0xea 0xa5 0x95 0xd8 0xbf 0xc0 0x06 0x6f 0xf8
252 0xd3 0x15 0x09 0xeb 0x0c 0x6c 0xaa 0x00 0x6c 0x80
253 0x7a 0x62 0x3e 0xf8 0x4c 0x3d 0x33 0xc1 0x95 0xd2
254 0x3e 0xe3 0x20 0xc4 0x0d 0xe0 0x55 0x81 0x57 0xc8
255 0x22 0xd4 0xb8 0xc5 0x69 0xd8 0x49 0xae 0xd5 0x9d
256 0x4e 0x0f 0xd7 0xf3 0x79 0x58 0x6b 0x4b 0x7f 0xf6
257 0x84 0xed 0x6a 0x18 0x9f 0x74 0x86 0xd4 0x9b 0x9c
258 0x4b 0xad 0x9b 0xa2 0x4b 0x96 0xab 0xf9 0x24 0x37
259 0x2c 0x8a 0x8f 0xff 0xb1 0x0d 0x55 0x35 0x49 0x00
260 0xa7 0x7a 0x3d 0xb5 0xf2 0x05 0xe1 0xb9 0x9f 0xcd
261 0x86 0x60 0x86 0x3a 0x15 0x9a 0xd4 0xab 0xe4 0x0f
262 0xa4 0x89 0x34 0x16 0x3d 0xdd 0xe5 0x42 0xa6 0x58
263 0x55 0x40 0xfd 0x68 0x3c 0xbf 0xd8 0xc0 0x0f 0x12
264 0x12 0x9a 0x28 0x4d 0xea 0xcc 0x4c 0xde 0xfe 0x58
265 0xbe 0x71 0x37 0x54 0x1c 0x04 0x71 0x26 0xc8 0xd4
266 0x9e 0x27 0x55 0xab 0x18 0x1a 0xb7 0xe9 0x40 0xb0
267 0xc0
268
269
270
271--
272 ---------------------------------------------------------------------
273We have the right to defend ourselves and our
274property, because of the kind of animals that we James A. Donald
275are. True law derives from this right, not from
276the arbitrary power of the omnipotent state. jamesd@netcom.com
277
278
diff --git a/src/lib/libcrypto/rc5/Makefile b/src/lib/libcrypto/rc5/Makefile
new file mode 100644
index 0000000000..efb0f36b59
--- /dev/null
+++ b/src/lib/libcrypto/rc5/Makefile
@@ -0,0 +1,103 @@
1#
2# OpenSSL/crypto/rc5/Makefile
3#
4
5DIR= rc5
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14RC5_ENC= rc5_enc.o
15# or use
16#DES_ENC= r586-elf.o
17
18CFLAGS= $(INCLUDES) $(CFLAG)
19ASFLAGS= $(INCLUDES) $(ASFLAG)
20AFLAGS= $(ASFLAGS)
21
22GENERAL=Makefile
23TEST=rc5test.c
24APPS=
25
26LIB=$(TOP)/libcrypto.a
27LIBSRC=rc5_skey.c rc5_ecb.c rc5_enc.c rc5cfb64.c rc5ofb64.c
28LIBOBJ=rc5_skey.o rc5_ecb.o $(RC5_ENC) rc5cfb64.o rc5ofb64.o
29
30SRC= $(LIBSRC)
31
32EXHEADER= rc5.h
33HEADER= rc5_locl.h $(EXHEADER)
34
35ALL= $(GENERAL) $(SRC) $(HEADER)
36
37top:
38 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
39
40all: lib
41
42lib: $(LIBOBJ)
43 $(AR) $(LIB) $(LIBOBJ)
44 $(RANLIB) $(LIB) || echo Never mind.
45 @touch lib
46
47# ELF
48r586-elf.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
49 (cd asm; $(PERL) rc5-586.pl elf $(CFLAGS) > ../$@)
50# COFF
51r586-cof.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
52 (cd asm; $(PERL) rc5-586.pl coff $(CFLAGS) > ../$@)
53# a.out
54r586-out.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
55 (cd asm; $(PERL) rc5-586.pl a.out $(CFLAGS) > ../$@)
56
57files:
58 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
59
60links:
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65install:
66 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
67 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
68 do \
69 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
70 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
71 done;
72
73tags:
74 ctags $(SRC)
75
76tests:
77
78lint:
79 lint -DLINT $(INCLUDES) $(SRC)>fluff
80
81depend:
82 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
83 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
84
85dclean:
86 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
87 mv -f Makefile.new $(MAKEFILE)
88
89clean:
90 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
91
92# DO NOT DELETE THIS LINE -- make depend depends on it.
93
94rc5_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
95rc5_ecb.o: ../../include/openssl/rc5.h rc5_ecb.c rc5_locl.h
96rc5_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc5.h
97rc5_enc.o: rc5_enc.c rc5_locl.h
98rc5_skey.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc5.h
99rc5_skey.o: rc5_locl.h rc5_skey.c
100rc5cfb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc5.h
101rc5cfb64.o: rc5_locl.h rc5cfb64.c
102rc5ofb64.o: ../../include/openssl/opensslconf.h ../../include/openssl/rc5.h
103rc5ofb64.o: rc5_locl.h rc5ofb64.c
diff --git a/src/lib/libcrypto/rc5/Makefile.ssl b/src/lib/libcrypto/rc5/Makefile.ssl
new file mode 100644
index 0000000000..3f9632f8f7
--- /dev/null
+++ b/src/lib/libcrypto/rc5/Makefile.ssl
@@ -0,0 +1,108 @@
1#
2# SSLeay/crypto/rc5/Makefile
3#
4
5DIR= rc5
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20RC5_ENC= rc5_enc.o
21# or use
22#DES_ENC= r586-elf.o
23
24CFLAGS= $(INCLUDES) $(CFLAG)
25ASFLAGS= $(INCLUDES) $(ASFLAG)
26
27GENERAL=Makefile
28TEST=rc5test.c
29APPS=
30
31LIB=$(TOP)/libcrypto.a
32LIBSRC=rc5_skey.c rc5_ecb.c rc5_enc.c rc5cfb64.c rc5ofb64.c
33LIBOBJ=rc5_skey.o rc5_ecb.o $(RC5_ENC) rc5cfb64.o rc5ofb64.o
34
35SRC= $(LIBSRC)
36
37EXHEADER= rc5.h
38HEADER= rc5_locl.h $(EXHEADER)
39
40ALL= $(GENERAL) $(SRC) $(HEADER)
41
42top:
43 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
44
45all: lib
46
47lib: $(LIBOBJ)
48 $(AR) $(LIB) $(LIBOBJ)
49 $(RANLIB) $(LIB) || echo Never mind.
50 @touch lib
51
52# elf
53asm/r586-elf.s: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
54 (cd asm; $(PERL) rc5-586.pl elf $(CFLAGS) > r586-elf.s)
55
56# a.out
57asm/r586-out.o: asm/r586unix.cpp
58 $(CPP) -DOUT asm/r586unix.cpp | as -o asm/r586-out.o
59
60# bsdi
61asm/r586bsdi.o: asm/r586unix.cpp
62 $(CPP) -DBSDI asm/r586unix.cpp | sed 's/ :/:/' | as -o asm/r586bsdi.o
63
64asm/r586unix.cpp: asm/rc5-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl
65 (cd asm; $(PERL) rc5-586.pl cpp >r586unix.cpp)
66
67files:
68 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
69
70links:
71 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
72 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
73 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
74 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
75
76install:
77 @for i in $(EXHEADER) ; \
78 do \
79 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
80 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
81 done;
82
83tags:
84 ctags $(SRC)
85
86tests:
87
88lint:
89 lint -DLINT $(INCLUDES) $(SRC)>fluff
90
91depend:
92 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
93
94dclean:
95 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
96 mv -f Makefile.new $(MAKEFILE)
97
98clean:
99 rm -f asm/r586unix.cpp asm/*-elf.* *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
100
101# DO NOT DELETE THIS LINE -- make depend depends on it.
102
103rc5_ecb.o: ../../include/openssl/opensslv.h ../../include/openssl/rc5.h
104rc5_ecb.o: rc5_ecb.c rc5_locl.h
105rc5_enc.o: ../../include/openssl/rc5.h rc5_enc.c rc5_locl.h
106rc5_skey.o: ../../include/openssl/rc5.h rc5_locl.h rc5_skey.c
107rc5cfb64.o: ../../include/openssl/rc5.h rc5_locl.h rc5cfb64.c
108rc5ofb64.o: ../../include/openssl/rc5.h rc5_locl.h rc5ofb64.c
diff --git a/src/lib/libcrypto/rc5/rc5.h b/src/lib/libcrypto/rc5/rc5.h
new file mode 100644
index 0000000000..aa3f26920b
--- /dev/null
+++ b/src/lib/libcrypto/rc5/rc5.h
@@ -0,0 +1,119 @@
1/* crypto/rc5/rc5.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#ifndef HEADER_RC5_H
60#define HEADER_RC5_H
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
66#ifdef OPENSSL_NO_RC5
67#error RC5 is disabled.
68#endif
69
70#define RC5_ENCRYPT 1
71#define RC5_DECRYPT 0
72
73/* 32 bit. For Alpha, things may get weird */
74#define RC5_32_INT unsigned long
75
76#define RC5_32_BLOCK 8
77#define RC5_32_KEY_LENGTH 16 /* This is a default, max is 255 */
78
79/* This are the only values supported. Tweak the code if you want more
80 * The most supported modes will be
81 * RC5-32/12/16
82 * RC5-32/16/8
83 */
84#define RC5_8_ROUNDS 8
85#define RC5_12_ROUNDS 12
86#define RC5_16_ROUNDS 16
87
88typedef struct rc5_key_st
89 {
90 /* Number of rounds */
91 int rounds;
92 RC5_32_INT data[2*(RC5_16_ROUNDS+1)];
93 } RC5_32_KEY;
94
95#ifdef OPENSSL_FIPS
96void private_RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
97 int rounds);
98#endif
99void RC5_32_set_key(RC5_32_KEY *key, int len, const unsigned char *data,
100 int rounds);
101void RC5_32_ecb_encrypt(const unsigned char *in,unsigned char *out,RC5_32_KEY *key,
102 int enc);
103void RC5_32_encrypt(unsigned long *data,RC5_32_KEY *key);
104void RC5_32_decrypt(unsigned long *data,RC5_32_KEY *key);
105void RC5_32_cbc_encrypt(const unsigned char *in, unsigned char *out,
106 long length, RC5_32_KEY *ks, unsigned char *iv,
107 int enc);
108void RC5_32_cfb64_encrypt(const unsigned char *in, unsigned char *out,
109 long length, RC5_32_KEY *schedule,
110 unsigned char *ivec, int *num, int enc);
111void RC5_32_ofb64_encrypt(const unsigned char *in, unsigned char *out,
112 long length, RC5_32_KEY *schedule,
113 unsigned char *ivec, int *num);
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif
diff --git a/src/lib/libcrypto/rc5/rc5_locl.h b/src/lib/libcrypto/rc5/rc5_locl.h
new file mode 100644
index 0000000000..282dd38822
--- /dev/null
+++ b/src/lib/libcrypto/rc5/rc5_locl.h
@@ -0,0 +1,207 @@
1/* crypto/rc5/rc5_locl.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdlib.h>
60
61#undef c2l
62#define c2l(c,l) (l =((unsigned long)(*((c)++))) , \
63 l|=((unsigned long)(*((c)++)))<< 8L, \
64 l|=((unsigned long)(*((c)++)))<<16L, \
65 l|=((unsigned long)(*((c)++)))<<24L)
66
67/* NOTE - c is not incremented as per c2l */
68#undef c2ln
69#define c2ln(c,l1,l2,n) { \
70 c+=n; \
71 l1=l2=0; \
72 switch (n) { \
73 case 8: l2 =((unsigned long)(*(--(c))))<<24L; \
74 case 7: l2|=((unsigned long)(*(--(c))))<<16L; \
75 case 6: l2|=((unsigned long)(*(--(c))))<< 8L; \
76 case 5: l2|=((unsigned long)(*(--(c)))); \
77 case 4: l1 =((unsigned long)(*(--(c))))<<24L; \
78 case 3: l1|=((unsigned long)(*(--(c))))<<16L; \
79 case 2: l1|=((unsigned long)(*(--(c))))<< 8L; \
80 case 1: l1|=((unsigned long)(*(--(c)))); \
81 } \
82 }
83
84#undef l2c
85#define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \
86 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
87 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
88 *((c)++)=(unsigned char)(((l)>>24L)&0xff))
89
90/* NOTE - c is not incremented as per l2c */
91#undef l2cn
92#define l2cn(l1,l2,c,n) { \
93 c+=n; \
94 switch (n) { \
95 case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \
96 case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \
97 case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \
98 case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \
99 case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \
100 case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \
101 case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \
102 case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \
103 } \
104 }
105
106/* NOTE - c is not incremented as per n2l */
107#define n2ln(c,l1,l2,n) { \
108 c+=n; \
109 l1=l2=0; \
110 switch (n) { \
111 case 8: l2 =((unsigned long)(*(--(c)))) ; \
112 case 7: l2|=((unsigned long)(*(--(c))))<< 8; \
113 case 6: l2|=((unsigned long)(*(--(c))))<<16; \
114 case 5: l2|=((unsigned long)(*(--(c))))<<24; \
115 case 4: l1 =((unsigned long)(*(--(c)))) ; \
116 case 3: l1|=((unsigned long)(*(--(c))))<< 8; \
117 case 2: l1|=((unsigned long)(*(--(c))))<<16; \
118 case 1: l1|=((unsigned long)(*(--(c))))<<24; \
119 } \
120 }
121
122/* NOTE - c is not incremented as per l2n */
123#define l2nn(l1,l2,c,n) { \
124 c+=n; \
125 switch (n) { \
126 case 8: *(--(c))=(unsigned char)(((l2) )&0xff); \
127 case 7: *(--(c))=(unsigned char)(((l2)>> 8)&0xff); \
128 case 6: *(--(c))=(unsigned char)(((l2)>>16)&0xff); \
129 case 5: *(--(c))=(unsigned char)(((l2)>>24)&0xff); \
130 case 4: *(--(c))=(unsigned char)(((l1) )&0xff); \
131 case 3: *(--(c))=(unsigned char)(((l1)>> 8)&0xff); \
132 case 2: *(--(c))=(unsigned char)(((l1)>>16)&0xff); \
133 case 1: *(--(c))=(unsigned char)(((l1)>>24)&0xff); \
134 } \
135 }
136
137#undef n2l
138#define n2l(c,l) (l =((unsigned long)(*((c)++)))<<24L, \
139 l|=((unsigned long)(*((c)++)))<<16L, \
140 l|=((unsigned long)(*((c)++)))<< 8L, \
141 l|=((unsigned long)(*((c)++))))
142
143#undef l2n
144#define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \
145 *((c)++)=(unsigned char)(((l)>>16L)&0xff), \
146 *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \
147 *((c)++)=(unsigned char)(((l) )&0xff))
148
149#if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)) || defined(__ICC)
150#define ROTATE_l32(a,n) _lrotl(a,n)
151#define ROTATE_r32(a,n) _lrotr(a,n)
152#elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC)
153# if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__)
154# define ROTATE_l32(a,n) ({ register unsigned int ret; \
155 asm ("roll %%cl,%0" \
156 : "=r"(ret) \
157 : "c"(n),"0"(a) \
158 : "cc"); \
159 ret; \
160 })
161# define ROTATE_r32(a,n) ({ register unsigned int ret; \
162 asm ("rorl %%cl,%0" \
163 : "=r"(ret) \
164 : "c"(n),"0"(a) \
165 : "cc"); \
166 ret; \
167 })
168# endif
169#endif
170#ifndef ROTATE_l32
171#define ROTATE_l32(a,n) (((a)<<(n&0x1f))|(((a)&0xffffffff)>>(32-(n&0x1f))))
172#endif
173#ifndef ROTATE_r32
174#define ROTATE_r32(a,n) (((a)<<(32-(n&0x1f)))|(((a)&0xffffffff)>>(n&0x1f)))
175#endif
176
177#define RC5_32_MASK 0xffffffffL
178
179#define RC5_16_P 0xB7E1
180#define RC5_16_Q 0x9E37
181#define RC5_32_P 0xB7E15163L
182#define RC5_32_Q 0x9E3779B9L
183#define RC5_64_P 0xB7E151628AED2A6BLL
184#define RC5_64_Q 0x9E3779B97F4A7C15LL
185
186#define E_RC5_32(a,b,s,n) \
187 a^=b; \
188 a=ROTATE_l32(a,b); \
189 a+=s[n]; \
190 a&=RC5_32_MASK; \
191 b^=a; \
192 b=ROTATE_l32(b,a); \
193 b+=s[n+1]; \
194 b&=RC5_32_MASK;
195
196#define D_RC5_32(a,b,s,n) \
197 b-=s[n+1]; \
198 b&=RC5_32_MASK; \
199 b=ROTATE_r32(b,a); \
200 b^=a; \
201 a-=s[n]; \
202 a&=RC5_32_MASK; \
203 a=ROTATE_r32(a,b); \
204 a^=b;
205
206
207
diff --git a/src/lib/libcrypto/rc5/rc5s.cpp b/src/lib/libcrypto/rc5/rc5s.cpp
new file mode 100644
index 0000000000..1c5518bc80
--- /dev/null
+++ b/src/lib/libcrypto/rc5/rc5s.cpp
@@ -0,0 +1,70 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/rc5.h>
36
37void main(int argc,char *argv[])
38 {
39 RC5_32_KEY key;
40 unsigned long s1,s2,e1,e2;
41 unsigned long data[2];
42 int i,j;
43 static unsigned char d[16]={0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF};
44
45 RC5_32_set_key(&key, 16,d,12);
46
47 for (j=0; j<6; j++)
48 {
49 for (i=0; i<1000; i++) /**/
50 {
51 RC5_32_encrypt(&data[0],&key);
52 GetTSC(s1);
53 RC5_32_encrypt(&data[0],&key);
54 RC5_32_encrypt(&data[0],&key);
55 RC5_32_encrypt(&data[0],&key);
56 GetTSC(e1);
57 GetTSC(s2);
58 RC5_32_encrypt(&data[0],&key);
59 RC5_32_encrypt(&data[0],&key);
60 RC5_32_encrypt(&data[0],&key);
61 RC5_32_encrypt(&data[0],&key);
62 GetTSC(e2);
63 RC5_32_encrypt(&data[0],&key);
64 }
65
66 printf("cast %d %d (%d)\n",
67 e1-s1,e2-s2,((e2-s2)-(e1-s1)));
68 }
69 }
70
diff --git a/src/lib/libcrypto/rc5/rc5test.c b/src/lib/libcrypto/rc5/rc5test.c
new file mode 100644
index 0000000000..ce3d0cc16f
--- /dev/null
+++ b/src/lib/libcrypto/rc5/rc5test.c
@@ -0,0 +1,386 @@
1/* crypto/rc5/rc5test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. 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 has been a quickly hacked 'ideatest.c'. When I add tests for other
60 * RC5 modes, more of the code will be uncommented. */
61
62#include <stdio.h>
63#include <string.h>
64#include <stdlib.h>
65
66#include "../e_os.h"
67
68#ifdef OPENSSL_NO_RC5
69int main(int argc, char *argv[])
70{
71 printf("No RC5 support\n");
72 return(0);
73}
74#else
75#include <openssl/rc5.h>
76
77static unsigned char RC5key[5][16]={
78 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
79 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
80 {0x91,0x5f,0x46,0x19,0xbe,0x41,0xb2,0x51,
81 0x63,0x55,0xa5,0x01,0x10,0xa9,0xce,0x91},
82 {0x78,0x33,0x48,0xe7,0x5a,0xeb,0x0f,0x2f,
83 0xd7,0xb1,0x69,0xbb,0x8d,0xc1,0x67,0x87},
84 {0xdc,0x49,0xdb,0x13,0x75,0xa5,0x58,0x4f,
85 0x64,0x85,0xb4,0x13,0xb5,0xf1,0x2b,0xaf},
86 {0x52,0x69,0xf1,0x49,0xd4,0x1b,0xa0,0x15,
87 0x24,0x97,0x57,0x4d,0x7f,0x15,0x31,0x25},
88 };
89
90static unsigned char RC5plain[5][8]={
91 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
92 {0x21,0xA5,0xDB,0xEE,0x15,0x4B,0x8F,0x6D},
93 {0xF7,0xC0,0x13,0xAC,0x5B,0x2B,0x89,0x52},
94 {0x2F,0x42,0xB3,0xB7,0x03,0x69,0xFC,0x92},
95 {0x65,0xC1,0x78,0xB2,0x84,0xD1,0x97,0xCC},
96 };
97
98static unsigned char RC5cipher[5][8]={
99 {0x21,0xA5,0xDB,0xEE,0x15,0x4B,0x8F,0x6D},
100 {0xF7,0xC0,0x13,0xAC,0x5B,0x2B,0x89,0x52},
101 {0x2F,0x42,0xB3,0xB7,0x03,0x69,0xFC,0x92},
102 {0x65,0xC1,0x78,0xB2,0x84,0xD1,0x97,0xCC},
103 {0xEB,0x44,0xE4,0x15,0xDA,0x31,0x98,0x24},
104 };
105
106#define RC5_CBC_NUM 27
107static unsigned char rc5_cbc_cipher[RC5_CBC_NUM][8]={
108 {0x7a,0x7b,0xba,0x4d,0x79,0x11,0x1d,0x1e},
109 {0x79,0x7b,0xba,0x4d,0x78,0x11,0x1d,0x1e},
110 {0x7a,0x7b,0xba,0x4d,0x79,0x11,0x1d,0x1f},
111 {0x7a,0x7b,0xba,0x4d,0x79,0x11,0x1d,0x1f},
112 {0x8b,0x9d,0xed,0x91,0xce,0x77,0x94,0xa6},
113 {0x2f,0x75,0x9f,0xe7,0xad,0x86,0xa3,0x78},
114 {0xdc,0xa2,0x69,0x4b,0xf4,0x0e,0x07,0x88},
115 {0xdc,0xa2,0x69,0x4b,0xf4,0x0e,0x07,0x88},
116 {0xdc,0xfe,0x09,0x85,0x77,0xec,0xa5,0xff},
117 {0x96,0x46,0xfb,0x77,0x63,0x8f,0x9c,0xa8},
118 {0xb2,0xb3,0x20,0x9d,0xb6,0x59,0x4d,0xa4},
119 {0x54,0x5f,0x7f,0x32,0xa5,0xfc,0x38,0x36},
120 {0x82,0x85,0xe7,0xc1,0xb5,0xbc,0x74,0x02},
121 {0xfc,0x58,0x6f,0x92,0xf7,0x08,0x09,0x34},
122 {0xcf,0x27,0x0e,0xf9,0x71,0x7f,0xf7,0xc4},
123 {0xe4,0x93,0xf1,0xc1,0xbb,0x4d,0x6e,0x8c},
124 {0x5c,0x4c,0x04,0x1e,0x0f,0x21,0x7a,0xc3},
125 {0x92,0x1f,0x12,0x48,0x53,0x73,0xb4,0xf7},
126 {0x5b,0xa0,0xca,0x6b,0xbe,0x7f,0x5f,0xad},
127 {0xc5,0x33,0x77,0x1c,0xd0,0x11,0x0e,0x63},
128 {0x29,0x4d,0xdb,0x46,0xb3,0x27,0x8d,0x60},
129 {0xda,0xd6,0xbd,0xa9,0xdf,0xe8,0xf7,0xe8},
130 {0x97,0xe0,0x78,0x78,0x37,0xed,0x31,0x7f},
131 {0x78,0x75,0xdb,0xf6,0x73,0x8c,0x64,0x78},
132 {0x8f,0x34,0xc3,0xc6,0x81,0xc9,0x96,0x95},
133 {0x7c,0xb3,0xf1,0xdf,0x34,0xf9,0x48,0x11},
134 {0x7f,0xd1,0xa0,0x23,0xa5,0xbb,0xa2,0x17},
135 };
136
137static unsigned char rc5_cbc_key[RC5_CBC_NUM][17]={
138 { 1,0x00},
139 { 1,0x00},
140 { 1,0x00},
141 { 1,0x00},
142 { 1,0x00},
143 { 1,0x11},
144 { 1,0x00},
145 { 4,0x00,0x00,0x00,0x00},
146 { 1,0x00},
147 { 1,0x00},
148 { 1,0x00},
149 { 1,0x00},
150 { 4,0x01,0x02,0x03,0x04},
151 { 4,0x01,0x02,0x03,0x04},
152 { 4,0x01,0x02,0x03,0x04},
153 { 8,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
154 { 8,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
155 { 8,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
156 { 8,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
157 {16,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
158 0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
159 {16,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
160 0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
161 {16,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
162 0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
163 { 5,0x01,0x02,0x03,0x04,0x05},
164 { 5,0x01,0x02,0x03,0x04,0x05},
165 { 5,0x01,0x02,0x03,0x04,0x05},
166 { 5,0x01,0x02,0x03,0x04,0x05},
167 { 5,0x01,0x02,0x03,0x04,0x05},
168 };
169
170static unsigned char rc5_cbc_plain[RC5_CBC_NUM][8]={
171 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
172 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
173 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
174 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
175 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
176 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
177 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
178 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
179 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
180 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
181 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
182 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
183 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
184 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
185 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
186 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
187 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
188 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
189 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
190 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
191 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
192 {0x10,0x20,0x30,0x40,0x50,0x60,0x70,0x80},
193 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
194 {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
195 {0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08},
196 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
197 {0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x01},
198 };
199
200static int rc5_cbc_rounds[RC5_CBC_NUM]={
201 0, 0, 0, 0, 0, 1, 2, 2,
202 8, 8,12,16, 8,12,16,12,
203 8,12,16, 8,12,16,12, 8,
204 8, 8, 8,
205 };
206
207static unsigned char rc5_cbc_iv[RC5_CBC_NUM][8]={
208 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
209 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
210 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01},
211 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
212 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
213 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
214 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
215 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
216 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
217 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
218 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
219 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
220 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
221 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
222 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
223 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
224 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
225 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
226 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
227 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
228 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
229 {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08},
230 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
231 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
232 {0x78,0x75,0xdb,0xf6,0x73,0x8c,0x64,0x78},
233 {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
234 {0x7c,0xb3,0xf1,0xdf,0x34,0xf9,0x48,0x11},
235 };
236
237int main(int argc, char *argv[])
238 {
239 int i,n,err=0;
240 RC5_32_KEY key;
241 unsigned char buf[8],buf2[8],ivb[8];
242
243 for (n=0; n<5; n++)
244 {
245 RC5_32_set_key(&key,16,&(RC5key[n][0]),12);
246
247 RC5_32_ecb_encrypt(&(RC5plain[n][0]),buf,&key,RC5_ENCRYPT);
248 if (memcmp(&(RC5cipher[n][0]),buf,8) != 0)
249 {
250 printf("ecb RC5 error encrypting (%d)\n",n+1);
251 printf("got :");
252 for (i=0; i<8; i++)
253 printf("%02X ",buf[i]);
254 printf("\n");
255 printf("expected:");
256 for (i=0; i<8; i++)
257 printf("%02X ",RC5cipher[n][i]);
258 err=20;
259 printf("\n");
260 }
261
262 RC5_32_ecb_encrypt(buf,buf2,&key,RC5_DECRYPT);
263 if (memcmp(&(RC5plain[n][0]),buf2,8) != 0)
264 {
265 printf("ecb RC5 error decrypting (%d)\n",n+1);
266 printf("got :");
267 for (i=0; i<8; i++)
268 printf("%02X ",buf2[i]);
269 printf("\n");
270 printf("expected:");
271 for (i=0; i<8; i++)
272 printf("%02X ",RC5plain[n][i]);
273 printf("\n");
274 err=3;
275 }
276 }
277 if (err == 0) printf("ecb RC5 ok\n");
278
279 for (n=0; n<RC5_CBC_NUM; n++)
280 {
281 i=rc5_cbc_rounds[n];
282 if (i < 8) continue;
283
284 RC5_32_set_key(&key,rc5_cbc_key[n][0],&(rc5_cbc_key[n][1]),i);
285
286 memcpy(ivb,&(rc5_cbc_iv[n][0]),8);
287 RC5_32_cbc_encrypt(&(rc5_cbc_plain[n][0]),buf,8,
288 &key,&(ivb[0]),RC5_ENCRYPT);
289
290 if (memcmp(&(rc5_cbc_cipher[n][0]),buf,8) != 0)
291 {
292 printf("cbc RC5 error encrypting (%d)\n",n+1);
293 printf("got :");
294 for (i=0; i<8; i++)
295 printf("%02X ",buf[i]);
296 printf("\n");
297 printf("expected:");
298 for (i=0; i<8; i++)
299 printf("%02X ",rc5_cbc_cipher[n][i]);
300 err=30;
301 printf("\n");
302 }
303
304 memcpy(ivb,&(rc5_cbc_iv[n][0]),8);
305 RC5_32_cbc_encrypt(buf,buf2,8,
306 &key,&(ivb[0]),RC5_DECRYPT);
307 if (memcmp(&(rc5_cbc_plain[n][0]),buf2,8) != 0)
308 {
309 printf("cbc RC5 error decrypting (%d)\n",n+1);
310 printf("got :");
311 for (i=0; i<8; i++)
312 printf("%02X ",buf2[i]);
313 printf("\n");
314 printf("expected:");
315 for (i=0; i<8; i++)
316 printf("%02X ",rc5_cbc_plain[n][i]);
317 printf("\n");
318 err=3;
319 }
320 }
321 if (err == 0) printf("cbc RC5 ok\n");
322
323 EXIT(err);
324 return(err);
325 }
326
327#ifdef undef
328static int cfb64_test(unsigned char *cfb_cipher)
329 {
330 IDEA_KEY_SCHEDULE eks,dks;
331 int err=0,i,n;
332
333 idea_set_encrypt_key(cfb_key,&eks);
334 idea_set_decrypt_key(&eks,&dks);
335 memcpy(cfb_tmp,cfb_iv,8);
336 n=0;
337 idea_cfb64_encrypt(plain,cfb_buf1,(long)12,&eks,
338 cfb_tmp,&n,IDEA_ENCRYPT);
339 idea_cfb64_encrypt(&(plain[12]),&(cfb_buf1[12]),
340 (long)CFB_TEST_SIZE-12,&eks,
341 cfb_tmp,&n,IDEA_ENCRYPT);
342 if (memcmp(cfb_cipher,cfb_buf1,CFB_TEST_SIZE) != 0)
343 {
344 err=1;
345 printf("idea_cfb64_encrypt encrypt error\n");
346 for (i=0; i<CFB_TEST_SIZE; i+=8)
347 printf("%s\n",pt(&(cfb_buf1[i])));
348 }
349 memcpy(cfb_tmp,cfb_iv,8);
350 n=0;
351 idea_cfb64_encrypt(cfb_buf1,cfb_buf2,(long)17,&eks,
352 cfb_tmp,&n,IDEA_DECRYPT);
353 idea_cfb64_encrypt(&(cfb_buf1[17]),&(cfb_buf2[17]),
354 (long)CFB_TEST_SIZE-17,&dks,
355 cfb_tmp,&n,IDEA_DECRYPT);
356 if (memcmp(plain,cfb_buf2,CFB_TEST_SIZE) != 0)
357 {
358 err=1;
359 printf("idea_cfb_encrypt decrypt error\n");
360 for (i=0; i<24; i+=8)
361 printf("%s\n",pt(&(cfb_buf2[i])));
362 }
363 return(err);
364 }
365
366static char *pt(unsigned char *p)
367 {
368 static char bufs[10][20];
369 static int bnum=0;
370 char *ret;
371 int i;
372 static char *f="0123456789ABCDEF";
373
374 ret= &(bufs[bnum++][0]);
375 bnum%=10;
376 for (i=0; i<8; i++)
377 {
378 ret[i*2]=f[(p[i]>>4)&0xf];
379 ret[i*2+1]=f[p[i]&0xf];
380 }
381 ret[16]='\0';
382 return(ret);
383 }
384
385#endif
386#endif
diff --git a/src/lib/libcrypto/ripemd/Makefile b/src/lib/libcrypto/ripemd/Makefile
new file mode 100644
index 0000000000..d55875c20c
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/Makefile
@@ -0,0 +1,99 @@
1#
2# OpenSSL/crypto/ripemd/Makefile
3#
4
5DIR= ripemd
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14RIP_ASM_OBJ=
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21TEST=rmdtest.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=rmd_dgst.c rmd_one.c
26LIBOBJ=rmd_dgst.o rmd_one.o $(RMD160_ASM_OBJ)
27
28SRC= $(LIBSRC)
29
30EXHEADER= ripemd.h
31HEADER= rmd_locl.h rmdconst.h $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45# ELF
46rm86-elf.s: asm/rmd-586.pl ../perlasm/x86asm.pl
47 (cd asm; $(PERL) rmd-586.pl elf $(CFLAGS) > ../$@)
48# COFF
49rm86-cof.s: asm/rmd-586.pl ../perlasm/x86asm.pl
50 (cd asm; $(PERL) rmd-586.pl coff $(CFLAGS) > ../$@)
51# a.out
52rm86-out.s: asm/rmd-586.pl ../perlasm/x86asm.pl
53 (cd asm; $(PERL) rmd-586.pl a.out $(CFLAGS) > ../$@)
54
55files:
56 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
57
58links:
59 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
60 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
61 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
62
63install:
64 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
65 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
66 do \
67 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
68 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
69 done;
70
71tags:
72 ctags $(SRC)
73
74tests:
75
76lint:
77 lint -DLINT $(INCLUDES) $(SRC)>fluff
78
79depend:
80 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
81 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
82
83dclean:
84 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
85 mv -f Makefile.new $(MAKEFILE)
86
87clean:
88 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
89
90# DO NOT DELETE THIS LINE -- make depend depends on it.
91
92rmd_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
93rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h
94rmd_dgst.o: ../md32_common.h rmd_dgst.c rmd_locl.h rmdconst.h
95rmd_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
96rmd_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
97rmd_one.o: ../../include/openssl/ossl_typ.h ../../include/openssl/ripemd.h
98rmd_one.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
99rmd_one.o: ../../include/openssl/symhacks.h rmd_one.c
diff --git a/src/lib/libcrypto/ripemd/Makefile.ssl b/src/lib/libcrypto/ripemd/Makefile.ssl
new file mode 100644
index 0000000000..f22ac790ae
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/Makefile.ssl
@@ -0,0 +1,108 @@
1#
2# SSLeay/crypto/ripemd/Makefile
3#
4
5DIR= ripemd
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20RIP_ASM_OBJ=
21
22CFLAGS= $(INCLUDES) $(CFLAG)
23ASFLAGS= $(INCLUDES) $(ASFLAG)
24
25GENERAL=Makefile
26TEST=rmdtest.c
27APPS=
28
29LIB=$(TOP)/libcrypto.a
30LIBSRC=rmd_dgst.c rmd_one.c
31LIBOBJ=rmd_dgst.o rmd_one.o $(RMD160_ASM_OBJ)
32
33SRC= $(LIBSRC)
34
35EXHEADER= ripemd.h
36HEADER= rmd_locl.h rmdconst.h $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50# elf
51asm/rm86-elf.s: asm/rmd-586.pl ../perlasm/x86asm.pl
52 (cd asm; $(PERL) rmd-586.pl elf $(CFLAGS) > rm86-elf.s)
53
54# a.out
55asm/rm86-out.o: asm/rm86unix.cpp
56 $(CPP) -DOUT asm/rm86unix.cpp | as -o asm/rm86-out.o
57
58# bsdi
59asm/rm86bsdi.o: asm/rm86unix.cpp
60 $(CPP) -DBSDI asm/rm86unix.cpp | sed 's/ :/:/' | as -o asm/rm86bsdi.o
61
62asm/rm86unix.cpp: asm/rmd-586.pl ../perlasm/x86asm.pl
63 (cd asm; $(PERL) rmd-586.pl cpp >rm86unix.cpp)
64
65files:
66 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
67
68links:
69 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
70 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
71 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
72 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
73
74install:
75 @for i in $(EXHEADER) ; \
76 do \
77 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
78 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
79 done;
80
81tags:
82 ctags $(SRC)
83
84tests:
85
86lint:
87 lint -DLINT $(INCLUDES) $(SRC)>fluff
88
89depend:
90 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
91
92dclean:
93 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
94 mv -f Makefile.new $(MAKEFILE)
95
96clean:
97 rm -f asm/rm86unix.cpp asm/*-elf.* *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
98
99# DO NOT DELETE THIS LINE -- make depend depends on it.
100
101rmd_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
102rmd_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/ripemd.h
103rmd_dgst.o: ../md32_common.h rmd_dgst.c rmd_locl.h rmdconst.h
104rmd_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
105rmd_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
106rmd_one.o: ../../include/openssl/ripemd.h ../../include/openssl/safestack.h
107rmd_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
108rmd_one.o: rmd_one.c
diff --git a/src/lib/libcrypto/ripemd/README b/src/lib/libcrypto/ripemd/README
index 7097707264..f1ffc8b134 100644
--- a/src/lib/libcrypto/ripemd/README
+++ b/src/lib/libcrypto/ripemd/README
@@ -4,7 +4,7 @@ http://www.esat.kuleuven.ac.be/~bosselae/ripemd160.html
4This is my implementation of RIPEMD-160. The pentium assember is a little 4This is my implementation of RIPEMD-160. The pentium assember is a little
5off the pace since I only get 1050 cycles, while the best is 1013. 5off the pace since I only get 1050 cycles, while the best is 1013.
6I have a few ideas for how to get another 20 or so cycles, but at 6I have a few ideas for how to get another 20 or so cycles, but at
7this point I will not bother right now. I belive the trick will be 7this point I will not bother right now. I believe the trick will be
8to remove my 'copy X array onto stack' until inside the RIP1() finctions the 8to remove my 'copy X array onto stack' until inside the RIP1() finctions the
9first time round. To do this I need another register and will only have one 9first time round. To do this I need another register and will only have one
10temporary one. A bit tricky.... I can also cleanup the saving of the 5 words 10temporary one. A bit tricky.... I can also cleanup the saving of the 5 words
diff --git a/src/lib/libcrypto/ripemd/asm/rips.cpp b/src/lib/libcrypto/ripemd/asm/rips.cpp
new file mode 100644
index 0000000000..f7a13677a9
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/asm/rips.cpp
@@ -0,0 +1,82 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/ripemd.h>
36
37#define ripemd160_block_x86 ripemd160_block_asm_host_order
38
39extern "C" {
40void ripemd160_block_x86(RIPEMD160_CTX *ctx, unsigned char *buffer,int num);
41}
42
43void main(int argc,char *argv[])
44 {
45 unsigned char buffer[64*256];
46 RIPEMD160_CTX ctx;
47 unsigned long s1,s2,e1,e2;
48 unsigned char k[16];
49 unsigned long data[2];
50 unsigned char iv[8];
51 int i,num=0,numm;
52 int j=0;
53
54 if (argc >= 2)
55 num=atoi(argv[1]);
56
57 if (num == 0) num=16;
58 if (num > 250) num=16;
59 numm=num+2;
60#if 0
61 num*=64;
62 numm*=64;
63#endif
64
65 for (j=0; j<6; j++)
66 {
67 for (i=0; i<10; i++) /**/
68 {
69 ripemd160_block_x86(&ctx,buffer,numm);
70 GetTSC(s1);
71 ripemd160_block_x86(&ctx,buffer,numm);
72 GetTSC(e1);
73 GetTSC(s2);
74 ripemd160_block_x86(&ctx,buffer,num);
75 GetTSC(e2);
76 ripemd160_block_x86(&ctx,buffer,num);
77 }
78 printf("ripemd160 (%d bytes) %d %d (%.2f)\n",num*64,
79 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
80 }
81 }
82
diff --git a/src/lib/libcrypto/ripemd/asm/rmd-586.pl b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
index 4f3c4c967f..0ab6f76bff 100644
--- a/src/lib/libcrypto/ripemd/asm/rmd-586.pl
+++ b/src/lib/libcrypto/ripemd/asm/rmd-586.pl
@@ -1,7 +1,7 @@
1#!/usr/local/bin/perl 1#!/usr/local/bin/perl
2 2
3# Normal is the 3# Normal is the
4# ripemd160_block_asm_data_order(RIPEMD160_CTX *c, ULONG *X,int blocks); 4# ripemd160_block_asm_host_order(RIPEMD160_CTX *c, ULONG *X,int blocks);
5 5
6$normal=0; 6$normal=0;
7 7
@@ -56,7 +56,7 @@ $KR3=0x7A6D76E9;
56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11, 56 8, 5,12, 9,12, 5,14, 6, 8,13, 6, 5,15,13,11,11,
57 ); 57 );
58 58
59&ripemd160_block("ripemd160_block_asm_data_order"); 59&ripemd160_block("ripemd160_block_asm_host_order");
60&asm_finish(); 60&asm_finish();
61 61
62sub Xv 62sub Xv
diff --git a/src/lib/libcrypto/ripemd/ripemd.h b/src/lib/libcrypto/ripemd/ripemd.h
index 033a5965b5..7d0d998189 100644
--- a/src/lib/libcrypto/ripemd/ripemd.h
+++ b/src/lib/libcrypto/ripemd/ripemd.h
@@ -60,7 +60,6 @@
60#define HEADER_RIPEMD_H 60#define HEADER_RIPEMD_H
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63#include <stddef.h>
64 63
65#ifdef __cplusplus 64#ifdef __cplusplus
66extern "C" { 65extern "C" {
@@ -88,13 +87,16 @@ typedef struct RIPEMD160state_st
88 RIPEMD160_LONG A,B,C,D,E; 87 RIPEMD160_LONG A,B,C,D,E;
89 RIPEMD160_LONG Nl,Nh; 88 RIPEMD160_LONG Nl,Nh;
90 RIPEMD160_LONG data[RIPEMD160_LBLOCK]; 89 RIPEMD160_LONG data[RIPEMD160_LBLOCK];
91 unsigned int num; 90 int num;
92 } RIPEMD160_CTX; 91 } RIPEMD160_CTX;
93 92
93#ifdef OPENSSL_FIPS
94int private_RIPEMD160_Init(RIPEMD160_CTX *c);
95#endif
94int RIPEMD160_Init(RIPEMD160_CTX *c); 96int RIPEMD160_Init(RIPEMD160_CTX *c);
95int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, size_t len); 97int RIPEMD160_Update(RIPEMD160_CTX *c, const void *data, unsigned long len);
96int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c); 98int RIPEMD160_Final(unsigned char *md, RIPEMD160_CTX *c);
97unsigned char *RIPEMD160(const unsigned char *d, size_t n, 99unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
98 unsigned char *md); 100 unsigned char *md);
99void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b); 101void RIPEMD160_Transform(RIPEMD160_CTX *c, const unsigned char *b);
100#ifdef __cplusplus 102#ifdef __cplusplus
diff --git a/src/lib/libcrypto/ripemd/rmd160.c b/src/lib/libcrypto/ripemd/rmd160.c
new file mode 100644
index 0000000000..b0ec574498
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmd160.c
@@ -0,0 +1,127 @@
1/* crypto/ripemd/rmd160.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/ripemd.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#if !defined(_OSD_POSIX) && !defined(__DJGPP__)
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("RIPEMD160(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 RIPEMD160_CTX c;
102 unsigned char md[RIPEMD160_DIGEST_LENGTH];
103 int fd;
104 int i;
105 static unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 RIPEMD160_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,BUFSIZE);
112 if (i <= 0) break;
113 RIPEMD160_Update(&c,buf,(unsigned long)i);
114 }
115 RIPEMD160_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libcrypto/ripemd/rmd_dgst.c b/src/lib/libcrypto/ripemd/rmd_dgst.c
index 61626284b8..58ff010d11 100644
--- a/src/lib/libcrypto/ripemd/rmd_dgst.c
+++ b/src/lib/libcrypto/ripemd/rmd_dgst.c
@@ -58,18 +58,19 @@
58 58
59#include <stdio.h> 59#include <stdio.h>
60#include "rmd_locl.h" 60#include "rmd_locl.h"
61#include <openssl/fips.h>
61#include <openssl/opensslv.h> 62#include <openssl/opensslv.h>
62 63
63const char RMD160_version[]="RIPE-MD160" OPENSSL_VERSION_PTEXT; 64const char *RMD160_version="RIPE-MD160" OPENSSL_VERSION_PTEXT;
64 65
65# ifdef RMD160_ASM 66# ifdef RMD160_ASM
66 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,size_t num); 67 void ripemd160_block_x86(RIPEMD160_CTX *c, unsigned long *p,int num);
67# define ripemd160_block ripemd160_block_x86 68# define ripemd160_block ripemd160_block_x86
68# else 69# else
69 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,size_t num); 70 void ripemd160_block(RIPEMD160_CTX *c, unsigned long *p,int num);
70# endif 71# endif
71 72
72int RIPEMD160_Init(RIPEMD160_CTX *c) 73FIPS_NON_FIPS_MD_Init(RIPEMD160)
73 { 74 {
74 c->A=RIPEMD160_A; 75 c->A=RIPEMD160_A;
75 c->B=RIPEMD160_B; 76 c->B=RIPEMD160_B;
@@ -82,14 +83,215 @@ int RIPEMD160_Init(RIPEMD160_CTX *c)
82 return 1; 83 return 1;
83 } 84 }
84 85
86#ifndef ripemd160_block_host_order
87#ifdef X
88#undef X
89#endif
90#define X(i) XX[i]
91void ripemd160_block_host_order (RIPEMD160_CTX *ctx, const void *p, int num)
92 {
93 const RIPEMD160_LONG *XX=p;
94 register volatile unsigned MD32_REG_T A,B,C,D,E;
95 register unsigned MD32_REG_T a,b,c,d,e;
96
97 for (;num--;XX+=HASH_LBLOCK)
98 {
99
100 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
101
102 RIP1(A,B,C,D,E,WL00,SL00);
103 RIP1(E,A,B,C,D,WL01,SL01);
104 RIP1(D,E,A,B,C,WL02,SL02);
105 RIP1(C,D,E,A,B,WL03,SL03);
106 RIP1(B,C,D,E,A,WL04,SL04);
107 RIP1(A,B,C,D,E,WL05,SL05);
108 RIP1(E,A,B,C,D,WL06,SL06);
109 RIP1(D,E,A,B,C,WL07,SL07);
110 RIP1(C,D,E,A,B,WL08,SL08);
111 RIP1(B,C,D,E,A,WL09,SL09);
112 RIP1(A,B,C,D,E,WL10,SL10);
113 RIP1(E,A,B,C,D,WL11,SL11);
114 RIP1(D,E,A,B,C,WL12,SL12);
115 RIP1(C,D,E,A,B,WL13,SL13);
116 RIP1(B,C,D,E,A,WL14,SL14);
117 RIP1(A,B,C,D,E,WL15,SL15);
118
119 RIP2(E,A,B,C,D,WL16,SL16,KL1);
120 RIP2(D,E,A,B,C,WL17,SL17,KL1);
121 RIP2(C,D,E,A,B,WL18,SL18,KL1);
122 RIP2(B,C,D,E,A,WL19,SL19,KL1);
123 RIP2(A,B,C,D,E,WL20,SL20,KL1);
124 RIP2(E,A,B,C,D,WL21,SL21,KL1);
125 RIP2(D,E,A,B,C,WL22,SL22,KL1);
126 RIP2(C,D,E,A,B,WL23,SL23,KL1);
127 RIP2(B,C,D,E,A,WL24,SL24,KL1);
128 RIP2(A,B,C,D,E,WL25,SL25,KL1);
129 RIP2(E,A,B,C,D,WL26,SL26,KL1);
130 RIP2(D,E,A,B,C,WL27,SL27,KL1);
131 RIP2(C,D,E,A,B,WL28,SL28,KL1);
132 RIP2(B,C,D,E,A,WL29,SL29,KL1);
133 RIP2(A,B,C,D,E,WL30,SL30,KL1);
134 RIP2(E,A,B,C,D,WL31,SL31,KL1);
135
136 RIP3(D,E,A,B,C,WL32,SL32,KL2);
137 RIP3(C,D,E,A,B,WL33,SL33,KL2);
138 RIP3(B,C,D,E,A,WL34,SL34,KL2);
139 RIP3(A,B,C,D,E,WL35,SL35,KL2);
140 RIP3(E,A,B,C,D,WL36,SL36,KL2);
141 RIP3(D,E,A,B,C,WL37,SL37,KL2);
142 RIP3(C,D,E,A,B,WL38,SL38,KL2);
143 RIP3(B,C,D,E,A,WL39,SL39,KL2);
144 RIP3(A,B,C,D,E,WL40,SL40,KL2);
145 RIP3(E,A,B,C,D,WL41,SL41,KL2);
146 RIP3(D,E,A,B,C,WL42,SL42,KL2);
147 RIP3(C,D,E,A,B,WL43,SL43,KL2);
148 RIP3(B,C,D,E,A,WL44,SL44,KL2);
149 RIP3(A,B,C,D,E,WL45,SL45,KL2);
150 RIP3(E,A,B,C,D,WL46,SL46,KL2);
151 RIP3(D,E,A,B,C,WL47,SL47,KL2);
152
153 RIP4(C,D,E,A,B,WL48,SL48,KL3);
154 RIP4(B,C,D,E,A,WL49,SL49,KL3);
155 RIP4(A,B,C,D,E,WL50,SL50,KL3);
156 RIP4(E,A,B,C,D,WL51,SL51,KL3);
157 RIP4(D,E,A,B,C,WL52,SL52,KL3);
158 RIP4(C,D,E,A,B,WL53,SL53,KL3);
159 RIP4(B,C,D,E,A,WL54,SL54,KL3);
160 RIP4(A,B,C,D,E,WL55,SL55,KL3);
161 RIP4(E,A,B,C,D,WL56,SL56,KL3);
162 RIP4(D,E,A,B,C,WL57,SL57,KL3);
163 RIP4(C,D,E,A,B,WL58,SL58,KL3);
164 RIP4(B,C,D,E,A,WL59,SL59,KL3);
165 RIP4(A,B,C,D,E,WL60,SL60,KL3);
166 RIP4(E,A,B,C,D,WL61,SL61,KL3);
167 RIP4(D,E,A,B,C,WL62,SL62,KL3);
168 RIP4(C,D,E,A,B,WL63,SL63,KL3);
169
170 RIP5(B,C,D,E,A,WL64,SL64,KL4);
171 RIP5(A,B,C,D,E,WL65,SL65,KL4);
172 RIP5(E,A,B,C,D,WL66,SL66,KL4);
173 RIP5(D,E,A,B,C,WL67,SL67,KL4);
174 RIP5(C,D,E,A,B,WL68,SL68,KL4);
175 RIP5(B,C,D,E,A,WL69,SL69,KL4);
176 RIP5(A,B,C,D,E,WL70,SL70,KL4);
177 RIP5(E,A,B,C,D,WL71,SL71,KL4);
178 RIP5(D,E,A,B,C,WL72,SL72,KL4);
179 RIP5(C,D,E,A,B,WL73,SL73,KL4);
180 RIP5(B,C,D,E,A,WL74,SL74,KL4);
181 RIP5(A,B,C,D,E,WL75,SL75,KL4);
182 RIP5(E,A,B,C,D,WL76,SL76,KL4);
183 RIP5(D,E,A,B,C,WL77,SL77,KL4);
184 RIP5(C,D,E,A,B,WL78,SL78,KL4);
185 RIP5(B,C,D,E,A,WL79,SL79,KL4);
186
187 a=A; b=B; c=C; d=D; e=E;
188 /* Do other half */
189 A=ctx->A; B=ctx->B; C=ctx->C; D=ctx->D; E=ctx->E;
190
191 RIP5(A,B,C,D,E,WR00,SR00,KR0);
192 RIP5(E,A,B,C,D,WR01,SR01,KR0);
193 RIP5(D,E,A,B,C,WR02,SR02,KR0);
194 RIP5(C,D,E,A,B,WR03,SR03,KR0);
195 RIP5(B,C,D,E,A,WR04,SR04,KR0);
196 RIP5(A,B,C,D,E,WR05,SR05,KR0);
197 RIP5(E,A,B,C,D,WR06,SR06,KR0);
198 RIP5(D,E,A,B,C,WR07,SR07,KR0);
199 RIP5(C,D,E,A,B,WR08,SR08,KR0);
200 RIP5(B,C,D,E,A,WR09,SR09,KR0);
201 RIP5(A,B,C,D,E,WR10,SR10,KR0);
202 RIP5(E,A,B,C,D,WR11,SR11,KR0);
203 RIP5(D,E,A,B,C,WR12,SR12,KR0);
204 RIP5(C,D,E,A,B,WR13,SR13,KR0);
205 RIP5(B,C,D,E,A,WR14,SR14,KR0);
206 RIP5(A,B,C,D,E,WR15,SR15,KR0);
207
208 RIP4(E,A,B,C,D,WR16,SR16,KR1);
209 RIP4(D,E,A,B,C,WR17,SR17,KR1);
210 RIP4(C,D,E,A,B,WR18,SR18,KR1);
211 RIP4(B,C,D,E,A,WR19,SR19,KR1);
212 RIP4(A,B,C,D,E,WR20,SR20,KR1);
213 RIP4(E,A,B,C,D,WR21,SR21,KR1);
214 RIP4(D,E,A,B,C,WR22,SR22,KR1);
215 RIP4(C,D,E,A,B,WR23,SR23,KR1);
216 RIP4(B,C,D,E,A,WR24,SR24,KR1);
217 RIP4(A,B,C,D,E,WR25,SR25,KR1);
218 RIP4(E,A,B,C,D,WR26,SR26,KR1);
219 RIP4(D,E,A,B,C,WR27,SR27,KR1);
220 RIP4(C,D,E,A,B,WR28,SR28,KR1);
221 RIP4(B,C,D,E,A,WR29,SR29,KR1);
222 RIP4(A,B,C,D,E,WR30,SR30,KR1);
223 RIP4(E,A,B,C,D,WR31,SR31,KR1);
224
225 RIP3(D,E,A,B,C,WR32,SR32,KR2);
226 RIP3(C,D,E,A,B,WR33,SR33,KR2);
227 RIP3(B,C,D,E,A,WR34,SR34,KR2);
228 RIP3(A,B,C,D,E,WR35,SR35,KR2);
229 RIP3(E,A,B,C,D,WR36,SR36,KR2);
230 RIP3(D,E,A,B,C,WR37,SR37,KR2);
231 RIP3(C,D,E,A,B,WR38,SR38,KR2);
232 RIP3(B,C,D,E,A,WR39,SR39,KR2);
233 RIP3(A,B,C,D,E,WR40,SR40,KR2);
234 RIP3(E,A,B,C,D,WR41,SR41,KR2);
235 RIP3(D,E,A,B,C,WR42,SR42,KR2);
236 RIP3(C,D,E,A,B,WR43,SR43,KR2);
237 RIP3(B,C,D,E,A,WR44,SR44,KR2);
238 RIP3(A,B,C,D,E,WR45,SR45,KR2);
239 RIP3(E,A,B,C,D,WR46,SR46,KR2);
240 RIP3(D,E,A,B,C,WR47,SR47,KR2);
241
242 RIP2(C,D,E,A,B,WR48,SR48,KR3);
243 RIP2(B,C,D,E,A,WR49,SR49,KR3);
244 RIP2(A,B,C,D,E,WR50,SR50,KR3);
245 RIP2(E,A,B,C,D,WR51,SR51,KR3);
246 RIP2(D,E,A,B,C,WR52,SR52,KR3);
247 RIP2(C,D,E,A,B,WR53,SR53,KR3);
248 RIP2(B,C,D,E,A,WR54,SR54,KR3);
249 RIP2(A,B,C,D,E,WR55,SR55,KR3);
250 RIP2(E,A,B,C,D,WR56,SR56,KR3);
251 RIP2(D,E,A,B,C,WR57,SR57,KR3);
252 RIP2(C,D,E,A,B,WR58,SR58,KR3);
253 RIP2(B,C,D,E,A,WR59,SR59,KR3);
254 RIP2(A,B,C,D,E,WR60,SR60,KR3);
255 RIP2(E,A,B,C,D,WR61,SR61,KR3);
256 RIP2(D,E,A,B,C,WR62,SR62,KR3);
257 RIP2(C,D,E,A,B,WR63,SR63,KR3);
258
259 RIP1(B,C,D,E,A,WR64,SR64);
260 RIP1(A,B,C,D,E,WR65,SR65);
261 RIP1(E,A,B,C,D,WR66,SR66);
262 RIP1(D,E,A,B,C,WR67,SR67);
263 RIP1(C,D,E,A,B,WR68,SR68);
264 RIP1(B,C,D,E,A,WR69,SR69);
265 RIP1(A,B,C,D,E,WR70,SR70);
266 RIP1(E,A,B,C,D,WR71,SR71);
267 RIP1(D,E,A,B,C,WR72,SR72);
268 RIP1(C,D,E,A,B,WR73,SR73);
269 RIP1(B,C,D,E,A,WR74,SR74);
270 RIP1(A,B,C,D,E,WR75,SR75);
271 RIP1(E,A,B,C,D,WR76,SR76);
272 RIP1(D,E,A,B,C,WR77,SR77);
273 RIP1(C,D,E,A,B,WR78,SR78);
274 RIP1(B,C,D,E,A,WR79,SR79);
275
276 D =ctx->B+c+D;
277 ctx->B=ctx->C+d+E;
278 ctx->C=ctx->D+e+A;
279 ctx->D=ctx->E+a+B;
280 ctx->E=ctx->A+b+C;
281 ctx->A=D;
282
283 }
284 }
285#endif
286
85#ifndef ripemd160_block_data_order 287#ifndef ripemd160_block_data_order
86#ifdef X 288#ifdef X
87#undef X 289#undef X
88#endif 290#endif
89void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, size_t num) 291void ripemd160_block_data_order (RIPEMD160_CTX *ctx, const void *p, int num)
90 { 292 {
91 const unsigned char *data=p; 293 const unsigned char *data=p;
92 register unsigned MD32_REG_T A,B,C,D,E; 294 register volatile unsigned MD32_REG_T A,B,C,D,E;
93 unsigned MD32_REG_T a,b,c,d,e,l; 295 unsigned MD32_REG_T a,b,c,d,e,l;
94#ifndef MD32_XARRAY 296#ifndef MD32_XARRAY
95 /* See comment in crypto/sha/sha_locl.h for details. */ 297 /* See comment in crypto/sha/sha_locl.h for details. */
diff --git a/src/lib/libcrypto/ripemd/rmd_locl.h b/src/lib/libcrypto/ripemd/rmd_locl.h
index f14b346e66..7b835dfbd4 100644
--- a/src/lib/libcrypto/ripemd/rmd_locl.h
+++ b/src/lib/libcrypto/ripemd/rmd_locl.h
@@ -72,20 +72,28 @@
72 */ 72 */
73#ifdef RMD160_ASM 73#ifdef RMD160_ASM
74# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) 74# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
75# define ripemd160_block_data_order ripemd160_block_asm_data_order 75# define ripemd160_block_host_order ripemd160_block_asm_host_order
76# endif 76# endif
77#endif 77#endif
78 78
79void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,size_t num); 79void ripemd160_block_host_order (RIPEMD160_CTX *c, const void *p,int num);
80void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,int num);
81
82#if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
83#define ripemd160_block_data_order ripemd160_block_host_order
84#endif
80 85
81#define DATA_ORDER_IS_LITTLE_ENDIAN 86#define DATA_ORDER_IS_LITTLE_ENDIAN
82 87
83#define HASH_LONG RIPEMD160_LONG 88#define HASH_LONG RIPEMD160_LONG
89#define HASH_LONG_LOG2 RIPEMD160_LONG_LOG2
84#define HASH_CTX RIPEMD160_CTX 90#define HASH_CTX RIPEMD160_CTX
85#define HASH_CBLOCK RIPEMD160_CBLOCK 91#define HASH_CBLOCK RIPEMD160_CBLOCK
92#define HASH_LBLOCK RIPEMD160_LBLOCK
86#define HASH_UPDATE RIPEMD160_Update 93#define HASH_UPDATE RIPEMD160_Update
87#define HASH_TRANSFORM RIPEMD160_Transform 94#define HASH_TRANSFORM RIPEMD160_Transform
88#define HASH_FINAL RIPEMD160_Final 95#define HASH_FINAL RIPEMD160_Final
96#define HASH_BLOCK_HOST_ORDER ripemd160_block_host_order
89#define HASH_MAKE_STRING(c,s) do { \ 97#define HASH_MAKE_STRING(c,s) do { \
90 unsigned long ll; \ 98 unsigned long ll; \
91 ll=(c)->A; HOST_l2c(ll,(s)); \ 99 ll=(c)->A; HOST_l2c(ll,(s)); \
@@ -94,7 +102,9 @@ void ripemd160_block_data_order (RIPEMD160_CTX *c, const void *p,size_t num);
94 ll=(c)->D; HOST_l2c(ll,(s)); \ 102 ll=(c)->D; HOST_l2c(ll,(s)); \
95 ll=(c)->E; HOST_l2c(ll,(s)); \ 103 ll=(c)->E; HOST_l2c(ll,(s)); \
96 } while (0) 104 } while (0)
105#if !defined(L_ENDIAN) || defined(ripemd160_block_data_order)
97#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order 106#define HASH_BLOCK_DATA_ORDER ripemd160_block_data_order
107#endif
98 108
99#include "md32_common.h" 109#include "md32_common.h"
100 110
diff --git a/src/lib/libcrypto/ripemd/rmd_one.c b/src/lib/libcrypto/ripemd/rmd_one.c
index 3efb13758f..b88446b267 100644
--- a/src/lib/libcrypto/ripemd/rmd_one.c
+++ b/src/lib/libcrypto/ripemd/rmd_one.c
@@ -61,7 +61,7 @@
61#include <openssl/ripemd.h> 61#include <openssl/ripemd.h>
62#include <openssl/crypto.h> 62#include <openssl/crypto.h>
63 63
64unsigned char *RIPEMD160(const unsigned char *d, size_t n, 64unsigned char *RIPEMD160(const unsigned char *d, unsigned long n,
65 unsigned char *md) 65 unsigned char *md)
66 { 66 {
67 RIPEMD160_CTX c; 67 RIPEMD160_CTX c;
diff --git a/src/lib/libcrypto/ripemd/rmdtest.c b/src/lib/libcrypto/ripemd/rmdtest.c
new file mode 100644
index 0000000000..d4c709e646
--- /dev/null
+++ b/src/lib/libcrypto/ripemd/rmdtest.c
@@ -0,0 +1,145 @@
1/* crypto/ripemd/rmdtest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_RIPEMD
66int main(int argc, char *argv[])
67{
68 printf("No ripemd support\n");
69 return(0);
70}
71#else
72#include <openssl/ripemd.h>
73#include <openssl/evp.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
78
79static char *test[]={
80 "",
81 "a",
82 "abc",
83 "message digest",
84 "abcdefghijklmnopqrstuvwxyz",
85 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
86 "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
87 "12345678901234567890123456789012345678901234567890123456789012345678901234567890",
88 NULL,
89 };
90
91static char *ret[]={
92 "9c1185a5c5e9fc54612808977ee8f548b2258d31",
93 "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe",
94 "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc",
95 "5d0689ef49d2fae572b881b123a85ffa21595f36",
96 "f71c27109c692c1b56bbdceb5b9d2865b3708dbc",
97 "12a053384a9c0c88e405a06c27dcf49ada62eb2b",
98 "b0e20b6e3116640286ed3a87a5713079b21f5189",
99 "9b752e45573d4b39f4dbd3323cab82bf63326bfb",
100 };
101
102static char *pt(unsigned char *md);
103int main(int argc, char *argv[])
104 {
105 int i,err=0;
106 unsigned char **P,**R;
107 char *p;
108 unsigned char md[RIPEMD160_DIGEST_LENGTH];
109
110 P=(unsigned char **)test;
111 R=(unsigned char **)ret;
112 i=1;
113 while (*P != NULL)
114 {
115#ifdef CHARSET_EBCDIC
116 ebcdic2ascii((char *)*P, (char *)*P, strlen((char *)*P));
117#endif
118 EVP_Digest(&(P[0][0]),(unsigned long)strlen((char *)*P),md,NULL,EVP_ripemd160(), NULL);
119 p=pt(md);
120 if (strcmp(p,(char *)*R) != 0)
121 {
122 printf("error calculating RIPEMD160 on '%s'\n",*P);
123 printf("got %s instead of %s\n",p,*R);
124 err++;
125 }
126 else
127 printf("test %d ok\n",i);
128 i++;
129 R++;
130 P++;
131 }
132 EXIT(err);
133 return(0);
134 }
135
136static char *pt(unsigned char *md)
137 {
138 int i;
139 static char buf[80];
140
141 for (i=0; i<RIPEMD160_DIGEST_LENGTH; i++)
142 sprintf(&(buf[i*2]),"%02x",md[i]);
143 return(buf);
144 }
145#endif
diff --git a/src/lib/libcrypto/rsa/Makefile b/src/lib/libcrypto/rsa/Makefile
new file mode 100644
index 0000000000..13900812ac
--- /dev/null
+++ b/src/lib/libcrypto/rsa/Makefile
@@ -0,0 +1,239 @@
1#
2# OpenSSL/crypto/rsa/Makefile
3#
4
5DIR= rsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=rsa_test.c
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
21 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \
22 rsa_pss.c rsa_x931.c rsa_asn1.c rsa_depr.c
23LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
24 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \
25 rsa_pss.o rsa_x931.o rsa_asn1.o rsa_depr.o
26
27SRC= $(LIBSRC)
28
29EXHEADER= rsa.h
30HEADER= $(EXHEADER)
31
32ALL= $(GENERAL) $(SRC) $(HEADER)
33
34top:
35 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
36
37all: lib
38
39lib: $(LIBOBJ)
40 $(AR) $(LIB) $(LIBOBJ)
41 $(RANLIB) $(LIB) || echo Never mind.
42 @touch lib
43
44files:
45 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
46
47links:
48 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51
52install:
53 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
54 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
55 do \
56 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done;
59
60tags:
61 ctags $(SRC)
62
63tests:
64
65lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff
67
68depend:
69 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
70 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
71
72dclean:
73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
74 mv -f Makefile.new $(MAKEFILE)
75
76clean:
77 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
78
79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
82rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
83rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
84rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
85rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
86rsa_asn1.o: ../../include/openssl/opensslconf.h
87rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
88rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
89rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
90rsa_asn1.o: ../cryptlib.h rsa_asn1.c
91rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
92rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
93rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
95rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
97rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
98rsa_chk.o: rsa_chk.c
99rsa_depr.o: ../../e_os.h ../../include/openssl/asn1.h
100rsa_depr.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
101rsa_depr.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
102rsa_depr.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
103rsa_depr.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
104rsa_depr.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105rsa_depr.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
106rsa_depr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
107rsa_depr.o: ../cryptlib.h rsa_depr.c
108rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h
109rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
110rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
111rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
112rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
113rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
114rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
115rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c
117rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
118rsa_err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
119rsa_err.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
120rsa_err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
121rsa_err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rsa.h
122rsa_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
123rsa_err.o: ../../include/openssl/symhacks.h rsa_err.c
124rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h
125rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
126rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
127rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
128rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
129rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
130rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
132rsa_gen.o: ../cryptlib.h rsa_gen.c
133rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
134rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
135rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
136rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
137rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
138rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
139rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
140rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
141rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
142rsa_lib.o: ../cryptlib.h rsa_lib.c
143rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h
144rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
145rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
146rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
147rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
148rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
150rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
151rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c
152rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h
153rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
154rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
155rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
156rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
157rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
158rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
159rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
160rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c
161rsa_oaep.o: ../../e_os.h ../../include/openssl/asn1.h
162rsa_oaep.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
163rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
164rsa_oaep.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
165rsa_oaep.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
166rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
167rsa_oaep.o: ../../include/openssl/opensslconf.h
168rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
169rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
170rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
171rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
172rsa_oaep.o: ../cryptlib.h rsa_oaep.c
173rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h
174rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
175rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
176rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
177rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
178rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
179rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
180rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
181rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c
182rsa_pss.o: ../../e_os.h ../../include/openssl/asn1.h
183rsa_pss.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
184rsa_pss.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
185rsa_pss.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
186rsa_pss.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
187rsa_pss.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
188rsa_pss.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
189rsa_pss.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
190rsa_pss.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
191rsa_pss.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
192rsa_pss.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pss.c
193rsa_saos.o: ../../e_os.h ../../include/openssl/asn1.h
194rsa_saos.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
195rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
196rsa_saos.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
197rsa_saos.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
198rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
199rsa_saos.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
200rsa_saos.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
201rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
202rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
203rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
204rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
205rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
206rsa_saos.o: ../cryptlib.h rsa_saos.c
207rsa_sign.o: ../../e_os.h ../../include/openssl/asn1.h
208rsa_sign.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
209rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
210rsa_sign.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
211rsa_sign.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
212rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
213rsa_sign.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
214rsa_sign.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
215rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
216rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rsa.h
217rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
218rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
219rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
220rsa_sign.o: ../cryptlib.h rsa_sign.c
221rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h
222rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
223rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
224rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
225rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
226rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
227rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
228rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
229rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_ssl.c
230rsa_x931.o: ../../e_os.h ../../include/openssl/asn1.h
231rsa_x931.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
232rsa_x931.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
233rsa_x931.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
234rsa_x931.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
235rsa_x931.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
236rsa_x931.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
237rsa_x931.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
238rsa_x931.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
239rsa_x931.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_x931.c
diff --git a/src/lib/libcrypto/rsa/Makefile.ssl b/src/lib/libcrypto/rsa/Makefile.ssl
new file mode 100644
index 0000000000..8089344a04
--- /dev/null
+++ b/src/lib/libcrypto/rsa/Makefile.ssl
@@ -0,0 +1,241 @@
1#
2# SSLeay/crypto/rsa/Makefile
3#
4
5DIR= rsa
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=rsa_test.c
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= rsa_eay.c rsa_gen.c rsa_lib.c rsa_sign.c rsa_saos.c rsa_err.c \
27 rsa_pk1.c rsa_ssl.c rsa_none.c rsa_oaep.c rsa_chk.c rsa_null.c \
28 rsa_asn1.c
29LIBOBJ= rsa_eay.o rsa_gen.o rsa_lib.o rsa_sign.o rsa_saos.o rsa_err.o \
30 rsa_pk1.o rsa_ssl.o rsa_none.o rsa_oaep.o rsa_chk.o rsa_null.o \
31 rsa_asn1.o
32
33SRC= $(LIBSRC)
34
35EXHEADER= rsa.h
36HEADER= $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
52
53links:
54 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
55 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
56 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
57 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
58
59install:
60 @for i in $(EXHEADER) ; \
61 do \
62 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
63 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
64 done;
65
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
76
77dclean:
78 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
79 mv -f Makefile.new $(MAKEFILE)
80
81clean:
82 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
83
84# DO NOT DELETE THIS LINE -- make depend depends on it.
85
86rsa_asn1.o: ../../e_os.h ../../include/openssl/asn1.h
87rsa_asn1.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
88rsa_asn1.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
89rsa_asn1.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
90rsa_asn1.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
91rsa_asn1.o: ../../include/openssl/opensslconf.h
92rsa_asn1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
93rsa_asn1.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
94rsa_asn1.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
95rsa_asn1.o: ../cryptlib.h rsa_asn1.c
96rsa_chk.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
97rsa_chk.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
98rsa_chk.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
99rsa_chk.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
100rsa_chk.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
101rsa_chk.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
102rsa_chk.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
103rsa_chk.o: rsa_chk.c
104rsa_eay.o: ../../e_os.h ../../include/openssl/asn1.h
105rsa_eay.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
106rsa_eay.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
107rsa_eay.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108rsa_eay.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109rsa_eay.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
110rsa_eay.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
111rsa_eay.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
112rsa_eay.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_eay.c
113rsa_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
114rsa_err.o: ../../include/openssl/bn.h ../../include/openssl/crypto.h
115rsa_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
116rsa_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
117rsa_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
118rsa_err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
119rsa_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
120rsa_err.o: rsa_err.c
121rsa_gen.o: ../../e_os.h ../../include/openssl/asn1.h
122rsa_gen.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
123rsa_gen.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
124rsa_gen.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
125rsa_gen.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
126rsa_gen.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
127rsa_gen.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
128rsa_gen.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
129rsa_gen.o: ../cryptlib.h rsa_gen.c
130rsa_lib.o: ../../e_os.h ../../include/openssl/asn1.h
131rsa_lib.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
132rsa_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
133rsa_lib.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
134rsa_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/engine.h
135rsa_lib.o: ../../include/openssl/err.h ../../include/openssl/lhash.h
136rsa_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
137rsa_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h
138rsa_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
139rsa_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
140rsa_lib.o: ../../include/openssl/ui.h ../cryptlib.h rsa_lib.c
141rsa_none.o: ../../e_os.h ../../include/openssl/asn1.h
142rsa_none.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
143rsa_none.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
144rsa_none.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
145rsa_none.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
146rsa_none.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
147rsa_none.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
148rsa_none.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
149rsa_none.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_none.c
150rsa_null.o: ../../e_os.h ../../include/openssl/asn1.h
151rsa_null.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
152rsa_null.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
153rsa_null.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
154rsa_null.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
155rsa_null.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
156rsa_null.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
157rsa_null.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
158rsa_null.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_null.c
159rsa_oaep.o: ../../e_os.h ../../include/openssl/aes.h
160rsa_oaep.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
161rsa_oaep.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
162rsa_oaep.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
163rsa_oaep.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
164rsa_oaep.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
165rsa_oaep.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
166rsa_oaep.o: ../../include/openssl/err.h ../../include/openssl/evp.h
167rsa_oaep.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
168rsa_oaep.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
169rsa_oaep.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
170rsa_oaep.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
171rsa_oaep.o: ../../include/openssl/opensslconf.h
172rsa_oaep.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
173rsa_oaep.o: ../../include/openssl/rand.h ../../include/openssl/rc2.h
174rsa_oaep.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
175rsa_oaep.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
176rsa_oaep.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
177rsa_oaep.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
178rsa_oaep.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
179rsa_oaep.o: ../cryptlib.h rsa_oaep.c
180rsa_pk1.o: ../../e_os.h ../../include/openssl/asn1.h
181rsa_pk1.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
182rsa_pk1.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
183rsa_pk1.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
184rsa_pk1.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
185rsa_pk1.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
186rsa_pk1.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
187rsa_pk1.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
188rsa_pk1.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_pk1.c
189rsa_saos.o: ../../e_os.h ../../include/openssl/aes.h
190rsa_saos.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
191rsa_saos.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
192rsa_saos.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
193rsa_saos.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
194rsa_saos.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
195rsa_saos.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
196rsa_saos.o: ../../include/openssl/err.h ../../include/openssl/evp.h
197rsa_saos.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
198rsa_saos.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
199rsa_saos.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
200rsa_saos.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
201rsa_saos.o: ../../include/openssl/opensslconf.h
202rsa_saos.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
203rsa_saos.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
204rsa_saos.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
205rsa_saos.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
206rsa_saos.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
207rsa_saos.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
208rsa_saos.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
209rsa_saos.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
210rsa_saos.o: ../cryptlib.h rsa_saos.c
211rsa_sign.o: ../../e_os.h ../../include/openssl/aes.h
212rsa_sign.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
213rsa_sign.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
214rsa_sign.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
215rsa_sign.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
216rsa_sign.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
217rsa_sign.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
218rsa_sign.o: ../../include/openssl/err.h ../../include/openssl/evp.h
219rsa_sign.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
220rsa_sign.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
221rsa_sign.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
222rsa_sign.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
223rsa_sign.o: ../../include/openssl/opensslconf.h
224rsa_sign.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
225rsa_sign.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
226rsa_sign.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
227rsa_sign.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
228rsa_sign.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
229rsa_sign.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
230rsa_sign.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
231rsa_sign.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
232rsa_sign.o: ../cryptlib.h rsa_sign.c
233rsa_ssl.o: ../../e_os.h ../../include/openssl/asn1.h
234rsa_ssl.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
235rsa_ssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
236rsa_ssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
237rsa_ssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
238rsa_ssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
239rsa_ssl.o: ../../include/openssl/rand.h ../../include/openssl/rsa.h
240rsa_ssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
241rsa_ssl.o: ../../include/openssl/symhacks.h ../cryptlib.h rsa_ssl.c
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index 6b5e4f8a9a..dbed701e89 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -64,25 +64,25 @@
64#ifndef OPENSSL_NO_BIO 64#ifndef OPENSSL_NO_BIO
65#include <openssl/bio.h> 65#include <openssl/bio.h>
66#endif 66#endif
67#include <openssl/bn.h>
67#include <openssl/crypto.h> 68#include <openssl/crypto.h>
68#include <openssl/ossl_typ.h> 69#include <openssl/ossl_typ.h>
69#ifndef OPENSSL_NO_DEPRECATED
70#include <openssl/bn.h>
71#endif
72 70
73#ifdef OPENSSL_NO_RSA 71#ifdef OPENSSL_NO_RSA
74#error RSA is disabled. 72#error RSA is disabled.
75#endif 73#endif
76 74
75#if defined(OPENSSL_FIPS)
76#define FIPS_RSA_SIZE_T int
77#endif
78
77#ifdef __cplusplus 79#ifdef __cplusplus
78extern "C" { 80extern "C" {
79#endif 81#endif
80 82
81/* Declared already in ossl_typ.h */ 83typedef struct rsa_st RSA;
82/* typedef struct rsa_st RSA; */
83/* typedef struct rsa_meth_st RSA_METHOD; */
84 84
85struct rsa_meth_st 85typedef struct rsa_meth_st
86 { 86 {
87 const char *name; 87 const char *name;
88 int (*rsa_pub_enc)(int flen,const unsigned char *from, 88 int (*rsa_pub_enc)(int flen,const unsigned char *from,
@@ -97,7 +97,7 @@ struct rsa_meth_st
97 int (*rsa_priv_dec)(int flen,const unsigned char *from, 97 int (*rsa_priv_dec)(int flen,const unsigned char *from,
98 unsigned char *to, 98 unsigned char *to,
99 RSA *rsa,int padding); 99 RSA *rsa,int padding);
100 int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa,BN_CTX *ctx); /* Can be null */ 100 int (*rsa_mod_exp)(BIGNUM *r0,const BIGNUM *I,RSA *rsa); /* Can be null */
101 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, 101 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
102 const BIGNUM *m, BN_CTX *ctx, 102 const BIGNUM *m, BN_CTX *ctx,
103 BN_MONT_CTX *m_ctx); /* Can be null */ 103 BN_MONT_CTX *m_ctx); /* Can be null */
@@ -118,12 +118,8 @@ struct rsa_meth_st
118 int (*rsa_verify)(int dtype, 118 int (*rsa_verify)(int dtype,
119 const unsigned char *m, unsigned int m_length, 119 const unsigned char *m, unsigned int m_length,
120 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa); 120 unsigned char *sigbuf, unsigned int siglen, const RSA *rsa);
121/* If this callback is NULL, the builtin software RSA key-gen will be used. This 121
122 * is for behavioural compatibility whilst the code gets rewired, but one day 122 } RSA_METHOD;
123 * it would be nice to assume there are no such things as "builtin software"
124 * implementations. */
125 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
126 };
127 123
128struct rsa_st 124struct rsa_st
129 { 125 {
@@ -156,19 +152,12 @@ struct rsa_st
156 * NULL */ 152 * NULL */
157 char *bignum_data; 153 char *bignum_data;
158 BN_BLINDING *blinding; 154 BN_BLINDING *blinding;
159 BN_BLINDING *mt_blinding;
160 }; 155 };
161 156
162#ifndef OPENSSL_RSA_MAX_MODULUS_BITS 157#define OPENSSL_RSA_MAX_MODULUS_BITS 16384
163# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
164#endif
165 158
166#ifndef OPENSSL_RSA_SMALL_MODULUS_BITS 159#define OPENSSL_RSA_SMALL_MODULUS_BITS 3072
167# define OPENSSL_RSA_SMALL_MODULUS_BITS 3072 160#define OPENSSL_RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "small" modulus only */
168#endif
169#ifndef OPENSSL_RSA_MAX_PUBEXP_BITS
170# define OPENSSL_RSA_MAX_PUBEXP_BITS 64 /* exponent limit enforced for "large" modulus only */
171#endif
172 161
173#define RSA_3 0x3L 162#define RSA_3 0x3L
174#define RSA_F4 0x10001L 163#define RSA_F4 0x10001L
@@ -195,27 +184,13 @@ struct rsa_st
195 * default (ignoring RSA_FLAG_BLINDING), 184 * default (ignoring RSA_FLAG_BLINDING),
196 * but other engines might not need it 185 * but other engines might not need it
197 */ 186 */
198#define RSA_FLAG_NO_CONSTTIME 0x0100 /* new with 0.9.8f; the built-in RSA 187#define RSA_FLAG_NO_EXP_CONSTTIME 0x0100 /* new with 0.9.7h; the built-in RSA
199 * implementation now uses constant time
200 * operations by default in private key operations,
201 * e.g., constant time modular exponentiation,
202 * modular inverse without leaking branches,
203 * division without leaking branches. This
204 * flag disables these constant time
205 * operations and results in faster RSA
206 * private key operations.
207 */
208#ifndef OPENSSL_NO_DEPRECATED
209#define RSA_FLAG_NO_EXP_CONSTTIME RSA_FLAG_NO_CONSTTIME /* deprecated name for the flag*/
210 /* new with 0.9.7h; the built-in RSA
211 * implementation now uses constant time 188 * implementation now uses constant time
212 * modular exponentiation for secret exponents 189 * modular exponentiation for secret exponents
213 * by default. This flag causes the 190 * by default. This flag causes the
214 * faster variable sliding window method to 191 * faster variable sliding window method to
215 * be used for all exponents. 192 * be used for all exponents.
216 */ 193 */
217#endif
218
219 194
220#define RSA_PKCS1_PADDING 1 195#define RSA_PKCS1_PADDING 1
221#define RSA_SSLV23_PADDING 2 196#define RSA_SSLV23_PADDING 2
@@ -231,17 +206,18 @@ struct rsa_st
231RSA * RSA_new(void); 206RSA * RSA_new(void);
232RSA * RSA_new_method(ENGINE *engine); 207RSA * RSA_new_method(ENGINE *engine);
233int RSA_size(const RSA *); 208int RSA_size(const RSA *);
234
235/* Deprecated version */
236#ifndef OPENSSL_NO_DEPRECATED
237RSA * RSA_generate_key(int bits, unsigned long e,void 209RSA * RSA_generate_key(int bits, unsigned long e,void
238 (*callback)(int,int,void *),void *cb_arg); 210 (*callback)(int,int,void *),void *cb_arg);
239#endif /* !defined(OPENSSL_NO_DEPRECATED) */
240
241/* New version */
242int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
243
244int RSA_check_key(const RSA *); 211int RSA_check_key(const RSA *);
212#ifdef OPENSSL_FIPS
213int RSA_X931_derive(RSA *rsa, BIGNUM *p1, BIGNUM *p2, BIGNUM *q1, BIGNUM *q2,
214 void (*cb)(int, int, void *), void *cb_arg,
215 const BIGNUM *Xp1, const BIGNUM *Xp2, const BIGNUM *Xp,
216 const BIGNUM *Xq1, const BIGNUM *Xq2, const BIGNUM *Xq,
217 const BIGNUM *e);
218RSA *RSA_X931_generate_key(int bits, const BIGNUM *e,
219 void (*cb)(int,int,void *), void *cb_arg);
220#endif
245 /* next 4 return -1 on error */ 221 /* next 4 return -1 on error */
246int RSA_public_encrypt(int flen, const unsigned char *from, 222int RSA_public_encrypt(int flen, const unsigned char *from,
247 unsigned char *to, RSA *rsa,int padding); 223 unsigned char *to, RSA *rsa,int padding);
@@ -281,19 +257,11 @@ int RSA_print_fp(FILE *fp, const RSA *r,int offset);
281int RSA_print(BIO *bp, const RSA *r,int offset); 257int RSA_print(BIO *bp, const RSA *r,int offset);
282#endif 258#endif
283 259
284int i2d_RSA_NET(const RSA *a, unsigned char **pp, 260int i2d_RSA_NET(const RSA *a, unsigned char **pp, int (*cb)(), int sgckey);
285 int (*cb)(char *buf, int len, const char *prompt, int verify), 261RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length, int (*cb)(), int sgckey);
286 int sgckey);
287RSA *d2i_RSA_NET(RSA **a, const unsigned char **pp, long length,
288 int (*cb)(char *buf, int len, const char *prompt, int verify),
289 int sgckey);
290 262
291int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, 263int i2d_Netscape_RSA(const RSA *a, unsigned char **pp, int (*cb)());
292 int (*cb)(char *buf, int len, const char *prompt, 264RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length, int (*cb)());
293 int verify));
294RSA *d2i_Netscape_RSA(RSA **a, const unsigned char **pp, long length,
295 int (*cb)(char *buf, int len, const char *prompt,
296 int verify));
297 265
298/* The following 2 functions sign and verify a X509_SIG ASN1 object 266/* The following 2 functions sign and verify a X509_SIG ASN1 object
299 * inside PKCS#1 padded RSA encryption */ 267 * inside PKCS#1 padded RSA encryption */
@@ -313,7 +281,6 @@ int RSA_verify_ASN1_OCTET_STRING(int type,
313 281
314int RSA_blinding_on(RSA *rsa, BN_CTX *ctx); 282int RSA_blinding_on(RSA *rsa, BN_CTX *ctx);
315void RSA_blinding_off(RSA *rsa); 283void RSA_blinding_off(RSA *rsa);
316BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *ctx);
317 284
318int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen, 285int RSA_padding_add_PKCS1_type_1(unsigned char *to,int tlen,
319 const unsigned char *f,int fl); 286 const unsigned char *f,int fl);
@@ -369,21 +336,14 @@ void ERR_load_RSA_strings(void);
369 336
370/* Function codes. */ 337/* Function codes. */
371#define RSA_F_MEMORY_LOCK 100 338#define RSA_F_MEMORY_LOCK 100
372#define RSA_F_RSA_BUILTIN_KEYGEN 129
373#define RSA_F_RSA_CHECK_KEY 123 339#define RSA_F_RSA_CHECK_KEY 123
374#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101 340#define RSA_F_RSA_EAY_PRIVATE_DECRYPT 101
375#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102 341#define RSA_F_RSA_EAY_PRIVATE_ENCRYPT 102
376#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103 342#define RSA_F_RSA_EAY_PUBLIC_DECRYPT 103
377#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104 343#define RSA_F_RSA_EAY_PUBLIC_ENCRYPT 104
378#define RSA_F_RSA_GENERATE_KEY 105 344#define RSA_F_RSA_GENERATE_KEY 105
379#define RSA_F_RSA_MEMORY_LOCK 130
380#define RSA_F_RSA_NEW_METHOD 106 345#define RSA_F_RSA_NEW_METHOD 106
381#define RSA_F_RSA_NULL 124 346#define RSA_F_RSA_NULL 124
382#define RSA_F_RSA_NULL_MOD_EXP 131
383#define RSA_F_RSA_NULL_PRIVATE_DECRYPT 132
384#define RSA_F_RSA_NULL_PRIVATE_ENCRYPT 133
385#define RSA_F_RSA_NULL_PUBLIC_DECRYPT 134
386#define RSA_F_RSA_NULL_PUBLIC_ENCRYPT 135
387#define RSA_F_RSA_PADDING_ADD_NONE 107 347#define RSA_F_RSA_PADDING_ADD_NONE 107
388#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121 348#define RSA_F_RSA_PADDING_ADD_PKCS1_OAEP 121
389#define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125 349#define RSA_F_RSA_PADDING_ADD_PKCS1_PSS 125
@@ -399,7 +359,6 @@ void ERR_load_RSA_strings(void);
399#define RSA_F_RSA_PADDING_CHECK_X931 128 359#define RSA_F_RSA_PADDING_CHECK_X931 128
400#define RSA_F_RSA_PRINT 115 360#define RSA_F_RSA_PRINT 115
401#define RSA_F_RSA_PRINT_FP 116 361#define RSA_F_RSA_PRINT_FP 116
402#define RSA_F_RSA_SETUP_BLINDING 136
403#define RSA_F_RSA_SIGN 117 362#define RSA_F_RSA_SIGN 117
404#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118 363#define RSA_F_RSA_SIGN_ASN1_OCTET_STRING 118
405#define RSA_F_RSA_VERIFY 119 364#define RSA_F_RSA_VERIFY 119
@@ -433,7 +392,6 @@ void ERR_load_RSA_strings(void);
433#define RSA_R_KEY_SIZE_TOO_SMALL 120 392#define RSA_R_KEY_SIZE_TOO_SMALL 120
434#define RSA_R_LAST_OCTET_INVALID 134 393#define RSA_R_LAST_OCTET_INVALID 134
435#define RSA_R_MODULUS_TOO_LARGE 105 394#define RSA_R_MODULUS_TOO_LARGE 105
436#define RSA_R_NO_PUBLIC_EXPONENT 140
437#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113 395#define RSA_R_NULL_BEFORE_BLOCK_MISSING 113
438#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127 396#define RSA_R_N_DOES_NOT_EQUAL_P_Q 127
439#define RSA_R_OAEP_DECODING_ERROR 121 397#define RSA_R_OAEP_DECODING_ERROR 121
diff --git a/src/lib/libcrypto/rsa/rsa_asn1.c b/src/lib/libcrypto/rsa/rsa_asn1.c
index bbbf26d50e..1455a7e0e4 100644
--- a/src/lib/libcrypto/rsa/rsa_asn1.c
+++ b/src/lib/libcrypto/rsa/rsa_asn1.c
@@ -63,10 +63,10 @@
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64 64
65static ASN1_METHOD method={ 65static ASN1_METHOD method={
66 (I2D_OF(void)) i2d_RSAPrivateKey, 66 (int (*)()) i2d_RSAPrivateKey,
67 (D2I_OF(void)) d2i_RSAPrivateKey, 67 (char *(*)())d2i_RSAPrivateKey,
68 (void *(*)(void)) RSA_new, 68 (char *(*)())RSA_new,
69 (void (*)(void *)) RSA_free}; 69 (void (*)()) RSA_free};
70 70
71ASN1_METHOD *RSAPrivateKey_asn1_meth(void) 71ASN1_METHOD *RSAPrivateKey_asn1_meth(void)
72 { 72 {
diff --git a/src/lib/libcrypto/rsa/rsa_chk.c b/src/lib/libcrypto/rsa/rsa_chk.c
index 9d848db8c6..002f2cb487 100644
--- a/src/lib/libcrypto/rsa/rsa_chk.c
+++ b/src/lib/libcrypto/rsa/rsa_chk.c
@@ -75,7 +75,7 @@ int RSA_check_key(const RSA *key)
75 } 75 }
76 76
77 /* p prime? */ 77 /* p prime? */
78 r = BN_is_prime_ex(key->p, BN_prime_checks, NULL, NULL); 78 r = BN_is_prime(key->p, BN_prime_checks, NULL, NULL, NULL);
79 if (r != 1) 79 if (r != 1)
80 { 80 {
81 ret = r; 81 ret = r;
@@ -85,7 +85,7 @@ int RSA_check_key(const RSA *key)
85 } 85 }
86 86
87 /* q prime? */ 87 /* q prime? */
88 r = BN_is_prime_ex(key->q, BN_prime_checks, NULL, NULL); 88 r = BN_is_prime(key->q, BN_prime_checks, NULL, NULL, NULL);
89 if (r != 1) 89 if (r != 1)
90 { 90 {
91 ret = r; 91 ret = r;
diff --git a/src/lib/libcrypto/rsa/rsa_eay.c b/src/lib/libcrypto/rsa/rsa_eay.c
index ffadaab9a4..610889dc80 100644
--- a/src/lib/libcrypto/rsa/rsa_eay.c
+++ b/src/lib/libcrypto/rsa/rsa_eay.c
@@ -56,7 +56,7 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ==================================================================== 58/* ====================================================================
59 * Copyright (c) 1998-2006 The OpenSSL Project. All rights reserved. 59 * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
60 * 60 *
61 * Redistribution and use in source and binary forms, with or without 61 * Redistribution and use in source and binary forms, with or without
62 * modification, are permitted provided that the following conditions 62 * modification, are permitted provided that the following conditions
@@ -115,7 +115,7 @@
115#include <openssl/rsa.h> 115#include <openssl/rsa.h>
116#include <openssl/rand.h> 116#include <openssl/rand.h>
117 117
118#ifndef RSA_NULL 118#if !defined(RSA_NULL) && !defined(OPENSSL_FIPS)
119 119
120static int RSA_eay_public_encrypt(int flen, const unsigned char *from, 120static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
121 unsigned char *to, RSA *rsa,int padding); 121 unsigned char *to, RSA *rsa,int padding);
@@ -125,7 +125,7 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
125 unsigned char *to, RSA *rsa,int padding); 125 unsigned char *to, RSA *rsa,int padding);
126static int RSA_eay_private_decrypt(int flen, const unsigned char *from, 126static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
127 unsigned char *to, RSA *rsa,int padding); 127 unsigned char *to, RSA *rsa,int padding);
128static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa, BN_CTX *ctx); 128static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *i, RSA *rsa);
129static int RSA_eay_init(RSA *rsa); 129static int RSA_eay_init(RSA *rsa);
130static int RSA_eay_finish(RSA *rsa); 130static int RSA_eay_finish(RSA *rsa);
131static RSA_METHOD rsa_pkcs1_eay_meth={ 131static RSA_METHOD rsa_pkcs1_eay_meth={
@@ -141,8 +141,7 @@ static RSA_METHOD rsa_pkcs1_eay_meth={
141 0, /* flags */ 141 0, /* flags */
142 NULL, 142 NULL,
143 0, /* rsa_sign */ 143 0, /* rsa_sign */
144 0, /* rsa_verify */ 144 0 /* rsa_verify */
145 NULL /* rsa_keygen */
146 }; 145 };
147 146
148const RSA_METHOD *RSA_PKCS1_SSLeay(void) 147const RSA_METHOD *RSA_PKCS1_SSLeay(void)
@@ -150,53 +149,19 @@ const RSA_METHOD *RSA_PKCS1_SSLeay(void)
150 return(&rsa_pkcs1_eay_meth); 149 return(&rsa_pkcs1_eay_meth);
151 } 150 }
152 151
153/* Usage example;
154 * MONT_HELPER(rsa->_method_mod_p, bn_ctx, rsa->p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
155 */
156#define MONT_HELPER(method_mod, ctx, m, pre_cond, err_instr) \
157 if ((pre_cond) && ((method_mod) == NULL) && \
158 !BN_MONT_CTX_set_locked(&(method_mod), \
159 CRYPTO_LOCK_RSA, \
160 (m), (ctx))) \
161 err_instr
162
163static int RSA_eay_public_encrypt(int flen, const unsigned char *from, 152static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
164 unsigned char *to, RSA *rsa, int padding) 153 unsigned char *to, RSA *rsa, int padding)
165 { 154 {
166 BIGNUM *f,*ret; 155 BIGNUM f,ret;
167 int i,j,k,num=0,r= -1; 156 int i,j,k,num=0,r= -1;
168 unsigned char *buf=NULL; 157 unsigned char *buf=NULL;
169 BN_CTX *ctx=NULL; 158 BN_CTX *ctx=NULL;
170 159
171 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS) 160 BN_init(&f);
172 { 161 BN_init(&ret);
173 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
174 return -1;
175 }
176
177 if (BN_ucmp(rsa->n, rsa->e) <= 0)
178 {
179 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
180 return -1;
181 }
182
183 /* for large moduli, enforce exponent limit */
184 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
185 {
186 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
187 {
188 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
189 return -1;
190 }
191 }
192
193 if ((ctx=BN_CTX_new()) == NULL) goto err; 162 if ((ctx=BN_CTX_new()) == NULL) goto err;
194 BN_CTX_start(ctx);
195 f = BN_CTX_get(ctx);
196 ret = BN_CTX_get(ctx);
197 num=BN_num_bytes(rsa->n); 163 num=BN_num_bytes(rsa->n);
198 buf = OPENSSL_malloc(num); 164 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
199 if (!f || !ret || !buf)
200 { 165 {
201 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE); 166 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,ERR_R_MALLOC_FAILURE);
202 goto err; 167 goto err;
@@ -224,34 +189,37 @@ static int RSA_eay_public_encrypt(int flen, const unsigned char *from,
224 } 189 }
225 if (i <= 0) goto err; 190 if (i <= 0) goto err;
226 191
227 if (BN_bin2bn(buf,num,f) == NULL) goto err; 192 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
228 193
229 if (BN_ucmp(f, rsa->n) >= 0) 194 if (BN_ucmp(&f, rsa->n) >= 0)
230 { 195 {
231 /* usually the padding functions would catch this */ 196 /* usually the padding functions would catch this */
232 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS); 197 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
233 goto err; 198 goto err;
234 } 199 }
235 200
236 MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); 201 if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
202 {
203 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
204 CRYPTO_LOCK_RSA, rsa->n, ctx))
205 goto err;
206 }
237 207
238 if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, 208 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
239 rsa->_method_mod_n)) goto err; 209 rsa->_method_mod_n)) goto err;
240 210
241 /* put in leading 0 bytes if the number is less than the 211 /* put in leading 0 bytes if the number is less than the
242 * length of the modulus */ 212 * length of the modulus */
243 j=BN_num_bytes(ret); 213 j=BN_num_bytes(&ret);
244 i=BN_bn2bin(ret,&(to[num-j])); 214 i=BN_bn2bin(&ret,&(to[num-j]));
245 for (k=0; k<(num-i); k++) 215 for (k=0; k<(num-i); k++)
246 to[k]=0; 216 to[k]=0;
247 217
248 r=num; 218 r=num;
249err: 219err:
250 if (ctx != NULL) 220 if (ctx != NULL) BN_CTX_free(ctx);
251 { 221 BN_clear_free(&f);
252 BN_CTX_end(ctx); 222 BN_clear_free(&ret);
253 BN_CTX_free(ctx);
254 }
255 if (buf != NULL) 223 if (buf != NULL)
256 { 224 {
257 OPENSSL_cleanse(buf,num); 225 OPENSSL_cleanse(buf,num);
@@ -260,115 +228,98 @@ err:
260 return(r); 228 return(r);
261 } 229 }
262 230
263static BN_BLINDING *rsa_get_blinding(RSA *rsa, int *local, BN_CTX *ctx) 231static int rsa_eay_blinding(RSA *rsa, BN_CTX *ctx)
264{ 232 {
265 BN_BLINDING *ret; 233 int ret = 1;
266 int got_write_lock = 0; 234 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
235 /* Check again inside the lock - the macro's check is racey */
236 if(rsa->blinding == NULL)
237 ret = RSA_blinding_on(rsa, ctx);
238 CRYPTO_w_unlock(CRYPTO_LOCK_RSA);
239 return ret;
240 }
267 241
268 CRYPTO_r_lock(CRYPTO_LOCK_RSA); 242#define BLINDING_HELPER(rsa, ctx, err_instr) \
243 do { \
244 if((!((rsa)->flags & RSA_FLAG_NO_BLINDING)) && \
245 ((rsa)->blinding == NULL) && \
246 !rsa_eay_blinding(rsa, ctx)) \
247 err_instr \
248 } while(0)
269 249
270 if (rsa->blinding == NULL) 250static BN_BLINDING *setup_blinding(RSA *rsa, BN_CTX *ctx)
271 { 251 {
272 CRYPTO_r_unlock(CRYPTO_LOCK_RSA); 252 BIGNUM *A, *Ai;
273 CRYPTO_w_lock(CRYPTO_LOCK_RSA); 253 BN_BLINDING *ret = NULL;
274 got_write_lock = 1;
275 254
276 if (rsa->blinding == NULL) 255 /* added in OpenSSL 0.9.6j and 0.9.7b */
277 rsa->blinding = RSA_setup_blinding(rsa, ctx);
278 }
279 256
280 ret = rsa->blinding; 257 /* NB: similar code appears in RSA_blinding_on (rsa_lib.c);
281 if (ret == NULL) 258 * this should be placed in a new function of its own, but for reasons
282 goto err; 259 * of binary compatibility can't */
283 260
284 if (BN_BLINDING_get_thread_id(ret) == CRYPTO_thread_id()) 261 BN_CTX_start(ctx);
262 A = BN_CTX_get(ctx);
263 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
285 { 264 {
286 /* rsa->blinding is ours! */ 265 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
287 266 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
288 *local = 1; 267 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
289 } 268 }
290 else 269 else
291 { 270 {
292 /* resort to rsa->mt_blinding instead */ 271 if (!BN_rand_range(A,rsa->n)) goto err;
293
294 *local = 0; /* instructs rsa_blinding_convert(), rsa_blinding_invert()
295 * that the BN_BLINDING is shared, meaning that accesses
296 * require locks, and that the blinding factor must be
297 * stored outside the BN_BLINDING
298 */
299
300 if (rsa->mt_blinding == NULL)
301 {
302 if (!got_write_lock)
303 {
304 CRYPTO_r_unlock(CRYPTO_LOCK_RSA);
305 CRYPTO_w_lock(CRYPTO_LOCK_RSA);
306 got_write_lock = 1;
307 }
308
309 if (rsa->mt_blinding == NULL)
310 rsa->mt_blinding = RSA_setup_blinding(rsa, ctx);
311 }
312 ret = rsa->mt_blinding;
313 } 272 }
273 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
314 274
315 err: 275 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
316 if (got_write_lock) 276 goto err;
317 CRYPTO_w_unlock(CRYPTO_LOCK_RSA); 277 ret = BN_BLINDING_new(A,Ai,rsa->n);
318 else 278 BN_free(Ai);
319 CRYPTO_r_unlock(CRYPTO_LOCK_RSA); 279err:
280 BN_CTX_end(ctx);
320 return ret; 281 return ret;
321} 282 }
322
323static int rsa_blinding_convert(BN_BLINDING *b, int local, BIGNUM *f,
324 BIGNUM *r, BN_CTX *ctx)
325{
326 if (local)
327 return BN_BLINDING_convert_ex(f, NULL, b, ctx);
328 else
329 {
330 int ret;
331 CRYPTO_r_lock(CRYPTO_LOCK_RSA_BLINDING);
332 ret = BN_BLINDING_convert_ex(f, r, b, ctx);
333 CRYPTO_r_unlock(CRYPTO_LOCK_RSA_BLINDING);
334 return ret;
335 }
336}
337
338static int rsa_blinding_invert(BN_BLINDING *b, int local, BIGNUM *f,
339 BIGNUM *r, BN_CTX *ctx)
340{
341 if (local)
342 return BN_BLINDING_invert_ex(f, NULL, b, ctx);
343 else
344 {
345 int ret;
346 CRYPTO_w_lock(CRYPTO_LOCK_RSA_BLINDING);
347 ret = BN_BLINDING_invert_ex(f, r, b, ctx);
348 CRYPTO_w_unlock(CRYPTO_LOCK_RSA_BLINDING);
349 return ret;
350 }
351}
352 283
353/* signing */ 284/* signing */
354static int RSA_eay_private_encrypt(int flen, const unsigned char *from, 285static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
355 unsigned char *to, RSA *rsa, int padding) 286 unsigned char *to, RSA *rsa, int padding)
356 { 287 {
357 BIGNUM *f, *ret, *br, *res; 288 BIGNUM f,ret, *res;
358 int i,j,k,num=0,r= -1; 289 int i,j,k,num=0,r= -1;
359 unsigned char *buf=NULL; 290 unsigned char *buf=NULL;
360 BN_CTX *ctx=NULL; 291 BN_CTX *ctx=NULL;
361 int local_blinding = 0; 292 int local_blinding = 0;
362 BN_BLINDING *blinding = NULL; 293 BN_BLINDING *blinding = NULL;
363 294
295 BN_init(&f);
296 BN_init(&ret);
297
298 if (BN_num_bits(rsa->n) > OPENSSL_RSA_MAX_MODULUS_BITS)
299 {
300 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_MODULUS_TOO_LARGE);
301 return -1;
302 }
303
304 if (BN_ucmp(rsa->n, rsa->e) <= 0)
305 {
306 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
307 return -1;
308 }
309
310 /* for large moduli, enforce exponent limit */
311 if (BN_num_bits(rsa->n) > OPENSSL_RSA_SMALL_MODULUS_BITS)
312 {
313 if (BN_num_bits(rsa->e) > OPENSSL_RSA_MAX_PUBEXP_BITS)
314 {
315 RSAerr(RSA_F_RSA_EAY_PUBLIC_ENCRYPT, RSA_R_BAD_E_VALUE);
316 return -1;
317 }
318 }
319
364 if ((ctx=BN_CTX_new()) == NULL) goto err; 320 if ((ctx=BN_CTX_new()) == NULL) goto err;
365 BN_CTX_start(ctx); 321 num=BN_num_bytes(rsa->n);
366 f = BN_CTX_get(ctx); 322 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
367 br = BN_CTX_get(ctx);
368 ret = BN_CTX_get(ctx);
369 num = BN_num_bytes(rsa->n);
370 buf = OPENSSL_malloc(num);
371 if(!f || !ret || !buf)
372 { 323 {
373 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE); 324 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,ERR_R_MALLOC_FAILURE);
374 goto err; 325 goto err;
@@ -379,9 +330,6 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
379 case RSA_PKCS1_PADDING: 330 case RSA_PKCS1_PADDING:
380 i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen); 331 i=RSA_padding_add_PKCS1_type_1(buf,num,from,flen);
381 break; 332 break;
382 case RSA_X931_PADDING:
383 i=RSA_padding_add_X931(buf,num,from,flen);
384 break;
385 case RSA_NO_PADDING: 333 case RSA_NO_PADDING:
386 i=RSA_padding_add_none(buf,num,from,flen); 334 i=RSA_padding_add_none(buf,num,from,flen);
387 break; 335 break;
@@ -392,18 +340,26 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
392 } 340 }
393 if (i <= 0) goto err; 341 if (i <= 0) goto err;
394 342
395 if (BN_bin2bn(buf,num,f) == NULL) goto err; 343 if (BN_bin2bn(buf,num,&f) == NULL) goto err;
396 344
397 if (BN_ucmp(f, rsa->n) >= 0) 345 if (BN_ucmp(&f, rsa->n) >= 0)
398 { 346 {
399 /* usually the padding functions would catch this */ 347 /* usually the padding functions would catch this */
400 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS); 348 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
401 goto err; 349 goto err;
402 } 350 }
403 351
352 BLINDING_HELPER(rsa, ctx, goto err;);
353 blinding = rsa->blinding;
354
355 /* Now unless blinding is disabled, 'blinding' is non-NULL.
356 * But the BN_BLINDING object may be owned by some other thread
357 * (we don't want to keep it constant and we don't want to use
358 * lots of locking to avoid race conditions, so only a single
359 * thread can use it; other threads have to use local blinding
360 * factors) */
404 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) 361 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
405 { 362 {
406 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
407 if (blinding == NULL) 363 if (blinding == NULL)
408 { 364 {
409 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR); 365 RSAerr(RSA_F_RSA_EAY_PRIVATE_ENCRYPT, ERR_R_INTERNAL_ERROR);
@@ -412,8 +368,20 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
412 } 368 }
413 369
414 if (blinding != NULL) 370 if (blinding != NULL)
415 if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx)) 371 {
416 goto err; 372 if (blinding->thread_id != CRYPTO_thread_id())
373 {
374 /* we need a local one-time blinding factor */
375
376 blinding = setup_blinding(rsa, ctx);
377 if (blinding == NULL)
378 goto err;
379 local_blinding = 1;
380 }
381 }
382
383 if (blinding)
384 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
417 385
418 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || 386 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
419 ((rsa->p != NULL) && 387 ((rsa->p != NULL) &&
@@ -422,42 +390,37 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
422 (rsa->dmq1 != NULL) && 390 (rsa->dmq1 != NULL) &&
423 (rsa->iqmp != NULL)) ) 391 (rsa->iqmp != NULL)) )
424 { 392 {
425 if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err; 393 if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err;
426 } 394 }
427 else 395 else
428 { 396 {
429 BIGNUM local_d; 397 BIGNUM local_d;
430 BIGNUM *d = NULL; 398 BIGNUM *d = NULL;
431 399
432 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 400 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
433 { 401 {
434 BN_init(&local_d); 402 BN_init(&local_d);
435 d = &local_d; 403 d = &local_d;
436 BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); 404 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
437 } 405 }
438 else 406 else
439 d= rsa->d; 407 d = rsa->d;
440 408 if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL)) goto err;
441 MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
442
443 if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
444 rsa->_method_mod_n)) goto err;
445 } 409 }
446 410
447 if (blinding) 411 if (blinding)
448 if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx)) 412 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
449 goto err;
450 413
451 if (padding == RSA_X931_PADDING) 414 if (padding == RSA_X931_PADDING)
452 { 415 {
453 BN_sub(f, rsa->n, ret); 416 BN_sub(&f, rsa->n, &ret);
454 if (BN_cmp(ret, f)) 417 if (BN_cmp(&ret, &f))
455 res = f; 418 res = &f;
456 else 419 else
457 res = ret; 420 res = &ret;
458 } 421 }
459 else 422 else
460 res = ret; 423 res = &ret;
461 424
462 /* put in leading 0 bytes if the number is less than the 425 /* put in leading 0 bytes if the number is less than the
463 * length of the modulus */ 426 * length of the modulus */
@@ -468,11 +431,11 @@ static int RSA_eay_private_encrypt(int flen, const unsigned char *from,
468 431
469 r=num; 432 r=num;
470err: 433err:
471 if (ctx != NULL) 434 if (ctx != NULL) BN_CTX_free(ctx);
472 { 435 BN_clear_free(&ret);
473 BN_CTX_end(ctx); 436 BN_clear_free(&f);
474 BN_CTX_free(ctx); 437 if (local_blinding)
475 } 438 BN_BLINDING_free(blinding);
476 if (buf != NULL) 439 if (buf != NULL)
477 { 440 {
478 OPENSSL_cleanse(buf,num); 441 OPENSSL_cleanse(buf,num);
@@ -484,7 +447,7 @@ err:
484static int RSA_eay_private_decrypt(int flen, const unsigned char *from, 447static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
485 unsigned char *to, RSA *rsa, int padding) 448 unsigned char *to, RSA *rsa, int padding)
486 { 449 {
487 BIGNUM *f, *ret, *br; 450 BIGNUM f,ret;
488 int j,num=0,r= -1; 451 int j,num=0,r= -1;
489 unsigned char *p; 452 unsigned char *p;
490 unsigned char *buf=NULL; 453 unsigned char *buf=NULL;
@@ -492,14 +455,14 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
492 int local_blinding = 0; 455 int local_blinding = 0;
493 BN_BLINDING *blinding = NULL; 456 BN_BLINDING *blinding = NULL;
494 457
495 if((ctx = BN_CTX_new()) == NULL) goto err; 458 BN_init(&f);
496 BN_CTX_start(ctx); 459 BN_init(&ret);
497 f = BN_CTX_get(ctx); 460 ctx=BN_CTX_new();
498 br = BN_CTX_get(ctx); 461 if (ctx == NULL) goto err;
499 ret = BN_CTX_get(ctx); 462
500 num = BN_num_bytes(rsa->n); 463 num=BN_num_bytes(rsa->n);
501 buf = OPENSSL_malloc(num); 464
502 if(!f || !ret || !buf) 465 if ((buf=(unsigned char *)OPENSSL_malloc(num)) == NULL)
503 { 466 {
504 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE); 467 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,ERR_R_MALLOC_FAILURE);
505 goto err; 468 goto err;
@@ -514,17 +477,25 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
514 } 477 }
515 478
516 /* make data into a big number */ 479 /* make data into a big number */
517 if (BN_bin2bn(from,(int)flen,f) == NULL) goto err; 480 if (BN_bin2bn(from,(int)flen,&f) == NULL) goto err;
518 481
519 if (BN_ucmp(f, rsa->n) >= 0) 482 if (BN_ucmp(&f, rsa->n) >= 0)
520 { 483 {
521 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS); 484 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
522 goto err; 485 goto err;
523 } 486 }
524 487
488 BLINDING_HELPER(rsa, ctx, goto err;);
489 blinding = rsa->blinding;
490
491 /* Now unless blinding is disabled, 'blinding' is non-NULL.
492 * But the BN_BLINDING object may be owned by some other thread
493 * (we don't want to keep it constant and we don't want to use
494 * lots of locking to avoid race conditions, so only a single
495 * thread can use it; other threads have to use local blinding
496 * factors) */
525 if (!(rsa->flags & RSA_FLAG_NO_BLINDING)) 497 if (!(rsa->flags & RSA_FLAG_NO_BLINDING))
526 { 498 {
527 blinding = rsa_get_blinding(rsa, &local_blinding, ctx);
528 if (blinding == NULL) 499 if (blinding == NULL)
529 { 500 {
530 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR); 501 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT, ERR_R_INTERNAL_ERROR);
@@ -533,8 +504,20 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
533 } 504 }
534 505
535 if (blinding != NULL) 506 if (blinding != NULL)
536 if (!rsa_blinding_convert(blinding, local_blinding, f, br, ctx)) 507 {
537 goto err; 508 if (blinding->thread_id != CRYPTO_thread_id())
509 {
510 /* we need a local one-time blinding factor */
511
512 blinding = setup_blinding(rsa, ctx);
513 if (blinding == NULL)
514 goto err;
515 local_blinding = 1;
516 }
517 }
518
519 if (blinding)
520 if (!BN_BLINDING_convert(&f, blinding, ctx)) goto err;
538 521
539 /* do the decrypt */ 522 /* do the decrypt */
540 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) || 523 if ( (rsa->flags & RSA_FLAG_EXT_PKEY) ||
@@ -544,33 +527,29 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
544 (rsa->dmq1 != NULL) && 527 (rsa->dmq1 != NULL) &&
545 (rsa->iqmp != NULL)) ) 528 (rsa->iqmp != NULL)) )
546 { 529 {
547 if (!rsa->meth->rsa_mod_exp(ret, f, rsa, ctx)) goto err; 530 if (!rsa->meth->rsa_mod_exp(&ret,&f,rsa)) goto err;
548 } 531 }
549 else 532 else
550 { 533 {
551 BIGNUM local_d; 534 BIGNUM local_d;
552 BIGNUM *d = NULL; 535 BIGNUM *d = NULL;
553 536
554 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 537 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
555 { 538 {
556 d = &local_d; 539 d = &local_d;
557 BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); 540 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
558 } 541 }
559 else 542 else
560 d = rsa->d; 543 d = rsa->d;
561 544 if (!rsa->meth->bn_mod_exp(&ret,&f,d,rsa->n,ctx,NULL))
562 MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); 545 goto err;
563 if (!rsa->meth->bn_mod_exp(ret,f,d,rsa->n,ctx,
564 rsa->_method_mod_n))
565 goto err;
566 } 546 }
567 547
568 if (blinding) 548 if (blinding)
569 if (!rsa_blinding_invert(blinding, local_blinding, ret, br, ctx)) 549 if (!BN_BLINDING_invert(&ret, blinding, ctx)) goto err;
570 goto err;
571 550
572 p=buf; 551 p=buf;
573 j=BN_bn2bin(ret,p); /* j is only used with no-padding mode */ 552 j=BN_bn2bin(&ret,p); /* j is only used with no-padding mode */
574 553
575 switch (padding) 554 switch (padding)
576 { 555 {
@@ -596,11 +575,11 @@ static int RSA_eay_private_decrypt(int flen, const unsigned char *from,
596 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED); 575 RSAerr(RSA_F_RSA_EAY_PRIVATE_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
597 576
598err: 577err:
599 if (ctx != NULL) 578 if (ctx != NULL) BN_CTX_free(ctx);
600 { 579 BN_clear_free(&f);
601 BN_CTX_end(ctx); 580 BN_clear_free(&ret);
602 BN_CTX_free(ctx); 581 if (local_blinding)
603 } 582 BN_BLINDING_free(blinding);
604 if (buf != NULL) 583 if (buf != NULL)
605 { 584 {
606 OPENSSL_cleanse(buf,num); 585 OPENSSL_cleanse(buf,num);
@@ -613,7 +592,7 @@ err:
613static int RSA_eay_public_decrypt(int flen, const unsigned char *from, 592static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
614 unsigned char *to, RSA *rsa, int padding) 593 unsigned char *to, RSA *rsa, int padding)
615 { 594 {
616 BIGNUM *f,*ret; 595 BIGNUM f,ret;
617 int i,num=0,r= -1; 596 int i,num=0,r= -1;
618 unsigned char *p; 597 unsigned char *p;
619 unsigned char *buf=NULL; 598 unsigned char *buf=NULL;
@@ -640,14 +619,15 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
640 return -1; 619 return -1;
641 } 620 }
642 } 621 }
643 622
644 if((ctx = BN_CTX_new()) == NULL) goto err; 623 BN_init(&f);
645 BN_CTX_start(ctx); 624 BN_init(&ret);
646 f = BN_CTX_get(ctx); 625 ctx=BN_CTX_new();
647 ret = BN_CTX_get(ctx); 626 if (ctx == NULL) goto err;
627
648 num=BN_num_bytes(rsa->n); 628 num=BN_num_bytes(rsa->n);
649 buf = OPENSSL_malloc(num); 629 buf=(unsigned char *)OPENSSL_malloc(num);
650 if(!f || !ret || !buf) 630 if (buf == NULL)
651 { 631 {
652 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE); 632 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,ERR_R_MALLOC_FAILURE);
653 goto err; 633 goto err;
@@ -661,33 +641,37 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
661 goto err; 641 goto err;
662 } 642 }
663 643
664 if (BN_bin2bn(from,flen,f) == NULL) goto err; 644 if (BN_bin2bn(from,flen,&f) == NULL) goto err;
665 645
666 if (BN_ucmp(f, rsa->n) >= 0) 646 if (BN_ucmp(&f, rsa->n) >= 0)
667 { 647 {
668 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS); 648 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_DATA_TOO_LARGE_FOR_MODULUS);
669 goto err; 649 goto err;
670 } 650 }
671 651
672 MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err); 652 /* do the decrypt */
653
654 if (rsa->flags & RSA_FLAG_CACHE_PUBLIC)
655 {
656 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_n,
657 CRYPTO_LOCK_RSA, rsa->n, ctx))
658 goto err;
659 }
673 660
674 if (!rsa->meth->bn_mod_exp(ret,f,rsa->e,rsa->n,ctx, 661 if (!rsa->meth->bn_mod_exp(&ret,&f,rsa->e,rsa->n,ctx,
675 rsa->_method_mod_n)) goto err; 662 rsa->_method_mod_n)) goto err;
676 663
677 if ((padding == RSA_X931_PADDING) && ((ret->d[0] & 0xf) != 12)) 664 if ((padding == RSA_X931_PADDING) && ((ret.d[0] & 0xf) != 12))
678 BN_sub(ret, rsa->n, ret); 665 BN_sub(&ret, rsa->n, &ret);
679 666
680 p=buf; 667 p=buf;
681 i=BN_bn2bin(ret,p); 668 i=BN_bn2bin(&ret,p);
682 669
683 switch (padding) 670 switch (padding)
684 { 671 {
685 case RSA_PKCS1_PADDING: 672 case RSA_PKCS1_PADDING:
686 r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num); 673 r=RSA_padding_check_PKCS1_type_1(to,num,buf,i,num);
687 break; 674 break;
688 case RSA_X931_PADDING:
689 r=RSA_padding_check_X931(to,num,buf,i,num);
690 break;
691 case RSA_NO_PADDING: 675 case RSA_NO_PADDING:
692 r=RSA_padding_check_none(to,num,buf,i,num); 676 r=RSA_padding_check_none(to,num,buf,i,num);
693 break; 677 break;
@@ -699,11 +683,9 @@ static int RSA_eay_public_decrypt(int flen, const unsigned char *from,
699 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED); 683 RSAerr(RSA_F_RSA_EAY_PUBLIC_DECRYPT,RSA_R_PADDING_CHECK_FAILED);
700 684
701err: 685err:
702 if (ctx != NULL) 686 if (ctx != NULL) BN_CTX_free(ctx);
703 { 687 BN_clear_free(&f);
704 BN_CTX_end(ctx); 688 BN_clear_free(&ret);
705 BN_CTX_free(ctx);
706 }
707 if (buf != NULL) 689 if (buf != NULL)
708 { 690 {
709 OPENSSL_cleanse(buf,num); 691 OPENSSL_cleanse(buf,num);
@@ -712,111 +694,59 @@ err:
712 return(r); 694 return(r);
713 } 695 }
714 696
715static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx) 697static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa)
716 { 698 {
717 BIGNUM *r1,*m1,*vrfy; 699 BIGNUM r1,m1,vrfy;
718 BIGNUM local_dmp1,local_dmq1,local_c,local_r1; 700 BIGNUM local_dmp1, local_dmq1;
719 BIGNUM *dmp1,*dmq1,*c,*pr1; 701 BIGNUM *dmp1, *dmq1;
720 int ret=0; 702 int ret=0;
703 BN_CTX *ctx;
721 704
722 BN_CTX_start(ctx); 705 BN_init(&m1);
723 r1 = BN_CTX_get(ctx); 706 BN_init(&r1);
724 m1 = BN_CTX_get(ctx); 707 BN_init(&vrfy);
725 vrfy = BN_CTX_get(ctx); 708 if ((ctx=BN_CTX_new()) == NULL) goto err;
726
727 {
728 BIGNUM local_p, local_q;
729 BIGNUM *p = NULL, *q = NULL;
730
731 /* Make sure BN_mod_inverse in Montgomery intialization uses the
732 * BN_FLG_CONSTTIME flag (unless RSA_FLAG_NO_CONSTTIME is set)
733 */
734 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
735 {
736 BN_init(&local_p);
737 p = &local_p;
738 BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);
739
740 BN_init(&local_q);
741 q = &local_q;
742 BN_with_flags(q, rsa->q, BN_FLG_CONSTTIME);
743 }
744 else
745 {
746 p = rsa->p;
747 q = rsa->q;
748 }
749
750 MONT_HELPER(rsa->_method_mod_p, ctx, p, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
751 MONT_HELPER(rsa->_method_mod_q, ctx, q, rsa->flags & RSA_FLAG_CACHE_PRIVATE, goto err);
752 }
753
754 MONT_HELPER(rsa->_method_mod_n, ctx, rsa->n, rsa->flags & RSA_FLAG_CACHE_PUBLIC, goto err);
755 709
756 /* compute I mod q */ 710 if (rsa->flags & RSA_FLAG_CACHE_PRIVATE)
757 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
758 {
759 c = &local_c;
760 BN_with_flags(c, I, BN_FLG_CONSTTIME);
761 if (!BN_mod(r1,c,rsa->q,ctx)) goto err;
762 }
763 else
764 { 711 {
765 if (!BN_mod(r1,I,rsa->q,ctx)) goto err; 712 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_p,
713 CRYPTO_LOCK_RSA, rsa->p, ctx))
714 goto err;
715 if (!BN_MONT_CTX_set_locked(&rsa->_method_mod_q,
716 CRYPTO_LOCK_RSA, rsa->q, ctx))
717 goto err;
766 } 718 }
767 719
768 /* compute r1^dmq1 mod q */ 720 if (!BN_mod(&r1,I,rsa->q,ctx)) goto err;
769 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 721 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
770 { 722 {
771 dmq1 = &local_dmq1; 723 dmq1 = &local_dmq1;
772 BN_with_flags(dmq1, rsa->dmq1, BN_FLG_CONSTTIME); 724 BN_with_flags(dmq1, rsa->dmq1, BN_FLG_EXP_CONSTTIME);
773 } 725 }
774 else 726 else
775 dmq1 = rsa->dmq1; 727 dmq1 = rsa->dmq1;
776 if (!rsa->meth->bn_mod_exp(m1,r1,dmq1,rsa->q,ctx, 728 if (!rsa->meth->bn_mod_exp(&m1,&r1,dmq1,rsa->q,ctx,
777 rsa->_method_mod_q)) goto err; 729 rsa->_method_mod_q)) goto err;
778 730
779 /* compute I mod p */ 731 if (!BN_mod(&r1,I,rsa->p,ctx)) goto err;
780 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 732 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
781 {
782 c = &local_c;
783 BN_with_flags(c, I, BN_FLG_CONSTTIME);
784 if (!BN_mod(r1,c,rsa->p,ctx)) goto err;
785 }
786 else
787 {
788 if (!BN_mod(r1,I,rsa->p,ctx)) goto err;
789 }
790
791 /* compute r1^dmp1 mod p */
792 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
793 { 733 {
794 dmp1 = &local_dmp1; 734 dmp1 = &local_dmp1;
795 BN_with_flags(dmp1, rsa->dmp1, BN_FLG_CONSTTIME); 735 BN_with_flags(dmp1, rsa->dmp1, BN_FLG_EXP_CONSTTIME);
796 } 736 }
797 else 737 else
798 dmp1 = rsa->dmp1; 738 dmp1 = rsa->dmp1;
799 if (!rsa->meth->bn_mod_exp(r0,r1,dmp1,rsa->p,ctx, 739 if (!rsa->meth->bn_mod_exp(r0,&r1,dmp1,rsa->p,ctx,
800 rsa->_method_mod_p)) goto err; 740 rsa->_method_mod_p)) goto err;
801 741
802 if (!BN_sub(r0,r0,m1)) goto err; 742 if (!BN_sub(r0,r0,&m1)) goto err;
803 /* This will help stop the size of r0 increasing, which does 743 /* This will help stop the size of r0 increasing, which does
804 * affect the multiply if it optimised for a power of 2 size */ 744 * affect the multiply if it optimised for a power of 2 size */
805 if (BN_is_negative(r0)) 745 if (r0->neg)
806 if (!BN_add(r0,r0,rsa->p)) goto err; 746 if (!BN_add(r0,r0,rsa->p)) goto err;
807 747
808 if (!BN_mul(r1,r0,rsa->iqmp,ctx)) goto err; 748 if (!BN_mul(&r1,r0,rsa->iqmp,ctx)) goto err;
809 749 if (!BN_mod(r0,&r1,rsa->p,ctx)) goto err;
810 /* Turn BN_FLG_CONSTTIME flag on before division operation */
811 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
812 {
813 pr1 = &local_r1;
814 BN_with_flags(pr1, r1, BN_FLG_CONSTTIME);
815 }
816 else
817 pr1 = r1;
818 if (!BN_mod(r0,pr1,rsa->p,ctx)) goto err;
819
820 /* If p < q it is occasionally possible for the correction of 750 /* If p < q it is occasionally possible for the correction of
821 * adding 'p' if r0 is negative above to leave the result still 751 * adding 'p' if r0 is negative above to leave the result still
822 * negative. This can break the private key operations: the following 752 * negative. This can break the private key operations: the following
@@ -824,23 +754,23 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
824 * This will *never* happen with OpenSSL generated keys because 754 * This will *never* happen with OpenSSL generated keys because
825 * they ensure p > q [steve] 755 * they ensure p > q [steve]
826 */ 756 */
827 if (BN_is_negative(r0)) 757 if (r0->neg)
828 if (!BN_add(r0,r0,rsa->p)) goto err; 758 if (!BN_add(r0,r0,rsa->p)) goto err;
829 if (!BN_mul(r1,r0,rsa->q,ctx)) goto err; 759 if (!BN_mul(&r1,r0,rsa->q,ctx)) goto err;
830 if (!BN_add(r0,r1,m1)) goto err; 760 if (!BN_add(r0,&r1,&m1)) goto err;
831 761
832 if (rsa->e && rsa->n) 762 if (rsa->e && rsa->n)
833 { 763 {
834 if (!rsa->meth->bn_mod_exp(vrfy,r0,rsa->e,rsa->n,ctx,rsa->_method_mod_n)) goto err; 764 if (!rsa->meth->bn_mod_exp(&vrfy,r0,rsa->e,rsa->n,ctx,NULL)) goto err;
835 /* If 'I' was greater than (or equal to) rsa->n, the operation 765 /* If 'I' was greater than (or equal to) rsa->n, the operation
836 * will be equivalent to using 'I mod n'. However, the result of 766 * will be equivalent to using 'I mod n'. However, the result of
837 * the verify will *always* be less than 'n' so we don't check 767 * the verify will *always* be less than 'n' so we don't check
838 * for absolute equality, just congruency. */ 768 * for absolute equality, just congruency. */
839 if (!BN_sub(vrfy, vrfy, I)) goto err; 769 if (!BN_sub(&vrfy, &vrfy, I)) goto err;
840 if (!BN_mod(vrfy, vrfy, rsa->n, ctx)) goto err; 770 if (!BN_mod(&vrfy, &vrfy, rsa->n, ctx)) goto err;
841 if (BN_is_negative(vrfy)) 771 if (vrfy.neg)
842 if (!BN_add(vrfy, vrfy, rsa->n)) goto err; 772 if (!BN_add(&vrfy, &vrfy, rsa->n)) goto err;
843 if (!BN_is_zero(vrfy)) 773 if (!BN_is_zero(&vrfy))
844 { 774 {
845 /* 'I' and 'vrfy' aren't congruent mod n. Don't leak 775 /* 'I' and 'vrfy' aren't congruent mod n. Don't leak
846 * miscalculated CRT output, just do a raw (slower) 776 * miscalculated CRT output, just do a raw (slower)
@@ -849,20 +779,22 @@ static int RSA_eay_mod_exp(BIGNUM *r0, const BIGNUM *I, RSA *rsa, BN_CTX *ctx)
849 BIGNUM local_d; 779 BIGNUM local_d;
850 BIGNUM *d = NULL; 780 BIGNUM *d = NULL;
851 781
852 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 782 if (!(rsa->flags & RSA_FLAG_NO_EXP_CONSTTIME))
853 { 783 {
854 d = &local_d; 784 d = &local_d;
855 BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); 785 BN_with_flags(d, rsa->d, BN_FLG_EXP_CONSTTIME);
856 } 786 }
857 else 787 else
858 d = rsa->d; 788 d = rsa->d;
859 if (!rsa->meth->bn_mod_exp(r0,I,d,rsa->n,ctx, 789 if (!rsa->meth->bn_mod_exp(r0,I,d,rsa->n,ctx,NULL)) goto err;
860 rsa->_method_mod_n)) goto err;
861 } 790 }
862 } 791 }
863 ret=1; 792 ret=1;
864err: 793err:
865 BN_CTX_end(ctx); 794 BN_clear_free(&m1);
795 BN_clear_free(&r1);
796 BN_clear_free(&vrfy);
797 BN_CTX_free(ctx);
866 return(ret); 798 return(ret);
867 } 799 }
868 800
diff --git a/src/lib/libcrypto/rsa/rsa_err.c b/src/lib/libcrypto/rsa/rsa_err.c
index fe3ba1b44b..ddcb28e663 100644
--- a/src/lib/libcrypto/rsa/rsa_err.c
+++ b/src/lib/libcrypto/rsa/rsa_err.c
@@ -71,21 +71,14 @@
71static ERR_STRING_DATA RSA_str_functs[]= 71static ERR_STRING_DATA RSA_str_functs[]=
72 { 72 {
73{ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"}, 73{ERR_FUNC(RSA_F_MEMORY_LOCK), "MEMORY_LOCK"},
74{ERR_FUNC(RSA_F_RSA_BUILTIN_KEYGEN), "RSA_BUILTIN_KEYGEN"},
75{ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"}, 74{ERR_FUNC(RSA_F_RSA_CHECK_KEY), "RSA_check_key"},
76{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"}, 75{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_DECRYPT), "RSA_EAY_PRIVATE_DECRYPT"},
77{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"}, 76{ERR_FUNC(RSA_F_RSA_EAY_PRIVATE_ENCRYPT), "RSA_EAY_PRIVATE_ENCRYPT"},
78{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"}, 77{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_DECRYPT), "RSA_EAY_PUBLIC_DECRYPT"},
79{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"}, 78{ERR_FUNC(RSA_F_RSA_EAY_PUBLIC_ENCRYPT), "RSA_EAY_PUBLIC_ENCRYPT"},
80{ERR_FUNC(RSA_F_RSA_GENERATE_KEY), "RSA_generate_key"}, 79{ERR_FUNC(RSA_F_RSA_GENERATE_KEY), "RSA_generate_key"},
81{ERR_FUNC(RSA_F_RSA_MEMORY_LOCK), "RSA_memory_lock"},
82{ERR_FUNC(RSA_F_RSA_NEW_METHOD), "RSA_new_method"}, 80{ERR_FUNC(RSA_F_RSA_NEW_METHOD), "RSA_new_method"},
83{ERR_FUNC(RSA_F_RSA_NULL), "RSA_NULL"}, 81{ERR_FUNC(RSA_F_RSA_NULL), "RSA_NULL"},
84{ERR_FUNC(RSA_F_RSA_NULL_MOD_EXP), "RSA_NULL_MOD_EXP"},
85{ERR_FUNC(RSA_F_RSA_NULL_PRIVATE_DECRYPT), "RSA_NULL_PRIVATE_DECRYPT"},
86{ERR_FUNC(RSA_F_RSA_NULL_PRIVATE_ENCRYPT), "RSA_NULL_PRIVATE_ENCRYPT"},
87{ERR_FUNC(RSA_F_RSA_NULL_PUBLIC_DECRYPT), "RSA_NULL_PUBLIC_DECRYPT"},
88{ERR_FUNC(RSA_F_RSA_NULL_PUBLIC_ENCRYPT), "RSA_NULL_PUBLIC_ENCRYPT"},
89{ERR_FUNC(RSA_F_RSA_PADDING_ADD_NONE), "RSA_padding_add_none"}, 82{ERR_FUNC(RSA_F_RSA_PADDING_ADD_NONE), "RSA_padding_add_none"},
90{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP), "RSA_padding_add_PKCS1_OAEP"}, 83{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP), "RSA_padding_add_PKCS1_OAEP"},
91{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS), "RSA_padding_add_PKCS1_PSS"}, 84{ERR_FUNC(RSA_F_RSA_PADDING_ADD_PKCS1_PSS), "RSA_padding_add_PKCS1_PSS"},
@@ -101,7 +94,6 @@ static ERR_STRING_DATA RSA_str_functs[]=
101{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"}, 94{ERR_FUNC(RSA_F_RSA_PADDING_CHECK_X931), "RSA_padding_check_X931"},
102{ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"}, 95{ERR_FUNC(RSA_F_RSA_PRINT), "RSA_print"},
103{ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"}, 96{ERR_FUNC(RSA_F_RSA_PRINT_FP), "RSA_print_fp"},
104{ERR_FUNC(RSA_F_RSA_SETUP_BLINDING), "RSA_setup_blinding"},
105{ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"}, 97{ERR_FUNC(RSA_F_RSA_SIGN), "RSA_sign"},
106{ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"}, 98{ERR_FUNC(RSA_F_RSA_SIGN_ASN1_OCTET_STRING), "RSA_sign_ASN1_OCTET_STRING"},
107{ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"}, 99{ERR_FUNC(RSA_F_RSA_VERIFY), "RSA_verify"},
@@ -138,21 +130,20 @@ static ERR_STRING_DATA RSA_str_reasons[]=
138{ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"}, 130{ERR_REASON(RSA_R_KEY_SIZE_TOO_SMALL) ,"key size too small"},
139{ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"}, 131{ERR_REASON(RSA_R_LAST_OCTET_INVALID) ,"last octet invalid"},
140{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"}, 132{ERR_REASON(RSA_R_MODULUS_TOO_LARGE) ,"modulus too large"},
141{ERR_REASON(RSA_R_NO_PUBLIC_EXPONENT) ,"no public exponent"},
142{ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"}, 133{ERR_REASON(RSA_R_NULL_BEFORE_BLOCK_MISSING),"null before block missing"},
143{ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"}, 134{ERR_REASON(RSA_R_N_DOES_NOT_EQUAL_P_Q) ,"n does not equal p q"},
144{ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"}, 135{ERR_REASON(RSA_R_OAEP_DECODING_ERROR) ,"oaep decoding error"},
136{ERR_REASON(RSA_R_SLEN_RECOVERY_FAILED) ,"salt length recovery failed"},
145{ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"}, 137{ERR_REASON(RSA_R_PADDING_CHECK_FAILED) ,"padding check failed"},
146{ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"}, 138{ERR_REASON(RSA_R_P_NOT_PRIME) ,"p not prime"},
147{ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"}, 139{ERR_REASON(RSA_R_Q_NOT_PRIME) ,"q not prime"},
148{ERR_REASON(RSA_R_RSA_OPERATIONS_NOT_SUPPORTED),"rsa operations not supported"}, 140{ERR_REASON(RSA_R_RSA_OPERATIONS_NOT_SUPPORTED),"rsa operations not supported"},
149{ERR_REASON(RSA_R_SLEN_CHECK_FAILED) ,"salt length check failed"},
150{ERR_REASON(RSA_R_SLEN_RECOVERY_FAILED) ,"salt length recovery failed"},
151{ERR_REASON(RSA_R_SSLV3_ROLLBACK_ATTACK) ,"sslv3 rollback attack"}, 141{ERR_REASON(RSA_R_SSLV3_ROLLBACK_ATTACK) ,"sslv3 rollback attack"},
152{ERR_REASON(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"}, 142{ERR_REASON(RSA_R_THE_ASN1_OBJECT_IDENTIFIER_IS_NOT_KNOWN_FOR_THIS_MD),"the asn1 object identifier is not known for this md"},
153{ERR_REASON(RSA_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"}, 143{ERR_REASON(RSA_R_UNKNOWN_ALGORITHM_TYPE),"unknown algorithm type"},
154{ERR_REASON(RSA_R_UNKNOWN_PADDING_TYPE) ,"unknown padding type"}, 144{ERR_REASON(RSA_R_UNKNOWN_PADDING_TYPE) ,"unknown padding type"},
155{ERR_REASON(RSA_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"}, 145{ERR_REASON(RSA_R_WRONG_SIGNATURE_LENGTH),"wrong signature length"},
146{ERR_REASON(RSA_R_SLEN_CHECK_FAILED) ,"salt length check failed"},
156{0,NULL} 147{0,NULL}
157 }; 148 };
158 149
@@ -160,12 +151,15 @@ static ERR_STRING_DATA RSA_str_reasons[]=
160 151
161void ERR_load_RSA_strings(void) 152void ERR_load_RSA_strings(void)
162 { 153 {
163#ifndef OPENSSL_NO_ERR 154 static int init=1;
164 155
165 if (ERR_func_error_string(RSA_str_functs[0].error) == NULL) 156 if (init)
166 { 157 {
158 init=0;
159#ifndef OPENSSL_NO_ERR
167 ERR_load_strings(0,RSA_str_functs); 160 ERR_load_strings(0,RSA_str_functs);
168 ERR_load_strings(0,RSA_str_reasons); 161 ERR_load_strings(0,RSA_str_reasons);
169 }
170#endif 162#endif
163
164 }
171 } 165 }
diff --git a/src/lib/libcrypto/rsa/rsa_gen.c b/src/lib/libcrypto/rsa/rsa_gen.c
index 767f7ab682..dd1422cc98 100644
--- a/src/lib/libcrypto/rsa/rsa_gen.c
+++ b/src/lib/libcrypto/rsa/rsa_gen.c
@@ -56,42 +56,26 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59
60/* NB: these functions have been "upgraded", the deprecated versions (which are
61 * compatibility wrappers using these functions) are in rsa_depr.c.
62 * - Geoff
63 */
64
65#include <stdio.h> 59#include <stdio.h>
66#include <time.h> 60#include <time.h>
67#include "cryptlib.h" 61#include "cryptlib.h"
68#include <openssl/bn.h> 62#include <openssl/bn.h>
69#include <openssl/rsa.h> 63#include <openssl/rsa.h>
70 64
71static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb); 65#ifndef OPENSSL_FIPS
72 66
73/* NB: this wrapper would normally be placed in rsa_lib.c and the static 67RSA *RSA_generate_key(int bits, unsigned long e_value,
74 * implementation would probably be in rsa_eay.c. Nonetheless, is kept here so 68 void (*callback)(int,int,void *), void *cb_arg)
75 * that we don't introduce a new linker dependency. Eg. any application that
76 * wasn't previously linking object code related to key-generation won't have to
77 * now just because key-generation is part of RSA_METHOD. */
78int RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
79 {
80 if(rsa->meth->rsa_keygen)
81 return rsa->meth->rsa_keygen(rsa, bits, e_value, cb);
82 return rsa_builtin_keygen(rsa, bits, e_value, cb);
83 }
84
85static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
86 { 69 {
70 RSA *rsa=NULL;
87 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp; 71 BIGNUM *r0=NULL,*r1=NULL,*r2=NULL,*r3=NULL,*tmp;
88 BIGNUM local_r0,local_d,local_p; 72 int bitsp,bitsq,ok= -1,n=0,i;
89 BIGNUM *pr0,*d,*p; 73 BN_CTX *ctx=NULL,*ctx2=NULL;
90 int bitsp,bitsq,ok= -1,n=0;
91 BN_CTX *ctx=NULL;
92 74
93 ctx=BN_CTX_new(); 75 ctx=BN_CTX_new();
94 if (ctx == NULL) goto err; 76 if (ctx == NULL) goto err;
77 ctx2=BN_CTX_new();
78 if (ctx2 == NULL) goto err;
95 BN_CTX_start(ctx); 79 BN_CTX_start(ctx);
96 r0 = BN_CTX_get(ctx); 80 r0 = BN_CTX_get(ctx);
97 r1 = BN_CTX_get(ctx); 81 r1 = BN_CTX_get(ctx);
@@ -101,58 +85,49 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
101 85
102 bitsp=(bits+1)/2; 86 bitsp=(bits+1)/2;
103 bitsq=bits-bitsp; 87 bitsq=bits-bitsp;
88 rsa=RSA_new();
89 if (rsa == NULL) goto err;
104 90
105 /* We need the RSA components non-NULL */ 91 /* set e */
106 if(!rsa->n && ((rsa->n=BN_new()) == NULL)) goto err; 92 rsa->e=BN_new();
107 if(!rsa->d && ((rsa->d=BN_new()) == NULL)) goto err; 93 if (rsa->e == NULL) goto err;
108 if(!rsa->e && ((rsa->e=BN_new()) == NULL)) goto err;
109 if(!rsa->p && ((rsa->p=BN_new()) == NULL)) goto err;
110 if(!rsa->q && ((rsa->q=BN_new()) == NULL)) goto err;
111 if(!rsa->dmp1 && ((rsa->dmp1=BN_new()) == NULL)) goto err;
112 if(!rsa->dmq1 && ((rsa->dmq1=BN_new()) == NULL)) goto err;
113 if(!rsa->iqmp && ((rsa->iqmp=BN_new()) == NULL)) goto err;
114 94
115 BN_copy(rsa->e, e_value); 95#if 1
96 /* The problem is when building with 8, 16, or 32 BN_ULONG,
97 * unsigned long can be larger */
98 for (i=0; i<sizeof(unsigned long)*8; i++)
99 {
100 if (e_value & (1UL<<i))
101 BN_set_bit(rsa->e,i);
102 }
103#else
104 if (!BN_set_word(rsa->e,e_value)) goto err;
105#endif
116 106
117 /* generate p and q */ 107 /* generate p and q */
118 for (;;) 108 for (;;)
119 { 109 {
120 if(!BN_generate_prime_ex(rsa->p, bitsp, 0, NULL, NULL, cb)) 110 rsa->p=BN_generate_prime(NULL,bitsp,0,NULL,NULL,callback,cb_arg);
121 goto err; 111 if (rsa->p == NULL) goto err;
122 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err; 112 if (!BN_sub(r2,rsa->p,BN_value_one())) goto err;
123 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; 113 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
124 if (BN_is_one(r1)) break; 114 if (BN_is_one(r1)) break;
125 if(!BN_GENCB_call(cb, 2, n++)) 115 if (callback != NULL) callback(2,n++,cb_arg);
126 goto err; 116 BN_free(rsa->p);
127 } 117 }
128 if(!BN_GENCB_call(cb, 3, 0)) 118 if (callback != NULL) callback(3,0,cb_arg);
129 goto err;
130 for (;;) 119 for (;;)
131 { 120 {
132 /* When generating ridiculously small keys, we can get stuck 121 rsa->q=BN_generate_prime(NULL,bitsq,0,NULL,NULL,callback,cb_arg);
133 * continually regenerating the same prime values. Check for 122 if (rsa->q == NULL) goto err;
134 * this and bail if it happens 3 times. */
135 unsigned int degenerate = 0;
136 do
137 {
138 if(!BN_generate_prime_ex(rsa->q, bitsq, 0, NULL, NULL, cb))
139 goto err;
140 } while((BN_cmp(rsa->p, rsa->q) == 0) && (++degenerate < 3));
141 if(degenerate == 3)
142 {
143 ok = 0; /* we set our own err */
144 RSAerr(RSA_F_RSA_BUILTIN_KEYGEN,RSA_R_KEY_SIZE_TOO_SMALL);
145 goto err;
146 }
147 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; 123 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err;
148 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err; 124 if (!BN_gcd(r1,r2,rsa->e,ctx)) goto err;
149 if (BN_is_one(r1)) 125 if (BN_is_one(r1) && (BN_cmp(rsa->p,rsa->q) != 0))
150 break; 126 break;
151 if(!BN_GENCB_call(cb, 2, n++)) 127 if (callback != NULL) callback(2,n++,cb_arg);
152 goto err; 128 BN_free(rsa->q);
153 } 129 }
154 if(!BN_GENCB_call(cb, 3, 1)) 130 if (callback != NULL) callback(3,1,cb_arg);
155 goto err;
156 if (BN_cmp(rsa->p,rsa->q) < 0) 131 if (BN_cmp(rsa->p,rsa->q) < 0)
157 { 132 {
158 tmp=rsa->p; 133 tmp=rsa->p;
@@ -161,59 +136,66 @@ static int rsa_builtin_keygen(RSA *rsa, int bits, BIGNUM *e_value, BN_GENCB *cb)
161 } 136 }
162 137
163 /* calculate n */ 138 /* calculate n */
139 rsa->n=BN_new();
140 if (rsa->n == NULL) goto err;
164 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err; 141 if (!BN_mul(rsa->n,rsa->p,rsa->q,ctx)) goto err;
165 142
166 /* calculate d */ 143 /* calculate d */
167 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */ 144 if (!BN_sub(r1,rsa->p,BN_value_one())) goto err; /* p-1 */
168 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */ 145 if (!BN_sub(r2,rsa->q,BN_value_one())) goto err; /* q-1 */
169 if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */ 146 if (!BN_mul(r0,r1,r2,ctx)) goto err; /* (p-1)(q-1) */
170 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
171 {
172 pr0 = &local_r0;
173 BN_with_flags(pr0, r0, BN_FLG_CONSTTIME);
174 }
175 else
176 pr0 = r0;
177 if (!BN_mod_inverse(rsa->d,rsa->e,pr0,ctx)) goto err; /* d */
178 147
179 /* set up d for correct BN_FLG_CONSTTIME flag */ 148/* should not be needed, since gcd(p-1,e) == 1 and gcd(q-1,e) == 1 */
180 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 149/* for (;;)
181 { 150 {
182 d = &local_d; 151 if (!BN_gcd(r3,r0,rsa->e,ctx)) goto err;
183 BN_with_flags(d, rsa->d, BN_FLG_CONSTTIME); 152 if (BN_is_one(r3)) break;
153
154 if (1)
155 {
156 if (!BN_add_word(rsa->e,2L)) goto err;
157 continue;
158 }
159 RSAerr(RSA_F_RSA_GENERATE_KEY,RSA_R_BAD_E_VALUE);
160 goto err;
184 } 161 }
185 else 162*/
186 d = rsa->d; 163 rsa->d=BN_mod_inverse(NULL,rsa->e,r0,ctx2); /* d */
164 if (rsa->d == NULL) goto err;
187 165
188 /* calculate d mod (p-1) */ 166 /* calculate d mod (p-1) */
189 if (!BN_mod(rsa->dmp1,d,r1,ctx)) goto err; 167 rsa->dmp1=BN_new();
168 if (rsa->dmp1 == NULL) goto err;
169 if (!BN_mod(rsa->dmp1,rsa->d,r1,ctx)) goto err;
190 170
191 /* calculate d mod (q-1) */ 171 /* calculate d mod (q-1) */
192 if (!BN_mod(rsa->dmq1,d,r2,ctx)) goto err; 172 rsa->dmq1=BN_new();
173 if (rsa->dmq1 == NULL) goto err;
174 if (!BN_mod(rsa->dmq1,rsa->d,r2,ctx)) goto err;
193 175
194 /* calculate inverse of q mod p */ 176 /* calculate inverse of q mod p */
195 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME)) 177 rsa->iqmp=BN_mod_inverse(NULL,rsa->q,rsa->p,ctx2);
196 { 178 if (rsa->iqmp == NULL) goto err;
197 p = &local_p;
198 BN_with_flags(p, rsa->p, BN_FLG_CONSTTIME);
199 }
200 else
201 p = rsa->p;
202 if (!BN_mod_inverse(rsa->iqmp,rsa->q,p,ctx)) goto err;
203 179
204 ok=1; 180 ok=1;
205err: 181err:
206 if (ok == -1) 182 if (ok == -1)
207 { 183 {
208 RSAerr(RSA_F_RSA_BUILTIN_KEYGEN,ERR_LIB_BN); 184 RSAerr(RSA_F_RSA_GENERATE_KEY,ERR_LIB_BN);
209 ok=0; 185 ok=0;
210 } 186 }
211 if (ctx != NULL) 187 if (ctx != NULL)
212 {
213 BN_CTX_end(ctx); 188 BN_CTX_end(ctx);
214 BN_CTX_free(ctx); 189 BN_CTX_free(ctx);
190 BN_CTX_free(ctx2);
191
192 if (!ok)
193 {
194 if (rsa != NULL) RSA_free(rsa);
195 return(NULL);
215 } 196 }
216 197 else
217 return ok; 198 return(rsa);
218 } 199 }
219 200
201#endif
diff --git a/src/lib/libcrypto/rsa/rsa_lib.c b/src/lib/libcrypto/rsa/rsa_lib.c
index 104aa4c1f2..e4d622851e 100644
--- a/src/lib/libcrypto/rsa/rsa_lib.c
+++ b/src/lib/libcrypto/rsa/rsa_lib.c
@@ -67,7 +67,7 @@
67#include <openssl/engine.h> 67#include <openssl/engine.h>
68#endif 68#endif
69 69
70const char RSA_version[]="RSA" OPENSSL_VERSION_PTEXT; 70const char *RSA_version="RSA" OPENSSL_VERSION_PTEXT;
71 71
72static const RSA_METHOD *default_RSA_meth=NULL; 72static const RSA_METHOD *default_RSA_meth=NULL;
73 73
@@ -179,7 +179,6 @@ RSA *RSA_new_method(ENGINE *engine)
179 ret->_method_mod_p=NULL; 179 ret->_method_mod_p=NULL;
180 ret->_method_mod_q=NULL; 180 ret->_method_mod_q=NULL;
181 ret->blinding=NULL; 181 ret->blinding=NULL;
182 ret->mt_blinding=NULL;
183 ret->bignum_data=NULL; 182 ret->bignum_data=NULL;
184 ret->flags=ret->meth->flags; 183 ret->flags=ret->meth->flags;
185 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data); 184 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_RSA, ret, &ret->ex_data);
@@ -233,7 +232,6 @@ void RSA_free(RSA *r)
233 if (r->dmq1 != NULL) BN_clear_free(r->dmq1); 232 if (r->dmq1 != NULL) BN_clear_free(r->dmq1);
234 if (r->iqmp != NULL) BN_clear_free(r->iqmp); 233 if (r->iqmp != NULL) BN_clear_free(r->iqmp);
235 if (r->blinding != NULL) BN_BLINDING_free(r->blinding); 234 if (r->blinding != NULL) BN_BLINDING_free(r->blinding);
236 if (r->mt_blinding != NULL) BN_BLINDING_free(r->mt_blinding);
237 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data); 235 if (r->bignum_data != NULL) OPENSSL_free_locked(r->bignum_data);
238 OPENSSL_free(r); 236 OPENSSL_free(r);
239 } 237 }
@@ -316,117 +314,59 @@ void RSA_blinding_off(RSA *rsa)
316 rsa->flags |= RSA_FLAG_NO_BLINDING; 314 rsa->flags |= RSA_FLAG_NO_BLINDING;
317 } 315 }
318 316
319int RSA_blinding_on(RSA *rsa, BN_CTX *ctx) 317int RSA_blinding_on(RSA *rsa, BN_CTX *p_ctx)
320 { 318 {
321 int ret=0; 319 BIGNUM *A,*Ai = NULL;
322
323 if (rsa->blinding != NULL)
324 RSA_blinding_off(rsa);
325
326 rsa->blinding = RSA_setup_blinding(rsa, ctx);
327 if (rsa->blinding == NULL)
328 goto err;
329
330 rsa->flags |= RSA_FLAG_BLINDING;
331 rsa->flags &= ~RSA_FLAG_NO_BLINDING;
332 ret=1;
333err:
334 return(ret);
335 }
336
337static BIGNUM *rsa_get_public_exp(const BIGNUM *d, const BIGNUM *p,
338 const BIGNUM *q, BN_CTX *ctx)
339{
340 BIGNUM *ret = NULL, *r0, *r1, *r2;
341
342 if (d == NULL || p == NULL || q == NULL)
343 return NULL;
344
345 BN_CTX_start(ctx);
346 r0 = BN_CTX_get(ctx);
347 r1 = BN_CTX_get(ctx);
348 r2 = BN_CTX_get(ctx);
349 if (r2 == NULL)
350 goto err;
351
352 if (!BN_sub(r1, p, BN_value_one())) goto err;
353 if (!BN_sub(r2, q, BN_value_one())) goto err;
354 if (!BN_mul(r0, r1, r2, ctx)) goto err;
355
356 ret = BN_mod_inverse(NULL, d, r0, ctx);
357err:
358 BN_CTX_end(ctx);
359 return ret;
360}
361
362BN_BLINDING *RSA_setup_blinding(RSA *rsa, BN_CTX *in_ctx)
363{
364 BIGNUM local_n;
365 BIGNUM *e,*n;
366 BN_CTX *ctx; 320 BN_CTX *ctx;
367 BN_BLINDING *ret = NULL; 321 int ret=0;
368 322
369 if (in_ctx == NULL) 323 if (p_ctx == NULL)
370 { 324 {
371 if ((ctx = BN_CTX_new()) == NULL) return 0; 325 if ((ctx=BN_CTX_new()) == NULL) goto err;
372 } 326 }
373 else 327 else
374 ctx = in_ctx; 328 ctx=p_ctx;
375 329
376 BN_CTX_start(ctx); 330 /* XXXXX: Shouldn't this be RSA_blinding_off(rsa)? */
377 e = BN_CTX_get(ctx); 331 if (rsa->blinding != NULL)
378 if (e == NULL)
379 { 332 {
380 RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_MALLOC_FAILURE); 333 BN_BLINDING_free(rsa->blinding);
381 goto err; 334 rsa->blinding = NULL;
382 } 335 }
383 336
384 if (rsa->e == NULL) 337 /* NB: similar code appears in setup_blinding (rsa_eay.c);
385 { 338 * this should be placed in a new function of its own, but for reasons
386 e = rsa_get_public_exp(rsa->d, rsa->p, rsa->q, ctx); 339 * of binary compatibility can't */
387 if (e == NULL)
388 {
389 RSAerr(RSA_F_RSA_SETUP_BLINDING, RSA_R_NO_PUBLIC_EXPONENT);
390 goto err;
391 }
392 }
393 else
394 e = rsa->e;
395 340
396 341 BN_CTX_start(ctx);
342 A = BN_CTX_get(ctx);
397 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL) 343 if ((RAND_status() == 0) && rsa->d != NULL && rsa->d->d != NULL)
398 { 344 {
399 /* if PRNG is not properly seeded, resort to secret 345 /* if PRNG is not properly seeded, resort to secret exponent as unpredictable seed */
400 * exponent as unpredictable seed */ 346 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0);
401 RAND_add(rsa->d->d, rsa->d->dmax * sizeof rsa->d->d[0], 0.0); 347 if (!BN_pseudo_rand_range(A,rsa->n)) goto err;
402 } 348 }
403 349 else
404 if (!(rsa->flags & RSA_FLAG_NO_CONSTTIME))
405 { 350 {
406 /* Set BN_FLG_CONSTTIME flag */ 351 if (!BN_rand_range(A,rsa->n)) goto err;
407 n = &local_n;
408 BN_with_flags(n, rsa->n, BN_FLG_CONSTTIME);
409 } 352 }
410 else 353 if ((Ai=BN_mod_inverse(NULL,A,rsa->n,ctx)) == NULL) goto err;
411 n = rsa->n;
412 354
413 ret = BN_BLINDING_create_param(NULL, e, n, ctx, 355 if (!rsa->meth->bn_mod_exp(A,A,rsa->e,rsa->n,ctx,rsa->_method_mod_n))
414 rsa->meth->bn_mod_exp, rsa->_method_mod_n);
415 if (ret == NULL)
416 {
417 RSAerr(RSA_F_RSA_SETUP_BLINDING, ERR_R_BN_LIB);
418 goto err; 356 goto err;
419 } 357 if ((rsa->blinding=BN_BLINDING_new(A,Ai,rsa->n)) == NULL) goto err;
420 BN_BLINDING_set_thread_id(ret, CRYPTO_thread_id()); 358 /* to make things thread-safe without excessive locking,
359 * rsa->blinding will be used just by the current thread: */
360 rsa->blinding->thread_id = CRYPTO_thread_id();
361 rsa->flags |= RSA_FLAG_BLINDING;
362 rsa->flags &= ~RSA_FLAG_NO_BLINDING;
363 ret=1;
421err: 364err:
365 if (Ai != NULL) BN_free(Ai);
422 BN_CTX_end(ctx); 366 BN_CTX_end(ctx);
423 if (in_ctx == NULL) 367 if (ctx != p_ctx) BN_CTX_free(ctx);
424 BN_CTX_free(ctx); 368 return(ret);
425 if(rsa->e == NULL) 369 }
426 BN_free(e);
427
428 return ret;
429}
430 370
431int RSA_memory_lock(RSA *r) 371int RSA_memory_lock(RSA *r)
432 { 372 {
@@ -449,7 +389,7 @@ int RSA_memory_lock(RSA *r)
449 j+= (*t[i])->top; 389 j+= (*t[i])->top;
450 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL) 390 if ((p=OPENSSL_malloc_locked((off+j)*sizeof(BN_ULONG))) == NULL)
451 { 391 {
452 RSAerr(RSA_F_RSA_MEMORY_LOCK,ERR_R_MALLOC_FAILURE); 392 RSAerr(RSA_F_MEMORY_LOCK,ERR_R_MALLOC_FAILURE);
453 return(0); 393 return(0);
454 } 394 }
455 bn=(BIGNUM *)p; 395 bn=(BIGNUM *)p;
diff --git a/src/lib/libcrypto/rsa/rsa_null.c b/src/lib/libcrypto/rsa/rsa_null.c
new file mode 100644
index 0000000000..64057fbdcf
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_null.c
@@ -0,0 +1,150 @@
1/* rsa_null.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <stdio.h>
60#include "cryptlib.h"
61#include <openssl/bn.h>
62#include <openssl/rsa.h>
63#include <openssl/rand.h>
64
65/* This is a dummy RSA implementation that just returns errors when called.
66 * It is designed to allow some RSA functions to work while stopping those
67 * covered by the RSA patent. That is RSA, encryption, decryption, signing
68 * and verify is not allowed but RSA key generation, key checking and other
69 * operations (like storing RSA keys) are permitted.
70 */
71
72static int RSA_null_public_encrypt(int flen, const unsigned char *from,
73 unsigned char *to, RSA *rsa,int padding);
74static int RSA_null_private_encrypt(int flen, const unsigned char *from,
75 unsigned char *to, RSA *rsa,int padding);
76static int RSA_null_public_decrypt(int flen, const unsigned char *from,
77 unsigned char *to, RSA *rsa,int padding);
78static int RSA_null_private_decrypt(int flen, const unsigned char *from,
79 unsigned char *to, RSA *rsa,int padding);
80#if 0 /* not currently used */
81static int RSA_null_mod_exp(const BIGNUM *r0, const BIGNUM *i, RSA *rsa);
82#endif
83static int RSA_null_init(RSA *rsa);
84static int RSA_null_finish(RSA *rsa);
85static RSA_METHOD rsa_null_meth={
86 "Null RSA",
87 RSA_null_public_encrypt,
88 RSA_null_public_decrypt,
89 RSA_null_private_encrypt,
90 RSA_null_private_decrypt,
91 NULL,
92 NULL,
93 RSA_null_init,
94 RSA_null_finish,
95 0,
96 NULL,
97 };
98
99const RSA_METHOD *RSA_null_method(void)
100 {
101 return(&rsa_null_meth);
102 }
103
104static int RSA_null_public_encrypt(int flen, const unsigned char *from,
105 unsigned char *to, RSA *rsa, int padding)
106 {
107 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
108 return -1;
109 }
110
111static int RSA_null_private_encrypt(int flen, const unsigned char *from,
112 unsigned char *to, RSA *rsa, int padding)
113 {
114 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
115 return -1;
116 }
117
118static int RSA_null_private_decrypt(int flen, const unsigned char *from,
119 unsigned char *to, RSA *rsa, int padding)
120 {
121 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
122 return -1;
123 }
124
125static int RSA_null_public_decrypt(int flen, const unsigned char *from,
126 unsigned char *to, RSA *rsa, int padding)
127 {
128 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
129 return -1;
130 }
131
132#if 0 /* not currently used */
133static int RSA_null_mod_exp(BIGNUM *r0, BIGNUM *I, RSA *rsa)
134 {
135 RSAerr(RSA_F_RSA_NULL, RSA_R_RSA_OPERATIONS_NOT_SUPPORTED);
136 return -1;
137 }
138#endif
139
140static int RSA_null_init(RSA *rsa)
141 {
142 return(1);
143 }
144
145static int RSA_null_finish(RSA *rsa)
146 {
147 return(1);
148 }
149
150
diff --git a/src/lib/libcrypto/rsa/rsa_oaep.c b/src/lib/libcrypto/rsa/rsa_oaep.c
index 3652677a99..d43ecaca63 100644
--- a/src/lib/libcrypto/rsa/rsa_oaep.c
+++ b/src/lib/libcrypto/rsa/rsa_oaep.c
@@ -28,9 +28,6 @@
28#include <openssl/rand.h> 28#include <openssl/rand.h>
29#include <openssl/sha.h> 29#include <openssl/sha.h>
30 30
31int MGF1(unsigned char *mask, long len,
32 const unsigned char *seed, long seedlen);
33
34int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen, 31int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
35 const unsigned char *from, int flen, 32 const unsigned char *from, int flen,
36 const unsigned char *param, int plen) 33 const unsigned char *param, int plen)
@@ -76,11 +73,13 @@ int RSA_padding_add_PKCS1_OAEP(unsigned char *to, int tlen,
76 20); 73 20);
77#endif 74#endif
78 75
79 MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH); 76 PKCS1_MGF1(dbmask, emlen - SHA_DIGEST_LENGTH, seed, SHA_DIGEST_LENGTH,
77 EVP_sha1());
80 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++) 78 for (i = 0; i < emlen - SHA_DIGEST_LENGTH; i++)
81 db[i] ^= dbmask[i]; 79 db[i] ^= dbmask[i];
82 80
83 MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH); 81 PKCS1_MGF1(seedmask, SHA_DIGEST_LENGTH, db, emlen - SHA_DIGEST_LENGTH,
82 EVP_sha1());
84 for (i = 0; i < SHA_DIGEST_LENGTH; i++) 83 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
85 seed[i] ^= seedmask[i]; 84 seed[i] ^= seedmask[i];
86 85
@@ -96,7 +95,6 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
96 const unsigned char *maskeddb; 95 const unsigned char *maskeddb;
97 int lzero; 96 int lzero;
98 unsigned char *db = NULL, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH]; 97 unsigned char *db = NULL, seed[SHA_DIGEST_LENGTH], phash[SHA_DIGEST_LENGTH];
99 unsigned char *padded_from;
100 int bad = 0; 98 int bad = 0;
101 99
102 if (--num < 2 * SHA_DIGEST_LENGTH + 1) 100 if (--num < 2 * SHA_DIGEST_LENGTH + 1)
@@ -107,6 +105,8 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
107 lzero = num - flen; 105 lzero = num - flen;
108 if (lzero < 0) 106 if (lzero < 0)
109 { 107 {
108 /* lzero == -1 */
109
110 /* signalling this error immediately after detection might allow 110 /* signalling this error immediately after detection might allow
111 * for side-channel attacks (e.g. timing if 'plen' is huge 111 * for side-channel attacks (e.g. timing if 'plen' is huge
112 * -- cf. James H. Manger, "A Chosen Ciphertext Attack on RSA Optimal 112 * -- cf. James H. Manger, "A Chosen Ciphertext Attack on RSA Optimal
@@ -114,30 +114,22 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
114 * so we use a 'bad' flag */ 114 * so we use a 'bad' flag */
115 bad = 1; 115 bad = 1;
116 lzero = 0; 116 lzero = 0;
117 flen = num; /* don't overflow the memcpy to padded_from */
118 } 117 }
118 maskeddb = from - lzero + SHA_DIGEST_LENGTH;
119 119
120 dblen = num - SHA_DIGEST_LENGTH; 120 dblen = num - SHA_DIGEST_LENGTH;
121 db = OPENSSL_malloc(dblen + num); 121 db = OPENSSL_malloc(dblen);
122 if (db == NULL) 122 if (db == NULL)
123 { 123 {
124 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, ERR_R_MALLOC_FAILURE); 124 RSAerr(RSA_F_RSA_PADDING_ADD_PKCS1_OAEP, ERR_R_MALLOC_FAILURE);
125 return -1; 125 return -1;
126 } 126 }
127 127
128 /* Always do this zero-padding copy (even when lzero == 0) 128 PKCS1_MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen, EVP_sha1());
129 * to avoid leaking timing info about the value of lzero. */ 129 for (i = lzero; i < SHA_DIGEST_LENGTH; i++)
130 padded_from = db + dblen; 130 seed[i] ^= from[i - lzero];
131 memset(padded_from, 0, lzero);
132 memcpy(padded_from + lzero, from, flen);
133
134 maskeddb = padded_from + SHA_DIGEST_LENGTH;
135
136 MGF1(seed, SHA_DIGEST_LENGTH, maskeddb, dblen);
137 for (i = 0; i < SHA_DIGEST_LENGTH; i++)
138 seed[i] ^= padded_from[i];
139 131
140 MGF1(db, dblen, seed, SHA_DIGEST_LENGTH); 132 PKCS1_MGF1(db, dblen, seed, SHA_DIGEST_LENGTH, EVP_sha1());
141 for (i = 0; i < dblen; i++) 133 for (i = 0; i < dblen; i++)
142 db[i] ^= maskeddb[i]; 134 db[i] ^= maskeddb[i];
143 135
@@ -150,13 +142,13 @@ int RSA_padding_check_PKCS1_OAEP(unsigned char *to, int tlen,
150 for (i = SHA_DIGEST_LENGTH; i < dblen; i++) 142 for (i = SHA_DIGEST_LENGTH; i < dblen; i++)
151 if (db[i] != 0x00) 143 if (db[i] != 0x00)
152 break; 144 break;
153 if (i == dblen || db[i] != 0x01) 145 if (db[i] != 0x01 || i++ >= dblen)
154 goto decoding_err; 146 goto decoding_err;
155 else 147 else
156 { 148 {
157 /* everything looks OK */ 149 /* everything looks OK */
158 150
159 mlen = dblen - ++i; 151 mlen = dblen - i;
160 if (tlen < mlen) 152 if (tlen < mlen)
161 { 153 {
162 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE); 154 RSAerr(RSA_F_RSA_PADDING_CHECK_PKCS1_OAEP, RSA_R_DATA_TOO_LARGE);
diff --git a/src/lib/libcrypto/rsa/rsa_saos.c b/src/lib/libcrypto/rsa/rsa_saos.c
index f98e0a80a6..24fc94835e 100644
--- a/src/lib/libcrypto/rsa/rsa_saos.c
+++ b/src/lib/libcrypto/rsa/rsa_saos.c
@@ -107,8 +107,7 @@ int RSA_verify_ASN1_OCTET_STRING(int dtype,
107 RSA *rsa) 107 RSA *rsa)
108 { 108 {
109 int i,ret=0; 109 int i,ret=0;
110 unsigned char *s; 110 unsigned char *p,*s;
111 const unsigned char *p;
112 ASN1_OCTET_STRING *sig=NULL; 111 ASN1_OCTET_STRING *sig=NULL;
113 112
114 if (siglen != (unsigned int)RSA_size(rsa)) 113 if (siglen != (unsigned int)RSA_size(rsa))
diff --git a/src/lib/libcrypto/rsa/rsa_sign.c b/src/lib/libcrypto/rsa/rsa_sign.c
index 71aabeea1b..db86f1ac58 100644
--- a/src/lib/libcrypto/rsa/rsa_sign.c
+++ b/src/lib/libcrypto/rsa/rsa_sign.c
@@ -146,7 +146,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
146 unsigned char *sigbuf, unsigned int siglen, RSA *rsa) 146 unsigned char *sigbuf, unsigned int siglen, RSA *rsa)
147 { 147 {
148 int i,ret=0,sigtype; 148 int i,ret=0,sigtype;
149 unsigned char *s; 149 unsigned char *p,*s;
150 X509_SIG *sig=NULL; 150 X509_SIG *sig=NULL;
151 151
152 if (siglen != (unsigned int)RSA_size(rsa)) 152 if (siglen != (unsigned int)RSA_size(rsa))
@@ -181,7 +181,7 @@ int RSA_verify(int dtype, const unsigned char *m, unsigned int m_len,
181 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE); 181 RSAerr(RSA_F_RSA_VERIFY,RSA_R_BAD_SIGNATURE);
182 else ret = 1; 182 else ret = 1;
183 } else { 183 } else {
184 const unsigned char *p=s; 184 p=s;
185 sig=d2i_X509_SIG(NULL,&p,(long)i); 185 sig=d2i_X509_SIG(NULL,&p,(long)i);
186 186
187 if (sig == NULL) goto err; 187 if (sig == NULL) goto err;
diff --git a/src/lib/libcrypto/rsa/rsa_test.c b/src/lib/libcrypto/rsa/rsa_test.c
new file mode 100644
index 0000000000..218bb2a39b
--- /dev/null
+++ b/src/lib/libcrypto/rsa/rsa_test.c
@@ -0,0 +1,318 @@
1/* test vectors from p1ovect1.txt */
2
3#include <stdio.h>
4#include <string.h>
5
6#include "e_os.h"
7
8#include <openssl/crypto.h>
9#include <openssl/err.h>
10#include <openssl/rand.h>
11#ifdef OPENSSL_NO_RSA
12int main(int argc, char *argv[])
13{
14 printf("No RSA support\n");
15 return(0);
16}
17#else
18#include <openssl/rsa.h>
19
20#define SetKey \
21 key->n = BN_bin2bn(n, sizeof(n)-1, key->n); \
22 key->e = BN_bin2bn(e, sizeof(e)-1, key->e); \
23 key->d = BN_bin2bn(d, sizeof(d)-1, key->d); \
24 key->p = BN_bin2bn(p, sizeof(p)-1, key->p); \
25 key->q = BN_bin2bn(q, sizeof(q)-1, key->q); \
26 key->dmp1 = BN_bin2bn(dmp1, sizeof(dmp1)-1, key->dmp1); \
27 key->dmq1 = BN_bin2bn(dmq1, sizeof(dmq1)-1, key->dmq1); \
28 key->iqmp = BN_bin2bn(iqmp, sizeof(iqmp)-1, key->iqmp); \
29 memcpy(c, ctext_ex, sizeof(ctext_ex) - 1); \
30 return (sizeof(ctext_ex) - 1);
31
32static int key1(RSA *key, unsigned char *c)
33 {
34 static unsigned char n[] =
35"\x00\xAA\x36\xAB\xCE\x88\xAC\xFD\xFF\x55\x52\x3C\x7F\xC4\x52\x3F"
36"\x90\xEF\xA0\x0D\xF3\x77\x4A\x25\x9F\x2E\x62\xB4\xC5\xD9\x9C\xB5"
37"\xAD\xB3\x00\xA0\x28\x5E\x53\x01\x93\x0E\x0C\x70\xFB\x68\x76\x93"
38"\x9C\xE6\x16\xCE\x62\x4A\x11\xE0\x08\x6D\x34\x1E\xBC\xAC\xA0\xA1"
39"\xF5";
40
41 static unsigned char e[] = "\x11";
42
43 static unsigned char d[] =
44"\x0A\x03\x37\x48\x62\x64\x87\x69\x5F\x5F\x30\xBC\x38\xB9\x8B\x44"
45"\xC2\xCD\x2D\xFF\x43\x40\x98\xCD\x20\xD8\xA1\x38\xD0\x90\xBF\x64"
46"\x79\x7C\x3F\xA7\xA2\xCD\xCB\x3C\xD1\xE0\xBD\xBA\x26\x54\xB4\xF9"
47"\xDF\x8E\x8A\xE5\x9D\x73\x3D\x9F\x33\xB3\x01\x62\x4A\xFD\x1D\x51";
48
49 static unsigned char p[] =
50"\x00\xD8\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
51"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x12"
52"\x0D";
53
54 static unsigned char q[] =
55"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
56"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
57"\x89";
58
59 static unsigned char dmp1[] =
60"\x59\x0B\x95\x72\xA2\xC2\xA9\xC4\x06\x05\x9D\xC2\xAB\x2F\x1D\xAF"
61"\xEB\x7E\x8B\x4F\x10\xA7\x54\x9E\x8E\xED\xF5\xB4\xFC\xE0\x9E\x05";
62
63 static unsigned char dmq1[] =
64"\x00\x8E\x3C\x05\x21\xFE\x15\xE0\xEA\x06\xA3\x6F\xF0\xF1\x0C\x99"
65"\x52\xC3\x5B\x7A\x75\x14\xFD\x32\x38\xB8\x0A\xAD\x52\x98\x62\x8D"
66"\x51";
67
68 static unsigned char iqmp[] =
69"\x36\x3F\xF7\x18\x9D\xA8\xE9\x0B\x1D\x34\x1F\x71\xD0\x9B\x76\xA8"
70"\xA9\x43\xE1\x1D\x10\xB2\x4D\x24\x9F\x2D\xEA\xFE\xF8\x0C\x18\x26";
71
72 static unsigned char ctext_ex[] =
73"\x1b\x8f\x05\xf9\xca\x1a\x79\x52\x6e\x53\xf3\xcc\x51\x4f\xdb\x89"
74"\x2b\xfb\x91\x93\x23\x1e\x78\xb9\x92\xe6\x8d\x50\xa4\x80\xcb\x52"
75"\x33\x89\x5c\x74\x95\x8d\x5d\x02\xab\x8c\x0f\xd0\x40\xeb\x58\x44"
76"\xb0\x05\xc3\x9e\xd8\x27\x4a\x9d\xbf\xa8\x06\x71\x40\x94\x39\xd2";
77
78 SetKey;
79 }
80
81static int key2(RSA *key, unsigned char *c)
82 {
83 static unsigned char n[] =
84"\x00\xA3\x07\x9A\x90\xDF\x0D\xFD\x72\xAC\x09\x0C\xCC\x2A\x78\xB8"
85"\x74\x13\x13\x3E\x40\x75\x9C\x98\xFA\xF8\x20\x4F\x35\x8A\x0B\x26"
86"\x3C\x67\x70\xE7\x83\xA9\x3B\x69\x71\xB7\x37\x79\xD2\x71\x7B\xE8"
87"\x34\x77\xCF";
88
89 static unsigned char e[] = "\x3";
90
91 static unsigned char d[] =
92"\x6C\xAF\xBC\x60\x94\xB3\xFE\x4C\x72\xB0\xB3\x32\xC6\xFB\x25\xA2"
93"\xB7\x62\x29\x80\x4E\x68\x65\xFC\xA4\x5A\x74\xDF\x0F\x8F\xB8\x41"
94"\x3B\x52\xC0\xD0\xE5\x3D\x9B\x59\x0F\xF1\x9B\xE7\x9F\x49\xDD\x21"
95"\xE5\xEB";
96
97 static unsigned char p[] =
98"\x00\xCF\x20\x35\x02\x8B\x9D\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92"
99"\xEA\x0D\xA3\xB4\x32\x04\xB5\xCF\xCE\x91";
100
101 static unsigned char q[] =
102"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
103"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5F";
104
105 static unsigned char dmp1[] =
106"\x00\x8A\x15\x78\xAC\x5D\x13\xAF\x10\x2B\x22\xB9\x99\xCD\x74\x61"
107"\xF1\x5E\x6D\x22\xCC\x03\x23\xDF\xDF\x0B";
108
109 static unsigned char dmq1[] =
110"\x00\x86\x55\x21\x4A\xC5\x4D\x8D\x4E\xCD\x61\x77\xF1\xC7\x36\x90"
111"\xCE\x2A\x48\x2C\x8B\x05\x99\xCB\xE0\x3F";
112
113 static unsigned char iqmp[] =
114"\x00\x83\xEF\xEF\xB8\xA9\xA4\x0D\x1D\xB6\xED\x98\xAD\x84\xED\x13"
115"\x35\xDC\xC1\x08\xF3\x22\xD0\x57\xCF\x8D";
116
117 static unsigned char ctext_ex[] =
118"\x14\xbd\xdd\x28\xc9\x83\x35\x19\x23\x80\xe8\xe5\x49\xb1\x58\x2a"
119"\x8b\x40\xb4\x48\x6d\x03\xa6\xa5\x31\x1f\x1f\xd5\xf0\xa1\x80\xe4"
120"\x17\x53\x03\x29\xa9\x34\x90\x74\xb1\x52\x13\x54\x29\x08\x24\x52"
121"\x62\x51";
122
123 SetKey;
124 }
125
126static int key3(RSA *key, unsigned char *c)
127 {
128 static unsigned char n[] =
129"\x00\xBB\xF8\x2F\x09\x06\x82\xCE\x9C\x23\x38\xAC\x2B\x9D\xA8\x71"
130"\xF7\x36\x8D\x07\xEE\xD4\x10\x43\xA4\x40\xD6\xB6\xF0\x74\x54\xF5"
131"\x1F\xB8\xDF\xBA\xAF\x03\x5C\x02\xAB\x61\xEA\x48\xCE\xEB\x6F\xCD"
132"\x48\x76\xED\x52\x0D\x60\xE1\xEC\x46\x19\x71\x9D\x8A\x5B\x8B\x80"
133"\x7F\xAF\xB8\xE0\xA3\xDF\xC7\x37\x72\x3E\xE6\xB4\xB7\xD9\x3A\x25"
134"\x84\xEE\x6A\x64\x9D\x06\x09\x53\x74\x88\x34\xB2\x45\x45\x98\x39"
135"\x4E\xE0\xAA\xB1\x2D\x7B\x61\xA5\x1F\x52\x7A\x9A\x41\xF6\xC1\x68"
136"\x7F\xE2\x53\x72\x98\xCA\x2A\x8F\x59\x46\xF8\xE5\xFD\x09\x1D\xBD"
137"\xCB";
138
139 static unsigned char e[] = "\x11";
140
141 static unsigned char d[] =
142"\x00\xA5\xDA\xFC\x53\x41\xFA\xF2\x89\xC4\xB9\x88\xDB\x30\xC1\xCD"
143"\xF8\x3F\x31\x25\x1E\x06\x68\xB4\x27\x84\x81\x38\x01\x57\x96\x41"
144"\xB2\x94\x10\xB3\xC7\x99\x8D\x6B\xC4\x65\x74\x5E\x5C\x39\x26\x69"
145"\xD6\x87\x0D\xA2\xC0\x82\xA9\x39\xE3\x7F\xDC\xB8\x2E\xC9\x3E\xDA"
146"\xC9\x7F\xF3\xAD\x59\x50\xAC\xCF\xBC\x11\x1C\x76\xF1\xA9\x52\x94"
147"\x44\xE5\x6A\xAF\x68\xC5\x6C\x09\x2C\xD3\x8D\xC3\xBE\xF5\xD2\x0A"
148"\x93\x99\x26\xED\x4F\x74\xA1\x3E\xDD\xFB\xE1\xA1\xCE\xCC\x48\x94"
149"\xAF\x94\x28\xC2\xB7\xB8\x88\x3F\xE4\x46\x3A\x4B\xC8\x5B\x1C\xB3"
150"\xC1";
151
152 static unsigned char p[] =
153"\x00\xEE\xCF\xAE\x81\xB1\xB9\xB3\xC9\x08\x81\x0B\x10\xA1\xB5\x60"
154"\x01\x99\xEB\x9F\x44\xAE\xF4\xFD\xA4\x93\xB8\x1A\x9E\x3D\x84\xF6"
155"\x32\x12\x4E\xF0\x23\x6E\x5D\x1E\x3B\x7E\x28\xFA\xE7\xAA\x04\x0A"
156"\x2D\x5B\x25\x21\x76\x45\x9D\x1F\x39\x75\x41\xBA\x2A\x58\xFB\x65"
157"\x99";
158
159 static unsigned char q[] =
160"\x00\xC9\x7F\xB1\xF0\x27\xF4\x53\xF6\x34\x12\x33\xEA\xAA\xD1\xD9"
161"\x35\x3F\x6C\x42\xD0\x88\x66\xB1\xD0\x5A\x0F\x20\x35\x02\x8B\x9D"
162"\x86\x98\x40\xB4\x16\x66\xB4\x2E\x92\xEA\x0D\xA3\xB4\x32\x04\xB5"
163"\xCF\xCE\x33\x52\x52\x4D\x04\x16\xA5\xA4\x41\xE7\x00\xAF\x46\x15"
164"\x03";
165
166 static unsigned char dmp1[] =
167"\x54\x49\x4C\xA6\x3E\xBA\x03\x37\xE4\xE2\x40\x23\xFC\xD6\x9A\x5A"
168"\xEB\x07\xDD\xDC\x01\x83\xA4\xD0\xAC\x9B\x54\xB0\x51\xF2\xB1\x3E"
169"\xD9\x49\x09\x75\xEA\xB7\x74\x14\xFF\x59\xC1\xF7\x69\x2E\x9A\x2E"
170"\x20\x2B\x38\xFC\x91\x0A\x47\x41\x74\xAD\xC9\x3C\x1F\x67\xC9\x81";
171
172 static unsigned char dmq1[] =
173"\x47\x1E\x02\x90\xFF\x0A\xF0\x75\x03\x51\xB7\xF8\x78\x86\x4C\xA9"
174"\x61\xAD\xBD\x3A\x8A\x7E\x99\x1C\x5C\x05\x56\xA9\x4C\x31\x46\xA7"
175"\xF9\x80\x3F\x8F\x6F\x8A\xE3\x42\xE9\x31\xFD\x8A\xE4\x7A\x22\x0D"
176"\x1B\x99\xA4\x95\x84\x98\x07\xFE\x39\xF9\x24\x5A\x98\x36\xDA\x3D";
177
178 static unsigned char iqmp[] =
179"\x00\xB0\x6C\x4F\xDA\xBB\x63\x01\x19\x8D\x26\x5B\xDB\xAE\x94\x23"
180"\xB3\x80\xF2\x71\xF7\x34\x53\x88\x50\x93\x07\x7F\xCD\x39\xE2\x11"
181"\x9F\xC9\x86\x32\x15\x4F\x58\x83\xB1\x67\xA9\x67\xBF\x40\x2B\x4E"
182"\x9E\x2E\x0F\x96\x56\xE6\x98\xEA\x36\x66\xED\xFB\x25\x79\x80\x39"
183"\xF7";
184
185 static unsigned char ctext_ex[] =
186"\xb8\x24\x6b\x56\xa6\xed\x58\x81\xae\xb5\x85\xd9\xa2\x5b\x2a\xd7"
187"\x90\xc4\x17\xe0\x80\x68\x1b\xf1\xac\x2b\xc3\xde\xb6\x9d\x8b\xce"
188"\xf0\xc4\x36\x6f\xec\x40\x0a\xf0\x52\xa7\x2e\x9b\x0e\xff\xb5\xb3"
189"\xf2\xf1\x92\xdb\xea\xca\x03\xc1\x27\x40\x05\x71\x13\xbf\x1f\x06"
190"\x69\xac\x22\xe9\xf3\xa7\x85\x2e\x3c\x15\xd9\x13\xca\xb0\xb8\x86"
191"\x3a\x95\xc9\x92\x94\xce\x86\x74\x21\x49\x54\x61\x03\x46\xf4\xd4"
192"\x74\xb2\x6f\x7c\x48\xb4\x2e\xe6\x8e\x1f\x57\x2a\x1f\xc4\x02\x6a"
193"\xc4\x56\xb4\xf5\x9f\x7b\x62\x1e\xa1\xb9\xd8\x8f\x64\x20\x2f\xb1";
194
195 SetKey;
196 }
197
198static int pad_unknown(void)
199{
200 unsigned long l;
201 while ((l = ERR_get_error()) != 0)
202 if (ERR_GET_REASON(l) == RSA_R_UNKNOWN_PADDING_TYPE)
203 return(1);
204 return(0);
205}
206
207static const char rnd_seed[] = "string to make the random number generator think it has entropy";
208
209int main(int argc, char *argv[])
210 {
211 int err=0;
212 int v;
213 RSA *key;
214 unsigned char ptext[256];
215 unsigned char ctext[256];
216 static unsigned char ptext_ex[] = "\x54\x85\x9b\x34\x2c\x49\xea\x2a";
217 unsigned char ctext_ex[256];
218 int plen;
219 int clen = 0;
220 int num;
221
222 CRYPTO_malloc_debug_init();
223 CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL);
224 CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);
225
226 RAND_seed(rnd_seed, sizeof rnd_seed); /* or OAEP may fail */
227
228 plen = sizeof(ptext_ex) - 1;
229
230 for (v = 0; v < 6; v++)
231 {
232 key = RSA_new();
233 switch (v%3) {
234 case 0:
235 clen = key1(key, ctext_ex);
236 break;
237 case 1:
238 clen = key2(key, ctext_ex);
239 break;
240 case 2:
241 clen = key3(key, ctext_ex);
242 break;
243 }
244 if (v/3 > 1) key->flags |= RSA_FLAG_NO_EXP_CONSTTIME;
245
246 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
247 RSA_PKCS1_PADDING);
248 if (num != clen)
249 {
250 printf("PKCS#1 v1.5 encryption failed!\n");
251 err=1;
252 goto oaep;
253 }
254
255 num = RSA_private_decrypt(num, ctext, ptext, key,
256 RSA_PKCS1_PADDING);
257 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
258 {
259 printf("PKCS#1 v1.5 decryption failed!\n");
260 err=1;
261 }
262 else
263 printf("PKCS #1 v1.5 encryption/decryption ok\n");
264
265 oaep:
266 ERR_clear_error();
267 num = RSA_public_encrypt(plen, ptext_ex, ctext, key,
268 RSA_PKCS1_OAEP_PADDING);
269 if (num == -1 && pad_unknown())
270 {
271 printf("No OAEP support\n");
272 goto next;
273 }
274 if (num != clen)
275 {
276 printf("OAEP encryption failed!\n");
277 err=1;
278 goto next;
279 }
280
281 num = RSA_private_decrypt(num, ctext, ptext, key,
282 RSA_PKCS1_OAEP_PADDING);
283 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
284 {
285 printf("OAEP decryption (encrypted data) failed!\n");
286 err=1;
287 }
288 else if (memcmp(ctext, ctext_ex, num) == 0)
289 {
290 printf("OAEP test vector %d passed!\n", v);
291 goto next;
292 }
293
294 /* Different ciphertexts (rsa_oaep.c without -DPKCS_TESTVECT).
295 Try decrypting ctext_ex */
296
297 num = RSA_private_decrypt(clen, ctext_ex, ptext, key,
298 RSA_PKCS1_OAEP_PADDING);
299
300 if (num != plen || memcmp(ptext, ptext_ex, num) != 0)
301 {
302 printf("OAEP decryption (test vector data) failed!\n");
303 err=1;
304 }
305 else
306 printf("OAEP encryption/decryption ok\n");
307 next:
308 RSA_free(key);
309 }
310
311 CRYPTO_cleanup_all_ex_data();
312 ERR_remove_state(0);
313
314 CRYPTO_mem_leaks_fp(stderr);
315
316 return err;
317 }
318#endif
diff --git a/src/lib/libcrypto/seed/Makefile b/src/lib/libcrypto/seed/Makefile
new file mode 100644
index 0000000000..f9de27b288
--- /dev/null
+++ b/src/lib/libcrypto/seed/Makefile
@@ -0,0 +1,87 @@
1#
2# crypto/seed/Makefile
3#
4
5DIR= seed
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14CFLAGS= $(INCLUDES) $(CFLAG)
15
16GENERAL=Makefile
17TEST=
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC=seed.c seed_ecb.c seed_cbc.c seed_cfb.c seed_ofb.c
22LIBOBJ=seed.o seed_ecb.o seed_cbc.o seed_cfb.o seed_ofb.o
23
24SRC= $(LIBSRC)
25
26EXHEADER= seed.h
27HEADER= seed_locl.h $(EXHEADER)
28
29ALL= $(GENERAL) $(SRC) $(HEADER)
30
31top:
32 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
33
34all: lib
35
36lib: $(LIBOBJ)
37 $(AR) $(LIB) $(LIBOBJ)
38 $(RANLIB) $(LIB) || echo Never mind.
39 @touch lib
40
41files:
42 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
43
44links:
45 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
46 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
47 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
48
49install:
50 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
51 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
52 do \
53 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
54 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
55 done;
56
57tags:
58 ctags $(SRC)
59
60tests:
61
62lint:
63 lint -DLINT $(INCLUDES) $(SRC)>fluff
64
65depend:
66 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
67 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
68
69dclean:
70 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
71 mv -f Makefile.new $(MAKEFILE)
72
73clean:
74 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
75
76# DO NOT DELETE THIS LINE -- make depend depends on it.
77
78seed.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
79seed.o: ../../include/openssl/seed.h seed.c seed_locl.h
80seed_cbc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
81seed_cbc.o: ../../include/openssl/seed.h seed_cbc.c seed_locl.h
82seed_cfb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
83seed_cfb.o: ../../include/openssl/seed.h seed_cfb.c seed_locl.h
84seed_ecb.o: ../../include/openssl/opensslconf.h ../../include/openssl/seed.h
85seed_ecb.o: seed_ecb.c
86seed_ofb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
87seed_ofb.o: ../../include/openssl/seed.h seed_locl.h seed_ofb.c
diff --git a/src/lib/libcrypto/seed/seed.c b/src/lib/libcrypto/seed/seed.c
new file mode 100644
index 0000000000..125dd7d66f
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed.c
@@ -0,0 +1,286 @@
1/*
2 * Copyright (c) 2007 KISA(Korea Information Security Agency). 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Neither the name of author nor the names of its contributors may
10 * be used to endorse or promote products derived from this software
11 * without specific prior written permission.
12 *
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 */
26#ifndef OPENSSL_NO_SEED
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#ifdef WIN32
32#include <memory.h>
33#endif
34
35#include <openssl/seed.h>
36#include "seed_locl.h"
37
38static seed_word SS[4][256] = { {
39 0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124,
40 0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360,
41 0x28082028, 0x04444044, 0x20002020, 0x1d8d919c, 0x20c0e0e0, 0x22c2e2e0, 0x08c8c0c8, 0x17071314,
42 0x2585a1a4, 0x0f8f838c, 0x03030300, 0x3b4b7378, 0x3b8bb3b8, 0x13031310, 0x12c2d2d0, 0x2ecee2ec,
43 0x30407070, 0x0c8c808c, 0x3f0f333c, 0x2888a0a8, 0x32023230, 0x1dcdd1dc, 0x36c6f2f4, 0x34447074,
44 0x2ccce0ec, 0x15859194, 0x0b0b0308, 0x17475354, 0x1c4c505c, 0x1b4b5358, 0x3d8db1bc, 0x01010100,
45 0x24042024, 0x1c0c101c, 0x33437370, 0x18889098, 0x10001010, 0x0cccc0cc, 0x32c2f2f0, 0x19c9d1d8,
46 0x2c0c202c, 0x27c7e3e4, 0x32427270, 0x03838380, 0x1b8b9398, 0x11c1d1d0, 0x06868284, 0x09c9c1c8,
47 0x20406060, 0x10405050, 0x2383a3a0, 0x2bcbe3e8, 0x0d0d010c, 0x3686b2b4, 0x1e8e929c, 0x0f4f434c,
48 0x3787b3b4, 0x1a4a5258, 0x06c6c2c4, 0x38487078, 0x2686a2a4, 0x12021210, 0x2f8fa3ac, 0x15c5d1d4,
49 0x21416160, 0x03c3c3c0, 0x3484b0b4, 0x01414140, 0x12425250, 0x3d4d717c, 0x0d8d818c, 0x08080008,
50 0x1f0f131c, 0x19899198, 0x00000000, 0x19091118, 0x04040004, 0x13435350, 0x37c7f3f4, 0x21c1e1e0,
51 0x3dcdf1fc, 0x36467274, 0x2f0f232c, 0x27072324, 0x3080b0b0, 0x0b8b8388, 0x0e0e020c, 0x2b8ba3a8,
52 0x2282a2a0, 0x2e4e626c, 0x13839390, 0x0d4d414c, 0x29496168, 0x3c4c707c, 0x09090108, 0x0a0a0208,
53 0x3f8fb3bc, 0x2fcfe3ec, 0x33c3f3f0, 0x05c5c1c4, 0x07878384, 0x14041014, 0x3ecef2fc, 0x24446064,
54 0x1eced2dc, 0x2e0e222c, 0x0b4b4348, 0x1a0a1218, 0x06060204, 0x21012120, 0x2b4b6368, 0x26466264,
55 0x02020200, 0x35c5f1f4, 0x12829290, 0x0a8a8288, 0x0c0c000c, 0x3383b3b0, 0x3e4e727c, 0x10c0d0d0,
56 0x3a4a7278, 0x07474344, 0x16869294, 0x25c5e1e4, 0x26062224, 0x00808080, 0x2d8da1ac, 0x1fcfd3dc,
57 0x2181a1a0, 0x30003030, 0x37073334, 0x2e8ea2ac, 0x36063234, 0x15051114, 0x22022220, 0x38083038,
58 0x34c4f0f4, 0x2787a3a4, 0x05454144, 0x0c4c404c, 0x01818180, 0x29c9e1e8, 0x04848084, 0x17879394,
59 0x35053134, 0x0bcbc3c8, 0x0ecec2cc, 0x3c0c303c, 0x31417170, 0x11011110, 0x07c7c3c4, 0x09898188,
60 0x35457174, 0x3bcbf3f8, 0x1acad2d8, 0x38c8f0f8, 0x14849094, 0x19495158, 0x02828280, 0x04c4c0c4,
61 0x3fcff3fc, 0x09494148, 0x39093138, 0x27476364, 0x00c0c0c0, 0x0fcfc3cc, 0x17c7d3d4, 0x3888b0b8,
62 0x0f0f030c, 0x0e8e828c, 0x02424240, 0x23032320, 0x11819190, 0x2c4c606c, 0x1bcbd3d8, 0x2484a0a4,
63 0x34043034, 0x31c1f1f0, 0x08484048, 0x02c2c2c0, 0x2f4f636c, 0x3d0d313c, 0x2d0d212c, 0x00404040,
64 0x3e8eb2bc, 0x3e0e323c, 0x3c8cb0bc, 0x01c1c1c0, 0x2a8aa2a8, 0x3a8ab2b8, 0x0e4e424c, 0x15455154,
65 0x3b0b3338, 0x1cccd0dc, 0x28486068, 0x3f4f737c, 0x1c8c909c, 0x18c8d0d8, 0x0a4a4248, 0x16465254,
66 0x37477374, 0x2080a0a0, 0x2dcde1ec, 0x06464244, 0x3585b1b4, 0x2b0b2328, 0x25456164, 0x3acaf2f8,
67 0x23c3e3e0, 0x3989b1b8, 0x3181b1b0, 0x1f8f939c, 0x1e4e525c, 0x39c9f1f8, 0x26c6e2e4, 0x3282b2b0,
68 0x31013130, 0x2acae2e8, 0x2d4d616c, 0x1f4f535c, 0x24c4e0e4, 0x30c0f0f0, 0x0dcdc1cc, 0x08888088,
69 0x16061214, 0x3a0a3238, 0x18485058, 0x14c4d0d4, 0x22426260, 0x29092128, 0x07070304, 0x33033330,
70 0x28c8e0e8, 0x1b0b1318, 0x05050104, 0x39497178, 0x10809090, 0x2a4a6268, 0x2a0a2228, 0x1a8a9298
71}, {
72 0x38380830, 0xe828c8e0, 0x2c2d0d21, 0xa42686a2, 0xcc0fcfc3, 0xdc1eced2, 0xb03383b3, 0xb83888b0,
73 0xac2f8fa3, 0x60204060, 0x54154551, 0xc407c7c3, 0x44044440, 0x6c2f4f63, 0x682b4b63, 0x581b4b53,
74 0xc003c3c3, 0x60224262, 0x30330333, 0xb43585b1, 0x28290921, 0xa02080a0, 0xe022c2e2, 0xa42787a3,
75 0xd013c3d3, 0x90118191, 0x10110111, 0x04060602, 0x1c1c0c10, 0xbc3c8cb0, 0x34360632, 0x480b4b43,
76 0xec2fcfe3, 0x88088880, 0x6c2c4c60, 0xa82888a0, 0x14170713, 0xc404c4c0, 0x14160612, 0xf434c4f0,
77 0xc002c2c2, 0x44054541, 0xe021c1e1, 0xd416c6d2, 0x3c3f0f33, 0x3c3d0d31, 0x8c0e8e82, 0x98188890,
78 0x28280820, 0x4c0e4e42, 0xf436c6f2, 0x3c3e0e32, 0xa42585a1, 0xf839c9f1, 0x0c0d0d01, 0xdc1fcfd3,
79 0xd818c8d0, 0x282b0b23, 0x64264662, 0x783a4a72, 0x24270723, 0x2c2f0f23, 0xf031c1f1, 0x70324272,
80 0x40024242, 0xd414c4d0, 0x40014141, 0xc000c0c0, 0x70334373, 0x64274763, 0xac2c8ca0, 0x880b8b83,
81 0xf437c7f3, 0xac2d8da1, 0x80008080, 0x1c1f0f13, 0xc80acac2, 0x2c2c0c20, 0xa82a8aa2, 0x34340430,
82 0xd012c2d2, 0x080b0b03, 0xec2ecee2, 0xe829c9e1, 0x5c1d4d51, 0x94148490, 0x18180810, 0xf838c8f0,
83 0x54174753, 0xac2e8ea2, 0x08080800, 0xc405c5c1, 0x10130313, 0xcc0dcdc1, 0x84068682, 0xb83989b1,
84 0xfc3fcff3, 0x7c3d4d71, 0xc001c1c1, 0x30310131, 0xf435c5f1, 0x880a8a82, 0x682a4a62, 0xb03181b1,
85 0xd011c1d1, 0x20200020, 0xd417c7d3, 0x00020202, 0x20220222, 0x04040400, 0x68284860, 0x70314171,
86 0x04070703, 0xd81bcbd3, 0x9c1d8d91, 0x98198991, 0x60214161, 0xbc3e8eb2, 0xe426c6e2, 0x58194951,
87 0xdc1dcdd1, 0x50114151, 0x90108090, 0xdc1cccd0, 0x981a8a92, 0xa02383a3, 0xa82b8ba3, 0xd010c0d0,
88 0x80018181, 0x0c0f0f03, 0x44074743, 0x181a0a12, 0xe023c3e3, 0xec2ccce0, 0x8c0d8d81, 0xbc3f8fb3,
89 0x94168692, 0x783b4b73, 0x5c1c4c50, 0xa02282a2, 0xa02181a1, 0x60234363, 0x20230323, 0x4c0d4d41,
90 0xc808c8c0, 0x9c1e8e92, 0x9c1c8c90, 0x383a0a32, 0x0c0c0c00, 0x2c2e0e22, 0xb83a8ab2, 0x6c2e4e62,
91 0x9c1f8f93, 0x581a4a52, 0xf032c2f2, 0x90128292, 0xf033c3f3, 0x48094941, 0x78384870, 0xcc0cccc0,
92 0x14150511, 0xf83bcbf3, 0x70304070, 0x74354571, 0x7c3f4f73, 0x34350531, 0x10100010, 0x00030303,
93 0x64244460, 0x6c2d4d61, 0xc406c6c2, 0x74344470, 0xd415c5d1, 0xb43484b0, 0xe82acae2, 0x08090901,
94 0x74364672, 0x18190911, 0xfc3ecef2, 0x40004040, 0x10120212, 0xe020c0e0, 0xbc3d8db1, 0x04050501,
95 0xf83acaf2, 0x00010101, 0xf030c0f0, 0x282a0a22, 0x5c1e4e52, 0xa82989a1, 0x54164652, 0x40034343,
96 0x84058581, 0x14140410, 0x88098981, 0x981b8b93, 0xb03080b0, 0xe425c5e1, 0x48084840, 0x78394971,
97 0x94178793, 0xfc3cccf0, 0x1c1e0e12, 0x80028282, 0x20210121, 0x8c0c8c80, 0x181b0b13, 0x5c1f4f53,
98 0x74374773, 0x54144450, 0xb03282b2, 0x1c1d0d11, 0x24250521, 0x4c0f4f43, 0x00000000, 0x44064642,
99 0xec2dcde1, 0x58184850, 0x50124252, 0xe82bcbe3, 0x7c3e4e72, 0xd81acad2, 0xc809c9c1, 0xfc3dcdf1,
100 0x30300030, 0x94158591, 0x64254561, 0x3c3c0c30, 0xb43686b2, 0xe424c4e0, 0xb83b8bb3, 0x7c3c4c70,
101 0x0c0e0e02, 0x50104050, 0x38390931, 0x24260622, 0x30320232, 0x84048480, 0x68294961, 0x90138393,
102 0x34370733, 0xe427c7e3, 0x24240420, 0xa42484a0, 0xc80bcbc3, 0x50134353, 0x080a0a02, 0x84078783,
103 0xd819c9d1, 0x4c0c4c40, 0x80038383, 0x8c0f8f83, 0xcc0ecec2, 0x383b0b33, 0x480a4a42, 0xb43787b3
104}, {
105 0xa1a82989, 0x81840585, 0xd2d416c6, 0xd3d013c3, 0x50541444, 0x111c1d0d, 0xa0ac2c8c, 0x21242505,
106 0x515c1d4d, 0x43400343, 0x10181808, 0x121c1e0e, 0x51501141, 0xf0fc3ccc, 0xc2c80aca, 0x63602343,
107 0x20282808, 0x40440444, 0x20202000, 0x919c1d8d, 0xe0e020c0, 0xe2e022c2, 0xc0c808c8, 0x13141707,
108 0xa1a42585, 0x838c0f8f, 0x03000303, 0x73783b4b, 0xb3b83b8b, 0x13101303, 0xd2d012c2, 0xe2ec2ece,
109 0x70703040, 0x808c0c8c, 0x333c3f0f, 0xa0a82888, 0x32303202, 0xd1dc1dcd, 0xf2f436c6, 0x70743444,
110 0xe0ec2ccc, 0x91941585, 0x03080b0b, 0x53541747, 0x505c1c4c, 0x53581b4b, 0xb1bc3d8d, 0x01000101,
111 0x20242404, 0x101c1c0c, 0x73703343, 0x90981888, 0x10101000, 0xc0cc0ccc, 0xf2f032c2, 0xd1d819c9,
112 0x202c2c0c, 0xe3e427c7, 0x72703242, 0x83800383, 0x93981b8b, 0xd1d011c1, 0x82840686, 0xc1c809c9,
113 0x60602040, 0x50501040, 0xa3a02383, 0xe3e82bcb, 0x010c0d0d, 0xb2b43686, 0x929c1e8e, 0x434c0f4f,
114 0xb3b43787, 0x52581a4a, 0xc2c406c6, 0x70783848, 0xa2a42686, 0x12101202, 0xa3ac2f8f, 0xd1d415c5,
115 0x61602141, 0xc3c003c3, 0xb0b43484, 0x41400141, 0x52501242, 0x717c3d4d, 0x818c0d8d, 0x00080808,
116 0x131c1f0f, 0x91981989, 0x00000000, 0x11181909, 0x00040404, 0x53501343, 0xf3f437c7, 0xe1e021c1,
117 0xf1fc3dcd, 0x72743646, 0x232c2f0f, 0x23242707, 0xb0b03080, 0x83880b8b, 0x020c0e0e, 0xa3a82b8b,
118 0xa2a02282, 0x626c2e4e, 0x93901383, 0x414c0d4d, 0x61682949, 0x707c3c4c, 0x01080909, 0x02080a0a,
119 0xb3bc3f8f, 0xe3ec2fcf, 0xf3f033c3, 0xc1c405c5, 0x83840787, 0x10141404, 0xf2fc3ece, 0x60642444,
120 0xd2dc1ece, 0x222c2e0e, 0x43480b4b, 0x12181a0a, 0x02040606, 0x21202101, 0x63682b4b, 0x62642646,
121 0x02000202, 0xf1f435c5, 0x92901282, 0x82880a8a, 0x000c0c0c, 0xb3b03383, 0x727c3e4e, 0xd0d010c0,
122 0x72783a4a, 0x43440747, 0x92941686, 0xe1e425c5, 0x22242606, 0x80800080, 0xa1ac2d8d, 0xd3dc1fcf,
123 0xa1a02181, 0x30303000, 0x33343707, 0xa2ac2e8e, 0x32343606, 0x11141505, 0x22202202, 0x30383808,
124 0xf0f434c4, 0xa3a42787, 0x41440545, 0x404c0c4c, 0x81800181, 0xe1e829c9, 0x80840484, 0x93941787,
125 0x31343505, 0xc3c80bcb, 0xc2cc0ece, 0x303c3c0c, 0x71703141, 0x11101101, 0xc3c407c7, 0x81880989,
126 0x71743545, 0xf3f83bcb, 0xd2d81aca, 0xf0f838c8, 0x90941484, 0x51581949, 0x82800282, 0xc0c404c4,
127 0xf3fc3fcf, 0x41480949, 0x31383909, 0x63642747, 0xc0c000c0, 0xc3cc0fcf, 0xd3d417c7, 0xb0b83888,
128 0x030c0f0f, 0x828c0e8e, 0x42400242, 0x23202303, 0x91901181, 0x606c2c4c, 0xd3d81bcb, 0xa0a42484,
129 0x30343404, 0xf1f031c1, 0x40480848, 0xc2c002c2, 0x636c2f4f, 0x313c3d0d, 0x212c2d0d, 0x40400040,
130 0xb2bc3e8e, 0x323c3e0e, 0xb0bc3c8c, 0xc1c001c1, 0xa2a82a8a, 0xb2b83a8a, 0x424c0e4e, 0x51541545,
131 0x33383b0b, 0xd0dc1ccc, 0x60682848, 0x737c3f4f, 0x909c1c8c, 0xd0d818c8, 0x42480a4a, 0x52541646,
132 0x73743747, 0xa0a02080, 0xe1ec2dcd, 0x42440646, 0xb1b43585, 0x23282b0b, 0x61642545, 0xf2f83aca,
133 0xe3e023c3, 0xb1b83989, 0xb1b03181, 0x939c1f8f, 0x525c1e4e, 0xf1f839c9, 0xe2e426c6, 0xb2b03282,
134 0x31303101, 0xe2e82aca, 0x616c2d4d, 0x535c1f4f, 0xe0e424c4, 0xf0f030c0, 0xc1cc0dcd, 0x80880888,
135 0x12141606, 0x32383a0a, 0x50581848, 0xd0d414c4, 0x62602242, 0x21282909, 0x03040707, 0x33303303,
136 0xe0e828c8, 0x13181b0b, 0x01040505, 0x71783949, 0x90901080, 0x62682a4a, 0x22282a0a, 0x92981a8a
137}, {
138 0x08303838, 0xc8e0e828, 0x0d212c2d, 0x86a2a426, 0xcfc3cc0f, 0xced2dc1e, 0x83b3b033, 0x88b0b838,
139 0x8fa3ac2f, 0x40606020, 0x45515415, 0xc7c3c407, 0x44404404, 0x4f636c2f, 0x4b63682b, 0x4b53581b,
140 0xc3c3c003, 0x42626022, 0x03333033, 0x85b1b435, 0x09212829, 0x80a0a020, 0xc2e2e022, 0x87a3a427,
141 0xc3d3d013, 0x81919011, 0x01111011, 0x06020406, 0x0c101c1c, 0x8cb0bc3c, 0x06323436, 0x4b43480b,
142 0xcfe3ec2f, 0x88808808, 0x4c606c2c, 0x88a0a828, 0x07131417, 0xc4c0c404, 0x06121416, 0xc4f0f434,
143 0xc2c2c002, 0x45414405, 0xc1e1e021, 0xc6d2d416, 0x0f333c3f, 0x0d313c3d, 0x8e828c0e, 0x88909818,
144 0x08202828, 0x4e424c0e, 0xc6f2f436, 0x0e323c3e, 0x85a1a425, 0xc9f1f839, 0x0d010c0d, 0xcfd3dc1f,
145 0xc8d0d818, 0x0b23282b, 0x46626426, 0x4a72783a, 0x07232427, 0x0f232c2f, 0xc1f1f031, 0x42727032,
146 0x42424002, 0xc4d0d414, 0x41414001, 0xc0c0c000, 0x43737033, 0x47636427, 0x8ca0ac2c, 0x8b83880b,
147 0xc7f3f437, 0x8da1ac2d, 0x80808000, 0x0f131c1f, 0xcac2c80a, 0x0c202c2c, 0x8aa2a82a, 0x04303434,
148 0xc2d2d012, 0x0b03080b, 0xcee2ec2e, 0xc9e1e829, 0x4d515c1d, 0x84909414, 0x08101818, 0xc8f0f838,
149 0x47535417, 0x8ea2ac2e, 0x08000808, 0xc5c1c405, 0x03131013, 0xcdc1cc0d, 0x86828406, 0x89b1b839,
150 0xcff3fc3f, 0x4d717c3d, 0xc1c1c001, 0x01313031, 0xc5f1f435, 0x8a82880a, 0x4a62682a, 0x81b1b031,
151 0xc1d1d011, 0x00202020, 0xc7d3d417, 0x02020002, 0x02222022, 0x04000404, 0x48606828, 0x41717031,
152 0x07030407, 0xcbd3d81b, 0x8d919c1d, 0x89919819, 0x41616021, 0x8eb2bc3e, 0xc6e2e426, 0x49515819,
153 0xcdd1dc1d, 0x41515011, 0x80909010, 0xccd0dc1c, 0x8a92981a, 0x83a3a023, 0x8ba3a82b, 0xc0d0d010,
154 0x81818001, 0x0f030c0f, 0x47434407, 0x0a12181a, 0xc3e3e023, 0xcce0ec2c, 0x8d818c0d, 0x8fb3bc3f,
155 0x86929416, 0x4b73783b, 0x4c505c1c, 0x82a2a022, 0x81a1a021, 0x43636023, 0x03232023, 0x4d414c0d,
156 0xc8c0c808, 0x8e929c1e, 0x8c909c1c, 0x0a32383a, 0x0c000c0c, 0x0e222c2e, 0x8ab2b83a, 0x4e626c2e,
157 0x8f939c1f, 0x4a52581a, 0xc2f2f032, 0x82929012, 0xc3f3f033, 0x49414809, 0x48707838, 0xccc0cc0c,
158 0x05111415, 0xcbf3f83b, 0x40707030, 0x45717435, 0x4f737c3f, 0x05313435, 0x00101010, 0x03030003,
159 0x44606424, 0x4d616c2d, 0xc6c2c406, 0x44707434, 0xc5d1d415, 0x84b0b434, 0xcae2e82a, 0x09010809,
160 0x46727436, 0x09111819, 0xcef2fc3e, 0x40404000, 0x02121012, 0xc0e0e020, 0x8db1bc3d, 0x05010405,
161 0xcaf2f83a, 0x01010001, 0xc0f0f030, 0x0a22282a, 0x4e525c1e, 0x89a1a829, 0x46525416, 0x43434003,
162 0x85818405, 0x04101414, 0x89818809, 0x8b93981b, 0x80b0b030, 0xc5e1e425, 0x48404808, 0x49717839,
163 0x87939417, 0xccf0fc3c, 0x0e121c1e, 0x82828002, 0x01212021, 0x8c808c0c, 0x0b13181b, 0x4f535c1f,
164 0x47737437, 0x44505414, 0x82b2b032, 0x0d111c1d, 0x05212425, 0x4f434c0f, 0x00000000, 0x46424406,
165 0xcde1ec2d, 0x48505818, 0x42525012, 0xcbe3e82b, 0x4e727c3e, 0xcad2d81a, 0xc9c1c809, 0xcdf1fc3d,
166 0x00303030, 0x85919415, 0x45616425, 0x0c303c3c, 0x86b2b436, 0xc4e0e424, 0x8bb3b83b, 0x4c707c3c,
167 0x0e020c0e, 0x40505010, 0x09313839, 0x06222426, 0x02323032, 0x84808404, 0x49616829, 0x83939013,
168 0x07333437, 0xc7e3e427, 0x04202424, 0x84a0a424, 0xcbc3c80b, 0x43535013, 0x0a02080a, 0x87838407,
169 0xc9d1d819, 0x4c404c0c, 0x83838003, 0x8f838c0f, 0xcec2cc0e, 0x0b33383b, 0x4a42480a, 0x87b3b437
170} };
171
172/* key schedule constants - golden ratio */
173#define KC0 0x9e3779b9
174#define KC1 0x3c6ef373
175#define KC2 0x78dde6e6
176#define KC3 0xf1bbcdcc
177#define KC4 0xe3779b99
178#define KC5 0xc6ef3733
179#define KC6 0x8dde6e67
180#define KC7 0x1bbcdccf
181#define KC8 0x3779b99e
182#define KC9 0x6ef3733c
183#define KC10 0xdde6e678
184#define KC11 0xbbcdccf1
185#define KC12 0x779b99e3
186#define KC13 0xef3733c6
187#define KC14 0xde6e678d
188#define KC15 0xbcdccf1b
189
190
191void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks)
192{
193 seed_word x1, x2, x3, x4;
194 seed_word t0, t1;
195
196 char2word(rawkey , x1);
197 char2word(rawkey+4 , x2);
198 char2word(rawkey+8 , x3);
199 char2word(rawkey+12, x4);
200
201 t0 = (x1 + x3 - KC0) & 0xffffffff;
202 t1 = (x2 - x4 + KC0) & 0xffffffff; KEYUPDATE_TEMP(t0, t1, &ks->data[0]);
203 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC1); KEYUPDATE_TEMP(t0, t1, &ks->data[2]);
204 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC2); KEYUPDATE_TEMP(t0, t1, &ks->data[4]);
205 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC3); KEYUPDATE_TEMP(t0, t1, &ks->data[6]);
206 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC4); KEYUPDATE_TEMP(t0, t1, &ks->data[8]);
207 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC5); KEYUPDATE_TEMP(t0, t1, &ks->data[10]);
208 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC6); KEYUPDATE_TEMP(t0, t1, &ks->data[12]);
209 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC7); KEYUPDATE_TEMP(t0, t1, &ks->data[14]);
210 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC8); KEYUPDATE_TEMP(t0, t1, &ks->data[16]);
211 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC9); KEYUPDATE_TEMP(t0, t1, &ks->data[18]);
212 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC10); KEYUPDATE_TEMP(t0, t1, &ks->data[20]);
213 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC11); KEYUPDATE_TEMP(t0, t1, &ks->data[22]);
214 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC12); KEYUPDATE_TEMP(t0, t1, &ks->data[24]);
215 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC13); KEYUPDATE_TEMP(t0, t1, &ks->data[26]);
216 KEYSCHEDULE_UPDATE0(t0, t1, x1, x2, x3, x4, KC14); KEYUPDATE_TEMP(t0, t1, &ks->data[28]);
217 KEYSCHEDULE_UPDATE1(t0, t1, x1, x2, x3, x4, KC15); KEYUPDATE_TEMP(t0, t1, &ks->data[30]);
218}
219
220void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks)
221{
222 seed_word x1, x2, x3, x4;
223 seed_word t0, t1;
224
225 char2word(s, x1);
226 char2word(s+4, x2);
227 char2word(s+8, x3);
228 char2word(s+12, x4);
229
230 E_SEED(t0, t1, x1, x2, x3, x4, 0);
231 E_SEED(t0, t1, x3, x4, x1, x2, 2);
232 E_SEED(t0, t1, x1, x2, x3, x4, 4);
233 E_SEED(t0, t1, x3, x4, x1, x2, 6);
234 E_SEED(t0, t1, x1, x2, x3, x4, 8);
235 E_SEED(t0, t1, x3, x4, x1, x2, 10);
236 E_SEED(t0, t1, x1, x2, x3, x4, 12);
237 E_SEED(t0, t1, x3, x4, x1, x2, 14);
238 E_SEED(t0, t1, x1, x2, x3, x4, 16);
239 E_SEED(t0, t1, x3, x4, x1, x2, 18);
240 E_SEED(t0, t1, x1, x2, x3, x4, 20);
241 E_SEED(t0, t1, x3, x4, x1, x2, 22);
242 E_SEED(t0, t1, x1, x2, x3, x4, 24);
243 E_SEED(t0, t1, x3, x4, x1, x2, 26);
244 E_SEED(t0, t1, x1, x2, x3, x4, 28);
245 E_SEED(t0, t1, x3, x4, x1, x2, 30);
246
247 word2char(x3, d);
248 word2char(x4, d+4);
249 word2char(x1, d+8);
250 word2char(x2, d+12);
251}
252
253void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks)
254{
255 seed_word x1, x2, x3, x4;
256 seed_word t0, t1;
257
258 char2word(s, x1);
259 char2word(s+4, x2);
260 char2word(s+8, x3);
261 char2word(s+12, x4);
262
263 E_SEED(t0, t1, x1, x2, x3, x4, 30);
264 E_SEED(t0, t1, x3, x4, x1, x2, 28);
265 E_SEED(t0, t1, x1, x2, x3, x4, 26);
266 E_SEED(t0, t1, x3, x4, x1, x2, 24);
267 E_SEED(t0, t1, x1, x2, x3, x4, 22);
268 E_SEED(t0, t1, x3, x4, x1, x2, 20);
269 E_SEED(t0, t1, x1, x2, x3, x4, 18);
270 E_SEED(t0, t1, x3, x4, x1, x2, 16);
271 E_SEED(t0, t1, x1, x2, x3, x4, 14);
272 E_SEED(t0, t1, x3, x4, x1, x2, 12);
273 E_SEED(t0, t1, x1, x2, x3, x4, 10);
274 E_SEED(t0, t1, x3, x4, x1, x2, 8);
275 E_SEED(t0, t1, x1, x2, x3, x4, 6);
276 E_SEED(t0, t1, x3, x4, x1, x2, 4);
277 E_SEED(t0, t1, x1, x2, x3, x4, 2);
278 E_SEED(t0, t1, x3, x4, x1, x2, 0);
279
280 word2char(x3, d);
281 word2char(x4, d+4);
282 word2char(x1, d+8);
283 word2char(x2, d+12);
284}
285
286#endif /* OPENSSL_NO_SEED */
diff --git a/src/lib/libcrypto/seed/seed.h b/src/lib/libcrypto/seed/seed.h
new file mode 100644
index 0000000000..427915ed9a
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed.h
@@ -0,0 +1,135 @@
1/*
2 * Copyright (c) 2007 KISA(Korea Information Security Agency). 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Neither the name of author nor the names of its contributors may
10 * be used to endorse or promote products derived from this software
11 * without specific prior written permission.
12 *
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 */
26/* ====================================================================
27 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 *
36 * 2. Redistributions in binary form must reproduce the above copyright
37 * notice, this list of conditions and the following disclaimer in
38 * the documentation and/or other materials provided with the
39 * distribution.
40 *
41 * 3. All advertising materials mentioning features or use of this
42 * software must display the following acknowledgment:
43 * "This product includes software developed by the OpenSSL Project
44 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
45 *
46 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
47 * endorse or promote products derived from this software without
48 * prior written permission. For written permission, please contact
49 * openssl-core@openssl.org.
50 *
51 * 5. Products derived from this software may not be called "OpenSSL"
52 * nor may "OpenSSL" appear in their names without prior written
53 * permission of the OpenSSL Project.
54 *
55 * 6. Redistributions of any form whatsoever must retain the following
56 * acknowledgment:
57 * "This product includes software developed by the OpenSSL Project
58 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
59 *
60 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
61 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
63 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
64 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
65 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
66 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
67 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
68 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
69 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
70 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
71 * OF THE POSSIBILITY OF SUCH DAMAGE.
72 * ====================================================================
73 *
74 * This product includes cryptographic software written by Eric Young
75 * (eay@cryptsoft.com). This product includes software written by Tim
76 * Hudson (tjh@cryptsoft.com).
77 *
78 */
79
80
81#ifndef HEADER_SEED_H
82#define HEADER_SEED_H
83
84#include <openssl/opensslconf.h>
85
86#ifdef OPENSSL_NO_SEED
87#error SEED is disabled.
88#endif
89
90#ifdef AES_LONG /* look whether we need 'long' to get 32 bits */
91# ifndef SEED_LONG
92# define SEED_LONG 1
93# endif
94#endif
95
96#if !defined(NO_SYS_TYPES_H)
97# include <sys/types.h>
98#endif
99
100#define SEED_BLOCK_SIZE 16
101#define SEED_KEY_LENGTH 16
102
103
104#ifdef __cplusplus
105extern "C" {
106#endif
107
108
109typedef struct seed_key_st {
110#ifdef SEED_LONG
111 unsigned long data[32];
112#else
113 unsigned int data[32];
114#endif
115} SEED_KEY_SCHEDULE;
116
117
118void SEED_set_key(const unsigned char rawkey[SEED_KEY_LENGTH], SEED_KEY_SCHEDULE *ks);
119
120void SEED_encrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks);
121void SEED_decrypt(const unsigned char s[SEED_BLOCK_SIZE], unsigned char d[SEED_BLOCK_SIZE], const SEED_KEY_SCHEDULE *ks);
122
123void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, const SEED_KEY_SCHEDULE *ks, int enc);
124void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out,
125 size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int enc);
126void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out,
127 size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc);
128void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out,
129 size_t len, const SEED_KEY_SCHEDULE *ks, unsigned char ivec[SEED_BLOCK_SIZE], int *num);
130
131#ifdef __cplusplus
132}
133#endif
134
135#endif /* HEADER_SEED_H */
diff --git a/src/lib/libcrypto/seed/seed_cbc.c b/src/lib/libcrypto/seed/seed_cbc.c
new file mode 100644
index 0000000000..4f718ccb44
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed_cbc.c
@@ -0,0 +1,129 @@
1/* crypto/seed/seed_cbc.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include "seed_locl.h"
53#include <string.h>
54
55void SEED_cbc_encrypt(const unsigned char *in, unsigned char *out,
56 size_t len, const SEED_KEY_SCHEDULE *ks,
57 unsigned char ivec[SEED_BLOCK_SIZE], int enc)
58 {
59 size_t n;
60 unsigned char tmp[SEED_BLOCK_SIZE];
61 const unsigned char *iv = ivec;
62
63 if (enc)
64 {
65 while (len >= SEED_BLOCK_SIZE)
66 {
67 for (n = 0; n < SEED_BLOCK_SIZE; ++n)
68 out[n] = in[n] ^ iv[n];
69 SEED_encrypt(out, out, ks);
70 iv = out;
71 len -= SEED_BLOCK_SIZE;
72 in += SEED_BLOCK_SIZE;
73 out += SEED_BLOCK_SIZE;
74 }
75 if (len)
76 {
77 for (n = 0; n < len; ++n)
78 out[n] = in[n] ^ iv[n];
79 for (n = len; n < SEED_BLOCK_SIZE; ++n)
80 out[n] = iv[n];
81 SEED_encrypt(out, out, ks);
82 iv = out;
83 }
84 memcpy(ivec, iv, SEED_BLOCK_SIZE);
85 }
86 else if (in != out) /* decrypt */
87 {
88 while (len >= SEED_BLOCK_SIZE)
89 {
90 SEED_decrypt(in, out, ks);
91 for (n = 0; n < SEED_BLOCK_SIZE; ++n)
92 out[n] ^= iv[n];
93 iv = in;
94 len -= SEED_BLOCK_SIZE;
95 in += SEED_BLOCK_SIZE;
96 out += SEED_BLOCK_SIZE;
97 }
98 if (len)
99 {
100 SEED_decrypt(in, tmp, ks);
101 for (n = 0; n < len; ++n)
102 out[n] = tmp[n] ^ iv[n];
103 iv = in;
104 }
105 memcpy(ivec, iv, SEED_BLOCK_SIZE);
106 }
107 else /* decrypt, overlap */
108 {
109 while (len >= SEED_BLOCK_SIZE)
110 {
111 memcpy(tmp, in, SEED_BLOCK_SIZE);
112 SEED_decrypt(in, out, ks);
113 for (n = 0; n < SEED_BLOCK_SIZE; ++n)
114 out[n] ^= ivec[n];
115 memcpy(ivec, tmp, SEED_BLOCK_SIZE);
116 len -= SEED_BLOCK_SIZE;
117 in += SEED_BLOCK_SIZE;
118 out += SEED_BLOCK_SIZE;
119 }
120 if (len)
121 {
122 memcpy(tmp, in, SEED_BLOCK_SIZE);
123 SEED_decrypt(tmp, tmp, ks);
124 for (n = 0; n < len; ++n)
125 out[n] = tmp[n] ^ ivec[n];
126 memcpy(ivec, tmp, SEED_BLOCK_SIZE);
127 }
128 }
129 }
diff --git a/src/lib/libcrypto/seed/seed_cfb.c b/src/lib/libcrypto/seed/seed_cfb.c
new file mode 100644
index 0000000000..07d878a788
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed_cfb.c
@@ -0,0 +1,144 @@
1/* crypto/seed/seed_cfb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#include "seed_locl.h"
109#include <string.h>
110
111void SEED_cfb128_encrypt(const unsigned char *in, unsigned char *out,
112 size_t len, const SEED_KEY_SCHEDULE *ks,
113 unsigned char ivec[SEED_BLOCK_SIZE], int *num, int enc)
114 {
115 int n;
116 unsigned char c;
117
118 n = *num;
119
120 if (enc)
121 {
122 while (len--)
123 {
124 if (n == 0)
125 SEED_encrypt(ivec, ivec, ks);
126 ivec[n] = *(out++) = *(in++) ^ ivec[n];
127 n = (n+1) % SEED_BLOCK_SIZE;
128 }
129 }
130 else
131 {
132 while (len--)
133 {
134 if (n == 0)
135 SEED_encrypt(ivec, ivec, ks);
136 c = *(in);
137 *(out++) = *(in++) ^ ivec[n];
138 ivec[n] = c;
139 n = (n+1) % SEED_BLOCK_SIZE;
140 }
141 }
142
143 *num = n;
144 }
diff --git a/src/lib/libcrypto/seed/seed_ecb.c b/src/lib/libcrypto/seed/seed_ecb.c
new file mode 100644
index 0000000000..e63f5ae14e
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed_ecb.c
@@ -0,0 +1,60 @@
1/* crypto/seed/seed_ecb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51
52#include <openssl/seed.h>
53
54void SEED_ecb_encrypt(const unsigned char *in, unsigned char *out, const SEED_KEY_SCHEDULE *ks, int enc)
55 {
56 if (enc)
57 SEED_encrypt(in, out, ks);
58 else
59 SEED_decrypt(in, out, ks);
60 }
diff --git a/src/lib/libcrypto/seed/seed_locl.h b/src/lib/libcrypto/seed/seed_locl.h
new file mode 100644
index 0000000000..fd456b6422
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed_locl.h
@@ -0,0 +1,116 @@
1/*
2 * Copyright (c) 2007 KISA(Korea Information Security Agency). 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 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Neither the name of author nor the names of its contributors may
10 * be used to endorse or promote products derived from this software
11 * without specific prior written permission.
12 *
13 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
17 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 * SUCH DAMAGE.
24 *
25 */
26#ifndef HEADER_SEED_LOCL_H
27#define HEADER_SEED_LOCL_H
28
29#include "openssl/e_os2.h"
30#include <openssl/seed.h>
31
32
33#ifdef SEED_LONG /* need 32-bit type */
34typedef unsigned long seed_word;
35#else
36typedef unsigned int seed_word;
37#endif
38
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44#define G_FUNC(v) \
45 SS[0][(unsigned char) (v) & 0xff] ^ SS[1][(unsigned char) ((v)>>8) & 0xff] ^ \
46 SS[2][(unsigned char)((v)>>16) & 0xff] ^ SS[3][(unsigned char)((v)>>24) & 0xff]
47
48#define char2word(c, i) \
49 (i) = ((((seed_word)(c)[0]) << 24) | (((seed_word)(c)[1]) << 16) | (((seed_word)(c)[2]) << 8) | ((seed_word)(c)[3]))
50
51#define word2char(l, c) \
52 *((c)+0) = (unsigned char)((l)>>24) & 0xff; \
53 *((c)+1) = (unsigned char)((l)>>16) & 0xff; \
54 *((c)+2) = (unsigned char)((l)>> 8) & 0xff; \
55 *((c)+3) = (unsigned char)((l)) & 0xff
56
57#define KEYSCHEDULE_UPDATE0(T0, T1, X1, X2, X3, X4, KC) \
58 (T0) = (X3); \
59 (X3) = (((X3)<<8) ^ ((X4)>>24)) & 0xffffffff; \
60 (X4) = (((X4)<<8) ^ ((T0)>>24)) & 0xffffffff; \
61 (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \
62 (T1) = ((X2) + (KC) - (X4)) & 0xffffffff
63
64#define KEYSCHEDULE_UPDATE1(T0, T1, X1, X2, X3, X4, KC) \
65 (T0) = (X1); \
66 (X1) = (((X1)>>8) ^ ((X2)<<24)) & 0xffffffff; \
67 (X2) = (((X2)>>8) ^ ((T0)<<24)) & 0xffffffff; \
68 (T0) = ((X1) + (X3) - (KC)) & 0xffffffff; \
69 (T1) = ((X2) + (KC) - (X4)) & 0xffffffff
70
71#define KEYUPDATE_TEMP(T0, T1, K) \
72 (K)[0] = G_FUNC((T0)); \
73 (K)[1] = G_FUNC((T1))
74
75#define XOR_SEEDBLOCK(DST, SRC) \
76 ((DST))[0] ^= ((SRC))[0]; \
77 ((DST))[1] ^= ((SRC))[1]; \
78 ((DST))[2] ^= ((SRC))[2]; \
79 ((DST))[3] ^= ((SRC))[3]
80
81#define MOV_SEEDBLOCK(DST, SRC) \
82 ((DST))[0] = ((SRC))[0]; \
83 ((DST))[1] = ((SRC))[1]; \
84 ((DST))[2] = ((SRC))[2]; \
85 ((DST))[3] = ((SRC))[3]
86
87# define CHAR2WORD(C, I) \
88 char2word((C), (I)[0]); \
89 char2word((C+4), (I)[1]); \
90 char2word((C+8), (I)[2]); \
91 char2word((C+12), (I)[3])
92
93# define WORD2CHAR(I, C) \
94 word2char((I)[0], (C)); \
95 word2char((I)[1], (C+4)); \
96 word2char((I)[2], (C+8)); \
97 word2char((I)[3], (C+12))
98
99# define E_SEED(T0, T1, X1, X2, X3, X4, rbase) \
100 (T0) = (X3) ^ (ks->data)[(rbase)]; \
101 (T1) = (X4) ^ (ks->data)[(rbase)+1]; \
102 (T1) ^= (T0); \
103 (T1) = G_FUNC((T1)); \
104 (T0) = ((T0) + (T1)) & 0xffffffff; \
105 (T0) = G_FUNC((T0)); \
106 (T1) = ((T1) + (T0)) & 0xffffffff; \
107 (T1) = G_FUNC((T1)); \
108 (T0) = ((T0) + (T1)) & 0xffffffff; \
109 (X1) ^= (T0); \
110 (X2) ^= (T1)
111
112#ifdef __cplusplus
113}
114#endif
115
116#endif /* HEADER_SEED_LOCL_H */
diff --git a/src/lib/libcrypto/seed/seed_ofb.c b/src/lib/libcrypto/seed/seed_ofb.c
new file mode 100644
index 0000000000..e2f3f57a38
--- /dev/null
+++ b/src/lib/libcrypto/seed/seed_ofb.c
@@ -0,0 +1,128 @@
1/* crypto/seed/seed_ofb.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 */
51/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
52 * All rights reserved.
53 *
54 * This package is an SSL implementation written
55 * by Eric Young (eay@cryptsoft.com).
56 * The implementation was written so as to conform with Netscapes SSL.
57 *
58 * This library is free for commercial and non-commercial use as long as
59 * the following conditions are aheared to. The following conditions
60 * apply to all code found in this distribution, be it the RC4, RSA,
61 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
62 * included with this distribution is covered by the same copyright terms
63 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
64 *
65 * Copyright remains Eric Young's, and as such any Copyright notices in
66 * the code are not to be removed.
67 * If this package is used in a product, Eric Young should be given attribution
68 * as the author of the parts of the library used.
69 * This can be in the form of a textual message at program startup or
70 * in documentation (online or textual) provided with the package.
71 *
72 * Redistribution and use in source and binary forms, with or without
73 * modification, are permitted provided that the following conditions
74 * are met:
75 * 1. Redistributions of source code must retain the copyright
76 * notice, this list of conditions and the following disclaimer.
77 * 2. Redistributions in binary form must reproduce the above copyright
78 * notice, this list of conditions and the following disclaimer in the
79 * documentation and/or other materials provided with the distribution.
80 * 3. All advertising materials mentioning features or use of this software
81 * must display the following acknowledgement:
82 * "This product includes cryptographic software written by
83 * Eric Young (eay@cryptsoft.com)"
84 * The word 'cryptographic' can be left out if the rouines from the library
85 * being used are not cryptographic related :-).
86 * 4. If you include any Windows specific code (or a derivative thereof) from
87 * the apps directory (application code) you must include an acknowledgement:
88 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
89 *
90 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
91 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
94 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100 * SUCH DAMAGE.
101 *
102 * The licence and distribution terms for any publically available version or
103 * derivative of this code cannot be changed. i.e. this code cannot simply be
104 * copied and put under another distribution licence
105 * [including the GNU Public Licence.]
106 */
107
108#include "seed_locl.h"
109#include <string.h>
110
111void SEED_ofb128_encrypt(const unsigned char *in, unsigned char *out,
112 size_t len, const SEED_KEY_SCHEDULE *ks,
113 unsigned char ivec[SEED_BLOCK_SIZE], int *num)
114 {
115 int n;
116
117 n = *num;
118
119 while (len--)
120 {
121 if (n == 0)
122 SEED_encrypt(ivec, ivec, ks);
123 *(out++) = *(in++) ^ ivec[n];
124 n = (n+1) % SEED_BLOCK_SIZE;
125 }
126
127 *num = n;
128 }
diff --git a/src/lib/libcrypto/sha/Makefile b/src/lib/libcrypto/sha/Makefile
new file mode 100644
index 0000000000..ac64fb61d3
--- /dev/null
+++ b/src/lib/libcrypto/sha/Makefile
@@ -0,0 +1,139 @@
1#
2# OpenSSL/crypto/sha/Makefile
3#
4
5DIR= sha
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11MAKEFILE= Makefile
12AR= ar r
13
14SHA1_ASM_OBJ=
15
16CFLAGS= $(INCLUDES) $(CFLAG)
17ASFLAGS= $(INCLUDES) $(ASFLAG)
18AFLAGS= $(ASFLAGS)
19
20GENERAL=Makefile
21TEST=shatest.c sha1test.c sha256t.c sha512t.c
22APPS=
23
24LIB=$(TOP)/libcrypto.a
25LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c sha256.c sha512.c
26LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o sha256.o sha512.o $(SHA1_ASM_OBJ)
27
28SRC= $(LIBSRC)
29
30EXHEADER= sha.h
31HEADER= sha_locl.h $(EXHEADER)
32
33ALL= $(GENERAL) $(SRC) $(HEADER)
34
35top:
36 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
37
38all: lib
39
40lib: $(LIBOBJ)
41 $(AR) $(LIB) $(LIBOBJ)
42 $(RANLIB) $(LIB) || echo Never mind.
43 @touch lib
44
45# ELF
46sx86-elf.s: asm/sha1-586.pl ../perlasm/x86asm.pl
47 (cd asm; $(PERL) sha1-586.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
48s512sse2-elf.s: asm/sha512-sse2.pl ../perlasm/x86asm.pl
49 (cd asm; $(PERL) sha512-sse2.pl elf $(CFLAGS) $(PROCESSOR) > ../$@)
50# COFF
51sx86-cof.s: asm/sha1-586.pl ../perlasm/x86asm.pl
52 (cd asm; $(PERL) sha1-586.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
53s512sse2-cof.s: asm/sha512-sse2.pl ../perlasm/x86asm.pl
54 (cd asm; $(PERL) sha512-sse2.pl coff $(CFLAGS) $(PROCESSOR) > ../$@)
55# a.out
56sx86-out.s: asm/sha1-586.pl ../perlasm/x86asm.pl
57 (cd asm; $(PERL) sha1-586.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
58s512sse2-out.s: asm/sha512-sse2.pl ../perlasm/x86asm.pl
59 (cd asm; $(PERL) sha512-sse2.pl a.out $(CFLAGS) $(PROCESSOR) > ../$@)
60
61sha1-ia64.s: asm/sha1-ia64.pl
62 (cd asm; $(PERL) sha1-ia64.pl $(CFLAGS) ) > $@
63sha256-ia64.s: asm/sha512-ia64.pl
64 (cd asm; $(PERL) sha512-ia64.pl ../$@ $(CFLAGS))
65sha512-ia64.s: asm/sha512-ia64.pl
66 (cd asm; $(PERL) sha512-ia64.pl ../$@ $(CFLAGS))
67
68# Solaris make has to be explicitly told
69sha1-x86_64.s: asm/sha1-x86_64.pl; $(PERL) asm/sha1-x86_64.pl $@
70sha256-x86_64.s:asm/sha512-x86_64.pl; $(PERL) asm/sha512-x86_64.pl $@
71sha512-x86_64.s:asm/sha512-x86_64.pl; $(PERL) asm/sha512-x86_64.pl $@
72
73files:
74 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
75
76links:
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
81install:
82 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
83 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
84 do \
85 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
86 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
87 done;
88
89tags:
90 ctags $(SRC)
91
92tests:
93
94lint:
95 lint -DLINT $(INCLUDES) $(SRC)>fluff
96
97depend:
98 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
99 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
100
101dclean:
102 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
103 mv -f Makefile.new $(MAKEFILE)
104
105clean:
106 rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
107
108# DO NOT DELETE THIS LINE -- make depend depends on it.
109
110sha1_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
111sha1_one.o: ../../include/openssl/opensslconf.h
112sha1_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
113sha1_one.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
114sha1_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
115sha1_one.o: sha1_one.c
116sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
117sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
118sha1dgst.o: ../md32_common.h sha1dgst.c sha_locl.h
119sha256.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
120sha256.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
121sha256.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
122sha256.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
123sha256.o: ../../include/openssl/symhacks.h ../md32_common.h sha256.c
124sha512.o: ../../e_os.h ../../include/openssl/bio.h
125sha512.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
126sha512.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
127sha512.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
128sha512.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
129sha512.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
130sha512.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
131sha512.o: ../cryptlib.h sha512.c
132sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
133sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
134sha_dgst.o: ../md32_common.h sha_dgst.c sha_locl.h
135sha_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
136sha_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
137sha_one.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
138sha_one.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
139sha_one.o: ../../include/openssl/symhacks.h sha_one.c
diff --git a/src/lib/libcrypto/sha/Makefile.ssl b/src/lib/libcrypto/sha/Makefile.ssl
new file mode 100644
index 0000000000..4ba201c787
--- /dev/null
+++ b/src/lib/libcrypto/sha/Makefile.ssl
@@ -0,0 +1,116 @@
1#
2# SSLeay/crypto/sha/Makefile
3#
4
5DIR= sha
6TOP= ../..
7CC= cc
8CPP= $(CC) -E
9INCLUDES=
10CFLAG=-g
11INSTALL_PREFIX=
12OPENSSLDIR= /usr/local/ssl
13INSTALLTOP=/usr/local/ssl
14MAKE= make -f Makefile.ssl
15MAKEDEPPROG= makedepend
16MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
17MAKEFILE= Makefile.ssl
18AR= ar r
19
20SHA1_ASM_OBJ=
21
22CFLAGS= $(INCLUDES) $(CFLAG)
23ASFLAGS= $(INCLUDES) $(ASFLAG)
24
25GENERAL=Makefile
26TEST=shatest.c sha1test.c
27APPS=
28
29LIB=$(TOP)/libcrypto.a
30LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c
31LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o $(SHA1_ASM_OBJ)
32
33SRC= $(LIBSRC)
34
35EXHEADER= sha.h
36HEADER= sha_locl.h $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50# elf
51asm/sx86-elf.s: asm/sha1-586.pl ../perlasm/x86asm.pl
52 (cd asm; $(PERL) sha1-586.pl elf $(CFLAGS) $(PROCESSOR) > sx86-elf.s)
53
54# a.out
55asm/sx86-out.o: asm/sx86unix.cpp
56 $(CPP) -DOUT asm/sx86unix.cpp | as -o asm/sx86-out.o
57
58# bsdi
59asm/sx86bsdi.o: asm/sx86unix.cpp
60 $(CPP) -DBSDI asm/sx86unix.cpp | sed 's/ :/:/' | as -o asm/sx86bsdi.o
61
62asm/sx86unix.cpp: asm/sha1-586.pl ../perlasm/x86asm.pl
63 (cd asm; $(PERL) sha1-586.pl cpp $(PROCESSOR) >sx86unix.cpp)
64
65files:
66 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
67
68links:
69 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
70 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
71 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
72 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
73
74install:
75 @for i in $(EXHEADER) ; \
76 do \
77 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
78 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
79 done;
80
81tags:
82 ctags $(SRC)
83
84tests:
85
86lint:
87 lint -DLINT $(INCLUDES) $(SRC)>fluff
88
89depend:
90 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
91
92dclean:
93 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
94 mv -f Makefile.new $(MAKEFILE)
95
96clean:
97 rm -f asm/sx86unix.cpp asm/*-elf.* *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o
98
99# DO NOT DELETE THIS LINE -- make depend depends on it.
100
101sha1_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102sha1_one.o: ../../include/openssl/opensslconf.h
103sha1_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
104sha1_one.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
105sha1_one.o: ../../include/openssl/symhacks.h sha1_one.c
106sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
107sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
108sha1dgst.o: ../md32_common.h sha1dgst.c sha_locl.h
109sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
110sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h
111sha_dgst.o: ../md32_common.h sha_dgst.c sha_locl.h
112sha_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
113sha_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
114sha_one.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
115sha_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
116sha_one.o: sha_one.c
diff --git a/src/lib/libcrypto/sha/asm/README b/src/lib/libcrypto/sha/asm/README
new file mode 100644
index 0000000000..b7e755765f
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/README
@@ -0,0 +1 @@
C2.pl works
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl
index 0b4dab2bd5..041acc0348 100644
--- a/src/lib/libcrypto/sha/asm/sha1-586.pl
+++ b/src/lib/libcrypto/sha/asm/sha1-586.pl
@@ -1,16 +1,4 @@
1#!/usr/bin/env perl 1#!/usr/local/bin/perl
2
3# ====================================================================
4# [Re]written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. The module is, however, dual licensed under OpenSSL and
6# CRYPTOGAMS licenses depending on where you obtain it. For further
7# details see http://www.openssl.org/~appro/cryptogams/.
8# ====================================================================
9
10# "[Re]written" was achieved in two major overhauls. In 2004 BODY_*
11# functions were re-implemented to address P4 performance issue [see
12# commentary below], and in 2006 the rest was rewritten in order to
13# gain freedom to liberate licensing terms.
14 2
15# It was noted that Intel IA-32 C compiler generates code which 3# It was noted that Intel IA-32 C compiler generates code which
16# performs ~30% *faster* on P4 CPU than original *hand-coded* 4# performs ~30% *faster* on P4 CPU than original *hand-coded*
@@ -21,7 +9,7 @@
21# 9#
22# compared with original compared with Intel cc 10# compared with original compared with Intel cc
23# assembler impl. generated code 11# assembler impl. generated code
24# Pentium -16% +48% 12# Pentium -25% +37%
25# PIII/AMD +8% +16% 13# PIII/AMD +8% +16%
26# P4 +85%(!) +45% 14# P4 +85%(!) +45%
27# 15#
@@ -29,115 +17,174 @@
29# improvement on P4 outweights the loss and incorporate this 17# improvement on P4 outweights the loss and incorporate this
30# re-tuned code to 0.9.7 and later. 18# re-tuned code to 0.9.7 and later.
31# ---------------------------------------------------------------- 19# ----------------------------------------------------------------
20# Those who for any particular reason absolutely must score on
21# Pentium can replace this module with one from 0.9.6 distribution.
22# This "offer" shall be revoked the moment programming interface to
23# this module is changed, in which case this paragraph should be
24# removed.
25# ----------------------------------------------------------------
32# <appro@fy.chalmers.se> 26# <appro@fy.chalmers.se>
33 27
34$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; 28$normal=0;
35push(@INC,"${dir}","${dir}../../perlasm"); 29
30push(@INC,"perlasm","../../perlasm");
36require "x86asm.pl"; 31require "x86asm.pl";
37 32
38&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); 33&asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386");
39 34
40$A="eax"; 35$A="eax";
41$B="ebx"; 36$B="ecx";
42$C="ecx"; 37$C="ebx";
43$D="edx"; 38$D="edx";
44$E="edi"; 39$E="edi";
45$T="esi"; 40$T="esi";
46$tmp1="ebp"; 41$tmp1="ebp";
47 42
48@V=($A,$B,$C,$D,$E,$T); 43$off=9*4;
44
45@K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6);
46
47&sha1_block_data("sha1_block_asm_data_order");
48
49&asm_finish();
50
51sub Nn
52 {
53 local($p)=@_;
54 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
55 return($n{$p});
56 }
57
58sub Np
59 {
60 local($p)=@_;
61 local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E);
62 local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A);
63 return($n{$p});
64 }
65
66sub Na
67 {
68 local($n)=@_;
69 return( (($n )&0x0f),
70 (($n+ 2)&0x0f),
71 (($n+ 8)&0x0f),
72 (($n+13)&0x0f),
73 (($n+ 1)&0x0f));
74 }
75
76sub X_expand
77 {
78 local($in)=@_;
79
80 &comment("First, load the words onto the stack in network byte order");
81 for ($i=0; $i<16; $i+=2)
82 {
83 &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0;
84 &mov($B,&DWP(($i+1)*4,$in,"",0));
85 &bswap($A);
86 &bswap($B);
87 &mov(&swtmp($i+0),$A);
88 &mov(&swtmp($i+1),$B);
89 }
90
91 &comment("We now have the X array on the stack");
92 &comment("starting at sp-4");
93 }
94
95# Rules of engagement
96# F is always trashable at the start, the running total.
97# E becomes the next F so it can be trashed after it has been 'accumulated'
98# F becomes A in the next round. We don't need to access it much.
99# During the X update part, the result ends up in $X[$n0].
49 100
50sub BODY_00_15 101sub BODY_00_15
51 { 102 {
52 local($n,$a,$b,$c,$d,$e,$f)=@_; 103 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
53 104
54 &comment("00_15 $n"); 105 &comment("00_15 $n");
55 106
56 &mov($f,$c); # f to hold F_00_19(b,c,d) 107 &mov($tmp1,$a);
57 if ($n==0) { &mov($tmp1,$a); } 108 &mov($f,$c); # f to hold F_00_19(b,c,d)
58 else { &mov($a,$tmp1); }
59 &rotl($tmp1,5); # tmp1=ROTATE(a,5) 109 &rotl($tmp1,5); # tmp1=ROTATE(a,5)
60 &xor($f,$d); 110 &xor($f,$d);
111 &and($f,$b);
112 &rotr($b,2); # b=ROTATE(b,30)
61 &add($tmp1,$e); # tmp1+=e; 113 &add($tmp1,$e); # tmp1+=e;
62 &and($f,$b); 114 &mov($e,&swtmp($n)); # e becomes volatile and
63 &mov($e,&swtmp($n%16)); # e becomes volatile and is loaded 115 # is loaded with xi
64 # with xi, also note that e becomes 116 &xor($f,$d); # f holds F_00_19(b,c,d)
65 # f in next round... 117 &lea($tmp1,&DWP($K,$tmp1,$e,1));# tmp1+=K_00_19+xi
66 &xor($f,$d); # f holds F_00_19(b,c,d) 118
67 &rotr($b,2); # b=ROTATE(b,30) 119 &add($f,$tmp1); # f+=tmp1
68 &lea($tmp1,&DWP(0x5a827999,$tmp1,$e)); # tmp1+=K_00_19+xi
69
70 if ($n==15) { &add($f,$tmp1); } # f+=tmp1
71 else { &add($tmp1,$f); } # f becomes a in next round
72 } 120 }
73 121
74sub BODY_16_19 122sub BODY_16_19
75 { 123 {
76 local($n,$a,$b,$c,$d,$e,$f)=@_; 124 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
125 local($n0,$n1,$n2,$n3,$np)=&Na($n);
77 126
78 &comment("16_19 $n"); 127 &comment("16_19 $n");
79 128
80 &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) 129 &mov($f,&swtmp($n1)); # f to hold Xupdate(xi,xa,xb,xc,xd)
81 &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d) 130 &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d)
82 &xor($f,&swtmp(($n+2)%16)); 131 &xor($f,&swtmp($n0));
83 &xor($tmp1,$d); 132 &xor($tmp1,$d);
84 &xor($f,&swtmp(($n+8)%16)); 133 &xor($f,&swtmp($n2));
85 &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d) 134 &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d)
86 &rotr($b,2); # b=ROTATE(b,30) 135 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
87 &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd 136 &rotr($b,2); # b=ROTATE(b,30)
88 &rotl($f,1); # f=ROTATE(f,1) 137 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d)
89 &xor($tmp1,$d); # tmp1=F_00_19(b,c,d) 138 &rotl($f,1); # f=ROATE(f,1)
90 &mov(&swtmp($n%16),$f); # xi=f 139 &mov(&swtmp($n0),$f); # xi=f
91 &lea($f,&DWP(0x5a827999,$f,$e));# f+=K_00_19+e 140 &lea($f,&DWP($K,$f,$e,1)); # f+=K_00_19+e
92 &mov($e,$a); # e becomes volatile 141 &mov($e,$a); # e becomes volatile
93 &rotl($e,5); # e=ROTATE(a,5) 142 &add($f,$tmp1); # f+=F_00_19(b,c,d)
94 &add($f,$tmp1); # f+=F_00_19(b,c,d) 143 &rotl($e,5); # e=ROTATE(a,5)
95 &add($f,$e); # f+=ROTATE(a,5) 144 &add($f,$e); # f+=ROTATE(a,5)
96 } 145 }
97 146
98sub BODY_20_39 147sub BODY_20_39
99 { 148 {
100 local($n,$a,$b,$c,$d,$e,$f)=@_; 149 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
101 local $K=($n<40)?0x6ed9eba1:0xca62c1d6;
102 150
103 &comment("20_39 $n"); 151 &comment("20_39 $n");
152 local($n0,$n1,$n2,$n3,$np)=&Na($n);
104 153
105 &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d) 154 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
106 &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) 155 &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d)
107 &rotr($b,2); # b=ROTATE(b,30) 156 &xor($f,&swtmp($n1));
108 &xor($f,&swtmp(($n+2)%16)); 157 &rotr($b,2); # b=ROTATE(b,30)
109 &xor($tmp1,$c); 158 &xor($f,&swtmp($n2));
110 &xor($f,&swtmp(($n+8)%16)); 159 &xor($tmp1,$c);
111 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d) 160 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
112 &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd 161 &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d)
113 &rotl($f,1); # f=ROTATE(f,1) 162 &rotl($f,1); # f=ROTATE(f,1)
114 &add($tmp1,$e); 163 &mov(&swtmp($n0),$f); # xi=f
115 &mov(&swtmp($n%16),$f); # xi=f 164 &lea($f,&DWP($K,$f,$e,1)); # f+=K_20_39+e
116 &mov($e,$a); # e becomes volatile 165 &mov($e,$a); # e becomes volatile
117 &rotl($e,5); # e=ROTATE(a,5) 166 &rotl($e,5); # e=ROTATE(a,5)
118 &lea($f,&DWP($K,$f,$tmp1)); # f+=K_20_39+e 167 &add($f,$tmp1); # f+=F_20_39(b,c,d)
119 &add($f,$e); # f+=ROTATE(a,5) 168 &add($f,$e); # f+=ROTATE(a,5)
120 } 169 }
121 170
122sub BODY_40_59 171sub BODY_40_59
123 { 172 {
124 local($n,$a,$b,$c,$d,$e,$f)=@_; 173 local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_;
125 174
126 &comment("40_59 $n"); 175 &comment("40_59 $n");
176 local($n0,$n1,$n2,$n3,$np)=&Na($n);
127 177
128 &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) 178 &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd)
129 &mov($tmp1,&swtmp(($n+2)%16));
130 &xor($f,$tmp1);
131 &mov($tmp1,&swtmp(($n+8)%16));
132 &xor($f,$tmp1);
133 &mov($tmp1,&swtmp(($n+13)%16));
134 &xor($f,$tmp1); # f holds xa^xb^xc^xd
135 &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d) 179 &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d)
136 &rotl($f,1); # f=ROTATE(f,1) 180 &xor($f,&swtmp($n1));
137 &or($tmp1,$c); 181 &or($tmp1,$c);
138 &mov(&swtmp($n%16),$f); # xi=f 182 &xor($f,&swtmp($n2));
139 &and($tmp1,$d); 183 &and($tmp1,$d);
140 &lea($f,&DWP(0x8f1bbcdc,$f,$e));# f+=K_40_59+e 184 &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd
185 &rotl($f,1); # f=ROTATE(f,1)
186 &mov(&swtmp($n0),$f); # xi=f
187 &lea($f,&DWP($K,$f,$e,1)); # f+=K_40_59+e
141 &mov($e,$b); # e becomes volatile and is used 188 &mov($e,$b); # e becomes volatile and is used
142 # to calculate F_40_59(b,c,d) 189 # to calculate F_40_59(b,c,d)
143 &rotr($b,2); # b=ROTATE(b,30) 190 &rotr($b,2); # b=ROTATE(b,30)
@@ -145,75 +192,234 @@ sub BODY_40_59
145 &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d) 192 &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d)
146 &mov($e,$a); 193 &mov($e,$a);
147 &rotl($e,5); # e=ROTATE(a,5) 194 &rotl($e,5); # e=ROTATE(a,5)
148 &add($f,$tmp1); # f+=tmp1; 195 &add($tmp1,$e); # tmp1+=ROTATE(a,5)
149 &add($f,$e); # f+=ROTATE(a,5) 196 &add($f,$tmp1); # f+=tmp1;
150 } 197 }
151 198
152&function_begin("sha1_block_data_order",16); 199sub BODY_60_79
153 &mov($tmp1,&wparam(0)); # SHA_CTX *c 200 {
154 &mov($T,&wparam(1)); # const void *input 201 &BODY_20_39(@_);
155 &mov($A,&wparam(2)); # size_t num 202 }
156 &stack_push(16); # allocate X[16] 203
157 &shl($A,6); 204sub sha1_block_host
158 &add($A,$T); 205 {
159 &mov(&wparam(2),$A); # pointer beyond the end of input 206 local($name, $sclabel)=@_;
160 &mov($E,&DWP(16,$tmp1));# pre-load E
161 207
162 &set_label("loop",16); 208 &function_begin_B($name,"");
163 209
164 # copy input chunk to X, but reversing byte order! 210 # parameter 1 is the MD5_CTX structure.
165 for ($i=0; $i<16; $i+=4) 211 # A 0
212 # B 4
213 # C 8
214 # D 12
215 # E 16
216
217 &mov("ecx", &wparam(2));
218 &push("esi");
219 &shl("ecx",6);
220 &mov("esi", &wparam(1));
221 &push("ebp");
222 &add("ecx","esi"); # offset to leave on
223 &push("ebx");
224 &mov("ebp", &wparam(0));
225 &push("edi");
226 &mov($D, &DWP(12,"ebp","",0));
227 &stack_push(18+9);
228 &mov($E, &DWP(16,"ebp","",0));
229 &mov($C, &DWP( 8,"ebp","",0));
230 &mov(&swtmp(17),"ecx");
231
232 &comment("First we need to setup the X array");
233
234 for ($i=0; $i<16; $i+=2)
166 { 235 {
167 &mov($A,&DWP(4*($i+0),$T)); 236 &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0;
168 &mov($B,&DWP(4*($i+1),$T)); 237 &mov($B,&DWP(($i+1)*4,"esi","",0));
169 &mov($C,&DWP(4*($i+2),$T));
170 &mov($D,&DWP(4*($i+3),$T));
171 &bswap($A);
172 &bswap($B);
173 &bswap($C);
174 &bswap($D);
175 &mov(&swtmp($i+0),$A); 238 &mov(&swtmp($i+0),$A);
176 &mov(&swtmp($i+1),$B); 239 &mov(&swtmp($i+1),$B);
177 &mov(&swtmp($i+2),$C);
178 &mov(&swtmp($i+3),$D);
179 } 240 }
180 &mov(&wparam(1),$T); # redundant in 1st spin 241 &jmp($sclabel);
181 242 &function_end_B($name);
182 &mov($A,&DWP(0,$tmp1)); # load SHA_CTX 243 }
183 &mov($B,&DWP(4,$tmp1)); 244
184 &mov($C,&DWP(8,$tmp1)); 245
185 &mov($D,&DWP(12,$tmp1)); 246sub sha1_block_data
186 # E is pre-loaded 247 {
187 248 local($name)=@_;
188 for($i=0;$i<16;$i++) { &BODY_00_15($i,@V); unshift(@V,pop(@V)); } 249
189 for(;$i<20;$i++) { &BODY_16_19($i,@V); unshift(@V,pop(@V)); } 250 &function_begin_B($name,"");
190 for(;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 251
191 for(;$i<60;$i++) { &BODY_40_59($i,@V); unshift(@V,pop(@V)); } 252 # parameter 1 is the MD5_CTX structure.
192 for(;$i<80;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } 253 # A 0
193 254 # B 4
194 (($V[5] eq $D) and ($V[0] eq $E)) or die; # double-check 255 # C 8
195 256 # D 12
196 &mov($tmp1,&wparam(0)); # re-load SHA_CTX* 257 # E 16
197 &mov($D,&wparam(1)); # D is last "T" and is discarded 258
198 259 &mov("ecx", &wparam(2));
199 &add($E,&DWP(0,$tmp1)); # E is last "A"... 260 &push("esi");
200 &add($T,&DWP(4,$tmp1)); 261 &shl("ecx",6);
201 &add($A,&DWP(8,$tmp1)); 262 &mov("esi", &wparam(1));
202 &add($B,&DWP(12,$tmp1)); 263 &push("ebp");
203 &add($C,&DWP(16,$tmp1)); 264 &add("ecx","esi"); # offset to leave on
204 265 &push("ebx");
205 &mov(&DWP(0,$tmp1),$E); # update SHA_CTX 266 &mov("ebp", &wparam(0));
206 &add($D,64); # advance input pointer 267 &push("edi");
207 &mov(&DWP(4,$tmp1),$T); 268 &mov($D, &DWP(12,"ebp","",0));
208 &cmp($D,&wparam(2)); # have we reached the end yet? 269 &stack_push(18+9);
209 &mov(&DWP(8,$tmp1),$A); 270 &mov($E, &DWP(16,"ebp","",0));
210 &mov($E,$C); # C is last "E" which needs to be "pre-loaded" 271 &mov($C, &DWP( 8,"ebp","",0));
211 &mov(&DWP(12,$tmp1),$B); 272 &mov(&swtmp(17),"ecx");
212 &mov($T,$D); # input pointer 273
213 &mov(&DWP(16,$tmp1),$C); 274 &comment("First we need to setup the X array");
214 &jb(&label("loop")); 275
215 276 &set_label("start") unless $normal;
216 &stack_pop(16); 277
217&function_end("sha1_block_data_order"); 278 &X_expand("esi");
279 &mov(&wparam(1),"esi");
280
281 &set_label("shortcut", 0, 1);
282 &comment("");
283 &comment("Start processing");
284
285 # odd start
286 &mov($A, &DWP( 0,"ebp","",0));
287 &mov($B, &DWP( 4,"ebp","",0));
288 $X="esp";
289 &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T);
290 &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E);
291 &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D);
292 &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C);
293 &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B);
294 &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A);
295 &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T);
296 &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E);
297 &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D);
298 &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C);
299 &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B);
300 &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A);
301 &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T);
302 &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E);
303 &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D);
304 &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C);
305 &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B);
306 &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A);
307 &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T);
308 &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E);
309
310 &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D);
311 &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C);
312 &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B);
313 &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A);
314 &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T);
315 &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E);
316 &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D);
317 &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C);
318 &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B);
319 &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A);
320 &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T);
321 &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E);
322 &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D);
323 &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C);
324 &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B);
325 &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A);
326 &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T);
327 &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E);
328 &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D);
329 &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C);
330
331 &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B);
332 &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A);
333 &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T);
334 &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E);
335 &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D);
336 &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C);
337 &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B);
338 &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A);
339 &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T);
340 &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E);
341 &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D);
342 &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C);
343 &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B);
344 &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A);
345 &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T);
346 &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E);
347 &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D);
348 &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C);
349 &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B);
350 &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A);
351
352 &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T);
353 &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E);
354 &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D);
355 &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C);
356 &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B);
357 &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A);
358 &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T);
359 &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E);
360 &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D);
361 &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C);
362 &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B);
363 &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A);
364 &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T);
365 &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E);
366 &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D);
367 &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C);
368 &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B);
369 &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A);
370 &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T);
371 &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E);
372
373 &comment("End processing");
374 &comment("");
375 # D is the tmp value
376
377 # E -> A
378 # T -> B
379 # A -> C
380 # B -> D
381 # C -> E
382 # D -> T
383
384 &mov($tmp1,&wparam(0));
385
386 &mov($D, &DWP(12,$tmp1,"",0));
387 &add($D,$B);
388 &mov($B, &DWP( 4,$tmp1,"",0));
389 &add($B,$T);
390 &mov($T, $A);
391 &mov($A, &DWP( 0,$tmp1,"",0));
392 &mov(&DWP(12,$tmp1,"",0),$D);
393
394 &add($A,$E);
395 &mov($E, &DWP(16,$tmp1,"",0));
396 &add($E,$C);
397 &mov($C, &DWP( 8,$tmp1,"",0));
398 &add($C,$T);
399
400 &mov(&DWP( 0,$tmp1,"",0),$A);
401 &mov("esi",&wparam(1));
402 &mov(&DWP( 8,$tmp1,"",0),$C);
403 &add("esi",64);
404 &mov("eax",&swtmp(17));
405 &mov(&DWP(16,$tmp1,"",0),$E);
406 &cmp("esi","eax");
407 &mov(&DWP( 4,$tmp1,"",0),$B);
408 &jb(&label("start"));
409
410 &stack_pop(18+9);
411 &pop("edi");
412 &pop("ebx");
413 &pop("ebp");
414 &pop("esi");
415 &ret();
416
417 # keep a note of shortcut label so it can be used outside
418 # block.
419 my $sclabel = &label("shortcut");
420
421 &function_end_B($name);
422 # Putting this here avoids problems with MASM in debugging mode
423 &sha1_block_host("sha1_block_asm_host_order", $sclabel);
424 }
218 425
219&asm_finish();
diff --git a/src/lib/libcrypto/sha/asm/sha512-sse2.pl b/src/lib/libcrypto/sha/asm/sha512-sse2.pl
new file mode 100644
index 0000000000..10902bf673
--- /dev/null
+++ b/src/lib/libcrypto/sha/asm/sha512-sse2.pl
@@ -0,0 +1,404 @@
1#!/usr/bin/env perl
2#
3# ====================================================================
4# Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL
5# project. Rights for redistribution and usage in source and binary
6# forms are granted according to the OpenSSL license.
7# ====================================================================
8#
9# SHA512_Transform_SSE2.
10#
11# As the name suggests, this is an IA-32 SSE2 implementation of
12# SHA512_Transform. Motivating factor for the undertaken effort was that
13# SHA512 was observed to *consistently* perform *significantly* poorer
14# than SHA256 [2x and slower is common] on 32-bit platforms. On 64-bit
15# platforms on the other hand SHA512 tend to outperform SHA256 [~50%
16# seem to be common improvement factor]. All this is perfectly natural,
17# as SHA512 is a 64-bit algorithm. But isn't IA-32 SSE2 essentially
18# a 64-bit instruction set? Is it rich enough to implement SHA512?
19# If answer was "no," then you wouldn't have been reading this...
20#
21# Throughput performance in MBps (larger is better):
22#
23# 2.4GHz P4 1.4GHz AMD32 1.4GHz AMD64(*)
24# SHA256/gcc(*) 54 43 59
25# SHA512/gcc 17 23 92
26# SHA512/sse2 61(**) 57(**)
27# SHA512/icc 26 28
28# SHA256/icc(*) 65 54
29#
30# (*) AMD64 and SHA256 numbers are presented mostly for amusement or
31# reference purposes.
32# (**) I.e. it gives ~2-3x speed-up if compared with compiler generated
33# code. One can argue that hand-coded *non*-SSE2 implementation
34# would perform better than compiler generated one as well, and
35# that comparison is therefore not exactly fair. Well, as SHA512
36# puts enormous pressure on IA-32 GP register bank, I reckon that
37# hand-coded version wouldn't perform significantly better than
38# one compiled with icc, ~20% perhaps... So that this code would
39# still outperform it with distinguishing marginal. But feel free
40# to prove me wrong:-)
41# <appro@fy.chalmers.se>
42push(@INC,"perlasm","../../perlasm");
43require "x86asm.pl";
44
45&asm_init($ARGV[0],"sha512-sse2.pl",$ARGV[$#ARGV] eq "386");
46
47$K512="esi"; # K512[80] table, found at the end...
48#$W512="esp"; # $W512 is not just W512[16]: it comprises *two* copies
49 # of W512[16] and a copy of A-H variables...
50$W512_SZ=8*(16+16+8); # see above...
51#$Kidx="ebx"; # index in K512 table, advances from 0 to 80...
52$Widx="edx"; # index in W512, wraps around at 16...
53$data="edi"; # 16 qwords of input data...
54$A="mm0"; # B-D and
55$E="mm1"; # F-H are allocated dynamically...
56$Aoff=256+0; # A-H offsets relative to $W512...
57$Boff=256+8;
58$Coff=256+16;
59$Doff=256+24;
60$Eoff=256+32;
61$Foff=256+40;
62$Goff=256+48;
63$Hoff=256+56;
64
65sub SHA2_ROUND()
66{ local ($kidx,$widx)=@_;
67
68 # One can argue that one could reorder instructions for better
69 # performance. Well, I tried and it doesn't seem to make any
70 # noticeable difference. Modern out-of-order execution cores
71 # reorder instructions to their liking in either case and they
72 # apparently do decent job. So we can keep the code more
73 # readable/regular/comprehensible:-)
74
75 # I adhere to 64-bit %mmX registers in order to avoid/not care
76 # about #GP exceptions on misaligned 128-bit access, most
77 # notably in paddq with memory operand. Not to mention that
78 # SSE2 intructions operating on %mmX can be scheduled every
79 # cycle [and not every second one if operating on %xmmN].
80
81 &movq ("mm4",&QWP($Foff,$W512)); # load f
82 &movq ("mm5",&QWP($Goff,$W512)); # load g
83 &movq ("mm6",&QWP($Hoff,$W512)); # load h
84
85 &movq ("mm2",$E); # %mm2 is sliding right
86 &movq ("mm3",$E); # %mm3 is sliding left
87 &psrlq ("mm2",14);
88 &psllq ("mm3",23);
89 &movq ("mm7","mm2"); # %mm7 is T1
90 &pxor ("mm7","mm3");
91 &psrlq ("mm2",4);
92 &psllq ("mm3",23);
93 &pxor ("mm7","mm2");
94 &pxor ("mm7","mm3");
95 &psrlq ("mm2",23);
96 &psllq ("mm3",4);
97 &pxor ("mm7","mm2");
98 &pxor ("mm7","mm3"); # T1=Sigma1_512(e)
99
100 &movq (&QWP($Foff,$W512),$E); # f = e
101 &movq (&QWP($Goff,$W512),"mm4"); # g = f
102 &movq (&QWP($Hoff,$W512),"mm5"); # h = g
103
104 &pxor ("mm4","mm5"); # f^=g
105 &pand ("mm4",$E); # f&=e
106 &pxor ("mm4","mm5"); # f^=g
107 &paddq ("mm7","mm4"); # T1+=Ch(e,f,g)
108
109 &movq ("mm2",&QWP($Boff,$W512)); # load b
110 &movq ("mm3",&QWP($Coff,$W512)); # load c
111 &movq ($E,&QWP($Doff,$W512)); # e = d
112
113 &paddq ("mm7","mm6"); # T1+=h
114 &paddq ("mm7",&QWP(0,$K512,$kidx,8)); # T1+=K512[i]
115 &paddq ("mm7",&QWP(0,$W512,$widx,8)); # T1+=W512[i]
116 &paddq ($E,"mm7"); # e += T1
117
118 &movq ("mm4",$A); # %mm4 is sliding right
119 &movq ("mm5",$A); # %mm5 is sliding left
120 &psrlq ("mm4",28);
121 &psllq ("mm5",25);
122 &movq ("mm6","mm4"); # %mm6 is T2
123 &pxor ("mm6","mm5");
124 &psrlq ("mm4",6);
125 &psllq ("mm5",5);
126 &pxor ("mm6","mm4");
127 &pxor ("mm6","mm5");
128 &psrlq ("mm4",5);
129 &psllq ("mm5",6);
130 &pxor ("mm6","mm4");
131 &pxor ("mm6","mm5"); # T2=Sigma0_512(a)
132
133 &movq (&QWP($Boff,$W512),$A); # b = a
134 &movq (&QWP($Coff,$W512),"mm2"); # c = b
135 &movq (&QWP($Doff,$W512),"mm3"); # d = c
136
137 &movq ("mm4",$A); # %mm4=a
138 &por ($A,"mm3"); # a=a|c
139 &pand ("mm4","mm3"); # %mm4=a&c
140 &pand ($A,"mm2"); # a=(a|c)&b
141 &por ("mm4",$A); # %mm4=(a&c)|((a|c)&b)
142 &paddq ("mm6","mm4"); # T2+=Maj(a,b,c)
143
144 &movq ($A,"mm7"); # a=T1
145 &paddq ($A,"mm6"); # a+=T2
146}
147
148$func="sha512_block_sse2";
149
150&function_begin_B($func);
151 if (0) {# Caller is expected to check if it's appropriate to
152 # call this routine. Below 3 lines are retained for
153 # debugging purposes...
154 &picmeup("eax","OPENSSL_ia32cap");
155 &bt (&DWP(0,"eax"),26);
156 &jnc ("SHA512_Transform");
157 }
158
159 &push ("ebp");
160 &mov ("ebp","esp");
161 &push ("ebx");
162 &push ("esi");
163 &push ("edi");
164
165 &mov ($Widx,&DWP(8,"ebp")); # A-H state, 1st arg
166 &mov ($data,&DWP(12,"ebp")); # input data, 2nd arg
167 &call (&label("pic_point")); # make it PIC!
168&set_label("pic_point");
169 &blindpop($K512);
170 &lea ($K512,&DWP(&label("K512")."-".&label("pic_point"),$K512));
171
172 $W512 = "esp"; # start using %esp as W512
173 &sub ($W512,$W512_SZ);
174 &and ($W512,-16); # ensure 128-bit alignment
175
176 # make private copy of A-H
177 # v assume the worst and stick to unaligned load
178 &movdqu ("xmm0",&QWP(0,$Widx));
179 &movdqu ("xmm1",&QWP(16,$Widx));
180 &movdqu ("xmm2",&QWP(32,$Widx));
181 &movdqu ("xmm3",&QWP(48,$Widx));
182
183&align(8);
184&set_label("_chunk_loop");
185
186 &movdqa (&QWP($Aoff,$W512),"xmm0"); # a,b
187 &movdqa (&QWP($Coff,$W512),"xmm1"); # c,d
188 &movdqa (&QWP($Eoff,$W512),"xmm2"); # e,f
189 &movdqa (&QWP($Goff,$W512),"xmm3"); # g,h
190
191 &xor ($Widx,$Widx);
192
193 &movdq2q($A,"xmm0"); # load a
194 &movdq2q($E,"xmm2"); # load e
195
196 # Why aren't loops unrolled? It makes sense to unroll if
197 # execution time for loop body is comparable with branch
198 # penalties and/or if whole data-set resides in register bank.
199 # Neither is case here... Well, it would be possible to
200 # eliminate few store operations, but it would hardly affect
201 # so to say stop-watch performance, as there is a lot of
202 # available memory slots to fill. It will only relieve some
203 # pressure off memory bus...
204
205 # flip input stream byte order...
206 &mov ("eax",&DWP(0,$data,$Widx,8));
207 &mov ("ebx",&DWP(4,$data,$Widx,8));
208 &bswap ("eax");
209 &bswap ("ebx");
210 &mov (&DWP(0,$W512,$Widx,8),"ebx"); # W512[i]
211 &mov (&DWP(4,$W512,$Widx,8),"eax");
212 &mov (&DWP(128+0,$W512,$Widx,8),"ebx"); # copy of W512[i]
213 &mov (&DWP(128+4,$W512,$Widx,8),"eax");
214
215&align(8);
216&set_label("_1st_loop"); # 0-15
217 # flip input stream byte order...
218 &mov ("eax",&DWP(0+8,$data,$Widx,8));
219 &mov ("ebx",&DWP(4+8,$data,$Widx,8));
220 &bswap ("eax");
221 &bswap ("ebx");
222 &mov (&DWP(0+8,$W512,$Widx,8),"ebx"); # W512[i]
223 &mov (&DWP(4+8,$W512,$Widx,8),"eax");
224 &mov (&DWP(128+0+8,$W512,$Widx,8),"ebx"); # copy of W512[i]
225 &mov (&DWP(128+4+8,$W512,$Widx,8),"eax");
226&set_label("_1st_looplet");
227 &SHA2_ROUND($Widx,$Widx); &inc($Widx);
228
229&cmp ($Widx,15)
230&jl (&label("_1st_loop"));
231&je (&label("_1st_looplet")); # playing similar trick on 2nd loop
232 # does not improve performance...
233
234 $Kidx = "ebx"; # start using %ebx as Kidx
235 &mov ($Kidx,$Widx);
236
237&align(8);
238&set_label("_2nd_loop"); # 16-79
239 &and($Widx,0xf);
240
241 # 128-bit fragment! I update W512[i] and W512[i+1] in
242 # parallel:-) Note that I refer to W512[(i&0xf)+N] and not to
243 # W512[(i+N)&0xf]! This is exactly what I maintain the second
244 # copy of W512[16] for...
245 &movdqu ("xmm0",&QWP(8*1,$W512,$Widx,8)); # s0=W512[i+1]
246 &movdqa ("xmm2","xmm0"); # %xmm2 is sliding right
247 &movdqa ("xmm3","xmm0"); # %xmm3 is sliding left
248 &psrlq ("xmm2",1);
249 &psllq ("xmm3",56);
250 &movdqa ("xmm0","xmm2");
251 &pxor ("xmm0","xmm3");
252 &psrlq ("xmm2",6);
253 &psllq ("xmm3",7);
254 &pxor ("xmm0","xmm2");
255 &pxor ("xmm0","xmm3");
256 &psrlq ("xmm2",1);
257 &pxor ("xmm0","xmm2"); # s0 = sigma0_512(s0);
258
259 &movdqa ("xmm1",&QWP(8*14,$W512,$Widx,8)); # s1=W512[i+14]
260 &movdqa ("xmm4","xmm1"); # %xmm4 is sliding right
261 &movdqa ("xmm5","xmm1"); # %xmm5 is sliding left
262 &psrlq ("xmm4",6);
263 &psllq ("xmm5",3);
264 &movdqa ("xmm1","xmm4");
265 &pxor ("xmm1","xmm5");
266 &psrlq ("xmm4",13);
267 &psllq ("xmm5",42);
268 &pxor ("xmm1","xmm4");
269 &pxor ("xmm1","xmm5");
270 &psrlq ("xmm4",42);
271 &pxor ("xmm1","xmm4"); # s1 = sigma1_512(s1);
272
273 # + have to explictly load W512[i+9] as it's not 128-bit
274 # v aligned and paddq would throw an exception...
275 &movdqu ("xmm6",&QWP(8*9,$W512,$Widx,8));
276 &paddq ("xmm0","xmm1"); # s0 += s1
277 &paddq ("xmm0","xmm6"); # s0 += W512[i+9]
278 &paddq ("xmm0",&QWP(0,$W512,$Widx,8)); # s0 += W512[i]
279
280 &movdqa (&QWP(0,$W512,$Widx,8),"xmm0"); # W512[i] = s0
281 &movdqa (&QWP(16*8,$W512,$Widx,8),"xmm0"); # copy of W512[i]
282
283 # as the above fragment was 128-bit, we "owe" 2 rounds...
284 &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx);
285 &SHA2_ROUND($Kidx,$Widx); &inc($Kidx); &inc($Widx);
286
287&cmp ($Kidx,80);
288&jl (&label("_2nd_loop"));
289
290 # update A-H state
291 &mov ($Widx,&DWP(8,"ebp")); # A-H state, 1st arg
292 &movq (&QWP($Aoff,$W512),$A); # write out a
293 &movq (&QWP($Eoff,$W512),$E); # write out e
294 &movdqu ("xmm0",&QWP(0,$Widx));
295 &movdqu ("xmm1",&QWP(16,$Widx));
296 &movdqu ("xmm2",&QWP(32,$Widx));
297 &movdqu ("xmm3",&QWP(48,$Widx));
298 &paddq ("xmm0",&QWP($Aoff,$W512)); # 128-bit additions...
299 &paddq ("xmm1",&QWP($Coff,$W512));
300 &paddq ("xmm2",&QWP($Eoff,$W512));
301 &paddq ("xmm3",&QWP($Goff,$W512));
302 &movdqu (&QWP(0,$Widx),"xmm0");
303 &movdqu (&QWP(16,$Widx),"xmm1");
304 &movdqu (&QWP(32,$Widx),"xmm2");
305 &movdqu (&QWP(48,$Widx),"xmm3");
306
307&add ($data,16*8); # advance input data pointer
308&dec (&DWP(16,"ebp")); # decrement 3rd arg
309&jnz (&label("_chunk_loop"));
310
311 # epilogue
312 &emms (); # required for at least ELF and Win32 ABIs
313 &mov ("edi",&DWP(-12,"ebp"));
314 &mov ("esi",&DWP(-8,"ebp"));
315 &mov ("ebx",&DWP(-4,"ebp"));
316 &leave ();
317&ret ();
318
319&align(64);
320&set_label("K512"); # Yes! I keep it in the code segment!
321 &data_word(0xd728ae22,0x428a2f98); # u64
322 &data_word(0x23ef65cd,0x71374491); # u64
323 &data_word(0xec4d3b2f,0xb5c0fbcf); # u64
324 &data_word(0x8189dbbc,0xe9b5dba5); # u64
325 &data_word(0xf348b538,0x3956c25b); # u64
326 &data_word(0xb605d019,0x59f111f1); # u64
327 &data_word(0xaf194f9b,0x923f82a4); # u64
328 &data_word(0xda6d8118,0xab1c5ed5); # u64
329 &data_word(0xa3030242,0xd807aa98); # u64
330 &data_word(0x45706fbe,0x12835b01); # u64
331 &data_word(0x4ee4b28c,0x243185be); # u64
332 &data_word(0xd5ffb4e2,0x550c7dc3); # u64
333 &data_word(0xf27b896f,0x72be5d74); # u64
334 &data_word(0x3b1696b1,0x80deb1fe); # u64
335 &data_word(0x25c71235,0x9bdc06a7); # u64
336 &data_word(0xcf692694,0xc19bf174); # u64
337 &data_word(0x9ef14ad2,0xe49b69c1); # u64
338 &data_word(0x384f25e3,0xefbe4786); # u64
339 &data_word(0x8b8cd5b5,0x0fc19dc6); # u64
340 &data_word(0x77ac9c65,0x240ca1cc); # u64
341 &data_word(0x592b0275,0x2de92c6f); # u64
342 &data_word(0x6ea6e483,0x4a7484aa); # u64
343 &data_word(0xbd41fbd4,0x5cb0a9dc); # u64
344 &data_word(0x831153b5,0x76f988da); # u64
345 &data_word(0xee66dfab,0x983e5152); # u64
346 &data_word(0x2db43210,0xa831c66d); # u64
347 &data_word(0x98fb213f,0xb00327c8); # u64
348 &data_word(0xbeef0ee4,0xbf597fc7); # u64
349 &data_word(0x3da88fc2,0xc6e00bf3); # u64
350 &data_word(0x930aa725,0xd5a79147); # u64
351 &data_word(0xe003826f,0x06ca6351); # u64
352 &data_word(0x0a0e6e70,0x14292967); # u64
353 &data_word(0x46d22ffc,0x27b70a85); # u64
354 &data_word(0x5c26c926,0x2e1b2138); # u64
355 &data_word(0x5ac42aed,0x4d2c6dfc); # u64
356 &data_word(0x9d95b3df,0x53380d13); # u64
357 &data_word(0x8baf63de,0x650a7354); # u64
358 &data_word(0x3c77b2a8,0x766a0abb); # u64
359 &data_word(0x47edaee6,0x81c2c92e); # u64
360 &data_word(0x1482353b,0x92722c85); # u64
361 &data_word(0x4cf10364,0xa2bfe8a1); # u64
362 &data_word(0xbc423001,0xa81a664b); # u64
363 &data_word(0xd0f89791,0xc24b8b70); # u64
364 &data_word(0x0654be30,0xc76c51a3); # u64
365 &data_word(0xd6ef5218,0xd192e819); # u64
366 &data_word(0x5565a910,0xd6990624); # u64
367 &data_word(0x5771202a,0xf40e3585); # u64
368 &data_word(0x32bbd1b8,0x106aa070); # u64
369 &data_word(0xb8d2d0c8,0x19a4c116); # u64
370 &data_word(0x5141ab53,0x1e376c08); # u64
371 &data_word(0xdf8eeb99,0x2748774c); # u64
372 &data_word(0xe19b48a8,0x34b0bcb5); # u64
373 &data_word(0xc5c95a63,0x391c0cb3); # u64
374 &data_word(0xe3418acb,0x4ed8aa4a); # u64
375 &data_word(0x7763e373,0x5b9cca4f); # u64
376 &data_word(0xd6b2b8a3,0x682e6ff3); # u64
377 &data_word(0x5defb2fc,0x748f82ee); # u64
378 &data_word(0x43172f60,0x78a5636f); # u64
379 &data_word(0xa1f0ab72,0x84c87814); # u64
380 &data_word(0x1a6439ec,0x8cc70208); # u64
381 &data_word(0x23631e28,0x90befffa); # u64
382 &data_word(0xde82bde9,0xa4506ceb); # u64
383 &data_word(0xb2c67915,0xbef9a3f7); # u64
384 &data_word(0xe372532b,0xc67178f2); # u64
385 &data_word(0xea26619c,0xca273ece); # u64
386 &data_word(0x21c0c207,0xd186b8c7); # u64
387 &data_word(0xcde0eb1e,0xeada7dd6); # u64
388 &data_word(0xee6ed178,0xf57d4f7f); # u64
389 &data_word(0x72176fba,0x06f067aa); # u64
390 &data_word(0xa2c898a6,0x0a637dc5); # u64
391 &data_word(0xbef90dae,0x113f9804); # u64
392 &data_word(0x131c471b,0x1b710b35); # u64
393 &data_word(0x23047d84,0x28db77f5); # u64
394 &data_word(0x40c72493,0x32caab7b); # u64
395 &data_word(0x15c9bebc,0x3c9ebe0a); # u64
396 &data_word(0x9c100d4c,0x431d67c4); # u64
397 &data_word(0xcb3e42b6,0x4cc5d4be); # u64
398 &data_word(0xfc657e2a,0x597f299c); # u64
399 &data_word(0x3ad6faec,0x5fcb6fab); # u64
400 &data_word(0x4a475817,0x6c44198c); # u64
401
402&function_end_B($func);
403
404&asm_finish();
diff --git a/src/lib/libcrypto/sha/sha.c b/src/lib/libcrypto/sha/sha.c
new file mode 100644
index 0000000000..42126551d1
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha.c
@@ -0,0 +1,124 @@
1/* crypto/sha/sha.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/sha.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67int read(int, void *, unsigned int);
68int main(int argc, char **argv)
69 {
70 int i,err=0;
71 FILE *IN;
72
73 if (argc == 1)
74 {
75 do_fp(stdin);
76 }
77 else
78 {
79 for (i=1; i<argc; i++)
80 {
81 IN=fopen(argv[i],"r");
82 if (IN == NULL)
83 {
84 perror(argv[i]);
85 err++;
86 continue;
87 }
88 printf("SHA(%s)= ",argv[i]);
89 do_fp(IN);
90 fclose(IN);
91 }
92 }
93 exit(err);
94 }
95
96void do_fp(FILE *f)
97 {
98 SHA_CTX c;
99 unsigned char md[SHA_DIGEST_LENGTH];
100 int fd;
101 int i;
102 unsigned char buf[BUFSIZE];
103
104 fd=fileno(f);
105 SHA_Init(&c);
106 for (;;)
107 {
108 i=read(fd,buf,BUFSIZE);
109 if (i <= 0) break;
110 SHA_Update(&c,buf,(unsigned long)i);
111 }
112 SHA_Final(&(md[0]),&c);
113 pt(md);
114 }
115
116void pt(unsigned char *md)
117 {
118 int i;
119
120 for (i=0; i<SHA_DIGEST_LENGTH; i++)
121 printf("%02x",md[i]);
122 printf("\n");
123 }
124
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h
index eed44d7f94..79c07b0fd1 100644
--- a/src/lib/libcrypto/sha/sha.h
+++ b/src/lib/libcrypto/sha/sha.h
@@ -60,7 +60,6 @@
60#define HEADER_SHA_H 60#define HEADER_SHA_H
61 61
62#include <openssl/e_os2.h> 62#include <openssl/e_os2.h>
63#include <stddef.h>
64 63
65#ifdef __cplusplus 64#ifdef __cplusplus
66extern "C" { 65extern "C" {
@@ -71,7 +70,7 @@ extern "C" {
71#endif 70#endif
72 71
73#if defined(OPENSSL_FIPS) 72#if defined(OPENSSL_FIPS)
74#define FIPS_SHA_SIZE_T size_t 73#define FIPS_SHA_SIZE_T unsigned long
75#endif 74#endif
76 75
77/* 76/*
@@ -102,97 +101,26 @@ typedef struct SHAstate_st
102 SHA_LONG h0,h1,h2,h3,h4; 101 SHA_LONG h0,h1,h2,h3,h4;
103 SHA_LONG Nl,Nh; 102 SHA_LONG Nl,Nh;
104 SHA_LONG data[SHA_LBLOCK]; 103 SHA_LONG data[SHA_LBLOCK];
105 unsigned int num; 104 int num;
106 } SHA_CTX; 105 } SHA_CTX;
107 106
108#ifndef OPENSSL_NO_SHA0 107#ifndef OPENSSL_NO_SHA0
108#ifdef OPENSSL_FIPS
109int private_SHA_Init(SHA_CTX *c);
110#endif
109int SHA_Init(SHA_CTX *c); 111int SHA_Init(SHA_CTX *c);
110int SHA_Update(SHA_CTX *c, const void *data, size_t len); 112int SHA_Update(SHA_CTX *c, const void *data, unsigned long len);
111int SHA_Final(unsigned char *md, SHA_CTX *c); 113int SHA_Final(unsigned char *md, SHA_CTX *c);
112unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); 114unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md);
113void SHA_Transform(SHA_CTX *c, const unsigned char *data); 115void SHA_Transform(SHA_CTX *c, const unsigned char *data);
114#endif 116#endif
115#ifndef OPENSSL_NO_SHA1 117#ifndef OPENSSL_NO_SHA1
116int SHA1_Init(SHA_CTX *c); 118int SHA1_Init(SHA_CTX *c);
117int SHA1_Update(SHA_CTX *c, const void *data, size_t len); 119int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len);
118int SHA1_Final(unsigned char *md, SHA_CTX *c); 120int SHA1_Final(unsigned char *md, SHA_CTX *c);
119unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md); 121unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md);
120void SHA1_Transform(SHA_CTX *c, const unsigned char *data); 122void SHA1_Transform(SHA_CTX *c, const unsigned char *data);
121#endif 123#endif
122
123#define SHA256_CBLOCK (SHA_LBLOCK*4) /* SHA-256 treats input data as a
124 * contiguous array of 32 bit
125 * wide big-endian values. */
126#define SHA224_DIGEST_LENGTH 28
127#define SHA256_DIGEST_LENGTH 32
128
129typedef struct SHA256state_st
130 {
131 SHA_LONG h[8];
132 SHA_LONG Nl,Nh;
133 SHA_LONG data[SHA_LBLOCK];
134 unsigned int num,md_len;
135 } SHA256_CTX;
136
137#ifndef OPENSSL_NO_SHA256
138int SHA224_Init(SHA256_CTX *c);
139int SHA224_Update(SHA256_CTX *c, const void *data, size_t len);
140int SHA224_Final(unsigned char *md, SHA256_CTX *c);
141unsigned char *SHA224(const unsigned char *d, size_t n,unsigned char *md);
142int SHA256_Init(SHA256_CTX *c);
143int SHA256_Update(SHA256_CTX *c, const void *data, size_t len);
144int SHA256_Final(unsigned char *md, SHA256_CTX *c);
145unsigned char *SHA256(const unsigned char *d, size_t n,unsigned char *md);
146void SHA256_Transform(SHA256_CTX *c, const unsigned char *data);
147#endif
148
149#define SHA384_DIGEST_LENGTH 48
150#define SHA512_DIGEST_LENGTH 64
151
152#ifndef OPENSSL_NO_SHA512
153/*
154 * Unlike 32-bit digest algorithms, SHA-512 *relies* on SHA_LONG64
155 * being exactly 64-bit wide. See Implementation Notes in sha512.c
156 * for further details.
157 */
158#define SHA512_CBLOCK (SHA_LBLOCK*8) /* SHA-512 treats input data as a
159 * contiguous array of 64 bit
160 * wide big-endian values. */
161#if (defined(_WIN32) || defined(_WIN64)) && !defined(__MINGW32__)
162#define SHA_LONG64 unsigned __int64
163#define U64(C) C##UI64
164#elif defined(__arch64__)
165#define SHA_LONG64 unsigned long
166#define U64(C) C##UL
167#else
168#define SHA_LONG64 unsigned long long
169#define U64(C) C##ULL
170#endif
171
172typedef struct SHA512state_st
173 {
174 SHA_LONG64 h[8];
175 SHA_LONG64 Nl,Nh;
176 union {
177 SHA_LONG64 d[SHA_LBLOCK];
178 unsigned char p[SHA512_CBLOCK];
179 } u;
180 unsigned int num,md_len;
181 } SHA512_CTX;
182#endif
183
184#ifndef OPENSSL_NO_SHA512
185int SHA384_Init(SHA512_CTX *c);
186int SHA384_Update(SHA512_CTX *c, const void *data, size_t len);
187int SHA384_Final(unsigned char *md, SHA512_CTX *c);
188unsigned char *SHA384(const unsigned char *d, size_t n,unsigned char *md);
189int SHA512_Init(SHA512_CTX *c);
190int SHA512_Update(SHA512_CTX *c, const void *data, size_t len);
191int SHA512_Final(unsigned char *md, SHA512_CTX *c);
192unsigned char *SHA512(const unsigned char *d, size_t n,unsigned char *md);
193void SHA512_Transform(SHA512_CTX *c, const unsigned char *data);
194#endif
195
196#ifdef __cplusplus 124#ifdef __cplusplus
197} 125}
198#endif 126#endif
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c
new file mode 100644
index 0000000000..d350c88ee4
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1.c
@@ -0,0 +1,127 @@
1/* crypto/sha/sha1.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <openssl/sha.h>
62
63#define BUFSIZE 1024*16
64
65void do_fp(FILE *f);
66void pt(unsigned char *md);
67#ifndef _OSD_POSIX
68int read(int, void *, unsigned int);
69#endif
70
71int main(int argc, char **argv)
72 {
73 int i,err=0;
74 FILE *IN;
75
76 if (argc == 1)
77 {
78 do_fp(stdin);
79 }
80 else
81 {
82 for (i=1; i<argc; i++)
83 {
84 IN=fopen(argv[i],"r");
85 if (IN == NULL)
86 {
87 perror(argv[i]);
88 err++;
89 continue;
90 }
91 printf("SHA1(%s)= ",argv[i]);
92 do_fp(IN);
93 fclose(IN);
94 }
95 }
96 exit(err);
97 }
98
99void do_fp(FILE *f)
100 {
101 SHA_CTX c;
102 unsigned char md[SHA_DIGEST_LENGTH];
103 int fd;
104 int i;
105 unsigned char buf[BUFSIZE];
106
107 fd=fileno(f);
108 SHA1_Init(&c);
109 for (;;)
110 {
111 i=read(fd,buf,BUFSIZE);
112 if (i <= 0) break;
113 SHA1_Update(&c,buf,(unsigned long)i);
114 }
115 SHA1_Final(&(md[0]),&c);
116 pt(md);
117 }
118
119void pt(unsigned char *md)
120 {
121 int i;
122
123 for (i=0; i<SHA_DIGEST_LENGTH; i++)
124 printf("%02x",md[i]);
125 printf("\n");
126 }
127
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c
index 7c65b60276..f4694b701b 100644
--- a/src/lib/libcrypto/sha/sha1_one.c
+++ b/src/lib/libcrypto/sha/sha1_one.c
@@ -61,8 +61,8 @@
61#include <openssl/sha.h> 61#include <openssl/sha.h>
62#include <openssl/crypto.h> 62#include <openssl/crypto.h>
63 63
64#ifndef OPENSSL_NO_SHA1 64#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_FIPS)
65unsigned char *SHA1(const unsigned char *d, size_t n, unsigned char *md) 65unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md)
66 { 66 {
67 SHA_CTX c; 67 SHA_CTX c;
68 static unsigned char m[SHA_DIGEST_LENGTH]; 68 static unsigned char m[SHA_DIGEST_LENGTH];
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c
index 50d1925cde..1e2009b760 100644
--- a/src/lib/libcrypto/sha/sha1dgst.c
+++ b/src/lib/libcrypto/sha/sha1dgst.c
@@ -56,19 +56,26 @@
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58 58
59#include <openssl/opensslconf.h>
60#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA) 59#if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA)
61 60
62#undef SHA_0 61#undef SHA_0
63#define SHA_1 62#define SHA_1
64 63
65#include <openssl/opensslv.h> 64#include <openssl/opensslv.h>
65#include <openssl/opensslconf.h>
66 66
67const char SHA1_version[]="SHA1" OPENSSL_VERSION_PTEXT; 67#ifndef OPENSSL_FIPS
68const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT;
68 69
69/* The implementation is in ../md32_common.h */ 70/* The implementation is in ../md32_common.h */
70 71
71#include "sha_locl.h" 72#include "sha_locl.h"
72 73
74#else /* ndef OPENSSL_FIPS */
75
76static void *dummy=&dummy;
77
78#endif /* ndef OPENSSL_FIPS */
79
73#endif 80#endif
74 81
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp
new file mode 100644
index 0000000000..af23d1e0f2
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1s.cpp
@@ -0,0 +1,82 @@
1//
2// gettsc.inl
3//
4// gives access to the Pentium's (secret) cycle counter
5//
6// This software was written by Leonard Janke (janke@unixg.ubc.ca)
7// in 1996-7 and is entered, by him, into the public domain.
8
9#if defined(__WATCOMC__)
10void GetTSC(unsigned long&);
11#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
12#elif defined(__GNUC__)
13inline
14void GetTSC(unsigned long& tsc)
15{
16 asm volatile(".byte 15, 49\n\t"
17 : "=eax" (tsc)
18 :
19 : "%edx", "%eax");
20}
21#elif defined(_MSC_VER)
22inline
23void GetTSC(unsigned long& tsc)
24{
25 unsigned long a;
26 __asm _emit 0fh
27 __asm _emit 31h
28 __asm mov a, eax;
29 tsc=a;
30}
31#endif
32
33#include <stdio.h>
34#include <stdlib.h>
35#include <openssl/sha.h>
36
37#define sha1_block_x86 sha1_block_asm_data_order
38extern "C" {
39void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num);
40}
41
42void main(int argc,char *argv[])
43 {
44 unsigned char buffer[64*256];
45 SHA_CTX ctx;
46 unsigned long s1,s2,e1,e2;
47 unsigned char k[16];
48 unsigned long data[2];
49 unsigned char iv[8];
50 int i,num=0,numm;
51 int j=0;
52
53 if (argc >= 2)
54 num=atoi(argv[1]);
55
56 if (num == 0) num=16;
57 if (num > 250) num=16;
58 numm=num+2;
59#if 0
60 num*=64;
61 numm*=64;
62#endif
63
64 for (j=0; j<6; j++)
65 {
66 for (i=0; i<10; i++) /**/
67 {
68 sha1_block_x86(&ctx,buffer,numm);
69 GetTSC(s1);
70 sha1_block_x86(&ctx,buffer,numm);
71 GetTSC(e1);
72 GetTSC(s2);
73 sha1_block_x86(&ctx,buffer,num);
74 GetTSC(e2);
75 sha1_block_x86(&ctx,buffer,num);
76 }
77
78 printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64,
79 e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2);
80 }
81 }
82
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c
new file mode 100644
index 0000000000..4f2e4ada2d
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha1test.c
@@ -0,0 +1,174 @@
1/* crypto/sha/sha1test.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#ifdef OPENSSL_NO_SHA
66int main(int argc, char *argv[])
67{
68 printf("No SHA support\n");
69 return(0);
70}
71#else
72#include <openssl/evp.h>
73#include <openssl/sha.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
78
79#undef SHA_0 /* FIPS 180 */
80#define SHA_1 /* FIPS 180-1 */
81
82static char *test[]={
83 "abc",
84 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
85 NULL,
86 };
87
88#ifdef SHA_0
89static char *ret[]={
90 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
91 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
92 };
93static char *bigret=
94 "3232affa48628a26653b5aaa44541fd90d690603";
95#endif
96#ifdef SHA_1
97static char *ret[]={
98 "a9993e364706816aba3e25717850c26c9cd0d89d",
99 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
100 };
101static char *bigret=
102 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
103#endif
104
105static char *pt(unsigned char *md);
106int main(int argc, char *argv[])
107 {
108 int i,err=0;
109 unsigned char **P,**R;
110 static unsigned char buf[1000];
111 char *p,*r;
112 EVP_MD_CTX c;
113 unsigned char md[SHA_DIGEST_LENGTH];
114
115#ifdef CHARSET_EBCDIC
116 ebcdic2ascii(test[0], test[0], strlen(test[0]));
117 ebcdic2ascii(test[1], test[1], strlen(test[1]));
118#endif
119
120 EVP_MD_CTX_init(&c);
121 P=(unsigned char **)test;
122 R=(unsigned char **)ret;
123 i=1;
124 while (*P != NULL)
125 {
126 EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha1(), NULL);
127 p=pt(md);
128 if (strcmp(p,(char *)*R) != 0)
129 {
130 printf("error calculating SHA1 on '%s'\n",*P);
131 printf("got %s instead of %s\n",p,*R);
132 err++;
133 }
134 else
135 printf("test %d ok\n",i);
136 i++;
137 R++;
138 P++;
139 }
140
141 memset(buf,'a',1000);
142#ifdef CHARSET_EBCDIC
143 ebcdic2ascii(buf, buf, 1000);
144#endif /*CHARSET_EBCDIC*/
145 EVP_DigestInit_ex(&c,EVP_sha1(), NULL);
146 for (i=0; i<1000; i++)
147 EVP_DigestUpdate(&c,buf,1000);
148 EVP_DigestFinal_ex(&c,md,NULL);
149 p=pt(md);
150
151 r=bigret;
152 if (strcmp(p,r) != 0)
153 {
154 printf("error calculating SHA1 on 'a' * 1000\n");
155 printf("got %s instead of %s\n",p,r);
156 err++;
157 }
158 else
159 printf("test 3 ok\n");
160 EXIT(err);
161 EVP_MD_CTX_cleanup(&c);
162 return(0);
163 }
164
165static char *pt(unsigned char *md)
166 {
167 int i;
168 static char buf[80];
169
170 for (i=0; i<SHA_DIGEST_LENGTH; i++)
171 sprintf(&(buf[i*2]),"%02x",md[i]);
172 return(buf);
173 }
174#endif
diff --git a/src/lib/libcrypto/sha/sha256t.c b/src/lib/libcrypto/sha/sha256t.c
new file mode 100644
index 0000000000..6b4a3bd001
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha256t.c
@@ -0,0 +1,147 @@
1/* crypto/sha/sha256t.c */
2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
4 * ====================================================================
5 */
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9
10#include <openssl/sha.h>
11#include <openssl/evp.h>
12
13#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256)
14int main(int argc, char *argv[])
15{
16 printf("No SHA256 support\n");
17 return(0);
18}
19#else
20
21unsigned char app_b1[SHA256_DIGEST_LENGTH] = {
22 0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea,
23 0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23,
24 0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c,
25 0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad };
26
27unsigned char app_b2[SHA256_DIGEST_LENGTH] = {
28 0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8,
29 0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39,
30 0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67,
31 0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1 };
32
33unsigned char app_b3[SHA256_DIGEST_LENGTH] = {
34 0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92,
35 0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67,
36 0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e,
37 0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0 };
38
39unsigned char addenum_1[SHA224_DIGEST_LENGTH] = {
40 0x23,0x09,0x7d,0x22,0x34,0x05,0xd8,0x22,
41 0x86,0x42,0xa4,0x77,0xbd,0xa2,0x55,0xb3,
42 0x2a,0xad,0xbc,0xe4,0xbd,0xa0,0xb3,0xf7,
43 0xe3,0x6c,0x9d,0xa7 };
44
45unsigned char addenum_2[SHA224_DIGEST_LENGTH] = {
46 0x75,0x38,0x8b,0x16,0x51,0x27,0x76,0xcc,
47 0x5d,0xba,0x5d,0xa1,0xfd,0x89,0x01,0x50,
48 0xb0,0xc6,0x45,0x5c,0xb4,0xf5,0x8b,0x19,
49 0x52,0x52,0x25,0x25 };
50
51unsigned char addenum_3[SHA224_DIGEST_LENGTH] = {
52 0x20,0x79,0x46,0x55,0x98,0x0c,0x91,0xd8,
53 0xbb,0xb4,0xc1,0xea,0x97,0x61,0x8a,0x4b,
54 0xf0,0x3f,0x42,0x58,0x19,0x48,0xb2,0xee,
55 0x4e,0xe7,0xad,0x67 };
56
57int main (int argc,char **argv)
58{ unsigned char md[SHA256_DIGEST_LENGTH];
59 int i;
60 EVP_MD_CTX evp;
61
62 fprintf(stdout,"Testing SHA-256 ");
63
64 EVP_Digest ("abc",3,md,NULL,EVP_sha256(),NULL);
65 if (memcmp(md,app_b1,sizeof(app_b1)))
66 { fflush(stdout);
67 fprintf(stderr,"\nTEST 1 of 3 failed.\n");
68 return 1;
69 }
70 else
71 fprintf(stdout,"."); fflush(stdout);
72
73 EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk"
74 "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha256(),NULL);
75 if (memcmp(md,app_b2,sizeof(app_b2)))
76 { fflush(stdout);
77 fprintf(stderr,"\nTEST 2 of 3 failed.\n");
78 return 1;
79 }
80 else
81 fprintf(stdout,"."); fflush(stdout);
82
83 EVP_MD_CTX_init (&evp);
84 EVP_DigestInit_ex (&evp,EVP_sha256(),NULL);
85 for (i=0;i<1000000;i+=160)
86 EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
87 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
88 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
89 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
90 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
91 (1000000-i)<160?1000000-i:160);
92 EVP_DigestFinal_ex (&evp,md,NULL);
93 EVP_MD_CTX_cleanup (&evp);
94
95 if (memcmp(md,app_b3,sizeof(app_b3)))
96 { fflush(stdout);
97 fprintf(stderr,"\nTEST 3 of 3 failed.\n");
98 return 1;
99 }
100 else
101 fprintf(stdout,"."); fflush(stdout);
102
103 fprintf(stdout," passed.\n"); fflush(stdout);
104
105 fprintf(stdout,"Testing SHA-224 ");
106
107 EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL);
108 if (memcmp(md,addenum_1,sizeof(addenum_1)))
109 { fflush(stdout);
110 fprintf(stderr,"\nTEST 1 of 3 failed.\n");
111 return 1;
112 }
113 else
114 fprintf(stdout,"."); fflush(stdout);
115
116 EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk"
117 "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha224(),NULL);
118 if (memcmp(md,addenum_2,sizeof(addenum_2)))
119 { fflush(stdout);
120 fprintf(stderr,"\nTEST 2 of 3 failed.\n");
121 return 1;
122 }
123 else
124 fprintf(stdout,"."); fflush(stdout);
125
126 EVP_MD_CTX_init (&evp);
127 EVP_DigestInit_ex (&evp,EVP_sha224(),NULL);
128 for (i=0;i<1000000;i+=64)
129 EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
130 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
131 (1000000-i)<64?1000000-i:64);
132 EVP_DigestFinal_ex (&evp,md,NULL);
133 EVP_MD_CTX_cleanup (&evp);
134
135 if (memcmp(md,addenum_3,sizeof(addenum_3)))
136 { fflush(stdout);
137 fprintf(stderr,"\nTEST 3 of 3 failed.\n");
138 return 1;
139 }
140 else
141 fprintf(stdout,"."); fflush(stdout);
142
143 fprintf(stdout," passed.\n"); fflush(stdout);
144
145 return 0;
146}
147#endif
diff --git a/src/lib/libcrypto/sha/sha512t.c b/src/lib/libcrypto/sha/sha512t.c
new file mode 100644
index 0000000000..210041d435
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha512t.c
@@ -0,0 +1,184 @@
1/* crypto/sha/sha512t.c */
2/* ====================================================================
3 * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
4 * ====================================================================
5 */
6#include <stdio.h>
7#include <string.h>
8#include <stdlib.h>
9
10#include <openssl/sha.h>
11#include <openssl/evp.h>
12#include <openssl/crypto.h>
13
14#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512)
15int main(int argc, char *argv[])
16{
17 printf("No SHA512 support\n");
18 return(0);
19}
20#else
21
22unsigned char app_c1[SHA512_DIGEST_LENGTH] = {
23 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba,
24 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31,
25 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2,
26 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a,
27 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8,
28 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd,
29 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e,
30 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f };
31
32unsigned char app_c2[SHA512_DIGEST_LENGTH] = {
33 0x8e,0x95,0x9b,0x75,0xda,0xe3,0x13,0xda,
34 0x8c,0xf4,0xf7,0x28,0x14,0xfc,0x14,0x3f,
35 0x8f,0x77,0x79,0xc6,0xeb,0x9f,0x7f,0xa1,
36 0x72,0x99,0xae,0xad,0xb6,0x88,0x90,0x18,
37 0x50,0x1d,0x28,0x9e,0x49,0x00,0xf7,0xe4,
38 0x33,0x1b,0x99,0xde,0xc4,0xb5,0x43,0x3a,
39 0xc7,0xd3,0x29,0xee,0xb6,0xdd,0x26,0x54,
40 0x5e,0x96,0xe5,0x5b,0x87,0x4b,0xe9,0x09 };
41
42unsigned char app_c3[SHA512_DIGEST_LENGTH] = {
43 0xe7,0x18,0x48,0x3d,0x0c,0xe7,0x69,0x64,
44 0x4e,0x2e,0x42,0xc7,0xbc,0x15,0xb4,0x63,
45 0x8e,0x1f,0x98,0xb1,0x3b,0x20,0x44,0x28,
46 0x56,0x32,0xa8,0x03,0xaf,0xa9,0x73,0xeb,
47 0xde,0x0f,0xf2,0x44,0x87,0x7e,0xa6,0x0a,
48 0x4c,0xb0,0x43,0x2c,0xe5,0x77,0xc3,0x1b,
49 0xeb,0x00,0x9c,0x5c,0x2c,0x49,0xaa,0x2e,
50 0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b };
51
52unsigned char app_d1[SHA384_DIGEST_LENGTH] = {
53 0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b,
54 0xb5,0xa0,0x3d,0x69,0x9a,0xc6,0x50,0x07,
55 0x27,0x2c,0x32,0xab,0x0e,0xde,0xd1,0x63,
56 0x1a,0x8b,0x60,0x5a,0x43,0xff,0x5b,0xed,
57 0x80,0x86,0x07,0x2b,0xa1,0xe7,0xcc,0x23,
58 0x58,0xba,0xec,0xa1,0x34,0xc8,0x25,0xa7 };
59
60unsigned char app_d2[SHA384_DIGEST_LENGTH] = {
61 0x09,0x33,0x0c,0x33,0xf7,0x11,0x47,0xe8,
62 0x3d,0x19,0x2f,0xc7,0x82,0xcd,0x1b,0x47,
63 0x53,0x11,0x1b,0x17,0x3b,0x3b,0x05,0xd2,
64 0x2f,0xa0,0x80,0x86,0xe3,0xb0,0xf7,0x12,
65 0xfc,0xc7,0xc7,0x1a,0x55,0x7e,0x2d,0xb9,
66 0x66,0xc3,0xe9,0xfa,0x91,0x74,0x60,0x39 };
67
68unsigned char app_d3[SHA384_DIGEST_LENGTH] = {
69 0x9d,0x0e,0x18,0x09,0x71,0x64,0x74,0xcb,
70 0x08,0x6e,0x83,0x4e,0x31,0x0a,0x4a,0x1c,
71 0xed,0x14,0x9e,0x9c,0x00,0xf2,0x48,0x52,
72 0x79,0x72,0xce,0xc5,0x70,0x4c,0x2a,0x5b,
73 0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb,
74 0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 };
75
76int main (int argc,char **argv)
77{ unsigned char md[SHA512_DIGEST_LENGTH];
78 int i;
79 EVP_MD_CTX evp;
80
81#ifdef OPENSSL_IA32_SSE2
82 /* Alternative to this is to call OpenSSL_add_all_algorithms...
83 * The below code is retained exclusively for debugging purposes. */
84 { char *env;
85
86 if ((env=getenv("OPENSSL_ia32cap")))
87 OPENSSL_ia32cap = strtoul (env,NULL,0);
88 }
89#endif
90
91 fprintf(stdout,"Testing SHA-512 ");
92
93 EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL);
94 if (memcmp(md,app_c1,sizeof(app_c1)))
95 { fflush(stdout);
96 fprintf(stderr,"\nTEST 1 of 3 failed.\n");
97 return 1;
98 }
99 else
100 fprintf(stdout,"."); fflush(stdout);
101
102 EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
103 "efghijkl""fghijklm""ghijklmn""hijklmno"
104 "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
105 "mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL);
106 if (memcmp(md,app_c2,sizeof(app_c2)))
107 { fflush(stdout);
108 fprintf(stderr,"\nTEST 2 of 3 failed.\n");
109 return 1;
110 }
111 else
112 fprintf(stdout,"."); fflush(stdout);
113
114 EVP_MD_CTX_init (&evp);
115 EVP_DigestInit_ex (&evp,EVP_sha512(),NULL);
116 for (i=0;i<1000000;i+=288)
117 EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
118 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
119 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
120 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
121 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
122 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
123 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
124 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
125 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
126 (1000000-i)<288?1000000-i:288);
127 EVP_DigestFinal_ex (&evp,md,NULL);
128 EVP_MD_CTX_cleanup (&evp);
129
130 if (memcmp(md,app_c3,sizeof(app_c3)))
131 { fflush(stdout);
132 fprintf(stderr,"\nTEST 3 of 3 failed.\n");
133 return 1;
134 }
135 else
136 fprintf(stdout,"."); fflush(stdout);
137
138 fprintf(stdout," passed.\n"); fflush(stdout);
139
140 fprintf(stdout,"Testing SHA-384 ");
141
142 EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL);
143 if (memcmp(md,app_d1,sizeof(app_d1)))
144 { fflush(stdout);
145 fprintf(stderr,"\nTEST 1 of 3 failed.\n");
146 return 1;
147 }
148 else
149 fprintf(stdout,"."); fflush(stdout);
150
151 EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk"
152 "efghijkl""fghijklm""ghijklmn""hijklmno"
153 "ijklmnop""jklmnopq""klmnopqr""lmnopqrs"
154 "mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL);
155 if (memcmp(md,app_d2,sizeof(app_d2)))
156 { fflush(stdout);
157 fprintf(stderr,"\nTEST 2 of 3 failed.\n");
158 return 1;
159 }
160 else
161 fprintf(stdout,"."); fflush(stdout);
162
163 EVP_MD_CTX_init (&evp);
164 EVP_DigestInit_ex (&evp,EVP_sha384(),NULL);
165 for (i=0;i<1000000;i+=64)
166 EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa"
167 "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa",
168 (1000000-i)<64?1000000-i:64);
169 EVP_DigestFinal_ex (&evp,md,NULL);
170 EVP_MD_CTX_cleanup (&evp);
171
172 if (memcmp(md,app_d3,sizeof(app_d3)))
173 { fflush(stdout);
174 fprintf(stderr,"\nTEST 3 of 3 failed.\n");
175 return 1;
176 }
177 else
178 fprintf(stdout,"."); fflush(stdout);
179
180 fprintf(stdout," passed.\n"); fflush(stdout);
181
182 return 0;
183}
184#endif
diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c
new file mode 100644
index 0000000000..5a4b3ab204
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha_dgst.c
@@ -0,0 +1,73 @@
1/* crypto/sha/sha1dgst.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA)
60
61#undef SHA_1
62#define SHA_0
63
64#include <openssl/opensslv.h>
65
66const char *SHA_version="SHA" OPENSSL_VERSION_PTEXT;
67
68/* The implementation is in ../md32_common.h */
69
70#include "sha_locl.h"
71
72#endif
73
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h
index e37e5726e3..a3623f72da 100644
--- a/src/lib/libcrypto/sha/sha_locl.h
+++ b/src/lib/libcrypto/sha/sha_locl.h
@@ -62,11 +62,17 @@
62#include <openssl/opensslconf.h> 62#include <openssl/opensslconf.h>
63#include <openssl/sha.h> 63#include <openssl/sha.h>
64 64
65#ifndef SHA_LONG_LOG2
66#define SHA_LONG_LOG2 2 /* default to 32 bits */
67#endif
68
65#define DATA_ORDER_IS_BIG_ENDIAN 69#define DATA_ORDER_IS_BIG_ENDIAN
66 70
67#define HASH_LONG SHA_LONG 71#define HASH_LONG SHA_LONG
72#define HASH_LONG_LOG2 SHA_LONG_LOG2
68#define HASH_CTX SHA_CTX 73#define HASH_CTX SHA_CTX
69#define HASH_CBLOCK SHA_CBLOCK 74#define HASH_CBLOCK SHA_CBLOCK
75#define HASH_LBLOCK SHA_LBLOCK
70#define HASH_MAKE_STRING(c,s) do { \ 76#define HASH_MAKE_STRING(c,s) do { \
71 unsigned long ll; \ 77 unsigned long ll; \
72 ll=(c)->h0; HOST_l2c(ll,(s)); \ 78 ll=(c)->h0; HOST_l2c(ll,(s)); \
@@ -82,10 +88,12 @@
82# define HASH_TRANSFORM SHA_Transform 88# define HASH_TRANSFORM SHA_Transform
83# define HASH_FINAL SHA_Final 89# define HASH_FINAL SHA_Final
84# define HASH_INIT SHA_Init 90# define HASH_INIT SHA_Init
91# define HASH_BLOCK_HOST_ORDER sha_block_host_order
85# define HASH_BLOCK_DATA_ORDER sha_block_data_order 92# define HASH_BLOCK_DATA_ORDER sha_block_data_order
86# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id)) 93# define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id))
87 94
88static void sha_block_data_order (SHA_CTX *c, const void *p,size_t num); 95 void sha_block_host_order (SHA_CTX *c, const void *p,int num);
96 void sha_block_data_order (SHA_CTX *c, const void *p,int num);
89 97
90#elif defined(SHA_1) 98#elif defined(SHA_1)
91 99
@@ -93,6 +101,7 @@ static void sha_block_data_order (SHA_CTX *c, const void *p,size_t num);
93# define HASH_TRANSFORM SHA1_Transform 101# define HASH_TRANSFORM SHA1_Transform
94# define HASH_FINAL SHA1_Final 102# define HASH_FINAL SHA1_Final
95# define HASH_INIT SHA1_Init 103# define HASH_INIT SHA1_Init
104# define HASH_BLOCK_HOST_ORDER sha1_block_host_order
96# define HASH_BLOCK_DATA_ORDER sha1_block_data_order 105# define HASH_BLOCK_DATA_ORDER sha1_block_data_order
97# if defined(__MWERKS__) && defined(__MC68K__) 106# if defined(__MWERKS__) && defined(__MC68K__)
98 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */ 107 /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */
@@ -105,10 +114,22 @@ static void sha_block_data_order (SHA_CTX *c, const void *p,size_t num);
105 ) 114 )
106# endif 115# endif
107 116
108#ifndef SHA1_ASM 117# ifdef SHA1_ASM
109static 118# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__)
110#endif 119# define sha1_block_host_order sha1_block_asm_host_order
111void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); 120# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
121# define sha1_block_data_order sha1_block_asm_data_order
122# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
123# define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order
124# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64)
125# define sha1_block_host_order sha1_block_asm_host_order
126# define DONT_IMPLEMENT_BLOCK_HOST_ORDER
127# define sha1_block_data_order sha1_block_asm_data_order
128# define DONT_IMPLEMENT_BLOCK_DATA_ORDER
129# endif
130# endif
131 void sha1_block_host_order (SHA_CTX *c, const void *p,int num);
132 void sha1_block_data_order (SHA_CTX *c, const void *p,int num);
112 133
113#else 134#else
114# error "Either SHA_0 or SHA_1 must be defined." 135# error "Either SHA_0 or SHA_1 must be defined."
@@ -122,7 +143,11 @@ void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num);
122#define INIT_DATA_h3 0x10325476UL 143#define INIT_DATA_h3 0x10325476UL
123#define INIT_DATA_h4 0xc3d2e1f0UL 144#define INIT_DATA_h4 0xc3d2e1f0UL
124 145
146#if defined(SHA_0) && defined(OPENSSL_FIPS)
147FIPS_NON_FIPS_MD_Init(SHA)
148#else
125int HASH_INIT (SHA_CTX *c) 149int HASH_INIT (SHA_CTX *c)
150#endif
126 { 151 {
127 c->h0=INIT_DATA_h0; 152 c->h0=INIT_DATA_h0;
128 c->h1=INIT_DATA_h1; 153 c->h1=INIT_DATA_h1;
@@ -152,8 +177,6 @@ int HASH_INIT (SHA_CTX *c)
152#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) 177#define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d)))
153#define F_60_79(b,c,d) F_20_39(b,c,d) 178#define F_60_79(b,c,d) F_20_39(b,c,d)
154 179
155#ifndef OPENSSL_SMALL_FOOTPRINT
156
157#define BODY_00_15(i,a,b,c,d,e,f,xi) \ 180#define BODY_00_15(i,a,b,c,d,e,f,xi) \
158 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ 181 (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \
159 (b)=ROTATE((b),30); 182 (b)=ROTATE((b),30);
@@ -206,11 +229,11 @@ int HASH_INIT (SHA_CTX *c)
206# define X(i) XX[i] 229# define X(i) XX[i]
207#endif 230#endif
208 231
209#if !defined(SHA_1) || !defined(SHA1_ASM) 232#ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER
210static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) 233void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num)
211 { 234 {
212 const unsigned char *data=p; 235 const SHA_LONG *W=d;
213 register unsigned MD32_REG_T A,B,C,D,E,T,l; 236 register unsigned MD32_REG_T A,B,C,D,E,T;
214#ifndef MD32_XARRAY 237#ifndef MD32_XARRAY
215 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, 238 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
216 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; 239 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
@@ -225,71 +248,41 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
225 E=c->h4; 248 E=c->h4;
226 249
227 for (;;) 250 for (;;)
228 {
229 const union { long one; char little; } is_endian = {1};
230
231 if (!is_endian.little && sizeof(SHA_LONG)==4 && ((size_t)p%4)==0)
232 {
233 const SHA_LONG *W=(const SHA_LONG *)data;
234
235 X( 0) = W[0]; X( 1) = W[ 1];
236 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); X( 2) = W[ 2];
237 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); X( 3) = W[ 3];
238 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); X( 4) = W[ 4];
239 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); X( 5) = W[ 5];
240 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); X( 6) = W[ 6];
241 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); X( 7) = W[ 7];
242 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); X( 8) = W[ 8];
243 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); X( 9) = W[ 9];
244 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); X(10) = W[10];
245 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); X(11) = W[11];
246 BODY_00_15(10,C,D,E,T,A,B,X(10)); X(12) = W[12];
247 BODY_00_15(11,B,C,D,E,T,A,X(11)); X(13) = W[13];
248 BODY_00_15(12,A,B,C,D,E,T,X(12)); X(14) = W[14];
249 BODY_00_15(13,T,A,B,C,D,E,X(13)); X(15) = W[15];
250 BODY_00_15(14,E,T,A,B,C,D,X(14));
251 BODY_00_15(15,D,E,T,A,B,C,X(15));
252
253 data += SHA_CBLOCK;
254 }
255 else
256 { 251 {
257 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l; 252 BODY_00_15( 0,A,B,C,D,E,T,W[ 0]);
258 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l; 253 BODY_00_15( 1,T,A,B,C,D,E,W[ 1]);
259 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l; 254 BODY_00_15( 2,E,T,A,B,C,D,W[ 2]);
260 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l; 255 BODY_00_15( 3,D,E,T,A,B,C,W[ 3]);
261 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l; 256 BODY_00_15( 4,C,D,E,T,A,B,W[ 4]);
262 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l; 257 BODY_00_15( 5,B,C,D,E,T,A,W[ 5]);
263 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l; 258 BODY_00_15( 6,A,B,C,D,E,T,W[ 6]);
264 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l; 259 BODY_00_15( 7,T,A,B,C,D,E,W[ 7]);
265 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l; 260 BODY_00_15( 8,E,T,A,B,C,D,W[ 8]);
266 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l; 261 BODY_00_15( 9,D,E,T,A,B,C,W[ 9]);
267 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l; 262 BODY_00_15(10,C,D,E,T,A,B,W[10]);
268 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l; 263 BODY_00_15(11,B,C,D,E,T,A,W[11]);
269 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l; 264 BODY_00_15(12,A,B,C,D,E,T,W[12]);
270 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l; 265 BODY_00_15(13,T,A,B,C,D,E,W[13]);
271 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l; 266 BODY_00_15(14,E,T,A,B,C,D,W[14]);
272 BODY_00_15(14,E,T,A,B,C,D,X(14)); 267 BODY_00_15(15,D,E,T,A,B,C,W[15]);
273 BODY_00_15(15,D,E,T,A,B,C,X(15)); 268
274 } 269 BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]);
275 270 BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]);
276 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13)); 271 BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]);
277 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14)); 272 BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0));
278 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15)); 273
279 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0)); 274 BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1));
280 275 BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2));
281 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1)); 276 BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3));
282 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2)); 277 BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4));
283 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3)); 278 BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5));
284 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4)); 279 BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6));
285 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5)); 280 BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7));
286 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6)); 281 BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8));
287 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7)); 282 BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9));
288 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8)); 283 BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10));
289 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9)); 284 BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11));
290 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10)); 285 BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12));
291 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
292 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
293 286
294 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13)); 287 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
295 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14)); 288 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
@@ -348,7 +341,7 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
348 c->h3=(c->h3+B)&0xffffffffL; 341 c->h3=(c->h3+B)&0xffffffffL;
349 c->h4=(c->h4+C)&0xffffffffL; 342 c->h4=(c->h4+C)&0xffffffffL;
350 343
351 if (--num == 0) break; 344 if (--num <= 0) break;
352 345
353 A=c->h0; 346 A=c->h0;
354 B=c->h1; 347 B=c->h1;
@@ -356,48 +349,22 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
356 D=c->h3; 349 D=c->h3;
357 E=c->h4; 350 E=c->h4;
358 351
359 } 352 W+=SHA_LBLOCK;
353 }
360 } 354 }
361#endif 355#endif
362 356
363#else /* OPENSSL_SMALL_FOOTPRINT */ 357#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER
364 358void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num)
365#define BODY_00_15(xi) do { \
366 T=E+K_00_19+F_00_19(B,C,D); \
367 E=D, D=C, C=ROTATE(B,30), B=A; \
368 A=ROTATE(A,5)+T+xi; } while(0)
369
370#define BODY_16_19(xa,xb,xc,xd) do { \
371 Xupdate(T,xa,xa,xb,xc,xd); \
372 T+=E+K_00_19+F_00_19(B,C,D); \
373 E=D, D=C, C=ROTATE(B,30), B=A; \
374 A=ROTATE(A,5)+T; } while(0)
375
376#define BODY_20_39(xa,xb,xc,xd) do { \
377 Xupdate(T,xa,xa,xb,xc,xd); \
378 T+=E+K_20_39+F_20_39(B,C,D); \
379 E=D, D=C, C=ROTATE(B,30), B=A; \
380 A=ROTATE(A,5)+T; } while(0)
381
382#define BODY_40_59(xa,xb,xc,xd) do { \
383 Xupdate(T,xa,xa,xb,xc,xd); \
384 T+=E+K_40_59+F_40_59(B,C,D); \
385 E=D, D=C, C=ROTATE(B,30), B=A; \
386 A=ROTATE(A,5)+T; } while(0)
387
388#define BODY_60_79(xa,xb,xc,xd) do { \
389 Xupdate(T,xa,xa,xb,xc,xd); \
390 T=E+K_60_79+F_60_79(B,C,D); \
391 E=D, D=C, C=ROTATE(B,30), B=A; \
392 A=ROTATE(A,5)+T+xa; } while(0)
393
394#if !defined(SHA_1) || !defined(SHA1_ASM)
395static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
396 { 359 {
397 const unsigned char *data=p; 360 const unsigned char *data=p;
398 register unsigned MD32_REG_T A,B,C,D,E,T,l; 361 register unsigned MD32_REG_T A,B,C,D,E,T,l;
399 int i; 362#ifndef MD32_XARRAY
400 SHA_LONG X[16]; 363 unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7,
364 XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15;
365#else
366 SHA_LONG XX[16];
367#endif
401 368
402 A=c->h0; 369 A=c->h0;
403 B=c->h1; 370 B=c->h1;
@@ -407,24 +374,101 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
407 374
408 for (;;) 375 for (;;)
409 { 376 {
410 for (i=0;i<16;i++) 377
411 { HOST_c2l(data,l); X[i]=l; BODY_00_15(X[i]); } 378 HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
412 for (i=0;i<4;i++) 379 BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l;
413 { BODY_16_19(X[i], X[i+2], X[i+8], X[(i+13)&15]); } 380 BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l;
414 for (;i<24;i++) 381 BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l;
415 { BODY_20_39(X[i&15], X[(i+2)&15], X[(i+8)&15],X[(i+13)&15]); } 382 BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l;
416 for (i=0;i<20;i++) 383 BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l;
417 { BODY_40_59(X[(i+8)&15],X[(i+10)&15],X[i&15], X[(i+5)&15]); } 384 BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l;
418 for (i=4;i<24;i++) 385 BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l;
419 { BODY_60_79(X[(i+8)&15],X[(i+10)&15],X[i&15], X[(i+5)&15]); } 386 BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l;
420 387 BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l;
421 c->h0=(c->h0+A)&0xffffffffL; 388 BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l;
422 c->h1=(c->h1+B)&0xffffffffL; 389 BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l;
423 c->h2=(c->h2+C)&0xffffffffL; 390 BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l;
424 c->h3=(c->h3+D)&0xffffffffL; 391 BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l;
425 c->h4=(c->h4+E)&0xffffffffL; 392 BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l;
426 393 BODY_00_15(14,E,T,A,B,C,D,X(14));
427 if (--num == 0) break; 394 BODY_00_15(15,D,E,T,A,B,C,X(15));
395
396 BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13));
397 BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14));
398 BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15));
399 BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0));
400
401 BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1));
402 BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2));
403 BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3));
404 BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4));
405 BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5));
406 BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6));
407 BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7));
408 BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8));
409 BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9));
410 BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10));
411 BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11));
412 BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12));
413
414 BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13));
415 BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14));
416 BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15));
417 BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0));
418 BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1));
419 BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2));
420 BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3));
421 BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4));
422
423 BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5));
424 BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6));
425 BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7));
426 BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8));
427 BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9));
428 BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10));
429 BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11));
430 BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12));
431 BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13));
432 BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14));
433 BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15));
434 BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0));
435 BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1));
436 BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2));
437 BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3));
438 BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4));
439 BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5));
440 BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6));
441 BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7));
442 BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8));
443
444 BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9));
445 BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10));
446 BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11));
447 BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12));
448 BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13));
449 BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14));
450 BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15));
451 BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0));
452 BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1));
453 BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2));
454 BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3));
455 BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4));
456 BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5));
457 BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6));
458 BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7));
459 BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8));
460 BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9));
461 BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10));
462 BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11));
463 BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12));
464
465 c->h0=(c->h0+E)&0xffffffffL;
466 c->h1=(c->h1+T)&0xffffffffL;
467 c->h2=(c->h2+A)&0xffffffffL;
468 c->h3=(c->h3+B)&0xffffffffL;
469 c->h4=(c->h4+C)&0xffffffffL;
470
471 if (--num <= 0) break;
428 472
429 A=c->h0; 473 A=c->h0;
430 B=c->h1; 474 B=c->h1;
@@ -435,5 +479,3 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
435 } 479 }
436 } 480 }
437#endif 481#endif
438
439#endif
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c
new file mode 100644
index 0000000000..d4f4d344df
--- /dev/null
+++ b/src/lib/libcrypto/sha/sha_one.c
@@ -0,0 +1,78 @@
1/* crypto/sha/sha_one.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <openssl/sha.h>
62#include <openssl/crypto.h>
63
64#ifndef OPENSSL_NO_SHA0
65unsigned char *SHA(const unsigned char *d, unsigned long n, unsigned char *md)
66 {
67 SHA_CTX c;
68 static unsigned char m[SHA_DIGEST_LENGTH];
69
70 if (md == NULL) md=m;
71 if (!SHA_Init(&c))
72 return NULL;
73 SHA_Update(&c,d,n);
74 SHA_Final(md,&c);
75 OPENSSL_cleanse(&c,sizeof(c));
76 return(md);
77 }
78#endif
diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c
new file mode 100644
index 0000000000..ff702aa53e
--- /dev/null
+++ b/src/lib/libcrypto/sha/shatest.c
@@ -0,0 +1,174 @@
1/* crypto/sha/shatest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <string.h>
61#include <stdlib.h>
62
63#include "../e_os.h"
64
65#if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0)
66int main(int argc, char *argv[])
67{
68 printf("No SHA0 support\n");
69 return(0);
70}
71#else
72#include <openssl/evp.h>
73#include <openssl/sha.h>
74
75#ifdef CHARSET_EBCDIC
76#include <openssl/ebcdic.h>
77#endif
78
79#define SHA_0 /* FIPS 180 */
80#undef SHA_1 /* FIPS 180-1 */
81
82static char *test[]={
83 "abc",
84 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",
85 NULL,
86 };
87
88#ifdef SHA_0
89static char *ret[]={
90 "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880",
91 "d2516ee1acfa5baf33dfc1c471e438449ef134c8",
92 };
93static char *bigret=
94 "3232affa48628a26653b5aaa44541fd90d690603";
95#endif
96#ifdef SHA_1
97static char *ret[]={
98 "a9993e364706816aba3e25717850c26c9cd0d89d",
99 "84983e441c3bd26ebaae4aa1f95129e5e54670f1",
100 };
101static char *bigret=
102 "34aa973cd4c4daa4f61eeb2bdbad27316534016f";
103#endif
104
105static char *pt(unsigned char *md);
106int main(int argc, char *argv[])
107 {
108 int i,err=0;
109 unsigned char **P,**R;
110 static unsigned char buf[1000];
111 char *p,*r;
112 EVP_MD_CTX c;
113 unsigned char md[SHA_DIGEST_LENGTH];
114
115#ifdef CHARSET_EBCDIC
116 ebcdic2ascii(test[0], test[0], strlen(test[0]));
117 ebcdic2ascii(test[1], test[1], strlen(test[1]));
118#endif
119
120 EVP_MD_CTX_init(&c);
121 P=(unsigned char **)test;
122 R=(unsigned char **)ret;
123 i=1;
124 while (*P != NULL)
125 {
126 EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha(), NULL);
127 p=pt(md);
128 if (strcmp(p,(char *)*R) != 0)
129 {
130 printf("error calculating SHA on '%s'\n",*P);
131 printf("got %s instead of %s\n",p,*R);
132 err++;
133 }
134 else
135 printf("test %d ok\n",i);
136 i++;
137 R++;
138 P++;
139 }
140
141 memset(buf,'a',1000);
142#ifdef CHARSET_EBCDIC
143 ebcdic2ascii(buf, buf, 1000);
144#endif /*CHARSET_EBCDIC*/
145 EVP_DigestInit_ex(&c,EVP_sha(), NULL);
146 for (i=0; i<1000; i++)
147 EVP_DigestUpdate(&c,buf,1000);
148 EVP_DigestFinal_ex(&c,md,NULL);
149 p=pt(md);
150
151 r=bigret;
152 if (strcmp(p,r) != 0)
153 {
154 printf("error calculating SHA on '%s'\n",p);
155 printf("got %s instead of %s\n",p,r);
156 err++;
157 }
158 else
159 printf("test 3 ok\n");
160 EVP_MD_CTX_cleanup(&c);
161 EXIT(err);
162 return(0);
163 }
164
165static char *pt(unsigned char *md)
166 {
167 int i;
168 static char buf[80];
169
170 for (i=0; i<SHA_DIGEST_LENGTH; i++)
171 sprintf(&(buf[i*2]),"%02x",md[i]);
172 return(buf);
173 }
174#endif
diff --git a/src/lib/libcrypto/stack/Makefile b/src/lib/libcrypto/stack/Makefile
new file mode 100644
index 0000000000..5327692ac8
--- /dev/null
+++ b/src/lib/libcrypto/stack/Makefile
@@ -0,0 +1,84 @@
1#
2# OpenSSL/crypto/stack/Makefile
3#
4
5DIR= stack
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=stack.c
21LIBOBJ=stack.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= stack.h safestack.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77stack.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
78stack.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
79stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80stack.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
81stack.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
82stack.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
83stack.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
84stack.o: ../../include/openssl/symhacks.h ../cryptlib.h stack.c
diff --git a/src/lib/libcrypto/stack/Makefile.ssl b/src/lib/libcrypto/stack/Makefile.ssl
new file mode 100644
index 0000000000..7120fb804a
--- /dev/null
+++ b/src/lib/libcrypto/stack/Makefile.ssl
@@ -0,0 +1,88 @@
1#
2# SSLeay/crypto/stack/Makefile
3#
4
5DIR= stack
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=stack.c
27LIBOBJ=stack.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= stack.h safestack.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82stack.o: ../../e_os.h ../../include/openssl/bio.h
83stack.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84stack.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85stack.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
86stack.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87stack.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88stack.o: ../cryptlib.h stack.c
diff --git a/src/lib/libcrypto/stack/safestack.h b/src/lib/libcrypto/stack/safestack.h
index 78cc485e6d..6010b7f122 100644
--- a/src/lib/libcrypto/stack/safestack.h
+++ b/src/lib/libcrypto/stack/safestack.h
@@ -55,22 +55,13 @@
55#ifndef HEADER_SAFESTACK_H 55#ifndef HEADER_SAFESTACK_H
56#define HEADER_SAFESTACK_H 56#define HEADER_SAFESTACK_H
57 57
58typedef void (*openssl_fptr)(void);
59#define openssl_fcast(f) ((openssl_fptr)f)
60
58#include <openssl/stack.h> 61#include <openssl/stack.h>
59 62
60#ifdef DEBUG_SAFESTACK 63#ifdef DEBUG_SAFESTACK
61 64
62#ifndef CHECKED_PTR_OF
63#define CHECKED_PTR_OF(type, p) \
64 ((void*) (1 ? p : (type*)0))
65#endif
66
67#define CHECKED_SK_FREE_FUNC(type, p) \
68 ((void (*)(void *)) ((1 ? p : (void (*)(type *))0)))
69
70#define CHECKED_SK_CMP_FUNC(type, p) \
71 ((int (*)(const char * const *, const char * const *)) \
72 ((1 ? p : (int (*)(const type * const *, const type * const *))0)))
73
74#define STACK_OF(type) struct stack_st_##type 65#define STACK_OF(type) struct stack_st_##type
75#define PREDECLARE_STACK_OF(type) STACK_OF(type); 66#define PREDECLARE_STACK_OF(type) STACK_OF(type);
76 67
@@ -85,71 +76,75 @@ STACK_OF(type) \
85/* SKM_sk_... stack macros are internal to safestack.h: 76/* SKM_sk_... stack macros are internal to safestack.h:
86 * never use them directly, use sk_<type>_... instead */ 77 * never use them directly, use sk_<type>_... instead */
87#define SKM_sk_new(type, cmp) \ 78#define SKM_sk_new(type, cmp) \
88 ((STACK_OF(type) *)sk_new(CHECKED_SK_CMP_FUNC(type, cmp))) 79 ((STACK_OF(type) * (*)(int (*)(const type * const *, const type * const *)))openssl_fcast(sk_new))(cmp)
89#define SKM_sk_new_null(type) \ 80#define SKM_sk_new_null(type) \
90 ((STACK_OF(type) *)sk_new_null()) 81 ((STACK_OF(type) * (*)(void))openssl_fcast(sk_new_null))()
91#define SKM_sk_free(type, st) \ 82#define SKM_sk_free(type, st) \
92 sk_free(CHECKED_PTR_OF(STACK_OF(type), st)) 83 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_free))(st)
93#define SKM_sk_num(type, st) \ 84#define SKM_sk_num(type, st) \
94 sk_num(CHECKED_PTR_OF(STACK_OF(type), st)) 85 ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_num))(st)
95#define SKM_sk_value(type, st,i) \ 86#define SKM_sk_value(type, st,i) \
96 ((type *)sk_value(CHECKED_PTR_OF(STACK_OF(type), st), i)) 87 ((type * (*)(const STACK_OF(type) *, int))openssl_fcast(sk_value))(st, i)
97#define SKM_sk_set(type, st,i,val) \ 88#define SKM_sk_set(type, st,i,val) \
98 sk_set(CHECKED_PTR_OF(STACK_OF(type), st), i, CHECKED_PTR_OF(type, val)) 89 ((type * (*)(STACK_OF(type) *, int, type *))openssl_fcast(sk_set))(st, i, val)
99#define SKM_sk_zero(type, st) \ 90#define SKM_sk_zero(type, st) \
100 sk_zero(CHECKED_PTR_OF(STACK_OF(type), st)) 91 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_zero))(st)
101#define SKM_sk_push(type, st,val) \ 92#define SKM_sk_push(type, st,val) \
102 sk_push(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) 93 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_push))(st, val)
103#define SKM_sk_unshift(type, st,val) \ 94#define SKM_sk_unshift(type, st,val) \
104 sk_unshift(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) 95 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_unshift))(st, val)
105#define SKM_sk_find(type, st,val) \ 96#define SKM_sk_find(type, st,val) \
106 sk_find(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val)) 97 ((int (*)(STACK_OF(type) *, type *))openssl_fcast(sk_find))(st, val)
107#define SKM_sk_delete(type, st,i) \ 98#define SKM_sk_delete(type, st,i) \
108 (type *)sk_delete(CHECKED_PTR_OF(STACK_OF(type), st), i) 99 ((type * (*)(STACK_OF(type) *, int))openssl_fcast(sk_delete))(st, i)
109#define SKM_sk_delete_ptr(type, st,ptr) \ 100#define SKM_sk_delete_ptr(type, st,ptr) \
110 (type *)sk_delete_ptr(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, ptr)) 101 ((type * (*)(STACK_OF(type) *, type *))openssl_fcast(sk_delete_ptr))(st, ptr)
111#define SKM_sk_insert(type, st,val,i) \ 102#define SKM_sk_insert(type, st,val,i) \
112 sk_insert(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_PTR_OF(type, val), i) 103 ((int (*)(STACK_OF(type) *, type *, int))openssl_fcast(sk_insert))(st, val, i)
113#define SKM_sk_set_cmp_func(type, st,cmp) \ 104#define SKM_sk_set_cmp_func(type, st,cmp) \
114 ((int (*)(const type * const *,const type * const *)) \ 105 ((int (*(*)(STACK_OF(type) *, int (*)(const type * const *, const type * const *))) \
115 sk_set_cmp_func(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_CMP_FUNC(type, cmp))) 106 (const type * const *, const type * const *))openssl_fcast(sk_set_cmp_func))\
107 (st, cmp)
116#define SKM_sk_dup(type, st) \ 108#define SKM_sk_dup(type, st) \
117 (STACK_OF(type) *)sk_dup(CHECKED_PTR_OF(STACK_OF(type), st)) 109 ((STACK_OF(type) *(*)(STACK_OF(type) *))openssl_fcast(sk_dup))(st)
118#define SKM_sk_pop_free(type, st,free_func) \ 110#define SKM_sk_pop_free(type, st,free_func) \
119 sk_pop_free(CHECKED_PTR_OF(STACK_OF(type), st), CHECKED_SK_FREE_FUNC(type, free_func)) 111 ((void (*)(STACK_OF(type) *, void (*)(type *)))openssl_fcast(sk_pop_free))\
112 (st, free_func)
120#define SKM_sk_shift(type, st) \ 113#define SKM_sk_shift(type, st) \
121 (type *)sk_shift(CHECKED_PTR_OF(STACK_OF(type), st)) 114 ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_shift))(st)
122#define SKM_sk_pop(type, st) \ 115#define SKM_sk_pop(type, st) \
123 (type *)sk_pop(CHECKED_PTR_OF(STACK_OF(type), st)) 116 ((type * (*)(STACK_OF(type) *))openssl_fcast(sk_pop))(st)
124#define SKM_sk_sort(type, st) \ 117#define SKM_sk_sort(type, st) \
125 sk_sort(CHECKED_PTR_OF(STACK_OF(type), st)) 118 ((void (*)(STACK_OF(type) *))openssl_fcast(sk_sort))(st)
126#define SKM_sk_is_sorted(type, st) \ 119#define SKM_sk_is_sorted(type, st) \
127 sk_is_sorted(CHECKED_PTR_OF(STACK_OF(type), st)) 120 ((int (*)(const STACK_OF(type) *))openssl_fcast(sk_is_sorted))(st)
128 121
129#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ 122#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
130 (STACK_OF(type) *)d2i_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type), st), \ 123 ((STACK_OF(type) * (*) (STACK_OF(type) **,unsigned char **, long , \
131 pp, length, \ 124 type *(*)(type **, unsigned char **,long), \
132 CHECKED_D2I_OF(type, d2i_func), \ 125 void (*)(type *), int ,int )) openssl_fcast(d2i_ASN1_SET)) \
133 CHECKED_SK_FREE_FUNC(type, free_func), \ 126 (st,pp,length, d2i_func, free_func, ex_tag,ex_class)
134 ex_tag, ex_class)
135
136#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \ 127#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
137 i2d_ASN1_SET(CHECKED_PTR_OF(STACK_OF(type), st), pp, \ 128 ((int (*)(STACK_OF(type) *,unsigned char **, \
138 CHECKED_I2D_OF(type, i2d_func), \ 129 int (*)(type *,unsigned char **), int , int , int)) openssl_fcast(i2d_ASN1_SET)) \
139 ex_tag, ex_class, is_set) 130 (st,pp,i2d_func,ex_tag,ex_class,is_set)
140 131
141#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \ 132#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
142 ASN1_seq_pack(CHECKED_PTR_OF(STACK_OF(type), st), \ 133 ((unsigned char *(*)(STACK_OF(type) *, \
143 CHECKED_I2D_OF(type, i2d_func), buf, len) 134 int (*)(type *,unsigned char **), unsigned char **,int *)) openssl_fcast(ASN1_seq_pack)) \
144 135 (st, i2d_func, buf, len)
145#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \ 136#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
146 (STACK_OF(type) *)ASN1_seq_unpack(buf, len, CHECKED_D2I_OF(type, d2i_func), CHECKED_SK_FREE_FUNC(type, free_func)) 137 ((STACK_OF(type) * (*)(unsigned char *,int, \
138 type *(*)(type **,unsigned char **, long), \
139 void (*)(type *)))openssl_fcast(ASN1_seq_unpack)) \
140 (buf,len,d2i_func, free_func)
147 141
148#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \ 142#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
149 (STACK_OF(type) *)PKCS12_decrypt_d2i(algor, \ 143 ((STACK_OF(type) * (*)(X509_ALGOR *, \
150 CHECKED_D2I_OF(type, d2i_func), \ 144 type *(*)(type **, unsigned char **, long), void (*)(type *), \
151 CHECKED_SK_FREE_FUNC(type, free_func), \ 145 const char *, int, \
152 pass, passlen, oct, seq) 146 ASN1_STRING *, int))openssl_fcast(PKCS12_decrypt_d2i)) \
147 (algor,d2i_func,free_func,pass,passlen,oct,seq)
153 148
154#else 149#else
155 150
@@ -175,7 +170,7 @@ STACK_OF(type) \
175#define SKM_sk_push(type, st,val) \ 170#define SKM_sk_push(type, st,val) \
176 sk_push(st, (char *)val) 171 sk_push(st, (char *)val)
177#define SKM_sk_unshift(type, st,val) \ 172#define SKM_sk_unshift(type, st,val) \
178 sk_unshift(st, (char *)val) 173 sk_unshift(st, val)
179#define SKM_sk_find(type, st,val) \ 174#define SKM_sk_find(type, st,val) \
180 sk_find(st, (char *)val) 175 sk_find(st, (char *)val)
181#define SKM_sk_delete(type, st,i) \ 176#define SKM_sk_delete(type, st,i) \
@@ -201,14 +196,14 @@ STACK_OF(type) \
201 sk_is_sorted(st) 196 sk_is_sorted(st)
202 197
203#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ 198#define SKM_ASN1_SET_OF_d2i(type, st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
204 d2i_ASN1_SET(st,pp,length, (void *(*)(void ** ,const unsigned char ** ,long))d2i_func, (void (*)(void *))free_func, ex_tag,ex_class) 199 d2i_ASN1_SET(st,pp,length, (char *(*)())d2i_func, (void (*)(void *))free_func, ex_tag,ex_class)
205#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \ 200#define SKM_ASN1_SET_OF_i2d(type, st, pp, i2d_func, ex_tag, ex_class, is_set) \
206 i2d_ASN1_SET(st,pp,(int (*)(void *, unsigned char **))i2d_func,ex_tag,ex_class,is_set) 201 i2d_ASN1_SET(st,pp,i2d_func,ex_tag,ex_class,is_set)
207 202
208#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \ 203#define SKM_ASN1_seq_pack(type, st, i2d_func, buf, len) \
209 ASN1_seq_pack(st, (int (*)(void *, unsigned char **))i2d_func, buf, len) 204 ASN1_seq_pack(st, i2d_func, buf, len)
210#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \ 205#define SKM_ASN1_seq_unpack(type, buf, len, d2i_func, free_func) \
211 ASN1_seq_unpack(buf,len,(void *(*)(void **,const unsigned char **,long))d2i_func, (void(*)(void *))free_func) 206 ASN1_seq_unpack(buf,len,(char *(*)())d2i_func, (void(*)(void *))free_func)
212 207
213#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \ 208#define SKM_PKCS12_decrypt_d2i(type, algor, d2i_func, free_func, pass, passlen, oct, seq) \
214 ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq)) 209 ((STACK *)PKCS12_decrypt_d2i(algor,(char *(*)())d2i_func, (void(*)(void *))free_func,pass,passlen,oct,seq))
@@ -226,7 +221,6 @@ STACK_OF(type) \
226#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val)) 221#define sk_ACCESS_DESCRIPTION_push(st, val) SKM_sk_push(ACCESS_DESCRIPTION, (st), (val))
227#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val)) 222#define sk_ACCESS_DESCRIPTION_unshift(st, val) SKM_sk_unshift(ACCESS_DESCRIPTION, (st), (val))
228#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val)) 223#define sk_ACCESS_DESCRIPTION_find(st, val) SKM_sk_find(ACCESS_DESCRIPTION, (st), (val))
229#define sk_ACCESS_DESCRIPTION_find_ex(st, val) SKM_sk_find_ex(ACCESS_DESCRIPTION, (st), (val))
230#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i)) 224#define sk_ACCESS_DESCRIPTION_delete(st, i) SKM_sk_delete(ACCESS_DESCRIPTION, (st), (i))
231#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr)) 225#define sk_ACCESS_DESCRIPTION_delete_ptr(st, ptr) SKM_sk_delete_ptr(ACCESS_DESCRIPTION, (st), (ptr))
232#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i)) 226#define sk_ACCESS_DESCRIPTION_insert(st, val, i) SKM_sk_insert(ACCESS_DESCRIPTION, (st), (val), (i))
@@ -238,28 +232,6 @@ STACK_OF(type) \
238#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st)) 232#define sk_ACCESS_DESCRIPTION_sort(st) SKM_sk_sort(ACCESS_DESCRIPTION, (st))
239#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st)) 233#define sk_ACCESS_DESCRIPTION_is_sorted(st) SKM_sk_is_sorted(ACCESS_DESCRIPTION, (st))
240 234
241#define sk_ASIdOrRange_new(st) SKM_sk_new(ASIdOrRange, (st))
242#define sk_ASIdOrRange_new_null() SKM_sk_new_null(ASIdOrRange)
243#define sk_ASIdOrRange_free(st) SKM_sk_free(ASIdOrRange, (st))
244#define sk_ASIdOrRange_num(st) SKM_sk_num(ASIdOrRange, (st))
245#define sk_ASIdOrRange_value(st, i) SKM_sk_value(ASIdOrRange, (st), (i))
246#define sk_ASIdOrRange_set(st, i, val) SKM_sk_set(ASIdOrRange, (st), (i), (val))
247#define sk_ASIdOrRange_zero(st) SKM_sk_zero(ASIdOrRange, (st))
248#define sk_ASIdOrRange_push(st, val) SKM_sk_push(ASIdOrRange, (st), (val))
249#define sk_ASIdOrRange_unshift(st, val) SKM_sk_unshift(ASIdOrRange, (st), (val))
250#define sk_ASIdOrRange_find(st, val) SKM_sk_find(ASIdOrRange, (st), (val))
251#define sk_ASIdOrRange_find_ex(st, val) SKM_sk_find_ex(ASIdOrRange, (st), (val))
252#define sk_ASIdOrRange_delete(st, i) SKM_sk_delete(ASIdOrRange, (st), (i))
253#define sk_ASIdOrRange_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASIdOrRange, (st), (ptr))
254#define sk_ASIdOrRange_insert(st, val, i) SKM_sk_insert(ASIdOrRange, (st), (val), (i))
255#define sk_ASIdOrRange_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(ASIdOrRange, (st), (cmp))
256#define sk_ASIdOrRange_dup(st) SKM_sk_dup(ASIdOrRange, st)
257#define sk_ASIdOrRange_pop_free(st, free_func) SKM_sk_pop_free(ASIdOrRange, (st), (free_func))
258#define sk_ASIdOrRange_shift(st) SKM_sk_shift(ASIdOrRange, (st))
259#define sk_ASIdOrRange_pop(st) SKM_sk_pop(ASIdOrRange, (st))
260#define sk_ASIdOrRange_sort(st) SKM_sk_sort(ASIdOrRange, (st))
261#define sk_ASIdOrRange_is_sorted(st) SKM_sk_is_sorted(ASIdOrRange, (st))
262
263#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st)) 235#define sk_ASN1_GENERALSTRING_new(st) SKM_sk_new(ASN1_GENERALSTRING, (st))
264#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING) 236#define sk_ASN1_GENERALSTRING_new_null() SKM_sk_new_null(ASN1_GENERALSTRING)
265#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st)) 237#define sk_ASN1_GENERALSTRING_free(st) SKM_sk_free(ASN1_GENERALSTRING, (st))
@@ -270,7 +242,6 @@ STACK_OF(type) \
270#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val)) 242#define sk_ASN1_GENERALSTRING_push(st, val) SKM_sk_push(ASN1_GENERALSTRING, (st), (val))
271#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val)) 243#define sk_ASN1_GENERALSTRING_unshift(st, val) SKM_sk_unshift(ASN1_GENERALSTRING, (st), (val))
272#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val)) 244#define sk_ASN1_GENERALSTRING_find(st, val) SKM_sk_find(ASN1_GENERALSTRING, (st), (val))
273#define sk_ASN1_GENERALSTRING_find_ex(st, val) SKM_sk_find_ex(ASN1_GENERALSTRING, (st), (val))
274#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i)) 245#define sk_ASN1_GENERALSTRING_delete(st, i) SKM_sk_delete(ASN1_GENERALSTRING, (st), (i))
275#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr)) 246#define sk_ASN1_GENERALSTRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_GENERALSTRING, (st), (ptr))
276#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i)) 247#define sk_ASN1_GENERALSTRING_insert(st, val, i) SKM_sk_insert(ASN1_GENERALSTRING, (st), (val), (i))
@@ -292,7 +263,6 @@ STACK_OF(type) \
292#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val)) 263#define sk_ASN1_INTEGER_push(st, val) SKM_sk_push(ASN1_INTEGER, (st), (val))
293#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val)) 264#define sk_ASN1_INTEGER_unshift(st, val) SKM_sk_unshift(ASN1_INTEGER, (st), (val))
294#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val)) 265#define sk_ASN1_INTEGER_find(st, val) SKM_sk_find(ASN1_INTEGER, (st), (val))
295#define sk_ASN1_INTEGER_find_ex(st, val) SKM_sk_find_ex(ASN1_INTEGER, (st), (val))
296#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i)) 266#define sk_ASN1_INTEGER_delete(st, i) SKM_sk_delete(ASN1_INTEGER, (st), (i))
297#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr)) 267#define sk_ASN1_INTEGER_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_INTEGER, (st), (ptr))
298#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i)) 268#define sk_ASN1_INTEGER_insert(st, val, i) SKM_sk_insert(ASN1_INTEGER, (st), (val), (i))
@@ -314,7 +284,6 @@ STACK_OF(type) \
314#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val)) 284#define sk_ASN1_OBJECT_push(st, val) SKM_sk_push(ASN1_OBJECT, (st), (val))
315#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val)) 285#define sk_ASN1_OBJECT_unshift(st, val) SKM_sk_unshift(ASN1_OBJECT, (st), (val))
316#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val)) 286#define sk_ASN1_OBJECT_find(st, val) SKM_sk_find(ASN1_OBJECT, (st), (val))
317#define sk_ASN1_OBJECT_find_ex(st, val) SKM_sk_find_ex(ASN1_OBJECT, (st), (val))
318#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i)) 287#define sk_ASN1_OBJECT_delete(st, i) SKM_sk_delete(ASN1_OBJECT, (st), (i))
319#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr)) 288#define sk_ASN1_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_OBJECT, (st), (ptr))
320#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i)) 289#define sk_ASN1_OBJECT_insert(st, val, i) SKM_sk_insert(ASN1_OBJECT, (st), (val), (i))
@@ -336,7 +305,6 @@ STACK_OF(type) \
336#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val)) 305#define sk_ASN1_STRING_TABLE_push(st, val) SKM_sk_push(ASN1_STRING_TABLE, (st), (val))
337#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val)) 306#define sk_ASN1_STRING_TABLE_unshift(st, val) SKM_sk_unshift(ASN1_STRING_TABLE, (st), (val))
338#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val)) 307#define sk_ASN1_STRING_TABLE_find(st, val) SKM_sk_find(ASN1_STRING_TABLE, (st), (val))
339#define sk_ASN1_STRING_TABLE_find_ex(st, val) SKM_sk_find_ex(ASN1_STRING_TABLE, (st), (val))
340#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i)) 308#define sk_ASN1_STRING_TABLE_delete(st, i) SKM_sk_delete(ASN1_STRING_TABLE, (st), (i))
341#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr)) 309#define sk_ASN1_STRING_TABLE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_STRING_TABLE, (st), (ptr))
342#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i)) 310#define sk_ASN1_STRING_TABLE_insert(st, val, i) SKM_sk_insert(ASN1_STRING_TABLE, (st), (val), (i))
@@ -358,7 +326,6 @@ STACK_OF(type) \
358#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val)) 326#define sk_ASN1_TYPE_push(st, val) SKM_sk_push(ASN1_TYPE, (st), (val))
359#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val)) 327#define sk_ASN1_TYPE_unshift(st, val) SKM_sk_unshift(ASN1_TYPE, (st), (val))
360#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val)) 328#define sk_ASN1_TYPE_find(st, val) SKM_sk_find(ASN1_TYPE, (st), (val))
361#define sk_ASN1_TYPE_find_ex(st, val) SKM_sk_find_ex(ASN1_TYPE, (st), (val))
362#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i)) 329#define sk_ASN1_TYPE_delete(st, i) SKM_sk_delete(ASN1_TYPE, (st), (i))
363#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr)) 330#define sk_ASN1_TYPE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_TYPE, (st), (ptr))
364#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i)) 331#define sk_ASN1_TYPE_insert(st, val, i) SKM_sk_insert(ASN1_TYPE, (st), (val), (i))
@@ -380,7 +347,6 @@ STACK_OF(type) \
380#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val)) 347#define sk_ASN1_VALUE_push(st, val) SKM_sk_push(ASN1_VALUE, (st), (val))
381#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val)) 348#define sk_ASN1_VALUE_unshift(st, val) SKM_sk_unshift(ASN1_VALUE, (st), (val))
382#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val)) 349#define sk_ASN1_VALUE_find(st, val) SKM_sk_find(ASN1_VALUE, (st), (val))
383#define sk_ASN1_VALUE_find_ex(st, val) SKM_sk_find_ex(ASN1_VALUE, (st), (val))
384#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i)) 350#define sk_ASN1_VALUE_delete(st, i) SKM_sk_delete(ASN1_VALUE, (st), (i))
385#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr)) 351#define sk_ASN1_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ASN1_VALUE, (st), (ptr))
386#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i)) 352#define sk_ASN1_VALUE_insert(st, val, i) SKM_sk_insert(ASN1_VALUE, (st), (val), (i))
@@ -402,7 +368,6 @@ STACK_OF(type) \
402#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val)) 368#define sk_BIO_push(st, val) SKM_sk_push(BIO, (st), (val))
403#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val)) 369#define sk_BIO_unshift(st, val) SKM_sk_unshift(BIO, (st), (val))
404#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val)) 370#define sk_BIO_find(st, val) SKM_sk_find(BIO, (st), (val))
405#define sk_BIO_find_ex(st, val) SKM_sk_find_ex(BIO, (st), (val))
406#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i)) 371#define sk_BIO_delete(st, i) SKM_sk_delete(BIO, (st), (i))
407#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr)) 372#define sk_BIO_delete_ptr(st, ptr) SKM_sk_delete_ptr(BIO, (st), (ptr))
408#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i)) 373#define sk_BIO_insert(st, val, i) SKM_sk_insert(BIO, (st), (val), (i))
@@ -414,94 +379,6 @@ STACK_OF(type) \
414#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st)) 379#define sk_BIO_sort(st) SKM_sk_sort(BIO, (st))
415#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st)) 380#define sk_BIO_is_sorted(st) SKM_sk_is_sorted(BIO, (st))
416 381
417#define sk_CMS_CertificateChoices_new(st) SKM_sk_new(CMS_CertificateChoices, (st))
418#define sk_CMS_CertificateChoices_new_null() SKM_sk_new_null(CMS_CertificateChoices)
419#define sk_CMS_CertificateChoices_free(st) SKM_sk_free(CMS_CertificateChoices, (st))
420#define sk_CMS_CertificateChoices_num(st) SKM_sk_num(CMS_CertificateChoices, (st))
421#define sk_CMS_CertificateChoices_value(st, i) SKM_sk_value(CMS_CertificateChoices, (st), (i))
422#define sk_CMS_CertificateChoices_set(st, i, val) SKM_sk_set(CMS_CertificateChoices, (st), (i), (val))
423#define sk_CMS_CertificateChoices_zero(st) SKM_sk_zero(CMS_CertificateChoices, (st))
424#define sk_CMS_CertificateChoices_push(st, val) SKM_sk_push(CMS_CertificateChoices, (st), (val))
425#define sk_CMS_CertificateChoices_unshift(st, val) SKM_sk_unshift(CMS_CertificateChoices, (st), (val))
426#define sk_CMS_CertificateChoices_find(st, val) SKM_sk_find(CMS_CertificateChoices, (st), (val))
427#define sk_CMS_CertificateChoices_find_ex(st, val) SKM_sk_find_ex(CMS_CertificateChoices, (st), (val))
428#define sk_CMS_CertificateChoices_delete(st, i) SKM_sk_delete(CMS_CertificateChoices, (st), (i))
429#define sk_CMS_CertificateChoices_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_CertificateChoices, (st), (ptr))
430#define sk_CMS_CertificateChoices_insert(st, val, i) SKM_sk_insert(CMS_CertificateChoices, (st), (val), (i))
431#define sk_CMS_CertificateChoices_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_CertificateChoices, (st), (cmp))
432#define sk_CMS_CertificateChoices_dup(st) SKM_sk_dup(CMS_CertificateChoices, st)
433#define sk_CMS_CertificateChoices_pop_free(st, free_func) SKM_sk_pop_free(CMS_CertificateChoices, (st), (free_func))
434#define sk_CMS_CertificateChoices_shift(st) SKM_sk_shift(CMS_CertificateChoices, (st))
435#define sk_CMS_CertificateChoices_pop(st) SKM_sk_pop(CMS_CertificateChoices, (st))
436#define sk_CMS_CertificateChoices_sort(st) SKM_sk_sort(CMS_CertificateChoices, (st))
437#define sk_CMS_CertificateChoices_is_sorted(st) SKM_sk_is_sorted(CMS_CertificateChoices, (st))
438
439#define sk_CMS_RecipientInfo_new(st) SKM_sk_new(CMS_RecipientInfo, (st))
440#define sk_CMS_RecipientInfo_new_null() SKM_sk_new_null(CMS_RecipientInfo)
441#define sk_CMS_RecipientInfo_free(st) SKM_sk_free(CMS_RecipientInfo, (st))
442#define sk_CMS_RecipientInfo_num(st) SKM_sk_num(CMS_RecipientInfo, (st))
443#define sk_CMS_RecipientInfo_value(st, i) SKM_sk_value(CMS_RecipientInfo, (st), (i))
444#define sk_CMS_RecipientInfo_set(st, i, val) SKM_sk_set(CMS_RecipientInfo, (st), (i), (val))
445#define sk_CMS_RecipientInfo_zero(st) SKM_sk_zero(CMS_RecipientInfo, (st))
446#define sk_CMS_RecipientInfo_push(st, val) SKM_sk_push(CMS_RecipientInfo, (st), (val))
447#define sk_CMS_RecipientInfo_unshift(st, val) SKM_sk_unshift(CMS_RecipientInfo, (st), (val))
448#define sk_CMS_RecipientInfo_find(st, val) SKM_sk_find(CMS_RecipientInfo, (st), (val))
449#define sk_CMS_RecipientInfo_find_ex(st, val) SKM_sk_find_ex(CMS_RecipientInfo, (st), (val))
450#define sk_CMS_RecipientInfo_delete(st, i) SKM_sk_delete(CMS_RecipientInfo, (st), (i))
451#define sk_CMS_RecipientInfo_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_RecipientInfo, (st), (ptr))
452#define sk_CMS_RecipientInfo_insert(st, val, i) SKM_sk_insert(CMS_RecipientInfo, (st), (val), (i))
453#define sk_CMS_RecipientInfo_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_RecipientInfo, (st), (cmp))
454#define sk_CMS_RecipientInfo_dup(st) SKM_sk_dup(CMS_RecipientInfo, st)
455#define sk_CMS_RecipientInfo_pop_free(st, free_func) SKM_sk_pop_free(CMS_RecipientInfo, (st), (free_func))
456#define sk_CMS_RecipientInfo_shift(st) SKM_sk_shift(CMS_RecipientInfo, (st))
457#define sk_CMS_RecipientInfo_pop(st) SKM_sk_pop(CMS_RecipientInfo, (st))
458#define sk_CMS_RecipientInfo_sort(st) SKM_sk_sort(CMS_RecipientInfo, (st))
459#define sk_CMS_RecipientInfo_is_sorted(st) SKM_sk_is_sorted(CMS_RecipientInfo, (st))
460
461#define sk_CMS_RevocationInfoChoice_new(st) SKM_sk_new(CMS_RevocationInfoChoice, (st))
462#define sk_CMS_RevocationInfoChoice_new_null() SKM_sk_new_null(CMS_RevocationInfoChoice)
463#define sk_CMS_RevocationInfoChoice_free(st) SKM_sk_free(CMS_RevocationInfoChoice, (st))
464#define sk_CMS_RevocationInfoChoice_num(st) SKM_sk_num(CMS_RevocationInfoChoice, (st))
465#define sk_CMS_RevocationInfoChoice_value(st, i) SKM_sk_value(CMS_RevocationInfoChoice, (st), (i))
466#define sk_CMS_RevocationInfoChoice_set(st, i, val) SKM_sk_set(CMS_RevocationInfoChoice, (st), (i), (val))
467#define sk_CMS_RevocationInfoChoice_zero(st) SKM_sk_zero(CMS_RevocationInfoChoice, (st))
468#define sk_CMS_RevocationInfoChoice_push(st, val) SKM_sk_push(CMS_RevocationInfoChoice, (st), (val))
469#define sk_CMS_RevocationInfoChoice_unshift(st, val) SKM_sk_unshift(CMS_RevocationInfoChoice, (st), (val))
470#define sk_CMS_RevocationInfoChoice_find(st, val) SKM_sk_find(CMS_RevocationInfoChoice, (st), (val))
471#define sk_CMS_RevocationInfoChoice_find_ex(st, val) SKM_sk_find_ex(CMS_RevocationInfoChoice, (st), (val))
472#define sk_CMS_RevocationInfoChoice_delete(st, i) SKM_sk_delete(CMS_RevocationInfoChoice, (st), (i))
473#define sk_CMS_RevocationInfoChoice_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_RevocationInfoChoice, (st), (ptr))
474#define sk_CMS_RevocationInfoChoice_insert(st, val, i) SKM_sk_insert(CMS_RevocationInfoChoice, (st), (val), (i))
475#define sk_CMS_RevocationInfoChoice_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_RevocationInfoChoice, (st), (cmp))
476#define sk_CMS_RevocationInfoChoice_dup(st) SKM_sk_dup(CMS_RevocationInfoChoice, st)
477#define sk_CMS_RevocationInfoChoice_pop_free(st, free_func) SKM_sk_pop_free(CMS_RevocationInfoChoice, (st), (free_func))
478#define sk_CMS_RevocationInfoChoice_shift(st) SKM_sk_shift(CMS_RevocationInfoChoice, (st))
479#define sk_CMS_RevocationInfoChoice_pop(st) SKM_sk_pop(CMS_RevocationInfoChoice, (st))
480#define sk_CMS_RevocationInfoChoice_sort(st) SKM_sk_sort(CMS_RevocationInfoChoice, (st))
481#define sk_CMS_RevocationInfoChoice_is_sorted(st) SKM_sk_is_sorted(CMS_RevocationInfoChoice, (st))
482
483#define sk_CMS_SignerInfo_new(st) SKM_sk_new(CMS_SignerInfo, (st))
484#define sk_CMS_SignerInfo_new_null() SKM_sk_new_null(CMS_SignerInfo)
485#define sk_CMS_SignerInfo_free(st) SKM_sk_free(CMS_SignerInfo, (st))
486#define sk_CMS_SignerInfo_num(st) SKM_sk_num(CMS_SignerInfo, (st))
487#define sk_CMS_SignerInfo_value(st, i) SKM_sk_value(CMS_SignerInfo, (st), (i))
488#define sk_CMS_SignerInfo_set(st, i, val) SKM_sk_set(CMS_SignerInfo, (st), (i), (val))
489#define sk_CMS_SignerInfo_zero(st) SKM_sk_zero(CMS_SignerInfo, (st))
490#define sk_CMS_SignerInfo_push(st, val) SKM_sk_push(CMS_SignerInfo, (st), (val))
491#define sk_CMS_SignerInfo_unshift(st, val) SKM_sk_unshift(CMS_SignerInfo, (st), (val))
492#define sk_CMS_SignerInfo_find(st, val) SKM_sk_find(CMS_SignerInfo, (st), (val))
493#define sk_CMS_SignerInfo_find_ex(st, val) SKM_sk_find_ex(CMS_SignerInfo, (st), (val))
494#define sk_CMS_SignerInfo_delete(st, i) SKM_sk_delete(CMS_SignerInfo, (st), (i))
495#define sk_CMS_SignerInfo_delete_ptr(st, ptr) SKM_sk_delete_ptr(CMS_SignerInfo, (st), (ptr))
496#define sk_CMS_SignerInfo_insert(st, val, i) SKM_sk_insert(CMS_SignerInfo, (st), (val), (i))
497#define sk_CMS_SignerInfo_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(CMS_SignerInfo, (st), (cmp))
498#define sk_CMS_SignerInfo_dup(st) SKM_sk_dup(CMS_SignerInfo, st)
499#define sk_CMS_SignerInfo_pop_free(st, free_func) SKM_sk_pop_free(CMS_SignerInfo, (st), (free_func))
500#define sk_CMS_SignerInfo_shift(st) SKM_sk_shift(CMS_SignerInfo, (st))
501#define sk_CMS_SignerInfo_pop(st) SKM_sk_pop(CMS_SignerInfo, (st))
502#define sk_CMS_SignerInfo_sort(st) SKM_sk_sort(CMS_SignerInfo, (st))
503#define sk_CMS_SignerInfo_is_sorted(st) SKM_sk_is_sorted(CMS_SignerInfo, (st))
504
505#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st)) 382#define sk_CONF_IMODULE_new(st) SKM_sk_new(CONF_IMODULE, (st))
506#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE) 383#define sk_CONF_IMODULE_new_null() SKM_sk_new_null(CONF_IMODULE)
507#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st)) 384#define sk_CONF_IMODULE_free(st) SKM_sk_free(CONF_IMODULE, (st))
@@ -512,7 +389,6 @@ STACK_OF(type) \
512#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val)) 389#define sk_CONF_IMODULE_push(st, val) SKM_sk_push(CONF_IMODULE, (st), (val))
513#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val)) 390#define sk_CONF_IMODULE_unshift(st, val) SKM_sk_unshift(CONF_IMODULE, (st), (val))
514#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val)) 391#define sk_CONF_IMODULE_find(st, val) SKM_sk_find(CONF_IMODULE, (st), (val))
515#define sk_CONF_IMODULE_find_ex(st, val) SKM_sk_find_ex(CONF_IMODULE, (st), (val))
516#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i)) 392#define sk_CONF_IMODULE_delete(st, i) SKM_sk_delete(CONF_IMODULE, (st), (i))
517#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr)) 393#define sk_CONF_IMODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_IMODULE, (st), (ptr))
518#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i)) 394#define sk_CONF_IMODULE_insert(st, val, i) SKM_sk_insert(CONF_IMODULE, (st), (val), (i))
@@ -534,7 +410,6 @@ STACK_OF(type) \
534#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val)) 410#define sk_CONF_MODULE_push(st, val) SKM_sk_push(CONF_MODULE, (st), (val))
535#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val)) 411#define sk_CONF_MODULE_unshift(st, val) SKM_sk_unshift(CONF_MODULE, (st), (val))
536#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val)) 412#define sk_CONF_MODULE_find(st, val) SKM_sk_find(CONF_MODULE, (st), (val))
537#define sk_CONF_MODULE_find_ex(st, val) SKM_sk_find_ex(CONF_MODULE, (st), (val))
538#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i)) 413#define sk_CONF_MODULE_delete(st, i) SKM_sk_delete(CONF_MODULE, (st), (i))
539#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr)) 414#define sk_CONF_MODULE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_MODULE, (st), (ptr))
540#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i)) 415#define sk_CONF_MODULE_insert(st, val, i) SKM_sk_insert(CONF_MODULE, (st), (val), (i))
@@ -556,7 +431,6 @@ STACK_OF(type) \
556#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val)) 431#define sk_CONF_VALUE_push(st, val) SKM_sk_push(CONF_VALUE, (st), (val))
557#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val)) 432#define sk_CONF_VALUE_unshift(st, val) SKM_sk_unshift(CONF_VALUE, (st), (val))
558#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val)) 433#define sk_CONF_VALUE_find(st, val) SKM_sk_find(CONF_VALUE, (st), (val))
559#define sk_CONF_VALUE_find_ex(st, val) SKM_sk_find_ex(CONF_VALUE, (st), (val))
560#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i)) 434#define sk_CONF_VALUE_delete(st, i) SKM_sk_delete(CONF_VALUE, (st), (i))
561#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr)) 435#define sk_CONF_VALUE_delete_ptr(st, ptr) SKM_sk_delete_ptr(CONF_VALUE, (st), (ptr))
562#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i)) 436#define sk_CONF_VALUE_insert(st, val, i) SKM_sk_insert(CONF_VALUE, (st), (val), (i))
@@ -578,7 +452,6 @@ STACK_OF(type) \
578#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val)) 452#define sk_CRYPTO_EX_DATA_FUNCS_push(st, val) SKM_sk_push(CRYPTO_EX_DATA_FUNCS, (st), (val))
579#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val)) 453#define sk_CRYPTO_EX_DATA_FUNCS_unshift(st, val) SKM_sk_unshift(CRYPTO_EX_DATA_FUNCS, (st), (val))
580#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val)) 454#define sk_CRYPTO_EX_DATA_FUNCS_find(st, val) SKM_sk_find(CRYPTO_EX_DATA_FUNCS, (st), (val))
581#define sk_CRYPTO_EX_DATA_FUNCS_find_ex(st, val) SKM_sk_find_ex(CRYPTO_EX_DATA_FUNCS, (st), (val))
582#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i)) 455#define sk_CRYPTO_EX_DATA_FUNCS_delete(st, i) SKM_sk_delete(CRYPTO_EX_DATA_FUNCS, (st), (i))
583#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr)) 456#define sk_CRYPTO_EX_DATA_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_EX_DATA_FUNCS, (st), (ptr))
584#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i)) 457#define sk_CRYPTO_EX_DATA_FUNCS_insert(st, val, i) SKM_sk_insert(CRYPTO_EX_DATA_FUNCS, (st), (val), (i))
@@ -600,7 +473,6 @@ STACK_OF(type) \
600#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val)) 473#define sk_CRYPTO_dynlock_push(st, val) SKM_sk_push(CRYPTO_dynlock, (st), (val))
601#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val)) 474#define sk_CRYPTO_dynlock_unshift(st, val) SKM_sk_unshift(CRYPTO_dynlock, (st), (val))
602#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val)) 475#define sk_CRYPTO_dynlock_find(st, val) SKM_sk_find(CRYPTO_dynlock, (st), (val))
603#define sk_CRYPTO_dynlock_find_ex(st, val) SKM_sk_find_ex(CRYPTO_dynlock, (st), (val))
604#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i)) 476#define sk_CRYPTO_dynlock_delete(st, i) SKM_sk_delete(CRYPTO_dynlock, (st), (i))
605#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr)) 477#define sk_CRYPTO_dynlock_delete_ptr(st, ptr) SKM_sk_delete_ptr(CRYPTO_dynlock, (st), (ptr))
606#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i)) 478#define sk_CRYPTO_dynlock_insert(st, val, i) SKM_sk_insert(CRYPTO_dynlock, (st), (val), (i))
@@ -622,7 +494,6 @@ STACK_OF(type) \
622#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val)) 494#define sk_DIST_POINT_push(st, val) SKM_sk_push(DIST_POINT, (st), (val))
623#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val)) 495#define sk_DIST_POINT_unshift(st, val) SKM_sk_unshift(DIST_POINT, (st), (val))
624#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val)) 496#define sk_DIST_POINT_find(st, val) SKM_sk_find(DIST_POINT, (st), (val))
625#define sk_DIST_POINT_find_ex(st, val) SKM_sk_find_ex(DIST_POINT, (st), (val))
626#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i)) 497#define sk_DIST_POINT_delete(st, i) SKM_sk_delete(DIST_POINT, (st), (i))
627#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr)) 498#define sk_DIST_POINT_delete_ptr(st, ptr) SKM_sk_delete_ptr(DIST_POINT, (st), (ptr))
628#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i)) 499#define sk_DIST_POINT_insert(st, val, i) SKM_sk_insert(DIST_POINT, (st), (val), (i))
@@ -644,7 +515,6 @@ STACK_OF(type) \
644#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val)) 515#define sk_ENGINE_push(st, val) SKM_sk_push(ENGINE, (st), (val))
645#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val)) 516#define sk_ENGINE_unshift(st, val) SKM_sk_unshift(ENGINE, (st), (val))
646#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val)) 517#define sk_ENGINE_find(st, val) SKM_sk_find(ENGINE, (st), (val))
647#define sk_ENGINE_find_ex(st, val) SKM_sk_find_ex(ENGINE, (st), (val))
648#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i)) 518#define sk_ENGINE_delete(st, i) SKM_sk_delete(ENGINE, (st), (i))
649#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr)) 519#define sk_ENGINE_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE, (st), (ptr))
650#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i)) 520#define sk_ENGINE_insert(st, val, i) SKM_sk_insert(ENGINE, (st), (val), (i))
@@ -666,7 +536,6 @@ STACK_OF(type) \
666#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val)) 536#define sk_ENGINE_CLEANUP_ITEM_push(st, val) SKM_sk_push(ENGINE_CLEANUP_ITEM, (st), (val))
667#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val)) 537#define sk_ENGINE_CLEANUP_ITEM_unshift(st, val) SKM_sk_unshift(ENGINE_CLEANUP_ITEM, (st), (val))
668#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val)) 538#define sk_ENGINE_CLEANUP_ITEM_find(st, val) SKM_sk_find(ENGINE_CLEANUP_ITEM, (st), (val))
669#define sk_ENGINE_CLEANUP_ITEM_find_ex(st, val) SKM_sk_find_ex(ENGINE_CLEANUP_ITEM, (st), (val))
670#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i)) 539#define sk_ENGINE_CLEANUP_ITEM_delete(st, i) SKM_sk_delete(ENGINE_CLEANUP_ITEM, (st), (i))
671#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr)) 540#define sk_ENGINE_CLEANUP_ITEM_delete_ptr(st, ptr) SKM_sk_delete_ptr(ENGINE_CLEANUP_ITEM, (st), (ptr))
672#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i)) 541#define sk_ENGINE_CLEANUP_ITEM_insert(st, val, i) SKM_sk_insert(ENGINE_CLEANUP_ITEM, (st), (val), (i))
@@ -688,7 +557,6 @@ STACK_OF(type) \
688#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val)) 557#define sk_GENERAL_NAME_push(st, val) SKM_sk_push(GENERAL_NAME, (st), (val))
689#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val)) 558#define sk_GENERAL_NAME_unshift(st, val) SKM_sk_unshift(GENERAL_NAME, (st), (val))
690#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val)) 559#define sk_GENERAL_NAME_find(st, val) SKM_sk_find(GENERAL_NAME, (st), (val))
691#define sk_GENERAL_NAME_find_ex(st, val) SKM_sk_find_ex(GENERAL_NAME, (st), (val))
692#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i)) 560#define sk_GENERAL_NAME_delete(st, i) SKM_sk_delete(GENERAL_NAME, (st), (i))
693#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr)) 561#define sk_GENERAL_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAME, (st), (ptr))
694#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i)) 562#define sk_GENERAL_NAME_insert(st, val, i) SKM_sk_insert(GENERAL_NAME, (st), (val), (i))
@@ -700,94 +568,6 @@ STACK_OF(type) \
700#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st)) 568#define sk_GENERAL_NAME_sort(st) SKM_sk_sort(GENERAL_NAME, (st))
701#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st)) 569#define sk_GENERAL_NAME_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAME, (st))
702 570
703#define sk_GENERAL_NAMES_new(st) SKM_sk_new(GENERAL_NAMES, (st))
704#define sk_GENERAL_NAMES_new_null() SKM_sk_new_null(GENERAL_NAMES)
705#define sk_GENERAL_NAMES_free(st) SKM_sk_free(GENERAL_NAMES, (st))
706#define sk_GENERAL_NAMES_num(st) SKM_sk_num(GENERAL_NAMES, (st))
707#define sk_GENERAL_NAMES_value(st, i) SKM_sk_value(GENERAL_NAMES, (st), (i))
708#define sk_GENERAL_NAMES_set(st, i, val) SKM_sk_set(GENERAL_NAMES, (st), (i), (val))
709#define sk_GENERAL_NAMES_zero(st) SKM_sk_zero(GENERAL_NAMES, (st))
710#define sk_GENERAL_NAMES_push(st, val) SKM_sk_push(GENERAL_NAMES, (st), (val))
711#define sk_GENERAL_NAMES_unshift(st, val) SKM_sk_unshift(GENERAL_NAMES, (st), (val))
712#define sk_GENERAL_NAMES_find(st, val) SKM_sk_find(GENERAL_NAMES, (st), (val))
713#define sk_GENERAL_NAMES_find_ex(st, val) SKM_sk_find_ex(GENERAL_NAMES, (st), (val))
714#define sk_GENERAL_NAMES_delete(st, i) SKM_sk_delete(GENERAL_NAMES, (st), (i))
715#define sk_GENERAL_NAMES_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_NAMES, (st), (ptr))
716#define sk_GENERAL_NAMES_insert(st, val, i) SKM_sk_insert(GENERAL_NAMES, (st), (val), (i))
717#define sk_GENERAL_NAMES_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_NAMES, (st), (cmp))
718#define sk_GENERAL_NAMES_dup(st) SKM_sk_dup(GENERAL_NAMES, st)
719#define sk_GENERAL_NAMES_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_NAMES, (st), (free_func))
720#define sk_GENERAL_NAMES_shift(st) SKM_sk_shift(GENERAL_NAMES, (st))
721#define sk_GENERAL_NAMES_pop(st) SKM_sk_pop(GENERAL_NAMES, (st))
722#define sk_GENERAL_NAMES_sort(st) SKM_sk_sort(GENERAL_NAMES, (st))
723#define sk_GENERAL_NAMES_is_sorted(st) SKM_sk_is_sorted(GENERAL_NAMES, (st))
724
725#define sk_GENERAL_SUBTREE_new(st) SKM_sk_new(GENERAL_SUBTREE, (st))
726#define sk_GENERAL_SUBTREE_new_null() SKM_sk_new_null(GENERAL_SUBTREE)
727#define sk_GENERAL_SUBTREE_free(st) SKM_sk_free(GENERAL_SUBTREE, (st))
728#define sk_GENERAL_SUBTREE_num(st) SKM_sk_num(GENERAL_SUBTREE, (st))
729#define sk_GENERAL_SUBTREE_value(st, i) SKM_sk_value(GENERAL_SUBTREE, (st), (i))
730#define sk_GENERAL_SUBTREE_set(st, i, val) SKM_sk_set(GENERAL_SUBTREE, (st), (i), (val))
731#define sk_GENERAL_SUBTREE_zero(st) SKM_sk_zero(GENERAL_SUBTREE, (st))
732#define sk_GENERAL_SUBTREE_push(st, val) SKM_sk_push(GENERAL_SUBTREE, (st), (val))
733#define sk_GENERAL_SUBTREE_unshift(st, val) SKM_sk_unshift(GENERAL_SUBTREE, (st), (val))
734#define sk_GENERAL_SUBTREE_find(st, val) SKM_sk_find(GENERAL_SUBTREE, (st), (val))
735#define sk_GENERAL_SUBTREE_find_ex(st, val) SKM_sk_find_ex(GENERAL_SUBTREE, (st), (val))
736#define sk_GENERAL_SUBTREE_delete(st, i) SKM_sk_delete(GENERAL_SUBTREE, (st), (i))
737#define sk_GENERAL_SUBTREE_delete_ptr(st, ptr) SKM_sk_delete_ptr(GENERAL_SUBTREE, (st), (ptr))
738#define sk_GENERAL_SUBTREE_insert(st, val, i) SKM_sk_insert(GENERAL_SUBTREE, (st), (val), (i))
739#define sk_GENERAL_SUBTREE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(GENERAL_SUBTREE, (st), (cmp))
740#define sk_GENERAL_SUBTREE_dup(st) SKM_sk_dup(GENERAL_SUBTREE, st)
741#define sk_GENERAL_SUBTREE_pop_free(st, free_func) SKM_sk_pop_free(GENERAL_SUBTREE, (st), (free_func))
742#define sk_GENERAL_SUBTREE_shift(st) SKM_sk_shift(GENERAL_SUBTREE, (st))
743#define sk_GENERAL_SUBTREE_pop(st) SKM_sk_pop(GENERAL_SUBTREE, (st))
744#define sk_GENERAL_SUBTREE_sort(st) SKM_sk_sort(GENERAL_SUBTREE, (st))
745#define sk_GENERAL_SUBTREE_is_sorted(st) SKM_sk_is_sorted(GENERAL_SUBTREE, (st))
746
747#define sk_IPAddressFamily_new(st) SKM_sk_new(IPAddressFamily, (st))
748#define sk_IPAddressFamily_new_null() SKM_sk_new_null(IPAddressFamily)
749#define sk_IPAddressFamily_free(st) SKM_sk_free(IPAddressFamily, (st))
750#define sk_IPAddressFamily_num(st) SKM_sk_num(IPAddressFamily, (st))
751#define sk_IPAddressFamily_value(st, i) SKM_sk_value(IPAddressFamily, (st), (i))
752#define sk_IPAddressFamily_set(st, i, val) SKM_sk_set(IPAddressFamily, (st), (i), (val))
753#define sk_IPAddressFamily_zero(st) SKM_sk_zero(IPAddressFamily, (st))
754#define sk_IPAddressFamily_push(st, val) SKM_sk_push(IPAddressFamily, (st), (val))
755#define sk_IPAddressFamily_unshift(st, val) SKM_sk_unshift(IPAddressFamily, (st), (val))
756#define sk_IPAddressFamily_find(st, val) SKM_sk_find(IPAddressFamily, (st), (val))
757#define sk_IPAddressFamily_find_ex(st, val) SKM_sk_find_ex(IPAddressFamily, (st), (val))
758#define sk_IPAddressFamily_delete(st, i) SKM_sk_delete(IPAddressFamily, (st), (i))
759#define sk_IPAddressFamily_delete_ptr(st, ptr) SKM_sk_delete_ptr(IPAddressFamily, (st), (ptr))
760#define sk_IPAddressFamily_insert(st, val, i) SKM_sk_insert(IPAddressFamily, (st), (val), (i))
761#define sk_IPAddressFamily_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(IPAddressFamily, (st), (cmp))
762#define sk_IPAddressFamily_dup(st) SKM_sk_dup(IPAddressFamily, st)
763#define sk_IPAddressFamily_pop_free(st, free_func) SKM_sk_pop_free(IPAddressFamily, (st), (free_func))
764#define sk_IPAddressFamily_shift(st) SKM_sk_shift(IPAddressFamily, (st))
765#define sk_IPAddressFamily_pop(st) SKM_sk_pop(IPAddressFamily, (st))
766#define sk_IPAddressFamily_sort(st) SKM_sk_sort(IPAddressFamily, (st))
767#define sk_IPAddressFamily_is_sorted(st) SKM_sk_is_sorted(IPAddressFamily, (st))
768
769#define sk_IPAddressOrRange_new(st) SKM_sk_new(IPAddressOrRange, (st))
770#define sk_IPAddressOrRange_new_null() SKM_sk_new_null(IPAddressOrRange)
771#define sk_IPAddressOrRange_free(st) SKM_sk_free(IPAddressOrRange, (st))
772#define sk_IPAddressOrRange_num(st) SKM_sk_num(IPAddressOrRange, (st))
773#define sk_IPAddressOrRange_value(st, i) SKM_sk_value(IPAddressOrRange, (st), (i))
774#define sk_IPAddressOrRange_set(st, i, val) SKM_sk_set(IPAddressOrRange, (st), (i), (val))
775#define sk_IPAddressOrRange_zero(st) SKM_sk_zero(IPAddressOrRange, (st))
776#define sk_IPAddressOrRange_push(st, val) SKM_sk_push(IPAddressOrRange, (st), (val))
777#define sk_IPAddressOrRange_unshift(st, val) SKM_sk_unshift(IPAddressOrRange, (st), (val))
778#define sk_IPAddressOrRange_find(st, val) SKM_sk_find(IPAddressOrRange, (st), (val))
779#define sk_IPAddressOrRange_find_ex(st, val) SKM_sk_find_ex(IPAddressOrRange, (st), (val))
780#define sk_IPAddressOrRange_delete(st, i) SKM_sk_delete(IPAddressOrRange, (st), (i))
781#define sk_IPAddressOrRange_delete_ptr(st, ptr) SKM_sk_delete_ptr(IPAddressOrRange, (st), (ptr))
782#define sk_IPAddressOrRange_insert(st, val, i) SKM_sk_insert(IPAddressOrRange, (st), (val), (i))
783#define sk_IPAddressOrRange_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(IPAddressOrRange, (st), (cmp))
784#define sk_IPAddressOrRange_dup(st) SKM_sk_dup(IPAddressOrRange, st)
785#define sk_IPAddressOrRange_pop_free(st, free_func) SKM_sk_pop_free(IPAddressOrRange, (st), (free_func))
786#define sk_IPAddressOrRange_shift(st) SKM_sk_shift(IPAddressOrRange, (st))
787#define sk_IPAddressOrRange_pop(st) SKM_sk_pop(IPAddressOrRange, (st))
788#define sk_IPAddressOrRange_sort(st) SKM_sk_sort(IPAddressOrRange, (st))
789#define sk_IPAddressOrRange_is_sorted(st) SKM_sk_is_sorted(IPAddressOrRange, (st))
790
791#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st)) 571#define sk_KRB5_APREQBODY_new(st) SKM_sk_new(KRB5_APREQBODY, (st))
792#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY) 572#define sk_KRB5_APREQBODY_new_null() SKM_sk_new_null(KRB5_APREQBODY)
793#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st)) 573#define sk_KRB5_APREQBODY_free(st) SKM_sk_free(KRB5_APREQBODY, (st))
@@ -798,7 +578,6 @@ STACK_OF(type) \
798#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val)) 578#define sk_KRB5_APREQBODY_push(st, val) SKM_sk_push(KRB5_APREQBODY, (st), (val))
799#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val)) 579#define sk_KRB5_APREQBODY_unshift(st, val) SKM_sk_unshift(KRB5_APREQBODY, (st), (val))
800#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val)) 580#define sk_KRB5_APREQBODY_find(st, val) SKM_sk_find(KRB5_APREQBODY, (st), (val))
801#define sk_KRB5_APREQBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_APREQBODY, (st), (val))
802#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i)) 581#define sk_KRB5_APREQBODY_delete(st, i) SKM_sk_delete(KRB5_APREQBODY, (st), (i))
803#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr)) 582#define sk_KRB5_APREQBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_APREQBODY, (st), (ptr))
804#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i)) 583#define sk_KRB5_APREQBODY_insert(st, val, i) SKM_sk_insert(KRB5_APREQBODY, (st), (val), (i))
@@ -820,7 +599,6 @@ STACK_OF(type) \
820#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val)) 599#define sk_KRB5_AUTHDATA_push(st, val) SKM_sk_push(KRB5_AUTHDATA, (st), (val))
821#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val)) 600#define sk_KRB5_AUTHDATA_unshift(st, val) SKM_sk_unshift(KRB5_AUTHDATA, (st), (val))
822#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val)) 601#define sk_KRB5_AUTHDATA_find(st, val) SKM_sk_find(KRB5_AUTHDATA, (st), (val))
823#define sk_KRB5_AUTHDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHDATA, (st), (val))
824#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i)) 602#define sk_KRB5_AUTHDATA_delete(st, i) SKM_sk_delete(KRB5_AUTHDATA, (st), (i))
825#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr)) 603#define sk_KRB5_AUTHDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHDATA, (st), (ptr))
826#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i)) 604#define sk_KRB5_AUTHDATA_insert(st, val, i) SKM_sk_insert(KRB5_AUTHDATA, (st), (val), (i))
@@ -842,7 +620,6 @@ STACK_OF(type) \
842#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val)) 620#define sk_KRB5_AUTHENTBODY_push(st, val) SKM_sk_push(KRB5_AUTHENTBODY, (st), (val))
843#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val)) 621#define sk_KRB5_AUTHENTBODY_unshift(st, val) SKM_sk_unshift(KRB5_AUTHENTBODY, (st), (val))
844#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val)) 622#define sk_KRB5_AUTHENTBODY_find(st, val) SKM_sk_find(KRB5_AUTHENTBODY, (st), (val))
845#define sk_KRB5_AUTHENTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_AUTHENTBODY, (st), (val))
846#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i)) 623#define sk_KRB5_AUTHENTBODY_delete(st, i) SKM_sk_delete(KRB5_AUTHENTBODY, (st), (i))
847#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr)) 624#define sk_KRB5_AUTHENTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_AUTHENTBODY, (st), (ptr))
848#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i)) 625#define sk_KRB5_AUTHENTBODY_insert(st, val, i) SKM_sk_insert(KRB5_AUTHENTBODY, (st), (val), (i))
@@ -864,7 +641,6 @@ STACK_OF(type) \
864#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val)) 641#define sk_KRB5_CHECKSUM_push(st, val) SKM_sk_push(KRB5_CHECKSUM, (st), (val))
865#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val)) 642#define sk_KRB5_CHECKSUM_unshift(st, val) SKM_sk_unshift(KRB5_CHECKSUM, (st), (val))
866#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val)) 643#define sk_KRB5_CHECKSUM_find(st, val) SKM_sk_find(KRB5_CHECKSUM, (st), (val))
867#define sk_KRB5_CHECKSUM_find_ex(st, val) SKM_sk_find_ex(KRB5_CHECKSUM, (st), (val))
868#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i)) 644#define sk_KRB5_CHECKSUM_delete(st, i) SKM_sk_delete(KRB5_CHECKSUM, (st), (i))
869#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr)) 645#define sk_KRB5_CHECKSUM_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_CHECKSUM, (st), (ptr))
870#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i)) 646#define sk_KRB5_CHECKSUM_insert(st, val, i) SKM_sk_insert(KRB5_CHECKSUM, (st), (val), (i))
@@ -886,7 +662,6 @@ STACK_OF(type) \
886#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val)) 662#define sk_KRB5_ENCDATA_push(st, val) SKM_sk_push(KRB5_ENCDATA, (st), (val))
887#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val)) 663#define sk_KRB5_ENCDATA_unshift(st, val) SKM_sk_unshift(KRB5_ENCDATA, (st), (val))
888#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val)) 664#define sk_KRB5_ENCDATA_find(st, val) SKM_sk_find(KRB5_ENCDATA, (st), (val))
889#define sk_KRB5_ENCDATA_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCDATA, (st), (val))
890#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i)) 665#define sk_KRB5_ENCDATA_delete(st, i) SKM_sk_delete(KRB5_ENCDATA, (st), (i))
891#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr)) 666#define sk_KRB5_ENCDATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCDATA, (st), (ptr))
892#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i)) 667#define sk_KRB5_ENCDATA_insert(st, val, i) SKM_sk_insert(KRB5_ENCDATA, (st), (val), (i))
@@ -908,7 +683,6 @@ STACK_OF(type) \
908#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val)) 683#define sk_KRB5_ENCKEY_push(st, val) SKM_sk_push(KRB5_ENCKEY, (st), (val))
909#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val)) 684#define sk_KRB5_ENCKEY_unshift(st, val) SKM_sk_unshift(KRB5_ENCKEY, (st), (val))
910#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val)) 685#define sk_KRB5_ENCKEY_find(st, val) SKM_sk_find(KRB5_ENCKEY, (st), (val))
911#define sk_KRB5_ENCKEY_find_ex(st, val) SKM_sk_find_ex(KRB5_ENCKEY, (st), (val))
912#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i)) 686#define sk_KRB5_ENCKEY_delete(st, i) SKM_sk_delete(KRB5_ENCKEY, (st), (i))
913#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr)) 687#define sk_KRB5_ENCKEY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_ENCKEY, (st), (ptr))
914#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i)) 688#define sk_KRB5_ENCKEY_insert(st, val, i) SKM_sk_insert(KRB5_ENCKEY, (st), (val), (i))
@@ -930,7 +704,6 @@ STACK_OF(type) \
930#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val)) 704#define sk_KRB5_PRINCNAME_push(st, val) SKM_sk_push(KRB5_PRINCNAME, (st), (val))
931#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val)) 705#define sk_KRB5_PRINCNAME_unshift(st, val) SKM_sk_unshift(KRB5_PRINCNAME, (st), (val))
932#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val)) 706#define sk_KRB5_PRINCNAME_find(st, val) SKM_sk_find(KRB5_PRINCNAME, (st), (val))
933#define sk_KRB5_PRINCNAME_find_ex(st, val) SKM_sk_find_ex(KRB5_PRINCNAME, (st), (val))
934#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i)) 707#define sk_KRB5_PRINCNAME_delete(st, i) SKM_sk_delete(KRB5_PRINCNAME, (st), (i))
935#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr)) 708#define sk_KRB5_PRINCNAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_PRINCNAME, (st), (ptr))
936#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i)) 709#define sk_KRB5_PRINCNAME_insert(st, val, i) SKM_sk_insert(KRB5_PRINCNAME, (st), (val), (i))
@@ -952,7 +725,6 @@ STACK_OF(type) \
952#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val)) 725#define sk_KRB5_TKTBODY_push(st, val) SKM_sk_push(KRB5_TKTBODY, (st), (val))
953#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val)) 726#define sk_KRB5_TKTBODY_unshift(st, val) SKM_sk_unshift(KRB5_TKTBODY, (st), (val))
954#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val)) 727#define sk_KRB5_TKTBODY_find(st, val) SKM_sk_find(KRB5_TKTBODY, (st), (val))
955#define sk_KRB5_TKTBODY_find_ex(st, val) SKM_sk_find_ex(KRB5_TKTBODY, (st), (val))
956#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i)) 728#define sk_KRB5_TKTBODY_delete(st, i) SKM_sk_delete(KRB5_TKTBODY, (st), (i))
957#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr)) 729#define sk_KRB5_TKTBODY_delete_ptr(st, ptr) SKM_sk_delete_ptr(KRB5_TKTBODY, (st), (ptr))
958#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i)) 730#define sk_KRB5_TKTBODY_insert(st, val, i) SKM_sk_insert(KRB5_TKTBODY, (st), (val), (i))
@@ -974,7 +746,6 @@ STACK_OF(type) \
974#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val)) 746#define sk_MIME_HEADER_push(st, val) SKM_sk_push(MIME_HEADER, (st), (val))
975#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val)) 747#define sk_MIME_HEADER_unshift(st, val) SKM_sk_unshift(MIME_HEADER, (st), (val))
976#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val)) 748#define sk_MIME_HEADER_find(st, val) SKM_sk_find(MIME_HEADER, (st), (val))
977#define sk_MIME_HEADER_find_ex(st, val) SKM_sk_find_ex(MIME_HEADER, (st), (val))
978#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i)) 749#define sk_MIME_HEADER_delete(st, i) SKM_sk_delete(MIME_HEADER, (st), (i))
979#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr)) 750#define sk_MIME_HEADER_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_HEADER, (st), (ptr))
980#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i)) 751#define sk_MIME_HEADER_insert(st, val, i) SKM_sk_insert(MIME_HEADER, (st), (val), (i))
@@ -996,7 +767,6 @@ STACK_OF(type) \
996#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val)) 767#define sk_MIME_PARAM_push(st, val) SKM_sk_push(MIME_PARAM, (st), (val))
997#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val)) 768#define sk_MIME_PARAM_unshift(st, val) SKM_sk_unshift(MIME_PARAM, (st), (val))
998#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val)) 769#define sk_MIME_PARAM_find(st, val) SKM_sk_find(MIME_PARAM, (st), (val))
999#define sk_MIME_PARAM_find_ex(st, val) SKM_sk_find_ex(MIME_PARAM, (st), (val))
1000#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i)) 770#define sk_MIME_PARAM_delete(st, i) SKM_sk_delete(MIME_PARAM, (st), (i))
1001#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr)) 771#define sk_MIME_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(MIME_PARAM, (st), (ptr))
1002#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i)) 772#define sk_MIME_PARAM_insert(st, val, i) SKM_sk_insert(MIME_PARAM, (st), (val), (i))
@@ -1018,7 +788,6 @@ STACK_OF(type) \
1018#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val)) 788#define sk_NAME_FUNCS_push(st, val) SKM_sk_push(NAME_FUNCS, (st), (val))
1019#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val)) 789#define sk_NAME_FUNCS_unshift(st, val) SKM_sk_unshift(NAME_FUNCS, (st), (val))
1020#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val)) 790#define sk_NAME_FUNCS_find(st, val) SKM_sk_find(NAME_FUNCS, (st), (val))
1021#define sk_NAME_FUNCS_find_ex(st, val) SKM_sk_find_ex(NAME_FUNCS, (st), (val))
1022#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i)) 791#define sk_NAME_FUNCS_delete(st, i) SKM_sk_delete(NAME_FUNCS, (st), (i))
1023#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr)) 792#define sk_NAME_FUNCS_delete_ptr(st, ptr) SKM_sk_delete_ptr(NAME_FUNCS, (st), (ptr))
1024#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i)) 793#define sk_NAME_FUNCS_insert(st, val, i) SKM_sk_insert(NAME_FUNCS, (st), (val), (i))
@@ -1040,7 +809,6 @@ STACK_OF(type) \
1040#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val)) 809#define sk_OCSP_CERTID_push(st, val) SKM_sk_push(OCSP_CERTID, (st), (val))
1041#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val)) 810#define sk_OCSP_CERTID_unshift(st, val) SKM_sk_unshift(OCSP_CERTID, (st), (val))
1042#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val)) 811#define sk_OCSP_CERTID_find(st, val) SKM_sk_find(OCSP_CERTID, (st), (val))
1043#define sk_OCSP_CERTID_find_ex(st, val) SKM_sk_find_ex(OCSP_CERTID, (st), (val))
1044#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i)) 812#define sk_OCSP_CERTID_delete(st, i) SKM_sk_delete(OCSP_CERTID, (st), (i))
1045#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr)) 813#define sk_OCSP_CERTID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_CERTID, (st), (ptr))
1046#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i)) 814#define sk_OCSP_CERTID_insert(st, val, i) SKM_sk_insert(OCSP_CERTID, (st), (val), (i))
@@ -1062,7 +830,6 @@ STACK_OF(type) \
1062#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val)) 830#define sk_OCSP_ONEREQ_push(st, val) SKM_sk_push(OCSP_ONEREQ, (st), (val))
1063#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val)) 831#define sk_OCSP_ONEREQ_unshift(st, val) SKM_sk_unshift(OCSP_ONEREQ, (st), (val))
1064#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val)) 832#define sk_OCSP_ONEREQ_find(st, val) SKM_sk_find(OCSP_ONEREQ, (st), (val))
1065#define sk_OCSP_ONEREQ_find_ex(st, val) SKM_sk_find_ex(OCSP_ONEREQ, (st), (val))
1066#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i)) 833#define sk_OCSP_ONEREQ_delete(st, i) SKM_sk_delete(OCSP_ONEREQ, (st), (i))
1067#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr)) 834#define sk_OCSP_ONEREQ_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_ONEREQ, (st), (ptr))
1068#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i)) 835#define sk_OCSP_ONEREQ_insert(st, val, i) SKM_sk_insert(OCSP_ONEREQ, (st), (val), (i))
@@ -1074,28 +841,6 @@ STACK_OF(type) \
1074#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st)) 841#define sk_OCSP_ONEREQ_sort(st) SKM_sk_sort(OCSP_ONEREQ, (st))
1075#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st)) 842#define sk_OCSP_ONEREQ_is_sorted(st) SKM_sk_is_sorted(OCSP_ONEREQ, (st))
1076 843
1077#define sk_OCSP_RESPID_new(st) SKM_sk_new(OCSP_RESPID, (st))
1078#define sk_OCSP_RESPID_new_null() SKM_sk_new_null(OCSP_RESPID)
1079#define sk_OCSP_RESPID_free(st) SKM_sk_free(OCSP_RESPID, (st))
1080#define sk_OCSP_RESPID_num(st) SKM_sk_num(OCSP_RESPID, (st))
1081#define sk_OCSP_RESPID_value(st, i) SKM_sk_value(OCSP_RESPID, (st), (i))
1082#define sk_OCSP_RESPID_set(st, i, val) SKM_sk_set(OCSP_RESPID, (st), (i), (val))
1083#define sk_OCSP_RESPID_zero(st) SKM_sk_zero(OCSP_RESPID, (st))
1084#define sk_OCSP_RESPID_push(st, val) SKM_sk_push(OCSP_RESPID, (st), (val))
1085#define sk_OCSP_RESPID_unshift(st, val) SKM_sk_unshift(OCSP_RESPID, (st), (val))
1086#define sk_OCSP_RESPID_find(st, val) SKM_sk_find(OCSP_RESPID, (st), (val))
1087#define sk_OCSP_RESPID_find_ex(st, val) SKM_sk_find_ex(OCSP_RESPID, (st), (val))
1088#define sk_OCSP_RESPID_delete(st, i) SKM_sk_delete(OCSP_RESPID, (st), (i))
1089#define sk_OCSP_RESPID_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_RESPID, (st), (ptr))
1090#define sk_OCSP_RESPID_insert(st, val, i) SKM_sk_insert(OCSP_RESPID, (st), (val), (i))
1091#define sk_OCSP_RESPID_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(OCSP_RESPID, (st), (cmp))
1092#define sk_OCSP_RESPID_dup(st) SKM_sk_dup(OCSP_RESPID, st)
1093#define sk_OCSP_RESPID_pop_free(st, free_func) SKM_sk_pop_free(OCSP_RESPID, (st), (free_func))
1094#define sk_OCSP_RESPID_shift(st) SKM_sk_shift(OCSP_RESPID, (st))
1095#define sk_OCSP_RESPID_pop(st) SKM_sk_pop(OCSP_RESPID, (st))
1096#define sk_OCSP_RESPID_sort(st) SKM_sk_sort(OCSP_RESPID, (st))
1097#define sk_OCSP_RESPID_is_sorted(st) SKM_sk_is_sorted(OCSP_RESPID, (st))
1098
1099#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st)) 844#define sk_OCSP_SINGLERESP_new(st) SKM_sk_new(OCSP_SINGLERESP, (st))
1100#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP) 845#define sk_OCSP_SINGLERESP_new_null() SKM_sk_new_null(OCSP_SINGLERESP)
1101#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st)) 846#define sk_OCSP_SINGLERESP_free(st) SKM_sk_free(OCSP_SINGLERESP, (st))
@@ -1106,7 +851,6 @@ STACK_OF(type) \
1106#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val)) 851#define sk_OCSP_SINGLERESP_push(st, val) SKM_sk_push(OCSP_SINGLERESP, (st), (val))
1107#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val)) 852#define sk_OCSP_SINGLERESP_unshift(st, val) SKM_sk_unshift(OCSP_SINGLERESP, (st), (val))
1108#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val)) 853#define sk_OCSP_SINGLERESP_find(st, val) SKM_sk_find(OCSP_SINGLERESP, (st), (val))
1109#define sk_OCSP_SINGLERESP_find_ex(st, val) SKM_sk_find_ex(OCSP_SINGLERESP, (st), (val))
1110#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i)) 854#define sk_OCSP_SINGLERESP_delete(st, i) SKM_sk_delete(OCSP_SINGLERESP, (st), (i))
1111#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr)) 855#define sk_OCSP_SINGLERESP_delete_ptr(st, ptr) SKM_sk_delete_ptr(OCSP_SINGLERESP, (st), (ptr))
1112#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i)) 856#define sk_OCSP_SINGLERESP_insert(st, val, i) SKM_sk_insert(OCSP_SINGLERESP, (st), (val), (i))
@@ -1128,7 +872,6 @@ STACK_OF(type) \
1128#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val)) 872#define sk_PKCS12_SAFEBAG_push(st, val) SKM_sk_push(PKCS12_SAFEBAG, (st), (val))
1129#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val)) 873#define sk_PKCS12_SAFEBAG_unshift(st, val) SKM_sk_unshift(PKCS12_SAFEBAG, (st), (val))
1130#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val)) 874#define sk_PKCS12_SAFEBAG_find(st, val) SKM_sk_find(PKCS12_SAFEBAG, (st), (val))
1131#define sk_PKCS12_SAFEBAG_find_ex(st, val) SKM_sk_find_ex(PKCS12_SAFEBAG, (st), (val))
1132#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i)) 875#define sk_PKCS12_SAFEBAG_delete(st, i) SKM_sk_delete(PKCS12_SAFEBAG, (st), (i))
1133#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr)) 876#define sk_PKCS12_SAFEBAG_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS12_SAFEBAG, (st), (ptr))
1134#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i)) 877#define sk_PKCS12_SAFEBAG_insert(st, val, i) SKM_sk_insert(PKCS12_SAFEBAG, (st), (val), (i))
@@ -1150,7 +893,6 @@ STACK_OF(type) \
1150#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val)) 893#define sk_PKCS7_push(st, val) SKM_sk_push(PKCS7, (st), (val))
1151#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val)) 894#define sk_PKCS7_unshift(st, val) SKM_sk_unshift(PKCS7, (st), (val))
1152#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val)) 895#define sk_PKCS7_find(st, val) SKM_sk_find(PKCS7, (st), (val))
1153#define sk_PKCS7_find_ex(st, val) SKM_sk_find_ex(PKCS7, (st), (val))
1154#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i)) 896#define sk_PKCS7_delete(st, i) SKM_sk_delete(PKCS7, (st), (i))
1155#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr)) 897#define sk_PKCS7_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7, (st), (ptr))
1156#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i)) 898#define sk_PKCS7_insert(st, val, i) SKM_sk_insert(PKCS7, (st), (val), (i))
@@ -1172,7 +914,6 @@ STACK_OF(type) \
1172#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val)) 914#define sk_PKCS7_RECIP_INFO_push(st, val) SKM_sk_push(PKCS7_RECIP_INFO, (st), (val))
1173#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val)) 915#define sk_PKCS7_RECIP_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_RECIP_INFO, (st), (val))
1174#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val)) 916#define sk_PKCS7_RECIP_INFO_find(st, val) SKM_sk_find(PKCS7_RECIP_INFO, (st), (val))
1175#define sk_PKCS7_RECIP_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_RECIP_INFO, (st), (val))
1176#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i)) 917#define sk_PKCS7_RECIP_INFO_delete(st, i) SKM_sk_delete(PKCS7_RECIP_INFO, (st), (i))
1177#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr)) 918#define sk_PKCS7_RECIP_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_RECIP_INFO, (st), (ptr))
1178#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i)) 919#define sk_PKCS7_RECIP_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_RECIP_INFO, (st), (val), (i))
@@ -1194,7 +935,6 @@ STACK_OF(type) \
1194#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val)) 935#define sk_PKCS7_SIGNER_INFO_push(st, val) SKM_sk_push(PKCS7_SIGNER_INFO, (st), (val))
1195#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val)) 936#define sk_PKCS7_SIGNER_INFO_unshift(st, val) SKM_sk_unshift(PKCS7_SIGNER_INFO, (st), (val))
1196#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val)) 937#define sk_PKCS7_SIGNER_INFO_find(st, val) SKM_sk_find(PKCS7_SIGNER_INFO, (st), (val))
1197#define sk_PKCS7_SIGNER_INFO_find_ex(st, val) SKM_sk_find_ex(PKCS7_SIGNER_INFO, (st), (val))
1198#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i)) 938#define sk_PKCS7_SIGNER_INFO_delete(st, i) SKM_sk_delete(PKCS7_SIGNER_INFO, (st), (i))
1199#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr)) 939#define sk_PKCS7_SIGNER_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(PKCS7_SIGNER_INFO, (st), (ptr))
1200#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i)) 940#define sk_PKCS7_SIGNER_INFO_insert(st, val, i) SKM_sk_insert(PKCS7_SIGNER_INFO, (st), (val), (i))
@@ -1216,7 +956,6 @@ STACK_OF(type) \
1216#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val)) 956#define sk_POLICYINFO_push(st, val) SKM_sk_push(POLICYINFO, (st), (val))
1217#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val)) 957#define sk_POLICYINFO_unshift(st, val) SKM_sk_unshift(POLICYINFO, (st), (val))
1218#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val)) 958#define sk_POLICYINFO_find(st, val) SKM_sk_find(POLICYINFO, (st), (val))
1219#define sk_POLICYINFO_find_ex(st, val) SKM_sk_find_ex(POLICYINFO, (st), (val))
1220#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i)) 959#define sk_POLICYINFO_delete(st, i) SKM_sk_delete(POLICYINFO, (st), (i))
1221#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr)) 960#define sk_POLICYINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYINFO, (st), (ptr))
1222#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i)) 961#define sk_POLICYINFO_insert(st, val, i) SKM_sk_insert(POLICYINFO, (st), (val), (i))
@@ -1238,7 +977,6 @@ STACK_OF(type) \
1238#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val)) 977#define sk_POLICYQUALINFO_push(st, val) SKM_sk_push(POLICYQUALINFO, (st), (val))
1239#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val)) 978#define sk_POLICYQUALINFO_unshift(st, val) SKM_sk_unshift(POLICYQUALINFO, (st), (val))
1240#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val)) 979#define sk_POLICYQUALINFO_find(st, val) SKM_sk_find(POLICYQUALINFO, (st), (val))
1241#define sk_POLICYQUALINFO_find_ex(st, val) SKM_sk_find_ex(POLICYQUALINFO, (st), (val))
1242#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i)) 980#define sk_POLICYQUALINFO_delete(st, i) SKM_sk_delete(POLICYQUALINFO, (st), (i))
1243#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr)) 981#define sk_POLICYQUALINFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICYQUALINFO, (st), (ptr))
1244#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i)) 982#define sk_POLICYQUALINFO_insert(st, val, i) SKM_sk_insert(POLICYQUALINFO, (st), (val), (i))
@@ -1250,28 +988,6 @@ STACK_OF(type) \
1250#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st)) 988#define sk_POLICYQUALINFO_sort(st) SKM_sk_sort(POLICYQUALINFO, (st))
1251#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st)) 989#define sk_POLICYQUALINFO_is_sorted(st) SKM_sk_is_sorted(POLICYQUALINFO, (st))
1252 990
1253#define sk_POLICY_MAPPING_new(st) SKM_sk_new(POLICY_MAPPING, (st))
1254#define sk_POLICY_MAPPING_new_null() SKM_sk_new_null(POLICY_MAPPING)
1255#define sk_POLICY_MAPPING_free(st) SKM_sk_free(POLICY_MAPPING, (st))
1256#define sk_POLICY_MAPPING_num(st) SKM_sk_num(POLICY_MAPPING, (st))
1257#define sk_POLICY_MAPPING_value(st, i) SKM_sk_value(POLICY_MAPPING, (st), (i))
1258#define sk_POLICY_MAPPING_set(st, i, val) SKM_sk_set(POLICY_MAPPING, (st), (i), (val))
1259#define sk_POLICY_MAPPING_zero(st) SKM_sk_zero(POLICY_MAPPING, (st))
1260#define sk_POLICY_MAPPING_push(st, val) SKM_sk_push(POLICY_MAPPING, (st), (val))
1261#define sk_POLICY_MAPPING_unshift(st, val) SKM_sk_unshift(POLICY_MAPPING, (st), (val))
1262#define sk_POLICY_MAPPING_find(st, val) SKM_sk_find(POLICY_MAPPING, (st), (val))
1263#define sk_POLICY_MAPPING_find_ex(st, val) SKM_sk_find_ex(POLICY_MAPPING, (st), (val))
1264#define sk_POLICY_MAPPING_delete(st, i) SKM_sk_delete(POLICY_MAPPING, (st), (i))
1265#define sk_POLICY_MAPPING_delete_ptr(st, ptr) SKM_sk_delete_ptr(POLICY_MAPPING, (st), (ptr))
1266#define sk_POLICY_MAPPING_insert(st, val, i) SKM_sk_insert(POLICY_MAPPING, (st), (val), (i))
1267#define sk_POLICY_MAPPING_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(POLICY_MAPPING, (st), (cmp))
1268#define sk_POLICY_MAPPING_dup(st) SKM_sk_dup(POLICY_MAPPING, st)
1269#define sk_POLICY_MAPPING_pop_free(st, free_func) SKM_sk_pop_free(POLICY_MAPPING, (st), (free_func))
1270#define sk_POLICY_MAPPING_shift(st) SKM_sk_shift(POLICY_MAPPING, (st))
1271#define sk_POLICY_MAPPING_pop(st) SKM_sk_pop(POLICY_MAPPING, (st))
1272#define sk_POLICY_MAPPING_sort(st) SKM_sk_sort(POLICY_MAPPING, (st))
1273#define sk_POLICY_MAPPING_is_sorted(st) SKM_sk_is_sorted(POLICY_MAPPING, (st))
1274
1275#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st)) 991#define sk_SSL_CIPHER_new(st) SKM_sk_new(SSL_CIPHER, (st))
1276#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER) 992#define sk_SSL_CIPHER_new_null() SKM_sk_new_null(SSL_CIPHER)
1277#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st)) 993#define sk_SSL_CIPHER_free(st) SKM_sk_free(SSL_CIPHER, (st))
@@ -1282,7 +998,6 @@ STACK_OF(type) \
1282#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val)) 998#define sk_SSL_CIPHER_push(st, val) SKM_sk_push(SSL_CIPHER, (st), (val))
1283#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val)) 999#define sk_SSL_CIPHER_unshift(st, val) SKM_sk_unshift(SSL_CIPHER, (st), (val))
1284#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val)) 1000#define sk_SSL_CIPHER_find(st, val) SKM_sk_find(SSL_CIPHER, (st), (val))
1285#define sk_SSL_CIPHER_find_ex(st, val) SKM_sk_find_ex(SSL_CIPHER, (st), (val))
1286#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i)) 1001#define sk_SSL_CIPHER_delete(st, i) SKM_sk_delete(SSL_CIPHER, (st), (i))
1287#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr)) 1002#define sk_SSL_CIPHER_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_CIPHER, (st), (ptr))
1288#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i)) 1003#define sk_SSL_CIPHER_insert(st, val, i) SKM_sk_insert(SSL_CIPHER, (st), (val), (i))
@@ -1304,7 +1019,6 @@ STACK_OF(type) \
1304#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val)) 1019#define sk_SSL_COMP_push(st, val) SKM_sk_push(SSL_COMP, (st), (val))
1305#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val)) 1020#define sk_SSL_COMP_unshift(st, val) SKM_sk_unshift(SSL_COMP, (st), (val))
1306#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val)) 1021#define sk_SSL_COMP_find(st, val) SKM_sk_find(SSL_COMP, (st), (val))
1307#define sk_SSL_COMP_find_ex(st, val) SKM_sk_find_ex(SSL_COMP, (st), (val))
1308#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i)) 1022#define sk_SSL_COMP_delete(st, i) SKM_sk_delete(SSL_COMP, (st), (i))
1309#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr)) 1023#define sk_SSL_COMP_delete_ptr(st, ptr) SKM_sk_delete_ptr(SSL_COMP, (st), (ptr))
1310#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i)) 1024#define sk_SSL_COMP_insert(st, val, i) SKM_sk_insert(SSL_COMP, (st), (val), (i))
@@ -1316,28 +1030,6 @@ STACK_OF(type) \
1316#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st)) 1030#define sk_SSL_COMP_sort(st) SKM_sk_sort(SSL_COMP, (st))
1317#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st)) 1031#define sk_SSL_COMP_is_sorted(st) SKM_sk_is_sorted(SSL_COMP, (st))
1318 1032
1319#define sk_STORE_OBJECT_new(st) SKM_sk_new(STORE_OBJECT, (st))
1320#define sk_STORE_OBJECT_new_null() SKM_sk_new_null(STORE_OBJECT)
1321#define sk_STORE_OBJECT_free(st) SKM_sk_free(STORE_OBJECT, (st))
1322#define sk_STORE_OBJECT_num(st) SKM_sk_num(STORE_OBJECT, (st))
1323#define sk_STORE_OBJECT_value(st, i) SKM_sk_value(STORE_OBJECT, (st), (i))
1324#define sk_STORE_OBJECT_set(st, i, val) SKM_sk_set(STORE_OBJECT, (st), (i), (val))
1325#define sk_STORE_OBJECT_zero(st) SKM_sk_zero(STORE_OBJECT, (st))
1326#define sk_STORE_OBJECT_push(st, val) SKM_sk_push(STORE_OBJECT, (st), (val))
1327#define sk_STORE_OBJECT_unshift(st, val) SKM_sk_unshift(STORE_OBJECT, (st), (val))
1328#define sk_STORE_OBJECT_find(st, val) SKM_sk_find(STORE_OBJECT, (st), (val))
1329#define sk_STORE_OBJECT_find_ex(st, val) SKM_sk_find_ex(STORE_OBJECT, (st), (val))
1330#define sk_STORE_OBJECT_delete(st, i) SKM_sk_delete(STORE_OBJECT, (st), (i))
1331#define sk_STORE_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(STORE_OBJECT, (st), (ptr))
1332#define sk_STORE_OBJECT_insert(st, val, i) SKM_sk_insert(STORE_OBJECT, (st), (val), (i))
1333#define sk_STORE_OBJECT_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(STORE_OBJECT, (st), (cmp))
1334#define sk_STORE_OBJECT_dup(st) SKM_sk_dup(STORE_OBJECT, st)
1335#define sk_STORE_OBJECT_pop_free(st, free_func) SKM_sk_pop_free(STORE_OBJECT, (st), (free_func))
1336#define sk_STORE_OBJECT_shift(st) SKM_sk_shift(STORE_OBJECT, (st))
1337#define sk_STORE_OBJECT_pop(st) SKM_sk_pop(STORE_OBJECT, (st))
1338#define sk_STORE_OBJECT_sort(st) SKM_sk_sort(STORE_OBJECT, (st))
1339#define sk_STORE_OBJECT_is_sorted(st) SKM_sk_is_sorted(STORE_OBJECT, (st))
1340
1341#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st)) 1033#define sk_SXNETID_new(st) SKM_sk_new(SXNETID, (st))
1342#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID) 1034#define sk_SXNETID_new_null() SKM_sk_new_null(SXNETID)
1343#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st)) 1035#define sk_SXNETID_free(st) SKM_sk_free(SXNETID, (st))
@@ -1348,7 +1040,6 @@ STACK_OF(type) \
1348#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val)) 1040#define sk_SXNETID_push(st, val) SKM_sk_push(SXNETID, (st), (val))
1349#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val)) 1041#define sk_SXNETID_unshift(st, val) SKM_sk_unshift(SXNETID, (st), (val))
1350#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val)) 1042#define sk_SXNETID_find(st, val) SKM_sk_find(SXNETID, (st), (val))
1351#define sk_SXNETID_find_ex(st, val) SKM_sk_find_ex(SXNETID, (st), (val))
1352#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i)) 1043#define sk_SXNETID_delete(st, i) SKM_sk_delete(SXNETID, (st), (i))
1353#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr)) 1044#define sk_SXNETID_delete_ptr(st, ptr) SKM_sk_delete_ptr(SXNETID, (st), (ptr))
1354#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i)) 1045#define sk_SXNETID_insert(st, val, i) SKM_sk_insert(SXNETID, (st), (val), (i))
@@ -1370,7 +1061,6 @@ STACK_OF(type) \
1370#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val)) 1061#define sk_UI_STRING_push(st, val) SKM_sk_push(UI_STRING, (st), (val))
1371#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val)) 1062#define sk_UI_STRING_unshift(st, val) SKM_sk_unshift(UI_STRING, (st), (val))
1372#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val)) 1063#define sk_UI_STRING_find(st, val) SKM_sk_find(UI_STRING, (st), (val))
1373#define sk_UI_STRING_find_ex(st, val) SKM_sk_find_ex(UI_STRING, (st), (val))
1374#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i)) 1064#define sk_UI_STRING_delete(st, i) SKM_sk_delete(UI_STRING, (st), (i))
1375#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr)) 1065#define sk_UI_STRING_delete_ptr(st, ptr) SKM_sk_delete_ptr(UI_STRING, (st), (ptr))
1376#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i)) 1066#define sk_UI_STRING_insert(st, val, i) SKM_sk_insert(UI_STRING, (st), (val), (i))
@@ -1392,7 +1082,6 @@ STACK_OF(type) \
1392#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val)) 1082#define sk_X509_push(st, val) SKM_sk_push(X509, (st), (val))
1393#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val)) 1083#define sk_X509_unshift(st, val) SKM_sk_unshift(X509, (st), (val))
1394#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val)) 1084#define sk_X509_find(st, val) SKM_sk_find(X509, (st), (val))
1395#define sk_X509_find_ex(st, val) SKM_sk_find_ex(X509, (st), (val))
1396#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i)) 1085#define sk_X509_delete(st, i) SKM_sk_delete(X509, (st), (i))
1397#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr)) 1086#define sk_X509_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509, (st), (ptr))
1398#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i)) 1087#define sk_X509_insert(st, val, i) SKM_sk_insert(X509, (st), (val), (i))
@@ -1414,7 +1103,6 @@ STACK_OF(type) \
1414#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val)) 1103#define sk_X509V3_EXT_METHOD_push(st, val) SKM_sk_push(X509V3_EXT_METHOD, (st), (val))
1415#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val)) 1104#define sk_X509V3_EXT_METHOD_unshift(st, val) SKM_sk_unshift(X509V3_EXT_METHOD, (st), (val))
1416#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val)) 1105#define sk_X509V3_EXT_METHOD_find(st, val) SKM_sk_find(X509V3_EXT_METHOD, (st), (val))
1417#define sk_X509V3_EXT_METHOD_find_ex(st, val) SKM_sk_find_ex(X509V3_EXT_METHOD, (st), (val))
1418#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i)) 1106#define sk_X509V3_EXT_METHOD_delete(st, i) SKM_sk_delete(X509V3_EXT_METHOD, (st), (i))
1419#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr)) 1107#define sk_X509V3_EXT_METHOD_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509V3_EXT_METHOD, (st), (ptr))
1420#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i)) 1108#define sk_X509V3_EXT_METHOD_insert(st, val, i) SKM_sk_insert(X509V3_EXT_METHOD, (st), (val), (i))
@@ -1436,7 +1124,6 @@ STACK_OF(type) \
1436#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val)) 1124#define sk_X509_ALGOR_push(st, val) SKM_sk_push(X509_ALGOR, (st), (val))
1437#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val)) 1125#define sk_X509_ALGOR_unshift(st, val) SKM_sk_unshift(X509_ALGOR, (st), (val))
1438#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val)) 1126#define sk_X509_ALGOR_find(st, val) SKM_sk_find(X509_ALGOR, (st), (val))
1439#define sk_X509_ALGOR_find_ex(st, val) SKM_sk_find_ex(X509_ALGOR, (st), (val))
1440#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i)) 1127#define sk_X509_ALGOR_delete(st, i) SKM_sk_delete(X509_ALGOR, (st), (i))
1441#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr)) 1128#define sk_X509_ALGOR_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ALGOR, (st), (ptr))
1442#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i)) 1129#define sk_X509_ALGOR_insert(st, val, i) SKM_sk_insert(X509_ALGOR, (st), (val), (i))
@@ -1458,7 +1145,6 @@ STACK_OF(type) \
1458#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val)) 1145#define sk_X509_ATTRIBUTE_push(st, val) SKM_sk_push(X509_ATTRIBUTE, (st), (val))
1459#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val)) 1146#define sk_X509_ATTRIBUTE_unshift(st, val) SKM_sk_unshift(X509_ATTRIBUTE, (st), (val))
1460#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val)) 1147#define sk_X509_ATTRIBUTE_find(st, val) SKM_sk_find(X509_ATTRIBUTE, (st), (val))
1461#define sk_X509_ATTRIBUTE_find_ex(st, val) SKM_sk_find_ex(X509_ATTRIBUTE, (st), (val))
1462#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i)) 1148#define sk_X509_ATTRIBUTE_delete(st, i) SKM_sk_delete(X509_ATTRIBUTE, (st), (i))
1463#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr)) 1149#define sk_X509_ATTRIBUTE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_ATTRIBUTE, (st), (ptr))
1464#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i)) 1150#define sk_X509_ATTRIBUTE_insert(st, val, i) SKM_sk_insert(X509_ATTRIBUTE, (st), (val), (i))
@@ -1480,7 +1166,6 @@ STACK_OF(type) \
1480#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val)) 1166#define sk_X509_CRL_push(st, val) SKM_sk_push(X509_CRL, (st), (val))
1481#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val)) 1167#define sk_X509_CRL_unshift(st, val) SKM_sk_unshift(X509_CRL, (st), (val))
1482#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val)) 1168#define sk_X509_CRL_find(st, val) SKM_sk_find(X509_CRL, (st), (val))
1483#define sk_X509_CRL_find_ex(st, val) SKM_sk_find_ex(X509_CRL, (st), (val))
1484#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i)) 1169#define sk_X509_CRL_delete(st, i) SKM_sk_delete(X509_CRL, (st), (i))
1485#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr)) 1170#define sk_X509_CRL_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_CRL, (st), (ptr))
1486#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i)) 1171#define sk_X509_CRL_insert(st, val, i) SKM_sk_insert(X509_CRL, (st), (val), (i))
@@ -1502,7 +1187,6 @@ STACK_OF(type) \
1502#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val)) 1187#define sk_X509_EXTENSION_push(st, val) SKM_sk_push(X509_EXTENSION, (st), (val))
1503#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val)) 1188#define sk_X509_EXTENSION_unshift(st, val) SKM_sk_unshift(X509_EXTENSION, (st), (val))
1504#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val)) 1189#define sk_X509_EXTENSION_find(st, val) SKM_sk_find(X509_EXTENSION, (st), (val))
1505#define sk_X509_EXTENSION_find_ex(st, val) SKM_sk_find_ex(X509_EXTENSION, (st), (val))
1506#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i)) 1190#define sk_X509_EXTENSION_delete(st, i) SKM_sk_delete(X509_EXTENSION, (st), (i))
1507#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr)) 1191#define sk_X509_EXTENSION_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_EXTENSION, (st), (ptr))
1508#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i)) 1192#define sk_X509_EXTENSION_insert(st, val, i) SKM_sk_insert(X509_EXTENSION, (st), (val), (i))
@@ -1524,7 +1208,6 @@ STACK_OF(type) \
1524#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val)) 1208#define sk_X509_INFO_push(st, val) SKM_sk_push(X509_INFO, (st), (val))
1525#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val)) 1209#define sk_X509_INFO_unshift(st, val) SKM_sk_unshift(X509_INFO, (st), (val))
1526#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val)) 1210#define sk_X509_INFO_find(st, val) SKM_sk_find(X509_INFO, (st), (val))
1527#define sk_X509_INFO_find_ex(st, val) SKM_sk_find_ex(X509_INFO, (st), (val))
1528#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i)) 1211#define sk_X509_INFO_delete(st, i) SKM_sk_delete(X509_INFO, (st), (i))
1529#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr)) 1212#define sk_X509_INFO_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_INFO, (st), (ptr))
1530#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i)) 1213#define sk_X509_INFO_insert(st, val, i) SKM_sk_insert(X509_INFO, (st), (val), (i))
@@ -1546,7 +1229,6 @@ STACK_OF(type) \
1546#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val)) 1229#define sk_X509_LOOKUP_push(st, val) SKM_sk_push(X509_LOOKUP, (st), (val))
1547#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val)) 1230#define sk_X509_LOOKUP_unshift(st, val) SKM_sk_unshift(X509_LOOKUP, (st), (val))
1548#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val)) 1231#define sk_X509_LOOKUP_find(st, val) SKM_sk_find(X509_LOOKUP, (st), (val))
1549#define sk_X509_LOOKUP_find_ex(st, val) SKM_sk_find_ex(X509_LOOKUP, (st), (val))
1550#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i)) 1232#define sk_X509_LOOKUP_delete(st, i) SKM_sk_delete(X509_LOOKUP, (st), (i))
1551#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr)) 1233#define sk_X509_LOOKUP_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_LOOKUP, (st), (ptr))
1552#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i)) 1234#define sk_X509_LOOKUP_insert(st, val, i) SKM_sk_insert(X509_LOOKUP, (st), (val), (i))
@@ -1568,7 +1250,6 @@ STACK_OF(type) \
1568#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val)) 1250#define sk_X509_NAME_push(st, val) SKM_sk_push(X509_NAME, (st), (val))
1569#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val)) 1251#define sk_X509_NAME_unshift(st, val) SKM_sk_unshift(X509_NAME, (st), (val))
1570#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val)) 1252#define sk_X509_NAME_find(st, val) SKM_sk_find(X509_NAME, (st), (val))
1571#define sk_X509_NAME_find_ex(st, val) SKM_sk_find_ex(X509_NAME, (st), (val))
1572#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i)) 1253#define sk_X509_NAME_delete(st, i) SKM_sk_delete(X509_NAME, (st), (i))
1573#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr)) 1254#define sk_X509_NAME_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME, (st), (ptr))
1574#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i)) 1255#define sk_X509_NAME_insert(st, val, i) SKM_sk_insert(X509_NAME, (st), (val), (i))
@@ -1590,7 +1271,6 @@ STACK_OF(type) \
1590#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val)) 1271#define sk_X509_NAME_ENTRY_push(st, val) SKM_sk_push(X509_NAME_ENTRY, (st), (val))
1591#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val)) 1272#define sk_X509_NAME_ENTRY_unshift(st, val) SKM_sk_unshift(X509_NAME_ENTRY, (st), (val))
1592#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val)) 1273#define sk_X509_NAME_ENTRY_find(st, val) SKM_sk_find(X509_NAME_ENTRY, (st), (val))
1593#define sk_X509_NAME_ENTRY_find_ex(st, val) SKM_sk_find_ex(X509_NAME_ENTRY, (st), (val))
1594#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i)) 1274#define sk_X509_NAME_ENTRY_delete(st, i) SKM_sk_delete(X509_NAME_ENTRY, (st), (i))
1595#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr)) 1275#define sk_X509_NAME_ENTRY_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_NAME_ENTRY, (st), (ptr))
1596#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i)) 1276#define sk_X509_NAME_ENTRY_insert(st, val, i) SKM_sk_insert(X509_NAME_ENTRY, (st), (val), (i))
@@ -1612,7 +1292,6 @@ STACK_OF(type) \
1612#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val)) 1292#define sk_X509_OBJECT_push(st, val) SKM_sk_push(X509_OBJECT, (st), (val))
1613#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val)) 1293#define sk_X509_OBJECT_unshift(st, val) SKM_sk_unshift(X509_OBJECT, (st), (val))
1614#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val)) 1294#define sk_X509_OBJECT_find(st, val) SKM_sk_find(X509_OBJECT, (st), (val))
1615#define sk_X509_OBJECT_find_ex(st, val) SKM_sk_find_ex(X509_OBJECT, (st), (val))
1616#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i)) 1295#define sk_X509_OBJECT_delete(st, i) SKM_sk_delete(X509_OBJECT, (st), (i))
1617#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr)) 1296#define sk_X509_OBJECT_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_OBJECT, (st), (ptr))
1618#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i)) 1297#define sk_X509_OBJECT_insert(st, val, i) SKM_sk_insert(X509_OBJECT, (st), (val), (i))
@@ -1624,72 +1303,6 @@ STACK_OF(type) \
1624#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st)) 1303#define sk_X509_OBJECT_sort(st) SKM_sk_sort(X509_OBJECT, (st))
1625#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st)) 1304#define sk_X509_OBJECT_is_sorted(st) SKM_sk_is_sorted(X509_OBJECT, (st))
1626 1305
1627#define sk_X509_POLICY_DATA_new(st) SKM_sk_new(X509_POLICY_DATA, (st))
1628#define sk_X509_POLICY_DATA_new_null() SKM_sk_new_null(X509_POLICY_DATA)
1629#define sk_X509_POLICY_DATA_free(st) SKM_sk_free(X509_POLICY_DATA, (st))
1630#define sk_X509_POLICY_DATA_num(st) SKM_sk_num(X509_POLICY_DATA, (st))
1631#define sk_X509_POLICY_DATA_value(st, i) SKM_sk_value(X509_POLICY_DATA, (st), (i))
1632#define sk_X509_POLICY_DATA_set(st, i, val) SKM_sk_set(X509_POLICY_DATA, (st), (i), (val))
1633#define sk_X509_POLICY_DATA_zero(st) SKM_sk_zero(X509_POLICY_DATA, (st))
1634#define sk_X509_POLICY_DATA_push(st, val) SKM_sk_push(X509_POLICY_DATA, (st), (val))
1635#define sk_X509_POLICY_DATA_unshift(st, val) SKM_sk_unshift(X509_POLICY_DATA, (st), (val))
1636#define sk_X509_POLICY_DATA_find(st, val) SKM_sk_find(X509_POLICY_DATA, (st), (val))
1637#define sk_X509_POLICY_DATA_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_DATA, (st), (val))
1638#define sk_X509_POLICY_DATA_delete(st, i) SKM_sk_delete(X509_POLICY_DATA, (st), (i))
1639#define sk_X509_POLICY_DATA_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_DATA, (st), (ptr))
1640#define sk_X509_POLICY_DATA_insert(st, val, i) SKM_sk_insert(X509_POLICY_DATA, (st), (val), (i))
1641#define sk_X509_POLICY_DATA_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_DATA, (st), (cmp))
1642#define sk_X509_POLICY_DATA_dup(st) SKM_sk_dup(X509_POLICY_DATA, st)
1643#define sk_X509_POLICY_DATA_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_DATA, (st), (free_func))
1644#define sk_X509_POLICY_DATA_shift(st) SKM_sk_shift(X509_POLICY_DATA, (st))
1645#define sk_X509_POLICY_DATA_pop(st) SKM_sk_pop(X509_POLICY_DATA, (st))
1646#define sk_X509_POLICY_DATA_sort(st) SKM_sk_sort(X509_POLICY_DATA, (st))
1647#define sk_X509_POLICY_DATA_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_DATA, (st))
1648
1649#define sk_X509_POLICY_NODE_new(st) SKM_sk_new(X509_POLICY_NODE, (st))
1650#define sk_X509_POLICY_NODE_new_null() SKM_sk_new_null(X509_POLICY_NODE)
1651#define sk_X509_POLICY_NODE_free(st) SKM_sk_free(X509_POLICY_NODE, (st))
1652#define sk_X509_POLICY_NODE_num(st) SKM_sk_num(X509_POLICY_NODE, (st))
1653#define sk_X509_POLICY_NODE_value(st, i) SKM_sk_value(X509_POLICY_NODE, (st), (i))
1654#define sk_X509_POLICY_NODE_set(st, i, val) SKM_sk_set(X509_POLICY_NODE, (st), (i), (val))
1655#define sk_X509_POLICY_NODE_zero(st) SKM_sk_zero(X509_POLICY_NODE, (st))
1656#define sk_X509_POLICY_NODE_push(st, val) SKM_sk_push(X509_POLICY_NODE, (st), (val))
1657#define sk_X509_POLICY_NODE_unshift(st, val) SKM_sk_unshift(X509_POLICY_NODE, (st), (val))
1658#define sk_X509_POLICY_NODE_find(st, val) SKM_sk_find(X509_POLICY_NODE, (st), (val))
1659#define sk_X509_POLICY_NODE_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_NODE, (st), (val))
1660#define sk_X509_POLICY_NODE_delete(st, i) SKM_sk_delete(X509_POLICY_NODE, (st), (i))
1661#define sk_X509_POLICY_NODE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_NODE, (st), (ptr))
1662#define sk_X509_POLICY_NODE_insert(st, val, i) SKM_sk_insert(X509_POLICY_NODE, (st), (val), (i))
1663#define sk_X509_POLICY_NODE_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_NODE, (st), (cmp))
1664#define sk_X509_POLICY_NODE_dup(st) SKM_sk_dup(X509_POLICY_NODE, st)
1665#define sk_X509_POLICY_NODE_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_NODE, (st), (free_func))
1666#define sk_X509_POLICY_NODE_shift(st) SKM_sk_shift(X509_POLICY_NODE, (st))
1667#define sk_X509_POLICY_NODE_pop(st) SKM_sk_pop(X509_POLICY_NODE, (st))
1668#define sk_X509_POLICY_NODE_sort(st) SKM_sk_sort(X509_POLICY_NODE, (st))
1669#define sk_X509_POLICY_NODE_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_NODE, (st))
1670
1671#define sk_X509_POLICY_REF_new(st) SKM_sk_new(X509_POLICY_REF, (st))
1672#define sk_X509_POLICY_REF_new_null() SKM_sk_new_null(X509_POLICY_REF)
1673#define sk_X509_POLICY_REF_free(st) SKM_sk_free(X509_POLICY_REF, (st))
1674#define sk_X509_POLICY_REF_num(st) SKM_sk_num(X509_POLICY_REF, (st))
1675#define sk_X509_POLICY_REF_value(st, i) SKM_sk_value(X509_POLICY_REF, (st), (i))
1676#define sk_X509_POLICY_REF_set(st, i, val) SKM_sk_set(X509_POLICY_REF, (st), (i), (val))
1677#define sk_X509_POLICY_REF_zero(st) SKM_sk_zero(X509_POLICY_REF, (st))
1678#define sk_X509_POLICY_REF_push(st, val) SKM_sk_push(X509_POLICY_REF, (st), (val))
1679#define sk_X509_POLICY_REF_unshift(st, val) SKM_sk_unshift(X509_POLICY_REF, (st), (val))
1680#define sk_X509_POLICY_REF_find(st, val) SKM_sk_find(X509_POLICY_REF, (st), (val))
1681#define sk_X509_POLICY_REF_find_ex(st, val) SKM_sk_find_ex(X509_POLICY_REF, (st), (val))
1682#define sk_X509_POLICY_REF_delete(st, i) SKM_sk_delete(X509_POLICY_REF, (st), (i))
1683#define sk_X509_POLICY_REF_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_POLICY_REF, (st), (ptr))
1684#define sk_X509_POLICY_REF_insert(st, val, i) SKM_sk_insert(X509_POLICY_REF, (st), (val), (i))
1685#define sk_X509_POLICY_REF_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_POLICY_REF, (st), (cmp))
1686#define sk_X509_POLICY_REF_dup(st) SKM_sk_dup(X509_POLICY_REF, st)
1687#define sk_X509_POLICY_REF_pop_free(st, free_func) SKM_sk_pop_free(X509_POLICY_REF, (st), (free_func))
1688#define sk_X509_POLICY_REF_shift(st) SKM_sk_shift(X509_POLICY_REF, (st))
1689#define sk_X509_POLICY_REF_pop(st) SKM_sk_pop(X509_POLICY_REF, (st))
1690#define sk_X509_POLICY_REF_sort(st) SKM_sk_sort(X509_POLICY_REF, (st))
1691#define sk_X509_POLICY_REF_is_sorted(st) SKM_sk_is_sorted(X509_POLICY_REF, (st))
1692
1693#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st)) 1306#define sk_X509_PURPOSE_new(st) SKM_sk_new(X509_PURPOSE, (st))
1694#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE) 1307#define sk_X509_PURPOSE_new_null() SKM_sk_new_null(X509_PURPOSE)
1695#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st)) 1308#define sk_X509_PURPOSE_free(st) SKM_sk_free(X509_PURPOSE, (st))
@@ -1700,7 +1313,6 @@ STACK_OF(type) \
1700#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val)) 1313#define sk_X509_PURPOSE_push(st, val) SKM_sk_push(X509_PURPOSE, (st), (val))
1701#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val)) 1314#define sk_X509_PURPOSE_unshift(st, val) SKM_sk_unshift(X509_PURPOSE, (st), (val))
1702#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val)) 1315#define sk_X509_PURPOSE_find(st, val) SKM_sk_find(X509_PURPOSE, (st), (val))
1703#define sk_X509_PURPOSE_find_ex(st, val) SKM_sk_find_ex(X509_PURPOSE, (st), (val))
1704#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i)) 1316#define sk_X509_PURPOSE_delete(st, i) SKM_sk_delete(X509_PURPOSE, (st), (i))
1705#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr)) 1317#define sk_X509_PURPOSE_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_PURPOSE, (st), (ptr))
1706#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i)) 1318#define sk_X509_PURPOSE_insert(st, val, i) SKM_sk_insert(X509_PURPOSE, (st), (val), (i))
@@ -1722,7 +1334,6 @@ STACK_OF(type) \
1722#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val)) 1334#define sk_X509_REVOKED_push(st, val) SKM_sk_push(X509_REVOKED, (st), (val))
1723#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val)) 1335#define sk_X509_REVOKED_unshift(st, val) SKM_sk_unshift(X509_REVOKED, (st), (val))
1724#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val)) 1336#define sk_X509_REVOKED_find(st, val) SKM_sk_find(X509_REVOKED, (st), (val))
1725#define sk_X509_REVOKED_find_ex(st, val) SKM_sk_find_ex(X509_REVOKED, (st), (val))
1726#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i)) 1337#define sk_X509_REVOKED_delete(st, i) SKM_sk_delete(X509_REVOKED, (st), (i))
1727#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr)) 1338#define sk_X509_REVOKED_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_REVOKED, (st), (ptr))
1728#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i)) 1339#define sk_X509_REVOKED_insert(st, val, i) SKM_sk_insert(X509_REVOKED, (st), (val), (i))
@@ -1744,7 +1355,6 @@ STACK_OF(type) \
1744#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val)) 1355#define sk_X509_TRUST_push(st, val) SKM_sk_push(X509_TRUST, (st), (val))
1745#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val)) 1356#define sk_X509_TRUST_unshift(st, val) SKM_sk_unshift(X509_TRUST, (st), (val))
1746#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val)) 1357#define sk_X509_TRUST_find(st, val) SKM_sk_find(X509_TRUST, (st), (val))
1747#define sk_X509_TRUST_find_ex(st, val) SKM_sk_find_ex(X509_TRUST, (st), (val))
1748#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i)) 1358#define sk_X509_TRUST_delete(st, i) SKM_sk_delete(X509_TRUST, (st), (i))
1749#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr)) 1359#define sk_X509_TRUST_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_TRUST, (st), (ptr))
1750#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i)) 1360#define sk_X509_TRUST_insert(st, val, i) SKM_sk_insert(X509_TRUST, (st), (val), (i))
@@ -1756,28 +1366,6 @@ STACK_OF(type) \
1756#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st)) 1366#define sk_X509_TRUST_sort(st) SKM_sk_sort(X509_TRUST, (st))
1757#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st)) 1367#define sk_X509_TRUST_is_sorted(st) SKM_sk_is_sorted(X509_TRUST, (st))
1758 1368
1759#define sk_X509_VERIFY_PARAM_new(st) SKM_sk_new(X509_VERIFY_PARAM, (st))
1760#define sk_X509_VERIFY_PARAM_new_null() SKM_sk_new_null(X509_VERIFY_PARAM)
1761#define sk_X509_VERIFY_PARAM_free(st) SKM_sk_free(X509_VERIFY_PARAM, (st))
1762#define sk_X509_VERIFY_PARAM_num(st) SKM_sk_num(X509_VERIFY_PARAM, (st))
1763#define sk_X509_VERIFY_PARAM_value(st, i) SKM_sk_value(X509_VERIFY_PARAM, (st), (i))
1764#define sk_X509_VERIFY_PARAM_set(st, i, val) SKM_sk_set(X509_VERIFY_PARAM, (st), (i), (val))
1765#define sk_X509_VERIFY_PARAM_zero(st) SKM_sk_zero(X509_VERIFY_PARAM, (st))
1766#define sk_X509_VERIFY_PARAM_push(st, val) SKM_sk_push(X509_VERIFY_PARAM, (st), (val))
1767#define sk_X509_VERIFY_PARAM_unshift(st, val) SKM_sk_unshift(X509_VERIFY_PARAM, (st), (val))
1768#define sk_X509_VERIFY_PARAM_find(st, val) SKM_sk_find(X509_VERIFY_PARAM, (st), (val))
1769#define sk_X509_VERIFY_PARAM_find_ex(st, val) SKM_sk_find_ex(X509_VERIFY_PARAM, (st), (val))
1770#define sk_X509_VERIFY_PARAM_delete(st, i) SKM_sk_delete(X509_VERIFY_PARAM, (st), (i))
1771#define sk_X509_VERIFY_PARAM_delete_ptr(st, ptr) SKM_sk_delete_ptr(X509_VERIFY_PARAM, (st), (ptr))
1772#define sk_X509_VERIFY_PARAM_insert(st, val, i) SKM_sk_insert(X509_VERIFY_PARAM, (st), (val), (i))
1773#define sk_X509_VERIFY_PARAM_set_cmp_func(st, cmp) SKM_sk_set_cmp_func(X509_VERIFY_PARAM, (st), (cmp))
1774#define sk_X509_VERIFY_PARAM_dup(st) SKM_sk_dup(X509_VERIFY_PARAM, st)
1775#define sk_X509_VERIFY_PARAM_pop_free(st, free_func) SKM_sk_pop_free(X509_VERIFY_PARAM, (st), (free_func))
1776#define sk_X509_VERIFY_PARAM_shift(st) SKM_sk_shift(X509_VERIFY_PARAM, (st))
1777#define sk_X509_VERIFY_PARAM_pop(st) SKM_sk_pop(X509_VERIFY_PARAM, (st))
1778#define sk_X509_VERIFY_PARAM_sort(st) SKM_sk_sort(X509_VERIFY_PARAM, (st))
1779#define sk_X509_VERIFY_PARAM_is_sorted(st) SKM_sk_is_sorted(X509_VERIFY_PARAM, (st))
1780
1781#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \ 1369#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, length, d2i_func, free_func, ex_tag, ex_class) \
1782 SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class)) 1370 SKM_ASN1_SET_OF_d2i(ACCESS_DESCRIPTION, (st), (pp), (length), (d2i_func), (free_func), (ex_tag), (ex_class))
1783#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \ 1371#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION(st, pp, i2d_func, ex_tag, ex_class, is_set) \
diff --git a/src/lib/libcrypto/stack/stack.c b/src/lib/libcrypto/stack/stack.c
index 378bd7c796..c7173eb6ab 100644
--- a/src/lib/libcrypto/stack/stack.c
+++ b/src/lib/libcrypto/stack/stack.c
@@ -68,12 +68,11 @@
68#include <stdio.h> 68#include <stdio.h>
69#include "cryptlib.h" 69#include "cryptlib.h"
70#include <openssl/stack.h> 70#include <openssl/stack.h>
71#include <openssl/objects.h>
72 71
73#undef MIN_NODES 72#undef MIN_NODES
74#define MIN_NODES 4 73#define MIN_NODES 4
75 74
76const char STACK_version[]="Stack" OPENSSL_VERSION_PTEXT; 75const char *STACK_version="Stack" OPENSSL_VERSION_PTEXT;
77 76
78#include <errno.h> 77#include <errno.h>
79 78
@@ -210,7 +209,7 @@ char *sk_delete(STACK *st, int loc)
210 return(ret); 209 return(ret);
211 } 210 }
212 211
213static int internal_find(STACK *st, char *data, int ret_val_options) 212int sk_find(STACK *st, char *data)
214 { 213 {
215 char **r; 214 char **r;
216 int i; 215 int i;
@@ -233,19 +232,19 @@ static int internal_find(STACK *st, char *data, int ret_val_options)
233 * not (type *) pointers, but the *pointers* to (type *) pointers, 232 * not (type *) pointers, but the *pointers* to (type *) pointers,
234 * so we get our extra level of pointer dereferencing that way. */ 233 * so we get our extra level of pointer dereferencing that way. */
235 comp_func=(int (*)(const void *,const void *))(st->comp); 234 comp_func=(int (*)(const void *,const void *))(st->comp);
236 r=(char **)OBJ_bsearch_ex((char *)&data,(char *)st->data, 235 r=(char **)bsearch(&data,(char *)st->data,
237 st->num,sizeof(char *),comp_func,ret_val_options); 236 st->num,sizeof(char *), comp_func);
238 if (r == NULL) return(-1); 237 if (r == NULL) return(-1);
239 return((int)(r-st->data)); 238 i=(int)(r-st->data);
240 } 239 for ( ; i>0; i--)
241 240 /* This needs a cast because the type being pointed to from
242int sk_find(STACK *st, char *data) 241 * the "&" expressions are (char *) rather than (const char *).
243 { 242 * For an explanation, read:
244 return internal_find(st, data, OBJ_BSEARCH_FIRST_VALUE_ON_MATCH); 243 * http://www.eskimo.com/~scs/C-faq/q11.10.html :-) */
245 } 244 if ((*st->comp)((const char * const *)&(st->data[i-1]),
246int sk_find_ex(STACK *st, char *data) 245 (const char * const *)&data) < 0)
247 { 246 break;
248 return internal_find(st, data, OBJ_BSEARCH_VALUE_ON_NOMATCH); 247 return(i);
249 } 248 }
250 249
251int sk_push(STACK *st, char *data) 250int sk_push(STACK *st, char *data)
diff --git a/src/lib/libcrypto/stack/stack.h b/src/lib/libcrypto/stack/stack.h
index 5cbb116a8b..7570b85fe8 100644
--- a/src/lib/libcrypto/stack/stack.h
+++ b/src/lib/libcrypto/stack/stack.h
@@ -89,7 +89,6 @@ int sk_insert(STACK *sk,char *data,int where);
89char *sk_delete(STACK *st,int loc); 89char *sk_delete(STACK *st,int loc);
90char *sk_delete_ptr(STACK *st, char *p); 90char *sk_delete_ptr(STACK *st, char *p);
91int sk_find(STACK *st,char *data); 91int sk_find(STACK *st,char *data);
92int sk_find_ex(STACK *st,char *data);
93int sk_push(STACK *st,char *data); 92int sk_push(STACK *st,char *data);
94int sk_unshift(STACK *st,char *data); 93int sk_unshift(STACK *st,char *data);
95char *sk_shift(STACK *st); 94char *sk_shift(STACK *st);
diff --git a/src/lib/libcrypto/store/Makefile b/src/lib/libcrypto/store/Makefile
new file mode 100644
index 0000000000..0dcfd7857a
--- /dev/null
+++ b/src/lib/libcrypto/store/Makefile
@@ -0,0 +1,112 @@
1#
2# OpenSSL/crypto/store/Makefile
3#
4
5DIR= store
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16#TEST= storetest.c
17TEST=
18APPS=
19
20LIB=$(TOP)/libcrypto.a
21LIBSRC= str_err.c str_lib.c str_meth.c str_mem.c
22LIBOBJ= str_err.o str_lib.o str_meth.o str_mem.o
23
24SRC= $(LIBSRC)
25
26#EXHEADER= store.h str_compat.h
27EXHEADER= store.h
28HEADER= $(EXHEADER) str_locl.h
29
30ALL= $(GENERAL) $(SRC) $(HEADER)
31
32top:
33 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
34
35all: lib
36
37lib: $(LIBOBJ)
38 $(AR) $(LIB) $(LIBOBJ)
39 $(RANLIB) $(LIB) || echo Never mind.
40 @touch lib
41
42files:
43 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
44
45links:
46 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
47 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
48 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
49
50install:
51 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
52 @headerlist="$(EXHEADER)"; for i in $$headerlist; \
53 do \
54 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
55 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
56 done;
57
58tags:
59 ctags $(SRC)
60
61tests:
62
63lint:
64 lint -DLINT $(INCLUDES) $(SRC)>fluff
65
66depend:
67 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
68 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
69
70dclean:
71 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
72 mv -f Makefile.new $(MAKEFILE)
73
74clean:
75 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
76
77# DO NOT DELETE THIS LINE -- make depend depends on it.
78
79str_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
80str_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
81str_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
82str_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
83str_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
84str_err.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h
85str_err.o: str_err.c
86str_lib.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
87str_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
88str_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
89str_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
90str_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/engine.h
91str_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
92str_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
93str_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
94str_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
95str_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
96str_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
97str_lib.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h
98str_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
99str_lib.o: str_lib.c str_locl.h
100str_mem.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
101str_mem.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102str_mem.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
103str_mem.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
104str_mem.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
105str_mem.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h
106str_mem.o: str_locl.h str_mem.c
107str_meth.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
108str_meth.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
109str_meth.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
110str_meth.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
111str_meth.o: ../../include/openssl/store.h ../../include/openssl/symhacks.h
112str_meth.o: str_locl.h str_meth.c
diff --git a/src/lib/libcrypto/store/README b/src/lib/libcrypto/store/README
new file mode 100644
index 0000000000..966168f6a5
--- /dev/null
+++ b/src/lib/libcrypto/store/README
@@ -0,0 +1,95 @@
1The STORE type
2==============
3
4A STORE, as defined in this code section, is really a rather simple
5thing which stores objects and per-object associations to a number
6of attributes. What attributes are supported entirely depends on
7the particular implementation of a STORE. It has some support for
8generation of certain objects (for example, keys and CRLs).
9
10
11Supported object types
12----------------------
13
14For now, the objects that are supported are the following:
15
16X.509 certificate
17X.509 CRL
18private key
19public key
20number
21arbitrary (application) data
22
23The intention is that a STORE should be able to store everything
24needed by an application that wants a cert/key store, as well as
25the data a CA might need to store (this includes the serial number
26counter, which explains the support for numbers).
27
28
29Supported attribute types
30-------------------------
31
32For now, the following attributes are supported:
33
34Friendly Name - the value is a normal C string
35Key ID - the value is a 160 bit SHA1 hash
36Issuer Key ID - the value is a 160 bit SHA1 hash
37Subject Key ID - the value is a 160 bit SHA1 hash
38Issuer/Serial Hash - the value is a 160 bit SHA1 hash
39Issuer - the value is a X509_NAME
40Serial - the value is a BIGNUM
41Subject - the value is a X509_NAME
42Certificate Hash - the value is a 160 bit SHA1 hash
43Email - the value is a normal C string
44Filename - the value is a normal C string
45
46It is expected that these attributes should be enough to support
47the need from most, if not all, current applications. Applications
48that need to do certificate verification would typically use Subject
49Key ID, Issuer/Serial Hash or Subject to look up issuer certificates.
50S/MIME applications would typically use Email to look up recipient
51and signer certificates.
52
53There's added support for combined sets of attributes to search for,
54with the special OR attribute.
55
56
57Supported basic functionality
58-----------------------------
59
60The functions that are supported through the STORE type are these:
61
62generate_object - for example to generate keys and CRLs
63get_object - to look up one object
64 NOTE: this function is really rather
65 redundant and probably of lesser usage
66 than the list functions
67store_object - store an object and the attributes
68 associated with it
69modify_object - modify the attributes associated with
70 a specific object
71revoke_object - revoke an object
72 NOTE: this only marks an object as
73 invalid, it doesn't remove the object
74 from the database
75delete_object - remove an object from the database
76list_object - list objects associated with a given
77 set of attributes
78 NOTE: this is really four functions:
79 list_start, list_next, list_end and
80 list_endp
81update_store - update the internal data of the store
82lock_store - lock the store
83unlock_store - unlock the store
84
85The list functions need some extra explanation: list_start is
86used to set up a lookup. That's where the attributes to use in
87the search are set up. It returns a search context. list_next
88returns the next object searched for. list_end closes the search.
89list_endp is used to check if we have reached the end.
90
91A few words on the store functions as well: update_store is
92typically used by a CA application to update the internal
93structure of a database. This may for example involve automatic
94removal of expired certificates. lock_store and unlock_store
95are used for locking a store to allow exclusive writes.
diff --git a/src/lib/libcrypto/store/store.h b/src/lib/libcrypto/store/store.h
new file mode 100644
index 0000000000..64583377a9
--- /dev/null
+++ b/src/lib/libcrypto/store/store.h
@@ -0,0 +1,554 @@
1/* crypto/store/store.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_STORE_H
60#define HEADER_STORE_H
61
62#include <openssl/ossl_typ.h>
63#ifndef OPENSSL_NO_DEPRECATED
64#include <openssl/evp.h>
65#include <openssl/bn.h>
66#include <openssl/x509.h>
67#endif
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73/* Already defined in ossl_typ.h */
74/* typedef struct store_st STORE; */
75/* typedef struct store_method_st STORE_METHOD; */
76
77
78/* All the following functions return 0, a negative number or NULL on error.
79 When everything is fine, they return a positive value or a non-NULL
80 pointer, all depending on their purpose. */
81
82/* Creators and destructor. */
83STORE *STORE_new_method(const STORE_METHOD *method);
84STORE *STORE_new_engine(ENGINE *engine);
85void STORE_free(STORE *ui);
86
87
88/* Give a user interface parametrised control commands. This can be used to
89 send down an integer, a data pointer or a function pointer, as well as
90 be used to get information from a STORE. */
91int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void));
92
93/* A control to set the directory with keys and certificates. Used by the
94 built-in directory level method. */
95#define STORE_CTRL_SET_DIRECTORY 0x0001
96/* A control to set a file to load. Used by the built-in file level method. */
97#define STORE_CTRL_SET_FILE 0x0002
98/* A control to set a configuration file to load. Can be used by any method
99 that wishes to load a configuration file. */
100#define STORE_CTRL_SET_CONF_FILE 0x0003
101/* A control to set a the section of the loaded configuration file. Can be
102 used by any method that wishes to load a configuration file. */
103#define STORE_CTRL_SET_CONF_SECTION 0x0004
104
105
106/* Some methods may use extra data */
107#define STORE_set_app_data(s,arg) STORE_set_ex_data(s,0,arg)
108#define STORE_get_app_data(s) STORE_get_ex_data(s,0)
109int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
110 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
111int STORE_set_ex_data(STORE *r,int idx,void *arg);
112void *STORE_get_ex_data(STORE *r, int idx);
113
114/* Use specific methods instead of the built-in one */
115const STORE_METHOD *STORE_get_method(STORE *store);
116const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth);
117
118/* The standard OpenSSL methods. */
119/* This is the in-memory method. It does everything except revoking and updating,
120 and is of course volatile. It's used by other methods that have an in-memory
121 cache. */
122const STORE_METHOD *STORE_Memory(void);
123#if 0 /* Not yet implemented */
124/* This is the directory store. It does everything except revoking and updating,
125 and uses STORE_Memory() to cache things in memory. */
126const STORE_METHOD *STORE_Directory(void);
127/* This is the file store. It does everything except revoking and updating,
128 and uses STORE_Memory() to cache things in memory. Certificates are added
129 to it with the store operation, and it will only get cached certificates. */
130const STORE_METHOD *STORE_File(void);
131#endif
132
133/* Store functions take a type code for the type of data they should store
134 or fetch */
135typedef enum STORE_object_types
136 {
137 STORE_OBJECT_TYPE_X509_CERTIFICATE= 0x01, /* X509 * */
138 STORE_OBJECT_TYPE_X509_CRL= 0x02, /* X509_CRL * */
139 STORE_OBJECT_TYPE_PRIVATE_KEY= 0x03, /* EVP_PKEY * */
140 STORE_OBJECT_TYPE_PUBLIC_KEY= 0x04, /* EVP_PKEY * */
141 STORE_OBJECT_TYPE_NUMBER= 0x05, /* BIGNUM * */
142 STORE_OBJECT_TYPE_ARBITRARY= 0x06, /* BUF_MEM * */
143 STORE_OBJECT_TYPE_NUM= 0x06 /* The amount of known
144 object types */
145 } STORE_OBJECT_TYPES;
146/* List of text strings corresponding to the object types. */
147extern const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1];
148
149/* Some store functions take a parameter list. Those parameters come with
150 one of the following codes. The comments following the codes below indicate
151 what type the value should be a pointer to. */
152typedef enum STORE_params
153 {
154 STORE_PARAM_EVP_TYPE= 0x01, /* int */
155 STORE_PARAM_BITS= 0x02, /* size_t */
156 STORE_PARAM_KEY_PARAMETERS= 0x03, /* ??? */
157 STORE_PARAM_KEY_NO_PARAMETERS= 0x04, /* N/A */
158 STORE_PARAM_AUTH_PASSPHRASE= 0x05, /* char * */
159 STORE_PARAM_AUTH_KRB5_TICKET= 0x06, /* void * */
160 STORE_PARAM_TYPE_NUM= 0x06 /* The amount of known
161 parameter types */
162 } STORE_PARAM_TYPES;
163/* Parameter value sizes. -1 means unknown, anything else is the required size. */
164extern const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1];
165
166/* Store functions take attribute lists. Those attributes come with codes.
167 The comments following the codes below indicate what type the value should
168 be a pointer to. */
169typedef enum STORE_attribs
170 {
171 STORE_ATTR_END= 0x00,
172 STORE_ATTR_FRIENDLYNAME= 0x01, /* C string */
173 STORE_ATTR_KEYID= 0x02, /* 160 bit string (SHA1) */
174 STORE_ATTR_ISSUERKEYID= 0x03, /* 160 bit string (SHA1) */
175 STORE_ATTR_SUBJECTKEYID= 0x04, /* 160 bit string (SHA1) */
176 STORE_ATTR_ISSUERSERIALHASH= 0x05, /* 160 bit string (SHA1) */
177 STORE_ATTR_ISSUER= 0x06, /* X509_NAME * */
178 STORE_ATTR_SERIAL= 0x07, /* BIGNUM * */
179 STORE_ATTR_SUBJECT= 0x08, /* X509_NAME * */
180 STORE_ATTR_CERTHASH= 0x09, /* 160 bit string (SHA1) */
181 STORE_ATTR_EMAIL= 0x0a, /* C string */
182 STORE_ATTR_FILENAME= 0x0b, /* C string */
183 STORE_ATTR_TYPE_NUM= 0x0b, /* The amount of known
184 attribute types */
185 STORE_ATTR_OR= 0xff /* This is a special
186 separator, which
187 expresses the OR
188 operation. */
189 } STORE_ATTR_TYPES;
190/* Attribute value sizes. -1 means unknown, anything else is the required size. */
191extern const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1];
192
193typedef enum STORE_certificate_status
194 {
195 STORE_X509_VALID= 0x00,
196 STORE_X509_EXPIRED= 0x01,
197 STORE_X509_SUSPENDED= 0x02,
198 STORE_X509_REVOKED= 0x03
199 } STORE_CERTIFICATE_STATUS;
200
201/* Engine store functions will return a structure that contains all the necessary
202 * information, including revokation status for certificates. This is really not
203 * needed for application authors, as the ENGINE framework functions will extract
204 * the OpenSSL-specific information when at all possible. However, for engine
205 * authors, it's crucial to know this structure. */
206typedef struct STORE_OBJECT_st
207 {
208 STORE_OBJECT_TYPES type;
209 union
210 {
211 struct
212 {
213 STORE_CERTIFICATE_STATUS status;
214 X509 *certificate;
215 } x509;
216 X509_CRL *crl;
217 EVP_PKEY *key;
218 BIGNUM *number;
219 BUF_MEM *arbitrary;
220 } data;
221 } STORE_OBJECT;
222DECLARE_STACK_OF(STORE_OBJECT)
223STORE_OBJECT *STORE_OBJECT_new(void);
224void STORE_OBJECT_free(STORE_OBJECT *data);
225
226
227
228/* The following functions handle the storage. They return 0, a negative number
229 or NULL on error, anything else on success. */
230X509 *STORE_get_certificate(STORE *e, OPENSSL_ITEM attributes[],
231 OPENSSL_ITEM parameters[]);
232int STORE_store_certificate(STORE *e, X509 *data, OPENSSL_ITEM attributes[],
233 OPENSSL_ITEM parameters[]);
234int STORE_modify_certificate(STORE *e, OPENSSL_ITEM search_attributes[],
235 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
236 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
237int STORE_revoke_certificate(STORE *e, OPENSSL_ITEM attributes[],
238 OPENSSL_ITEM parameters[]);
239int STORE_delete_certificate(STORE *e, OPENSSL_ITEM attributes[],
240 OPENSSL_ITEM parameters[]);
241void *STORE_list_certificate_start(STORE *e, OPENSSL_ITEM attributes[],
242 OPENSSL_ITEM parameters[]);
243X509 *STORE_list_certificate_next(STORE *e, void *handle);
244int STORE_list_certificate_end(STORE *e, void *handle);
245int STORE_list_certificate_endp(STORE *e, void *handle);
246EVP_PKEY *STORE_generate_key(STORE *e, OPENSSL_ITEM attributes[],
247 OPENSSL_ITEM parameters[]);
248EVP_PKEY *STORE_get_private_key(STORE *e, OPENSSL_ITEM attributes[],
249 OPENSSL_ITEM parameters[]);
250int STORE_store_private_key(STORE *e, EVP_PKEY *data,
251 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
252int STORE_modify_private_key(STORE *e, OPENSSL_ITEM search_attributes[],
253 OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],
254 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
255int STORE_revoke_private_key(STORE *e, OPENSSL_ITEM attributes[],
256 OPENSSL_ITEM parameters[]);
257int STORE_delete_private_key(STORE *e, OPENSSL_ITEM attributes[],
258 OPENSSL_ITEM parameters[]);
259void *STORE_list_private_key_start(STORE *e, OPENSSL_ITEM attributes[],
260 OPENSSL_ITEM parameters[]);
261EVP_PKEY *STORE_list_private_key_next(STORE *e, void *handle);
262int STORE_list_private_key_end(STORE *e, void *handle);
263int STORE_list_private_key_endp(STORE *e, void *handle);
264EVP_PKEY *STORE_get_public_key(STORE *e, OPENSSL_ITEM attributes[],
265 OPENSSL_ITEM parameters[]);
266int STORE_store_public_key(STORE *e, EVP_PKEY *data, OPENSSL_ITEM attributes[],
267 OPENSSL_ITEM parameters[]);
268int STORE_modify_public_key(STORE *e, OPENSSL_ITEM search_attributes[],
269 OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],
270 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
271int STORE_revoke_public_key(STORE *e, OPENSSL_ITEM attributes[],
272 OPENSSL_ITEM parameters[]);
273int STORE_delete_public_key(STORE *e, OPENSSL_ITEM attributes[],
274 OPENSSL_ITEM parameters[]);
275void *STORE_list_public_key_start(STORE *e, OPENSSL_ITEM attributes[],
276 OPENSSL_ITEM parameters[]);
277EVP_PKEY *STORE_list_public_key_next(STORE *e, void *handle);
278int STORE_list_public_key_end(STORE *e, void *handle);
279int STORE_list_public_key_endp(STORE *e, void *handle);
280X509_CRL *STORE_generate_crl(STORE *e, OPENSSL_ITEM attributes[],
281 OPENSSL_ITEM parameters[]);
282X509_CRL *STORE_get_crl(STORE *e, OPENSSL_ITEM attributes[],
283 OPENSSL_ITEM parameters[]);
284int STORE_store_crl(STORE *e, X509_CRL *data, OPENSSL_ITEM attributes[],
285 OPENSSL_ITEM parameters[]);
286int STORE_modify_crl(STORE *e, OPENSSL_ITEM search_attributes[],
287 OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],
288 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
289int STORE_delete_crl(STORE *e, OPENSSL_ITEM attributes[],
290 OPENSSL_ITEM parameters[]);
291void *STORE_list_crl_start(STORE *e, OPENSSL_ITEM attributes[],
292 OPENSSL_ITEM parameters[]);
293X509_CRL *STORE_list_crl_next(STORE *e, void *handle);
294int STORE_list_crl_end(STORE *e, void *handle);
295int STORE_list_crl_endp(STORE *e, void *handle);
296int STORE_store_number(STORE *e, BIGNUM *data, OPENSSL_ITEM attributes[],
297 OPENSSL_ITEM parameters[]);
298int STORE_modify_number(STORE *e, OPENSSL_ITEM search_attributes[],
299 OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],
300 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
301BIGNUM *STORE_get_number(STORE *e, OPENSSL_ITEM attributes[],
302 OPENSSL_ITEM parameters[]);
303int STORE_delete_number(STORE *e, OPENSSL_ITEM attributes[],
304 OPENSSL_ITEM parameters[]);
305int STORE_store_arbitrary(STORE *e, BUF_MEM *data, OPENSSL_ITEM attributes[],
306 OPENSSL_ITEM parameters[]);
307int STORE_modify_arbitrary(STORE *e, OPENSSL_ITEM search_attributes[],
308 OPENSSL_ITEM add_sttributes[], OPENSSL_ITEM modify_attributes[],
309 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
310BUF_MEM *STORE_get_arbitrary(STORE *e, OPENSSL_ITEM attributes[],
311 OPENSSL_ITEM parameters[]);
312int STORE_delete_arbitrary(STORE *e, OPENSSL_ITEM attributes[],
313 OPENSSL_ITEM parameters[]);
314
315
316/* Create and manipulate methods */
317STORE_METHOD *STORE_create_method(char *name);
318void STORE_destroy_method(STORE_METHOD *store_method);
319
320/* These callback types are use for store handlers */
321typedef int (*STORE_INITIALISE_FUNC_PTR)(STORE *);
322typedef void (*STORE_CLEANUP_FUNC_PTR)(STORE *);
323typedef STORE_OBJECT *(*STORE_GENERATE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
324typedef STORE_OBJECT *(*STORE_GET_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
325typedef void *(*STORE_START_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
326typedef STORE_OBJECT *(*STORE_NEXT_OBJECT_FUNC_PTR)(STORE *, void *handle);
327typedef int (*STORE_END_OBJECT_FUNC_PTR)(STORE *, void *handle);
328typedef int (*STORE_HANDLE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
329typedef int (*STORE_STORE_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, STORE_OBJECT *data, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
330typedef int (*STORE_MODIFY_OBJECT_FUNC_PTR)(STORE *, STORE_OBJECT_TYPES type, OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[]);
331typedef int (*STORE_GENERIC_FUNC_PTR)(STORE *, OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
332typedef int (*STORE_CTRL_FUNC_PTR)(STORE *, int cmd, long l, void *p, void (*f)(void));
333
334int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f);
335int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f);
336int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f);
337int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f);
338int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f);
339int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR store_f);
340int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f);
341int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f);
342int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f);
343int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f);
344int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f);
345int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);
346int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);
347int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR);
348int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f);
349
350STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm);
351STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm);
352STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm);
353STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm);
354STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm);
355STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm);
356STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm);
357STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm);
358STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm);
359STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm);
360STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm);
361STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm);
362STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm);
363STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm);
364STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm);
365
366/* Method helper structures and functions. */
367
368/* This structure is the result of parsing through the information in a list
369 of OPENSSL_ITEMs. It stores all the necessary information in a structured
370 way.*/
371typedef struct STORE_attr_info_st STORE_ATTR_INFO;
372
373/* Parse a list of OPENSSL_ITEMs and return a pointer to a STORE_ATTR_INFO.
374 Note that we do this in the list form, since the list of OPENSSL_ITEMs can
375 come in blocks separated with STORE_ATTR_OR. Note that the value returned
376 by STORE_parse_attrs_next() must be freed with STORE_ATTR_INFO_free(). */
377void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes);
378STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle);
379int STORE_parse_attrs_end(void *handle);
380int STORE_parse_attrs_endp(void *handle);
381
382/* Creator and destructor */
383STORE_ATTR_INFO *STORE_ATTR_INFO_new(void);
384int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs);
385
386/* Manipulators */
387char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);
388unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
389 STORE_ATTR_TYPES code);
390X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);
391BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code);
392int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
393 char *cstr, size_t cstr_size);
394int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
395 unsigned char *sha1str, size_t sha1str_size);
396int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
397 X509_NAME *dn);
398int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
399 BIGNUM *number);
400int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
401 char *cstr, size_t cstr_size);
402int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
403 unsigned char *sha1str, size_t sha1str_size);
404int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
405 X509_NAME *dn);
406int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
407 BIGNUM *number);
408
409/* Compare on basis of a bit pattern formed by the STORE_ATTR_TYPES values
410 in each contained attribute. */
411int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
412/* Check if the set of attributes in a is within the range of attributes
413 set in b. */
414int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
415/* Check if the set of attributes in a are also set in b. */
416int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
417/* Same as STORE_ATTR_INFO_in(), but also checks the attribute values. */
418int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b);
419
420
421/* BEGIN ERROR CODES */
422/* The following lines are auto generated by the script mkerr.pl. Any changes
423 * made after this point may be overwritten when the script is next run.
424 */
425void ERR_load_STORE_strings(void);
426
427/* Error codes for the STORE functions. */
428
429/* Function codes. */
430#define STORE_F_MEM_DELETE 134
431#define STORE_F_MEM_GENERATE 135
432#define STORE_F_MEM_LIST_END 168
433#define STORE_F_MEM_LIST_NEXT 136
434#define STORE_F_MEM_LIST_START 137
435#define STORE_F_MEM_MODIFY 169
436#define STORE_F_MEM_STORE 138
437#define STORE_F_STORE_ATTR_INFO_GET0_CSTR 139
438#define STORE_F_STORE_ATTR_INFO_GET0_DN 140
439#define STORE_F_STORE_ATTR_INFO_GET0_NUMBER 141
440#define STORE_F_STORE_ATTR_INFO_GET0_SHA1STR 142
441#define STORE_F_STORE_ATTR_INFO_MODIFY_CSTR 143
442#define STORE_F_STORE_ATTR_INFO_MODIFY_DN 144
443#define STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER 145
444#define STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR 146
445#define STORE_F_STORE_ATTR_INFO_SET_CSTR 147
446#define STORE_F_STORE_ATTR_INFO_SET_DN 148
447#define STORE_F_STORE_ATTR_INFO_SET_NUMBER 149
448#define STORE_F_STORE_ATTR_INFO_SET_SHA1STR 150
449#define STORE_F_STORE_CERTIFICATE 170
450#define STORE_F_STORE_CTRL 161
451#define STORE_F_STORE_DELETE_ARBITRARY 158
452#define STORE_F_STORE_DELETE_CERTIFICATE 102
453#define STORE_F_STORE_DELETE_CRL 103
454#define STORE_F_STORE_DELETE_NUMBER 104
455#define STORE_F_STORE_DELETE_PRIVATE_KEY 105
456#define STORE_F_STORE_DELETE_PUBLIC_KEY 106
457#define STORE_F_STORE_GENERATE_CRL 107
458#define STORE_F_STORE_GENERATE_KEY 108
459#define STORE_F_STORE_GET_ARBITRARY 159
460#define STORE_F_STORE_GET_CERTIFICATE 109
461#define STORE_F_STORE_GET_CRL 110
462#define STORE_F_STORE_GET_NUMBER 111
463#define STORE_F_STORE_GET_PRIVATE_KEY 112
464#define STORE_F_STORE_GET_PUBLIC_KEY 113
465#define STORE_F_STORE_LIST_CERTIFICATE_END 114
466#define STORE_F_STORE_LIST_CERTIFICATE_ENDP 153
467#define STORE_F_STORE_LIST_CERTIFICATE_NEXT 115
468#define STORE_F_STORE_LIST_CERTIFICATE_START 116
469#define STORE_F_STORE_LIST_CRL_END 117
470#define STORE_F_STORE_LIST_CRL_ENDP 154
471#define STORE_F_STORE_LIST_CRL_NEXT 118
472#define STORE_F_STORE_LIST_CRL_START 119
473#define STORE_F_STORE_LIST_PRIVATE_KEY_END 120
474#define STORE_F_STORE_LIST_PRIVATE_KEY_ENDP 155
475#define STORE_F_STORE_LIST_PRIVATE_KEY_NEXT 121
476#define STORE_F_STORE_LIST_PRIVATE_KEY_START 122
477#define STORE_F_STORE_LIST_PUBLIC_KEY_END 123
478#define STORE_F_STORE_LIST_PUBLIC_KEY_ENDP 156
479#define STORE_F_STORE_LIST_PUBLIC_KEY_NEXT 124
480#define STORE_F_STORE_LIST_PUBLIC_KEY_START 125
481#define STORE_F_STORE_MODIFY_ARBITRARY 162
482#define STORE_F_STORE_MODIFY_CERTIFICATE 163
483#define STORE_F_STORE_MODIFY_CRL 164
484#define STORE_F_STORE_MODIFY_NUMBER 165
485#define STORE_F_STORE_MODIFY_PRIVATE_KEY 166
486#define STORE_F_STORE_MODIFY_PUBLIC_KEY 167
487#define STORE_F_STORE_NEW_ENGINE 133
488#define STORE_F_STORE_NEW_METHOD 132
489#define STORE_F_STORE_PARSE_ATTRS_END 151
490#define STORE_F_STORE_PARSE_ATTRS_ENDP 172
491#define STORE_F_STORE_PARSE_ATTRS_NEXT 152
492#define STORE_F_STORE_PARSE_ATTRS_START 171
493#define STORE_F_STORE_REVOKE_CERTIFICATE 129
494#define STORE_F_STORE_REVOKE_PRIVATE_KEY 130
495#define STORE_F_STORE_REVOKE_PUBLIC_KEY 131
496#define STORE_F_STORE_STORE_ARBITRARY 157
497#define STORE_F_STORE_STORE_CERTIFICATE 100
498#define STORE_F_STORE_STORE_CRL 101
499#define STORE_F_STORE_STORE_NUMBER 126
500#define STORE_F_STORE_STORE_PRIVATE_KEY 127
501#define STORE_F_STORE_STORE_PUBLIC_KEY 128
502
503/* Reason codes. */
504#define STORE_R_ALREADY_HAS_A_VALUE 127
505#define STORE_R_FAILED_DELETING_ARBITRARY 132
506#define STORE_R_FAILED_DELETING_CERTIFICATE 100
507#define STORE_R_FAILED_DELETING_KEY 101
508#define STORE_R_FAILED_DELETING_NUMBER 102
509#define STORE_R_FAILED_GENERATING_CRL 103
510#define STORE_R_FAILED_GENERATING_KEY 104
511#define STORE_R_FAILED_GETTING_ARBITRARY 133
512#define STORE_R_FAILED_GETTING_CERTIFICATE 105
513#define STORE_R_FAILED_GETTING_KEY 106
514#define STORE_R_FAILED_GETTING_NUMBER 107
515#define STORE_R_FAILED_LISTING_CERTIFICATES 108
516#define STORE_R_FAILED_LISTING_KEYS 109
517#define STORE_R_FAILED_MODIFYING_ARBITRARY 138
518#define STORE_R_FAILED_MODIFYING_CERTIFICATE 139
519#define STORE_R_FAILED_MODIFYING_CRL 140
520#define STORE_R_FAILED_MODIFYING_NUMBER 141
521#define STORE_R_FAILED_MODIFYING_PRIVATE_KEY 142
522#define STORE_R_FAILED_MODIFYING_PUBLIC_KEY 143
523#define STORE_R_FAILED_REVOKING_CERTIFICATE 110
524#define STORE_R_FAILED_REVOKING_KEY 111
525#define STORE_R_FAILED_STORING_ARBITRARY 134
526#define STORE_R_FAILED_STORING_CERTIFICATE 112
527#define STORE_R_FAILED_STORING_KEY 113
528#define STORE_R_FAILED_STORING_NUMBER 114
529#define STORE_R_NOT_IMPLEMENTED 128
530#define STORE_R_NO_CONTROL_FUNCTION 144
531#define STORE_R_NO_DELETE_ARBITRARY_FUNCTION 135
532#define STORE_R_NO_DELETE_NUMBER_FUNCTION 115
533#define STORE_R_NO_DELETE_OBJECT_FUNCTION 116
534#define STORE_R_NO_GENERATE_CRL_FUNCTION 117
535#define STORE_R_NO_GENERATE_OBJECT_FUNCTION 118
536#define STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION 136
537#define STORE_R_NO_GET_OBJECT_FUNCTION 119
538#define STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION 120
539#define STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION 131
540#define STORE_R_NO_LIST_OBJECT_END_FUNCTION 121
541#define STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION 122
542#define STORE_R_NO_LIST_OBJECT_START_FUNCTION 123
543#define STORE_R_NO_MODIFY_OBJECT_FUNCTION 145
544#define STORE_R_NO_REVOKE_OBJECT_FUNCTION 124
545#define STORE_R_NO_STORE 129
546#define STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION 137
547#define STORE_R_NO_STORE_OBJECT_FUNCTION 125
548#define STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION 126
549#define STORE_R_NO_VALUE 130
550
551#ifdef __cplusplus
552}
553#endif
554#endif
diff --git a/src/lib/libcrypto/store/str_err.c b/src/lib/libcrypto/store/str_err.c
new file mode 100644
index 0000000000..6fee649822
--- /dev/null
+++ b/src/lib/libcrypto/store/str_err.c
@@ -0,0 +1,211 @@
1/* crypto/store/str_err.c */
2/* ====================================================================
3 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56/* NOTE: this file was auto generated by the mkerr.pl script: any changes
57 * made to it will be overwritten when the script next updates this file,
58 * only reason strings will be preserved.
59 */
60
61#include <stdio.h>
62#include <openssl/err.h>
63#include <openssl/store.h>
64
65/* BEGIN ERROR CODES */
66#ifndef OPENSSL_NO_ERR
67
68#define ERR_FUNC(func) ERR_PACK(ERR_LIB_STORE,func,0)
69#define ERR_REASON(reason) ERR_PACK(ERR_LIB_STORE,0,reason)
70
71static ERR_STRING_DATA STORE_str_functs[]=
72 {
73{ERR_FUNC(STORE_F_MEM_DELETE), "MEM_DELETE"},
74{ERR_FUNC(STORE_F_MEM_GENERATE), "MEM_GENERATE"},
75{ERR_FUNC(STORE_F_MEM_LIST_END), "MEM_LIST_END"},
76{ERR_FUNC(STORE_F_MEM_LIST_NEXT), "MEM_LIST_NEXT"},
77{ERR_FUNC(STORE_F_MEM_LIST_START), "MEM_LIST_START"},
78{ERR_FUNC(STORE_F_MEM_MODIFY), "MEM_MODIFY"},
79{ERR_FUNC(STORE_F_MEM_STORE), "MEM_STORE"},
80{ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_CSTR), "STORE_ATTR_INFO_get0_cstr"},
81{ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_DN), "STORE_ATTR_INFO_get0_dn"},
82{ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_NUMBER), "STORE_ATTR_INFO_get0_number"},
83{ERR_FUNC(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR), "STORE_ATTR_INFO_get0_sha1str"},
84{ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR), "STORE_ATTR_INFO_modify_cstr"},
85{ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_DN), "STORE_ATTR_INFO_modify_dn"},
86{ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER), "STORE_ATTR_INFO_modify_number"},
87{ERR_FUNC(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR), "STORE_ATTR_INFO_modify_sha1str"},
88{ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_CSTR), "STORE_ATTR_INFO_set_cstr"},
89{ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_DN), "STORE_ATTR_INFO_set_dn"},
90{ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_NUMBER), "STORE_ATTR_INFO_set_number"},
91{ERR_FUNC(STORE_F_STORE_ATTR_INFO_SET_SHA1STR), "STORE_ATTR_INFO_set_sha1str"},
92{ERR_FUNC(STORE_F_STORE_CERTIFICATE), "STORE_CERTIFICATE"},
93{ERR_FUNC(STORE_F_STORE_CTRL), "STORE_ctrl"},
94{ERR_FUNC(STORE_F_STORE_DELETE_ARBITRARY), "STORE_delete_arbitrary"},
95{ERR_FUNC(STORE_F_STORE_DELETE_CERTIFICATE), "STORE_delete_certificate"},
96{ERR_FUNC(STORE_F_STORE_DELETE_CRL), "STORE_delete_crl"},
97{ERR_FUNC(STORE_F_STORE_DELETE_NUMBER), "STORE_delete_number"},
98{ERR_FUNC(STORE_F_STORE_DELETE_PRIVATE_KEY), "STORE_delete_private_key"},
99{ERR_FUNC(STORE_F_STORE_DELETE_PUBLIC_KEY), "STORE_delete_public_key"},
100{ERR_FUNC(STORE_F_STORE_GENERATE_CRL), "STORE_generate_crl"},
101{ERR_FUNC(STORE_F_STORE_GENERATE_KEY), "STORE_generate_key"},
102{ERR_FUNC(STORE_F_STORE_GET_ARBITRARY), "STORE_get_arbitrary"},
103{ERR_FUNC(STORE_F_STORE_GET_CERTIFICATE), "STORE_get_certificate"},
104{ERR_FUNC(STORE_F_STORE_GET_CRL), "STORE_get_crl"},
105{ERR_FUNC(STORE_F_STORE_GET_NUMBER), "STORE_get_number"},
106{ERR_FUNC(STORE_F_STORE_GET_PRIVATE_KEY), "STORE_get_private_key"},
107{ERR_FUNC(STORE_F_STORE_GET_PUBLIC_KEY), "STORE_get_public_key"},
108{ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_END), "STORE_list_certificate_end"},
109{ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_ENDP), "STORE_list_certificate_endp"},
110{ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_NEXT), "STORE_list_certificate_next"},
111{ERR_FUNC(STORE_F_STORE_LIST_CERTIFICATE_START), "STORE_list_certificate_start"},
112{ERR_FUNC(STORE_F_STORE_LIST_CRL_END), "STORE_list_crl_end"},
113{ERR_FUNC(STORE_F_STORE_LIST_CRL_ENDP), "STORE_list_crl_endp"},
114{ERR_FUNC(STORE_F_STORE_LIST_CRL_NEXT), "STORE_list_crl_next"},
115{ERR_FUNC(STORE_F_STORE_LIST_CRL_START), "STORE_list_crl_start"},
116{ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_END), "STORE_list_private_key_end"},
117{ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP), "STORE_list_private_key_endp"},
118{ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT), "STORE_list_private_key_next"},
119{ERR_FUNC(STORE_F_STORE_LIST_PRIVATE_KEY_START), "STORE_list_private_key_start"},
120{ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_END), "STORE_list_public_key_end"},
121{ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP), "STORE_list_public_key_endp"},
122{ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT), "STORE_list_public_key_next"},
123{ERR_FUNC(STORE_F_STORE_LIST_PUBLIC_KEY_START), "STORE_list_public_key_start"},
124{ERR_FUNC(STORE_F_STORE_MODIFY_ARBITRARY), "STORE_modify_arbitrary"},
125{ERR_FUNC(STORE_F_STORE_MODIFY_CERTIFICATE), "STORE_modify_certificate"},
126{ERR_FUNC(STORE_F_STORE_MODIFY_CRL), "STORE_modify_crl"},
127{ERR_FUNC(STORE_F_STORE_MODIFY_NUMBER), "STORE_modify_number"},
128{ERR_FUNC(STORE_F_STORE_MODIFY_PRIVATE_KEY), "STORE_modify_private_key"},
129{ERR_FUNC(STORE_F_STORE_MODIFY_PUBLIC_KEY), "STORE_modify_public_key"},
130{ERR_FUNC(STORE_F_STORE_NEW_ENGINE), "STORE_new_engine"},
131{ERR_FUNC(STORE_F_STORE_NEW_METHOD), "STORE_new_method"},
132{ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_END), "STORE_parse_attrs_end"},
133{ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_ENDP), "STORE_parse_attrs_endp"},
134{ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_NEXT), "STORE_parse_attrs_next"},
135{ERR_FUNC(STORE_F_STORE_PARSE_ATTRS_START), "STORE_parse_attrs_start"},
136{ERR_FUNC(STORE_F_STORE_REVOKE_CERTIFICATE), "STORE_revoke_certificate"},
137{ERR_FUNC(STORE_F_STORE_REVOKE_PRIVATE_KEY), "STORE_revoke_private_key"},
138{ERR_FUNC(STORE_F_STORE_REVOKE_PUBLIC_KEY), "STORE_revoke_public_key"},
139{ERR_FUNC(STORE_F_STORE_STORE_ARBITRARY), "STORE_store_arbitrary"},
140{ERR_FUNC(STORE_F_STORE_STORE_CERTIFICATE), "STORE_store_certificate"},
141{ERR_FUNC(STORE_F_STORE_STORE_CRL), "STORE_store_crl"},
142{ERR_FUNC(STORE_F_STORE_STORE_NUMBER), "STORE_store_number"},
143{ERR_FUNC(STORE_F_STORE_STORE_PRIVATE_KEY), "STORE_store_private_key"},
144{ERR_FUNC(STORE_F_STORE_STORE_PUBLIC_KEY), "STORE_store_public_key"},
145{0,NULL}
146 };
147
148static ERR_STRING_DATA STORE_str_reasons[]=
149 {
150{ERR_REASON(STORE_R_ALREADY_HAS_A_VALUE) ,"already has a value"},
151{ERR_REASON(STORE_R_FAILED_DELETING_ARBITRARY),"failed deleting arbitrary"},
152{ERR_REASON(STORE_R_FAILED_DELETING_CERTIFICATE),"failed deleting certificate"},
153{ERR_REASON(STORE_R_FAILED_DELETING_KEY) ,"failed deleting key"},
154{ERR_REASON(STORE_R_FAILED_DELETING_NUMBER),"failed deleting number"},
155{ERR_REASON(STORE_R_FAILED_GENERATING_CRL),"failed generating crl"},
156{ERR_REASON(STORE_R_FAILED_GENERATING_KEY),"failed generating key"},
157{ERR_REASON(STORE_R_FAILED_GETTING_ARBITRARY),"failed getting arbitrary"},
158{ERR_REASON(STORE_R_FAILED_GETTING_CERTIFICATE),"failed getting certificate"},
159{ERR_REASON(STORE_R_FAILED_GETTING_KEY) ,"failed getting key"},
160{ERR_REASON(STORE_R_FAILED_GETTING_NUMBER),"failed getting number"},
161{ERR_REASON(STORE_R_FAILED_LISTING_CERTIFICATES),"failed listing certificates"},
162{ERR_REASON(STORE_R_FAILED_LISTING_KEYS) ,"failed listing keys"},
163{ERR_REASON(STORE_R_FAILED_MODIFYING_ARBITRARY),"failed modifying arbitrary"},
164{ERR_REASON(STORE_R_FAILED_MODIFYING_CERTIFICATE),"failed modifying certificate"},
165{ERR_REASON(STORE_R_FAILED_MODIFYING_CRL),"failed modifying crl"},
166{ERR_REASON(STORE_R_FAILED_MODIFYING_NUMBER),"failed modifying number"},
167{ERR_REASON(STORE_R_FAILED_MODIFYING_PRIVATE_KEY),"failed modifying private key"},
168{ERR_REASON(STORE_R_FAILED_MODIFYING_PUBLIC_KEY),"failed modifying public key"},
169{ERR_REASON(STORE_R_FAILED_REVOKING_CERTIFICATE),"failed revoking certificate"},
170{ERR_REASON(STORE_R_FAILED_REVOKING_KEY) ,"failed revoking key"},
171{ERR_REASON(STORE_R_FAILED_STORING_ARBITRARY),"failed storing arbitrary"},
172{ERR_REASON(STORE_R_FAILED_STORING_CERTIFICATE),"failed storing certificate"},
173{ERR_REASON(STORE_R_FAILED_STORING_KEY) ,"failed storing key"},
174{ERR_REASON(STORE_R_FAILED_STORING_NUMBER),"failed storing number"},
175{ERR_REASON(STORE_R_NOT_IMPLEMENTED) ,"not implemented"},
176{ERR_REASON(STORE_R_NO_CONTROL_FUNCTION) ,"no control function"},
177{ERR_REASON(STORE_R_NO_DELETE_ARBITRARY_FUNCTION),"no delete arbitrary function"},
178{ERR_REASON(STORE_R_NO_DELETE_NUMBER_FUNCTION),"no delete number function"},
179{ERR_REASON(STORE_R_NO_DELETE_OBJECT_FUNCTION),"no delete object function"},
180{ERR_REASON(STORE_R_NO_GENERATE_CRL_FUNCTION),"no generate crl function"},
181{ERR_REASON(STORE_R_NO_GENERATE_OBJECT_FUNCTION),"no generate object function"},
182{ERR_REASON(STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION),"no get object arbitrary function"},
183{ERR_REASON(STORE_R_NO_GET_OBJECT_FUNCTION),"no get object function"},
184{ERR_REASON(STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION),"no get object number function"},
185{ERR_REASON(STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION),"no list object endp function"},
186{ERR_REASON(STORE_R_NO_LIST_OBJECT_END_FUNCTION),"no list object end function"},
187{ERR_REASON(STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION),"no list object next function"},
188{ERR_REASON(STORE_R_NO_LIST_OBJECT_START_FUNCTION),"no list object start function"},
189{ERR_REASON(STORE_R_NO_MODIFY_OBJECT_FUNCTION),"no modify object function"},
190{ERR_REASON(STORE_R_NO_REVOKE_OBJECT_FUNCTION),"no revoke object function"},
191{ERR_REASON(STORE_R_NO_STORE) ,"no store"},
192{ERR_REASON(STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION),"no store object arbitrary function"},
193{ERR_REASON(STORE_R_NO_STORE_OBJECT_FUNCTION),"no store object function"},
194{ERR_REASON(STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION),"no store object number function"},
195{ERR_REASON(STORE_R_NO_VALUE) ,"no value"},
196{0,NULL}
197 };
198
199#endif
200
201void ERR_load_STORE_strings(void)
202 {
203#ifndef OPENSSL_NO_ERR
204
205 if (ERR_func_error_string(STORE_str_functs[0].error) == NULL)
206 {
207 ERR_load_strings(0,STORE_str_functs);
208 ERR_load_strings(0,STORE_str_reasons);
209 }
210#endif
211 }
diff --git a/src/lib/libcrypto/store/str_lib.c b/src/lib/libcrypto/store/str_lib.c
new file mode 100644
index 0000000000..32ae5bd395
--- /dev/null
+++ b/src/lib/libcrypto/store/str_lib.c
@@ -0,0 +1,1824 @@
1/* crypto/store/str_lib.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/bn.h>
61#include <openssl/err.h>
62#ifndef OPENSSL_NO_ENGINE
63#include <openssl/engine.h>
64#endif
65#include <openssl/sha.h>
66#include <openssl/x509.h>
67#include "str_locl.h"
68
69const char * const STORE_object_type_string[STORE_OBJECT_TYPE_NUM+1] =
70 {
71 0,
72 "X.509 Certificate",
73 "X.509 CRL",
74 "Private Key",
75 "Public Key",
76 "Number",
77 "Arbitrary Data"
78 };
79
80const int STORE_param_sizes[STORE_PARAM_TYPE_NUM+1] =
81 {
82 0,
83 sizeof(int), /* EVP_TYPE */
84 sizeof(size_t), /* BITS */
85 -1, /* KEY_PARAMETERS */
86 0 /* KEY_NO_PARAMETERS */
87 };
88
89const int STORE_attr_sizes[STORE_ATTR_TYPE_NUM+1] =
90 {
91 0,
92 -1, /* FRIENDLYNAME: C string */
93 SHA_DIGEST_LENGTH, /* KEYID: SHA1 digest, 160 bits */
94 SHA_DIGEST_LENGTH, /* ISSUERKEYID: SHA1 digest, 160 bits */
95 SHA_DIGEST_LENGTH, /* SUBJECTKEYID: SHA1 digest, 160 bits */
96 SHA_DIGEST_LENGTH, /* ISSUERSERIALHASH: SHA1 digest, 160 bits */
97 sizeof(X509_NAME *), /* ISSUER: X509_NAME * */
98 sizeof(BIGNUM *), /* SERIAL: BIGNUM * */
99 sizeof(X509_NAME *), /* SUBJECT: X509_NAME * */
100 SHA_DIGEST_LENGTH, /* CERTHASH: SHA1 digest, 160 bits */
101 -1, /* EMAIL: C string */
102 -1, /* FILENAME: C string */
103 };
104
105STORE *STORE_new_method(const STORE_METHOD *method)
106 {
107 STORE *ret;
108
109 if (method == NULL)
110 {
111 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_PASSED_NULL_PARAMETER);
112 return NULL;
113 }
114
115 ret=(STORE *)OPENSSL_malloc(sizeof(STORE));
116 if (ret == NULL)
117 {
118 STOREerr(STORE_F_STORE_NEW_METHOD,ERR_R_MALLOC_FAILURE);
119 return NULL;
120 }
121
122 ret->meth=method;
123
124 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_STORE, ret, &ret->ex_data);
125 if (ret->meth->init && !ret->meth->init(ret))
126 {
127 STORE_free(ret);
128 ret = NULL;
129 }
130 return ret;
131 }
132
133STORE *STORE_new_engine(ENGINE *engine)
134 {
135 STORE *ret = NULL;
136 ENGINE *e = engine;
137 const STORE_METHOD *meth = 0;
138
139#ifdef OPENSSL_NO_ENGINE
140 e = NULL;
141#else
142 if (engine)
143 {
144 if (!ENGINE_init(engine))
145 {
146 STOREerr(STORE_F_STORE_NEW_ENGINE, ERR_R_ENGINE_LIB);
147 return NULL;
148 }
149 e = engine;
150 }
151 else
152 {
153 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_PASSED_NULL_PARAMETER);
154 return NULL;
155 }
156 if(e)
157 {
158 meth = ENGINE_get_STORE(e);
159 if(!meth)
160 {
161 STOREerr(STORE_F_STORE_NEW_ENGINE,
162 ERR_R_ENGINE_LIB);
163 ENGINE_finish(e);
164 return NULL;
165 }
166 }
167#endif
168
169 ret = STORE_new_method(meth);
170 if (ret == NULL)
171 {
172 STOREerr(STORE_F_STORE_NEW_ENGINE,ERR_R_STORE_LIB);
173 return NULL;
174 }
175
176 ret->engine = e;
177
178 return(ret);
179 }
180
181void STORE_free(STORE *store)
182 {
183 if (store == NULL)
184 return;
185 if (store->meth->clean)
186 store->meth->clean(store);
187 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_STORE, store, &store->ex_data);
188 OPENSSL_free(store);
189 }
190
191int STORE_ctrl(STORE *store, int cmd, long i, void *p, void (*f)(void))
192 {
193 if (store == NULL)
194 {
195 STOREerr(STORE_F_STORE_CTRL,ERR_R_PASSED_NULL_PARAMETER);
196 return 0;
197 }
198 if (store->meth->ctrl)
199 return store->meth->ctrl(store, cmd, i, p, f);
200 STOREerr(STORE_F_STORE_CTRL,STORE_R_NO_CONTROL_FUNCTION);
201 return 0;
202 }
203
204
205int STORE_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
206 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func)
207 {
208 return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_STORE, argl, argp,
209 new_func, dup_func, free_func);
210 }
211
212int STORE_set_ex_data(STORE *r, int idx, void *arg)
213 {
214 return(CRYPTO_set_ex_data(&r->ex_data,idx,arg));
215 }
216
217void *STORE_get_ex_data(STORE *r, int idx)
218 {
219 return(CRYPTO_get_ex_data(&r->ex_data,idx));
220 }
221
222const STORE_METHOD *STORE_get_method(STORE *store)
223 {
224 return store->meth;
225 }
226
227const STORE_METHOD *STORE_set_method(STORE *store, const STORE_METHOD *meth)
228 {
229 store->meth=meth;
230 return store->meth;
231 }
232
233
234/* API helpers */
235
236#define check_store(s,fncode,fnname,fnerrcode) \
237 do \
238 { \
239 if ((s) == NULL || (s)->meth == NULL) \
240 { \
241 STOREerr((fncode), ERR_R_PASSED_NULL_PARAMETER); \
242 return 0; \
243 } \
244 if ((s)->meth->fnname == NULL) \
245 { \
246 STOREerr((fncode), (fnerrcode)); \
247 return 0; \
248 } \
249 } \
250 while(0)
251
252/* API functions */
253
254X509 *STORE_get_certificate(STORE *s, OPENSSL_ITEM attributes[],
255 OPENSSL_ITEM parameters[])
256 {
257 STORE_OBJECT *object;
258 X509 *x;
259
260 check_store(s,STORE_F_STORE_GET_CERTIFICATE,
261 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
262
263 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
264 attributes, parameters);
265 if (!object || !object->data.x509.certificate)
266 {
267 STOREerr(STORE_F_STORE_GET_CERTIFICATE,
268 STORE_R_FAILED_GETTING_CERTIFICATE);
269 return 0;
270 }
271 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
272#ifdef REF_PRINT
273 REF_PRINT("X509",data);
274#endif
275 x = object->data.x509.certificate;
276 STORE_OBJECT_free(object);
277 return x;
278 }
279
280int STORE_store_certificate(STORE *s, X509 *data, OPENSSL_ITEM attributes[],
281 OPENSSL_ITEM parameters[])
282 {
283 STORE_OBJECT *object;
284 int i;
285
286 check_store(s,STORE_F_STORE_CERTIFICATE,
287 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
288
289 object = STORE_OBJECT_new();
290 if (!object)
291 {
292 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
293 ERR_R_MALLOC_FAILURE);
294 return 0;
295 }
296
297 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509);
298#ifdef REF_PRINT
299 REF_PRINT("X509",data);
300#endif
301 object->data.x509.certificate = data;
302
303 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
304 object, attributes, parameters);
305
306 STORE_OBJECT_free(object);
307
308 if (!i)
309 {
310 STOREerr(STORE_F_STORE_STORE_CERTIFICATE,
311 STORE_R_FAILED_STORING_CERTIFICATE);
312 return 0;
313 }
314 return 1;
315 }
316
317int STORE_modify_certificate(STORE *s, OPENSSL_ITEM search_attributes[],
318 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
319 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
320 {
321 check_store(s,STORE_F_STORE_MODIFY_CERTIFICATE,
322 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
323
324 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
325 search_attributes, add_attributes, modify_attributes,
326 delete_attributes, parameters))
327 {
328 STOREerr(STORE_F_STORE_MODIFY_CERTIFICATE,
329 STORE_R_FAILED_MODIFYING_CERTIFICATE);
330 return 0;
331 }
332 return 1;
333 }
334
335int STORE_revoke_certificate(STORE *s, OPENSSL_ITEM attributes[],
336 OPENSSL_ITEM parameters[])
337 {
338 check_store(s,STORE_F_STORE_REVOKE_CERTIFICATE,
339 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
340
341 if (!s->meth->revoke_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
342 attributes, parameters))
343 {
344 STOREerr(STORE_F_STORE_REVOKE_CERTIFICATE,
345 STORE_R_FAILED_REVOKING_CERTIFICATE);
346 return 0;
347 }
348 return 1;
349 }
350
351int STORE_delete_certificate(STORE *s, OPENSSL_ITEM attributes[],
352 OPENSSL_ITEM parameters[])
353 {
354 check_store(s,STORE_F_STORE_DELETE_CERTIFICATE,
355 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
356
357 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CERTIFICATE,
358 attributes, parameters))
359 {
360 STOREerr(STORE_F_STORE_DELETE_CERTIFICATE,
361 STORE_R_FAILED_DELETING_CERTIFICATE);
362 return 0;
363 }
364 return 1;
365 }
366
367void *STORE_list_certificate_start(STORE *s, OPENSSL_ITEM attributes[],
368 OPENSSL_ITEM parameters[])
369 {
370 void *handle;
371
372 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_START,
373 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
374
375 handle = s->meth->list_object_start(s,
376 STORE_OBJECT_TYPE_X509_CERTIFICATE, attributes, parameters);
377 if (!handle)
378 {
379 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_START,
380 STORE_R_FAILED_LISTING_CERTIFICATES);
381 return 0;
382 }
383 return handle;
384 }
385
386X509 *STORE_list_certificate_next(STORE *s, void *handle)
387 {
388 STORE_OBJECT *object;
389 X509 *x;
390
391 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_NEXT,
392 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
393
394 object = s->meth->list_object_next(s, handle);
395 if (!object || !object->data.x509.certificate)
396 {
397 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_NEXT,
398 STORE_R_FAILED_LISTING_CERTIFICATES);
399 return 0;
400 }
401 CRYPTO_add(&object->data.x509.certificate->references,1,CRYPTO_LOCK_X509);
402#ifdef REF_PRINT
403 REF_PRINT("X509",data);
404#endif
405 x = object->data.x509.certificate;
406 STORE_OBJECT_free(object);
407 return x;
408 }
409
410int STORE_list_certificate_end(STORE *s, void *handle)
411 {
412 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_END,
413 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
414
415 if (!s->meth->list_object_end(s, handle))
416 {
417 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_END,
418 STORE_R_FAILED_LISTING_CERTIFICATES);
419 return 0;
420 }
421 return 1;
422 }
423
424int STORE_list_certificate_endp(STORE *s, void *handle)
425 {
426 check_store(s,STORE_F_STORE_LIST_CERTIFICATE_ENDP,
427 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
428
429 if (!s->meth->list_object_endp(s, handle))
430 {
431 STOREerr(STORE_F_STORE_LIST_CERTIFICATE_ENDP,
432 STORE_R_FAILED_LISTING_CERTIFICATES);
433 return 0;
434 }
435 return 1;
436 }
437
438EVP_PKEY *STORE_generate_key(STORE *s, OPENSSL_ITEM attributes[],
439 OPENSSL_ITEM parameters[])
440 {
441 STORE_OBJECT *object;
442 EVP_PKEY *pkey;
443
444 check_store(s,STORE_F_STORE_GENERATE_KEY,
445 generate_object,STORE_R_NO_GENERATE_OBJECT_FUNCTION);
446
447 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
448 attributes, parameters);
449 if (!object || !object->data.key)
450 {
451 STOREerr(STORE_F_STORE_GENERATE_KEY,
452 STORE_R_FAILED_GENERATING_KEY);
453 return 0;
454 }
455 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
456#ifdef REF_PRINT
457 REF_PRINT("EVP_PKEY",data);
458#endif
459 pkey = object->data.key;
460 STORE_OBJECT_free(object);
461 return pkey;
462 }
463
464EVP_PKEY *STORE_get_private_key(STORE *s, OPENSSL_ITEM attributes[],
465 OPENSSL_ITEM parameters[])
466 {
467 STORE_OBJECT *object;
468 EVP_PKEY *pkey;
469
470 check_store(s,STORE_F_STORE_GET_PRIVATE_KEY,
471 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
472
473 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
474 attributes, parameters);
475 if (!object || !object->data.key || !object->data.key)
476 {
477 STOREerr(STORE_F_STORE_GET_PRIVATE_KEY,
478 STORE_R_FAILED_GETTING_KEY);
479 return 0;
480 }
481 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
482#ifdef REF_PRINT
483 REF_PRINT("EVP_PKEY",data);
484#endif
485 pkey = object->data.key;
486 STORE_OBJECT_free(object);
487 return pkey;
488 }
489
490int STORE_store_private_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
491 OPENSSL_ITEM parameters[])
492 {
493 STORE_OBJECT *object;
494 int i;
495
496 check_store(s,STORE_F_STORE_STORE_PRIVATE_KEY,
497 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
498
499 object = STORE_OBJECT_new();
500 if (!object)
501 {
502 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
503 ERR_R_MALLOC_FAILURE);
504 return 0;
505 }
506 object->data.key = EVP_PKEY_new();
507 if (!object->data.key)
508 {
509 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
510 ERR_R_MALLOC_FAILURE);
511 return 0;
512 }
513
514 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
515#ifdef REF_PRINT
516 REF_PRINT("EVP_PKEY",data);
517#endif
518 object->data.key = data;
519
520 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY, object,
521 attributes, parameters);
522
523 STORE_OBJECT_free(object);
524
525 if (!i)
526 {
527 STOREerr(STORE_F_STORE_STORE_PRIVATE_KEY,
528 STORE_R_FAILED_STORING_KEY);
529 return 0;
530 }
531 return i;
532 }
533
534int STORE_modify_private_key(STORE *s, OPENSSL_ITEM search_attributes[],
535 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
536 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
537 {
538 check_store(s,STORE_F_STORE_MODIFY_PRIVATE_KEY,
539 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
540
541 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
542 search_attributes, add_attributes, modify_attributes,
543 delete_attributes, parameters))
544 {
545 STOREerr(STORE_F_STORE_MODIFY_PRIVATE_KEY,
546 STORE_R_FAILED_MODIFYING_PRIVATE_KEY);
547 return 0;
548 }
549 return 1;
550 }
551
552int STORE_revoke_private_key(STORE *s, OPENSSL_ITEM attributes[],
553 OPENSSL_ITEM parameters[])
554 {
555 int i;
556
557 check_store(s,STORE_F_STORE_REVOKE_PRIVATE_KEY,
558 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
559
560 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
561 attributes, parameters);
562
563 if (!i)
564 {
565 STOREerr(STORE_F_STORE_REVOKE_PRIVATE_KEY,
566 STORE_R_FAILED_REVOKING_KEY);
567 return 0;
568 }
569 return i;
570 }
571
572int STORE_delete_private_key(STORE *s, OPENSSL_ITEM attributes[],
573 OPENSSL_ITEM parameters[])
574 {
575 check_store(s,STORE_F_STORE_DELETE_PRIVATE_KEY,
576 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
577
578 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
579 attributes, parameters))
580 {
581 STOREerr(STORE_F_STORE_DELETE_PRIVATE_KEY,
582 STORE_R_FAILED_DELETING_KEY);
583 return 0;
584 }
585 return 1;
586 }
587
588void *STORE_list_private_key_start(STORE *s, OPENSSL_ITEM attributes[],
589 OPENSSL_ITEM parameters[])
590 {
591 void *handle;
592
593 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_START,
594 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
595
596 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PRIVATE_KEY,
597 attributes, parameters);
598 if (!handle)
599 {
600 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_START,
601 STORE_R_FAILED_LISTING_KEYS);
602 return 0;
603 }
604 return handle;
605 }
606
607EVP_PKEY *STORE_list_private_key_next(STORE *s, void *handle)
608 {
609 STORE_OBJECT *object;
610 EVP_PKEY *pkey;
611
612 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
613 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
614
615 object = s->meth->list_object_next(s, handle);
616 if (!object || !object->data.key || !object->data.key)
617 {
618 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_NEXT,
619 STORE_R_FAILED_LISTING_KEYS);
620 return 0;
621 }
622 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
623#ifdef REF_PRINT
624 REF_PRINT("EVP_PKEY",data);
625#endif
626 pkey = object->data.key;
627 STORE_OBJECT_free(object);
628 return pkey;
629 }
630
631int STORE_list_private_key_end(STORE *s, void *handle)
632 {
633 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_END,
634 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
635
636 if (!s->meth->list_object_end(s, handle))
637 {
638 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_END,
639 STORE_R_FAILED_LISTING_KEYS);
640 return 0;
641 }
642 return 1;
643 }
644
645int STORE_list_private_key_endp(STORE *s, void *handle)
646 {
647 check_store(s,STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
648 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
649
650 if (!s->meth->list_object_endp(s, handle))
651 {
652 STOREerr(STORE_F_STORE_LIST_PRIVATE_KEY_ENDP,
653 STORE_R_FAILED_LISTING_KEYS);
654 return 0;
655 }
656 return 1;
657 }
658
659EVP_PKEY *STORE_get_public_key(STORE *s, OPENSSL_ITEM attributes[],
660 OPENSSL_ITEM parameters[])
661 {
662 STORE_OBJECT *object;
663 EVP_PKEY *pkey;
664
665 check_store(s,STORE_F_STORE_GET_PUBLIC_KEY,
666 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
667
668 object = s->meth->get_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
669 attributes, parameters);
670 if (!object || !object->data.key || !object->data.key)
671 {
672 STOREerr(STORE_F_STORE_GET_PUBLIC_KEY,
673 STORE_R_FAILED_GETTING_KEY);
674 return 0;
675 }
676 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
677#ifdef REF_PRINT
678 REF_PRINT("EVP_PKEY",data);
679#endif
680 pkey = object->data.key;
681 STORE_OBJECT_free(object);
682 return pkey;
683 }
684
685int STORE_store_public_key(STORE *s, EVP_PKEY *data, OPENSSL_ITEM attributes[],
686 OPENSSL_ITEM parameters[])
687 {
688 STORE_OBJECT *object;
689 int i;
690
691 check_store(s,STORE_F_STORE_STORE_PUBLIC_KEY,
692 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
693
694 object = STORE_OBJECT_new();
695 if (!object)
696 {
697 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
698 ERR_R_MALLOC_FAILURE);
699 return 0;
700 }
701 object->data.key = EVP_PKEY_new();
702 if (!object->data.key)
703 {
704 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
705 ERR_R_MALLOC_FAILURE);
706 return 0;
707 }
708
709 CRYPTO_add(&data->references,1,CRYPTO_LOCK_EVP_PKEY);
710#ifdef REF_PRINT
711 REF_PRINT("EVP_PKEY",data);
712#endif
713 object->data.key = data;
714
715 i = s->meth->store_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY, object,
716 attributes, parameters);
717
718 STORE_OBJECT_free(object);
719
720 if (!i)
721 {
722 STOREerr(STORE_F_STORE_STORE_PUBLIC_KEY,
723 STORE_R_FAILED_STORING_KEY);
724 return 0;
725 }
726 return i;
727 }
728
729int STORE_modify_public_key(STORE *s, OPENSSL_ITEM search_attributes[],
730 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
731 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
732 {
733 check_store(s,STORE_F_STORE_MODIFY_PUBLIC_KEY,
734 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
735
736 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
737 search_attributes, add_attributes, modify_attributes,
738 delete_attributes, parameters))
739 {
740 STOREerr(STORE_F_STORE_MODIFY_PUBLIC_KEY,
741 STORE_R_FAILED_MODIFYING_PUBLIC_KEY);
742 return 0;
743 }
744 return 1;
745 }
746
747int STORE_revoke_public_key(STORE *s, OPENSSL_ITEM attributes[],
748 OPENSSL_ITEM parameters[])
749 {
750 int i;
751
752 check_store(s,STORE_F_STORE_REVOKE_PUBLIC_KEY,
753 revoke_object,STORE_R_NO_REVOKE_OBJECT_FUNCTION);
754
755 i = s->meth->revoke_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
756 attributes, parameters);
757
758 if (!i)
759 {
760 STOREerr(STORE_F_STORE_REVOKE_PUBLIC_KEY,
761 STORE_R_FAILED_REVOKING_KEY);
762 return 0;
763 }
764 return i;
765 }
766
767int STORE_delete_public_key(STORE *s, OPENSSL_ITEM attributes[],
768 OPENSSL_ITEM parameters[])
769 {
770 check_store(s,STORE_F_STORE_DELETE_PUBLIC_KEY,
771 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
772
773 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
774 attributes, parameters))
775 {
776 STOREerr(STORE_F_STORE_DELETE_PUBLIC_KEY,
777 STORE_R_FAILED_DELETING_KEY);
778 return 0;
779 }
780 return 1;
781 }
782
783void *STORE_list_public_key_start(STORE *s, OPENSSL_ITEM attributes[],
784 OPENSSL_ITEM parameters[])
785 {
786 void *handle;
787
788 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_START,
789 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
790
791 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_PUBLIC_KEY,
792 attributes, parameters);
793 if (!handle)
794 {
795 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_START,
796 STORE_R_FAILED_LISTING_KEYS);
797 return 0;
798 }
799 return handle;
800 }
801
802EVP_PKEY *STORE_list_public_key_next(STORE *s, void *handle)
803 {
804 STORE_OBJECT *object;
805 EVP_PKEY *pkey;
806
807 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
808 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
809
810 object = s->meth->list_object_next(s, handle);
811 if (!object || !object->data.key || !object->data.key)
812 {
813 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_NEXT,
814 STORE_R_FAILED_LISTING_KEYS);
815 return 0;
816 }
817 CRYPTO_add(&object->data.key->references,1,CRYPTO_LOCK_EVP_PKEY);
818#ifdef REF_PRINT
819 REF_PRINT("EVP_PKEY",data);
820#endif
821 pkey = object->data.key;
822 STORE_OBJECT_free(object);
823 return pkey;
824 }
825
826int STORE_list_public_key_end(STORE *s, void *handle)
827 {
828 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_END,
829 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
830
831 if (!s->meth->list_object_end(s, handle))
832 {
833 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_END,
834 STORE_R_FAILED_LISTING_KEYS);
835 return 0;
836 }
837 return 1;
838 }
839
840int STORE_list_public_key_endp(STORE *s, void *handle)
841 {
842 check_store(s,STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
843 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
844
845 if (!s->meth->list_object_endp(s, handle))
846 {
847 STOREerr(STORE_F_STORE_LIST_PUBLIC_KEY_ENDP,
848 STORE_R_FAILED_LISTING_KEYS);
849 return 0;
850 }
851 return 1;
852 }
853
854X509_CRL *STORE_generate_crl(STORE *s, OPENSSL_ITEM attributes[],
855 OPENSSL_ITEM parameters[])
856 {
857 STORE_OBJECT *object;
858 X509_CRL *crl;
859
860 check_store(s,STORE_F_STORE_GENERATE_CRL,
861 generate_object,STORE_R_NO_GENERATE_CRL_FUNCTION);
862
863 object = s->meth->generate_object(s, STORE_OBJECT_TYPE_X509_CRL,
864 attributes, parameters);
865 if (!object || !object->data.crl)
866 {
867 STOREerr(STORE_F_STORE_GENERATE_CRL,
868 STORE_R_FAILED_GENERATING_CRL);
869 return 0;
870 }
871 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
872#ifdef REF_PRINT
873 REF_PRINT("X509_CRL",data);
874#endif
875 crl = object->data.crl;
876 STORE_OBJECT_free(object);
877 return crl;
878 }
879
880X509_CRL *STORE_get_crl(STORE *s, OPENSSL_ITEM attributes[],
881 OPENSSL_ITEM parameters[])
882 {
883 STORE_OBJECT *object;
884 X509_CRL *crl;
885
886 check_store(s,STORE_F_STORE_GET_CRL,
887 get_object,STORE_R_NO_GET_OBJECT_FUNCTION);
888
889 object = s->meth->get_object(s, STORE_OBJECT_TYPE_X509_CRL,
890 attributes, parameters);
891 if (!object || !object->data.crl)
892 {
893 STOREerr(STORE_F_STORE_GET_CRL,
894 STORE_R_FAILED_GETTING_KEY);
895 return 0;
896 }
897 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
898#ifdef REF_PRINT
899 REF_PRINT("X509_CRL",data);
900#endif
901 crl = object->data.crl;
902 STORE_OBJECT_free(object);
903 return crl;
904 }
905
906int STORE_store_crl(STORE *s, X509_CRL *data, OPENSSL_ITEM attributes[],
907 OPENSSL_ITEM parameters[])
908 {
909 STORE_OBJECT *object;
910 int i;
911
912 check_store(s,STORE_F_STORE_STORE_CRL,
913 store_object,STORE_R_NO_STORE_OBJECT_FUNCTION);
914
915 object = STORE_OBJECT_new();
916 if (!object)
917 {
918 STOREerr(STORE_F_STORE_STORE_CRL,
919 ERR_R_MALLOC_FAILURE);
920 return 0;
921 }
922
923 CRYPTO_add(&data->references,1,CRYPTO_LOCK_X509_CRL);
924#ifdef REF_PRINT
925 REF_PRINT("X509_CRL",data);
926#endif
927 object->data.crl = data;
928
929 i = s->meth->store_object(s, STORE_OBJECT_TYPE_X509_CRL, object,
930 attributes, parameters);
931
932 STORE_OBJECT_free(object);
933
934 if (!i)
935 {
936 STOREerr(STORE_F_STORE_STORE_CRL,
937 STORE_R_FAILED_STORING_KEY);
938 return 0;
939 }
940 return i;
941 }
942
943int STORE_modify_crl(STORE *s, OPENSSL_ITEM search_attributes[],
944 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
945 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
946 {
947 check_store(s,STORE_F_STORE_MODIFY_CRL,
948 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
949
950 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_X509_CRL,
951 search_attributes, add_attributes, modify_attributes,
952 delete_attributes, parameters))
953 {
954 STOREerr(STORE_F_STORE_MODIFY_CRL,
955 STORE_R_FAILED_MODIFYING_CRL);
956 return 0;
957 }
958 return 1;
959 }
960
961int STORE_delete_crl(STORE *s, OPENSSL_ITEM attributes[],
962 OPENSSL_ITEM parameters[])
963 {
964 check_store(s,STORE_F_STORE_DELETE_CRL,
965 delete_object,STORE_R_NO_DELETE_OBJECT_FUNCTION);
966
967 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_X509_CRL,
968 attributes, parameters))
969 {
970 STOREerr(STORE_F_STORE_DELETE_CRL,
971 STORE_R_FAILED_DELETING_KEY);
972 return 0;
973 }
974 return 1;
975 }
976
977void *STORE_list_crl_start(STORE *s, OPENSSL_ITEM attributes[],
978 OPENSSL_ITEM parameters[])
979 {
980 void *handle;
981
982 check_store(s,STORE_F_STORE_LIST_CRL_START,
983 list_object_start,STORE_R_NO_LIST_OBJECT_START_FUNCTION);
984
985 handle = s->meth->list_object_start(s, STORE_OBJECT_TYPE_X509_CRL,
986 attributes, parameters);
987 if (!handle)
988 {
989 STOREerr(STORE_F_STORE_LIST_CRL_START,
990 STORE_R_FAILED_LISTING_KEYS);
991 return 0;
992 }
993 return handle;
994 }
995
996X509_CRL *STORE_list_crl_next(STORE *s, void *handle)
997 {
998 STORE_OBJECT *object;
999 X509_CRL *crl;
1000
1001 check_store(s,STORE_F_STORE_LIST_CRL_NEXT,
1002 list_object_next,STORE_R_NO_LIST_OBJECT_NEXT_FUNCTION);
1003
1004 object = s->meth->list_object_next(s, handle);
1005 if (!object || !object->data.crl)
1006 {
1007 STOREerr(STORE_F_STORE_LIST_CRL_NEXT,
1008 STORE_R_FAILED_LISTING_KEYS);
1009 return 0;
1010 }
1011 CRYPTO_add(&object->data.crl->references,1,CRYPTO_LOCK_X509_CRL);
1012#ifdef REF_PRINT
1013 REF_PRINT("X509_CRL",data);
1014#endif
1015 crl = object->data.crl;
1016 STORE_OBJECT_free(object);
1017 return crl;
1018 }
1019
1020int STORE_list_crl_end(STORE *s, void *handle)
1021 {
1022 check_store(s,STORE_F_STORE_LIST_CRL_END,
1023 list_object_end,STORE_R_NO_LIST_OBJECT_END_FUNCTION);
1024
1025 if (!s->meth->list_object_end(s, handle))
1026 {
1027 STOREerr(STORE_F_STORE_LIST_CRL_END,
1028 STORE_R_FAILED_LISTING_KEYS);
1029 return 0;
1030 }
1031 return 1;
1032 }
1033
1034int STORE_list_crl_endp(STORE *s, void *handle)
1035 {
1036 check_store(s,STORE_F_STORE_LIST_CRL_ENDP,
1037 list_object_endp,STORE_R_NO_LIST_OBJECT_ENDP_FUNCTION);
1038
1039 if (!s->meth->list_object_endp(s, handle))
1040 {
1041 STOREerr(STORE_F_STORE_LIST_CRL_ENDP,
1042 STORE_R_FAILED_LISTING_KEYS);
1043 return 0;
1044 }
1045 return 1;
1046 }
1047
1048int STORE_store_number(STORE *s, BIGNUM *data, OPENSSL_ITEM attributes[],
1049 OPENSSL_ITEM parameters[])
1050 {
1051 STORE_OBJECT *object;
1052 int i;
1053
1054 check_store(s,STORE_F_STORE_STORE_NUMBER,
1055 store_object,STORE_R_NO_STORE_OBJECT_NUMBER_FUNCTION);
1056
1057 object = STORE_OBJECT_new();
1058 if (!object)
1059 {
1060 STOREerr(STORE_F_STORE_STORE_NUMBER,
1061 ERR_R_MALLOC_FAILURE);
1062 return 0;
1063 }
1064
1065 object->data.number = data;
1066
1067 i = s->meth->store_object(s, STORE_OBJECT_TYPE_NUMBER, object,
1068 attributes, parameters);
1069
1070 STORE_OBJECT_free(object);
1071
1072 if (!i)
1073 {
1074 STOREerr(STORE_F_STORE_STORE_NUMBER,
1075 STORE_R_FAILED_STORING_NUMBER);
1076 return 0;
1077 }
1078 return 1;
1079 }
1080
1081int STORE_modify_number(STORE *s, OPENSSL_ITEM search_attributes[],
1082 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1083 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1084 {
1085 check_store(s,STORE_F_STORE_MODIFY_NUMBER,
1086 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1087
1088 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_NUMBER,
1089 search_attributes, add_attributes, modify_attributes,
1090 delete_attributes, parameters))
1091 {
1092 STOREerr(STORE_F_STORE_MODIFY_NUMBER,
1093 STORE_R_FAILED_MODIFYING_NUMBER);
1094 return 0;
1095 }
1096 return 1;
1097 }
1098
1099BIGNUM *STORE_get_number(STORE *s, OPENSSL_ITEM attributes[],
1100 OPENSSL_ITEM parameters[])
1101 {
1102 STORE_OBJECT *object;
1103 BIGNUM *n;
1104
1105 check_store(s,STORE_F_STORE_GET_NUMBER,
1106 get_object,STORE_R_NO_GET_OBJECT_NUMBER_FUNCTION);
1107
1108 object = s->meth->get_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1109 parameters);
1110 if (!object || !object->data.number)
1111 {
1112 STOREerr(STORE_F_STORE_GET_NUMBER,
1113 STORE_R_FAILED_GETTING_NUMBER);
1114 return 0;
1115 }
1116 n = object->data.number;
1117 object->data.number = NULL;
1118 STORE_OBJECT_free(object);
1119 return n;
1120 }
1121
1122int STORE_delete_number(STORE *s, OPENSSL_ITEM attributes[],
1123 OPENSSL_ITEM parameters[])
1124 {
1125 check_store(s,STORE_F_STORE_DELETE_NUMBER,
1126 delete_object,STORE_R_NO_DELETE_NUMBER_FUNCTION);
1127
1128 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_NUMBER, attributes,
1129 parameters))
1130 {
1131 STOREerr(STORE_F_STORE_DELETE_NUMBER,
1132 STORE_R_FAILED_DELETING_NUMBER);
1133 return 0;
1134 }
1135 return 1;
1136 }
1137
1138int STORE_store_arbitrary(STORE *s, BUF_MEM *data, OPENSSL_ITEM attributes[],
1139 OPENSSL_ITEM parameters[])
1140 {
1141 STORE_OBJECT *object;
1142 int i;
1143
1144 check_store(s,STORE_F_STORE_STORE_ARBITRARY,
1145 store_object,STORE_R_NO_STORE_OBJECT_ARBITRARY_FUNCTION);
1146
1147 object = STORE_OBJECT_new();
1148 if (!object)
1149 {
1150 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1151 ERR_R_MALLOC_FAILURE);
1152 return 0;
1153 }
1154
1155 object->data.arbitrary = data;
1156
1157 i = s->meth->store_object(s, STORE_OBJECT_TYPE_ARBITRARY, object,
1158 attributes, parameters);
1159
1160 STORE_OBJECT_free(object);
1161
1162 if (!i)
1163 {
1164 STOREerr(STORE_F_STORE_STORE_ARBITRARY,
1165 STORE_R_FAILED_STORING_ARBITRARY);
1166 return 0;
1167 }
1168 return 1;
1169 }
1170
1171int STORE_modify_arbitrary(STORE *s, OPENSSL_ITEM search_attributes[],
1172 OPENSSL_ITEM add_attributes[], OPENSSL_ITEM modify_attributes[],
1173 OPENSSL_ITEM delete_attributes[], OPENSSL_ITEM parameters[])
1174 {
1175 check_store(s,STORE_F_STORE_MODIFY_ARBITRARY,
1176 modify_object,STORE_R_NO_MODIFY_OBJECT_FUNCTION);
1177
1178 if (!s->meth->modify_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1179 search_attributes, add_attributes, modify_attributes,
1180 delete_attributes, parameters))
1181 {
1182 STOREerr(STORE_F_STORE_MODIFY_ARBITRARY,
1183 STORE_R_FAILED_MODIFYING_ARBITRARY);
1184 return 0;
1185 }
1186 return 1;
1187 }
1188
1189BUF_MEM *STORE_get_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1190 OPENSSL_ITEM parameters[])
1191 {
1192 STORE_OBJECT *object;
1193 BUF_MEM *b;
1194
1195 check_store(s,STORE_F_STORE_GET_ARBITRARY,
1196 get_object,STORE_R_NO_GET_OBJECT_ARBITRARY_FUNCTION);
1197
1198 object = s->meth->get_object(s, STORE_OBJECT_TYPE_ARBITRARY,
1199 attributes, parameters);
1200 if (!object || !object->data.arbitrary)
1201 {
1202 STOREerr(STORE_F_STORE_GET_ARBITRARY,
1203 STORE_R_FAILED_GETTING_ARBITRARY);
1204 return 0;
1205 }
1206 b = object->data.arbitrary;
1207 object->data.arbitrary = NULL;
1208 STORE_OBJECT_free(object);
1209 return b;
1210 }
1211
1212int STORE_delete_arbitrary(STORE *s, OPENSSL_ITEM attributes[],
1213 OPENSSL_ITEM parameters[])
1214 {
1215 check_store(s,STORE_F_STORE_DELETE_ARBITRARY,
1216 delete_object,STORE_R_NO_DELETE_ARBITRARY_FUNCTION);
1217
1218 if (!s->meth->delete_object(s, STORE_OBJECT_TYPE_ARBITRARY, attributes,
1219 parameters))
1220 {
1221 STOREerr(STORE_F_STORE_DELETE_ARBITRARY,
1222 STORE_R_FAILED_DELETING_ARBITRARY);
1223 return 0;
1224 }
1225 return 1;
1226 }
1227
1228STORE_OBJECT *STORE_OBJECT_new(void)
1229 {
1230 STORE_OBJECT *object = OPENSSL_malloc(sizeof(STORE_OBJECT));
1231 if (object) memset(object, 0, sizeof(STORE_OBJECT));
1232 return object;
1233 }
1234void STORE_OBJECT_free(STORE_OBJECT *data)
1235 {
1236 if (!data) return;
1237 switch (data->type)
1238 {
1239 case STORE_OBJECT_TYPE_X509_CERTIFICATE:
1240 X509_free(data->data.x509.certificate);
1241 break;
1242 case STORE_OBJECT_TYPE_X509_CRL:
1243 X509_CRL_free(data->data.crl);
1244 break;
1245 case STORE_OBJECT_TYPE_PRIVATE_KEY:
1246 case STORE_OBJECT_TYPE_PUBLIC_KEY:
1247 EVP_PKEY_free(data->data.key);
1248 break;
1249 case STORE_OBJECT_TYPE_NUMBER:
1250 BN_free(data->data.number);
1251 break;
1252 case STORE_OBJECT_TYPE_ARBITRARY:
1253 BUF_MEM_free(data->data.arbitrary);
1254 break;
1255 }
1256 OPENSSL_free(data);
1257 }
1258
1259IMPLEMENT_STACK_OF(STORE_OBJECT*)
1260
1261
1262struct STORE_attr_info_st
1263 {
1264 unsigned char set[(STORE_ATTR_TYPE_NUM + 8) / 8];
1265 union
1266 {
1267 char *cstring;
1268 unsigned char *sha1string;
1269 X509_NAME *dn;
1270 BIGNUM *number;
1271 void *any;
1272 } values[STORE_ATTR_TYPE_NUM+1];
1273 size_t value_sizes[STORE_ATTR_TYPE_NUM+1];
1274 };
1275
1276#define ATTR_IS_SET(a,i) ((i) > 0 && (i) < STORE_ATTR_TYPE_NUM \
1277 && ((a)->set[(i) / 8] & (1 << ((i) % 8))))
1278#define SET_ATTRBIT(a,i) ((a)->set[(i) / 8] |= (1 << ((i) % 8)))
1279#define CLEAR_ATTRBIT(a,i) ((a)->set[(i) / 8] &= ~(1 << ((i) % 8)))
1280
1281STORE_ATTR_INFO *STORE_ATTR_INFO_new(void)
1282 {
1283 return (STORE_ATTR_INFO *)OPENSSL_malloc(sizeof(STORE_ATTR_INFO));
1284 }
1285static void STORE_ATTR_INFO_attr_free(STORE_ATTR_INFO *attrs,
1286 STORE_ATTR_TYPES code)
1287 {
1288 if (ATTR_IS_SET(attrs,code))
1289 {
1290 switch(code)
1291 {
1292 case STORE_ATTR_FRIENDLYNAME:
1293 case STORE_ATTR_EMAIL:
1294 case STORE_ATTR_FILENAME:
1295 STORE_ATTR_INFO_modify_cstr(attrs, code, NULL, 0);
1296 break;
1297 case STORE_ATTR_KEYID:
1298 case STORE_ATTR_ISSUERKEYID:
1299 case STORE_ATTR_SUBJECTKEYID:
1300 case STORE_ATTR_ISSUERSERIALHASH:
1301 case STORE_ATTR_CERTHASH:
1302 STORE_ATTR_INFO_modify_sha1str(attrs, code, NULL, 0);
1303 break;
1304 case STORE_ATTR_ISSUER:
1305 case STORE_ATTR_SUBJECT:
1306 STORE_ATTR_INFO_modify_dn(attrs, code, NULL);
1307 break;
1308 case STORE_ATTR_SERIAL:
1309 STORE_ATTR_INFO_modify_number(attrs, code, NULL);
1310 break;
1311 default:
1312 break;
1313 }
1314 }
1315 }
1316int STORE_ATTR_INFO_free(STORE_ATTR_INFO *attrs)
1317 {
1318 if (attrs)
1319 {
1320 STORE_ATTR_TYPES i;
1321 for(i = 0; i++ < STORE_ATTR_TYPE_NUM;)
1322 STORE_ATTR_INFO_attr_free(attrs, i);
1323 OPENSSL_free(attrs);
1324 }
1325 return 1;
1326 }
1327char *STORE_ATTR_INFO_get0_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1328 {
1329 if (!attrs)
1330 {
1331 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1332 ERR_R_PASSED_NULL_PARAMETER);
1333 return NULL;
1334 }
1335 if (ATTR_IS_SET(attrs,code))
1336 return attrs->values[code].cstring;
1337 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_CSTR,
1338 STORE_R_NO_VALUE);
1339 return NULL;
1340 }
1341unsigned char *STORE_ATTR_INFO_get0_sha1str(STORE_ATTR_INFO *attrs,
1342 STORE_ATTR_TYPES code)
1343 {
1344 if (!attrs)
1345 {
1346 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1347 ERR_R_PASSED_NULL_PARAMETER);
1348 return NULL;
1349 }
1350 if (ATTR_IS_SET(attrs,code))
1351 return attrs->values[code].sha1string;
1352 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_SHA1STR,
1353 STORE_R_NO_VALUE);
1354 return NULL;
1355 }
1356X509_NAME *STORE_ATTR_INFO_get0_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1357 {
1358 if (!attrs)
1359 {
1360 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1361 ERR_R_PASSED_NULL_PARAMETER);
1362 return NULL;
1363 }
1364 if (ATTR_IS_SET(attrs,code))
1365 return attrs->values[code].dn;
1366 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_DN,
1367 STORE_R_NO_VALUE);
1368 return NULL;
1369 }
1370BIGNUM *STORE_ATTR_INFO_get0_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code)
1371 {
1372 if (!attrs)
1373 {
1374 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1375 ERR_R_PASSED_NULL_PARAMETER);
1376 return NULL;
1377 }
1378 if (ATTR_IS_SET(attrs,code))
1379 return attrs->values[code].number;
1380 STOREerr(STORE_F_STORE_ATTR_INFO_GET0_NUMBER,
1381 STORE_R_NO_VALUE);
1382 return NULL;
1383 }
1384int STORE_ATTR_INFO_set_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1385 char *cstr, size_t cstr_size)
1386 {
1387 if (!attrs)
1388 {
1389 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1390 ERR_R_PASSED_NULL_PARAMETER);
1391 return 0;
1392 }
1393 if (!ATTR_IS_SET(attrs,code))
1394 {
1395 if ((attrs->values[code].cstring = BUF_strndup(cstr, cstr_size)))
1396 return 1;
1397 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR,
1398 ERR_R_MALLOC_FAILURE);
1399 return 0;
1400 }
1401 STOREerr(STORE_F_STORE_ATTR_INFO_SET_CSTR, STORE_R_ALREADY_HAS_A_VALUE);
1402 return 0;
1403 }
1404int STORE_ATTR_INFO_set_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1405 unsigned char *sha1str, size_t sha1str_size)
1406 {
1407 if (!attrs)
1408 {
1409 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1410 ERR_R_PASSED_NULL_PARAMETER);
1411 return 0;
1412 }
1413 if (!ATTR_IS_SET(attrs,code))
1414 {
1415 if ((attrs->values[code].sha1string =
1416 (unsigned char *)BUF_memdup(sha1str,
1417 sha1str_size)))
1418 return 1;
1419 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR,
1420 ERR_R_MALLOC_FAILURE);
1421 return 0;
1422 }
1423 STOREerr(STORE_F_STORE_ATTR_INFO_SET_SHA1STR, STORE_R_ALREADY_HAS_A_VALUE);
1424 return 0;
1425 }
1426int STORE_ATTR_INFO_set_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1427 X509_NAME *dn)
1428 {
1429 if (!attrs)
1430 {
1431 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1432 ERR_R_PASSED_NULL_PARAMETER);
1433 return 0;
1434 }
1435 if (!ATTR_IS_SET(attrs,code))
1436 {
1437 if ((attrs->values[code].dn = X509_NAME_dup(dn)))
1438 return 1;
1439 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN,
1440 ERR_R_MALLOC_FAILURE);
1441 return 0;
1442 }
1443 STOREerr(STORE_F_STORE_ATTR_INFO_SET_DN, STORE_R_ALREADY_HAS_A_VALUE);
1444 return 0;
1445 }
1446int STORE_ATTR_INFO_set_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1447 BIGNUM *number)
1448 {
1449 if (!attrs)
1450 {
1451 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1452 ERR_R_PASSED_NULL_PARAMETER);
1453 return 0;
1454 }
1455 if (!ATTR_IS_SET(attrs,code))
1456 {
1457 if ((attrs->values[code].number = BN_dup(number)))
1458 return 1;
1459 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER,
1460 ERR_R_MALLOC_FAILURE);
1461 return 0;
1462 }
1463 STOREerr(STORE_F_STORE_ATTR_INFO_SET_NUMBER, STORE_R_ALREADY_HAS_A_VALUE);
1464 return 0;
1465 }
1466int STORE_ATTR_INFO_modify_cstr(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1467 char *cstr, size_t cstr_size)
1468 {
1469 if (!attrs)
1470 {
1471 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_CSTR,
1472 ERR_R_PASSED_NULL_PARAMETER);
1473 return 0;
1474 }
1475 if (ATTR_IS_SET(attrs,code))
1476 {
1477 OPENSSL_free(attrs->values[code].cstring);
1478 attrs->values[code].cstring = NULL;
1479 CLEAR_ATTRBIT(attrs, code);
1480 }
1481 return STORE_ATTR_INFO_set_cstr(attrs, code, cstr, cstr_size);
1482 }
1483int STORE_ATTR_INFO_modify_sha1str(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1484 unsigned char *sha1str, size_t sha1str_size)
1485 {
1486 if (!attrs)
1487 {
1488 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_SHA1STR,
1489 ERR_R_PASSED_NULL_PARAMETER);
1490 return 0;
1491 }
1492 if (ATTR_IS_SET(attrs,code))
1493 {
1494 OPENSSL_free(attrs->values[code].sha1string);
1495 attrs->values[code].sha1string = NULL;
1496 CLEAR_ATTRBIT(attrs, code);
1497 }
1498 return STORE_ATTR_INFO_set_sha1str(attrs, code, sha1str, sha1str_size);
1499 }
1500int STORE_ATTR_INFO_modify_dn(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1501 X509_NAME *dn)
1502 {
1503 if (!attrs)
1504 {
1505 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_DN,
1506 ERR_R_PASSED_NULL_PARAMETER);
1507 return 0;
1508 }
1509 if (ATTR_IS_SET(attrs,code))
1510 {
1511 OPENSSL_free(attrs->values[code].dn);
1512 attrs->values[code].dn = NULL;
1513 CLEAR_ATTRBIT(attrs, code);
1514 }
1515 return STORE_ATTR_INFO_set_dn(attrs, code, dn);
1516 }
1517int STORE_ATTR_INFO_modify_number(STORE_ATTR_INFO *attrs, STORE_ATTR_TYPES code,
1518 BIGNUM *number)
1519 {
1520 if (!attrs)
1521 {
1522 STOREerr(STORE_F_STORE_ATTR_INFO_MODIFY_NUMBER,
1523 ERR_R_PASSED_NULL_PARAMETER);
1524 return 0;
1525 }
1526 if (ATTR_IS_SET(attrs,code))
1527 {
1528 OPENSSL_free(attrs->values[code].number);
1529 attrs->values[code].number = NULL;
1530 CLEAR_ATTRBIT(attrs, code);
1531 }
1532 return STORE_ATTR_INFO_set_number(attrs, code, number);
1533 }
1534
1535struct attr_list_ctx_st
1536 {
1537 OPENSSL_ITEM *attributes;
1538 };
1539void *STORE_parse_attrs_start(OPENSSL_ITEM *attributes)
1540 {
1541 if (attributes)
1542 {
1543 struct attr_list_ctx_st *context =
1544 (struct attr_list_ctx_st *)OPENSSL_malloc(sizeof(struct attr_list_ctx_st));
1545 if (context)
1546 context->attributes = attributes;
1547 else
1548 STOREerr(STORE_F_STORE_PARSE_ATTRS_START,
1549 ERR_R_MALLOC_FAILURE);
1550 return context;
1551 }
1552 STOREerr(STORE_F_STORE_PARSE_ATTRS_START, ERR_R_PASSED_NULL_PARAMETER);
1553 return 0;
1554 }
1555STORE_ATTR_INFO *STORE_parse_attrs_next(void *handle)
1556 {
1557 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1558
1559 if (context && context->attributes)
1560 {
1561 STORE_ATTR_INFO *attrs = NULL;
1562
1563 while(context->attributes
1564 && context->attributes->code != STORE_ATTR_OR
1565 && context->attributes->code != STORE_ATTR_END)
1566 {
1567 switch(context->attributes->code)
1568 {
1569 case STORE_ATTR_FRIENDLYNAME:
1570 case STORE_ATTR_EMAIL:
1571 case STORE_ATTR_FILENAME:
1572 if (!attrs) attrs = STORE_ATTR_INFO_new();
1573 if (attrs == NULL)
1574 {
1575 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1576 ERR_R_MALLOC_FAILURE);
1577 goto err;
1578 }
1579 STORE_ATTR_INFO_set_cstr(attrs,
1580 context->attributes->code,
1581 context->attributes->value,
1582 context->attributes->value_size);
1583 break;
1584 case STORE_ATTR_KEYID:
1585 case STORE_ATTR_ISSUERKEYID:
1586 case STORE_ATTR_SUBJECTKEYID:
1587 case STORE_ATTR_ISSUERSERIALHASH:
1588 case STORE_ATTR_CERTHASH:
1589 if (!attrs) attrs = STORE_ATTR_INFO_new();
1590 if (attrs == NULL)
1591 {
1592 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1593 ERR_R_MALLOC_FAILURE);
1594 goto err;
1595 }
1596 STORE_ATTR_INFO_set_sha1str(attrs,
1597 context->attributes->code,
1598 context->attributes->value,
1599 context->attributes->value_size);
1600 break;
1601 case STORE_ATTR_ISSUER:
1602 case STORE_ATTR_SUBJECT:
1603 if (!attrs) attrs = STORE_ATTR_INFO_new();
1604 if (attrs == NULL)
1605 {
1606 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1607 ERR_R_MALLOC_FAILURE);
1608 goto err;
1609 }
1610 STORE_ATTR_INFO_modify_dn(attrs,
1611 context->attributes->code,
1612 context->attributes->value);
1613 break;
1614 case STORE_ATTR_SERIAL:
1615 if (!attrs) attrs = STORE_ATTR_INFO_new();
1616 if (attrs == NULL)
1617 {
1618 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT,
1619 ERR_R_MALLOC_FAILURE);
1620 goto err;
1621 }
1622 STORE_ATTR_INFO_modify_number(attrs,
1623 context->attributes->code,
1624 context->attributes->value);
1625 break;
1626 }
1627 context->attributes++;
1628 }
1629 if (context->attributes->code == STORE_ATTR_OR)
1630 context->attributes++;
1631 return attrs;
1632 err:
1633 while(context->attributes
1634 && context->attributes->code != STORE_ATTR_OR
1635 && context->attributes->code != STORE_ATTR_END)
1636 context->attributes++;
1637 if (context->attributes->code == STORE_ATTR_OR)
1638 context->attributes++;
1639 return NULL;
1640 }
1641 STOREerr(STORE_F_STORE_PARSE_ATTRS_NEXT, ERR_R_PASSED_NULL_PARAMETER);
1642 return NULL;
1643 }
1644int STORE_parse_attrs_end(void *handle)
1645 {
1646 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1647
1648 if (context && context->attributes)
1649 {
1650#if 0
1651 OPENSSL_ITEM *attributes = context->attributes;
1652#endif
1653 OPENSSL_free(context);
1654 return 1;
1655 }
1656 STOREerr(STORE_F_STORE_PARSE_ATTRS_END, ERR_R_PASSED_NULL_PARAMETER);
1657 return 0;
1658 }
1659
1660int STORE_parse_attrs_endp(void *handle)
1661 {
1662 struct attr_list_ctx_st *context = (struct attr_list_ctx_st *)handle;
1663
1664 if (context && context->attributes)
1665 {
1666 return context->attributes->code == STORE_ATTR_END;
1667 }
1668 STOREerr(STORE_F_STORE_PARSE_ATTRS_ENDP, ERR_R_PASSED_NULL_PARAMETER);
1669 return 0;
1670 }
1671
1672static int attr_info_compare_compute_range(
1673 unsigned char *abits, unsigned char *bbits,
1674 unsigned int *alowp, unsigned int *ahighp,
1675 unsigned int *blowp, unsigned int *bhighp)
1676 {
1677 unsigned int alow = (unsigned int)-1, ahigh = 0;
1678 unsigned int blow = (unsigned int)-1, bhigh = 0;
1679 int i, res = 0;
1680
1681 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1682 {
1683 if (res == 0)
1684 {
1685 if (*abits < *bbits) res = -1;
1686 if (*abits > *bbits) res = 1;
1687 }
1688 if (*abits)
1689 {
1690 if (alow == (unsigned int)-1)
1691 {
1692 alow = i * 8;
1693 if (!(*abits & 0x01)) alow++;
1694 if (!(*abits & 0x02)) alow++;
1695 if (!(*abits & 0x04)) alow++;
1696 if (!(*abits & 0x08)) alow++;
1697 if (!(*abits & 0x10)) alow++;
1698 if (!(*abits & 0x20)) alow++;
1699 if (!(*abits & 0x40)) alow++;
1700 }
1701 ahigh = i * 8 + 7;
1702 if (!(*abits & 0x80)) ahigh++;
1703 if (!(*abits & 0x40)) ahigh++;
1704 if (!(*abits & 0x20)) ahigh++;
1705 if (!(*abits & 0x10)) ahigh++;
1706 if (!(*abits & 0x08)) ahigh++;
1707 if (!(*abits & 0x04)) ahigh++;
1708 if (!(*abits & 0x02)) ahigh++;
1709 }
1710 if (*bbits)
1711 {
1712 if (blow == (unsigned int)-1)
1713 {
1714 blow = i * 8;
1715 if (!(*bbits & 0x01)) blow++;
1716 if (!(*bbits & 0x02)) blow++;
1717 if (!(*bbits & 0x04)) blow++;
1718 if (!(*bbits & 0x08)) blow++;
1719 if (!(*bbits & 0x10)) blow++;
1720 if (!(*bbits & 0x20)) blow++;
1721 if (!(*bbits & 0x40)) blow++;
1722 }
1723 bhigh = i * 8 + 7;
1724 if (!(*bbits & 0x80)) bhigh++;
1725 if (!(*bbits & 0x40)) bhigh++;
1726 if (!(*bbits & 0x20)) bhigh++;
1727 if (!(*bbits & 0x10)) bhigh++;
1728 if (!(*bbits & 0x08)) bhigh++;
1729 if (!(*bbits & 0x04)) bhigh++;
1730 if (!(*bbits & 0x02)) bhigh++;
1731 }
1732 }
1733 if (ahigh + alow < bhigh + blow) res = -1;
1734 if (ahigh + alow > bhigh + blow) res = 1;
1735 if (alowp) *alowp = alow;
1736 if (ahighp) *ahighp = ahigh;
1737 if (blowp) *blowp = blow;
1738 if (bhighp) *bhighp = bhigh;
1739 return res;
1740 }
1741
1742int STORE_ATTR_INFO_compare(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1743 {
1744 if (a == b) return 0;
1745 if (!a) return -1;
1746 if (!b) return 1;
1747 return attr_info_compare_compute_range(a->set, b->set, 0, 0, 0, 0);
1748 }
1749int STORE_ATTR_INFO_in_range(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1750 {
1751 unsigned int alow, ahigh, blow, bhigh;
1752
1753 if (a == b) return 1;
1754 if (!a) return 0;
1755 if (!b) return 0;
1756 attr_info_compare_compute_range(a->set, b->set,
1757 &alow, &ahigh, &blow, &bhigh);
1758 if (alow >= blow && ahigh <= bhigh)
1759 return 1;
1760 return 0;
1761 }
1762int STORE_ATTR_INFO_in(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1763 {
1764 unsigned char *abits, *bbits;
1765 int i;
1766
1767 if (a == b) return 1;
1768 if (!a) return 0;
1769 if (!b) return 0;
1770 abits = a->set;
1771 bbits = b->set;
1772 for (i = 0; i < (STORE_ATTR_TYPE_NUM + 8) / 8; i++, abits++, bbits++)
1773 {
1774 if (*abits && (*bbits & *abits) != *abits)
1775 return 0;
1776 }
1777 return 1;
1778 }
1779int STORE_ATTR_INFO_in_ex(STORE_ATTR_INFO *a, STORE_ATTR_INFO *b)
1780 {
1781 STORE_ATTR_TYPES i;
1782
1783 if (a == b) return 1;
1784 if (!STORE_ATTR_INFO_in(a, b)) return 0;
1785 for (i = 1; i < STORE_ATTR_TYPE_NUM; i++)
1786 if (ATTR_IS_SET(a, i))
1787 {
1788 switch(i)
1789 {
1790 case STORE_ATTR_FRIENDLYNAME:
1791 case STORE_ATTR_EMAIL:
1792 case STORE_ATTR_FILENAME:
1793 if (strcmp(a->values[i].cstring,
1794 b->values[i].cstring))
1795 return 0;
1796 break;
1797 case STORE_ATTR_KEYID:
1798 case STORE_ATTR_ISSUERKEYID:
1799 case STORE_ATTR_SUBJECTKEYID:
1800 case STORE_ATTR_ISSUERSERIALHASH:
1801 case STORE_ATTR_CERTHASH:
1802 if (memcmp(a->values[i].sha1string,
1803 b->values[i].sha1string,
1804 a->value_sizes[i]))
1805 return 0;
1806 break;
1807 case STORE_ATTR_ISSUER:
1808 case STORE_ATTR_SUBJECT:
1809 if (X509_NAME_cmp(a->values[i].dn,
1810 b->values[i].dn))
1811 return 0;
1812 break;
1813 case STORE_ATTR_SERIAL:
1814 if (BN_cmp(a->values[i].number,
1815 b->values[i].number))
1816 return 0;
1817 break;
1818 default:
1819 break;
1820 }
1821 }
1822
1823 return 1;
1824 }
diff --git a/src/lib/libcrypto/store/str_locl.h b/src/lib/libcrypto/store/str_locl.h
new file mode 100644
index 0000000000..3f8cb75619
--- /dev/null
+++ b/src/lib/libcrypto/store/str_locl.h
@@ -0,0 +1,124 @@
1/* crypto/store/str_locl.h -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#ifndef HEADER_STORE_LOCL_H
60#define HEADER_STORE_LOCL_H
61
62#include <openssl/crypto.h>
63#include <openssl/store.h>
64
65#ifdef __cplusplus
66extern "C" {
67#endif
68
69struct store_method_st
70 {
71 char *name;
72
73 /* All the functions return a positive integer or non-NULL for success
74 and 0, a negative integer or NULL for failure */
75
76 /* Initialise the STORE with private data */
77 STORE_INITIALISE_FUNC_PTR init;
78 /* Initialise the STORE with private data */
79 STORE_CLEANUP_FUNC_PTR clean;
80 /* Generate an object of a given type */
81 STORE_GENERATE_OBJECT_FUNC_PTR generate_object;
82 /* Get an object of a given type. This function isn't really very
83 useful since the listing functions (below) can be used for the
84 same purpose and are much more general. */
85 STORE_GET_OBJECT_FUNC_PTR get_object;
86 /* Store an object of a given type. */
87 STORE_STORE_OBJECT_FUNC_PTR store_object;
88 /* Modify the attributes bound to an object of a given type. */
89 STORE_MODIFY_OBJECT_FUNC_PTR modify_object;
90 /* Revoke an object of a given type. */
91 STORE_HANDLE_OBJECT_FUNC_PTR revoke_object;
92 /* Delete an object of a given type. */
93 STORE_HANDLE_OBJECT_FUNC_PTR delete_object;
94 /* List a bunch of objects of a given type and with the associated
95 attributes. */
96 STORE_START_OBJECT_FUNC_PTR list_object_start;
97 STORE_NEXT_OBJECT_FUNC_PTR list_object_next;
98 STORE_END_OBJECT_FUNC_PTR list_object_end;
99 STORE_END_OBJECT_FUNC_PTR list_object_endp;
100 /* Store-level function to make any necessary update operations. */
101 STORE_GENERIC_FUNC_PTR update_store;
102 /* Store-level function to get exclusive access to the store. */
103 STORE_GENERIC_FUNC_PTR lock_store;
104 /* Store-level function to release exclusive access to the store. */
105 STORE_GENERIC_FUNC_PTR unlock_store;
106
107 /* Generic control function */
108 STORE_CTRL_FUNC_PTR ctrl;
109 };
110
111struct store_st
112 {
113 const STORE_METHOD *meth;
114 /* functional reference if 'meth' is ENGINE-provided */
115 ENGINE *engine;
116
117 CRYPTO_EX_DATA ex_data;
118 int references;
119 };
120#ifdef __cplusplus
121}
122#endif
123
124#endif
diff --git a/src/lib/libcrypto/store/str_mem.c b/src/lib/libcrypto/store/str_mem.c
new file mode 100644
index 0000000000..527757ae09
--- /dev/null
+++ b/src/lib/libcrypto/store/str_mem.c
@@ -0,0 +1,357 @@
1/* crypto/store/str_mem.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/err.h>
61#include "str_locl.h"
62
63/* The memory store is currently highly experimental. It's meant to become
64 a base store used by other stores for internal caching (for full caching
65 support, aging needs to be added).
66
67 The database use is meant to support as much attribute association as
68 possible, while providing for as small search ranges as possible.
69 This is currently provided for by sorting the entries by numbers that
70 are composed of bits set at the positions indicated by attribute type
71 codes. This provides for ranges determined by the highest attribute
72 type code value. A better idea might be to sort by values computed
73 from the range of attributes associated with the object (basically,
74 the difference between the highest and lowest attribute type code)
75 and it's distance from a base (basically, the lowest associated
76 attribute type code).
77*/
78
79struct mem_object_data_st
80 {
81 STORE_OBJECT *object;
82 STORE_ATTR_INFO *attr_info;
83 int references;
84 };
85
86struct mem_data_st
87 {
88 STACK *data; /* A stack of mem_object_data_st,
89 sorted with STORE_ATTR_INFO_compare(). */
90 unsigned int compute_components : 1; /* Currently unused, but can
91 be used to add attributes
92 from parts of the data. */
93 };
94
95struct mem_ctx_st
96 {
97 int type; /* The type we're searching for */
98 STACK *search_attributes; /* Sets of attributes to search for.
99 Each element is a STORE_ATTR_INFO. */
100 int search_index; /* which of the search attributes we found a match
101 for, -1 when we still haven't found any */
102 int index; /* -1 as long as we're searching for the first */
103 };
104
105static int mem_init(STORE *s);
106static void mem_clean(STORE *s);
107static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type,
108 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
109static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
110 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
111static int mem_store(STORE *s, STORE_OBJECT_TYPES type,
112 STORE_OBJECT *data, OPENSSL_ITEM attributes[],
113 OPENSSL_ITEM parameters[]);
114static int mem_modify(STORE *s, STORE_OBJECT_TYPES type,
115 OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[],
116 OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[],
117 OPENSSL_ITEM parameters[]);
118static int mem_delete(STORE *s, STORE_OBJECT_TYPES type,
119 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
120static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
121 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[]);
122static STORE_OBJECT *mem_list_next(STORE *s, void *handle);
123static int mem_list_end(STORE *s, void *handle);
124static int mem_list_endp(STORE *s, void *handle);
125static int mem_lock(STORE *s, OPENSSL_ITEM attributes[],
126 OPENSSL_ITEM parameters[]);
127static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[],
128 OPENSSL_ITEM parameters[]);
129static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void));
130
131static STORE_METHOD store_memory =
132 {
133 "OpenSSL memory store interface",
134 mem_init,
135 mem_clean,
136 mem_generate,
137 mem_get,
138 mem_store,
139 mem_modify,
140 NULL, /* revoke */
141 mem_delete,
142 mem_list_start,
143 mem_list_next,
144 mem_list_end,
145 mem_list_endp,
146 NULL, /* update */
147 mem_lock,
148 mem_unlock,
149 mem_ctrl
150 };
151
152const STORE_METHOD *STORE_Memory(void)
153 {
154 return &store_memory;
155 }
156
157static int mem_init(STORE *s)
158 {
159 return 1;
160 }
161
162static void mem_clean(STORE *s)
163 {
164 return;
165 }
166
167static STORE_OBJECT *mem_generate(STORE *s, STORE_OBJECT_TYPES type,
168 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
169 {
170 STOREerr(STORE_F_MEM_GENERATE, STORE_R_NOT_IMPLEMENTED);
171 return 0;
172 }
173static STORE_OBJECT *mem_get(STORE *s, STORE_OBJECT_TYPES type,
174 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
175 {
176 void *context = mem_list_start(s, type, attributes, parameters);
177
178 if (context)
179 {
180 STORE_OBJECT *object = mem_list_next(s, context);
181
182 if (mem_list_end(s, context))
183 return object;
184 }
185 return NULL;
186 }
187static int mem_store(STORE *s, STORE_OBJECT_TYPES type,
188 STORE_OBJECT *data, OPENSSL_ITEM attributes[],
189 OPENSSL_ITEM parameters[])
190 {
191 STOREerr(STORE_F_MEM_STORE, STORE_R_NOT_IMPLEMENTED);
192 return 0;
193 }
194static int mem_modify(STORE *s, STORE_OBJECT_TYPES type,
195 OPENSSL_ITEM search_attributes[], OPENSSL_ITEM add_attributes[],
196 OPENSSL_ITEM modify_attributes[], OPENSSL_ITEM delete_attributes[],
197 OPENSSL_ITEM parameters[])
198 {
199 STOREerr(STORE_F_MEM_MODIFY, STORE_R_NOT_IMPLEMENTED);
200 return 0;
201 }
202static int mem_delete(STORE *s, STORE_OBJECT_TYPES type,
203 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
204 {
205 STOREerr(STORE_F_MEM_DELETE, STORE_R_NOT_IMPLEMENTED);
206 return 0;
207 }
208
209/* The list functions may be the hardest to understand. Basically,
210 mem_list_start compiles a stack of attribute info elements, and
211 puts that stack into the context to be returned. mem_list_next
212 will then find the first matching element in the store, and then
213 walk all the way to the end of the store (since any combination
214 of attribute bits above the starting point may match the searched
215 for bit pattern...). */
216static void *mem_list_start(STORE *s, STORE_OBJECT_TYPES type,
217 OPENSSL_ITEM attributes[], OPENSSL_ITEM parameters[])
218 {
219 struct mem_ctx_st *context =
220 (struct mem_ctx_st *)OPENSSL_malloc(sizeof(struct mem_ctx_st));
221 void *attribute_context = NULL;
222 STORE_ATTR_INFO *attrs = NULL;
223
224 if (!context)
225 {
226 STOREerr(STORE_F_MEM_LIST_START, ERR_R_MALLOC_FAILURE);
227 return 0;
228 }
229 memset(context, 0, sizeof(struct mem_ctx_st));
230
231 attribute_context = STORE_parse_attrs_start(attributes);
232 if (!attribute_context)
233 {
234 STOREerr(STORE_F_MEM_LIST_START, ERR_R_STORE_LIB);
235 goto err;
236 }
237
238 while((attrs = STORE_parse_attrs_next(attribute_context)))
239 {
240 if (context->search_attributes == NULL)
241 {
242 context->search_attributes =
243 sk_new((int (*)(const char * const *, const char * const *))STORE_ATTR_INFO_compare);
244 if (!context->search_attributes)
245 {
246 STOREerr(STORE_F_MEM_LIST_START,
247 ERR_R_MALLOC_FAILURE);
248 goto err;
249 }
250 }
251 sk_push(context->search_attributes,(char *)attrs);
252 }
253 if (!STORE_parse_attrs_endp(attribute_context))
254 goto err;
255 STORE_parse_attrs_end(attribute_context);
256 context->search_index = -1;
257 context->index = -1;
258 return context;
259 err:
260 if (attribute_context) STORE_parse_attrs_end(attribute_context);
261 mem_list_end(s, context);
262 return NULL;
263 }
264static STORE_OBJECT *mem_list_next(STORE *s, void *handle)
265 {
266 int i;
267 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
268 struct mem_object_data_st key = { 0, 0, 1 };
269 struct mem_data_st *store =
270 (struct mem_data_st *)STORE_get_ex_data(s, 1);
271 int srch;
272 int cres = 0;
273
274 if (!context)
275 {
276 STOREerr(STORE_F_MEM_LIST_NEXT, ERR_R_PASSED_NULL_PARAMETER);
277 return NULL;
278 }
279 if (!store)
280 {
281 STOREerr(STORE_F_MEM_LIST_NEXT, STORE_R_NO_STORE);
282 return NULL;
283 }
284
285 if (context->search_index == -1)
286 {
287 for (i = 0; i < sk_num(context->search_attributes); i++)
288 {
289 key.attr_info =
290 (STORE_ATTR_INFO *)sk_value(context->search_attributes, i);
291 srch = sk_find_ex(store->data, (char *)&key);
292
293 if (srch >= 0)
294 {
295 context->search_index = srch;
296 break;
297 }
298 }
299 }
300 if (context->search_index < 0)
301 return NULL;
302
303 key.attr_info =
304 (STORE_ATTR_INFO *)sk_value(context->search_attributes,
305 context->search_index);
306 for(srch = context->search_index;
307 srch < sk_num(store->data)
308 && STORE_ATTR_INFO_in_range(key.attr_info,
309 (STORE_ATTR_INFO *)sk_value(store->data, srch))
310 && !(cres = STORE_ATTR_INFO_in_ex(key.attr_info,
311 (STORE_ATTR_INFO *)sk_value(store->data, srch)));
312 srch++)
313 ;
314
315 context->search_index = srch;
316 if (cres)
317 return ((struct mem_object_data_st *)sk_value(store->data,
318 srch))->object;
319 return NULL;
320 }
321static int mem_list_end(STORE *s, void *handle)
322 {
323 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
324
325 if (!context)
326 {
327 STOREerr(STORE_F_MEM_LIST_END, ERR_R_PASSED_NULL_PARAMETER);
328 return 0;
329 }
330 if (context && context->search_attributes)
331 sk_free(context->search_attributes);
332 if (context) OPENSSL_free(context);
333 return 1;
334 }
335static int mem_list_endp(STORE *s, void *handle)
336 {
337 struct mem_ctx_st *context = (struct mem_ctx_st *)handle;
338
339 if (!context
340 || context->search_index == sk_num(context->search_attributes))
341 return 1;
342 return 0;
343 }
344static int mem_lock(STORE *s, OPENSSL_ITEM attributes[],
345 OPENSSL_ITEM parameters[])
346 {
347 return 1;
348 }
349static int mem_unlock(STORE *s, OPENSSL_ITEM attributes[],
350 OPENSSL_ITEM parameters[])
351 {
352 return 1;
353 }
354static int mem_ctrl(STORE *s, int cmd, long l, void *p, void (*f)(void))
355 {
356 return 1;
357 }
diff --git a/src/lib/libcrypto/store/str_meth.c b/src/lib/libcrypto/store/str_meth.c
new file mode 100644
index 0000000000..a46de03a26
--- /dev/null
+++ b/src/lib/libcrypto/store/str_meth.c
@@ -0,0 +1,250 @@
1/* crypto/store/str_meth.c -*- mode:C; c-file-style: "eay" -*- */
2/* Written by Richard Levitte (richard@levitte.org) for the OpenSSL
3 * project 2003.
4 */
5/* ====================================================================
6 * Copyright (c) 2003 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * openssl-core@openssl.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59#include <string.h>
60#include <openssl/buffer.h>
61#include "str_locl.h"
62
63STORE_METHOD *STORE_create_method(char *name)
64 {
65 STORE_METHOD *store_method = (STORE_METHOD *)OPENSSL_malloc(sizeof(STORE_METHOD));
66
67 if (store_method)
68 {
69 memset(store_method, 0, sizeof(*store_method));
70 store_method->name = BUF_strdup(name);
71 }
72 return store_method;
73 }
74
75/* BIG FSCKING WARNING!!!! If you use this on a statically allocated method
76 (that is, it hasn't been allocated using STORE_create_method(), you deserve
77 anything Murphy can throw at you and more! You have been warned. */
78void STORE_destroy_method(STORE_METHOD *store_method)
79 {
80 if (!store_method) return;
81 OPENSSL_free(store_method->name);
82 store_method->name = NULL;
83 OPENSSL_free(store_method);
84 }
85
86int STORE_method_set_initialise_function(STORE_METHOD *sm, STORE_INITIALISE_FUNC_PTR init_f)
87 {
88 sm->init = init_f;
89 return 1;
90 }
91
92int STORE_method_set_cleanup_function(STORE_METHOD *sm, STORE_CLEANUP_FUNC_PTR clean_f)
93 {
94 sm->clean = clean_f;
95 return 1;
96 }
97
98int STORE_method_set_generate_function(STORE_METHOD *sm, STORE_GENERATE_OBJECT_FUNC_PTR generate_f)
99 {
100 sm->generate_object = generate_f;
101 return 1;
102 }
103
104int STORE_method_set_get_function(STORE_METHOD *sm, STORE_GET_OBJECT_FUNC_PTR get_f)
105 {
106 sm->get_object = get_f;
107 return 1;
108 }
109
110int STORE_method_set_store_function(STORE_METHOD *sm, STORE_STORE_OBJECT_FUNC_PTR store_f)
111 {
112 sm->store_object = store_f;
113 return 1;
114 }
115
116int STORE_method_set_modify_function(STORE_METHOD *sm, STORE_MODIFY_OBJECT_FUNC_PTR modify_f)
117 {
118 sm->modify_object = modify_f;
119 return 1;
120 }
121
122int STORE_method_set_revoke_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR revoke_f)
123 {
124 sm->revoke_object = revoke_f;
125 return 1;
126 }
127
128int STORE_method_set_delete_function(STORE_METHOD *sm, STORE_HANDLE_OBJECT_FUNC_PTR delete_f)
129 {
130 sm->delete_object = delete_f;
131 return 1;
132 }
133
134int STORE_method_set_list_start_function(STORE_METHOD *sm, STORE_START_OBJECT_FUNC_PTR list_start_f)
135 {
136 sm->list_object_start = list_start_f;
137 return 1;
138 }
139
140int STORE_method_set_list_next_function(STORE_METHOD *sm, STORE_NEXT_OBJECT_FUNC_PTR list_next_f)
141 {
142 sm->list_object_next = list_next_f;
143 return 1;
144 }
145
146int STORE_method_set_list_end_function(STORE_METHOD *sm, STORE_END_OBJECT_FUNC_PTR list_end_f)
147 {
148 sm->list_object_end = list_end_f;
149 return 1;
150 }
151
152int STORE_method_set_update_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR update_f)
153 {
154 sm->update_store = update_f;
155 return 1;
156 }
157
158int STORE_method_set_lock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR lock_f)
159 {
160 sm->lock_store = lock_f;
161 return 1;
162 }
163
164int STORE_method_set_unlock_store_function(STORE_METHOD *sm, STORE_GENERIC_FUNC_PTR unlock_f)
165 {
166 sm->unlock_store = unlock_f;
167 return 1;
168 }
169
170int STORE_method_set_ctrl_function(STORE_METHOD *sm, STORE_CTRL_FUNC_PTR ctrl_f)
171 {
172 sm->ctrl = ctrl_f;
173 return 1;
174 }
175
176STORE_INITIALISE_FUNC_PTR STORE_method_get_initialise_function(STORE_METHOD *sm)
177 {
178 return sm->init;
179 }
180
181STORE_CLEANUP_FUNC_PTR STORE_method_get_cleanup_function(STORE_METHOD *sm)
182 {
183 return sm->clean;
184 }
185
186STORE_GENERATE_OBJECT_FUNC_PTR STORE_method_get_generate_function(STORE_METHOD *sm)
187 {
188 return sm->generate_object;
189 }
190
191STORE_GET_OBJECT_FUNC_PTR STORE_method_get_get_function(STORE_METHOD *sm)
192 {
193 return sm->get_object;
194 }
195
196STORE_STORE_OBJECT_FUNC_PTR STORE_method_get_store_function(STORE_METHOD *sm)
197 {
198 return sm->store_object;
199 }
200
201STORE_MODIFY_OBJECT_FUNC_PTR STORE_method_get_modify_function(STORE_METHOD *sm)
202 {
203 return sm->modify_object;
204 }
205
206STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_revoke_function(STORE_METHOD *sm)
207 {
208 return sm->revoke_object;
209 }
210
211STORE_HANDLE_OBJECT_FUNC_PTR STORE_method_get_delete_function(STORE_METHOD *sm)
212 {
213 return sm->delete_object;
214 }
215
216STORE_START_OBJECT_FUNC_PTR STORE_method_get_list_start_function(STORE_METHOD *sm)
217 {
218 return sm->list_object_start;
219 }
220
221STORE_NEXT_OBJECT_FUNC_PTR STORE_method_get_list_next_function(STORE_METHOD *sm)
222 {
223 return sm->list_object_next;
224 }
225
226STORE_END_OBJECT_FUNC_PTR STORE_method_get_list_end_function(STORE_METHOD *sm)
227 {
228 return sm->list_object_end;
229 }
230
231STORE_GENERIC_FUNC_PTR STORE_method_get_update_store_function(STORE_METHOD *sm)
232 {
233 return sm->update_store;
234 }
235
236STORE_GENERIC_FUNC_PTR STORE_method_get_lock_store_function(STORE_METHOD *sm)
237 {
238 return sm->lock_store;
239 }
240
241STORE_GENERIC_FUNC_PTR STORE_method_get_unlock_store_function(STORE_METHOD *sm)
242 {
243 return sm->unlock_store;
244 }
245
246STORE_CTRL_FUNC_PTR STORE_method_get_ctrl_function(STORE_METHOD *sm)
247 {
248 return sm->ctrl;
249 }
250
diff --git a/src/lib/libcrypto/symhacks.h b/src/lib/libcrypto/symhacks.h
new file mode 100644
index 0000000000..774162fec9
--- /dev/null
+++ b/src/lib/libcrypto/symhacks.h
@@ -0,0 +1,275 @@
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_SYMHACKS_H
56#define HEADER_SYMHACKS_H
57
58#include <openssl/e_os2.h>
59
60/* Hacks to solve the problem with linkers incapable of handling very long
61 symbol names. In the case of VMS, the limit is 31 characters on VMS for
62 VAX. */
63#ifdef OPENSSL_SYS_VMS
64
65/* Hack a long name in crypto/ex_data.c */
66#undef CRYPTO_get_ex_data_implementation
67#define CRYPTO_get_ex_data_implementation CRYPTO_get_ex_data_impl
68#undef CRYPTO_set_ex_data_implementation
69#define CRYPTO_set_ex_data_implementation CRYPTO_set_ex_data_impl
70
71/* Hack a long name in crypto/asn1/a_mbstr.c */
72#undef ASN1_STRING_set_default_mask_asc
73#define ASN1_STRING_set_default_mask_asc ASN1_STRING_set_def_mask_asc
74
75#if 0 /* No longer needed, since safestack macro magic does the job */
76/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_SIGNER_INFO) */
77#undef i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO
78#define i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO i2d_ASN1_SET_OF_PKCS7_SIGINF
79#undef d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO
80#define d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO d2i_ASN1_SET_OF_PKCS7_SIGINF
81#endif
82
83#if 0 /* No longer needed, since safestack macro magic does the job */
84/* Hack the names created with DECLARE_ASN1_SET_OF(PKCS7_RECIP_INFO) */
85#undef i2d_ASN1_SET_OF_PKCS7_RECIP_INFO
86#define i2d_ASN1_SET_OF_PKCS7_RECIP_INFO i2d_ASN1_SET_OF_PKCS7_RECINF
87#undef d2i_ASN1_SET_OF_PKCS7_RECIP_INFO
88#define d2i_ASN1_SET_OF_PKCS7_RECIP_INFO d2i_ASN1_SET_OF_PKCS7_RECINF
89#endif
90
91#if 0 /* No longer needed, since safestack macro magic does the job */
92/* Hack the names created with DECLARE_ASN1_SET_OF(ACCESS_DESCRIPTION) */
93#undef i2d_ASN1_SET_OF_ACCESS_DESCRIPTION
94#define i2d_ASN1_SET_OF_ACCESS_DESCRIPTION i2d_ASN1_SET_OF_ACC_DESC
95#undef d2i_ASN1_SET_OF_ACCESS_DESCRIPTION
96#define d2i_ASN1_SET_OF_ACCESS_DESCRIPTION d2i_ASN1_SET_OF_ACC_DESC
97#endif
98
99/* Hack the names created with DECLARE_PEM_rw(NETSCAPE_CERT_SEQUENCE) */
100#undef PEM_read_NETSCAPE_CERT_SEQUENCE
101#define PEM_read_NETSCAPE_CERT_SEQUENCE PEM_read_NS_CERT_SEQ
102#undef PEM_write_NETSCAPE_CERT_SEQUENCE
103#define PEM_write_NETSCAPE_CERT_SEQUENCE PEM_write_NS_CERT_SEQ
104#undef PEM_read_bio_NETSCAPE_CERT_SEQUENCE
105#define PEM_read_bio_NETSCAPE_CERT_SEQUENCE PEM_read_bio_NS_CERT_SEQ
106#undef PEM_write_bio_NETSCAPE_CERT_SEQUENCE
107#define PEM_write_bio_NETSCAPE_CERT_SEQUENCE PEM_write_bio_NS_CERT_SEQ
108#undef PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE
109#define PEM_write_cb_bio_NETSCAPE_CERT_SEQUENCE PEM_write_cb_bio_NS_CERT_SEQ
110
111/* Hack the names created with DECLARE_PEM_rw(PKCS8_PRIV_KEY_INFO) */
112#undef PEM_read_PKCS8_PRIV_KEY_INFO
113#define PEM_read_PKCS8_PRIV_KEY_INFO PEM_read_P8_PRIV_KEY_INFO
114#undef PEM_write_PKCS8_PRIV_KEY_INFO
115#define PEM_write_PKCS8_PRIV_KEY_INFO PEM_write_P8_PRIV_KEY_INFO
116#undef PEM_read_bio_PKCS8_PRIV_KEY_INFO
117#define PEM_read_bio_PKCS8_PRIV_KEY_INFO PEM_read_bio_P8_PRIV_KEY_INFO
118#undef PEM_write_bio_PKCS8_PRIV_KEY_INFO
119#define PEM_write_bio_PKCS8_PRIV_KEY_INFO PEM_write_bio_P8_PRIV_KEY_INFO
120#undef PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO
121#define PEM_write_cb_bio_PKCS8_PRIV_KEY_INFO PEM_wrt_cb_bio_P8_PRIV_KEY_INFO
122
123/* Hack other PEM names */
124#undef PEM_write_bio_PKCS8PrivateKey_nid
125#define PEM_write_bio_PKCS8PrivateKey_nid PEM_write_bio_PKCS8PrivKey_nid
126
127/* Hack some long X509 names */
128#undef X509_REVOKED_get_ext_by_critical
129#define X509_REVOKED_get_ext_by_critical X509_REVOKED_get_ext_by_critic
130
131/* Hack some long CRYPTO names */
132#undef CRYPTO_set_dynlock_destroy_callback
133#define CRYPTO_set_dynlock_destroy_callback CRYPTO_set_dynlock_destroy_cb
134#undef CRYPTO_set_dynlock_create_callback
135#define CRYPTO_set_dynlock_create_callback CRYPTO_set_dynlock_create_cb
136#undef CRYPTO_set_dynlock_lock_callback
137#define CRYPTO_set_dynlock_lock_callback CRYPTO_set_dynlock_lock_cb
138#undef CRYPTO_get_dynlock_lock_callback
139#define CRYPTO_get_dynlock_lock_callback CRYPTO_get_dynlock_lock_cb
140#undef CRYPTO_get_dynlock_destroy_callback
141#define CRYPTO_get_dynlock_destroy_callback CRYPTO_get_dynlock_destroy_cb
142#undef CRYPTO_get_dynlock_create_callback
143#define CRYPTO_get_dynlock_create_callback CRYPTO_get_dynlock_create_cb
144#undef CRYPTO_set_locked_mem_ex_functions
145#define CRYPTO_set_locked_mem_ex_functions CRYPTO_set_locked_mem_ex_funcs
146#undef CRYPTO_get_locked_mem_ex_functions
147#define CRYPTO_get_locked_mem_ex_functions CRYPTO_get_locked_mem_ex_funcs
148
149/* Hack some long SSL names */
150#undef SSL_CTX_set_default_verify_paths
151#define SSL_CTX_set_default_verify_paths SSL_CTX_set_def_verify_paths
152#undef SSL_get_ex_data_X509_STORE_CTX_idx
153#define SSL_get_ex_data_X509_STORE_CTX_idx SSL_get_ex_d_X509_STORE_CTX_idx
154#undef SSL_add_file_cert_subjects_to_stack
155#define SSL_add_file_cert_subjects_to_stack SSL_add_file_cert_subjs_to_stk
156#if 0 /* This function is not defined i VMS. */
157#undef SSL_add_dir_cert_subjects_to_stack
158#define SSL_add_dir_cert_subjects_to_stack SSL_add_dir_cert_subjs_to_stk
159#endif
160#undef SSL_CTX_use_certificate_chain_file
161#define SSL_CTX_use_certificate_chain_file SSL_CTX_use_cert_chain_file
162#undef SSL_CTX_set_cert_verify_callback
163#define SSL_CTX_set_cert_verify_callback SSL_CTX_set_cert_verify_cb
164#undef SSL_CTX_set_default_passwd_cb_userdata
165#define SSL_CTX_set_default_passwd_cb_userdata SSL_CTX_set_def_passwd_cb_ud
166
167/* Hack some long ENGINE names */
168#undef ENGINE_get_default_BN_mod_exp_crt
169#define ENGINE_get_default_BN_mod_exp_crt ENGINE_get_def_BN_mod_exp_crt
170#undef ENGINE_set_default_BN_mod_exp_crt
171#define ENGINE_set_default_BN_mod_exp_crt ENGINE_set_def_BN_mod_exp_crt
172#undef ENGINE_set_load_privkey_function
173#define ENGINE_set_load_privkey_function ENGINE_set_load_privkey_fn
174#undef ENGINE_get_load_privkey_function
175#define ENGINE_get_load_privkey_function ENGINE_get_load_privkey_fn
176
177/* Hack some long OCSP names */
178#undef OCSP_REQUEST_get_ext_by_critical
179#define OCSP_REQUEST_get_ext_by_critical OCSP_REQUEST_get_ext_by_crit
180#undef OCSP_BASICRESP_get_ext_by_critical
181#define OCSP_BASICRESP_get_ext_by_critical OCSP_BASICRESP_get_ext_by_crit
182#undef OCSP_SINGLERESP_get_ext_by_critical
183#define OCSP_SINGLERESP_get_ext_by_critical OCSP_SINGLERESP_get_ext_by_crit
184
185/* Hack some long DES names */
186#undef _ossl_old_des_ede3_cfb64_encrypt
187#define _ossl_old_des_ede3_cfb64_encrypt _ossl_odes_ede3_cfb64_encrypt
188#undef _ossl_old_des_ede3_ofb64_encrypt
189#define _ossl_old_des_ede3_ofb64_encrypt _ossl_odes_ede3_ofb64_encrypt
190
191/* Hack some long EVP names */
192#undef OPENSSL_add_all_algorithms_noconf
193#define OPENSSL_add_all_algorithms_noconf OPENSSL_add_all_algo_noconf
194#undef OPENSSL_add_all_algorithms_conf
195#define OPENSSL_add_all_algorithms_conf OPENSSL_add_all_algo_conf
196
197/* Hack some long EC names */
198#undef EC_POINT_set_Jprojective_coordinates_GFp
199#define EC_POINT_set_Jprojective_coordinates_GFp \
200 EC_POINT_set_Jproj_coords_GFp
201#undef EC_POINT_get_Jprojective_coordinates_GFp
202#define EC_POINT_get_Jprojective_coordinates_GFp \
203 EC_POINT_get_Jproj_coords_GFp
204#undef EC_POINT_set_affine_coordinates_GFp
205#define EC_POINT_set_affine_coordinates_GFp EC_POINT_set_affine_coords_GFp
206#undef EC_POINT_get_affine_coordinates_GFp
207#define EC_POINT_get_affine_coordinates_GFp EC_POINT_get_affine_coords_GFp
208#undef EC_POINT_set_compressed_coordinates_GFp
209#define EC_POINT_set_compressed_coordinates_GFp EC_POINT_set_compr_coords_GFp
210#undef ec_GFp_simple_group_set_curve_GFp
211#define ec_GFp_simple_group_set_curve_GFp ec_GFp_simple_grp_set_curve_GFp
212#undef ec_GFp_simple_group_get_curve_GFp
213#define ec_GFp_simple_group_get_curve_GFp ec_GFp_simple_grp_get_curve_GFp
214#undef ec_GFp_simple_group_clear_finish
215#define ec_GFp_simple_group_clear_finish ec_GFp_simple_grp_clear_finish
216#undef ec_GFp_simple_group_set_generator
217#define ec_GFp_simple_group_set_generator ec_GFp_simple_grp_set_generator
218#undef ec_GFp_simple_group_get0_generator
219#define ec_GFp_simple_group_get0_generator ec_GFp_simple_grp_gt0_generator
220#undef ec_GFp_simple_group_get_cofactor
221#define ec_GFp_simple_group_get_cofactor ec_GFp_simple_grp_get_cofactor
222#undef ec_GFp_simple_point_clear_finish
223#define ec_GFp_simple_point_clear_finish ec_GFp_simple_pt_clear_finish
224#undef ec_GFp_simple_point_set_to_infinity
225#define ec_GFp_simple_point_set_to_infinity ec_GFp_simple_pt_set_to_inf
226#undef ec_GFp_simple_points_make_affine
227#define ec_GFp_simple_points_make_affine ec_GFp_simple_pts_make_affine
228#undef ec_GFp_simple_group_get_curve_GFp
229#define ec_GFp_simple_group_get_curve_GFp ec_GFp_simple_grp_get_curve_GFp
230#undef ec_GFp_simple_set_Jprojective_coordinates_GFp
231#define ec_GFp_simple_set_Jprojective_coordinates_GFp \
232 ec_GFp_smp_set_Jproj_coords_GFp
233#undef ec_GFp_simple_get_Jprojective_coordinates_GFp
234#define ec_GFp_simple_get_Jprojective_coordinates_GFp \
235 ec_GFp_smp_get_Jproj_coords_GFp
236#undef ec_GFp_simple_point_set_affine_coordinates_GFp
237#define ec_GFp_simple_point_set_affine_coordinates_GFp \
238 ec_GFp_smp_pt_set_af_coords_GFp
239#undef ec_GFp_simple_point_get_affine_coordinates_GFp
240#define ec_GFp_simple_point_get_affine_coordinates_GFp \
241 ec_GFp_smp_pt_get_af_coords_GFp
242#undef ec_GFp_simple_set_compressed_coordinates_GFp
243#define ec_GFp_simple_set_compressed_coordinates_GFp \
244 ec_GFp_smp_set_compr_coords_GFp
245
246#endif /* defined OPENSSL_SYS_VMS */
247
248
249/* Case insensiteve linking causes problems.... */
250#if defined(OPENSSL_SYS_WIN16) || defined(OPENSSL_SYS_VMS) || defined(OPENSSL_SYS_OS2)
251#undef ERR_load_CRYPTO_strings
252#define ERR_load_CRYPTO_strings ERR_load_CRYPTOlib_strings
253#undef OCSP_crlID_new
254#define OCSP_crlID_new OCSP_crlID2_new
255
256/* These functions do not seem to exist! However, I'm paranoid...
257 Original command in x509v3.h:
258 These functions are being redefined in another directory,
259 and clash when the linker is case-insensitive, so let's
260 hide them a little, by giving them an extra 'o' at the
261 beginning of the name... */
262#undef X509v3_cleanup_extensions
263#define X509v3_cleanup_extensions oX509v3_cleanup_extensions
264#undef X509v3_add_extension
265#define X509v3_add_extension oX509v3_add_extension
266#undef X509v3_add_netscape_extensions
267#define X509v3_add_netscape_extensions oX509v3_add_netscape_extensions
268#undef X509v3_add_standard_extensions
269#define X509v3_add_standard_extensions oX509v3_add_standard_extensions
270
271
272#endif
273
274
275#endif /* ! defined HEADER_VMS_IDHACKS_H */
diff --git a/src/lib/libcrypto/threads/README b/src/lib/libcrypto/threads/README
new file mode 100644
index 0000000000..df6b26e146
--- /dev/null
+++ b/src/lib/libcrypto/threads/README
@@ -0,0 +1,14 @@
1Mutithreading testing area.
2
3Since this stuff is very very platorm specific, this is not part of the
4normal build. Have a read of doc/threads.doc.
5
6mttest will do some testing and will currently build under Windows NT/95,
7Solaris and Linux. The IRIX stuff is not finished.
8
9I have tested this program on a 12 CPU ultra sparc box (solaris 2.5.1)
10and things seem to work ok.
11
12The Linux pthreads package can be retrieved from
13http://www.mit.edu:8001/people/proven/pthreads.html
14
diff --git a/src/lib/libcrypto/threads/mttest.c b/src/lib/libcrypto/threads/mttest.c
new file mode 100644
index 0000000000..7588966cb2
--- /dev/null
+++ b/src/lib/libcrypto/threads/mttest.c
@@ -0,0 +1,1096 @@
1/* crypto/threads/mttest.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef OPENSSL_SYS_WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
80#include <openssl/lhash.h>
81#include <openssl/crypto.h>
82#include <openssl/buffer.h>
83#include "../../e_os.h"
84#include <openssl/x509.h>
85#include <openssl/ssl.h>
86#include <openssl/err.h>
87#include <openssl/rand.h>
88
89#define TEST_SERVER_CERT "../../apps/server.pem"
90#define TEST_CLIENT_CERT "../../apps/client.pem"
91
92#define MAX_THREAD_NUMBER 100
93
94int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *xs);
95void thread_setup(void);
96void thread_cleanup(void);
97void do_threads(SSL_CTX *s_ctx,SSL_CTX *c_ctx);
98
99void irix_locking_callback(int mode,int type,char *file,int line);
100void solaris_locking_callback(int mode,int type,char *file,int line);
101void win32_locking_callback(int mode,int type,char *file,int line);
102void pthreads_locking_callback(int mode,int type,char *file,int line);
103
104unsigned long irix_thread_id(void );
105unsigned long solaris_thread_id(void );
106unsigned long pthreads_thread_id(void );
107
108BIO *bio_err=NULL;
109BIO *bio_stdout=NULL;
110
111static char *cipher=NULL;
112int verbose=0;
113#ifdef FIONBIO
114static int s_nbio=0;
115#endif
116
117int thread_number=10;
118int number_of_loops=10;
119int reconnect=0;
120int cache_stats=0;
121
122static const char rnd_seed[] = "string to make the random number generator think it has entropy";
123
124int doit(char *ctx[4]);
125static void print_stats(FILE *fp, SSL_CTX *ctx)
126{
127 fprintf(fp,"%4ld items in the session cache\n",
128 SSL_CTX_sess_number(ctx));
129 fprintf(fp,"%4d client connects (SSL_connect())\n",
130 SSL_CTX_sess_connect(ctx));
131 fprintf(fp,"%4d client connects that finished\n",
132 SSL_CTX_sess_connect_good(ctx));
133 fprintf(fp,"%4d server connects (SSL_accept())\n",
134 SSL_CTX_sess_accept(ctx));
135 fprintf(fp,"%4d server connects that finished\n",
136 SSL_CTX_sess_accept_good(ctx));
137 fprintf(fp,"%4d session cache hits\n",SSL_CTX_sess_hits(ctx));
138 fprintf(fp,"%4d session cache misses\n",SSL_CTX_sess_misses(ctx));
139 fprintf(fp,"%4d session cache timeouts\n",SSL_CTX_sess_timeouts(ctx));
140 }
141
142static void sv_usage(void)
143 {
144 fprintf(stderr,"usage: ssltest [args ...]\n");
145 fprintf(stderr,"\n");
146 fprintf(stderr," -server_auth - check server certificate\n");
147 fprintf(stderr," -client_auth - do client authentication\n");
148 fprintf(stderr," -v - more output\n");
149 fprintf(stderr," -CApath arg - PEM format directory of CA's\n");
150 fprintf(stderr," -CAfile arg - PEM format file of CA's\n");
151 fprintf(stderr," -threads arg - number of threads\n");
152 fprintf(stderr," -loops arg - number of 'connections', per thread\n");
153 fprintf(stderr," -reconnect - reuse session-id's\n");
154 fprintf(stderr," -stats - server session-id cache stats\n");
155 fprintf(stderr," -cert arg - server certificate/key\n");
156 fprintf(stderr," -ccert arg - client certificate/key\n");
157 fprintf(stderr," -ssl3 - just SSLv3n\n");
158 }
159
160int main(int argc, char *argv[])
161 {
162 char *CApath=NULL,*CAfile=NULL;
163 int badop=0;
164 int ret=1;
165 int client_auth=0;
166 int server_auth=0;
167 SSL_CTX *s_ctx=NULL;
168 SSL_CTX *c_ctx=NULL;
169 char *scert=TEST_SERVER_CERT;
170 char *ccert=TEST_CLIENT_CERT;
171 SSL_METHOD *ssl_method=SSLv23_method();
172
173 RAND_seed(rnd_seed, sizeof rnd_seed);
174
175 if (bio_err == NULL)
176 bio_err=BIO_new_fp(stderr,BIO_NOCLOSE);
177 if (bio_stdout == NULL)
178 bio_stdout=BIO_new_fp(stdout,BIO_NOCLOSE);
179 argc--;
180 argv++;
181
182 while (argc >= 1)
183 {
184 if (strcmp(*argv,"-server_auth") == 0)
185 server_auth=1;
186 else if (strcmp(*argv,"-client_auth") == 0)
187 client_auth=1;
188 else if (strcmp(*argv,"-reconnect") == 0)
189 reconnect=1;
190 else if (strcmp(*argv,"-stats") == 0)
191 cache_stats=1;
192 else if (strcmp(*argv,"-ssl3") == 0)
193 ssl_method=SSLv3_method();
194 else if (strcmp(*argv,"-ssl2") == 0)
195 ssl_method=SSLv2_method();
196 else if (strcmp(*argv,"-CApath") == 0)
197 {
198 if (--argc < 1) goto bad;
199 CApath= *(++argv);
200 }
201 else if (strcmp(*argv,"-CAfile") == 0)
202 {
203 if (--argc < 1) goto bad;
204 CAfile= *(++argv);
205 }
206 else if (strcmp(*argv,"-cert") == 0)
207 {
208 if (--argc < 1) goto bad;
209 scert= *(++argv);
210 }
211 else if (strcmp(*argv,"-ccert") == 0)
212 {
213 if (--argc < 1) goto bad;
214 ccert= *(++argv);
215 }
216 else if (strcmp(*argv,"-threads") == 0)
217 {
218 if (--argc < 1) goto bad;
219 thread_number= atoi(*(++argv));
220 if (thread_number == 0) thread_number=1;
221 if (thread_number > MAX_THREAD_NUMBER)
222 thread_number=MAX_THREAD_NUMBER;
223 }
224 else if (strcmp(*argv,"-loops") == 0)
225 {
226 if (--argc < 1) goto bad;
227 number_of_loops= atoi(*(++argv));
228 if (number_of_loops == 0) number_of_loops=1;
229 }
230 else
231 {
232 fprintf(stderr,"unknown option %s\n",*argv);
233 badop=1;
234 break;
235 }
236 argc--;
237 argv++;
238 }
239 if (badop)
240 {
241bad:
242 sv_usage();
243 goto end;
244 }
245
246 if (cipher == NULL && OPENSSL_issetugid() == 0)
247 cipher=getenv("SSL_CIPHER");
248
249 SSL_load_error_strings();
250 OpenSSL_add_ssl_algorithms();
251
252 c_ctx=SSL_CTX_new(ssl_method);
253 s_ctx=SSL_CTX_new(ssl_method);
254 if ((c_ctx == NULL) || (s_ctx == NULL))
255 {
256 ERR_print_errors(bio_err);
257 goto end;
258 }
259
260 SSL_CTX_set_session_cache_mode(s_ctx,
261 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
262 SSL_CTX_set_session_cache_mode(c_ctx,
263 SSL_SESS_CACHE_NO_AUTO_CLEAR|SSL_SESS_CACHE_SERVER);
264
265 if (!SSL_CTX_use_certificate_file(s_ctx,scert,SSL_FILETYPE_PEM))
266 {
267 ERR_print_errors(bio_err);
268 }
269 else if (!SSL_CTX_use_RSAPrivateKey_file(s_ctx,scert,SSL_FILETYPE_PEM))
270 {
271 ERR_print_errors(bio_err);
272 goto end;
273 }
274
275 if (client_auth)
276 {
277 SSL_CTX_use_certificate_file(c_ctx,ccert,
278 SSL_FILETYPE_PEM);
279 SSL_CTX_use_RSAPrivateKey_file(c_ctx,ccert,
280 SSL_FILETYPE_PEM);
281 }
282
283 if ( (!SSL_CTX_load_verify_locations(s_ctx,CAfile,CApath)) ||
284 (!SSL_CTX_set_default_verify_paths(s_ctx)) ||
285 (!SSL_CTX_load_verify_locations(c_ctx,CAfile,CApath)) ||
286 (!SSL_CTX_set_default_verify_paths(c_ctx)))
287 {
288 fprintf(stderr,"SSL_load_verify_locations\n");
289 ERR_print_errors(bio_err);
290 goto end;
291 }
292
293 if (client_auth)
294 {
295 fprintf(stderr,"client authentication\n");
296 SSL_CTX_set_verify(s_ctx,
297 SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
298 verify_callback);
299 }
300 if (server_auth)
301 {
302 fprintf(stderr,"server authentication\n");
303 SSL_CTX_set_verify(c_ctx,SSL_VERIFY_PEER,
304 verify_callback);
305 }
306
307 thread_setup();
308 do_threads(s_ctx,c_ctx);
309 thread_cleanup();
310end:
311
312 if (c_ctx != NULL)
313 {
314 fprintf(stderr,"Client SSL_CTX stats then free it\n");
315 print_stats(stderr,c_ctx);
316 SSL_CTX_free(c_ctx);
317 }
318 if (s_ctx != NULL)
319 {
320 fprintf(stderr,"Server SSL_CTX stats then free it\n");
321 print_stats(stderr,s_ctx);
322 if (cache_stats)
323 {
324 fprintf(stderr,"-----\n");
325 lh_stats(SSL_CTX_sessions(s_ctx),stderr);
326 fprintf(stderr,"-----\n");
327 /* lh_node_stats(SSL_CTX_sessions(s_ctx),stderr);
328 fprintf(stderr,"-----\n"); */
329 lh_node_usage_stats(SSL_CTX_sessions(s_ctx),stderr);
330 fprintf(stderr,"-----\n");
331 }
332 SSL_CTX_free(s_ctx);
333 fprintf(stderr,"done free\n");
334 }
335 exit(ret);
336 return(0);
337 }
338
339#define W_READ 1
340#define W_WRITE 2
341#define C_DONE 1
342#define S_DONE 2
343
344int ndoit(SSL_CTX *ssl_ctx[2])
345 {
346 int i;
347 int ret;
348 char *ctx[4];
349
350 ctx[0]=(char *)ssl_ctx[0];
351 ctx[1]=(char *)ssl_ctx[1];
352
353 if (reconnect)
354 {
355 ctx[2]=(char *)SSL_new(ssl_ctx[0]);
356 ctx[3]=(char *)SSL_new(ssl_ctx[1]);
357 }
358 else
359 {
360 ctx[2]=NULL;
361 ctx[3]=NULL;
362 }
363
364 fprintf(stdout,"started thread %lu\n",CRYPTO_thread_id());
365 for (i=0; i<number_of_loops; i++)
366 {
367/* fprintf(stderr,"%4d %2d ctx->ref (%3d,%3d)\n",
368 CRYPTO_thread_id(),i,
369 ssl_ctx[0]->references,
370 ssl_ctx[1]->references); */
371 /* pthread_delay_np(&tm);*/
372
373 ret=doit(ctx);
374 if (ret != 0)
375 {
376 fprintf(stdout,"error[%d] %lu - %d\n",
377 i,CRYPTO_thread_id(),ret);
378 return(ret);
379 }
380 }
381 fprintf(stdout,"DONE %lu\n",CRYPTO_thread_id());
382 if (reconnect)
383 {
384 SSL_free((SSL *)ctx[2]);
385 SSL_free((SSL *)ctx[3]);
386 }
387 return(0);
388 }
389
390int doit(char *ctx[4])
391 {
392 SSL_CTX *s_ctx,*c_ctx;
393 static char cbuf[200],sbuf[200];
394 SSL *c_ssl=NULL;
395 SSL *s_ssl=NULL;
396 BIO *c_to_s=NULL;
397 BIO *s_to_c=NULL;
398 BIO *c_bio=NULL;
399 BIO *s_bio=NULL;
400 int c_r,c_w,s_r,s_w;
401 int c_want,s_want;
402 int i;
403 int done=0;
404 int c_write,s_write;
405 int do_server=0,do_client=0;
406
407 s_ctx=(SSL_CTX *)ctx[0];
408 c_ctx=(SSL_CTX *)ctx[1];
409
410 if (ctx[2] != NULL)
411 s_ssl=(SSL *)ctx[2];
412 else
413 s_ssl=SSL_new(s_ctx);
414
415 if (ctx[3] != NULL)
416 c_ssl=(SSL *)ctx[3];
417 else
418 c_ssl=SSL_new(c_ctx);
419
420 if ((s_ssl == NULL) || (c_ssl == NULL)) goto err;
421
422 c_to_s=BIO_new(BIO_s_mem());
423 s_to_c=BIO_new(BIO_s_mem());
424 if ((s_to_c == NULL) || (c_to_s == NULL)) goto err;
425
426 c_bio=BIO_new(BIO_f_ssl());
427 s_bio=BIO_new(BIO_f_ssl());
428 if ((c_bio == NULL) || (s_bio == NULL)) goto err;
429
430 SSL_set_connect_state(c_ssl);
431 SSL_set_bio(c_ssl,s_to_c,c_to_s);
432 BIO_set_ssl(c_bio,c_ssl,(ctx[2] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
433
434 SSL_set_accept_state(s_ssl);
435 SSL_set_bio(s_ssl,c_to_s,s_to_c);
436 BIO_set_ssl(s_bio,s_ssl,(ctx[3] == NULL)?BIO_CLOSE:BIO_NOCLOSE);
437
438 c_r=0; s_r=1;
439 c_w=1; s_w=0;
440 c_want=W_WRITE;
441 s_want=0;
442 c_write=1,s_write=0;
443
444 /* We can always do writes */
445 for (;;)
446 {
447 do_server=0;
448 do_client=0;
449
450 i=(int)BIO_pending(s_bio);
451 if ((i && s_r) || s_w) do_server=1;
452
453 i=(int)BIO_pending(c_bio);
454 if ((i && c_r) || c_w) do_client=1;
455
456 if (do_server && verbose)
457 {
458 if (SSL_in_init(s_ssl))
459 printf("server waiting in SSL_accept - %s\n",
460 SSL_state_string_long(s_ssl));
461 else if (s_write)
462 printf("server:SSL_write()\n");
463 else
464 printf("server:SSL_read()\n");
465 }
466
467 if (do_client && verbose)
468 {
469 if (SSL_in_init(c_ssl))
470 printf("client waiting in SSL_connect - %s\n",
471 SSL_state_string_long(c_ssl));
472 else if (c_write)
473 printf("client:SSL_write()\n");
474 else
475 printf("client:SSL_read()\n");
476 }
477
478 if (!do_client && !do_server)
479 {
480 fprintf(stdout,"ERROR IN STARTUP\n");
481 break;
482 }
483 if (do_client && !(done & C_DONE))
484 {
485 if (c_write)
486 {
487 i=BIO_write(c_bio,"hello from client\n",18);
488 if (i < 0)
489 {
490 c_r=0;
491 c_w=0;
492 if (BIO_should_retry(c_bio))
493 {
494 if (BIO_should_read(c_bio))
495 c_r=1;
496 if (BIO_should_write(c_bio))
497 c_w=1;
498 }
499 else
500 {
501 fprintf(stderr,"ERROR in CLIENT\n");
502 ERR_print_errors_fp(stderr);
503 return(1);
504 }
505 }
506 else if (i == 0)
507 {
508 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
509 return(1);
510 }
511 else
512 {
513 /* ok */
514 c_write=0;
515 }
516 }
517 else
518 {
519 i=BIO_read(c_bio,cbuf,100);
520 if (i < 0)
521 {
522 c_r=0;
523 c_w=0;
524 if (BIO_should_retry(c_bio))
525 {
526 if (BIO_should_read(c_bio))
527 c_r=1;
528 if (BIO_should_write(c_bio))
529 c_w=1;
530 }
531 else
532 {
533 fprintf(stderr,"ERROR in CLIENT\n");
534 ERR_print_errors_fp(stderr);
535 return(1);
536 }
537 }
538 else if (i == 0)
539 {
540 fprintf(stderr,"SSL CLIENT STARTUP FAILED\n");
541 return(1);
542 }
543 else
544 {
545 done|=C_DONE;
546#ifdef undef
547 fprintf(stdout,"CLIENT:from server:");
548 fwrite(cbuf,1,i,stdout);
549 fflush(stdout);
550#endif
551 }
552 }
553 }
554
555 if (do_server && !(done & S_DONE))
556 {
557 if (!s_write)
558 {
559 i=BIO_read(s_bio,sbuf,100);
560 if (i < 0)
561 {
562 s_r=0;
563 s_w=0;
564 if (BIO_should_retry(s_bio))
565 {
566 if (BIO_should_read(s_bio))
567 s_r=1;
568 if (BIO_should_write(s_bio))
569 s_w=1;
570 }
571 else
572 {
573 fprintf(stderr,"ERROR in SERVER\n");
574 ERR_print_errors_fp(stderr);
575 return(1);
576 }
577 }
578 else if (i == 0)
579 {
580 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
581 return(1);
582 }
583 else
584 {
585 s_write=1;
586 s_w=1;
587#ifdef undef
588 fprintf(stdout,"SERVER:from client:");
589 fwrite(sbuf,1,i,stdout);
590 fflush(stdout);
591#endif
592 }
593 }
594 else
595 {
596 i=BIO_write(s_bio,"hello from server\n",18);
597 if (i < 0)
598 {
599 s_r=0;
600 s_w=0;
601 if (BIO_should_retry(s_bio))
602 {
603 if (BIO_should_read(s_bio))
604 s_r=1;
605 if (BIO_should_write(s_bio))
606 s_w=1;
607 }
608 else
609 {
610 fprintf(stderr,"ERROR in SERVER\n");
611 ERR_print_errors_fp(stderr);
612 return(1);
613 }
614 }
615 else if (i == 0)
616 {
617 fprintf(stderr,"SSL SERVER STARTUP FAILED\n");
618 return(1);
619 }
620 else
621 {
622 s_write=0;
623 s_r=1;
624 done|=S_DONE;
625 }
626 }
627 }
628
629 if ((done & S_DONE) && (done & C_DONE)) break;
630 }
631
632 SSL_set_shutdown(c_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
633 SSL_set_shutdown(s_ssl,SSL_SENT_SHUTDOWN|SSL_RECEIVED_SHUTDOWN);
634
635#ifdef undef
636 fprintf(stdout,"DONE\n");
637#endif
638err:
639 /* We have to set the BIO's to NULL otherwise they will be
640 * free()ed twice. Once when th s_ssl is SSL_free()ed and
641 * again when c_ssl is SSL_free()ed.
642 * This is a hack required because s_ssl and c_ssl are sharing the same
643 * BIO structure and SSL_set_bio() and SSL_free() automatically
644 * BIO_free non NULL entries.
645 * You should not normally do this or be required to do this */
646
647 if (s_ssl != NULL)
648 {
649 s_ssl->rbio=NULL;
650 s_ssl->wbio=NULL;
651 }
652 if (c_ssl != NULL)
653 {
654 c_ssl->rbio=NULL;
655 c_ssl->wbio=NULL;
656 }
657
658 /* The SSL's are optionally freed in the following calls */
659 if (c_to_s != NULL) BIO_free(c_to_s);
660 if (s_to_c != NULL) BIO_free(s_to_c);
661
662 if (c_bio != NULL) BIO_free(c_bio);
663 if (s_bio != NULL) BIO_free(s_bio);
664 return(0);
665 }
666
667int MS_CALLBACK verify_callback(int ok, X509_STORE_CTX *ctx)
668 {
669 char *s, buf[256];
670
671 if (verbose)
672 {
673 s=X509_NAME_oneline(X509_get_subject_name(ctx->current_cert),
674 buf,256);
675 if (s != NULL)
676 {
677 if (ok)
678 fprintf(stderr,"depth=%d %s\n",
679 ctx->error_depth,buf);
680 else
681 fprintf(stderr,"depth=%d error=%d %s\n",
682 ctx->error_depth,ctx->error,buf);
683 }
684 }
685 return(ok);
686 }
687
688#define THREAD_STACK_SIZE (16*1024)
689
690#ifdef OPENSSL_SYS_WIN32
691
692static HANDLE *lock_cs;
693
694void thread_setup(void)
695 {
696 int i;
697
698 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(HANDLE));
699 for (i=0; i<CRYPTO_num_locks(); i++)
700 {
701 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
702 }
703
704 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
705 /* id callback defined */
706 }
707
708void thread_cleanup(void)
709 {
710 int i;
711
712 CRYPTO_set_locking_callback(NULL);
713 for (i=0; i<CRYPTO_num_locks(); i++)
714 CloseHandle(lock_cs[i]);
715 OPENSSL_free(lock_cs);
716 }
717
718void win32_locking_callback(int mode, int type, char *file, int line)
719 {
720 if (mode & CRYPTO_LOCK)
721 {
722 WaitForSingleObject(lock_cs[type],INFINITE);
723 }
724 else
725 {
726 ReleaseMutex(lock_cs[type]);
727 }
728 }
729
730void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
731 {
732 double ret;
733 SSL_CTX *ssl_ctx[2];
734 DWORD thread_id[MAX_THREAD_NUMBER];
735 HANDLE thread_handle[MAX_THREAD_NUMBER];
736 int i;
737 SYSTEMTIME start,end;
738
739 ssl_ctx[0]=s_ctx;
740 ssl_ctx[1]=c_ctx;
741
742 GetSystemTime(&start);
743 for (i=0; i<thread_number; i++)
744 {
745 thread_handle[i]=CreateThread(NULL,
746 THREAD_STACK_SIZE,
747 (LPTHREAD_START_ROUTINE)ndoit,
748 (void *)ssl_ctx,
749 0L,
750 &(thread_id[i]));
751 }
752
753 printf("reaping\n");
754 for (i=0; i<thread_number; i+=50)
755 {
756 int j;
757
758 j=(thread_number < (i+50))?(thread_number-i):50;
759
760 if (WaitForMultipleObjects(j,
761 (CONST HANDLE *)&(thread_handle[i]),TRUE,INFINITE)
762 == WAIT_FAILED)
763 {
764 fprintf(stderr,"WaitForMultipleObjects failed:%d\n",GetLastError());
765 exit(1);
766 }
767 }
768 GetSystemTime(&end);
769
770 if (start.wDayOfWeek > end.wDayOfWeek) end.wDayOfWeek+=7;
771 ret=(end.wDayOfWeek-start.wDayOfWeek)*24;
772
773 ret=(ret+end.wHour-start.wHour)*60;
774 ret=(ret+end.wMinute-start.wMinute)*60;
775 ret=(ret+end.wSecond-start.wSecond);
776 ret+=(end.wMilliseconds-start.wMilliseconds)/1000.0;
777
778 printf("win32 threads done - %.3f seconds\n",ret);
779 }
780
781#endif /* OPENSSL_SYS_WIN32 */
782
783#ifdef SOLARIS
784
785static mutex_t *lock_cs;
786/*static rwlock_t *lock_cs; */
787static long *lock_count;
788
789void thread_setup(void)
790 {
791 int i;
792
793 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t));
794 lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
795 for (i=0; i<CRYPTO_num_locks(); i++)
796 {
797 lock_count[i]=0;
798 /* rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL); */
799 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
800 }
801
802 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
803 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
804 }
805
806void thread_cleanup(void)
807 {
808 int i;
809
810 CRYPTO_set_locking_callback(NULL);
811
812 fprintf(stderr,"cleanup\n");
813
814 for (i=0; i<CRYPTO_num_locks(); i++)
815 {
816 /* rwlock_destroy(&(lock_cs[i])); */
817 mutex_destroy(&(lock_cs[i]));
818 fprintf(stderr,"%8ld:%s\n",lock_count[i],CRYPTO_get_lock_name(i));
819 }
820 OPENSSL_free(lock_cs);
821 OPENSSL_free(lock_count);
822
823 fprintf(stderr,"done cleanup\n");
824
825 }
826
827void solaris_locking_callback(int mode, int type, char *file, int line)
828 {
829#ifdef undef
830 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
831 CRYPTO_thread_id(),
832 (mode&CRYPTO_LOCK)?"l":"u",
833 (type&CRYPTO_READ)?"r":"w",file,line);
834#endif
835
836 /*
837 if (CRYPTO_LOCK_SSL_CERT == type)
838 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
839 CRYPTO_thread_id(),
840 mode,file,line);
841 */
842 if (mode & CRYPTO_LOCK)
843 {
844 /* if (mode & CRYPTO_READ)
845 rw_rdlock(&(lock_cs[type]));
846 else
847 rw_wrlock(&(lock_cs[type])); */
848
849 mutex_lock(&(lock_cs[type]));
850 lock_count[type]++;
851 }
852 else
853 {
854/* rw_unlock(&(lock_cs[type])); */
855 mutex_unlock(&(lock_cs[type]));
856 }
857 }
858
859void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
860 {
861 SSL_CTX *ssl_ctx[2];
862 thread_t thread_ctx[MAX_THREAD_NUMBER];
863 int i;
864
865 ssl_ctx[0]=s_ctx;
866 ssl_ctx[1]=c_ctx;
867
868 thr_setconcurrency(thread_number);
869 for (i=0; i<thread_number; i++)
870 {
871 thr_create(NULL, THREAD_STACK_SIZE,
872 (void *(*)())ndoit,
873 (void *)ssl_ctx,
874 0L,
875 &(thread_ctx[i]));
876 }
877
878 printf("reaping\n");
879 for (i=0; i<thread_number; i++)
880 {
881 thr_join(thread_ctx[i],NULL,NULL);
882 }
883
884 printf("solaris threads done (%d,%d)\n",
885 s_ctx->references,c_ctx->references);
886 }
887
888unsigned long solaris_thread_id(void)
889 {
890 unsigned long ret;
891
892 ret=(unsigned long)thr_self();
893 return(ret);
894 }
895#endif /* SOLARIS */
896
897#ifdef IRIX
898
899
900static usptr_t *arena;
901static usema_t **lock_cs;
902
903void thread_setup(void)
904 {
905 int i;
906 char filename[20];
907
908 strcpy(filename,"/tmp/mttest.XXXXXX");
909 mktemp(filename);
910
911 usconfig(CONF_STHREADIOOFF);
912 usconfig(CONF_STHREADMALLOCOFF);
913 usconfig(CONF_INITUSERS,100);
914 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
915 arena=usinit(filename);
916 unlink(filename);
917
918 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *));
919 for (i=0; i<CRYPTO_num_locks(); i++)
920 {
921 lock_cs[i]=usnewsema(arena,1);
922 }
923
924 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
925 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
926 }
927
928void thread_cleanup(void)
929 {
930 int i;
931
932 CRYPTO_set_locking_callback(NULL);
933 for (i=0; i<CRYPTO_num_locks(); i++)
934 {
935 char buf[10];
936
937 sprintf(buf,"%2d:",i);
938 usdumpsema(lock_cs[i],stdout,buf);
939 usfreesema(lock_cs[i],arena);
940 }
941 OPENSSL_free(lock_cs);
942 }
943
944void irix_locking_callback(int mode, int type, char *file, int line)
945 {
946 if (mode & CRYPTO_LOCK)
947 {
948 printf("lock %d\n",type);
949 uspsema(lock_cs[type]);
950 }
951 else
952 {
953 printf("unlock %d\n",type);
954 usvsema(lock_cs[type]);
955 }
956 }
957
958void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
959 {
960 SSL_CTX *ssl_ctx[2];
961 int thread_ctx[MAX_THREAD_NUMBER];
962 int i;
963
964 ssl_ctx[0]=s_ctx;
965 ssl_ctx[1]=c_ctx;
966
967 for (i=0; i<thread_number; i++)
968 {
969 thread_ctx[i]=sproc((void (*)())ndoit,
970 PR_SADDR|PR_SFDS,(void *)ssl_ctx);
971 }
972
973 printf("reaping\n");
974 for (i=0; i<thread_number; i++)
975 {
976 wait(NULL);
977 }
978
979 printf("irix threads done (%d,%d)\n",
980 s_ctx->references,c_ctx->references);
981 }
982
983unsigned long irix_thread_id(void)
984 {
985 unsigned long ret;
986
987 ret=(unsigned long)getpid();
988 return(ret);
989 }
990#endif /* IRIX */
991
992#ifdef PTHREADS
993
994static pthread_mutex_t *lock_cs;
995static long *lock_count;
996
997void thread_setup(void)
998 {
999 int i;
1000
1001 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
1002 lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
1003 for (i=0; i<CRYPTO_num_locks(); i++)
1004 {
1005 lock_count[i]=0;
1006 pthread_mutex_init(&(lock_cs[i]),NULL);
1007 }
1008
1009 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
1010 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
1011 }
1012
1013void thread_cleanup(void)
1014 {
1015 int i;
1016
1017 CRYPTO_set_locking_callback(NULL);
1018 fprintf(stderr,"cleanup\n");
1019 for (i=0; i<CRYPTO_num_locks(); i++)
1020 {
1021 pthread_mutex_destroy(&(lock_cs[i]));
1022 fprintf(stderr,"%8ld:%s\n",lock_count[i],
1023 CRYPTO_get_lock_name(i));
1024 }
1025 OPENSSL_free(lock_cs);
1026 OPENSSL_free(lock_count);
1027
1028 fprintf(stderr,"done cleanup\n");
1029 }
1030
1031void pthreads_locking_callback(int mode, int type, char *file,
1032 int line)
1033 {
1034#ifdef undef
1035 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
1036 CRYPTO_thread_id(),
1037 (mode&CRYPTO_LOCK)?"l":"u",
1038 (type&CRYPTO_READ)?"r":"w",file,line);
1039#endif
1040/*
1041 if (CRYPTO_LOCK_SSL_CERT == type)
1042 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
1043 CRYPTO_thread_id(),
1044 mode,file,line);
1045*/
1046 if (mode & CRYPTO_LOCK)
1047 {
1048 pthread_mutex_lock(&(lock_cs[type]));
1049 lock_count[type]++;
1050 }
1051 else
1052 {
1053 pthread_mutex_unlock(&(lock_cs[type]));
1054 }
1055 }
1056
1057void do_threads(SSL_CTX *s_ctx, SSL_CTX *c_ctx)
1058 {
1059 SSL_CTX *ssl_ctx[2];
1060 pthread_t thread_ctx[MAX_THREAD_NUMBER];
1061 int i;
1062
1063 ssl_ctx[0]=s_ctx;
1064 ssl_ctx[1]=c_ctx;
1065
1066 /*
1067 thr_setconcurrency(thread_number);
1068 */
1069 for (i=0; i<thread_number; i++)
1070 {
1071 pthread_create(&(thread_ctx[i]), NULL,
1072 (void *(*)())ndoit, (void *)ssl_ctx);
1073 }
1074
1075 printf("reaping\n");
1076 for (i=0; i<thread_number; i++)
1077 {
1078 pthread_join(thread_ctx[i],NULL);
1079 }
1080
1081 printf("pthreads threads done (%d,%d)\n",
1082 s_ctx->references,c_ctx->references);
1083 }
1084
1085unsigned long pthreads_thread_id(void)
1086 {
1087 unsigned long ret;
1088
1089 ret=(unsigned long)pthread_self();
1090 return(ret);
1091 }
1092
1093#endif /* PTHREADS */
1094
1095
1096
diff --git a/src/lib/libcrypto/threads/netware.bat b/src/lib/libcrypto/threads/netware.bat
new file mode 100644
index 0000000000..0b3eca3caf
--- /dev/null
+++ b/src/lib/libcrypto/threads/netware.bat
@@ -0,0 +1,79 @@
1@echo off
2rem batch file to build multi-thread test ( mttest.nlm )
3
4rem command line arguments:
5rem debug => build using debug settings
6
7rem
8rem After building, copy mttest.nlm to the server and run it, you'll probably
9rem want to redirect stdout and stderr. An example command line would be
10rem "mttest.nlm -thread 20 -loops 10 -CAfile \openssl\apps\server.pem >mttest.out 2>mttest.err"
11rem
12
13del mttest.nlm
14
15set BLD_DEBUG=
16set CFLAGS=
17set LFLAGS=
18set LIBS=
19
20if "%1" == "DEBUG" set BLD_DEBUG=YES
21if "%1" == "debug" set BLD_DEBUG=YES
22
23if "%MWCIncludes%" == "" goto inc_error
24if "%PRELUDE%" == "" goto prelude_error
25if "%IMPORTS%" == "" goto imports_error
26
27set CFLAGS=-c -I..\..\outinc_nw -nosyspath -DOPENSSL_SYS_NETWARE -opt off -g -sym internal -maxerrors 20
28
29if "%BLD_DEBUG%" == "YES" set LIBS=..\..\out_nw.dbg\ssl.lib ..\..\out_nw.dbg\crypto.lib
30if "%BLD_DEBUG%" == "" set LIBS=..\..\out_nw\ssl.lib ..\..\out_nw\crypto.lib
31
32set LFLAGS=-msgstyle gcc -zerobss -stacksize 32768 -nostdlib -sym internal
33
34rem generate command file for metrowerks
35echo.
36echo Generating Metrowerks command file: mttest.def
37echo # dynamically generated command file for metrowerks build > mttest.def
38echo IMPORT @%IMPORTS%\clib.imp >> mttest.def
39echo IMPORT @%IMPORTS%\threads.imp >> mttest.def
40echo IMPORT @%IMPORTS%\ws2nlm.imp >> mttest.def
41echo IMPORT GetProcessSwitchCount >> mttest.def
42echo MODULE clib >> mttest.def
43
44rem compile
45echo.
46echo Compiling mttest.c
47mwccnlm.exe mttest.c %CFLAGS%
48if errorlevel 1 goto end
49
50rem link
51echo.
52echo Linking mttest.nlm
53mwldnlm.exe %LFLAGS% -screenname mttest -commandfile mttest.def mttest.o "%PRELUDE%" %LIBS% -o mttest.nlm
54if errorlevel 1 goto end
55
56goto end
57
58:inc_error
59echo.
60echo Environment variable MWCIncludes is not set - see install.nw
61goto end
62
63:prelude_error
64echo.
65echo Environment variable PRELUDE is not set - see install.nw
66goto end
67
68:imports_error
69echo.
70echo Environment variable IMPORTS is not set - see install.nw
71goto end
72
73
74:end
75set BLD_DEBUG=
76set CFLAGS=
77set LFLAGS=
78set LIBS=
79
diff --git a/src/lib/libcrypto/threads/profile.sh b/src/lib/libcrypto/threads/profile.sh
new file mode 100644
index 0000000000..6e3e342fc0
--- /dev/null
+++ b/src/lib/libcrypto/threads/profile.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -p -DSOLARIS -I../../include -g mttest.c -o mttest -L/usr/lib/libc -ldl -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/ptest.bat b/src/lib/libcrypto/threads/ptest.bat
new file mode 100644
index 0000000000..4071b5ffea
--- /dev/null
+++ b/src/lib/libcrypto/threads/ptest.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3purify cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssl32.lib ..\..\out\crypt32.lib
4
diff --git a/src/lib/libcrypto/threads/pthread.sh b/src/lib/libcrypto/threads/pthread.sh
new file mode 100644
index 0000000000..f1c49821d2
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread.sh
@@ -0,0 +1,9 @@
1#!/bin/sh
2#
3# build using pthreads
4#
5# http://www.mit.edu:8001/people/proven/pthreads.html
6#
7/bin/rm -f mttest
8pgcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto
9
diff --git a/src/lib/libcrypto/threads/pthread2.sh b/src/lib/libcrypto/threads/pthread2.sh
new file mode 100644
index 0000000000..41264c6a50
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthread2.sh
@@ -0,0 +1,7 @@
1#!/bin/sh
2#
3# build using pthreads where it's already built into the system
4#
5/bin/rm -f mttest
6gcc -DPTHREADS -I../../include -g mttest.c -o mttest -L../.. -lssl -lcrypto -lpthread
7
diff --git a/src/lib/libcrypto/threads/pthreads-vms.com b/src/lib/libcrypto/threads/pthreads-vms.com
new file mode 100644
index 0000000000..63f5b8cc2e
--- /dev/null
+++ b/src/lib/libcrypto/threads/pthreads-vms.com
@@ -0,0 +1,9 @@
1$! To compile mttest on VMS.
2$!
3$! WARNING: only tested with DEC C so far.
4$
5$ arch := vax
6$ if f$getsyi("CPU") .ge. 128 then arch := axp
7$ define/user openssl [--.include.openssl]
8$ cc/def=PTHREADS mttest.c
9$ link mttest,[--.'arch'.exe.ssl]libssl/lib,[--.'arch'.exe.crypto]libcrypto/lib
diff --git a/src/lib/libcrypto/threads/purify.sh b/src/lib/libcrypto/threads/purify.sh
new file mode 100644
index 0000000000..6d44fe26b7
--- /dev/null
+++ b/src/lib/libcrypto/threads/purify.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3purify cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/solaris.sh b/src/lib/libcrypto/threads/solaris.sh
new file mode 100644
index 0000000000..bc93094a27
--- /dev/null
+++ b/src/lib/libcrypto/threads/solaris.sh
@@ -0,0 +1,4 @@
1#!/bin/sh
2/bin/rm -f mttest
3cc -DSOLARIS -I../../include -g mttest.c -o mttest -L../.. -lthread -lssl -lcrypto -lnsl -lsocket
4
diff --git a/src/lib/libcrypto/threads/th-lock.c b/src/lib/libcrypto/threads/th-lock.c
new file mode 100644
index 0000000000..a6a79b9f45
--- /dev/null
+++ b/src/lib/libcrypto/threads/th-lock.c
@@ -0,0 +1,387 @@
1/* crypto/threads/th-lock.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59#include <stdio.h>
60#include <stdlib.h>
61#include <string.h>
62#include <errno.h>
63#ifdef LINUX
64#include <typedefs.h>
65#endif
66#ifdef OPENSSL_SYS_WIN32
67#include <windows.h>
68#endif
69#ifdef SOLARIS
70#include <synch.h>
71#include <thread.h>
72#endif
73#ifdef IRIX
74#include <ulocks.h>
75#include <sys/prctl.h>
76#endif
77#ifdef PTHREADS
78#include <pthread.h>
79#endif
80#include <openssl/lhash.h>
81#include <openssl/crypto.h>
82#include <openssl/buffer.h>
83#include <openssl/e_os.h>
84#include <openssl/x509.h>
85#include <openssl/ssl.h>
86#include <openssl/err.h>
87
88void CRYPTO_thread_setup(void);
89void CRYPTO_thread_cleanup(void);
90
91static void irix_locking_callback(int mode,int type,char *file,int line);
92static void solaris_locking_callback(int mode,int type,char *file,int line);
93static void win32_locking_callback(int mode,int type,char *file,int line);
94static void pthreads_locking_callback(int mode,int type,char *file,int line);
95
96static unsigned long irix_thread_id(void );
97static unsigned long solaris_thread_id(void );
98static unsigned long pthreads_thread_id(void );
99
100/* usage:
101 * CRYPTO_thread_setup();
102 * application code
103 * CRYPTO_thread_cleanup();
104 */
105
106#define THREAD_STACK_SIZE (16*1024)
107
108#ifdef OPENSSL_SYS_WIN32
109
110static HANDLE *lock_cs;
111
112void CRYPTO_thread_setup(void)
113 {
114 int i;
115
116 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(HANDLE));
117 for (i=0; i<CRYPTO_num_locks(); i++)
118 {
119 lock_cs[i]=CreateMutex(NULL,FALSE,NULL);
120 }
121
122 CRYPTO_set_locking_callback((void (*)(int,int,char *,int))win32_locking_callback);
123 /* id callback defined */
124 return(1);
125 }
126
127static void CRYPTO_thread_cleanup(void)
128 {
129 int i;
130
131 CRYPTO_set_locking_callback(NULL);
132 for (i=0; i<CRYPTO_num_locks(); i++)
133 CloseHandle(lock_cs[i]);
134 OPENSSL_free(lock_cs);
135 }
136
137void win32_locking_callback(int mode, int type, char *file, int line)
138 {
139 if (mode & CRYPTO_LOCK)
140 {
141 WaitForSingleObject(lock_cs[type],INFINITE);
142 }
143 else
144 {
145 ReleaseMutex(lock_cs[type]);
146 }
147 }
148
149#endif /* OPENSSL_SYS_WIN32 */
150
151#ifdef SOLARIS
152
153#define USE_MUTEX
154
155#ifdef USE_MUTEX
156static mutex_t *lock_cs;
157#else
158static rwlock_t *lock_cs;
159#endif
160static long *lock_count;
161
162void CRYPTO_thread_setup(void)
163 {
164 int i;
165
166#ifdef USE_MUTEX
167 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(mutex_t));
168#else
169 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(rwlock_t));
170#endif
171 lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
172 for (i=0; i<CRYPTO_num_locks(); i++)
173 {
174 lock_count[i]=0;
175#ifdef USE_MUTEX
176 mutex_init(&(lock_cs[i]),USYNC_THREAD,NULL);
177#else
178 rwlock_init(&(lock_cs[i]),USYNC_THREAD,NULL);
179#endif
180 }
181
182 CRYPTO_set_id_callback((unsigned long (*)())solaris_thread_id);
183 CRYPTO_set_locking_callback((void (*)())solaris_locking_callback);
184 }
185
186void CRYPTO_thread_cleanup(void)
187 {
188 int i;
189
190 CRYPTO_set_locking_callback(NULL);
191 for (i=0; i<CRYPTO_num_locks(); i++)
192 {
193#ifdef USE_MUTEX
194 mutex_destroy(&(lock_cs[i]));
195#else
196 rwlock_destroy(&(lock_cs[i]));
197#endif
198 }
199 OPENSSL_free(lock_cs);
200 OPENSSL_free(lock_count);
201 }
202
203void solaris_locking_callback(int mode, int type, char *file, int line)
204 {
205#if 0
206 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
207 CRYPTO_thread_id(),
208 (mode&CRYPTO_LOCK)?"l":"u",
209 (type&CRYPTO_READ)?"r":"w",file,line);
210#endif
211
212#if 0
213 if (CRYPTO_LOCK_SSL_CERT == type)
214 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
215 CRYPTO_thread_id(),
216 mode,file,line);
217#endif
218 if (mode & CRYPTO_LOCK)
219 {
220#ifdef USE_MUTEX
221 mutex_lock(&(lock_cs[type]));
222#else
223 if (mode & CRYPTO_READ)
224 rw_rdlock(&(lock_cs[type]));
225 else
226 rw_wrlock(&(lock_cs[type]));
227#endif
228 lock_count[type]++;
229 }
230 else
231 {
232#ifdef USE_MUTEX
233 mutex_unlock(&(lock_cs[type]));
234#else
235 rw_unlock(&(lock_cs[type]));
236#endif
237 }
238 }
239
240unsigned long solaris_thread_id(void)
241 {
242 unsigned long ret;
243
244 ret=(unsigned long)thr_self();
245 return(ret);
246 }
247#endif /* SOLARIS */
248
249#ifdef IRIX
250/* I don't think this works..... */
251
252static usptr_t *arena;
253static usema_t **lock_cs;
254
255void CRYPTO_thread_setup(void)
256 {
257 int i;
258 char filename[20];
259
260 strcpy(filename,"/tmp/mttest.XXXXXX");
261 mktemp(filename);
262
263 usconfig(CONF_STHREADIOOFF);
264 usconfig(CONF_STHREADMALLOCOFF);
265 usconfig(CONF_INITUSERS,100);
266 usconfig(CONF_LOCKTYPE,US_DEBUGPLUS);
267 arena=usinit(filename);
268 unlink(filename);
269
270 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(usema_t *));
271 for (i=0; i<CRYPTO_num_locks(); i++)
272 {
273 lock_cs[i]=usnewsema(arena,1);
274 }
275
276 CRYPTO_set_id_callback((unsigned long (*)())irix_thread_id);
277 CRYPTO_set_locking_callback((void (*)())irix_locking_callback);
278 }
279
280void CRYPTO_thread_cleanup(void)
281 {
282 int i;
283
284 CRYPTO_set_locking_callback(NULL);
285 for (i=0; i<CRYPTO_num_locks(); i++)
286 {
287 char buf[10];
288
289 sprintf(buf,"%2d:",i);
290 usdumpsema(lock_cs[i],stdout,buf);
291 usfreesema(lock_cs[i],arena);
292 }
293 OPENSSL_free(lock_cs);
294 }
295
296void irix_locking_callback(int mode, int type, char *file, int line)
297 {
298 if (mode & CRYPTO_LOCK)
299 {
300 uspsema(lock_cs[type]);
301 }
302 else
303 {
304 usvsema(lock_cs[type]);
305 }
306 }
307
308unsigned long irix_thread_id(void)
309 {
310 unsigned long ret;
311
312 ret=(unsigned long)getpid();
313 return(ret);
314 }
315#endif /* IRIX */
316
317/* Linux and a few others */
318#ifdef PTHREADS
319
320static pthread_mutex_t *lock_cs;
321static long *lock_count;
322
323void CRYPTO_thread_setup(void)
324 {
325 int i;
326
327 lock_cs=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
328 lock_count=OPENSSL_malloc(CRYPTO_num_locks() * sizeof(long));
329 for (i=0; i<CRYPTO_num_locks(); i++)
330 {
331 lock_count[i]=0;
332 pthread_mutex_init(&(lock_cs[i]),NULL);
333 }
334
335 CRYPTO_set_id_callback((unsigned long (*)())pthreads_thread_id);
336 CRYPTO_set_locking_callback((void (*)())pthreads_locking_callback);
337 }
338
339void thread_cleanup(void)
340 {
341 int i;
342
343 CRYPTO_set_locking_callback(NULL);
344 for (i=0; i<CRYPTO_num_locks(); i++)
345 {
346 pthread_mutex_destroy(&(lock_cs[i]));
347 }
348 OPENSSL_free(lock_cs);
349 OPENSSL_free(lock_count);
350 }
351
352void pthreads_locking_callback(int mode, int type, char *file,
353 int line)
354 {
355#if 0
356 fprintf(stderr,"thread=%4d mode=%s lock=%s %s:%d\n",
357 CRYPTO_thread_id(),
358 (mode&CRYPTO_LOCK)?"l":"u",
359 (type&CRYPTO_READ)?"r":"w",file,line);
360#endif
361#if 0
362 if (CRYPTO_LOCK_SSL_CERT == type)
363 fprintf(stderr,"(t,m,f,l) %ld %d %s %d\n",
364 CRYPTO_thread_id(),
365 mode,file,line);
366#endif
367 if (mode & CRYPTO_LOCK)
368 {
369 pthread_mutex_lock(&(lock_cs[type]));
370 lock_count[type]++;
371 }
372 else
373 {
374 pthread_mutex_unlock(&(lock_cs[type]));
375 }
376 }
377
378unsigned long pthreads_thread_id(void)
379 {
380 unsigned long ret;
381
382 ret=(unsigned long)pthread_self();
383 return(ret);
384 }
385
386#endif /* PTHREADS */
387
diff --git a/src/lib/libcrypto/threads/win32.bat b/src/lib/libcrypto/threads/win32.bat
new file mode 100644
index 0000000000..ee6da80a07
--- /dev/null
+++ b/src/lib/libcrypto/threads/win32.bat
@@ -0,0 +1,4 @@
1del mttest.exe
2
3cl /O2 -DWIN32 /MD -I..\..\out mttest.c /Femttest ..\..\out\ssleay32.lib ..\..\out\libeay32.lib
4
diff --git a/src/lib/libcrypto/tmdiff.c b/src/lib/libcrypto/tmdiff.c
new file mode 100644
index 0000000000..307523ebba
--- /dev/null
+++ b/src/lib/libcrypto/tmdiff.c
@@ -0,0 +1,249 @@
1/* crypto/tmdiff.c */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be 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 "cryptlib.h"
61#include <openssl/tmdiff.h>
62#if !defined(OPENSSL_SYS_MSDOS)
63#include OPENSSL_UNISTD
64#endif
65
66#ifdef TIMEB
67#undef OPENSSL_SYS_WIN32
68#undef TIMES
69#endif
70
71#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_WIN32) && !(defined(OPENSSL_SYS_VMS) || defined(__DECC)) && !defined(OPENSSL_SYS_MACOSX_RHAPSODY) && !defined(OPENSSL_SYS_VXWORKS)
72# define TIMES
73#endif
74
75#ifndef _IRIX
76# include <time.h>
77#endif
78#ifdef TIMES
79# include <sys/types.h>
80# include <sys/times.h>
81#endif
82
83/* Depending on the VMS version, the tms structure is perhaps defined.
84 The __TMS macro will show if it was. If it wasn't defined, we should
85 undefine TIMES, since that tells the rest of the program how things
86 should be handled. -- Richard Levitte */
87#if defined(OPENSSL_SYS_VMS_DECC) && !defined(__TMS)
88#undef TIMES
89#endif
90
91#if defined(sun) || defined(__ultrix)
92#define _POSIX_SOURCE
93#include <limits.h>
94#include <sys/param.h>
95#endif
96
97#if !defined(TIMES) && !defined(OPENSSL_SYS_VXWORKS)
98#include <sys/timeb.h>
99#endif
100
101#ifdef OPENSSL_SYS_WIN32
102#include <windows.h>
103#endif
104
105/* The following if from times(3) man page. It may need to be changed */
106#ifndef HZ
107# if defined(_SC_CLK_TCK) \
108 && (!defined(OPENSSL_SYS_VMS) || __CTRL_VER >= 70000000)
109# define HZ ((double)sysconf(_SC_CLK_TCK))
110# else
111# ifndef CLK_TCK
112# ifndef _BSD_CLK_TCK_ /* FreeBSD hack */
113# define HZ 100.0
114# else /* _BSD_CLK_TCK_ */
115# define HZ ((double)_BSD_CLK_TCK_)
116# endif
117# else /* CLK_TCK */
118# define HZ ((double)CLK_TCK)
119# endif
120# endif
121#endif
122
123typedef struct ms_tm
124 {
125#ifdef TIMES
126 struct tms ms_tms;
127#else
128# ifdef OPENSSL_SYS_WIN32
129 HANDLE thread_id;
130 FILETIME ms_win32;
131# else
132# ifdef OPENSSL_SYS_VXWORKS
133 unsigned long ticks;
134# else
135 struct timeb ms_timeb;
136# endif
137# endif
138#endif
139 } MS_TM;
140
141char *ms_time_new(void)
142 {
143 MS_TM *ret;
144
145 ret=(MS_TM *)OPENSSL_malloc(sizeof(MS_TM));
146 if (ret == NULL)
147 return(NULL);
148 memset(ret,0,sizeof(MS_TM));
149#ifdef OPENSSL_SYS_WIN32
150 ret->thread_id=GetCurrentThread();
151#endif
152 return((char *)ret);
153 }
154
155void ms_time_free(char *a)
156 {
157 if (a != NULL)
158 OPENSSL_free(a);
159 }
160
161void ms_time_get(char *a)
162 {
163 MS_TM *tm=(MS_TM *)a;
164#ifdef OPENSSL_SYS_WIN32
165 FILETIME tmpa,tmpb,tmpc;
166#endif
167
168#ifdef TIMES
169 times(&tm->ms_tms);
170#else
171# ifdef OPENSSL_SYS_WIN32
172 GetThreadTimes(tm->thread_id,&tmpa,&tmpb,&tmpc,&(tm->ms_win32));
173# else
174# ifdef OPENSSL_SYS_VXWORKS
175 tm->ticks = tickGet();
176# else
177 ftime(&tm->ms_timeb);
178# endif
179# endif
180#endif
181 }
182
183double ms_time_diff(char *ap, char *bp)
184 {
185 MS_TM *a=(MS_TM *)ap;
186 MS_TM *b=(MS_TM *)bp;
187 double ret;
188
189#ifdef TIMES
190 ret=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
191#else
192# ifdef OPENSSL_SYS_WIN32
193 {
194#ifdef __GNUC__
195 signed long long la,lb;
196#else
197 signed _int64 la,lb;
198#endif
199 la=a->ms_win32.dwHighDateTime;
200 lb=b->ms_win32.dwHighDateTime;
201 la<<=32;
202 lb<<=32;
203 la+=a->ms_win32.dwLowDateTime;
204 lb+=b->ms_win32.dwLowDateTime;
205 ret=((double)(lb-la))/1e7;
206 }
207# else
208# ifdef OPENSSL_SYS_VXWORKS
209 ret = (double)(b->ticks - a->ticks) / (double)sysClkRateGet();
210# else
211 ret= (double)(b->ms_timeb.time-a->ms_timeb.time)+
212 (((double)b->ms_timeb.millitm)-
213 ((double)a->ms_timeb.millitm))/1000.0;
214# endif
215# endif
216#endif
217 return((ret < 0.0000001)?0.0000001:ret);
218 }
219
220int ms_time_cmp(char *ap, char *bp)
221 {
222 MS_TM *a=(MS_TM *)ap,*b=(MS_TM *)bp;
223 double d;
224 int ret;
225
226#ifdef TIMES
227 d=(b->ms_tms.tms_utime-a->ms_tms.tms_utime)/HZ;
228#else
229# ifdef OPENSSL_SYS_WIN32
230 d =(b->ms_win32.dwHighDateTime&0x000fffff)*10+b->ms_win32.dwLowDateTime/1e7;
231 d-=(a->ms_win32.dwHighDateTime&0x000fffff)*10+a->ms_win32.dwLowDateTime/1e7;
232# else
233# ifdef OPENSSL_SYS_VXWORKS
234 d = (b->ticks - a->ticks);
235# else
236 d= (double)(b->ms_timeb.time-a->ms_timeb.time)+
237 (((double)b->ms_timeb.millitm)-(double)a->ms_timeb.millitm)/1000.0;
238# endif
239# endif
240#endif
241 if (d == 0.0)
242 ret=0;
243 else if (d < 0)
244 ret= -1;
245 else
246 ret=1;
247 return(ret);
248 }
249
diff --git a/src/lib/libcrypto/tmdiff.h b/src/lib/libcrypto/tmdiff.h
new file mode 100644
index 0000000000..41a8a1e0e0
--- /dev/null
+++ b/src/lib/libcrypto/tmdiff.h
@@ -0,0 +1,81 @@
1/* crypto/tmdiff.h */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved.
4 *
5 * This package is an SSL implementation written
6 * by Eric Young (eay@cryptsoft.com).
7 * The implementation was written so as to conform with Netscapes SSL.
8 *
9 * This library is free for commercial and non-commercial use as long as
10 * the following conditions are aheared to. The following conditions
11 * apply to all code found in this distribution, be it the RC4, RSA,
12 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
13 * included with this distribution is covered by the same copyright terms
14 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
15 *
16 * Copyright remains Eric Young's, and as such any Copyright notices in
17 * the code are not to be removed.
18 * If this package is used in a product, Eric Young should be given attribution
19 * as the author of the parts of the library used.
20 * This can be in the form of a textual message at program startup or
21 * in documentation (online or textual) provided with the package.
22 *
23 * Redistribution and use in source and binary forms, with or without
24 * modification, are permitted provided that the following conditions
25 * are met:
26 * 1. Redistributions of source code must retain the copyright
27 * notice, this list of conditions and the following disclaimer.
28 * 2. Redistributions in binary form must reproduce the above copyright
29 * notice, this list of conditions and the following disclaimer in the
30 * documentation and/or other materials provided with the distribution.
31 * 3. All advertising materials mentioning features or use of this software
32 * must display the following acknowledgement:
33 * "This product includes cryptographic software written by
34 * Eric Young (eay@cryptsoft.com)"
35 * The word 'cryptographic' can be left out if the rouines from the library
36 * being used are not cryptographic related :-).
37 * 4. If you include any Windows specific code (or a derivative thereof) from
38 * the apps directory (application code) you must include an acknowledgement:
39 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
40 *
41 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
42 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
44 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
45 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
46 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
47 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
48 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
49 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
50 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
51 * SUCH DAMAGE.
52 *
53 * The licence and distribution terms for any publically available version or
54 * derivative of this code cannot be changed. i.e. this code cannot simply be
55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.]
57 */
58
59/* Header for dynamic hash table routines
60 * Author - Eric Young
61 */
62
63#ifndef HEADER_TMDIFF_H
64#define HEADER_TMDIFF_H
65
66#ifdef __cplusplus
67extern "C" {
68#endif
69
70char *ms_time_new(void );
71void ms_time_free(char *a);
72void ms_time_get(char *a);
73double ms_time_diff(char *start,char *end);
74int ms_time_cmp(char *ap,char *bp);
75
76#ifdef __cplusplus
77}
78#endif
79
80#endif
81
diff --git a/src/lib/libcrypto/txt_db/Makefile b/src/lib/libcrypto/txt_db/Makefile
new file mode 100644
index 0000000000..e6f30331d8
--- /dev/null
+++ b/src/lib/libcrypto/txt_db/Makefile
@@ -0,0 +1,84 @@
1#
2# OpenSSL/crypto/txt_db/Makefile
3#
4
5DIR= txt_db
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC=txt_db.c
21LIBOBJ=txt_db.o
22
23SRC= $(LIBSRC)
24
25EXHEADER= txt_db.h
26HEADER= $(EXHEADER)
27
28ALL= $(GENERAL) $(SRC) $(HEADER)
29
30top:
31 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
32
33all: lib
34
35lib: $(LIBOBJ)
36 $(AR) $(LIB) $(LIBOBJ)
37 $(RANLIB) $(LIB) || echo Never mind.
38 @touch lib
39
40files:
41 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
42
43links:
44 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
45 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
46 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
47
48install:
49 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
50 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
51 do \
52 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
53 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
54 done;
55
56tags:
57 ctags $(SRC)
58
59tests:
60
61lint:
62 lint -DLINT $(INCLUDES) $(SRC)>fluff
63
64depend:
65 @[ -n "$(MAKEDEPEND)" ] # should be set by top Makefile...
66 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
67
68dclean:
69 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
70 mv -f Makefile.new $(MAKEFILE)
71
72clean:
73 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
74
75# DO NOT DELETE THIS LINE -- make depend depends on it.
76
77txt_db.o: ../../e_os.h ../../include/openssl/bio.h
78txt_db.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
79txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
80txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
81txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
82txt_db.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
83txt_db.o: ../../include/openssl/symhacks.h ../../include/openssl/txt_db.h
84txt_db.o: ../cryptlib.h txt_db.c
diff --git a/src/lib/libcrypto/txt_db/Makefile.ssl b/src/lib/libcrypto/txt_db/Makefile.ssl
new file mode 100644
index 0000000000..6221dfae4d
--- /dev/null
+++ b/src/lib/libcrypto/txt_db/Makefile.ssl
@@ -0,0 +1,88 @@
1#
2# SSLeay/crypto/txt_db/Makefile
3#
4
5DIR= txt_db
6TOP= ../..
7CC= cc
8INCLUDES=
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC=txt_db.c
27LIBOBJ=txt_db.o
28
29SRC= $(LIBSRC)
30
31EXHEADER= txt_db.h
32HEADER= $(EXHEADER)
33
34ALL= $(GENERAL) $(SRC) $(HEADER)
35
36top:
37 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
38
39all: lib
40
41lib: $(LIBOBJ)
42 $(AR) $(LIB) $(LIBOBJ)
43 $(RANLIB) $(LIB) || echo Never mind.
44 @touch lib
45
46files:
47 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
48
49links:
50 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
51 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
52 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
53 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
54
55install:
56 @for i in $(EXHEADER) ; \
57 do \
58 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
59 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
60 done;
61
62tags:
63 ctags $(SRC)
64
65tests:
66
67lint:
68 lint -DLINT $(INCLUDES) $(SRC)>fluff
69
70depend:
71 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
72
73dclean:
74 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
75 mv -f Makefile.new $(MAKEFILE)
76
77clean:
78 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
79
80# DO NOT DELETE THIS LINE -- make depend depends on it.
81
82txt_db.o: ../../e_os.h ../../include/openssl/bio.h
83txt_db.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
84txt_db.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
85txt_db.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
86txt_db.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
87txt_db.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
88txt_db.o: ../../include/openssl/txt_db.h ../cryptlib.h txt_db.c
diff --git a/src/lib/libcrypto/txt_db/txt_db.c b/src/lib/libcrypto/txt_db/txt_db.c
index 3ed5f72ee9..58b300b00b 100644
--- a/src/lib/libcrypto/txt_db/txt_db.c
+++ b/src/lib/libcrypto/txt_db/txt_db.c
@@ -66,7 +66,7 @@
66#undef BUFSIZE 66#undef BUFSIZE
67#define BUFSIZE 512 67#define BUFSIZE 512
68 68
69const char TXT_DB_version[]="TXT_DB" OPENSSL_VERSION_PTEXT; 69const char *TXT_DB_version="TXT_DB" OPENSSL_VERSION_PTEXT;
70 70
71TXT_DB *TXT_DB_read(BIO *in, int num) 71TXT_DB *TXT_DB_read(BIO *in, int num)
72 { 72 {
@@ -92,7 +92,7 @@ TXT_DB *TXT_DB_read(BIO *in, int num)
92 goto err; 92 goto err;
93 if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL) 93 if ((ret->index=(LHASH **)OPENSSL_malloc(sizeof(LHASH *)*num)) == NULL)
94 goto err; 94 goto err;
95 if ((ret->qual=(int (**)(char **))OPENSSL_malloc(sizeof(int (**)(char **))*num)) == NULL) 95 if ((ret->qual=(int (**)())OPENSSL_malloc(sizeof(int (**)())*num)) == NULL)
96 goto err; 96 goto err;
97 for (i=0; i<num; i++) 97 for (i=0; i<num; i++)
98 { 98 {
@@ -179,13 +179,10 @@ err:
179#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16) 179#if !defined(OPENSSL_NO_STDIO) && !defined(OPENSSL_SYS_WIN16)
180 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n"); 180 if (er == 1) fprintf(stderr,"OPENSSL_malloc failure\n");
181#endif 181#endif
182 if (ret != NULL) 182 if (ret->data != NULL) sk_free(ret->data);
183 { 183 if (ret->index != NULL) OPENSSL_free(ret->index);
184 if (ret->data != NULL) sk_free(ret->data); 184 if (ret->qual != NULL) OPENSSL_free(ret->qual);
185 if (ret->index != NULL) OPENSSL_free(ret->index); 185 if (ret != NULL) OPENSSL_free(ret);
186 if (ret->qual != NULL) OPENSSL_free(ret->qual);
187 if (ret != NULL) OPENSSL_free(ret);
188 }
189 return(NULL); 186 return(NULL);
190 } 187 }
191 else 188 else
@@ -213,11 +210,11 @@ char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value)
213 return(ret); 210 return(ret);
214 } 211 }
215 212
216int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **), 213int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(),
217 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp) 214 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp)
218 { 215 {
219 LHASH *idx; 216 LHASH *idx;
220 char **r; 217 char *r;
221 int i,n; 218 int i,n;
222 219
223 if (field >= db->num_fields) 220 if (field >= db->num_fields)
@@ -233,12 +230,12 @@ int TXT_DB_create_index(TXT_DB *db, int field, int (*qual)(char **),
233 n=sk_num(db->data); 230 n=sk_num(db->data);
234 for (i=0; i<n; i++) 231 for (i=0; i<n; i++)
235 { 232 {
236 r=(char **)sk_value(db->data,i); 233 r=(char *)sk_value(db->data,i);
237 if ((qual != NULL) && (qual(r) == 0)) continue; 234 if ((qual != NULL) && (qual(r) == 0)) continue;
238 if ((r=lh_insert(idx,r)) != NULL) 235 if ((r=lh_insert(idx,r)) != NULL)
239 { 236 {
240 db->error=DB_ERROR_INDEX_CLASH; 237 db->error=DB_ERROR_INDEX_CLASH;
241 db->arg1=sk_find(db->data,(char *)r); 238 db->arg1=sk_find(db->data,r);
242 db->arg2=i; 239 db->arg2=i;
243 lh_free(idx); 240 lh_free(idx);
244 return(0); 241 return(0);
diff --git a/src/lib/libcrypto/txt_db/txt_db.h b/src/lib/libcrypto/txt_db/txt_db.h
index 307e1ba23f..563392aeff 100644
--- a/src/lib/libcrypto/txt_db/txt_db.h
+++ b/src/lib/libcrypto/txt_db/txt_db.h
@@ -59,7 +59,6 @@
59#ifndef HEADER_TXT_DB_H 59#ifndef HEADER_TXT_DB_H
60#define HEADER_TXT_DB_H 60#define HEADER_TXT_DB_H
61 61
62#include <openssl/opensslconf.h>
63#ifndef OPENSSL_NO_BIO 62#ifndef OPENSSL_NO_BIO
64#include <openssl/bio.h> 63#include <openssl/bio.h>
65#endif 64#endif
@@ -82,7 +81,7 @@ typedef struct txt_db_st
82 int num_fields; 81 int num_fields;
83 STACK /* char ** */ *data; 82 STACK /* char ** */ *data;
84 LHASH **index; 83 LHASH **index;
85 int (**qual)(char **); 84 int (**qual)();
86 long error; 85 long error;
87 long arg1; 86 long arg1;
88 long arg2; 87 long arg2;
@@ -96,7 +95,7 @@ long TXT_DB_write(BIO *out, TXT_DB *db);
96TXT_DB *TXT_DB_read(char *in, int num); 95TXT_DB *TXT_DB_read(char *in, int num);
97long TXT_DB_write(char *out, TXT_DB *db); 96long TXT_DB_write(char *out, TXT_DB *db);
98#endif 97#endif
99int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(char **), 98int TXT_DB_create_index(TXT_DB *db,int field,int (*qual)(),
100 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp); 99 LHASH_HASH_FN_TYPE hash, LHASH_COMP_FN_TYPE cmp);
101void TXT_DB_free(TXT_DB *db); 100void TXT_DB_free(TXT_DB *db);
102char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value); 101char **TXT_DB_get_by_index(TXT_DB *db, int idx, char **value);
diff --git a/src/lib/libcrypto/ui/Makefile b/src/lib/libcrypto/ui/Makefile
new file mode 100644
index 0000000000..a685659fb4
--- /dev/null
+++ b/src/lib/libcrypto/ui/Makefile
@@ -0,0 +1,111 @@
1#
2# OpenSSL/crypto/ui/Makefile
3#
4
5DIR= ui
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile
16#TEST= uitest.c
17TEST=
18APPS=
19
20COMPATSRC= ui_compat.c
21COMPATOBJ= ui_compat.o
22
23LIB=$(TOP)/libcrypto.a
24LIBSRC= ui_err.c ui_lib.c ui_openssl.c ui_util.c $(COMPATSRC)
25LIBOBJ= ui_err.o ui_lib.o ui_openssl.o ui_util.o $(COMPATOBJ)
26
27SRC= $(LIBSRC)
28
29EXHEADER= ui.h ui_compat.h
30HEADER= $(EXHEADER) ui_locl.h
31
32ALL= $(GENERAL) $(SRC) $(HEADER)
33
34top:
35 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
36
37all: lib
38
39lib: $(LIBOBJ)
40 $(AR) $(LIB) $(LIBOBJ)
41 $(RANLIB) $(LIB) || echo Never mind.
42 @touch lib
43
44files:
45 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
46
47links:
48 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
49 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
50 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
51
52install:
53 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
54 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
55 do \
56 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
57 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
58 done;
59
60tags:
61 ctags $(SRC)
62
63tests:
64
65lint:
66 lint -DLINT $(INCLUDES) $(SRC)>fluff
67
68depend:
69 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
70 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
71
72dclean:
73 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
74 mv -f Makefile.new $(MAKEFILE)
75
76clean:
77 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
78
79# DO NOT DELETE THIS LINE -- make depend depends on it.
80
81ui_compat.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h
82ui_compat.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
83ui_compat.o: ../../include/openssl/stack.h ../../include/openssl/ui.h
84ui_compat.o: ../../include/openssl/ui_compat.h ui_compat.c
85ui_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
86ui_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
87ui_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
88ui_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
89ui_err.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
90ui_err.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h ui_err.c
91ui_lib.o: ../../e_os.h ../../include/openssl/bio.h
92ui_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
93ui_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94ui_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
95ui_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
96ui_lib.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
97ui_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
98ui_lib.o: ../cryptlib.h ui_lib.c ui_locl.h
99ui_openssl.o: ../../e_os.h ../../include/openssl/bio.h
100ui_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
101ui_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
102ui_openssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
103ui_openssl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
104ui_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
105ui_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
106ui_openssl.o: ../cryptlib.h ui_locl.h ui_openssl.c
107ui_util.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
108ui_util.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
109ui_util.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h
110ui_util.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
111ui_util.o: ../../include/openssl/ui.h ui_locl.h ui_util.c
diff --git a/src/lib/libcrypto/ui/Makefile.ssl b/src/lib/libcrypto/ui/Makefile.ssl
new file mode 100644
index 0000000000..ba46951d1c
--- /dev/null
+++ b/src/lib/libcrypto/ui/Makefile.ssl
@@ -0,0 +1,117 @@
1#
2# OpenSSL/crypto/ui/Makefile
3#
4
5DIR= ui
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile
22#TEST= uitest.c
23TEST=
24APPS=
25
26COMPATSRC= ui_compat.c
27COMPATOBJ= ui_compat.o
28
29LIB=$(TOP)/libcrypto.a
30LIBSRC= ui_err.c ui_lib.c ui_openssl.c ui_util.c $(COMPATSRC)
31LIBOBJ= ui_err.o ui_lib.o ui_openssl.o ui_util.o $(COMPATOBJ)
32
33SRC= $(LIBSRC)
34
35EXHEADER= ui.h ui_compat.h
36HEADER= $(EXHEADER) ui_locl.h
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
52
53links:
54 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
55 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
56 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
57 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
58
59install:
60 @for i in $(EXHEADER) ; \
61 do \
62 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
63 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
64 done;
65
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
76
77dclean:
78 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
79 mv -f Makefile.new $(MAKEFILE)
80
81clean:
82 rm -f *.o */*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
83
84# DO NOT DELETE THIS LINE -- make depend depends on it.
85
86ui_compat.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
87ui_compat.o: ../../include/openssl/opensslconf.h
88ui_compat.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
89ui_compat.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
90ui_compat.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
91ui_compat.o: ui_compat.c
92ui_err.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h
93ui_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
94ui_err.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
95ui_err.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
96ui_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
97ui_err.o: ../../include/openssl/ui.h ui_err.c
98ui_lib.o: ../../e_os.h ../../include/openssl/bio.h
99ui_lib.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
100ui_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
101ui_lib.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
102ui_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h
103ui_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
104ui_lib.o: ../../include/openssl/ui.h ../cryptlib.h ui_lib.c ui_locl.h
105ui_openssl.o: ../../e_os.h ../../include/openssl/bio.h
106ui_openssl.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
107ui_openssl.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
108ui_openssl.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h
109ui_openssl.o: ../../include/openssl/opensslv.h
110ui_openssl.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
111ui_openssl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
112ui_openssl.o: ../cryptlib.h ui_locl.h ui_openssl.c
113ui_util.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
114ui_util.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
115ui_util.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h
116ui_util.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
117ui_util.o: ui_util.c
diff --git a/src/lib/libcrypto/ui/ui.h b/src/lib/libcrypto/ui/ui.h
index 018296412b..735a2d988e 100644
--- a/src/lib/libcrypto/ui/ui.h
+++ b/src/lib/libcrypto/ui/ui.h
@@ -59,19 +59,25 @@
59#ifndef HEADER_UI_H 59#ifndef HEADER_UI_H
60#define HEADER_UI_H 60#define HEADER_UI_H
61 61
62#ifndef OPENSSL_NO_DEPRECATED
63#include <openssl/crypto.h> 62#include <openssl/crypto.h>
64#endif
65#include <openssl/safestack.h> 63#include <openssl/safestack.h>
66#include <openssl/ossl_typ.h>
67 64
68#ifdef __cplusplus 65#ifdef __cplusplus
69extern "C" { 66extern "C" {
70#endif 67#endif
71 68
72/* Declared already in ossl_typ.h */ 69/* The UI type is a holder for a specific user interface session. It can
73/* typedef struct ui_st UI; */ 70 contain an illimited number of informational or error strings as well
74/* typedef struct ui_method_st UI_METHOD; */ 71 as things to prompt for, both passwords (noecho mode) and others (echo
72 mode), and verification of the same. All of these are called strings,
73 and are further described below. */
74typedef struct ui_st UI;
75
76/* All instances of UI have a reference to a method structure, which is a
77 ordered vector of functions that implement the lower level things to do.
78 There is an instruction on the implementation further down, in the section
79 for method implementors. */
80typedef struct ui_method_st UI_METHOD;
75 81
76 82
77/* All the following functions return -1 or NULL on error and in some cases 83/* All the following functions return -1 or NULL on error and in some cases
@@ -211,7 +217,7 @@ int UI_process(UI *ui);
211/* Give a user interface parametrised control commands. This can be used to 217/* Give a user interface parametrised control commands. This can be used to
212 send down an integer, a data pointer or a function pointer, as well as 218 send down an integer, a data pointer or a function pointer, as well as
213 be used to get information from a UI. */ 219 be used to get information from a UI. */
214int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)); 220int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)());
215 221
216/* The commands */ 222/* The commands */
217/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the 223/* Use UI_CONTROL_PRINT_ERRORS with the value 1 to have UI_process print the
diff --git a/src/lib/libcrypto/ui/ui_compat.c b/src/lib/libcrypto/ui/ui_compat.c
new file mode 100644
index 0000000000..13e0f70d90
--- /dev/null
+++ b/src/lib/libcrypto/ui/ui_compat.c
@@ -0,0 +1,67 @@
1/* crypto/ui/ui_compat.c -*- mode:C; c-file-style: "eay" -*- */
2/* ====================================================================
3 * Copyright (c) 2001-2002 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * openssl-core@openssl.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <string.h>
57#include <openssl/ui_compat.h>
58
59int _ossl_old_des_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 {
61 return UI_UTIL_read_pw_string(buf, length, prompt, verify);
62 }
63
64int _ossl_old_des_read_pw(char *buf,char *buff,int size,const char *prompt,int verify)
65 {
66 return UI_UTIL_read_pw(buf, buff, size, prompt, verify);
67 }
diff --git a/src/lib/libcrypto/ui/ui_err.c b/src/lib/libcrypto/ui/ui_err.c
index 786bd0dbc3..d983cdd66f 100644
--- a/src/lib/libcrypto/ui/ui_err.c
+++ b/src/lib/libcrypto/ui/ui_err.c
@@ -101,12 +101,15 @@ static ERR_STRING_DATA UI_str_reasons[]=
101 101
102void ERR_load_UI_strings(void) 102void ERR_load_UI_strings(void)
103 { 103 {
104#ifndef OPENSSL_NO_ERR 104 static int init=1;
105 105
106 if (ERR_func_error_string(UI_str_functs[0].error) == NULL) 106 if (init)
107 { 107 {
108 init=0;
109#ifndef OPENSSL_NO_ERR
108 ERR_load_strings(0,UI_str_functs); 110 ERR_load_strings(0,UI_str_functs);
109 ERR_load_strings(0,UI_str_reasons); 111 ERR_load_strings(0,UI_str_reasons);
110 }
111#endif 112#endif
113
114 }
112 } 115 }
diff --git a/src/lib/libcrypto/ui/ui_lib.c b/src/lib/libcrypto/ui/ui_lib.c
index 7ab249c3be..dbc9711a2d 100644
--- a/src/lib/libcrypto/ui/ui_lib.c
+++ b/src/lib/libcrypto/ui/ui_lib.c
@@ -57,12 +57,12 @@
57 */ 57 */
58 58
59#include <string.h> 59#include <string.h>
60#include "cryptlib.h"
61#include <openssl/e_os2.h> 60#include <openssl/e_os2.h>
62#include <openssl/buffer.h> 61#include <openssl/buffer.h>
63#include <openssl/ui.h> 62#include <openssl/ui.h>
64#include <openssl/err.h> 63#include <openssl/err.h>
65#include "ui_locl.h" 64#include "ui_locl.h"
65#include "cryptlib.h"
66 66
67IMPLEMENT_STACK_OF(UI_STRING_ST) 67IMPLEMENT_STACK_OF(UI_STRING_ST)
68 68
@@ -545,7 +545,7 @@ int UI_process(UI *ui)
545 return ok; 545 return ok;
546 } 546 }
547 547
548int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)(void)) 548int UI_ctrl(UI *ui, int cmd, long i, void *p, void (*f)())
549 { 549 {
550 if (ui == NULL) 550 if (ui == NULL)
551 { 551 {
@@ -620,10 +620,8 @@ UI_METHOD *UI_create_method(char *name)
620 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD)); 620 UI_METHOD *ui_method = (UI_METHOD *)OPENSSL_malloc(sizeof(UI_METHOD));
621 621
622 if (ui_method) 622 if (ui_method)
623 {
624 memset(ui_method, 0, sizeof(*ui_method)); 623 memset(ui_method, 0, sizeof(*ui_method));
625 ui_method->name = BUF_strdup(name); 624 ui_method->name = BUF_strdup(name);
626 }
627 return ui_method; 625 return ui_method;
628 } 626 }
629 627
diff --git a/src/lib/libcrypto/ui/ui_locl.h b/src/lib/libcrypto/ui/ui_locl.h
index aa4a55637d..7d3a75a619 100644
--- a/src/lib/libcrypto/ui/ui_locl.h
+++ b/src/lib/libcrypto/ui/ui_locl.h
@@ -60,11 +60,6 @@
60#define HEADER_UI_LOCL_H 60#define HEADER_UI_LOCL_H
61 61
62#include <openssl/ui.h> 62#include <openssl/ui.h>
63#include <openssl/crypto.h>
64
65#ifdef _
66#undef _
67#endif
68 63
69struct ui_method_st 64struct ui_method_st
70 { 65 {
diff --git a/src/lib/libcrypto/ui/ui_openssl.c b/src/lib/libcrypto/ui/ui_openssl.c
index 1f23a45a33..d03aeba91a 100644
--- a/src/lib/libcrypto/ui/ui_openssl.c
+++ b/src/lib/libcrypto/ui/ui_openssl.c
@@ -117,17 +117,6 @@
117 117
118#include <openssl/e_os2.h> 118#include <openssl/e_os2.h>
119 119
120/* need for #define _POSIX_C_SOURCE arises whenever you pass -ansi to gcc
121 * [maybe others?], because it masks interfaces not discussed in standard,
122 * sigaction and fileno included. -pedantic would be more appropriate for
123 * the intended purposes, but we can't prevent users from adding -ansi.
124 */
125#define _POSIX_C_SOURCE 1
126#include <signal.h>
127#include <stdio.h>
128#include <string.h>
129#include <errno.h>
130
131#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS) 120#if !defined(OPENSSL_SYS_MSDOS) && !defined(OPENSSL_SYS_VMS)
132# ifdef OPENSSL_UNISTD 121# ifdef OPENSSL_UNISTD
133# include OPENSSL_UNISTD 122# include OPENSSL_UNISTD
@@ -156,6 +145,10 @@
156/* 06-Apr-92 Luke Brennan Support for VMS */ 145/* 06-Apr-92 Luke Brennan Support for VMS */
157#include "ui_locl.h" 146#include "ui_locl.h"
158#include "cryptlib.h" 147#include "cryptlib.h"
148#include <signal.h>
149#include <stdio.h>
150#include <string.h>
151#include <errno.h>
159 152
160#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */ 153#ifdef OPENSSL_SYS_VMS /* prototypes for sys$whatever */
161# include <starlet.h> 154# include <starlet.h>
@@ -206,12 +199,6 @@
206#undef SGTTY 199#undef SGTTY
207#endif 200#endif
208 201
209#if defined(OPENSSL_SYS_NETWARE)
210#undef TERMIOS
211#undef TERMIO
212#undef SGTTY
213#endif
214
215#ifdef TERMIOS 202#ifdef TERMIOS
216# include <termios.h> 203# include <termios.h>
217# define TTY_STRUCT struct termios 204# define TTY_STRUCT struct termios
@@ -260,7 +247,7 @@ struct IOSB {
260 typedef int sig_atomic_t; 247 typedef int sig_atomic_t;
261#endif 248#endif
262 249
263#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE) || defined(OPENSSL_SYS_NETWARE) 250#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(MAC_OS_GUSI_SOURCE)
264/* 251/*
265 * This one needs work. As a matter of fact the code is unoperational 252 * This one needs work. As a matter of fact the code is unoperational
266 * and this is only a trick to get it compiled. 253 * and this is only a trick to get it compiled.
@@ -396,7 +383,8 @@ static void read_till_nl(FILE *in)
396 char buf[SIZE+1]; 383 char buf[SIZE+1];
397 384
398 do { 385 do {
399 fgets(buf,SIZE,in); 386 if (fgets(buf,sizeof(buf),in) == NULL)
387 break;
400 } while (strchr(buf,'\n') == NULL); 388 } while (strchr(buf,'\n') == NULL);
401 } 389 }
402 390
@@ -473,7 +461,7 @@ static int open_console(UI *ui)
473 CRYPTO_w_lock(CRYPTO_LOCK_UI); 461 CRYPTO_w_lock(CRYPTO_LOCK_UI);
474 is_a_tty = 1; 462 is_a_tty = 1;
475 463
476#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS) || defined(OPENSSL_SYS_NETWARE) 464#if defined(OPENSSL_SYS_MACINTOSH_CLASSIC) || defined(OPENSSL_SYS_VXWORKS)
477 tty_in=stdin; 465 tty_in=stdin;
478 tty_out=stderr; 466 tty_out=stderr;
479#else 467#else
@@ -489,7 +477,7 @@ static int open_console(UI *ui)
489#endif 477#endif
490 478
491#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS) 479#if defined(TTY_get) && !defined(OPENSSL_SYS_VMS)
492 if (TTY_get(fileno(tty_in),&tty_orig) == -1) 480 if (TTY_get(fileno(tty_in),&tty_orig) == -1)
493 { 481 {
494#ifdef ENOTTY 482#ifdef ENOTTY
495 if (errno == ENOTTY) 483 if (errno == ENOTTY)
@@ -578,9 +566,7 @@ static int close_console(UI *ui)
578/* Internal functions to handle signals and act on them */ 566/* Internal functions to handle signals and act on them */
579static void pushsig(void) 567static void pushsig(void)
580 { 568 {
581#ifndef OPENSSL_SYS_WIN32
582 int i; 569 int i;
583#endif
584#ifdef SIGACTION 570#ifdef SIGACTION
585 struct sigaction sa; 571 struct sigaction sa;
586 572
@@ -588,14 +574,6 @@ static void pushsig(void)
588 sa.sa_handler=recsig; 574 sa.sa_handler=recsig;
589#endif 575#endif
590 576
591#ifdef OPENSSL_SYS_WIN32
592 savsig[SIGABRT]=signal(SIGABRT,recsig);
593 savsig[SIGFPE]=signal(SIGFPE,recsig);
594 savsig[SIGILL]=signal(SIGILL,recsig);
595 savsig[SIGINT]=signal(SIGINT,recsig);
596 savsig[SIGSEGV]=signal(SIGSEGV,recsig);
597 savsig[SIGTERM]=signal(SIGTERM,recsig);
598#else
599 for (i=1; i<NX509_SIG; i++) 577 for (i=1; i<NX509_SIG; i++)
600 { 578 {
601#ifdef SIGUSR1 579#ifdef SIGUSR1
@@ -616,7 +594,6 @@ static void pushsig(void)
616 savsig[i]=signal(i,recsig); 594 savsig[i]=signal(i,recsig);
617#endif 595#endif
618 } 596 }
619#endif
620 597
621#ifdef SIGWINCH 598#ifdef SIGWINCH
622 signal(SIGWINCH,SIG_DFL); 599 signal(SIGWINCH,SIG_DFL);
@@ -625,15 +602,8 @@ static void pushsig(void)
625 602
626static void popsig(void) 603static void popsig(void)
627 { 604 {
628#ifdef OPENSSL_SYS_WIN32
629 signal(SIGABRT,savsig[SIGABRT]);
630 signal(SIGFPE,savsig[SIGFPE]);
631 signal(SIGILL,savsig[SIGILL]);
632 signal(SIGINT,savsig[SIGINT]);
633 signal(SIGSEGV,savsig[SIGSEGV]);
634 signal(SIGTERM,savsig[SIGTERM]);
635#else
636 int i; 605 int i;
606
637 for (i=1; i<NX509_SIG; i++) 607 for (i=1; i<NX509_SIG; i++)
638 { 608 {
639#ifdef SIGUSR1 609#ifdef SIGUSR1
@@ -650,7 +620,6 @@ static void popsig(void)
650 signal(i,savsig[i]); 620 signal(i,savsig[i]);
651#endif 621#endif
652 } 622 }
653#endif
654 } 623 }
655 624
656static void recsig(int i) 625static void recsig(int i)
diff --git a/src/lib/libcrypto/ui/ui_util.c b/src/lib/libcrypto/ui/ui_util.c
index 5d9760bb7b..46bc8c1a9a 100644
--- a/src/lib/libcrypto/ui/ui_util.c
+++ b/src/lib/libcrypto/ui/ui_util.c
@@ -54,7 +54,7 @@
54 */ 54 */
55 55
56#include <string.h> 56#include <string.h>
57#include "ui_locl.h" 57#include <openssl/ui.h>
58 58
59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify) 59int UI_UTIL_read_pw_string(char *buf,int length,const char *prompt,int verify)
60 { 60 {
diff --git a/src/lib/libcrypto/uid.c b/src/lib/libcrypto/uid.c
new file mode 100644
index 0000000000..73205a4baa
--- /dev/null
+++ b/src/lib/libcrypto/uid.c
@@ -0,0 +1,89 @@
1/* crypto/uid.c */
2/* ====================================================================
3 * Copyright (c) 2001 The OpenSSL Project. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 *
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in
14 * the documentation and/or other materials provided with the
15 * distribution.
16 *
17 * 3. All advertising materials mentioning features or use of this
18 * software must display the following acknowledgment:
19 * "This product includes software developed by the OpenSSL Project
20 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
21 *
22 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
23 * endorse or promote products derived from this software without
24 * prior written permission. For written permission, please contact
25 * licensing@OpenSSL.org.
26 *
27 * 5. Products derived from this software may not be called "OpenSSL"
28 * nor may "OpenSSL" appear in their names without prior written
29 * permission of the OpenSSL Project.
30 *
31 * 6. Redistributions of any form whatsoever must retain the following
32 * acknowledgment:
33 * "This product includes software developed by the OpenSSL Project
34 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
35 *
36 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
37 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
38 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
39 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
40 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
42 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
43 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
44 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
45 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
46 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
47 * OF THE POSSIBILITY OF SUCH DAMAGE.
48 * ====================================================================
49 *
50 * This product includes cryptographic software written by Eric Young
51 * (eay@cryptsoft.com). This product includes software written by Tim
52 * Hudson (tjh@cryptsoft.com).
53 *
54 */
55
56#include <openssl/crypto.h>
57#include <openssl/opensslconf.h>
58
59#if defined(__OpenBSD__) || (defined(__FreeBSD__) && __FreeBSD__ > 2)
60
61#include OPENSSL_UNISTD
62
63int OPENSSL_issetugid(void)
64 {
65 return issetugid();
66 }
67
68#elif defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_VXWORKS)
69
70int OPENSSL_issetugid(void)
71 {
72 return 0;
73 }
74
75#else
76
77#include OPENSSL_UNISTD
78#include <sys/types.h>
79
80int OPENSSL_issetugid(void)
81 {
82 if (getuid() != geteuid()) return 1;
83 if (getgid() != getegid()) return 1;
84 return 0;
85 }
86#endif
87
88
89
diff --git a/src/lib/libcrypto/util/FreeBSD.sh b/src/lib/libcrypto/util/FreeBSD.sh
new file mode 100644
index 0000000000..db8edfc6aa
--- /dev/null
+++ b/src/lib/libcrypto/util/FreeBSD.sh
@@ -0,0 +1,6 @@
1#!/bin/sh
2
3perl util/perlpath.pl /usr/bin
4perl util/ssldir.pl /usr/local
5perl util/mk1mf.pl FreeBSD >Makefile.FreeBSD
6perl Configure FreeBSD
diff --git a/src/lib/libcrypto/util/add_cr.pl b/src/lib/libcrypto/util/add_cr.pl
new file mode 100644
index 0000000000..c7b62c11ec
--- /dev/null
+++ b/src/lib/libcrypto/util/add_cr.pl
@@ -0,0 +1,123 @@
1#!/usr/local/bin/perl
2#
3# This adds a copyright message to a souce code file.
4# It also gets the file name correct.
5#
6# perl util/add_cr.pl *.[ch] */*.[ch] */*/*.[ch]
7#
8
9foreach (@ARGV)
10 {
11 &dofile($_);
12 }
13
14sub dofile
15 {
16 local($file)=@_;
17
18 open(IN,"<$file") || die "unable to open $file:$!\n";
19
20 print STDERR "doing $file\n";
21 @in=<IN>;
22
23 return(1) if ($in[0] =~ / NOCW /);
24
25 @out=();
26 open(OUT,">$file.out") || die "unable to open $file.$$:$!\n";
27 push(@out,"/* $file */\n");
28 if (($in[1] !~ /^\/\* Copyright \(C\) [0-9-]+ Eric Young \(eay\@cryptsoft.com\)/))
29 {
30 push(@out,&Copyright);
31 $i=2;
32 @a=grep(/ Copyright \(C\) /,@in);
33 if ($#a >= 0)
34 {
35 while (($i <= $#in) && ($in[$i] ne " */\n"))
36 { $i++; }
37 $i++ if ($in[$i] eq " */\n");
38
39 while (($i <= $#in) && ($in[$i] =~ /^\s*$/))
40 { $i++; }
41
42 push(@out,"\n");
43 for ( ; $i <= $#in; $i++)
44 { push(@out,$in[$i]); }
45 }
46 else
47 { push(@out,@in); }
48 }
49 else
50 {
51 shift(@in);
52 push(@out,@in);
53 }
54 print OUT @out;
55 close(IN);
56 close(OUT);
57 rename("$file","$file.orig") || die "unable to rename $file:$!\n";
58 rename("$file.out",$file) || die "unable to rename $file.out:$!\n";
59 }
60
61
62
63sub Copyright
64 {
65 return <<'EOF';
66/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
67 * All rights reserved.
68 *
69 * This package is an SSL implementation written
70 * by Eric Young (eay@cryptsoft.com).
71 * The implementation was written so as to conform with Netscapes SSL.
72 *
73 * This library is free for commercial and non-commercial use as long as
74 * the following conditions are aheared to. The following conditions
75 * apply to all code found in this distribution, be it the RC4, RSA,
76 * lhash, DES, etc., code; not just the SSL code. The SSL documentation
77 * included with this distribution is covered by the same copyright terms
78 * except that the holder is Tim Hudson (tjh@cryptsoft.com).
79 *
80 * Copyright remains Eric Young's, and as such any Copyright notices in
81 * the code are not to be removed.
82 * If this package is used in a product, Eric Young should be given attribution
83 * as the author of the parts of the library used.
84 * This can be in the form of a textual message at program startup or
85 * in documentation (online or textual) provided with the package.
86 *
87 * Redistribution and use in source and binary forms, with or without
88 * modification, are permitted provided that the following conditions
89 * are met:
90 * 1. Redistributions of source code must retain the copyright
91 * notice, this list of conditions and the following disclaimer.
92 * 2. Redistributions in binary form must reproduce the above copyright
93 * notice, this list of conditions and the following disclaimer in the
94 * documentation and/or other materials provided with the distribution.
95 * 3. All advertising materials mentioning features or use of this software
96 * must display the following acknowledgement:
97 * "This product includes cryptographic software written by
98 * Eric Young (eay@cryptsoft.com)"
99 * The word 'cryptographic' can be left out if the rouines from the library
100 * being used are not cryptographic related :-).
101 * 4. If you include any Windows specific code (or a derivative thereof) from
102 * the apps directory (application code) you must include an acknowledgement:
103 * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
104 *
105 * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
106 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
107 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
108 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
109 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
110 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
111 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
112 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
113 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
114 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
115 * SUCH DAMAGE.
116 *
117 * The licence and distribution terms for any publically available version or
118 * derivative of this code cannot be changed. i.e. this code cannot simply be
119 * copied and put under another distribution licence
120 * [including the GNU Public Licence.]
121 */
122EOF
123 }
diff --git a/src/lib/libcrypto/util/bat.sh b/src/lib/libcrypto/util/bat.sh
new file mode 100644
index 0000000000..4d9a8287d0
--- /dev/null
+++ b/src/lib/libcrypto/util/bat.sh
@@ -0,0 +1,134 @@
1#!/usr/local/bin/perl
2
3$infile="/home/eay/ssl/SSLeay/MINFO";
4
5open(IN,"<$infile") || die "unable to open $infile:$!\n";
6$_=<IN>;
7for (;;)
8 {
9 chop;
10
11 ($key,$val)=/^([^=]+)=(.*)/;
12 if ($key eq "RELATIVE_DIRECTORY")
13 {
14 if ($lib ne "")
15 {
16 $uc=$lib;
17 $uc =~ s/^lib(.*)\.a/$1/;
18 $uc =~ tr/a-z/A-Z/;
19 $lib_nam{$uc}=$uc;
20 $lib_obj{$uc}.=$libobj." ";
21 }
22 last if ($val eq "FINISHED");
23 $lib="";
24 $libobj="";
25 $dir=$val;
26 }
27
28 if ($key eq "TEST")
29 { $test.=&var_add($dir,$val); }
30
31 if (($key eq "PROGS") || ($key eq "E_OBJ"))
32 { $e_exe.=&var_add($dir,$val); }
33
34 if ($key eq "LIB")
35 {
36 $lib=$val;
37 $lib =~ s/^.*\/([^\/]+)$/$1/;
38 }
39
40 if ($key eq "EXHEADER")
41 { $exheader.=&var_add($dir,$val); }
42
43 if ($key eq "HEADER")
44 { $header.=&var_add($dir,$val); }
45
46 if ($key eq "LIBSRC")
47 { $libsrc.=&var_add($dir,$val); }
48
49 if (!($_=<IN>))
50 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
51 }
52close(IN);
53
54@a=split(/\s+/,$libsrc);
55foreach (@a)
56 {
57 print "${_}.c\n";
58 }
59
60sub var_add
61 {
62 local($dir,$val)=@_;
63 local(@a,$_,$ret);
64
65 return("") if $no_engine && $dir =~ /\/engine/;
66 return("") if $no_idea && $dir =~ /\/idea/;
67 return("") if $no_rc2 && $dir =~ /\/rc2/;
68 return("") if $no_rc4 && $dir =~ /\/rc4/;
69 return("") if $no_rsa && $dir =~ /\/rsa/;
70 return("") if $no_rsa && $dir =~ /^rsaref/;
71 return("") if $no_dsa && $dir =~ /\/dsa/;
72 return("") if $no_dh && $dir =~ /\/dh/;
73 if ($no_des && $dir =~ /\/des/)
74 {
75 if ($val =~ /read_pwd/)
76 { return("$dir/read_pwd "); }
77 else
78 { return(""); }
79 }
80 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
81 return("") if $no_sock && $dir =~ /\/proxy/;
82 return("") if $no_bf && $dir =~ /\/bf/;
83 return("") if $no_cast && $dir =~ /\/cast/;
84
85 $val =~ s/^\s*(.*)\s*$/$1/;
86 @a=split(/\s+/,$val);
87 grep(s/\.[och]$//,@a);
88
89 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
90 @a=grep(!/^e_.*_d$/,@a) if $no_des;
91 @a=grep(!/^e_.*_i$/,@a) if $no_idea;
92 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
93 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
94 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
95 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
96
97 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
98 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
99
100 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
101
102 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
103 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
104
105 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
106 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
107 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
108
109 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
110 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
111
112 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
113
114 @a=grep(!/_dhp$/,@a) if $no_dh;
115
116 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
117 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
118 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
119
120 @a=grep(!/^engine$/,@a) if $no_engine;
121 @a=grep(!/(^rsa$)|(^genrsa$)|(^req$)|(^ca$)/,@a) if $no_rsa;
122 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
123 @a=grep(!/^gendsa$/,@a) if $no_sha1;
124 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
125
126 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
127
128 grep($_="$dir/$_",@a);
129 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
130 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
131 $ret=join(' ',@a)." ";
132 return($ret);
133 }
134
diff --git a/src/lib/libcrypto/util/checkhash.pl b/src/lib/libcrypto/util/checkhash.pl
new file mode 100644
index 0000000000..c61fa72178
--- /dev/null
+++ b/src/lib/libcrypto/util/checkhash.pl
@@ -0,0 +1,222 @@
1#!/usr/bin/env perl -w
2
3my $package = caller;
4
5if (!(defined $package))
6 {
7 my $retval = check_hashes(@ARGV);
8 exit $retval;
9 }
10
111;
12
13sub check_hashes
14 {
15
16 my @args = @_;
17
18 my $change_dir = "";
19 my $check_program = "sha/fips_standalone_sha1";
20
21 my $verbose = 0;
22 my $badfiles = 0;
23 my $rebuild = 0;
24 my $force_rewrite = 0;
25 my $hash_file = "fipshashes.c";
26 my $recurse = 0;
27
28 my @fingerprint_files;
29
30 while (@args)
31 {
32 my $arg = $args[0];
33 if ($arg eq "-chdir")
34 {
35 shift @args;
36 $change_dir = shift @args;
37 }
38 elsif ($arg eq "-rebuild")
39 {
40 shift @args;
41 $rebuild = 1;
42 }
43 elsif ($arg eq "-verbose")
44 {
45 shift @args;
46 $verbose = 1;
47 }
48 elsif ($arg eq "-force-rewrite")
49 {
50 shift @args;
51 $force_rewrite = 1;
52 }
53 elsif ($arg eq "-hash_file")
54 {
55 shift @args;
56 $hash_file = shift @args;
57 }
58 elsif ($arg eq "-recurse")
59 {
60 shift @args;
61 $recurse = 1;
62 }
63 elsif ($arg eq "-program_path")
64 {
65 shift @args;
66 $check_program = shift @args;
67 }
68 else
69 {
70 print STDERR "Unknown Option $arg";
71 return 1;
72 }
73
74 }
75
76 chdir $change_dir if $change_dir ne "";
77
78 if ($recurse)
79 {
80 @fingerprint_files = ("fingerprint.sha1",
81 <*/fingerprint.sha1>);
82 }
83 else
84 {
85 push @fingerprint_files, $hash_file;
86 }
87
88 foreach $fp (@fingerprint_files)
89 {
90 if (!open(IN, "$fp"))
91 {
92 print STDERR "Can't open file $fp";
93 return 1;
94 }
95 print STDERR "Opening Fingerprint file $fp\n" if $verbose;
96 my $dir = $fp;
97 $dir =~ s/[^\/]*$//;
98 while (<IN>)
99 {
100 chomp;
101 if (!(($file, $hash) = /^\"HMAC-SHA1\((.*)\)\s*=\s*(\w*)\",$/))
102 {
103 /^\"/ || next;
104 print STDERR "FATAL: Invalid syntax in file $fp\n";
105 print STDERR "Line:\n$_\n";
106 fatal_error();
107 return 1;
108 }
109 if (!$rebuild && length($hash) != 40)
110 {
111 print STDERR "FATAL: Invalid hash length in $fp for file $file\n";
112 fatal_error();
113 return 1;
114 }
115 push @hashed_files, "$dir$file";
116 if (exists $hashes{"$dir$file"})
117 {
118 print STDERR "FATAL: Duplicate Hash file $dir$file\n";
119 fatal_error();
120 return 1;
121 }
122 if (! -r "$dir$file")
123 {
124 print STDERR "FATAL: Can't access $dir$file\n";
125 fatal_error();
126 return 1;
127 }
128 $hashes{"$dir$file"} = $hash;
129 }
130 close IN;
131 }
132
133 @checked_hashes = `$check_program @hashed_files`;
134
135 if ($? != 0)
136 {
137 print STDERR "Error running hash program $check_program\n";
138 fatal_error();
139 return 1;
140 }
141
142 if (@checked_hashes != @hashed_files)
143 {
144 print STDERR "FATAL: hash count incorrect\n";
145 fatal_error();
146 return 1;
147 }
148
149 foreach (@checked_hashes)
150 {
151 chomp;
152 if (!(($file, $hash) = /^HMAC-SHA1\((.*)\)\s*=\s*(\w*)$/))
153 {
154 print STDERR "FATAL: Invalid syntax in file $fp\n";
155 print STDERR "Line:\n$_\n";
156 fatal_error();
157 return 1;
158 }
159 if (length($hash) != 40)
160 {
161 print STDERR "FATAL: Invalid hash length for file $file\n";
162 fatal_error();
163 return 1;
164 }
165 if ($hash ne $hashes{$file})
166 {
167 if ($rebuild)
168 {
169 print STDERR "Updating hash on file $file\n";
170 $hashes{$file} = $hash;
171 }
172 else
173 {
174 print STDERR "Hash check failed for file $file\n";
175 }
176 $badfiles++;
177 }
178 elsif ($verbose)
179 { print "Hash Check OK for $file\n";}
180 }
181
182
183 if ($badfiles && !$rebuild)
184 {
185 print STDERR "FATAL: hash mismatch on $badfiles files\n";
186 fatal_error();
187 return 1;
188 }
189
190 if ($badfiles || $force_rewrite)
191 {
192 print "Updating Hash file $hash_file\n";
193 if (!open(OUT, ">$hash_file"))
194 {
195 print STDERR "Error rewriting $hash_file";
196 return 1;
197 }
198 print OUT "const char * const FIPS_source_hashes[] = {\n";
199 foreach (@hashed_files)
200 {
201 print OUT "\"HMAC-SHA1($_)= $hashes{$_}\",\n";
202 }
203 print OUT "};\n";
204 close OUT;
205 }
206
207 if (!$badfiles)
208 {
209 print "FIPS hash check successful\n";
210 }
211
212 return 0;
213
214 }
215
216
217sub fatal_error
218 {
219 print STDERR "*** Your source code does not match the FIPS validated source ***\n";
220 }
221
222
diff --git a/src/lib/libcrypto/util/ck_errf.pl b/src/lib/libcrypto/util/ck_errf.pl
new file mode 100644
index 0000000000..7a24d6c5a2
--- /dev/null
+++ b/src/lib/libcrypto/util/ck_errf.pl
@@ -0,0 +1,45 @@
1#!/usr/local/bin/perl
2#
3# This is just a quick script to scan for cases where the 'error'
4# function name in a XXXerr() macro is wrong.
5#
6# Run in the top level by going
7# perl util/ck_errf.pl */*.c */*/*.c
8#
9
10foreach $file (@ARGV)
11 {
12 open(IN,"<$file") || die "unable to open $file\n";
13 $func="";
14 while (<IN>)
15 {
16 if (/^[a-zA-Z].+[\s*]([A-Za-z_0-9]+)\(.*\)/)
17 {
18 $func=$1;
19 $func =~ tr/A-Z/a-z/;
20 }
21 if (/([A-Z0-9]+)err\(([^,]+)/)
22 {
23 next if ($func eq "");
24 $errlib=$1;
25 $n=$2;
26 if ($n !~ /([^_]+)_F_(.+)$/)
27 {
28 # print "check -$file:$.:$func:$n\n";
29 next;
30 }
31 $lib=$1;
32 $n=$2;
33
34 if ($lib ne $errlib)
35 { print "$file:$.:$func:$n\n"; next; }
36
37 $n =~ tr/A-Z/a-z/;
38 if (($n ne $func) && ($errlib ne "SYS"))
39 { print "$file:$.:$func:$n\n"; next; }
40 # print "$func:$1\n";
41 }
42 }
43 close(IN);
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..6c485d1e2f
--- /dev/null
+++ b/src/lib/libcrypto/util/clean-depend.pl
@@ -0,0 +1,54 @@
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
14my $thisfile="";
15while(<STDIN>) {
16 my ($dummy, $file,$deps)=/^((.*):)? (.*)$/;
17 my $origfile="";
18 $thisfile=$file if defined $file;
19 next if !defined $deps;
20 $origfile=$thisfile;
21 $origfile=~s/\.o$/.c/;
22 my @deps=split ' ',$deps;
23 @deps=grep(!/^\//,@deps);
24 @deps=grep(!/^\\$/,@deps);
25 @deps=grep(!/^$origfile$/,@deps);
26# pull out the kludged kerberos header (if present).
27 @deps=grep(!/^[.\/]+\/krb5.h/,@deps);
28 push @{$files{$thisfile}},@deps;
29}
30
31my $file;
32foreach $file (sort keys %files) {
33 my $len=0;
34 my $dep;
35 my $origfile=$file;
36 $origfile=~s/\.o$/.c/;
37 $file=~s/^\.\///;
38 push @{$files{$file}},$origfile;
39 my $prevdep="";
40 foreach $dep (sort @{$files{$file}}) {
41 $dep=~s/^\.\///;
42 next if $prevdep eq $dep; # to exterminate duplicates...
43 $prevdep = $dep;
44 $len=0 if $len+length($dep)+1 >= 80;
45 if($len == 0) {
46 print "\n$file:";
47 $len=length($file)+1;
48 }
49 print " $dep";
50 $len+=length($dep)+1;
51 }
52}
53
54print "\n";
diff --git a/src/lib/libcrypto/util/copy.pl b/src/lib/libcrypto/util/copy.pl
new file mode 100644
index 0000000000..e20b45530a
--- /dev/null
+++ b/src/lib/libcrypto/util/copy.pl
@@ -0,0 +1,59 @@
1#!/usr/local/bin/perl
2
3use Fcntl;
4
5
6# copy.pl
7
8# Perl script 'copy' comment. On Windows the built in "copy" command also
9# copies timestamps: this messes up Makefile dependencies.
10
11my $arg;
12
13foreach $arg (@ARGV) {
14 $arg =~ s|\\|/|g; # compensate for bug/feature in cygwin glob...
15 foreach (glob $arg)
16 {
17 push @filelist, $_;
18 }
19}
20
21$fnum = @filelist;
22
23if ($fnum <= 1)
24 {
25 die "Need at least two filenames";
26 }
27
28$dest = pop @filelist;
29
30if ($fnum > 2 && ! -d $dest)
31 {
32 die "Destination must be a directory";
33 }
34
35foreach (@filelist)
36 {
37 if (-d $dest)
38 {
39 $dfile = $_;
40 $dfile =~ s|^.*[/\\]([^/\\]*)$|$1|;
41 $dfile = "$dest/$dfile";
42 }
43 else
44 {
45 $dfile = $dest;
46 }
47 sysopen(IN, $_, O_RDONLY|O_BINARY) || die "Can't Open $_";
48 sysopen(OUT, $dfile, O_WRONLY|O_CREAT|O_TRUNC|O_BINARY)
49 || die "Can't Open $dfile";
50 while (sysread IN, $buf, 10240)
51 {
52 syswrite(OUT, $buf, length($buf));
53 }
54 close(IN);
55 close(OUT);
56 print "Copying: $_ to $dfile\n";
57 }
58
59
diff --git a/src/lib/libcrypto/util/cygwin.sh b/src/lib/libcrypto/util/cygwin.sh
new file mode 100644
index 0000000000..7f791d47f4
--- /dev/null
+++ b/src/lib/libcrypto/util/cygwin.sh
@@ -0,0 +1,127 @@
1#!/bin/bash
2#
3# This script configures, builds and packs the binary package for
4# the Cygwin net distribution version of OpenSSL
5#
6
7# Uncomment when debugging
8#set -x
9
10CONFIG_OPTIONS="--prefix=/usr shared no-idea no-rc5 no-mdc2"
11INSTALL_PREFIX=/tmp/install
12
13VERSION=
14SUBVERSION=$1
15
16function cleanup()
17{
18 rm -rf ${INSTALL_PREFIX}/etc
19 rm -rf ${INSTALL_PREFIX}/usr
20}
21
22function get_openssl_version()
23{
24 eval `grep '^VERSION=' Makefile`
25 if [ -z "${VERSION}" ]
26 then
27 echo "Error: Couldn't retrieve OpenSSL version from Makefile."
28 echo " Check value of variable VERSION in Makefile."
29 exit 1
30 fi
31}
32
33function base_install()
34{
35 mkdir -p ${INSTALL_PREFIX}
36 cleanup
37 make install INSTALL_PREFIX="${INSTALL_PREFIX}"
38}
39
40function doc_install()
41{
42 DOC_DIR=${INSTALL_PREFIX}/usr/share/doc/openssl
43
44 mkdir -p ${DOC_DIR}
45 cp CHANGES CHANGES.SSLeay INSTALL LICENSE NEWS README ${DOC_DIR}
46
47 create_cygwin_readme
48}
49
50function create_cygwin_readme()
51{
52 README_DIR=${INSTALL_PREFIX}/usr/share/doc/Cygwin
53 README_FILE=${README_DIR}/openssl-${VERSION}.README
54
55 mkdir -p ${README_DIR}
56 cat > ${README_FILE} <<- EOF
57 The Cygwin version has been built using the following configure:
58
59 ./config ${CONFIG_OPTIONS}
60
61 The IDEA, RC5 and MDC2 algorithms are disabled due to patent and/or
62 licensing issues.
63 EOF
64}
65
66function create_profile_files()
67{
68 PROFILE_DIR=${INSTALL_PREFIX}/etc/profile.d
69
70 mkdir -p $PROFILE_DIR
71 cat > ${PROFILE_DIR}/openssl.sh <<- "EOF"
72 export MANPATH="${MANPATH}:/usr/ssl/man"
73 EOF
74 cat > ${PROFILE_DIR}/openssl.csh <<- "EOF"
75 if ( $?MANPATH ) then
76 setenv MANPATH "${MANPATH}:/usr/ssl/man"
77 else
78 setenv MANPATH ":/usr/ssl/man"
79 endif
80 EOF
81}
82
83if [ -z "${SUBVERSION}" ]
84then
85 echo "Usage: $0 subversion"
86 exit 1
87fi
88
89if [ ! -f config ]
90then
91 echo "You must start this script in the OpenSSL toplevel source dir."
92 exit 1
93fi
94
95./config ${CONFIG_OPTIONS}
96
97get_openssl_version
98
99make depend || exit 1
100
101make || exit 1
102
103base_install
104
105doc_install
106
107create_cygwin_readme
108
109create_profile_files
110
111cd ${INSTALL_PREFIX}
112strip usr/bin/*.exe usr/bin/*.dll
113
114# Runtime package
115find etc usr/bin usr/share/doc usr/ssl/certs usr/ssl/man/man[157] \
116 usr/ssl/misc usr/ssl/openssl.cnf usr/ssl/private -empty -o \! -type d |
117tar cjfT openssl-${VERSION}-${SUBVERSION}.tar.bz2 -
118# Development package
119find usr/include usr/lib usr/ssl/man/man3 -empty -o \! -type d |
120tar cjfT openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2 -
121
122ls -l openssl-${VERSION}-${SUBVERSION}.tar.bz2
123ls -l openssl-devel-${VERSION}-${SUBVERSION}.tar.bz2
124
125cleanup
126
127exit 0
diff --git a/src/lib/libcrypto/util/deleof.pl b/src/lib/libcrypto/util/deleof.pl
new file mode 100644
index 0000000000..155acd88ff
--- /dev/null
+++ b/src/lib/libcrypto/util/deleof.pl
@@ -0,0 +1,7 @@
1#!/usr/local/bin/perl
2
3while (<>)
4 {
5 print
6 last if (/^# DO NOT DELETE THIS LINE/);
7 }
diff --git a/src/lib/libcrypto/util/dirname.pl b/src/lib/libcrypto/util/dirname.pl
new file mode 100644
index 0000000000..d7a66d96ac
--- /dev/null
+++ b/src/lib/libcrypto/util/dirname.pl
@@ -0,0 +1,18 @@
1#!/usr/local/bin/perl
2
3if ($#ARGV < 0) {
4 die "dirname.pl: too few arguments\n";
5} elsif ($#ARGV > 0) {
6 die "dirname.pl: too many arguments\n";
7}
8
9my $d = $ARGV[0];
10
11if ($d =~ m|.*/.*|) {
12 $d =~ s|/[^/]*$||;
13} else {
14 $d = ".";
15}
16
17print $d,"\n";
18exit(0);
diff --git a/src/lib/libcrypto/util/do_ms.sh b/src/lib/libcrypto/util/do_ms.sh
new file mode 100644
index 0000000000..515b074cff
--- /dev/null
+++ b/src/lib/libcrypto/util/do_ms.sh
@@ -0,0 +1,19 @@
1#!/bin/sh
2#
3# generate the Microsoft makefiles and .def files
4#
5
6PATH=util:../util:$PATH
7
8# perl util/mk1mf.pl no-sock VC-MSDOS >ms/msdos.mak
9# perl util/mk1mf.pl VC-W31-32 >ms/w31.mak
10perl util/mk1mf.pl dll VC-WIN16 >ms/w31dll.mak
11# perl util/mk1mf.pl VC-WIN32 >ms/nt.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
15
16perl util/mkdef.pl 16 libeay > ms/libeay16.def
17perl util/mkdef.pl 32 libeay > ms/libeay32.def
18perl util/mkdef.pl 16 ssleay > ms/ssleay16.def
19perl util/mkdef.pl 32 ssleay > ms/ssleay32.def
diff --git a/src/lib/libcrypto/util/domd b/src/lib/libcrypto/util/domd
new file mode 100644
index 0000000000..5610521f0b
--- /dev/null
+++ b/src/lib/libcrypto/util/domd
@@ -0,0 +1,34 @@
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
7if [ "$1" = "-MD" ]; then
8 shift
9 MAKEDEPEND=$1
10 shift
11fi
12if [ "$MAKEDEPEND" = "" ]; then MAKEDEPEND=makedepend; fi
13
14cp Makefile Makefile.save
15# fake the presence of Kerberos
16touch $TOP/krb5.h
17if [ "$MAKEDEPEND" = "gcc" ]; then
18 args=""
19 while [ $# -gt 0 ]; do
20 if [ "$1" != "--" ]; then args="$args $1"; fi
21 shift
22 done
23 sed -e '/^# DO NOT DELETE.*/,$d' < Makefile > Makefile.tmp
24 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' >> Makefile.tmp
25 gcc -D OPENSSL_DOING_MAKEDEPEND -M $args >> Makefile.tmp
26 ${PERL} $TOP/util/clean-depend.pl < Makefile.tmp > Makefile.new
27 rm -f Makefile.tmp
28else
29 ${MAKEDEPEND} -D OPENSSL_DOING_MAKEDEPEND -f Makefile $@
30 ${PERL} $TOP/util/clean-depend.pl < Makefile > Makefile.new
31fi
32mv Makefile.new Makefile
33# unfake the presence of Kerberos
34rm $TOP/krb5.h
diff --git a/src/lib/libcrypto/util/err-ins.pl b/src/lib/libcrypto/util/err-ins.pl
new file mode 100644
index 0000000000..31b70df8d0
--- /dev/null
+++ b/src/lib/libcrypto/util/err-ins.pl
@@ -0,0 +1,33 @@
1#!/usr/local/bin/perl
2#
3# tack error codes onto the end of a file
4#
5
6open(ERR,$ARGV[0]) || die "unable to open error file '$ARGV[0]':$!\n";
7@err=<ERR>;
8close(ERR);
9
10open(IN,$ARGV[1]) || die "unable to open header file '$ARGV[1]':$!\n";
11
12@out="";
13while (<IN>)
14 {
15 push(@out,$_);
16 last if /BEGIN ERROR CODES/;
17 }
18close(IN);
19
20open(OUT,">$ARGV[1]") || die "unable to open header file '$ARGV[1]':$1\n";
21print OUT @out;
22print OUT @err;
23print OUT <<"EOF";
24
25#ifdef __cplusplus
26}
27#endif
28#endif
29
30EOF
31close(OUT);
32
33
diff --git a/src/lib/libcrypto/util/extract-names.pl b/src/lib/libcrypto/util/extract-names.pl
new file mode 100644
index 0000000000..35bd6ed843
--- /dev/null
+++ b/src/lib/libcrypto/util/extract-names.pl
@@ -0,0 +1,26 @@
1#!/usr/bin/perl
2
3$/ = ""; # Eat a paragraph at once.
4while(<STDIN>) {
5 chop;
6 s/\n/ /gm;
7 if (/^=head1 /) {
8 $name = 0;
9 } elsif ($name) {
10 if (/ - /) {
11 s/ - .*//;
12 s/,\s+/,/g;
13 s/\s+,/,/g;
14 s/^\s+//g;
15 s/\s+$//g;
16 s/\s/_/g;
17 push @words, split ',';
18 }
19 }
20 if (/^=head1 *NAME *$/) {
21 $name = 1;
22 }
23}
24
25print join("\n", @words),"\n";
26
diff --git a/src/lib/libcrypto/util/extract-section.pl b/src/lib/libcrypto/util/extract-section.pl
new file mode 100644
index 0000000000..7a0ba4f69a
--- /dev/null
+++ b/src/lib/libcrypto/util/extract-section.pl
@@ -0,0 +1,12 @@
1#!/usr/bin/perl
2
3while(<STDIN>) {
4 if (/=for\s+comment\s+openssl_manual_section:(\S+)/)
5 {
6 print "$1\n";
7 exit 0;
8 }
9}
10
11print "$ARGV[0]\n";
12
diff --git a/src/lib/libcrypto/util/files.pl b/src/lib/libcrypto/util/files.pl
new file mode 100644
index 0000000000..41f033e3b9
--- /dev/null
+++ b/src/lib/libcrypto/util/files.pl
@@ -0,0 +1,61 @@
1#!/usr/local/bin/perl
2#
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
5#
6
7$s="";
8while (<>)
9 {
10 chop;
11 s/#.*//;
12 if (/^(\S+)\s*=\s*(.*)$/)
13 {
14 $o="";
15 ($s,$b)=($1,$2);
16 for (;;)
17 {
18 if ($b =~ /\\$/)
19 {
20 chop($b);
21 $o.=$b." ";
22 $b=<>;
23 chop($b);
24 }
25 else
26 {
27 $o.=$b." ";
28 last;
29 }
30 }
31 $o =~ s/^\s+//;
32 $o =~ s/\s+$//;
33 $o =~ s/\s+/ /g;
34
35 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
36 $sym{$s}=$o;
37 }
38 }
39
40$pwd=`pwd`; chop($pwd);
41
42if ($sym{'TOP'} eq ".")
43 {
44 $n=0;
45 $dir=".";
46 }
47else {
48 $n=split(/\//,$sym{'TOP'});
49 @_=split(/\//,$pwd);
50 $z=$#_-$n+1;
51 foreach $i ($z .. $#_) { $dir.=$_[$i]."/"; }
52 chop($dir);
53 }
54
55print "RELATIVE_DIRECTORY=$dir\n";
56
57foreach (sort keys %sym)
58 {
59 print "$_=$sym{$_}\n";
60 }
61print "RELATIVE_DIRECTORY=\n";
diff --git a/src/lib/libcrypto/util/fipslink.pl b/src/lib/libcrypto/util/fipslink.pl
new file mode 100644
index 0000000000..a893833c5c
--- /dev/null
+++ b/src/lib/libcrypto/util/fipslink.pl
@@ -0,0 +1,78 @@
1#!/usr/bin/perl
2
3sub check_env
4 {
5 my @ret;
6 foreach (@_)
7 {
8 die "Environment variable $_ not defined!\n" unless exists $ENV{$_};
9 push @ret, $ENV{$_};
10 }
11 return @ret;
12 }
13
14
15my ($fips_cc,$fips_cc_args, $fips_link,$fips_target, $fips_libdir, $sha1_exe)
16 = check_env("FIPS_CC", "FIPS_CC_ARGS", "FIPS_LINK", "FIPS_TARGET",
17 "FIPSLIB_D", "FIPS_SHA1_EXE");
18
19
20
21if (exists $ENV{"PREMAIN_DSO_EXE"})
22 {
23 $fips_premain_dso = $ENV{"PREMAIN_DSO_EXE"};
24 }
25 else
26 {
27 $fips_premain_dso = "";
28 }
29
30check_hash($sha1_exe, "fips_premain.c");
31check_hash($sha1_exe, "fipscanister.o");
32
33
34print "Integrity check OK\n";
35
36print "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c\n";
37system "$fips_cc $fips_cc_args $fips_libdir/fips_premain.c";
38die "First stage Compile failure" if $? != 0;
39
40print "$fips_link @ARGV\n";
41system "$fips_link @ARGV";
42die "First stage Link failure" if $? != 0;
43
44
45print "$fips_premain_dso $fips_target\n";
46$fips_hash=`$fips_premain_dso $fips_target`;
47chomp $fips_hash;
48die "Get hash failure" if $? != 0;
49
50
51print "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c\n";
52system "$fips_cc -DHMAC_SHA1_SIG=\\\"$fips_hash\\\" $fips_cc_args $fips_libdir/fips_premain.c";
53die "Second stage Compile failure" if $? != 0;
54
55
56print "$fips_link @ARGV\n";
57system "$fips_link @ARGV";
58die "Second stage Link failure" if $? != 0;
59
60sub check_hash
61 {
62 my ($sha1_exe, $filename) = @_;
63 my ($hashfile, $hashval);
64
65 open(IN, "${fips_libdir}/${filename}.sha1") || die "Cannot open file hash file ${fips_libdir}/${filename}.sha1";
66 $hashfile = <IN>;
67 close IN;
68 $hashval = `$sha1_exe ${fips_libdir}/$filename`;
69 chomp $hashfile;
70 chomp $hashval;
71 $hashfile =~ s/^.*=\s+//;
72 $hashval =~ s/^.*=\s+//;
73 die "Invalid hash syntax in file" if (length($hashfile) != 40);
74 die "Invalid hash received for file" if (length($hashval) != 40);
75 die "***HASH VALUE MISMATCH FOR FILE $filename ***" if ($hashval ne $hashfile);
76 }
77
78
diff --git a/src/lib/libcrypto/util/fixNT.sh b/src/lib/libcrypto/util/fixNT.sh
new file mode 100644
index 0000000000..ab9e766b86
--- /dev/null
+++ b/src/lib/libcrypto/util/fixNT.sh
@@ -0,0 +1,14 @@
1#!/bin/sh
2#
3# clean up the mess that NT makes of my source tree
4#
5
6if [ -f makefile -a ! -f Makefile ]; then
7 /bin/mv makefile Makefile
8fi
9chmod +x Configure util/*
10echo cleaning
11/bin/rm -f `find . -name '*.$$$' -print` 2>/dev/null >/dev/null
12echo 'removing those damn ^M'
13perl -pi -e 's/\015//' `find . -type 'f' -print |grep -v '.obj$' |grep -v '.der$' |grep -v '.gz'`
14make -f Makefile links
diff --git a/src/lib/libcrypto/util/install.sh b/src/lib/libcrypto/util/install.sh
new file mode 100644
index 0000000000..e1d0c982df
--- /dev/null
+++ b/src/lib/libcrypto/util/install.sh
@@ -0,0 +1,108 @@
1#!/bin/sh
2#
3# install - install a program, script, or datafile
4# This comes from X11R5; it is not part of GNU.
5#
6# $XConsortium: install.sh,v 1.2 89/12/18 14:47:22 jim Exp $
7#
8# This script is compatible with the BSD install script, but was written
9# from scratch.
10#
11
12
13# set DOITPROG to echo to test this script
14
15doit="${DOITPROG:-}"
16
17
18# put in absolute paths if you don't have them in your path; or use env. vars.
19
20mvprog="${MVPROG:-mv}"
21cpprog="${CPPROG:-cp}"
22chmodprog="${CHMODPROG:-chmod}"
23chownprog="${CHOWNPROG:-chown}"
24chgrpprog="${CHGRPPROG:-chgrp}"
25stripprog="${STRIPPROG:-strip}"
26rmprog="${RMPROG:-rm}"
27
28instcmd="$mvprog"
29chmodcmd=""
30chowncmd=""
31chgrpcmd=""
32stripcmd=""
33rmcmd="$rmprog -f"
34src=""
35dst=""
36
37while [ x"$1" != x ]; do
38 case $1 in
39 -c) instcmd="$cpprog"
40 shift
41 continue;;
42
43 -m) chmodcmd="$chmodprog $2"
44 shift
45 shift
46 continue;;
47
48 -o) chowncmd="$chownprog $2"
49 shift
50 shift
51 continue;;
52
53 -g) chgrpcmd="$chgrpprog $2"
54 shift
55 shift
56 continue;;
57
58 -s) stripcmd="$stripprog"
59 shift
60 continue;;
61
62 *) if [ x"$src" = x ]
63 then
64 src=$1
65 else
66 dst=$1
67 fi
68 shift
69 continue;;
70 esac
71done
72
73if [ x"$src" = x ]
74then
75 echo "install: no input file specified"
76 exit 1
77fi
78
79if [ x"$dst" = x ]
80then
81 echo "install: no destination specified"
82 exit 1
83fi
84
85
86# if destination is a directory, append the input filename; if your system
87# does not like double slashes in filenames, you may need to add some logic
88
89if [ -d $dst ]
90then
91 dst="$dst"/`basename $src`
92fi
93
94
95# get rid of the old one and mode the new one in
96
97$doit $rmcmd $dst
98$doit $instcmd $src $dst
99
100
101# and set any options; do chmod last to preserve setuid bits
102
103if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; fi
104if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; fi
105if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; fi
106if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; fi
107
108exit 0
diff --git a/src/lib/libcrypto/util/libeay.num b/src/lib/libcrypto/util/libeay.num
new file mode 100644
index 0000000000..4222bef6d6
--- /dev/null
+++ b/src/lib/libcrypto/util/libeay.num
@@ -0,0 +1,2907 @@
1SSLeay 1 EXIST::FUNCTION:
2SSLeay_version 2 EXIST::FUNCTION:
3ASN1_BIT_STRING_asn1_meth 3 EXIST::FUNCTION:
4ASN1_HEADER_free 4 EXIST::FUNCTION:
5ASN1_HEADER_new 5 EXIST::FUNCTION:
6ASN1_IA5STRING_asn1_meth 6 EXIST::FUNCTION:
7ASN1_INTEGER_get 7 EXIST::FUNCTION:
8ASN1_INTEGER_set 8 EXIST::FUNCTION:
9ASN1_INTEGER_to_BN 9 EXIST::FUNCTION:
10ASN1_OBJECT_create 10 EXIST::FUNCTION:
11ASN1_OBJECT_free 11 EXIST::FUNCTION:
12ASN1_OBJECT_new 12 EXIST::FUNCTION:
13ASN1_PRINTABLE_type 13 EXIST::FUNCTION:
14ASN1_STRING_cmp 14 EXIST::FUNCTION:
15ASN1_STRING_dup 15 EXIST::FUNCTION:
16ASN1_STRING_free 16 EXIST::FUNCTION:
17ASN1_STRING_new 17 EXIST::FUNCTION:
18ASN1_STRING_print 18 EXIST::FUNCTION:BIO
19ASN1_STRING_set 19 EXIST::FUNCTION:
20ASN1_STRING_type_new 20 EXIST::FUNCTION:
21ASN1_TYPE_free 21 EXIST::FUNCTION:
22ASN1_TYPE_new 22 EXIST::FUNCTION:
23ASN1_UNIVERSALSTRING_to_string 23 EXIST::FUNCTION:
24ASN1_UTCTIME_check 24 EXIST::FUNCTION:
25ASN1_UTCTIME_print 25 EXIST::FUNCTION:BIO
26ASN1_UTCTIME_set 26 EXIST::FUNCTION:
27ASN1_check_infinite_end 27 EXIST::FUNCTION:
28ASN1_d2i_bio 28 EXIST::FUNCTION:BIO
29ASN1_d2i_fp 29 EXIST::FUNCTION:FP_API
30ASN1_digest 30 EXIST::FUNCTION:EVP
31ASN1_dup 31 EXIST::FUNCTION:
32ASN1_get_object 32 EXIST::FUNCTION:
33ASN1_i2d_bio 33 EXIST::FUNCTION:BIO
34ASN1_i2d_fp 34 EXIST::FUNCTION:FP_API
35ASN1_object_size 35 EXIST::FUNCTION:
36ASN1_parse 36 EXIST::FUNCTION:BIO
37ASN1_put_object 37 EXIST::FUNCTION:
38ASN1_sign 38 EXIST::FUNCTION:EVP
39ASN1_verify 39 EXIST::FUNCTION:EVP
40BF_cbc_encrypt 40 EXIST::FUNCTION:BF
41BF_cfb64_encrypt 41 EXIST::FUNCTION:BF
42BF_ecb_encrypt 42 EXIST::FUNCTION:BF
43BF_encrypt 43 EXIST::FUNCTION:BF
44BF_ofb64_encrypt 44 EXIST::FUNCTION:BF
45BF_options 45 EXIST::FUNCTION:BF
46BF_set_key 46 EXIST::FUNCTION:BF
47BIO_CONNECT_free 47 NOEXIST::FUNCTION:
48BIO_CONNECT_new 48 NOEXIST::FUNCTION:
49BIO_accept 51 EXIST::FUNCTION:
50BIO_ctrl 52 EXIST::FUNCTION:
51BIO_int_ctrl 53 EXIST::FUNCTION:
52BIO_debug_callback 54 EXIST::FUNCTION:
53BIO_dump 55 EXIST::FUNCTION:
54BIO_dup_chain 56 EXIST::FUNCTION:
55BIO_f_base64 57 EXIST::FUNCTION:BIO
56BIO_f_buffer 58 EXIST::FUNCTION:
57BIO_f_cipher 59 EXIST::FUNCTION:BIO
58BIO_f_md 60 EXIST::FUNCTION:BIO
59BIO_f_null 61 EXIST::FUNCTION:
60BIO_f_proxy_server 62 NOEXIST::FUNCTION:
61BIO_fd_non_fatal_error 63 EXIST::FUNCTION:
62BIO_fd_should_retry 64 EXIST::FUNCTION:
63BIO_find_type 65 EXIST::FUNCTION:
64BIO_free 66 EXIST::FUNCTION:
65BIO_free_all 67 EXIST::FUNCTION:
66BIO_get_accept_socket 69 EXIST::FUNCTION:
67BIO_get_filter_bio 70 NOEXIST::FUNCTION:
68BIO_get_host_ip 71 EXIST::FUNCTION:
69BIO_get_port 72 EXIST::FUNCTION:
70BIO_get_retry_BIO 73 EXIST::FUNCTION:
71BIO_get_retry_reason 74 EXIST::FUNCTION:
72BIO_gethostbyname 75 EXIST::FUNCTION:
73BIO_gets 76 EXIST::FUNCTION:
74BIO_new 78 EXIST::FUNCTION:
75BIO_new_accept 79 EXIST::FUNCTION:
76BIO_new_connect 80 EXIST::FUNCTION:
77BIO_new_fd 81 EXIST::FUNCTION:
78BIO_new_file 82 EXIST:!WIN16:FUNCTION:FP_API
79BIO_new_fp 83 EXIST:!WIN16:FUNCTION:FP_API
80BIO_new_socket 84 EXIST::FUNCTION:
81BIO_pop 85 EXIST::FUNCTION:
82BIO_printf 86 EXIST::FUNCTION:
83BIO_push 87 EXIST::FUNCTION:
84BIO_puts 88 EXIST::FUNCTION:
85BIO_read 89 EXIST::FUNCTION:
86BIO_s_accept 90 EXIST::FUNCTION:
87BIO_s_connect 91 EXIST::FUNCTION:
88BIO_s_fd 92 EXIST::FUNCTION:
89BIO_s_file 93 EXIST:!WIN16:FUNCTION:FP_API
90BIO_s_mem 95 EXIST::FUNCTION:
91BIO_s_null 96 EXIST::FUNCTION:
92BIO_s_proxy_client 97 NOEXIST::FUNCTION:
93BIO_s_socket 98 EXIST::FUNCTION:
94BIO_set 100 EXIST::FUNCTION:
95BIO_set_cipher 101 EXIST::FUNCTION:BIO
96BIO_set_tcp_ndelay 102 EXIST::FUNCTION:
97BIO_sock_cleanup 103 EXIST::FUNCTION:
98BIO_sock_error 104 EXIST::FUNCTION:
99BIO_sock_init 105 EXIST::FUNCTION:
100BIO_sock_non_fatal_error 106 EXIST::FUNCTION:
101BIO_sock_should_retry 107 EXIST::FUNCTION:
102BIO_socket_ioctl 108 EXIST::FUNCTION:
103BIO_write 109 EXIST::FUNCTION:
104BN_CTX_free 110 EXIST::FUNCTION:
105BN_CTX_new 111 EXIST::FUNCTION:
106BN_MONT_CTX_free 112 EXIST::FUNCTION:
107BN_MONT_CTX_new 113 EXIST::FUNCTION:
108BN_MONT_CTX_set 114 EXIST::FUNCTION:
109BN_add 115 EXIST::FUNCTION:
110BN_add_word 116 EXIST::FUNCTION:
111BN_hex2bn 117 EXIST::FUNCTION:
112BN_bin2bn 118 EXIST::FUNCTION:
113BN_bn2hex 119 EXIST::FUNCTION:
114BN_bn2bin 120 EXIST::FUNCTION:
115BN_clear 121 EXIST::FUNCTION:
116BN_clear_bit 122 EXIST::FUNCTION:
117BN_clear_free 123 EXIST::FUNCTION:
118BN_cmp 124 EXIST::FUNCTION:
119BN_copy 125 EXIST::FUNCTION:
120BN_div 126 EXIST::FUNCTION:
121BN_div_word 127 EXIST::FUNCTION:
122BN_dup 128 EXIST::FUNCTION:
123BN_free 129 EXIST::FUNCTION:
124BN_from_montgomery 130 EXIST::FUNCTION:
125BN_gcd 131 EXIST::FUNCTION:
126BN_generate_prime 132 EXIST::FUNCTION:
127BN_get_word 133 EXIST::FUNCTION:
128BN_is_bit_set 134 EXIST::FUNCTION:
129BN_is_prime 135 EXIST::FUNCTION:
130BN_lshift 136 EXIST::FUNCTION:
131BN_lshift1 137 EXIST::FUNCTION:
132BN_mask_bits 138 EXIST::FUNCTION:
133BN_mod 139 NOEXIST::FUNCTION:
134BN_mod_exp 140 EXIST::FUNCTION:
135BN_mod_exp_mont 141 EXIST::FUNCTION:
136BN_mod_exp_simple 143 EXIST::FUNCTION:
137BN_mod_inverse 144 EXIST::FUNCTION:
138BN_mod_mul 145 EXIST::FUNCTION:
139BN_mod_mul_montgomery 146 EXIST::FUNCTION:
140BN_mod_word 148 EXIST::FUNCTION:
141BN_mul 149 EXIST::FUNCTION:
142BN_new 150 EXIST::FUNCTION:
143BN_num_bits 151 EXIST::FUNCTION:
144BN_num_bits_word 152 EXIST::FUNCTION:
145BN_options 153 EXIST::FUNCTION:
146BN_print 154 EXIST::FUNCTION:
147BN_print_fp 155 EXIST::FUNCTION:FP_API
148BN_rand 156 EXIST::FUNCTION:
149BN_reciprocal 157 EXIST::FUNCTION:
150BN_rshift 158 EXIST::FUNCTION:
151BN_rshift1 159 EXIST::FUNCTION:
152BN_set_bit 160 EXIST::FUNCTION:
153BN_set_word 161 EXIST::FUNCTION:
154BN_sqr 162 EXIST::FUNCTION:
155BN_sub 163 EXIST::FUNCTION:
156BN_to_ASN1_INTEGER 164 EXIST::FUNCTION:
157BN_ucmp 165 EXIST::FUNCTION:
158BN_value_one 166 EXIST::FUNCTION:
159BUF_MEM_free 167 EXIST::FUNCTION:
160BUF_MEM_grow 168 EXIST::FUNCTION:
161BUF_MEM_new 169 EXIST::FUNCTION:
162BUF_strdup 170 EXIST::FUNCTION:
163CONF_free 171 EXIST::FUNCTION:
164CONF_get_number 172 EXIST::FUNCTION:
165CONF_get_section 173 EXIST::FUNCTION:
166CONF_get_string 174 EXIST::FUNCTION:
167CONF_load 175 EXIST::FUNCTION:
168CRYPTO_add_lock 176 EXIST::FUNCTION:
169CRYPTO_dbg_free 177 EXIST::FUNCTION:
170CRYPTO_dbg_malloc 178 EXIST::FUNCTION:
171CRYPTO_dbg_realloc 179 EXIST::FUNCTION:
172CRYPTO_dbg_remalloc 180 NOEXIST::FUNCTION:
173CRYPTO_free 181 EXIST::FUNCTION:
174CRYPTO_get_add_lock_callback 182 EXIST::FUNCTION:
175CRYPTO_get_id_callback 183 EXIST::FUNCTION:
176CRYPTO_get_lock_name 184 EXIST::FUNCTION:
177CRYPTO_get_locking_callback 185 EXIST::FUNCTION:
178CRYPTO_get_mem_functions 186 EXIST::FUNCTION:
179CRYPTO_lock 187 EXIST::FUNCTION:
180CRYPTO_malloc 188 EXIST::FUNCTION:
181CRYPTO_mem_ctrl 189 EXIST::FUNCTION:
182CRYPTO_mem_leaks 190 EXIST::FUNCTION:
183CRYPTO_mem_leaks_cb 191 EXIST::FUNCTION:
184CRYPTO_mem_leaks_fp 192 EXIST::FUNCTION:FP_API
185CRYPTO_realloc 193 EXIST::FUNCTION:
186CRYPTO_remalloc 194 EXIST::FUNCTION:
187CRYPTO_set_add_lock_callback 195 EXIST::FUNCTION:
188CRYPTO_set_id_callback 196 EXIST::FUNCTION:
189CRYPTO_set_locking_callback 197 EXIST::FUNCTION:
190CRYPTO_set_mem_functions 198 EXIST::FUNCTION:
191CRYPTO_thread_id 199 EXIST::FUNCTION:
192DH_check 200 EXIST::FUNCTION:DH
193DH_compute_key 201 EXIST::FUNCTION:DH
194DH_free 202 EXIST::FUNCTION:DH
195DH_generate_key 203 EXIST::FUNCTION:DH
196DH_generate_parameters 204 EXIST::FUNCTION:DH
197DH_new 205 EXIST::FUNCTION:DH
198DH_size 206 EXIST::FUNCTION:DH
199DHparams_print 207 EXIST::FUNCTION:BIO,DH
200DHparams_print_fp 208 EXIST::FUNCTION:DH,FP_API
201DSA_free 209 EXIST::FUNCTION:DSA
202DSA_generate_key 210 EXIST::FUNCTION:DSA
203DSA_generate_parameters 211 EXIST::FUNCTION:DSA
204DSA_is_prime 212 NOEXIST::FUNCTION:
205DSA_new 213 EXIST::FUNCTION:DSA
206DSA_print 214 EXIST::FUNCTION:BIO,DSA
207DSA_print_fp 215 EXIST::FUNCTION:DSA,FP_API
208DSA_sign 216 EXIST::FUNCTION:DSA
209DSA_sign_setup 217 EXIST::FUNCTION:DSA
210DSA_size 218 EXIST::FUNCTION:DSA
211DSA_verify 219 EXIST::FUNCTION:DSA
212DSAparams_print 220 EXIST::FUNCTION:BIO,DSA
213DSAparams_print_fp 221 EXIST::FUNCTION:DSA,FP_API
214ERR_clear_error 222 EXIST::FUNCTION:
215ERR_error_string 223 EXIST::FUNCTION:
216ERR_free_strings 224 EXIST::FUNCTION:
217ERR_func_error_string 225 EXIST::FUNCTION:
218ERR_get_err_state_table 226 EXIST::FUNCTION:LHASH
219ERR_get_error 227 EXIST::FUNCTION:
220ERR_get_error_line 228 EXIST::FUNCTION:
221ERR_get_state 229 EXIST::FUNCTION:
222ERR_get_string_table 230 EXIST::FUNCTION:LHASH
223ERR_lib_error_string 231 EXIST::FUNCTION:
224ERR_load_ASN1_strings 232 EXIST::FUNCTION:
225ERR_load_BIO_strings 233 EXIST::FUNCTION:
226ERR_load_BN_strings 234 EXIST::FUNCTION:
227ERR_load_BUF_strings 235 EXIST::FUNCTION:
228ERR_load_CONF_strings 236 EXIST::FUNCTION:
229ERR_load_DH_strings 237 EXIST::FUNCTION:DH
230ERR_load_DSA_strings 238 EXIST::FUNCTION:DSA
231ERR_load_ERR_strings 239 EXIST::FUNCTION:
232ERR_load_EVP_strings 240 EXIST::FUNCTION:
233ERR_load_OBJ_strings 241 EXIST::FUNCTION:
234ERR_load_PEM_strings 242 EXIST::FUNCTION:
235ERR_load_PROXY_strings 243 NOEXIST::FUNCTION:
236ERR_load_RSA_strings 244 EXIST::FUNCTION:RSA
237ERR_load_X509_strings 245 EXIST::FUNCTION:
238ERR_load_crypto_strings 246 EXIST::FUNCTION:
239ERR_load_strings 247 EXIST::FUNCTION:
240ERR_peek_error 248 EXIST::FUNCTION:
241ERR_peek_error_line 249 EXIST::FUNCTION:
242ERR_print_errors 250 EXIST::FUNCTION:BIO
243ERR_print_errors_fp 251 EXIST::FUNCTION:FP_API
244ERR_put_error 252 EXIST::FUNCTION:
245ERR_reason_error_string 253 EXIST::FUNCTION:
246ERR_remove_state 254 EXIST::FUNCTION:
247EVP_BytesToKey 255 EXIST::FUNCTION:
248EVP_CIPHER_CTX_cleanup 256 EXIST::FUNCTION:
249EVP_CipherFinal 257 EXIST::FUNCTION:
250EVP_CipherInit 258 EXIST::FUNCTION:
251EVP_CipherUpdate 259 EXIST::FUNCTION:
252EVP_DecodeBlock 260 EXIST::FUNCTION:
253EVP_DecodeFinal 261 EXIST::FUNCTION:
254EVP_DecodeInit 262 EXIST::FUNCTION:
255EVP_DecodeUpdate 263 EXIST::FUNCTION:
256EVP_DecryptFinal 264 EXIST::FUNCTION:
257EVP_DecryptInit 265 EXIST::FUNCTION:
258EVP_DecryptUpdate 266 EXIST::FUNCTION:
259EVP_DigestFinal 267 EXIST::FUNCTION:
260EVP_DigestInit 268 EXIST::FUNCTION:
261EVP_DigestUpdate 269 EXIST::FUNCTION:
262EVP_EncodeBlock 270 EXIST::FUNCTION:
263EVP_EncodeFinal 271 EXIST::FUNCTION:
264EVP_EncodeInit 272 EXIST::FUNCTION:
265EVP_EncodeUpdate 273 EXIST::FUNCTION:
266EVP_EncryptFinal 274 EXIST::FUNCTION:
267EVP_EncryptInit 275 EXIST::FUNCTION:
268EVP_EncryptUpdate 276 EXIST::FUNCTION:
269EVP_OpenFinal 277 EXIST::FUNCTION:RSA
270EVP_OpenInit 278 EXIST::FUNCTION:RSA
271EVP_PKEY_assign 279 EXIST::FUNCTION:
272EVP_PKEY_copy_parameters 280 EXIST::FUNCTION:
273EVP_PKEY_free 281 EXIST::FUNCTION:
274EVP_PKEY_missing_parameters 282 EXIST::FUNCTION:
275EVP_PKEY_new 283 EXIST::FUNCTION:
276EVP_PKEY_save_parameters 284 EXIST::FUNCTION:
277EVP_PKEY_size 285 EXIST::FUNCTION:
278EVP_PKEY_type 286 EXIST::FUNCTION:
279EVP_SealFinal 287 EXIST::FUNCTION:RSA
280EVP_SealInit 288 EXIST::FUNCTION:RSA
281EVP_SignFinal 289 EXIST::FUNCTION:
282EVP_VerifyFinal 290 EXIST::FUNCTION:
283EVP_add_alias 291 NOEXIST::FUNCTION:
284EVP_add_cipher 292 EXIST::FUNCTION:
285EVP_add_digest 293 EXIST::FUNCTION:
286EVP_bf_cbc 294 EXIST::FUNCTION:BF
287EVP_bf_cfb64 295 EXIST::FUNCTION:BF
288EVP_bf_ecb 296 EXIST::FUNCTION:BF
289EVP_bf_ofb 297 EXIST::FUNCTION:BF
290EVP_cleanup 298 EXIST::FUNCTION:
291EVP_des_cbc 299 EXIST::FUNCTION:DES
292EVP_des_cfb64 300 EXIST::FUNCTION:DES
293EVP_des_ecb 301 EXIST::FUNCTION:DES
294EVP_des_ede 302 EXIST::FUNCTION:DES
295EVP_des_ede3 303 EXIST::FUNCTION:DES
296EVP_des_ede3_cbc 304 EXIST::FUNCTION:DES
297EVP_des_ede3_cfb64 305 EXIST::FUNCTION:DES
298EVP_des_ede3_ofb 306 EXIST::FUNCTION:DES
299EVP_des_ede_cbc 307 EXIST::FUNCTION:DES
300EVP_des_ede_cfb64 308 EXIST::FUNCTION:DES
301EVP_des_ede_ofb 309 EXIST::FUNCTION:DES
302EVP_des_ofb 310 EXIST::FUNCTION:DES
303EVP_desx_cbc 311 EXIST::FUNCTION:DES
304EVP_dss 312 EXIST::FUNCTION:DSA,SHA
305EVP_dss1 313 EXIST::FUNCTION:DSA,SHA
306EVP_enc_null 314 EXIST::FUNCTION:
307EVP_get_cipherbyname 315 EXIST::FUNCTION:
308EVP_get_digestbyname 316 EXIST::FUNCTION:
309EVP_get_pw_prompt 317 EXIST::FUNCTION:
310EVP_idea_cbc 318 EXIST::FUNCTION:IDEA
311EVP_idea_cfb64 319 EXIST::FUNCTION:IDEA
312EVP_idea_ecb 320 EXIST::FUNCTION:IDEA
313EVP_idea_ofb 321 EXIST::FUNCTION:IDEA
314EVP_md2 322 EXIST::FUNCTION:MD2
315EVP_md5 323 EXIST::FUNCTION:MD5
316EVP_md_null 324 EXIST::FUNCTION:
317EVP_rc2_cbc 325 EXIST::FUNCTION:RC2
318EVP_rc2_cfb64 326 EXIST::FUNCTION:RC2
319EVP_rc2_ecb 327 EXIST::FUNCTION:RC2
320EVP_rc2_ofb 328 EXIST::FUNCTION:RC2
321EVP_rc4 329 EXIST::FUNCTION:RC4
322EVP_read_pw_string 330 EXIST::FUNCTION:
323EVP_set_pw_prompt 331 EXIST::FUNCTION:
324EVP_sha 332 EXIST::FUNCTION:SHA
325EVP_sha1 333 EXIST::FUNCTION:SHA
326MD2 334 EXIST::FUNCTION:MD2
327MD2_Final 335 EXIST::FUNCTION:MD2
328MD2_Init 336 EXIST::FUNCTION:MD2
329MD2_Update 337 EXIST::FUNCTION:MD2
330MD2_options 338 EXIST::FUNCTION:MD2
331MD5 339 EXIST::FUNCTION:MD5
332MD5_Final 340 EXIST::FUNCTION:MD5
333MD5_Init 341 EXIST::FUNCTION:MD5
334MD5_Update 342 EXIST::FUNCTION:MD5
335MDC2 343 EXIST::FUNCTION:MDC2
336MDC2_Final 344 EXIST::FUNCTION:MDC2
337MDC2_Init 345 EXIST::FUNCTION:MDC2
338MDC2_Update 346 EXIST::FUNCTION:MDC2
339NETSCAPE_SPKAC_free 347 EXIST::FUNCTION:
340NETSCAPE_SPKAC_new 348 EXIST::FUNCTION:
341NETSCAPE_SPKI_free 349 EXIST::FUNCTION:
342NETSCAPE_SPKI_new 350 EXIST::FUNCTION:
343NETSCAPE_SPKI_sign 351 EXIST::FUNCTION:EVP
344NETSCAPE_SPKI_verify 352 EXIST::FUNCTION:EVP
345OBJ_add_object 353 EXIST::FUNCTION:
346OBJ_bsearch 354 EXIST::FUNCTION:
347OBJ_cleanup 355 EXIST::FUNCTION:
348OBJ_cmp 356 EXIST::FUNCTION:
349OBJ_create 357 EXIST::FUNCTION:
350OBJ_dup 358 EXIST::FUNCTION:
351OBJ_ln2nid 359 EXIST::FUNCTION:
352OBJ_new_nid 360 EXIST::FUNCTION:
353OBJ_nid2ln 361 EXIST::FUNCTION:
354OBJ_nid2obj 362 EXIST::FUNCTION:
355OBJ_nid2sn 363 EXIST::FUNCTION:
356OBJ_obj2nid 364 EXIST::FUNCTION:
357OBJ_sn2nid 365 EXIST::FUNCTION:
358OBJ_txt2nid 366 EXIST::FUNCTION:
359PEM_ASN1_read 367 EXIST:!WIN16:FUNCTION:
360PEM_ASN1_read_bio 368 EXIST::FUNCTION:BIO
361PEM_ASN1_write 369 EXIST:!WIN16:FUNCTION:
362PEM_ASN1_write_bio 370 EXIST::FUNCTION:BIO
363PEM_SealFinal 371 EXIST::FUNCTION:RSA
364PEM_SealInit 372 EXIST::FUNCTION:RSA
365PEM_SealUpdate 373 EXIST::FUNCTION:RSA
366PEM_SignFinal 374 EXIST::FUNCTION:
367PEM_SignInit 375 EXIST::FUNCTION:
368PEM_SignUpdate 376 EXIST::FUNCTION:
369PEM_X509_INFO_read 377 EXIST:!WIN16:FUNCTION:
370PEM_X509_INFO_read_bio 378 EXIST::FUNCTION:BIO
371PEM_X509_INFO_write_bio 379 EXIST::FUNCTION:BIO
372PEM_dek_info 380 EXIST::FUNCTION:
373PEM_do_header 381 EXIST::FUNCTION:
374PEM_get_EVP_CIPHER_INFO 382 EXIST::FUNCTION:
375PEM_proc_type 383 EXIST::FUNCTION:
376PEM_read 384 EXIST:!WIN16:FUNCTION:
377PEM_read_DHparams 385 EXIST:!WIN16:FUNCTION:DH
378PEM_read_DSAPrivateKey 386 EXIST:!WIN16:FUNCTION:DSA
379PEM_read_DSAparams 387 EXIST:!WIN16:FUNCTION:DSA
380PEM_read_PKCS7 388 EXIST:!WIN16:FUNCTION:
381PEM_read_PrivateKey 389 EXIST:!WIN16:FUNCTION:
382PEM_read_RSAPrivateKey 390 EXIST:!WIN16:FUNCTION:RSA
383PEM_read_X509 391 EXIST:!WIN16:FUNCTION:
384PEM_read_X509_CRL 392 EXIST:!WIN16:FUNCTION:
385PEM_read_X509_REQ 393 EXIST:!WIN16:FUNCTION:
386PEM_read_bio 394 EXIST::FUNCTION:BIO
387PEM_read_bio_DHparams 395 EXIST::FUNCTION:DH
388PEM_read_bio_DSAPrivateKey 396 EXIST::FUNCTION:DSA
389PEM_read_bio_DSAparams 397 EXIST::FUNCTION:DSA
390PEM_read_bio_PKCS7 398 EXIST::FUNCTION:
391PEM_read_bio_PrivateKey 399 EXIST::FUNCTION:
392PEM_read_bio_RSAPrivateKey 400 EXIST::FUNCTION:RSA
393PEM_read_bio_X509 401 EXIST::FUNCTION:
394PEM_read_bio_X509_CRL 402 EXIST::FUNCTION:
395PEM_read_bio_X509_REQ 403 EXIST::FUNCTION:
396PEM_write 404 EXIST:!WIN16:FUNCTION:
397PEM_write_DHparams 405 EXIST:!WIN16:FUNCTION:DH
398PEM_write_DSAPrivateKey 406 EXIST:!WIN16:FUNCTION:DSA
399PEM_write_DSAparams 407 EXIST:!WIN16:FUNCTION:DSA
400PEM_write_PKCS7 408 EXIST:!WIN16:FUNCTION:
401PEM_write_PrivateKey 409 EXIST:!WIN16:FUNCTION:
402PEM_write_RSAPrivateKey 410 EXIST:!WIN16:FUNCTION:RSA
403PEM_write_X509 411 EXIST:!WIN16:FUNCTION:
404PEM_write_X509_CRL 412 EXIST:!WIN16:FUNCTION:
405PEM_write_X509_REQ 413 EXIST:!WIN16:FUNCTION:
406PEM_write_bio 414 EXIST::FUNCTION:BIO
407PEM_write_bio_DHparams 415 EXIST::FUNCTION:DH
408PEM_write_bio_DSAPrivateKey 416 EXIST::FUNCTION:DSA
409PEM_write_bio_DSAparams 417 EXIST::FUNCTION:DSA
410PEM_write_bio_PKCS7 418 EXIST::FUNCTION:
411PEM_write_bio_PrivateKey 419 EXIST::FUNCTION:
412PEM_write_bio_RSAPrivateKey 420 EXIST::FUNCTION:RSA
413PEM_write_bio_X509 421 EXIST::FUNCTION:
414PEM_write_bio_X509_CRL 422 EXIST::FUNCTION:
415PEM_write_bio_X509_REQ 423 EXIST::FUNCTION:
416PKCS7_DIGEST_free 424 EXIST::FUNCTION:
417PKCS7_DIGEST_new 425 EXIST::FUNCTION:
418PKCS7_ENCRYPT_free 426 EXIST::FUNCTION:
419PKCS7_ENCRYPT_new 427 EXIST::FUNCTION:
420PKCS7_ENC_CONTENT_free 428 EXIST::FUNCTION:
421PKCS7_ENC_CONTENT_new 429 EXIST::FUNCTION:
422PKCS7_ENVELOPE_free 430 EXIST::FUNCTION:
423PKCS7_ENVELOPE_new 431 EXIST::FUNCTION:
424PKCS7_ISSUER_AND_SERIAL_digest 432 EXIST::FUNCTION:
425PKCS7_ISSUER_AND_SERIAL_free 433 EXIST::FUNCTION:
426PKCS7_ISSUER_AND_SERIAL_new 434 EXIST::FUNCTION:
427PKCS7_RECIP_INFO_free 435 EXIST::FUNCTION:
428PKCS7_RECIP_INFO_new 436 EXIST::FUNCTION:
429PKCS7_SIGNED_free 437 EXIST::FUNCTION:
430PKCS7_SIGNED_new 438 EXIST::FUNCTION:
431PKCS7_SIGNER_INFO_free 439 EXIST::FUNCTION:
432PKCS7_SIGNER_INFO_new 440 EXIST::FUNCTION:
433PKCS7_SIGN_ENVELOPE_free 441 EXIST::FUNCTION:
434PKCS7_SIGN_ENVELOPE_new 442 EXIST::FUNCTION:
435PKCS7_dup 443 EXIST::FUNCTION:
436PKCS7_free 444 EXIST::FUNCTION:
437PKCS7_new 445 EXIST::FUNCTION:
438PROXY_ENTRY_add_noproxy 446 NOEXIST::FUNCTION:
439PROXY_ENTRY_clear_noproxy 447 NOEXIST::FUNCTION:
440PROXY_ENTRY_free 448 NOEXIST::FUNCTION:
441PROXY_ENTRY_get_noproxy 449 NOEXIST::FUNCTION:
442PROXY_ENTRY_new 450 NOEXIST::FUNCTION:
443PROXY_ENTRY_set_server 451 NOEXIST::FUNCTION:
444PROXY_add_noproxy 452 NOEXIST::FUNCTION:
445PROXY_add_server 453 NOEXIST::FUNCTION:
446PROXY_check_by_host 454 NOEXIST::FUNCTION:
447PROXY_check_url 455 NOEXIST::FUNCTION:
448PROXY_clear_noproxy 456 NOEXIST::FUNCTION:
449PROXY_free 457 NOEXIST::FUNCTION:
450PROXY_get_noproxy 458 NOEXIST::FUNCTION:
451PROXY_get_proxies 459 NOEXIST::FUNCTION:
452PROXY_get_proxy_entry 460 NOEXIST::FUNCTION:
453PROXY_load_conf 461 NOEXIST::FUNCTION:
454PROXY_new 462 NOEXIST::FUNCTION:
455PROXY_print 463 NOEXIST::FUNCTION:
456RAND_bytes 464 EXIST::FUNCTION:
457RAND_cleanup 465 EXIST::FUNCTION:
458RAND_file_name 466 EXIST::FUNCTION:
459RAND_load_file 467 EXIST::FUNCTION:
460RAND_screen 468 EXIST:WIN32:FUNCTION:
461RAND_seed 469 EXIST::FUNCTION:
462RAND_write_file 470 EXIST::FUNCTION:
463RC2_cbc_encrypt 471 EXIST::FUNCTION:RC2
464RC2_cfb64_encrypt 472 EXIST::FUNCTION:RC2
465RC2_ecb_encrypt 473 EXIST::FUNCTION:RC2
466RC2_encrypt 474 EXIST::FUNCTION:RC2
467RC2_ofb64_encrypt 475 EXIST::FUNCTION:RC2
468RC2_set_key 476 EXIST::FUNCTION:RC2
469RC4 477 EXIST::FUNCTION:RC4
470RC4_options 478 EXIST::FUNCTION:RC4
471RC4_set_key 479 EXIST::FUNCTION:RC4
472RSAPrivateKey_asn1_meth 480 EXIST::FUNCTION:RSA
473RSAPrivateKey_dup 481 EXIST::FUNCTION:RSA
474RSAPublicKey_dup 482 EXIST::FUNCTION:RSA
475RSA_PKCS1_SSLeay 483 EXIST::FUNCTION:RSA
476RSA_free 484 EXIST::FUNCTION:RSA
477RSA_generate_key 485 EXIST::FUNCTION:RSA
478RSA_new 486 EXIST::FUNCTION:RSA
479RSA_new_method 487 EXIST::FUNCTION:RSA
480RSA_print 488 EXIST::FUNCTION:BIO,RSA
481RSA_print_fp 489 EXIST::FUNCTION:FP_API,RSA
482RSA_private_decrypt 490 EXIST::FUNCTION:RSA
483RSA_private_encrypt 491 EXIST::FUNCTION:RSA
484RSA_public_decrypt 492 EXIST::FUNCTION:RSA
485RSA_public_encrypt 493 EXIST::FUNCTION:RSA
486RSA_set_default_method 494 EXIST::FUNCTION:RSA
487RSA_sign 495 EXIST::FUNCTION:RSA
488RSA_sign_ASN1_OCTET_STRING 496 EXIST::FUNCTION:RSA
489RSA_size 497 EXIST::FUNCTION:RSA
490RSA_verify 498 EXIST::FUNCTION:RSA
491RSA_verify_ASN1_OCTET_STRING 499 EXIST::FUNCTION:RSA
492SHA 500 EXIST::FUNCTION:SHA,SHA0
493SHA1 501 EXIST::FUNCTION:SHA,SHA1
494SHA1_Final 502 EXIST::FUNCTION:SHA,SHA1
495SHA1_Init 503 EXIST::FUNCTION:SHA,SHA1
496SHA1_Update 504 EXIST::FUNCTION:SHA,SHA1
497SHA_Final 505 EXIST::FUNCTION:SHA,SHA0
498SHA_Init 506 EXIST::FUNCTION:SHA,SHA0
499SHA_Update 507 EXIST::FUNCTION:SHA,SHA0
500OpenSSL_add_all_algorithms 508 NOEXIST::FUNCTION:
501OpenSSL_add_all_ciphers 509 EXIST::FUNCTION:
502OpenSSL_add_all_digests 510 EXIST::FUNCTION:
503TXT_DB_create_index 511 EXIST::FUNCTION:
504TXT_DB_free 512 EXIST::FUNCTION:
505TXT_DB_get_by_index 513 EXIST::FUNCTION:
506TXT_DB_insert 514 EXIST::FUNCTION:
507TXT_DB_read 515 EXIST::FUNCTION:BIO
508TXT_DB_write 516 EXIST::FUNCTION:BIO
509X509_ALGOR_free 517 EXIST::FUNCTION:
510X509_ALGOR_new 518 EXIST::FUNCTION:
511X509_ATTRIBUTE_free 519 EXIST::FUNCTION:
512X509_ATTRIBUTE_new 520 EXIST::FUNCTION:
513X509_CINF_free 521 EXIST::FUNCTION:
514X509_CINF_new 522 EXIST::FUNCTION:
515X509_CRL_INFO_free 523 EXIST::FUNCTION:
516X509_CRL_INFO_new 524 EXIST::FUNCTION:
517X509_CRL_add_ext 525 EXIST::FUNCTION:
518X509_CRL_cmp 526 EXIST::FUNCTION:
519X509_CRL_delete_ext 527 EXIST::FUNCTION:
520X509_CRL_dup 528 EXIST::FUNCTION:
521X509_CRL_free 529 EXIST::FUNCTION:
522X509_CRL_get_ext 530 EXIST::FUNCTION:
523X509_CRL_get_ext_by_NID 531 EXIST::FUNCTION:
524X509_CRL_get_ext_by_OBJ 532 EXIST::FUNCTION:
525X509_CRL_get_ext_by_critical 533 EXIST::FUNCTION:
526X509_CRL_get_ext_count 534 EXIST::FUNCTION:
527X509_CRL_new 535 EXIST::FUNCTION:
528X509_CRL_sign 536 EXIST::FUNCTION:EVP
529X509_CRL_verify 537 EXIST::FUNCTION:EVP
530X509_EXTENSION_create_by_NID 538 EXIST::FUNCTION:
531X509_EXTENSION_create_by_OBJ 539 EXIST::FUNCTION:
532X509_EXTENSION_dup 540 EXIST::FUNCTION:
533X509_EXTENSION_free 541 EXIST::FUNCTION:
534X509_EXTENSION_get_critical 542 EXIST::FUNCTION:
535X509_EXTENSION_get_data 543 EXIST::FUNCTION:
536X509_EXTENSION_get_object 544 EXIST::FUNCTION:
537X509_EXTENSION_new 545 EXIST::FUNCTION:
538X509_EXTENSION_set_critical 546 EXIST::FUNCTION:
539X509_EXTENSION_set_data 547 EXIST::FUNCTION:
540X509_EXTENSION_set_object 548 EXIST::FUNCTION:
541X509_INFO_free 549 EXIST::FUNCTION:EVP
542X509_INFO_new 550 EXIST::FUNCTION:EVP
543X509_LOOKUP_by_alias 551 EXIST::FUNCTION:
544X509_LOOKUP_by_fingerprint 552 EXIST::FUNCTION:
545X509_LOOKUP_by_issuer_serial 553 EXIST::FUNCTION:
546X509_LOOKUP_by_subject 554 EXIST::FUNCTION:
547X509_LOOKUP_ctrl 555 EXIST::FUNCTION:
548X509_LOOKUP_file 556 EXIST::FUNCTION:
549X509_LOOKUP_free 557 EXIST::FUNCTION:
550X509_LOOKUP_hash_dir 558 EXIST::FUNCTION:
551X509_LOOKUP_init 559 EXIST::FUNCTION:
552X509_LOOKUP_new 560 EXIST::FUNCTION:
553X509_LOOKUP_shutdown 561 EXIST::FUNCTION:
554X509_NAME_ENTRY_create_by_NID 562 EXIST::FUNCTION:
555X509_NAME_ENTRY_create_by_OBJ 563 EXIST::FUNCTION:
556X509_NAME_ENTRY_dup 564 EXIST::FUNCTION:
557X509_NAME_ENTRY_free 565 EXIST::FUNCTION:
558X509_NAME_ENTRY_get_data 566 EXIST::FUNCTION:
559X509_NAME_ENTRY_get_object 567 EXIST::FUNCTION:
560X509_NAME_ENTRY_new 568 EXIST::FUNCTION:
561X509_NAME_ENTRY_set_data 569 EXIST::FUNCTION:
562X509_NAME_ENTRY_set_object 570 EXIST::FUNCTION:
563X509_NAME_add_entry 571 EXIST::FUNCTION:
564X509_NAME_cmp 572 EXIST::FUNCTION:
565X509_NAME_delete_entry 573 EXIST::FUNCTION:
566X509_NAME_digest 574 EXIST::FUNCTION:EVP
567X509_NAME_dup 575 EXIST::FUNCTION:
568X509_NAME_entry_count 576 EXIST::FUNCTION:
569X509_NAME_free 577 EXIST::FUNCTION:
570X509_NAME_get_entry 578 EXIST::FUNCTION:
571X509_NAME_get_index_by_NID 579 EXIST::FUNCTION:
572X509_NAME_get_index_by_OBJ 580 EXIST::FUNCTION:
573X509_NAME_get_text_by_NID 581 EXIST::FUNCTION:
574X509_NAME_get_text_by_OBJ 582 EXIST::FUNCTION:
575X509_NAME_hash 583 EXIST::FUNCTION:
576X509_NAME_new 584 EXIST::FUNCTION:
577X509_NAME_oneline 585 EXIST::FUNCTION:EVP
578X509_NAME_print 586 EXIST::FUNCTION:BIO
579X509_NAME_set 587 EXIST::FUNCTION:
580X509_OBJECT_free_contents 588 EXIST::FUNCTION:
581X509_OBJECT_retrieve_by_subject 589 EXIST::FUNCTION:
582X509_OBJECT_up_ref_count 590 EXIST::FUNCTION:
583X509_PKEY_free 591 EXIST::FUNCTION:
584X509_PKEY_new 592 EXIST::FUNCTION:
585X509_PUBKEY_free 593 EXIST::FUNCTION:
586X509_PUBKEY_get 594 EXIST::FUNCTION:
587X509_PUBKEY_new 595 EXIST::FUNCTION:
588X509_PUBKEY_set 596 EXIST::FUNCTION:
589X509_REQ_INFO_free 597 EXIST::FUNCTION:
590X509_REQ_INFO_new 598 EXIST::FUNCTION:
591X509_REQ_dup 599 EXIST::FUNCTION:
592X509_REQ_free 600 EXIST::FUNCTION:
593X509_REQ_get_pubkey 601 EXIST::FUNCTION:
594X509_REQ_new 602 EXIST::FUNCTION:
595X509_REQ_print 603 EXIST::FUNCTION:BIO
596X509_REQ_print_fp 604 EXIST::FUNCTION:FP_API
597X509_REQ_set_pubkey 605 EXIST::FUNCTION:
598X509_REQ_set_subject_name 606 EXIST::FUNCTION:
599X509_REQ_set_version 607 EXIST::FUNCTION:
600X509_REQ_sign 608 EXIST::FUNCTION:EVP
601X509_REQ_to_X509 609 EXIST::FUNCTION:
602X509_REQ_verify 610 EXIST::FUNCTION:EVP
603X509_REVOKED_add_ext 611 EXIST::FUNCTION:
604X509_REVOKED_delete_ext 612 EXIST::FUNCTION:
605X509_REVOKED_free 613 EXIST::FUNCTION:
606X509_REVOKED_get_ext 614 EXIST::FUNCTION:
607X509_REVOKED_get_ext_by_NID 615 EXIST::FUNCTION:
608X509_REVOKED_get_ext_by_OBJ 616 EXIST::FUNCTION:
609X509_REVOKED_get_ext_by_critical 617 EXIST:!VMS:FUNCTION:
610X509_REVOKED_get_ext_by_critic 617 EXIST:VMS:FUNCTION:
611X509_REVOKED_get_ext_count 618 EXIST::FUNCTION:
612X509_REVOKED_new 619 EXIST::FUNCTION:
613X509_SIG_free 620 EXIST::FUNCTION:
614X509_SIG_new 621 EXIST::FUNCTION:
615X509_STORE_CTX_cleanup 622 EXIST::FUNCTION:
616X509_STORE_CTX_init 623 EXIST::FUNCTION:
617X509_STORE_add_cert 624 EXIST::FUNCTION:
618X509_STORE_add_lookup 625 EXIST::FUNCTION:
619X509_STORE_free 626 EXIST::FUNCTION:
620X509_STORE_get_by_subject 627 EXIST::FUNCTION:
621X509_STORE_load_locations 628 EXIST::FUNCTION:STDIO
622X509_STORE_new 629 EXIST::FUNCTION:
623X509_STORE_set_default_paths 630 EXIST::FUNCTION:STDIO
624X509_VAL_free 631 EXIST::FUNCTION:
625X509_VAL_new 632 EXIST::FUNCTION:
626X509_add_ext 633 EXIST::FUNCTION:
627X509_asn1_meth 634 EXIST::FUNCTION:
628X509_certificate_type 635 EXIST::FUNCTION:
629X509_check_private_key 636 EXIST::FUNCTION:
630X509_cmp_current_time 637 EXIST::FUNCTION:
631X509_delete_ext 638 EXIST::FUNCTION:
632X509_digest 639 EXIST::FUNCTION:EVP
633X509_dup 640 EXIST::FUNCTION:
634X509_free 641 EXIST::FUNCTION:
635X509_get_default_cert_area 642 EXIST::FUNCTION:
636X509_get_default_cert_dir 643 EXIST::FUNCTION:
637X509_get_default_cert_dir_env 644 EXIST::FUNCTION:
638X509_get_default_cert_file 645 EXIST::FUNCTION:
639X509_get_default_cert_file_env 646 EXIST::FUNCTION:
640X509_get_default_private_dir 647 EXIST::FUNCTION:
641X509_get_ext 648 EXIST::FUNCTION:
642X509_get_ext_by_NID 649 EXIST::FUNCTION:
643X509_get_ext_by_OBJ 650 EXIST::FUNCTION:
644X509_get_ext_by_critical 651 EXIST::FUNCTION:
645X509_get_ext_count 652 EXIST::FUNCTION:
646X509_get_issuer_name 653 EXIST::FUNCTION:
647X509_get_pubkey 654 EXIST::FUNCTION:
648X509_get_pubkey_parameters 655 EXIST::FUNCTION:
649X509_get_serialNumber 656 EXIST::FUNCTION:
650X509_get_subject_name 657 EXIST::FUNCTION:
651X509_gmtime_adj 658 EXIST::FUNCTION:
652X509_issuer_and_serial_cmp 659 EXIST::FUNCTION:
653X509_issuer_and_serial_hash 660 EXIST::FUNCTION:
654X509_issuer_name_cmp 661 EXIST::FUNCTION:
655X509_issuer_name_hash 662 EXIST::FUNCTION:
656X509_load_cert_file 663 EXIST::FUNCTION:STDIO
657X509_new 664 EXIST::FUNCTION:
658X509_print 665 EXIST::FUNCTION:BIO
659X509_print_fp 666 EXIST::FUNCTION:FP_API
660X509_set_issuer_name 667 EXIST::FUNCTION:
661X509_set_notAfter 668 EXIST::FUNCTION:
662X509_set_notBefore 669 EXIST::FUNCTION:
663X509_set_pubkey 670 EXIST::FUNCTION:
664X509_set_serialNumber 671 EXIST::FUNCTION:
665X509_set_subject_name 672 EXIST::FUNCTION:
666X509_set_version 673 EXIST::FUNCTION:
667X509_sign 674 EXIST::FUNCTION:EVP
668X509_subject_name_cmp 675 EXIST::FUNCTION:
669X509_subject_name_hash 676 EXIST::FUNCTION:
670X509_to_X509_REQ 677 EXIST::FUNCTION:
671X509_verify 678 EXIST::FUNCTION:EVP
672X509_verify_cert 679 EXIST::FUNCTION:
673X509_verify_cert_error_string 680 EXIST::FUNCTION:
674X509v3_add_ext 681 EXIST::FUNCTION:
675X509v3_add_extension 682 NOEXIST::FUNCTION:
676X509v3_add_netscape_extensions 683 NOEXIST::FUNCTION:
677X509v3_add_standard_extensions 684 NOEXIST::FUNCTION:
678X509v3_cleanup_extensions 685 NOEXIST::FUNCTION:
679X509v3_data_type_by_NID 686 NOEXIST::FUNCTION:
680X509v3_data_type_by_OBJ 687 NOEXIST::FUNCTION:
681X509v3_delete_ext 688 EXIST::FUNCTION:
682X509v3_get_ext 689 EXIST::FUNCTION:
683X509v3_get_ext_by_NID 690 EXIST::FUNCTION:
684X509v3_get_ext_by_OBJ 691 EXIST::FUNCTION:
685X509v3_get_ext_by_critical 692 EXIST::FUNCTION:
686X509v3_get_ext_count 693 EXIST::FUNCTION:
687X509v3_pack_string 694 NOEXIST::FUNCTION:
688X509v3_pack_type_by_NID 695 NOEXIST::FUNCTION:
689X509v3_pack_type_by_OBJ 696 NOEXIST::FUNCTION:
690X509v3_unpack_string 697 NOEXIST::FUNCTION:
691_des_crypt 698 NOEXIST::FUNCTION:
692a2d_ASN1_OBJECT 699 EXIST::FUNCTION:
693a2i_ASN1_INTEGER 700 EXIST::FUNCTION:BIO
694a2i_ASN1_STRING 701 EXIST::FUNCTION:BIO
695asn1_Finish 702 EXIST::FUNCTION:
696asn1_GetSequence 703 EXIST::FUNCTION:
697bn_div_words 704 EXIST::FUNCTION:
698bn_expand2 705 EXIST::FUNCTION:
699bn_mul_add_words 706 EXIST::FUNCTION:
700bn_mul_words 707 EXIST::FUNCTION:
701BN_uadd 708 EXIST::FUNCTION:
702BN_usub 709 EXIST::FUNCTION:
703bn_sqr_words 710 EXIST::FUNCTION:
704_ossl_old_crypt 711 EXIST:!NeXT,!PERL5:FUNCTION:DES
705d2i_ASN1_BIT_STRING 712 EXIST::FUNCTION:
706d2i_ASN1_BOOLEAN 713 EXIST::FUNCTION:
707d2i_ASN1_HEADER 714 EXIST::FUNCTION:
708d2i_ASN1_IA5STRING 715 EXIST::FUNCTION:
709d2i_ASN1_INTEGER 716 EXIST::FUNCTION:
710d2i_ASN1_OBJECT 717 EXIST::FUNCTION:
711d2i_ASN1_OCTET_STRING 718 EXIST::FUNCTION:
712d2i_ASN1_PRINTABLE 719 EXIST::FUNCTION:
713d2i_ASN1_PRINTABLESTRING 720 EXIST::FUNCTION:
714d2i_ASN1_SET 721 EXIST::FUNCTION:
715d2i_ASN1_T61STRING 722 EXIST::FUNCTION:
716d2i_ASN1_TYPE 723 EXIST::FUNCTION:
717d2i_ASN1_UTCTIME 724 EXIST::FUNCTION:
718d2i_ASN1_bytes 725 EXIST::FUNCTION:
719d2i_ASN1_type_bytes 726 EXIST::FUNCTION:
720d2i_DHparams 727 EXIST::FUNCTION:DH
721d2i_DSAPrivateKey 728 EXIST::FUNCTION:DSA
722d2i_DSAPrivateKey_bio 729 EXIST::FUNCTION:BIO,DSA
723d2i_DSAPrivateKey_fp 730 EXIST::FUNCTION:DSA,FP_API
724d2i_DSAPublicKey 731 EXIST::FUNCTION:DSA
725d2i_DSAparams 732 EXIST::FUNCTION:DSA
726d2i_NETSCAPE_SPKAC 733 EXIST::FUNCTION:
727d2i_NETSCAPE_SPKI 734 EXIST::FUNCTION:
728d2i_Netscape_RSA 735 EXIST::FUNCTION:RSA
729d2i_PKCS7 736 EXIST::FUNCTION:
730d2i_PKCS7_DIGEST 737 EXIST::FUNCTION:
731d2i_PKCS7_ENCRYPT 738 EXIST::FUNCTION:
732d2i_PKCS7_ENC_CONTENT 739 EXIST::FUNCTION:
733d2i_PKCS7_ENVELOPE 740 EXIST::FUNCTION:
734d2i_PKCS7_ISSUER_AND_SERIAL 741 EXIST::FUNCTION:
735d2i_PKCS7_RECIP_INFO 742 EXIST::FUNCTION:
736d2i_PKCS7_SIGNED 743 EXIST::FUNCTION:
737d2i_PKCS7_SIGNER_INFO 744 EXIST::FUNCTION:
738d2i_PKCS7_SIGN_ENVELOPE 745 EXIST::FUNCTION:
739d2i_PKCS7_bio 746 EXIST::FUNCTION:
740d2i_PKCS7_fp 747 EXIST::FUNCTION:FP_API
741d2i_PrivateKey 748 EXIST::FUNCTION:
742d2i_PublicKey 749 EXIST::FUNCTION:
743d2i_RSAPrivateKey 750 EXIST::FUNCTION:RSA
744d2i_RSAPrivateKey_bio 751 EXIST::FUNCTION:BIO,RSA
745d2i_RSAPrivateKey_fp 752 EXIST::FUNCTION:FP_API,RSA
746d2i_RSAPublicKey 753 EXIST::FUNCTION:RSA
747d2i_X509 754 EXIST::FUNCTION:
748d2i_X509_ALGOR 755 EXIST::FUNCTION:
749d2i_X509_ATTRIBUTE 756 EXIST::FUNCTION:
750d2i_X509_CINF 757 EXIST::FUNCTION:
751d2i_X509_CRL 758 EXIST::FUNCTION:
752d2i_X509_CRL_INFO 759 EXIST::FUNCTION:
753d2i_X509_CRL_bio 760 EXIST::FUNCTION:BIO
754d2i_X509_CRL_fp 761 EXIST::FUNCTION:FP_API
755d2i_X509_EXTENSION 762 EXIST::FUNCTION:
756d2i_X509_NAME 763 EXIST::FUNCTION:
757d2i_X509_NAME_ENTRY 764 EXIST::FUNCTION:
758d2i_X509_PKEY 765 EXIST::FUNCTION:
759d2i_X509_PUBKEY 766 EXIST::FUNCTION:
760d2i_X509_REQ 767 EXIST::FUNCTION:
761d2i_X509_REQ_INFO 768 EXIST::FUNCTION:
762d2i_X509_REQ_bio 769 EXIST::FUNCTION:BIO
763d2i_X509_REQ_fp 770 EXIST::FUNCTION:FP_API
764d2i_X509_REVOKED 771 EXIST::FUNCTION:
765d2i_X509_SIG 772 EXIST::FUNCTION:
766d2i_X509_VAL 773 EXIST::FUNCTION:
767d2i_X509_bio 774 EXIST::FUNCTION:BIO
768d2i_X509_fp 775 EXIST::FUNCTION:FP_API
769DES_cbc_cksum 777 EXIST::FUNCTION:DES
770DES_cbc_encrypt 778 EXIST::FUNCTION:DES
771DES_cblock_print_file 779 NOEXIST::FUNCTION:
772DES_cfb64_encrypt 780 EXIST::FUNCTION:DES
773DES_cfb_encrypt 781 EXIST::FUNCTION:DES
774DES_decrypt3 782 EXIST::FUNCTION:DES
775DES_ecb3_encrypt 783 EXIST::FUNCTION:DES
776DES_ecb_encrypt 784 EXIST::FUNCTION:DES
777DES_ede3_cbc_encrypt 785 EXIST::FUNCTION:DES
778DES_ede3_cfb64_encrypt 786 EXIST::FUNCTION:DES
779DES_ede3_ofb64_encrypt 787 EXIST::FUNCTION:DES
780DES_enc_read 788 EXIST::FUNCTION:DES
781DES_enc_write 789 EXIST::FUNCTION:DES
782DES_encrypt1 790 EXIST::FUNCTION:DES
783DES_encrypt2 791 EXIST::FUNCTION:DES
784DES_encrypt3 792 EXIST::FUNCTION:DES
785DES_fcrypt 793 EXIST::FUNCTION:DES
786DES_is_weak_key 794 EXIST::FUNCTION:DES
787DES_key_sched 795 EXIST::FUNCTION:DES
788DES_ncbc_encrypt 796 EXIST::FUNCTION:DES
789DES_ofb64_encrypt 797 EXIST::FUNCTION:DES
790DES_ofb_encrypt 798 EXIST::FUNCTION:DES
791DES_options 799 EXIST::FUNCTION:DES
792DES_pcbc_encrypt 800 EXIST::FUNCTION:DES
793DES_quad_cksum 801 EXIST::FUNCTION:DES
794DES_random_key 802 EXIST::FUNCTION:DES
795_ossl_old_des_random_seed 803 EXIST::FUNCTION:DES
796_ossl_old_des_read_2passwords 804 EXIST::FUNCTION:DES
797_ossl_old_des_read_password 805 EXIST::FUNCTION:DES
798_ossl_old_des_read_pw 806 EXIST::FUNCTION:
799_ossl_old_des_read_pw_string 807 EXIST::FUNCTION:
800DES_set_key 808 EXIST::FUNCTION:DES
801DES_set_odd_parity 809 EXIST::FUNCTION:DES
802DES_string_to_2keys 810 EXIST::FUNCTION:DES
803DES_string_to_key 811 EXIST::FUNCTION:DES
804DES_xcbc_encrypt 812 EXIST::FUNCTION:DES
805DES_xwhite_in2out 813 EXIST::FUNCTION:DES
806fcrypt_body 814 NOEXIST::FUNCTION:
807i2a_ASN1_INTEGER 815 EXIST::FUNCTION:BIO
808i2a_ASN1_OBJECT 816 EXIST::FUNCTION:BIO
809i2a_ASN1_STRING 817 EXIST::FUNCTION:BIO
810i2d_ASN1_BIT_STRING 818 EXIST::FUNCTION:
811i2d_ASN1_BOOLEAN 819 EXIST::FUNCTION:
812i2d_ASN1_HEADER 820 EXIST::FUNCTION:
813i2d_ASN1_IA5STRING 821 EXIST::FUNCTION:
814i2d_ASN1_INTEGER 822 EXIST::FUNCTION:
815i2d_ASN1_OBJECT 823 EXIST::FUNCTION:
816i2d_ASN1_OCTET_STRING 824 EXIST::FUNCTION:
817i2d_ASN1_PRINTABLE 825 EXIST::FUNCTION:
818i2d_ASN1_SET 826 EXIST::FUNCTION:
819i2d_ASN1_TYPE 827 EXIST::FUNCTION:
820i2d_ASN1_UTCTIME 828 EXIST::FUNCTION:
821i2d_ASN1_bytes 829 EXIST::FUNCTION:
822i2d_DHparams 830 EXIST::FUNCTION:DH
823i2d_DSAPrivateKey 831 EXIST::FUNCTION:DSA
824i2d_DSAPrivateKey_bio 832 EXIST::FUNCTION:BIO,DSA
825i2d_DSAPrivateKey_fp 833 EXIST::FUNCTION:DSA,FP_API
826i2d_DSAPublicKey 834 EXIST::FUNCTION:DSA
827i2d_DSAparams 835 EXIST::FUNCTION:DSA
828i2d_NETSCAPE_SPKAC 836 EXIST::FUNCTION:
829i2d_NETSCAPE_SPKI 837 EXIST::FUNCTION:
830i2d_Netscape_RSA 838 EXIST::FUNCTION:RSA
831i2d_PKCS7 839 EXIST::FUNCTION:
832i2d_PKCS7_DIGEST 840 EXIST::FUNCTION:
833i2d_PKCS7_ENCRYPT 841 EXIST::FUNCTION:
834i2d_PKCS7_ENC_CONTENT 842 EXIST::FUNCTION:
835i2d_PKCS7_ENVELOPE 843 EXIST::FUNCTION:
836i2d_PKCS7_ISSUER_AND_SERIAL 844 EXIST::FUNCTION:
837i2d_PKCS7_RECIP_INFO 845 EXIST::FUNCTION:
838i2d_PKCS7_SIGNED 846 EXIST::FUNCTION:
839i2d_PKCS7_SIGNER_INFO 847 EXIST::FUNCTION:
840i2d_PKCS7_SIGN_ENVELOPE 848 EXIST::FUNCTION:
841i2d_PKCS7_bio 849 EXIST::FUNCTION:
842i2d_PKCS7_fp 850 EXIST::FUNCTION:FP_API
843i2d_PrivateKey 851 EXIST::FUNCTION:
844i2d_PublicKey 852 EXIST::FUNCTION:
845i2d_RSAPrivateKey 853 EXIST::FUNCTION:RSA
846i2d_RSAPrivateKey_bio 854 EXIST::FUNCTION:BIO,RSA
847i2d_RSAPrivateKey_fp 855 EXIST::FUNCTION:FP_API,RSA
848i2d_RSAPublicKey 856 EXIST::FUNCTION:RSA
849i2d_X509 857 EXIST::FUNCTION:
850i2d_X509_ALGOR 858 EXIST::FUNCTION:
851i2d_X509_ATTRIBUTE 859 EXIST::FUNCTION:
852i2d_X509_CINF 860 EXIST::FUNCTION:
853i2d_X509_CRL 861 EXIST::FUNCTION:
854i2d_X509_CRL_INFO 862 EXIST::FUNCTION:
855i2d_X509_CRL_bio 863 EXIST::FUNCTION:BIO
856i2d_X509_CRL_fp 864 EXIST::FUNCTION:FP_API
857i2d_X509_EXTENSION 865 EXIST::FUNCTION:
858i2d_X509_NAME 866 EXIST::FUNCTION:
859i2d_X509_NAME_ENTRY 867 EXIST::FUNCTION:
860i2d_X509_PKEY 868 EXIST::FUNCTION:
861i2d_X509_PUBKEY 869 EXIST::FUNCTION:
862i2d_X509_REQ 870 EXIST::FUNCTION:
863i2d_X509_REQ_INFO 871 EXIST::FUNCTION:
864i2d_X509_REQ_bio 872 EXIST::FUNCTION:BIO
865i2d_X509_REQ_fp 873 EXIST::FUNCTION:FP_API
866i2d_X509_REVOKED 874 EXIST::FUNCTION:
867i2d_X509_SIG 875 EXIST::FUNCTION:
868i2d_X509_VAL 876 EXIST::FUNCTION:
869i2d_X509_bio 877 EXIST::FUNCTION:BIO
870i2d_X509_fp 878 EXIST::FUNCTION:FP_API
871idea_cbc_encrypt 879 EXIST::FUNCTION:IDEA
872idea_cfb64_encrypt 880 EXIST::FUNCTION:IDEA
873idea_ecb_encrypt 881 EXIST::FUNCTION:IDEA
874idea_encrypt 882 EXIST::FUNCTION:IDEA
875idea_ofb64_encrypt 883 EXIST::FUNCTION:IDEA
876idea_options 884 EXIST::FUNCTION:IDEA
877idea_set_decrypt_key 885 EXIST::FUNCTION:IDEA
878idea_set_encrypt_key 886 EXIST::FUNCTION:IDEA
879lh_delete 887 EXIST::FUNCTION:
880lh_doall 888 EXIST::FUNCTION:
881lh_doall_arg 889 EXIST::FUNCTION:
882lh_free 890 EXIST::FUNCTION:
883lh_insert 891 EXIST::FUNCTION:
884lh_new 892 EXIST::FUNCTION:
885lh_node_stats 893 EXIST::FUNCTION:FP_API
886lh_node_stats_bio 894 EXIST::FUNCTION:BIO
887lh_node_usage_stats 895 EXIST::FUNCTION:FP_API
888lh_node_usage_stats_bio 896 EXIST::FUNCTION:BIO
889lh_retrieve 897 EXIST::FUNCTION:
890lh_stats 898 EXIST::FUNCTION:FP_API
891lh_stats_bio 899 EXIST::FUNCTION:BIO
892lh_strhash 900 EXIST::FUNCTION:
893sk_delete 901 EXIST::FUNCTION:
894sk_delete_ptr 902 EXIST::FUNCTION:
895sk_dup 903 EXIST::FUNCTION:
896sk_find 904 EXIST::FUNCTION:
897sk_free 905 EXIST::FUNCTION:
898sk_insert 906 EXIST::FUNCTION:
899sk_new 907 EXIST::FUNCTION:
900sk_pop 908 EXIST::FUNCTION:
901sk_pop_free 909 EXIST::FUNCTION:
902sk_push 910 EXIST::FUNCTION:
903sk_set_cmp_func 911 EXIST::FUNCTION:
904sk_shift 912 EXIST::FUNCTION:
905sk_unshift 913 EXIST::FUNCTION:
906sk_zero 914 EXIST::FUNCTION:
907BIO_f_nbio_test 915 EXIST::FUNCTION:
908ASN1_TYPE_get 916 EXIST::FUNCTION:
909ASN1_TYPE_set 917 EXIST::FUNCTION:
910PKCS7_content_free 918 NOEXIST::FUNCTION:
911ERR_load_PKCS7_strings 919 EXIST::FUNCTION:
912X509_find_by_issuer_and_serial 920 EXIST::FUNCTION:
913X509_find_by_subject 921 EXIST::FUNCTION:
914PKCS7_ctrl 927 EXIST::FUNCTION:
915PKCS7_set_type 928 EXIST::FUNCTION:
916PKCS7_set_content 929 EXIST::FUNCTION:
917PKCS7_SIGNER_INFO_set 930 EXIST::FUNCTION:
918PKCS7_add_signer 931 EXIST::FUNCTION:
919PKCS7_add_certificate 932 EXIST::FUNCTION:
920PKCS7_add_crl 933 EXIST::FUNCTION:
921PKCS7_content_new 934 EXIST::FUNCTION:
922PKCS7_dataSign 935 NOEXIST::FUNCTION:
923PKCS7_dataVerify 936 EXIST::FUNCTION:
924PKCS7_dataInit 937 EXIST::FUNCTION:
925PKCS7_add_signature 938 EXIST::FUNCTION:
926PKCS7_cert_from_signer_info 939 EXIST::FUNCTION:
927PKCS7_get_signer_info 940 EXIST::FUNCTION:
928EVP_delete_alias 941 NOEXIST::FUNCTION:
929EVP_mdc2 942 EXIST::FUNCTION:MDC2
930PEM_read_bio_RSAPublicKey 943 EXIST::FUNCTION:RSA
931PEM_write_bio_RSAPublicKey 944 EXIST::FUNCTION:RSA
932d2i_RSAPublicKey_bio 945 EXIST::FUNCTION:BIO,RSA
933i2d_RSAPublicKey_bio 946 EXIST::FUNCTION:BIO,RSA
934PEM_read_RSAPublicKey 947 EXIST:!WIN16:FUNCTION:RSA
935PEM_write_RSAPublicKey 949 EXIST:!WIN16:FUNCTION:RSA
936d2i_RSAPublicKey_fp 952 EXIST::FUNCTION:FP_API,RSA
937i2d_RSAPublicKey_fp 954 EXIST::FUNCTION:FP_API,RSA
938BIO_copy_next_retry 955 EXIST::FUNCTION:
939RSA_flags 956 EXIST::FUNCTION:RSA
940X509_STORE_add_crl 957 EXIST::FUNCTION:
941X509_load_crl_file 958 EXIST::FUNCTION:STDIO
942EVP_rc2_40_cbc 959 EXIST::FUNCTION:RC2
943EVP_rc4_40 960 EXIST::FUNCTION:RC4
944EVP_CIPHER_CTX_init 961 EXIST::FUNCTION:
945HMAC 962 EXIST::FUNCTION:HMAC
946HMAC_Init 963 EXIST::FUNCTION:HMAC
947HMAC_Update 964 EXIST::FUNCTION:HMAC
948HMAC_Final 965 EXIST::FUNCTION:HMAC
949ERR_get_next_error_library 966 EXIST::FUNCTION:
950EVP_PKEY_cmp_parameters 967 EXIST::FUNCTION:
951HMAC_cleanup 968 NOEXIST::FUNCTION:
952BIO_ptr_ctrl 969 EXIST::FUNCTION:
953BIO_new_file_internal 970 EXIST:WIN16:FUNCTION:FP_API
954BIO_new_fp_internal 971 EXIST:WIN16:FUNCTION:FP_API
955BIO_s_file_internal 972 EXIST:WIN16:FUNCTION:FP_API
956BN_BLINDING_convert 973 EXIST::FUNCTION:
957BN_BLINDING_invert 974 EXIST::FUNCTION:
958BN_BLINDING_update 975 EXIST::FUNCTION:
959RSA_blinding_on 977 EXIST::FUNCTION:RSA
960RSA_blinding_off 978 EXIST::FUNCTION:RSA
961i2t_ASN1_OBJECT 979 EXIST::FUNCTION:
962BN_BLINDING_new 980 EXIST::FUNCTION:
963BN_BLINDING_free 981 EXIST::FUNCTION:
964EVP_cast5_cbc 983 EXIST::FUNCTION:CAST
965EVP_cast5_cfb64 984 EXIST::FUNCTION:CAST
966EVP_cast5_ecb 985 EXIST::FUNCTION:CAST
967EVP_cast5_ofb 986 EXIST::FUNCTION:CAST
968BF_decrypt 987 EXIST::FUNCTION:BF
969CAST_set_key 988 EXIST::FUNCTION:CAST
970CAST_encrypt 989 EXIST::FUNCTION:CAST
971CAST_decrypt 990 EXIST::FUNCTION:CAST
972CAST_ecb_encrypt 991 EXIST::FUNCTION:CAST
973CAST_cbc_encrypt 992 EXIST::FUNCTION:CAST
974CAST_cfb64_encrypt 993 EXIST::FUNCTION:CAST
975CAST_ofb64_encrypt 994 EXIST::FUNCTION:CAST
976RC2_decrypt 995 EXIST::FUNCTION:RC2
977OBJ_create_objects 997 EXIST::FUNCTION:
978BN_exp 998 EXIST::FUNCTION:
979BN_mul_word 999 EXIST::FUNCTION:
980BN_sub_word 1000 EXIST::FUNCTION:
981BN_dec2bn 1001 EXIST::FUNCTION:
982BN_bn2dec 1002 EXIST::FUNCTION:
983BIO_ghbn_ctrl 1003 NOEXIST::FUNCTION:
984CRYPTO_free_ex_data 1004 EXIST::FUNCTION:
985CRYPTO_get_ex_data 1005 EXIST::FUNCTION:
986CRYPTO_set_ex_data 1007 EXIST::FUNCTION:
987ERR_load_CRYPTO_strings 1009 EXIST:!OS2,!VMS,!WIN16:FUNCTION:
988ERR_load_CRYPTOlib_strings 1009 EXIST:OS2,VMS,WIN16:FUNCTION:
989EVP_PKEY_bits 1010 EXIST::FUNCTION:
990MD5_Transform 1011 EXIST::FUNCTION:MD5
991SHA1_Transform 1012 EXIST::FUNCTION:SHA,SHA1
992SHA_Transform 1013 EXIST::FUNCTION:SHA,SHA0
993X509_STORE_CTX_get_chain 1014 EXIST::FUNCTION:
994X509_STORE_CTX_get_current_cert 1015 EXIST::FUNCTION:
995X509_STORE_CTX_get_error 1016 EXIST::FUNCTION:
996X509_STORE_CTX_get_error_depth 1017 EXIST::FUNCTION:
997X509_STORE_CTX_get_ex_data 1018 EXIST::FUNCTION:
998X509_STORE_CTX_set_cert 1020 EXIST::FUNCTION:
999X509_STORE_CTX_set_chain 1021 EXIST::FUNCTION:
1000X509_STORE_CTX_set_error 1022 EXIST::FUNCTION:
1001X509_STORE_CTX_set_ex_data 1023 EXIST::FUNCTION:
1002CRYPTO_dup_ex_data 1025 EXIST::FUNCTION:
1003CRYPTO_get_new_lockid 1026 EXIST::FUNCTION:
1004CRYPTO_new_ex_data 1027 EXIST::FUNCTION:
1005RSA_set_ex_data 1028 EXIST::FUNCTION:RSA
1006RSA_get_ex_data 1029 EXIST::FUNCTION:RSA
1007RSA_get_ex_new_index 1030 EXIST::FUNCTION:RSA
1008RSA_padding_add_PKCS1_type_1 1031 EXIST::FUNCTION:RSA
1009RSA_padding_add_PKCS1_type_2 1032 EXIST::FUNCTION:RSA
1010RSA_padding_add_SSLv23 1033 EXIST::FUNCTION:RSA
1011RSA_padding_add_none 1034 EXIST::FUNCTION:RSA
1012RSA_padding_check_PKCS1_type_1 1035 EXIST::FUNCTION:RSA
1013RSA_padding_check_PKCS1_type_2 1036 EXIST::FUNCTION:RSA
1014RSA_padding_check_SSLv23 1037 EXIST::FUNCTION:RSA
1015RSA_padding_check_none 1038 EXIST::FUNCTION:RSA
1016bn_add_words 1039 EXIST::FUNCTION:
1017d2i_Netscape_RSA_2 1040 NOEXIST::FUNCTION:
1018CRYPTO_get_ex_new_index 1041 EXIST::FUNCTION:
1019RIPEMD160_Init 1042 EXIST::FUNCTION:RIPEMD
1020RIPEMD160_Update 1043 EXIST::FUNCTION:RIPEMD
1021RIPEMD160_Final 1044 EXIST::FUNCTION:RIPEMD
1022RIPEMD160 1045 EXIST::FUNCTION:RIPEMD
1023RIPEMD160_Transform 1046 EXIST::FUNCTION:RIPEMD
1024RC5_32_set_key 1047 EXIST::FUNCTION:RC5
1025RC5_32_ecb_encrypt 1048 EXIST::FUNCTION:RC5
1026RC5_32_encrypt 1049 EXIST::FUNCTION:RC5
1027RC5_32_decrypt 1050 EXIST::FUNCTION:RC5
1028RC5_32_cbc_encrypt 1051 EXIST::FUNCTION:RC5
1029RC5_32_cfb64_encrypt 1052 EXIST::FUNCTION:RC5
1030RC5_32_ofb64_encrypt 1053 EXIST::FUNCTION:RC5
1031BN_bn2mpi 1058 EXIST::FUNCTION:
1032BN_mpi2bn 1059 EXIST::FUNCTION:
1033ASN1_BIT_STRING_get_bit 1060 EXIST::FUNCTION:
1034ASN1_BIT_STRING_set_bit 1061 EXIST::FUNCTION:
1035BIO_get_ex_data 1062 EXIST::FUNCTION:
1036BIO_get_ex_new_index 1063 EXIST::FUNCTION:
1037BIO_set_ex_data 1064 EXIST::FUNCTION:
1038X509v3_get_key_usage 1066 NOEXIST::FUNCTION:
1039X509v3_set_key_usage 1067 NOEXIST::FUNCTION:
1040a2i_X509v3_key_usage 1068 NOEXIST::FUNCTION:
1041i2a_X509v3_key_usage 1069 NOEXIST::FUNCTION:
1042EVP_PKEY_decrypt 1070 EXIST::FUNCTION:
1043EVP_PKEY_encrypt 1071 EXIST::FUNCTION:
1044PKCS7_RECIP_INFO_set 1072 EXIST::FUNCTION:
1045PKCS7_add_recipient 1073 EXIST::FUNCTION:
1046PKCS7_add_recipient_info 1074 EXIST::FUNCTION:
1047PKCS7_set_cipher 1075 EXIST::FUNCTION:
1048ASN1_TYPE_get_int_octetstring 1076 EXIST::FUNCTION:
1049ASN1_TYPE_get_octetstring 1077 EXIST::FUNCTION:
1050ASN1_TYPE_set_int_octetstring 1078 EXIST::FUNCTION:
1051ASN1_TYPE_set_octetstring 1079 EXIST::FUNCTION:
1052ASN1_UTCTIME_set_string 1080 EXIST::FUNCTION:
1053ERR_add_error_data 1081 EXIST::FUNCTION:BIO
1054ERR_set_error_data 1082 EXIST::FUNCTION:
1055EVP_CIPHER_asn1_to_param 1083 EXIST::FUNCTION:
1056EVP_CIPHER_param_to_asn1 1084 EXIST::FUNCTION:
1057EVP_CIPHER_get_asn1_iv 1085 EXIST::FUNCTION:
1058EVP_CIPHER_set_asn1_iv 1086 EXIST::FUNCTION:
1059EVP_rc5_32_12_16_cbc 1087 EXIST::FUNCTION:RC5
1060EVP_rc5_32_12_16_cfb64 1088 EXIST::FUNCTION:RC5
1061EVP_rc5_32_12_16_ecb 1089 EXIST::FUNCTION:RC5
1062EVP_rc5_32_12_16_ofb 1090 EXIST::FUNCTION:RC5
1063asn1_add_error 1091 EXIST::FUNCTION:
1064d2i_ASN1_BMPSTRING 1092 EXIST::FUNCTION:
1065i2d_ASN1_BMPSTRING 1093 EXIST::FUNCTION:
1066BIO_f_ber 1094 NOEXIST::FUNCTION:
1067BN_init 1095 EXIST::FUNCTION:
1068COMP_CTX_new 1096 EXIST::FUNCTION:
1069COMP_CTX_free 1097 EXIST::FUNCTION:
1070COMP_CTX_compress_block 1098 NOEXIST::FUNCTION:
1071COMP_CTX_expand_block 1099 NOEXIST::FUNCTION:
1072X509_STORE_CTX_get_ex_new_index 1100 EXIST::FUNCTION:
1073OBJ_NAME_add 1101 EXIST::FUNCTION:
1074BIO_socket_nbio 1102 EXIST::FUNCTION:
1075EVP_rc2_64_cbc 1103 EXIST::FUNCTION:RC2
1076OBJ_NAME_cleanup 1104 EXIST::FUNCTION:
1077OBJ_NAME_get 1105 EXIST::FUNCTION:
1078OBJ_NAME_init 1106 EXIST::FUNCTION:
1079OBJ_NAME_new_index 1107 EXIST::FUNCTION:
1080OBJ_NAME_remove 1108 EXIST::FUNCTION:
1081BN_MONT_CTX_copy 1109 EXIST::FUNCTION:
1082BIO_new_socks4a_connect 1110 NOEXIST::FUNCTION:
1083BIO_s_socks4a_connect 1111 NOEXIST::FUNCTION:
1084PROXY_set_connect_mode 1112 NOEXIST::FUNCTION:
1085RAND_SSLeay 1113 EXIST::FUNCTION:
1086RAND_set_rand_method 1114 EXIST::FUNCTION:
1087RSA_memory_lock 1115 EXIST::FUNCTION:RSA
1088bn_sub_words 1116 EXIST::FUNCTION:
1089bn_mul_normal 1117 NOEXIST::FUNCTION:
1090bn_mul_comba8 1118 NOEXIST::FUNCTION:
1091bn_mul_comba4 1119 NOEXIST::FUNCTION:
1092bn_sqr_normal 1120 NOEXIST::FUNCTION:
1093bn_sqr_comba8 1121 NOEXIST::FUNCTION:
1094bn_sqr_comba4 1122 NOEXIST::FUNCTION:
1095bn_cmp_words 1123 NOEXIST::FUNCTION:
1096bn_mul_recursive 1124 NOEXIST::FUNCTION:
1097bn_mul_part_recursive 1125 NOEXIST::FUNCTION:
1098bn_sqr_recursive 1126 NOEXIST::FUNCTION:
1099bn_mul_low_normal 1127 NOEXIST::FUNCTION:
1100BN_RECP_CTX_init 1128 EXIST::FUNCTION:
1101BN_RECP_CTX_new 1129 EXIST::FUNCTION:
1102BN_RECP_CTX_free 1130 EXIST::FUNCTION:
1103BN_RECP_CTX_set 1131 EXIST::FUNCTION:
1104BN_mod_mul_reciprocal 1132 EXIST::FUNCTION:
1105BN_mod_exp_recp 1133 EXIST::FUNCTION:
1106BN_div_recp 1134 EXIST::FUNCTION:
1107BN_CTX_init 1135 EXIST::FUNCTION:
1108BN_MONT_CTX_init 1136 EXIST::FUNCTION:
1109RAND_get_rand_method 1137 EXIST::FUNCTION:
1110PKCS7_add_attribute 1138 EXIST::FUNCTION:
1111PKCS7_add_signed_attribute 1139 EXIST::FUNCTION:
1112PKCS7_digest_from_attributes 1140 EXIST::FUNCTION:
1113PKCS7_get_attribute 1141 EXIST::FUNCTION:
1114PKCS7_get_issuer_and_serial 1142 EXIST::FUNCTION:
1115PKCS7_get_signed_attribute 1143 EXIST::FUNCTION:
1116COMP_compress_block 1144 EXIST::FUNCTION:
1117COMP_expand_block 1145 EXIST::FUNCTION:
1118COMP_rle 1146 EXIST::FUNCTION:
1119COMP_zlib 1147 EXIST::FUNCTION:
1120ms_time_diff 1148 EXIST::FUNCTION:
1121ms_time_new 1149 EXIST::FUNCTION:
1122ms_time_free 1150 EXIST::FUNCTION:
1123ms_time_cmp 1151 EXIST::FUNCTION:
1124ms_time_get 1152 EXIST::FUNCTION:
1125PKCS7_set_attributes 1153 EXIST::FUNCTION:
1126PKCS7_set_signed_attributes 1154 EXIST::FUNCTION:
1127X509_ATTRIBUTE_create 1155 EXIST::FUNCTION:
1128X509_ATTRIBUTE_dup 1156 EXIST::FUNCTION:
1129ASN1_GENERALIZEDTIME_check 1157 EXIST::FUNCTION:
1130ASN1_GENERALIZEDTIME_print 1158 EXIST::FUNCTION:BIO
1131ASN1_GENERALIZEDTIME_set 1159 EXIST::FUNCTION:
1132ASN1_GENERALIZEDTIME_set_string 1160 EXIST::FUNCTION:
1133ASN1_TIME_print 1161 EXIST::FUNCTION:BIO
1134BASIC_CONSTRAINTS_free 1162 EXIST::FUNCTION:
1135BASIC_CONSTRAINTS_new 1163 EXIST::FUNCTION:
1136ERR_load_X509V3_strings 1164 EXIST::FUNCTION:
1137NETSCAPE_CERT_SEQUENCE_free 1165 EXIST::FUNCTION:
1138NETSCAPE_CERT_SEQUENCE_new 1166 EXIST::FUNCTION:
1139OBJ_txt2obj 1167 EXIST::FUNCTION:
1140PEM_read_NETSCAPE_CERT_SEQUENCE 1168 EXIST:!VMS,!WIN16:FUNCTION:
1141PEM_read_NS_CERT_SEQ 1168 EXIST:VMS:FUNCTION:
1142PEM_read_bio_NETSCAPE_CERT_SEQUENCE 1169 EXIST:!VMS:FUNCTION:
1143PEM_read_bio_NS_CERT_SEQ 1169 EXIST:VMS:FUNCTION:
1144PEM_write_NETSCAPE_CERT_SEQUENCE 1170 EXIST:!VMS,!WIN16:FUNCTION:
1145PEM_write_NS_CERT_SEQ 1170 EXIST:VMS:FUNCTION:
1146PEM_write_bio_NETSCAPE_CERT_SEQUENCE 1171 EXIST:!VMS:FUNCTION:
1147PEM_write_bio_NS_CERT_SEQ 1171 EXIST:VMS:FUNCTION:
1148X509V3_EXT_add 1172 EXIST::FUNCTION:
1149X509V3_EXT_add_alias 1173 EXIST::FUNCTION:
1150X509V3_EXT_add_conf 1174 EXIST::FUNCTION:
1151X509V3_EXT_cleanup 1175 EXIST::FUNCTION:
1152X509V3_EXT_conf 1176 EXIST::FUNCTION:
1153X509V3_EXT_conf_nid 1177 EXIST::FUNCTION:
1154X509V3_EXT_get 1178 EXIST::FUNCTION:
1155X509V3_EXT_get_nid 1179 EXIST::FUNCTION:
1156X509V3_EXT_print 1180 EXIST::FUNCTION:
1157X509V3_EXT_print_fp 1181 EXIST::FUNCTION:
1158X509V3_add_standard_extensions 1182 EXIST::FUNCTION:
1159X509V3_add_value 1183 EXIST::FUNCTION:
1160X509V3_add_value_bool 1184 EXIST::FUNCTION:
1161X509V3_add_value_int 1185 EXIST::FUNCTION:
1162X509V3_conf_free 1186 EXIST::FUNCTION:
1163X509V3_get_value_bool 1187 EXIST::FUNCTION:
1164X509V3_get_value_int 1188 EXIST::FUNCTION:
1165X509V3_parse_list 1189 EXIST::FUNCTION:
1166d2i_ASN1_GENERALIZEDTIME 1190 EXIST::FUNCTION:
1167d2i_ASN1_TIME 1191 EXIST::FUNCTION:
1168d2i_BASIC_CONSTRAINTS 1192 EXIST::FUNCTION:
1169d2i_NETSCAPE_CERT_SEQUENCE 1193 EXIST::FUNCTION:
1170d2i_ext_ku 1194 NOEXIST::FUNCTION:
1171ext_ku_free 1195 NOEXIST::FUNCTION:
1172ext_ku_new 1196 NOEXIST::FUNCTION:
1173i2d_ASN1_GENERALIZEDTIME 1197 EXIST::FUNCTION:
1174i2d_ASN1_TIME 1198 EXIST::FUNCTION:
1175i2d_BASIC_CONSTRAINTS 1199 EXIST::FUNCTION:
1176i2d_NETSCAPE_CERT_SEQUENCE 1200 EXIST::FUNCTION:
1177i2d_ext_ku 1201 NOEXIST::FUNCTION:
1178EVP_MD_CTX_copy 1202 EXIST::FUNCTION:
1179i2d_ASN1_ENUMERATED 1203 EXIST::FUNCTION:
1180d2i_ASN1_ENUMERATED 1204 EXIST::FUNCTION:
1181ASN1_ENUMERATED_set 1205 EXIST::FUNCTION:
1182ASN1_ENUMERATED_get 1206 EXIST::FUNCTION:
1183BN_to_ASN1_ENUMERATED 1207 EXIST::FUNCTION:
1184ASN1_ENUMERATED_to_BN 1208 EXIST::FUNCTION:
1185i2a_ASN1_ENUMERATED 1209 EXIST::FUNCTION:BIO
1186a2i_ASN1_ENUMERATED 1210 EXIST::FUNCTION:BIO
1187i2d_GENERAL_NAME 1211 EXIST::FUNCTION:
1188d2i_GENERAL_NAME 1212 EXIST::FUNCTION:
1189GENERAL_NAME_new 1213 EXIST::FUNCTION:
1190GENERAL_NAME_free 1214 EXIST::FUNCTION:
1191GENERAL_NAMES_new 1215 EXIST::FUNCTION:
1192GENERAL_NAMES_free 1216 EXIST::FUNCTION:
1193d2i_GENERAL_NAMES 1217 EXIST::FUNCTION:
1194i2d_GENERAL_NAMES 1218 EXIST::FUNCTION:
1195i2v_GENERAL_NAMES 1219 EXIST::FUNCTION:
1196i2s_ASN1_OCTET_STRING 1220 EXIST::FUNCTION:
1197s2i_ASN1_OCTET_STRING 1221 EXIST::FUNCTION:
1198X509V3_EXT_check_conf 1222 NOEXIST::FUNCTION:
1199hex_to_string 1223 EXIST::FUNCTION:
1200string_to_hex 1224 EXIST::FUNCTION:
1201DES_ede3_cbcm_encrypt 1225 EXIST::FUNCTION:DES
1202RSA_padding_add_PKCS1_OAEP 1226 EXIST::FUNCTION:RSA
1203RSA_padding_check_PKCS1_OAEP 1227 EXIST::FUNCTION:RSA
1204X509_CRL_print_fp 1228 EXIST::FUNCTION:FP_API
1205X509_CRL_print 1229 EXIST::FUNCTION:BIO
1206i2v_GENERAL_NAME 1230 EXIST::FUNCTION:
1207v2i_GENERAL_NAME 1231 EXIST::FUNCTION:
1208i2d_PKEY_USAGE_PERIOD 1232 EXIST::FUNCTION:
1209d2i_PKEY_USAGE_PERIOD 1233 EXIST::FUNCTION:
1210PKEY_USAGE_PERIOD_new 1234 EXIST::FUNCTION:
1211PKEY_USAGE_PERIOD_free 1235 EXIST::FUNCTION:
1212v2i_GENERAL_NAMES 1236 EXIST::FUNCTION:
1213i2s_ASN1_INTEGER 1237 EXIST::FUNCTION:
1214X509V3_EXT_d2i 1238 EXIST::FUNCTION:
1215name_cmp 1239 EXIST::FUNCTION:
1216str_dup 1240 NOEXIST::FUNCTION:
1217i2s_ASN1_ENUMERATED 1241 EXIST::FUNCTION:
1218i2s_ASN1_ENUMERATED_TABLE 1242 EXIST::FUNCTION:
1219BIO_s_log 1243 EXIST:!OS2,!WIN16,!WIN32,!macintosh:FUNCTION:
1220BIO_f_reliable 1244 EXIST::FUNCTION:BIO
1221PKCS7_dataFinal 1245 EXIST::FUNCTION:
1222PKCS7_dataDecode 1246 EXIST::FUNCTION:
1223X509V3_EXT_CRL_add_conf 1247 EXIST::FUNCTION:
1224BN_set_params 1248 EXIST::FUNCTION:
1225BN_get_params 1249 EXIST::FUNCTION:
1226BIO_get_ex_num 1250 NOEXIST::FUNCTION:
1227BIO_set_ex_free_func 1251 NOEXIST::FUNCTION:
1228EVP_ripemd160 1252 EXIST::FUNCTION:RIPEMD
1229ASN1_TIME_set 1253 EXIST::FUNCTION:
1230i2d_AUTHORITY_KEYID 1254 EXIST::FUNCTION:
1231d2i_AUTHORITY_KEYID 1255 EXIST::FUNCTION:
1232AUTHORITY_KEYID_new 1256 EXIST::FUNCTION:
1233AUTHORITY_KEYID_free 1257 EXIST::FUNCTION:
1234ASN1_seq_unpack 1258 EXIST::FUNCTION:
1235ASN1_seq_pack 1259 EXIST::FUNCTION:
1236ASN1_unpack_string 1260 EXIST::FUNCTION:
1237ASN1_pack_string 1261 EXIST::FUNCTION:
1238PKCS12_pack_safebag 1262 NOEXIST::FUNCTION:
1239PKCS12_MAKE_KEYBAG 1263 EXIST::FUNCTION:
1240PKCS8_encrypt 1264 EXIST::FUNCTION:
1241PKCS12_MAKE_SHKEYBAG 1265 EXIST::FUNCTION:
1242PKCS12_pack_p7data 1266 EXIST::FUNCTION:
1243PKCS12_pack_p7encdata 1267 EXIST::FUNCTION:
1244PKCS12_add_localkeyid 1268 EXIST::FUNCTION:
1245PKCS12_add_friendlyname_asc 1269 EXIST::FUNCTION:
1246PKCS12_add_friendlyname_uni 1270 EXIST::FUNCTION:
1247PKCS12_get_friendlyname 1271 EXIST::FUNCTION:
1248PKCS12_pbe_crypt 1272 EXIST::FUNCTION:
1249PKCS12_decrypt_d2i 1273 NOEXIST::FUNCTION:
1250PKCS12_i2d_encrypt 1274 NOEXIST::FUNCTION:
1251PKCS12_init 1275 EXIST::FUNCTION:
1252PKCS12_key_gen_asc 1276 EXIST::FUNCTION:
1253PKCS12_key_gen_uni 1277 EXIST::FUNCTION:
1254PKCS12_gen_mac 1278 EXIST::FUNCTION:
1255PKCS12_verify_mac 1279 EXIST::FUNCTION:
1256PKCS12_set_mac 1280 EXIST::FUNCTION:
1257PKCS12_setup_mac 1281 EXIST::FUNCTION:
1258asc2uni 1282 EXIST::FUNCTION:
1259uni2asc 1283 EXIST::FUNCTION:
1260i2d_PKCS12_BAGS 1284 EXIST::FUNCTION:
1261PKCS12_BAGS_new 1285 EXIST::FUNCTION:
1262d2i_PKCS12_BAGS 1286 EXIST::FUNCTION:
1263PKCS12_BAGS_free 1287 EXIST::FUNCTION:
1264i2d_PKCS12 1288 EXIST::FUNCTION:
1265d2i_PKCS12 1289 EXIST::FUNCTION:
1266PKCS12_new 1290 EXIST::FUNCTION:
1267PKCS12_free 1291 EXIST::FUNCTION:
1268i2d_PKCS12_MAC_DATA 1292 EXIST::FUNCTION:
1269PKCS12_MAC_DATA_new 1293 EXIST::FUNCTION:
1270d2i_PKCS12_MAC_DATA 1294 EXIST::FUNCTION:
1271PKCS12_MAC_DATA_free 1295 EXIST::FUNCTION:
1272i2d_PKCS12_SAFEBAG 1296 EXIST::FUNCTION:
1273PKCS12_SAFEBAG_new 1297 EXIST::FUNCTION:
1274d2i_PKCS12_SAFEBAG 1298 EXIST::FUNCTION:
1275PKCS12_SAFEBAG_free 1299 EXIST::FUNCTION:
1276ERR_load_PKCS12_strings 1300 EXIST::FUNCTION:
1277PKCS12_PBE_add 1301 EXIST::FUNCTION:
1278PKCS8_add_keyusage 1302 EXIST::FUNCTION:
1279PKCS12_get_attr_gen 1303 EXIST::FUNCTION:
1280PKCS12_parse 1304 EXIST::FUNCTION:
1281PKCS12_create 1305 EXIST::FUNCTION:
1282i2d_PKCS12_bio 1306 EXIST::FUNCTION:
1283i2d_PKCS12_fp 1307 EXIST::FUNCTION:
1284d2i_PKCS12_bio 1308 EXIST::FUNCTION:
1285d2i_PKCS12_fp 1309 EXIST::FUNCTION:
1286i2d_PBEPARAM 1310 EXIST::FUNCTION:
1287PBEPARAM_new 1311 EXIST::FUNCTION:
1288d2i_PBEPARAM 1312 EXIST::FUNCTION:
1289PBEPARAM_free 1313 EXIST::FUNCTION:
1290i2d_PKCS8_PRIV_KEY_INFO 1314 EXIST::FUNCTION:
1291PKCS8_PRIV_KEY_INFO_new 1315 EXIST::FUNCTION:
1292d2i_PKCS8_PRIV_KEY_INFO 1316 EXIST::FUNCTION:
1293PKCS8_PRIV_KEY_INFO_free 1317 EXIST::FUNCTION:
1294EVP_PKCS82PKEY 1318 EXIST::FUNCTION:
1295EVP_PKEY2PKCS8 1319 EXIST::FUNCTION:
1296PKCS8_set_broken 1320 EXIST::FUNCTION:
1297EVP_PBE_ALGOR_CipherInit 1321 NOEXIST::FUNCTION:
1298EVP_PBE_alg_add 1322 EXIST::FUNCTION:
1299PKCS5_pbe_set 1323 EXIST::FUNCTION:
1300EVP_PBE_cleanup 1324 EXIST::FUNCTION:
1301i2d_SXNET 1325 EXIST::FUNCTION:
1302d2i_SXNET 1326 EXIST::FUNCTION:
1303SXNET_new 1327 EXIST::FUNCTION:
1304SXNET_free 1328 EXIST::FUNCTION:
1305i2d_SXNETID 1329 EXIST::FUNCTION:
1306d2i_SXNETID 1330 EXIST::FUNCTION:
1307SXNETID_new 1331 EXIST::FUNCTION:
1308SXNETID_free 1332 EXIST::FUNCTION:
1309DSA_SIG_new 1333 EXIST::FUNCTION:DSA
1310DSA_SIG_free 1334 EXIST::FUNCTION:DSA
1311DSA_do_sign 1335 EXIST::FUNCTION:DSA
1312DSA_do_verify 1336 EXIST::FUNCTION:DSA
1313d2i_DSA_SIG 1337 EXIST::FUNCTION:DSA
1314i2d_DSA_SIG 1338 EXIST::FUNCTION:DSA
1315i2d_ASN1_VISIBLESTRING 1339 EXIST::FUNCTION:
1316d2i_ASN1_VISIBLESTRING 1340 EXIST::FUNCTION:
1317i2d_ASN1_UTF8STRING 1341 EXIST::FUNCTION:
1318d2i_ASN1_UTF8STRING 1342 EXIST::FUNCTION:
1319i2d_DIRECTORYSTRING 1343 EXIST::FUNCTION:
1320d2i_DIRECTORYSTRING 1344 EXIST::FUNCTION:
1321i2d_DISPLAYTEXT 1345 EXIST::FUNCTION:
1322d2i_DISPLAYTEXT 1346 EXIST::FUNCTION:
1323d2i_ASN1_SET_OF_X509 1379 NOEXIST::FUNCTION:
1324i2d_ASN1_SET_OF_X509 1380 NOEXIST::FUNCTION:
1325i2d_PBKDF2PARAM 1397 EXIST::FUNCTION:
1326PBKDF2PARAM_new 1398 EXIST::FUNCTION:
1327d2i_PBKDF2PARAM 1399 EXIST::FUNCTION:
1328PBKDF2PARAM_free 1400 EXIST::FUNCTION:
1329i2d_PBE2PARAM 1401 EXIST::FUNCTION:
1330PBE2PARAM_new 1402 EXIST::FUNCTION:
1331d2i_PBE2PARAM 1403 EXIST::FUNCTION:
1332PBE2PARAM_free 1404 EXIST::FUNCTION:
1333d2i_ASN1_SET_OF_GENERAL_NAME 1421 NOEXIST::FUNCTION:
1334i2d_ASN1_SET_OF_GENERAL_NAME 1422 NOEXIST::FUNCTION:
1335d2i_ASN1_SET_OF_SXNETID 1439 NOEXIST::FUNCTION:
1336i2d_ASN1_SET_OF_SXNETID 1440 NOEXIST::FUNCTION:
1337d2i_ASN1_SET_OF_POLICYQUALINFO 1457 NOEXIST::FUNCTION:
1338i2d_ASN1_SET_OF_POLICYQUALINFO 1458 NOEXIST::FUNCTION:
1339d2i_ASN1_SET_OF_POLICYINFO 1475 NOEXIST::FUNCTION:
1340i2d_ASN1_SET_OF_POLICYINFO 1476 NOEXIST::FUNCTION:
1341SXNET_add_id_asc 1477 EXIST::FUNCTION:
1342SXNET_add_id_ulong 1478 EXIST::FUNCTION:
1343SXNET_add_id_INTEGER 1479 EXIST::FUNCTION:
1344SXNET_get_id_asc 1480 EXIST::FUNCTION:
1345SXNET_get_id_ulong 1481 EXIST::FUNCTION:
1346SXNET_get_id_INTEGER 1482 EXIST::FUNCTION:
1347X509V3_set_conf_lhash 1483 EXIST::FUNCTION:
1348i2d_CERTIFICATEPOLICIES 1484 EXIST::FUNCTION:
1349CERTIFICATEPOLICIES_new 1485 EXIST::FUNCTION:
1350CERTIFICATEPOLICIES_free 1486 EXIST::FUNCTION:
1351d2i_CERTIFICATEPOLICIES 1487 EXIST::FUNCTION:
1352i2d_POLICYINFO 1488 EXIST::FUNCTION:
1353POLICYINFO_new 1489 EXIST::FUNCTION:
1354d2i_POLICYINFO 1490 EXIST::FUNCTION:
1355POLICYINFO_free 1491 EXIST::FUNCTION:
1356i2d_POLICYQUALINFO 1492 EXIST::FUNCTION:
1357POLICYQUALINFO_new 1493 EXIST::FUNCTION:
1358d2i_POLICYQUALINFO 1494 EXIST::FUNCTION:
1359POLICYQUALINFO_free 1495 EXIST::FUNCTION:
1360i2d_USERNOTICE 1496 EXIST::FUNCTION:
1361USERNOTICE_new 1497 EXIST::FUNCTION:
1362d2i_USERNOTICE 1498 EXIST::FUNCTION:
1363USERNOTICE_free 1499 EXIST::FUNCTION:
1364i2d_NOTICEREF 1500 EXIST::FUNCTION:
1365NOTICEREF_new 1501 EXIST::FUNCTION:
1366d2i_NOTICEREF 1502 EXIST::FUNCTION:
1367NOTICEREF_free 1503 EXIST::FUNCTION:
1368X509V3_get_string 1504 EXIST::FUNCTION:
1369X509V3_get_section 1505 EXIST::FUNCTION:
1370X509V3_string_free 1506 EXIST::FUNCTION:
1371X509V3_section_free 1507 EXIST::FUNCTION:
1372X509V3_set_ctx 1508 EXIST::FUNCTION:
1373s2i_ASN1_INTEGER 1509 EXIST::FUNCTION:
1374CRYPTO_set_locked_mem_functions 1510 EXIST::FUNCTION:
1375CRYPTO_get_locked_mem_functions 1511 EXIST::FUNCTION:
1376CRYPTO_malloc_locked 1512 EXIST::FUNCTION:
1377CRYPTO_free_locked 1513 EXIST::FUNCTION:
1378BN_mod_exp2_mont 1514 EXIST::FUNCTION:
1379ERR_get_error_line_data 1515 EXIST::FUNCTION:
1380ERR_peek_error_line_data 1516 EXIST::FUNCTION:
1381PKCS12_PBE_keyivgen 1517 EXIST::FUNCTION:
1382X509_ALGOR_dup 1518 EXIST::FUNCTION:
1383d2i_ASN1_SET_OF_DIST_POINT 1535 NOEXIST::FUNCTION:
1384i2d_ASN1_SET_OF_DIST_POINT 1536 NOEXIST::FUNCTION:
1385i2d_CRL_DIST_POINTS 1537 EXIST::FUNCTION:
1386CRL_DIST_POINTS_new 1538 EXIST::FUNCTION:
1387CRL_DIST_POINTS_free 1539 EXIST::FUNCTION:
1388d2i_CRL_DIST_POINTS 1540 EXIST::FUNCTION:
1389i2d_DIST_POINT 1541 EXIST::FUNCTION:
1390DIST_POINT_new 1542 EXIST::FUNCTION:
1391d2i_DIST_POINT 1543 EXIST::FUNCTION:
1392DIST_POINT_free 1544 EXIST::FUNCTION:
1393i2d_DIST_POINT_NAME 1545 EXIST::FUNCTION:
1394DIST_POINT_NAME_new 1546 EXIST::FUNCTION:
1395DIST_POINT_NAME_free 1547 EXIST::FUNCTION:
1396d2i_DIST_POINT_NAME 1548 EXIST::FUNCTION:
1397X509V3_add_value_uchar 1549 EXIST::FUNCTION:
1398d2i_ASN1_SET_OF_X509_ATTRIBUTE 1555 NOEXIST::FUNCTION:
1399i2d_ASN1_SET_OF_ASN1_TYPE 1560 NOEXIST::FUNCTION:
1400d2i_ASN1_SET_OF_X509_EXTENSION 1567 NOEXIST::FUNCTION:
1401d2i_ASN1_SET_OF_X509_NAME_ENTRY 1574 NOEXIST::FUNCTION:
1402d2i_ASN1_SET_OF_ASN1_TYPE 1589 NOEXIST::FUNCTION:
1403i2d_ASN1_SET_OF_X509_ATTRIBUTE 1615 NOEXIST::FUNCTION:
1404i2d_ASN1_SET_OF_X509_EXTENSION 1624 NOEXIST::FUNCTION:
1405i2d_ASN1_SET_OF_X509_NAME_ENTRY 1633 NOEXIST::FUNCTION:
1406X509V3_EXT_i2d 1646 EXIST::FUNCTION:
1407X509V3_EXT_val_prn 1647 EXIST::FUNCTION:
1408X509V3_EXT_add_list 1648 EXIST::FUNCTION:
1409EVP_CIPHER_type 1649 EXIST::FUNCTION:
1410EVP_PBE_CipherInit 1650 EXIST::FUNCTION:
1411X509V3_add_value_bool_nf 1651 EXIST::FUNCTION:
1412d2i_ASN1_UINTEGER 1652 EXIST::FUNCTION:
1413sk_value 1653 EXIST::FUNCTION:
1414sk_num 1654 EXIST::FUNCTION:
1415sk_set 1655 EXIST::FUNCTION:
1416i2d_ASN1_SET_OF_X509_REVOKED 1661 NOEXIST::FUNCTION:
1417sk_sort 1671 EXIST::FUNCTION:
1418d2i_ASN1_SET_OF_X509_REVOKED 1674 NOEXIST::FUNCTION:
1419i2d_ASN1_SET_OF_X509_ALGOR 1682 NOEXIST::FUNCTION:
1420i2d_ASN1_SET_OF_X509_CRL 1685 NOEXIST::FUNCTION:
1421d2i_ASN1_SET_OF_X509_ALGOR 1696 NOEXIST::FUNCTION:
1422d2i_ASN1_SET_OF_X509_CRL 1702 NOEXIST::FUNCTION:
1423i2d_ASN1_SET_OF_PKCS7_SIGNER_INFO 1723 NOEXIST::FUNCTION:
1424i2d_ASN1_SET_OF_PKCS7_RECIP_INFO 1738 NOEXIST::FUNCTION:
1425d2i_ASN1_SET_OF_PKCS7_SIGNER_INFO 1748 NOEXIST::FUNCTION:
1426d2i_ASN1_SET_OF_PKCS7_RECIP_INFO 1753 NOEXIST::FUNCTION:
1427PKCS5_PBE_add 1775 EXIST::FUNCTION:
1428PEM_write_bio_PKCS8 1776 EXIST::FUNCTION:
1429i2d_PKCS8_fp 1777 EXIST::FUNCTION:FP_API
1430PEM_read_bio_PKCS8_PRIV_KEY_INFO 1778 EXIST:!VMS:FUNCTION:
1431PEM_read_bio_P8_PRIV_KEY_INFO 1778 EXIST:VMS:FUNCTION:
1432d2i_PKCS8_bio 1779 EXIST::FUNCTION:BIO
1433d2i_PKCS8_PRIV_KEY_INFO_fp 1780 EXIST::FUNCTION:FP_API
1434PEM_write_bio_PKCS8_PRIV_KEY_INFO 1781 EXIST:!VMS:FUNCTION:
1435PEM_write_bio_P8_PRIV_KEY_INFO 1781 EXIST:VMS:FUNCTION:
1436PEM_read_PKCS8 1782 EXIST:!WIN16:FUNCTION:
1437d2i_PKCS8_PRIV_KEY_INFO_bio 1783 EXIST::FUNCTION:BIO
1438d2i_PKCS8_fp 1784 EXIST::FUNCTION:FP_API
1439PEM_write_PKCS8 1785 EXIST:!WIN16:FUNCTION:
1440PEM_read_PKCS8_PRIV_KEY_INFO 1786 EXIST:!VMS,!WIN16:FUNCTION:
1441PEM_read_P8_PRIV_KEY_INFO 1786 EXIST:VMS:FUNCTION:
1442PEM_read_bio_PKCS8 1787 EXIST::FUNCTION:
1443PEM_write_PKCS8_PRIV_KEY_INFO 1788 EXIST:!VMS,!WIN16:FUNCTION:
1444PEM_write_P8_PRIV_KEY_INFO 1788 EXIST:VMS:FUNCTION:
1445PKCS5_PBE_keyivgen 1789 EXIST::FUNCTION:
1446i2d_PKCS8_bio 1790 EXIST::FUNCTION:BIO
1447i2d_PKCS8_PRIV_KEY_INFO_fp 1791 EXIST::FUNCTION:FP_API
1448i2d_PKCS8_PRIV_KEY_INFO_bio 1792 EXIST::FUNCTION:BIO
1449BIO_s_bio 1793 EXIST::FUNCTION:
1450PKCS5_pbe2_set 1794 EXIST::FUNCTION:
1451PKCS5_PBKDF2_HMAC_SHA1 1795 EXIST::FUNCTION:
1452PKCS5_v2_PBE_keyivgen 1796 EXIST::FUNCTION:
1453PEM_write_bio_PKCS8PrivateKey 1797 EXIST::FUNCTION:
1454PEM_write_PKCS8PrivateKey 1798 EXIST::FUNCTION:
1455BIO_ctrl_get_read_request 1799 EXIST::FUNCTION:
1456BIO_ctrl_pending 1800 EXIST::FUNCTION:
1457BIO_ctrl_wpending 1801 EXIST::FUNCTION:
1458BIO_new_bio_pair 1802 EXIST::FUNCTION:
1459BIO_ctrl_get_write_guarantee 1803 EXIST::FUNCTION:
1460CRYPTO_num_locks 1804 EXIST::FUNCTION:
1461CONF_load_bio 1805 EXIST::FUNCTION:
1462CONF_load_fp 1806 EXIST::FUNCTION:FP_API
1463i2d_ASN1_SET_OF_ASN1_OBJECT 1837 NOEXIST::FUNCTION:
1464d2i_ASN1_SET_OF_ASN1_OBJECT 1844 NOEXIST::FUNCTION:
1465PKCS7_signatureVerify 1845 EXIST::FUNCTION:
1466RSA_set_method 1846 EXIST::FUNCTION:RSA
1467RSA_get_method 1847 EXIST::FUNCTION:RSA
1468RSA_get_default_method 1848 EXIST::FUNCTION:RSA
1469RSA_check_key 1869 EXIST::FUNCTION:RSA
1470OBJ_obj2txt 1870 EXIST::FUNCTION:
1471DSA_dup_DH 1871 EXIST::FUNCTION:DH,DSA
1472X509_REQ_get_extensions 1872 EXIST::FUNCTION:
1473X509_REQ_set_extension_nids 1873 EXIST::FUNCTION:
1474BIO_nwrite 1874 EXIST::FUNCTION:
1475X509_REQ_extension_nid 1875 EXIST::FUNCTION:
1476BIO_nread 1876 EXIST::FUNCTION:
1477X509_REQ_get_extension_nids 1877 EXIST::FUNCTION:
1478BIO_nwrite0 1878 EXIST::FUNCTION:
1479X509_REQ_add_extensions_nid 1879 EXIST::FUNCTION:
1480BIO_nread0 1880 EXIST::FUNCTION:
1481X509_REQ_add_extensions 1881 EXIST::FUNCTION:
1482BIO_new_mem_buf 1882 EXIST::FUNCTION:
1483DH_set_ex_data 1883 EXIST::FUNCTION:DH
1484DH_set_method 1884 EXIST::FUNCTION:DH
1485DSA_OpenSSL 1885 EXIST::FUNCTION:DSA
1486DH_get_ex_data 1886 EXIST::FUNCTION:DH
1487DH_get_ex_new_index 1887 EXIST::FUNCTION:DH
1488DSA_new_method 1888 EXIST::FUNCTION:DSA
1489DH_new_method 1889 EXIST::FUNCTION:DH
1490DH_OpenSSL 1890 EXIST::FUNCTION:DH
1491DSA_get_ex_new_index 1891 EXIST::FUNCTION:DSA
1492DH_get_default_method 1892 EXIST::FUNCTION:DH
1493DSA_set_ex_data 1893 EXIST::FUNCTION:DSA
1494DH_set_default_method 1894 EXIST::FUNCTION:DH
1495DSA_get_ex_data 1895 EXIST::FUNCTION:DSA
1496X509V3_EXT_REQ_add_conf 1896 EXIST::FUNCTION:
1497NETSCAPE_SPKI_print 1897 EXIST::FUNCTION:EVP
1498NETSCAPE_SPKI_set_pubkey 1898 EXIST::FUNCTION:EVP
1499NETSCAPE_SPKI_b64_encode 1899 EXIST::FUNCTION:EVP
1500NETSCAPE_SPKI_get_pubkey 1900 EXIST::FUNCTION:EVP
1501NETSCAPE_SPKI_b64_decode 1901 EXIST::FUNCTION:EVP
1502UTF8_putc 1902 EXIST::FUNCTION:
1503UTF8_getc 1903 EXIST::FUNCTION:
1504RSA_null_method 1904 EXIST::FUNCTION:RSA
1505ASN1_tag2str 1905 EXIST::FUNCTION:
1506BIO_ctrl_reset_read_request 1906 EXIST::FUNCTION:
1507DISPLAYTEXT_new 1907 EXIST::FUNCTION:
1508ASN1_GENERALIZEDTIME_free 1908 EXIST::FUNCTION:
1509X509_REVOKED_get_ext_d2i 1909 EXIST::FUNCTION:
1510X509_set_ex_data 1910 EXIST::FUNCTION:
1511X509_reject_set_bit_asc 1911 NOEXIST::FUNCTION:
1512X509_NAME_add_entry_by_txt 1912 EXIST::FUNCTION:
1513X509_NAME_add_entry_by_NID 1914 EXIST::FUNCTION:
1514X509_PURPOSE_get0 1915 EXIST::FUNCTION:
1515PEM_read_X509_AUX 1917 EXIST:!WIN16:FUNCTION:
1516d2i_AUTHORITY_INFO_ACCESS 1918 EXIST::FUNCTION:
1517PEM_write_PUBKEY 1921 EXIST:!WIN16:FUNCTION:
1518ACCESS_DESCRIPTION_new 1925 EXIST::FUNCTION:
1519X509_CERT_AUX_free 1926 EXIST::FUNCTION:
1520d2i_ACCESS_DESCRIPTION 1927 EXIST::FUNCTION:
1521X509_trust_clear 1928 EXIST::FUNCTION:
1522X509_TRUST_add 1931 EXIST::FUNCTION:
1523ASN1_VISIBLESTRING_new 1932 EXIST::FUNCTION:
1524X509_alias_set1 1933 EXIST::FUNCTION:
1525ASN1_PRINTABLESTRING_free 1934 EXIST::FUNCTION:
1526EVP_PKEY_get1_DSA 1935 EXIST::FUNCTION:DSA
1527ASN1_BMPSTRING_new 1936 EXIST::FUNCTION:
1528ASN1_mbstring_copy 1937 EXIST::FUNCTION:
1529ASN1_UTF8STRING_new 1938 EXIST::FUNCTION:
1530DSA_get_default_method 1941 EXIST::FUNCTION:DSA
1531i2d_ASN1_SET_OF_ACCESS_DESCRIPTION 1945 NOEXIST::FUNCTION:
1532ASN1_T61STRING_free 1946 EXIST::FUNCTION:
1533DSA_set_method 1949 EXIST::FUNCTION:DSA
1534X509_get_ex_data 1950 EXIST::FUNCTION:
1535ASN1_STRING_type 1951 EXIST::FUNCTION:
1536X509_PURPOSE_get_by_sname 1952 EXIST::FUNCTION:
1537ASN1_TIME_free 1954 EXIST::FUNCTION:
1538ASN1_OCTET_STRING_cmp 1955 EXIST::FUNCTION:
1539ASN1_BIT_STRING_new 1957 EXIST::FUNCTION:
1540X509_get_ext_d2i 1958 EXIST::FUNCTION:
1541PEM_read_bio_X509_AUX 1959 EXIST::FUNCTION:
1542ASN1_STRING_set_default_mask_asc 1960 EXIST:!VMS:FUNCTION:
1543ASN1_STRING_set_def_mask_asc 1960 EXIST:VMS:FUNCTION:
1544PEM_write_bio_RSA_PUBKEY 1961 EXIST::FUNCTION:RSA
1545ASN1_INTEGER_cmp 1963 EXIST::FUNCTION:
1546d2i_RSA_PUBKEY_fp 1964 EXIST::FUNCTION:FP_API,RSA
1547X509_trust_set_bit_asc 1967 NOEXIST::FUNCTION:
1548PEM_write_bio_DSA_PUBKEY 1968 EXIST::FUNCTION:DSA
1549X509_STORE_CTX_free 1969 EXIST::FUNCTION:
1550EVP_PKEY_set1_DSA 1970 EXIST::FUNCTION:DSA
1551i2d_DSA_PUBKEY_fp 1971 EXIST::FUNCTION:DSA,FP_API
1552X509_load_cert_crl_file 1972 EXIST::FUNCTION:STDIO
1553ASN1_TIME_new 1973 EXIST::FUNCTION:
1554i2d_RSA_PUBKEY 1974 EXIST::FUNCTION:RSA
1555X509_STORE_CTX_purpose_inherit 1976 EXIST::FUNCTION:
1556PEM_read_RSA_PUBKEY 1977 EXIST:!WIN16:FUNCTION:RSA
1557d2i_X509_AUX 1980 EXIST::FUNCTION:
1558i2d_DSA_PUBKEY 1981 EXIST::FUNCTION:DSA
1559X509_CERT_AUX_print 1982 EXIST::FUNCTION:BIO
1560PEM_read_DSA_PUBKEY 1984 EXIST:!WIN16:FUNCTION:DSA
1561i2d_RSA_PUBKEY_bio 1985 EXIST::FUNCTION:BIO,RSA
1562ASN1_BIT_STRING_num_asc 1986 EXIST::FUNCTION:
1563i2d_PUBKEY 1987 EXIST::FUNCTION:
1564ASN1_UTCTIME_free 1988 EXIST::FUNCTION:
1565DSA_set_default_method 1989 EXIST::FUNCTION:DSA
1566X509_PURPOSE_get_by_id 1990 EXIST::FUNCTION:
1567ACCESS_DESCRIPTION_free 1994 EXIST::FUNCTION:
1568PEM_read_bio_PUBKEY 1995 EXIST::FUNCTION:
1569ASN1_STRING_set_by_NID 1996 EXIST::FUNCTION:
1570X509_PURPOSE_get_id 1997 EXIST::FUNCTION:
1571DISPLAYTEXT_free 1998 EXIST::FUNCTION:
1572OTHERNAME_new 1999 EXIST::FUNCTION:
1573X509_CERT_AUX_new 2001 EXIST::FUNCTION:
1574X509_TRUST_cleanup 2007 EXIST::FUNCTION:
1575X509_NAME_add_entry_by_OBJ 2008 EXIST::FUNCTION:
1576X509_CRL_get_ext_d2i 2009 EXIST::FUNCTION:
1577X509_PURPOSE_get0_name 2011 EXIST::FUNCTION:
1578PEM_read_PUBKEY 2012 EXIST:!WIN16:FUNCTION:
1579i2d_DSA_PUBKEY_bio 2014 EXIST::FUNCTION:BIO,DSA
1580i2d_OTHERNAME 2015 EXIST::FUNCTION:
1581ASN1_OCTET_STRING_free 2016 EXIST::FUNCTION:
1582ASN1_BIT_STRING_set_asc 2017 EXIST::FUNCTION:
1583X509_get_ex_new_index 2019 EXIST::FUNCTION:
1584ASN1_STRING_TABLE_cleanup 2020 EXIST::FUNCTION:
1585X509_TRUST_get_by_id 2021 EXIST::FUNCTION:
1586X509_PURPOSE_get_trust 2022 EXIST::FUNCTION:
1587ASN1_STRING_length 2023 EXIST::FUNCTION:
1588d2i_ASN1_SET_OF_ACCESS_DESCRIPTION 2024 NOEXIST::FUNCTION:
1589ASN1_PRINTABLESTRING_new 2025 EXIST::FUNCTION:
1590X509V3_get_d2i 2026 EXIST::FUNCTION:
1591ASN1_ENUMERATED_free 2027 EXIST::FUNCTION:
1592i2d_X509_CERT_AUX 2028 EXIST::FUNCTION:
1593X509_STORE_CTX_set_trust 2030 EXIST::FUNCTION:
1594ASN1_STRING_set_default_mask 2032 EXIST::FUNCTION:
1595X509_STORE_CTX_new 2033 EXIST::FUNCTION:
1596EVP_PKEY_get1_RSA 2034 EXIST::FUNCTION:RSA
1597DIRECTORYSTRING_free 2038 EXIST::FUNCTION:
1598PEM_write_X509_AUX 2039 EXIST:!WIN16:FUNCTION:
1599ASN1_OCTET_STRING_set 2040 EXIST::FUNCTION:
1600d2i_DSA_PUBKEY_fp 2041 EXIST::FUNCTION:DSA,FP_API
1601d2i_RSA_PUBKEY 2044 EXIST::FUNCTION:RSA
1602X509_TRUST_get0_name 2046 EXIST::FUNCTION:
1603X509_TRUST_get0 2047 EXIST::FUNCTION:
1604AUTHORITY_INFO_ACCESS_free 2048 EXIST::FUNCTION:
1605ASN1_IA5STRING_new 2049 EXIST::FUNCTION:
1606d2i_DSA_PUBKEY 2050 EXIST::FUNCTION:DSA
1607X509_check_purpose 2051 EXIST::FUNCTION:
1608ASN1_ENUMERATED_new 2052 EXIST::FUNCTION:
1609d2i_RSA_PUBKEY_bio 2053 EXIST::FUNCTION:BIO,RSA
1610d2i_PUBKEY 2054 EXIST::FUNCTION:
1611X509_TRUST_get_trust 2055 EXIST::FUNCTION:
1612X509_TRUST_get_flags 2056 EXIST::FUNCTION:
1613ASN1_BMPSTRING_free 2057 EXIST::FUNCTION:
1614ASN1_T61STRING_new 2058 EXIST::FUNCTION:
1615ASN1_UTCTIME_new 2060 EXIST::FUNCTION:
1616i2d_AUTHORITY_INFO_ACCESS 2062 EXIST::FUNCTION:
1617EVP_PKEY_set1_RSA 2063 EXIST::FUNCTION:RSA
1618X509_STORE_CTX_set_purpose 2064 EXIST::FUNCTION:
1619ASN1_IA5STRING_free 2065 EXIST::FUNCTION:
1620PEM_write_bio_X509_AUX 2066 EXIST::FUNCTION:
1621X509_PURPOSE_get_count 2067 EXIST::FUNCTION:
1622CRYPTO_add_info 2068 NOEXIST::FUNCTION:
1623X509_NAME_ENTRY_create_by_txt 2071 EXIST::FUNCTION:
1624ASN1_STRING_get_default_mask 2072 EXIST::FUNCTION:
1625X509_alias_get0 2074 EXIST::FUNCTION:
1626ASN1_STRING_data 2075 EXIST::FUNCTION:
1627i2d_ACCESS_DESCRIPTION 2077 EXIST::FUNCTION:
1628X509_trust_set_bit 2078 NOEXIST::FUNCTION:
1629ASN1_BIT_STRING_free 2080 EXIST::FUNCTION:
1630PEM_read_bio_RSA_PUBKEY 2081 EXIST::FUNCTION:RSA
1631X509_add1_reject_object 2082 EXIST::FUNCTION:
1632X509_check_trust 2083 EXIST::FUNCTION:
1633PEM_read_bio_DSA_PUBKEY 2088 EXIST::FUNCTION:DSA
1634X509_PURPOSE_add 2090 EXIST::FUNCTION:
1635ASN1_STRING_TABLE_get 2091 EXIST::FUNCTION:
1636ASN1_UTF8STRING_free 2092 EXIST::FUNCTION:
1637d2i_DSA_PUBKEY_bio 2093 EXIST::FUNCTION:BIO,DSA
1638PEM_write_RSA_PUBKEY 2095 EXIST:!WIN16:FUNCTION:RSA
1639d2i_OTHERNAME 2096 EXIST::FUNCTION:
1640X509_reject_set_bit 2098 NOEXIST::FUNCTION:
1641PEM_write_DSA_PUBKEY 2101 EXIST:!WIN16:FUNCTION:DSA
1642X509_PURPOSE_get0_sname 2105 EXIST::FUNCTION:
1643EVP_PKEY_set1_DH 2107 EXIST::FUNCTION:DH
1644ASN1_OCTET_STRING_dup 2108 EXIST::FUNCTION:
1645ASN1_BIT_STRING_set 2109 EXIST::FUNCTION:
1646X509_TRUST_get_count 2110 EXIST::FUNCTION:
1647ASN1_INTEGER_free 2111 EXIST::FUNCTION:
1648OTHERNAME_free 2112 EXIST::FUNCTION:
1649i2d_RSA_PUBKEY_fp 2113 EXIST::FUNCTION:FP_API,RSA
1650ASN1_INTEGER_dup 2114 EXIST::FUNCTION:
1651d2i_X509_CERT_AUX 2115 EXIST::FUNCTION:
1652PEM_write_bio_PUBKEY 2117 EXIST::FUNCTION:
1653ASN1_VISIBLESTRING_free 2118 EXIST::FUNCTION:
1654X509_PURPOSE_cleanup 2119 EXIST::FUNCTION:
1655ASN1_mbstring_ncopy 2123 EXIST::FUNCTION:
1656ASN1_GENERALIZEDTIME_new 2126 EXIST::FUNCTION:
1657EVP_PKEY_get1_DH 2128 EXIST::FUNCTION:DH
1658ASN1_OCTET_STRING_new 2130 EXIST::FUNCTION:
1659ASN1_INTEGER_new 2131 EXIST::FUNCTION:
1660i2d_X509_AUX 2132 EXIST::FUNCTION:
1661ASN1_BIT_STRING_name_print 2134 EXIST::FUNCTION:BIO
1662X509_cmp 2135 EXIST::FUNCTION:
1663ASN1_STRING_length_set 2136 EXIST::FUNCTION:
1664DIRECTORYSTRING_new 2137 EXIST::FUNCTION:
1665X509_add1_trust_object 2140 EXIST::FUNCTION:
1666PKCS12_newpass 2141 EXIST::FUNCTION:
1667SMIME_write_PKCS7 2142 EXIST::FUNCTION:
1668SMIME_read_PKCS7 2143 EXIST::FUNCTION:
1669DES_set_key_checked 2144 EXIST::FUNCTION:DES
1670PKCS7_verify 2145 EXIST::FUNCTION:
1671PKCS7_encrypt 2146 EXIST::FUNCTION:
1672DES_set_key_unchecked 2147 EXIST::FUNCTION:DES
1673SMIME_crlf_copy 2148 EXIST::FUNCTION:
1674i2d_ASN1_PRINTABLESTRING 2149 EXIST::FUNCTION:
1675PKCS7_get0_signers 2150 EXIST::FUNCTION:
1676PKCS7_decrypt 2151 EXIST::FUNCTION:
1677SMIME_text 2152 EXIST::FUNCTION:
1678PKCS7_simple_smimecap 2153 EXIST::FUNCTION:
1679PKCS7_get_smimecap 2154 EXIST::FUNCTION:
1680PKCS7_sign 2155 EXIST::FUNCTION:
1681PKCS7_add_attrib_smimecap 2156 EXIST::FUNCTION:
1682CRYPTO_dbg_set_options 2157 EXIST::FUNCTION:
1683CRYPTO_remove_all_info 2158 EXIST::FUNCTION:
1684CRYPTO_get_mem_debug_functions 2159 EXIST::FUNCTION:
1685CRYPTO_is_mem_check_on 2160 EXIST::FUNCTION:
1686CRYPTO_set_mem_debug_functions 2161 EXIST::FUNCTION:
1687CRYPTO_pop_info 2162 EXIST::FUNCTION:
1688CRYPTO_push_info_ 2163 EXIST::FUNCTION:
1689CRYPTO_set_mem_debug_options 2164 EXIST::FUNCTION:
1690PEM_write_PKCS8PrivateKey_nid 2165 EXIST::FUNCTION:
1691PEM_write_bio_PKCS8PrivateKey_nid 2166 EXIST:!VMS:FUNCTION:
1692PEM_write_bio_PKCS8PrivKey_nid 2166 EXIST:VMS:FUNCTION:
1693d2i_PKCS8PrivateKey_bio 2167 EXIST::FUNCTION:
1694ASN1_NULL_free 2168 EXIST::FUNCTION:
1695d2i_ASN1_NULL 2169 EXIST::FUNCTION:
1696ASN1_NULL_new 2170 EXIST::FUNCTION:
1697i2d_PKCS8PrivateKey_bio 2171 EXIST::FUNCTION:
1698i2d_PKCS8PrivateKey_fp 2172 EXIST::FUNCTION:
1699i2d_ASN1_NULL 2173 EXIST::FUNCTION:
1700i2d_PKCS8PrivateKey_nid_fp 2174 EXIST::FUNCTION:
1701d2i_PKCS8PrivateKey_fp 2175 EXIST::FUNCTION:
1702i2d_PKCS8PrivateKey_nid_bio 2176 EXIST::FUNCTION:
1703i2d_PKCS8PrivateKeyInfo_fp 2177 EXIST::FUNCTION:FP_API
1704i2d_PKCS8PrivateKeyInfo_bio 2178 EXIST::FUNCTION:BIO
1705PEM_cb 2179 NOEXIST::FUNCTION:
1706i2d_PrivateKey_fp 2180 EXIST::FUNCTION:FP_API
1707d2i_PrivateKey_bio 2181 EXIST::FUNCTION:BIO
1708d2i_PrivateKey_fp 2182 EXIST::FUNCTION:FP_API
1709i2d_PrivateKey_bio 2183 EXIST::FUNCTION:BIO
1710X509_reject_clear 2184 EXIST::FUNCTION:
1711X509_TRUST_set_default 2185 EXIST::FUNCTION:
1712d2i_AutoPrivateKey 2186 EXIST::FUNCTION:
1713X509_ATTRIBUTE_get0_type 2187 EXIST::FUNCTION:
1714X509_ATTRIBUTE_set1_data 2188 EXIST::FUNCTION:
1715X509at_get_attr 2189 EXIST::FUNCTION:
1716X509at_get_attr_count 2190 EXIST::FUNCTION:
1717X509_ATTRIBUTE_create_by_NID 2191 EXIST::FUNCTION:
1718X509_ATTRIBUTE_set1_object 2192 EXIST::FUNCTION:
1719X509_ATTRIBUTE_count 2193 EXIST::FUNCTION:
1720X509_ATTRIBUTE_create_by_OBJ 2194 EXIST::FUNCTION:
1721X509_ATTRIBUTE_get0_object 2195 EXIST::FUNCTION:
1722X509at_get_attr_by_NID 2196 EXIST::FUNCTION:
1723X509at_add1_attr 2197 EXIST::FUNCTION:
1724X509_ATTRIBUTE_get0_data 2198 EXIST::FUNCTION:
1725X509at_delete_attr 2199 EXIST::FUNCTION:
1726X509at_get_attr_by_OBJ 2200 EXIST::FUNCTION:
1727RAND_add 2201 EXIST::FUNCTION:
1728BIO_number_written 2202 EXIST::FUNCTION:
1729BIO_number_read 2203 EXIST::FUNCTION:
1730X509_STORE_CTX_get1_chain 2204 EXIST::FUNCTION:
1731ERR_load_RAND_strings 2205 EXIST::FUNCTION:
1732RAND_pseudo_bytes 2206 EXIST::FUNCTION:
1733X509_REQ_get_attr_by_NID 2207 EXIST::FUNCTION:
1734X509_REQ_get_attr 2208 EXIST::FUNCTION:
1735X509_REQ_add1_attr_by_NID 2209 EXIST::FUNCTION:
1736X509_REQ_get_attr_by_OBJ 2210 EXIST::FUNCTION:
1737X509at_add1_attr_by_NID 2211 EXIST::FUNCTION:
1738X509_REQ_add1_attr_by_OBJ 2212 EXIST::FUNCTION:
1739X509_REQ_get_attr_count 2213 EXIST::FUNCTION:
1740X509_REQ_add1_attr 2214 EXIST::FUNCTION:
1741X509_REQ_delete_attr 2215 EXIST::FUNCTION:
1742X509at_add1_attr_by_OBJ 2216 EXIST::FUNCTION:
1743X509_REQ_add1_attr_by_txt 2217 EXIST::FUNCTION:
1744X509_ATTRIBUTE_create_by_txt 2218 EXIST::FUNCTION:
1745X509at_add1_attr_by_txt 2219 EXIST::FUNCTION:
1746BN_pseudo_rand 2239 EXIST::FUNCTION:
1747BN_is_prime_fasttest 2240 EXIST::FUNCTION:
1748BN_CTX_end 2241 EXIST::FUNCTION:
1749BN_CTX_start 2242 EXIST::FUNCTION:
1750BN_CTX_get 2243 EXIST::FUNCTION:
1751EVP_PKEY2PKCS8_broken 2244 EXIST::FUNCTION:
1752ASN1_STRING_TABLE_add 2245 EXIST::FUNCTION:
1753CRYPTO_dbg_get_options 2246 EXIST::FUNCTION:
1754AUTHORITY_INFO_ACCESS_new 2247 EXIST::FUNCTION:
1755CRYPTO_get_mem_debug_options 2248 EXIST::FUNCTION:
1756DES_crypt 2249 EXIST::FUNCTION:DES
1757PEM_write_bio_X509_REQ_NEW 2250 EXIST::FUNCTION:
1758PEM_write_X509_REQ_NEW 2251 EXIST:!WIN16:FUNCTION:
1759BIO_callback_ctrl 2252 EXIST::FUNCTION:
1760RAND_egd 2253 EXIST::FUNCTION:
1761RAND_status 2254 EXIST::FUNCTION:
1762bn_dump1 2255 NOEXIST::FUNCTION:
1763DES_check_key_parity 2256 EXIST::FUNCTION:DES
1764lh_num_items 2257 EXIST::FUNCTION:
1765RAND_event 2258 EXIST:WIN32:FUNCTION:
1766DSO_new 2259 EXIST::FUNCTION:
1767DSO_new_method 2260 EXIST::FUNCTION:
1768DSO_free 2261 EXIST::FUNCTION:
1769DSO_flags 2262 EXIST::FUNCTION:
1770DSO_up 2263 NOEXIST::FUNCTION:
1771DSO_set_default_method 2264 EXIST::FUNCTION:
1772DSO_get_default_method 2265 EXIST::FUNCTION:
1773DSO_get_method 2266 EXIST::FUNCTION:
1774DSO_set_method 2267 EXIST::FUNCTION:
1775DSO_load 2268 EXIST::FUNCTION:
1776DSO_bind_var 2269 EXIST::FUNCTION:
1777DSO_METHOD_null 2270 EXIST::FUNCTION:
1778DSO_METHOD_openssl 2271 EXIST::FUNCTION:
1779DSO_METHOD_dlfcn 2272 EXIST::FUNCTION:
1780DSO_METHOD_win32 2273 EXIST::FUNCTION:
1781ERR_load_DSO_strings 2274 EXIST::FUNCTION:
1782DSO_METHOD_dl 2275 EXIST::FUNCTION:
1783NCONF_load 2276 EXIST::FUNCTION:
1784NCONF_load_fp 2278 EXIST::FUNCTION:FP_API
1785NCONF_new 2279 EXIST::FUNCTION:
1786NCONF_get_string 2280 EXIST::FUNCTION:
1787NCONF_free 2281 EXIST::FUNCTION:
1788NCONF_get_number 2282 NOEXIST::FUNCTION:
1789CONF_dump_fp 2283 EXIST::FUNCTION:
1790NCONF_load_bio 2284 EXIST::FUNCTION:
1791NCONF_dump_fp 2285 EXIST::FUNCTION:
1792NCONF_get_section 2286 EXIST::FUNCTION:
1793NCONF_dump_bio 2287 EXIST::FUNCTION:
1794CONF_dump_bio 2288 EXIST::FUNCTION:
1795NCONF_free_data 2289 EXIST::FUNCTION:
1796CONF_set_default_method 2290 EXIST::FUNCTION:
1797ERR_error_string_n 2291 EXIST::FUNCTION:
1798BIO_snprintf 2292 EXIST::FUNCTION:
1799DSO_ctrl 2293 EXIST::FUNCTION:
1800i2d_ASN1_SET_OF_ASN1_INTEGER 2317 NOEXIST::FUNCTION:
1801i2d_ASN1_SET_OF_PKCS12_SAFEBAG 2320 NOEXIST::FUNCTION:
1802i2d_ASN1_SET_OF_PKCS7 2328 NOEXIST::FUNCTION:
1803BIO_vfree 2334 EXIST::FUNCTION:
1804d2i_ASN1_SET_OF_ASN1_INTEGER 2339 NOEXIST::FUNCTION:
1805d2i_ASN1_SET_OF_PKCS12_SAFEBAG 2341 NOEXIST::FUNCTION:
1806ASN1_UTCTIME_get 2350 NOEXIST::FUNCTION:
1807X509_REQ_digest 2362 EXIST::FUNCTION:EVP
1808X509_CRL_digest 2391 EXIST::FUNCTION:EVP
1809d2i_ASN1_SET_OF_PKCS7 2397 NOEXIST::FUNCTION:
1810EVP_CIPHER_CTX_set_key_length 2399 EXIST::FUNCTION:
1811EVP_CIPHER_CTX_ctrl 2400 EXIST::FUNCTION:
1812BN_mod_exp_mont_word 2401 EXIST::FUNCTION:
1813RAND_egd_bytes 2402 EXIST::FUNCTION:
1814X509_REQ_get1_email 2403 EXIST::FUNCTION:
1815X509_get1_email 2404 EXIST::FUNCTION:
1816X509_email_free 2405 EXIST::FUNCTION:
1817i2d_RSA_NET 2406 EXIST::FUNCTION:RSA
1818d2i_RSA_NET_2 2407 NOEXIST::FUNCTION:
1819d2i_RSA_NET 2408 EXIST::FUNCTION:RSA
1820DSO_bind_func 2409 EXIST::FUNCTION:
1821CRYPTO_get_new_dynlockid 2410 EXIST::FUNCTION:
1822sk_new_null 2411 EXIST::FUNCTION:
1823CRYPTO_set_dynlock_destroy_callback 2412 EXIST:!VMS:FUNCTION:
1824CRYPTO_set_dynlock_destroy_cb 2412 EXIST:VMS:FUNCTION:
1825CRYPTO_destroy_dynlockid 2413 EXIST::FUNCTION:
1826CRYPTO_set_dynlock_size 2414 NOEXIST::FUNCTION:
1827CRYPTO_set_dynlock_create_callback 2415 EXIST:!VMS:FUNCTION:
1828CRYPTO_set_dynlock_create_cb 2415 EXIST:VMS:FUNCTION:
1829CRYPTO_set_dynlock_lock_callback 2416 EXIST:!VMS:FUNCTION:
1830CRYPTO_set_dynlock_lock_cb 2416 EXIST:VMS:FUNCTION:
1831CRYPTO_get_dynlock_lock_callback 2417 EXIST:!VMS:FUNCTION:
1832CRYPTO_get_dynlock_lock_cb 2417 EXIST:VMS:FUNCTION:
1833CRYPTO_get_dynlock_destroy_callback 2418 EXIST:!VMS:FUNCTION:
1834CRYPTO_get_dynlock_destroy_cb 2418 EXIST:VMS:FUNCTION:
1835CRYPTO_get_dynlock_value 2419 EXIST::FUNCTION:
1836CRYPTO_get_dynlock_create_callback 2420 EXIST:!VMS:FUNCTION:
1837CRYPTO_get_dynlock_create_cb 2420 EXIST:VMS:FUNCTION:
1838c2i_ASN1_BIT_STRING 2421 EXIST::FUNCTION:
1839i2c_ASN1_BIT_STRING 2422 EXIST::FUNCTION:
1840RAND_poll 2423 EXIST::FUNCTION:
1841c2i_ASN1_INTEGER 2424 EXIST::FUNCTION:
1842i2c_ASN1_INTEGER 2425 EXIST::FUNCTION:
1843BIO_dump_indent 2426 EXIST::FUNCTION:
1844ASN1_parse_dump 2427 EXIST::FUNCTION:BIO
1845c2i_ASN1_OBJECT 2428 EXIST::FUNCTION:
1846X509_NAME_print_ex_fp 2429 EXIST::FUNCTION:FP_API
1847ASN1_STRING_print_ex_fp 2430 EXIST::FUNCTION:FP_API
1848X509_NAME_print_ex 2431 EXIST::FUNCTION:BIO
1849ASN1_STRING_print_ex 2432 EXIST::FUNCTION:BIO
1850MD4 2433 EXIST::FUNCTION:MD4
1851MD4_Transform 2434 EXIST::FUNCTION:MD4
1852MD4_Final 2435 EXIST::FUNCTION:MD4
1853MD4_Update 2436 EXIST::FUNCTION:MD4
1854MD4_Init 2437 EXIST::FUNCTION:MD4
1855EVP_md4 2438 EXIST::FUNCTION:MD4
1856i2d_PUBKEY_bio 2439 EXIST::FUNCTION:BIO
1857i2d_PUBKEY_fp 2440 EXIST::FUNCTION:FP_API
1858d2i_PUBKEY_bio 2441 EXIST::FUNCTION:BIO
1859ASN1_STRING_to_UTF8 2442 EXIST::FUNCTION:
1860BIO_vprintf 2443 EXIST::FUNCTION:
1861BIO_vsnprintf 2444 EXIST::FUNCTION:
1862d2i_PUBKEY_fp 2445 EXIST::FUNCTION:FP_API
1863X509_cmp_time 2446 EXIST::FUNCTION:
1864X509_STORE_CTX_set_time 2447 EXIST::FUNCTION:
1865X509_STORE_CTX_get1_issuer 2448 EXIST::FUNCTION:
1866X509_OBJECT_retrieve_match 2449 EXIST::FUNCTION:
1867X509_OBJECT_idx_by_subject 2450 EXIST::FUNCTION:
1868X509_STORE_CTX_set_flags 2451 EXIST::FUNCTION:
1869X509_STORE_CTX_trusted_stack 2452 EXIST::FUNCTION:
1870X509_time_adj 2453 EXIST::FUNCTION:
1871X509_check_issued 2454 EXIST::FUNCTION:
1872ASN1_UTCTIME_cmp_time_t 2455 EXIST::FUNCTION:
1873DES_set_weak_key_flag 2456 NOEXIST::FUNCTION:
1874DES_check_key 2457 NOEXIST::FUNCTION:
1875DES_rw_mode 2458 NOEXIST::FUNCTION:
1876RSA_PKCS1_RSAref 2459 NOEXIST::FUNCTION:
1877X509_keyid_set1 2460 EXIST::FUNCTION:
1878BIO_next 2461 EXIST::FUNCTION:
1879DSO_METHOD_vms 2462 EXIST::FUNCTION:
1880BIO_f_linebuffer 2463 EXIST:VMS:FUNCTION:
1881BN_bntest_rand 2464 EXIST::FUNCTION:
1882OPENSSL_issetugid 2465 EXIST::FUNCTION:
1883BN_rand_range 2466 EXIST::FUNCTION:
1884ERR_load_ENGINE_strings 2467 EXIST::FUNCTION:ENGINE
1885ENGINE_set_DSA 2468 EXIST::FUNCTION:ENGINE
1886ENGINE_get_finish_function 2469 EXIST::FUNCTION:ENGINE
1887ENGINE_get_default_RSA 2470 EXIST::FUNCTION:ENGINE
1888ENGINE_get_BN_mod_exp 2471 NOEXIST::FUNCTION:
1889DSA_get_default_openssl_method 2472 NOEXIST::FUNCTION:
1890ENGINE_set_DH 2473 EXIST::FUNCTION:ENGINE
1891ENGINE_set_def_BN_mod_exp_crt 2474 NOEXIST::FUNCTION:
1892ENGINE_set_default_BN_mod_exp_crt 2474 NOEXIST::FUNCTION:
1893ENGINE_init 2475 EXIST::FUNCTION:ENGINE
1894DH_get_default_openssl_method 2476 NOEXIST::FUNCTION:
1895RSA_set_default_openssl_method 2477 NOEXIST::FUNCTION:
1896ENGINE_finish 2478 EXIST::FUNCTION:ENGINE
1897ENGINE_load_public_key 2479 EXIST::FUNCTION:ENGINE
1898ENGINE_get_DH 2480 EXIST::FUNCTION:ENGINE
1899ENGINE_ctrl 2481 EXIST::FUNCTION:ENGINE
1900ENGINE_get_init_function 2482 EXIST::FUNCTION:ENGINE
1901ENGINE_set_init_function 2483 EXIST::FUNCTION:ENGINE
1902ENGINE_set_default_DSA 2484 EXIST::FUNCTION:ENGINE
1903ENGINE_get_name 2485 EXIST::FUNCTION:ENGINE
1904ENGINE_get_last 2486 EXIST::FUNCTION:ENGINE
1905ENGINE_get_prev 2487 EXIST::FUNCTION:ENGINE
1906ENGINE_get_default_DH 2488 EXIST::FUNCTION:ENGINE
1907ENGINE_get_RSA 2489 EXIST::FUNCTION:ENGINE
1908ENGINE_set_default 2490 EXIST::FUNCTION:ENGINE
1909ENGINE_get_RAND 2491 EXIST::FUNCTION:ENGINE
1910ENGINE_get_first 2492 EXIST::FUNCTION:ENGINE
1911ENGINE_by_id 2493 EXIST::FUNCTION:ENGINE
1912ENGINE_set_finish_function 2494 EXIST::FUNCTION:ENGINE
1913ENGINE_get_def_BN_mod_exp_crt 2495 NOEXIST::FUNCTION:
1914ENGINE_get_default_BN_mod_exp_crt 2495 NOEXIST::FUNCTION:
1915RSA_get_default_openssl_method 2496 NOEXIST::FUNCTION:
1916ENGINE_set_RSA 2497 EXIST::FUNCTION:ENGINE
1917ENGINE_load_private_key 2498 EXIST::FUNCTION:ENGINE
1918ENGINE_set_default_RAND 2499 EXIST::FUNCTION:ENGINE
1919ENGINE_set_BN_mod_exp 2500 NOEXIST::FUNCTION:
1920ENGINE_remove 2501 EXIST::FUNCTION:ENGINE
1921ENGINE_free 2502 EXIST::FUNCTION:ENGINE
1922ENGINE_get_BN_mod_exp_crt 2503 NOEXIST::FUNCTION:
1923ENGINE_get_next 2504 EXIST::FUNCTION:ENGINE
1924ENGINE_set_name 2505 EXIST::FUNCTION:ENGINE
1925ENGINE_get_default_DSA 2506 EXIST::FUNCTION:ENGINE
1926ENGINE_set_default_BN_mod_exp 2507 NOEXIST::FUNCTION:
1927ENGINE_set_default_RSA 2508 EXIST::FUNCTION:ENGINE
1928ENGINE_get_default_RAND 2509 EXIST::FUNCTION:ENGINE
1929ENGINE_get_default_BN_mod_exp 2510 NOEXIST::FUNCTION:
1930ENGINE_set_RAND 2511 EXIST::FUNCTION:ENGINE
1931ENGINE_set_id 2512 EXIST::FUNCTION:ENGINE
1932ENGINE_set_BN_mod_exp_crt 2513 NOEXIST::FUNCTION:
1933ENGINE_set_default_DH 2514 EXIST::FUNCTION:ENGINE
1934ENGINE_new 2515 EXIST::FUNCTION:ENGINE
1935ENGINE_get_id 2516 EXIST::FUNCTION:ENGINE
1936DSA_set_default_openssl_method 2517 NOEXIST::FUNCTION:
1937ENGINE_add 2518 EXIST::FUNCTION:ENGINE
1938DH_set_default_openssl_method 2519 NOEXIST::FUNCTION:
1939ENGINE_get_DSA 2520 EXIST::FUNCTION:ENGINE
1940ENGINE_get_ctrl_function 2521 EXIST::FUNCTION:ENGINE
1941ENGINE_set_ctrl_function 2522 EXIST::FUNCTION:ENGINE
1942BN_pseudo_rand_range 2523 EXIST::FUNCTION:
1943X509_STORE_CTX_set_verify_cb 2524 EXIST::FUNCTION:
1944ERR_load_COMP_strings 2525 EXIST::FUNCTION:
1945PKCS12_item_decrypt_d2i 2526 EXIST::FUNCTION:
1946ASN1_UTF8STRING_it 2527 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1947ASN1_UTF8STRING_it 2527 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1948ENGINE_unregister_ciphers 2528 EXIST::FUNCTION:ENGINE
1949ENGINE_get_ciphers 2529 EXIST::FUNCTION:ENGINE
1950d2i_OCSP_BASICRESP 2530 EXIST::FUNCTION:
1951KRB5_CHECKSUM_it 2531 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1952KRB5_CHECKSUM_it 2531 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1953EC_POINT_add 2532 EXIST::FUNCTION:EC
1954ASN1_item_ex_i2d 2533 EXIST::FUNCTION:
1955OCSP_CERTID_it 2534 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1956OCSP_CERTID_it 2534 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1957d2i_OCSP_RESPBYTES 2535 EXIST::FUNCTION:
1958X509V3_add1_i2d 2536 EXIST::FUNCTION:
1959PKCS7_ENVELOPE_it 2537 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1960PKCS7_ENVELOPE_it 2537 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1961UI_add_input_boolean 2538 EXIST::FUNCTION:
1962ENGINE_unregister_RSA 2539 EXIST::FUNCTION:ENGINE
1963X509V3_EXT_nconf 2540 EXIST::FUNCTION:
1964ASN1_GENERALSTRING_free 2541 EXIST::FUNCTION:
1965d2i_OCSP_CERTSTATUS 2542 EXIST::FUNCTION:
1966X509_REVOKED_set_serialNumber 2543 EXIST::FUNCTION:
1967X509_print_ex 2544 EXIST::FUNCTION:BIO
1968OCSP_ONEREQ_get1_ext_d2i 2545 EXIST::FUNCTION:
1969ENGINE_register_all_RAND 2546 EXIST::FUNCTION:ENGINE
1970ENGINE_load_dynamic 2547 EXIST::FUNCTION:ENGINE
1971PBKDF2PARAM_it 2548 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1972PBKDF2PARAM_it 2548 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1973EXTENDED_KEY_USAGE_new 2549 EXIST::FUNCTION:
1974EC_GROUP_clear_free 2550 EXIST::FUNCTION:EC
1975OCSP_sendreq_bio 2551 EXIST::FUNCTION:
1976ASN1_item_digest 2552 EXIST::FUNCTION:EVP
1977OCSP_BASICRESP_delete_ext 2553 EXIST::FUNCTION:
1978OCSP_SIGNATURE_it 2554 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1979OCSP_SIGNATURE_it 2554 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1980X509_CRL_it 2555 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1981X509_CRL_it 2555 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1982OCSP_BASICRESP_add_ext 2556 EXIST::FUNCTION:
1983KRB5_ENCKEY_it 2557 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1984KRB5_ENCKEY_it 2557 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1985UI_method_set_closer 2558 EXIST::FUNCTION:
1986X509_STORE_set_purpose 2559 EXIST::FUNCTION:
1987i2d_ASN1_GENERALSTRING 2560 EXIST::FUNCTION:
1988OCSP_response_status 2561 EXIST::FUNCTION:
1989i2d_OCSP_SERVICELOC 2562 EXIST::FUNCTION:
1990ENGINE_get_digest_engine 2563 EXIST::FUNCTION:ENGINE
1991EC_GROUP_set_curve_GFp 2564 EXIST::FUNCTION:EC
1992OCSP_REQUEST_get_ext_by_OBJ 2565 EXIST::FUNCTION:
1993_ossl_old_des_random_key 2566 EXIST::FUNCTION:DES
1994ASN1_T61STRING_it 2567 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
1995ASN1_T61STRING_it 2567 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
1996EC_GROUP_method_of 2568 EXIST::FUNCTION:EC
1997i2d_KRB5_APREQ 2569 EXIST::FUNCTION:
1998_ossl_old_des_encrypt 2570 EXIST::FUNCTION:DES
1999ASN1_PRINTABLE_new 2571 EXIST::FUNCTION:
2000HMAC_Init_ex 2572 EXIST::FUNCTION:HMAC
2001d2i_KRB5_AUTHENT 2573 EXIST::FUNCTION:
2002OCSP_archive_cutoff_new 2574 EXIST::FUNCTION:
2003EC_POINT_set_Jprojective_coordinates_GFp 2575 EXIST:!VMS:FUNCTION:EC
2004EC_POINT_set_Jproj_coords_GFp 2575 EXIST:VMS:FUNCTION:EC
2005_ossl_old_des_is_weak_key 2576 EXIST::FUNCTION:DES
2006OCSP_BASICRESP_get_ext_by_OBJ 2577 EXIST::FUNCTION:
2007EC_POINT_oct2point 2578 EXIST::FUNCTION:EC
2008OCSP_SINGLERESP_get_ext_count 2579 EXIST::FUNCTION:
2009UI_ctrl 2580 EXIST::FUNCTION:
2010_shadow_DES_rw_mode 2581 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:DES
2011_shadow_DES_rw_mode 2581 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:DES
2012asn1_do_adb 2582 EXIST::FUNCTION:
2013ASN1_template_i2d 2583 EXIST::FUNCTION:
2014ENGINE_register_DH 2584 EXIST::FUNCTION:ENGINE
2015UI_construct_prompt 2585 EXIST::FUNCTION:
2016X509_STORE_set_trust 2586 EXIST::FUNCTION:
2017UI_dup_input_string 2587 EXIST::FUNCTION:
2018d2i_KRB5_APREQ 2588 EXIST::FUNCTION:
2019EVP_MD_CTX_copy_ex 2589 EXIST::FUNCTION:
2020OCSP_request_is_signed 2590 EXIST::FUNCTION:
2021i2d_OCSP_REQINFO 2591 EXIST::FUNCTION:
2022KRB5_ENCKEY_free 2592 EXIST::FUNCTION:
2023OCSP_resp_get0 2593 EXIST::FUNCTION:
2024GENERAL_NAME_it 2594 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2025GENERAL_NAME_it 2594 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2026ASN1_GENERALIZEDTIME_it 2595 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2027ASN1_GENERALIZEDTIME_it 2595 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2028X509_STORE_set_flags 2596 EXIST::FUNCTION:
2029EC_POINT_set_compressed_coordinates_GFp 2597 EXIST:!VMS:FUNCTION:EC
2030EC_POINT_set_compr_coords_GFp 2597 EXIST:VMS:FUNCTION:EC
2031OCSP_response_status_str 2598 EXIST::FUNCTION:
2032d2i_OCSP_REVOKEDINFO 2599 EXIST::FUNCTION:
2033OCSP_basic_add1_cert 2600 EXIST::FUNCTION:
2034ERR_get_implementation 2601 EXIST::FUNCTION:
2035EVP_CipherFinal_ex 2602 EXIST::FUNCTION:
2036OCSP_CERTSTATUS_new 2603 EXIST::FUNCTION:
2037CRYPTO_cleanup_all_ex_data 2604 EXIST::FUNCTION:
2038OCSP_resp_find 2605 EXIST::FUNCTION:
2039BN_nnmod 2606 EXIST::FUNCTION:
2040X509_CRL_sort 2607 EXIST::FUNCTION:
2041X509_REVOKED_set_revocationDate 2608 EXIST::FUNCTION:
2042ENGINE_register_RAND 2609 EXIST::FUNCTION:ENGINE
2043OCSP_SERVICELOC_new 2610 EXIST::FUNCTION:
2044EC_POINT_set_affine_coordinates_GFp 2611 EXIST:!VMS:FUNCTION:EC
2045EC_POINT_set_affine_coords_GFp 2611 EXIST:VMS:FUNCTION:EC
2046_ossl_old_des_options 2612 EXIST::FUNCTION:DES
2047SXNET_it 2613 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2048SXNET_it 2613 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2049UI_dup_input_boolean 2614 EXIST::FUNCTION:
2050PKCS12_add_CSPName_asc 2615 EXIST::FUNCTION:
2051EC_POINT_is_at_infinity 2616 EXIST::FUNCTION:EC
2052ENGINE_load_cryptodev 2617 EXIST::FUNCTION:ENGINE
2053DSO_convert_filename 2618 EXIST::FUNCTION:
2054POLICYQUALINFO_it 2619 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2055POLICYQUALINFO_it 2619 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2056ENGINE_register_ciphers 2620 EXIST::FUNCTION:ENGINE
2057BN_mod_lshift_quick 2621 EXIST::FUNCTION:
2058DSO_set_filename 2622 EXIST::FUNCTION:
2059ASN1_item_free 2623 EXIST::FUNCTION:
2060KRB5_TKTBODY_free 2624 EXIST::FUNCTION:
2061AUTHORITY_KEYID_it 2625 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2062AUTHORITY_KEYID_it 2625 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2063KRB5_APREQBODY_new 2626 EXIST::FUNCTION:
2064X509V3_EXT_REQ_add_nconf 2627 EXIST::FUNCTION:
2065ENGINE_ctrl_cmd_string 2628 EXIST::FUNCTION:ENGINE
2066i2d_OCSP_RESPDATA 2629 EXIST::FUNCTION:
2067EVP_MD_CTX_init 2630 EXIST::FUNCTION:
2068EXTENDED_KEY_USAGE_free 2631 EXIST::FUNCTION:
2069PKCS7_ATTR_SIGN_it 2632 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2070PKCS7_ATTR_SIGN_it 2632 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2071UI_add_error_string 2633 EXIST::FUNCTION:
2072KRB5_CHECKSUM_free 2634 EXIST::FUNCTION:
2073OCSP_REQUEST_get_ext 2635 EXIST::FUNCTION:
2074ENGINE_load_ubsec 2636 EXIST::FUNCTION:ENGINE
2075ENGINE_register_all_digests 2637 EXIST::FUNCTION:ENGINE
2076PKEY_USAGE_PERIOD_it 2638 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2077PKEY_USAGE_PERIOD_it 2638 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2078PKCS12_unpack_authsafes 2639 EXIST::FUNCTION:
2079ASN1_item_unpack 2640 EXIST::FUNCTION:
2080NETSCAPE_SPKAC_it 2641 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2081NETSCAPE_SPKAC_it 2641 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2082X509_REVOKED_it 2642 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2083X509_REVOKED_it 2642 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2084ASN1_STRING_encode 2643 EXIST::FUNCTION:
2085EVP_aes_128_ecb 2644 EXIST::FUNCTION:AES
2086KRB5_AUTHENT_free 2645 EXIST::FUNCTION:
2087OCSP_BASICRESP_get_ext_by_critical 2646 EXIST:!VMS:FUNCTION:
2088OCSP_BASICRESP_get_ext_by_crit 2646 EXIST:VMS:FUNCTION:
2089OCSP_cert_status_str 2647 EXIST::FUNCTION:
2090d2i_OCSP_REQUEST 2648 EXIST::FUNCTION:
2091UI_dup_info_string 2649 EXIST::FUNCTION:
2092_ossl_old_des_xwhite_in2out 2650 EXIST::FUNCTION:DES
2093PKCS12_it 2651 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2094PKCS12_it 2651 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2095OCSP_SINGLERESP_get_ext_by_critical 2652 EXIST:!VMS:FUNCTION:
2096OCSP_SINGLERESP_get_ext_by_crit 2652 EXIST:VMS:FUNCTION:
2097OCSP_CERTSTATUS_free 2653 EXIST::FUNCTION:
2098_ossl_old_des_crypt 2654 EXIST::FUNCTION:DES
2099ASN1_item_i2d 2655 EXIST::FUNCTION:
2100EVP_DecryptFinal_ex 2656 EXIST::FUNCTION:
2101ENGINE_load_openssl 2657 EXIST::FUNCTION:ENGINE
2102ENGINE_get_cmd_defns 2658 EXIST::FUNCTION:ENGINE
2103ENGINE_set_load_privkey_function 2659 EXIST:!VMS:FUNCTION:ENGINE
2104ENGINE_set_load_privkey_fn 2659 EXIST:VMS:FUNCTION:ENGINE
2105EVP_EncryptFinal_ex 2660 EXIST::FUNCTION:
2106ENGINE_set_default_digests 2661 EXIST::FUNCTION:ENGINE
2107X509_get0_pubkey_bitstr 2662 EXIST::FUNCTION:
2108asn1_ex_i2c 2663 EXIST::FUNCTION:
2109ENGINE_register_RSA 2664 EXIST::FUNCTION:ENGINE
2110ENGINE_unregister_DSA 2665 EXIST::FUNCTION:ENGINE
2111_ossl_old_des_key_sched 2666 EXIST::FUNCTION:DES
2112X509_EXTENSION_it 2667 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2113X509_EXTENSION_it 2667 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2114i2d_KRB5_AUTHENT 2668 EXIST::FUNCTION:
2115SXNETID_it 2669 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2116SXNETID_it 2669 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2117d2i_OCSP_SINGLERESP 2670 EXIST::FUNCTION:
2118EDIPARTYNAME_new 2671 EXIST::FUNCTION:
2119PKCS12_certbag2x509 2672 EXIST::FUNCTION:
2120_ossl_old_des_ofb64_encrypt 2673 EXIST::FUNCTION:DES
2121d2i_EXTENDED_KEY_USAGE 2674 EXIST::FUNCTION:
2122ERR_print_errors_cb 2675 EXIST::FUNCTION:
2123ENGINE_set_ciphers 2676 EXIST::FUNCTION:ENGINE
2124d2i_KRB5_APREQBODY 2677 EXIST::FUNCTION:
2125UI_method_get_flusher 2678 EXIST::FUNCTION:
2126X509_PUBKEY_it 2679 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2127X509_PUBKEY_it 2679 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2128_ossl_old_des_enc_read 2680 EXIST::FUNCTION:DES
2129PKCS7_ENCRYPT_it 2681 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2130PKCS7_ENCRYPT_it 2681 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2131i2d_OCSP_RESPONSE 2682 EXIST::FUNCTION:
2132EC_GROUP_get_cofactor 2683 EXIST::FUNCTION:EC
2133PKCS12_unpack_p7data 2684 EXIST::FUNCTION:
2134d2i_KRB5_AUTHDATA 2685 EXIST::FUNCTION:
2135OCSP_copy_nonce 2686 EXIST::FUNCTION:
2136KRB5_AUTHDATA_new 2687 EXIST::FUNCTION:
2137OCSP_RESPDATA_new 2688 EXIST::FUNCTION:
2138EC_GFp_mont_method 2689 EXIST::FUNCTION:EC
2139OCSP_REVOKEDINFO_free 2690 EXIST::FUNCTION:
2140UI_get_ex_data 2691 EXIST::FUNCTION:
2141KRB5_APREQBODY_free 2692 EXIST::FUNCTION:
2142EC_GROUP_get0_generator 2693 EXIST::FUNCTION:EC
2143UI_get_default_method 2694 EXIST::FUNCTION:
2144X509V3_set_nconf 2695 EXIST::FUNCTION:
2145PKCS12_item_i2d_encrypt 2696 EXIST::FUNCTION:
2146X509_add1_ext_i2d 2697 EXIST::FUNCTION:
2147PKCS7_SIGNER_INFO_it 2698 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2148PKCS7_SIGNER_INFO_it 2698 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2149KRB5_PRINCNAME_new 2699 EXIST::FUNCTION:
2150PKCS12_SAFEBAG_it 2700 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2151PKCS12_SAFEBAG_it 2700 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2152EC_GROUP_get_order 2701 EXIST::FUNCTION:EC
2153d2i_OCSP_RESPID 2702 EXIST::FUNCTION:
2154OCSP_request_verify 2703 EXIST::FUNCTION:
2155NCONF_get_number_e 2704 EXIST::FUNCTION:
2156_ossl_old_des_decrypt3 2705 EXIST::FUNCTION:DES
2157X509_signature_print 2706 EXIST::FUNCTION:EVP
2158OCSP_SINGLERESP_free 2707 EXIST::FUNCTION:
2159ENGINE_load_builtin_engines 2708 EXIST::FUNCTION:ENGINE
2160i2d_OCSP_ONEREQ 2709 EXIST::FUNCTION:
2161OCSP_REQUEST_add_ext 2710 EXIST::FUNCTION:
2162OCSP_RESPBYTES_new 2711 EXIST::FUNCTION:
2163EVP_MD_CTX_create 2712 EXIST::FUNCTION:
2164OCSP_resp_find_status 2713 EXIST::FUNCTION:
2165X509_ALGOR_it 2714 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2166X509_ALGOR_it 2714 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2167ASN1_TIME_it 2715 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2168ASN1_TIME_it 2715 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2169OCSP_request_set1_name 2716 EXIST::FUNCTION:
2170OCSP_ONEREQ_get_ext_count 2717 EXIST::FUNCTION:
2171UI_get0_result 2718 EXIST::FUNCTION:
2172PKCS12_AUTHSAFES_it 2719 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2173PKCS12_AUTHSAFES_it 2719 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2174EVP_aes_256_ecb 2720 EXIST::FUNCTION:AES
2175PKCS12_pack_authsafes 2721 EXIST::FUNCTION:
2176ASN1_IA5STRING_it 2722 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2177ASN1_IA5STRING_it 2722 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2178UI_get_input_flags 2723 EXIST::FUNCTION:
2179EC_GROUP_set_generator 2724 EXIST::FUNCTION:EC
2180_ossl_old_des_string_to_2keys 2725 EXIST::FUNCTION:DES
2181OCSP_CERTID_free 2726 EXIST::FUNCTION:
2182X509_CERT_AUX_it 2727 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2183X509_CERT_AUX_it 2727 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2184CERTIFICATEPOLICIES_it 2728 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2185CERTIFICATEPOLICIES_it 2728 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2186_ossl_old_des_ede3_cbc_encrypt 2729 EXIST::FUNCTION:DES
2187RAND_set_rand_engine 2730 EXIST::FUNCTION:ENGINE
2188DSO_get_loaded_filename 2731 EXIST::FUNCTION:
2189X509_ATTRIBUTE_it 2732 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2190X509_ATTRIBUTE_it 2732 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2191OCSP_ONEREQ_get_ext_by_NID 2733 EXIST::FUNCTION:
2192PKCS12_decrypt_skey 2734 EXIST::FUNCTION:
2193KRB5_AUTHENT_it 2735 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2194KRB5_AUTHENT_it 2735 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2195UI_dup_error_string 2736 EXIST::FUNCTION:
2196RSAPublicKey_it 2737 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA
2197RSAPublicKey_it 2737 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RSA
2198i2d_OCSP_REQUEST 2738 EXIST::FUNCTION:
2199PKCS12_x509crl2certbag 2739 EXIST::FUNCTION:
2200OCSP_SERVICELOC_it 2740 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2201OCSP_SERVICELOC_it 2740 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2202ASN1_item_sign 2741 EXIST::FUNCTION:EVP
2203X509_CRL_set_issuer_name 2742 EXIST::FUNCTION:
2204OBJ_NAME_do_all_sorted 2743 EXIST::FUNCTION:
2205i2d_OCSP_BASICRESP 2744 EXIST::FUNCTION:
2206i2d_OCSP_RESPBYTES 2745 EXIST::FUNCTION:
2207PKCS12_unpack_p7encdata 2746 EXIST::FUNCTION:
2208HMAC_CTX_init 2747 EXIST::FUNCTION:HMAC
2209ENGINE_get_digest 2748 EXIST::FUNCTION:ENGINE
2210OCSP_RESPONSE_print 2749 EXIST::FUNCTION:
2211KRB5_TKTBODY_it 2750 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2212KRB5_TKTBODY_it 2750 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2213ACCESS_DESCRIPTION_it 2751 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2214ACCESS_DESCRIPTION_it 2751 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2215PKCS7_ISSUER_AND_SERIAL_it 2752 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2216PKCS7_ISSUER_AND_SERIAL_it 2752 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2217PBE2PARAM_it 2753 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2218PBE2PARAM_it 2753 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2219PKCS12_certbag2x509crl 2754 EXIST::FUNCTION:
2220PKCS7_SIGNED_it 2755 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2221PKCS7_SIGNED_it 2755 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2222ENGINE_get_cipher 2756 EXIST::FUNCTION:ENGINE
2223i2d_OCSP_CRLID 2757 EXIST::FUNCTION:
2224OCSP_SINGLERESP_new 2758 EXIST::FUNCTION:
2225ENGINE_cmd_is_executable 2759 EXIST::FUNCTION:ENGINE
2226RSA_up_ref 2760 EXIST::FUNCTION:RSA
2227ASN1_GENERALSTRING_it 2761 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2228ASN1_GENERALSTRING_it 2761 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2229ENGINE_register_DSA 2762 EXIST::FUNCTION:ENGINE
2230X509V3_EXT_add_nconf_sk 2763 EXIST::FUNCTION:
2231ENGINE_set_load_pubkey_function 2764 EXIST::FUNCTION:ENGINE
2232PKCS8_decrypt 2765 EXIST::FUNCTION:
2233PEM_bytes_read_bio 2766 EXIST::FUNCTION:BIO
2234DIRECTORYSTRING_it 2767 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2235DIRECTORYSTRING_it 2767 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2236d2i_OCSP_CRLID 2768 EXIST::FUNCTION:
2237EC_POINT_is_on_curve 2769 EXIST::FUNCTION:EC
2238CRYPTO_set_locked_mem_ex_functions 2770 EXIST:!VMS:FUNCTION:
2239CRYPTO_set_locked_mem_ex_funcs 2770 EXIST:VMS:FUNCTION:
2240d2i_KRB5_CHECKSUM 2771 EXIST::FUNCTION:
2241ASN1_item_dup 2772 EXIST::FUNCTION:
2242X509_it 2773 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2243X509_it 2773 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2244BN_mod_add 2774 EXIST::FUNCTION:
2245KRB5_AUTHDATA_free 2775 EXIST::FUNCTION:
2246_ossl_old_des_cbc_cksum 2776 EXIST::FUNCTION:DES
2247ASN1_item_verify 2777 EXIST::FUNCTION:EVP
2248CRYPTO_set_mem_ex_functions 2778 EXIST::FUNCTION:
2249EC_POINT_get_Jprojective_coordinates_GFp 2779 EXIST:!VMS:FUNCTION:EC
2250EC_POINT_get_Jproj_coords_GFp 2779 EXIST:VMS:FUNCTION:EC
2251ZLONG_it 2780 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2252ZLONG_it 2780 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2253CRYPTO_get_locked_mem_ex_functions 2781 EXIST:!VMS:FUNCTION:
2254CRYPTO_get_locked_mem_ex_funcs 2781 EXIST:VMS:FUNCTION:
2255ASN1_TIME_check 2782 EXIST::FUNCTION:
2256UI_get0_user_data 2783 EXIST::FUNCTION:
2257HMAC_CTX_cleanup 2784 EXIST::FUNCTION:HMAC
2258DSA_up_ref 2785 EXIST::FUNCTION:DSA
2259_ossl_old_des_ede3_cfb64_encrypt 2786 EXIST:!VMS:FUNCTION:DES
2260_ossl_odes_ede3_cfb64_encrypt 2786 EXIST:VMS:FUNCTION:DES
2261ASN1_BMPSTRING_it 2787 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2262ASN1_BMPSTRING_it 2787 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2263ASN1_tag2bit 2788 EXIST::FUNCTION:
2264UI_method_set_flusher 2789 EXIST::FUNCTION:
2265X509_ocspid_print 2790 EXIST::FUNCTION:BIO
2266KRB5_ENCDATA_it 2791 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2267KRB5_ENCDATA_it 2791 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2268ENGINE_get_load_pubkey_function 2792 EXIST::FUNCTION:ENGINE
2269UI_add_user_data 2793 EXIST::FUNCTION:
2270OCSP_REQUEST_delete_ext 2794 EXIST::FUNCTION:
2271UI_get_method 2795 EXIST::FUNCTION:
2272OCSP_ONEREQ_free 2796 EXIST::FUNCTION:
2273ASN1_PRINTABLESTRING_it 2797 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2274ASN1_PRINTABLESTRING_it 2797 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2275X509_CRL_set_nextUpdate 2798 EXIST::FUNCTION:
2276OCSP_REQUEST_it 2799 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2277OCSP_REQUEST_it 2799 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2278OCSP_BASICRESP_it 2800 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2279OCSP_BASICRESP_it 2800 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2280AES_ecb_encrypt 2801 EXIST::FUNCTION:AES
2281BN_mod_sqr 2802 EXIST::FUNCTION:
2282NETSCAPE_CERT_SEQUENCE_it 2803 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2283NETSCAPE_CERT_SEQUENCE_it 2803 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2284GENERAL_NAMES_it 2804 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2285GENERAL_NAMES_it 2804 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2286AUTHORITY_INFO_ACCESS_it 2805 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2287AUTHORITY_INFO_ACCESS_it 2805 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2288ASN1_FBOOLEAN_it 2806 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2289ASN1_FBOOLEAN_it 2806 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2290UI_set_ex_data 2807 EXIST::FUNCTION:
2291_ossl_old_des_string_to_key 2808 EXIST::FUNCTION:DES
2292ENGINE_register_all_RSA 2809 EXIST::FUNCTION:ENGINE
2293d2i_KRB5_PRINCNAME 2810 EXIST::FUNCTION:
2294OCSP_RESPBYTES_it 2811 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2295OCSP_RESPBYTES_it 2811 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2296X509_CINF_it 2812 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2297X509_CINF_it 2812 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2298ENGINE_unregister_digests 2813 EXIST::FUNCTION:ENGINE
2299d2i_EDIPARTYNAME 2814 EXIST::FUNCTION:
2300d2i_OCSP_SERVICELOC 2815 EXIST::FUNCTION:
2301ENGINE_get_digests 2816 EXIST::FUNCTION:ENGINE
2302_ossl_old_des_set_odd_parity 2817 EXIST::FUNCTION:DES
2303OCSP_RESPDATA_free 2818 EXIST::FUNCTION:
2304d2i_KRB5_TICKET 2819 EXIST::FUNCTION:
2305OTHERNAME_it 2820 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2306OTHERNAME_it 2820 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2307EVP_MD_CTX_cleanup 2821 EXIST::FUNCTION:
2308d2i_ASN1_GENERALSTRING 2822 EXIST::FUNCTION:
2309X509_CRL_set_version 2823 EXIST::FUNCTION:
2310BN_mod_sub 2824 EXIST::FUNCTION:
2311OCSP_SINGLERESP_get_ext_by_NID 2825 EXIST::FUNCTION:
2312ENGINE_get_ex_new_index 2826 EXIST::FUNCTION:ENGINE
2313OCSP_REQUEST_free 2827 EXIST::FUNCTION:
2314OCSP_REQUEST_add1_ext_i2d 2828 EXIST::FUNCTION:
2315X509_VAL_it 2829 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2316X509_VAL_it 2829 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2317EC_POINTs_make_affine 2830 EXIST::FUNCTION:EC
2318EC_POINT_mul 2831 EXIST::FUNCTION:EC
2319X509V3_EXT_add_nconf 2832 EXIST::FUNCTION:
2320X509_TRUST_set 2833 EXIST::FUNCTION:
2321X509_CRL_add1_ext_i2d 2834 EXIST::FUNCTION:
2322_ossl_old_des_fcrypt 2835 EXIST::FUNCTION:DES
2323DISPLAYTEXT_it 2836 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2324DISPLAYTEXT_it 2836 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2325X509_CRL_set_lastUpdate 2837 EXIST::FUNCTION:
2326OCSP_BASICRESP_free 2838 EXIST::FUNCTION:
2327OCSP_BASICRESP_add1_ext_i2d 2839 EXIST::FUNCTION:
2328d2i_KRB5_AUTHENTBODY 2840 EXIST::FUNCTION:
2329CRYPTO_set_ex_data_implementation 2841 EXIST:!VMS:FUNCTION:
2330CRYPTO_set_ex_data_impl 2841 EXIST:VMS:FUNCTION:
2331KRB5_ENCDATA_new 2842 EXIST::FUNCTION:
2332DSO_up_ref 2843 EXIST::FUNCTION:
2333OCSP_crl_reason_str 2844 EXIST::FUNCTION:
2334UI_get0_result_string 2845 EXIST::FUNCTION:
2335ASN1_GENERALSTRING_new 2846 EXIST::FUNCTION:
2336X509_SIG_it 2847 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2337X509_SIG_it 2847 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2338ERR_set_implementation 2848 EXIST::FUNCTION:
2339ERR_load_EC_strings 2849 EXIST::FUNCTION:EC
2340UI_get0_action_string 2850 EXIST::FUNCTION:
2341OCSP_ONEREQ_get_ext 2851 EXIST::FUNCTION:
2342EC_POINT_method_of 2852 EXIST::FUNCTION:EC
2343i2d_KRB5_APREQBODY 2853 EXIST::FUNCTION:
2344_ossl_old_des_ecb3_encrypt 2854 EXIST::FUNCTION:DES
2345CRYPTO_get_mem_ex_functions 2855 EXIST::FUNCTION:
2346ENGINE_get_ex_data 2856 EXIST::FUNCTION:ENGINE
2347UI_destroy_method 2857 EXIST::FUNCTION:
2348ASN1_item_i2d_bio 2858 EXIST::FUNCTION:BIO
2349OCSP_ONEREQ_get_ext_by_OBJ 2859 EXIST::FUNCTION:
2350ASN1_primitive_new 2860 EXIST::FUNCTION:
2351ASN1_PRINTABLE_it 2861 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2352ASN1_PRINTABLE_it 2861 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2353EVP_aes_192_ecb 2862 EXIST::FUNCTION:AES
2354OCSP_SIGNATURE_new 2863 EXIST::FUNCTION:
2355LONG_it 2864 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2356LONG_it 2864 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2357ASN1_VISIBLESTRING_it 2865 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2358ASN1_VISIBLESTRING_it 2865 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2359OCSP_SINGLERESP_add1_ext_i2d 2866 EXIST::FUNCTION:
2360d2i_OCSP_CERTID 2867 EXIST::FUNCTION:
2361ASN1_item_d2i_fp 2868 EXIST::FUNCTION:FP_API
2362CRL_DIST_POINTS_it 2869 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2363CRL_DIST_POINTS_it 2869 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2364GENERAL_NAME_print 2870 EXIST::FUNCTION:
2365OCSP_SINGLERESP_delete_ext 2871 EXIST::FUNCTION:
2366PKCS12_SAFEBAGS_it 2872 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2367PKCS12_SAFEBAGS_it 2872 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2368d2i_OCSP_SIGNATURE 2873 EXIST::FUNCTION:
2369OCSP_request_add1_nonce 2874 EXIST::FUNCTION:
2370ENGINE_set_cmd_defns 2875 EXIST::FUNCTION:ENGINE
2371OCSP_SERVICELOC_free 2876 EXIST::FUNCTION:
2372EC_GROUP_free 2877 EXIST::FUNCTION:EC
2373ASN1_BIT_STRING_it 2878 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2374ASN1_BIT_STRING_it 2878 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2375X509_REQ_it 2879 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2376X509_REQ_it 2879 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2377_ossl_old_des_cbc_encrypt 2880 EXIST::FUNCTION:DES
2378ERR_unload_strings 2881 EXIST::FUNCTION:
2379PKCS7_SIGN_ENVELOPE_it 2882 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2380PKCS7_SIGN_ENVELOPE_it 2882 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2381EDIPARTYNAME_free 2883 EXIST::FUNCTION:
2382OCSP_REQINFO_free 2884 EXIST::FUNCTION:
2383EC_GROUP_new_curve_GFp 2885 EXIST::FUNCTION:EC
2384OCSP_REQUEST_get1_ext_d2i 2886 EXIST::FUNCTION:
2385PKCS12_item_pack_safebag 2887 EXIST::FUNCTION:
2386asn1_ex_c2i 2888 EXIST::FUNCTION:
2387ENGINE_register_digests 2889 EXIST::FUNCTION:ENGINE
2388i2d_OCSP_REVOKEDINFO 2890 EXIST::FUNCTION:
2389asn1_enc_restore 2891 EXIST::FUNCTION:
2390UI_free 2892 EXIST::FUNCTION:
2391UI_new_method 2893 EXIST::FUNCTION:
2392EVP_EncryptInit_ex 2894 EXIST::FUNCTION:
2393X509_pubkey_digest 2895 EXIST::FUNCTION:EVP
2394EC_POINT_invert 2896 EXIST::FUNCTION:EC
2395OCSP_basic_sign 2897 EXIST::FUNCTION:
2396i2d_OCSP_RESPID 2898 EXIST::FUNCTION:
2397OCSP_check_nonce 2899 EXIST::FUNCTION:
2398ENGINE_ctrl_cmd 2900 EXIST::FUNCTION:ENGINE
2399d2i_KRB5_ENCKEY 2901 EXIST::FUNCTION:
2400OCSP_parse_url 2902 EXIST::FUNCTION:
2401OCSP_SINGLERESP_get_ext 2903 EXIST::FUNCTION:
2402OCSP_CRLID_free 2904 EXIST::FUNCTION:
2403OCSP_BASICRESP_get1_ext_d2i 2905 EXIST::FUNCTION:
2404RSAPrivateKey_it 2906 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:RSA
2405RSAPrivateKey_it 2906 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:RSA
2406ENGINE_register_all_DH 2907 EXIST::FUNCTION:ENGINE
2407i2d_EDIPARTYNAME 2908 EXIST::FUNCTION:
2408EC_POINT_get_affine_coordinates_GFp 2909 EXIST:!VMS:FUNCTION:EC
2409EC_POINT_get_affine_coords_GFp 2909 EXIST:VMS:FUNCTION:EC
2410OCSP_CRLID_new 2910 EXIST::FUNCTION:
2411ENGINE_get_flags 2911 EXIST::FUNCTION:ENGINE
2412OCSP_ONEREQ_it 2912 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2413OCSP_ONEREQ_it 2912 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2414UI_process 2913 EXIST::FUNCTION:
2415ASN1_INTEGER_it 2914 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2416ASN1_INTEGER_it 2914 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2417EVP_CipherInit_ex 2915 EXIST::FUNCTION:
2418UI_get_string_type 2916 EXIST::FUNCTION:
2419ENGINE_unregister_DH 2917 EXIST::FUNCTION:ENGINE
2420ENGINE_register_all_DSA 2918 EXIST::FUNCTION:ENGINE
2421OCSP_ONEREQ_get_ext_by_critical 2919 EXIST::FUNCTION:
2422bn_dup_expand 2920 EXIST::FUNCTION:
2423OCSP_cert_id_new 2921 EXIST::FUNCTION:
2424BASIC_CONSTRAINTS_it 2922 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2425BASIC_CONSTRAINTS_it 2922 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2426BN_mod_add_quick 2923 EXIST::FUNCTION:
2427EC_POINT_new 2924 EXIST::FUNCTION:EC
2428EVP_MD_CTX_destroy 2925 EXIST::FUNCTION:
2429OCSP_RESPBYTES_free 2926 EXIST::FUNCTION:
2430EVP_aes_128_cbc 2927 EXIST::FUNCTION:AES
2431OCSP_SINGLERESP_get1_ext_d2i 2928 EXIST::FUNCTION:
2432EC_POINT_free 2929 EXIST::FUNCTION:EC
2433DH_up_ref 2930 EXIST::FUNCTION:DH
2434X509_NAME_ENTRY_it 2931 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2435X509_NAME_ENTRY_it 2931 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2436UI_get_ex_new_index 2932 EXIST::FUNCTION:
2437BN_mod_sub_quick 2933 EXIST::FUNCTION:
2438OCSP_ONEREQ_add_ext 2934 EXIST::FUNCTION:
2439OCSP_request_sign 2935 EXIST::FUNCTION:
2440EVP_DigestFinal_ex 2936 EXIST::FUNCTION:
2441ENGINE_set_digests 2937 EXIST::FUNCTION:ENGINE
2442OCSP_id_issuer_cmp 2938 EXIST::FUNCTION:
2443OBJ_NAME_do_all 2939 EXIST::FUNCTION:
2444EC_POINTs_mul 2940 EXIST::FUNCTION:EC
2445ENGINE_register_complete 2941 EXIST::FUNCTION:ENGINE
2446X509V3_EXT_nconf_nid 2942 EXIST::FUNCTION:
2447ASN1_SEQUENCE_it 2943 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2448ASN1_SEQUENCE_it 2943 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2449UI_set_default_method 2944 EXIST::FUNCTION:
2450RAND_query_egd_bytes 2945 EXIST::FUNCTION:
2451UI_method_get_writer 2946 EXIST::FUNCTION:
2452UI_OpenSSL 2947 EXIST::FUNCTION:
2453PEM_def_callback 2948 EXIST::FUNCTION:
2454ENGINE_cleanup 2949 EXIST::FUNCTION:ENGINE
2455DIST_POINT_it 2950 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2456DIST_POINT_it 2950 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2457OCSP_SINGLERESP_it 2951 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2458OCSP_SINGLERESP_it 2951 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2459d2i_KRB5_TKTBODY 2952 EXIST::FUNCTION:
2460EC_POINT_cmp 2953 EXIST::FUNCTION:EC
2461OCSP_REVOKEDINFO_new 2954 EXIST::FUNCTION:
2462i2d_OCSP_CERTSTATUS 2955 EXIST::FUNCTION:
2463OCSP_basic_add1_nonce 2956 EXIST::FUNCTION:
2464ASN1_item_ex_d2i 2957 EXIST::FUNCTION:
2465BN_mod_lshift1_quick 2958 EXIST::FUNCTION:
2466UI_set_method 2959 EXIST::FUNCTION:
2467OCSP_id_get0_info 2960 EXIST::FUNCTION:
2468BN_mod_sqrt 2961 EXIST::FUNCTION:
2469EC_GROUP_copy 2962 EXIST::FUNCTION:EC
2470KRB5_ENCDATA_free 2963 EXIST::FUNCTION:
2471_ossl_old_des_cfb_encrypt 2964 EXIST::FUNCTION:DES
2472OCSP_SINGLERESP_get_ext_by_OBJ 2965 EXIST::FUNCTION:
2473OCSP_cert_to_id 2966 EXIST::FUNCTION:
2474OCSP_RESPID_new 2967 EXIST::FUNCTION:
2475OCSP_RESPDATA_it 2968 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2476OCSP_RESPDATA_it 2968 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2477d2i_OCSP_RESPDATA 2969 EXIST::FUNCTION:
2478ENGINE_register_all_complete 2970 EXIST::FUNCTION:ENGINE
2479OCSP_check_validity 2971 EXIST::FUNCTION:
2480PKCS12_BAGS_it 2972 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2481PKCS12_BAGS_it 2972 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2482OCSP_url_svcloc_new 2973 EXIST::FUNCTION:
2483ASN1_template_free 2974 EXIST::FUNCTION:
2484OCSP_SINGLERESP_add_ext 2975 EXIST::FUNCTION:
2485KRB5_AUTHENTBODY_it 2976 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2486KRB5_AUTHENTBODY_it 2976 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2487X509_supported_extension 2977 EXIST::FUNCTION:
2488i2d_KRB5_AUTHDATA 2978 EXIST::FUNCTION:
2489UI_method_get_opener 2979 EXIST::FUNCTION:
2490ENGINE_set_ex_data 2980 EXIST::FUNCTION:ENGINE
2491OCSP_REQUEST_print 2981 EXIST::FUNCTION:
2492CBIGNUM_it 2982 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2493CBIGNUM_it 2982 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2494KRB5_TICKET_new 2983 EXIST::FUNCTION:
2495KRB5_APREQ_new 2984 EXIST::FUNCTION:
2496EC_GROUP_get_curve_GFp 2985 EXIST::FUNCTION:EC
2497KRB5_ENCKEY_new 2986 EXIST::FUNCTION:
2498ASN1_template_d2i 2987 EXIST::FUNCTION:
2499_ossl_old_des_quad_cksum 2988 EXIST::FUNCTION:DES
2500OCSP_single_get0_status 2989 EXIST::FUNCTION:
2501BN_swap 2990 EXIST::FUNCTION:
2502POLICYINFO_it 2991 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2503POLICYINFO_it 2991 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2504ENGINE_set_destroy_function 2992 EXIST::FUNCTION:ENGINE
2505asn1_enc_free 2993 EXIST::FUNCTION:
2506OCSP_RESPID_it 2994 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2507OCSP_RESPID_it 2994 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2508EC_GROUP_new 2995 EXIST::FUNCTION:EC
2509EVP_aes_256_cbc 2996 EXIST::FUNCTION:AES
2510i2d_KRB5_PRINCNAME 2997 EXIST::FUNCTION:
2511_ossl_old_des_encrypt2 2998 EXIST::FUNCTION:DES
2512_ossl_old_des_encrypt3 2999 EXIST::FUNCTION:DES
2513PKCS8_PRIV_KEY_INFO_it 3000 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2514PKCS8_PRIV_KEY_INFO_it 3000 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2515OCSP_REQINFO_it 3001 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2516OCSP_REQINFO_it 3001 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2517PBEPARAM_it 3002 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2518PBEPARAM_it 3002 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2519KRB5_AUTHENTBODY_new 3003 EXIST::FUNCTION:
2520X509_CRL_add0_revoked 3004 EXIST::FUNCTION:
2521EDIPARTYNAME_it 3005 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2522EDIPARTYNAME_it 3005 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2523NETSCAPE_SPKI_it 3006 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2524NETSCAPE_SPKI_it 3006 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2525UI_get0_test_string 3007 EXIST::FUNCTION:
2526ENGINE_get_cipher_engine 3008 EXIST::FUNCTION:ENGINE
2527ENGINE_register_all_ciphers 3009 EXIST::FUNCTION:ENGINE
2528EC_POINT_copy 3010 EXIST::FUNCTION:EC
2529BN_kronecker 3011 EXIST::FUNCTION:
2530_ossl_old_des_ede3_ofb64_encrypt 3012 EXIST:!VMS:FUNCTION:DES
2531_ossl_odes_ede3_ofb64_encrypt 3012 EXIST:VMS:FUNCTION:DES
2532UI_method_get_reader 3013 EXIST::FUNCTION:
2533OCSP_BASICRESP_get_ext_count 3014 EXIST::FUNCTION:
2534ASN1_ENUMERATED_it 3015 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2535ASN1_ENUMERATED_it 3015 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2536UI_set_result 3016 EXIST::FUNCTION:
2537i2d_KRB5_TICKET 3017 EXIST::FUNCTION:
2538X509_print_ex_fp 3018 EXIST::FUNCTION:FP_API
2539EVP_CIPHER_CTX_set_padding 3019 EXIST::FUNCTION:
2540d2i_OCSP_RESPONSE 3020 EXIST::FUNCTION:
2541ASN1_UTCTIME_it 3021 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2542ASN1_UTCTIME_it 3021 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2543_ossl_old_des_enc_write 3022 EXIST::FUNCTION:DES
2544OCSP_RESPONSE_new 3023 EXIST::FUNCTION:
2545AES_set_encrypt_key 3024 EXIST::FUNCTION:AES
2546OCSP_resp_count 3025 EXIST::FUNCTION:
2547KRB5_CHECKSUM_new 3026 EXIST::FUNCTION:
2548ENGINE_load_cswift 3027 EXIST::FUNCTION:ENGINE
2549OCSP_onereq_get0_id 3028 EXIST::FUNCTION:
2550ENGINE_set_default_ciphers 3029 EXIST::FUNCTION:ENGINE
2551NOTICEREF_it 3030 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2552NOTICEREF_it 3030 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2553X509V3_EXT_CRL_add_nconf 3031 EXIST::FUNCTION:
2554OCSP_REVOKEDINFO_it 3032 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2555OCSP_REVOKEDINFO_it 3032 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2556AES_encrypt 3033 EXIST::FUNCTION:AES
2557OCSP_REQUEST_new 3034 EXIST::FUNCTION:
2558ASN1_ANY_it 3035 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2559ASN1_ANY_it 3035 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2560CRYPTO_ex_data_new_class 3036 EXIST::FUNCTION:
2561_ossl_old_des_ncbc_encrypt 3037 EXIST::FUNCTION:DES
2562i2d_KRB5_TKTBODY 3038 EXIST::FUNCTION:
2563EC_POINT_clear_free 3039 EXIST::FUNCTION:EC
2564AES_decrypt 3040 EXIST::FUNCTION:AES
2565asn1_enc_init 3041 EXIST::FUNCTION:
2566UI_get_result_maxsize 3042 EXIST::FUNCTION:
2567OCSP_CERTID_new 3043 EXIST::FUNCTION:
2568ENGINE_unregister_RAND 3044 EXIST::FUNCTION:ENGINE
2569UI_method_get_closer 3045 EXIST::FUNCTION:
2570d2i_KRB5_ENCDATA 3046 EXIST::FUNCTION:
2571OCSP_request_onereq_count 3047 EXIST::FUNCTION:
2572OCSP_basic_verify 3048 EXIST::FUNCTION:
2573KRB5_AUTHENTBODY_free 3049 EXIST::FUNCTION:
2574ASN1_item_d2i 3050 EXIST::FUNCTION:
2575ASN1_primitive_free 3051 EXIST::FUNCTION:
2576i2d_EXTENDED_KEY_USAGE 3052 EXIST::FUNCTION:
2577i2d_OCSP_SIGNATURE 3053 EXIST::FUNCTION:
2578asn1_enc_save 3054 EXIST::FUNCTION:
2579ENGINE_load_nuron 3055 EXIST::FUNCTION:ENGINE
2580_ossl_old_des_pcbc_encrypt 3056 EXIST::FUNCTION:DES
2581PKCS12_MAC_DATA_it 3057 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2582PKCS12_MAC_DATA_it 3057 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2583OCSP_accept_responses_new 3058 EXIST::FUNCTION:
2584asn1_do_lock 3059 EXIST::FUNCTION:
2585PKCS7_ATTR_VERIFY_it 3060 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2586PKCS7_ATTR_VERIFY_it 3060 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2587KRB5_APREQBODY_it 3061 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2588KRB5_APREQBODY_it 3061 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2589i2d_OCSP_SINGLERESP 3062 EXIST::FUNCTION:
2590ASN1_item_ex_new 3063 EXIST::FUNCTION:
2591UI_add_verify_string 3064 EXIST::FUNCTION:
2592_ossl_old_des_set_key 3065 EXIST::FUNCTION:DES
2593KRB5_PRINCNAME_it 3066 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2594KRB5_PRINCNAME_it 3066 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2595EVP_DecryptInit_ex 3067 EXIST::FUNCTION:
2596i2d_OCSP_CERTID 3068 EXIST::FUNCTION:
2597ASN1_item_d2i_bio 3069 EXIST::FUNCTION:BIO
2598EC_POINT_dbl 3070 EXIST::FUNCTION:EC
2599asn1_get_choice_selector 3071 EXIST::FUNCTION:
2600i2d_KRB5_CHECKSUM 3072 EXIST::FUNCTION:
2601ENGINE_set_table_flags 3073 EXIST::FUNCTION:ENGINE
2602AES_options 3074 EXIST::FUNCTION:AES
2603ENGINE_load_chil 3075 EXIST::FUNCTION:ENGINE
2604OCSP_id_cmp 3076 EXIST::FUNCTION:
2605OCSP_BASICRESP_new 3077 EXIST::FUNCTION:
2606OCSP_REQUEST_get_ext_by_NID 3078 EXIST::FUNCTION:
2607KRB5_APREQ_it 3079 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2608KRB5_APREQ_it 3079 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2609ENGINE_get_destroy_function 3080 EXIST::FUNCTION:ENGINE
2610CONF_set_nconf 3081 EXIST::FUNCTION:
2611ASN1_PRINTABLE_free 3082 EXIST::FUNCTION:
2612OCSP_BASICRESP_get_ext_by_NID 3083 EXIST::FUNCTION:
2613DIST_POINT_NAME_it 3084 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2614DIST_POINT_NAME_it 3084 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2615X509V3_extensions_print 3085 EXIST::FUNCTION:
2616_ossl_old_des_cfb64_encrypt 3086 EXIST::FUNCTION:DES
2617X509_REVOKED_add1_ext_i2d 3087 EXIST::FUNCTION:
2618_ossl_old_des_ofb_encrypt 3088 EXIST::FUNCTION:DES
2619KRB5_TKTBODY_new 3089 EXIST::FUNCTION:
2620ASN1_OCTET_STRING_it 3090 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2621ASN1_OCTET_STRING_it 3090 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2622ERR_load_UI_strings 3091 EXIST::FUNCTION:
2623i2d_KRB5_ENCKEY 3092 EXIST::FUNCTION:
2624ASN1_template_new 3093 EXIST::FUNCTION:
2625OCSP_SIGNATURE_free 3094 EXIST::FUNCTION:
2626ASN1_item_i2d_fp 3095 EXIST::FUNCTION:FP_API
2627KRB5_PRINCNAME_free 3096 EXIST::FUNCTION:
2628PKCS7_RECIP_INFO_it 3097 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2629PKCS7_RECIP_INFO_it 3097 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2630EXTENDED_KEY_USAGE_it 3098 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2631EXTENDED_KEY_USAGE_it 3098 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2632EC_GFp_simple_method 3099 EXIST::FUNCTION:EC
2633EC_GROUP_precompute_mult 3100 EXIST::FUNCTION:EC
2634OCSP_request_onereq_get0 3101 EXIST::FUNCTION:
2635UI_method_set_writer 3102 EXIST::FUNCTION:
2636KRB5_AUTHENT_new 3103 EXIST::FUNCTION:
2637X509_CRL_INFO_it 3104 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2638X509_CRL_INFO_it 3104 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2639DSO_set_name_converter 3105 EXIST::FUNCTION:
2640AES_set_decrypt_key 3106 EXIST::FUNCTION:AES
2641PKCS7_DIGEST_it 3107 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2642PKCS7_DIGEST_it 3107 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2643PKCS12_x5092certbag 3108 EXIST::FUNCTION:
2644EVP_DigestInit_ex 3109 EXIST::FUNCTION:
2645i2a_ACCESS_DESCRIPTION 3110 EXIST::FUNCTION:
2646OCSP_RESPONSE_it 3111 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2647OCSP_RESPONSE_it 3111 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2648PKCS7_ENC_CONTENT_it 3112 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2649PKCS7_ENC_CONTENT_it 3112 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2650OCSP_request_add0_id 3113 EXIST::FUNCTION:
2651EC_POINT_make_affine 3114 EXIST::FUNCTION:EC
2652DSO_get_filename 3115 EXIST::FUNCTION:
2653OCSP_CERTSTATUS_it 3116 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2654OCSP_CERTSTATUS_it 3116 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2655OCSP_request_add1_cert 3117 EXIST::FUNCTION:
2656UI_get0_output_string 3118 EXIST::FUNCTION:
2657UI_dup_verify_string 3119 EXIST::FUNCTION:
2658BN_mod_lshift 3120 EXIST::FUNCTION:
2659KRB5_AUTHDATA_it 3121 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2660KRB5_AUTHDATA_it 3121 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2661asn1_set_choice_selector 3122 EXIST::FUNCTION:
2662OCSP_basic_add1_status 3123 EXIST::FUNCTION:
2663OCSP_RESPID_free 3124 EXIST::FUNCTION:
2664asn1_get_field_ptr 3125 EXIST::FUNCTION:
2665UI_add_input_string 3126 EXIST::FUNCTION:
2666OCSP_CRLID_it 3127 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2667OCSP_CRLID_it 3127 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2668i2d_KRB5_AUTHENTBODY 3128 EXIST::FUNCTION:
2669OCSP_REQUEST_get_ext_count 3129 EXIST::FUNCTION:
2670ENGINE_load_atalla 3130 EXIST::FUNCTION:ENGINE
2671X509_NAME_it 3131 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2672X509_NAME_it 3131 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2673USERNOTICE_it 3132 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2674USERNOTICE_it 3132 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2675OCSP_REQINFO_new 3133 EXIST::FUNCTION:
2676OCSP_BASICRESP_get_ext 3134 EXIST::FUNCTION:
2677CRYPTO_get_ex_data_implementation 3135 EXIST:!VMS:FUNCTION:
2678CRYPTO_get_ex_data_impl 3135 EXIST:VMS:FUNCTION:
2679ASN1_item_pack 3136 EXIST::FUNCTION:
2680i2d_KRB5_ENCDATA 3137 EXIST::FUNCTION:
2681X509_PURPOSE_set 3138 EXIST::FUNCTION:
2682X509_REQ_INFO_it 3139 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2683X509_REQ_INFO_it 3139 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2684UI_method_set_opener 3140 EXIST::FUNCTION:
2685ASN1_item_ex_free 3141 EXIST::FUNCTION:
2686ASN1_BOOLEAN_it 3142 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2687ASN1_BOOLEAN_it 3142 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2688ENGINE_get_table_flags 3143 EXIST::FUNCTION:ENGINE
2689UI_create_method 3144 EXIST::FUNCTION:
2690OCSP_ONEREQ_add1_ext_i2d 3145 EXIST::FUNCTION:
2691_shadow_DES_check_key 3146 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:DES
2692_shadow_DES_check_key 3146 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:DES
2693d2i_OCSP_REQINFO 3147 EXIST::FUNCTION:
2694UI_add_info_string 3148 EXIST::FUNCTION:
2695UI_get_result_minsize 3149 EXIST::FUNCTION:
2696ASN1_NULL_it 3150 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2697ASN1_NULL_it 3150 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2698BN_mod_lshift1 3151 EXIST::FUNCTION:
2699d2i_OCSP_ONEREQ 3152 EXIST::FUNCTION:
2700OCSP_ONEREQ_new 3153 EXIST::FUNCTION:
2701KRB5_TICKET_it 3154 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2702KRB5_TICKET_it 3154 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2703EVP_aes_192_cbc 3155 EXIST::FUNCTION:AES
2704KRB5_TICKET_free 3156 EXIST::FUNCTION:
2705UI_new 3157 EXIST::FUNCTION:
2706OCSP_response_create 3158 EXIST::FUNCTION:
2707_ossl_old_des_xcbc_encrypt 3159 EXIST::FUNCTION:DES
2708PKCS7_it 3160 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2709PKCS7_it 3160 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2710OCSP_REQUEST_get_ext_by_critical 3161 EXIST:!VMS:FUNCTION:
2711OCSP_REQUEST_get_ext_by_crit 3161 EXIST:VMS:FUNCTION:
2712ENGINE_set_flags 3162 EXIST::FUNCTION:ENGINE
2713_ossl_old_des_ecb_encrypt 3163 EXIST::FUNCTION:DES
2714OCSP_response_get1_basic 3164 EXIST::FUNCTION:
2715EVP_Digest 3165 EXIST::FUNCTION:
2716OCSP_ONEREQ_delete_ext 3166 EXIST::FUNCTION:
2717ASN1_TBOOLEAN_it 3167 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2718ASN1_TBOOLEAN_it 3167 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2719ASN1_item_new 3168 EXIST::FUNCTION:
2720ASN1_TIME_to_generalizedtime 3169 EXIST::FUNCTION:
2721BIGNUM_it 3170 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2722BIGNUM_it 3170 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2723AES_cbc_encrypt 3171 EXIST::FUNCTION:AES
2724ENGINE_get_load_privkey_function 3172 EXIST:!VMS:FUNCTION:ENGINE
2725ENGINE_get_load_privkey_fn 3172 EXIST:VMS:FUNCTION:ENGINE
2726OCSP_RESPONSE_free 3173 EXIST::FUNCTION:
2727UI_method_set_reader 3174 EXIST::FUNCTION:
2728i2d_ASN1_T61STRING 3175 EXIST::FUNCTION:
2729EC_POINT_set_to_infinity 3176 EXIST::FUNCTION:EC
2730ERR_load_OCSP_strings 3177 EXIST::FUNCTION:
2731EC_POINT_point2oct 3178 EXIST::FUNCTION:EC
2732KRB5_APREQ_free 3179 EXIST::FUNCTION:
2733ASN1_OBJECT_it 3180 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2734ASN1_OBJECT_it 3180 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2735OCSP_crlID_new 3181 EXIST:!OS2,!VMS,!WIN16:FUNCTION:
2736OCSP_crlID2_new 3181 EXIST:OS2,VMS,WIN16:FUNCTION:
2737CONF_modules_load_file 3182 EXIST::FUNCTION:
2738CONF_imodule_set_usr_data 3183 EXIST::FUNCTION:
2739ENGINE_set_default_string 3184 EXIST::FUNCTION:ENGINE
2740CONF_module_get_usr_data 3185 EXIST::FUNCTION:
2741ASN1_add_oid_module 3186 EXIST::FUNCTION:
2742CONF_modules_finish 3187 EXIST::FUNCTION:
2743OPENSSL_config 3188 EXIST::FUNCTION:
2744CONF_modules_unload 3189 EXIST::FUNCTION:
2745CONF_imodule_get_value 3190 EXIST::FUNCTION:
2746CONF_module_set_usr_data 3191 EXIST::FUNCTION:
2747CONF_parse_list 3192 EXIST::FUNCTION:
2748CONF_module_add 3193 EXIST::FUNCTION:
2749CONF_get1_default_config_file 3194 EXIST::FUNCTION:
2750CONF_imodule_get_flags 3195 EXIST::FUNCTION:
2751CONF_imodule_get_module 3196 EXIST::FUNCTION:
2752CONF_modules_load 3197 EXIST::FUNCTION:
2753CONF_imodule_get_name 3198 EXIST::FUNCTION:
2754ERR_peek_top_error 3199 NOEXIST::FUNCTION:
2755CONF_imodule_get_usr_data 3200 EXIST::FUNCTION:
2756CONF_imodule_set_flags 3201 EXIST::FUNCTION:
2757ENGINE_add_conf_module 3202 EXIST::FUNCTION:ENGINE
2758ERR_peek_last_error_line 3203 EXIST::FUNCTION:
2759ERR_peek_last_error_line_data 3204 EXIST::FUNCTION:
2760ERR_peek_last_error 3205 EXIST::FUNCTION:
2761DES_read_2passwords 3206 EXIST::FUNCTION:DES
2762DES_read_password 3207 EXIST::FUNCTION:DES
2763UI_UTIL_read_pw 3208 EXIST::FUNCTION:
2764UI_UTIL_read_pw_string 3209 EXIST::FUNCTION:
2765ENGINE_load_aep 3210 EXIST::FUNCTION:ENGINE
2766ENGINE_load_sureware 3211 EXIST::FUNCTION:ENGINE
2767OPENSSL_add_all_algorithms_noconf 3212 EXIST:!VMS:FUNCTION:
2768OPENSSL_add_all_algo_noconf 3212 EXIST:VMS:FUNCTION:
2769OPENSSL_add_all_algorithms_conf 3213 EXIST:!VMS:FUNCTION:
2770OPENSSL_add_all_algo_conf 3213 EXIST:VMS:FUNCTION:
2771OPENSSL_load_builtin_modules 3214 EXIST::FUNCTION:
2772AES_ofb128_encrypt 3215 EXIST::FUNCTION:AES
2773AES_ctr128_encrypt 3216 EXIST::FUNCTION:AES
2774AES_cfb128_encrypt 3217 EXIST::FUNCTION:AES
2775ENGINE_load_4758cca 3218 EXIST::FUNCTION:ENGINE
2776_ossl_096_des_random_seed 3219 EXIST::FUNCTION:DES
2777EVP_aes_256_ofb 3220 EXIST::FUNCTION:AES
2778EVP_aes_192_ofb 3221 EXIST::FUNCTION:AES
2779EVP_aes_128_cfb128 3222 EXIST::FUNCTION:AES
2780EVP_aes_256_cfb128 3223 EXIST::FUNCTION:AES
2781EVP_aes_128_ofb 3224 EXIST::FUNCTION:AES
2782EVP_aes_192_cfb128 3225 EXIST::FUNCTION:AES
2783CONF_modules_free 3226 EXIST::FUNCTION:
2784NCONF_default 3227 EXIST::FUNCTION:
2785OPENSSL_no_config 3228 EXIST::FUNCTION:
2786NCONF_WIN32 3229 EXIST::FUNCTION:
2787ASN1_UNIVERSALSTRING_new 3230 EXIST::FUNCTION:
2788EVP_des_ede_ecb 3231 EXIST::FUNCTION:DES
2789i2d_ASN1_UNIVERSALSTRING 3232 EXIST::FUNCTION:
2790ASN1_UNIVERSALSTRING_free 3233 EXIST::FUNCTION:
2791ASN1_UNIVERSALSTRING_it 3234 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2792ASN1_UNIVERSALSTRING_it 3234 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2793d2i_ASN1_UNIVERSALSTRING 3235 EXIST::FUNCTION:
2794EVP_des_ede3_ecb 3236 EXIST::FUNCTION:DES
2795X509_REQ_print_ex 3237 EXIST::FUNCTION:BIO
2796ENGINE_up_ref 3238 EXIST::FUNCTION:ENGINE
2797BUF_MEM_grow_clean 3239 EXIST::FUNCTION:
2798CRYPTO_realloc_clean 3240 EXIST::FUNCTION:
2799BUF_strlcat 3241 EXIST::FUNCTION:
2800BIO_indent 3242 EXIST::FUNCTION:
2801BUF_strlcpy 3243 EXIST::FUNCTION:
2802OpenSSLDie 3244 EXIST::FUNCTION:
2803OPENSSL_cleanse 3245 EXIST::FUNCTION:
2804ENGINE_setup_bsd_cryptodev 3246 EXIST:__FreeBSD__:FUNCTION:ENGINE
2805ERR_release_err_state_table 3247 EXIST::FUNCTION:LHASH
2806EVP_aes_128_cfb8 3248 EXIST::FUNCTION:AES
2807FIPS_corrupt_rsa 3249 EXIST:OPENSSL_FIPS:FUNCTION:
2808FIPS_selftest_des 3250 EXIST:OPENSSL_FIPS:FUNCTION:
2809EVP_aes_128_cfb1 3251 EXIST::FUNCTION:AES
2810EVP_aes_192_cfb8 3252 EXIST::FUNCTION:AES
2811FIPS_mode_set 3253 EXIST:OPENSSL_FIPS:FUNCTION:
2812FIPS_selftest_dsa 3254 EXIST:OPENSSL_FIPS:FUNCTION:
2813EVP_aes_256_cfb8 3255 EXIST::FUNCTION:AES
2814FIPS_allow_md5 3256 NOEXIST::FUNCTION:
2815DES_ede3_cfb_encrypt 3257 EXIST::FUNCTION:DES
2816EVP_des_ede3_cfb8 3258 EXIST::FUNCTION:DES
2817FIPS_rand_seeded 3259 EXIST:OPENSSL_FIPS:FUNCTION:
2818AES_cfbr_encrypt_block 3260 EXIST::FUNCTION:AES
2819AES_cfb8_encrypt 3261 EXIST::FUNCTION:AES
2820FIPS_rand_seed 3262 EXIST:OPENSSL_FIPS:FUNCTION:
2821FIPS_corrupt_des 3263 EXIST:OPENSSL_FIPS:FUNCTION:
2822EVP_aes_192_cfb1 3264 EXIST::FUNCTION:AES
2823FIPS_selftest_aes 3265 EXIST:OPENSSL_FIPS:FUNCTION:
2824FIPS_set_prng_key 3266 EXIST:OPENSSL_FIPS:FUNCTION:
2825EVP_des_cfb8 3267 EXIST::FUNCTION:DES
2826FIPS_corrupt_dsa 3268 EXIST:OPENSSL_FIPS:FUNCTION:
2827FIPS_test_mode 3269 EXIST:OPENSSL_FIPS:FUNCTION:
2828FIPS_rand_method 3270 EXIST:OPENSSL_FIPS:FUNCTION:
2829EVP_aes_256_cfb1 3271 EXIST::FUNCTION:AES
2830ERR_load_FIPS_strings 3272 EXIST:OPENSSL_FIPS:FUNCTION:
2831FIPS_corrupt_aes 3273 EXIST:OPENSSL_FIPS:FUNCTION:
2832FIPS_selftest_sha1 3274 EXIST:OPENSSL_FIPS:FUNCTION:
2833FIPS_selftest_rsa 3275 EXIST:OPENSSL_FIPS:FUNCTION:
2834FIPS_corrupt_sha1 3276 EXIST:OPENSSL_FIPS:FUNCTION:
2835EVP_des_cfb1 3277 EXIST::FUNCTION:DES
2836FIPS_dsa_check 3278 EXIST:OPENSSL_FIPS:FUNCTION:
2837AES_cfb1_encrypt 3279 EXIST::FUNCTION:AES
2838EVP_des_ede3_cfb1 3280 EXIST::FUNCTION:DES
2839FIPS_rand_check 3281 EXIST:OPENSSL_FIPS:FUNCTION:
2840FIPS_md5_allowed 3282 NOEXIST::FUNCTION:
2841FIPS_mode 3283 EXIST:OPENSSL_FIPS:FUNCTION:
2842FIPS_selftest_failed 3284 EXIST:OPENSSL_FIPS:FUNCTION:
2843sk_is_sorted 3285 EXIST::FUNCTION:
2844X509_check_ca 3286 EXIST::FUNCTION:
2845private_idea_set_encrypt_key 3287 EXIST:OPENSSL_FIPS:FUNCTION:IDEA
2846HMAC_CTX_set_flags 3288 EXIST::FUNCTION:HMAC
2847private_SHA_Init 3289 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA0
2848private_CAST_set_key 3290 EXIST:OPENSSL_FIPS:FUNCTION:CAST
2849private_RIPEMD160_Init 3291 EXIST:OPENSSL_FIPS:FUNCTION:RIPEMD
2850private_RC5_32_set_key 3292 EXIST:OPENSSL_FIPS:FUNCTION:RC5
2851private_MD5_Init 3293 EXIST:OPENSSL_FIPS:FUNCTION:MD5
2852private_RC4_set_key 3294 EXIST:OPENSSL_FIPS:FUNCTION:RC4
2853private_MDC2_Init 3295 EXIST:OPENSSL_FIPS:FUNCTION:MDC2
2854private_RC2_set_key 3296 EXIST:OPENSSL_FIPS:FUNCTION:RC2
2855private_MD4_Init 3297 EXIST:OPENSSL_FIPS:FUNCTION:MD4
2856private_BF_set_key 3298 EXIST:OPENSSL_FIPS:FUNCTION:BF
2857private_MD2_Init 3299 EXIST:OPENSSL_FIPS:FUNCTION:MD2
2858d2i_PROXY_CERT_INFO_EXTENSION 3300 EXIST::FUNCTION:
2859PROXY_POLICY_it 3301 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2860PROXY_POLICY_it 3301 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2861i2d_PROXY_POLICY 3302 EXIST::FUNCTION:
2862i2d_PROXY_CERT_INFO_EXTENSION 3303 EXIST::FUNCTION:
2863d2i_PROXY_POLICY 3304 EXIST::FUNCTION:
2864PROXY_CERT_INFO_EXTENSION_new 3305 EXIST::FUNCTION:
2865PROXY_CERT_INFO_EXTENSION_free 3306 EXIST::FUNCTION:
2866PROXY_CERT_INFO_EXTENSION_it 3307 EXIST:!EXPORT_VAR_AS_FUNCTION:VARIABLE:
2867PROXY_CERT_INFO_EXTENSION_it 3307 EXIST:EXPORT_VAR_AS_FUNCTION:FUNCTION:
2868PROXY_POLICY_free 3308 EXIST::FUNCTION:
2869PROXY_POLICY_new 3309 EXIST::FUNCTION:
2870BN_MONT_CTX_set_locked 3310 EXIST::FUNCTION:
2871FIPS_selftest_rng 3311 EXIST:OPENSSL_FIPS:FUNCTION:
2872EVP_sha384 3312 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2873EVP_sha512 3313 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2874EVP_sha224 3314 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2875EVP_sha256 3315 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2876FIPS_selftest_hmac 3316 EXIST:OPENSSL_FIPS:FUNCTION:
2877FIPS_corrupt_rng 3317 EXIST:OPENSSL_FIPS:FUNCTION:
2878BN_mod_exp_mont_consttime 3318 EXIST::FUNCTION:
2879RSA_X931_hash_id 3319 EXIST::FUNCTION:RSA
2880RSA_padding_check_X931 3320 EXIST::FUNCTION:RSA
2881RSA_verify_PKCS1_PSS 3321 EXIST::FUNCTION:RSA
2882RSA_padding_add_X931 3322 EXIST::FUNCTION:RSA
2883RSA_padding_add_PKCS1_PSS 3323 EXIST::FUNCTION:RSA
2884PKCS1_MGF1 3324 EXIST::FUNCTION:RSA
2885BN_X931_generate_Xpq 3325 EXIST:OPENSSL_FIPS:FUNCTION:
2886RSA_X931_generate_key 3326 EXIST:OPENSSL_FIPS:FUNCTION:RSA
2887BN_X931_derive_prime 3327 EXIST:OPENSSL_FIPS:FUNCTION:
2888BN_X931_generate_prime 3328 EXIST:OPENSSL_FIPS:FUNCTION:
2889RSA_X931_derive 3329 EXIST:OPENSSL_FIPS:FUNCTION:RSA
2890SHA512_Update 3356 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2891SHA256_Init 3479 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2892SHA224 3510 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2893SHA384_Update 3551 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2894SHA224_Final 3560 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2895SHA224_Update 3562 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2896SHA512_Final 3581 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2897SHA224_Init 3631 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2898SHA512_Init 3633 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2899SHA256 3654 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2900SHA256_Transform 3664 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2901SHA512 3669 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2902SHA512_Transform 3675 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2903SHA256_Final 3712 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
2904SHA384_Init 3737 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2905SHA384_Final 3740 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2906SHA384 3745 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA512
2907SHA256_Update 3765 EXIST:OPENSSL_FIPS:FUNCTION:SHA,SHA256
diff --git a/src/lib/libcrypto/util/mk1mf.pl b/src/lib/libcrypto/util/mk1mf.pl
new file mode 100644
index 0000000000..05a6086164
--- /dev/null
+++ b/src/lib/libcrypto/util/mk1mf.pl
@@ -0,0 +1,1165 @@
1#!/usr/local/bin/perl
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.
4# This script outputs one mega makefile that has no shell stuff or any
5# funny stuff
6#
7
8$INSTALLTOP="/usr/local/ssl";
9$OPTIONS="";
10$ssl_version="";
11$banner="\t\@echo Building OpenSSL";
12
13local $zlib_opt = 0; # 0 = no zlib, 1 = static, 2 = dynamic
14local $zlib_lib = "";
15
16my $fips_canister_path = "";
17my $fips_premain_dso_exe_path = "";
18my $fips_premain_c_path = "";
19my $fips_sha1_exe_path = "";
20
21my $fipslibdir = "";
22my $baseaddr = "";
23
24my $ex_l_libs = "";
25
26
27open(IN,"<Makefile") || die "unable to open Makefile!\n";
28while(<IN>) {
29 $ssl_version=$1 if (/^VERSION=(.*)$/);
30 $OPTIONS=$1 if (/^OPTIONS=(.*)$/);
31 $INSTALLTOP=$1 if (/^INSTALLTOP=(.*$)/);
32}
33close(IN);
34
35die "Makefile is not the toplevel Makefile!\n" if $ssl_version eq "";
36
37$infile="MINFO";
38
39%ops=(
40 "VC-WIN32", "Microsoft Visual C++ [4-6] - Windows NT or 9X",
41 "VC-WIN32-GMAKE", "Microsoft Visual C++ [4-6] - Windows NT or 9X, GNU make",
42 "VC-CE", "Microsoft eMbedded Visual C++ 3.0 - Windows CE ONLY",
43 "VC-NT", "Microsoft Visual C++ [4-6] - Windows NT ONLY",
44 "VC-W31-16", "Microsoft Visual C++ 1.52 - Windows 3.1 - 286",
45 "VC-WIN16", "Alias for VC-W31-32",
46 "VC-W31-32", "Microsoft Visual C++ 1.52 - Windows 3.1 - 386+",
47 "VC-MSDOS","Microsoft Visual C++ 1.52 - MSDOS",
48 "Mingw32", "GNU C++ - Windows NT or 9x",
49 "Mingw32-files", "Create files with DOS copy ...",
50 "BC-NT", "Borland C++ 4.5 - Windows NT",
51 "BC-W31", "Borland C++ 4.5 - Windows 3.1 - PROBABLY NOT WORKING",
52 "BC-MSDOS","Borland C++ 4.5 - MSDOS",
53 "linux-elf","Linux elf",
54 "ultrix-mips","DEC mips ultrix",
55 "FreeBSD","FreeBSD distribution",
56 "OS2-EMX", "EMX GCC OS/2",
57 "default","cc under unix",
58 );
59
60$platform="";
61my $xcflags="";
62foreach (@ARGV)
63 {
64 if (!&read_options && !defined($ops{$_}))
65 {
66 print STDERR "unknown option - $_\n";
67 print STDERR "usage: perl mk1mf.pl [options] [system]\n";
68 print STDERR "\nwhere [system] can be one of the following\n";
69 foreach $i (sort keys %ops)
70 { printf STDERR "\t%-10s\t%s\n",$i,$ops{$i}; }
71 print STDERR <<"EOF";
72and [options] can be one of
73 no-md2 no-md4 no-md5 no-sha no-mdc2 - Skip this digest
74 no-ripemd
75 no-rc2 no-rc4 no-rc5 no-idea no-des - Skip this symetric cipher
76 no-bf no-cast no-aes
77 no-rsa no-dsa no-dh - Skip this public key cipher
78 no-ssl2 no-ssl3 - Skip this version of SSL
79 just-ssl - remove all non-ssl keys/digest
80 no-asm - No x86 asm
81 no-krb5 - No KRB5
82 no-ec - No EC
83 no-engine - No engine
84 no-hw - No hw
85 nasm - Use NASM for x86 asm
86 gaswin - Use GNU as with Mingw32
87 no-socks - No socket code
88 no-err - No error strings
89 dll/shlib - Build shared libraries (MS)
90 debug - Debug build
91 profile - Profiling build
92 gcc - Use Gcc (unix)
93
94Values that can be set
95TMP=tmpdir OUT=outdir SRC=srcdir BIN=binpath INC=header-outdir CC=C-compiler
96
97-L<ex_lib_path> -l<ex_lib> - extra library flags (unix)
98-<ex_cc_flags> - extra 'cc' flags,
99 added (MS), or replace (unix)
100EOF
101 exit(1);
102 }
103 $platform=$_;
104 }
105foreach (grep(!/^$/, split(/ /, $OPTIONS)))
106 {
107 print STDERR "unknown option - $_\n" if !&read_options;
108 }
109
110$no_mdc2=1 if ($no_des);
111
112$no_ssl3=1 if ($no_md5 || $no_sha);
113$no_ssl3=1 if ($no_rsa && $no_dh);
114
115$no_ssl2=1 if ($no_md5);
116$no_ssl2=1 if ($no_rsa);
117
118$out_def="out";
119$inc_def="outinc";
120$tmp_def="tmp";
121
122$mkdir="-mkdir";
123$mkcanister="ld -r -o";
124
125$ex_build_targets = "";
126
127($ssl,$crypto)=("ssl","crypto");
128$cryptocompat = "";
129$ranlib="echo ranlib";
130
131$cc=(defined($VARS{'CC'}))?$VARS{'CC'}:'cc';
132$src_dir=(defined($VARS{'SRC'}))?$VARS{'SRC'}:'.';
133$bin_dir=(defined($VARS{'BIN'}))?$VARS{'BIN'}:'';
134
135# $bin_dir.=$o causes a core dump on my sparc :-(
136
137$NT=0;
138
139push(@INC,"util/pl","pl");
140if ($platform eq "VC-MSDOS")
141 {
142 $asmbits=16;
143 $msdos=1;
144 require 'VC-16.pl';
145 }
146elsif ($platform eq "VC-W31-16")
147 {
148 $asmbits=16;
149 $msdos=1; $win16=1;
150 require 'VC-16.pl';
151 }
152elsif (($platform eq "VC-W31-32") || ($platform eq "VC-WIN16"))
153 {
154 $asmbits=32;
155 $msdos=1; $win16=1;
156 require 'VC-16.pl';
157 }
158elsif (($platform eq "VC-WIN32") || ($platform eq "VC-NT"))
159 {
160 $NT = 1 if $platform eq "VC-NT";
161 require 'VC-32.pl';
162 }
163elsif ($platform eq "VC-WIN32-GMAKE")
164 {
165 require 'VC-32-GMAKE.pl';
166 }
167elsif ($platform eq "VC-CE")
168 {
169 require 'VC-CE.pl';
170 }
171elsif ($platform eq "Mingw32")
172 {
173 require 'Mingw32.pl';
174 }
175elsif ($platform eq "Mingw32-files")
176 {
177 require 'Mingw32f.pl';
178 }
179elsif ($platform eq "BC-NT")
180 {
181 $bc=1;
182 require 'BC-32.pl';
183 }
184elsif ($platform eq "BC-W31")
185 {
186 $bc=1;
187 $msdos=1; $w16=1;
188 require 'BC-16.pl';
189 }
190elsif ($platform eq "BC-Q16")
191 {
192 $msdos=1; $w16=1; $shlib=0; $qw=1;
193 require 'BC-16.pl';
194 }
195elsif ($platform eq "BC-MSDOS")
196 {
197 $asmbits=16;
198 $msdos=1;
199 require 'BC-16.pl';
200 }
201elsif ($platform eq "FreeBSD")
202 {
203 require 'unix.pl';
204 $cflags='-DTERMIO -D_ANSI_SOURCE -O2 -fomit-frame-pointer';
205 }
206elsif ($platform eq "linux-elf")
207 {
208 require "unix.pl";
209 require "linux.pl";
210 $unix=1;
211 }
212elsif ($platform eq "ultrix-mips")
213 {
214 require "unix.pl";
215 require "ultrix.pl";
216 $unix=1;
217 }
218elsif ($platform eq "OS2-EMX")
219 {
220 $wc=1;
221 require 'OS2-EMX.pl';
222 }
223else
224 {
225 require "unix.pl";
226
227 $unix=1;
228 $cflags.=' -DTERMIO';
229 }
230
231$out_dir=(defined($VARS{'OUT'}))?$VARS{'OUT'}:$out_def.($debug?".dbg":"");
232$tmp_dir=(defined($VARS{'TMP'}))?$VARS{'TMP'}:$tmp_def.($debug?".dbg":"");
233$inc_dir=(defined($VARS{'INC'}))?$VARS{'INC'}:$inc_def;
234
235$bin_dir=$bin_dir.$o unless ((substr($bin_dir,-1,1) eq $o) || ($bin_dir eq ''));
236
237$cflags= "$xcflags$cflags" if $xcflags ne "";
238
239$cflags.=" -DOPENSSL_NO_IDEA" if $no_idea;
240$cflags.=" -DOPENSSL_NO_AES" if $no_aes;
241$cflags.=" -DOPENSSL_NO_RC2" if $no_rc2;
242$cflags.=" -DOPENSSL_NO_RC4" if $no_rc4;
243$cflags.=" -DOPENSSL_NO_RC5" if $no_rc5;
244$cflags.=" -DOPENSSL_NO_MD2" if $no_md2;
245$cflags.=" -DOPENSSL_NO_MD4" if $no_md4;
246$cflags.=" -DOPENSSL_NO_MD5" if $no_md5;
247$cflags.=" -DOPENSSL_NO_SHA" if $no_sha;
248$cflags.=" -DOPENSSL_NO_SHA1" if $no_sha1;
249$cflags.=" -DOPENSSL_NO_RIPEMD" if $no_ripemd;
250$cflags.=" -DOPENSSL_NO_MDC2" if $no_mdc2;
251$cflags.=" -DOPENSSL_NO_BF" if $no_bf;
252$cflags.=" -DOPENSSL_NO_CAST" if $no_cast;
253$cflags.=" -DOPENSSL_NO_DES" if $no_des;
254$cflags.=" -DOPENSSL_NO_RSA" if $no_rsa;
255$cflags.=" -DOPENSSL_NO_DSA" if $no_dsa;
256$cflags.=" -DOPENSSL_NO_DH" if $no_dh;
257$cflags.=" -DOPENSSL_NO_SOCK" if $no_sock;
258$cflags.=" -DOPENSSL_NO_SSL2" if $no_ssl2;
259$cflags.=" -DOPENSSL_NO_SSL3" if $no_ssl3;
260$cflags.=" -DOPENSSL_NO_ERR" if $no_err;
261$cflags.=" -DOPENSSL_NO_KRB5" if $no_krb5;
262$cflags.=" -DOPENSSL_NO_EC" if $no_ec;
263$cflags.=" -DOPENSSL_NO_ENGINE" if $no_engine;
264$cflags.=" -DOPENSSL_NO_HW" if $no_hw;
265$cflags.=" -DOPENSSL_FIPS" if $fips;
266#$cflags.=" -DRSAref" if $rsaref ne "";
267
268$cflags.= " -DZLIB" if $zlib_opt;
269$cflags.= " -DZLIB_SHARED" if $zlib_opt == 2;
270
271## if ($unix)
272## { $cflags="$c_flags" if ($c_flags ne ""); }
273##else
274 { $cflags="$c_flags$cflags" if ($c_flags ne ""); }
275
276$ex_libs="$l_flags$ex_libs" if ($l_flags ne "");
277
278
279%shlib_ex_cflags=("SSL" => " -DOPENSSL_BUILD_SHLIBSSL",
280 "CRYPTO" => " -DOPENSSL_BUILD_SHLIBCRYPTO");
281
282if ($msdos)
283 {
284 $banner ="\t\@echo Make sure you have run 'perl Configure $platform' in the\n";
285 $banner.="\t\@echo top level directory, if you don't have perl, you will\n";
286 $banner.="\t\@echo need to probably edit crypto/bn/bn.h, check the\n";
287 $banner.="\t\@echo documentation for details.\n";
288 }
289
290# have to do this to allow $(CC) under unix
291$link="$bin_dir$link" if ($link !~ /^\$/);
292
293$INSTALLTOP =~ s|/|$o|g;
294
295#############################################
296# We parse in input file and 'store' info for later printing.
297open(IN,"<$infile") || die "unable to open $infile:$!\n";
298$_=<IN>;
299for (;;)
300 {
301 chop;
302
303 ($key,$val)=/^([^=]+)=(.*)/;
304 if ($key eq "RELATIVE_DIRECTORY")
305 {
306 if ($lib ne "")
307 {
308 if ($fips && $dir =~ /^fips/)
309 {
310 $uc = "FIPS";
311 }
312 else
313 {
314 $uc=$lib;
315 $uc =~ s/^lib(.*)\.a/$1/;
316 $uc =~ tr/a-z/A-Z/;
317 }
318 if (($uc ne "FIPS") || $fips_canister_build)
319 {
320 $lib_nam{$uc}=$uc;
321 $lib_obj{$uc}.=$libobj." ";
322 }
323 }
324 last if ($val eq "FINISHED");
325 $lib="";
326 $libobj="";
327 $dir=$val;
328 }
329
330 if ($key eq "KRB5_INCLUDES")
331 { $cflags .= " $val";}
332
333 if ($key eq "ZLIB_INCLUDE")
334 { $cflags .= " $val" if $val ne "";}
335
336 if ($key eq "LIBZLIB")
337 { $zlib_lib = "$val" if $val ne "";}
338
339 if ($key eq "LIBKRB5")
340 { $ex_libs .= " $val" if $val ne "";}
341
342 if ($key eq "TEST")
343 { $test.=&var_add($dir,$val); }
344
345 if (($key eq "PROGS") || ($key eq "E_OBJ"))
346 { $e_exe.=&var_add($dir,$val); }
347
348 if ($key eq "LIB")
349 {
350 $lib=$val;
351 $lib =~ s/^.*\/([^\/]+)$/$1/;
352 }
353
354 if ($key eq "EXHEADER")
355 { $exheader.=&var_add($dir,$val); }
356
357 if ($key eq "HEADER")
358 { $header.=&var_add($dir,$val); }
359
360 if ($key eq "LIBOBJ")
361 { $libobj=&var_add($dir,$val); }
362
363 if ($key eq "FIPSLIBDIR")
364 { $fipslibdir=$val;}
365
366 if ($key eq "BASEADDR")
367 { $baseaddr=$val;}
368
369 if (!($_=<IN>))
370 { $_="RELATIVE_DIRECTORY=FINISHED\n"; }
371 }
372close(IN);
373
374if ($fips_canister_path eq "")
375 {
376 $fips_canister_path = "\$(FIPSLIB_D)${o}fipscanister.o";
377 }
378
379if ($fips_premain_c_path eq "")
380 {
381 $fips_premain_c_path = "\$(FIPSLIB_D)${o}fips_premain.c";
382 }
383
384if ($fips)
385 {
386 if ($fips_sha1_exe_path eq "")
387 {
388 $fips_sha1_exe_path =
389 "\$(BIN_D)${o}fips_standalone_sha1$exep";
390 }
391 }
392 else
393 {
394 $fips_sha1_exe_path = "";
395 }
396
397if ($fips_premain_dso_exe_path eq "")
398 {
399 $fips_premain_dso_exe_path = "\$(BIN_D)${o}fips_premain_dso$exep";
400 }
401
402# $ex_build_targets .= "\$(BIN_D)${o}\$(E_PREMAIN_DSO)$exep" if ($fips);
403
404if ($fips)
405 {
406 if (!$shlib)
407 {
408 $ex_build_targets .= " \$(LIB_D)$o$crypto_compat \$(PREMAIN_DSO_EXE)";
409 $ex_l_libs .= " \$(O_FIPSCANISTER)";
410 }
411 if ($fipslibdir eq "")
412 {
413 open (IN, "util/fipslib_path.txt") || fipslib_error();
414 $fipslibdir = <IN>;
415 chomp $fipslibdir;
416 close IN;
417 }
418 fips_check_files($fipslibdir,
419 "fipscanister.o", "fipscanister.o.sha1",
420 "fips_premain.c", "fips_premain.c.sha1");
421 }
422
423
424$defs= <<"EOF";
425# This makefile has been automatically generated from the OpenSSL distribution.
426# This single makefile will build the complete OpenSSL distribution and
427# by default leave the 'intertesting' output files in .${o}out and the stuff
428# that needs deleting in .${o}tmp.
429# The file was generated by running 'make makefile.one', which
430# does a 'make files', which writes all the environment variables from all
431# the makefiles to the file call MINFO. This file is used by
432# util${o}mk1mf.pl to generate makefile.one.
433# The 'makefile per directory' system suites me when developing this
434# library and also so I can 'distribute' indervidual library sections.
435# The one monster makefile better suits building in non-unix
436# environments.
437
438EOF
439
440$defs .= $preamble if defined $preamble;
441
442if ($platform eq "VC-CE")
443 {
444 $defs.= <<"EOF";
445!INCLUDE <\$(WCECOMPAT)/wcedefs.mak>
446
447EOF
448 $ex_libs .= " $zlib_lib" if $zlib_opt == 1;
449 }
450
451$defs.= <<"EOF";
452INSTALLTOP=$INSTALLTOP
453
454# Set your compiler options
455PLATFORM=$platform
456CC=$bin_dir${cc}
457CFLAG=$cflags
458APP_CFLAG=$app_cflag
459LIB_CFLAG=$lib_cflag
460SHLIB_CFLAG=$shl_cflag
461APP_EX_OBJ=$app_ex_obj
462SHLIB_EX_OBJ=$shlib_ex_obj
463# add extra libraries to this define, for solaris -lsocket -lnsl would
464# be added
465EX_LIBS=$ex_libs
466
467# The OpenSSL directory
468SRC_D=$src_dir
469
470LINK=$link
471PERL=perl
472FIPSLINK=\$(PERL) util${o}fipslink.pl
473LFLAGS=$lflags
474
475BN_ASM_OBJ=$bn_asm_obj
476BN_ASM_SRC=$bn_asm_src
477BNCO_ASM_OBJ=$bnco_asm_obj
478BNCO_ASM_SRC=$bnco_asm_src
479DES_ENC_OBJ=$des_enc_obj
480DES_ENC_SRC=$des_enc_src
481BF_ENC_OBJ=$bf_enc_obj
482BF_ENC_SRC=$bf_enc_src
483CAST_ENC_OBJ=$cast_enc_obj
484CAST_ENC_SRC=$cast_enc_src
485RC4_ENC_OBJ=$rc4_enc_obj
486RC4_ENC_SRC=$rc4_enc_src
487RC5_ENC_OBJ=$rc5_enc_obj
488RC5_ENC_SRC=$rc5_enc_src
489MD5_ASM_OBJ=$md5_asm_obj
490MD5_ASM_SRC=$md5_asm_src
491SHA1_ASM_OBJ=$sha1_asm_obj
492SHA1_ASM_SRC=$sha1_asm_src
493RMD160_ASM_OBJ=$rmd160_asm_obj
494RMD160_ASM_SRC=$rmd160_asm_src
495
496# The output directory for everything intersting
497OUT_D=$out_dir
498# The output directory for all the temporary muck
499TMP_D=$tmp_dir
500# The output directory for the header files
501INC_D=$inc_dir
502INCO_D=$inc_dir${o}openssl
503
504# Directory containing FIPS module
505
506
507CP=$cp
508RM=$rm
509RANLIB=$ranlib
510MKDIR=$mkdir
511MKLIB=$bin_dir$mklib
512MLFLAGS=$mlflags
513ASM=$bin_dir$asm
514MKCANISTER=$mkcanister
515
516# FIPS validated module and support file locations
517
518E_PREMAIN_DSO=fips_premain_dso
519
520FIPSLIB_D=$fipslibdir
521BASEADDR=$baseaddr
522FIPS_PREMAIN_SRC=$fips_premain_c_path
523O_FIPSCANISTER=$fips_canister_path
524FIPS_SHA1_EXE=$fips_sha1_exe_path
525PREMAIN_DSO_EXE=$fips_premain_dso_exe_path
526
527######################################################
528# You should not need to touch anything below this point
529######################################################
530
531E_EXE=openssl
532SSL=$ssl
533CRYPTO=$crypto
534
535# BIN_D - Binary output directory
536# TEST_D - Binary test file output directory
537# LIB_D - library output directory
538# Note: if you change these point to different directories then uncomment out
539# the lines around the 'NB' comment below.
540#
541BIN_D=\$(OUT_D)
542TEST_D=\$(OUT_D)
543LIB_D=\$(OUT_D)
544
545# INCL_D - local library directory
546# OBJ_D - temp object file directory
547OBJ_D=\$(TMP_D)
548INCL_D=\$(TMP_D)
549
550O_SSL= \$(LIB_D)$o$plib\$(SSL)$shlibp
551O_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$shlibp
552SO_SSL= $plib\$(SSL)$so_shlibp
553SO_CRYPTO= $plib\$(CRYPTO)$so_shlibp
554L_SSL= \$(LIB_D)$o$plib\$(SSL)$libp
555L_CRYPTO= \$(LIB_D)$o$plib\$(CRYPTO)$libp
556
557L_LIBS= \$(L_SSL) \$(L_CRYPTO) $ex_l_libs
558
559######################################################
560# Don't touch anything below this point
561######################################################
562
563INC=-I\$(INC_D) -I\$(INCL_D)
564APP_CFLAGS=\$(INC) \$(CFLAG) \$(APP_CFLAG)
565LIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG)
566SHLIB_CFLAGS=\$(INC) \$(CFLAG) \$(LIB_CFLAG) \$(SHLIB_CFLAG)
567LIBS_DEP=\$(O_CRYPTO) \$(O_SSL) $ex_libs_dep
568
569#############################################
570EOF
571
572$rules=<<"EOF";
573all: banner \$(TMP_D) \$(BIN_D) \$(TEST_D) \$(LIB_D) \$(INCO_D) headers \$(FIPS_SHA1_EXE) lib exe $ex_build_targets
574
575banner:
576$banner
577
578\$(TMP_D):
579 \$(MKDIR) \$(TMP_D)
580# NB: uncomment out these lines if BIN_D, TEST_D and LIB_D are different
581#\$(BIN_D):
582# \$(MKDIR) \$(BIN_D)
583#
584#\$(TEST_D):
585# \$(MKDIR) \$(TEST_D)
586
587\$(LIB_D):
588 \$(MKDIR) \$(LIB_D)
589
590\$(INCO_D): \$(INC_D)
591 \$(MKDIR) \$(INCO_D)
592
593\$(INC_D):
594 \$(MKDIR) \$(INC_D)
595
596headers: \$(HEADER) \$(EXHEADER)
597 @
598
599lib: \$(LIBS_DEP)
600
601exe: \$(T_EXE) \$(BIN_D)$o\$(E_EXE)$exep
602
603install:
604 \$(MKDIR) \$(INSTALLTOP)
605 \$(MKDIR) \$(INSTALLTOP)${o}bin
606 \$(MKDIR) \$(INSTALLTOP)${o}include
607 \$(MKDIR) \$(INSTALLTOP)${o}include${o}openssl
608 \$(MKDIR) \$(INSTALLTOP)${o}lib
609 \$(CP) \$(INCO_D)${o}*.\[ch\] \$(INSTALLTOP)${o}include${o}openssl
610 \$(CP) \$(BIN_D)$o\$(E_EXE)$exep \$(INSTALLTOP)${o}bin
611 \$(CP) \$(O_SSL) \$(INSTALLTOP)${o}lib
612 \$(CP) \$(O_CRYPTO) \$(INSTALLTOP)${o}lib
613
614clean:
615 \$(RM) \$(TMP_D)$o*.*
616
617vclean:
618 \$(RM) \$(TMP_D)$o*.*
619 \$(RM) \$(OUT_D)$o*.*
620
621EOF
622
623my $platform_cpp_symbol = "MK1MF_PLATFORM_$platform";
624$platform_cpp_symbol =~ s/-/_/g;
625if (open(IN,"crypto/buildinf.h"))
626 {
627 # Remove entry for this platform in existing file buildinf.h.
628
629 my $old_buildinf_h = "";
630 while (<IN>)
631 {
632 if (/^\#ifdef $platform_cpp_symbol$/)
633 {
634 while (<IN>) { last if (/^\#endif/); }
635 }
636 else
637 {
638 $old_buildinf_h .= $_;
639 }
640 }
641 close(IN);
642
643 open(OUT,">crypto/buildinf.h") || die "Can't open buildinf.h";
644 print OUT $old_buildinf_h;
645 close(OUT);
646 }
647
648open (OUT,">>crypto/buildinf.h") || die "Can't open buildinf.h";
649printf OUT <<EOF;
650#ifdef $platform_cpp_symbol
651 /* auto-generated/updated by util/mk1mf.pl for crypto/cversion.c */
652 #define CFLAGS "$cc $cflags"
653 #define PLATFORM "$platform"
654EOF
655printf OUT " #define DATE \"%s\"\n", scalar gmtime();
656printf OUT "#endif\n";
657close(OUT);
658
659# Strip of trailing ' '
660foreach (keys %lib_obj) { $lib_obj{$_}=&clean_up_ws($lib_obj{$_}); }
661$test=&clean_up_ws($test);
662$e_exe=&clean_up_ws($e_exe);
663$exheader=&clean_up_ws($exheader);
664$header=&clean_up_ws($header);
665
666# First we strip the exheaders from the headers list
667foreach (split(/\s+/,$exheader)){ $h{$_}=1; }
668foreach (split(/\s+/,$header)) { $h.=$_." " unless $h{$_}; }
669chop($h); $header=$h;
670
671$defs.=&do_defs("HEADER",$header,"\$(INCL_D)",".h");
672$rules.=&do_copy_rule("\$(INCL_D)",$header,".h");
673
674$defs.=&do_defs("EXHEADER",$exheader,"\$(INCO_D)",".h");
675$rules.=&do_copy_rule("\$(INCO_D)",$exheader,".h");
676
677$defs.=&do_defs("T_OBJ",$test,"\$(OBJ_D)",$obj);
678$rules.=&do_compile_rule("\$(OBJ_D)",$test,"\$(APP_CFLAGS)");
679
680$defs.=&do_defs("E_OBJ",$e_exe,"\$(OBJ_D)",$obj);
681$rules.=&do_compile_rule("\$(OBJ_D)",$e_exe,'-DMONOLITH $(APP_CFLAGS)');
682
683# Special case rules for fips_start and fips_end fips_premain_dso
684
685if ($fips)
686 {
687 if ($fips_canister_build)
688 {
689 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_start$obj",
690 "fips-1.0${o}fips_canister.c",
691 "-DFIPS_START \$(SHLIB_CFLAGS)");
692 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_end$obj",
693 "fips-1.0${o}fips_canister.c", "\$(SHLIB_CFLAGS)");
694 }
695 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_standalone_sha1$obj",
696 "fips-1.0${o}sha${o}fips_standalone_sha1.c",
697 "\$(SHLIB_CFLAGS)");
698 $rules.=&cc_compile_target("\$(OBJ_D)${o}fips_sha1dgst$obj",
699 "fips-1.0${o}sha${o}fips_sha1dgst.c",
700 "\$(SHLIB_CFLAGS)") unless $fips_canister_build;
701 $rules.=&cc_compile_target("\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj",
702 "fips-1.0${o}fips_premain.c",
703 "-DFINGERPRINT_PREMAIN_DSO_LOAD \$(SHLIB_CFLAGS)");
704 }
705
706foreach (values %lib_nam)
707 {
708 $lib_obj=$lib_obj{$_};
709 local($slib)=$shlib;
710
711 if (($_ eq "SSL") && $no_ssl2 && $no_ssl3)
712 {
713 $rules.="\$(O_SSL):\n\n";
714 next;
715 }
716
717 if (($bn_asm_obj ne "") && ($_ eq "CRYPTO"))
718 {
719 $lib_obj =~ s/\s\S*\/bn_asm\S*/ \$(BN_ASM_OBJ)/;
720 $rules.=&do_asm_rule($bn_asm_obj,$bn_asm_src);
721 }
722 if (($bnco_asm_obj ne "") && ($_ eq "CRYPTO"))
723 {
724 $lib_obj .= "\$(BNCO_ASM_OBJ)";
725 $rules.=&do_asm_rule($bnco_asm_obj,$bnco_asm_src);
726 }
727 if (($des_enc_obj ne "") && ($_ eq "CRYPTO"))
728 {
729 $lib_obj =~ s/\s\S*des_enc\S*/ \$(DES_ENC_OBJ)/;
730 $lib_obj =~ s/\s\S*\/fcrypt_b\S*\s*/ /;
731 $rules.=&do_asm_rule($des_enc_obj,$des_enc_src);
732 }
733 if (($bf_enc_obj ne "") && ($_ eq "CRYPTO"))
734 {
735 $lib_obj =~ s/\s\S*\/bf_enc\S*/ \$(BF_ENC_OBJ)/;
736 $rules.=&do_asm_rule($bf_enc_obj,$bf_enc_src);
737 }
738 if (($cast_enc_obj ne "") && ($_ eq "CRYPTO"))
739 {
740 $lib_obj =~ s/(\s\S*\/c_enc\S*)/ \$(CAST_ENC_OBJ)/;
741 $rules.=&do_asm_rule($cast_enc_obj,$cast_enc_src);
742 }
743 if (($rc4_enc_obj ne "") && ($_ eq "CRYPTO"))
744 {
745 $lib_obj =~ s/\s\S*\/rc4_enc\S*/ \$(RC4_ENC_OBJ)/;
746 $rules.=&do_asm_rule($rc4_enc_obj,$rc4_enc_src);
747 }
748 if (($rc5_enc_obj ne "") && ($_ eq "CRYPTO"))
749 {
750 $lib_obj =~ s/\s\S*\/rc5_enc\S*/ \$(RC5_ENC_OBJ)/;
751 $rules.=&do_asm_rule($rc5_enc_obj,$rc5_enc_src);
752 }
753 if (($md5_asm_obj ne "") && ($_ eq "CRYPTO"))
754 {
755 $lib_obj =~ s/\s(\S*\/md5_dgst\S*)/ $1 \$(MD5_ASM_OBJ)/;
756 $rules.=&do_asm_rule($md5_asm_obj,$md5_asm_src);
757 }
758 if (($sha1_asm_obj ne "") && ($_ eq "CRYPTO"))
759 {
760 $lib_obj =~ s/\s(\S*\/sha1dgst\S*)/ $1 \$(SHA1_ASM_OBJ)/;
761 $rules.=&do_asm_rule($sha1_asm_obj,$sha1_asm_src);
762 }
763 if (($rmd160_asm_obj ne "") && ($_ eq "CRYPTO"))
764 {
765 $lib_obj =~ s/\s(\S*\/rmd_dgst\S*)/ $1 \$(RMD160_ASM_OBJ)/;
766 $rules.=&do_asm_rule($rmd160_asm_obj,$rmd160_asm_src);
767 }
768 $defs.=&do_defs(${_}."OBJ",$lib_obj,"\$(OBJ_D)",$obj);
769 $lib=($slib)?" \$(SHLIB_CFLAGS)".$shlib_ex_cflags{$_}:" \$(LIB_CFLAGS)";
770 $rules.=&do_compile_rule("\$(OBJ_D)",$lib_obj{$_},$lib);
771 }
772
773$defs.=&do_defs("T_EXE",$test,"\$(TEST_D)",$exep);
774foreach (split(/\s+/,$test))
775 {
776 $t=&bname($_);
777 $tt="\$(OBJ_D)${o}$t${obj}";
778 $rules.=&do_link_rule("\$(TEST_D)$o$t$exep",$tt,"\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)");
779 }
780
781$rules.= &do_lib_rule("\$(SSLOBJ)","\$(O_SSL)",$ssl,$shlib,"\$(SO_SSL)");
782
783
784if ($fips)
785 {
786 if ($shlib)
787 {
788 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
789 "\$(O_CRYPTO)",
790 "$crypto",
791 $shlib, "\$(SO_CRYPTO)", "\$(BASEADDR)");
792 }
793 else
794 {
795 $rules.= &do_lib_rule("\$(CRYPTOOBJ)",
796 "\$(O_CRYPTO)",$crypto,$shlib,"\$(SO_CRYPTO)", "");
797 $rules.= &do_lib_rule("\$(CRYPTOOBJ) \$(O_FIPSCANISTER)",
798 "\$(LIB_D)$o$crypto_compat",$crypto,$shlib,"\$(SO_CRYPTO)", "");
799 }
800 }
801 else
802 {
803 $rules.= &do_lib_rule("\$(CRYPTOOBJ)","\$(O_CRYPTO)",$crypto,$shlib,
804 "\$(SO_CRYPTO)");
805 }
806
807
808if ($fips)
809 {
810 $rules.= &do_rlink_rule("\$(O_FIPSCANISTER)", "\$(OBJ_D)${o}fips_start$obj \$(FIPSOBJ) \$(OBJ_D)${o}fips_end$obj", "\$(FIPSLIB_D)${o}fips_standalone_sha1$exep", "") if $fips_canister_build;
811 $rules.=&do_link_rule("\$(PREMAIN_DSO_EXE)","\$(OBJ_D)${o}\$(E_PREMAIN_DSO)$obj \$(CRYPTOOBJ) \$(O_FIPSCANISTER)","","\$(EX_LIBS)", 1);
812
813 $rules.=&do_link_rule("\$(FIPS_SHA1_EXE)","\$(OBJ_D)${o}fips_standalone_sha1$obj \$(OBJ_D)${o}fips_sha1dgst$obj","","", 1);
814 }
815
816 $rules.=&do_link_rule("\$(BIN_D)$o\$(E_EXE)$exep","\$(E_OBJ)","\$(LIBS_DEP)","\$(L_LIBS) \$(EX_LIBS)",0);
817
818print $defs;
819
820if ($platform eq "linux-elf") {
821 print <<"EOF";
822# Generate perlasm output files
823%.cpp:
824 (cd \$(\@D)/..; PERL=perl make -f Makefile asm/\$(\@F))
825EOF
826}
827print "###################################################################\n";
828print $rules;
829
830###############################################
831# strip off any trailing .[och] and append the relative directory
832# also remembering to do nothing if we are in one of the dropped
833# directories
834sub var_add
835 {
836 local($dir,$val)=@_;
837 local(@a,$_,$ret);
838
839 return("") if $no_engine && $dir =~ /\/engine/;
840 return("") if $no_hw && $dir =~ /\/hw/;
841 return("") if $no_idea && $dir =~ /\/idea/;
842 return("") if $no_aes && $dir =~ /\/aes/;
843 return("") if $no_rc2 && $dir =~ /\/rc2/;
844 return("") if $no_rc4 && $dir =~ /\/rc4/;
845 return("") if $no_rc5 && $dir =~ /\/rc5/;
846 return("") if $no_rsa && $dir =~ /\/rsa/;
847 return("") if $no_rsa && $dir =~ /^rsaref/;
848 return("") if $no_dsa && $dir =~ /\/dsa/;
849 return("") if $no_dh && $dir =~ /\/dh/;
850 return("") if $no_ec && $dir =~ /\/ec/;
851 if ($no_des && $dir =~ /\/des/)
852 {
853 if ($val =~ /read_pwd/)
854 { return("$dir/read_pwd "); }
855 else
856 { return(""); }
857 }
858 return("") if $no_mdc2 && $dir =~ /\/mdc2/;
859 return("") if $no_sock && $dir =~ /\/proxy/;
860 return("") if $no_bf && $dir =~ /\/bf/;
861 return("") if $no_cast && $dir =~ /\/cast/;
862
863 $val =~ s/^\s*(.*)\s*$/$1/;
864 @a=split(/\s+/,$val);
865 grep(s/\.[och]$//,@a);
866
867 @a=grep(!/^e_.*_3d$/,@a) if $no_des;
868 @a=grep(!/^e_.*_d$/,@a) if $no_des;
869 @a=grep(!/^e_.*_ae$/,@a) if $no_idea;
870 @a=grep(!/^e_.*_i$/,@a) if $no_aes;
871 @a=grep(!/^e_.*_r2$/,@a) if $no_rc2;
872 @a=grep(!/^e_.*_r5$/,@a) if $no_rc5;
873 @a=grep(!/^e_.*_bf$/,@a) if $no_bf;
874 @a=grep(!/^e_.*_c$/,@a) if $no_cast;
875 @a=grep(!/^e_rc4$/,@a) if $no_rc4;
876
877 @a=grep(!/(^s2_)|(^s23_)/,@a) if $no_ssl2;
878 @a=grep(!/(^s3_)|(^s23_)/,@a) if $no_ssl3;
879
880 @a=grep(!/(_sock$)|(_acpt$)|(_conn$)|(^pxy_)/,@a) if $no_sock;
881
882 @a=grep(!/(^md2)|(_md2$)/,@a) if $no_md2;
883 @a=grep(!/(^md4)|(_md4$)/,@a) if $no_md4;
884 @a=grep(!/(^md5)|(_md5$)/,@a) if $no_md5;
885 @a=grep(!/(rmd)|(ripemd)/,@a) if $no_ripemd;
886
887 @a=grep(!/(^d2i_r_)|(^i2d_r_)/,@a) if $no_rsa;
888 @a=grep(!/(^p_open$)|(^p_seal$)/,@a) if $no_rsa;
889 @a=grep(!/(^pem_seal$)/,@a) if $no_rsa;
890
891 @a=grep(!/(m_dss$)|(m_dss1$)/,@a) if $no_dsa;
892 @a=grep(!/(^d2i_s_)|(^i2d_s_)|(_dsap$)/,@a) if $no_dsa;
893
894 @a=grep(!/^n_pkey$/,@a) if $no_rsa || $no_rc4;
895
896 @a=grep(!/_dhp$/,@a) if $no_dh;
897
898 @a=grep(!/(^sha[^1])|(_sha$)|(m_dss$)/,@a) if $no_sha;
899 @a=grep(!/(^sha1)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
900 @a=grep(!/_mdc2$/,@a) if $no_mdc2;
901
902 @a=grep(!/^engine$/,@a) if $no_engine;
903 @a=grep(!/^hw$/,@a) if $no_hw;
904 @a=grep(!/(^rsa$)|(^genrsa$)/,@a) if $no_rsa;
905 @a=grep(!/(^dsa$)|(^gendsa$)|(^dsaparam$)/,@a) if $no_dsa;
906 @a=grep(!/^gendsa$/,@a) if $no_sha1;
907 @a=grep(!/(^dh$)|(^gendh$)/,@a) if $no_dh;
908
909 @a=grep(!/(^dh)|(_sha1$)|(m_dss1$)/,@a) if $no_sha1;
910
911 grep($_="$dir/$_",@a);
912 @a=grep(!/(^|\/)s_/,@a) if $no_sock;
913 @a=grep(!/(^|\/)bio_sock/,@a) if $no_sock;
914 $ret=join(' ',@a)." ";
915 return($ret);
916 }
917
918# change things so that each 'token' is only separated by one space
919sub clean_up_ws
920 {
921 local($w)=@_;
922
923 $w =~ s/^\s*(.*)\s*$/$1/;
924 $w =~ s/\s+/ /g;
925 return($w);
926 }
927
928sub do_defs
929 {
930 local($var,$files,$location,$postfix)=@_;
931 local($_,$ret,$pf);
932 local(*OUT,$tmp,$t);
933
934 $files =~ s/\//$o/g if $o ne '/';
935 $ret="$var=";
936 $n=1;
937 $Vars{$var}.="";
938 foreach (split(/ /,$files))
939 {
940 $orig=$_;
941 $_=&bname($_) unless /^\$/;
942 if ($n++ == 2)
943 {
944 $n=0;
945 $ret.="\\\n\t";
946 }
947 if (($_ =~ /bss_file/) && ($postfix eq ".h"))
948 { $pf=".c"; }
949 else { $pf=$postfix; }
950 if ($_ =~ /BN_ASM/) { $t="$_ "; }
951 elsif ($_ =~ /BNCO_ASM/){ $t="$_ "; }
952 elsif ($_ =~ /DES_ENC/) { $t="$_ "; }
953 elsif ($_ =~ /BF_ENC/) { $t="$_ "; }
954 elsif ($_ =~ /CAST_ENC/){ $t="$_ "; }
955 elsif ($_ =~ /RC4_ENC/) { $t="$_ "; }
956 elsif ($_ =~ /RC5_ENC/) { $t="$_ "; }
957 elsif ($_ =~ /MD5_ASM/) { $t="$_ "; }
958 elsif ($_ =~ /SHA1_ASM/){ $t="$_ "; }
959 elsif ($_ =~ /RMD160_ASM/){ $t="$_ "; }
960 else { $t="$location${o}$_$pf "; }
961
962 $Vars{$var}.="$t ";
963 $ret.=$t;
964 }
965 chop($ret);
966 $ret.="\n\n";
967 return($ret);
968 }
969
970# return the name with the leading path removed
971sub bname
972 {
973 local($ret)=@_;
974 $ret =~ s/^.*[\\\/]([^\\\/]+)$/$1/;
975 return($ret);
976 }
977
978
979##############################################################
980# do a rule for each file that says 'compile' to new direcory
981# compile the files in '$files' into $to
982sub do_compile_rule
983 {
984 local($to,$files,$ex)=@_;
985 local($ret,$_,$n);
986
987 $files =~ s/\//$o/g if $o ne '/';
988 foreach (split(/\s+/,$files))
989 {
990 $n=&bname($_);
991 $ret.=&cc_compile_target("$to${o}$n$obj","${_}.c",$ex)
992 }
993 return($ret);
994 }
995
996##############################################################
997# do a rule for each file that says 'compile' to new direcory
998sub cc_compile_target
999 {
1000 local($target,$source,$ex_flags)=@_;
1001 local($ret);
1002
1003 $ex_flags.=" -DMK1MF_BUILD -D$platform_cpp_symbol" if ($source =~ /cversion/);
1004 $target =~ s/\//$o/g if $o ne "/";
1005 $source =~ s/\//$o/g if $o ne "/";
1006 $ret ="$target: \$(SRC_D)$o$source\n\t";
1007 $ret.="\$(CC) ${ofile}$target $ex_flags -c \$(SRC_D)$o$source\n\n";
1008 return($ret);
1009 }
1010
1011##############################################################
1012sub do_asm_rule
1013 {
1014 local($target,$src)=@_;
1015 local($ret,@s,@t,$i);
1016
1017 $target =~ s/\//$o/g if $o ne "/";
1018 $src =~ s/\//$o/g if $o ne "/";
1019
1020 @s=split(/\s+/,$src);
1021 @t=split(/\s+/,$target);
1022
1023 for ($i=0; $i<=$#s; $i++)
1024 {
1025 $ret.="$t[$i]: $s[$i]\n";
1026 $ret.="\t\$(ASM) $afile$t[$i] \$(SRC_D)$o$s[$i]\n\n";
1027 }
1028 return($ret);
1029 }
1030
1031sub do_shlib_rule
1032 {
1033 local($n,$def)=@_;
1034 local($ret,$nn);
1035 local($t);
1036
1037 ($nn=$n) =~ tr/a-z/A-Z/;
1038 $ret.="$n.dll: \$(${nn}OBJ)\n";
1039 if ($vc && $w32)
1040 {
1041 $ret.="\t\$(MKSHLIB) $efile$n.dll $def @<<\n \$(${nn}OBJ_F)\n<<\n";
1042 }
1043 $ret.="\n";
1044 return($ret);
1045 }
1046
1047# do a rule for each file that says 'copy' to new direcory on change
1048sub do_copy_rule
1049 {
1050 local($to,$files,$p)=@_;
1051 local($ret,$_,$n,$pp);
1052
1053 $files =~ s/\//$o/g if $o ne '/';
1054 foreach (split(/\s+/,$files))
1055 {
1056 $n=&bname($_);
1057 if ($n =~ /bss_file/)
1058 { $pp=".c"; }
1059 else { $pp=$p; }
1060 $ret.="$to${o}$n$pp: \$(SRC_D)$o$_$pp\n\t\$(CP) \$(SRC_D)$o$_$pp $to${o}$n$pp\n\n";
1061 }
1062 return($ret);
1063 }
1064
1065sub read_options
1066 {
1067 if (/^no-rc2$/) { $no_rc2=1; }
1068 elsif (/^no-rc4$/) { $no_rc4=1; }
1069 elsif (/^no-rc5$/) { $no_rc5=1; }
1070 elsif (/^no-idea$/) { $no_idea=1; }
1071 elsif (/^no-aes$/) { $no_aes=1; }
1072 elsif (/^no-des$/) { $no_des=1; }
1073 elsif (/^no-bf$/) { $no_bf=1; }
1074 elsif (/^no-cast$/) { $no_cast=1; }
1075 elsif (/^no-md2$/) { $no_md2=1; }
1076 elsif (/^no-md4$/) { $no_md4=1; }
1077 elsif (/^no-md5$/) { $no_md5=1; }
1078 elsif (/^no-sha$/) { $no_sha=1; }
1079 elsif (/^no-sha1$/) { $no_sha1=1; }
1080 elsif (/^no-ripemd$/) { $no_ripemd=1; }
1081 elsif (/^no-mdc2$/) { $no_mdc2=1; }
1082 elsif (/^no-patents$/) { $no_rc2=$no_rc4=$no_rc5=$no_idea=$no_rsa=1; }
1083 elsif (/^no-rsa$/) { $no_rsa=1; }
1084 elsif (/^no-dsa$/) { $no_dsa=1; }
1085 elsif (/^no-dh$/) { $no_dh=1; }
1086 elsif (/^no-hmac$/) { $no_hmac=1; }
1087 elsif (/^no-aes$/) { $no_aes=1; }
1088 elsif (/^no-asm$/) { $no_asm=1; }
1089 elsif (/^nasm$/) { $nasm=1; }
1090 elsif (/^gaswin$/) { $gaswin=1; }
1091 elsif (/^no-ssl2$/) { $no_ssl2=1; }
1092 elsif (/^no-ssl3$/) { $no_ssl3=1; }
1093 elsif (/^no-err$/) { $no_err=1; }
1094 elsif (/^no-sock$/) { $no_sock=1; }
1095 elsif (/^no-krb5$/) { $no_krb5=1; }
1096 elsif (/^no-ec$/) { $no_ec=1; }
1097 elsif (/^no-engine$/) { $no_engine=1; }
1098 elsif (/^no-hw$/) { $no_hw=1; }
1099
1100 elsif (/^just-ssl$/) { $no_rc2=$no_idea=$no_des=$no_bf=$no_cast=1;
1101 $no_md2=$no_sha=$no_mdc2=$no_dsa=$no_dh=1;
1102 $no_ssl2=$no_err=$no_ripemd=$no_rc5=1;
1103 $no_aes=1; }
1104
1105 elsif (/^rsaref$/) { }
1106 elsif (/^fips$/) { $fips=1; }
1107 elsif (/^gcc$/) { $gcc=1; }
1108 elsif (/^debug$/) { $debug=1; }
1109 elsif (/^profile$/) { $profile=1; }
1110 elsif (/^shlib$/) { $shlib=1; }
1111 elsif (/^dll$/) { $shlib=1; }
1112 elsif (/^shared$/) { } # We just need to ignore it for now...
1113 elsif (/^zlib$/) { $zlib_opt = 1 if $zlib_opt == 0 }
1114 elsif (/^zlib-dynamic$/){ $zlib_opt = 2; }
1115 elsif (/^--with-krb5-flavor=(.*)$/)
1116 {
1117 my $krb5_flavor = $1;
1118 if ($krb5_flavor =~ /^force-[Hh]eimdal$/)
1119 {
1120 $xcflags="-DKRB5_HEIMDAL $xcflags";
1121 }
1122 elsif ($krb5_flavor =~ /^MIT/i)
1123 {
1124 $xcflags="-DKRB5_MIT $xcflags";
1125 if ($krb5_flavor =~ /^MIT[._-]*1[._-]*[01]/i)
1126 {
1127 $xcflags="-DKRB5_MIT_OLD11 $xcflags"
1128 }
1129 }
1130 }
1131 elsif (/^([^=]*)=(.*)$/){ $VARS{$1}=$2; }
1132 elsif (/^-[lL].*$/) { $l_flags.="$_ "; }
1133 elsif ((!/^-help/) && (!/^-h/) && (!/^-\?/) && /^-.*$/)
1134 { $c_flags.="$_ "; }
1135 else { return(0); }
1136 return(1);
1137 }
1138
1139sub fipslib_error
1140 {
1141 print STDERR "***FIPS module directory sanity check failed***\n";
1142 print STDERR "FIPS module build failed, or was deleted\n";
1143 print STDERR "Please rebuild FIPS module.\n";
1144 exit 1;
1145 }
1146
1147sub fips_check_files
1148 {
1149 my $dir = shift @_;
1150 my $ret = 1;
1151 if (!-d $dir)
1152 {
1153 print STDERR "FIPS module directory $dir does not exist\n";
1154 fipslib_error();
1155 }
1156 foreach (@_)
1157 {
1158 if (!-f "$dir${o}$_")
1159 {
1160 print STDERR "FIPS module file $_ does not exist!\n";
1161 $ret = 0;
1162 }
1163 }
1164 fipslib_error() if ($ret == 0);
1165 }
diff --git a/src/lib/libcrypto/util/mkcerts.sh b/src/lib/libcrypto/util/mkcerts.sh
new file mode 100644
index 0000000000..0184fcb70e
--- /dev/null
+++ b/src/lib/libcrypto/util/mkcerts.sh
@@ -0,0 +1,220 @@
1#!/bin/sh
2
3# This script will re-make all the required certs.
4# cd apps
5# sh ../util/mkcerts.sh
6# mv ca-cert.pem pca-cert.pem ../certs
7# cd ..
8# cat certs/*.pem >>apps/server.pem
9# cat certs/*.pem >>apps/server2.pem
10# SSLEAY=`pwd`/apps/ssleay; export SSLEAY
11# sh tools/c_rehash certs
12#
13
14CAbits=1024
15SSLEAY="../apps/openssl"
16CONF="-config ../apps/openssl.cnf"
17
18# create pca request.
19echo creating $CAbits bit PCA cert request
20$SSLEAY req $CONF \
21 -new -md5 -newkey $CAbits \
22 -keyout pca-key.pem \
23 -out pca-req.pem -nodes >/dev/null <<EOF
24AU
25Queensland
26.
27CryptSoft Pty Ltd
28.
29Test PCA (1024 bit)
30
31
32
33EOF
34
35if [ $? != 0 ]; then
36 echo problems generating PCA request
37 exit 1
38fi
39
40#sign it.
41echo
42echo self signing PCA
43$SSLEAY x509 -md5 -days 1461 \
44 -req -signkey pca-key.pem \
45 -CAcreateserial -CAserial pca-cert.srl \
46 -in pca-req.pem -out pca-cert.pem
47
48if [ $? != 0 ]; then
49 echo problems self signing PCA cert
50 exit 1
51fi
52echo
53
54# create ca request.
55echo creating $CAbits bit CA cert request
56$SSLEAY req $CONF \
57 -new -md5 -newkey $CAbits \
58 -keyout ca-key.pem \
59 -out ca-req.pem -nodes >/dev/null <<EOF
60AU
61Queensland
62.
63CryptSoft Pty Ltd
64.
65Test CA (1024 bit)
66
67
68
69EOF
70
71if [ $? != 0 ]; then
72 echo problems generating CA request
73 exit 1
74fi
75
76#sign it.
77echo
78echo signing CA
79$SSLEAY x509 -md5 -days 1461 \
80 -req \
81 -CAcreateserial -CAserial pca-cert.srl \
82 -CA pca-cert.pem -CAkey pca-key.pem \
83 -in ca-req.pem -out ca-cert.pem
84
85if [ $? != 0 ]; then
86 echo problems signing CA cert
87 exit 1
88fi
89echo
90
91# create server request.
92echo creating 512 bit server cert request
93$SSLEAY req $CONF \
94 -new -md5 -newkey 512 \
95 -keyout s512-key.pem \
96 -out s512-req.pem -nodes >/dev/null <<EOF
97AU
98Queensland
99.
100CryptSoft Pty Ltd
101.
102Server test cert (512 bit)
103
104
105
106EOF
107
108if [ $? != 0 ]; then
109 echo problems generating 512 bit server cert request
110 exit 1
111fi
112
113#sign it.
114echo
115echo signing 512 bit server cert
116$SSLEAY x509 -md5 -days 365 \
117 -req \
118 -CAcreateserial -CAserial ca-cert.srl \
119 -CA ca-cert.pem -CAkey ca-key.pem \
120 -in s512-req.pem -out server.pem
121
122if [ $? != 0 ]; then
123 echo problems signing 512 bit server cert
124 exit 1
125fi
126echo
127
128# create 1024 bit server request.
129echo creating 1024 bit server cert request
130$SSLEAY req $CONF \
131 -new -md5 -newkey 1024 \
132 -keyout s1024key.pem \
133 -out s1024req.pem -nodes >/dev/null <<EOF
134AU
135Queensland
136.
137CryptSoft Pty Ltd
138.
139Server test cert (1024 bit)
140
141
142
143EOF
144
145if [ $? != 0 ]; then
146 echo problems generating 1024 bit server cert request
147 exit 1
148fi
149
150#sign it.
151echo
152echo signing 1024 bit server cert
153$SSLEAY x509 -md5 -days 365 \
154 -req \
155 -CAcreateserial -CAserial ca-cert.srl \
156 -CA ca-cert.pem -CAkey ca-key.pem \
157 -in s1024req.pem -out server2.pem
158
159if [ $? != 0 ]; then
160 echo problems signing 1024 bit server cert
161 exit 1
162fi
163echo
164
165# create 512 bit client request.
166echo creating 512 bit client cert request
167$SSLEAY req $CONF \
168 -new -md5 -newkey 512 \
169 -keyout c512-key.pem \
170 -out c512-req.pem -nodes >/dev/null <<EOF
171AU
172Queensland
173.
174CryptSoft Pty Ltd
175.
176Client test cert (512 bit)
177
178
179
180EOF
181
182if [ $? != 0 ]; then
183 echo problems generating 512 bit client cert request
184 exit 1
185fi
186
187#sign it.
188echo
189echo signing 512 bit client cert
190$SSLEAY x509 -md5 -days 365 \
191 -req \
192 -CAcreateserial -CAserial ca-cert.srl \
193 -CA ca-cert.pem -CAkey ca-key.pem \
194 -in c512-req.pem -out client.pem
195
196if [ $? != 0 ]; then
197 echo problems signing 512 bit client cert
198 exit 1
199fi
200
201echo cleanup
202
203cat pca-key.pem >> pca-cert.pem
204cat ca-key.pem >> ca-cert.pem
205cat s512-key.pem >> server.pem
206cat s1024key.pem >> server2.pem
207cat c512-key.pem >> client.pem
208
209for i in pca-cert.pem ca-cert.pem server.pem server2.pem client.pem
210do
211$SSLEAY x509 -issuer -subject -in $i -noout >$$
212cat $$
213/bin/cat $i >>$$
214/bin/mv $$ $i
215done
216
217#/bin/rm -f *key.pem *req.pem *.srl
218
219echo Finished
220
diff --git a/src/lib/libcrypto/util/mkdef.pl b/src/lib/libcrypto/util/mkdef.pl
new file mode 100644
index 0000000000..6c1e53bb14
--- /dev/null
+++ b/src/lib/libcrypto/util/mkdef.pl
@@ -0,0 +1,1407 @@
1#!/usr/local/bin/perl -w
2#
3# generate a .def file
4#
5# It does this by parsing the header files and looking for the
6# prototyped functions: it then prunes the output.
7#
8# Intermediary files are created, call libeay.num and ssleay.num,...
9# Previously, they had the following format:
10#
11# routine-name nnnn
12#
13# But that isn't enough for a number of reasons, the first on being that
14# this format is (needlessly) very Win32-centric, and even then...
15# One of the biggest problems is that there's no information about what
16# routines should actually be used, which varies with what crypto algorithms
17# are disabled. Also, some operating systems (for example VMS with VAX C)
18# need to keep track of the global variables as well as the functions.
19#
20# So, a remake of this script is done so as to include information on the
21# kind of symbol it is (function or variable) and what algorithms they're
22# part of. This will allow easy translating to .def files or the corresponding
23# file in other operating systems (a .opt file for VMS, possibly with a .mar
24# file).
25#
26# The format now becomes:
27#
28# routine-name nnnn info
29#
30# and the "info" part is actually a colon-separated string of fields with
31# the following meaning:
32#
33# existence:platform:kind:algorithms
34#
35# - "existence" can be "EXIST" or "NOEXIST" depending on if the symbol is
36# found somewhere in the source,
37# - "platforms" is empty if it exists on all platforms, otherwise it contains
38# comma-separated list of the platform, just as they are if the symbol exists
39# for those platforms, or prepended with a "!" if not. This helps resolve
40# symbol name variants for platforms where the names are too long for the
41# compiler or linker, or if the systems is case insensitive and there is a
42# clash, or the symbol is implemented differently (see
43# EXPORT_VAR_AS_FUNCTION). This script assumes renaming of symbols is found
44# in the file crypto/symhacks.h.
45# The semantics for the platforms is that every item is checked against the
46# environment. For the negative items ("!FOO"), if any of them is false
47# (i.e. "FOO" is true) in the environment, the corresponding symbol can't be
48# used. For the positive itms, if all of them are false in the environment,
49# the corresponding symbol can't be used. Any combination of positive and
50# negative items are possible, and of course leave room for some redundancy.
51# - "kind" is "FUNCTION" or "VARIABLE". The meaning of that is obvious.
52# - "algorithms" is a comma-separated list of algorithm names. This helps
53# exclude symbols that are part of an algorithm that some user wants to
54# exclude.
55#
56
57my $debug=0;
58
59my $crypto_num= "util/libeay.num";
60my $ssl_num= "util/ssleay.num";
61my $libname;
62
63my $do_update = 0;
64my $do_rewrite = 1;
65my $do_crypto = 0;
66my $do_ssl = 0;
67my $do_ctest = 0;
68my $do_ctestall = 0;
69my $do_checkexist = 0;
70
71my $VMSVAX=0;
72my $VMSAlpha=0;
73my $VMS=0;
74my $W32=0;
75my $W16=0;
76my $NT=0;
77my $OS2=0;
78# Set this to make typesafe STACK definitions appear in DEF
79my $safe_stack_def = 0;
80
81my @known_platforms = ( "__FreeBSD__", "PERL5", "NeXT",
82 "EXPORT_VAR_AS_FUNCTION", "OPENSSL_FIPS" );
83my @known_ossl_platforms = ( "VMS", "WIN16", "WIN32", "WINNT", "OS2" );
84my @known_algorithms = ( "RC2", "RC4", "RC5", "IDEA", "DES", "BF",
85 "CAST", "MD2", "MD4", "MD5", "SHA", "SHA0", "SHA1",
86 "SHA256", "SHA512", "RIPEMD",
87 "MDC2", "RSA", "DSA", "DH", "EC", "HMAC", "AES",
88 # Envelope "algorithms"
89 "EVP", "X509", "ASN1_TYPEDEFS",
90 # Helper "algorithms"
91 "BIO", "COMP", "BUFFER", "LHASH", "STACK", "ERR",
92 "LOCKING",
93 # External "algorithms"
94 "FP_API", "STDIO", "SOCK", "KRB5", "ENGINE", "HW" );
95
96my $options="";
97open(IN,"<Makefile") || die "unable to open Makefile!\n";
98while(<IN>) {
99 $options=$1 if (/^OPTIONS=(.*)$/);
100}
101close(IN);
102
103# The following ciphers may be excluded (by Configure). This means functions
104# defined with ifndef(NO_XXX) are not included in the .def file, and everything
105# in directory xxx is ignored.
106my $no_rc2; my $no_rc4; my $no_rc5; my $no_idea; my $no_des; my $no_bf;
107my $no_cast;
108my $no_md2; my $no_md4; my $no_md5; my $no_sha; my $no_ripemd; my $no_mdc2;
109my $no_rsa; my $no_dsa; my $no_dh; my $no_hmac=0; my $no_aes; my $no_krb5;
110my $no_ec; my $no_engine; my $no_hw;
111my $no_fp_api;
112my $fips;
113
114foreach (@ARGV, split(/ /, $options))
115 {
116 $debug=1 if $_ eq "debug";
117 $W32=1 if $_ eq "32";
118 $W16=1 if $_ eq "16";
119 if($_ eq "NT") {
120 $W32 = 1;
121 $NT = 1;
122 }
123 if ($_ eq "VMS-VAX") {
124 $VMS=1;
125 $VMSVAX=1;
126 }
127 if ($_ eq "VMS-Alpha") {
128 $VMS=1;
129 $VMSAlpha=1;
130 }
131 $VMS=1 if $_ eq "VMS";
132 $OS2=1 if $_ eq "OS2";
133 $fips=1 if $_ eq "fips";
134
135 $do_ssl=1 if $_ eq "ssleay";
136 if ($_ eq "ssl") {
137 $do_ssl=1;
138 $libname=$_
139 }
140 $do_crypto=1 if $_ eq "libeay";
141 if ($_ eq "crypto") {
142 $do_crypto=1;
143 $libname=$_;
144 }
145 $do_update=1 if $_ eq "update";
146 $do_rewrite=1 if $_ eq "rewrite";
147 $do_ctest=1 if $_ eq "ctest";
148 $do_ctestall=1 if $_ eq "ctestall";
149 $do_checkexist=1 if $_ eq "exist";
150 #$safe_stack_def=1 if $_ eq "-DDEBUG_SAFESTACK";
151
152 if (/^no-rc2$/) { $no_rc2=1; }
153 elsif (/^no-rc4$/) { $no_rc4=1; }
154 elsif (/^no-rc5$/) { $no_rc5=1; }
155 elsif (/^no-idea$/) { $no_idea=1; }
156 elsif (/^no-des$/) { $no_des=1; $no_mdc2=1; }
157 elsif (/^no-bf$/) { $no_bf=1; }
158 elsif (/^no-cast$/) { $no_cast=1; }
159 elsif (/^no-md2$/) { $no_md2=1; }
160 elsif (/^no-md4$/) { $no_md4=1; }
161 elsif (/^no-md5$/) { $no_md5=1; }
162 elsif (/^no-sha$/) { $no_sha=1; }
163 elsif (/^no-ripemd$/) { $no_ripemd=1; }
164 elsif (/^no-mdc2$/) { $no_mdc2=1; }
165 elsif (/^no-rsa$/) { $no_rsa=1; }
166 elsif (/^no-dsa$/) { $no_dsa=1; }
167 elsif (/^no-dh$/) { $no_dh=1; }
168 elsif (/^no-ec$/) { $no_ec=1; }
169 elsif (/^no-hmac$/) { $no_hmac=1; }
170 elsif (/^no-aes$/) { $no_aes=1; }
171 elsif (/^no-evp$/) { $no_evp=1; }
172 elsif (/^no-lhash$/) { $no_lhash=1; }
173 elsif (/^no-stack$/) { $no_stack=1; }
174 elsif (/^no-err$/) { $no_err=1; }
175 elsif (/^no-buffer$/) { $no_buffer=1; }
176 elsif (/^no-bio$/) { $no_bio=1; }
177 #elsif (/^no-locking$/) { $no_locking=1; }
178 elsif (/^no-comp$/) { $no_comp=1; }
179 elsif (/^no-dso$/) { $no_dso=1; }
180 elsif (/^no-krb5$/) { $no_krb5=1; }
181 elsif (/^no-engine$/) { $no_engine=1; }
182 elsif (/^no-hw$/) { $no_hw=1; }
183 }
184
185
186if (!$libname) {
187 if ($do_ssl) {
188 $libname="SSLEAY";
189 }
190 if ($do_crypto) {
191 $libname="LIBEAY";
192 }
193}
194
195# If no platform is given, assume WIN32
196if ($W32 + $W16 + $VMS + $OS2 == 0) {
197 $W32 = 1;
198}
199
200# Add extra knowledge
201if ($W16) {
202 $no_fp_api=1;
203}
204
205if (!$do_ssl && !$do_crypto)
206 {
207 print STDERR "usage: $0 ( ssl | crypto ) [ 16 | 32 | NT | OS2 ]\n";
208 exit(1);
209 }
210
211%ssl_list=&load_numbers($ssl_num);
212$max_ssl = $max_num;
213%crypto_list=&load_numbers($crypto_num);
214$max_crypto = $max_num;
215
216my $ssl="ssl/ssl.h";
217$ssl.=" ssl/kssl.h";
218
219my $crypto ="crypto/crypto.h";
220$crypto.=" crypto/des/des.h crypto/des/des_old.h" ; # unless $no_des;
221$crypto.=" crypto/idea/idea.h" ; # unless $no_idea;
222$crypto.=" crypto/rc4/rc4.h" ; # unless $no_rc4;
223$crypto.=" crypto/rc5/rc5.h" ; # unless $no_rc5;
224$crypto.=" crypto/rc2/rc2.h" ; # unless $no_rc2;
225$crypto.=" crypto/bf/blowfish.h" ; # unless $no_bf;
226$crypto.=" crypto/cast/cast.h" ; # unless $no_cast;
227$crypto.=" crypto/md2/md2.h" ; # unless $no_md2;
228$crypto.=" crypto/md4/md4.h" ; # unless $no_md4;
229$crypto.=" crypto/md5/md5.h" ; # unless $no_md5;
230$crypto.=" crypto/mdc2/mdc2.h" ; # unless $no_mdc2;
231$crypto.=" crypto/sha/sha.h" ; # unless $no_sha;
232$crypto.=" crypto/ripemd/ripemd.h" ; # unless $no_ripemd;
233$crypto.=" crypto/aes/aes.h" ; # unless $no_aes;
234
235$crypto.=" crypto/bn/bn.h";
236$crypto.=" crypto/rsa/rsa.h" ; # unless $no_rsa;
237$crypto.=" crypto/dsa/dsa.h" ; # unless $no_dsa;
238$crypto.=" crypto/dh/dh.h" ; # unless $no_dh;
239$crypto.=" crypto/ec/ec.h" ; # unless $no_ec;
240$crypto.=" crypto/hmac/hmac.h" ; # unless $no_hmac;
241
242$crypto.=" crypto/engine/engine.h"; # unless $no_engine;
243$crypto.=" crypto/stack/stack.h" ; # unless $no_stack;
244$crypto.=" crypto/buffer/buffer.h" ; # unless $no_buffer;
245$crypto.=" crypto/bio/bio.h" ; # unless $no_bio;
246$crypto.=" crypto/dso/dso.h" ; # unless $no_dso;
247$crypto.=" crypto/lhash/lhash.h" ; # unless $no_lhash;
248$crypto.=" crypto/conf/conf.h";
249$crypto.=" crypto/txt_db/txt_db.h";
250
251$crypto.=" crypto/evp/evp.h" ; # unless $no_evp;
252$crypto.=" crypto/objects/objects.h";
253$crypto.=" crypto/pem/pem.h";
254#$crypto.=" crypto/meth/meth.h";
255$crypto.=" crypto/asn1/asn1.h";
256$crypto.=" crypto/asn1/asn1t.h";
257$crypto.=" crypto/asn1/asn1_mac.h";
258$crypto.=" crypto/err/err.h" ; # unless $no_err;
259$crypto.=" crypto/pkcs7/pkcs7.h";
260$crypto.=" crypto/pkcs12/pkcs12.h";
261$crypto.=" crypto/x509/x509.h";
262$crypto.=" crypto/x509/x509_vfy.h";
263$crypto.=" crypto/x509v3/x509v3.h";
264$crypto.=" crypto/rand/rand.h";
265$crypto.=" crypto/comp/comp.h" ; # unless $no_comp;
266$crypto.=" crypto/ocsp/ocsp.h";
267$crypto.=" crypto/ui/ui.h crypto/ui/ui_compat.h";
268$crypto.=" crypto/krb5/krb5_asn.h";
269$crypto.=" crypto/tmdiff.h";
270$crypto.=" fips-1.0/fips.h fips-1.0/rand/fips_rand.h fips-1.0/sha/fips_sha.h";
271
272my $symhacks="crypto/symhacks.h";
273
274my @ssl_symbols = &do_defs("SSLEAY", $ssl, $symhacks);
275my @crypto_symbols = &do_defs("LIBEAY", $crypto, $symhacks);
276
277if ($do_update) {
278
279if ($do_ssl == 1) {
280
281 &maybe_add_info("SSLEAY",*ssl_list,@ssl_symbols);
282 if ($do_rewrite == 1) {
283 open(OUT, ">$ssl_num");
284 &rewrite_numbers(*OUT,"SSLEAY",*ssl_list,@ssl_symbols);
285 } else {
286 open(OUT, ">>$ssl_num");
287 }
288 &update_numbers(*OUT,"SSLEAY",*ssl_list,$max_ssl,@ssl_symbols);
289 close OUT;
290}
291
292if($do_crypto == 1) {
293
294 &maybe_add_info("LIBEAY",*crypto_list,@crypto_symbols);
295 if ($do_rewrite == 1) {
296 open(OUT, ">$crypto_num");
297 &rewrite_numbers(*OUT,"LIBEAY",*crypto_list,@crypto_symbols);
298 } else {
299 open(OUT, ">>$crypto_num");
300 }
301 &update_numbers(*OUT,"LIBEAY",*crypto_list,$max_crypto,@crypto_symbols);
302 close OUT;
303}
304
305} elsif ($do_checkexist) {
306 &check_existing(*ssl_list, @ssl_symbols)
307 if $do_ssl == 1;
308 &check_existing(*crypto_list, @crypto_symbols)
309 if $do_crypto == 1;
310} elsif ($do_ctest || $do_ctestall) {
311
312 print <<"EOF";
313
314/* Test file to check all DEF file symbols are present by trying
315 * to link to all of them. This is *not* intended to be run!
316 */
317
318int main()
319{
320EOF
321 &print_test_file(*STDOUT,"SSLEAY",*ssl_list,$do_ctestall,@ssl_symbols)
322 if $do_ssl == 1;
323
324 &print_test_file(*STDOUT,"LIBEAY",*crypto_list,$do_ctestall,@crypto_symbols)
325 if $do_crypto == 1;
326
327 print "}\n";
328
329} else {
330
331 &print_def_file(*STDOUT,$libname,*ssl_list,@ssl_symbols)
332 if $do_ssl == 1;
333
334 &print_def_file(*STDOUT,$libname,*crypto_list,@crypto_symbols)
335 if $do_crypto == 1;
336
337}
338
339
340sub do_defs
341{
342 my($name,$files,$symhacksfile)=@_;
343 my $file;
344 my @ret;
345 my %syms;
346 my %platform; # For anything undefined, we assume ""
347 my %kind; # For anything undefined, we assume "FUNCTION"
348 my %algorithm; # For anything undefined, we assume ""
349 my %variant;
350 my %variant_cnt; # To be able to allocate "name{n}" if "name"
351 # is the same name as the original.
352 my $cpp;
353 my %unknown_algorithms = ();
354
355 foreach $file (split(/\s+/,$symhacksfile." ".$files))
356 {
357 print STDERR "DEBUG: starting on $file:\n" if $debug;
358 open(IN,"<$file") || die "unable to open $file:$!\n";
359 my $line = "", my $def= "";
360 my %tag = (
361 (map { $_ => 0 } @known_platforms),
362 (map { "OPENSSL_SYS_".$_ => 0 } @known_ossl_platforms),
363 (map { "OPENSSL_NO_".$_ => 0 } @known_algorithms),
364 NOPROTO => 0,
365 PERL5 => 0,
366 _WINDLL => 0,
367 CONST_STRICT => 0,
368 TRUE => 1,
369 );
370 my $symhacking = $file eq $symhacksfile;
371 my @current_platforms = ();
372 my @current_algorithms = ();
373
374 # params: symbol, alias, platforms, kind
375 # The reason to put this subroutine in a variable is that
376 # it will otherwise create it's own, unshared, version of
377 # %tag and %variant...
378 my $make_variant = sub
379 {
380 my ($s, $a, $p, $k) = @_;
381 my ($a1, $a2);
382
383 print STDERR "DEBUG: make_variant: Entered with ",$s,", ",$a,", ",(defined($p)?$p:""),", ",(defined($k)?$k:""),"\n" if $debug;
384 if (defined($p))
385 {
386 $a1 = join(",",$p,
387 grep(!/^$/,
388 map { $tag{$_} == 1 ? $_ : "" }
389 @known_platforms));
390 }
391 else
392 {
393 $a1 = join(",",
394 grep(!/^$/,
395 map { $tag{$_} == 1 ? $_ : "" }
396 @known_platforms));
397 }
398 $a2 = join(",",
399 grep(!/^$/,
400 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ : "" }
401 @known_ossl_platforms));
402 print STDERR "DEBUG: make_variant: a1 = $a1; a2 = $a2\n" if $debug;
403 if ($a1 eq "") { $a1 = $a2; }
404 elsif ($a1 ne "" && $a2 ne "") { $a1 .= ",".$a2; }
405 if ($a eq $s)
406 {
407 if (!defined($variant_cnt{$s}))
408 {
409 $variant_cnt{$s} = 0;
410 }
411 $variant_cnt{$s}++;
412 $a .= "{$variant_cnt{$s}}";
413 }
414 my $toadd = $a.":".$a1.(defined($k)?":".$k:"");
415 my $togrep = $s.'(\{[0-9]+\})?:'.$a1.(defined($k)?":".$k:"");
416 if (!grep(/^$togrep$/,
417 split(/;/, defined($variant{$s})?$variant{$s}:""))) {
418 if (defined($variant{$s})) { $variant{$s} .= ";"; }
419 $variant{$s} .= $toadd;
420 }
421 print STDERR "DEBUG: make_variant: Exit with variant of ",$s," = ",$variant{$s},"\n" if $debug;
422 };
423
424 print STDERR "DEBUG: parsing ----------\n" if $debug;
425 while(<IN>) {
426 last if (/\/\* Error codes for the \w+ functions\. \*\//);
427 if ($line ne '') {
428 $_ = $line . $_;
429 $line = '';
430 }
431
432 if (/\\$/) {
433 chomp; # remove eol
434 chop; # remove ending backslash
435 $line = $_;
436 next;
437 }
438
439 $cpp = 1 if /^\#.*ifdef.*cplusplus/;
440 if ($cpp) {
441 $cpp = 0 if /^\#.*endif/;
442 next;
443 }
444
445 s/\/\*.*?\*\///gs; # ignore comments
446 if (/\/\*/) { # if we have part
447 $line = $_; # of a comment,
448 next; # continue reading
449 }
450 s/{[^{}]*}//gs; # ignore {} blocks
451 print STDERR "DEBUG: \$def=\"$def\"\n" if $debug && $def ne "";
452 print STDERR "DEBUG: \$_=\"$_\"\n" if $debug;
453 if (/^\#\s*ifndef\s+(.*)/) {
454 push(@tag,"-");
455 push(@tag,$1);
456 $tag{$1}=-1;
457 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
458 } elsif (/^\#\s*if\s+!defined\(([^\)]+)\)/) {
459 push(@tag,"-");
460 if (/^\#\s*if\s+(!defined\(([^\)]+)\)(\s+\&\&\s+!defined\(([^\)]+)\))*)$/) {
461 my $tmp_1 = $1;
462 my $tmp_;
463 foreach $tmp_ (split '\&\&',$tmp_1) {
464 $tmp_ =~ /!defined\(([^\)]+)\)/;
465 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
466 push(@tag,$1);
467 $tag{$1}=-1;
468 }
469 } else {
470 print STDERR "Warning: $file: complicated expression: $_" if $debug; # because it is O...
471 print STDERR "DEBUG: $file: found tag $1 = -1\n" if $debug;
472 push(@tag,$1);
473 $tag{$1}=-1;
474 }
475 } elsif (/^\#\s*ifdef\s+(\S*)/) {
476 push(@tag,"-");
477 push(@tag,$1);
478 $tag{$1}=1;
479 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
480 } elsif (/^\#\s*if\s+defined\(([^\)]+)\)/) {
481 push(@tag,"-");
482 if (/^\#\s*if\s+(defined\(([^\)]+)\)(\s+\|\|\s+defined\(([^\)]+)\))*)$/) {
483 my $tmp_1 = $1;
484 my $tmp_;
485 foreach $tmp_ (split '\|\|',$tmp_1) {
486 $tmp_ =~ /defined\(([^\)]+)\)/;
487 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
488 push(@tag,$1);
489 $tag{$1}=1;
490 }
491 } else {
492 print STDERR "Warning: $file: complicated expression: $_\n" if $debug; # because it is O...
493 print STDERR "DEBUG: $file: found tag $1 = 1\n" if $debug;
494 push(@tag,$1);
495 $tag{$1}=1;
496 }
497 } elsif (/^\#\s*error\s+(\w+) is disabled\./) {
498 my $tag_i = $#tag;
499 while($tag[$tag_i] ne "-") {
500 if ($tag[$tag_i] eq "OPENSSL_NO_".$1) {
501 $tag{$tag[$tag_i]}=2;
502 print STDERR "DEBUG: $file: chaged tag $1 = 2\n" if $debug;
503 }
504 $tag_i--;
505 }
506 } elsif (/^\#\s*endif/) {
507 my $tag_i = $#tag;
508 while($tag[$tag_i] ne "-") {
509 my $t=$tag[$tag_i];
510 print STDERR "DEBUG: \$t=\"$t\"\n" if $debug;
511 if ($tag{$t}==2) {
512 $tag{$t}=-1;
513 } else {
514 $tag{$t}=0;
515 }
516 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
517 pop(@tag);
518 if ($t =~ /^OPENSSL_NO_([A-Z0-9_]+)$/) {
519 $t=$1;
520 } else {
521 $t="";
522 }
523 if ($t ne ""
524 && !grep(/^$t$/, @known_algorithms)) {
525 $unknown_algorithms{$t} = 1;
526 #print STDERR "DEBUG: Added as unknown algorithm: $t\n" if $debug;
527 }
528 $tag_i--;
529 }
530 pop(@tag);
531 } elsif (/^\#\s*else/) {
532 my $tag_i = $#tag;
533 while($tag[$tag_i] ne "-") {
534 my $t=$tag[$tag_i];
535 $tag{$t}= -$tag{$t};
536 print STDERR "DEBUG: $file: changed tag ",$t," = ",$tag{$t},"\n" if $debug;
537 $tag_i--;
538 }
539 } elsif (/^\#\s*if\s+1/) {
540 push(@tag,"-");
541 # Dummy tag
542 push(@tag,"TRUE");
543 $tag{"TRUE"}=1;
544 print STDERR "DEBUG: $file: found 1\n" if $debug;
545 } elsif (/^\#\s*if\s+0/) {
546 push(@tag,"-");
547 # Dummy tag
548 push(@tag,"TRUE");
549 $tag{"TRUE"}=-1;
550 print STDERR "DEBUG: $file: found 0\n" if $debug;
551 } elsif (/^\#\s*define\s+(\w+)\s+(\w+)/
552 && $symhacking && $tag{'TRUE'} != -1) {
553 # This is for aliasing. When we find an alias,
554 # we have to invert
555 &$make_variant($1,$2);
556 print STDERR "DEBUG: $file: defined $1 = $2\n" if $debug;
557 }
558 if (/^\#/) {
559 @current_platforms =
560 grep(!/^$/,
561 map { $tag{$_} == 1 ? $_ :
562 $tag{$_} == -1 ? "!".$_ : "" }
563 @known_platforms);
564 push @current_platforms
565 , grep(!/^$/,
566 map { $tag{"OPENSSL_SYS_".$_} == 1 ? $_ :
567 $tag{"OPENSSL_SYS_".$_} == -1 ? "!".$_ : "" }
568 @known_ossl_platforms);
569 @current_algorithms =
570 grep(!/^$/,
571 map { $tag{"OPENSSL_NO_".$_} == -1 ? $_ : "" }
572 @known_algorithms);
573 $def .=
574 "#INFO:"
575 .join(',',@current_platforms).":"
576 .join(',',@current_algorithms).";";
577 next;
578 }
579 if ($tag{'TRUE'} != -1) {
580 if (/^\s*DECLARE_STACK_OF\s*\(\s*(\w*)\s*\)/) {
581 next;
582 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
583 $def .= "int d2i_$3(void);";
584 $def .= "int i2d_$3(void);";
585 # Variant for platforms that do not
586 # have to access globale variables
587 # in shared libraries through functions
588 $def .=
589 "#INFO:"
590 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
591 .join(',',@current_algorithms).";";
592 $def .= "OPENSSL_EXTERN int $2_it;";
593 $def .=
594 "#INFO:"
595 .join(',',@current_platforms).":"
596 .join(',',@current_algorithms).";";
597 # Variant for platforms that have to
598 # access globale variables in shared
599 # libraries through functions
600 &$make_variant("$2_it","$2_it",
601 "EXPORT_VAR_AS_FUNCTION",
602 "FUNCTION");
603 next;
604 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_fname\s*\(\s*(\w*)\s*,\s*(\w*)\s*,\s*(\w*)\s*\)/) {
605 $def .= "int d2i_$3(void);";
606 $def .= "int i2d_$3(void);";
607 $def .= "int $3_free(void);";
608 $def .= "int $3_new(void);";
609 # Variant for platforms that do not
610 # have to access globale variables
611 # in shared libraries through functions
612 $def .=
613 "#INFO:"
614 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
615 .join(',',@current_algorithms).";";
616 $def .= "OPENSSL_EXTERN int $2_it;";
617 $def .=
618 "#INFO:"
619 .join(',',@current_platforms).":"
620 .join(',',@current_algorithms).";";
621 # Variant for platforms that have to
622 # access globale variables in shared
623 # libraries through functions
624 &$make_variant("$2_it","$2_it",
625 "EXPORT_VAR_AS_FUNCTION",
626 "FUNCTION");
627 next;
628 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS\s*\(\s*(\w*)\s*\)/ ||
629 /^\s*DECLARE_ASN1_FUNCTIONS_const\s*\(\s*(\w*)\s*\)/) {
630 $def .= "int d2i_$1(void);";
631 $def .= "int i2d_$1(void);";
632 $def .= "int $1_free(void);";
633 $def .= "int $1_new(void);";
634 # Variant for platforms that do not
635 # have to access globale variables
636 # in shared libraries through functions
637 $def .=
638 "#INFO:"
639 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
640 .join(',',@current_algorithms).";";
641 $def .= "OPENSSL_EXTERN int $1_it;";
642 $def .=
643 "#INFO:"
644 .join(',',@current_platforms).":"
645 .join(',',@current_algorithms).";";
646 # Variant for platforms that have to
647 # access globale variables in shared
648 # libraries through functions
649 &$make_variant("$1_it","$1_it",
650 "EXPORT_VAR_AS_FUNCTION",
651 "FUNCTION");
652 next;
653 } elsif (/^\s*DECLARE_ASN1_ENCODE_FUNCTIONS_const\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
654 $def .= "int d2i_$2(void);";
655 $def .= "int i2d_$2(void);";
656 # Variant for platforms that do not
657 # have to access globale variables
658 # in shared libraries through functions
659 $def .=
660 "#INFO:"
661 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
662 .join(',',@current_algorithms).";";
663 $def .= "OPENSSL_EXTERN int $2_it;";
664 $def .=
665 "#INFO:"
666 .join(',',@current_platforms).":"
667 .join(',',@current_algorithms).";";
668 # Variant for platforms that have to
669 # access globale variables in shared
670 # libraries through functions
671 &$make_variant("$2_it","$2_it",
672 "EXPORT_VAR_AS_FUNCTION",
673 "FUNCTION");
674 next;
675 } elsif (/^\s*DECLARE_ASN1_FUNCTIONS_name\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
676 $def .= "int d2i_$2(void);";
677 $def .= "int i2d_$2(void);";
678 $def .= "int $2_free(void);";
679 $def .= "int $2_new(void);";
680 # Variant for platforms that do not
681 # have to access globale variables
682 # in shared libraries through functions
683 $def .=
684 "#INFO:"
685 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
686 .join(',',@current_algorithms).";";
687 $def .= "OPENSSL_EXTERN int $2_it;";
688 $def .=
689 "#INFO:"
690 .join(',',@current_platforms).":"
691 .join(',',@current_algorithms).";";
692 # Variant for platforms that have to
693 # access globale variables in shared
694 # libraries through functions
695 &$make_variant("$2_it","$2_it",
696 "EXPORT_VAR_AS_FUNCTION",
697 "FUNCTION");
698 next;
699 } elsif (/^\s*DECLARE_ASN1_ITEM\s*\(\s*(\w*)\s*\)/) {
700 # Variant for platforms that do not
701 # have to access globale variables
702 # in shared libraries through functions
703 $def .=
704 "#INFO:"
705 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
706 .join(',',@current_algorithms).";";
707 $def .= "OPENSSL_EXTERN int $1_it;";
708 $def .=
709 "#INFO:"
710 .join(',',@current_platforms).":"
711 .join(',',@current_algorithms).";";
712 # Variant for platforms that have to
713 # access globale variables in shared
714 # libraries through functions
715 &$make_variant("$1_it","$1_it",
716 "EXPORT_VAR_AS_FUNCTION",
717 "FUNCTION");
718 next;
719 } elsif (/^\s*DECLARE_ASN1_SET_OF\s*\(\s*(\w*)\s*\)/) {
720 next;
721 } elsif (/^\s*DECLARE_PKCS12_STACK_OF\s*\(\s*(\w*)\s*\)/) {
722 next;
723 } elsif (/^DECLARE_PEM_rw\s*\(\s*(\w*)\s*,/ ||
724 /^DECLARE_PEM_rw_cb\s*\(\s*(\w*)\s*,/ ) {
725 # Things not in Win16
726 $def .=
727 "#INFO:"
728 .join(',',"!WIN16",@current_platforms).":"
729 .join(',',@current_algorithms).";";
730 $def .= "int PEM_read_$1(void);";
731 $def .= "int PEM_write_$1(void);";
732 $def .=
733 "#INFO:"
734 .join(',',@current_platforms).":"
735 .join(',',@current_algorithms).";";
736 # Things that are everywhere
737 $def .= "int PEM_read_bio_$1(void);";
738 $def .= "int PEM_write_bio_$1(void);";
739 next;
740 } elsif (/^DECLARE_PEM_write\s*\(\s*(\w*)\s*,/ ||
741 /^DECLARE_PEM_write_cb\s*\(\s*(\w*)\s*,/ ) {
742 # Things not in Win16
743 $def .=
744 "#INFO:"
745 .join(',',"!WIN16",@current_platforms).":"
746 .join(',',@current_algorithms).";";
747 $def .= "int PEM_write_$1(void);";
748 $def .=
749 "#INFO:"
750 .join(',',@current_platforms).":"
751 .join(',',@current_algorithms).";";
752 # Things that are everywhere
753 $def .= "int PEM_write_bio_$1(void);";
754 next;
755 } elsif (/^DECLARE_PEM_read\s*\(\s*(\w*)\s*,/ ||
756 /^DECLARE_PEM_read_cb\s*\(\s*(\w*)\s*,/ ) {
757 # Things not in Win16
758 $def .=
759 "#INFO:"
760 .join(',',"!WIN16",@current_platforms).":"
761 .join(',',@current_algorithms).";";
762 $def .= "int PEM_read_$1(void);";
763 $def .=
764 "#INFO:"
765 .join(',',@current_platforms).":"
766 .join(',',@current_algorithms).";";
767 # Things that are everywhere
768 $def .= "int PEM_read_bio_$1(void);";
769 next;
770 } elsif (/^OPENSSL_DECLARE_GLOBAL\s*\(\s*(\w*)\s*,\s*(\w*)\s*\)/) {
771 # Variant for platforms that do not
772 # have to access globale variables
773 # in shared libraries through functions
774 $def .=
775 "#INFO:"
776 .join(',',"!EXPORT_VAR_AS_FUNCTION",@current_platforms).":"
777 .join(',',@current_algorithms).";";
778 $def .= "OPENSSL_EXTERN int _shadow_$2;";
779 $def .=
780 "#INFO:"
781 .join(',',@current_platforms).":"
782 .join(',',@current_algorithms).";";
783 # Variant for platforms that have to
784 # access globale variables in shared
785 # libraries through functions
786 &$make_variant("_shadow_$2","_shadow_$2",
787 "EXPORT_VAR_AS_FUNCTION",
788 "FUNCTION");
789 } elsif ($tag{'CONST_STRICT'} != 1) {
790 if (/\{|\/\*|\([^\)]*$/) {
791 $line = $_;
792 } else {
793 $def .= $_;
794 }
795 }
796 }
797 }
798 close(IN);
799
800 my $algs = '';
801 my $plays;
802
803 print STDERR "DEBUG: postprocessing ----------\n" if $debug;
804 foreach (split /;/, $def) {
805 my $s; my $k = "FUNCTION"; my $p; my $a;
806 s/^[\n\s]*//g;
807 s/[\n\s]*$//g;
808 next if(/\#undef/);
809 next if(/typedef\W/);
810 next if(/\#define/);
811
812 print STDERR "DEBUG: \$_ = \"$_\"\n" if $debug;
813 if (/^\#INFO:([^:]*):(.*)$/) {
814 $plats = $1;
815 $algs = $2;
816 print STDERR "DEBUG: found info on platforms ($plats) and algorithms ($algs)\n" if $debug;
817 next;
818 } elsif (/^\s*OPENSSL_EXTERN\s.*?(\w+(\{[0-9]+\})?)(\[[0-9]*\])*\s*$/) {
819 $s = $1;
820 $k = "VARIABLE";
821 print STDERR "DEBUG: found external variable $s\n" if $debug;
822 } elsif (/\(\*(\w*(\{[0-9]+\})?)\([^\)]+/) {
823 $s = $1;
824 print STDERR "DEBUG: found ANSI C function $s\n" if $debug;
825 } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s) {
826 # K&R C
827 print STDERR "DEBUG: found K&R C function $s\n" if $debug;
828 next;
829 } elsif (/\w+\W+\w+(\{[0-9]+\})?\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
830 while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
831 s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
832 s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
833 }
834 s/\(void\)//;
835 /(\w+(\{[0-9]+\})?)\W*\(\)/s;
836 $s = $1;
837 print STDERR "DEBUG: found function $s\n" if $debug;
838 } elsif (/\(/ and not (/=/)) {
839 print STDERR "File $file: cannot parse: $_;\n";
840 next;
841 } else {
842 next;
843 }
844
845 $syms{$s} = 1;
846 $kind{$s} = $k;
847
848 $p = $plats;
849 $a = $algs;
850 $a .= ",BF" if($s =~ /EVP_bf/);
851 $a .= ",CAST" if($s =~ /EVP_cast/);
852 $a .= ",DES" if($s =~ /EVP_des/);
853 $a .= ",DSA" if($s =~ /EVP_dss/);
854 $a .= ",IDEA" if($s =~ /EVP_idea/);
855 $a .= ",MD2" if($s =~ /EVP_md2/);
856 $a .= ",MD4" if($s =~ /EVP_md4/);
857 $a .= ",MD5" if($s =~ /EVP_md5/);
858 $a .= ",RC2" if($s =~ /EVP_rc2/);
859 $a .= ",RC4" if($s =~ /EVP_rc4/);
860 $a .= ",RC5" if($s =~ /EVP_rc5/);
861 $a .= ",RIPEMD" if($s =~ /EVP_ripemd/);
862 $a .= ",SHA" if($s =~ /EVP_sha/);
863 $a .= ",RSA" if($s =~ /EVP_(Open|Seal)(Final|Init)/);
864 $a .= ",RSA" if($s =~ /PEM_Seal(Final|Init|Update)/);
865 $a .= ",RSA" if($s =~ /RSAPrivateKey/);
866 $a .= ",RSA" if($s =~ /SSLv23?_((client|server)_)?method/);
867 # SHA2 algorithms only defined in FIPS mode for
868 # OpenSSL 0.9.7
869 $p .= "OPENSSL_FIPS" if($s =~ /SHA[235]/);
870
871 $platform{$s} =
872 &reduce_platforms((defined($platform{$s})?$platform{$s}.',':"").$p);
873 $algorithm{$s} = '' if !defined $algorithm{$s};
874 $algorithm{$s} .= ','.$a;
875
876 if (defined($variant{$s})) {
877 foreach $v (split /;/,$variant{$s}) {
878 (my $r, my $p, my $k) = split(/:/,$v);
879 my $ip = join ',',map({ /^!(.*)$/ ? $1 : "!".$_ } split /,/, $p);
880 $syms{$r} = 1;
881 if (!defined($k)) { $k = $kind{$s}; }
882 $kind{$r} = $k."(".$s.")";
883 $algorithm{$r} = $algorithm{$s};
884 $platform{$r} = &reduce_platforms($platform{$s}.",".$p.",".$p);
885 $platform{$s} = &reduce_platforms($platform{$s}.','.$ip.','.$ip);
886 print STDERR "DEBUG: \$variant{\"$s\"} = ",$v,"; \$r = $r; \$p = ",$platform{$r},"; \$a = ",$algorithm{$r},"; \$kind = ",$kind{$r},"\n" if $debug;
887 }
888 }
889 print STDERR "DEBUG: \$s = $s; \$p = ",$platform{$s},"; \$a = ",$algorithm{$s},"; \$kind = ",$kind{$s},"\n" if $debug;
890 }
891 }
892
893 # Prune the returned symbols
894
895 delete $syms{"bn_dump1"};
896 $platform{"BIO_s_log"} .= ",!WIN32,!WIN16,!macintosh";
897
898 $platform{"PEM_read_NS_CERT_SEQ"} = "VMS";
899 $platform{"PEM_write_NS_CERT_SEQ"} = "VMS";
900 $platform{"PEM_read_P8_PRIV_KEY_INFO"} = "VMS";
901 $platform{"PEM_write_P8_PRIV_KEY_INFO"} = "VMS";
902
903 # Info we know about
904
905 push @ret, map { $_."\\".&info_string($_,"EXIST",
906 $platform{$_},
907 $kind{$_},
908 $algorithm{$_}) } keys %syms;
909
910 if (keys %unknown_algorithms) {
911 print STDERR "WARNING: mkdef.pl doesn't know the following algorithms:\n";
912 print STDERR "\t",join("\n\t",keys %unknown_algorithms),"\n";
913 }
914 return(@ret);
915}
916
917# Param: string of comma-separated platform-specs.
918sub reduce_platforms
919{
920 my ($platforms) = @_;
921 my $pl = defined($platforms) ? $platforms : "";
922 my %p = map { $_ => 0 } split /,/, $pl;
923 my $ret;
924
925 print STDERR "DEBUG: Entered reduce_platforms with \"$platforms\"\n"
926 if $debug;
927 # We do this, because if there's code like the following, it really
928 # means the function exists in all cases and should therefore be
929 # everywhere. By increasing and decreasing, we may attain 0:
930 #
931 # ifndef WIN16
932 # int foo();
933 # else
934 # int _fat foo();
935 # endif
936 foreach $platform (split /,/, $pl) {
937 if ($platform =~ /^!(.*)$/) {
938 $p{$1}--;
939 } else {
940 $p{$platform}++;
941 }
942 }
943 foreach $platform (keys %p) {
944 if ($p{$platform} == 0) { delete $p{$platform}; }
945 }
946
947 delete $p{""};
948
949 $ret = join(',',sort(map { $p{$_} < 0 ? "!".$_ : $_ } keys %p));
950 print STDERR "DEBUG: Exiting reduce_platforms with \"$ret\"\n"
951 if $debug;
952 return $ret;
953}
954
955sub info_string {
956 (my $symbol, my $exist, my $platforms, my $kind, my $algorithms) = @_;
957
958 my %a = defined($algorithms) ?
959 map { $_ => 1 } split /,/, $algorithms : ();
960 my $k = defined($kind) ? $kind : "FUNCTION";
961 my $ret;
962 my $p = &reduce_platforms($platforms);
963
964 delete $a{""};
965
966 $ret = $exist;
967 $ret .= ":".$p;
968 $ret .= ":".$k;
969 $ret .= ":".join(',',sort keys %a);
970 return $ret;
971}
972
973sub maybe_add_info {
974 (my $name, *nums, my @symbols) = @_;
975 my $sym;
976 my $new_info = 0;
977 my %syms=();
978
979 print STDERR "Updating $name info\n";
980 foreach $sym (@symbols) {
981 (my $s, my $i) = split /\\/, $sym;
982 if (defined($nums{$s})) {
983 $i =~ s/^(.*?:.*?:\w+)(\(\w+\))?/$1/;
984 (my $n, my $dummy) = split /\\/, $nums{$s};
985 if (!defined($dummy) || $i ne $dummy) {
986 $nums{$s} = $n."\\".$i;
987 $new_info++;
988 print STDERR "DEBUG: maybe_add_info for $s: \"$dummy\" => \"$i\"\n" if $debug;
989 }
990 }
991 $syms{$s} = 1;
992 }
993
994 my @s=sort { &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n") } keys %nums;
995 foreach $sym (@s) {
996 (my $n, my $i) = split /\\/, $nums{$sym};
997 if (!defined($syms{$sym}) && $i !~ /^NOEXIST:/) {
998 $new_info++;
999 print STDERR "DEBUG: maybe_add_info for $sym: -> undefined\n" if $debug;
1000 }
1001 }
1002 if ($new_info) {
1003 print STDERR "$new_info old symbols got an info update\n";
1004 if (!$do_rewrite) {
1005 print STDERR "You should do a rewrite to fix this.\n";
1006 }
1007 } else {
1008 print STDERR "No old symbols needed info update\n";
1009 }
1010}
1011
1012# Param: string of comma-separated keywords, each possibly prefixed with a "!"
1013sub is_valid
1014{
1015 my ($keywords_txt,$platforms) = @_;
1016 my (@keywords) = split /,/,$keywords_txt;
1017 my ($falsesum, $truesum) = (0, 1);
1018
1019 # Param: one keyword
1020 sub recognise
1021 {
1022 my ($keyword,$platforms) = @_;
1023
1024 if ($platforms) {
1025 # platforms
1026 if ($keyword eq "VMS" && $VMS) { return 1; }
1027 if ($keyword eq "WIN32" && $W32) { return 1; }
1028 if ($keyword eq "WIN16" && $W16) { return 1; }
1029 if ($keyword eq "WINNT" && $NT) { return 1; }
1030 if ($keyword eq "OS2" && $OS2) { return 1; }
1031 # Special platforms:
1032 # EXPORT_VAR_AS_FUNCTION means that global variables
1033 # will be represented as functions. This currently
1034 # only happens on VMS-VAX.
1035 if ($keyword eq "EXPORT_VAR_AS_FUNCTION" && ($VMSVAX || $W32 || $W16)) {
1036 return 1;
1037 }
1038 if ($keyword eq "OPENSSL_FIPS" && $fips) {
1039 return 1;
1040 }
1041 return 0;
1042 } else {
1043 # algorithms
1044 if ($keyword eq "RC2" && $no_rc2) { return 0; }
1045 if ($keyword eq "RC4" && $no_rc4) { return 0; }
1046 if ($keyword eq "RC5" && $no_rc5) { return 0; }
1047 if ($keyword eq "IDEA" && $no_idea) { return 0; }
1048 if ($keyword eq "DES" && $no_des) { return 0; }
1049 if ($keyword eq "BF" && $no_bf) { return 0; }
1050 if ($keyword eq "CAST" && $no_cast) { return 0; }
1051 if ($keyword eq "MD2" && $no_md2) { return 0; }
1052 if ($keyword eq "MD4" && $no_md4) { return 0; }
1053 if ($keyword eq "MD5" && $no_md5) { return 0; }
1054 if ($keyword eq "SHA" && $no_sha) { return 0; }
1055 if ($keyword eq "RIPEMD" && $no_ripemd) { return 0; }
1056 if ($keyword eq "MDC2" && $no_mdc2) { return 0; }
1057 if ($keyword eq "RSA" && $no_rsa) { return 0; }
1058 if ($keyword eq "DSA" && $no_dsa) { return 0; }
1059 if ($keyword eq "DH" && $no_dh) { return 0; }
1060 if ($keyword eq "EC" && $no_ec) { return 0; }
1061 if ($keyword eq "HMAC" && $no_hmac) { return 0; }
1062 if ($keyword eq "AES" && $no_aes) { return 0; }
1063 if ($keyword eq "EVP" && $no_evp) { return 0; }
1064 if ($keyword eq "LHASH" && $no_lhash) { return 0; }
1065 if ($keyword eq "STACK" && $no_stack) { return 0; }
1066 if ($keyword eq "ERR" && $no_err) { return 0; }
1067 if ($keyword eq "BUFFER" && $no_buffer) { return 0; }
1068 if ($keyword eq "BIO" && $no_bio) { return 0; }
1069 if ($keyword eq "COMP" && $no_comp) { return 0; }
1070 if ($keyword eq "DSO" && $no_dso) { return 0; }
1071 if ($keyword eq "KRB5" && $no_krb5) { return 0; }
1072 if ($keyword eq "ENGINE" && $no_engine) { return 0; }
1073 if ($keyword eq "HW" && $no_hw) { return 0; }
1074 if ($keyword eq "FP_API" && $no_fp_api) { return 0; }
1075
1076 # Nothing recognise as true
1077 return 1;
1078 }
1079 }
1080
1081 foreach $k (@keywords) {
1082 if ($k =~ /^!(.*)$/) {
1083 $falsesum += &recognise($1,$platforms);
1084 } else {
1085 $truesum *= &recognise($k,$platforms);
1086 }
1087 }
1088 print STDERR "DEBUG: [",$#keywords,",",$#keywords < 0,"] is_valid($keywords_txt) => (\!$falsesum) && $truesum = ",(!$falsesum) && $truesum,"\n" if $debug;
1089 return (!$falsesum) && $truesum;
1090}
1091
1092sub print_test_file
1093{
1094 (*OUT,my $name,*nums,my $testall,my @symbols)=@_;
1095 my $n = 1; my @e; my @r;
1096 my $sym; my $prev = ""; my $prefSSLeay;
1097
1098 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1099 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:.*/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:.*/,@symbols);
1100 @symbols=((sort @e),(sort @r));
1101
1102 foreach $sym (@symbols) {
1103 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1104 my $v = 0;
1105 $v = 1 if $i=~ /^.*?:.*?:VARIABLE/;
1106 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1107 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1108 if (!defined($nums{$s})) {
1109 print STDERR "Warning: $s does not have a number assigned\n"
1110 if(!$do_update);
1111 } elsif (is_valid($p,1) && is_valid($a,0)) {
1112 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1113 if ($prev eq $s2) {
1114 print OUT "\t/* The following has already appeared previously */\n";
1115 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1116 }
1117 $prev = $s2; # To warn about duplicates...
1118
1119 ($nn,$ni)=($nums{$s2} =~ /^(.*?)\\(.*)$/);
1120 if ($v) {
1121 print OUT "\textern int $s2; /* type unknown */ /* $nn $ni */\n";
1122 } else {
1123 print OUT "\textern int $s2(); /* type unknown */ /* $nn $ni */\n";
1124 }
1125 }
1126 }
1127}
1128
1129sub get_version {
1130 local *MF;
1131 my $v = '?';
1132 open MF, 'Makefile' or return $v;
1133 while (<MF>) {
1134 $v = $1, last if /^VERSION=(.*?)\s*$/;
1135 }
1136 close MF;
1137 return $v;
1138}
1139
1140sub print_def_file
1141{
1142 (*OUT,my $name,*nums,my @symbols)=@_;
1143 my $n = 1; my @e; my @r; my @v; my $prev="";
1144 my $liboptions="";
1145 my $libname = $name;
1146 my $http_vendor = 'www.openssl.org/';
1147 my $version = get_version();
1148 my $what = "OpenSSL: implementation of Secure Socket Layer";
1149 my $description = "$what $version, $name - http://$http_vendor";
1150
1151 if ($W32)
1152 { $libname.="32"; }
1153 elsif ($W16)
1154 { $libname.="16"; }
1155 elsif ($OS2)
1156 { # DLL names should not clash on the whole system.
1157 # However, they should not have any particular relationship
1158 # to the name of the static library. Chose descriptive names
1159 # (must be at most 8 chars).
1160 my %translate = (ssl => 'open_ssl', crypto => 'cryptssl');
1161 $libname = $translate{$name} || $name;
1162 $liboptions = <<EOO;
1163INITINSTANCE
1164DATA MULTIPLE NONSHARED
1165EOO
1166 # Vendor field can't contain colon, drat; so we omit http://
1167 $description = "\@#$http_vendor:$version#\@$what; DLL for library $name. Build for EMX -Zmtd";
1168 }
1169
1170 print OUT <<"EOF";
1171;
1172; Definition file for the DLL version of the $name library from OpenSSL
1173;
1174
1175LIBRARY $libname $liboptions
1176
1177DESCRIPTION '$description'
1178
1179EOF
1180
1181 if ($W16) {
1182 print <<"EOF";
1183CODE PRELOAD MOVEABLE
1184DATA PRELOAD MOVEABLE SINGLE
1185
1186EXETYPE WINDOWS
1187
1188HEAPSIZE 4096
1189STACKSIZE 8192
1190
1191EOF
1192 }
1193
1194 print "EXPORTS\n";
1195
1196 (@e)=grep(/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1197 (@r)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:FUNCTION/ && !/^SSLeay(\{[0-9]+\})?\\.*?:.*?:FUNCTION/,@symbols);
1198 (@v)=grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:VARIABLE/,@symbols);
1199 @symbols=((sort @e),(sort @r), (sort @v));
1200
1201
1202 foreach $sym (@symbols) {
1203 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1204 my $v = 0;
1205 $v = 1 if $i =~ /^.*?:.*?:VARIABLE/;
1206 if (!defined($nums{$s})) {
1207 printf STDERR "Warning: $s does not have a number assigned\n"
1208 if(!$do_update);
1209 } else {
1210 (my $n, my $dummy) = split /\\/, $nums{$s};
1211 my %pf = ();
1212 my $p = ($i =~ /^[^:]*:([^:]*):/,$1);
1213 my $a = ($i =~ /^[^:]*:[^:]*:[^:]*:([^:]*)/,$1);
1214 if (is_valid($p,1) && is_valid($a,0)) {
1215 my $s2 = ($s =~ /^(.*?)(\{[0-9]+\})?$/, $1);
1216 if ($prev eq $s2) {
1217 print STDERR "Warning: Symbol '",$s2,"' redefined. old=",($nums{$prev} =~ /^(.*?)\\/,$1),", new=",($nums{$s2} =~ /^(.*?)\\/,$1),"\n";
1218 }
1219 $prev = $s2; # To warn about duplicates...
1220 if($v && !$OS2) {
1221 printf OUT " %s%-39s @%-8d DATA\n",($W32)?"":"_",$s2,$n;
1222 } else {
1223 printf OUT " %s%-39s @%d\n",($W32||$OS2)?"":"_",$s2,$n;
1224 }
1225 }
1226 }
1227 }
1228 printf OUT "\n";
1229}
1230
1231sub load_numbers
1232{
1233 my($name)=@_;
1234 my(@a,%ret);
1235
1236 $max_num = 0;
1237 $num_noinfo = 0;
1238 $prev = "";
1239 $prev_cnt = 0;
1240
1241 open(IN,"<$name") || die "unable to open $name:$!\n";
1242 while (<IN>) {
1243 chop;
1244 s/#.*$//;
1245 next if /^\s*$/;
1246 @a=split;
1247 if (defined $ret{$a[0]}) {
1248 # This is actually perfectly OK
1249 #print STDERR "Warning: Symbol '",$a[0],"' redefined. old=",$ret{$a[0]},", new=",$a[1],"\n";
1250 }
1251 if ($max_num > $a[1]) {
1252 print STDERR "Warning: Number decreased from ",$max_num," to ",$a[1],"\n";
1253 }
1254 elsif ($max_num == $a[1]) {
1255 # This is actually perfectly OK
1256 #print STDERR "Warning: Symbol ",$a[0]," has same number as previous ",$prev,": ",$a[1],"\n";
1257 if ($a[0] eq $prev) {
1258 $prev_cnt++;
1259 $a[0] .= "{$prev_cnt}";
1260 }
1261 }
1262 else {
1263 $prev_cnt = 0;
1264 }
1265 if ($#a < 2) {
1266 # Existence will be proven later, in do_defs
1267 $ret{$a[0]}=$a[1];
1268 $num_noinfo++;
1269 } else {
1270 $ret{$a[0]}=$a[1]."\\".$a[2]; # \\ is a special marker
1271 }
1272 $max_num = $a[1] if $a[1] > $max_num;
1273 $prev=$a[0];
1274 }
1275 if ($num_noinfo) {
1276 print STDERR "Warning: $num_noinfo symbols were without info.";
1277 if ($do_rewrite) {
1278 printf STDERR " The rewrite will fix this.\n";
1279 } else {
1280 printf STDERR " You should do a rewrite to fix this.\n";
1281 }
1282 }
1283 close(IN);
1284 return(%ret);
1285}
1286
1287sub parse_number
1288{
1289 (my $str, my $what) = @_;
1290 (my $n, my $i) = split(/\\/,$str);
1291 if ($what eq "n") {
1292 return $n;
1293 } else {
1294 return $i;
1295 }
1296}
1297
1298sub rewrite_numbers
1299{
1300 (*OUT,$name,*nums,@symbols)=@_;
1301 my $thing;
1302
1303 print STDERR "Rewriting $name\n";
1304
1305 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1306 my $r; my %r; my %rsyms;
1307 foreach $r (@r) {
1308 (my $s, my $i) = split /\\/, $r;
1309 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1310 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1311 $r{$a} = $s."\\".$i;
1312 $rsyms{$s} = 1;
1313 }
1314
1315 my %syms = ();
1316 foreach $_ (@symbols) {
1317 (my $n, my $i) = split /\\/;
1318 $syms{$n} = 1;
1319 }
1320
1321 my @s=sort {
1322 &parse_number($nums{$a},"n") <=> &parse_number($nums{$b},"n")
1323 || $a cmp $b
1324 } keys %nums;
1325 foreach $sym (@s) {
1326 (my $n, my $i) = split /\\/, $nums{$sym};
1327 next if defined($i) && $i =~ /^.*?:.*?:\w+\(\w+\)/;
1328 next if defined($rsyms{$sym});
1329 print STDERR "DEBUG: rewrite_numbers for sym = ",$sym,": i = ",$i,", n = ",$n,", rsym{sym} = ",$rsyms{$sym},"syms{sym} = ",$syms{$sym},"\n" if $debug;
1330 $i="NOEXIST::FUNCTION:"
1331 if !defined($i) || $i eq "" || !defined($syms{$sym});
1332 my $s2 = $sym;
1333 $s2 =~ s/\{[0-9]+\}$//;
1334 printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
1335 if (exists $r{$sym}) {
1336 (my $s, $i) = split /\\/,$r{$sym};
1337 my $s2 = $s;
1338 $s2 =~ s/\{[0-9]+\}$//;
1339 printf OUT "%s%-39s %d\t%s\n","",$s2,$n,$i;
1340 }
1341 }
1342}
1343
1344sub update_numbers
1345{
1346 (*OUT,$name,*nums,my $start_num, my @symbols)=@_;
1347 my $new_syms = 0;
1348
1349 print STDERR "Updating $name numbers\n";
1350
1351 my @r = grep(/^\w+(\{[0-9]+\})?\\.*?:.*?:\w+\(\w+\)/,@symbols);
1352 my $r; my %r; my %rsyms;
1353 foreach $r (@r) {
1354 (my $s, my $i) = split /\\/, $r;
1355 my $a = $1 if $i =~ /^.*?:.*?:\w+\((\w+)\)/;
1356 $i =~ s/^(.*?:.*?:\w+)\(\w+\)/$1/;
1357 $r{$a} = $s."\\".$i;
1358 $rsyms{$s} = 1;
1359 }
1360
1361 foreach $sym (@symbols) {
1362 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1363 next if $i =~ /^.*?:.*?:\w+\(\w+\)/;
1364 next if defined($rsyms{$sym});
1365 die "ERROR: Symbol $sym had no info attached to it."
1366 if $i eq "";
1367 if (!exists $nums{$s}) {
1368 $new_syms++;
1369 my $s2 = $s;
1370 $s2 =~ s/\{[0-9]+\}$//;
1371 printf OUT "%s%-39s %d\t%s\n","",$s2, ++$start_num,$i;
1372 if (exists $r{$s}) {
1373 ($s, $i) = split /\\/,$r{$s};
1374 $s =~ s/\{[0-9]+\}$//;
1375 printf OUT "%s%-39s %d\t%s\n","",$s, $start_num,$i;
1376 }
1377 }
1378 }
1379 if($new_syms) {
1380 print STDERR "$new_syms New symbols added\n";
1381 } else {
1382 print STDERR "No New symbols Added\n";
1383 }
1384}
1385
1386sub check_existing
1387{
1388 (*nums, my @symbols)=@_;
1389 my %existing; my @remaining;
1390 @remaining=();
1391 foreach $sym (@symbols) {
1392 (my $s, my $i) = $sym =~ /^(.*?)\\(.*)$/;
1393 $existing{$s}=1;
1394 }
1395 foreach $sym (keys %nums) {
1396 if (!exists $existing{$sym}) {
1397 push @remaining, $sym;
1398 }
1399 }
1400 if(@remaining) {
1401 print STDERR "The following symbols do not seem to exist:\n";
1402 foreach $sym (@remaining) {
1403 print STDERR "\t",$sym,"\n";
1404 }
1405 }
1406}
1407
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
index 53e14ab4df..9678514604 100644
--- a/src/lib/libcrypto/util/mkerr.pl
+++ b/src/lib/libcrypto/util/mkerr.pl
@@ -44,7 +44,8 @@ while (@ARGV) {
44} 44}
45 45
46if($recurse) { 46if($recurse) {
47 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>); 47 @source = (<crypto/*.c>, <crypto/*/*.c>, <ssl/*.c>, <fips-1.0/*.c>,
48 <fips-1.0/*/*.c>);
48} else { 49} else {
49 @source = @ARGV; 50 @source = @ARGV;
50} 51}
@@ -65,8 +66,6 @@ while(<IN>)
65 $csrc{$1} = $3; 66 $csrc{$1} = $3;
66 $fmax{$1} = 99; 67 $fmax{$1} = 99;
67 $rmax{$1} = 99; 68 $rmax{$1} = 99;
68 $fassigned{$1} = ":";
69 $rassigned{$1} = ":";
70 $fnew{$1} = 0; 69 $fnew{$1} = 0;
71 $rnew{$1} = 0; 70 $rnew{$1} = 0;
72 } 71 }
@@ -105,24 +104,15 @@ while (($hdr, $lib) = each %libinc)
105 next; 104 next;
106 } 105 }
107 106
108 if(/\/\*/) { 107 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
109 if (not /\*\//) { # multiline comment...
110 $line = $_; # ... just accumulate
111 next;
112 } else {
113 s/\/\*.*?\*\///gs; # wipe it
114 }
115 }
116
117 if ($cpp) { 108 if ($cpp) {
118 $cpp++ if /^#\s*if/; 109 $cpp = 0 if /^#.*endif/;
119 $cpp-- if /^#\s*endif/;
120 next; 110 next;
121 } 111 }
122 $cpp = 1 if /^#.*ifdef.*cplusplus/; # skip "C" declaration
123 112
124 next if (/^\#/); # skip preprocessor directives 113 next if (/^\#/); # skip preprocessor directives
125 114
115 s/\/\*.*?\*\///gs; # ignore comments
126 s/{[^{}]*}//gs; # ignore {} blocks 116 s/{[^{}]*}//gs; # ignore {} blocks
127 117
128 if (/\{|\/\*/) { # Add a } so editor works... 118 if (/\{|\/\*/) { # Add a } so editor works...
@@ -135,37 +125,31 @@ while (($hdr, $lib) = each %libinc)
135 125
136 print STDERR " \r" if $debug; 126 print STDERR " \r" if $debug;
137 $defnr = 0; 127 $defnr = 0;
138 # Delete any DECLARE_ macros
139 $def =~ s/DECLARE_\w+\([\w,\s]+\)//gs;
140 foreach (split /;/, $def) { 128 foreach (split /;/, $def) {
141 $defnr++; 129 $defnr++;
142 print STDERR "def: $defnr\r" if $debug; 130 print STDERR "def: $defnr\r" if $debug;
143 131
144 # The goal is to collect function names from function declarations.
145
146 s/^[\n\s]*//g; 132 s/^[\n\s]*//g;
147 s/[\n\s]*$//g; 133 s/[\n\s]*$//g;
148 134 next if(/typedef\W/);
149 # Skip over recognized non-function declarations 135 if (/\(\*(\w*)\([^\)]+/) {
150 next if(/typedef\W/ or /DECLARE_STACK_OF/ or /TYPEDEF_.*_OF/); 136 my $name = $1;
151 137 $name =~ tr/[a-z]/[A-Z]/;
152 # Remove STACK_OF(foo) 138 $ftrans{$name} = $1;
153 s/STACK_OF\(\w+\)/void/; 139 } elsif (/\w+\W+(\w+)\W*\(\s*\)(\s*__attribute__\(.*\)\s*)?$/s){
154 140 # K&R C
155 # Reduce argument lists to empty () 141 next ;
156 # fold round brackets recursively: (t(*v)(t),t) -> (t{}{},t) -> {} 142 } elsif (/\w+\W+\w+\W*\(.*\)(\s*__attribute__\(.*\)\s*)?$/s) {
157 while(/\(.*\)/s) { 143 while (not /\(\)(\s*__attribute__\(.*\)\s*)?$/s) {
158 s/\([^\(\)]+\)/\{\}/gs; 144 s/[^\(\)]*\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
159 s/\(\s*\*\s*(\w+)\s*\{\}\s*\)/$1/gs; #(*f{}) -> f 145 s/\([^\(\)]*\)\)(\s*__attribute__\(.*\)\s*)?$/\)/s;
160 } 146 }
161 # pretend as we didn't use curly braces: {} -> () 147 s/\(void\)//;
162 s/\{\}/\(\)/gs; 148 /(\w+(\{[0-9]+\})?)\W*\(\)/s;
163 149 my $name = $1;
164 if (/(\w+)\s*\(\).*/s) { # first token prior [first] () is
165 my $name = $1; # a function name!
166 $name =~ tr/[a-z]/[A-Z]/; 150 $name =~ tr/[a-z]/[A-Z]/;
167 $ftrans{$name} = $1; 151 $ftrans{$name} = $1;
168 } elsif (/[\(\)]/ and not (/=/)) { 152 } elsif (/\(/ and not (/=/ or /DECLARE_STACK/)) {
169 print STDERR "Header $hdr: cannot parse: $_;\n"; 153 print STDERR "Header $hdr: cannot parse: $_;\n";
170 } 154 }
171 } 155 }
@@ -178,7 +162,7 @@ while (($hdr, $lib) = each %libinc)
178 # maximum code used. 162 # maximum code used.
179 163
180 if ($gotfile) { 164 if ($gotfile) {
181 while(<IN>) { 165 while(<IN>) {
182 if(/^\#define\s+(\S+)\s+(\S+)/) { 166 if(/^\#define\s+(\S+)\s+(\S+)/) {
183 $name = $1; 167 $name = $1;
184 $code = $2; 168 $code = $2;
@@ -189,49 +173,18 @@ while (($hdr, $lib) = each %libinc)
189 } 173 }
190 if($1 eq "R") { 174 if($1 eq "R") {
191 $rcodes{$name} = $code; 175 $rcodes{$name} = $code;
192 if ($rassigned{$lib} =~ /:$code:/) {
193 print STDERR "!! ERROR: $lib reason code $code assigned twice\n";
194 }
195 $rassigned{$lib} .= "$code:";
196 if(!(exists $rextra{$name}) && 176 if(!(exists $rextra{$name}) &&
197 ($code > $rmax{$lib}) ) { 177 ($code > $rmax{$lib}) ) {
198 $rmax{$lib} = $code; 178 $rmax{$lib} = $code;
199 } 179 }
200 } else { 180 } else {
201 if ($fassigned{$lib} =~ /:$code:/) {
202 print STDERR "!! ERROR: $lib function code $code assigned twice\n";
203 }
204 $fassigned{$lib} .= "$code:";
205 if($code > $fmax{$lib}) { 181 if($code > $fmax{$lib}) {
206 $fmax{$lib} = $code; 182 $fmax{$lib} = $code;
207 } 183 }
208 $fcodes{$name} = $code; 184 $fcodes{$name} = $code;
209 } 185 }
210 } 186 }
211 } 187 }
212 }
213
214 if ($debug) {
215 if (defined($fmax{$lib})) {
216 print STDERR "Max function code fmax" . "{" . "$lib" . "} = $fmax{$lib}\n";
217 $fassigned{$lib} =~ m/^:(.*):$/;
218 @fassigned = sort {$a <=> $b} split(":", $1);
219 print STDERR " @fassigned\n";
220 }
221 if (defined($rmax{$lib})) {
222 print STDERR "Max reason code rmax" . "{" . "$lib" . "} = $rmax{$lib}\n";
223 $rassigned{$lib} =~ m/^:(.*):$/;
224 @rassigned = sort {$a <=> $b} split(":", $1);
225 print STDERR " @rassigned\n";
226 }
227 }
228
229 if ($lib eq "SSL") {
230 if ($rmax{$lib} >= 1000) {
231 print STDERR "!! ERROR: SSL error codes 1000+ are reserved for alerts.\n";
232 print STDERR "!! Any new alerts must be added to $config.\n";
233 print STDERR "\n";
234 }
235 } 188 }
236 close IN; 189 close IN;
237} 190}
@@ -248,10 +201,11 @@ while (($hdr, $lib) = each %libinc)
248# so all those unreferenced can be printed out. 201# so all those unreferenced can be printed out.
249 202
250 203
204print STDERR "Files loaded: " if $debug;
251foreach $file (@source) { 205foreach $file (@source) {
252 # Don't parse the error source file. 206 # Don't parse the error source file.
253 next if exists $cskip{$file}; 207 next if exists $cskip{$file};
254 print STDERR "File loaded: ".$file."\r" if $debug; 208 print STDERR $file if $debug;
255 open(IN, "<$file") || die "Can't open source file $file\n"; 209 open(IN, "<$file") || die "Can't open source file $file\n";
256 while(<IN>) { 210 while(<IN>) {
257 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) { 211 if(/(([A-Z0-9]+)_F_([A-Z0-9_]+))/) {
@@ -275,7 +229,7 @@ foreach $file (@source) {
275 } 229 }
276 close IN; 230 close IN;
277} 231}
278print STDERR " \n" if $debug; 232print STDERR "\n" if $debug;
279 233
280# Now process each library in turn. 234# Now process each library in turn.
281 235
@@ -312,7 +266,7 @@ foreach $lib (keys %csrc)
312 } else { 266 } else {
313 push @out, 267 push @out,
314"/* ====================================================================\n", 268"/* ====================================================================\n",
315" * Copyright (c) 2001-2008 The OpenSSL Project. All rights reserved.\n", 269" * Copyright (c) 2001-2005 The OpenSSL Project. All rights reserved.\n",
316" *\n", 270" *\n",
317" * Redistribution and use in source and binary forms, with or without\n", 271" * Redistribution and use in source and binary forms, with or without\n",
318" * modification, are permitted provided that the following conditions\n", 272" * modification, are permitted provided that the following conditions\n",
@@ -402,16 +356,7 @@ EOF
402 foreach $i (@function) { 356 foreach $i (@function) {
403 $z=6-int(length($i)/8); 357 $z=6-int(length($i)/8);
404 if($fcodes{$i} eq "X") { 358 if($fcodes{$i} eq "X") {
405 $fassigned{$lib} =~ m/^:([^:]*):/; 359 $fcodes{$i} = ++$fmax{$lib};
406 $findcode = $1;
407 if (!defined($findcode)) {
408 $findcode = $fmax{$lib};
409 }
410 while ($fassigned{$lib} =~ m/:$findcode:/) {
411 $findcode++;
412 }
413 $fcodes{$i} = $findcode;
414 $fassigned{$lib} .= "$findcode:";
415 print STDERR "New Function code $i\n" if $debug; 360 print STDERR "New Function code $i\n" if $debug;
416 } 361 }
417 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z; 362 printf OUT "#define $i%s $fcodes{$i}\n","\t" x $z;
@@ -422,16 +367,7 @@ EOF
422 foreach $i (@reasons) { 367 foreach $i (@reasons) {
423 $z=6-int(length($i)/8); 368 $z=6-int(length($i)/8);
424 if($rcodes{$i} eq "X") { 369 if($rcodes{$i} eq "X") {
425 $rassigned{$lib} =~ m/^:([^:]*):/; 370 $rcodes{$i} = ++$rmax{$lib};
426 $findcode = $1;
427 if (!defined($findcode)) {
428 $findcode = $rmax{$lib};
429 }
430 while ($rassigned{$lib} =~ m/:$findcode:/) {
431 $findcode++;
432 }
433 $rcodes{$i} = $findcode;
434 $rassigned{$lib} .= "$findcode:";
435 print STDERR "New Reason code $i\n" if $debug; 371 print STDERR "New Reason code $i\n" if $debug;
436 } 372 }
437 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z; 373 printf OUT "#define $i%s $rcodes{$i}\n","\t" x $z;
@@ -486,7 +422,7 @@ EOF
486 print OUT <<"EOF"; 422 print OUT <<"EOF";
487/* $cfile */ 423/* $cfile */
488/* ==================================================================== 424/* ====================================================================
489 * Copyright (c) 1999-2008 The OpenSSL Project. All rights reserved. 425 * Copyright (c) 1999-2005 The OpenSSL Project. All rights reserved.
490 * 426 *
491 * Redistribution and use in source and binary forms, with or without 427 * Redistribution and use in source and binary forms, with or without
492 * modification, are permitted provided that the following conditions 428 * modification, are permitted provided that the following conditions
@@ -600,14 +536,17 @@ if($static) {
600 536
601${staticloader}void ERR_load_${lib}_strings(void) 537${staticloader}void ERR_load_${lib}_strings(void)
602 { 538 {
603#ifndef OPENSSL_NO_ERR 539 static int init=1;
604 540
605 if (ERR_func_error_string(${lib}_str_functs[0].error) == NULL) 541 if (init)
606 { 542 {
543 init=0;
544#ifndef OPENSSL_NO_ERR
607 ERR_load_strings($load_errcode,${lib}_str_functs); 545 ERR_load_strings($load_errcode,${lib}_str_functs);
608 ERR_load_strings($load_errcode,${lib}_str_reasons); 546 ERR_load_strings($load_errcode,${lib}_str_reasons);
609 }
610#endif 547#endif
548
549 }
611 } 550 }
612EOF 551EOF
613} else { 552} else {
diff --git a/src/lib/libcrypto/util/mkfiles.pl b/src/lib/libcrypto/util/mkfiles.pl
new file mode 100644
index 0000000000..bc78510f56
--- /dev/null
+++ b/src/lib/libcrypto/util/mkfiles.pl
@@ -0,0 +1,126 @@
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/md4",
14"crypto/md5",
15"crypto/sha",
16"crypto/mdc2",
17"crypto/hmac",
18"crypto/ripemd",
19"crypto/des",
20"crypto/rc2",
21"crypto/rc4",
22"crypto/rc5",
23"crypto/idea",
24"crypto/bf",
25"crypto/cast",
26"crypto/aes",
27"crypto/bn",
28"crypto/rsa",
29"crypto/dsa",
30"crypto/dso",
31"crypto/dh",
32"crypto/ec",
33"crypto/buffer",
34"crypto/bio",
35"crypto/stack",
36"crypto/lhash",
37"crypto/rand",
38"crypto/err",
39"crypto/objects",
40"crypto/evp",
41"crypto/asn1",
42"crypto/pem",
43"crypto/x509",
44"crypto/x509v3",
45"crypto/conf",
46"crypto/txt_db",
47"crypto/pkcs7",
48"crypto/pkcs12",
49"crypto/comp",
50"crypto/engine",
51"crypto/ocsp",
52"crypto/ui",
53"crypto/krb5",
54"fips-1.0",
55"fips-1.0/aes",
56"fips-1.0/des",
57"fips-1.0/dsa",
58"fips-1.0/dh",
59"fips-1.0/hmac",
60"fips-1.0/rand",
61"fips-1.0/rsa",
62"fips-1.0/sha",
63"ssl",
64"apps",
65"test",
66"tools"
67);
68
69foreach (@dirs) {
70 &files_dir ($_, "Makefile");
71}
72
73exit(0);
74
75sub files_dir
76{
77my ($dir, $makefile) = @_;
78
79my %sym;
80
81open (IN, "$dir/$makefile") || die "Can't open $dir/$makefile";
82
83my $s="";
84
85while (<IN>)
86 {
87 chop;
88 s/#.*//;
89 if (/^(\S+)\s*=\s*(.*)$/)
90 {
91 $o="";
92 ($s,$b)=($1,$2);
93 for (;;)
94 {
95 if ($b =~ /\\$/)
96 {
97 chop($b);
98 $o.=$b." ";
99 $b=<IN>;
100 chop($b);
101 }
102 else
103 {
104 $o.=$b." ";
105 last;
106 }
107 }
108 $o =~ s/^\s+//;
109 $o =~ s/\s+$//;
110 $o =~ s/\s+/ /g;
111
112 $o =~ s/\$[({]([^)}]+)[)}]/$sym{$1}/g;
113 $sym{$s}=$o;
114 }
115 }
116
117print "RELATIVE_DIRECTORY=$dir\n";
118
119foreach (sort keys %sym)
120 {
121 print "$_=$sym{$_}\n";
122 }
123print "RELATIVE_DIRECTORY=\n";
124
125close (IN);
126}
diff --git a/src/lib/libcrypto/util/mklink.pl b/src/lib/libcrypto/util/mklink.pl
new file mode 100644
index 0000000000..182732d959
--- /dev/null
+++ b/src/lib/libcrypto/util/mklink.pl
@@ -0,0 +1,73 @@
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#
18
19use Cwd;
20
21my $from = shift;
22my @files = @ARGV;
23
24my @from_path = split(/[\\\/]/, $from);
25my $pwd = getcwd();
26chomp($pwd);
27my @pwd_path = split(/[\\\/]/, $pwd);
28
29my @to_path = ();
30
31my $dirname;
32foreach $dirname (@from_path) {
33
34 # In this loop, @to_path always is a relative path from
35 # @pwd_path (interpreted is an absolute path) to the original pwd.
36
37 # At the end, @from_path (as a relative path from the original pwd)
38 # designates the same directory as the absolute path @pwd_path,
39 # which means that @to_path then is a path from there to the original pwd.
40
41 next if ($dirname eq "" || $dirname eq ".");
42
43 if ($dirname eq "..") {
44 @to_path = (pop(@pwd_path), @to_path);
45 } else {
46 @to_path = ("..", @to_path);
47 push(@pwd_path, $dirname);
48 }
49}
50
51my $to = join('/', @to_path);
52
53my $file;
54$symlink_exists=eval {symlink("",""); 1};
55foreach $file (@files) {
56 my $err = "";
57 if ($symlink_exists) {
58 unlink "$from/$file";
59 symlink("$to/$file", "$from/$file") or $err = " [$!]";
60 } else {
61 unlink "$from/$file";
62 open (OLD, "<$file") or die "Can't open $file: $!";
63 open (NEW, ">$from/$file") or die "Can't open $from/$file: $!";
64 binmode(OLD);
65 binmode(NEW);
66 while (<OLD>) {
67 print NEW $_;
68 }
69 close (OLD) or die "Can't close $file: $!";
70 close (NEW) or die "Can't close $from/$file: $!";
71 }
72 print $file . " => $from/$file$err\n";
73}
diff --git a/src/lib/libcrypto/util/mkstack.pl b/src/lib/libcrypto/util/mkstack.pl
index 2a968f395f..0ca9eb6a76 100644
--- a/src/lib/libcrypto/util/mkstack.pl
+++ b/src/lib/libcrypto/util/mkstack.pl
@@ -75,7 +75,6 @@ while(<IN>) {
75#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val)) 75#define sk_${type_thing}_push(st, val) SKM_sk_push($type_thing, (st), (val))
76#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val)) 76#define sk_${type_thing}_unshift(st, val) SKM_sk_unshift($type_thing, (st), (val))
77#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val)) 77#define sk_${type_thing}_find(st, val) SKM_sk_find($type_thing, (st), (val))
78#define sk_${type_thing}_find_ex(st, val) SKM_sk_find_ex($type_thing, (st), (val))
79#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i)) 78#define sk_${type_thing}_delete(st, i) SKM_sk_delete($type_thing, (st), (i))
80#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr)) 79#define sk_${type_thing}_delete_ptr(st, ptr) SKM_sk_delete_ptr($type_thing, (st), (ptr))
81#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i)) 80#define sk_${type_thing}_insert(st, val, i) SKM_sk_insert($type_thing, (st), (val), (i))
diff --git a/src/lib/libcrypto/util/opensslwrap.sh b/src/lib/libcrypto/util/opensslwrap.sh
new file mode 100755
index 0000000000..b27cbb897f
--- /dev/null
+++ b/src/lib/libcrypto/util/opensslwrap.sh
@@ -0,0 +1,26 @@
1#!/bin/sh
2
3HERE="`echo $0 | sed -e 's|[^/]*$||'`"
4OPENSSL="${HERE}../apps/openssl"
5
6if [ -d "${HERE}../engines" -a "x$OPENSSL_ENGINES" = "x" ]; then
7 OPENSSL_ENGINES="${HERE}../engines"; export OPENSSL_ENGINES
8fi
9
10if [ -x "${OPENSSL}.exe" ]; then
11 # The original reason for this script existence is to work around
12 # certain caveats in run-time linker behaviour. On Windows platforms
13 # adjusting $PATH used to be sufficient, but with introduction of
14 # SafeDllSearchMode in XP/2003 the only way to get it right in
15 # *all* possible situations is to copy newly built .DLLs to apps/
16 # and test/, which is now done elsewhere... The $PATH is adjusted
17 # for backward compatibility (and nostagical reasons:-).
18 if [ "$OSTYPE" != msdosdjgpp ]; then
19 PATH="${HERE}..:$PATH"; export PATH
20 fi
21 exec "${OPENSSL}.exe" "$@"
22elif [ -x "${OPENSSL}" -a -x "${HERE}shlib_wrap.sh" ]; then
23 exec "${HERE}shlib_wrap.sh" "${OPENSSL}" "$@"
24else
25 exec "${OPENSSL}" "$@" # hope for the best...
26fi
diff --git a/src/lib/libcrypto/util/perlpath.pl b/src/lib/libcrypto/util/perlpath.pl
new file mode 100644
index 0000000000..a1f236bd98
--- /dev/null
+++ b/src/lib/libcrypto/util/perlpath.pl
@@ -0,0 +1,35 @@
1#!/usr/local/bin/perl
2#
3# modify the '#!/usr/local/bin/perl'
4# line in all scripts that rely on perl.
5#
6
7require "find.pl";
8
9$#ARGV == 0 || print STDERR "usage: perlpath newpath (eg /usr/bin)\n";
10&find(".");
11
12sub wanted
13 {
14 return unless /\.pl$/ || /^[Cc]onfigur/;
15
16 open(IN,"<$_") || die "unable to open $dir/$_:$!\n";
17 @a=<IN>;
18 close(IN);
19
20 if (-d $ARGV[0]) {
21 $a[0]="#!$ARGV[0]/perl\n";
22 }
23 else {
24 $a[0]="#!$ARGV[0]\n";
25 }
26
27 # Playing it safe...
28 $new="$_.new";
29 open(OUT,">$new") || die "unable to open $dir/$new:$!\n";
30 print OUT @a;
31 close(OUT);
32
33 rename($new,$_) || die "unable to rename $dir/$new:$!\n";
34 chmod(0755,$_) || die "unable to chmod $dir/$new:$!\n";
35 }
diff --git a/src/lib/libcrypto/util/pl/BC-16.pl b/src/lib/libcrypto/util/pl/BC-16.pl
new file mode 100644
index 0000000000..8030653daa
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/BC-16.pl
@@ -0,0 +1,151 @@
1#!/usr/local/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$o='\\';
6$cp='copy';
7$rm='del';
8
9# C compiler stuff
10$cc='bcc';
11
12if ($debug)
13 { $op="-v "; }
14else { $op="-O "; }
15
16$cflags="-d -ml $op -DL_ENDIAN";
17# I add the stack opt
18$base_lflags="/c /C";
19$lflags="$base_lflags";
20
21if ($win16)
22 {
23 $shlib=1;
24 $cflags.=" -DOPENSSL_SYSNAME_WIN16";
25 $app_cflag="-W";
26 $lib_cflag="-WD";
27 $lflags.="/Twe";
28 }
29else
30 {
31 $cflags.=" -DOENSSL_SYSNAME_MSDOS";
32 $lflags.=" /Tde";
33 }
34
35if ($shlib)
36 {
37 $mlflags=" /Twd $base_lflags"; # stack if defined in .def file
38 $libs="libw ldllcew";
39 $no_asm=1;
40 }
41else
42 { $mlflags=''; }
43
44$obj='.obj';
45$ofile="-o";
46
47# EXE linking stuff
48$link="tlink";
49$efile="";
50$exep='.exe';
51$ex_libs="CL";
52$ex_libs.=$no_sock?"":" winsock.lib";
53
54$app_ex_obj="C0L.obj ";
55$shlib_ex_obj="" if ($shlib);
56
57# static library stuff
58$mklib='tlib';
59$ranlib='echo no ranlib';
60$plib="";
61$libp=".lib";
62$shlibp=($shlib)?".dll":".lib";
63$lfile='';
64
65$asm='bcc -c -B -Tml';
66$afile='/o';
67if ($no_asm || $fips)
68 {
69 $bn_asm_obj='';
70 $bn_asm_src='';
71 }
72elsif ($asmbits == 32)
73 {
74 $bn_asm_obj='crypto\bn\asm\x86w32.obj';
75 $bn_asm_src='crypto\bn\asm\x86w32.asm';
76 }
77else
78 {
79 $bn_asm_obj='crypto\bn\asm\x86w16.obj';
80 $bn_asm_src='crypto\bn\asm\x86w16.asm';
81 }
82
83sub do_lib_rule
84 {
85 local($target,$name,$shlib)=@_;
86 local($ret,$Name);
87
88 $taget =~ s/\//$o/g if $o ne '/';
89 ($Name=$name) =~ tr/a-z/A-Z/;
90
91 $ret.="$target: \$(${Name}OBJ)\n";
92 $ret.="\t\$(RM) \$(O_$Name)\n";
93
94 # Due to a pathetic line length limit, I unwrap the args.
95 local($lib_names)="";
96 local($dll_names)="";
97 foreach $_ (sort split(/\s+/,$Vars{"${Name}OBJ"}))
98 {
99 $lib_names.=" +$_ &\n";
100 $dll_names.=" $_\n";
101 }
102
103 if (!$shlib)
104 {
105 $ret.="\t\$(MKLIB) $target & <<|\n$lib_names\n,\n|\n";
106 }
107 else
108 {
109 local($ex)=($Name eq "SSL")?' $(L_CRYPTO) winsock':"";
110 $ret.="\t\$(LINK) \$(MLFLAGS) @&&|\n";
111 $ret.=$dll_names;
112 $ret.="\n $target\n\n $ex $libs\nms$o${name}16.def;\n|\n";
113 ($out_lib=$target) =~ s/O_/L_/;
114 $ret.="\timplib /nowep $out_lib $target\n\n";
115 }
116 $ret.="\n";
117 return($ret);
118 }
119
120sub do_link_rule
121 {
122 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
123 local($ret,$f,$_,@f);
124
125 $file =~ s/\//$o/g if $o ne '/';
126 $n=&bname($target);
127 $ret.="$target: $files $dep_libs\n";
128 $ret.=" \$(LINK) @&&|";
129
130 # Due to a pathetic line length limit, I have to unwrap the args.
131 $ret.=" \$(LFLAGS) ";
132 if ($files =~ /\(([^)]*)\)$/)
133 {
134 $ret.=" \$(APP_EX_OBJ)";
135 foreach $_ (sort split(/\s+/,$Vars{$1}))
136 { $ret.="\n $r $_ +"; }
137 chop($ret);
138 $ret.="\n";
139 }
140 else
141 { $ret.="\n $r \$(APP_EX_OBJ) $files\n"; }
142 $ret.=" $target\n\n $libs\n\n|\n";
143 if (defined $sha1file)
144 {
145 $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
146 }
147 $ret.="\n";
148 return($ret);
149 }
150
1511;
diff --git a/src/lib/libcrypto/util/pl/BC-32.pl b/src/lib/libcrypto/util/pl/BC-32.pl
new file mode 100644
index 0000000000..28869c868d
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/BC-32.pl
@@ -0,0 +1,144 @@
1#!/usr/local/bin/perl
2# Borland C++ builder 3 and 4 -- Janez Jere <jj@void.si>
3#
4
5$ssl= "ssleay32";
6$crypto="libeay32";
7
8$o='\\';
9$cp='copy';
10$rm='del';
11
12# C compiler stuff
13$cc='bcc32';
14$lflags="-ap -Tpe -x -Gn ";
15$mlflags='';
16
17$out_def="out32";
18$tmp_def="tmp32";
19$inc_def="inc32";
20#enable max error messages, disable most common warnings
21$cflags="-DWIN32_LEAN_AND_MEAN -q -w-ccc -w-rch -w-pia -w-aus -w-par -w-inl -c -tWC -tWM -DOPENSSL_SYSNAME_WIN32 -DL_ENDIAN -DDSO_WIN32 -D_stricmp=stricmp -D_strnicmp=strnicmp ";
22if ($debug)
23{
24 $cflags.="-Od -y -v -vi- -D_DEBUG";
25 $mlflags.=' ';
26}
27else
28{
29 $cflags.="-O2 -ff -fp";
30}
31
32$obj='.obj';
33$ofile="-o";
34
35# EXE linking stuff
36$link="ilink32";
37$efile="";
38$exep='.exe';
39if ($no_sock)
40 { $ex_libs=""; }
41else { $ex_libs="cw32mt.lib import32.lib"; }
42
43# static library stuff
44$mklib='tlib /P64';
45$ranlib='';
46$plib="";
47$libp=".lib";
48$shlibp=($shlib)?".dll":".lib";
49$lfile='';
50
51$shlib_ex_obj="";
52$app_ex_obj="c0x32.obj";
53
54$asm='nasmw -f obj -d__omf__';
55$asm.=" /Zi" if $debug;
56$afile='-o';
57
58$bn_mulw_obj='';
59$bn_mulw_src='';
60$des_enc_obj='';
61$des_enc_src='';
62$bf_enc_obj='';
63$bf_enc_src='';
64
65if (!$no_asm && !$fips)
66 {
67 $bn_mulw_obj='crypto\bn\asm\bn_win32.obj';
68 $bn_mulw_src='crypto\bn\asm\bn_win32.asm';
69 $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj';
70 $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm';
71 $bf_enc_obj='crypto\bf\asm\b_win32.obj';
72 $bf_enc_src='crypto\bf\asm\b_win32.asm';
73 $cast_enc_obj='crypto\cast\asm\c_win32.obj';
74 $cast_enc_src='crypto\cast\asm\c_win32.asm';
75 $rc4_enc_obj='crypto\rc4\asm\r4_win32.obj';
76 $rc4_enc_src='crypto\rc4\asm\r4_win32.asm';
77 $rc5_enc_obj='crypto\rc5\asm\r5_win32.obj';
78 $rc5_enc_src='crypto\rc5\asm\r5_win32.asm';
79 $md5_asm_obj='crypto\md5\asm\m5_win32.obj';
80 $md5_asm_src='crypto\md5\asm\m5_win32.asm';
81 $sha1_asm_obj='crypto\sha\asm\s1_win32.obj';
82 $sha1_asm_src='crypto\sha\asm\s1_win32.asm';
83 $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj';
84 $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm';
85 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
86 }
87
88if ($shlib)
89 {
90 $mlflags.=" $lflags /dll";
91# $cflags =~ s| /MD| /MT|;
92 $lib_cflag=" /GD -D_WINDLL -D_DLL";
93 $out_def="out32dll";
94 $tmp_def="tmp32dll";
95 }
96
97sub do_lib_rule
98 {
99 local($objs,$target,$name,$shlib)=@_;
100 local($ret,$Name);
101
102 $taget =~ s/\//$o/g if $o ne '/';
103 ($Name=$name) =~ tr/a-z/A-Z/;
104
105# $target="\$(LIB_D)$o$target";
106 $ret.="$target: $objs\n";
107 if (!$shlib)
108 {
109 $ret.=<<___;
110 -\$(RM) $lfile$target
111 \$(MKLIB) $lfile$target \@&&!
112+\$(**: = &^
113+)
114!
115___
116 }
117 else
118 {
119 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
120 $ex.=' wsock32.lib gdi32.lib';
121 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
122 }
123 $ret.="\n";
124 return($ret);
125 }
126
127sub do_link_rule
128 {
129 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
130 local($ret,$_);
131
132 $file =~ s/\//$o/g if $o ne '/';
133 $n=&bname($targer);
134 $ret.="$target: $files $dep_libs\n";
135 $ret.="\t\$(LINK) \$(LFLAGS) $files \$(APP_EX_OBJ), $target,, $libs\n";
136 if (defined $sha1file)
137 {
138 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
139 }
140 $ret.="\n";
141 return($ret);
142 }
143
1441;
diff --git a/src/lib/libcrypto/util/pl/Mingw32.pl b/src/lib/libcrypto/util/pl/Mingw32.pl
new file mode 100644
index 0000000000..b9bb24d21d
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/Mingw32.pl
@@ -0,0 +1,109 @@
1#!/usr/local/bin/perl
2#
3# Mingw32.pl -- Mingw
4#
5
6$o='/';
7$cp='cp';
8$rm='rm -f';
9$mkdir='gmkdir';
10
11$o='\\';
12$cp='copy';
13$rm='del';
14$mkdir='mkdir';
15
16# C compiler stuff
17
18$cc='gcc';
19if ($debug)
20 { $cflags="-DL_ENDIAN -DDSO_WIN32 -g2 -ggdb"; }
21else
22 { $cflags="-DL_ENDIAN -DDSO_WIN32 -fomit-frame-pointer -O3 -mcpu=i486 -Wall"; }
23
24if ($gaswin and !$no_asm and !$fips)
25 {
26 $bn_asm_obj='$(OBJ_D)\bn-win32.o';
27 $bn_asm_src='crypto/bn/asm/bn-win32.s';
28 $bnco_asm_obj='$(OBJ_D)\co-win32.o';
29 $bnco_asm_src='crypto/bn/asm/co-win32.s';
30 $des_enc_obj='$(OBJ_D)\d-win32.o $(OBJ_D)\y-win32.o';
31 $des_enc_src='crypto/des/asm/d-win32.s crypto/des/asm/y-win32.s';
32 $bf_enc_obj='$(OBJ_D)\b-win32.o';
33 $bf_enc_src='crypto/bf/asm/b-win32.s';
34# $cast_enc_obj='$(OBJ_D)\c-win32.o';
35# $cast_enc_src='crypto/cast/asm/c-win32.s';
36 $rc4_enc_obj='$(OBJ_D)\r4-win32.o';
37 $rc4_enc_src='crypto/rc4/asm/r4-win32.s';
38 $rc5_enc_obj='$(OBJ_D)\r5-win32.o';
39 $rc5_enc_src='crypto/rc5/asm/r5-win32.s';
40 $md5_asm_obj='$(OBJ_D)\m5-win32.o';
41 $md5_asm_src='crypto/md5/asm/m5-win32.s';
42 $rmd160_asm_obj='$(OBJ_D)\rm-win32.o';
43 $rmd160_asm_src='crypto/ripemd/asm/rm-win32.s';
44 $sha1_asm_obj='$(OBJ_D)\s1-win32.o';
45 $sha1_asm_src='crypto/sha/asm/s1-win32.s';
46 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM";
47 }
48
49
50$obj='.o';
51$ofile='-o ';
52
53# EXE linking stuff
54$link='${CC}';
55$lflags='${CFLAGS}';
56$efile='-o ';
57$exep='';
58$ex_libs="-lwsock32 -lgdi32";
59
60# static library stuff
61$mklib='ar r';
62$mlflags='';
63$ranlib='ranlib';
64$plib='lib';
65$libp=".a";
66$shlibp=".a";
67$lfile='';
68
69$asm='as';
70$afile='-o ';
71#$bn_asm_obj="";
72#$bn_asm_src="";
73#$des_enc_obj="";
74#$des_enc_src="";
75#$bf_enc_obj="";
76#$bf_enc_src="";
77
78sub do_lib_rule
79 {
80 local($obj,$target,$name,$shlib)=@_;
81 local($ret,$_,$Name);
82
83 $target =~ s/\//$o/g if $o ne '/';
84 $target="$target";
85 ($Name=$name) =~ tr/a-z/A-Z/;
86
87 $ret.="$target: \$(${Name}OBJ)\n";
88 $ret.="\tif exist $target \$(RM) $target\n";
89 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
90 $ret.="\t\$(RANLIB) $target\n\n";
91 }
92
93sub do_link_rule
94 {
95 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
96 local($ret,$_);
97
98 $file =~ s/\//$o/g if $o ne '/';
99 $n=&bname($target);
100 $ret.="$target: $files $dep_libs\n";
101 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n";
102 if (defined $sha1file)
103 {
104 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
105 }
106 $ret.="\n";
107 return($ret);
108 }
1091;
diff --git a/src/lib/libcrypto/util/pl/OS2-EMX.pl b/src/lib/libcrypto/util/pl/OS2-EMX.pl
new file mode 100644
index 0000000000..8dbeaa7a08
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/OS2-EMX.pl
@@ -0,0 +1,125 @@
1#!/usr/local/bin/perl
2#
3# OS2-EMX.pl - for EMX GCC on OS/2
4#
5
6$o='/';
7$cp='cp';
8$rm='rm -f';
9
10$preamble = "SHELL=sh\n";
11
12# C compiler stuff
13
14$cc='gcc';
15$cflags="-DL_ENDIAN -O3 -fomit-frame-pointer -m486 -Zmtd -Wall ";
16$cflags.="-Zomf " if $shlib;
17$shl_cflag="-Zdll";
18
19if ($debug) {
20 $cflags.="-g ";
21}
22
23$obj=$shlib ? '.obj' : '.o';
24$ofile='-o ';
25
26# EXE linking stuff
27$link='${CC}';
28$lflags='${CFLAGS} -Zbsd-signals -s';
29$efile='-o ';
30$exep='.exe';
31$ex_libs="-lsocket";
32
33# static library stuff
34$mklib='ar r';
35$mlflags='';
36$ranlib="ar s";
37$plib='';
38$libp=$shlib ? ".lib" : ".a";
39$shlibp=$shlib ? ".dll" : ".a";
40$lfile='';
41
42$asm=$shlib ? 'as -Zomf' : 'as';
43$afile='-o ';
44$bn_asm_obj="";
45$bn_asm_src="";
46$des_enc_obj="";
47$des_enc_src="";
48$bf_enc_obj="";
49$bf_enc_src="";
50
51if (!$no_asm && !$fips)
52 {
53 $bn_asm_obj="crypto/bn/asm/bn-os2$obj crypto/bn/asm/co-os2$obj";
54 $bn_asm_src="crypto/bn/asm/bn-os2.asm crypto/bn/asm/co-os2.asm";
55 $des_enc_obj="crypto/des/asm/d-os2$obj crypto/des/asm/y-os2$obj";
56 $des_enc_src="crypto/des/asm/d-os2.asm crypto/des/asm/y-os2.asm";
57 $bf_enc_obj="crypto/bf/asm/b-os2$obj";
58 $bf_enc_src="crypto/bf/asm/b-os2.asm";
59 $cast_enc_obj="crypto/cast/asm/c-os2$obj";
60 $cast_enc_src="crypto/cast/asm/c-os2.asm";
61 $rc4_enc_obj="crypto/rc4/asm/r4-os2$obj";
62 $rc4_enc_src="crypto/rc4/asm/r4-os2.asm";
63 $rc5_enc_obj="crypto/rc5/asm/r5-os2$obj";
64 $rc5_enc_src="crypto/rc5/asm/r5-os2.asm";
65 $md5_asm_obj="crypto/md5/asm/m5-os2$obj";
66 $md5_asm_src="crypto/md5/asm/m5-os2.asm";
67 $sha1_asm_obj="crypto/sha/asm/s1-os2$obj";
68 $sha1_asm_src="crypto/sha/asm/s1-os2.asm";
69 $rmd160_asm_obj="crypto/ripemd/asm/rm-os2$obj";
70 $rmd160_asm_src="crypto/ripemd/asm/rm-os2.asm";
71 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DOPENSSL_BN_ASM_PART_WORDS";
72 }
73
74if ($shlib)
75 {
76 $mlflags.=" $lflags -Zdll";
77 $lib_cflag=" -D_DLL";
78 $out_def="out_dll";
79 $tmp_def="tmp_dll";
80 }
81
82sub do_lib_rule
83 {
84 local($obj,$target,$name,$shlib)=@_;
85 local($ret,$_,$Name);
86
87 $target =~ s/\//$o/g if $o ne '/';
88 $target="$target";
89 ($Name=$name) =~ tr/a-z/A-Z/;
90
91 $ret.="$target: \$(${Name}OBJ)\n";
92 if (!$shlib)
93 {
94 $ret.="\t\$(RM) $target\n";
95 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
96 $ret.="\t\$(RANLIB) $target\n\n";
97 }
98 else
99 {
100 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
101 $ex.=' -lsocket';
102 $ret.="\t\$(LINK) \$(SHLIB_CFLAGS) \$(MLFLAGS) $efile$target \$(SHLIB_EX_OBJ) \$(${Name}OBJ) $ex os2/${Name}.def\n";
103 $ret.="\temximp -o $out_def/$name.a os2/${Name}.def\n";
104 $ret.="\temximp -o $out_def/$name.lib os2/${Name}.def\n\n";
105 }
106 }
107
108sub do_link_rule
109 {
110 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
111 local($ret,$_);
112
113 $file =~ s/\//$o/g if $o ne '/';
114 $n=&bname($target);
115 $ret.="$target: $files $dep_libs\n";
116 $ret.="\t\$(LINK) ${efile}$target \$(CFLAG) \$(LFLAGS) $files $libs\n";
117 if (defined $sha1file)
118 {
119 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
120 }
121 $ret.="\n";
122 return($ret);
123 }
124
1251;
diff --git a/src/lib/libcrypto/util/pl/VC-16.pl b/src/lib/libcrypto/util/pl/VC-16.pl
new file mode 100644
index 0000000000..564ba3fd08
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-16.pl
@@ -0,0 +1,177 @@
1#!/usr/local/bin/perl
2# VCw16lib.pl - the file for Visual C++ 1.52b for windows, static libraries
3#
4
5$ssl= "ssleay16";
6$crypto="libeay16";
7
8$o='\\';
9$cp='copy';
10$rm='del';
11
12# C compiler stuff
13$cc='cl';
14
15$out_def="out16";
16$tmp_def="tmp16";
17$inc_def="inc16";
18
19if ($debug)
20 {
21 $op="/Od /Zi /Zd";
22 $base_lflags="/CO";
23 }
24else {
25 $op="/G2 /f- /Ocgnotb2";
26 }
27$base_lflags.=" /FARCALL /NOLOGO /NOD /SEG:1024 /ONERROR:NOEXE /NOE /PACKC:60000";
28if ($win16) { $base_lflags.=" /PACKD:60000"; }
29
30$cflags="/ALw /Gx- /Gt256 /Gf $op /W3 /WX -DL_ENDIAN /nologo";
31# I add the stack opt
32$lflags="$base_lflags /STACK:20000";
33
34if ($win16)
35 {
36 $cflags.=" -DOPENSSL_SYSNAME_WIN16";
37 $app_cflag="/Gw /FPi87";
38 $lib_cflag="/Gw";
39 $lib_cflag.=" -D_WINDLL -D_DLL" if $shlib;
40 $lib_cflag.=" -DWIN16TTY" if !$shlib;
41 $lflags.=" /ALIGN:256";
42 $ex_libs.="oldnames llibcewq libw";
43 }
44else
45 {
46 $no_sock=1;
47 $cflags.=" -DMSDOS";
48 $lflags.=" /EXEPACK";
49 $ex_libs.="oldnames.lib llibce.lib";
50 }
51
52if ($shlib)
53 {
54 $mlflags="$base_lflags";
55 $libs="oldnames ldllcew libw";
56 $shlib_ex_obj="";
57# $no_asm=1;
58 $out_def="out16dll";
59 $tmp_def="tmp16dll";
60 }
61else
62 { $mlflags=''; }
63
64$app_ex_obj="";
65
66$obj='.obj';
67$ofile="/Fo";
68
69# EXE linking stuff
70$link="link";
71$efile="";
72$exep='.exe';
73$ex_libs.=$no_sock?"":" winsock";
74
75# static library stuff
76$mklib='lib /PAGESIZE:1024';
77$ranlib='';
78$plib="";
79$libp=".lib";
80$shlibp=($shlib)?".dll":".lib";
81$lfile='';
82
83$asm='ml /Cp /c /Cx';
84$afile='/Fo';
85
86$bn_asm_obj='';
87$bn_asm_src='';
88$des_enc_obj='';
89$des_enc_src='';
90$bf_enc_obj='';
91$bf_enc_src='';
92
93if (!$no_asm && !$fips)
94 {
95 if ($asmbits == 32)
96 {
97 $bn_asm_obj='crypto\bn\asm\x86w32.obj';
98 $bn_asm_src='crypto\bn\asm\x86w32.asm';
99 }
100 else
101 {
102 $bn_asm_obj='crypto\bn\asm\x86w16.obj';
103 $bn_asm_src='crypto\bn\asm\x86w16.asm';
104 }
105 }
106
107sub do_lib_rule
108 {
109 local($objs,$target,$name,$shlib)=@_;
110 local($ret,$Name);
111
112 $taget =~ s/\//$o/g if $o ne '/';
113 ($Name=$name) =~ tr/a-z/A-Z/;
114
115# $target="\$(LIB_D)$o$target";
116 $ret.="$target: $objs\n";
117# $ret.="\t\$(RM) \$(O_$Name)\n";
118
119 # Due to a pathetic line length limit, I unwrap the args.
120 local($lib_names)="";
121 local($dll_names)=" \$(SHLIB_EX_OBJ) +\n";
122 ($obj)= ($objs =~ /\((.*)\)/);
123 foreach $_ (sort split(/\s+/,$Vars{$obj}))
124 {
125 $lib_names.="+$_ &\n";
126 $dll_names.=" $_ +\n";
127 }
128
129 if (!$shlib)
130 {
131 $ret.="\tdel $target\n";
132 $ret.="\t\$(MKLIB) @<<\n$target\ny\n$lib_names\n\n<<\n";
133 }
134 else
135 {
136 local($ex)=($target =~ /O_SSL/)?'$(L_CRYPTO)':"";
137 $ex.=' winsock';
138 $ret.="\t\$(LINK) \$(MLFLAGS) @<<\n";
139 $ret.=$dll_names;
140 $ret.="\n $target\n\n $ex $libs\nms$o${name}.def;\n<<\n";
141 ($out_lib=$target) =~ s/O_/L_/;
142 $ret.="\timplib /noignorecase /nowep $out_lib $target\n";
143 }
144 $ret.="\n";
145 return($ret);
146 }
147
148sub do_link_rule
149 {
150 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
151 local($ret,$f,$_,@f);
152
153 $file =~ s/\//$o/g if $o ne '/';
154 $n=&bname($targer);
155 $ret.="$target: $files $dep_libs\n";
156 $ret.=" \$(LINK) \$(LFLAGS) @<<\n";
157
158 # Due to a pathetic line length limit, I have to unwrap the args.
159 if ($files =~ /\(([^)]*)\)$/)
160 {
161 @a=('$(APP_EX_OBJ)');
162 push(@a,sort split(/\s+/,$Vars{$1}));
163 for $_ (@a)
164 { $ret.=" $_ +\n"; }
165 }
166 else
167 { $ret.=" \$(APP_EX_OBJ) $files"; }
168 $ret.="\n $target\n\n $libs\n\n<<\n";
169 if (defined $sha1file)
170 {
171 $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
172 }
173 $ret.="\n";
174 return($ret);
175 }
176
1771;
diff --git a/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl b/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl
new file mode 100644
index 0000000000..b5bbcac6c2
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-32-GMAKE.pl
@@ -0,0 +1,222 @@
1#!/usr/local/bin/perl
2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries
3#
4
5
6if ($fips && !$shlib)
7 {
8 $crypto="libeayfips32";
9 $crypto_compat = "libeaycompat32.lib";
10 }
11else
12 {
13 $crypto="libeay32";
14 }
15$ssl= "ssleay32";
16
17$o='/';
18#$cp='copy nul+'; # Timestamps get stuffed otherwise
19#$rm='del';
20
21$cp='cp';
22$rm='rm';
23
24$zlib_lib="zlib1.lib";
25
26# C compiler stuff
27$cc='cl';
28$cflags=' -MD -W3 -WX -Ox -O2 -Ob2 -Gs0 -GF -Gy -nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
29$cflags.=' -D_CRT_SECURE_NO_DEPRECATE'; # shut up VC8
30$cflags.=' -D_CRT_NONSTDC_NO_DEPRECATE'; # shut up VC8
31$lflags="-nologo -subsystem:console -machine:I386 -opt:ref";
32$mlflags='';
33
34$out_def="gmout32";
35$tmp_def="gmtmp32";
36$inc_def="gminc32";
37
38if ($debug)
39 {
40 $cflags=" -MDd -W3 -WX -Zi -Yd -Od -nologo -DOPENSSL_SYSNAME_WIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32";
41 $lflags.=" -debug";
42 $mlflags.=' -debug';
43 }
44$cflags .= " -DOPENSSL_SYSNAME_WINNT" if $NT == 1;
45
46$obj='.obj';
47$ofile="-Fo";
48
49# EXE linking stuff
50$link="link";
51$efile="-out:";
52$exep='.exe';
53if ($no_sock)
54 { $ex_libs=""; }
55else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
56
57# static library stuff
58$mklib='lib';
59$ranlib='';
60$plib="";
61$libp=".lib";
62$shlibp=($shlib)?".dll":".lib";
63$lfile='-out:';
64
65$shlib_ex_obj="";
66$app_ex_obj="setargv.obj";
67if ($nasm) {
68 $asm='nasmw -f win32';
69 $afile='-o ';
70} else {
71 $asm='ml -Cp -coff -c -Cx';
72 $asm.=" -Zi" if $debug;
73 $afile='-Fo';
74}
75
76$bn_asm_obj='';
77$bn_asm_src='';
78$des_enc_obj='';
79$des_enc_src='';
80$bf_enc_obj='';
81$bf_enc_src='';
82
83if (!$no_asm && !$fips)
84 {
85 $bn_asm_obj='crypto/bn/asm/bn_win32.obj';
86 $bn_asm_src='crypto/bn/asm/bn_win32.asm';
87 $des_enc_obj='crypto/des/asm/d_win32.obj crypto/des/asm/y_win32.obj';
88 $des_enc_src='crypto/des/asm/d_win32.asm crypto/des/asm/y_win32.asm';
89 $bf_enc_obj='crypto/bf/asm/b_win32.obj';
90 $bf_enc_src='crypto/bf/asm/b_win32.asm';
91 $cast_enc_obj='crypto/cast/asm/c_win32.obj';
92 $cast_enc_src='crypto/cast/asm/c_win32.asm';
93 $rc4_enc_obj='crypto/rc4/asm/r4_win32.obj';
94 $rc4_enc_src='crypto/rc4/asm/r4_win32.asm';
95 $rc5_enc_obj='crypto/rc5/asm/r5_win32.obj';
96 $rc5_enc_src='crypto/rc5/asm/r5_win32.asm';
97 $md5_asm_obj='crypto/md5/asm/m5_win32.obj';
98 $md5_asm_src='crypto/md5/asm/m5_win32.asm';
99 $sha1_asm_obj='crypto/sha/asm/s1_win32.obj';
100 $sha1_asm_src='crypto/sha/asm/s1_win32.asm';
101 $rmd160_asm_obj='crypto/ripemd/asm/rm_win32.obj';
102 $rmd160_asm_src='crypto/ripemd/asm/rm_win32.asm';
103 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
104 }
105
106if ($shlib)
107 {
108 $mlflags.=" $lflags -dll";
109# $cflags =~ s| -MD| -MT|;
110 $lib_cflag=" -D_WINDLL";
111 $out_def="gmout32dll";
112 $tmp_def="gmtmp32dll";
113 }
114
115$cflags.=" -Fd$out_def";
116
117sub do_lib_rule
118 {
119 local($objs,$target,$name,$shlib,$ign,$base_addr, $fips_get_sig, $fips_premain_src)=@_;
120 local($ret,$Name);
121
122 $taget =~ s/\//$o/g if $o ne '/';
123 ($Name=$name) =~ tr/a-z/A-Z/;
124 my $base_arg;
125 if ($base_addr ne "")
126 {
127 $base_arg= " -base:$base_addr";
128 }
129 else
130 {
131 $base_arg = "";
132 }
133
134
135# $target="\$(LIB_D)$o$target";
136 if (!$shlib)
137 {
138# $ret.="\t\$(RM) \$(O_$Name)\n";
139 $ret.="$target: $objs\n";
140 $ex =' advapi32.lib';
141 $ret.="\t\$(MKLIB) $lfile$target $objs $ex\n\n";
142 }
143 else
144 {
145 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
146 $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
147 $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
148 if (defined $fips_get_sig)
149 {
150 $ret.="$target: \$(O_FIPSCANISTER) $objs $fips_get_sig\n";
151 $ret.="\tFIPS_LINK=\$(LINK) ";
152 $ret.="FIPS_CC=\$(CC) ";
153 $ret.="FIPS_CC_ARGS=\"-Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\" ";
154 $ret.="FIPS_PREMAIN_DSO=$fips_get_sig ";
155 $ret.="FIPS_TARGET=$target ";
156 $ret.="FIPS_LIBDIR=\$(FIPSLIB_D) ";
157 $ret.="\$(FIPSLINK) \$(MLFLAGS) $base_arg $efile$target ";
158 $ret.="-def:ms/${Name}.def \$(SHLIB_EX_OBJ) $objs ";
159 $ret.="\$(OBJ_D)${o}fips_premain.obj $ex\n\n";
160 }
161 else
162 {
163 $ret.="$target: $objs\n";
164 $ret.="\t\$(LINK) \$(MLFLAGS) $base_arg $efile$target /def:ms/${Name}.def \$(SHLIB_EX_OBJ) $objs $ex\n\n";
165 }
166 }
167 $ret.="\n";
168 return($ret);
169 }
170
171sub do_link_rule
172 {
173 local($target,$files,$dep_libs,$libs,$standalone)=@_;
174 local($ret,$_);
175 $file =~ s/\//$o/g if $o ne '/';
176 $n=&bname($targer);
177 if ($standalone)
178 {
179 $ret.="$target: $files $dep_libs\n";
180 $ret.="\t\$(LINK) \$(LFLAGS) $efile$target ";
181 $ret.="$files $libs\n\n";
182 }
183 elsif ($fips && !$shlib)
184 {
185 $ret.="$target: \$(O_FIPSCANISTER) $files $dep_libs\n";
186 $ret.="\tFIPS_LINK=\$(LINK) ";
187 $ret.="FIPS_CC=\$(CC) ";
188 $ret.="FIPS_CC_ARGS=\"-Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\" ";
189 $ret.="FIPS_PREMAIN_DSO= ";
190 $ret.="FIPS_TARGET=$target ";
191 $ret.="FIPS_LIBDIR=\$(FIPSLIB_D) ";
192 $ret.=" \$(FIPSLINK) \$(LFLAGS) $efile$target ";
193 $ret.="\$(APP_EX_OBJ) $files \$(OBJ_D)${o}fips_premain.obj $libs\n\n";
194 }
195 else
196 {
197 $ret.="$target: $files $dep_libs\n";
198 $ret.="\t\$(LINK) \$(LFLAGS) $efile$target ";
199 $ret.="\$(APP_EX_OBJ) $files $libs\n\n";
200 }
201 $ret.="\n";
202 return($ret);
203 }
204
205sub do_rlink_rule
206 {
207 local($target,$files,$check_hash, $deps)=@_;
208 local($ret,$_);
209
210 $file =~ s/\//$o/g if $o ne '/';
211 $n=&bname($targer);
212 $ret.="$target: $check_hash $files $deps\n";
213 $ret.="\t\$(PERL) util${o}checkhash.pl -chdir fips-1.0 -program_path ..$o$check_hash\n";
214 $ret.="\t\$(MKCANISTER) $target $files\n";
215 $ret.="\t$check_hash $target > $target.sha1\n";
216 $ret.="\t\$(CP) fips-1.0${o}fips_premain.c \$(FIPSLIB_D)\n";
217 $ret.="\t$check_hash \$(FIPSLIB_D)${o}fips_premain.c > \$(FIPSLIB_D)${o}fips_premain.c.sha1\n\n";
218 return($ret);
219 }
220
221
2221;
diff --git a/src/lib/libcrypto/util/pl/VC-32.pl b/src/lib/libcrypto/util/pl/VC-32.pl
new file mode 100644
index 0000000000..4e97dfa9af
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-32.pl
@@ -0,0 +1,220 @@
1#!/usr/local/bin/perl
2# VCw32lib.pl - the file for Visual C++ 4.[01] for windows NT, static libraries
3#
4
5$ssl= "ssleay32";
6
7if ($fips && !$shlib)
8 {
9 $crypto="libeayfips32";
10 $crypto_compat = "libeaycompat32.lib";
11 }
12else
13 {
14 $crypto="libeay32";
15 }
16
17$o='\\';
18$cp='copy nul+'; # Timestamps get stuffed otherwise
19$rm='del';
20
21$zlib_lib="zlib1.lib";
22
23# C compiler stuff
24$cc='cl';
25$cflags=' /MD /W3 /WX /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo -DOPENSSL_SYSNAME_WIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32';
26$cflags.=' -D_CRT_SECURE_NO_DEPRECATE'; # shut up VC8
27$cflags.=' -D_CRT_NONSTDC_NO_DEPRECATE'; # shut up VC8
28$lflags="/nologo /subsystem:console /machine:I386 /opt:ref";
29$mlflags='';
30
31$out_def="out32";
32$tmp_def="tmp32";
33$inc_def="inc32";
34
35if ($debug)
36 {
37 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DOPENSSL_SYSNAME_WIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32";
38 $lflags.=" /debug";
39 $mlflags.=' /debug';
40 }
41$cflags .= " -DOPENSSL_SYSNAME_WINNT" if $NT == 1;
42
43$obj='.obj';
44$ofile="/Fo";
45
46# EXE linking stuff
47$link="link";
48$efile="/out:";
49$exep='.exe';
50if ($no_sock)
51 { $ex_libs=""; }
52else { $ex_libs="wsock32.lib user32.lib gdi32.lib"; }
53
54# static library stuff
55$mklib='lib';
56$ranlib='';
57$plib="";
58$libp=".lib";
59$shlibp=($shlib)?".dll":".lib";
60$lfile='/out:';
61
62$shlib_ex_obj="";
63$app_ex_obj="setargv.obj";
64if ($nasm) {
65 $asm='nasmw -f win32';
66 $afile='-o ';
67} else {
68 $asm='ml /Cp /coff /c /Cx';
69 $asm.=" /Zi" if $debug;
70 $afile='/Fo';
71}
72
73$bn_asm_obj='';
74$bn_asm_src='';
75$des_enc_obj='';
76$des_enc_src='';
77$bf_enc_obj='';
78$bf_enc_src='';
79
80if (!$no_asm && !$fips)
81 {
82 $bn_asm_obj='crypto\bn\asm\bn_win32.obj';
83 $bn_asm_src='crypto\bn\asm\bn_win32.asm';
84 $des_enc_obj='crypto\des\asm\d_win32.obj crypto\des\asm\y_win32.obj';
85 $des_enc_src='crypto\des\asm\d_win32.asm crypto\des\asm\y_win32.asm';
86 $bf_enc_obj='crypto\bf\asm\b_win32.obj';
87 $bf_enc_src='crypto\bf\asm\b_win32.asm';
88 $cast_enc_obj='crypto\cast\asm\c_win32.obj';
89 $cast_enc_src='crypto\cast\asm\c_win32.asm';
90 $rc4_enc_obj='crypto\rc4\asm\r4_win32.obj';
91 $rc4_enc_src='crypto\rc4\asm\r4_win32.asm';
92 $rc5_enc_obj='crypto\rc5\asm\r5_win32.obj';
93 $rc5_enc_src='crypto\rc5\asm\r5_win32.asm';
94 $md5_asm_obj='crypto\md5\asm\m5_win32.obj';
95 $md5_asm_src='crypto\md5\asm\m5_win32.asm';
96 $sha1_asm_obj='crypto\sha\asm\s1_win32.obj';
97 $sha1_asm_src='crypto\sha\asm\s1_win32.asm';
98 $rmd160_asm_obj='crypto\ripemd\asm\rm_win32.obj';
99 $rmd160_asm_src='crypto\ripemd\asm\rm_win32.asm';
100 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM -DRMD160_ASM";
101 }
102
103if ($shlib)
104 {
105 $mlflags.=" $lflags /dll";
106# $cflags =~ s| /MD| /MT|;
107 $lib_cflag=" -D_WINDLL";
108 $out_def="out32dll";
109 $tmp_def="tmp32dll";
110 }
111
112$cflags.=" /Fd$out_def";
113
114sub do_lib_rule
115 {
116 local($objs,$target,$name,$shlib,$ign,$base_addr) = @_;
117 local($ret,$Name);
118
119 $taget =~ s/\//$o/g if $o ne '/';
120 ($Name=$name) =~ tr/a-z/A-Z/;
121 my $base_arg;
122 if ($base_addr ne "")
123 {
124 $base_arg= " /base:$base_addr";
125 }
126 else
127 {
128 $base_arg = "";
129 }
130
131
132# $target="\$(LIB_D)$o$target";
133 if (!$shlib)
134 {
135# $ret.="\t\$(RM) \$(O_$Name)\n";
136 $ret.="$target: $objs\n";
137 $ex =' advapi32.lib';
138 $ex.=" \$(FIPSLIB_D)${o}_chkstk.o" if $fips && $target =~ /O_CRYPTO/;
139 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs $ex\n<<\n";
140 }
141 else
142 {
143 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
144 $ex.=' wsock32.lib gdi32.lib advapi32.lib user32.lib';
145 $ex.=" $zlib_lib" if $zlib_opt == 1 && $target =~ /O_CRYPTO/;
146 if ($fips && $target =~ /O_CRYPTO/)
147 {
148 $ex.=" \$(FIPSLIB_D)${o}_chkstk.o";
149 $ret.="$target: $objs \$(PREMAIN_DSO_EXE)\n";
150 $ret.="\tSET FIPS_LINK=\$(LINK)\n";
151 $ret.="\tSET FIPS_CC=\$(CC)\n";
152 $ret.="\tSET FIPS_CC_ARGS=/Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\n";
153 $ret.="\tSET PREMAIN_DSO_EXE=\$(PREMAIN_DSO_EXE)\n";
154 $ret.="\tSET FIPS_SHA1_EXE=\$(FIPS_SHA1_EXE)\n";
155 $ret.="\tSET FIPS_TARGET=$target\n";
156 $ret.="\tSET FIPSLIB_D=\$(FIPSLIB_D)\n";
157 $ret.="\t\$(FIPSLINK) \$(MLFLAGS) $base_arg $efile$target ";
158 $ret.="/def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs ";
159 $ret.="\$(OBJ_D)${o}fips_premain.obj $ex\n<<\n";
160 }
161 else
162 {
163 $ret.="$target: $objs\n";
164 $ret.="\t\$(LINK) \$(MLFLAGS) $base_arg $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
165 }
166 }
167 $ret.="\n";
168 return($ret);
169 }
170
171sub do_link_rule
172 {
173 local($target,$files,$dep_libs,$libs,$standalone)=@_;
174 local($ret,$_);
175 $file =~ s/\//$o/g if $o ne '/';
176 $n=&bname($targer);
177 $ret.="$target: $files $dep_libs\n";
178 if ($standalone)
179 {
180 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n\t";
181 $ret.="\$(FIPSLIB_D)${o}_chkstk.o " if ($files =~ /O_FIPSCANISTER/);
182 $ret.="$files $libs\n<<\n";
183 }
184 elsif ($fips && !$shlib)
185 {
186 $ret.="\tSET FIPS_LINK=\$(LINK)\n";
187 $ret.="\tSET FIPS_CC=\$(CC)\n";
188 $ret.="\tSET FIPS_CC_ARGS=/Fo\$(OBJ_D)${o}fips_premain.obj \$(SHLIB_CFLAGS) -c\n";
189 $ret.="\tSET PREMAIN_DSO_EXE=\n";
190 $ret.="\tSET FIPS_TARGET=$target\n";
191 $ret.="\tSET FIPS_SHA1_EXE=\$(FIPS_SHA1_EXE)\n";
192 $ret.="\tSET FIPSLIB_D=\$(FIPSLIB_D)\n";
193 $ret.=" \$(FIPSLINK) \$(LFLAGS) $efile$target @<<\n";
194 $ret.=" \$(APP_EX_OBJ) $files \$(OBJ_D)${o}fips_premain.obj $libs\n<<\n";
195 }
196 else
197 {
198 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n";
199 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n";
200 }
201 $ret.="\n";
202 return($ret);
203 }
204
205sub do_rlink_rule
206 {
207 local($target,$files,$dep_libs,$libs)=@_;
208 local($ret,$_);
209
210 $file =~ s/\//$o/g if $o ne '/';
211 $n=&bname($targer);
212 $ret.="$target: $files $dep_libs\n";
213 $ret.=" \$(MKCANISTER) $target <<\n";
214 $ret.="INPUT($files)\n<<\n";
215 $ret.="\n";
216 return($ret);
217 }
218
219
2201;
diff --git a/src/lib/libcrypto/util/pl/VC-CE.pl b/src/lib/libcrypto/util/pl/VC-CE.pl
new file mode 100644
index 0000000000..2fd0c4dd32
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/VC-CE.pl
@@ -0,0 +1,116 @@
1#!/usr/local/bin/perl
2# VC-CE.pl - the file for eMbedded Visual C++ 3.0 for windows CE, static libraries
3#
4
5$ssl= "ssleay32";
6$crypto="libeay32";
7$RSAref="RSAref32";
8
9$o='\\';
10$cp='copy nul+'; # Timestamps get stuffed otherwise
11$rm='del';
12
13# C compiler stuff
14$cc='$(CC)';
15$cflags=' /W3 /WX /Ox /O2 /Ob2 /Gs0 /GF /Gy /nologo $(WCETARGETDEFS) -DUNICODE -D_UNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -DL_ENDIAN -DDSO_WIN32 -DNO_CHMOD -I$(WCECOMPAT)/include';
16$lflags='/nologo /subsystem:windowsce,$(WCELDVERSION) /machine:$(WCELDMACHINE) /opt:ref';
17$mlflags='';
18
19$out_def='out32_$(TARGETCPU)';
20$tmp_def='tmp32_$(TARGETCPU)';
21$inc_def="inc32";
22
23if ($debug)
24 {
25 $cflags=" /MDd /W3 /WX /Zi /Yd /Od /nologo -DWIN32 -D_DEBUG -DL_ENDIAN -DWIN32_LEAN_AND_MEAN -DDEBUG -DDSO_WIN32";
26 $lflags.=" /debug";
27 $mlflags.=' /debug';
28 }
29
30$obj='.obj';
31$ofile="/Fo";
32
33# EXE linking stuff
34$link="link";
35$efile="/out:";
36$exep='.exe';
37if ($no_sock)
38 { $ex_libs=""; }
39else { $ex_libs='winsock.lib $(WCECOMPAT)/lib/wcecompatex.lib $(WCELDFLAGS)'; }
40
41# static library stuff
42$mklib='lib';
43$ranlib='';
44$plib="";
45$libp=".lib";
46$shlibp=($shlib)?".dll":".lib";
47$lfile='/out:';
48
49$shlib_ex_obj="";
50$app_ex_obj="";
51$app_ex_obj="";
52
53$bn_asm_obj='';
54$bn_asm_src='';
55$des_enc_obj='';
56$des_enc_src='';
57$bf_enc_obj='';
58$bf_enc_src='';
59
60if ($shlib)
61 {
62 $mlflags.=" $lflags /dll";
63# $cflags =~ s| /MD| /MT|;
64 $lib_cflag=" -D_WINDLL -D_DLL";
65 $out_def='out32dll_$(TARGETCPU)';
66 $tmp_def='tmp32dll_$(TARGETCPU)';
67 }
68
69$cflags.=" /Fd$out_def";
70
71sub do_lib_rule
72 {
73 local($objs,$target,$name,$shlib)=@_;
74 local($ret,$Name);
75
76 $taget =~ s/\//$o/g if $o ne '/';
77 ($Name=$name) =~ tr/a-z/A-Z/;
78
79# $target="\$(LIB_D)$o$target";
80 $ret.="$target: $objs\n";
81 if (!$shlib)
82 {
83# $ret.="\t\$(RM) \$(O_$Name)\n";
84 $ex =' ';
85 $ret.="\t\$(MKLIB) $lfile$target @<<\n $objs $ex\n<<\n";
86 }
87 else
88 {
89 local($ex)=($target =~ /O_SSL/)?' $(L_CRYPTO)':'';
90# $ex.=' winsock.lib coredll.lib $(WCECOMPAT)/lib/wcecompatex.lib';
91 $ex.=' winsock.lib $(WCECOMPAT)/lib/wcecompatex.lib';
92 $ret.="\t\$(LINK) \$(MLFLAGS) $efile$target /def:ms/${Name}.def @<<\n \$(SHLIB_EX_OBJ) $objs $ex\n<<\n";
93 }
94 $ret.="\n";
95 return($ret);
96 }
97
98sub do_link_rule
99 {
100 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
101 local($ret,$_);
102
103 $file =~ s/\//$o/g if $o ne '/';
104 $n=&bname($targer);
105 $ret.="$target: $files $dep_libs\n";
106 $ret.=" \$(LINK) \$(LFLAGS) $efile$target @<<\n";
107 $ret.=" \$(APP_EX_OBJ) $files $libs\n<<\n";
108 if (defined $sha1file)
109 {
110 $ret.=" $openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
111 }
112 $ret.="\n";
113 return($ret);
114 }
115
1161;
diff --git a/src/lib/libcrypto/util/pl/linux.pl b/src/lib/libcrypto/util/pl/linux.pl
new file mode 100644
index 0000000000..df05c40526
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/linux.pl
@@ -0,0 +1,109 @@
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='gcc';
13if ($debug)
14 { $cflags="-g2 -ggdb -DREF_CHECK -DCRYPTO_MDEBUG"; }
15elsif ($profile)
16 { $cflags="-pg -O3"; }
17else
18 { $cflags="-O3 -fomit-frame-pointer"; }
19
20if (!$no_asm)
21 {
22 $bn_asm_obj='$(OBJ_D)/bn86-elf.o';
23 $bn_asm_src='crypto/bn/asm/bn86unix.cpp';
24 $bnco_asm_obj='$(OBJ_D)/co86-elf.o';
25 $bnco_asm_src='crypto/bn/asm/co86unix.cpp';
26 $des_enc_obj='$(OBJ_D)/dx86-elf.o $(OBJ_D)/yx86-elf.o';
27 $des_enc_src='crypto/des/asm/dx86unix.cpp crypto/des/asm/yx86unix.cpp';
28 $bf_enc_obj='$(OBJ_D)/bx86-elf.o';
29 $bf_enc_src='crypto/bf/asm/bx86unix.cpp';
30 $cast_enc_obj='$(OBJ_D)/cx86-elf.o';
31 $cast_enc_src='crypto/cast/asm/cx86unix.cpp';
32 $rc4_enc_obj='$(OBJ_D)/rx86-elf.o';
33 $rc4_enc_src='crypto/rc4/asm/rx86unix.cpp';
34 $rc5_enc_obj='$(OBJ_D)/r586-elf.o';
35 $rc5_enc_src='crypto/rc5/asm/r586unix.cpp';
36 $md5_asm_obj='$(OBJ_D)/mx86-elf.o';
37 $md5_asm_src='crypto/md5/asm/mx86unix.cpp';
38 $rmd160_asm_obj='$(OBJ_D)/rm86-elf.o';
39 $rmd160_asm_src='crypto/ripemd/asm/rm86unix.cpp';
40 $sha1_asm_obj='$(OBJ_D)/sx86-elf.o';
41 $sha1_asm_src='crypto/sha/asm/sx86unix.cpp';
42 $cflags.=" -DBN_ASM -DMD5_ASM -DSHA1_ASM";
43 }
44
45$cflags.=" -DTERMIO -DL_ENDIAN -m486 -Wall";
46
47if ($shlib)
48 {
49 $shl_cflag=" -DPIC -fpic";
50 $shlibp=".so.$ssl_version";
51 $so_shlibp=".so";
52 }
53
54sub do_shlib_rule
55 {
56 local($obj,$target,$name,$shlib,$so_name)=@_;
57 local($ret,$_,$Name);
58
59 $target =~ s/\//$o/g if $o ne '/';
60 ($Name=$name) =~ tr/a-z/A-Z/;
61
62 $ret.="$target: \$(${Name}OBJ)\n";
63 $ret.="\t\$(RM) target\n";
64 $ret.="\tgcc \${CFLAGS} -shared -Wl,-soname,$target -o $target \$(${Name}OBJ)\n";
65 ($t=$target) =~ s/(^.*)\/[^\/]*$/$1/;
66 if ($so_name ne "")
67 {
68 $ret.="\t\$(RM) \$(LIB_D)$o$so_name\n";
69 $ret.="\tln -s $target \$(LIB_D)$o$so_name\n\n";
70 }
71 }
72
73sub do_link_rule
74 {
75 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
76 local($ret,$_);
77
78 $file =~ s/\//$o/g if $o ne '/';
79 $n=&bname($target);
80 $ret.="$target: $files $dep_libs\n";
81 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n";
82 if (defined $sha1file)
83 {
84 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
85 }
86 $ret.="\n";
87 return($ret);
88 }
89
90sub do_asm_rule
91 {
92 local($target,$src)=@_;
93 local($ret,@s,@t,$i);
94
95 $target =~ s/\//$o/g if $o ne "/";
96 $src =~ s/\//$o/g if $o ne "/";
97
98 @s=split(/\s+/,$src);
99 @t=split(/\s+/,$target);
100
101 for ($i=0; $i<=$#s; $i++)
102 {
103 $ret.="$t[$i]: $s[$i]\n";
104 $ret.="\tgcc -E -DELF \$(SRC_D)$o$s[$i]|\$(AS) $afile$t[$i]\n\n";
105 }
106 return($ret);
107 }
108
1091;
diff --git a/src/lib/libcrypto/util/pl/netware.pl b/src/lib/libcrypto/util/pl/netware.pl
new file mode 100644
index 0000000000..173c9919f2
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/netware.pl
@@ -0,0 +1,526 @@
1# Metrowerks Codewarrior or gcc / nlmconv for NetWare
2#
3
4$version_header = "crypto/opensslv.h";
5open(IN, "$version_header") or die "Couldn't open $version_header: $!";
6while (<IN>) {
7 if (/^#define[\s\t]+OPENSSL_VERSION_NUMBER[\s\t]+0x(\d)(\d{2})(\d{2})(\d{2})/)
8 {
9 # die "OpenSSL version detected: $1.$2.$3.$4\n";
10 #$nlmvernum = "$1,$2,$3";
11 $nlmvernum = "$1,".($2*10+$3).",".($4*1);
12 #$nlmverstr = "$1.".($2*1).".".($3*1).($4?(chr(96+$4)):"");
13 break;
14 }
15}
16close(IN) or die "Couldn't close $version_header: $!";
17
18$readme_file = "README";
19open(IN, $readme_file) or die "Couldn't open $readme_file: $!";
20while (<IN>) {
21 if (/^[\s\t]+OpenSSL[\s\t]+(\d)\.(\d{1,2})\.(\d{1,2})([a-z])(.*)/)
22 {
23 #$nlmvernum = "$1,$2,$3";
24 #$nlmvernum = "$1,".($2*10+$3).",".($4*1);
25 $nlmverstr = "$1.$2.$3$4$5";
26 }
27 elsif (/^[\s\t]+(Copyright \(c\) \d{4}\-\d{4} The OpenSSL Project)$/)
28 {
29 $nlmcpystr = $1;
30 }
31 break if ($nlmvernum && $nlmcpystr);
32}
33close(IN) or die "Couldn't close $readme_file: $!";
34
35# Define stacksize here
36$nlmstack = "32768";
37
38# some default settings here in case we failed to find them in README
39$nlmvernum = "1,0,0" if (!$nlmvernum);
40$nlmverstr = "OpenSSL" if (!$nlmverstr);
41$nlmcpystr = "Copyright (c) 1998-now The OpenSSL Project" if (!$nlmcpystr);
42
43# die "OpenSSL copyright: $nlmcpystr\nOpenSSL verstring: $nlmverstr\nOpenSSL vernumber: $nlmvernum\n";
44
45# The import files and other misc imports needed to link
46@misc_imports = ("GetProcessSwitchCount", "RunningProcess",
47 "GetSuperHighResolutionTimer");
48if ($LIBC)
49{
50 @import_files = ("libc.imp");
51 @module_files = ("libc");
52 $libarch = "LIBC";
53}
54else
55{
56 # clib build
57 @import_files = ("clib.imp");
58 push(@import_files, "socklib.imp") if ($BSDSOCK);
59 @module_files = ("clib");
60 # push(@misc_imports, "_rt_modu64%16", "_rt_divu64%16");
61 $libarch = "CLIB";
62}
63if ($BSDSOCK)
64{
65 $libarch .= "-BSD";
66}
67else
68{
69 $libarch .= "-WS2";
70 push(@import_files, "ws2nlm.imp");
71}
72
73# The "IMPORTS" environment variable must be set and point to the location
74# where import files (*.imp) can be found.
75# Example: set IMPORTS=c:\ndk\nwsdk\imports
76$import_path = $ENV{"IMPORTS"} || die ("IMPORTS environment variable not set\n");
77
78
79# The "PRELUDE" environment variable must be set and point to the location
80# and name of the prelude source to link with ( nwpre.obj is recommended ).
81# Example: set PRELUDE=c:\codewar\novell support\metrowerks support\libraries\runtime\nwpre.obj
82$prelude = $ENV{"PRELUDE"} || die ("PRELUDE environment variable not set\n");
83
84# The "INCLUDES" environment variable must be set and point to the location
85# where import files (*.imp) can be found.
86$include_path = $ENV{"INCLUDE"} || die ("INCLUDES environment variable not set\n");
87$include_path =~ s/\\/\//g;
88$include_path = join(" -I", split(/;/, $include_path));
89
90# check for gcc compiler
91$gnuc = $ENV{"GNUC"};
92
93#$ssl= "ssleay32";
94#$crypto="libeay32";
95
96if ($gnuc)
97{
98 # C compiler
99 $cc='gcc';
100 # Linker
101 $link='nlmconv';
102 # librarian
103 $mklib='ar';
104 $o='/';
105 # cp command
106 $cp='cp -af';
107 # rm command
108 $rm='rm -f';
109 # mv command
110 $mv='mv -f';
111 # mkdir command
112 $mkdir='gmkdir';
113 #$ranlib='ranlib';
114}
115else
116{
117 # C compiler
118 $cc='mwccnlm';
119 # Linker
120 $link='mwldnlm';
121 # librarian
122 $mklib='mwldnlm';
123 # Path separator
124 $o='\\';
125 # cp command
126 $cp='copy >nul:';
127 # rm command
128 $rm='del /f /q';
129}
130
131# assembler
132if ($nw_nasm)
133{
134 if ($gnuc)
135 {
136 $asm="nasmw -s -f elf";
137 }
138 else
139 {
140 $asm="nasmw -s -f coff";
141 }
142 $afile="-o ";
143 $asm.=" -g" if $debug;
144}
145elsif ($nw_mwasm)
146{
147 $asm="mwasmnlm -maxerrors 20";
148 $afile="-o ";
149 $asm.=" -g" if $debug;
150}
151elsif ($nw_masm)
152{
153# masm assembly settings - it should be possible to use masm but haven't
154# got it working.
155# $asm='ml /Cp /coff /c /Cx';
156# $asm.=" /Zi" if $debug;
157# $afile='/Fo';
158 die("Support for masm assembler not yet functional\n");
159}
160else
161{
162 $asm="";
163 $afile="";
164}
165
166
167
168if ($gnuc)
169{
170 # compile flags for GNUC
171 # additional flags based upon debug | non-debug
172 if ($debug)
173 {
174 $cflags="-g -DDEBUG";
175 }
176 else
177 {
178 $cflags="-O2";
179 }
180 $cflags.=" -nostdinc -I$include_path \\
181 -fno-builtin -fpcc-struct-return -fno-strict-aliasing \\
182 -funsigned-char -Wall -Wno-unused -Wno-uninitialized";
183
184 # link flags
185 $lflags="-T";
186}
187else
188{
189 # compile flags for CodeWarrior
190 # additional flags based upon debug | non-debug
191 if ($debug)
192 {
193 $cflags="-opt off -g -sym internal -DDEBUG";
194 }
195 else
196 {
197 # CodeWarrior compiler has a problem with optimizations for floating
198 # points - no optimizations until further investigation
199 # $cflags="-opt all";
200 }
201
202 # NOTES: Several c files in the crypto subdirectory include headers from
203 # their local directories. Metrowerks wouldn't find these h files
204 # without adding individual include directives as compile flags
205 # or modifying the c files. Instead of adding individual include
206 # paths for each subdirectory a recursive include directive
207 # is used ( -ir crypto ).
208 #
209 # A similar issue exists for the engines and apps subdirectories.
210 #
211 # Turned off the "possible" warnings ( -w nopossible ). Metrowerks
212 # complained a lot about various stuff. May want to turn back
213 # on for further development.
214 $cflags.=" -nostdinc -ir crypto -ir engines -ir apps -I$include_path \\
215 -msgstyle gcc -align 4 -processor pentium -char unsigned \\
216 -w on -w nolargeargs -w nopossible -w nounusedarg -w nounusedexpr \\
217 -w noimplicitconv -relax_pointers -nosyspath -maxerrors 20";
218
219 # link flags
220 $lflags="-msgstyle gcc -zerobss -nostdlib -sym internal -commandfile";
221}
222
223# common defines
224$cflags.=" -DL_ENDIAN -DOPENSSL_SYSNAME_NETWARE -U_WIN32";
225
226# If LibC build add in NKS_LIBC define and set the entry/exit
227# routines - The default entry/exit routines are for CLib and don't exist
228# in LibC
229if ($LIBC)
230{
231 $cflags.=" -DNETWARE_LIBC";
232 $nlmstart = "_LibCPrelude";
233 $nlmexit = "_LibCPostlude";
234 @nlm_flags = ("pseudopreemption", "flag_on 64");
235}
236else
237{
238 $cflags.=" -DNETWARE_CLIB";
239 $nlmstart = "_Prelude";
240 $nlmexit = "_Stop";
241}
242
243# If BSD Socket support is requested, set a define for the compiler
244if ($BSDSOCK)
245{
246 $cflags.=" -DNETWARE_BSDSOCK";
247 if (!$LIBC)
248 {
249 $cflags.=" -DNETDB_USE_INTERNET";
250 }
251}
252
253
254# linking stuff
255# for the output directories use the mk1mf.pl values with "_nw" appended
256if ($shlib)
257{
258 if ($LIBC)
259 {
260 $out_def.="_nw_libc_nlm";
261 $tmp_def.="_nw_libc_nlm";
262 $inc_def.="_nw_libc_nlm";
263 }
264 else # NETWARE_CLIB
265 {
266 $out_def.="_nw_clib_nlm";
267 $tmp_def.="_nw_clib_nlm";
268 $inc_def.="_nw_clib_nlm";
269 }
270}
271else
272{
273 if ($gnuc) # GNUC Tools
274 {
275 $libp=".a";
276 $shlibp=".a";
277 $lib_flags="-cr";
278 }
279 else # CodeWarrior
280 {
281 $libp=".lib";
282 $shlibp=".lib";
283 $lib_flags="-nodefaults -type library -o";
284 }
285 if ($LIBC)
286 {
287 $out_def.="_nw_libc";
288 $tmp_def.="_nw_libc";
289 $inc_def.="_nw_libc";
290 }
291 else # NETWARE_CLIB
292 {
293 $out_def.="_nw_clib";
294 $tmp_def.="_nw_clib";
295 $inc_def.="_nw_clib";
296 }
297}
298
299# used by mk1mf.pl
300$obj='.o';
301$ofile='-o ';
302$efile='';
303$exep='.nlm';
304$ex_libs='';
305
306if (!$no_asm)
307{
308 $bn_asm_obj="\$(OBJ_D)${o}bn-nw${obj}";
309 $bn_asm_src="crypto${o}bn${o}asm${o}bn-nw.asm";
310 $bnco_asm_obj="\$(OBJ_D)${o}co-nw${obj}";
311 $bnco_asm_src="crypto${o}bn${o}asm${o}co-nw.asm";
312 $aes_asm_obj="\$(OBJ_D)${o}a-nw${obj}";
313 $aes_asm_src="crypto${o}aes${o}asm${o}a-nw.asm";
314 $des_enc_obj="\$(OBJ_D)${o}d-nw${obj} \$(OBJ_D)${o}y-nw${obj}";
315 $des_enc_src="crypto${o}des${o}asm${o}d-nw.asm crypto${o}des${o}asm${o}y-nw.asm";
316 $bf_enc_obj="\$(OBJ_D)${o}b-nw${obj}";
317 $bf_enc_src="crypto${o}bf${o}asm${o}b-nw.asm";
318 $cast_enc_obj="\$(OBJ_D)${o}c-nw${obj}";
319 $cast_enc_src="crypto${o}cast${o}asm${o}c-nw.asm";
320 $rc4_enc_obj="\$(OBJ_D)${o}r4-nw${obj}";
321 $rc4_enc_src="crypto${o}rc4${o}asm${o}r4-nw.asm";
322 $rc5_enc_obj="\$(OBJ_D)${o}r5-nw${obj}";
323 $rc5_enc_src="crypto${o}rc5${o}asm${o}r5-nw.asm";
324 $md5_asm_obj="\$(OBJ_D)${o}m5-nw${obj}";
325 $md5_asm_src="crypto${o}md5${o}asm${o}m5-nw.asm";
326 $sha1_asm_obj="\$(OBJ_D)${o}s1-nw${obj}";
327 $sha1_asm_src="crypto${o}sha${o}asm${o}s1-nw.asm";
328 $rmd160_asm_obj="\$(OBJ_D)${o}rm-nw${obj}";
329 $rmd160_asm_src="crypto${o}ripemd${o}asm${o}rm-nw.asm";
330 $cpuid_asm_obj="\$(OBJ_D)${o}x86cpuid-nw${obj}";
331 $cpuid_asm_src="crypto${o}x86cpuid-nw.asm";
332 $cflags.=" -DOPENSSL_CPUID_OBJ -DBN_ASM -DOPENSSL_BN_ASM_PART_WORDS -DMD5_ASM -DSHA1_ASM";
333 $cflags.=" -DAES_ASM -DRMD160_ASM";
334}
335else
336{
337 $bn_asm_obj='';
338 $bn_asm_src='';
339 $bnco_asm_obj='';
340 $bnco_asm_src='';
341 $aes_asm_obj='';
342 $aes_asm_src='';
343 $des_enc_obj='';
344 $des_enc_src='';
345 $bf_enc_obj='';
346 $bf_enc_src='';
347 $cast_enc_obj='';
348 $cast_enc_src='';
349 $rc4_enc_obj='';
350 $rc4_enc_src='';
351 $rc5_enc_obj='';
352 $rc5_enc_src='';
353 $md5_asm_obj='';
354 $md5_asm_src='';
355 $sha1_asm_obj='';
356 $sha1_asm_src='';
357 $rmd160_asm_obj='';
358 $rmd160_asm_src='';
359 $cpuid_asm_obj='';
360 $cpuid_asm_src='';
361}
362
363# create the *.def linker command files in \openssl\netware\ directory
364sub do_def_file
365{
366 # strip off the leading path
367 my($target) = bname(shift);
368 my($i);
369
370 if ($target =~ /(.*).nlm/)
371 {
372 $target = $1;
373 }
374
375 # special case for openssl - the mk1mf.pl defines E_EXE = openssl
376 if ($target =~ /E_EXE/)
377 {
378 $target =~ s/\$\(E_EXE\)/openssl/;
379 }
380
381 # Note: originally tried to use full path ( \openssl\netware\$target.def )
382 # Metrowerks linker choked on this with an assertion failure. bug???
383 #
384 my($def_file) = "netware${o}$target.def";
385
386 open(DEF_OUT, ">$def_file") || die("unable to open file $def_file\n");
387
388 print( DEF_OUT "# command file generated by netware.pl for NLM target.\n" );
389 print( DEF_OUT "# do not edit this file - all your changes will be lost!!\n" );
390 print( DEF_OUT "#\n");
391 print( DEF_OUT "DESCRIPTION \"$target ($libarch) - OpenSSL $nlmverstr\"\n");
392 print( DEF_OUT "COPYRIGHT \"$nlmcpystr\"\n");
393 print( DEF_OUT "VERSION $nlmvernum\n");
394 print( DEF_OUT "STACK $nlmstack\n");
395 print( DEF_OUT "START $nlmstart\n");
396 print( DEF_OUT "EXIT $nlmexit\n");
397
398 # special case for openssl
399 if ($target eq "openssl")
400 {
401 print( DEF_OUT "SCREENNAME \"OpenSSL $nlmverstr\"\n");
402 }
403 else
404 {
405 print( DEF_OUT "SCREENNAME \"DEFAULT\"\n");
406 }
407
408 foreach $i (@misc_imports)
409 {
410 print( DEF_OUT "IMPORT $i\n");
411 }
412
413 foreach $i (@import_files)
414 {
415 print( DEF_OUT "IMPORT \@$import_path${o}$i\n");
416 }
417
418 foreach $i (@module_files)
419 {
420 print( DEF_OUT "MODULE $i\n");
421 }
422
423 foreach $i (@nlm_flags)
424 {
425 print( DEF_OUT "$i\n");
426 }
427
428 if ($gnuc)
429 {
430 if ($target =~ /openssl/)
431 {
432 print( DEF_OUT "INPUT ${tmp_def}${o}openssl${obj}\n");
433 print( DEF_OUT "INPUT ${tmp_def}${o}openssl${libp}\n");
434 }
435 else
436 {
437 print( DEF_OUT "INPUT ${tmp_def}${o}${target}${obj}\n");
438 }
439 print( DEF_OUT "INPUT $prelude\n");
440 print( DEF_OUT "INPUT ${out_def}${o}${ssl}${libp} ${out_def}${o}${crypto}${libp}\n");
441 print( DEF_OUT "OUTPUT $target.nlm\n");
442 }
443
444 close(DEF_OUT);
445 return($def_file);
446}
447
448sub do_lib_rule
449{
450 my($objs,$target,$name,$shlib)=@_;
451 my($ret);
452
453 $ret.="$target: $objs\n";
454 if (!$shlib)
455 {
456 $ret.="\t\@echo Building Lib: $name\n";
457 $ret.="\t\$(MKLIB) $lib_flags $target $objs\n";
458 $ret.="\t\@echo .\n"
459 }
460 else
461 {
462 die( "Building as NLM not currently supported!" );
463 }
464
465 $ret.="\n";
466 return($ret);
467}
468
469sub do_link_rule
470{
471 my($target,$files,$dep_libs,$libs)=@_;
472 my($ret);
473 my($def_file) = do_def_file($target);
474
475 $ret.="$target: $files $dep_libs\n";
476
477 # NOTE: When building the test nlms no screen name is given
478 # which causes the console screen to be used. By using the console
479 # screen there is no "<press any key to continue>" message which
480 # requires user interaction. The test script ( do_tests.pl ) needs
481 # to be able to run the tests without requiring user interaction.
482 #
483 # However, the sample program "openssl.nlm" is used by the tests and is
484 # a interactive sample so a screen is desired when not be run by the
485 # tests. To solve the problem, two versions of the program are built:
486 # openssl2 - no screen used by tests
487 # openssl - default screen - use for normal interactive modes
488 #
489
490 # special case for openssl - the mk1mf.pl defines E_EXE = openssl
491 if ($target =~ /E_EXE/)
492 {
493 my($target2) = $target;
494
495 $target2 =~ s/\(E_EXE\)/\(E_EXE\)2/;
496
497 # openssl2
498 my($def_file2) = do_def_file($target2);
499
500 if ($gnuc)
501 {
502 $ret.="\t\$(MKLIB) $lib_flags \$(TMP_D)${o}\$(E_EXE).a \$(filter-out \$(TMP_D)${o}\$(E_EXE)${obj},$files)\n";
503 $ret.="\t\$(LINK) \$(LFLAGS) $def_file2\n";
504 $ret.="\t\@$mv \$(E_EXE)2.nlm \$(TEST_D)\n";
505 }
506 else
507 {
508 $ret.="\t\$(LINK) \$(LFLAGS) $def_file2 $files \"$prelude\" $libs -o $target2\n";
509 }
510 }
511 if ($gnuc)
512 {
513 $ret.="\t\$(LINK) \$(LFLAGS) $def_file\n";
514 $ret.="\t\@$mv \$(\@F) \$(TEST_D)\n";
515 }
516 else
517 {
518 $ret.="\t\$(LINK) \$(LFLAGS) $def_file $files \"$prelude\" $libs -o $target\n";
519 }
520
521 $ret.="\n";
522 return($ret);
523
524}
525
5261;
diff --git a/src/lib/libcrypto/util/pl/ultrix.pl b/src/lib/libcrypto/util/pl/ultrix.pl
new file mode 100644
index 0000000000..447b854708
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/ultrix.pl
@@ -0,0 +1,43 @@
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 && !$fips)
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,$sha1file,$openssl)=@_;
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";
35 if (defined $sha1file)
36 {
37 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
38 }
39 $ret.="\n";
40 return($ret);
41 }
42
431;
diff --git a/src/lib/libcrypto/util/pl/unix.pl b/src/lib/libcrypto/util/pl/unix.pl
new file mode 100644
index 0000000000..bbd1798a2e
--- /dev/null
+++ b/src/lib/libcrypto/util/pl/unix.pl
@@ -0,0 +1,101 @@
1#!/usr/local/bin/perl
2#
3# unix.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
12if ($gcc)
13 {
14 $cc='gcc';
15 if ($debug)
16 { $cflags="-g2 -ggdb"; }
17 else
18 { $cflags="-O3 -fomit-frame-pointer"; }
19 }
20else
21 {
22 $cc='cc';
23 if ($debug)
24 { $cflags="-g"; }
25 else
26 { $cflags="-O"; }
27 }
28$obj='.o';
29$ofile='-o ';
30
31# EXE linking stuff
32$link='${CC}';
33$lflags='${CFLAGS}';
34$efile='-o ';
35$exep='';
36$ex_libs="";
37
38# static library stuff
39$mklib='ar r';
40$mlflags='';
41$ranlib=&which("ranlib") or $ranlib="true";
42$plib='lib';
43$libp=".a";
44$shlibp=".a";
45$lfile='';
46
47$asm='as';
48$afile='-o ';
49$bn_asm_obj="";
50$bn_asm_src="";
51$des_enc_obj="";
52$des_enc_src="";
53$bf_enc_obj="";
54$bf_enc_src="";
55
56sub do_lib_rule
57 {
58 local($obj,$target,$name,$shlib)=@_;
59 local($ret,$_,$Name);
60
61 $target =~ s/\//$o/g if $o ne '/';
62 $target="$target";
63 ($Name=$name) =~ tr/a-z/A-Z/;
64
65 $ret.="$target: \$(${Name}OBJ)\n";
66 $ret.="\t\$(RM) $target\n";
67 $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
68 $ret.="\t\$(RANLIB) $target\n\n";
69 }
70
71sub do_link_rule
72 {
73 local($target,$files,$dep_libs,$libs,$sha1file,$openssl)=@_;
74 local($ret,$_);
75
76 $file =~ s/\//$o/g if $o ne '/';
77 $n=&bname($target);
78 $ret.="$target: $files $dep_libs\n";
79 $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n";
80 if (defined $sha1file)
81 {
82 $ret.="\t$openssl sha1 -hmac etaonrishdlcupfm -binary $target > $sha1file";
83 }
84 $ret.="\n";
85 return($ret);
86 }
87
88sub which
89 {
90 my ($name)=@_;
91 my $path;
92 foreach $path (split /:/, $ENV{PATH})
93 {
94 if (-x "$path/$name")
95 {
96 return "$path/$name";
97 }
98 }
99 }
100
1011;
diff --git a/src/lib/libcrypto/util/pod2man.pl b/src/lib/libcrypto/util/pod2man.pl
new file mode 100644
index 0000000000..546d1ec186
--- /dev/null
+++ b/src/lib/libcrypto/util/pod2man.pl
@@ -0,0 +1,1184 @@
1: #!/usr/bin/perl-5.005
2 eval 'exec /usr/bin/perl -S $0 ${1+"$@"}'
3 if $running_under_some_shell;
4
5$DEF_PM_SECTION = '3pm' || '3';
6
7=head1 NAME
8
9pod2man - translate embedded Perl pod directives into man pages
10
11=head1 SYNOPSIS
12
13B<pod2man>
14[ B<--section=>I<manext> ]
15[ B<--release=>I<relpatch> ]
16[ B<--center=>I<string> ]
17[ B<--date=>I<string> ]
18[ B<--fixed=>I<font> ]
19[ B<--official> ]
20[ B<--lax> ]
21I<inputfile>
22
23=head1 DESCRIPTION
24
25B<pod2man> converts its input file containing embedded pod directives (see
26L<perlpod>) into nroff source suitable for viewing with nroff(1) or
27troff(1) using the man(7) macro set.
28
29Besides the obvious pod conversions, B<pod2man> also takes care of
30func(), func(n), and simple variable references like $foo or @bar so
31you don't have to use code escapes for them; complex expressions like
32C<$fred{'stuff'}> will still need to be escaped, though. Other nagging
33little roffish things that it catches include translating the minus in
34something like foo-bar, making a long dash--like this--into a real em
35dash, fixing up "paired quotes", putting a little space after the
36parens in something like func(), making C++ and PI look right, making
37double underbars have a little tiny space between them, making ALLCAPS
38a teeny bit smaller in troff(1), and escaping backslashes so you don't
39have to.
40
41=head1 OPTIONS
42
43=over 8
44
45=item center
46
47Set the centered header to a specific string. The default is
48"User Contributed Perl Documentation", unless the C<--official> flag is
49given, in which case the default is "Perl Programmers Reference Guide".
50
51=item date
52
53Set the left-hand footer string to this value. By default,
54the modification date of the input file will be used.
55
56=item fixed
57
58The fixed font to use for code refs. Defaults to CW.
59
60=item official
61
62Set the default header to indicate that this page is of
63the standard release in case C<--center> is not given.
64
65=item release
66
67Set the centered footer. By default, this is the current
68perl release.
69
70=item section
71
72Set the section for the C<.TH> macro. The standard conventions on
73sections are to use 1 for user commands, 2 for system calls, 3 for
74functions, 4 for devices, 5 for file formats, 6 for games, 7 for
75miscellaneous information, and 8 for administrator commands. This works
76best if you put your Perl man pages in a separate tree, like
77F</usr/local/perl/man/>. By default, section 1 will be used
78unless the file ends in F<.pm> in which case section 3 will be selected.
79
80=item lax
81
82Don't complain when required sections aren't present.
83
84=back
85
86=head1 Anatomy of a Proper Man Page
87
88For those not sure of the proper layout of a man page, here's
89an example of the skeleton of a proper man page. Head of the
90major headers should be setout as a C<=head1> directive, and
91are historically written in the rather startling ALL UPPER CASE
92format, although this is not mandatory.
93Minor headers may be included using C<=head2>, and are
94typically in mixed case.
95
96=over 10
97
98=item NAME
99
100Mandatory section; should be a comma-separated list of programs or
101functions documented by this podpage, such as:
102
103 foo, bar - programs to do something
104
105=item SYNOPSIS
106
107A short usage summary for programs and functions, which
108may someday be deemed mandatory.
109
110=item DESCRIPTION
111
112Long drawn out discussion of the program. It's a good idea to break this
113up into subsections using the C<=head2> directives, like
114
115 =head2 A Sample Subection
116
117 =head2 Yet Another Sample Subection
118
119=item OPTIONS
120
121Some people make this separate from the description.
122
123=item RETURN VALUE
124
125What the program or function returns if successful.
126
127=item ERRORS
128
129Exceptions, return codes, exit stati, and errno settings.
130
131=item EXAMPLES
132
133Give some example uses of the program.
134
135=item ENVIRONMENT
136
137Envariables this program might care about.
138
139=item FILES
140
141All files used by the program. You should probably use the FE<lt>E<gt>
142for these.
143
144=item SEE ALSO
145
146Other man pages to check out, like man(1), man(7), makewhatis(8), or catman(8).
147
148=item NOTES
149
150Miscellaneous commentary.
151
152=item CAVEATS
153
154Things to take special care with; sometimes called WARNINGS.
155
156=item DIAGNOSTICS
157
158All possible messages the program can print out--and
159what they mean.
160
161=item BUGS
162
163Things that are broken or just don't work quite right.
164
165=item RESTRICTIONS
166
167Bugs you don't plan to fix :-)
168
169=item AUTHOR
170
171Who wrote it (or AUTHORS if multiple).
172
173=item HISTORY
174
175Programs derived from other sources sometimes have this, or
176you might keep a modification log here.
177
178=back
179
180=head1 EXAMPLES
181
182 pod2man program > program.1
183 pod2man some_module.pm > /usr/perl/man/man3/some_module.3
184 pod2man --section=7 note.pod > note.7
185
186=head1 DIAGNOSTICS
187
188The following diagnostics are generated by B<pod2man>. Items
189marked "(W)" are non-fatal, whereas the "(F)" errors will cause
190B<pod2man> to immediately exit with a non-zero status.
191
192=over 4
193
194=item bad option in paragraph %d of %s: ``%s'' should be [%s]<%s>
195
196(W) If you start include an option, you should set it off
197as bold, italic, or code.
198
199=item can't open %s: %s
200
201(F) The input file wasn't available for the given reason.
202
203=item Improper man page - no dash in NAME header in paragraph %d of %s
204
205(W) The NAME header did not have an isolated dash in it. This is
206considered important.
207
208=item Invalid man page - no NAME line in %s
209
210(F) You did not include a NAME header, which is essential.
211
212=item roff font should be 1 or 2 chars, not `%s' (F)
213
214(F) The font specified with the C<--fixed> option was not
215a one- or two-digit roff font.
216
217=item %s is missing required section: %s
218
219(W) Required sections include NAME, DESCRIPTION, and if you're
220using a section starting with a 3, also a SYNOPSIS. Actually,
221not having a NAME is a fatal.
222
223=item Unknown escape: %s in %s
224
225(W) An unknown HTML entity (probably for an 8-bit character) was given via
226a C<EE<lt>E<gt>> directive. Besides amp, lt, gt, and quot, recognized
227entities are Aacute, aacute, Acirc, acirc, AElig, aelig, Agrave, agrave,
228Aring, aring, Atilde, atilde, Auml, auml, Ccedil, ccedil, Eacute, eacute,
229Ecirc, ecirc, Egrave, egrave, ETH, eth, Euml, euml, Iacute, iacute, Icirc,
230icirc, Igrave, igrave, Iuml, iuml, Ntilde, ntilde, Oacute, oacute, Ocirc,
231ocirc, Ograve, ograve, Oslash, oslash, Otilde, otilde, Ouml, ouml, szlig,
232THORN, thorn, Uacute, uacute, Ucirc, ucirc, Ugrave, ugrave, Uuml, uuml,
233Yacute, yacute, and yuml.
234
235=item Unmatched =back
236
237(W) You have a C<=back> without a corresponding C<=over>.
238
239=item Unrecognized pod directive: %s
240
241(W) You specified a pod directive that isn't in the known list of
242C<=head1>, C<=head2>, C<=item>, C<=over>, C<=back>, or C<=cut>.
243
244
245=back
246
247=head1 NOTES
248
249If you would like to print out a lot of man page continuously, you
250probably want to set the C and D registers to set contiguous page
251numbering and even/odd paging, at least on some versions of man(7).
252Settting the F register will get you some additional experimental
253indexing:
254
255 troff -man -rC1 -rD1 -rF1 perl.1 perldata.1 perlsyn.1 ...
256
257The indexing merely outputs messages via C<.tm> for each
258major page, section, subsection, item, and any C<XE<lt>E<gt>>
259directives.
260
261
262=head1 RESTRICTIONS
263
264None at this time.
265
266=head1 BUGS
267
268The =over and =back directives don't really work right. They
269take absolute positions instead of offsets, don't nest well, and
270making people count is suboptimal in any event.
271
272=head1 AUTHORS
273
274Original prototype by Larry Wall, but so massively hacked over by
275Tom Christiansen such that Larry probably doesn't recognize it anymore.
276
277=cut
278
279$/ = "";
280$cutting = 1;
281@Indices = ();
282
283# We try first to get the version number from a local binary, in case we're
284# running an installed version of Perl to produce documentation from an
285# uninstalled newer version's pod files.
286if ($^O ne 'plan9' and $^O ne 'dos' and $^O ne 'os2' and $^O ne 'MSWin32') {
287 my $perl = (-x './perl' && -f './perl' ) ?
288 './perl' :
289 ((-x '../perl' && -f '../perl') ?
290 '../perl' :
291 '');
292 ($version,$patch) = `$perl -e 'print $]'` =~ /^(\d\.\d{3})(\d{2})?/ if $perl;
293}
294# No luck; we'll just go with the running Perl's version
295($version,$patch) = $] =~ /^(.{5})(\d{2})?/ unless $version;
296$DEF_RELEASE = "perl $version";
297$DEF_RELEASE .= ", patch $patch" if $patch;
298
299
300sub makedate {
301 my $secs = shift;
302 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($secs);
303 my $mname = (qw{Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec})[$mon];
304 $year += 1900;
305 return "$mday/$mname/$year";
306}
307
308use Getopt::Long;
309
310$DEF_SECTION = 1;
311$DEF_CENTER = "User Contributed Perl Documentation";
312$STD_CENTER = "Perl Programmers Reference Guide";
313$DEF_FIXED = 'CW';
314$DEF_LAX = 0;
315
316sub usage {
317 warn "$0: @_\n" if @_;
318 die <<EOF;
319usage: $0 [options] podpage
320Options are:
321 --section=manext (default "$DEF_SECTION")
322 --release=relpatch (default "$DEF_RELEASE")
323 --center=string (default "$DEF_CENTER")
324 --date=string (default "$DEF_DATE")
325 --fixed=font (default "$DEF_FIXED")
326 --official (default NOT)
327 --lax (default NOT)
328EOF
329}
330
331$uok = GetOptions( qw(
332 section=s
333 release=s
334 center=s
335 date=s
336 fixed=s
337 official
338 lax
339 help));
340
341$DEF_DATE = makedate((stat($ARGV[0]))[9] || time());
342
343usage("Usage error!") unless $uok;
344usage() if $opt_help;
345usage("Need one and only one podpage argument") unless @ARGV == 1;
346
347$section = $opt_section || ($ARGV[0] =~ /\.pm$/
348 ? $DEF_PM_SECTION : $DEF_SECTION);
349$RP = $opt_release || $DEF_RELEASE;
350$center = $opt_center || ($opt_official ? $STD_CENTER : $DEF_CENTER);
351$lax = $opt_lax || $DEF_LAX;
352
353$CFont = $opt_fixed || $DEF_FIXED;
354
355if (length($CFont) == 2) {
356 $CFont_embed = "\\f($CFont";
357}
358elsif (length($CFont) == 1) {
359 $CFont_embed = "\\f$CFont";
360}
361else {
362 die "roff font should be 1 or 2 chars, not `$CFont_embed'";
363}
364
365$date = $opt_date || $DEF_DATE;
366
367for (qw{NAME DESCRIPTION}) {
368# for (qw{NAME DESCRIPTION AUTHOR}) {
369 $wanna_see{$_}++;
370}
371$wanna_see{SYNOPSIS}++ if $section =~ /^3/;
372
373
374$name = @ARGV ? $ARGV[0] : "<STDIN>";
375$Filename = $name;
376if ($section =~ /^1/) {
377 require File::Basename;
378 $name = uc File::Basename::basename($name);
379}
380$name =~ s/\.(pod|p[lm])$//i;
381
382# Lose everything up to the first of
383# */lib/*perl* standard or site_perl module
384# */*perl*/lib from -D prefix=/opt/perl
385# */*perl*/ random module hierarchy
386# which works.
387$name =~ s-//+-/-g;
388if ($name =~ s-^.*?/lib/[^/]*perl[^/]*/--i
389 or $name =~ s-^.*?/[^/]*perl[^/]*/lib/--i
390 or $name =~ s-^.*?/[^/]*perl[^/]*/--i) {
391 # Lose ^site(_perl)?/.
392 $name =~ s-^site(_perl)?/--;
393 # Lose ^arch/. (XXX should we use Config? Just for archname?)
394 $name =~ s~^(.*-$^O|$^O-.*)/~~o;
395 # Lose ^version/.
396 $name =~ s-^\d+\.\d+/--;
397}
398
399# Translate Getopt/Long to Getopt::Long, etc.
400$name =~ s(/)(::)g;
401
402if ($name ne 'something') {
403 FCHECK: {
404 open(F, "< $ARGV[0]") || die "can't open $ARGV[0]: $!";
405 while (<F>) {
406 next unless /^=\b/;
407 if (/^=head1\s+NAME\s*$/) { # an /m would forgive mistakes
408 $_ = <F>;
409 unless (/\s*-+\s+/) {
410 $oops++;
411 warn "$0: Improper man page - no dash in NAME header in paragraph $. of $ARGV[0]\n"
412 } else {
413 my @n = split /\s+-+\s+/;
414 if (@n != 2) {
415 $oops++;
416 warn "$0: Improper man page - malformed NAME header in paragraph $. of $ARGV[0]\n"
417 }
418 else {
419 $n[0] =~ s/\n/ /g;
420 $n[1] =~ s/\n/ /g;
421 %namedesc = @n;
422 }
423 }
424 last FCHECK;
425 }
426 next if /^=cut\b/; # DB_File and Net::Ping have =cut before NAME
427 next if /^=pod\b/; # It is OK to have =pod before NAME
428 next if /^=for\s+comment\b/; # It is OK to have =for comment before NAME
429 die "$0: Invalid man page - 1st pod line is not NAME in $ARGV[0]\n" unless $lax;
430 }
431 die "$0: Invalid man page - no documentation in $ARGV[0]\n" unless $lax;
432 }
433 close F;
434}
435
436print <<"END";
437.rn '' }`
438''' \$RCSfile\$\$Revision\$\$Date\$
439'''
440''' \$Log\$
441'''
442.de Sh
443.br
444.if t .Sp
445.ne 5
446.PP
447\\fB\\\\\$1\\fR
448.PP
449..
450.de Sp
451.if t .sp .5v
452.if n .sp
453..
454.de Ip
455.br
456.ie \\\\n(.\$>=3 .ne \\\\\$3
457.el .ne 3
458.IP "\\\\\$1" \\\\\$2
459..
460.de Vb
461.ft $CFont
462.nf
463.ne \\\\\$1
464..
465.de Ve
466.ft R
467
468.fi
469..
470'''
471'''
472''' Set up \\*(-- to give an unbreakable dash;
473''' string Tr holds user defined translation string.
474''' Bell System Logo is used as a dummy character.
475'''
476.tr \\(*W-|\\(bv\\*(Tr
477.ie n \\{\\
478.ds -- \\(*W-
479.ds PI pi
480.if (\\n(.H=4u)&(1m=24u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-12u'-\\" diablo 10 pitch
481.if (\\n(.H=4u)&(1m=20u) .ds -- \\(*W\\h'-12u'\\(*W\\h'-8u'-\\" diablo 12 pitch
482.ds L" ""
483.ds R" ""
484''' \\*(M", \\*(S", \\*(N" and \\*(T" are the equivalent of
485''' \\*(L" and \\*(R", except that they are used on ".xx" lines,
486''' such as .IP and .SH, which do another additional levels of
487''' double-quote interpretation
488.ds M" """
489.ds S" """
490.ds N" """""
491.ds T" """""
492.ds L' '
493.ds R' '
494.ds M' '
495.ds S' '
496.ds N' '
497.ds T' '
498'br\\}
499.el\\{\\
500.ds -- \\(em\\|
501.tr \\*(Tr
502.ds L" ``
503.ds R" ''
504.ds M" ``
505.ds S" ''
506.ds N" ``
507.ds T" ''
508.ds L' `
509.ds R' '
510.ds M' `
511.ds S' '
512.ds N' `
513.ds T' '
514.ds PI \\(*p
515'br\\}
516END
517
518print <<'END';
519.\" If the F register is turned on, we'll generate
520.\" index entries out stderr for the following things:
521.\" TH Title
522.\" SH Header
523.\" Sh Subsection
524.\" Ip Item
525.\" X<> Xref (embedded
526.\" Of course, you have to process the output yourself
527.\" in some meaninful fashion.
528.if \nF \{
529.de IX
530.tm Index:\\$1\t\\n%\t"\\$2"
531..
532.nr % 0
533.rr F
534.\}
535END
536
537print <<"END";
538.TH $name $section "$RP" "$date" "$center"
539.UC
540END
541
542push(@Indices, qq{.IX Title "$name $section"});
543
544while (($name, $desc) = each %namedesc) {
545 for ($name, $desc) { s/^\s+//; s/\s+$//; }
546 push(@Indices, qq(.IX Name "$name - $desc"\n));
547}
548
549print <<'END';
550.if n .hy 0
551.if n .na
552.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'
553.de CQ \" put $1 in typewriter font
554END
555print ".ft $CFont\n";
556print <<'END';
557'if n "\c
558'if t \\&\\$1\c
559'if n \\&\\$1\c
560'if n \&"
561\\&\\$2 \\$3 \\$4 \\$5 \\$6 \\$7
562'.ft R
563..
564.\" @(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2
565. \" AM - accent mark definitions
566.bd B 3
567. \" fudge factors for nroff and troff
568.if n \{\
569. ds #H 0
570. ds #V .8m
571. ds #F .3m
572. ds #[ \f1
573. ds #] \fP
574.\}
575.if t \{\
576. ds #H ((1u-(\\\\n(.fu%2u))*.13m)
577. ds #V .6m
578. ds #F 0
579. ds #[ \&
580. ds #] \&
581.\}
582. \" simple accents for nroff and troff
583.if n \{\
584. ds ' \&
585. ds ` \&
586. ds ^ \&
587. ds , \&
588. ds ~ ~
589. ds ? ?
590. ds ! !
591. ds /
592. ds q
593.\}
594.if t \{\
595. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u"
596. ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'
597. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'
598. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'
599. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'
600. ds ? \s-2c\h'-\w'c'u*7/10'\u\h'\*(#H'\zi\d\s+2\h'\w'c'u*8/10'
601. ds ! \s-2\(or\s+2\h'-\w'\(or'u'\v'-.8m'.\v'.8m'
602. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'
603. ds q o\h'-\w'o'u*8/10'\s-4\v'.4m'\z\(*i\v'-.4m'\s+4\h'\w'o'u*8/10'
604.\}
605. \" troff and (daisy-wheel) nroff accents
606.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'
607.ds 8 \h'\*(#H'\(*b\h'-\*(#H'
608.ds v \\k:\h'-(\\n(.wu*9/10-\*(#H)'\v'-\*(#V'\*(#[\s-4v\s0\v'\*(#V'\h'|\\n:u'\*(#]
609.ds _ \\k:\h'-(\\n(.wu*9/10-\*(#H+(\*(#F*2/3))'\v'-.4m'\z\(hy\v'.4m'\h'|\\n:u'
610.ds . \\k:\h'-(\\n(.wu*8/10)'\v'\*(#V*4/10'\z.\v'-\*(#V*4/10'\h'|\\n:u'
611.ds 3 \*(#[\v'.2m'\s-2\&3\s0\v'-.2m'\*(#]
612.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#]
613.ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'
614.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'
615.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#]
616.ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#]
617.ds ae a\h'-(\w'a'u*4/10)'e
618.ds Ae A\h'-(\w'A'u*4/10)'E
619.ds oe o\h'-(\w'o'u*4/10)'e
620.ds Oe O\h'-(\w'O'u*4/10)'E
621. \" corrections for vroff
622.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'
623.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'
624. \" for low resolution devices (crt and lpr)
625.if \n(.H>23 .if \n(.V>19 \
626\{\
627. ds : e
628. ds 8 ss
629. ds v \h'-1'\o'\(aa\(ga'
630. ds _ \h'-1'^
631. ds . \h'-1'.
632. ds 3 3
633. ds o a
634. ds d- d\h'-1'\(ga
635. ds D- D\h'-1'\(hy
636. ds th \o'bp'
637. ds Th \o'LP'
638. ds ae ae
639. ds Ae AE
640. ds oe oe
641. ds Oe OE
642.\}
643.rm #[ #] #H #V #F C
644END
645
646$indent = 0;
647
648$begun = "";
649
650# Unrolling [^A-Z>]|[A-Z](?!<) gives: // MRE pp 165.
651my $nonest = '(?:[^A-Z>]*(?:[A-Z](?!<)[^A-Z>]*)*)';
652
653while (<>) {
654 if ($cutting) {
655 next unless /^=/;
656 $cutting = 0;
657 }
658 if ($begun) {
659 if (/^=end\s+$begun/) {
660 $begun = "";
661 }
662 elsif ($begun =~ /^(roff|man)$/) {
663 print STDOUT $_;
664 }
665 next;
666 }
667 chomp;
668
669 # Translate verbatim paragraph
670
671 if (/^\s/) {
672 @lines = split(/\n/);
673 for (@lines) {
674 1 while s
675 {^( [^\t]* ) \t ( \t* ) }
676 { $1 . ' ' x (8 - (length($1)%8) + 8 * (length($2))) }ex;
677 s/\\/\\e/g;
678 s/\A/\\&/s;
679 }
680 $lines = @lines;
681 makespace() unless $verbatim++;
682 print ".Vb $lines\n";
683 print join("\n", @lines), "\n";
684 print ".Ve\n";
685 $needspace = 0;
686 next;
687 }
688
689 $verbatim = 0;
690
691 if (/^=for\s+(\S+)\s*/s) {
692 if ($1 eq "man" or $1 eq "roff") {
693 print STDOUT $',"\n\n";
694 } else {
695 # ignore unknown for
696 }
697 next;
698 }
699 elsif (/^=begin\s+(\S+)\s*/s) {
700 $begun = $1;
701 if ($1 eq "man" or $1 eq "roff") {
702 print STDOUT $'."\n\n";
703 }
704 next;
705 }
706
707 # check for things that'll hosed our noremap scheme; affects $_
708 init_noremap();
709
710 if (!/^=item/) {
711
712 # trofficate backslashes; must do it before what happens below
713 s/\\/noremap('\\e')/ge;
714
715 # protect leading periods and quotes against *roff
716 # mistaking them for directives
717 s/^(?:[A-Z]<)?[.']/\\&$&/gm;
718
719 # first hide the escapes in case we need to
720 # intuit something and get it wrong due to fmting
721
722 1 while s/([A-Z]<$nonest>)/noremap($1)/ge;
723
724 # func() is a reference to a perl function
725 s{
726 \b
727 (
728 [:\w]+ \(\)
729 )
730 } {I<$1>}gx;
731
732 # func(n) is a reference to a perl function or a man page
733 s{
734 ([:\w]+)
735 (
736 \( [^\051]+ \)
737 )
738 } {I<$1>\\|$2}gx;
739
740 # convert simple variable references
741 s/(\s+)([\$\@%][\w:]+)(?!\()/${1}C<$2>/g;
742
743 if (m{ (
744 [\-\w]+
745 \(
746 [^\051]*?
747 [\@\$,]
748 [^\051]*?
749 \)
750 )
751 }x && $` !~ /([LCI]<[^<>]*|-)$/ && !/^=\w/)
752 {
753 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [LCI]<$1>\n";
754 $oops++;
755 }
756
757 while (/(-[a-zA-Z])\b/g && $` !~ /[\w\-]$/) {
758 warn "$0: bad option in paragraph $. of $ARGV: ``$1'' should be [CB]<$1>\n";
759 $oops++;
760 }
761
762 # put it back so we get the <> processed again;
763 clear_noremap(0); # 0 means leave the E's
764
765 } else {
766 # trofficate backslashes
767 s/\\/noremap('\\e')/ge;
768
769 }
770
771 # need to hide E<> first; they're processed in clear_noremap
772 s/(E<[^<>]+>)/noremap($1)/ge;
773
774
775 $maxnest = 10;
776 while ($maxnest-- && /[A-Z]</) {
777
778 # can't do C font here
779 s/([BI])<($nonest)>/font($1) . $2 . font('R')/eg;
780
781 # files and filelike refs in italics
782 s/F<($nonest)>/I<$1>/g;
783
784 # no break -- usually we want C<> for this
785 s/S<($nonest)>/nobreak($1)/eg;
786
787 # LREF: a la HREF L<show this text|man/section>
788 s:L<([^|>]+)\|[^>]+>:$1:g;
789
790 # LREF: a manpage(3f)
791 s:L<([a-zA-Z][^\s\/]+)(\([^\)]+\))?>:the I<$1>$2 manpage:g;
792
793 # LREF: an =item on another manpage
794 s{
795 L<
796 ([^/]+)
797 /
798 (
799 [:\w]+
800 (\(\))?
801 )
802 >
803 } {the C<$2> entry in the I<$1> manpage}gx;
804
805 # LREF: an =item on this manpage
806 s{
807 ((?:
808 L<
809 /
810 (
811 [:\w]+
812 (\(\))?
813 )
814 >
815 (,?\s+(and\s+)?)?
816 )+)
817 } { internal_lrefs($1) }gex;
818
819 # LREF: a =head2 (head1?), maybe on a manpage, maybe right here
820 # the "func" can disambiguate
821 s{
822 L<
823 (?:
824 ([a-zA-Z]\S+?) /
825 )?
826 "?(.*?)"?
827 >
828 }{
829 do {
830 $1 # if no $1, assume it means on this page.
831 ? "the section on I<$2> in the I<$1> manpage"
832 : "the section on I<$2>"
833 }
834 }gesx; # s in case it goes over multiple lines, so . matches \n
835
836 s/Z<>/\\&/g;
837
838 # comes last because not subject to reprocessing
839 s/C<($nonest)>/noremap("${CFont_embed}${1}\\fR")/eg;
840 }
841
842 if (s/^=//) {
843 $needspace = 0; # Assume this.
844
845 s/\n/ /g;
846
847 ($Cmd, $_) = split(' ', $_, 2);
848
849 $dotlevel = 1;
850 if ($Cmd eq 'head1') {
851 $dotlevel = 1;
852 }
853 elsif ($Cmd eq 'head2') {
854 $dotlevel = 1;
855 }
856 elsif ($Cmd eq 'item') {
857 $dotlevel = 2;
858 }
859
860 if (defined $_) {
861 &escapes($dotlevel);
862 s/"/""/g;
863 }
864
865 clear_noremap(1);
866
867 if ($Cmd eq 'cut') {
868 $cutting = 1;
869 }
870 elsif ($Cmd eq 'head1') {
871 s/\s+$//;
872 delete $wanna_see{$_} if exists $wanna_see{$_};
873 print qq{.SH "$_"\n};
874 push(@Indices, qq{.IX Header "$_"\n});
875 }
876 elsif ($Cmd eq 'head2') {
877 print qq{.Sh "$_"\n};
878 push(@Indices, qq{.IX Subsection "$_"\n});
879 }
880 elsif ($Cmd eq 'over') {
881 push(@indent,$indent);
882 $indent += ($_ + 0) || 5;
883 }
884 elsif ($Cmd eq 'back') {
885 $indent = pop(@indent);
886 warn "$0: Unmatched =back in paragraph $. of $ARGV\n" unless defined $indent;
887 $needspace = 1;
888 }
889 elsif ($Cmd eq 'item') {
890 s/^\*( |$)/\\(bu$1/g;
891 # if you know how to get ":s please do
892 s/\\\*\(L"([^"]+?)\\\*\(R"/'$1'/g;
893 s/\\\*\(L"([^"]+?)""/'$1'/g;
894 s/[^"]""([^"]+?)""[^"]/'$1'/g;
895 # here do something about the $" in perlvar?
896 print STDOUT qq{.Ip "$_" $indent\n};
897 push(@Indices, qq{.IX Item "$_"\n});
898 }
899 elsif ($Cmd eq 'pod') {
900 # this is just a comment
901 }
902 else {
903 warn "$0: Unrecognized pod directive in paragraph $. of $ARGV: $Cmd\n";
904 }
905 }
906 else {
907 if ($needspace) {
908 &makespace;
909 }
910 &escapes(0);
911 clear_noremap(1);
912 print $_, "\n";
913 $needspace = 1;
914 }
915}
916
917print <<"END";
918
919.rn }` ''
920END
921
922if (%wanna_see && !$lax) {
923 @missing = keys %wanna_see;
924 warn "$0: $Filename is missing required section"
925 . (@missing > 1 && "s")
926 . ": @missing\n";
927 $oops++;
928}
929
930foreach (@Indices) { print "$_\n"; }
931
932exit;
933#exit ($oops != 0);
934
935#########################################################################
936
937sub nobreak {
938 my $string = shift;
939 $string =~ s/ /\\ /g;
940 $string;
941}
942
943sub escapes {
944 my $indot = shift;
945
946 s/X<(.*?)>/mkindex($1)/ge;
947
948 # translate the minus in foo-bar into foo\-bar for roff
949 s/([^0-9a-z-])-([^-])/$1\\-$2/g;
950
951 # make -- into the string version \*(-- (defined above)
952 s/\b--\b/\\*(--/g;
953 s/"--([^"])/"\\*(--$1/g; # should be a better way
954 s/([^"])--"/$1\\*(--"/g;
955
956 # fix up quotes; this is somewhat tricky
957 my $dotmacroL = 'L';
958 my $dotmacroR = 'R';
959 if ( $indot == 1 ) {
960 $dotmacroL = 'M';
961 $dotmacroR = 'S';
962 }
963 elsif ( $indot >= 2 ) {
964 $dotmacroL = 'N';
965 $dotmacroR = 'T';
966 }
967 if (!/""/) {
968 s/(^|\s)(['"])/noremap("$1\\*($dotmacroL$2")/ge;
969 s/(['"])($|[\-\s,;\\!?.])/noremap("\\*($dotmacroR$1$2")/ge;
970 }
971
972 #s/(?!")(?:.)--(?!")(?:.)/\\*(--/g;
973 #s/(?:(?!")(?:.)--(?:"))|(?:(?:")--(?!")(?:.))/\\*(--/g;
974
975
976 # make sure that func() keeps a bit a space tween the parens
977 ### s/\b\(\)/\\|()/g;
978 ### s/\b\(\)/(\\|)/g;
979
980 # make C++ into \*C+, which is a squinched version (defined above)
981 s/\bC\+\+/\\*(C+/g;
982
983 # make double underbars have a little tiny space between them
984 s/__/_\\|_/g;
985
986 # PI goes to \*(PI (defined above)
987 s/\bPI\b/noremap('\\*(PI')/ge;
988
989 # make all caps a teeny bit smaller, but don't muck with embedded code literals
990 my $hidCFont = font('C');
991 if ($Cmd !~ /^head1/) { # SH already makes smaller
992 # /g isn't enough; 1 while or we'll be off
993
994# 1 while s{
995# (?!$hidCFont)(..|^.|^)
996# \b
997# (
998# [A-Z][\/A-Z+:\-\d_$.]+
999# )
1000# (s?)
1001# \b
1002# } {$1\\s-1$2\\s0}gmox;
1003
1004 1 while s{
1005 (?!$hidCFont)(..|^.|^)
1006 (
1007 \b[A-Z]{2,}[\/A-Z+:\-\d_\$]*\b
1008 )
1009 } {
1010 $1 . noremap( '\\s-1' . $2 . '\\s0' )
1011 }egmox;
1012
1013 }
1014}
1015
1016# make troff just be normal, but make small nroff get quoted
1017# decided to just put the quotes in the text; sigh;
1018sub ccvt {
1019 local($_,$prev) = @_;
1020 noremap(qq{.CQ "$_" \n\\&});
1021}
1022
1023sub makespace {
1024 if ($indent) {
1025 print ".Sp\n";
1026 }
1027 else {
1028 print ".PP\n";
1029 }
1030}
1031
1032sub mkindex {
1033 my ($entry) = @_;
1034 my @entries = split m:\s*/\s*:, $entry;
1035 push @Indices, ".IX Xref " . join ' ', map {qq("$_")} @entries;
1036 return '';
1037}
1038
1039sub font {
1040 local($font) = shift;
1041 return '\\f' . noremap($font);
1042}
1043
1044sub noremap {
1045 local($thing_to_hide) = shift;
1046 $thing_to_hide =~ tr/\000-\177/\200-\377/;
1047 return $thing_to_hide;
1048}
1049
1050sub init_noremap {
1051 # escape high bit characters in input stream
1052 s/([\200-\377])/"E<".ord($1).">"/ge;
1053}
1054
1055sub clear_noremap {
1056 my $ready_to_print = $_[0];
1057
1058 tr/\200-\377/\000-\177/;
1059
1060 # trofficate backslashes
1061 # s/(?!\\e)(?:..|^.|^)\\/\\e/g;
1062
1063 # now for the E<>s, which have been hidden until now
1064 # otherwise the interative \w<> processing would have
1065 # been hosed by the E<gt>
1066 s {
1067 E<
1068 (
1069 ( \d + )
1070 | ( [A-Za-z]+ )
1071 )
1072 >
1073 } {
1074 do {
1075 defined $2
1076 ? chr($2)
1077 :
1078 exists $HTML_Escapes{$3}
1079 ? do { $HTML_Escapes{$3} }
1080 : do {
1081 warn "$0: Unknown escape in paragraph $. of $ARGV: ``$&''\n";
1082 "E<$1>";
1083 }
1084 }
1085 }egx if $ready_to_print;
1086}
1087
1088sub internal_lrefs {
1089 local($_) = shift;
1090 local $trailing_and = s/and\s+$// ? "and " : "";
1091
1092 s{L</([^>]+)>}{$1}g;
1093 my(@items) = split( /(?:,?\s+(?:and\s+)?)/ );
1094 my $retstr = "the ";
1095 my $i;
1096 for ($i = 0; $i <= $#items; $i++) {
1097 $retstr .= "C<$items[$i]>";
1098 $retstr .= ", " if @items > 2 && $i != $#items;
1099 $retstr .= " and " if $i+2 == @items;
1100 }
1101
1102 $retstr .= " entr" . ( @items > 1 ? "ies" : "y" )
1103 . " elsewhere in this document";
1104 # terminal space to avoid words running together (pattern used
1105 # strips terminal spaces)
1106 $retstr .= " " if length $trailing_and;
1107 $retstr .= $trailing_and;
1108
1109 return $retstr;
1110
1111}
1112
1113BEGIN {
1114%HTML_Escapes = (
1115 'amp' => '&', # ampersand
1116 'lt' => '<', # left chevron, less-than
1117 'gt' => '>', # right chevron, greater-than
1118 'quot' => '"', # double quote
1119
1120 "Aacute" => "A\\*'", # capital A, acute accent
1121 "aacute" => "a\\*'", # small a, acute accent
1122 "Acirc" => "A\\*^", # capital A, circumflex accent
1123 "acirc" => "a\\*^", # small a, circumflex accent
1124 "AElig" => '\*(AE', # capital AE diphthong (ligature)
1125 "aelig" => '\*(ae', # small ae diphthong (ligature)
1126 "Agrave" => "A\\*`", # capital A, grave accent
1127 "agrave" => "A\\*`", # small a, grave accent
1128 "Aring" => 'A\\*o', # capital A, ring
1129 "aring" => 'a\\*o', # small a, ring
1130 "Atilde" => 'A\\*~', # capital A, tilde
1131 "atilde" => 'a\\*~', # small a, tilde
1132 "Auml" => 'A\\*:', # capital A, dieresis or umlaut mark
1133 "auml" => 'a\\*:', # small a, dieresis or umlaut mark
1134 "Ccedil" => 'C\\*,', # capital C, cedilla
1135 "ccedil" => 'c\\*,', # small c, cedilla
1136 "Eacute" => "E\\*'", # capital E, acute accent
1137 "eacute" => "e\\*'", # small e, acute accent
1138 "Ecirc" => "E\\*^", # capital E, circumflex accent
1139 "ecirc" => "e\\*^", # small e, circumflex accent
1140 "Egrave" => "E\\*`", # capital E, grave accent
1141 "egrave" => "e\\*`", # small e, grave accent
1142 "ETH" => '\\*(D-', # capital Eth, Icelandic
1143 "eth" => '\\*(d-', # small eth, Icelandic
1144 "Euml" => "E\\*:", # capital E, dieresis or umlaut mark
1145 "euml" => "e\\*:", # small e, dieresis or umlaut mark
1146 "Iacute" => "I\\*'", # capital I, acute accent
1147 "iacute" => "i\\*'", # small i, acute accent
1148 "Icirc" => "I\\*^", # capital I, circumflex accent
1149 "icirc" => "i\\*^", # small i, circumflex accent
1150 "Igrave" => "I\\*`", # capital I, grave accent
1151 "igrave" => "i\\*`", # small i, grave accent
1152 "Iuml" => "I\\*:", # capital I, dieresis or umlaut mark
1153 "iuml" => "i\\*:", # small i, dieresis or umlaut mark
1154 "Ntilde" => 'N\*~', # capital N, tilde
1155 "ntilde" => 'n\*~', # small n, tilde
1156 "Oacute" => "O\\*'", # capital O, acute accent
1157 "oacute" => "o\\*'", # small o, acute accent
1158 "Ocirc" => "O\\*^", # capital O, circumflex accent
1159 "ocirc" => "o\\*^", # small o, circumflex accent
1160 "Ograve" => "O\\*`", # capital O, grave accent
1161 "ograve" => "o\\*`", # small o, grave accent
1162 "Oslash" => "O\\*/", # capital O, slash
1163 "oslash" => "o\\*/", # small o, slash
1164 "Otilde" => "O\\*~", # capital O, tilde
1165 "otilde" => "o\\*~", # small o, tilde
1166 "Ouml" => "O\\*:", # capital O, dieresis or umlaut mark
1167 "ouml" => "o\\*:", # small o, dieresis or umlaut mark
1168 "szlig" => '\*8', # small sharp s, German (sz ligature)
1169 "THORN" => '\\*(Th', # capital THORN, Icelandic
1170 "thorn" => '\\*(th',, # small thorn, Icelandic
1171 "Uacute" => "U\\*'", # capital U, acute accent
1172 "uacute" => "u\\*'", # small u, acute accent
1173 "Ucirc" => "U\\*^", # capital U, circumflex accent
1174 "ucirc" => "u\\*^", # small u, circumflex accent
1175 "Ugrave" => "U\\*`", # capital U, grave accent
1176 "ugrave" => "u\\*`", # small u, grave accent
1177 "Uuml" => "U\\*:", # capital U, dieresis or umlaut mark
1178 "uuml" => "u\\*:", # small u, dieresis or umlaut mark
1179 "Yacute" => "Y\\*'", # capital Y, acute accent
1180 "yacute" => "y\\*'", # small y, acute accent
1181 "yuml" => "y\\*:", # small y, dieresis or umlaut mark
1182);
1183}
1184
diff --git a/src/lib/libcrypto/util/pod2mantest b/src/lib/libcrypto/util/pod2mantest
new file mode 100644
index 0000000000..384e683df4
--- /dev/null
+++ b/src/lib/libcrypto/util/pod2mantest
@@ -0,0 +1,58 @@
1#!/bin/sh
2
3# This script is used by test/Makefile to check whether a sane 'pod2man'
4# is installed.
5# ('make install' should not try to run 'pod2man' if it does not exist or if
6# it is a broken 'pod2man' version that is known to cause trouble. if we find
7# the system 'pod2man' to be broken, we use our own copy instead)
8#
9# In any case, output an appropriate command line for running (or not
10# running) pod2man.
11
12
13IFS=:
14if test "$OSTYPE" = "msdosdjgpp"; then IFS=";"; fi
15
16try_without_dir=true
17# First we try "pod2man", then "$dir/pod2man" for each item in $PATH.
18for dir in dummy${IFS}$PATH; do
19 if [ "$try_without_dir" = true ]; then
20 # first iteration
21 pod2man=pod2man
22 try_without_dir=false
23 else
24 # second and later iterations
25 pod2man="$dir/pod2man"
26 if [ ! -f "$pod2man" ]; then # '-x' is not available on Ultrix
27 pod2man=''
28 fi
29 fi
30
31 if [ ! "$pod2man" = '' ]; then
32 failure=none
33
34 if "$pod2man" --section=1 --center=OpenSSL --release=dev pod2mantest.pod | fgrep OpenSSL >/dev/null; then
35 :
36 else
37 failure=BasicTest
38 fi
39
40 if [ "$failure" = none ]; then
41 if "$pod2man" --section=1 --center=OpenSSL --release=dev pod2mantest.pod | grep '^MARKER - ' >/dev/null; then
42 failure=MultilineTest
43 fi
44 fi
45
46
47 if [ "$failure" = none ]; then
48 echo "$pod2man"
49 exit 0
50 fi
51
52 echo "$pod2man does not work properly ('$failure' failed). Looking for another pod2man ..." >&2
53 fi
54done
55
56echo "No working pod2man found. Consider installing a new version." >&2
57echo "As a workaround, we'll use a bundled old copy of pod2man.pl." >&2
58echo "$1 ../../util/pod2man.pl"
diff --git a/src/lib/libcrypto/util/pod2mantest.pod b/src/lib/libcrypto/util/pod2mantest.pod
new file mode 100644
index 0000000000..5d2539a17f
--- /dev/null
+++ b/src/lib/libcrypto/util/pod2mantest.pod
@@ -0,0 +1,15 @@
1=pod
2
3=head1 NAME
4
5foo, bar,
6MARKER - test of multiline name section
7
8=head1 DESCRIPTION
9
10This is a test .pod file to see if we have a buggy pod2man or not.
11If we have a buggy implementation, we will get a line matching the
12regular expression "^ +MARKER - test of multiline name section *$"
13at the end of the resulting document.
14
15=cut
diff --git a/src/lib/libcrypto/util/point.sh b/src/lib/libcrypto/util/point.sh
new file mode 100644
index 0000000000..4790e08f8a
--- /dev/null
+++ b/src/lib/libcrypto/util/point.sh
@@ -0,0 +1,10 @@
1#!/bin/sh
2
3rm -f "$2"
4if test "$OSTYPE" = msdosdjgpp; then
5 cp "$1" "$2"
6else
7 ln -s "$1" "$2"
8fi
9echo "$2 => $1"
10
diff --git a/src/lib/libcrypto/util/selftest.pl b/src/lib/libcrypto/util/selftest.pl
new file mode 100644
index 0000000000..4778c5ab01
--- /dev/null
+++ b/src/lib/libcrypto/util/selftest.pl
@@ -0,0 +1,201 @@
1#!/usr/local/bin/perl -w
2#
3# Run the test suite and generate a report
4#
5
6if (! -f "Configure") {
7 print "Please run perl util/selftest.pl in the OpenSSL directory.\n";
8 exit 1;
9}
10
11my $report="testlog";
12my $os="??";
13my $version="??";
14my $platform0="??";
15my $platform="??";
16my $options="??";
17my $last="??";
18my $ok=0;
19my $cc="cc";
20my $cversion="??";
21my $sep="-----------------------------------------------------------------------------\n";
22my $not_our_fault="\nPlease ask your system administrator/vendor for more information.\n[Problems with your operating system setup should not be reported\nto the OpenSSL project.]\n";
23
24open(OUT,">$report") or die;
25
26print OUT "OpenSSL self-test report:\n\n";
27
28$uname=`uname -a`;
29$uname="??\n" if $uname eq "";
30
31$c=`sh config -t`;
32foreach $_ (split("\n",$c)) {
33 $os=$1 if (/Operating system: (.*)$/);
34 $platform0=$1 if (/Configuring for (.*)$/);
35}
36
37system "sh config" if (! -f "Makefile");
38
39if (open(IN,"<Makefile")) {
40 while (<IN>) {
41 $version=$1 if (/^VERSION=(.*)$/);
42 $platform=$1 if (/^PLATFORM=(.*)$/);
43 $options=$1 if (/^OPTIONS=(.*)$/);
44 $cc=$1 if (/^CC= *(.*)$/);
45 }
46 close(IN);
47} else {
48 print OUT "Error running config!\n";
49}
50
51$cversion=`$cc -v 2>&1`;
52$cversion=`$cc -V 2>&1` if $cversion =~ "[Uu]sage";
53$cversion=`$cc -V |head -1` if $cversion =~ "Error";
54$cversion=`$cc --version` if $cversion eq "";
55$cversion =~ s/Reading specs.*\n//;
56$cversion =~ s/usage.*\n//;
57chomp $cversion;
58
59if (open(IN,"<CHANGES")) {
60 while(<IN>) {
61 if (/\*\) (.{0,55})/ && !/applies to/) {
62 $last=$1;
63 last;
64 }
65 }
66 close(IN);
67}
68
69print OUT "OpenSSL version: $version\n";
70print OUT "Last change: $last...\n";
71print OUT "Options: $options\n" if $options ne "";
72print OUT "OS (uname): $uname";
73print OUT "OS (config): $os\n";
74print OUT "Target (default): $platform0\n";
75print OUT "Target: $platform\n";
76print OUT "Compiler: $cversion\n";
77print OUT "\n";
78
79print "Checking compiler...\n";
80if (open(TEST,">cctest.c")) {
81 print TEST "#include <stdio.h>\n#include <errno.h>\nmain(){printf(\"Hello world\\n\");}\n";
82 close(TEST);
83 system("$cc -o cctest cctest.c");
84 if (`./cctest` !~ /Hello world/) {
85 print OUT "Compiler doesn't work.\n";
86 print OUT $not_our_fault;
87 goto err;
88 }
89 system("ar r cctest.a /dev/null");
90 if (not -f "cctest.a") {
91 print OUT "Check your archive tool (ar).\n";
92 print OUT $not_our_fault;
93 goto err;
94 }
95} else {
96 print OUT "Can't create cctest.c\n";
97}
98if (open(TEST,">cctest.c")) {
99 print TEST "#include <openssl/opensslv.h>\nmain(){printf(OPENSSL_VERSION_TEXT);}\n";
100 close(TEST);
101 system("$cc -o cctest -Iinclude cctest.c");
102 $cctest = `./cctest`;
103 if ($cctest !~ /OpenSSL $version/) {
104 if ($cctest =~ /OpenSSL/) {
105 print OUT "#include uses headers from different OpenSSL version!\n";
106 } else {
107 print OUT "Can't compile test program!\n";
108 }
109 print OUT $not_our_fault;
110 goto err;
111 }
112} else {
113 print OUT "Can't create cctest.c\n";
114}
115
116print "Running make...\n";
117if (system("make 2>&1 | tee make.log") > 255) {
118
119 print OUT "make failed!\n";
120 if (open(IN,"<make.log")) {
121 print OUT $sep;
122 while (<IN>) {
123 print OUT;
124 }
125 close(IN);
126 print OUT $sep;
127 } else {
128 print OUT "make.log not found!\n";
129 }
130 goto err;
131}
132
133# Not sure why this is here. The tests themselves can detect if their
134# particular feature isn't included, and should therefore skip themselves.
135# To skip *all* tests just because one algorithm isn't included is like
136# shooting mosquito with an elephant gun...
137# -- Richard Levitte, inspired by problem report 1089
138#
139#$_=$options;
140#s/no-asm//;
141#s/no-shared//;
142#s/no-krb5//;
143#if (/no-/)
144#{
145# print OUT "Test skipped.\n";
146# goto err;
147#}
148
149print "Running make test...\n";
150if (system("make test 2>&1 | tee maketest.log") > 255)
151 {
152 print OUT "make test failed!\n";
153} else {
154 $ok=1;
155}
156
157if ($ok and open(IN,"<maketest.log")) {
158 while (<IN>) {
159 $ok=2 if /^platform: $platform/;
160 }
161 close(IN);
162}
163
164if ($ok != 2) {
165 print OUT "Failure!\n";
166 if (open(IN,"<make.log")) {
167 print OUT $sep;
168 while (<IN>) {
169 print OUT;
170 }
171 close(IN);
172 print OUT $sep;
173 } else {
174 print OUT "make.log not found!\n";
175 }
176 if (open(IN,"<maketest.log")) {
177 while (<IN>) {
178 print OUT;
179 }
180 close(IN);
181 print OUT $sep;
182 } else {
183 print OUT "maketest.log not found!\n";
184 }
185} else {
186 print OUT "Test passed.\n";
187}
188err:
189close(OUT);
190
191print "\n";
192open(IN,"<$report") or die;
193while (<IN>) {
194 if (/$sep/) {
195 print "[...]\n";
196 last;
197 }
198 print;
199}
200print "\nTest report in file $report\n";
201
diff --git a/src/lib/libcrypto/util/shlib_wrap.sh b/src/lib/libcrypto/util/shlib_wrap.sh
new file mode 100755
index 0000000000..a2f62d696f
--- /dev/null
+++ b/src/lib/libcrypto/util/shlib_wrap.sh
@@ -0,0 +1,91 @@
1#!/bin/sh
2
3[ $# -ne 0 ] || set -x # debug mode without arguments:-)
4
5THERE="`echo $0 | sed -e 's|[^/]*$||' 2>/dev/null`.."
6[ -d "${THERE}" ] || exec "$@" # should never happen...
7
8# Alternative to this is to parse ${THERE}/Makefile...
9LIBCRYPTOSO="${THERE}/libcrypto.so"
10if [ -f "$LIBCRYPTOSO" ]; then
11 while [ -h "$LIBCRYPTOSO" ]; do
12 LIBCRYPTOSO="${THERE}/`ls -l "$LIBCRYPTOSO" | sed -e 's|.*\-> ||'`"
13 done
14 SOSUFFIX=`echo ${LIBCRYPTOSO} | sed -e 's|.*\.so||' 2>/dev/null`
15 LIBSSLSO="${THERE}/libssl.so${SOSUFFIX}"
16fi
17
18SYSNAME=`(uname -s) 2>/dev/null`;
19case "$SYSNAME" in
20SunOS|IRIX*)
21 # SunOS and IRIX run-time linkers evaluate alternative
22 # variables depending on target ABI...
23 rld_var=LD_LIBRARY_PATH
24 case "`(/usr/bin/file "$LIBCRYPTOSO") 2>/dev/null`" in
25 *ELF\ 64*SPARC*|*ELF\ 64*AMD64*)
26 [ -n "$LD_LIBRARY_PATH_64" ] && rld_var=LD_LIBRARY_PATH_64
27 LD_PRELOAD_64="$LIBCRYPTOSO $LIBSSLSO"; export LD_PRELOAD_64
28 preload_var=LD_PRELOAD_64
29 ;;
30 # Why are newly built .so's preloaded anyway? Because run-time
31 # .so lookup path embedded into application takes precedence
32 # over LD_LIBRARY_PATH and as result application ends up linking
33 # to previously installed .so's. On IRIX instead of preloading
34 # newly built .so's we trick run-time linker to fail to find
35 # the installed .so by setting _RLD_ROOT variable.
36 *ELF\ 32*MIPS*)
37 #_RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD_LIST
38 _RLD_ROOT=/no/such/dir; export _RLD_ROOT
39 eval $rld_var=\"/usr/lib'${'$rld_var':+:$'$rld_var'}'\"
40 preload_var=_RLD_LIST
41 ;;
42 *ELF\ N32*MIPS*)
43 [ -n "$LD_LIBRARYN32_PATH" ] && rld_var=LD_LIBRARYN32_PATH
44 #_RLDN32_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLDN32_LIST
45 _RLDN32_ROOT=/no/such/dir; export _RLDN32_ROOT
46 eval $rld_var=\"/usr/lib32'${'$rld_var':+:$'$rld_var'}'\"
47 preload_var=_RLDN32_LIST
48 ;;
49 *ELF\ 64*MIPS*)
50 [ -n "$LD_LIBRARY64_PATH" ] && rld_var=LD_LIBRARY64_PATH
51 #_RLD64_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT"; export _RLD64_LIST
52 _RLD64_ROOT=/no/such/dir; export _RLD64_ROOT
53 eval $rld_var=\"/usr/lib64'${'$rld_var':+:$'$rld_var'}'\"
54 preload_var=_RLD64_LIST
55 ;;
56 esac
57 eval $rld_var=\"${THERE}'${'$rld_var':+:$'$rld_var'}'\"; export $rld_var
58 unset rld_var
59 ;;
60*) LD_LIBRARY_PATH="${THERE}:$LD_LIBRARY_PATH" # Linux, ELF HP-UX
61 DYLD_LIBRARY_PATH="${THERE}:$DYLD_LIBRARY_PATH" # MacOS X
62 SHLIB_PATH="${THERE}:$SHLIB_PATH" # legacy HP-UX
63 LIBPATH="${THERE}:$LIBPATH" # AIX, OS/2
64 export LD_LIBRARY_PATH DYLD_LIBRARY_PATH SHLIB_PATH LIBPATH
65 # Even though $PATH is adjusted [for Windows sake], it doesn't
66 # necessarily does the trick. Trouble is that with introduction
67 # of SafeDllSearchMode in XP/2003 it's more appropriate to copy
68 # .DLLs in vicinity of executable, which is done elsewhere...
69 if [ "$OSTYPE" != msdosdjgpp ]; then
70 PATH="${THERE}:$PATH"; export PATH
71 fi
72 ;;
73esac
74
75if [ -f "$LIBCRYPTOSO" -a -z "$preload_var" ]; then
76 # Following three lines are major excuse for isolating them into
77 # this wrapper script. Original reason for setting LD_PRELOAD
78 # was to make it possible to pass 'make test' when user linked
79 # with -rpath pointing to previous version installation. Wrapping
80 # it into a script makes it possible to do so on multi-ABI
81 # platforms.
82 case "$SYSNAME" in
83 *BSD) LD_PRELOAD="$LIBCRYPTOSO:$LIBSSLSO" ;; # *BSD
84 *) LD_PRELOAD="$LIBCRYPTOSO $LIBSSLSO" ;; # SunOS, Linux, ELF HP-UX
85 esac
86 _RLD_LIST="$LIBCRYPTOSO:$LIBSSLSO:DEFAULT" # Tru64, o32 IRIX
87 DYLD_INSERT_LIBRARIES="$LIBCRYPTOSO:$LIBSSLSO" # MacOS X
88 export LD_PRELOAD _RLD_LIST DYLD_INSERT_LIBRARIES
89fi
90
91exec "$@"
diff --git a/src/lib/libcrypto/util/sp-diff.pl b/src/lib/libcrypto/util/sp-diff.pl
new file mode 100644
index 0000000000..9d6c60387f
--- /dev/null
+++ b/src/lib/libcrypto/util/sp-diff.pl
@@ -0,0 +1,80 @@
1#!/usr/local/bin/perl
2#
3# This file takes as input, the files that have been output from
4# ssleay speed.
5# It prints a table of the relative differences with %100 being 'no difference'
6#
7
8($#ARGV == 1) || die "$0 speedout1 speedout2\n";
9
10%one=&loadfile($ARGV[0]);
11%two=&loadfile($ARGV[1]);
12
13$line=0;
14foreach $a ("md2","md4","md5","sha","sha1","rc4","des cfb","des cbc","des ede3",
15 "idea cfb","idea cbc","rc2 cfb","rc2 cbc","blowfish cbc","cast cbc")
16 {
17 if (defined($one{$a,8}) && defined($two{$a,8}))
18 {
19 print "type 8 byte% 64 byte% 256 byte% 1024 byte% 8192 byte%\n"
20 unless $line;
21 $line++;
22 printf "%-12s ",$a;
23 foreach $b (8,64,256,1024,8192)
24 {
25 $r=$two{$a,$b}/$one{$a,$b}*100;
26 printf "%12.2f",$r;
27 }
28 print "\n";
29 }
30 }
31
32foreach $a (
33 "rsa 512","rsa 1024","rsa 2048","rsa 4096",
34 "dsa 512","dsa 1024","dsa 2048",
35 )
36 {
37 if (defined($one{$a,1}) && defined($two{$a,1}))
38 {
39 $r1=($one{$a,1}/$two{$a,1})*100;
40 $r2=($one{$a,2}/$two{$a,2})*100;
41 printf "$a bits %% %6.2f %% %6.2f\n",$r1,$r2;
42 }
43 }
44
45sub loadfile
46 {
47 local($file)=@_;
48 local($_,%ret);
49
50 open(IN,"<$file") || die "unable to open '$file' for input\n";
51 $header=1;
52 while (<IN>)
53 {
54 $header=0 if /^[dr]sa/;
55 if (/^type/) { $header=0; next; }
56 next if $header;
57 chop;
58 @a=split;
59 if ($a[0] =~ /^[dr]sa$/)
60 {
61 ($n,$t1,$t2)=($_ =~ /^([dr]sa\s+\d+)\s+bits\s+([.\d]+)s\s+([.\d]+)/);
62 $ret{$n,1}=$t1;
63 $ret{$n,2}=$t2;
64 }
65 else
66 {
67 $n=join(' ',grep(/[^k]$/,@a));
68 @k=grep(s/k$//,@a);
69
70 $ret{$n, 8}=$k[0];
71 $ret{$n, 64}=$k[1];
72 $ret{$n, 256}=$k[2];
73 $ret{$n,1024}=$k[3];
74 $ret{$n,8192}=$k[4];
75 }
76 }
77 close(IN);
78 return(%ret);
79 }
80
diff --git a/src/lib/libcrypto/util/speed.sh b/src/lib/libcrypto/util/speed.sh
new file mode 100644
index 0000000000..f489706197
--- /dev/null
+++ b/src/lib/libcrypto/util/speed.sh
@@ -0,0 +1,39 @@
1#!/bin/sh
2
3#
4# This is a ugly script use, in conjuction with editing the 'b'
5# configuration in the $(TOP)/Configure script which will
6# output when finished a file called speed.log which is the
7# timings of SSLeay with various options turned on or off.
8#
9# from the $(TOP) directory
10# Edit Configure, modifying things to do with the b/bl-4c-2c etc
11# configurations.
12#
13
14make clean
15perl Configure b
16make
17apps/ssleay version -v -b -f >speed.1
18apps/ssleay speed >speed.1l
19
20perl Configure bl-4c-2c
21/bin/rm -f crypto/rc4/*.o crypto/bn/bn*.o crypto/md2/md2_dgst.o
22make
23apps/ssleay speed rc4 rsa md2 >speed.2l
24
25perl Configure bl-4c-ri
26/bin/rm -f crypto/rc4/rc4*.o
27make
28apps/ssleay speed rc4 >speed.3l
29
30perl Configure b2-is-ri-dp
31/bin/rm -f crypto/idea/i_*.o crypto/rc4/*.o crypto/des/ecb_enc.o crypto/bn/bn*.o
32apps/ssleay speed rsa rc4 idea des >speed.4l
33
34cat speed.1 >speed.log
35cat speed.1l >>speed.log
36perl util/sp-diff.pl speed.1l speed.2l >>speed.log
37perl util/sp-diff.pl speed.1l speed.3l >>speed.log
38perl util/sp-diff.pl speed.1l speed.4l >>speed.log
39
diff --git a/src/lib/libcrypto/util/src-dep.pl b/src/lib/libcrypto/util/src-dep.pl
new file mode 100644
index 0000000000..ad997e4746
--- /dev/null
+++ b/src/lib/libcrypto/util/src-dep.pl
@@ -0,0 +1,147 @@
1#!/usr/local/bin/perl
2
3# we make up an array of
4# $file{function_name}=filename;
5# $unres{filename}="func1 func2 ...."
6$debug=1;
7#$nm_func="parse_linux";
8$nm_func="parse_solaris";
9
10foreach (@ARGV)
11 {
12 &$nm_func($_);
13 }
14
15foreach $file (sort keys %unres)
16 {
17 @a=split(/\s+/,$unres{$file});
18 %ff=();
19 foreach $func (@a)
20 {
21 $f=$file{$func};
22 $ff{$f}=1 if $f ne "";
23 }
24
25 foreach $a (keys %ff)
26 { $we_need{$file}.="$a "; }
27 }
28
29foreach $file (sort keys %we_need)
30 {
31# print " $file $we_need{$file}\n";
32 foreach $bit (split(/\s+/,$we_need{$file}))
33 { push(@final,&walk($bit)); }
34
35 foreach (@final) { $fin{$_}=1; }
36 @final="";
37 foreach (sort keys %fin)
38 { push(@final,$_); }
39
40 print "$file: @final\n";
41 }
42
43sub walk
44 {
45 local($f)=@_;
46 local(@a,%seen,@ret,$r);
47
48 @ret="";
49 $f =~ s/^\s+//;
50 $f =~ s/\s+$//;
51 return "" if ($f =~ "^\s*$");
52
53 return(split(/\s/,$done{$f})) if defined ($done{$f});
54
55 return if $in{$f} > 0;
56 $in{$f}++;
57 push(@ret,$f);
58 foreach $r (split(/\s+/,$we_need{$f}))
59 {
60 push(@ret,&walk($r));
61 }
62 $in{$f}--;
63 $done{$f}=join(" ",@ret);
64 return(@ret);
65 }
66
67sub parse_linux
68 {
69 local($name)=@_;
70
71 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
72 while (<IN>)
73 {
74 chop;
75 next if /^\s*$/;
76 if (/^[^[](.*):$/)
77 {
78 $file=$1;
79 $file="$1.c" if /\[(.*).o\]/;
80 print STDERR "$file\n";
81 $we_need{$file}=" ";
82 next;
83 }
84
85 @a=split(/\s*\|\s*/);
86 next unless $#a == 7;
87 next unless $a[4] eq "GLOB";
88 if ($a[6] eq "UNDEF")
89 {
90 $unres{$file}.=$a[7]." ";
91 }
92 else
93 {
94 if ($file{$a[7]} ne "")
95 {
96 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
97 }
98 else
99 {
100 $file{$a[7]}=$file;
101 }
102 }
103 }
104 close(IN);
105 }
106
107sub parse_solaris
108 {
109 local($name)=@_;
110
111 open(IN,"nm $name|") || die "unable to run 'nn $name':$!\n";
112 while (<IN>)
113 {
114 chop;
115 next if /^\s*$/;
116 if (/^(\S+):$/)
117 {
118 $file=$1;
119 #$file="$1.c" if $file =~ /^(.*).o$/;
120 print STDERR "$file\n";
121 $we_need{$file}=" ";
122 next;
123 }
124 @a=split(/\s*\|\s*/);
125 next unless $#a == 7;
126 next unless $a[4] eq "GLOB";
127 if ($a[6] eq "UNDEF")
128 {
129 $unres{$file}.=$a[7]." ";
130 print STDERR "$file needs $a[7]\n" if $debug;
131 }
132 else
133 {
134 if ($file{$a[7]} ne "")
135 {
136 print STDERR "duplicate definition of $a[7],\n$file{$a[7]} and $file \n";
137 }
138 else
139 {
140 $file{$a[7]}=$file;
141 print STDERR "$file has $a[7]\n" if $debug;
142 }
143 }
144 }
145 close(IN);
146 }
147
diff --git a/src/lib/libcrypto/util/ssleay.num b/src/lib/libcrypto/util/ssleay.num
new file mode 100644
index 0000000000..46e38a131f
--- /dev/null
+++ b/src/lib/libcrypto/util/ssleay.num
@@ -0,0 +1,217 @@
1ERR_load_SSL_strings 1 EXIST::FUNCTION:
2SSL_CIPHER_description 2 EXIST::FUNCTION:
3SSL_CTX_add_client_CA 3 EXIST::FUNCTION:
4SSL_CTX_add_session 4 EXIST::FUNCTION:
5SSL_CTX_check_private_key 5 EXIST::FUNCTION:
6SSL_CTX_ctrl 6 EXIST::FUNCTION:
7SSL_CTX_flush_sessions 7 EXIST::FUNCTION:
8SSL_CTX_free 8 EXIST::FUNCTION:
9SSL_CTX_get_client_CA_list 9 EXIST::FUNCTION:
10SSL_CTX_get_verify_callback 10 EXIST::FUNCTION:
11SSL_CTX_get_verify_mode 11 EXIST::FUNCTION:
12SSL_CTX_new 12 EXIST::FUNCTION:
13SSL_CTX_remove_session 13 EXIST::FUNCTION:
14SSL_CTX_set_cipher_list 15 EXIST::FUNCTION:
15SSL_CTX_set_client_CA_list 16 EXIST::FUNCTION:
16SSL_CTX_set_default_passwd_cb 17 EXIST::FUNCTION:
17SSL_CTX_set_ssl_version 19 EXIST::FUNCTION:
18SSL_CTX_set_verify 21 EXIST::FUNCTION:
19SSL_CTX_use_PrivateKey 22 EXIST::FUNCTION:
20SSL_CTX_use_PrivateKey_ASN1 23 EXIST::FUNCTION:
21SSL_CTX_use_PrivateKey_file 24 EXIST::FUNCTION:STDIO
22SSL_CTX_use_RSAPrivateKey 25 EXIST::FUNCTION:RSA
23SSL_CTX_use_RSAPrivateKey_ASN1 26 EXIST::FUNCTION:RSA
24SSL_CTX_use_RSAPrivateKey_file 27 EXIST::FUNCTION:RSA,STDIO
25SSL_CTX_use_certificate 28 EXIST::FUNCTION:
26SSL_CTX_use_certificate_ASN1 29 EXIST::FUNCTION:
27SSL_CTX_use_certificate_file 30 EXIST::FUNCTION:STDIO
28SSL_SESSION_free 31 EXIST::FUNCTION:
29SSL_SESSION_new 32 EXIST::FUNCTION:
30SSL_SESSION_print 33 EXIST::FUNCTION:BIO
31SSL_SESSION_print_fp 34 EXIST::FUNCTION:FP_API
32SSL_accept 35 EXIST::FUNCTION:
33SSL_add_client_CA 36 EXIST::FUNCTION:
34SSL_alert_desc_string 37 EXIST::FUNCTION:
35SSL_alert_desc_string_long 38 EXIST::FUNCTION:
36SSL_alert_type_string 39 EXIST::FUNCTION:
37SSL_alert_type_string_long 40 EXIST::FUNCTION:
38SSL_check_private_key 41 EXIST::FUNCTION:
39SSL_clear 42 EXIST::FUNCTION:
40SSL_connect 43 EXIST::FUNCTION:
41SSL_copy_session_id 44 EXIST::FUNCTION:
42SSL_ctrl 45 EXIST::FUNCTION:
43SSL_dup 46 EXIST::FUNCTION:
44SSL_dup_CA_list 47 EXIST::FUNCTION:
45SSL_free 48 EXIST::FUNCTION:
46SSL_get_certificate 49 EXIST::FUNCTION:
47SSL_get_cipher_list 52 EXIST::FUNCTION:
48SSL_get_ciphers 55 EXIST::FUNCTION:
49SSL_get_client_CA_list 56 EXIST::FUNCTION:
50SSL_get_default_timeout 57 EXIST::FUNCTION:
51SSL_get_error 58 EXIST::FUNCTION:
52SSL_get_fd 59 EXIST::FUNCTION:
53SSL_get_peer_cert_chain 60 EXIST::FUNCTION:
54SSL_get_peer_certificate 61 EXIST::FUNCTION:
55SSL_get_rbio 63 EXIST::FUNCTION:BIO
56SSL_get_read_ahead 64 EXIST::FUNCTION:
57SSL_get_shared_ciphers 65 EXIST::FUNCTION:
58SSL_get_ssl_method 66 EXIST::FUNCTION:
59SSL_get_verify_callback 69 EXIST::FUNCTION:
60SSL_get_verify_mode 70 EXIST::FUNCTION:
61SSL_get_version 71 EXIST::FUNCTION:
62SSL_get_wbio 72 EXIST::FUNCTION:BIO
63SSL_load_client_CA_file 73 EXIST::FUNCTION:STDIO
64SSL_load_error_strings 74 EXIST::FUNCTION:
65SSL_new 75 EXIST::FUNCTION:
66SSL_peek 76 EXIST::FUNCTION:
67SSL_pending 77 EXIST::FUNCTION:
68SSL_read 78 EXIST::FUNCTION:
69SSL_renegotiate 79 EXIST::FUNCTION:
70SSL_rstate_string 80 EXIST::FUNCTION:
71SSL_rstate_string_long 81 EXIST::FUNCTION:
72SSL_set_accept_state 82 EXIST::FUNCTION:
73SSL_set_bio 83 EXIST::FUNCTION:BIO
74SSL_set_cipher_list 84 EXIST::FUNCTION:
75SSL_set_client_CA_list 85 EXIST::FUNCTION:
76SSL_set_connect_state 86 EXIST::FUNCTION:
77SSL_set_fd 87 EXIST::FUNCTION:SOCK
78SSL_set_read_ahead 88 EXIST::FUNCTION:
79SSL_set_rfd 89 EXIST::FUNCTION:SOCK
80SSL_set_session 90 EXIST::FUNCTION:
81SSL_set_ssl_method 91 EXIST::FUNCTION:
82SSL_set_verify 94 EXIST::FUNCTION:
83SSL_set_wfd 95 EXIST::FUNCTION:SOCK
84SSL_shutdown 96 EXIST::FUNCTION:
85SSL_state_string 97 EXIST::FUNCTION:
86SSL_state_string_long 98 EXIST::FUNCTION:
87SSL_use_PrivateKey 99 EXIST::FUNCTION:
88SSL_use_PrivateKey_ASN1 100 EXIST::FUNCTION:
89SSL_use_PrivateKey_file 101 EXIST::FUNCTION:STDIO
90SSL_use_RSAPrivateKey 102 EXIST::FUNCTION:RSA
91SSL_use_RSAPrivateKey_ASN1 103 EXIST::FUNCTION:RSA
92SSL_use_RSAPrivateKey_file 104 EXIST::FUNCTION:RSA,STDIO
93SSL_use_certificate 105 EXIST::FUNCTION:
94SSL_use_certificate_ASN1 106 EXIST::FUNCTION:
95SSL_use_certificate_file 107 EXIST::FUNCTION:STDIO
96SSL_write 108 EXIST::FUNCTION:
97SSLeay_add_ssl_algorithms 109 NOEXIST::FUNCTION:
98SSLv23_client_method 110 EXIST::FUNCTION:RSA
99SSLv23_method 111 EXIST::FUNCTION:RSA
100SSLv23_server_method 112 EXIST::FUNCTION:RSA
101SSLv2_client_method 113 EXIST::FUNCTION:RSA
102SSLv2_method 114 EXIST::FUNCTION:RSA
103SSLv2_server_method 115 EXIST::FUNCTION:RSA
104SSLv3_client_method 116 EXIST::FUNCTION:
105SSLv3_method 117 EXIST::FUNCTION:
106SSLv3_server_method 118 EXIST::FUNCTION:
107d2i_SSL_SESSION 119 EXIST::FUNCTION:
108i2d_SSL_SESSION 120 EXIST::FUNCTION:
109BIO_f_ssl 121 EXIST::FUNCTION:BIO
110BIO_new_ssl 122 EXIST::FUNCTION:BIO
111BIO_proxy_ssl_copy_session_id 123 NOEXIST::FUNCTION:
112BIO_ssl_copy_session_id 124 EXIST::FUNCTION:BIO
113SSL_do_handshake 125 EXIST::FUNCTION:
114SSL_get_privatekey 126 EXIST::FUNCTION:
115SSL_get_current_cipher 127 EXIST::FUNCTION:
116SSL_CIPHER_get_bits 128 EXIST::FUNCTION:
117SSL_CIPHER_get_version 129 EXIST::FUNCTION:
118SSL_CIPHER_get_name 130 EXIST::FUNCTION:
119BIO_ssl_shutdown 131 EXIST::FUNCTION:BIO
120SSL_SESSION_cmp 132 EXIST::FUNCTION:
121SSL_SESSION_hash 133 EXIST::FUNCTION:
122SSL_SESSION_get_time 134 EXIST::FUNCTION:
123SSL_SESSION_set_time 135 EXIST::FUNCTION:
124SSL_SESSION_get_timeout 136 EXIST::FUNCTION:
125SSL_SESSION_set_timeout 137 EXIST::FUNCTION:
126SSL_CTX_get_ex_data 138 EXIST::FUNCTION:
127SSL_CTX_get_quiet_shutdown 140 EXIST::FUNCTION:
128SSL_CTX_load_verify_locations 141 EXIST::FUNCTION:
129SSL_CTX_set_default_verify_paths 142 EXIST:!VMS:FUNCTION:
130SSL_CTX_set_def_verify_paths 142 EXIST:VMS:FUNCTION:
131SSL_CTX_set_ex_data 143 EXIST::FUNCTION:
132SSL_CTX_set_quiet_shutdown 145 EXIST::FUNCTION:
133SSL_SESSION_get_ex_data 146 EXIST::FUNCTION:
134SSL_SESSION_set_ex_data 148 EXIST::FUNCTION:
135SSL_get_SSL_CTX 150 EXIST::FUNCTION:
136SSL_get_ex_data 151 EXIST::FUNCTION:
137SSL_get_quiet_shutdown 153 EXIST::FUNCTION:
138SSL_get_session 154 EXIST::FUNCTION:
139SSL_get_shutdown 155 EXIST::FUNCTION:
140SSL_get_verify_result 157 EXIST::FUNCTION:
141SSL_set_ex_data 158 EXIST::FUNCTION:
142SSL_set_info_callback 160 EXIST::FUNCTION:
143SSL_set_quiet_shutdown 161 EXIST::FUNCTION:
144SSL_set_shutdown 162 EXIST::FUNCTION:
145SSL_set_verify_result 163 EXIST::FUNCTION:
146SSL_version 164 EXIST::FUNCTION:
147SSL_get_info_callback 165 EXIST::FUNCTION:
148SSL_state 166 EXIST::FUNCTION:
149SSL_CTX_get_ex_new_index 167 EXIST::FUNCTION:
150SSL_SESSION_get_ex_new_index 168 EXIST::FUNCTION:
151SSL_get_ex_new_index 169 EXIST::FUNCTION:
152TLSv1_method 170 EXIST::FUNCTION:
153TLSv1_server_method 171 EXIST::FUNCTION:
154TLSv1_client_method 172 EXIST::FUNCTION:
155BIO_new_buffer_ssl_connect 173 EXIST::FUNCTION:BIO
156BIO_new_ssl_connect 174 EXIST::FUNCTION:BIO
157SSL_get_ex_data_X509_STORE_CTX_idx 175 EXIST:!VMS:FUNCTION:
158SSL_get_ex_d_X509_STORE_CTX_idx 175 EXIST:VMS:FUNCTION:
159SSL_CTX_set_tmp_dh_callback 176 EXIST::FUNCTION:DH
160SSL_CTX_set_tmp_rsa_callback 177 EXIST::FUNCTION:RSA
161SSL_CTX_set_timeout 178 EXIST::FUNCTION:
162SSL_CTX_get_timeout 179 EXIST::FUNCTION:
163SSL_CTX_get_cert_store 180 EXIST::FUNCTION:
164SSL_CTX_set_cert_store 181 EXIST::FUNCTION:
165SSL_want 182 EXIST::FUNCTION:
166SSL_library_init 183 EXIST::FUNCTION:
167SSL_COMP_add_compression_method 184 EXIST::FUNCTION:COMP
168SSL_add_file_cert_subjects_to_stack 185 EXIST:!VMS:FUNCTION:STDIO
169SSL_add_file_cert_subjs_to_stk 185 EXIST:VMS:FUNCTION:STDIO
170SSL_set_tmp_rsa_callback 186 EXIST::FUNCTION:RSA
171SSL_set_tmp_dh_callback 187 EXIST::FUNCTION:DH
172SSL_add_dir_cert_subjects_to_stack 188 EXIST:!VMS:FUNCTION:STDIO
173SSL_add_dir_cert_subjs_to_stk 188 NOEXIST::FUNCTION:
174SSL_set_session_id_context 189 EXIST::FUNCTION:
175SSL_CTX_use_certificate_chain_file 222 EXIST:!VMS:FUNCTION:STDIO
176SSL_CTX_use_cert_chain_file 222 EXIST:VMS:FUNCTION:STDIO
177SSL_CTX_set_verify_depth 225 EXIST::FUNCTION:
178SSL_set_verify_depth 226 EXIST::FUNCTION:
179SSL_CTX_get_verify_depth 228 EXIST::FUNCTION:
180SSL_get_verify_depth 229 EXIST::FUNCTION:
181SSL_CTX_set_session_id_context 231 EXIST::FUNCTION:
182SSL_CTX_set_cert_verify_callback 232 EXIST:!VMS:FUNCTION:
183SSL_CTX_set_cert_verify_cb 232 EXIST:VMS:FUNCTION:
184SSL_CTX_set_default_passwd_cb_userdata 235 EXIST:!VMS:FUNCTION:
185SSL_CTX_set_def_passwd_cb_ud 235 EXIST:VMS:FUNCTION:
186SSL_set_purpose 236 EXIST::FUNCTION:
187SSL_CTX_set_trust 237 EXIST::FUNCTION:
188SSL_CTX_set_purpose 238 EXIST::FUNCTION:
189SSL_set_trust 239 EXIST::FUNCTION:
190SSL_get_finished 240 EXIST::FUNCTION:
191SSL_get_peer_finished 241 EXIST::FUNCTION:
192SSL_get1_session 242 EXIST::FUNCTION:
193SSL_CTX_callback_ctrl 243 EXIST::FUNCTION:
194SSL_callback_ctrl 244 EXIST::FUNCTION:
195SSL_CTX_sessions 245 EXIST::FUNCTION:
196SSL_get_rfd 246 EXIST::FUNCTION:
197SSL_get_wfd 247 EXIST::FUNCTION:
198kssl_cget_tkt 248 EXIST::FUNCTION:KRB5
199SSL_has_matching_session_id 249 EXIST::FUNCTION:
200kssl_err_set 250 EXIST::FUNCTION:KRB5
201kssl_ctx_show 251 EXIST::FUNCTION:KRB5
202kssl_validate_times 252 EXIST::FUNCTION:KRB5
203kssl_check_authent 253 EXIST::FUNCTION:KRB5
204kssl_ctx_new 254 EXIST::FUNCTION:KRB5
205kssl_build_principal_2 255 EXIST::FUNCTION:KRB5
206kssl_skip_confound 256 EXIST::FUNCTION:KRB5
207kssl_sget_tkt 257 EXIST::FUNCTION:KRB5
208SSL_set_generate_session_id 258 EXIST::FUNCTION:
209kssl_ctx_setkey 259 EXIST::FUNCTION:KRB5
210kssl_ctx_setprinc 260 EXIST::FUNCTION:KRB5
211kssl_ctx_free 261 EXIST::FUNCTION:KRB5
212kssl_krb5_free_data_contents 262 EXIST::FUNCTION:KRB5
213kssl_ctx_setstring 263 EXIST::FUNCTION:KRB5
214SSL_CTX_set_generate_session_id 264 EXIST::FUNCTION:
215SSL_renegotiate_pending 265 EXIST::FUNCTION:
216SSL_CTX_set_msg_callback 266 EXIST::FUNCTION:
217SSL_set_msg_callback 267 EXIST::FUNCTION:
diff --git a/src/lib/libcrypto/util/tab_num.pl b/src/lib/libcrypto/util/tab_num.pl
new file mode 100644
index 0000000000..a81ed0edc2
--- /dev/null
+++ b/src/lib/libcrypto/util/tab_num.pl
@@ -0,0 +1,17 @@
1#!/usr/local/bin/perl
2
3$num=1;
4$width=40;
5
6while (<>)
7 {
8 chop;
9
10 $i=length($_);
11
12 $n=$width-$i;
13 $i=int(($n+7)/8);
14 print $_.("\t" x $i).$num."\n";
15 $num++;
16 }
17
diff --git a/src/lib/libcrypto/util/x86asm.sh b/src/lib/libcrypto/util/x86asm.sh
new file mode 100644
index 0000000000..d2090a9849
--- /dev/null
+++ b/src/lib/libcrypto/util/x86asm.sh
@@ -0,0 +1,42 @@
1#!/bin/sh
2
3echo Generating x86 assember
4echo Bignum
5(cd crypto/bn/asm; perl x86.pl cpp > bn86unix.cpp)
6(cd crypto/bn/asm; perl x86.pl win32 > bn-win32.asm)
7
8echo DES
9(cd crypto/des/asm; perl des-586.pl cpp > dx86unix.cpp)
10(cd crypto/des/asm; perl des-586.pl win32 > d-win32.asm)
11
12echo "crypt(3)"
13(cd crypto/des/asm; perl crypt586.pl cpp > yx86unix.cpp)
14(cd crypto/des/asm; perl crypt586.pl win32 > y-win32.asm)
15
16echo Blowfish
17(cd crypto/bf/asm; perl bf-586.pl cpp > bx86unix.cpp)
18(cd crypto/bf/asm; perl bf-586.pl win32 > b-win32.asm)
19
20echo CAST5
21(cd crypto/cast/asm; perl cast-586.pl cpp > cx86unix.cpp)
22(cd crypto/cast/asm; perl cast-586.pl win32 > c-win32.asm)
23
24echo RC4
25(cd crypto/rc4/asm; perl rc4-586.pl cpp > rx86unix.cpp)
26(cd crypto/rc4/asm; perl rc4-586.pl win32 > r4-win32.asm)
27
28echo MD5
29(cd crypto/md5/asm; perl md5-586.pl cpp > mx86unix.cpp)
30(cd crypto/md5/asm; perl md5-586.pl win32 > m5-win32.asm)
31
32echo SHA1
33(cd crypto/sha/asm; perl sha1-586.pl cpp > sx86unix.cpp)
34(cd crypto/sha/asm; perl sha1-586.pl win32 > s1-win32.asm)
35
36echo RIPEMD160
37(cd crypto/ripemd/asm; perl rmd-586.pl cpp > rm86unix.cpp)
38(cd crypto/ripemd/asm; perl rmd-586.pl win32 > rm-win32.asm)
39
40echo RC5/32
41(cd crypto/rc5/asm; perl rc5-586.pl cpp > r586unix.cpp)
42(cd crypto/rc5/asm; perl rc5-586.pl win32 > r5-win32.asm)
diff --git a/src/lib/libcrypto/x509/Makefile b/src/lib/libcrypto/x509/Makefile
new file mode 100644
index 0000000000..ddcc3124a7
--- /dev/null
+++ b/src/lib/libcrypto/x509/Makefile
@@ -0,0 +1,406 @@
1#
2# OpenSSL/crypto/x509/Makefile
3#
4
5DIR= x509
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile README
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \
21 x509_obj.c x509_req.c x509spki.c x509_vfy.c \
22 x509_set.c x509cset.c x509rset.c x509_err.c \
23 x509name.c x509_v3.c x509_ext.c x509_att.c \
24 x509type.c x509_lu.c x_all.c x509_txt.c \
25 x509_trs.c by_file.c by_dir.c x509_vpm.c
26LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \
27 x509_obj.o x509_req.o x509spki.o x509_vfy.o \
28 x509_set.o x509cset.o x509rset.o x509_err.o \
29 x509name.o x509_v3.o x509_ext.o x509_att.o \
30 x509type.o x509_lu.o x_all.o x509_txt.o \
31 x509_trs.o by_file.o by_dir.o x509_vpm.o
32
33SRC= $(LIBSRC)
34
35EXHEADER= x509.h x509_vfy.h
36HEADER= $(EXHEADER)
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
52
53links:
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 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
60 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
61 do \
62 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
63 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
64 done;
65
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
76 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
77
78dclean:
79 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
80 mv -f Makefile.new $(MAKEFILE)
81
82clean:
83 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
84
85# DO NOT DELETE THIS LINE -- make depend depends on it.
86
87by_dir.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
88by_dir.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
89by_dir.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
90by_dir.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
91by_dir.o: ../../include/openssl/err.h ../../include/openssl/evp.h
92by_dir.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
93by_dir.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
94by_dir.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
95by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
96by_dir.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
97by_dir.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
98by_dir.o: ../../include/openssl/x509_vfy.h ../cryptlib.h by_dir.c
99by_file.o: ../../e_os.h ../../include/openssl/asn1.h
100by_file.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
101by_file.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
102by_file.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
103by_file.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
104by_file.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
105by_file.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
106by_file.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
107by_file.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
108by_file.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
109by_file.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
110by_file.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
111by_file.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
112by_file.o: ../cryptlib.h by_file.c
113x509_att.o: ../../e_os.h ../../include/openssl/asn1.h
114x509_att.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
115x509_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
116x509_att.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
117x509_att.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
118x509_att.o: ../../include/openssl/err.h ../../include/openssl/evp.h
119x509_att.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
120x509_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
121x509_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
122x509_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
123x509_att.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
124x509_att.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
125x509_att.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
126x509_att.o: ../cryptlib.h x509_att.c
127x509_cmp.o: ../../e_os.h ../../include/openssl/asn1.h
128x509_cmp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
129x509_cmp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
130x509_cmp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
131x509_cmp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
132x509_cmp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
133x509_cmp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
134x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
135x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
136x509_cmp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
137x509_cmp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
138x509_cmp.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
139x509_cmp.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
140x509_cmp.o: ../cryptlib.h x509_cmp.c
141x509_d2.o: ../../e_os.h ../../include/openssl/asn1.h
142x509_d2.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
143x509_d2.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
144x509_d2.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
145x509_d2.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
146x509_d2.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
147x509_d2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
148x509_d2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
149x509_d2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
150x509_d2.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
151x509_d2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
152x509_d2.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
153x509_d2.o: ../cryptlib.h x509_d2.c
154x509_def.o: ../../e_os.h ../../include/openssl/asn1.h
155x509_def.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
156x509_def.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
157x509_def.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
158x509_def.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
159x509_def.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
160x509_def.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
161x509_def.o: ../../include/openssl/opensslconf.h
162x509_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
163x509_def.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
164x509_def.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
165x509_def.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
166x509_def.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_def.c
167x509_err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
168x509_err.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
169x509_err.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
170x509_err.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
171x509_err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
172x509_err.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
173x509_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
174x509_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
175x509_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
176x509_err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
177x509_err.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
178x509_err.o: ../../include/openssl/x509_vfy.h x509_err.c
179x509_ext.o: ../../e_os.h ../../include/openssl/asn1.h
180x509_ext.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
181x509_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
182x509_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
183x509_ext.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
184x509_ext.o: ../../include/openssl/err.h ../../include/openssl/evp.h
185x509_ext.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
186x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
187x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
188x509_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
189x509_ext.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
190x509_ext.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
191x509_ext.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
192x509_ext.o: ../cryptlib.h x509_ext.c
193x509_lu.o: ../../e_os.h ../../include/openssl/asn1.h
194x509_lu.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
195x509_lu.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
196x509_lu.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
197x509_lu.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
198x509_lu.o: ../../include/openssl/err.h ../../include/openssl/evp.h
199x509_lu.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
200x509_lu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
201x509_lu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
202x509_lu.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
203x509_lu.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
204x509_lu.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
205x509_lu.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
206x509_lu.o: ../cryptlib.h x509_lu.c
207x509_obj.o: ../../e_os.h ../../include/openssl/asn1.h
208x509_obj.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
209x509_obj.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
210x509_obj.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
211x509_obj.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
212x509_obj.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
213x509_obj.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
214x509_obj.o: ../../include/openssl/opensslconf.h
215x509_obj.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
216x509_obj.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
217x509_obj.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
218x509_obj.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
219x509_obj.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_obj.c
220x509_r2x.o: ../../e_os.h ../../include/openssl/asn1.h
221x509_r2x.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
222x509_r2x.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
223x509_r2x.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
224x509_r2x.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
225x509_r2x.o: ../../include/openssl/err.h ../../include/openssl/evp.h
226x509_r2x.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
227x509_r2x.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
228x509_r2x.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
229x509_r2x.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
230x509_r2x.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
231x509_r2x.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
232x509_r2x.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_r2x.c
233x509_req.o: ../../e_os.h ../../include/openssl/asn1.h
234x509_req.o: ../../include/openssl/bio.h ../../include/openssl/bn.h
235x509_req.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
236x509_req.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
237x509_req.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
238x509_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
239x509_req.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
240x509_req.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
241x509_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
242x509_req.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
243x509_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
244x509_req.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
245x509_req.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
246x509_req.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_req.c
247x509_set.o: ../../e_os.h ../../include/openssl/asn1.h
248x509_set.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
249x509_set.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
250x509_set.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
251x509_set.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
252x509_set.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
253x509_set.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
254x509_set.o: ../../include/openssl/opensslconf.h
255x509_set.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
256x509_set.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
257x509_set.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
258x509_set.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
259x509_set.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_set.c
260x509_trs.o: ../../e_os.h ../../include/openssl/asn1.h
261x509_trs.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
262x509_trs.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
263x509_trs.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
264x509_trs.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
265x509_trs.o: ../../include/openssl/err.h ../../include/openssl/evp.h
266x509_trs.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
267x509_trs.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
268x509_trs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
269x509_trs.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
270x509_trs.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
271x509_trs.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
272x509_trs.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
273x509_trs.o: ../cryptlib.h x509_trs.c
274x509_txt.o: ../../e_os.h ../../include/openssl/asn1.h
275x509_txt.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
276x509_txt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
277x509_txt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
278x509_txt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
279x509_txt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
280x509_txt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
281x509_txt.o: ../../include/openssl/opensslconf.h
282x509_txt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
283x509_txt.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
284x509_txt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
285x509_txt.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
286x509_txt.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_txt.c
287x509_v3.o: ../../e_os.h ../../include/openssl/asn1.h
288x509_v3.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
289x509_v3.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
290x509_v3.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
291x509_v3.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
292x509_v3.o: ../../include/openssl/err.h ../../include/openssl/evp.h
293x509_v3.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
294x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
295x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
296x509_v3.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
297x509_v3.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
298x509_v3.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
299x509_v3.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
300x509_v3.o: ../cryptlib.h x509_v3.c
301x509_vfy.o: ../../e_os.h ../../include/openssl/asn1.h
302x509_vfy.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
303x509_vfy.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
304x509_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
305x509_vfy.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
306x509_vfy.o: ../../include/openssl/err.h ../../include/openssl/evp.h
307x509_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
308x509_vfy.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
309x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
310x509_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
311x509_vfy.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
312x509_vfy.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
313x509_vfy.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
314x509_vfy.o: ../cryptlib.h x509_vfy.c
315x509_vpm.o: ../../e_os.h ../../include/openssl/asn1.h
316x509_vpm.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
317x509_vpm.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
318x509_vpm.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
319x509_vpm.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
320x509_vpm.o: ../../include/openssl/err.h ../../include/openssl/evp.h
321x509_vpm.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
322x509_vpm.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
323x509_vpm.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
324x509_vpm.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
325x509_vpm.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
326x509_vpm.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
327x509_vpm.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
328x509_vpm.o: ../cryptlib.h x509_vpm.c
329x509cset.o: ../../e_os.h ../../include/openssl/asn1.h
330x509cset.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
331x509cset.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
332x509cset.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
333x509cset.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
334x509cset.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
335x509cset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
336x509cset.o: ../../include/openssl/opensslconf.h
337x509cset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
338x509cset.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
339x509cset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
340x509cset.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
341x509cset.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509cset.c
342x509name.o: ../../e_os.h ../../include/openssl/asn1.h
343x509name.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
344x509name.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
345x509name.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
346x509name.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
347x509name.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
348x509name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
349x509name.o: ../../include/openssl/opensslconf.h
350x509name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
351x509name.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
352x509name.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
353x509name.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
354x509name.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509name.c
355x509rset.o: ../../e_os.h ../../include/openssl/asn1.h
356x509rset.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
357x509rset.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
358x509rset.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
359x509rset.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
360x509rset.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
361x509rset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
362x509rset.o: ../../include/openssl/opensslconf.h
363x509rset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
364x509rset.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
365x509rset.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
366x509rset.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
367x509rset.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509rset.c
368x509spki.o: ../../e_os.h ../../include/openssl/asn1.h
369x509spki.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
370x509spki.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
371x509spki.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
372x509spki.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
373x509spki.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
374x509spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
375x509spki.o: ../../include/openssl/opensslconf.h
376x509spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
377x509spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
378x509spki.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
379x509spki.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
380x509spki.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509spki.c
381x509type.o: ../../e_os.h ../../include/openssl/asn1.h
382x509type.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
383x509type.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
384x509type.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
385x509type.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
386x509type.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
387x509type.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
388x509type.o: ../../include/openssl/opensslconf.h
389x509type.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
390x509type.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
391x509type.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
392x509type.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
393x509type.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509type.c
394x_all.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
395x_all.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h
396x_all.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
397x_all.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
398x_all.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
399x_all.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
400x_all.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
401x_all.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
402x_all.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
403x_all.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
404x_all.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
405x_all.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
406x_all.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x_all.c
diff --git a/src/lib/libcrypto/x509/Makefile.ssl b/src/lib/libcrypto/x509/Makefile.ssl
new file mode 100644
index 0000000000..3a3452536c
--- /dev/null
+++ b/src/lib/libcrypto/x509/Makefile.ssl
@@ -0,0 +1,594 @@
1#
2# SSLeay/crypto/x509/Makefile
3#
4
5DIR= x509
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= x509_def.c x509_d2.c x509_r2x.c x509_cmp.c \
27 x509_obj.c x509_req.c x509spki.c x509_vfy.c \
28 x509_set.c x509cset.c x509rset.c x509_err.c \
29 x509name.c x509_v3.c x509_ext.c x509_att.c \
30 x509type.c x509_lu.c x_all.c x509_txt.c \
31 x509_trs.c by_file.c by_dir.c
32LIBOBJ= x509_def.o x509_d2.o x509_r2x.o x509_cmp.o \
33 x509_obj.o x509_req.o x509spki.o x509_vfy.o \
34 x509_set.o x509cset.o x509rset.o x509_err.o \
35 x509name.o x509_v3.o x509_ext.o x509_att.o \
36 x509type.o x509_lu.o x_all.o x509_txt.o \
37 x509_trs.o by_file.o by_dir.o
38
39SRC= $(LIBSRC)
40
41EXHEADER= x509.h x509_vfy.h
42HEADER= $(EXHEADER)
43
44ALL= $(GENERAL) $(SRC) $(HEADER)
45
46top:
47 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
48
49all: lib
50
51lib: $(LIBOBJ)
52 $(AR) $(LIB) $(LIBOBJ)
53 $(RANLIB) $(LIB) || echo Never mind.
54 @touch lib
55
56files:
57 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
58
59links:
60 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
61 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
62 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
63 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
64
65install:
66 @for i in $(EXHEADER) ; \
67 do \
68 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
69 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
70 done;
71
72tags:
73 ctags $(SRC)
74
75tests:
76
77lint:
78 lint -DLINT $(INCLUDES) $(SRC)>fluff
79
80depend:
81 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
82
83dclean:
84 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
85 mv -f Makefile.new $(MAKEFILE)
86
87clean:
88 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
89
90# DO NOT DELETE THIS LINE -- make depend depends on it.
91
92by_dir.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
93by_dir.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
94by_dir.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
95by_dir.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
96by_dir.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
97by_dir.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
98by_dir.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
99by_dir.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
100by_dir.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
101by_dir.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
102by_dir.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
103by_dir.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
104by_dir.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
105by_dir.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
106by_dir.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
107by_dir.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
108by_dir.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
109by_dir.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
110by_dir.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
111by_dir.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
112by_dir.o: ../cryptlib.h by_dir.c
113by_file.o: ../../e_os.h ../../include/openssl/aes.h
114by_file.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
115by_file.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
116by_file.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
117by_file.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
118by_file.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
119by_file.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
120by_file.o: ../../include/openssl/err.h ../../include/openssl/evp.h
121by_file.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
122by_file.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
123by_file.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
124by_file.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
125by_file.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
126by_file.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pem.h
127by_file.o: ../../include/openssl/pem2.h ../../include/openssl/pkcs7.h
128by_file.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
129by_file.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
130by_file.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
131by_file.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
132by_file.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
133by_file.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
134by_file.o: ../../include/openssl/x509_vfy.h ../cryptlib.h by_file.c
135x509_att.o: ../../e_os.h ../../include/openssl/aes.h
136x509_att.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
137x509_att.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
138x509_att.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
139x509_att.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
140x509_att.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
141x509_att.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
142x509_att.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
143x509_att.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
144x509_att.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
145x509_att.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
146x509_att.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
147x509_att.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
148x509_att.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
149x509_att.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
150x509_att.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
151x509_att.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
152x509_att.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
153x509_att.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
154x509_att.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
155x509_att.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
156x509_att.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_att.c
157x509_cmp.o: ../../e_os.h ../../include/openssl/aes.h
158x509_cmp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
159x509_cmp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
160x509_cmp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
161x509_cmp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
162x509_cmp.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
163x509_cmp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
164x509_cmp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
165x509_cmp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
166x509_cmp.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
167x509_cmp.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
168x509_cmp.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
169x509_cmp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
170x509_cmp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
171x509_cmp.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
172x509_cmp.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
173x509_cmp.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
174x509_cmp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
175x509_cmp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176x509_cmp.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
177x509_cmp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
178x509_cmp.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_cmp.c
179x509_d2.o: ../../e_os.h ../../include/openssl/aes.h
180x509_d2.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
181x509_d2.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
182x509_d2.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
183x509_d2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
184x509_d2.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
185x509_d2.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
186x509_d2.o: ../../include/openssl/err.h ../../include/openssl/evp.h
187x509_d2.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
188x509_d2.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
189x509_d2.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
190x509_d2.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
191x509_d2.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
192x509_d2.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
193x509_d2.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
194x509_d2.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
195x509_d2.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
196x509_d2.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
197x509_d2.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
198x509_d2.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
199x509_d2.o: ../../include/openssl/x509_vfy.h ../cryptlib.h x509_d2.c
200x509_def.o: ../../e_os.h ../../include/openssl/aes.h
201x509_def.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
202x509_def.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
203x509_def.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
204x509_def.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
205x509_def.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
206x509_def.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
207x509_def.o: ../../include/openssl/err.h ../../include/openssl/evp.h
208x509_def.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
209x509_def.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
210x509_def.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
211x509_def.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
212x509_def.o: ../../include/openssl/opensslconf.h
213x509_def.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
214x509_def.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
215x509_def.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
216x509_def.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
217x509_def.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
218x509_def.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
219x509_def.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
220x509_def.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
221x509_def.o: ../cryptlib.h x509_def.c
222x509_err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
223x509_err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
224x509_err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
225x509_err.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
226x509_err.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
227x509_err.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
228x509_err.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
229x509_err.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
230x509_err.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
231x509_err.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
232x509_err.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
233x509_err.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
234x509_err.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
235x509_err.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
236x509_err.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
237x509_err.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
238x509_err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
239x509_err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
240x509_err.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
241x509_err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
242x509_err.o: x509_err.c
243x509_ext.o: ../../e_os.h ../../include/openssl/aes.h
244x509_ext.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
245x509_ext.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
246x509_ext.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
247x509_ext.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
248x509_ext.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
249x509_ext.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
250x509_ext.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
251x509_ext.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
252x509_ext.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
253x509_ext.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
254x509_ext.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
255x509_ext.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
256x509_ext.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
257x509_ext.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
258x509_ext.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
259x509_ext.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
260x509_ext.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
261x509_ext.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
262x509_ext.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
263x509_ext.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
264x509_ext.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_ext.c
265x509_lu.o: ../../e_os.h ../../include/openssl/aes.h
266x509_lu.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
267x509_lu.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
268x509_lu.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
269x509_lu.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
270x509_lu.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
271x509_lu.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
272x509_lu.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
273x509_lu.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
274x509_lu.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
275x509_lu.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
276x509_lu.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
277x509_lu.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
278x509_lu.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
279x509_lu.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
280x509_lu.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
281x509_lu.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
282x509_lu.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
283x509_lu.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
284x509_lu.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
285x509_lu.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
286x509_lu.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_lu.c
287x509_obj.o: ../../e_os.h ../../include/openssl/aes.h
288x509_obj.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
289x509_obj.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
290x509_obj.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
291x509_obj.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
292x509_obj.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
293x509_obj.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
294x509_obj.o: ../../include/openssl/err.h ../../include/openssl/evp.h
295x509_obj.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
296x509_obj.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
297x509_obj.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
298x509_obj.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
299x509_obj.o: ../../include/openssl/opensslconf.h
300x509_obj.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
301x509_obj.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
302x509_obj.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
303x509_obj.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
304x509_obj.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
305x509_obj.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
306x509_obj.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
307x509_obj.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
308x509_obj.o: ../cryptlib.h x509_obj.c
309x509_r2x.o: ../../e_os.h ../../include/openssl/aes.h
310x509_r2x.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
311x509_r2x.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
312x509_r2x.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
313x509_r2x.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
314x509_r2x.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
315x509_r2x.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
316x509_r2x.o: ../../include/openssl/err.h ../../include/openssl/evp.h
317x509_r2x.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
318x509_r2x.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
319x509_r2x.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
320x509_r2x.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
321x509_r2x.o: ../../include/openssl/opensslconf.h
322x509_r2x.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
323x509_r2x.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
324x509_r2x.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
325x509_r2x.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
326x509_r2x.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
327x509_r2x.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
328x509_r2x.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
329x509_r2x.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
330x509_r2x.o: ../cryptlib.h x509_r2x.c
331x509_req.o: ../../e_os.h ../../include/openssl/aes.h
332x509_req.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
333x509_req.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
334x509_req.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
335x509_req.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
336x509_req.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
337x509_req.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
338x509_req.o: ../../include/openssl/err.h ../../include/openssl/evp.h
339x509_req.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
340x509_req.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
341x509_req.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
342x509_req.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
343x509_req.o: ../../include/openssl/opensslconf.h
344x509_req.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
345x509_req.o: ../../include/openssl/pem.h ../../include/openssl/pem2.h
346x509_req.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
347x509_req.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
348x509_req.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
349x509_req.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
350x509_req.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
351x509_req.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
352x509_req.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
353x509_req.o: ../cryptlib.h x509_req.c
354x509_set.o: ../../e_os.h ../../include/openssl/aes.h
355x509_set.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
356x509_set.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
357x509_set.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
358x509_set.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
359x509_set.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
360x509_set.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
361x509_set.o: ../../include/openssl/err.h ../../include/openssl/evp.h
362x509_set.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
363x509_set.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
364x509_set.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
365x509_set.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
366x509_set.o: ../../include/openssl/opensslconf.h
367x509_set.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
368x509_set.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
369x509_set.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
370x509_set.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
371x509_set.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
372x509_set.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
373x509_set.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
374x509_set.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
375x509_set.o: ../cryptlib.h x509_set.c
376x509_trs.o: ../../e_os.h ../../include/openssl/aes.h
377x509_trs.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
378x509_trs.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
379x509_trs.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
380x509_trs.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
381x509_trs.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
382x509_trs.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
383x509_trs.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
384x509_trs.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
385x509_trs.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
386x509_trs.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
387x509_trs.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
388x509_trs.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
389x509_trs.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
390x509_trs.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
391x509_trs.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
392x509_trs.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
393x509_trs.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
394x509_trs.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
395x509_trs.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
396x509_trs.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
397x509_trs.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_trs.c
398x509_txt.o: ../../e_os.h ../../include/openssl/aes.h
399x509_txt.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
400x509_txt.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
401x509_txt.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
402x509_txt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
403x509_txt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
404x509_txt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
405x509_txt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
406x509_txt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
407x509_txt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
408x509_txt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
409x509_txt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
410x509_txt.o: ../../include/openssl/opensslconf.h
411x509_txt.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
412x509_txt.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
413x509_txt.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
414x509_txt.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
415x509_txt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
416x509_txt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
417x509_txt.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
418x509_txt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
419x509_txt.o: ../cryptlib.h x509_txt.c
420x509_v3.o: ../../e_os.h ../../include/openssl/aes.h
421x509_v3.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
422x509_v3.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
423x509_v3.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
424x509_v3.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
425x509_v3.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
426x509_v3.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
427x509_v3.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
428x509_v3.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
429x509_v3.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
430x509_v3.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
431x509_v3.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
432x509_v3.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
433x509_v3.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
434x509_v3.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
435x509_v3.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
436x509_v3.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
437x509_v3.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
438x509_v3.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
439x509_v3.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
440x509_v3.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
441x509_v3.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_v3.c
442x509_vfy.o: ../../e_os.h ../../include/openssl/aes.h
443x509_vfy.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
444x509_vfy.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
445x509_vfy.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
446x509_vfy.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
447x509_vfy.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
448x509_vfy.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
449x509_vfy.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
450x509_vfy.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
451x509_vfy.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
452x509_vfy.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
453x509_vfy.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
454x509_vfy.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
455x509_vfy.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
456x509_vfy.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
457x509_vfy.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
458x509_vfy.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
459x509_vfy.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
460x509_vfy.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
461x509_vfy.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
462x509_vfy.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
463x509_vfy.o: ../../include/openssl/x509v3.h ../cryptlib.h x509_vfy.c
464x509cset.o: ../../e_os.h ../../include/openssl/aes.h
465x509cset.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
466x509cset.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
467x509cset.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
468x509cset.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
469x509cset.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
470x509cset.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
471x509cset.o: ../../include/openssl/err.h ../../include/openssl/evp.h
472x509cset.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
473x509cset.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
474x509cset.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
475x509cset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
476x509cset.o: ../../include/openssl/opensslconf.h
477x509cset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
478x509cset.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
479x509cset.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
480x509cset.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
481x509cset.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
482x509cset.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
483x509cset.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
484x509cset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
485x509cset.o: ../cryptlib.h x509cset.c
486x509name.o: ../../e_os.h ../../include/openssl/aes.h
487x509name.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
488x509name.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
489x509name.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
490x509name.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
491x509name.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
492x509name.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
493x509name.o: ../../include/openssl/err.h ../../include/openssl/evp.h
494x509name.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
495x509name.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
496x509name.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
497x509name.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
498x509name.o: ../../include/openssl/opensslconf.h
499x509name.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
500x509name.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
501x509name.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
502x509name.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
503x509name.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
504x509name.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
505x509name.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
506x509name.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
507x509name.o: ../cryptlib.h x509name.c
508x509rset.o: ../../e_os.h ../../include/openssl/aes.h
509x509rset.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
510x509rset.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
511x509rset.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
512x509rset.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
513x509rset.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
514x509rset.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
515x509rset.o: ../../include/openssl/err.h ../../include/openssl/evp.h
516x509rset.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
517x509rset.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
518x509rset.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
519x509rset.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
520x509rset.o: ../../include/openssl/opensslconf.h
521x509rset.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
522x509rset.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
523x509rset.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
524x509rset.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
525x509rset.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
526x509rset.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
527x509rset.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
528x509rset.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
529x509rset.o: ../cryptlib.h x509rset.c
530x509spki.o: ../../e_os.h ../../include/openssl/aes.h
531x509spki.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
532x509spki.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
533x509spki.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
534x509spki.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
535x509spki.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
536x509spki.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
537x509spki.o: ../../include/openssl/err.h ../../include/openssl/evp.h
538x509spki.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
539x509spki.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
540x509spki.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
541x509spki.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
542x509spki.o: ../../include/openssl/opensslconf.h
543x509spki.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
544x509spki.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
545x509spki.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
546x509spki.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
547x509spki.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
548x509spki.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
549x509spki.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
550x509spki.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
551x509spki.o: ../cryptlib.h x509spki.c
552x509type.o: ../../e_os.h ../../include/openssl/aes.h
553x509type.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
554x509type.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
555x509type.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
556x509type.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
557x509type.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
558x509type.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
559x509type.o: ../../include/openssl/err.h ../../include/openssl/evp.h
560x509type.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
561x509type.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
562x509type.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
563x509type.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
564x509type.o: ../../include/openssl/opensslconf.h
565x509type.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
566x509type.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
567x509type.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
568x509type.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
569x509type.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
570x509type.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
571x509type.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
572x509type.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
573x509type.o: ../cryptlib.h x509type.c
574x_all.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
575x_all.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
576x_all.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
577x_all.o: ../../include/openssl/cast.h ../../include/openssl/crypto.h
578x_all.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
579x_all.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
580x_all.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
581x_all.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
582x_all.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
583x_all.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
584x_all.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
585x_all.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
586x_all.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
587x_all.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
588x_all.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
589x_all.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
590x_all.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
591x_all.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
592x_all.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
593x_all.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
594x_all.o: ../cryptlib.h x_all.c
diff --git a/src/lib/libcrypto/x509/by_dir.c b/src/lib/libcrypto/x509/by_dir.c
index 37f9a48206..ea689aed1a 100644
--- a/src/lib/libcrypto/x509/by_dir.c
+++ b/src/lib/libcrypto/x509/by_dir.c
@@ -189,7 +189,7 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
189 189
190 s=dir; 190 s=dir;
191 p=s; 191 p=s;
192 for (;;p++) 192 for (;;)
193 { 193 {
194 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0')) 194 if ((*p == LIST_SEPARATOR_CHAR) || (*p == '\0'))
195 { 195 {
@@ -198,11 +198,8 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
198 len=(int)(p-ss); 198 len=(int)(p-ss);
199 if (len == 0) continue; 199 if (len == 0) continue;
200 for (j=0; j<ctx->num_dirs; j++) 200 for (j=0; j<ctx->num_dirs; j++)
201 if (strlen(ctx->dirs[j]) == (size_t)len && 201 if (strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0)
202 strncmp(ctx->dirs[j],ss,(unsigned int)len) == 0) 202 continue;
203 break;
204 if (j<ctx->num_dirs)
205 continue;
206 if (ctx->num_dirs_alloced < (ctx->num_dirs+1)) 203 if (ctx->num_dirs_alloced < (ctx->num_dirs+1))
207 { 204 {
208 ctx->num_dirs_alloced+=10; 205 ctx->num_dirs_alloced+=10;
@@ -234,6 +231,7 @@ static int add_cert_dir(BY_DIR *ctx, const char *dir, int type)
234 ctx->num_dirs++; 231 ctx->num_dirs++;
235 } 232 }
236 if (*p == '\0') break; 233 if (*p == '\0') break;
234 p++;
237 } 235 }
238 return(1); 236 return(1);
239 } 237 }
diff --git a/src/lib/libcrypto/x509/x509.h b/src/lib/libcrypto/x509/x509.h
index e71b5257e5..e8c1a59cf2 100644
--- a/src/lib/libcrypto/x509/x509.h
+++ b/src/lib/libcrypto/x509/x509.h
@@ -55,16 +55,10 @@
55 * copied and put under another distribution licence 55 * copied and put under another distribution licence
56 * [including the GNU Public Licence.] 56 * [including the GNU Public Licence.]
57 */ 57 */
58/* ====================================================================
59 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
60 * ECDH support in OpenSSL originally developed by
61 * SUN MICROSYSTEMS, INC., and contributed to the OpenSSL project.
62 */
63 58
64#ifndef HEADER_X509_H 59#ifndef HEADER_X509_H
65#define HEADER_X509_H 60#define HEADER_X509_H
66 61
67#include <openssl/e_os2.h>
68#include <openssl/symhacks.h> 62#include <openssl/symhacks.h>
69#ifndef OPENSSL_NO_BUFFER 63#ifndef OPENSSL_NO_BUFFER
70#include <openssl/buffer.h> 64#include <openssl/buffer.h>
@@ -79,33 +73,21 @@
79#include <openssl/asn1.h> 73#include <openssl/asn1.h>
80#include <openssl/safestack.h> 74#include <openssl/safestack.h>
81 75
82#ifndef OPENSSL_NO_EC
83#include <openssl/ec.h>
84#endif
85
86#ifndef OPENSSL_NO_ECDSA
87#include <openssl/ecdsa.h>
88#endif
89
90#ifndef OPENSSL_NO_ECDH
91#include <openssl/ecdh.h>
92#endif
93
94#ifndef OPENSSL_NO_DEPRECATED
95#ifndef OPENSSL_NO_RSA 76#ifndef OPENSSL_NO_RSA
96#include <openssl/rsa.h> 77#include <openssl/rsa.h>
97#endif 78#endif
79
98#ifndef OPENSSL_NO_DSA 80#ifndef OPENSSL_NO_DSA
99#include <openssl/dsa.h> 81#include <openssl/dsa.h>
100#endif 82#endif
83
101#ifndef OPENSSL_NO_DH 84#ifndef OPENSSL_NO_DH
102#include <openssl/dh.h> 85#include <openssl/dh.h>
103#endif 86#endif
104#endif
105
106#ifndef OPENSSL_NO_SHA 87#ifndef OPENSSL_NO_SHA
107#include <openssl/sha.h> 88#include <openssl/sha.h>
108#endif 89#endif
90#include <openssl/e_os2.h>
109#include <openssl/ossl_typ.h> 91#include <openssl/ossl_typ.h>
110 92
111#ifdef __cplusplus 93#ifdef __cplusplus
@@ -113,9 +95,8 @@ extern "C" {
113#endif 95#endif
114 96
115#ifdef OPENSSL_SYS_WIN32 97#ifdef OPENSSL_SYS_WIN32
116/* Under Win32 these are defined in wincrypt.h */ 98/* Under Win32 this is defined in wincrypt.h */
117#undef X509_NAME 99#undef X509_NAME
118#undef X509_CERT_PAIR
119#endif 100#endif
120 101
121#define X509_FILETYPE_PEM 1 102#define X509_FILETYPE_PEM 1
@@ -136,8 +117,8 @@ extern "C" {
136typedef struct X509_objects_st 117typedef struct X509_objects_st
137 { 118 {
138 int nid; 119 int nid;
139 int (*a2i)(void); 120 int (*a2i)();
140 int (*i2a)(void); 121 int (*i2a)();
141 } X509_OBJECTS; 122 } X509_OBJECTS;
142 123
143struct X509_algor_st 124struct X509_algor_st
@@ -146,10 +127,9 @@ struct X509_algor_st
146 ASN1_TYPE *parameter; 127 ASN1_TYPE *parameter;
147 } /* X509_ALGOR */; 128 } /* X509_ALGOR */;
148 129
130DECLARE_STACK_OF(X509_ALGOR)
149DECLARE_ASN1_SET_OF(X509_ALGOR) 131DECLARE_ASN1_SET_OF(X509_ALGOR)
150 132
151typedef STACK_OF(X509_ALGOR) X509_ALGORS;
152
153typedef struct X509_val_st 133typedef struct X509_val_st
154 { 134 {
155 ASN1_TIME *notBefore; 135 ASN1_TIME *notBefore;
@@ -204,8 +184,6 @@ typedef struct X509_extension_st
204 ASN1_OCTET_STRING *value; 184 ASN1_OCTET_STRING *value;
205 } X509_EXTENSION; 185 } X509_EXTENSION;
206 186
207typedef STACK_OF(X509_EXTENSION) X509_EXTENSIONS;
208
209DECLARE_STACK_OF(X509_EXTENSION) 187DECLARE_STACK_OF(X509_EXTENSION)
210DECLARE_ASN1_SET_OF(X509_EXTENSION) 188DECLARE_ASN1_SET_OF(X509_EXTENSION)
211 189
@@ -283,18 +261,12 @@ struct x509_st
283 CRYPTO_EX_DATA ex_data; 261 CRYPTO_EX_DATA ex_data;
284 /* These contain copies of various extension values */ 262 /* These contain copies of various extension values */
285 long ex_pathlen; 263 long ex_pathlen;
286 long ex_pcpathlen;
287 unsigned long ex_flags; 264 unsigned long ex_flags;
288 unsigned long ex_kusage; 265 unsigned long ex_kusage;
289 unsigned long ex_xkusage; 266 unsigned long ex_xkusage;
290 unsigned long ex_nscert; 267 unsigned long ex_nscert;
291 ASN1_OCTET_STRING *skid; 268 ASN1_OCTET_STRING *skid;
292 struct AUTHORITY_KEYID_st *akid; 269 struct AUTHORITY_KEYID_st *akid;
293 X509_POLICY_CACHE *policy_cache;
294#ifndef OPENSSL_NO_RFC3779
295 STACK_OF(IPAddressFamily) *rfc3779_addr;
296 struct ASIdentifiers_st *rfc3779_asid;
297#endif
298#ifndef OPENSSL_NO_SHA 270#ifndef OPENSSL_NO_SHA
299 unsigned char sha1_hash[SHA_DIGEST_LENGTH]; 271 unsigned char sha1_hash[SHA_DIGEST_LENGTH];
300#endif 272#endif
@@ -317,11 +289,6 @@ typedef struct x509_trust_st {
317 289
318DECLARE_STACK_OF(X509_TRUST) 290DECLARE_STACK_OF(X509_TRUST)
319 291
320typedef struct x509_cert_pair_st {
321 X509 *forward;
322 X509 *reverse;
323} X509_CERT_PAIR;
324
325/* standard trust ids */ 292/* standard trust ids */
326 293
327#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */ 294#define X509_TRUST_DEFAULT -1 /* Only valid in purpose settings */
@@ -688,17 +655,6 @@ extern "C" {
688#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \ 655#define i2d_DSAPrivateKey_bio(bp,dsa) ASN1_i2d_bio(i2d_DSAPrivateKey,bp, \
689 (unsigned char *)dsa) 656 (unsigned char *)dsa)
690 657
691#define d2i_ECPrivateKey_fp(fp,ecdsa) (EC_KEY *)ASN1_d2i_fp((char *(*)())\
692 EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (fp), \
693 (unsigned char **)(ecdsa))
694#define i2d_ECPrivateKey_fp(fp,ecdsa) ASN1_i2d_fp(i2d_ECPrivateKey,fp, \
695 (unsigned char *)ecdsa)
696#define d2i_ECPrivateKey_bio(bp,ecdsa) (EC_KEY *)ASN1_d2i_bio((char *(*)())\
697 EC_KEY_new,(char *(*)())d2i_ECPrivateKey, (bp), \
698 (unsigned char **)(ecdsa))
699#define i2d_ECPrivateKey_bio(bp,ecdsa) ASN1_i2d_bio(i2d_ECPrivateKey,bp, \
700 (unsigned char *)ecdsa)
701
702#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\ 658#define X509_ALGOR_dup(xn) (X509_ALGOR *)ASN1_dup((int (*)())i2d_X509_ALGOR,\
703 (char *(*)())d2i_X509_ALGOR,(char *)xn) 659 (char *(*)())d2i_X509_ALGOR,(char *)xn)
704 660
@@ -802,12 +758,6 @@ int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa);
802DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa); 758DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
803int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa); 759int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
804#endif 760#endif
805#ifndef OPENSSL_NO_EC
806EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey);
807int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey);
808EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey);
809int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey);
810#endif
811X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8); 761X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
812int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8); 762int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
813PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, 763PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
@@ -841,12 +791,6 @@ int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa);
841DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa); 791DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
842int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa); 792int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
843#endif 793#endif
844#ifndef OPENSSL_NO_EC
845EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey);
846int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *eckey);
847EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey);
848int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey);
849#endif
850X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8); 794X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
851int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8); 795int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
852PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, 796PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
@@ -865,10 +809,6 @@ X509_EXTENSION *X509_EXTENSION_dup(X509_EXTENSION *ex);
865X509_CRL *X509_CRL_dup(X509_CRL *crl); 809X509_CRL *X509_CRL_dup(X509_CRL *crl);
866X509_REQ *X509_REQ_dup(X509_REQ *req); 810X509_REQ *X509_REQ_dup(X509_REQ *req);
867X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn); 811X509_ALGOR *X509_ALGOR_dup(X509_ALGOR *xn);
868int X509_ALGOR_set0(X509_ALGOR *alg, ASN1_OBJECT *aobj, int ptype, void *pval);
869void X509_ALGOR_get0(ASN1_OBJECT **paobj, int *pptype, void **ppval,
870 X509_ALGOR *algor);
871
872X509_NAME *X509_NAME_dup(X509_NAME *xn); 812X509_NAME *X509_NAME_dup(X509_NAME *xn);
873X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne); 813X509_NAME_ENTRY *X509_NAME_ENTRY_dup(X509_NAME_ENTRY *ne);
874 814
@@ -890,7 +830,6 @@ X509_REQ * X509_to_X509_REQ(X509 *x, EVP_PKEY *pkey, const EVP_MD *md);
890X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey); 830X509 * X509_REQ_to_X509(X509_REQ *r, int days,EVP_PKEY *pkey);
891 831
892DECLARE_ASN1_FUNCTIONS(X509_ALGOR) 832DECLARE_ASN1_FUNCTIONS(X509_ALGOR)
893DECLARE_ASN1_ENCODE_FUNCTIONS(X509_ALGORS, X509_ALGORS, X509_ALGORS)
894DECLARE_ASN1_FUNCTIONS(X509_VAL) 833DECLARE_ASN1_FUNCTIONS(X509_VAL)
895 834
896DECLARE_ASN1_FUNCTIONS(X509_PUBKEY) 835DECLARE_ASN1_FUNCTIONS(X509_PUBKEY)
@@ -900,21 +839,16 @@ EVP_PKEY * X509_PUBKEY_get(X509_PUBKEY *key);
900int X509_get_pubkey_parameters(EVP_PKEY *pkey, 839int X509_get_pubkey_parameters(EVP_PKEY *pkey,
901 STACK_OF(X509) *chain); 840 STACK_OF(X509) *chain);
902int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp); 841int i2d_PUBKEY(EVP_PKEY *a,unsigned char **pp);
903EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,const unsigned char **pp, 842EVP_PKEY * d2i_PUBKEY(EVP_PKEY **a,unsigned char **pp,
904 long length); 843 long length);
905#ifndef OPENSSL_NO_RSA 844#ifndef OPENSSL_NO_RSA
906int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp); 845int i2d_RSA_PUBKEY(RSA *a,unsigned char **pp);
907RSA * d2i_RSA_PUBKEY(RSA **a,const unsigned char **pp, 846RSA * d2i_RSA_PUBKEY(RSA **a,unsigned char **pp,
908 long length); 847 long length);
909#endif 848#endif
910#ifndef OPENSSL_NO_DSA 849#ifndef OPENSSL_NO_DSA
911int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp); 850int i2d_DSA_PUBKEY(DSA *a,unsigned char **pp);
912DSA * d2i_DSA_PUBKEY(DSA **a,const unsigned char **pp, 851DSA * d2i_DSA_PUBKEY(DSA **a,unsigned char **pp,
913 long length);
914#endif
915#ifndef OPENSSL_NO_EC
916int i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp);
917EC_KEY *d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp,
918 long length); 852 long length);
919#endif 853#endif
920 854
@@ -926,7 +860,6 @@ DECLARE_ASN1_FUNCTIONS(X509_ATTRIBUTE)
926X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value); 860X509_ATTRIBUTE *X509_ATTRIBUTE_create(int nid, int atrtype, void *value);
927 861
928DECLARE_ASN1_FUNCTIONS(X509_EXTENSION) 862DECLARE_ASN1_FUNCTIONS(X509_EXTENSION)
929DECLARE_ASN1_ENCODE_FUNCTIONS(X509_EXTENSIONS, X509_EXTENSIONS, X509_EXTENSIONS)
930 863
931DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY) 864DECLARE_ASN1_FUNCTIONS(X509_NAME_ENTRY)
932 865
@@ -939,19 +872,16 @@ DECLARE_ASN1_FUNCTIONS(X509_CINF)
939DECLARE_ASN1_FUNCTIONS(X509) 872DECLARE_ASN1_FUNCTIONS(X509)
940DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX) 873DECLARE_ASN1_FUNCTIONS(X509_CERT_AUX)
941 874
942DECLARE_ASN1_FUNCTIONS(X509_CERT_PAIR)
943
944int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func, 875int X509_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
945 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func); 876 CRYPTO_EX_dup *dup_func, CRYPTO_EX_free *free_func);
946int X509_set_ex_data(X509 *r, int idx, void *arg); 877int X509_set_ex_data(X509 *r, int idx, void *arg);
947void *X509_get_ex_data(X509 *r, int idx); 878void *X509_get_ex_data(X509 *r, int idx);
948int i2d_X509_AUX(X509 *a,unsigned char **pp); 879int i2d_X509_AUX(X509 *a,unsigned char **pp);
949X509 * d2i_X509_AUX(X509 **a,const unsigned char **pp,long length); 880X509 * d2i_X509_AUX(X509 **a,unsigned char **pp,long length);
950 881
951int X509_alias_set1(X509 *x, unsigned char *name, int len); 882int X509_alias_set1(X509 *x, unsigned char *name, int len);
952int X509_keyid_set1(X509 *x, unsigned char *id, int len); 883int X509_keyid_set1(X509 *x, unsigned char *id, int len);
953unsigned char * X509_alias_get0(X509 *x, int *len); 884unsigned char * X509_alias_get0(X509 *x, int *len);
954unsigned char * X509_keyid_get0(X509 *x, int *len);
955int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int); 885int (*X509_TRUST_set_default(int (*trust)(int , X509 *, int)))(int, X509 *, int);
956int X509_TRUST_set(int *t, int trust); 886int X509_TRUST_set(int *t, int trust);
957int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj); 887int X509_add1_trust_object(X509 *x, ASN1_OBJECT *obj);
@@ -968,7 +898,7 @@ int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev);
968X509_PKEY * X509_PKEY_new(void ); 898X509_PKEY * X509_PKEY_new(void );
969void X509_PKEY_free(X509_PKEY *a); 899void X509_PKEY_free(X509_PKEY *a);
970int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp); 900int i2d_X509_PKEY(X509_PKEY *a,unsigned char **pp);
971X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,const unsigned char **pp,long length); 901X509_PKEY * d2i_X509_PKEY(X509_PKEY **a,unsigned char **pp,long length);
972 902
973DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI) 903DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKI)
974DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC) 904DECLARE_ASN1_FUNCTIONS(NETSCAPE_SPKAC)
@@ -979,15 +909,15 @@ X509_INFO * X509_INFO_new(void);
979void X509_INFO_free(X509_INFO *a); 909void X509_INFO_free(X509_INFO *a);
980char * X509_NAME_oneline(X509_NAME *a,char *buf,int size); 910char * X509_NAME_oneline(X509_NAME *a,char *buf,int size);
981 911
982int ASN1_verify(i2d_of_void *i2d, X509_ALGOR *algor1, 912int ASN1_verify(int (*i2d)(), X509_ALGOR *algor1,
983 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey); 913 ASN1_BIT_STRING *signature,char *data,EVP_PKEY *pkey);
984 914
985int ASN1_digest(i2d_of_void *i2d,const EVP_MD *type,char *data, 915int ASN1_digest(int (*i2d)(),const EVP_MD *type,char *data,
986 unsigned char *md,unsigned int *len); 916 unsigned char *md,unsigned int *len);
987 917
988int ASN1_sign(i2d_of_void *i2d, X509_ALGOR *algor1, 918int ASN1_sign(int (*i2d)(), X509_ALGOR *algor1, X509_ALGOR *algor2,
989 X509_ALGOR *algor2, ASN1_BIT_STRING *signature, 919 ASN1_BIT_STRING *signature,
990 char *data,EVP_PKEY *pkey, const EVP_MD *type); 920 char *data,EVP_PKEY *pkey, const EVP_MD *type);
991 921
992int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data, 922int ASN1_item_digest(const ASN1_ITEM *it,const EVP_MD *type,void *data,
993 unsigned char *md,unsigned int *len); 923 unsigned char *md,unsigned int *len);
@@ -1052,8 +982,6 @@ int X509_CRL_sort(X509_CRL *crl);
1052int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial); 982int X509_REVOKED_set_serialNumber(X509_REVOKED *x, ASN1_INTEGER *serial);
1053int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm); 983int X509_REVOKED_set_revocationDate(X509_REVOKED *r, ASN1_TIME *tm);
1054 984
1055int X509_REQ_check_private_key(X509_REQ *x509,EVP_PKEY *pkey);
1056
1057int X509_check_private_key(X509 *x509,EVP_PKEY *pkey); 985int X509_check_private_key(X509 *x509,EVP_PKEY *pkey);
1058 986
1059int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b); 987int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b);
@@ -1200,8 +1128,6 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_NID(STACK_OF(X509_ATTRIBUTE) **x,
1200STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x, 1128STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
1201 const char *attrname, int type, 1129 const char *attrname, int type,
1202 const unsigned char *bytes, int len); 1130 const unsigned char *bytes, int len);
1203void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x,
1204 ASN1_OBJECT *obj, int lastpos, int type);
1205X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, 1131X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
1206 int atrtype, const void *data, int len); 1132 int atrtype, const void *data, int len);
1207X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr, 1133X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_OBJ(X509_ATTRIBUTE **attr,
@@ -1216,24 +1142,6 @@ int X509_ATTRIBUTE_count(X509_ATTRIBUTE *attr);
1216ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr); 1142ASN1_OBJECT *X509_ATTRIBUTE_get0_object(X509_ATTRIBUTE *attr);
1217ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx); 1143ASN1_TYPE *X509_ATTRIBUTE_get0_type(X509_ATTRIBUTE *attr, int idx);
1218 1144
1219int EVP_PKEY_get_attr_count(const EVP_PKEY *key);
1220int EVP_PKEY_get_attr_by_NID(const EVP_PKEY *key, int nid,
1221 int lastpos);
1222int EVP_PKEY_get_attr_by_OBJ(const EVP_PKEY *key, ASN1_OBJECT *obj,
1223 int lastpos);
1224X509_ATTRIBUTE *EVP_PKEY_get_attr(const EVP_PKEY *key, int loc);
1225X509_ATTRIBUTE *EVP_PKEY_delete_attr(EVP_PKEY *key, int loc);
1226int EVP_PKEY_add1_attr(EVP_PKEY *key, X509_ATTRIBUTE *attr);
1227int EVP_PKEY_add1_attr_by_OBJ(EVP_PKEY *key,
1228 const ASN1_OBJECT *obj, int type,
1229 const unsigned char *bytes, int len);
1230int EVP_PKEY_add1_attr_by_NID(EVP_PKEY *key,
1231 int nid, int type,
1232 const unsigned char *bytes, int len);
1233int EVP_PKEY_add1_attr_by_txt(EVP_PKEY *key,
1234 const char *attrname, int type,
1235 const unsigned char *bytes, int len);
1236
1237int X509_verify_cert(X509_STORE_CTX *ctx); 1145int X509_verify_cert(X509_STORE_CTX *ctx);
1238 1146
1239/* lookup a cert from a X509 STACK */ 1147/* lookup a cert from a X509 STACK */
@@ -1280,20 +1188,18 @@ void ERR_load_X509_strings(void);
1280/* Function codes. */ 1188/* Function codes. */
1281#define X509_F_ADD_CERT_DIR 100 1189#define X509_F_ADD_CERT_DIR 100
1282#define X509_F_BY_FILE_CTRL 101 1190#define X509_F_BY_FILE_CTRL 101
1283#define X509_F_CHECK_POLICY 145
1284#define X509_F_DIR_CTRL 102 1191#define X509_F_DIR_CTRL 102
1285#define X509_F_GET_CERT_BY_SUBJECT 103 1192#define X509_F_GET_CERT_BY_SUBJECT 103
1286#define X509_F_NETSCAPE_SPKI_B64_DECODE 129 1193#define X509_F_NETSCAPE_SPKI_B64_DECODE 129
1287#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130 1194#define X509_F_NETSCAPE_SPKI_B64_ENCODE 130
1288#define X509_F_X509AT_ADD1_ATTR 135
1289#define X509_F_X509V3_ADD_EXT 104 1195#define X509_F_X509V3_ADD_EXT 104
1196#define X509_F_X509_ADD_ATTR 135
1290#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136 1197#define X509_F_X509_ATTRIBUTE_CREATE_BY_NID 136
1291#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137 1198#define X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ 137
1292#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140 1199#define X509_F_X509_ATTRIBUTE_CREATE_BY_TXT 140
1293#define X509_F_X509_ATTRIBUTE_GET0_DATA 139 1200#define X509_F_X509_ATTRIBUTE_GET0_DATA 139
1294#define X509_F_X509_ATTRIBUTE_SET1_DATA 138 1201#define X509_F_X509_ATTRIBUTE_SET1_DATA 138
1295#define X509_F_X509_CHECK_PRIVATE_KEY 128 1202#define X509_F_X509_CHECK_PRIVATE_KEY 128
1296#define X509_F_X509_CRL_PRINT_FP 147
1297#define X509_F_X509_EXTENSION_CREATE_BY_NID 108 1203#define X509_F_X509_EXTENSION_CREATE_BY_NID 108
1298#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109 1204#define X509_F_X509_EXTENSION_CREATE_BY_OBJ 109
1299#define X509_F_X509_GET_PUBKEY_PARAMETERS 110 1205#define X509_F_X509_GET_PUBKEY_PARAMETERS 110
@@ -1306,16 +1212,14 @@ void ERR_load_X509_strings(void);
1306#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115 1212#define X509_F_X509_NAME_ENTRY_SET_OBJECT 115
1307#define X509_F_X509_NAME_ONELINE 116 1213#define X509_F_X509_NAME_ONELINE 116
1308#define X509_F_X509_NAME_PRINT 117 1214#define X509_F_X509_NAME_PRINT 117
1309#define X509_F_X509_PRINT_EX_FP 118 1215#define X509_F_X509_PRINT_FP 118
1310#define X509_F_X509_PUBKEY_GET 119 1216#define X509_F_X509_PUBKEY_GET 119
1311#define X509_F_X509_PUBKEY_SET 120 1217#define X509_F_X509_PUBKEY_SET 120
1312#define X509_F_X509_REQ_CHECK_PRIVATE_KEY 144 1218#define X509_F_X509_REQ_PRINT 121
1313#define X509_F_X509_REQ_PRINT_EX 121
1314#define X509_F_X509_REQ_PRINT_FP 122 1219#define X509_F_X509_REQ_PRINT_FP 122
1315#define X509_F_X509_REQ_TO_X509 123 1220#define X509_F_X509_REQ_TO_X509 123
1316#define X509_F_X509_STORE_ADD_CERT 124 1221#define X509_F_X509_STORE_ADD_CERT 124
1317#define X509_F_X509_STORE_ADD_CRL 125 1222#define X509_F_X509_STORE_ADD_CRL 125
1318#define X509_F_X509_STORE_CTX_GET1_ISSUER 146
1319#define X509_F_X509_STORE_CTX_INIT 143 1223#define X509_F_X509_STORE_CTX_INIT 143
1320#define X509_F_X509_STORE_CTX_NEW 142 1224#define X509_F_X509_STORE_CTX_NEW 142
1321#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134 1225#define X509_F_X509_STORE_CTX_PURPOSE_INHERIT 134
diff --git a/src/lib/libcrypto/x509/x509_att.c b/src/lib/libcrypto/x509/x509_att.c
index 511b49d589..0bae3d32a1 100644
--- a/src/lib/libcrypto/x509/x509_att.c
+++ b/src/lib/libcrypto/x509/x509_att.c
@@ -67,7 +67,8 @@
67 67
68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x) 68int X509at_get_attr_count(const STACK_OF(X509_ATTRIBUTE) *x)
69{ 69{
70 return sk_X509_ATTRIBUTE_num(x); 70 if (!x) return 0;
71 return(sk_X509_ATTRIBUTE_num(x));
71} 72}
72 73
73int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid, 74int X509at_get_attr_by_NID(const STACK_OF(X509_ATTRIBUTE) *x, int nid,
@@ -124,13 +125,7 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
124 X509_ATTRIBUTE *new_attr=NULL; 125 X509_ATTRIBUTE *new_attr=NULL;
125 STACK_OF(X509_ATTRIBUTE) *sk=NULL; 126 STACK_OF(X509_ATTRIBUTE) *sk=NULL;
126 127
127 if (x == NULL) 128 if ((x != NULL) && (*x == NULL))
128 {
129 X509err(X509_F_X509AT_ADD1_ATTR, ERR_R_PASSED_NULL_PARAMETER);
130 goto err2;
131 }
132
133 if (*x == NULL)
134 { 129 {
135 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL) 130 if ((sk=sk_X509_ATTRIBUTE_new_null()) == NULL)
136 goto err; 131 goto err;
@@ -142,11 +137,11 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr(STACK_OF(X509_ATTRIBUTE) **x,
142 goto err2; 137 goto err2;
143 if (!sk_X509_ATTRIBUTE_push(sk,new_attr)) 138 if (!sk_X509_ATTRIBUTE_push(sk,new_attr))
144 goto err; 139 goto err;
145 if (*x == NULL) 140 if ((x != NULL) && (*x == NULL))
146 *x=sk; 141 *x=sk;
147 return(sk); 142 return(sk);
148err: 143err:
149 X509err(X509_F_X509AT_ADD1_ATTR,ERR_R_MALLOC_FAILURE); 144 X509err(X509_F_X509_ADD_ATTR,ERR_R_MALLOC_FAILURE);
150err2: 145err2:
151 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr); 146 if (new_attr != NULL) X509_ATTRIBUTE_free(new_attr);
152 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk); 147 if (sk != NULL) sk_X509_ATTRIBUTE_free(sk);
@@ -192,22 +187,6 @@ STACK_OF(X509_ATTRIBUTE) *X509at_add1_attr_by_txt(STACK_OF(X509_ATTRIBUTE) **x,
192 return ret; 187 return ret;
193} 188}
194 189
195void *X509at_get0_data_by_OBJ(STACK_OF(X509_ATTRIBUTE) *x,
196 ASN1_OBJECT *obj, int lastpos, int type)
197{
198 int i;
199 X509_ATTRIBUTE *at;
200 i = X509at_get_attr_by_OBJ(x, obj, lastpos);
201 if (i == -1)
202 return NULL;
203 if ((lastpos <= -2) && (X509at_get_attr_by_OBJ(x, obj, i) != -1))
204 return NULL;
205 at = X509at_get_attr(x, i);
206 if (lastpos <= -3 && (X509_ATTRIBUTE_count(at) != 1))
207 return NULL;
208 return X509_ATTRIBUTE_get0_data(at, 0, type, NULL);
209}
210
211X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid, 190X509_ATTRIBUTE *X509_ATTRIBUTE_create_by_NID(X509_ATTRIBUTE **attr, int nid,
212 int atrtype, const void *data, int len) 191 int atrtype, const void *data, int len)
213{ 192{
@@ -285,8 +264,8 @@ int X509_ATTRIBUTE_set1_object(X509_ATTRIBUTE *attr, const ASN1_OBJECT *obj)
285int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len) 264int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *data, int len)
286{ 265{
287 ASN1_TYPE *ttmp; 266 ASN1_TYPE *ttmp;
288 ASN1_STRING *stmp = NULL; 267 ASN1_STRING *stmp;
289 int atype = 0; 268 int atype;
290 if (!attr) return 0; 269 if (!attr) return 0;
291 if(attrtype & MBSTRING_FLAG) { 270 if(attrtype & MBSTRING_FLAG) {
292 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype, 271 stmp = ASN1_STRING_set_by_NID(NULL, data, len, attrtype,
@@ -296,22 +275,16 @@ int X509_ATTRIBUTE_set1_data(X509_ATTRIBUTE *attr, int attrtype, const void *dat
296 return 0; 275 return 0;
297 } 276 }
298 atype = stmp->type; 277 atype = stmp->type;
299 } else if (len != -1){ 278 } else {
300 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err; 279 if(!(stmp = ASN1_STRING_type_new(attrtype))) goto err;
301 if(!ASN1_STRING_set(stmp, data, len)) goto err; 280 if(!ASN1_STRING_set(stmp, data, len)) goto err;
302 atype = attrtype; 281 atype = attrtype;
303 } 282 }
304 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err; 283 if(!(attr->value.set = sk_ASN1_TYPE_new_null())) goto err;
305 if(!(ttmp = ASN1_TYPE_new())) goto err; 284 if(!(ttmp = ASN1_TYPE_new())) goto err;
306 if (len == -1)
307 {
308 if (!ASN1_TYPE_set1(ttmp, attrtype, data))
309 goto err;
310 }
311 else
312 ASN1_TYPE_set(ttmp, atype, stmp);
313 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err; 285 if(!sk_ASN1_TYPE_push(attr->value.set, ttmp)) goto err;
314 attr->single = 0; 286 attr->single = 0;
287 ASN1_TYPE_set(ttmp, atype, stmp);
315 return 1; 288 return 1;
316 err: 289 err:
317 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE); 290 X509err(X509_F_X509_ATTRIBUTE_SET1_DATA, ERR_R_MALLOC_FAILURE);
diff --git a/src/lib/libcrypto/x509/x509_cmp.c b/src/lib/libcrypto/x509/x509_cmp.c
index 0d6bc653b2..030d0966fc 100644
--- a/src/lib/libcrypto/x509/x509_cmp.c
+++ b/src/lib/libcrypto/x509/x509_cmp.c
@@ -322,10 +322,16 @@ unsigned long X509_NAME_hash(X509_NAME *x)
322 { 322 {
323 unsigned long ret=0; 323 unsigned long ret=0;
324 unsigned char md[16]; 324 unsigned char md[16];
325 EVP_MD_CTX md_ctx;
325 326
326 /* Make sure X509_NAME structure contains valid cached encoding */ 327 /* Make sure X509_NAME structure contains valid cached encoding */
327 i2d_X509_NAME(x,NULL); 328 i2d_X509_NAME(x,NULL);
328 EVP_Digest(x->bytes->data, x->bytes->length, md, NULL, EVP_md5(), NULL); 329 EVP_MD_CTX_init(&md_ctx);
330 EVP_MD_CTX_set_flags(&md_ctx, EVP_MD_CTX_FLAG_NON_FIPS_ALLOW);
331 EVP_DigestInit_ex(&md_ctx, EVP_md5(), NULL);
332 EVP_DigestUpdate(&md_ctx, x->bytes->data, x->bytes->length);
333 EVP_DigestFinal_ex(&md_ctx,md,NULL);
334 EVP_MD_CTX_cleanup(&md_ctx);
329 335
330 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)| 336 ret=( ((unsigned long)md[0] )|((unsigned long)md[1]<<8L)|
331 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L) 337 ((unsigned long)md[2]<<16L)|((unsigned long)md[3]<<24L)
@@ -390,36 +396,45 @@ int X509_check_private_key(X509 *x, EVP_PKEY *k)
390 int ok=0; 396 int ok=0;
391 397
392 xk=X509_get_pubkey(x); 398 xk=X509_get_pubkey(x);
393 switch (EVP_PKEY_cmp(xk, k)) 399 if (xk->type != k->type)
400 {
401 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
402 goto err;
403 }
404 switch (k->type)
394 { 405 {
395 case 1: 406#ifndef OPENSSL_NO_RSA
396 ok=1; 407 case EVP_PKEY_RSA:
408 if (BN_cmp(xk->pkey.rsa->n,k->pkey.rsa->n) != 0
409 || BN_cmp(xk->pkey.rsa->e,k->pkey.rsa->e) != 0)
410 {
411 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
412 goto err;
413 }
397 break; 414 break;
398 case 0: 415#endif
399 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH); 416#ifndef OPENSSL_NO_DSA
400 break; 417 case EVP_PKEY_DSA:
401 case -1: 418 if (BN_cmp(xk->pkey.dsa->pub_key,k->pkey.dsa->pub_key) != 0)
402 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH); 419 {
420 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
421 goto err;
422 }
403 break; 423 break;
404 case -2:
405#ifndef OPENSSL_NO_EC
406 if (k->type == EVP_PKEY_EC)
407 {
408 X509err(X509_F_X509_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);
409 break;
410 }
411#endif 424#endif
412#ifndef OPENSSL_NO_DH 425#ifndef OPENSSL_NO_DH
413 if (k->type == EVP_PKEY_DH) 426 case EVP_PKEY_DH:
414 { 427 /* No idea */
415 /* No idea */ 428 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
416 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY); 429 goto err;
417 break;
418 }
419#endif 430#endif
431 default:
420 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE); 432 X509err(X509_F_X509_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
433 goto err;
421 } 434 }
422 435
436 ok=1;
437err:
423 EVP_PKEY_free(xk); 438 EVP_PKEY_free(xk);
424 return(ok); 439 return(ok);
425 } 440 }
diff --git a/src/lib/libcrypto/x509/x509_err.c b/src/lib/libcrypto/x509/x509_err.c
index fb377292da..d44d046027 100644
--- a/src/lib/libcrypto/x509/x509_err.c
+++ b/src/lib/libcrypto/x509/x509_err.c
@@ -72,20 +72,18 @@ static ERR_STRING_DATA X509_str_functs[]=
72 { 72 {
73{ERR_FUNC(X509_F_ADD_CERT_DIR), "ADD_CERT_DIR"}, 73{ERR_FUNC(X509_F_ADD_CERT_DIR), "ADD_CERT_DIR"},
74{ERR_FUNC(X509_F_BY_FILE_CTRL), "BY_FILE_CTRL"}, 74{ERR_FUNC(X509_F_BY_FILE_CTRL), "BY_FILE_CTRL"},
75{ERR_FUNC(X509_F_CHECK_POLICY), "CHECK_POLICY"},
76{ERR_FUNC(X509_F_DIR_CTRL), "DIR_CTRL"}, 75{ERR_FUNC(X509_F_DIR_CTRL), "DIR_CTRL"},
77{ERR_FUNC(X509_F_GET_CERT_BY_SUBJECT), "GET_CERT_BY_SUBJECT"}, 76{ERR_FUNC(X509_F_GET_CERT_BY_SUBJECT), "GET_CERT_BY_SUBJECT"},
78{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_DECODE), "NETSCAPE_SPKI_b64_decode"}, 77{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_DECODE), "NETSCAPE_SPKI_b64_decode"},
79{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_ENCODE), "NETSCAPE_SPKI_b64_encode"}, 78{ERR_FUNC(X509_F_NETSCAPE_SPKI_B64_ENCODE), "NETSCAPE_SPKI_b64_encode"},
80{ERR_FUNC(X509_F_X509AT_ADD1_ATTR), "X509at_add1_attr"},
81{ERR_FUNC(X509_F_X509V3_ADD_EXT), "X509v3_add_ext"}, 79{ERR_FUNC(X509_F_X509V3_ADD_EXT), "X509v3_add_ext"},
80{ERR_FUNC(X509_F_X509_ADD_ATTR), "X509_ADD_ATTR"},
82{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_NID), "X509_ATTRIBUTE_create_by_NID"}, 81{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_NID), "X509_ATTRIBUTE_create_by_NID"},
83{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ), "X509_ATTRIBUTE_create_by_OBJ"}, 82{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_OBJ), "X509_ATTRIBUTE_create_by_OBJ"},
84{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT), "X509_ATTRIBUTE_create_by_txt"}, 83{ERR_FUNC(X509_F_X509_ATTRIBUTE_CREATE_BY_TXT), "X509_ATTRIBUTE_create_by_txt"},
85{ERR_FUNC(X509_F_X509_ATTRIBUTE_GET0_DATA), "X509_ATTRIBUTE_get0_data"}, 84{ERR_FUNC(X509_F_X509_ATTRIBUTE_GET0_DATA), "X509_ATTRIBUTE_get0_data"},
86{ERR_FUNC(X509_F_X509_ATTRIBUTE_SET1_DATA), "X509_ATTRIBUTE_set1_data"}, 85{ERR_FUNC(X509_F_X509_ATTRIBUTE_SET1_DATA), "X509_ATTRIBUTE_set1_data"},
87{ERR_FUNC(X509_F_X509_CHECK_PRIVATE_KEY), "X509_check_private_key"}, 86{ERR_FUNC(X509_F_X509_CHECK_PRIVATE_KEY), "X509_check_private_key"},
88{ERR_FUNC(X509_F_X509_CRL_PRINT_FP), "X509_CRL_print_fp"},
89{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_NID), "X509_EXTENSION_create_by_NID"}, 87{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_NID), "X509_EXTENSION_create_by_NID"},
90{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_OBJ), "X509_EXTENSION_create_by_OBJ"}, 88{ERR_FUNC(X509_F_X509_EXTENSION_CREATE_BY_OBJ), "X509_EXTENSION_create_by_OBJ"},
91{ERR_FUNC(X509_F_X509_GET_PUBKEY_PARAMETERS), "X509_get_pubkey_parameters"}, 89{ERR_FUNC(X509_F_X509_GET_PUBKEY_PARAMETERS), "X509_get_pubkey_parameters"},
@@ -98,16 +96,14 @@ static ERR_STRING_DATA X509_str_functs[]=
98{ERR_FUNC(X509_F_X509_NAME_ENTRY_SET_OBJECT), "X509_NAME_ENTRY_set_object"}, 96{ERR_FUNC(X509_F_X509_NAME_ENTRY_SET_OBJECT), "X509_NAME_ENTRY_set_object"},
99{ERR_FUNC(X509_F_X509_NAME_ONELINE), "X509_NAME_oneline"}, 97{ERR_FUNC(X509_F_X509_NAME_ONELINE), "X509_NAME_oneline"},
100{ERR_FUNC(X509_F_X509_NAME_PRINT), "X509_NAME_print"}, 98{ERR_FUNC(X509_F_X509_NAME_PRINT), "X509_NAME_print"},
101{ERR_FUNC(X509_F_X509_PRINT_EX_FP), "X509_print_ex_fp"}, 99{ERR_FUNC(X509_F_X509_PRINT_FP), "X509_print_fp"},
102{ERR_FUNC(X509_F_X509_PUBKEY_GET), "X509_PUBKEY_get"}, 100{ERR_FUNC(X509_F_X509_PUBKEY_GET), "X509_PUBKEY_get"},
103{ERR_FUNC(X509_F_X509_PUBKEY_SET), "X509_PUBKEY_set"}, 101{ERR_FUNC(X509_F_X509_PUBKEY_SET), "X509_PUBKEY_set"},
104{ERR_FUNC(X509_F_X509_REQ_CHECK_PRIVATE_KEY), "X509_REQ_check_private_key"}, 102{ERR_FUNC(X509_F_X509_REQ_PRINT), "X509_REQ_print"},
105{ERR_FUNC(X509_F_X509_REQ_PRINT_EX), "X509_REQ_print_ex"},
106{ERR_FUNC(X509_F_X509_REQ_PRINT_FP), "X509_REQ_print_fp"}, 103{ERR_FUNC(X509_F_X509_REQ_PRINT_FP), "X509_REQ_print_fp"},
107{ERR_FUNC(X509_F_X509_REQ_TO_X509), "X509_REQ_to_X509"}, 104{ERR_FUNC(X509_F_X509_REQ_TO_X509), "X509_REQ_to_X509"},
108{ERR_FUNC(X509_F_X509_STORE_ADD_CERT), "X509_STORE_add_cert"}, 105{ERR_FUNC(X509_F_X509_STORE_ADD_CERT), "X509_STORE_add_cert"},
109{ERR_FUNC(X509_F_X509_STORE_ADD_CRL), "X509_STORE_add_crl"}, 106{ERR_FUNC(X509_F_X509_STORE_ADD_CRL), "X509_STORE_add_crl"},
110{ERR_FUNC(X509_F_X509_STORE_CTX_GET1_ISSUER), "X509_STORE_CTX_get1_issuer"},
111{ERR_FUNC(X509_F_X509_STORE_CTX_INIT), "X509_STORE_CTX_init"}, 107{ERR_FUNC(X509_F_X509_STORE_CTX_INIT), "X509_STORE_CTX_init"},
112{ERR_FUNC(X509_F_X509_STORE_CTX_NEW), "X509_STORE_CTX_new"}, 108{ERR_FUNC(X509_F_X509_STORE_CTX_NEW), "X509_STORE_CTX_new"},
113{ERR_FUNC(X509_F_X509_STORE_CTX_PURPOSE_INHERIT), "X509_STORE_CTX_purpose_inherit"}, 109{ERR_FUNC(X509_F_X509_STORE_CTX_PURPOSE_INHERIT), "X509_STORE_CTX_purpose_inherit"},
@@ -150,12 +146,15 @@ static ERR_STRING_DATA X509_str_reasons[]=
150 146
151void ERR_load_X509_strings(void) 147void ERR_load_X509_strings(void)
152 { 148 {
153#ifndef OPENSSL_NO_ERR 149 static int init=1;
154 150
155 if (ERR_func_error_string(X509_str_functs[0].error) == NULL) 151 if (init)
156 { 152 {
153 init=0;
154#ifndef OPENSSL_NO_ERR
157 ERR_load_strings(0,X509_str_functs); 155 ERR_load_strings(0,X509_str_functs);
158 ERR_load_strings(0,X509_str_reasons); 156 ERR_load_strings(0,X509_str_reasons);
159 }
160#endif 157#endif
158
159 }
161 } 160 }
diff --git a/src/lib/libcrypto/x509/x509_lu.c b/src/lib/libcrypto/x509/x509_lu.c
index cd2cfb6d85..b780dae5e2 100644
--- a/src/lib/libcrypto/x509/x509_lu.c
+++ b/src/lib/libcrypto/x509/x509_lu.c
@@ -187,8 +187,10 @@ X509_STORE *X509_STORE_new(void)
187 ret->verify=0; 187 ret->verify=0;
188 ret->verify_cb=0; 188 ret->verify_cb=0;
189 189
190 if ((ret->param = X509_VERIFY_PARAM_new()) == NULL) 190 ret->purpose = 0;
191 return NULL; 191 ret->trust = 0;
192
193 ret->flags = 0;
192 194
193 ret->get_issuer = 0; 195 ret->get_issuer = 0;
194 ret->check_issued = 0; 196 ret->check_issued = 0;
@@ -200,6 +202,7 @@ X509_STORE *X509_STORE_new(void)
200 202
201 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data); 203 CRYPTO_new_ex_data(CRYPTO_EX_INDEX_X509_STORE, ret, &ret->ex_data);
202 ret->references=1; 204 ret->references=1;
205 ret->depth=0;
203 return ret; 206 return ret;
204 } 207 }
205 208
@@ -241,8 +244,6 @@ void X509_STORE_free(X509_STORE *vfy)
241 sk_X509_OBJECT_pop_free(vfy->objs, cleanup); 244 sk_X509_OBJECT_pop_free(vfy->objs, cleanup);
242 245
243 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data); 246 CRYPTO_free_ex_data(CRYPTO_EX_INDEX_X509_STORE, vfy, &vfy->ex_data);
244 if (vfy->param)
245 X509_VERIFY_PARAM_free(vfy->param);
246 OPENSSL_free(vfy); 247 OPENSSL_free(vfy);
247 } 248 }
248 249
@@ -497,7 +498,7 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
497 if (ok == X509_LU_RETRY) 498 if (ok == X509_LU_RETRY)
498 { 499 {
499 X509_OBJECT_free_contents(&obj); 500 X509_OBJECT_free_contents(&obj);
500 X509err(X509_F_X509_STORE_CTX_GET1_ISSUER,X509_R_SHOULD_RETRY); 501 X509err(X509_F_X509_VERIFY_CERT,X509_R_SHOULD_RETRY);
501 return -1; 502 return -1;
502 } 503 }
503 else if (ok != X509_LU_FAIL) 504 else if (ok != X509_LU_FAIL)
@@ -537,30 +538,19 @@ int X509_STORE_CTX_get1_issuer(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
537 return 0; 538 return 0;
538} 539}
539 540
540int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags) 541void X509_STORE_set_flags(X509_STORE *ctx, long flags)
541 { 542 {
542 return X509_VERIFY_PARAM_set_flags(ctx->param, flags); 543 ctx->flags |= flags;
543 }
544
545int X509_STORE_set_depth(X509_STORE *ctx, int depth)
546 {
547 X509_VERIFY_PARAM_set_depth(ctx->param, depth);
548 return 1;
549 } 544 }
550 545
551int X509_STORE_set_purpose(X509_STORE *ctx, int purpose) 546int X509_STORE_set_purpose(X509_STORE *ctx, int purpose)
552 { 547 {
553 return X509_VERIFY_PARAM_set_purpose(ctx->param, purpose); 548 return X509_PURPOSE_set(&ctx->purpose, purpose);
554 } 549 }
555 550
556int X509_STORE_set_trust(X509_STORE *ctx, int trust) 551int X509_STORE_set_trust(X509_STORE *ctx, int trust)
557 { 552 {
558 return X509_VERIFY_PARAM_set_trust(ctx->param, trust); 553 return X509_TRUST_set(&ctx->trust, trust);
559 }
560
561int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *param)
562 {
563 return X509_VERIFY_PARAM_set1(ctx->param, param);
564 } 554 }
565 555
566IMPLEMENT_STACK_OF(X509_LOOKUP) 556IMPLEMENT_STACK_OF(X509_LOOKUP)
diff --git a/src/lib/libcrypto/x509/x509_r2x.c b/src/lib/libcrypto/x509/x509_r2x.c
index 254a14693d..fb8a78dabe 100644
--- a/src/lib/libcrypto/x509/x509_r2x.c
+++ b/src/lib/libcrypto/x509/x509_r2x.c
@@ -89,10 +89,8 @@ X509 *X509_REQ_to_X509(X509_REQ *r, int days, EVP_PKEY *pkey)
89 } 89 }
90 90
91 xn=X509_REQ_get_subject_name(r); 91 xn=X509_REQ_get_subject_name(r);
92 if (X509_set_subject_name(ret,X509_NAME_dup(xn)) == 0) 92 X509_set_subject_name(ret,X509_NAME_dup(xn));
93 goto err; 93 X509_set_issuer_name(ret,X509_NAME_dup(xn));
94 if (X509_set_issuer_name(ret,X509_NAME_dup(xn)) == 0)
95 goto err;
96 94
97 if (X509_gmtime_adj(xi->validity->notBefore,0) == NULL) 95 if (X509_gmtime_adj(xi->validity->notBefore,0) == NULL)
98 goto err; 96 goto err;
diff --git a/src/lib/libcrypto/x509/x509_req.c b/src/lib/libcrypto/x509/x509_req.c
index 3872e1fb64..59fc6ca548 100644
--- a/src/lib/libcrypto/x509/x509_req.c
+++ b/src/lib/libcrypto/x509/x509_req.c
@@ -113,46 +113,6 @@ EVP_PKEY *X509_REQ_get_pubkey(X509_REQ *req)
113 return(X509_PUBKEY_get(req->req_info->pubkey)); 113 return(X509_PUBKEY_get(req->req_info->pubkey));
114 } 114 }
115 115
116int X509_REQ_check_private_key(X509_REQ *x, EVP_PKEY *k)
117 {
118 EVP_PKEY *xk=NULL;
119 int ok=0;
120
121 xk=X509_REQ_get_pubkey(x);
122 switch (EVP_PKEY_cmp(xk, k))
123 {
124 case 1:
125 ok=1;
126 break;
127 case 0:
128 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_VALUES_MISMATCH);
129 break;
130 case -1:
131 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_KEY_TYPE_MISMATCH);
132 break;
133 case -2:
134#ifndef OPENSSL_NO_EC
135 if (k->type == EVP_PKEY_EC)
136 {
137 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY, ERR_R_EC_LIB);
138 break;
139 }
140#endif
141#ifndef OPENSSL_NO_DH
142 if (k->type == EVP_PKEY_DH)
143 {
144 /* No idea */
145 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_CANT_CHECK_DH_KEY);
146 break;
147 }
148#endif
149 X509err(X509_F_X509_REQ_CHECK_PRIVATE_KEY,X509_R_UNKNOWN_KEY_TYPE);
150 }
151
152 EVP_PKEY_free(xk);
153 return(ok);
154 }
155
156/* It seems several organisations had the same idea of including a list of 116/* It seems several organisations had the same idea of including a list of
157 * extensions in a certificate request. There are at least two OIDs that are 117 * extensions in a certificate request. There are at least two OIDs that are
158 * used and there may be more: so the list is configurable. 118 * used and there may be more: so the list is configurable.
@@ -187,7 +147,7 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
187 X509_ATTRIBUTE *attr; 147 X509_ATTRIBUTE *attr;
188 ASN1_TYPE *ext = NULL; 148 ASN1_TYPE *ext = NULL;
189 int idx, *pnid; 149 int idx, *pnid;
190 const unsigned char *p; 150 unsigned char *p;
191 151
192 if ((req == NULL) || (req->req_info == NULL) || !ext_nids) 152 if ((req == NULL) || (req->req_info == NULL) || !ext_nids)
193 return(NULL); 153 return(NULL);
@@ -209,7 +169,7 @@ STACK_OF(X509_EXTENSION) *X509_REQ_get_extensions(X509_REQ *req)
209 ext->value.sequence->length, 169 ext->value.sequence->length,
210 d2i_X509_EXTENSION, X509_EXTENSION_free, 170 d2i_X509_EXTENSION, X509_EXTENSION_free,
211 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL); 171 V_ASN1_SEQUENCE, V_ASN1_UNIVERSAL);
212} 172 }
213 173
214/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs 174/* Add a STACK_OF extensions to a certificate request: allow alternative OIDs
215 * in case we want to create a non standard one. 175 * in case we want to create a non standard one.
@@ -242,11 +202,6 @@ int X509_REQ_add_extensions_nid(X509_REQ *req, STACK_OF(X509_EXTENSION) *exts,
242 at = NULL; 202 at = NULL;
243 attr->single = 0; 203 attr->single = 0;
244 attr->object = OBJ_nid2obj(nid); 204 attr->object = OBJ_nid2obj(nid);
245 if (!req->req_info->attributes)
246 {
247 if (!(req->req_info->attributes = sk_X509_ATTRIBUTE_new_null()))
248 goto err;
249 }
250 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err; 205 if(!sk_X509_ATTRIBUTE_push(req->req_info->attributes, attr)) goto err;
251 return 1; 206 return 1;
252 err: 207 err:
diff --git a/src/lib/libcrypto/x509/x509_trs.c b/src/lib/libcrypto/x509/x509_trs.c
index 9c84a59d52..881252608d 100644
--- a/src/lib/libcrypto/x509/x509_trs.c
+++ b/src/lib/libcrypto/x509/x509_trs.c
@@ -128,7 +128,7 @@ int X509_TRUST_get_count(void)
128X509_TRUST * X509_TRUST_get0(int idx) 128X509_TRUST * X509_TRUST_get0(int idx)
129{ 129{
130 if(idx < 0) return NULL; 130 if(idx < 0) return NULL;
131 if(idx < (int)X509_TRUST_COUNT) return trstandard + idx; 131 if(idx < X509_TRUST_COUNT) return trstandard + idx;
132 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT); 132 return sk_X509_TRUST_value(trtable, idx - X509_TRUST_COUNT);
133} 133}
134 134
@@ -219,7 +219,7 @@ static void trtable_free(X509_TRUST *p)
219 219
220void X509_TRUST_cleanup(void) 220void X509_TRUST_cleanup(void)
221{ 221{
222 unsigned int i; 222 int i;
223 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i); 223 for(i = 0; i < X509_TRUST_COUNT; i++) trtable_free(trstandard + i);
224 sk_X509_TRUST_pop_free(trtable, trtable_free); 224 sk_X509_TRUST_pop_free(trtable, trtable_free);
225 trtable = NULL; 225 trtable = NULL;
diff --git a/src/lib/libcrypto/x509/x509_txt.c b/src/lib/libcrypto/x509/x509_txt.c
index 73a8ec726f..f19e66a238 100644
--- a/src/lib/libcrypto/x509/x509_txt.c
+++ b/src/lib/libcrypto/x509/x509_txt.c
@@ -129,7 +129,7 @@ const char *X509_verify_cert_error_string(long n)
129 case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED: 129 case X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED:
130 return("proxy path length constraint exceeded"); 130 return("proxy path length constraint exceeded");
131 case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED: 131 case X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED:
132 return("proxy certificates not allowed, please set the appropriate flag"); 132 return("proxy cerificates not allowed, please set the appropriate flag");
133 case X509_V_ERR_INVALID_PURPOSE: 133 case X509_V_ERR_INVALID_PURPOSE:
134 return ("unsupported certificate purpose"); 134 return ("unsupported certificate purpose");
135 case X509_V_ERR_CERT_UNTRUSTED: 135 case X509_V_ERR_CERT_UNTRUSTED:
@@ -156,14 +156,6 @@ const char *X509_verify_cert_error_string(long n)
156 return("key usage does not include digital signature"); 156 return("key usage does not include digital signature");
157 case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION: 157 case X509_V_ERR_UNHANDLED_CRITICAL_CRL_EXTENSION:
158 return("unhandled critical CRL extension"); 158 return("unhandled critical CRL extension");
159 case X509_V_ERR_INVALID_EXTENSION:
160 return("invalid or inconsistent certificate extension");
161 case X509_V_ERR_INVALID_POLICY_EXTENSION:
162 return("invalid or inconsistent certificate policy extension");
163 case X509_V_ERR_NO_EXPLICIT_POLICY:
164 return("no explicit policy");
165 case X509_V_ERR_UNNESTED_RESOURCE:
166 return("RFC 3779 resource not subset of parent's resources");
167 default: 159 default:
168 BIO_snprintf(buf,sizeof buf,"error number %ld",n); 160 BIO_snprintf(buf,sizeof buf,"error number %ld",n);
169 return(buf); 161 return(buf);
diff --git a/src/lib/libcrypto/x509/x509_v3.c b/src/lib/libcrypto/x509/x509_v3.c
index 42e6f0ab05..67b1796a92 100644
--- a/src/lib/libcrypto/x509/x509_v3.c
+++ b/src/lib/libcrypto/x509/x509_v3.c
@@ -147,13 +147,7 @@ STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
147 int n; 147 int n;
148 STACK_OF(X509_EXTENSION) *sk=NULL; 148 STACK_OF(X509_EXTENSION) *sk=NULL;
149 149
150 if (x == NULL) 150 if ((x != NULL) && (*x == NULL))
151 {
152 X509err(X509_F_X509V3_ADD_EXT,ERR_R_PASSED_NULL_PARAMETER);
153 goto err2;
154 }
155
156 if (*x == NULL)
157 { 151 {
158 if ((sk=sk_X509_EXTENSION_new_null()) == NULL) 152 if ((sk=sk_X509_EXTENSION_new_null()) == NULL)
159 goto err; 153 goto err;
@@ -169,7 +163,7 @@ STACK_OF(X509_EXTENSION) *X509v3_add_ext(STACK_OF(X509_EXTENSION) **x,
169 goto err2; 163 goto err2;
170 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc)) 164 if (!sk_X509_EXTENSION_insert(sk,new_ex,loc))
171 goto err; 165 goto err;
172 if (*x == NULL) 166 if ((x != NULL) && (*x == NULL))
173 *x=sk; 167 *x=sk;
174 return(sk); 168 return(sk);
175err: 169err:
diff --git a/src/lib/libcrypto/x509/x509_vfy.c b/src/lib/libcrypto/x509/x509_vfy.c
index 9a62ebcf67..383e082aba 100644
--- a/src/lib/libcrypto/x509/x509_vfy.c
+++ b/src/lib/libcrypto/x509/x509_vfy.c
@@ -77,9 +77,8 @@ static int check_chain_extensions(X509_STORE_CTX *ctx);
77static int check_trust(X509_STORE_CTX *ctx); 77static int check_trust(X509_STORE_CTX *ctx);
78static int check_revocation(X509_STORE_CTX *ctx); 78static int check_revocation(X509_STORE_CTX *ctx);
79static int check_cert(X509_STORE_CTX *ctx); 79static int check_cert(X509_STORE_CTX *ctx);
80static int check_policy(X509_STORE_CTX *ctx);
81static int internal_verify(X509_STORE_CTX *ctx); 80static int internal_verify(X509_STORE_CTX *ctx);
82const char X509_version[]="X.509" OPENSSL_VERSION_PTEXT; 81const char *X509_version="X.509" OPENSSL_VERSION_PTEXT;
83 82
84 83
85static int null_callback(int ok, X509_STORE_CTX *e) 84static int null_callback(int ok, X509_STORE_CTX *e)
@@ -98,12 +97,11 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
98 { 97 {
99 X509 *x,*xtmp,*chain_ss=NULL; 98 X509 *x,*xtmp,*chain_ss=NULL;
100 X509_NAME *xn; 99 X509_NAME *xn;
101 int bad_chain = 0;
102 X509_VERIFY_PARAM *param = ctx->param;
103 int depth,i,ok=0; 100 int depth,i,ok=0;
104 int num; 101 int num;
105 int (*cb)(int xok,X509_STORE_CTX *xctx); 102 int (*cb)();
106 STACK_OF(X509) *sktmp=NULL; 103 STACK_OF(X509) *sktmp=NULL;
104
107 if (ctx->cert == NULL) 105 if (ctx->cert == NULL)
108 { 106 {
109 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY); 107 X509err(X509_F_X509_VERIFY_CERT,X509_R_NO_CERT_SET_FOR_US_TO_VERIFY);
@@ -136,7 +134,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
136 134
137 num=sk_X509_num(ctx->chain); 135 num=sk_X509_num(ctx->chain);
138 x=sk_X509_value(ctx->chain,num-1); 136 x=sk_X509_value(ctx->chain,num-1);
139 depth=param->depth; 137 depth=ctx->depth;
140 138
141 139
142 for (;;) 140 for (;;)
@@ -164,7 +162,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
164 goto end; 162 goto end;
165 } 163 }
166 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509); 164 CRYPTO_add(&xtmp->references,1,CRYPTO_LOCK_X509);
167 (void)sk_X509_delete_ptr(sktmp,xtmp); 165 sk_X509_delete_ptr(sktmp,xtmp);
168 ctx->last_untrusted++; 166 ctx->last_untrusted++;
169 x=xtmp; 167 x=xtmp;
170 num++; 168 num++;
@@ -203,7 +201,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
203 ctx->current_cert=x; 201 ctx->current_cert=x;
204 ctx->error_depth=i-1; 202 ctx->error_depth=i-1;
205 if (ok == 1) X509_free(xtmp); 203 if (ok == 1) X509_free(xtmp);
206 bad_chain = 1;
207 ok=cb(0,ctx); 204 ok=cb(0,ctx);
208 if (!ok) goto end; 205 if (!ok) goto end;
209 } 206 }
@@ -214,7 +211,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
214 */ 211 */
215 X509_free(x); 212 X509_free(x);
216 x = xtmp; 213 x = xtmp;
217 (void)sk_X509_set(ctx->chain, i - 1, x); 214 sk_X509_set(ctx->chain, i - 1, x);
218 ctx->last_untrusted=0; 215 ctx->last_untrusted=0;
219 } 216 }
220 } 217 }
@@ -279,7 +276,6 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
279 } 276 }
280 277
281 ctx->error_depth=num-1; 278 ctx->error_depth=num-1;
282 bad_chain = 1;
283 ok=cb(0,ctx); 279 ok=cb(0,ctx);
284 if (!ok) goto end; 280 if (!ok) goto end;
285 } 281 }
@@ -291,7 +287,7 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
291 287
292 /* The chain extensions are OK: check trust */ 288 /* The chain extensions are OK: check trust */
293 289
294 if (param->trust > 0) ok = check_trust(ctx); 290 if (ctx->trust > 0) ok = check_trust(ctx);
295 291
296 if (!ok) goto end; 292 if (!ok) goto end;
297 293
@@ -305,25 +301,11 @@ int X509_verify_cert(X509_STORE_CTX *ctx)
305 ok = ctx->check_revocation(ctx); 301 ok = ctx->check_revocation(ctx);
306 if(!ok) goto end; 302 if(!ok) goto end;
307 303
308 /* At this point, we have a chain and need to verify it */ 304 /* At this point, we have a chain and just need to verify it */
309 if (ctx->verify != NULL) 305 if (ctx->verify != NULL)
310 ok=ctx->verify(ctx); 306 ok=ctx->verify(ctx);
311 else 307 else
312 ok=internal_verify(ctx); 308 ok=internal_verify(ctx);
313 if(!ok) goto end;
314
315#ifndef OPENSSL_NO_RFC3779
316 /* RFC 3779 path validation, now that CRL check has been done */
317 ok = v3_asid_validate_path(ctx);
318 if (!ok) goto end;
319 ok = v3_addr_validate_path(ctx);
320 if (!ok) goto end;
321#endif
322
323 /* If we get this far evaluate policies */
324 if (!bad_chain && (ctx->param->flags & X509_V_FLAG_POLICY_CHECK))
325 ok = ctx->check_policy(ctx);
326 if(!ok) goto end;
327 if (0) 309 if (0)
328 { 310 {
329end: 311end:
@@ -360,7 +342,7 @@ static int check_issued(X509_STORE_CTX *ctx, X509 *x, X509 *issuer)
360 if (ret == X509_V_OK) 342 if (ret == X509_V_OK)
361 return 1; 343 return 1;
362 /* If we haven't asked for issuer errors don't set ctx */ 344 /* If we haven't asked for issuer errors don't set ctx */
363 if (!(ctx->param->flags & X509_V_FLAG_CB_ISSUER_CHECK)) 345 if (!(ctx->flags & X509_V_FLAG_CB_ISSUER_CHECK))
364 return 0; 346 return 0;
365 347
366 ctx->error = ret; 348 ctx->error = ret;
@@ -383,7 +365,7 @@ static int get_issuer_sk(X509 **issuer, X509_STORE_CTX *ctx, X509 *x)
383 else 365 else
384 return 0; 366 return 0;
385} 367}
386 368
387 369
388/* Check a certificate chains extensions for consistency 370/* Check a certificate chains extensions for consistency
389 * with the supplied purpose 371 * with the supplied purpose
@@ -396,10 +378,9 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
396#else 378#else
397 int i, ok=0, must_be_ca; 379 int i, ok=0, must_be_ca;
398 X509 *x; 380 X509 *x;
399 int (*cb)(int xok,X509_STORE_CTX *xctx); 381 int (*cb)();
400 int proxy_path_length = 0; 382 int proxy_path_length = 0;
401 int allow_proxy_certs = 383 int allow_proxy_certs = !!(ctx->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
402 !!(ctx->param->flags & X509_V_FLAG_ALLOW_PROXY_CERTS);
403 cb=ctx->verify_cb; 384 cb=ctx->verify_cb;
404 385
405 /* must_be_ca can have 1 of 3 values: 386 /* must_be_ca can have 1 of 3 values:
@@ -422,7 +403,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
422 { 403 {
423 int ret; 404 int ret;
424 x = sk_X509_value(ctx->chain, i); 405 x = sk_X509_value(ctx->chain, i);
425 if (!(ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) 406 if (!(ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
426 && (x->ex_flags & EXFLAG_CRITICAL)) 407 && (x->ex_flags & EXFLAG_CRITICAL))
427 { 408 {
428 ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION; 409 ctx->error = X509_V_ERR_UNHANDLED_CRITICAL_EXTENSION;
@@ -443,7 +424,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
443 switch(must_be_ca) 424 switch(must_be_ca)
444 { 425 {
445 case -1: 426 case -1:
446 if ((ctx->param->flags & X509_V_FLAG_X509_STRICT) 427 if ((ctx->flags & X509_V_FLAG_X509_STRICT)
447 && (ret != 1) && (ret != 0)) 428 && (ret != 1) && (ret != 0))
448 { 429 {
449 ret = 0; 430 ret = 0;
@@ -463,7 +444,7 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
463 break; 444 break;
464 default: 445 default:
465 if ((ret == 0) 446 if ((ret == 0)
466 || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) 447 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
467 && (ret != 1))) 448 && (ret != 1)))
468 { 449 {
469 ret = 0; 450 ret = 0;
@@ -480,12 +461,12 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
480 ok=cb(0,ctx); 461 ok=cb(0,ctx);
481 if (!ok) goto end; 462 if (!ok) goto end;
482 } 463 }
483 if (ctx->param->purpose > 0) 464 if (ctx->purpose > 0)
484 { 465 {
485 ret = X509_check_purpose(x, ctx->param->purpose, 466 ret = X509_check_purpose(x, ctx->purpose,
486 must_be_ca > 0); 467 must_be_ca > 0);
487 if ((ret == 0) 468 if ((ret == 0)
488 || ((ctx->param->flags & X509_V_FLAG_X509_STRICT) 469 || ((ctx->flags & X509_V_FLAG_X509_STRICT)
489 && (ret != 1))) 470 && (ret != 1)))
490 { 471 {
491 ctx->error = X509_V_ERR_INVALID_PURPOSE; 472 ctx->error = X509_V_ERR_INVALID_PURPOSE;
@@ -511,15 +492,21 @@ static int check_chain_extensions(X509_STORE_CTX *ctx)
511 CA certificate. */ 492 CA certificate. */
512 if (x->ex_flags & EXFLAG_PROXY) 493 if (x->ex_flags & EXFLAG_PROXY)
513 { 494 {
514 if (x->ex_pcpathlen != -1 && i > x->ex_pcpathlen) 495 PROXY_CERT_INFO_EXTENSION *pci =
496 X509_get_ext_d2i(x, NID_proxyCertInfo,
497 NULL, NULL);
498 if (pci->pcPathLengthConstraint &&
499 ASN1_INTEGER_get(pci->pcPathLengthConstraint)
500 < i)
515 { 501 {
516 ctx->error = 502 PROXY_CERT_INFO_EXTENSION_free(pci);
517 X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED; 503 ctx->error = X509_V_ERR_PROXY_PATH_LENGTH_EXCEEDED;
518 ctx->error_depth = i; 504 ctx->error_depth = i;
519 ctx->current_cert = x; 505 ctx->current_cert = x;
520 ok=cb(0,ctx); 506 ok=cb(0,ctx);
521 if (!ok) goto end; 507 if (!ok) goto end;
522 } 508 }
509 PROXY_CERT_INFO_EXTENSION_free(pci);
523 proxy_path_length++; 510 proxy_path_length++;
524 must_be_ca = 0; 511 must_be_ca = 0;
525 } 512 }
@@ -539,12 +526,12 @@ static int check_trust(X509_STORE_CTX *ctx)
539#else 526#else
540 int i, ok; 527 int i, ok;
541 X509 *x; 528 X509 *x;
542 int (*cb)(int xok,X509_STORE_CTX *xctx); 529 int (*cb)();
543 cb=ctx->verify_cb; 530 cb=ctx->verify_cb;
544/* For now just check the last certificate in the chain */ 531/* For now just check the last certificate in the chain */
545 i = sk_X509_num(ctx->chain) - 1; 532 i = sk_X509_num(ctx->chain) - 1;
546 x = sk_X509_value(ctx->chain, i); 533 x = sk_X509_value(ctx->chain, i);
547 ok = X509_check_trust(x, ctx->param->trust, 0); 534 ok = X509_check_trust(x, ctx->trust, 0);
548 if (ok == X509_TRUST_TRUSTED) 535 if (ok == X509_TRUST_TRUSTED)
549 return 1; 536 return 1;
550 ctx->error_depth = i; 537 ctx->error_depth = i;
@@ -561,9 +548,9 @@ static int check_trust(X509_STORE_CTX *ctx)
561static int check_revocation(X509_STORE_CTX *ctx) 548static int check_revocation(X509_STORE_CTX *ctx)
562 { 549 {
563 int i, last, ok; 550 int i, last, ok;
564 if (!(ctx->param->flags & X509_V_FLAG_CRL_CHECK)) 551 if (!(ctx->flags & X509_V_FLAG_CRL_CHECK))
565 return 1; 552 return 1;
566 if (ctx->param->flags & X509_V_FLAG_CRL_CHECK_ALL) 553 if (ctx->flags & X509_V_FLAG_CRL_CHECK_ALL)
567 last = sk_X509_num(ctx->chain) - 1; 554 last = sk_X509_num(ctx->chain) - 1;
568 else 555 else
569 last = 0; 556 last = 0;
@@ -606,124 +593,17 @@ static int check_cert(X509_STORE_CTX *ctx)
606 593
607 } 594 }
608 595
609/* Check CRL times against values in X509_STORE_CTX */
610
611static int check_crl_time(X509_STORE_CTX *ctx, X509_CRL *crl, int notify)
612 {
613 time_t *ptime;
614 int i;
615 ctx->current_crl = crl;
616 if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME)
617 ptime = &ctx->param->check_time;
618 else
619 ptime = NULL;
620
621 i=X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
622 if (i == 0)
623 {
624 ctx->error=X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
625 if (!notify || !ctx->verify_cb(0, ctx))
626 return 0;
627 }
628
629 if (i > 0)
630 {
631 ctx->error=X509_V_ERR_CRL_NOT_YET_VALID;
632 if (!notify || !ctx->verify_cb(0, ctx))
633 return 0;
634 }
635
636 if(X509_CRL_get_nextUpdate(crl))
637 {
638 i=X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
639
640 if (i == 0)
641 {
642 ctx->error=X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
643 if (!notify || !ctx->verify_cb(0, ctx))
644 return 0;
645 }
646
647 if (i < 0)
648 {
649 ctx->error=X509_V_ERR_CRL_HAS_EXPIRED;
650 if (!notify || !ctx->verify_cb(0, ctx))
651 return 0;
652 }
653 }
654
655 ctx->current_crl = NULL;
656
657 return 1;
658 }
659
660/* Lookup CRLs from the supplied list. Look for matching isser name
661 * and validity. If we can't find a valid CRL return the last one
662 * with matching name. This gives more meaningful error codes. Otherwise
663 * we'd get a CRL not found error if a CRL existed with matching name but
664 * was invalid.
665 */
666
667static int get_crl_sk(X509_STORE_CTX *ctx, X509_CRL **pcrl,
668 X509_NAME *nm, STACK_OF(X509_CRL) *crls)
669 {
670 int i;
671 X509_CRL *crl, *best_crl = NULL;
672 for (i = 0; i < sk_X509_CRL_num(crls); i++)
673 {
674 crl = sk_X509_CRL_value(crls, i);
675 if (X509_NAME_cmp(nm, X509_CRL_get_issuer(crl)))
676 continue;
677 if (check_crl_time(ctx, crl, 0))
678 {
679 *pcrl = crl;
680 CRYPTO_add(&crl->references, 1, CRYPTO_LOCK_X509);
681 return 1;
682 }
683 best_crl = crl;
684 }
685 if (best_crl)
686 {
687 *pcrl = best_crl;
688 CRYPTO_add(&best_crl->references, 1, CRYPTO_LOCK_X509);
689 }
690
691 return 0;
692 }
693
694/* Retrieve CRL corresponding to certificate: currently just a 596/* Retrieve CRL corresponding to certificate: currently just a
695 * subject lookup: maybe use AKID later... 597 * subject lookup: maybe use AKID later...
598 * Also might look up any included CRLs too (e.g PKCS#7 signedData).
696 */ 599 */
697static int get_crl(X509_STORE_CTX *ctx, X509_CRL **pcrl, X509 *x) 600static int get_crl(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x)
698 { 601 {
699 int ok; 602 int ok;
700 X509_CRL *crl = NULL;
701 X509_OBJECT xobj; 603 X509_OBJECT xobj;
702 X509_NAME *nm; 604 ok = X509_STORE_get_by_subject(ctx, X509_LU_CRL, X509_get_issuer_name(x), &xobj);
703 nm = X509_get_issuer_name(x); 605 if (!ok) return 0;
704 ok = get_crl_sk(ctx, &crl, nm, ctx->crls); 606 *crl = xobj.data.crl;
705 if (ok)
706 {
707 *pcrl = crl;
708 return 1;
709 }
710
711 ok = X509_STORE_get_by_subject(ctx, X509_LU_CRL, nm, &xobj);
712
713 if (!ok)
714 {
715 /* If we got a near match from get_crl_sk use that */
716 if (crl)
717 {
718 *pcrl = crl;
719 return 1;
720 }
721 return 0;
722 }
723
724 *pcrl = xobj.data.crl;
725 if (crl)
726 X509_CRL_free(crl);
727 return 1; 607 return 1;
728 } 608 }
729 609
@@ -732,7 +612,8 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
732 { 612 {
733 X509 *issuer = NULL; 613 X509 *issuer = NULL;
734 EVP_PKEY *ikey = NULL; 614 EVP_PKEY *ikey = NULL;
735 int ok = 0, chnum, cnum; 615 int ok = 0, chnum, cnum, i;
616 time_t *ptime;
736 cnum = ctx->error_depth; 617 cnum = ctx->error_depth;
737 chnum = sk_X509_num(ctx->chain) - 1; 618 chnum = sk_X509_num(ctx->chain) - 1;
738 /* Find CRL issuer: if not last certificate then issuer 619 /* Find CRL issuer: if not last certificate then issuer
@@ -784,9 +665,45 @@ static int check_crl(X509_STORE_CTX *ctx, X509_CRL *crl)
784 } 665 }
785 } 666 }
786 667
787 ok = check_crl_time(ctx, crl, 1); 668 /* OK, CRL signature valid check times */
788 if (!ok) 669 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
789 goto err; 670 ptime = &ctx->check_time;
671 else
672 ptime = NULL;
673
674 i=X509_cmp_time(X509_CRL_get_lastUpdate(crl), ptime);
675 if (i == 0)
676 {
677 ctx->error=X509_V_ERR_ERROR_IN_CRL_LAST_UPDATE_FIELD;
678 ok = ctx->verify_cb(0, ctx);
679 if (!ok) goto err;
680 }
681
682 if (i > 0)
683 {
684 ctx->error=X509_V_ERR_CRL_NOT_YET_VALID;
685 ok = ctx->verify_cb(0, ctx);
686 if (!ok) goto err;
687 }
688
689 if(X509_CRL_get_nextUpdate(crl))
690 {
691 i=X509_cmp_time(X509_CRL_get_nextUpdate(crl), ptime);
692
693 if (i == 0)
694 {
695 ctx->error=X509_V_ERR_ERROR_IN_CRL_NEXT_UPDATE_FIELD;
696 ok = ctx->verify_cb(0, ctx);
697 if (!ok) goto err;
698 }
699
700 if (i < 0)
701 {
702 ctx->error=X509_V_ERR_CRL_HAS_EXPIRED;
703 ok = ctx->verify_cb(0, ctx);
704 if (!ok) goto err;
705 }
706 }
790 707
791 ok = 1; 708 ok = 1;
792 709
@@ -824,7 +741,7 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
824 if (!ok) return 0; 741 if (!ok) return 0;
825 } 742 }
826 743
827 if (ctx->param->flags & X509_V_FLAG_IGNORE_CRITICAL) 744 if (ctx->flags & X509_V_FLAG_IGNORE_CRITICAL)
828 return 1; 745 return 1;
829 746
830 /* See if we have any critical CRL extensions: since we 747 /* See if we have any critical CRL extensions: since we
@@ -851,106 +768,13 @@ static int cert_crl(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x)
851 return 1; 768 return 1;
852 } 769 }
853 770
854static int check_policy(X509_STORE_CTX *ctx)
855 {
856 int ret;
857 ret = X509_policy_check(&ctx->tree, &ctx->explicit_policy, ctx->chain,
858 ctx->param->policies, ctx->param->flags);
859 if (ret == 0)
860 {
861 X509err(X509_F_CHECK_POLICY,ERR_R_MALLOC_FAILURE);
862 return 0;
863 }
864 /* Invalid or inconsistent extensions */
865 if (ret == -1)
866 {
867 /* Locate certificates with bad extensions and notify
868 * callback.
869 */
870 X509 *x;
871 int i;
872 for (i = 1; i < sk_X509_num(ctx->chain); i++)
873 {
874 x = sk_X509_value(ctx->chain, i);
875 if (!(x->ex_flags & EXFLAG_INVALID_POLICY))
876 continue;
877 ctx->current_cert = x;
878 ctx->error = X509_V_ERR_INVALID_POLICY_EXTENSION;
879 ret = ctx->verify_cb(0, ctx);
880 }
881 return 1;
882 }
883 if (ret == -2)
884 {
885 ctx->current_cert = NULL;
886 ctx->error = X509_V_ERR_NO_EXPLICIT_POLICY;
887 return ctx->verify_cb(0, ctx);
888 }
889
890 if (ctx->param->flags & X509_V_FLAG_NOTIFY_POLICY)
891 {
892 ctx->current_cert = NULL;
893 ctx->error = X509_V_OK;
894 if (!ctx->verify_cb(2, ctx))
895 return 0;
896 }
897
898 return 1;
899 }
900
901static int check_cert_time(X509_STORE_CTX *ctx, X509 *x)
902 {
903 time_t *ptime;
904 int i;
905
906 if (ctx->param->flags & X509_V_FLAG_USE_CHECK_TIME)
907 ptime = &ctx->param->check_time;
908 else
909 ptime = NULL;
910
911 i=X509_cmp_time(X509_get_notBefore(x), ptime);
912 if (i == 0)
913 {
914 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
915 ctx->current_cert=x;
916 if (!ctx->verify_cb(0, ctx))
917 return 0;
918 }
919
920 if (i > 0)
921 {
922 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
923 ctx->current_cert=x;
924 if (!ctx->verify_cb(0, ctx))
925 return 0;
926 }
927
928 i=X509_cmp_time(X509_get_notAfter(x), ptime);
929 if (i == 0)
930 {
931 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
932 ctx->current_cert=x;
933 if (!ctx->verify_cb(0, ctx))
934 return 0;
935 }
936
937 if (i < 0)
938 {
939 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
940 ctx->current_cert=x;
941 if (!ctx->verify_cb(0, ctx))
942 return 0;
943 }
944
945 return 1;
946 }
947
948static int internal_verify(X509_STORE_CTX *ctx) 771static int internal_verify(X509_STORE_CTX *ctx)
949 { 772 {
950 int ok=0,n; 773 int i,ok=0,n;
951 X509 *xs,*xi; 774 X509 *xs,*xi;
952 EVP_PKEY *pkey=NULL; 775 EVP_PKEY *pkey=NULL;
953 int (*cb)(int xok,X509_STORE_CTX *xctx); 776 time_t *ptime;
777 int (*cb)();
954 778
955 cb=ctx->verify_cb; 779 cb=ctx->verify_cb;
956 780
@@ -958,7 +782,10 @@ static int internal_verify(X509_STORE_CTX *ctx)
958 ctx->error_depth=n-1; 782 ctx->error_depth=n-1;
959 n--; 783 n--;
960 xi=sk_X509_value(ctx->chain,n); 784 xi=sk_X509_value(ctx->chain,n);
961 785 if (ctx->flags & X509_V_FLAG_USE_CHECK_TIME)
786 ptime = &ctx->check_time;
787 else
788 ptime = NULL;
962 if (ctx->check_issued(ctx, xi, xi)) 789 if (ctx->check_issued(ctx, xi, xi))
963 xs=xi; 790 xs=xi;
964 else 791 else
@@ -1011,13 +838,41 @@ static int internal_verify(X509_STORE_CTX *ctx)
1011 } 838 }
1012 EVP_PKEY_free(pkey); 839 EVP_PKEY_free(pkey);
1013 pkey=NULL; 840 pkey=NULL;
841
842 i=X509_cmp_time(X509_get_notBefore(xs), ptime);
843 if (i == 0)
844 {
845 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_BEFORE_FIELD;
846 ctx->current_cert=xs;
847 ok=(*cb)(0,ctx);
848 if (!ok) goto end;
849 }
850 if (i > 0)
851 {
852 ctx->error=X509_V_ERR_CERT_NOT_YET_VALID;
853 ctx->current_cert=xs;
854 ok=(*cb)(0,ctx);
855 if (!ok) goto end;
856 }
857 xs->valid=1;
1014 } 858 }
1015 859
1016 xs->valid = 1; 860 i=X509_cmp_time(X509_get_notAfter(xs), ptime);
861 if (i == 0)
862 {
863 ctx->error=X509_V_ERR_ERROR_IN_CERT_NOT_AFTER_FIELD;
864 ctx->current_cert=xs;
865 ok=(*cb)(0,ctx);
866 if (!ok) goto end;
867 }
1017 868
1018 ok = check_cert_time(ctx, xs); 869 if (i < 0)
1019 if (!ok) 870 {
1020 goto end; 871 ctx->error=X509_V_ERR_CERT_HAS_EXPIRED;
872 ctx->current_cert=xs;
873 ok=(*cb)(0,ctx);
874 if (!ok) goto end;
875 }
1021 876
1022 /* The last error (if any) is still in the error value */ 877 /* The last error (if any) is still in the error value */
1023 ctx->current_issuer=xi; 878 ctx->current_issuer=xi;
@@ -1250,11 +1105,6 @@ void X509_STORE_CTX_set_chain(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1250 ctx->untrusted=sk; 1105 ctx->untrusted=sk;
1251 } 1106 }
1252 1107
1253void X509_STORE_CTX_set0_crls(X509_STORE_CTX *ctx, STACK_OF(X509_CRL) *sk)
1254 {
1255 ctx->crls=sk;
1256 }
1257
1258int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose) 1108int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose)
1259 { 1109 {
1260 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0); 1110 return X509_STORE_CTX_purpose_inherit(ctx, 0, purpose, 0);
@@ -1318,8 +1168,8 @@ int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
1318 } 1168 }
1319 } 1169 }
1320 1170
1321 if (purpose && !ctx->param->purpose) ctx->param->purpose = purpose; 1171 if (purpose && !ctx->purpose) ctx->purpose = purpose;
1322 if (trust && !ctx->param->trust) ctx->param->trust = trust; 1172 if (trust && !ctx->trust) ctx->trust = trust;
1323 return 1; 1173 return 1;
1324} 1174}
1325 1175
@@ -1345,30 +1195,20 @@ void X509_STORE_CTX_free(X509_STORE_CTX *ctx)
1345int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509, 1195int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
1346 STACK_OF(X509) *chain) 1196 STACK_OF(X509) *chain)
1347 { 1197 {
1348 int ret = 1;
1349 ctx->ctx=store; 1198 ctx->ctx=store;
1350 ctx->current_method=0; 1199 ctx->current_method=0;
1351 ctx->cert=x509; 1200 ctx->cert=x509;
1352 ctx->untrusted=chain; 1201 ctx->untrusted=chain;
1353 ctx->crls = NULL;
1354 ctx->last_untrusted=0; 1202 ctx->last_untrusted=0;
1203 ctx->check_time=0;
1355 ctx->other_ctx=NULL; 1204 ctx->other_ctx=NULL;
1356 ctx->valid=0; 1205 ctx->valid=0;
1357 ctx->chain=NULL; 1206 ctx->chain=NULL;
1207 ctx->depth=9;
1358 ctx->error=0; 1208 ctx->error=0;
1359 ctx->explicit_policy=0;
1360 ctx->error_depth=0; 1209 ctx->error_depth=0;
1361 ctx->current_cert=NULL; 1210 ctx->current_cert=NULL;
1362 ctx->current_issuer=NULL; 1211 ctx->current_issuer=NULL;
1363 ctx->tree = NULL;
1364
1365 ctx->param = X509_VERIFY_PARAM_new();
1366
1367 if (!ctx->param)
1368 {
1369 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE);
1370 return 0;
1371 }
1372 1212
1373 /* Inherit callbacks and flags from X509_STORE if not set 1213 /* Inherit callbacks and flags from X509_STORE if not set
1374 * use defaults. 1214 * use defaults.
@@ -1376,26 +1216,18 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
1376 1216
1377 1217
1378 if (store) 1218 if (store)
1379 ret = X509_VERIFY_PARAM_inherit(ctx->param, store->param);
1380 else
1381 ctx->param->flags |= X509_VP_FLAG_DEFAULT|X509_VP_FLAG_ONCE;
1382
1383 if (store)
1384 { 1219 {
1385 ctx->verify_cb = store->verify_cb; 1220 ctx->purpose=store->purpose;
1221 ctx->trust=store->trust;
1222 ctx->flags = store->flags;
1386 ctx->cleanup = store->cleanup; 1223 ctx->cleanup = store->cleanup;
1387 } 1224 }
1388 else 1225 else
1389 ctx->cleanup = 0;
1390
1391 if (ret)
1392 ret = X509_VERIFY_PARAM_inherit(ctx->param,
1393 X509_VERIFY_PARAM_lookup("default"));
1394
1395 if (ret == 0)
1396 { 1226 {
1397 X509err(X509_F_X509_STORE_CTX_INIT,ERR_R_MALLOC_FAILURE); 1227 ctx->purpose = 0;
1398 return 0; 1228 ctx->trust = 0;
1229 ctx->flags = 0;
1230 ctx->cleanup = 0;
1399 } 1231 }
1400 1232
1401 if (store && store->check_issued) 1233 if (store && store->check_issued)
@@ -1438,8 +1270,6 @@ int X509_STORE_CTX_init(X509_STORE_CTX *ctx, X509_STORE *store, X509 *x509,
1438 else 1270 else
1439 ctx->cert_crl = cert_crl; 1271 ctx->cert_crl = cert_crl;
1440 1272
1441 ctx->check_policy = check_policy;
1442
1443 1273
1444 /* This memset() can't make any sense anyway, so it's removed. As 1274 /* This memset() can't make any sense anyway, so it's removed. As
1445 * X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we put a 1275 * X509_STORE_CTX_cleanup does a proper "free" on the ex_data, we put a
@@ -1468,16 +1298,6 @@ void X509_STORE_CTX_trusted_stack(X509_STORE_CTX *ctx, STACK_OF(X509) *sk)
1468void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx) 1298void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
1469 { 1299 {
1470 if (ctx->cleanup) ctx->cleanup(ctx); 1300 if (ctx->cleanup) ctx->cleanup(ctx);
1471 if (ctx->param != NULL)
1472 {
1473 X509_VERIFY_PARAM_free(ctx->param);
1474 ctx->param=NULL;
1475 }
1476 if (ctx->tree != NULL)
1477 {
1478 X509_policy_tree_free(ctx->tree);
1479 ctx->tree=NULL;
1480 }
1481 if (ctx->chain != NULL) 1301 if (ctx->chain != NULL)
1482 { 1302 {
1483 sk_X509_pop_free(ctx->chain,X509_free); 1303 sk_X509_pop_free(ctx->chain,X509_free);
@@ -1487,19 +1307,15 @@ void X509_STORE_CTX_cleanup(X509_STORE_CTX *ctx)
1487 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA)); 1307 memset(&ctx->ex_data,0,sizeof(CRYPTO_EX_DATA));
1488 } 1308 }
1489 1309
1490void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth) 1310void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags)
1491 { 1311 {
1492 X509_VERIFY_PARAM_set_depth(ctx->param, depth); 1312 ctx->flags |= flags;
1493 } 1313 }
1494 1314
1495void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags) 1315void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t)
1496 { 1316 {
1497 X509_VERIFY_PARAM_set_flags(ctx->param, flags); 1317 ctx->check_time = t;
1498 } 1318 ctx->flags |= X509_V_FLAG_USE_CHECK_TIME;
1499
1500void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, time_t t)
1501 {
1502 X509_VERIFY_PARAM_set_time(ctx->param, t);
1503 } 1319 }
1504 1320
1505void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, 1321void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
@@ -1508,37 +1324,6 @@ void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
1508 ctx->verify_cb=verify_cb; 1324 ctx->verify_cb=verify_cb;
1509 } 1325 }
1510 1326
1511X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx)
1512 {
1513 return ctx->tree;
1514 }
1515
1516int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx)
1517 {
1518 return ctx->explicit_policy;
1519 }
1520
1521int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name)
1522 {
1523 const X509_VERIFY_PARAM *param;
1524 param = X509_VERIFY_PARAM_lookup(name);
1525 if (!param)
1526 return 0;
1527 return X509_VERIFY_PARAM_inherit(ctx->param, param);
1528 }
1529
1530X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx)
1531 {
1532 return ctx->param;
1533 }
1534
1535void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param)
1536 {
1537 if (ctx->param)
1538 X509_VERIFY_PARAM_free(ctx->param);
1539 ctx->param = param;
1540 }
1541
1542IMPLEMENT_STACK_OF(X509) 1327IMPLEMENT_STACK_OF(X509)
1543IMPLEMENT_ASN1_SET_OF(X509) 1328IMPLEMENT_ASN1_SET_OF(X509)
1544 1329
diff --git a/src/lib/libcrypto/x509/x509_vfy.h b/src/lib/libcrypto/x509/x509_vfy.h
index 76c76e1719..7fd1f0bc4d 100644
--- a/src/lib/libcrypto/x509/x509_vfy.h
+++ b/src/lib/libcrypto/x509/x509_vfy.h
@@ -65,7 +65,6 @@
65#ifndef HEADER_X509_VFY_H 65#ifndef HEADER_X509_VFY_H
66#define HEADER_X509_VFY_H 66#define HEADER_X509_VFY_H
67 67
68#include <openssl/opensslconf.h>
69#ifndef OPENSSL_NO_LHASH 68#ifndef OPENSSL_NO_LHASH
70#include <openssl/lhash.h> 69#include <openssl/lhash.h>
71#endif 70#endif
@@ -156,25 +155,6 @@ typedef struct x509_lookup_method_st
156 X509_OBJECT *ret); 155 X509_OBJECT *ret);
157 } X509_LOOKUP_METHOD; 156 } X509_LOOKUP_METHOD;
158 157
159/* This structure hold all parameters associated with a verify operation
160 * by including an X509_VERIFY_PARAM structure in related structures the
161 * parameters used can be customized
162 */
163
164typedef struct X509_VERIFY_PARAM_st
165 {
166 char *name;
167 time_t check_time; /* Time to use */
168 unsigned long inh_flags; /* Inheritance flags */
169 unsigned long flags; /* Various verify flags */
170 int purpose; /* purpose to check untrusted certificates */
171 int trust; /* trust setting to check */
172 int depth; /* Verify depth */
173 STACK_OF(ASN1_OBJECT) *policies; /* Permissible policies */
174 } X509_VERIFY_PARAM;
175
176DECLARE_STACK_OF(X509_VERIFY_PARAM)
177
178/* This is used to hold everything. It is used for all certificate 158/* This is used to hold everything. It is used for all certificate
179 * validation. Once we have a certificate chain, the 'verify' 159 * validation. Once we have a certificate chain, the 'verify'
180 * function is then called to actually check the cert chain. */ 160 * function is then called to actually check the cert chain. */
@@ -187,8 +167,13 @@ struct x509_store_st
187 /* These are external lookup methods */ 167 /* These are external lookup methods */
188 STACK_OF(X509_LOOKUP) *get_cert_methods; 168 STACK_OF(X509_LOOKUP) *get_cert_methods;
189 169
190 X509_VERIFY_PARAM *param; 170 /* The following fields are not used by X509_STORE but are
171 * inherited by X509_STORE_CTX when it is initialised.
172 */
191 173
174 unsigned long flags; /* Various verify flags */
175 int purpose;
176 int trust;
192 /* Callbacks for various operations */ 177 /* Callbacks for various operations */
193 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */ 178 int (*verify)(X509_STORE_CTX *ctx); /* called to verify a certificate */
194 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */ 179 int (*verify_cb)(int ok,X509_STORE_CTX *ctx); /* error callback */
@@ -202,9 +187,10 @@ struct x509_store_st
202 187
203 CRYPTO_EX_DATA ex_data; 188 CRYPTO_EX_DATA ex_data;
204 int references; 189 int references;
190 int depth; /* how deep to look (still unused -- X509_STORE_CTX's depth is used) */
205 } /* X509_STORE */; 191 } /* X509_STORE */;
206 192
207int X509_STORE_set_depth(X509_STORE *store, int depth); 193#define X509_STORE_set_depth(ctx,d) ((ctx)->depth=(d))
208 194
209#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func)) 195#define X509_STORE_set_verify_cb_func(ctx,func) ((ctx)->verify_cb=(func))
210#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func)) 196#define X509_STORE_set_verify_func(ctx,func) ((ctx)->verify=(func))
@@ -231,9 +217,10 @@ struct x509_store_ctx_st /* X509_STORE_CTX */
231 /* The following are set by the caller */ 217 /* The following are set by the caller */
232 X509 *cert; /* The cert to check */ 218 X509 *cert; /* The cert to check */
233 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */ 219 STACK_OF(X509) *untrusted; /* chain of X509s - untrusted - passed in */
234 STACK_OF(X509_CRL) *crls; /* set of CRLs passed in */ 220 int purpose; /* purpose to check untrusted certificates */
235 221 int trust; /* trust setting to check */
236 X509_VERIFY_PARAM *param; 222 time_t check_time; /* time to make verify at */
223 unsigned long flags; /* Various verify flags */
237 void *other_ctx; /* Other info for use with get_issuer() */ 224 void *other_ctx; /* Other info for use with get_issuer() */
238 225
239 /* Callbacks for various operations */ 226 /* Callbacks for various operations */
@@ -245,16 +232,13 @@ struct x509_store_ctx_st /* X509_STORE_CTX */
245 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */ 232 int (*get_crl)(X509_STORE_CTX *ctx, X509_CRL **crl, X509 *x); /* retrieve CRL */
246 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */ 233 int (*check_crl)(X509_STORE_CTX *ctx, X509_CRL *crl); /* Check CRL validity */
247 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */ 234 int (*cert_crl)(X509_STORE_CTX *ctx, X509_CRL *crl, X509 *x); /* Check certificate against CRL */
248 int (*check_policy)(X509_STORE_CTX *ctx);
249 int (*cleanup)(X509_STORE_CTX *ctx); 235 int (*cleanup)(X509_STORE_CTX *ctx);
250 236
251 /* The following is built up */ 237 /* The following is built up */
238 int depth; /* how far to go looking up certs */
252 int valid; /* if 0, rebuild chain */ 239 int valid; /* if 0, rebuild chain */
253 int last_untrusted; /* index of last untrusted cert */ 240 int last_untrusted; /* index of last untrusted cert */
254 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */ 241 STACK_OF(X509) *chain; /* chain of X509s - built up and trusted */
255 X509_POLICY_TREE *tree; /* Valid policy tree */
256
257 int explicit_policy; /* Require explicit policy value */
258 242
259 /* When something goes wrong, this is why */ 243 /* When something goes wrong, this is why */
260 int error_depth; 244 int error_depth;
@@ -266,7 +250,7 @@ struct x509_store_ctx_st /* X509_STORE_CTX */
266 CRYPTO_EX_DATA ex_data; 250 CRYPTO_EX_DATA ex_data;
267 } /* X509_STORE_CTX */; 251 } /* X509_STORE_CTX */;
268 252
269void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth); 253#define X509_STORE_CTX_set_depth(ctx,d) ((ctx)->depth=(d))
270 254
271#define X509_STORE_CTX_set_app_data(ctx,data) \ 255#define X509_STORE_CTX_set_app_data(ctx,data) \
272 X509_STORE_CTX_set_ex_data(ctx,0,data) 256 X509_STORE_CTX_set_ex_data(ctx,0,data)
@@ -327,12 +311,6 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
327#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39 311#define X509_V_ERR_KEYUSAGE_NO_DIGITAL_SIGNATURE 39
328#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40 312#define X509_V_ERR_PROXY_CERTIFICATES_NOT_ALLOWED 40
329 313
330#define X509_V_ERR_INVALID_EXTENSION 41
331#define X509_V_ERR_INVALID_POLICY_EXTENSION 42
332#define X509_V_ERR_NO_EXPLICIT_POLICY 43
333
334#define X509_V_ERR_UNNESTED_RESOURCE 44
335
336/* The application is not happy */ 314/* The application is not happy */
337#define X509_V_ERR_APPLICATION_VERIFICATION 50 315#define X509_V_ERR_APPLICATION_VERIFICATION 50
338 316
@@ -352,28 +330,6 @@ void X509_STORE_CTX_set_depth(X509_STORE_CTX *ctx, int depth);
352#define X509_V_FLAG_X509_STRICT 0x20 330#define X509_V_FLAG_X509_STRICT 0x20
353/* Enable proxy certificate validation */ 331/* Enable proxy certificate validation */
354#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40 332#define X509_V_FLAG_ALLOW_PROXY_CERTS 0x40
355/* Enable policy checking */
356#define X509_V_FLAG_POLICY_CHECK 0x80
357/* Policy variable require-explicit-policy */
358#define X509_V_FLAG_EXPLICIT_POLICY 0x100
359/* Policy variable inhibit-any-policy */
360#define X509_V_FLAG_INHIBIT_ANY 0x200
361/* Policy variable inhibit-policy-mapping */
362#define X509_V_FLAG_INHIBIT_MAP 0x400
363/* Notify callback that policy is OK */
364#define X509_V_FLAG_NOTIFY_POLICY 0x800
365
366#define X509_VP_FLAG_DEFAULT 0x1
367#define X509_VP_FLAG_OVERWRITE 0x2
368#define X509_VP_FLAG_RESET_FLAGS 0x4
369#define X509_VP_FLAG_LOCKED 0x8
370#define X509_VP_FLAG_ONCE 0x10
371
372/* Internal use: mask of policy related options */
373#define X509_V_FLAG_POLICY_MASK (X509_V_FLAG_POLICY_CHECK \
374 | X509_V_FLAG_EXPLICIT_POLICY \
375 | X509_V_FLAG_INHIBIT_ANY \
376 | X509_V_FLAG_INHIBIT_MAP)
377 333
378int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type, 334int X509_OBJECT_idx_by_subject(STACK_OF(X509_OBJECT) *h, int type,
379 X509_NAME *name); 335 X509_NAME *name);
@@ -384,10 +340,9 @@ void X509_OBJECT_free_contents(X509_OBJECT *a);
384X509_STORE *X509_STORE_new(void ); 340X509_STORE *X509_STORE_new(void );
385void X509_STORE_free(X509_STORE *v); 341void X509_STORE_free(X509_STORE *v);
386 342
387int X509_STORE_set_flags(X509_STORE *ctx, unsigned long flags); 343void X509_STORE_set_flags(X509_STORE *ctx, long flags);
388int X509_STORE_set_purpose(X509_STORE *ctx, int purpose); 344int X509_STORE_set_purpose(X509_STORE *ctx, int purpose);
389int X509_STORE_set_trust(X509_STORE *ctx, int trust); 345int X509_STORE_set_trust(X509_STORE *ctx, int trust);
390int X509_STORE_set1_param(X509_STORE *ctx, X509_VERIFY_PARAM *pm);
391 346
392X509_STORE_CTX *X509_STORE_CTX_new(void); 347X509_STORE_CTX *X509_STORE_CTX_new(void);
393 348
@@ -451,78 +406,14 @@ STACK_OF(X509) *X509_STORE_CTX_get_chain(X509_STORE_CTX *ctx);
451STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx); 406STACK_OF(X509) *X509_STORE_CTX_get1_chain(X509_STORE_CTX *ctx);
452void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x); 407void X509_STORE_CTX_set_cert(X509_STORE_CTX *c,X509 *x);
453void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk); 408void X509_STORE_CTX_set_chain(X509_STORE_CTX *c,STACK_OF(X509) *sk);
454void X509_STORE_CTX_set0_crls(X509_STORE_CTX *c,STACK_OF(X509_CRL) *sk);
455int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose); 409int X509_STORE_CTX_set_purpose(X509_STORE_CTX *ctx, int purpose);
456int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust); 410int X509_STORE_CTX_set_trust(X509_STORE_CTX *ctx, int trust);
457int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose, 411int X509_STORE_CTX_purpose_inherit(X509_STORE_CTX *ctx, int def_purpose,
458 int purpose, int trust); 412 int purpose, int trust);
459void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, unsigned long flags); 413void X509_STORE_CTX_set_flags(X509_STORE_CTX *ctx, long flags);
460void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, unsigned long flags, 414void X509_STORE_CTX_set_time(X509_STORE_CTX *ctx, long flags, time_t t);
461 time_t t);
462void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx, 415void X509_STORE_CTX_set_verify_cb(X509_STORE_CTX *ctx,
463 int (*verify_cb)(int, X509_STORE_CTX *)); 416 int (*verify_cb)(int, X509_STORE_CTX *));
464
465X509_POLICY_TREE *X509_STORE_CTX_get0_policy_tree(X509_STORE_CTX *ctx);
466int X509_STORE_CTX_get_explicit_policy(X509_STORE_CTX *ctx);
467
468X509_VERIFY_PARAM *X509_STORE_CTX_get0_param(X509_STORE_CTX *ctx);
469void X509_STORE_CTX_set0_param(X509_STORE_CTX *ctx, X509_VERIFY_PARAM *param);
470int X509_STORE_CTX_set_default(X509_STORE_CTX *ctx, const char *name);
471
472/* X509_VERIFY_PARAM functions */
473
474X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void);
475void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param);
476int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *to,
477 const X509_VERIFY_PARAM *from);
478int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
479 const X509_VERIFY_PARAM *from);
480int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name);
481int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags);
482int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
483 unsigned long flags);
484unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param);
485int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose);
486int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust);
487void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth);
488void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t);
489int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
490 ASN1_OBJECT *policy);
491int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param,
492 STACK_OF(ASN1_OBJECT) *policies);
493int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param);
494
495int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param);
496const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name);
497void X509_VERIFY_PARAM_table_cleanup(void);
498
499int X509_policy_check(X509_POLICY_TREE **ptree, int *pexplicit_policy,
500 STACK_OF(X509) *certs,
501 STACK_OF(ASN1_OBJECT) *policy_oids,
502 unsigned int flags);
503
504void X509_policy_tree_free(X509_POLICY_TREE *tree);
505
506int X509_policy_tree_level_count(const X509_POLICY_TREE *tree);
507X509_POLICY_LEVEL *
508 X509_policy_tree_get0_level(const X509_POLICY_TREE *tree, int i);
509
510STACK_OF(X509_POLICY_NODE) *
511 X509_policy_tree_get0_policies(const X509_POLICY_TREE *tree);
512
513STACK_OF(X509_POLICY_NODE) *
514 X509_policy_tree_get0_user_policies(const X509_POLICY_TREE *tree);
515
516int X509_policy_level_node_count(X509_POLICY_LEVEL *level);
517
518X509_POLICY_NODE *X509_policy_level_get0_node(X509_POLICY_LEVEL *level, int i);
519
520const ASN1_OBJECT *X509_policy_node_get0_policy(const X509_POLICY_NODE *node);
521
522STACK_OF(POLICYQUALINFO) *
523 X509_policy_node_get0_qualifiers(const X509_POLICY_NODE *node);
524const X509_POLICY_NODE *
525 X509_policy_node_get0_parent(const X509_POLICY_NODE *node);
526 417
527#ifdef __cplusplus 418#ifdef __cplusplus
528} 419}
diff --git a/src/lib/libcrypto/x509/x509spki.c b/src/lib/libcrypto/x509/x509spki.c
index ed868b838e..4c3af946ec 100644
--- a/src/lib/libcrypto/x509/x509spki.c
+++ b/src/lib/libcrypto/x509/x509spki.c
@@ -77,8 +77,7 @@ EVP_PKEY *NETSCAPE_SPKI_get_pubkey(NETSCAPE_SPKI *x)
77 77
78NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len) 78NETSCAPE_SPKI * NETSCAPE_SPKI_b64_decode(const char *str, int len)
79{ 79{
80 unsigned char *spki_der; 80 unsigned char *spki_der, *p;
81 const unsigned char *p;
82 int spki_len; 81 int spki_len;
83 NETSCAPE_SPKI *spki; 82 NETSCAPE_SPKI *spki;
84 if(len <= 0) len = strlen(str); 83 if(len <= 0) len = strlen(str);
diff --git a/src/lib/libcrypto/x509/x509type.c b/src/lib/libcrypto/x509/x509type.c
index 2cd994c5b0..c25959a742 100644
--- a/src/lib/libcrypto/x509/x509type.c
+++ b/src/lib/libcrypto/x509/x509type.c
@@ -86,9 +86,6 @@ int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
86 case EVP_PKEY_DSA: 86 case EVP_PKEY_DSA:
87 ret=EVP_PK_DSA|EVP_PKT_SIGN; 87 ret=EVP_PK_DSA|EVP_PKT_SIGN;
88 break; 88 break;
89 case EVP_PKEY_EC:
90 ret=EVP_PK_EC|EVP_PKT_SIGN|EVP_PKT_EXCH;
91 break;
92 case EVP_PKEY_DH: 89 case EVP_PKEY_DH:
93 ret=EVP_PK_DH|EVP_PKT_EXCH; 90 ret=EVP_PK_DH|EVP_PKT_EXCH;
94 break; 91 break;
@@ -105,9 +102,6 @@ int X509_certificate_type(X509 *x, EVP_PKEY *pkey)
105 case EVP_PKEY_DSA: 102 case EVP_PKEY_DSA:
106 ret|=EVP_PKS_DSA; 103 ret|=EVP_PKS_DSA;
107 break; 104 break;
108 case EVP_PKEY_EC:
109 ret|=EVP_PKS_EC;
110 break;
111 default: 105 default:
112 break; 106 break;
113 } 107 }
diff --git a/src/lib/libcrypto/x509/x_all.c b/src/lib/libcrypto/x509/x_all.c
index 9039caad60..ac6dea493a 100644
--- a/src/lib/libcrypto/x509/x_all.c
+++ b/src/lib/libcrypto/x509/x_all.c
@@ -64,12 +64,6 @@
64#include <openssl/asn1.h> 64#include <openssl/asn1.h>
65#include <openssl/evp.h> 65#include <openssl/evp.h>
66#include <openssl/x509.h> 66#include <openssl/x509.h>
67#ifndef OPENSSL_NO_RSA
68#include <openssl/rsa.h>
69#endif
70#ifndef OPENSSL_NO_DSA
71#include <openssl/dsa.h>
72#endif
73 67
74int X509_verify(X509 *a, EVP_PKEY *r) 68int X509_verify(X509 *a, EVP_PKEY *r)
75 { 69 {
@@ -229,9 +223,9 @@ RSA *d2i_RSAPublicKey_fp(FILE *fp, RSA **rsa)
229 223
230RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa) 224RSA *d2i_RSA_PUBKEY_fp(FILE *fp, RSA **rsa)
231 { 225 {
232 return ASN1_d2i_fp((void *(*)(void)) 226 return((RSA *)ASN1_d2i_fp((char *(*)())
233 RSA_new,(D2I_OF(void))d2i_RSA_PUBKEY, fp, 227 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (fp),
234 (void **)rsa); 228 (unsigned char **)(rsa)));
235 } 229 }
236 230
237int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa) 231int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
@@ -241,7 +235,7 @@ int i2d_RSAPublicKey_fp(FILE *fp, RSA *rsa)
241 235
242int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa) 236int i2d_RSA_PUBKEY_fp(FILE *fp, RSA *rsa)
243 { 237 {
244 return ASN1_i2d_fp((I2D_OF(void))i2d_RSA_PUBKEY,fp,rsa); 238 return(ASN1_i2d_fp(i2d_RSA_PUBKEY,fp,(unsigned char *)rsa));
245 } 239 }
246#endif 240#endif
247 241
@@ -263,7 +257,9 @@ RSA *d2i_RSAPublicKey_bio(BIO *bp, RSA **rsa)
263 257
264RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa) 258RSA *d2i_RSA_PUBKEY_bio(BIO *bp, RSA **rsa)
265 { 259 {
266 return ASN1_d2i_bio_of(RSA,RSA_new,d2i_RSA_PUBKEY,bp,rsa); 260 return((RSA *)ASN1_d2i_bio((char *(*)())
261 RSA_new,(char *(*)())d2i_RSA_PUBKEY, (bp),
262 (unsigned char **)(rsa)));
267 } 263 }
268 264
269int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa) 265int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
@@ -273,7 +269,7 @@ int i2d_RSAPublicKey_bio(BIO *bp, RSA *rsa)
273 269
274int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa) 270int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
275 { 271 {
276 return ASN1_i2d_bio_of(RSA,i2d_RSA_PUBKEY,bp,rsa); 272 return(ASN1_i2d_bio(i2d_RSA_PUBKEY,bp,(unsigned char *)rsa));
277 } 273 }
278#endif 274#endif
279 275
@@ -281,92 +277,55 @@ int i2d_RSA_PUBKEY_bio(BIO *bp, RSA *rsa)
281#ifndef OPENSSL_NO_FP_API 277#ifndef OPENSSL_NO_FP_API
282DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa) 278DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa)
283 { 279 {
284 return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSAPrivateKey,fp,dsa); 280 return((DSA *)ASN1_d2i_fp((char *(*)())
281 DSA_new,(char *(*)())d2i_DSAPrivateKey, (fp),
282 (unsigned char **)(dsa)));
285 } 283 }
286 284
287int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa) 285int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa)
288 { 286 {
289 return ASN1_i2d_fp_of_const(DSA,i2d_DSAPrivateKey,fp,dsa); 287 return(ASN1_i2d_fp(i2d_DSAPrivateKey,fp,(unsigned char *)dsa));
290 } 288 }
291 289
292DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa) 290DSA *d2i_DSA_PUBKEY_fp(FILE *fp, DSA **dsa)
293 { 291 {
294 return ASN1_d2i_fp_of(DSA,DSA_new,d2i_DSA_PUBKEY,fp,dsa); 292 return((DSA *)ASN1_d2i_fp((char *(*)())
293 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (fp),
294 (unsigned char **)(dsa)));
295 } 295 }
296 296
297int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa) 297int i2d_DSA_PUBKEY_fp(FILE *fp, DSA *dsa)
298 { 298 {
299 return ASN1_i2d_fp_of(DSA,i2d_DSA_PUBKEY,fp,dsa); 299 return(ASN1_i2d_fp(i2d_DSA_PUBKEY,fp,(unsigned char *)dsa));
300 } 300 }
301#endif 301#endif
302 302
303DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa) 303DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa)
304 { 304 {
305 return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSAPrivateKey,bp,dsa 305 return((DSA *)ASN1_d2i_bio((char *(*)())
306); 306 DSA_new,(char *(*)())d2i_DSAPrivateKey, (bp),
307 (unsigned char **)(dsa)));
307 } 308 }
308 309
309int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa) 310int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa)
310 { 311 {
311 return ASN1_i2d_bio_of_const(DSA,i2d_DSAPrivateKey,bp,dsa); 312 return(ASN1_i2d_bio(i2d_DSAPrivateKey,bp,(unsigned char *)dsa));
312 } 313 }
313 314
314DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa) 315DSA *d2i_DSA_PUBKEY_bio(BIO *bp, DSA **dsa)
315 { 316 {
316 return ASN1_d2i_bio_of(DSA,DSA_new,d2i_DSA_PUBKEY,bp,dsa); 317 return((DSA *)ASN1_d2i_bio((char *(*)())
318 DSA_new,(char *(*)())d2i_DSA_PUBKEY, (bp),
319 (unsigned char **)(dsa)));
317 } 320 }
318 321
319int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa) 322int i2d_DSA_PUBKEY_bio(BIO *bp, DSA *dsa)
320 { 323 {
321 return ASN1_i2d_bio_of(DSA,i2d_DSA_PUBKEY,bp,dsa); 324 return(ASN1_i2d_bio(i2d_DSA_PUBKEY,bp,(unsigned char *)dsa));
322 } 325 }
323 326
324#endif 327#endif
325 328
326#ifndef OPENSSL_NO_EC
327#ifndef OPENSSL_NO_FP_API
328EC_KEY *d2i_EC_PUBKEY_fp(FILE *fp, EC_KEY **eckey)
329 {
330 return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,fp,eckey);
331 }
332
333int i2d_EC_PUBKEY_fp(FILE *fp, EC_KEY *eckey)
334 {
335 return ASN1_i2d_fp_of(EC_KEY,i2d_EC_PUBKEY,fp,eckey);
336 }
337
338EC_KEY *d2i_ECPrivateKey_fp(FILE *fp, EC_KEY **eckey)
339 {
340 return ASN1_d2i_fp_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,fp,eckey);
341 }
342
343int i2d_ECPrivateKey_fp(FILE *fp, EC_KEY *eckey)
344 {
345 return ASN1_i2d_fp_of(EC_KEY,i2d_ECPrivateKey,fp,eckey);
346 }
347#endif
348EC_KEY *d2i_EC_PUBKEY_bio(BIO *bp, EC_KEY **eckey)
349 {
350 return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_EC_PUBKEY,bp,eckey);
351 }
352
353int i2d_EC_PUBKEY_bio(BIO *bp, EC_KEY *ecdsa)
354 {
355 return ASN1_i2d_bio_of(EC_KEY,i2d_EC_PUBKEY,bp,ecdsa);
356 }
357
358EC_KEY *d2i_ECPrivateKey_bio(BIO *bp, EC_KEY **eckey)
359 {
360 return ASN1_d2i_bio_of(EC_KEY,EC_KEY_new,d2i_ECPrivateKey,bp,eckey);
361 }
362
363int i2d_ECPrivateKey_bio(BIO *bp, EC_KEY *eckey)
364 {
365 return ASN1_i2d_bio_of(EC_KEY,i2d_ECPrivateKey,bp,eckey);
366 }
367#endif
368
369
370int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md, 329int X509_pubkey_digest(const X509 *data, const EVP_MD *type, unsigned char *md,
371 unsigned int *len) 330 unsigned int *len)
372 { 331 {
@@ -411,37 +370,40 @@ int PKCS7_ISSUER_AND_SERIAL_digest(PKCS7_ISSUER_AND_SERIAL *data, const EVP_MD *
411#ifndef OPENSSL_NO_FP_API 370#ifndef OPENSSL_NO_FP_API
412X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8) 371X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
413 { 372 {
414 return ASN1_d2i_fp_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,fp,p8); 373 return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
374 (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
415 } 375 }
416 376
417int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8) 377int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
418 { 378 {
419 return ASN1_i2d_fp_of(X509_SIG,i2d_X509_SIG,fp,p8); 379 return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
420 } 380 }
421#endif 381#endif
422 382
423X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8) 383X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
424 { 384 {
425 return ASN1_d2i_bio_of(X509_SIG,X509_SIG_new,d2i_X509_SIG,bp,p8); 385 return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
386 (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
426 } 387 }
427 388
428int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8) 389int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
429 { 390 {
430 return ASN1_i2d_bio_of(X509_SIG,i2d_X509_SIG,bp,p8); 391 return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
431 } 392 }
432 393
433#ifndef OPENSSL_NO_FP_API 394#ifndef OPENSSL_NO_FP_API
434PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, 395PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
435 PKCS8_PRIV_KEY_INFO **p8inf) 396 PKCS8_PRIV_KEY_INFO **p8inf)
436 { 397 {
437 return ASN1_d2i_fp_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, 398 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
438 d2i_PKCS8_PRIV_KEY_INFO,fp,p8inf); 399 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
400 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
401 (unsigned char **)(p8inf)));
439 } 402 }
440 403
441int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf) 404int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
442 { 405 {
443 return ASN1_i2d_fp_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,fp, 406 return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
444 p8inf);
445 } 407 }
446 408
447int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key) 409int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
@@ -457,22 +419,24 @@ int i2d_PKCS8PrivateKeyInfo_fp(FILE *fp, EVP_PKEY *key)
457 419
458int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey) 420int i2d_PrivateKey_fp(FILE *fp, EVP_PKEY *pkey)
459 { 421 {
460 return ASN1_i2d_fp_of(EVP_PKEY,i2d_PrivateKey,fp,pkey); 422 return(ASN1_i2d_fp(i2d_PrivateKey,fp,(unsigned char *)pkey));
461 } 423 }
462 424
463EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a) 425EVP_PKEY *d2i_PrivateKey_fp(FILE *fp, EVP_PKEY **a)
464{ 426{
465 return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,fp,a); 427 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
428 (char *(*)())d2i_AutoPrivateKey, (fp),(unsigned char **)(a)));
466} 429}
467 430
468int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey) 431int i2d_PUBKEY_fp(FILE *fp, EVP_PKEY *pkey)
469 { 432 {
470 return ASN1_i2d_fp_of(EVP_PKEY,i2d_PUBKEY,fp,pkey); 433 return(ASN1_i2d_fp(i2d_PUBKEY,fp,(unsigned char *)pkey));
471 } 434 }
472 435
473EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a) 436EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
474{ 437{
475 return ASN1_d2i_fp_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,fp,a); 438 return((EVP_PKEY *)ASN1_d2i_fp((char *(*)())EVP_PKEY_new,
439 (char *(*)())d2i_PUBKEY, (fp),(unsigned char **)(a)));
476} 440}
477 441
478#endif 442#endif
@@ -480,14 +444,15 @@ EVP_PKEY *d2i_PUBKEY_fp(FILE *fp, EVP_PKEY **a)
480PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, 444PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
481 PKCS8_PRIV_KEY_INFO **p8inf) 445 PKCS8_PRIV_KEY_INFO **p8inf)
482 { 446 {
483 return ASN1_d2i_bio_of(PKCS8_PRIV_KEY_INFO,PKCS8_PRIV_KEY_INFO_new, 447 return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
484 d2i_PKCS8_PRIV_KEY_INFO,bp,p8inf); 448 (char *(*)())PKCS8_PRIV_KEY_INFO_new,
449 (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
450 (unsigned char **)(p8inf)));
485 } 451 }
486 452
487int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf) 453int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
488 { 454 {
489 return ASN1_i2d_bio_of(PKCS8_PRIV_KEY_INFO,i2d_PKCS8_PRIV_KEY_INFO,bp, 455 return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
490 p8inf);
491 } 456 }
492 457
493int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key) 458int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
@@ -503,20 +468,22 @@ int i2d_PKCS8PrivateKeyInfo_bio(BIO *bp, EVP_PKEY *key)
503 468
504int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey) 469int i2d_PrivateKey_bio(BIO *bp, EVP_PKEY *pkey)
505 { 470 {
506 return ASN1_i2d_bio_of(EVP_PKEY,i2d_PrivateKey,bp,pkey); 471 return(ASN1_i2d_bio(i2d_PrivateKey,bp,(unsigned char *)pkey));
507 } 472 }
508 473
509EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a) 474EVP_PKEY *d2i_PrivateKey_bio(BIO *bp, EVP_PKEY **a)
510 { 475 {
511 return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_AutoPrivateKey,bp,a); 476 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
477 (char *(*)())d2i_AutoPrivateKey, (bp),(unsigned char **)(a)));
512 } 478 }
513 479
514int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey) 480int i2d_PUBKEY_bio(BIO *bp, EVP_PKEY *pkey)
515 { 481 {
516 return ASN1_i2d_bio_of(EVP_PKEY,i2d_PUBKEY,bp,pkey); 482 return(ASN1_i2d_bio(i2d_PUBKEY,bp,(unsigned char *)pkey));
517 } 483 }
518 484
519EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a) 485EVP_PKEY *d2i_PUBKEY_bio(BIO *bp, EVP_PKEY **a)
520 { 486 {
521 return ASN1_d2i_bio_of(EVP_PKEY,EVP_PKEY_new,d2i_PUBKEY,bp,a); 487 return((EVP_PKEY *)ASN1_d2i_bio((char *(*)())EVP_PKEY_new,
488 (char *(*)())d2i_PUBKEY, (bp),(unsigned char **)(a)));
522 } 489 }
diff --git a/src/lib/libcrypto/x509v3/Makefile b/src/lib/libcrypto/x509v3/Makefile
new file mode 100644
index 0000000000..556ef351bf
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/Makefile
@@ -0,0 +1,591 @@
1#
2# OpenSSL/crypto/x509v3/Makefile
3#
4
5DIR= x509v3
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10MAKEFILE= Makefile
11AR= ar r
12
13CFLAGS= $(INCLUDES) $(CFLAG)
14
15GENERAL=Makefile README
16TEST=
17APPS=
18
19LIB=$(TOP)/libcrypto.a
20LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c v3_lib.c \
21v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c v3_pku.c \
22v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c v3_purp.c v3_info.c \
23v3_ocsp.c v3_akeya.c v3_pmaps.c v3_pcons.c v3_ncons.c v3_pcia.c v3_pci.c \
24pcy_cache.c pcy_node.c pcy_data.c pcy_map.c pcy_tree.c pcy_lib.c \
25v3_asid.c v3_addr.c
26LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \
27v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \
28v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o v3_purp.o v3_info.o \
29v3_ocsp.o v3_akeya.o v3_pmaps.o v3_pcons.o v3_ncons.o v3_pcia.o v3_pci.o \
30pcy_cache.o pcy_node.o pcy_data.o pcy_map.o pcy_tree.o pcy_lib.o \
31v3_asid.o v3_addr.o
32
33SRC= $(LIBSRC)
34
35EXHEADER= x509v3.h
36HEADER= $(EXHEADER) pcy_int.h
37
38ALL= $(GENERAL) $(SRC) $(HEADER)
39
40top:
41 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
42
43all: lib
44
45lib: $(LIBOBJ)
46 $(AR) $(LIB) $(LIBOBJ)
47 $(RANLIB) $(LIB) || echo Never mind.
48 @touch lib
49
50files:
51 $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
52
53links:
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 @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
60 @headerlist="$(EXHEADER)"; for i in $$headerlist ; \
61 do \
62 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
63 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
64 done;
65
66tags:
67 ctags $(SRC)
68
69tests:
70
71lint:
72 lint -DLINT $(INCLUDES) $(SRC)>fluff
73
74depend:
75 @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile...
76 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
77
78dclean:
79 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
80 mv -f Makefile.new $(MAKEFILE)
81
82clean:
83 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
84
85# DO NOT DELETE THIS LINE -- make depend depends on it.
86
87pcy_cache.o: ../../e_os.h ../../include/openssl/asn1.h
88pcy_cache.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
89pcy_cache.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
90pcy_cache.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
91pcy_cache.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
92pcy_cache.o: ../../include/openssl/err.h ../../include/openssl/evp.h
93pcy_cache.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
94pcy_cache.o: ../../include/openssl/objects.h
95pcy_cache.o: ../../include/openssl/opensslconf.h
96pcy_cache.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
97pcy_cache.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
98pcy_cache.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
99pcy_cache.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
100pcy_cache.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
101pcy_cache.o: ../cryptlib.h pcy_cache.c pcy_int.h
102pcy_data.o: ../../e_os.h ../../include/openssl/asn1.h
103pcy_data.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
104pcy_data.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
105pcy_data.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
106pcy_data.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
107pcy_data.o: ../../include/openssl/err.h ../../include/openssl/evp.h
108pcy_data.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
109pcy_data.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
110pcy_data.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
111pcy_data.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
112pcy_data.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
113pcy_data.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
114pcy_data.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
115pcy_data.o: ../cryptlib.h pcy_data.c pcy_int.h
116pcy_lib.o: ../../e_os.h ../../include/openssl/asn1.h
117pcy_lib.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
118pcy_lib.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
119pcy_lib.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
120pcy_lib.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
121pcy_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
122pcy_lib.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
123pcy_lib.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
124pcy_lib.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
125pcy_lib.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
126pcy_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
127pcy_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
128pcy_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
129pcy_lib.o: ../cryptlib.h pcy_int.h pcy_lib.c
130pcy_map.o: ../../e_os.h ../../include/openssl/asn1.h
131pcy_map.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
132pcy_map.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
133pcy_map.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
134pcy_map.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
135pcy_map.o: ../../include/openssl/err.h ../../include/openssl/evp.h
136pcy_map.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
137pcy_map.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
138pcy_map.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
139pcy_map.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
140pcy_map.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
141pcy_map.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
142pcy_map.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
143pcy_map.o: ../cryptlib.h pcy_int.h pcy_map.c
144pcy_node.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
145pcy_node.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
146pcy_node.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
147pcy_node.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
148pcy_node.o: ../../include/openssl/ecdsa.h ../../include/openssl/evp.h
149pcy_node.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
150pcy_node.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
151pcy_node.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
152pcy_node.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
153pcy_node.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
154pcy_node.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
155pcy_node.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
156pcy_node.o: pcy_int.h pcy_node.c
157pcy_tree.o: ../../e_os.h ../../include/openssl/asn1.h
158pcy_tree.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
159pcy_tree.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
160pcy_tree.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
161pcy_tree.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
162pcy_tree.o: ../../include/openssl/err.h ../../include/openssl/evp.h
163pcy_tree.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
164pcy_tree.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
165pcy_tree.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
166pcy_tree.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
167pcy_tree.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
168pcy_tree.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
169pcy_tree.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
170pcy_tree.o: ../cryptlib.h pcy_int.h pcy_tree.c
171v3_addr.o: ../../e_os.h ../../include/openssl/asn1.h
172v3_addr.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
173v3_addr.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
174v3_addr.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
175v3_addr.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
176v3_addr.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
177v3_addr.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
178v3_addr.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
179v3_addr.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
180v3_addr.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
181v3_addr.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
182v3_addr.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
183v3_addr.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
184v3_addr.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_addr.c
185v3_akey.o: ../../e_os.h ../../include/openssl/asn1.h
186v3_akey.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
187v3_akey.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
188v3_akey.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
189v3_akey.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
190v3_akey.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
191v3_akey.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
192v3_akey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
193v3_akey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
194v3_akey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
195v3_akey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
196v3_akey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
197v3_akey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
198v3_akey.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_akey.c
199v3_akeya.o: ../../e_os.h ../../include/openssl/asn1.h
200v3_akeya.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
201v3_akeya.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
202v3_akeya.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
203v3_akeya.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
204v3_akeya.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
205v3_akeya.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
206v3_akeya.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
207v3_akeya.o: ../../include/openssl/opensslconf.h
208v3_akeya.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
209v3_akeya.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
210v3_akeya.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
211v3_akeya.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
212v3_akeya.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
213v3_akeya.o: ../cryptlib.h v3_akeya.c
214v3_alt.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
215v3_alt.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
216v3_alt.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
217v3_alt.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
218v3_alt.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
219v3_alt.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
220v3_alt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
221v3_alt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
222v3_alt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
223v3_alt.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
224v3_alt.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
225v3_alt.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
226v3_alt.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_alt.c
227v3_asid.o: ../../e_os.h ../../include/openssl/asn1.h
228v3_asid.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
229v3_asid.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
230v3_asid.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
231v3_asid.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
232v3_asid.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
233v3_asid.o: ../../include/openssl/err.h ../../include/openssl/evp.h
234v3_asid.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
235v3_asid.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
236v3_asid.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
237v3_asid.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
238v3_asid.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
239v3_asid.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
240v3_asid.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
241v3_asid.o: ../cryptlib.h v3_asid.c
242v3_bcons.o: ../../e_os.h ../../include/openssl/asn1.h
243v3_bcons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
244v3_bcons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
245v3_bcons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
246v3_bcons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
247v3_bcons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
248v3_bcons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
249v3_bcons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
250v3_bcons.o: ../../include/openssl/opensslconf.h
251v3_bcons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
252v3_bcons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
253v3_bcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
254v3_bcons.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
255v3_bcons.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
256v3_bcons.o: ../cryptlib.h v3_bcons.c
257v3_bitst.o: ../../e_os.h ../../include/openssl/asn1.h
258v3_bitst.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
259v3_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
260v3_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
261v3_bitst.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
262v3_bitst.o: ../../include/openssl/err.h ../../include/openssl/evp.h
263v3_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
264v3_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
265v3_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
266v3_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
267v3_bitst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
268v3_bitst.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
269v3_bitst.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
270v3_bitst.o: ../cryptlib.h v3_bitst.c
271v3_conf.o: ../../e_os.h ../../include/openssl/asn1.h
272v3_conf.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
273v3_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
274v3_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
275v3_conf.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
276v3_conf.o: ../../include/openssl/err.h ../../include/openssl/evp.h
277v3_conf.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
278v3_conf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
279v3_conf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
280v3_conf.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
281v3_conf.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
282v3_conf.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
283v3_conf.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
284v3_conf.o: ../cryptlib.h v3_conf.c
285v3_cpols.o: ../../e_os.h ../../include/openssl/asn1.h
286v3_cpols.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
287v3_cpols.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
288v3_cpols.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
289v3_cpols.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
290v3_cpols.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
291v3_cpols.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
292v3_cpols.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
293v3_cpols.o: ../../include/openssl/opensslconf.h
294v3_cpols.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
295v3_cpols.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
296v3_cpols.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
297v3_cpols.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
298v3_cpols.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
299v3_cpols.o: ../cryptlib.h pcy_int.h v3_cpols.c
300v3_crld.o: ../../e_os.h ../../include/openssl/asn1.h
301v3_crld.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
302v3_crld.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
303v3_crld.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
304v3_crld.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
305v3_crld.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
306v3_crld.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
307v3_crld.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
308v3_crld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
309v3_crld.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
310v3_crld.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
311v3_crld.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
312v3_crld.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
313v3_crld.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_crld.c
314v3_enum.o: ../../e_os.h ../../include/openssl/asn1.h
315v3_enum.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
316v3_enum.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
317v3_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
318v3_enum.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
319v3_enum.o: ../../include/openssl/err.h ../../include/openssl/evp.h
320v3_enum.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
321v3_enum.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
322v3_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
323v3_enum.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
324v3_enum.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
325v3_enum.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
326v3_enum.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
327v3_enum.o: ../cryptlib.h v3_enum.c
328v3_extku.o: ../../e_os.h ../../include/openssl/asn1.h
329v3_extku.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
330v3_extku.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
331v3_extku.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
332v3_extku.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
333v3_extku.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
334v3_extku.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
335v3_extku.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
336v3_extku.o: ../../include/openssl/opensslconf.h
337v3_extku.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
338v3_extku.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
339v3_extku.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
340v3_extku.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
341v3_extku.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
342v3_extku.o: ../cryptlib.h v3_extku.c
343v3_genn.o: ../../e_os.h ../../include/openssl/asn1.h
344v3_genn.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
345v3_genn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
346v3_genn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
347v3_genn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
348v3_genn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
349v3_genn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
350v3_genn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
351v3_genn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
352v3_genn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
353v3_genn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
354v3_genn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
355v3_genn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
356v3_genn.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_genn.c
357v3_ia5.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
358v3_ia5.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
359v3_ia5.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
360v3_ia5.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
361v3_ia5.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
362v3_ia5.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
363v3_ia5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
364v3_ia5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
365v3_ia5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
366v3_ia5.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
367v3_ia5.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
368v3_ia5.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
369v3_ia5.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_ia5.c
370v3_info.o: ../../e_os.h ../../include/openssl/asn1.h
371v3_info.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
372v3_info.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
373v3_info.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
374v3_info.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
375v3_info.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
376v3_info.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
377v3_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
378v3_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
379v3_info.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
380v3_info.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
381v3_info.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
382v3_info.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
383v3_info.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_info.c
384v3_int.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
385v3_int.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
386v3_int.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
387v3_int.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
388v3_int.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
389v3_int.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
390v3_int.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
391v3_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
392v3_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
393v3_int.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
394v3_int.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
395v3_int.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
396v3_int.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_int.c
397v3_lib.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
398v3_lib.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
399v3_lib.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
400v3_lib.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
401v3_lib.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
402v3_lib.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
403v3_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
404v3_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
405v3_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
406v3_lib.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
407v3_lib.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
408v3_lib.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
409v3_lib.o: ../../include/openssl/x509v3.h ../cryptlib.h ext_dat.h v3_lib.c
410v3_ncons.o: ../../e_os.h ../../include/openssl/asn1.h
411v3_ncons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
412v3_ncons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
413v3_ncons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
414v3_ncons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
415v3_ncons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
416v3_ncons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
417v3_ncons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
418v3_ncons.o: ../../include/openssl/opensslconf.h
419v3_ncons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
420v3_ncons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
421v3_ncons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
422v3_ncons.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
423v3_ncons.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
424v3_ncons.o: ../cryptlib.h v3_ncons.c
425v3_ocsp.o: ../../e_os.h ../../include/openssl/asn1.h
426v3_ocsp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
427v3_ocsp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
428v3_ocsp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
429v3_ocsp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
430v3_ocsp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
431v3_ocsp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
432v3_ocsp.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
433v3_ocsp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
434v3_ocsp.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
435v3_ocsp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
436v3_ocsp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
437v3_ocsp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
438v3_ocsp.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_ocsp.c
439v3_pci.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
440v3_pci.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
441v3_pci.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
442v3_pci.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
443v3_pci.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
444v3_pci.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
445v3_pci.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
446v3_pci.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
447v3_pci.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
448v3_pci.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
449v3_pci.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
450v3_pci.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
451v3_pci.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_pci.c
452v3_pcia.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
453v3_pcia.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
454v3_pcia.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
455v3_pcia.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
456v3_pcia.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
457v3_pcia.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
458v3_pcia.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
459v3_pcia.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
460v3_pcia.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
461v3_pcia.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
462v3_pcia.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
463v3_pcia.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
464v3_pcia.o: ../../include/openssl/x509v3.h v3_pcia.c
465v3_pcons.o: ../../e_os.h ../../include/openssl/asn1.h
466v3_pcons.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
467v3_pcons.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
468v3_pcons.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
469v3_pcons.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
470v3_pcons.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
471v3_pcons.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
472v3_pcons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
473v3_pcons.o: ../../include/openssl/opensslconf.h
474v3_pcons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
475v3_pcons.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
476v3_pcons.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
477v3_pcons.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
478v3_pcons.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
479v3_pcons.o: ../cryptlib.h v3_pcons.c
480v3_pku.o: ../../e_os.h ../../include/openssl/asn1.h
481v3_pku.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
482v3_pku.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
483v3_pku.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
484v3_pku.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
485v3_pku.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
486v3_pku.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
487v3_pku.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
488v3_pku.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
489v3_pku.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
490v3_pku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
491v3_pku.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
492v3_pku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
493v3_pku.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_pku.c
494v3_pmaps.o: ../../e_os.h ../../include/openssl/asn1.h
495v3_pmaps.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
496v3_pmaps.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
497v3_pmaps.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
498v3_pmaps.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
499v3_pmaps.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
500v3_pmaps.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
501v3_pmaps.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
502v3_pmaps.o: ../../include/openssl/opensslconf.h
503v3_pmaps.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
504v3_pmaps.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
505v3_pmaps.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
506v3_pmaps.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
507v3_pmaps.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
508v3_pmaps.o: ../cryptlib.h v3_pmaps.c
509v3_prn.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
510v3_prn.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
511v3_prn.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
512v3_prn.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
513v3_prn.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
514v3_prn.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
515v3_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
516v3_prn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
517v3_prn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
518v3_prn.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
519v3_prn.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
520v3_prn.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
521v3_prn.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_prn.c
522v3_purp.o: ../../e_os.h ../../include/openssl/asn1.h
523v3_purp.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
524v3_purp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
525v3_purp.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
526v3_purp.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
527v3_purp.o: ../../include/openssl/err.h ../../include/openssl/evp.h
528v3_purp.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
529v3_purp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
530v3_purp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
531v3_purp.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
532v3_purp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
533v3_purp.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
534v3_purp.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
535v3_purp.o: ../cryptlib.h v3_purp.c
536v3_skey.o: ../../e_os.h ../../include/openssl/asn1.h
537v3_skey.o: ../../include/openssl/bio.h ../../include/openssl/buffer.h
538v3_skey.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
539v3_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
540v3_skey.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
541v3_skey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
542v3_skey.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
543v3_skey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
544v3_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
545v3_skey.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
546v3_skey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
547v3_skey.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
548v3_skey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
549v3_skey.o: ../cryptlib.h v3_skey.c
550v3_sxnet.o: ../../e_os.h ../../include/openssl/asn1.h
551v3_sxnet.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
552v3_sxnet.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
553v3_sxnet.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
554v3_sxnet.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
555v3_sxnet.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
556v3_sxnet.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
557v3_sxnet.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
558v3_sxnet.o: ../../include/openssl/opensslconf.h
559v3_sxnet.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
560v3_sxnet.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
561v3_sxnet.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
562v3_sxnet.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
563v3_sxnet.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
564v3_sxnet.o: ../cryptlib.h v3_sxnet.c
565v3_utl.o: ../../e_os.h ../../include/openssl/asn1.h ../../include/openssl/bio.h
566v3_utl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
567v3_utl.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
568v3_utl.o: ../../include/openssl/e_os2.h ../../include/openssl/ec.h
569v3_utl.o: ../../include/openssl/ecdh.h ../../include/openssl/ecdsa.h
570v3_utl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
571v3_utl.o: ../../include/openssl/lhash.h ../../include/openssl/obj_mac.h
572v3_utl.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
573v3_utl.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
574v3_utl.o: ../../include/openssl/pkcs7.h ../../include/openssl/safestack.h
575v3_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
576v3_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/x509.h
577v3_utl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
578v3_utl.o: ../cryptlib.h v3_utl.c
579v3err.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
580v3err.o: ../../include/openssl/buffer.h ../../include/openssl/conf.h
581v3err.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h
582v3err.o: ../../include/openssl/ec.h ../../include/openssl/ecdh.h
583v3err.o: ../../include/openssl/ecdsa.h ../../include/openssl/err.h
584v3err.o: ../../include/openssl/evp.h ../../include/openssl/lhash.h
585v3err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
586v3err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
587v3err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
588v3err.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
589v3err.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
590v3err.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
591v3err.o: ../../include/openssl/x509v3.h v3err.c
diff --git a/src/lib/libcrypto/x509v3/Makefile.ssl b/src/lib/libcrypto/x509v3/Makefile.ssl
new file mode 100644
index 0000000000..66df90c346
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/Makefile.ssl
@@ -0,0 +1,603 @@
1#
2# SSLeay/crypto/x509v3/Makefile
3#
4
5DIR= x509v3
6TOP= ../..
7CC= cc
8INCLUDES= -I.. -I$(TOP) -I../../include
9CFLAG=-g
10INSTALL_PREFIX=
11OPENSSLDIR= /usr/local/ssl
12INSTALLTOP=/usr/local/ssl
13MAKE= make -f Makefile.ssl
14MAKEDEPPROG= makedepend
15MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG)
16MAKEFILE= Makefile.ssl
17AR= ar r
18
19CFLAGS= $(INCLUDES) $(CFLAG)
20
21GENERAL=Makefile README
22TEST=
23APPS=
24
25LIB=$(TOP)/libcrypto.a
26LIBSRC= v3_bcons.c v3_bitst.c v3_conf.c v3_extku.c v3_ia5.c v3_lib.c \
27v3_prn.c v3_utl.c v3err.c v3_genn.c v3_alt.c v3_skey.c v3_akey.c v3_pku.c \
28v3_int.c v3_enum.c v3_sxnet.c v3_cpols.c v3_crld.c v3_purp.c v3_info.c \
29v3_ocsp.c v3_akeya.c
30LIBOBJ= v3_bcons.o v3_bitst.o v3_conf.o v3_extku.o v3_ia5.o v3_lib.o \
31v3_prn.o v3_utl.o v3err.o v3_genn.o v3_alt.o v3_skey.o v3_akey.o v3_pku.o \
32v3_int.o v3_enum.o v3_sxnet.o v3_cpols.o v3_crld.o v3_purp.o v3_info.o \
33v3_ocsp.o v3_akeya.o
34
35SRC= $(LIBSRC)
36
37EXHEADER= x509v3.h
38HEADER= $(EXHEADER)
39
40ALL= $(GENERAL) $(SRC) $(HEADER)
41
42top:
43 (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all)
44
45all: lib
46
47lib: $(LIBOBJ)
48 $(AR) $(LIB) $(LIBOBJ)
49 $(RANLIB) $(LIB) || echo Never mind.
50 @touch lib
51
52files:
53 $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
54
55links:
56 @sh $(TOP)/util/point.sh Makefile.ssl Makefile
57 @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER)
58 @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST)
59 @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS)
60
61install:
62 @for i in $(EXHEADER) ; \
63 do \
64 (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \
65 chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \
66 done;
67
68tags:
69 ctags $(SRC)
70
71tests:
72
73lint:
74 lint -DLINT $(INCLUDES) $(SRC)>fluff
75
76depend:
77 $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC)
78
79dclean:
80 $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new
81 mv -f Makefile.new $(MAKEFILE)
82
83clean:
84 rm -f *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff
85
86# DO NOT DELETE THIS LINE -- make depend depends on it.
87
88v3_akey.o: ../../e_os.h ../../include/openssl/aes.h
89v3_akey.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
90v3_akey.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
91v3_akey.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
92v3_akey.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
93v3_akey.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
94v3_akey.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
95v3_akey.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
96v3_akey.o: ../../include/openssl/err.h ../../include/openssl/evp.h
97v3_akey.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
98v3_akey.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
99v3_akey.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
100v3_akey.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
101v3_akey.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
102v3_akey.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
103v3_akey.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
104v3_akey.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
105v3_akey.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
106v3_akey.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
107v3_akey.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
108v3_akey.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
109v3_akey.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
110v3_akey.o: ../cryptlib.h v3_akey.c
111v3_akeya.o: ../../e_os.h ../../include/openssl/aes.h
112v3_akeya.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
113v3_akeya.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
114v3_akeya.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
115v3_akeya.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
116v3_akeya.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
117v3_akeya.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
118v3_akeya.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
119v3_akeya.o: ../../include/openssl/err.h ../../include/openssl/evp.h
120v3_akeya.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
121v3_akeya.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
122v3_akeya.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
123v3_akeya.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
124v3_akeya.o: ../../include/openssl/opensslconf.h
125v3_akeya.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
126v3_akeya.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
127v3_akeya.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
128v3_akeya.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
129v3_akeya.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
130v3_akeya.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
131v3_akeya.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
132v3_akeya.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
133v3_akeya.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_akeya.c
134v3_alt.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
135v3_alt.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
136v3_alt.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
137v3_alt.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
138v3_alt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
139v3_alt.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
140v3_alt.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
141v3_alt.o: ../../include/openssl/err.h ../../include/openssl/evp.h
142v3_alt.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
143v3_alt.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
144v3_alt.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
145v3_alt.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
146v3_alt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
147v3_alt.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
148v3_alt.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
149v3_alt.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
150v3_alt.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
151v3_alt.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
152v3_alt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
153v3_alt.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
154v3_alt.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
155v3_alt.o: ../cryptlib.h v3_alt.c
156v3_bcons.o: ../../e_os.h ../../include/openssl/aes.h
157v3_bcons.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
158v3_bcons.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
159v3_bcons.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
160v3_bcons.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
161v3_bcons.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
162v3_bcons.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
163v3_bcons.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
164v3_bcons.o: ../../include/openssl/err.h ../../include/openssl/evp.h
165v3_bcons.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
166v3_bcons.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
167v3_bcons.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
168v3_bcons.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
169v3_bcons.o: ../../include/openssl/opensslconf.h
170v3_bcons.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
171v3_bcons.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
172v3_bcons.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
173v3_bcons.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
174v3_bcons.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
175v3_bcons.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
176v3_bcons.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
177v3_bcons.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
178v3_bcons.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_bcons.c
179v3_bitst.o: ../../e_os.h ../../include/openssl/aes.h
180v3_bitst.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
181v3_bitst.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
182v3_bitst.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
183v3_bitst.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
184v3_bitst.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
185v3_bitst.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
186v3_bitst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
187v3_bitst.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
188v3_bitst.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
189v3_bitst.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
190v3_bitst.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
191v3_bitst.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
192v3_bitst.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
193v3_bitst.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
194v3_bitst.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
195v3_bitst.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
196v3_bitst.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
197v3_bitst.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
198v3_bitst.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
199v3_bitst.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
200v3_bitst.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_bitst.c
201v3_conf.o: ../../e_os.h ../../include/openssl/aes.h
202v3_conf.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
203v3_conf.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
204v3_conf.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
205v3_conf.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
206v3_conf.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
207v3_conf.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
208v3_conf.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
209v3_conf.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
210v3_conf.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
211v3_conf.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
212v3_conf.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
213v3_conf.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
214v3_conf.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
215v3_conf.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
216v3_conf.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
217v3_conf.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
218v3_conf.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
219v3_conf.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
220v3_conf.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
221v3_conf.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
222v3_conf.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_conf.c
223v3_cpols.o: ../../e_os.h ../../include/openssl/aes.h
224v3_cpols.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
225v3_cpols.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
226v3_cpols.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
227v3_cpols.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
228v3_cpols.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
229v3_cpols.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
230v3_cpols.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
231v3_cpols.o: ../../include/openssl/err.h ../../include/openssl/evp.h
232v3_cpols.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
233v3_cpols.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
234v3_cpols.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
235v3_cpols.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
236v3_cpols.o: ../../include/openssl/opensslconf.h
237v3_cpols.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
238v3_cpols.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
239v3_cpols.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
240v3_cpols.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
241v3_cpols.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
242v3_cpols.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
243v3_cpols.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
244v3_cpols.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
245v3_cpols.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_cpols.c
246v3_crld.o: ../../e_os.h ../../include/openssl/aes.h
247v3_crld.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
248v3_crld.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
249v3_crld.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
250v3_crld.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
251v3_crld.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
252v3_crld.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
253v3_crld.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
254v3_crld.o: ../../include/openssl/err.h ../../include/openssl/evp.h
255v3_crld.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
256v3_crld.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
257v3_crld.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
258v3_crld.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
259v3_crld.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
260v3_crld.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
261v3_crld.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
262v3_crld.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
263v3_crld.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
264v3_crld.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
265v3_crld.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
266v3_crld.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
267v3_crld.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
268v3_crld.o: ../cryptlib.h v3_crld.c
269v3_enum.o: ../../e_os.h ../../include/openssl/aes.h
270v3_enum.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
271v3_enum.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
272v3_enum.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
273v3_enum.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
274v3_enum.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
275v3_enum.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
276v3_enum.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
277v3_enum.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
278v3_enum.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
279v3_enum.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
280v3_enum.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
281v3_enum.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
282v3_enum.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
283v3_enum.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
284v3_enum.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
285v3_enum.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
286v3_enum.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
287v3_enum.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
288v3_enum.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
289v3_enum.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
290v3_enum.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_enum.c
291v3_extku.o: ../../e_os.h ../../include/openssl/aes.h
292v3_extku.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
293v3_extku.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
294v3_extku.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
295v3_extku.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
296v3_extku.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
297v3_extku.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
298v3_extku.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
299v3_extku.o: ../../include/openssl/err.h ../../include/openssl/evp.h
300v3_extku.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
301v3_extku.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
302v3_extku.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
303v3_extku.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
304v3_extku.o: ../../include/openssl/opensslconf.h
305v3_extku.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
306v3_extku.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
307v3_extku.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
308v3_extku.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
309v3_extku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
310v3_extku.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
311v3_extku.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
312v3_extku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
313v3_extku.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_extku.c
314v3_genn.o: ../../e_os.h ../../include/openssl/aes.h
315v3_genn.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
316v3_genn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
317v3_genn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
318v3_genn.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
319v3_genn.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
320v3_genn.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
321v3_genn.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
322v3_genn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
323v3_genn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
324v3_genn.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
325v3_genn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
326v3_genn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
327v3_genn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
328v3_genn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
329v3_genn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
330v3_genn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
331v3_genn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
332v3_genn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
333v3_genn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
334v3_genn.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
335v3_genn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
336v3_genn.o: ../cryptlib.h v3_genn.c
337v3_ia5.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
338v3_ia5.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
339v3_ia5.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
340v3_ia5.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
341v3_ia5.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
342v3_ia5.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
343v3_ia5.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
344v3_ia5.o: ../../include/openssl/err.h ../../include/openssl/evp.h
345v3_ia5.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
346v3_ia5.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
347v3_ia5.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
348v3_ia5.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
349v3_ia5.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
350v3_ia5.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
351v3_ia5.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
352v3_ia5.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
353v3_ia5.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
354v3_ia5.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
355v3_ia5.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
356v3_ia5.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
357v3_ia5.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
358v3_ia5.o: ../cryptlib.h v3_ia5.c
359v3_info.o: ../../e_os.h ../../include/openssl/aes.h
360v3_info.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
361v3_info.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
362v3_info.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
363v3_info.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
364v3_info.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
365v3_info.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
366v3_info.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
367v3_info.o: ../../include/openssl/err.h ../../include/openssl/evp.h
368v3_info.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
369v3_info.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
370v3_info.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
371v3_info.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
372v3_info.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
373v3_info.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
374v3_info.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
375v3_info.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
376v3_info.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
377v3_info.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
378v3_info.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
379v3_info.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
380v3_info.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
381v3_info.o: ../cryptlib.h v3_info.c
382v3_int.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
383v3_int.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
384v3_int.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
385v3_int.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
386v3_int.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
387v3_int.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
388v3_int.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
389v3_int.o: ../../include/openssl/err.h ../../include/openssl/evp.h
390v3_int.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
391v3_int.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
392v3_int.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
393v3_int.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
394v3_int.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
395v3_int.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
396v3_int.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
397v3_int.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
398v3_int.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
399v3_int.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
400v3_int.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
401v3_int.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
402v3_int.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
403v3_int.o: ../cryptlib.h v3_int.c
404v3_lib.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
405v3_lib.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
406v3_lib.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
407v3_lib.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
408v3_lib.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
409v3_lib.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
410v3_lib.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
411v3_lib.o: ../../include/openssl/err.h ../../include/openssl/evp.h
412v3_lib.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
413v3_lib.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
414v3_lib.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
415v3_lib.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
416v3_lib.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
417v3_lib.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
418v3_lib.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
419v3_lib.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
420v3_lib.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
421v3_lib.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
422v3_lib.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
423v3_lib.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
424v3_lib.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
425v3_lib.o: ../cryptlib.h ext_dat.h v3_lib.c
426v3_ocsp.o: ../../e_os.h ../../include/openssl/aes.h
427v3_ocsp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
428v3_ocsp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
429v3_ocsp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
430v3_ocsp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
431v3_ocsp.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
432v3_ocsp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
433v3_ocsp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
434v3_ocsp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
435v3_ocsp.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
436v3_ocsp.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
437v3_ocsp.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
438v3_ocsp.o: ../../include/openssl/objects.h ../../include/openssl/ocsp.h
439v3_ocsp.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
440v3_ocsp.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
441v3_ocsp.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
442v3_ocsp.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
443v3_ocsp.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
444v3_ocsp.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
445v3_ocsp.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
446v3_ocsp.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
447v3_ocsp.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
448v3_ocsp.o: ../cryptlib.h v3_ocsp.c
449v3_pku.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
450v3_pku.o: ../../include/openssl/asn1t.h ../../include/openssl/bio.h
451v3_pku.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
452v3_pku.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
453v3_pku.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
454v3_pku.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
455v3_pku.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
456v3_pku.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
457v3_pku.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
458v3_pku.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
459v3_pku.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
460v3_pku.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
461v3_pku.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
462v3_pku.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
463v3_pku.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
464v3_pku.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
465v3_pku.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
466v3_pku.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
467v3_pku.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
468v3_pku.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
469v3_pku.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
470v3_pku.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_pku.c
471v3_prn.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
472v3_prn.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
473v3_prn.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
474v3_prn.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
475v3_prn.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
476v3_prn.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
477v3_prn.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
478v3_prn.o: ../../include/openssl/err.h ../../include/openssl/evp.h
479v3_prn.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
480v3_prn.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
481v3_prn.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
482v3_prn.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
483v3_prn.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
484v3_prn.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
485v3_prn.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
486v3_prn.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
487v3_prn.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
488v3_prn.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
489v3_prn.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
490v3_prn.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
491v3_prn.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
492v3_prn.o: ../cryptlib.h v3_prn.c
493v3_purp.o: ../../e_os.h ../../include/openssl/aes.h
494v3_purp.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
495v3_purp.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
496v3_purp.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
497v3_purp.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
498v3_purp.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
499v3_purp.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
500v3_purp.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
501v3_purp.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
502v3_purp.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
503v3_purp.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
504v3_purp.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
505v3_purp.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
506v3_purp.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
507v3_purp.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
508v3_purp.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
509v3_purp.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
510v3_purp.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
511v3_purp.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
512v3_purp.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
513v3_purp.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
514v3_purp.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_purp.c
515v3_skey.o: ../../e_os.h ../../include/openssl/aes.h
516v3_skey.o: ../../include/openssl/asn1.h ../../include/openssl/bio.h
517v3_skey.o: ../../include/openssl/blowfish.h ../../include/openssl/bn.h
518v3_skey.o: ../../include/openssl/buffer.h ../../include/openssl/cast.h
519v3_skey.o: ../../include/openssl/conf.h ../../include/openssl/crypto.h
520v3_skey.o: ../../include/openssl/des.h ../../include/openssl/des_old.h
521v3_skey.o: ../../include/openssl/dh.h ../../include/openssl/dsa.h
522v3_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h
523v3_skey.o: ../../include/openssl/evp.h ../../include/openssl/idea.h
524v3_skey.o: ../../include/openssl/lhash.h ../../include/openssl/md2.h
525v3_skey.o: ../../include/openssl/md4.h ../../include/openssl/md5.h
526v3_skey.o: ../../include/openssl/mdc2.h ../../include/openssl/obj_mac.h
527v3_skey.o: ../../include/openssl/objects.h ../../include/openssl/opensslconf.h
528v3_skey.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
529v3_skey.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
530v3_skey.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
531v3_skey.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
532v3_skey.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
533v3_skey.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
534v3_skey.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
535v3_skey.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
536v3_skey.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_skey.c
537v3_sxnet.o: ../../e_os.h ../../include/openssl/aes.h
538v3_sxnet.o: ../../include/openssl/asn1.h ../../include/openssl/asn1t.h
539v3_sxnet.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
540v3_sxnet.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
541v3_sxnet.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
542v3_sxnet.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
543v3_sxnet.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
544v3_sxnet.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
545v3_sxnet.o: ../../include/openssl/err.h ../../include/openssl/evp.h
546v3_sxnet.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
547v3_sxnet.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
548v3_sxnet.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
549v3_sxnet.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
550v3_sxnet.o: ../../include/openssl/opensslconf.h
551v3_sxnet.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h
552v3_sxnet.o: ../../include/openssl/pkcs7.h ../../include/openssl/rc2.h
553v3_sxnet.o: ../../include/openssl/rc4.h ../../include/openssl/rc5.h
554v3_sxnet.o: ../../include/openssl/ripemd.h ../../include/openssl/rsa.h
555v3_sxnet.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h
556v3_sxnet.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h
557v3_sxnet.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h
558v3_sxnet.o: ../../include/openssl/x509.h ../../include/openssl/x509_vfy.h
559v3_sxnet.o: ../../include/openssl/x509v3.h ../cryptlib.h v3_sxnet.c
560v3_utl.o: ../../e_os.h ../../include/openssl/aes.h ../../include/openssl/asn1.h
561v3_utl.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
562v3_utl.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
563v3_utl.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
564v3_utl.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
565v3_utl.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
566v3_utl.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
567v3_utl.o: ../../include/openssl/err.h ../../include/openssl/evp.h
568v3_utl.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
569v3_utl.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
570v3_utl.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
571v3_utl.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
572v3_utl.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
573v3_utl.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
574v3_utl.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
575v3_utl.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
576v3_utl.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
577v3_utl.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
578v3_utl.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
579v3_utl.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
580v3_utl.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
581v3_utl.o: ../cryptlib.h v3_utl.c
582v3err.o: ../../include/openssl/aes.h ../../include/openssl/asn1.h
583v3err.o: ../../include/openssl/bio.h ../../include/openssl/blowfish.h
584v3err.o: ../../include/openssl/bn.h ../../include/openssl/buffer.h
585v3err.o: ../../include/openssl/cast.h ../../include/openssl/conf.h
586v3err.o: ../../include/openssl/crypto.h ../../include/openssl/des.h
587v3err.o: ../../include/openssl/des_old.h ../../include/openssl/dh.h
588v3err.o: ../../include/openssl/dsa.h ../../include/openssl/e_os2.h
589v3err.o: ../../include/openssl/err.h ../../include/openssl/evp.h
590v3err.o: ../../include/openssl/idea.h ../../include/openssl/lhash.h
591v3err.o: ../../include/openssl/md2.h ../../include/openssl/md4.h
592v3err.o: ../../include/openssl/md5.h ../../include/openssl/mdc2.h
593v3err.o: ../../include/openssl/obj_mac.h ../../include/openssl/objects.h
594v3err.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h
595v3err.o: ../../include/openssl/ossl_typ.h ../../include/openssl/pkcs7.h
596v3err.o: ../../include/openssl/rc2.h ../../include/openssl/rc4.h
597v3err.o: ../../include/openssl/rc5.h ../../include/openssl/ripemd.h
598v3err.o: ../../include/openssl/rsa.h ../../include/openssl/safestack.h
599v3err.o: ../../include/openssl/sha.h ../../include/openssl/stack.h
600v3err.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h
601v3err.o: ../../include/openssl/ui_compat.h ../../include/openssl/x509.h
602v3err.o: ../../include/openssl/x509_vfy.h ../../include/openssl/x509v3.h
603v3err.o: v3err.c
diff --git a/src/lib/libcrypto/x509v3/ext_dat.h b/src/lib/libcrypto/x509v3/ext_dat.h
index 5c063ac65d..d8328ac468 100644
--- a/src/lib/libcrypto/x509v3/ext_dat.h
+++ b/src/lib/libcrypto/x509v3/ext_dat.h
@@ -65,11 +65,6 @@ extern X509V3_EXT_METHOD v3_delta_crl, v3_cpols, v3_crld;
65extern X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp, v3_ocsp_acutoff; 65extern X509V3_EXT_METHOD v3_ocsp_nonce, v3_ocsp_accresp, v3_ocsp_acutoff;
66extern X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck, v3_ocsp_serviceloc; 66extern X509V3_EXT_METHOD v3_ocsp_crlid, v3_ocsp_nocheck, v3_ocsp_serviceloc;
67extern X509V3_EXT_METHOD v3_crl_hold, v3_pci; 67extern X509V3_EXT_METHOD v3_crl_hold, v3_pci;
68extern X509V3_EXT_METHOD v3_policy_mappings, v3_policy_constraints;
69extern X509V3_EXT_METHOD v3_name_constraints, v3_inhibit_anyp;
70#ifndef OPENSSL_NO_RFC3779
71extern X509V3_EXT_METHOD v3_addr, v3_asid;
72#endif
73 68
74/* This table will be searched using OBJ_bsearch so it *must* kept in 69/* This table will be searched using OBJ_bsearch so it *must* kept in
75 * order of the ext_nid values. 70 * order of the ext_nid values.
@@ -102,10 +97,6 @@ static X509V3_EXT_METHOD *standard_exts[] = {
102#endif 97#endif
103&v3_sxnet, 98&v3_sxnet,
104&v3_info, 99&v3_info,
105#ifndef OPENSSL_NO_RFC3779
106&v3_addr,
107&v3_asid,
108#endif
109#ifndef OPENSSL_NO_OCSP 100#ifndef OPENSSL_NO_OCSP
110&v3_ocsp_nonce, 101&v3_ocsp_nonce,
111&v3_ocsp_crlid, 102&v3_ocsp_crlid,
@@ -115,14 +106,10 @@ static X509V3_EXT_METHOD *standard_exts[] = {
115&v3_ocsp_serviceloc, 106&v3_ocsp_serviceloc,
116#endif 107#endif
117&v3_sinfo, 108&v3_sinfo,
118&v3_policy_constraints,
119#ifndef OPENSSL_NO_OCSP 109#ifndef OPENSSL_NO_OCSP
120&v3_crl_hold, 110&v3_crl_hold,
121#endif 111#endif
122&v3_pci, 112&v3_pci,
123&v3_name_constraints,
124&v3_policy_mappings,
125&v3_inhibit_anyp
126}; 113};
127 114
128/* Number of standard extensions */ 115/* Number of standard extensions */
diff --git a/src/lib/libcrypto/x509v3/tabtest.c b/src/lib/libcrypto/x509v3/tabtest.c
new file mode 100644
index 0000000000..dad0d38dd5
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/tabtest.c
@@ -0,0 +1,88 @@
1/* tabtest.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project 1999.
4 */
5/* ====================================================================
6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
18 * distribution.
19 *
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
24 *
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
29 *
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
33 *
34 * 6. Redistributions of any form whatsoever must retain the following
35 * acknowledgment:
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
38 *
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
52 *
53 * This product includes cryptographic software written by Eric Young
54 * (eay@cryptsoft.com). This product includes software written by Tim
55 * Hudson (tjh@cryptsoft.com).
56 *
57 */
58
59/* Simple program to check the ext_dat.h is correct and print out
60 * problems if it is not.
61 */
62
63#include <stdio.h>
64
65#include <openssl/x509v3.h>
66
67#include "ext_dat.h"
68
69main()
70{
71 int i, prev = -1, bad = 0;
72 X509V3_EXT_METHOD **tmp;
73 i = sizeof(standard_exts) / sizeof(X509V3_EXT_METHOD *);
74 if(i != STANDARD_EXTENSION_COUNT)
75 fprintf(stderr, "Extension number invalid expecting %d\n", i);
76 tmp = standard_exts;
77 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++) {
78 if((*tmp)->ext_nid < prev) bad = 1;
79 prev = (*tmp)->ext_nid;
80
81 }
82 if(bad) {
83 tmp = standard_exts;
84 fprintf(stderr, "Extensions out of order!\n");
85 for(i = 0; i < STANDARD_EXTENSION_COUNT; i++, tmp++)
86 printf("%d : %s\n", (*tmp)->ext_nid, OBJ_nid2sn((*tmp)->ext_nid));
87 } else fprintf(stderr, "Order OK\n");
88}
diff --git a/src/lib/libcrypto/x509v3/v3_addr.c b/src/lib/libcrypto/x509v3/v3_addr.c
new file mode 100644
index 0000000000..ed9847b307
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_addr.c
@@ -0,0 +1,1280 @@
1/*
2 * Contributed to the OpenSSL Project by the American Registry for
3 * Internet Numbers ("ARIN").
4 */
5/* ====================================================================
6 * Copyright (c) 2006 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 * Implementation of RFC 3779 section 2.2.
60 */
61
62#include <stdio.h>
63#include <stdlib.h>
64#include <assert.h>
65#include "cryptlib.h"
66#include <openssl/conf.h>
67#include <openssl/asn1.h>
68#include <openssl/asn1t.h>
69#include <openssl/buffer.h>
70#include <openssl/x509v3.h>
71
72#ifndef OPENSSL_NO_RFC3779
73
74/*
75 * OpenSSL ASN.1 template translation of RFC 3779 2.2.3.
76 */
77
78ASN1_SEQUENCE(IPAddressRange) = {
79 ASN1_SIMPLE(IPAddressRange, min, ASN1_BIT_STRING),
80 ASN1_SIMPLE(IPAddressRange, max, ASN1_BIT_STRING)
81} ASN1_SEQUENCE_END(IPAddressRange)
82
83ASN1_CHOICE(IPAddressOrRange) = {
84 ASN1_SIMPLE(IPAddressOrRange, u.addressPrefix, ASN1_BIT_STRING),
85 ASN1_SIMPLE(IPAddressOrRange, u.addressRange, IPAddressRange)
86} ASN1_CHOICE_END(IPAddressOrRange)
87
88ASN1_CHOICE(IPAddressChoice) = {
89 ASN1_SIMPLE(IPAddressChoice, u.inherit, ASN1_NULL),
90 ASN1_SEQUENCE_OF(IPAddressChoice, u.addressesOrRanges, IPAddressOrRange)
91} ASN1_CHOICE_END(IPAddressChoice)
92
93ASN1_SEQUENCE(IPAddressFamily) = {
94 ASN1_SIMPLE(IPAddressFamily, addressFamily, ASN1_OCTET_STRING),
95 ASN1_SIMPLE(IPAddressFamily, ipAddressChoice, IPAddressChoice)
96} ASN1_SEQUENCE_END(IPAddressFamily)
97
98ASN1_ITEM_TEMPLATE(IPAddrBlocks) =
99 ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF, 0,
100 IPAddrBlocks, IPAddressFamily)
101ASN1_ITEM_TEMPLATE_END(IPAddrBlocks)
102
103IMPLEMENT_ASN1_FUNCTIONS(IPAddressRange)
104IMPLEMENT_ASN1_FUNCTIONS(IPAddressOrRange)
105IMPLEMENT_ASN1_FUNCTIONS(IPAddressChoice)
106IMPLEMENT_ASN1_FUNCTIONS(IPAddressFamily)
107
108/*
109 * How much buffer space do we need for a raw address?
110 */
111#define ADDR_RAW_BUF_LEN 16
112
113/*
114 * What's the address length associated with this AFI?
115 */
116static int length_from_afi(const unsigned afi)
117{
118 switch (afi) {
119 case IANA_AFI_IPV4:
120 return 4;
121 case IANA_AFI_IPV6:
122 return 16;
123 default:
124 return 0;
125 }
126}
127
128/*
129 * Extract the AFI from an IPAddressFamily.
130 */
131unsigned v3_addr_get_afi(const IPAddressFamily *f)
132{
133 return ((f != NULL &&
134 f->addressFamily != NULL &&
135 f->addressFamily->data != NULL)
136 ? ((f->addressFamily->data[0] << 8) |
137 (f->addressFamily->data[1]))
138 : 0);
139}
140
141/*
142 * Expand the bitstring form of an address into a raw byte array.
143 * At the moment this is coded for simplicity, not speed.
144 */
145static void addr_expand(unsigned char *addr,
146 const ASN1_BIT_STRING *bs,
147 const int length,
148 const unsigned char fill)
149{
150 assert(bs->length >= 0 && bs->length <= length);
151 if (bs->length > 0) {
152 memcpy(addr, bs->data, bs->length);
153 if ((bs->flags & 7) != 0) {
154 unsigned char mask = 0xFF >> (8 - (bs->flags & 7));
155 if (fill == 0)
156 addr[bs->length - 1] &= ~mask;
157 else
158 addr[bs->length - 1] |= mask;
159 }
160 }
161 memset(addr + bs->length, fill, length - bs->length);
162}
163
164/*
165 * Extract the prefix length from a bitstring.
166 */
167#define addr_prefixlen(bs) ((int) ((bs)->length * 8 - ((bs)->flags & 7)))
168
169/*
170 * i2r handler for one address bitstring.
171 */
172static int i2r_address(BIO *out,
173 const unsigned afi,
174 const unsigned char fill,
175 const ASN1_BIT_STRING *bs)
176{
177 unsigned char addr[ADDR_RAW_BUF_LEN];
178 int i, n;
179
180 switch (afi) {
181 case IANA_AFI_IPV4:
182 addr_expand(addr, bs, 4, fill);
183 BIO_printf(out, "%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
184 break;
185 case IANA_AFI_IPV6:
186 addr_expand(addr, bs, 16, fill);
187 for (n = 16; n > 1 && addr[n-1] == 0x00 && addr[n-2] == 0x00; n -= 2)
188 ;
189 for (i = 0; i < n; i += 2)
190 BIO_printf(out, "%x%s", (addr[i] << 8) | addr[i+1], (i < 14 ? ":" : ""));
191 if (i < 16)
192 BIO_puts(out, ":");
193 break;
194 default:
195 for (i = 0; i < bs->length; i++)
196 BIO_printf(out, "%s%02x", (i > 0 ? ":" : ""), bs->data[i]);
197 BIO_printf(out, "[%d]", (int) (bs->flags & 7));
198 break;
199 }
200 return 1;
201}
202
203/*
204 * i2r handler for a sequence of addresses and ranges.
205 */
206static int i2r_IPAddressOrRanges(BIO *out,
207 const int indent,
208 const IPAddressOrRanges *aors,
209 const unsigned afi)
210{
211 int i;
212 for (i = 0; i < sk_IPAddressOrRange_num(aors); i++) {
213 const IPAddressOrRange *aor = sk_IPAddressOrRange_value(aors, i);
214 BIO_printf(out, "%*s", indent, "");
215 switch (aor->type) {
216 case IPAddressOrRange_addressPrefix:
217 if (!i2r_address(out, afi, 0x00, aor->u.addressPrefix))
218 return 0;
219 BIO_printf(out, "/%d\n", addr_prefixlen(aor->u.addressPrefix));
220 continue;
221 case IPAddressOrRange_addressRange:
222 if (!i2r_address(out, afi, 0x00, aor->u.addressRange->min))
223 return 0;
224 BIO_puts(out, "-");
225 if (!i2r_address(out, afi, 0xFF, aor->u.addressRange->max))
226 return 0;
227 BIO_puts(out, "\n");
228 continue;
229 }
230 }
231 return 1;
232}
233
234/*
235 * i2r handler for an IPAddrBlocks extension.
236 */
237static int i2r_IPAddrBlocks(X509V3_EXT_METHOD *method,
238 void *ext,
239 BIO *out,
240 int indent)
241{
242 const IPAddrBlocks *addr = ext;
243 int i;
244 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
245 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
246 const unsigned afi = v3_addr_get_afi(f);
247 switch (afi) {
248 case IANA_AFI_IPV4:
249 BIO_printf(out, "%*sIPv4", indent, "");
250 break;
251 case IANA_AFI_IPV6:
252 BIO_printf(out, "%*sIPv6", indent, "");
253 break;
254 default:
255 BIO_printf(out, "%*sUnknown AFI %u", indent, "", afi);
256 break;
257 }
258 if (f->addressFamily->length > 2) {
259 switch (f->addressFamily->data[2]) {
260 case 1:
261 BIO_puts(out, " (Unicast)");
262 break;
263 case 2:
264 BIO_puts(out, " (Multicast)");
265 break;
266 case 3:
267 BIO_puts(out, " (Unicast/Multicast)");
268 break;
269 case 4:
270 BIO_puts(out, " (MPLS)");
271 break;
272 case 64:
273 BIO_puts(out, " (Tunnel)");
274 break;
275 case 65:
276 BIO_puts(out, " (VPLS)");
277 break;
278 case 66:
279 BIO_puts(out, " (BGP MDT)");
280 break;
281 case 128:
282 BIO_puts(out, " (MPLS-labeled VPN)");
283 break;
284 default:
285 BIO_printf(out, " (Unknown SAFI %u)",
286 (unsigned) f->addressFamily->data[2]);
287 break;
288 }
289 }
290 switch (f->ipAddressChoice->type) {
291 case IPAddressChoice_inherit:
292 BIO_puts(out, ": inherit\n");
293 break;
294 case IPAddressChoice_addressesOrRanges:
295 BIO_puts(out, ":\n");
296 if (!i2r_IPAddressOrRanges(out,
297 indent + 2,
298 f->ipAddressChoice->u.addressesOrRanges,
299 afi))
300 return 0;
301 break;
302 }
303 }
304 return 1;
305}
306
307/*
308 * Sort comparison function for a sequence of IPAddressOrRange
309 * elements.
310 */
311static int IPAddressOrRange_cmp(const IPAddressOrRange *a,
312 const IPAddressOrRange *b,
313 const int length)
314{
315 unsigned char addr_a[ADDR_RAW_BUF_LEN], addr_b[ADDR_RAW_BUF_LEN];
316 int prefixlen_a = 0;
317 int prefixlen_b = 0;
318 int r;
319
320 switch (a->type) {
321 case IPAddressOrRange_addressPrefix:
322 addr_expand(addr_a, a->u.addressPrefix, length, 0x00);
323 prefixlen_a = addr_prefixlen(a->u.addressPrefix);
324 break;
325 case IPAddressOrRange_addressRange:
326 addr_expand(addr_a, a->u.addressRange->min, length, 0x00);
327 prefixlen_a = length * 8;
328 break;
329 }
330
331 switch (b->type) {
332 case IPAddressOrRange_addressPrefix:
333 addr_expand(addr_b, b->u.addressPrefix, length, 0x00);
334 prefixlen_b = addr_prefixlen(b->u.addressPrefix);
335 break;
336 case IPAddressOrRange_addressRange:
337 addr_expand(addr_b, b->u.addressRange->min, length, 0x00);
338 prefixlen_b = length * 8;
339 break;
340 }
341
342 if ((r = memcmp(addr_a, addr_b, length)) != 0)
343 return r;
344 else
345 return prefixlen_a - prefixlen_b;
346}
347
348/*
349 * IPv4-specific closure over IPAddressOrRange_cmp, since sk_sort()
350 * comparision routines are only allowed two arguments.
351 */
352static int v4IPAddressOrRange_cmp(const IPAddressOrRange * const *a,
353 const IPAddressOrRange * const *b)
354{
355 return IPAddressOrRange_cmp(*a, *b, 4);
356}
357
358/*
359 * IPv6-specific closure over IPAddressOrRange_cmp, since sk_sort()
360 * comparision routines are only allowed two arguments.
361 */
362static int v6IPAddressOrRange_cmp(const IPAddressOrRange * const *a,
363 const IPAddressOrRange * const *b)
364{
365 return IPAddressOrRange_cmp(*a, *b, 16);
366}
367
368/*
369 * Calculate whether a range collapses to a prefix.
370 * See last paragraph of RFC 3779 2.2.3.7.
371 */
372static int range_should_be_prefix(const unsigned char *min,
373 const unsigned char *max,
374 const int length)
375{
376 unsigned char mask;
377 int i, j;
378
379 for (i = 0; i < length && min[i] == max[i]; i++)
380 ;
381 for (j = length - 1; j >= 0 && min[j] == 0x00 && max[j] == 0xFF; j--)
382 ;
383 if (i < j)
384 return -1;
385 if (i > j)
386 return i * 8;
387 mask = min[i] ^ max[i];
388 switch (mask) {
389 case 0x01: j = 7; break;
390 case 0x03: j = 6; break;
391 case 0x07: j = 5; break;
392 case 0x0F: j = 4; break;
393 case 0x1F: j = 3; break;
394 case 0x3F: j = 2; break;
395 case 0x7F: j = 1; break;
396 default: return -1;
397 }
398 if ((min[i] & mask) != 0 || (max[i] & mask) != mask)
399 return -1;
400 else
401 return i * 8 + j;
402}
403
404/*
405 * Construct a prefix.
406 */
407static int make_addressPrefix(IPAddressOrRange **result,
408 unsigned char *addr,
409 const int prefixlen)
410{
411 int bytelen = (prefixlen + 7) / 8, bitlen = prefixlen % 8;
412 IPAddressOrRange *aor = IPAddressOrRange_new();
413
414 if (aor == NULL)
415 return 0;
416 aor->type = IPAddressOrRange_addressPrefix;
417 if (aor->u.addressPrefix == NULL &&
418 (aor->u.addressPrefix = ASN1_BIT_STRING_new()) == NULL)
419 goto err;
420 if (!ASN1_BIT_STRING_set(aor->u.addressPrefix, addr, bytelen))
421 goto err;
422 aor->u.addressPrefix->flags &= ~7;
423 aor->u.addressPrefix->flags |= ASN1_STRING_FLAG_BITS_LEFT;
424 if (bitlen > 0) {
425 aor->u.addressPrefix->data[bytelen - 1] &= ~(0xFF >> bitlen);
426 aor->u.addressPrefix->flags |= 8 - bitlen;
427 }
428
429 *result = aor;
430 return 1;
431
432 err:
433 IPAddressOrRange_free(aor);
434 return 0;
435}
436
437/*
438 * Construct a range. If it can be expressed as a prefix,
439 * return a prefix instead. Doing this here simplifies
440 * the rest of the code considerably.
441 */
442static int make_addressRange(IPAddressOrRange **result,
443 unsigned char *min,
444 unsigned char *max,
445 const int length)
446{
447 IPAddressOrRange *aor;
448 int i, prefixlen;
449
450 if ((prefixlen = range_should_be_prefix(min, max, length)) >= 0)
451 return make_addressPrefix(result, min, prefixlen);
452
453 if ((aor = IPAddressOrRange_new()) == NULL)
454 return 0;
455 aor->type = IPAddressOrRange_addressRange;
456 assert(aor->u.addressRange == NULL);
457 if ((aor->u.addressRange = IPAddressRange_new()) == NULL)
458 goto err;
459 if (aor->u.addressRange->min == NULL &&
460 (aor->u.addressRange->min = ASN1_BIT_STRING_new()) == NULL)
461 goto err;
462 if (aor->u.addressRange->max == NULL &&
463 (aor->u.addressRange->max = ASN1_BIT_STRING_new()) == NULL)
464 goto err;
465
466 for (i = length; i > 0 && min[i - 1] == 0x00; --i)
467 ;
468 if (!ASN1_BIT_STRING_set(aor->u.addressRange->min, min, i))
469 goto err;
470 aor->u.addressRange->min->flags &= ~7;
471 aor->u.addressRange->min->flags |= ASN1_STRING_FLAG_BITS_LEFT;
472 if (i > 0) {
473 unsigned char b = min[i - 1];
474 int j = 1;
475 while ((b & (0xFFU >> j)) != 0)
476 ++j;
477 aor->u.addressRange->min->flags |= 8 - j;
478 }
479
480 for (i = length; i > 0 && max[i - 1] == 0xFF; --i)
481 ;
482 if (!ASN1_BIT_STRING_set(aor->u.addressRange->max, max, i))
483 goto err;
484 aor->u.addressRange->max->flags &= ~7;
485 aor->u.addressRange->max->flags |= ASN1_STRING_FLAG_BITS_LEFT;
486 if (i > 0) {
487 unsigned char b = max[i - 1];
488 int j = 1;
489 while ((b & (0xFFU >> j)) != (0xFFU >> j))
490 ++j;
491 aor->u.addressRange->max->flags |= 8 - j;
492 }
493
494 *result = aor;
495 return 1;
496
497 err:
498 IPAddressOrRange_free(aor);
499 return 0;
500}
501
502/*
503 * Construct a new address family or find an existing one.
504 */
505static IPAddressFamily *make_IPAddressFamily(IPAddrBlocks *addr,
506 const unsigned afi,
507 const unsigned *safi)
508{
509 IPAddressFamily *f;
510 unsigned char key[3];
511 unsigned keylen;
512 int i;
513
514 key[0] = (afi >> 8) & 0xFF;
515 key[1] = afi & 0xFF;
516 if (safi != NULL) {
517 key[2] = *safi & 0xFF;
518 keylen = 3;
519 } else {
520 keylen = 2;
521 }
522
523 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
524 f = sk_IPAddressFamily_value(addr, i);
525 assert(f->addressFamily->data != NULL);
526 if (f->addressFamily->length == keylen &&
527 !memcmp(f->addressFamily->data, key, keylen))
528 return f;
529 }
530
531 if ((f = IPAddressFamily_new()) == NULL)
532 goto err;
533 if (f->ipAddressChoice == NULL &&
534 (f->ipAddressChoice = IPAddressChoice_new()) == NULL)
535 goto err;
536 if (f->addressFamily == NULL &&
537 (f->addressFamily = ASN1_OCTET_STRING_new()) == NULL)
538 goto err;
539 if (!ASN1_OCTET_STRING_set(f->addressFamily, key, keylen))
540 goto err;
541 if (!sk_IPAddressFamily_push(addr, f))
542 goto err;
543
544 return f;
545
546 err:
547 IPAddressFamily_free(f);
548 return NULL;
549}
550
551/*
552 * Add an inheritance element.
553 */
554int v3_addr_add_inherit(IPAddrBlocks *addr,
555 const unsigned afi,
556 const unsigned *safi)
557{
558 IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi);
559 if (f == NULL ||
560 f->ipAddressChoice == NULL ||
561 (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges &&
562 f->ipAddressChoice->u.addressesOrRanges != NULL))
563 return 0;
564 if (f->ipAddressChoice->type == IPAddressChoice_inherit &&
565 f->ipAddressChoice->u.inherit != NULL)
566 return 1;
567 if (f->ipAddressChoice->u.inherit == NULL &&
568 (f->ipAddressChoice->u.inherit = ASN1_NULL_new()) == NULL)
569 return 0;
570 f->ipAddressChoice->type = IPAddressChoice_inherit;
571 return 1;
572}
573
574/*
575 * Construct an IPAddressOrRange sequence, or return an existing one.
576 */
577static IPAddressOrRanges *make_prefix_or_range(IPAddrBlocks *addr,
578 const unsigned afi,
579 const unsigned *safi)
580{
581 IPAddressFamily *f = make_IPAddressFamily(addr, afi, safi);
582 IPAddressOrRanges *aors = NULL;
583
584 if (f == NULL ||
585 f->ipAddressChoice == NULL ||
586 (f->ipAddressChoice->type == IPAddressChoice_inherit &&
587 f->ipAddressChoice->u.inherit != NULL))
588 return NULL;
589 if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges)
590 aors = f->ipAddressChoice->u.addressesOrRanges;
591 if (aors != NULL)
592 return aors;
593 if ((aors = sk_IPAddressOrRange_new_null()) == NULL)
594 return NULL;
595 switch (afi) {
596 case IANA_AFI_IPV4:
597 sk_IPAddressOrRange_set_cmp_func(aors, v4IPAddressOrRange_cmp);
598 break;
599 case IANA_AFI_IPV6:
600 sk_IPAddressOrRange_set_cmp_func(aors, v6IPAddressOrRange_cmp);
601 break;
602 }
603 f->ipAddressChoice->type = IPAddressChoice_addressesOrRanges;
604 f->ipAddressChoice->u.addressesOrRanges = aors;
605 return aors;
606}
607
608/*
609 * Add a prefix.
610 */
611int v3_addr_add_prefix(IPAddrBlocks *addr,
612 const unsigned afi,
613 const unsigned *safi,
614 unsigned char *a,
615 const int prefixlen)
616{
617 IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi);
618 IPAddressOrRange *aor;
619 if (aors == NULL || !make_addressPrefix(&aor, a, prefixlen))
620 return 0;
621 if (sk_IPAddressOrRange_push(aors, aor))
622 return 1;
623 IPAddressOrRange_free(aor);
624 return 0;
625}
626
627/*
628 * Add a range.
629 */
630int v3_addr_add_range(IPAddrBlocks *addr,
631 const unsigned afi,
632 const unsigned *safi,
633 unsigned char *min,
634 unsigned char *max)
635{
636 IPAddressOrRanges *aors = make_prefix_or_range(addr, afi, safi);
637 IPAddressOrRange *aor;
638 int length = length_from_afi(afi);
639 if (aors == NULL)
640 return 0;
641 if (!make_addressRange(&aor, min, max, length))
642 return 0;
643 if (sk_IPAddressOrRange_push(aors, aor))
644 return 1;
645 IPAddressOrRange_free(aor);
646 return 0;
647}
648
649/*
650 * Extract min and max values from an IPAddressOrRange.
651 */
652static void extract_min_max(IPAddressOrRange *aor,
653 unsigned char *min,
654 unsigned char *max,
655 int length)
656{
657 assert(aor != NULL && min != NULL && max != NULL);
658 switch (aor->type) {
659 case IPAddressOrRange_addressPrefix:
660 addr_expand(min, aor->u.addressPrefix, length, 0x00);
661 addr_expand(max, aor->u.addressPrefix, length, 0xFF);
662 return;
663 case IPAddressOrRange_addressRange:
664 addr_expand(min, aor->u.addressRange->min, length, 0x00);
665 addr_expand(max, aor->u.addressRange->max, length, 0xFF);
666 return;
667 }
668}
669
670/*
671 * Public wrapper for extract_min_max().
672 */
673int v3_addr_get_range(IPAddressOrRange *aor,
674 const unsigned afi,
675 unsigned char *min,
676 unsigned char *max,
677 const int length)
678{
679 int afi_length = length_from_afi(afi);
680 if (aor == NULL || min == NULL || max == NULL ||
681 afi_length == 0 || length < afi_length ||
682 (aor->type != IPAddressOrRange_addressPrefix &&
683 aor->type != IPAddressOrRange_addressRange))
684 return 0;
685 extract_min_max(aor, min, max, afi_length);
686 return afi_length;
687}
688
689/*
690 * Sort comparision function for a sequence of IPAddressFamily.
691 *
692 * The last paragraph of RFC 3779 2.2.3.3 is slightly ambiguous about
693 * the ordering: I can read it as meaning that IPv6 without a SAFI
694 * comes before IPv4 with a SAFI, which seems pretty weird. The
695 * examples in appendix B suggest that the author intended the
696 * null-SAFI rule to apply only within a single AFI, which is what I
697 * would have expected and is what the following code implements.
698 */
699static int IPAddressFamily_cmp(const IPAddressFamily * const *a_,
700 const IPAddressFamily * const *b_)
701{
702 const ASN1_OCTET_STRING *a = (*a_)->addressFamily;
703 const ASN1_OCTET_STRING *b = (*b_)->addressFamily;
704 int len = ((a->length <= b->length) ? a->length : b->length);
705 int cmp = memcmp(a->data, b->data, len);
706 return cmp ? cmp : a->length - b->length;
707}
708
709/*
710 * Check whether an IPAddrBLocks is in canonical form.
711 */
712int v3_addr_is_canonical(IPAddrBlocks *addr)
713{
714 unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
715 unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN];
716 IPAddressOrRanges *aors;
717 int i, j, k;
718
719 /*
720 * Empty extension is cannonical.
721 */
722 if (addr == NULL)
723 return 1;
724
725 /*
726 * Check whether the top-level list is in order.
727 */
728 for (i = 0; i < sk_IPAddressFamily_num(addr) - 1; i++) {
729 const IPAddressFamily *a = sk_IPAddressFamily_value(addr, i);
730 const IPAddressFamily *b = sk_IPAddressFamily_value(addr, i + 1);
731 if (IPAddressFamily_cmp(&a, &b) >= 0)
732 return 0;
733 }
734
735 /*
736 * Top level's ok, now check each address family.
737 */
738 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
739 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
740 int length = length_from_afi(v3_addr_get_afi(f));
741
742 /*
743 * Inheritance is canonical. Anything other than inheritance or
744 * a SEQUENCE OF IPAddressOrRange is an ASN.1 error or something.
745 */
746 if (f == NULL || f->ipAddressChoice == NULL)
747 return 0;
748 switch (f->ipAddressChoice->type) {
749 case IPAddressChoice_inherit:
750 continue;
751 case IPAddressChoice_addressesOrRanges:
752 break;
753 default:
754 return 0;
755 }
756
757 /*
758 * It's an IPAddressOrRanges sequence, check it.
759 */
760 aors = f->ipAddressChoice->u.addressesOrRanges;
761 if (sk_IPAddressOrRange_num(aors) == 0)
762 return 0;
763 for (j = 0; j < sk_IPAddressOrRange_num(aors) - 1; j++) {
764 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
765 IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, j + 1);
766
767 extract_min_max(a, a_min, a_max, length);
768 extract_min_max(b, b_min, b_max, length);
769
770 /*
771 * Punt misordered list, overlapping start, or inverted range.
772 */
773 if (memcmp(a_min, b_min, length) >= 0 ||
774 memcmp(a_min, a_max, length) > 0 ||
775 memcmp(b_min, b_max, length) > 0)
776 return 0;
777
778 /*
779 * Punt if adjacent or overlapping. Check for adjacency by
780 * subtracting one from b_min first.
781 */
782 for (k = length - 1; k >= 0 && b_min[k]-- == 0x00; k--)
783 ;
784 if (memcmp(a_max, b_min, length) >= 0)
785 return 0;
786
787 /*
788 * Check for range that should be expressed as a prefix.
789 */
790 if (a->type == IPAddressOrRange_addressRange &&
791 range_should_be_prefix(a_min, a_max, length) >= 0)
792 return 0;
793 }
794
795 /*
796 * Check final range to see if it should be a prefix.
797 */
798 j = sk_IPAddressOrRange_num(aors) - 1;
799 {
800 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, j);
801 if (a->type == IPAddressOrRange_addressRange) {
802 extract_min_max(a, a_min, a_max, length);
803 if (range_should_be_prefix(a_min, a_max, length) >= 0)
804 return 0;
805 }
806 }
807 }
808
809 /*
810 * If we made it through all that, we're happy.
811 */
812 return 1;
813}
814
815/*
816 * Whack an IPAddressOrRanges into canonical form.
817 */
818static int IPAddressOrRanges_canonize(IPAddressOrRanges *aors,
819 const unsigned afi)
820{
821 int i, j, length = length_from_afi(afi);
822
823 /*
824 * Sort the IPAddressOrRanges sequence.
825 */
826 sk_IPAddressOrRange_sort(aors);
827
828 /*
829 * Clean up representation issues, punt on duplicates or overlaps.
830 */
831 for (i = 0; i < sk_IPAddressOrRange_num(aors) - 1; i++) {
832 IPAddressOrRange *a = sk_IPAddressOrRange_value(aors, i);
833 IPAddressOrRange *b = sk_IPAddressOrRange_value(aors, i + 1);
834 unsigned char a_min[ADDR_RAW_BUF_LEN], a_max[ADDR_RAW_BUF_LEN];
835 unsigned char b_min[ADDR_RAW_BUF_LEN], b_max[ADDR_RAW_BUF_LEN];
836
837 extract_min_max(a, a_min, a_max, length);
838 extract_min_max(b, b_min, b_max, length);
839
840 /*
841 * Punt overlaps.
842 */
843 if (memcmp(a_max, b_min, length) >= 0)
844 return 0;
845
846 /*
847 * Merge if a and b are adjacent. We check for
848 * adjacency by subtracting one from b_min first.
849 */
850 for (j = length - 1; j >= 0 && b_min[j]-- == 0x00; j--)
851 ;
852 if (memcmp(a_max, b_min, length) == 0) {
853 IPAddressOrRange *merged;
854 if (!make_addressRange(&merged, a_min, b_max, length))
855 return 0;
856 sk_IPAddressOrRange_set(aors, i, merged);
857 sk_IPAddressOrRange_delete(aors, i + 1);
858 IPAddressOrRange_free(a);
859 IPAddressOrRange_free(b);
860 --i;
861 continue;
862 }
863 }
864
865 return 1;
866}
867
868/*
869 * Whack an IPAddrBlocks extension into canonical form.
870 */
871int v3_addr_canonize(IPAddrBlocks *addr)
872{
873 int i;
874 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
875 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
876 if (f->ipAddressChoice->type == IPAddressChoice_addressesOrRanges &&
877 !IPAddressOrRanges_canonize(f->ipAddressChoice->u.addressesOrRanges,
878 v3_addr_get_afi(f)))
879 return 0;
880 }
881 sk_IPAddressFamily_sort(addr);
882 assert(v3_addr_is_canonical(addr));
883 return 1;
884}
885
886/*
887 * v2i handler for the IPAddrBlocks extension.
888 */
889static void *v2i_IPAddrBlocks(struct v3_ext_method *method,
890 struct v3_ext_ctx *ctx,
891 STACK_OF(CONF_VALUE) *values)
892{
893 static const char v4addr_chars[] = "0123456789.";
894 static const char v6addr_chars[] = "0123456789.:abcdefABCDEF";
895 IPAddrBlocks *addr = NULL;
896 char *s = NULL, *t;
897 int i;
898
899 if ((addr = sk_IPAddressFamily_new(IPAddressFamily_cmp)) == NULL) {
900 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
901 return NULL;
902 }
903
904 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
905 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
906 unsigned char min[ADDR_RAW_BUF_LEN], max[ADDR_RAW_BUF_LEN];
907 unsigned afi, *safi = NULL, safi_;
908 const char *addr_chars;
909 int prefixlen, i1, i2, delim, length;
910
911 if ( !name_cmp(val->name, "IPv4")) {
912 afi = IANA_AFI_IPV4;
913 } else if (!name_cmp(val->name, "IPv6")) {
914 afi = IANA_AFI_IPV6;
915 } else if (!name_cmp(val->name, "IPv4-SAFI")) {
916 afi = IANA_AFI_IPV4;
917 safi = &safi_;
918 } else if (!name_cmp(val->name, "IPv6-SAFI")) {
919 afi = IANA_AFI_IPV6;
920 safi = &safi_;
921 } else {
922 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_NAME_ERROR);
923 X509V3_conf_err(val);
924 goto err;
925 }
926
927 switch (afi) {
928 case IANA_AFI_IPV4:
929 addr_chars = v4addr_chars;
930 break;
931 case IANA_AFI_IPV6:
932 addr_chars = v6addr_chars;
933 break;
934 }
935
936 length = length_from_afi(afi);
937
938 /*
939 * Handle SAFI, if any, and BUF_strdup() so we can null-terminate
940 * the other input values.
941 */
942 if (safi != NULL) {
943 *safi = strtoul(val->value, &t, 0);
944 t += strspn(t, " \t");
945 if (*safi > 0xFF || *t++ != ':') {
946 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_SAFI);
947 X509V3_conf_err(val);
948 goto err;
949 }
950 t += strspn(t, " \t");
951 s = BUF_strdup(t);
952 } else {
953 s = BUF_strdup(val->value);
954 }
955 if (s == NULL) {
956 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
957 goto err;
958 }
959
960 /*
961 * Check for inheritance. Not worth additional complexity to
962 * optimize this (seldom-used) case.
963 */
964 if (!strcmp(s, "inherit")) {
965 if (!v3_addr_add_inherit(addr, afi, safi)) {
966 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_INHERITANCE);
967 X509V3_conf_err(val);
968 goto err;
969 }
970 OPENSSL_free(s);
971 s = NULL;
972 continue;
973 }
974
975 i1 = strspn(s, addr_chars);
976 i2 = i1 + strspn(s + i1, " \t");
977 delim = s[i2++];
978 s[i1] = '\0';
979
980 if (a2i_ipadd(min, s) != length) {
981 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
982 X509V3_conf_err(val);
983 goto err;
984 }
985
986 switch (delim) {
987 case '/':
988 prefixlen = (int) strtoul(s + i2, &t, 10);
989 if (t == s + i2 || *t != '\0') {
990 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
991 X509V3_conf_err(val);
992 goto err;
993 }
994 if (!v3_addr_add_prefix(addr, afi, safi, min, prefixlen)) {
995 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
996 goto err;
997 }
998 break;
999 case '-':
1000 i1 = i2 + strspn(s + i2, " \t");
1001 i2 = i1 + strspn(s + i1, addr_chars);
1002 if (i1 == i2 || s[i2] != '\0') {
1003 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
1004 X509V3_conf_err(val);
1005 goto err;
1006 }
1007 if (a2i_ipadd(max, s + i1) != length) {
1008 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_INVALID_IPADDRESS);
1009 X509V3_conf_err(val);
1010 goto err;
1011 }
1012 if (!v3_addr_add_range(addr, afi, safi, min, max)) {
1013 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
1014 goto err;
1015 }
1016 break;
1017 case '\0':
1018 if (!v3_addr_add_prefix(addr, afi, safi, min, length * 8)) {
1019 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, ERR_R_MALLOC_FAILURE);
1020 goto err;
1021 }
1022 break;
1023 default:
1024 X509V3err(X509V3_F_V2I_IPADDRBLOCKS, X509V3_R_EXTENSION_VALUE_ERROR);
1025 X509V3_conf_err(val);
1026 goto err;
1027 }
1028
1029 OPENSSL_free(s);
1030 s = NULL;
1031 }
1032
1033 /*
1034 * Canonize the result, then we're done.
1035 */
1036 if (!v3_addr_canonize(addr))
1037 goto err;
1038 return addr;
1039
1040 err:
1041 OPENSSL_free(s);
1042 sk_IPAddressFamily_pop_free(addr, IPAddressFamily_free);
1043 return NULL;
1044}
1045
1046/*
1047 * OpenSSL dispatch
1048 */
1049const X509V3_EXT_METHOD v3_addr = {
1050 NID_sbgp_ipAddrBlock, /* nid */
1051 0, /* flags */
1052 ASN1_ITEM_ref(IPAddrBlocks), /* template */
1053 0, 0, 0, 0, /* old functions, ignored */
1054 0, /* i2s */
1055 0, /* s2i */
1056 0, /* i2v */
1057 v2i_IPAddrBlocks, /* v2i */
1058 i2r_IPAddrBlocks, /* i2r */
1059 0, /* r2i */
1060 NULL /* extension-specific data */
1061};
1062
1063/*
1064 * Figure out whether extension sues inheritance.
1065 */
1066int v3_addr_inherits(IPAddrBlocks *addr)
1067{
1068 int i;
1069 if (addr == NULL)
1070 return 0;
1071 for (i = 0; i < sk_IPAddressFamily_num(addr); i++) {
1072 IPAddressFamily *f = sk_IPAddressFamily_value(addr, i);
1073 if (f->ipAddressChoice->type == IPAddressChoice_inherit)
1074 return 1;
1075 }
1076 return 0;
1077}
1078
1079/*
1080 * Figure out whether parent contains child.
1081 */
1082static int addr_contains(IPAddressOrRanges *parent,
1083 IPAddressOrRanges *child,
1084 int length)
1085{
1086 unsigned char p_min[ADDR_RAW_BUF_LEN], p_max[ADDR_RAW_BUF_LEN];
1087 unsigned char c_min[ADDR_RAW_BUF_LEN], c_max[ADDR_RAW_BUF_LEN];
1088 int p, c;
1089
1090 if (child == NULL || parent == child)
1091 return 1;
1092 if (parent == NULL)
1093 return 0;
1094
1095 p = 0;
1096 for (c = 0; c < sk_IPAddressOrRange_num(child); c++) {
1097 extract_min_max(sk_IPAddressOrRange_value(child, c),
1098 c_min, c_max, length);
1099 for (;; p++) {
1100 if (p >= sk_IPAddressOrRange_num(parent))
1101 return 0;
1102 extract_min_max(sk_IPAddressOrRange_value(parent, p),
1103 p_min, p_max, length);
1104 if (memcmp(p_max, c_max, length) < 0)
1105 continue;
1106 if (memcmp(p_min, c_min, length) > 0)
1107 return 0;
1108 break;
1109 }
1110 }
1111
1112 return 1;
1113}
1114
1115/*
1116 * Test whether a is a subset of b.
1117 */
1118int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b)
1119{
1120 int i;
1121 if (a == NULL || a == b)
1122 return 1;
1123 if (b == NULL || v3_addr_inherits(a) || v3_addr_inherits(b))
1124 return 0;
1125 sk_IPAddressFamily_set_cmp_func(b, IPAddressFamily_cmp);
1126 for (i = 0; i < sk_IPAddressFamily_num(a); i++) {
1127 IPAddressFamily *fa = sk_IPAddressFamily_value(a, i);
1128 int j = sk_IPAddressFamily_find(b, fa);
1129 IPAddressFamily *fb = sk_IPAddressFamily_value(b, j);
1130 if (!addr_contains(fb->ipAddressChoice->u.addressesOrRanges,
1131 fa->ipAddressChoice->u.addressesOrRanges,
1132 length_from_afi(v3_addr_get_afi(fb))))
1133 return 0;
1134 }
1135 return 1;
1136}
1137
1138/*
1139 * Validation error handling via callback.
1140 */
1141#define validation_err(_err_) \
1142 do { \
1143 if (ctx != NULL) { \
1144 ctx->error = _err_; \
1145 ctx->error_depth = i; \
1146 ctx->current_cert = x; \
1147 ret = ctx->verify_cb(0, ctx); \
1148 } else { \
1149 ret = 0; \
1150 } \
1151 if (!ret) \
1152 goto done; \
1153 } while (0)
1154
1155/*
1156 * Core code for RFC 3779 2.3 path validation.
1157 */
1158static int v3_addr_validate_path_internal(X509_STORE_CTX *ctx,
1159 STACK_OF(X509) *chain,
1160 IPAddrBlocks *ext)
1161{
1162 IPAddrBlocks *child = NULL;
1163 int i, j, ret = 1;
1164 X509 *x = NULL;
1165
1166 assert(chain != NULL && sk_X509_num(chain) > 0);
1167 assert(ctx != NULL || ext != NULL);
1168 assert(ctx == NULL || ctx->verify_cb != NULL);
1169
1170 /*
1171 * Figure out where to start. If we don't have an extension to
1172 * check, we're done. Otherwise, check canonical form and
1173 * set up for walking up the chain.
1174 */
1175 if (ext != NULL) {
1176 i = -1;
1177 } else {
1178 i = 0;
1179 x = sk_X509_value(chain, i);
1180 assert(x != NULL);
1181 if ((ext = x->rfc3779_addr) == NULL)
1182 goto done;
1183 }
1184 if (!v3_addr_is_canonical(ext))
1185 validation_err(X509_V_ERR_INVALID_EXTENSION);
1186 sk_IPAddressFamily_set_cmp_func(ext, IPAddressFamily_cmp);
1187 if ((child = sk_IPAddressFamily_dup(ext)) == NULL) {
1188 X509V3err(X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL, ERR_R_MALLOC_FAILURE);
1189 ret = 0;
1190 goto done;
1191 }
1192
1193 /*
1194 * Now walk up the chain. No cert may list resources that its
1195 * parent doesn't list.
1196 */
1197 for (i++; i < sk_X509_num(chain); i++) {
1198 x = sk_X509_value(chain, i);
1199 assert(x != NULL);
1200 if (!v3_addr_is_canonical(x->rfc3779_addr))
1201 validation_err(X509_V_ERR_INVALID_EXTENSION);
1202 if (x->rfc3779_addr == NULL) {
1203 for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
1204 IPAddressFamily *fc = sk_IPAddressFamily_value(child, j);
1205 if (fc->ipAddressChoice->type != IPAddressChoice_inherit) {
1206 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1207 break;
1208 }
1209 }
1210 continue;
1211 }
1212 sk_IPAddressFamily_set_cmp_func(x->rfc3779_addr, IPAddressFamily_cmp);
1213 for (j = 0; j < sk_IPAddressFamily_num(child); j++) {
1214 IPAddressFamily *fc = sk_IPAddressFamily_value(child, j);
1215 int k = sk_IPAddressFamily_find(x->rfc3779_addr, fc);
1216 IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, k);
1217 if (fp == NULL) {
1218 if (fc->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) {
1219 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1220 break;
1221 }
1222 continue;
1223 }
1224 if (fp->ipAddressChoice->type == IPAddressChoice_addressesOrRanges) {
1225 if (fc->ipAddressChoice->type == IPAddressChoice_inherit ||
1226 addr_contains(fp->ipAddressChoice->u.addressesOrRanges,
1227 fc->ipAddressChoice->u.addressesOrRanges,
1228 length_from_afi(v3_addr_get_afi(fc))))
1229 sk_IPAddressFamily_set(child, j, fp);
1230 else
1231 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1232 }
1233 }
1234 }
1235
1236 /*
1237 * Trust anchor can't inherit.
1238 */
1239 if (x->rfc3779_addr != NULL) {
1240 for (j = 0; j < sk_IPAddressFamily_num(x->rfc3779_addr); j++) {
1241 IPAddressFamily *fp = sk_IPAddressFamily_value(x->rfc3779_addr, j);
1242 if (fp->ipAddressChoice->type == IPAddressChoice_inherit &&
1243 sk_IPAddressFamily_find(child, fp) >= 0)
1244 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
1245 }
1246 }
1247
1248 done:
1249 sk_IPAddressFamily_free(child);
1250 return ret;
1251}
1252
1253#undef validation_err
1254
1255/*
1256 * RFC 3779 2.3 path validation -- called from X509_verify_cert().
1257 */
1258int v3_addr_validate_path(X509_STORE_CTX *ctx)
1259{
1260 return v3_addr_validate_path_internal(ctx, ctx->chain, NULL);
1261}
1262
1263/*
1264 * RFC 3779 2.3 path validation of an extension.
1265 * Test whether chain covers extension.
1266 */
1267int v3_addr_validate_resource_set(STACK_OF(X509) *chain,
1268 IPAddrBlocks *ext,
1269 int allow_inheritance)
1270{
1271 if (ext == NULL)
1272 return 1;
1273 if (chain == NULL || sk_X509_num(chain) == 0)
1274 return 0;
1275 if (!allow_inheritance && v3_addr_inherits(ext))
1276 return 0;
1277 return v3_addr_validate_path_internal(NULL, chain, ext);
1278}
1279
1280#endif /* OPENSSL_NO_RFC3779 */
diff --git a/src/lib/libcrypto/x509v3/v3_akey.c b/src/lib/libcrypto/x509v3/v3_akey.c
index ac0548b775..97e686f97a 100644
--- a/src/lib/libcrypto/x509v3/v3_akey.c
+++ b/src/lib/libcrypto/x509v3/v3_akey.c
@@ -68,17 +68,15 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, 68static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); 69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
70 70
71const X509V3_EXT_METHOD v3_akey_id = 71X509V3_EXT_METHOD v3_akey_id = {
72 { 72NID_authority_key_identifier, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID),
73 NID_authority_key_identifier, 730,0,0,0,
74 X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_KEYID), 740,0,
75 0,0,0,0, 75(X509V3_EXT_I2V)i2v_AUTHORITY_KEYID,
76 0,0, 76(X509V3_EXT_V2I)v2i_AUTHORITY_KEYID,
77 (X509V3_EXT_I2V)i2v_AUTHORITY_KEYID, 770,0,
78 (X509V3_EXT_V2I)v2i_AUTHORITY_KEYID, 78NULL
79 0,0, 79};
80 NULL
81 };
82 80
83static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, 81static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
84 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist) 82 AUTHORITY_KEYID *akeyid, STACK_OF(CONF_VALUE) *extlist)
@@ -110,99 +108,83 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
110 108
111static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method, 109static AUTHORITY_KEYID *v2i_AUTHORITY_KEYID(X509V3_EXT_METHOD *method,
112 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values) 110 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values)
113 { 111{
114 char keyid=0, issuer=0; 112char keyid=0, issuer=0;
115 int i; 113int i;
116 CONF_VALUE *cnf; 114CONF_VALUE *cnf;
117 ASN1_OCTET_STRING *ikeyid = NULL; 115ASN1_OCTET_STRING *ikeyid = NULL;
118 X509_NAME *isname = NULL; 116X509_NAME *isname = NULL;
119 GENERAL_NAMES * gens = NULL; 117GENERAL_NAMES * gens = NULL;
120 GENERAL_NAME *gen = NULL; 118GENERAL_NAME *gen = NULL;
121 ASN1_INTEGER *serial = NULL; 119ASN1_INTEGER *serial = NULL;
122 X509_EXTENSION *ext; 120X509_EXTENSION *ext;
123 X509 *cert; 121X509 *cert;
124 AUTHORITY_KEYID *akeyid; 122AUTHORITY_KEYID *akeyid;
125 123for(i = 0; i < sk_CONF_VALUE_num(values); i++) {
126 for(i = 0; i < sk_CONF_VALUE_num(values); i++) 124 cnf = sk_CONF_VALUE_value(values, i);
127 { 125 if(!strcmp(cnf->name, "keyid")) {
128 cnf = sk_CONF_VALUE_value(values, i); 126 keyid = 1;
129 if(!strcmp(cnf->name, "keyid")) 127 if(cnf->value && !strcmp(cnf->value, "always")) keyid = 2;
130 { 128 } else if(!strcmp(cnf->name, "issuer")) {
131 keyid = 1; 129 issuer = 1;
132 if(cnf->value && !strcmp(cnf->value, "always")) 130 if(cnf->value && !strcmp(cnf->value, "always")) issuer = 2;
133 keyid = 2; 131 } else {
134 } 132 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
135 else if(!strcmp(cnf->name, "issuer")) 133 ERR_add_error_data(2, "name=", cnf->name);
136 {
137 issuer = 1;
138 if(cnf->value && !strcmp(cnf->value, "always"))
139 issuer = 2;
140 }
141 else
142 {
143 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNKNOWN_OPTION);
144 ERR_add_error_data(2, "name=", cnf->name);
145 return NULL;
146 }
147 }
148
149 if(!ctx || !ctx->issuer_cert)
150 {
151 if(ctx && (ctx->flags==CTX_TEST))
152 return AUTHORITY_KEYID_new();
153 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
154 return NULL; 134 return NULL;
155 } 135 }
156 136}
157 cert = ctx->issuer_cert; 137
158 138if(!ctx || !ctx->issuer_cert) {
159 if(keyid) 139 if(ctx && (ctx->flags==CTX_TEST)) return AUTHORITY_KEYID_new();
160 { 140 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_NO_ISSUER_CERTIFICATE);
161 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
162 if((i >= 0) && (ext = X509_get_ext(cert, i)))
163 ikeyid = X509V3_EXT_d2i(ext);
164 if(keyid==2 && !ikeyid)
165 {
166 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
167 return NULL;
168 }
169 }
170
171 if((issuer && !ikeyid) || (issuer == 2))
172 {
173 isname = X509_NAME_dup(X509_get_issuer_name(cert));
174 serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
175 if(!isname || !serial)
176 {
177 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
178 goto err;
179 }
180 }
181
182 if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
183
184 if(isname)
185 {
186 if(!(gens = sk_GENERAL_NAME_new_null())
187 || !(gen = GENERAL_NAME_new())
188 || !sk_GENERAL_NAME_push(gens, gen))
189 {
190 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
191 goto err;
192 }
193 gen->type = GEN_DIRNAME;
194 gen->d.dirn = isname;
195 }
196
197 akeyid->issuer = gens;
198 akeyid->serial = serial;
199 akeyid->keyid = ikeyid;
200
201 return akeyid;
202
203 err:
204 X509_NAME_free(isname);
205 M_ASN1_INTEGER_free(serial);
206 M_ASN1_OCTET_STRING_free(ikeyid);
207 return NULL; 141 return NULL;
142}
143
144cert = ctx->issuer_cert;
145
146if(keyid) {
147 i = X509_get_ext_by_NID(cert, NID_subject_key_identifier, -1);
148 if((i >= 0) && (ext = X509_get_ext(cert, i)))
149 ikeyid = X509V3_EXT_d2i(ext);
150 if(keyid==2 && !ikeyid) {
151 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_KEYID);
152 return NULL;
153 }
154}
155
156if((issuer && !ikeyid) || (issuer == 2)) {
157 isname = X509_NAME_dup(X509_get_issuer_name(cert));
158 serial = M_ASN1_INTEGER_dup(X509_get_serialNumber(cert));
159 if(!isname || !serial) {
160 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS);
161 goto err;
208 } 162 }
163}
164
165if(!(akeyid = AUTHORITY_KEYID_new())) goto err;
166
167if(isname) {
168 if(!(gens = sk_GENERAL_NAME_new_null()) || !(gen = GENERAL_NAME_new())
169 || !sk_GENERAL_NAME_push(gens, gen)) {
170 X509V3err(X509V3_F_V2I_AUTHORITY_KEYID,ERR_R_MALLOC_FAILURE);
171 goto err;
172 }
173 gen->type = GEN_DIRNAME;
174 gen->d.dirn = isname;
175}
176
177akeyid->issuer = gens;
178akeyid->serial = serial;
179akeyid->keyid = ikeyid;
180
181return akeyid;
182
183err:
184X509_NAME_free(isname);
185M_ASN1_INTEGER_free(serial);
186M_ASN1_OCTET_STRING_free(ikeyid);
187return NULL;
188
189}
190
diff --git a/src/lib/libcrypto/x509v3/v3_alt.c b/src/lib/libcrypto/x509v3/v3_alt.c
index bb2f5bc54e..58b935a3b6 100644
--- a/src/lib/libcrypto/x509v3/v3_alt.c
+++ b/src/lib/libcrypto/x509v3/v3_alt.c
@@ -1,9 +1,9 @@
1/* v3_alt.c */ 1/* v3_alt.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -65,10 +65,7 @@ static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx
65static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 65static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p); 66static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p);
67static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens); 67static int copy_issuer(X509V3_CTX *ctx, GENERAL_NAMES *gens);
68static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx); 68X509V3_EXT_METHOD v3_alt[] = {
69static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx);
70
71const X509V3_EXT_METHOD v3_alt[] = {
72{ NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES), 69{ NID_subject_alt_name, 0, ASN1_ITEM_ref(GENERAL_NAMES),
730,0,0,0, 700,0,0,0,
740,0, 710,0,
@@ -101,8 +98,7 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
101 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret) 98 GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret)
102{ 99{
103 unsigned char *p; 100 unsigned char *p;
104 char oline[256], htmp[5]; 101 char oline[256];
105 int i;
106 switch (gen->type) 102 switch (gen->type)
107 { 103 {
108 case GEN_OTHERNAME: 104 case GEN_OTHERNAME:
@@ -136,27 +132,13 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
136 132
137 case GEN_IPADD: 133 case GEN_IPADD:
138 p = gen->d.ip->data; 134 p = gen->d.ip->data;
139 if(gen->d.ip->length == 4) 135 /* BUG: doesn't support IPV6 */
140 BIO_snprintf(oline, sizeof oline, 136 if(gen->d.ip->length != 4) {
141 "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
142 else if(gen->d.ip->length == 16)
143 {
144 oline[0] = 0;
145 for (i = 0; i < 8; i++)
146 {
147 BIO_snprintf(htmp, sizeof htmp,
148 "%X", p[0] << 8 | p[1]);
149 p += 2;
150 strcat(oline, htmp);
151 if (i != 7)
152 strcat(oline, ":");
153 }
154 }
155 else
156 {
157 X509V3_add_value("IP Address","<invalid>", &ret); 137 X509V3_add_value("IP Address","<invalid>", &ret);
158 break; 138 break;
159 } 139 }
140 BIO_snprintf(oline, sizeof oline,
141 "%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
160 X509V3_add_value("IP Address",oline, &ret); 142 X509V3_add_value("IP Address",oline, &ret);
161 break; 143 break;
162 144
@@ -171,7 +153,6 @@ STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method,
171int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen) 153int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
172{ 154{
173 unsigned char *p; 155 unsigned char *p;
174 int i;
175 switch (gen->type) 156 switch (gen->type)
176 { 157 {
177 case GEN_OTHERNAME: 158 case GEN_OTHERNAME:
@@ -206,24 +187,12 @@ int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen)
206 187
207 case GEN_IPADD: 188 case GEN_IPADD:
208 p = gen->d.ip->data; 189 p = gen->d.ip->data;
209 if(gen->d.ip->length == 4) 190 /* BUG: doesn't support IPV6 */
210 BIO_printf(out, "IP Address:%d.%d.%d.%d", 191 if(gen->d.ip->length != 4) {
211 p[0], p[1], p[2], p[3]);
212 else if(gen->d.ip->length == 16)
213 {
214 BIO_printf(out, "IP Address");
215 for (i = 0; i < 8; i++)
216 {
217 BIO_printf(out, ":%X", p[0] << 8 | p[1]);
218 p += 2;
219 }
220 BIO_puts(out, "\n");
221 }
222 else
223 {
224 BIO_printf(out,"IP Address:<invalid>"); 192 BIO_printf(out,"IP Address:<invalid>");
225 break; 193 break;
226 } 194 }
195 BIO_printf(out, "IP Address:%d.%d.%d.%d", p[0], p[1], p[2], p[3]);
227 break; 196 break;
228 197
229 case GEN_RID: 198 case GEN_RID:
@@ -241,7 +210,7 @@ static GENERAL_NAMES *v2i_issuer_alt(X509V3_EXT_METHOD *method,
241 CONF_VALUE *cnf; 210 CONF_VALUE *cnf;
242 int i; 211 int i;
243 if(!(gens = sk_GENERAL_NAME_new_null())) { 212 if(!(gens = sk_GENERAL_NAME_new_null())) {
244 X509V3err(X509V3_F_V2I_ISSUER_ALT,ERR_R_MALLOC_FAILURE); 213 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
245 return NULL; 214 return NULL;
246 } 215 }
247 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { 216 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -306,7 +275,7 @@ static GENERAL_NAMES *v2i_subject_alt(X509V3_EXT_METHOD *method,
306 CONF_VALUE *cnf; 275 CONF_VALUE *cnf;
307 int i; 276 int i;
308 if(!(gens = sk_GENERAL_NAME_new_null())) { 277 if(!(gens = sk_GENERAL_NAME_new_null())) {
309 X509V3err(X509V3_F_V2I_SUBJECT_ALT,ERR_R_MALLOC_FAILURE); 278 X509V3err(X509V3_F_V2I_GENERAL_NAMES,ERR_R_MALLOC_FAILURE);
310 return NULL; 279 return NULL;
311 } 280 }
312 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { 281 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
@@ -341,8 +310,7 @@ static int copy_email(X509V3_CTX *ctx, GENERAL_NAMES *gens, int move_p)
341 X509_NAME_ENTRY *ne; 310 X509_NAME_ENTRY *ne;
342 GENERAL_NAME *gen = NULL; 311 GENERAL_NAME *gen = NULL;
343 int i; 312 int i;
344 if(ctx != NULL && ctx->flags == CTX_TEST) 313 if(ctx->flags == CTX_TEST) return 1;
345 return 1;
346 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) { 314 if(!ctx || (!ctx->subject_cert && !ctx->subject_req)) {
347 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS); 315 X509V3err(X509V3_F_COPY_EMAIL,X509V3_R_NO_SUBJECT_DETAILS);
348 goto err; 316 goto err;
@@ -410,172 +378,81 @@ GENERAL_NAMES *v2i_GENERAL_NAMES(X509V3_EXT_METHOD *method,
410 378
411GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, 379GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
412 CONF_VALUE *cnf) 380 CONF_VALUE *cnf)
413 { 381{
414 return v2i_GENERAL_NAME_ex(NULL, method, ctx, cnf, 0); 382char is_string = 0;
415 } 383int type;
416 384GENERAL_NAME *gen = NULL;
417GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out,
418 X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
419 CONF_VALUE *cnf, int is_nc)
420 {
421 char is_string = 0;
422 int type;
423 GENERAL_NAME *gen = NULL;
424 385
425 char *name, *value; 386char *name, *value;
426 387
427 name = cnf->name; 388name = cnf->name;
428 value = cnf->value; 389value = cnf->value;
429 390
430 if(!value) 391if(!value) {
431 { 392 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_MISSING_VALUE);
432 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_MISSING_VALUE); 393 return NULL;
433 return NULL; 394}
434 }
435 395
436 if (out) 396if(!(gen = GENERAL_NAME_new())) {
437 gen = out; 397 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
438 else 398 return NULL;
439 { 399}
440 gen = GENERAL_NAME_new();
441 if(gen == NULL)
442 {
443 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,ERR_R_MALLOC_FAILURE);
444 return NULL;
445 }
446 }
447 400
448 if(!name_cmp(name, "email")) 401if(!name_cmp(name, "email")) {
449 { 402 is_string = 1;
450 is_string = 1; 403 type = GEN_EMAIL;
451 type = GEN_EMAIL; 404} else if(!name_cmp(name, "URI")) {
452 } 405 is_string = 1;
453 else if(!name_cmp(name, "URI")) 406 type = GEN_URI;
454 { 407} else if(!name_cmp(name, "DNS")) {
455 is_string = 1; 408 is_string = 1;
456 type = GEN_URI; 409 type = GEN_DNS;
457 } 410} else if(!name_cmp(name, "RID")) {
458 else if(!name_cmp(name, "DNS")) 411 ASN1_OBJECT *obj;
459 { 412 if(!(obj = OBJ_txt2obj(value,0))) {
460 is_string = 1; 413 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_OBJECT);
461 type = GEN_DNS; 414 ERR_add_error_data(2, "value=", value);
462 }
463 else if(!name_cmp(name, "RID"))
464 {
465 ASN1_OBJECT *obj;
466 if(!(obj = OBJ_txt2obj(value,0)))
467 {
468 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_BAD_OBJECT);
469 ERR_add_error_data(2, "value=", value);
470 goto err;
471 }
472 gen->d.rid = obj;
473 type = GEN_RID;
474 }
475 else if(!name_cmp(name, "IP"))
476 {
477 if (is_nc)
478 gen->d.ip = a2i_IPADDRESS_NC(value);
479 else
480 gen->d.ip = a2i_IPADDRESS(value);
481 if(gen->d.ip == NULL)
482 {
483 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_BAD_IP_ADDRESS);
484 ERR_add_error_data(2, "value=", value);
485 goto err;
486 }
487 type = GEN_IPADD;
488 }
489 else if(!name_cmp(name, "dirName"))
490 {
491 type = GEN_DIRNAME;
492 if (!do_dirname(gen, value, ctx))
493 {
494 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_DIRNAME_ERROR);
495 goto err;
496 }
497 }
498 else if(!name_cmp(name, "otherName"))
499 {
500 if (!do_othername(gen, value, ctx))
501 {
502 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_OTHERNAME_ERROR);
503 goto err;
504 }
505 type = GEN_OTHERNAME;
506 }
507 else
508 {
509 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,X509V3_R_UNSUPPORTED_OPTION);
510 ERR_add_error_data(2, "name=", name);
511 goto err; 415 goto err;
512 } 416 }
513 417 gen->d.rid = obj;
514 if(is_string) 418 type = GEN_RID;
515 { 419} else if(!name_cmp(name, "IP")) {
516 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) || 420 int i1,i2,i3,i4;
517 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value, 421 unsigned char ip[4];
518 strlen(value))) 422 if((sscanf(value, "%d.%d.%d.%d",&i1,&i2,&i3,&i4) != 4) ||
519 { 423 (i1 < 0) || (i1 > 255) || (i2 < 0) || (i2 > 255) ||
520 X509V3err(X509V3_F_V2I_GENERAL_NAME_EX,ERR_R_MALLOC_FAILURE); 424 (i3 < 0) || (i3 > 255) || (i4 < 0) || (i4 > 255) ) {
425 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_BAD_IP_ADDRESS);
426 ERR_add_error_data(2, "value=", value);
427 goto err;
428 }
429 ip[0] = i1; ip[1] = i2 ; ip[2] = i3 ; ip[3] = i4;
430 if(!(gen->d.ip = M_ASN1_OCTET_STRING_new()) ||
431 !ASN1_STRING_set(gen->d.ip, ip, 4)) {
432 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
521 goto err; 433 goto err;
522 }
523 }
524
525 gen->type = type;
526
527 return gen;
528
529 err:
530 GENERAL_NAME_free(gen);
531 return NULL;
532 } 434 }
435 type = GEN_IPADD;
436} else {
437 X509V3err(X509V3_F_V2I_GENERAL_NAME,X509V3_R_UNSUPPORTED_OPTION);
438 ERR_add_error_data(2, "name=", name);
439 goto err;
440}
533 441
534static int do_othername(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx) 442if(is_string) {
535 { 443 if(!(gen->d.ia5 = M_ASN1_IA5STRING_new()) ||
536 char *objtmp = NULL, *p; 444 !ASN1_STRING_set(gen->d.ia5, (unsigned char*)value,
537 int objlen; 445 strlen(value))) {
538 if (!(p = strchr(value, ';'))) 446 X509V3err(X509V3_F_V2I_GENERAL_NAME,ERR_R_MALLOC_FAILURE);
539 return 0; 447 goto err;
540 if (!(gen->d.otherName = OTHERNAME_new()))
541 return 0;
542 /* Free this up because we will overwrite it.
543 * no need to free type_id because it is static
544 */
545 ASN1_TYPE_free(gen->d.otherName->value);
546 if (!(gen->d.otherName->value = ASN1_generate_v3(p + 1, ctx)))
547 return 0;
548 objlen = p - value;
549 objtmp = OPENSSL_malloc(objlen + 1);
550 strncpy(objtmp, value, objlen);
551 objtmp[objlen] = 0;
552 gen->d.otherName->type_id = OBJ_txt2obj(objtmp, 0);
553 OPENSSL_free(objtmp);
554 if (!gen->d.otherName->type_id)
555 return 0;
556 return 1;
557 } 448 }
449}
558 450
559static int do_dirname(GENERAL_NAME *gen, char *value, X509V3_CTX *ctx) 451gen->type = type;
560 { 452
561 int ret; 453return gen;
562 STACK_OF(CONF_VALUE) *sk; 454
563 X509_NAME *nm; 455err:
564 if (!(nm = X509_NAME_new())) 456GENERAL_NAME_free(gen);
565 return 0; 457return NULL;
566 sk = X509V3_get_section(ctx, value); 458}
567 if (!sk)
568 {
569 X509V3err(X509V3_F_DO_DIRNAME,X509V3_R_SECTION_NOT_FOUND);
570 ERR_add_error_data(2, "section=", value);
571 X509_NAME_free(nm);
572 return 0;
573 }
574 /* FIXME: should allow other character types... */
575 ret = X509V3_NAME_from_section(nm, sk, MBSTRING_ASC);
576 if (!ret)
577 X509_NAME_free(nm);
578 gen->d.dirn = nm;
579
580 return ret;
581 }
diff --git a/src/lib/libcrypto/x509v3/v3_asid.c b/src/lib/libcrypto/x509v3/v3_asid.c
new file mode 100644
index 0000000000..271930f967
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3_asid.c
@@ -0,0 +1,842 @@
1/*
2 * Contributed to the OpenSSL Project by the American Registry for
3 * Internet Numbers ("ARIN").
4 */
5/* ====================================================================
6 * Copyright (c) 2006 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 * Implementation of RFC 3779 section 3.2.
60 */
61
62#include <stdio.h>
63#include <string.h>
64#include <assert.h>
65#include "cryptlib.h"
66#include <openssl/conf.h>
67#include <openssl/asn1.h>
68#include <openssl/asn1t.h>
69#include <openssl/x509v3.h>
70#include <openssl/x509.h>
71#include <openssl/bn.h>
72
73#ifndef OPENSSL_NO_RFC3779
74
75/*
76 * OpenSSL ASN.1 template translation of RFC 3779 3.2.3.
77 */
78
79ASN1_SEQUENCE(ASRange) = {
80 ASN1_SIMPLE(ASRange, min, ASN1_INTEGER),
81 ASN1_SIMPLE(ASRange, max, ASN1_INTEGER)
82} ASN1_SEQUENCE_END(ASRange)
83
84ASN1_CHOICE(ASIdOrRange) = {
85 ASN1_SIMPLE(ASIdOrRange, u.id, ASN1_INTEGER),
86 ASN1_SIMPLE(ASIdOrRange, u.range, ASRange)
87} ASN1_CHOICE_END(ASIdOrRange)
88
89ASN1_CHOICE(ASIdentifierChoice) = {
90 ASN1_SIMPLE(ASIdentifierChoice, u.inherit, ASN1_NULL),
91 ASN1_SEQUENCE_OF(ASIdentifierChoice, u.asIdsOrRanges, ASIdOrRange)
92} ASN1_CHOICE_END(ASIdentifierChoice)
93
94ASN1_SEQUENCE(ASIdentifiers) = {
95 ASN1_EXP_OPT(ASIdentifiers, asnum, ASIdentifierChoice, 0),
96 ASN1_EXP_OPT(ASIdentifiers, rdi, ASIdentifierChoice, 1)
97} ASN1_SEQUENCE_END(ASIdentifiers)
98
99IMPLEMENT_ASN1_FUNCTIONS(ASRange)
100IMPLEMENT_ASN1_FUNCTIONS(ASIdOrRange)
101IMPLEMENT_ASN1_FUNCTIONS(ASIdentifierChoice)
102IMPLEMENT_ASN1_FUNCTIONS(ASIdentifiers)
103
104/*
105 * i2r method for an ASIdentifierChoice.
106 */
107static int i2r_ASIdentifierChoice(BIO *out,
108 ASIdentifierChoice *choice,
109 int indent,
110 const char *msg)
111{
112 int i;
113 char *s;
114 if (choice == NULL)
115 return 1;
116 BIO_printf(out, "%*s%s:\n", indent, "", msg);
117 switch (choice->type) {
118 case ASIdentifierChoice_inherit:
119 BIO_printf(out, "%*sinherit\n", indent + 2, "");
120 break;
121 case ASIdentifierChoice_asIdsOrRanges:
122 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges); i++) {
123 ASIdOrRange *aor = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
124 switch (aor->type) {
125 case ASIdOrRange_id:
126 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.id)) == NULL)
127 return 0;
128 BIO_printf(out, "%*s%s\n", indent + 2, "", s);
129 OPENSSL_free(s);
130 break;
131 case ASIdOrRange_range:
132 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->min)) == NULL)
133 return 0;
134 BIO_printf(out, "%*s%s-", indent + 2, "", s);
135 OPENSSL_free(s);
136 if ((s = i2s_ASN1_INTEGER(NULL, aor->u.range->max)) == NULL)
137 return 0;
138 BIO_printf(out, "%s\n", s);
139 OPENSSL_free(s);
140 break;
141 default:
142 return 0;
143 }
144 }
145 break;
146 default:
147 return 0;
148 }
149 return 1;
150}
151
152/*
153 * i2r method for an ASIdentifier extension.
154 */
155static int i2r_ASIdentifiers(X509V3_EXT_METHOD *method,
156 void *ext,
157 BIO *out,
158 int indent)
159{
160 ASIdentifiers *asid = ext;
161 return (i2r_ASIdentifierChoice(out, asid->asnum, indent,
162 "Autonomous System Numbers") &&
163 i2r_ASIdentifierChoice(out, asid->rdi, indent,
164 "Routing Domain Identifiers"));
165}
166
167/*
168 * Sort comparision function for a sequence of ASIdOrRange elements.
169 */
170static int ASIdOrRange_cmp(const ASIdOrRange * const *a_,
171 const ASIdOrRange * const *b_)
172{
173 const ASIdOrRange *a = *a_, *b = *b_;
174
175 assert((a->type == ASIdOrRange_id && a->u.id != NULL) ||
176 (a->type == ASIdOrRange_range && a->u.range != NULL &&
177 a->u.range->min != NULL && a->u.range->max != NULL));
178
179 assert((b->type == ASIdOrRange_id && b->u.id != NULL) ||
180 (b->type == ASIdOrRange_range && b->u.range != NULL &&
181 b->u.range->min != NULL && b->u.range->max != NULL));
182
183 if (a->type == ASIdOrRange_id && b->type == ASIdOrRange_id)
184 return ASN1_INTEGER_cmp(a->u.id, b->u.id);
185
186 if (a->type == ASIdOrRange_range && b->type == ASIdOrRange_range) {
187 int r = ASN1_INTEGER_cmp(a->u.range->min, b->u.range->min);
188 return r != 0 ? r : ASN1_INTEGER_cmp(a->u.range->max, b->u.range->max);
189 }
190
191 if (a->type == ASIdOrRange_id)
192 return ASN1_INTEGER_cmp(a->u.id, b->u.range->min);
193 else
194 return ASN1_INTEGER_cmp(a->u.range->min, b->u.id);
195}
196
197/*
198 * Add an inherit element.
199 */
200int v3_asid_add_inherit(ASIdentifiers *asid, int which)
201{
202 ASIdentifierChoice **choice;
203 if (asid == NULL)
204 return 0;
205 switch (which) {
206 case V3_ASID_ASNUM:
207 choice = &asid->asnum;
208 break;
209 case V3_ASID_RDI:
210 choice = &asid->rdi;
211 break;
212 default:
213 return 0;
214 }
215 if (*choice == NULL) {
216 if ((*choice = ASIdentifierChoice_new()) == NULL)
217 return 0;
218 assert((*choice)->u.inherit == NULL);
219 if (((*choice)->u.inherit = ASN1_NULL_new()) == NULL)
220 return 0;
221 (*choice)->type = ASIdentifierChoice_inherit;
222 }
223 return (*choice)->type == ASIdentifierChoice_inherit;
224}
225
226/*
227 * Add an ID or range to an ASIdentifierChoice.
228 */
229int v3_asid_add_id_or_range(ASIdentifiers *asid,
230 int which,
231 ASN1_INTEGER *min,
232 ASN1_INTEGER *max)
233{
234 ASIdentifierChoice **choice;
235 ASIdOrRange *aor;
236 if (asid == NULL)
237 return 0;
238 switch (which) {
239 case V3_ASID_ASNUM:
240 choice = &asid->asnum;
241 break;
242 case V3_ASID_RDI:
243 choice = &asid->rdi;
244 break;
245 default:
246 return 0;
247 }
248 if (*choice != NULL && (*choice)->type == ASIdentifierChoice_inherit)
249 return 0;
250 if (*choice == NULL) {
251 if ((*choice = ASIdentifierChoice_new()) == NULL)
252 return 0;
253 assert((*choice)->u.asIdsOrRanges == NULL);
254 (*choice)->u.asIdsOrRanges = sk_ASIdOrRange_new(ASIdOrRange_cmp);
255 if ((*choice)->u.asIdsOrRanges == NULL)
256 return 0;
257 (*choice)->type = ASIdentifierChoice_asIdsOrRanges;
258 }
259 if ((aor = ASIdOrRange_new()) == NULL)
260 return 0;
261 if (max == NULL) {
262 aor->type = ASIdOrRange_id;
263 aor->u.id = min;
264 } else {
265 aor->type = ASIdOrRange_range;
266 if ((aor->u.range = ASRange_new()) == NULL)
267 goto err;
268 ASN1_INTEGER_free(aor->u.range->min);
269 aor->u.range->min = min;
270 ASN1_INTEGER_free(aor->u.range->max);
271 aor->u.range->max = max;
272 }
273 if (!(sk_ASIdOrRange_push((*choice)->u.asIdsOrRanges, aor)))
274 goto err;
275 return 1;
276
277 err:
278 ASIdOrRange_free(aor);
279 return 0;
280}
281
282/*
283 * Extract min and max values from an ASIdOrRange.
284 */
285static void extract_min_max(ASIdOrRange *aor,
286 ASN1_INTEGER **min,
287 ASN1_INTEGER **max)
288{
289 assert(aor != NULL && min != NULL && max != NULL);
290 switch (aor->type) {
291 case ASIdOrRange_id:
292 *min = aor->u.id;
293 *max = aor->u.id;
294 return;
295 case ASIdOrRange_range:
296 *min = aor->u.range->min;
297 *max = aor->u.range->max;
298 return;
299 }
300}
301
302/*
303 * Check whether an ASIdentifierChoice is in canonical form.
304 */
305static int ASIdentifierChoice_is_canonical(ASIdentifierChoice *choice)
306{
307 ASN1_INTEGER *a_max_plus_one = NULL;
308 BIGNUM *bn = NULL;
309 int i, ret = 0;
310
311 /*
312 * Empty element or inheritance is canonical.
313 */
314 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
315 return 1;
316
317 /*
318 * If not a list, or if empty list, it's broken.
319 */
320 if (choice->type != ASIdentifierChoice_asIdsOrRanges ||
321 sk_ASIdOrRange_num(choice->u.asIdsOrRanges) == 0)
322 return 0;
323
324 /*
325 * It's a list, check it.
326 */
327 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
328 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
329 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
330 ASN1_INTEGER *a_min, *a_max, *b_min, *b_max;
331
332 extract_min_max(a, &a_min, &a_max);
333 extract_min_max(b, &b_min, &b_max);
334
335 /*
336 * Punt misordered list, overlapping start, or inverted range.
337 */
338 if (ASN1_INTEGER_cmp(a_min, b_min) >= 0 ||
339 ASN1_INTEGER_cmp(a_min, a_max) > 0 ||
340 ASN1_INTEGER_cmp(b_min, b_max) > 0)
341 goto done;
342
343 /*
344 * Calculate a_max + 1 to check for adjacency.
345 */
346 if ((bn == NULL && (bn = BN_new()) == NULL) ||
347 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
348 !BN_add_word(bn, 1) ||
349 (a_max_plus_one = BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
350 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL,
351 ERR_R_MALLOC_FAILURE);
352 goto done;
353 }
354
355 /*
356 * Punt if adjacent or overlapping.
357 */
358 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) >= 0)
359 goto done;
360 }
361
362 ret = 1;
363
364 done:
365 ASN1_INTEGER_free(a_max_plus_one);
366 BN_free(bn);
367 return ret;
368}
369
370/*
371 * Check whether an ASIdentifier extension is in canonical form.
372 */
373int v3_asid_is_canonical(ASIdentifiers *asid)
374{
375 return (asid == NULL ||
376 (ASIdentifierChoice_is_canonical(asid->asnum) ||
377 ASIdentifierChoice_is_canonical(asid->rdi)));
378}
379
380/*
381 * Whack an ASIdentifierChoice into canonical form.
382 */
383static int ASIdentifierChoice_canonize(ASIdentifierChoice *choice)
384{
385 ASN1_INTEGER *a_max_plus_one = NULL;
386 BIGNUM *bn = NULL;
387 int i, ret = 0;
388
389 /*
390 * Nothing to do for empty element or inheritance.
391 */
392 if (choice == NULL || choice->type == ASIdentifierChoice_inherit)
393 return 1;
394
395 /*
396 * We have a list. Sort it.
397 */
398 assert(choice->type == ASIdentifierChoice_asIdsOrRanges);
399 sk_ASIdOrRange_sort(choice->u.asIdsOrRanges);
400
401 /*
402 * Now check for errors and suboptimal encoding, rejecting the
403 * former and fixing the latter.
404 */
405 for (i = 0; i < sk_ASIdOrRange_num(choice->u.asIdsOrRanges) - 1; i++) {
406 ASIdOrRange *a = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i);
407 ASIdOrRange *b = sk_ASIdOrRange_value(choice->u.asIdsOrRanges, i + 1);
408 ASN1_INTEGER *a_min, *a_max, *b_min, *b_max;
409
410 extract_min_max(a, &a_min, &a_max);
411 extract_min_max(b, &b_min, &b_max);
412
413 /*
414 * Make sure we're properly sorted (paranoia).
415 */
416 assert(ASN1_INTEGER_cmp(a_min, b_min) <= 0);
417
418 /*
419 * Check for overlaps.
420 */
421 if (ASN1_INTEGER_cmp(a_max, b_min) >= 0) {
422 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
423 X509V3_R_EXTENSION_VALUE_ERROR);
424 goto done;
425 }
426
427 /*
428 * Calculate a_max + 1 to check for adjacency.
429 */
430 if ((bn == NULL && (bn = BN_new()) == NULL) ||
431 ASN1_INTEGER_to_BN(a_max, bn) == NULL ||
432 !BN_add_word(bn, 1) ||
433 (a_max_plus_one = BN_to_ASN1_INTEGER(bn, a_max_plus_one)) == NULL) {
434 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE, ERR_R_MALLOC_FAILURE);
435 goto done;
436 }
437
438 /*
439 * If a and b are adjacent, merge them.
440 */
441 if (ASN1_INTEGER_cmp(a_max_plus_one, b_min) == 0) {
442 ASRange *r;
443 switch (a->type) {
444 case ASIdOrRange_id:
445 if ((r = OPENSSL_malloc(sizeof(ASRange))) == NULL) {
446 X509V3err(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE,
447 ERR_R_MALLOC_FAILURE);
448 goto done;
449 }
450 r->min = a_min;
451 r->max = b_max;
452 a->type = ASIdOrRange_range;
453 a->u.range = r;
454 break;
455 case ASIdOrRange_range:
456 ASN1_INTEGER_free(a->u.range->max);
457 a->u.range->max = b_max;
458 break;
459 }
460 switch (b->type) {
461 case ASIdOrRange_id:
462 b->u.id = NULL;
463 break;
464 case ASIdOrRange_range:
465 b->u.range->max = NULL;
466 break;
467 }
468 ASIdOrRange_free(b);
469 sk_ASIdOrRange_delete(choice->u.asIdsOrRanges, i + 1);
470 i--;
471 continue;
472 }
473 }
474
475 assert(ASIdentifierChoice_is_canonical(choice)); /* Paranoia */
476
477 ret = 1;
478
479 done:
480 ASN1_INTEGER_free(a_max_plus_one);
481 BN_free(bn);
482 return ret;
483}
484
485/*
486 * Whack an ASIdentifier extension into canonical form.
487 */
488int v3_asid_canonize(ASIdentifiers *asid)
489{
490 return (asid == NULL ||
491 (ASIdentifierChoice_canonize(asid->asnum) &&
492 ASIdentifierChoice_canonize(asid->rdi)));
493}
494
495/*
496 * v2i method for an ASIdentifier extension.
497 */
498static void *v2i_ASIdentifiers(struct v3_ext_method *method,
499 struct v3_ext_ctx *ctx,
500 STACK_OF(CONF_VALUE) *values)
501{
502 ASIdentifiers *asid = NULL;
503 int i;
504
505 if ((asid = ASIdentifiers_new()) == NULL) {
506 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
507 return NULL;
508 }
509
510 for (i = 0; i < sk_CONF_VALUE_num(values); i++) {
511 CONF_VALUE *val = sk_CONF_VALUE_value(values, i);
512 ASN1_INTEGER *min = NULL, *max = NULL;
513 int i1, i2, i3, is_range, which;
514
515 /*
516 * Figure out whether this is an AS or an RDI.
517 */
518 if ( !name_cmp(val->name, "AS")) {
519 which = V3_ASID_ASNUM;
520 } else if (!name_cmp(val->name, "RDI")) {
521 which = V3_ASID_RDI;
522 } else {
523 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_EXTENSION_NAME_ERROR);
524 X509V3_conf_err(val);
525 goto err;
526 }
527
528 /*
529 * Handle inheritance.
530 */
531 if (!strcmp(val->value, "inherit")) {
532 if (v3_asid_add_inherit(asid, which))
533 continue;
534 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_INHERITANCE);
535 X509V3_conf_err(val);
536 goto err;
537 }
538
539 /*
540 * Number, range, or mistake, pick it apart and figure out which.
541 */
542 i1 = strspn(val->value, "0123456789");
543 if (val->value[i1] == '\0') {
544 is_range = 0;
545 } else {
546 is_range = 1;
547 i2 = i1 + strspn(val->value + i1, " \t");
548 if (val->value[i2] != '-') {
549 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_ASNUMBER);
550 X509V3_conf_err(val);
551 goto err;
552 }
553 i2++;
554 i2 = i2 + strspn(val->value + i2, " \t");
555 i3 = i2 + strspn(val->value + i2, "0123456789");
556 if (val->value[i3] != '\0') {
557 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, X509V3_R_INVALID_ASRANGE);
558 X509V3_conf_err(val);
559 goto err;
560 }
561 }
562
563 /*
564 * Syntax is ok, read and add it.
565 */
566 if (!is_range) {
567 if (!X509V3_get_value_int(val, &min)) {
568 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
569 goto err;
570 }
571 } else {
572 char *s = BUF_strdup(val->value);
573 if (s == NULL) {
574 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
575 goto err;
576 }
577 s[i1] = '\0';
578 min = s2i_ASN1_INTEGER(NULL, s);
579 max = s2i_ASN1_INTEGER(NULL, s + i2);
580 OPENSSL_free(s);
581 if (min == NULL || max == NULL) {
582 ASN1_INTEGER_free(min);
583 ASN1_INTEGER_free(max);
584 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
585 goto err;
586 }
587 }
588 if (!v3_asid_add_id_or_range(asid, which, min, max)) {
589 ASN1_INTEGER_free(min);
590 ASN1_INTEGER_free(max);
591 X509V3err(X509V3_F_V2I_ASIDENTIFIERS, ERR_R_MALLOC_FAILURE);
592 goto err;
593 }
594 }
595
596 /*
597 * Canonize the result, then we're done.
598 */
599 if (!v3_asid_canonize(asid))
600 goto err;
601 return asid;
602
603 err:
604 ASIdentifiers_free(asid);
605 return NULL;
606}
607
608/*
609 * OpenSSL dispatch.
610 */
611const X509V3_EXT_METHOD v3_asid = {
612 NID_sbgp_autonomousSysNum, /* nid */
613 0, /* flags */
614 ASN1_ITEM_ref(ASIdentifiers), /* template */
615 0, 0, 0, 0, /* old functions, ignored */
616 0, /* i2s */
617 0, /* s2i */
618 0, /* i2v */
619 v2i_ASIdentifiers, /* v2i */
620 i2r_ASIdentifiers, /* i2r */
621 0, /* r2i */
622 NULL /* extension-specific data */
623};
624
625/*
626 * Figure out whether extension uses inheritance.
627 */
628int v3_asid_inherits(ASIdentifiers *asid)
629{
630 return (asid != NULL &&
631 ((asid->asnum != NULL &&
632 asid->asnum->type == ASIdentifierChoice_inherit) ||
633 (asid->rdi != NULL &&
634 asid->rdi->type == ASIdentifierChoice_inherit)));
635}
636
637/*
638 * Figure out whether parent contains child.
639 */
640static int asid_contains(ASIdOrRanges *parent, ASIdOrRanges *child)
641{
642 ASN1_INTEGER *p_min, *p_max, *c_min, *c_max;
643 int p, c;
644
645 if (child == NULL || parent == child)
646 return 1;
647 if (parent == NULL)
648 return 0;
649
650 p = 0;
651 for (c = 0; c < sk_ASIdOrRange_num(child); c++) {
652 extract_min_max(sk_ASIdOrRange_value(child, c), &c_min, &c_max);
653 for (;; p++) {
654 if (p >= sk_ASIdOrRange_num(parent))
655 return 0;
656 extract_min_max(sk_ASIdOrRange_value(parent, p), &p_min, &p_max);
657 if (ASN1_INTEGER_cmp(p_max, c_max) < 0)
658 continue;
659 if (ASN1_INTEGER_cmp(p_min, c_min) > 0)
660 return 0;
661 break;
662 }
663 }
664
665 return 1;
666}
667
668/*
669 * Test whether a is a subet of b.
670 */
671int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b)
672{
673 return (a == NULL ||
674 a == b ||
675 (b != NULL &&
676 !v3_asid_inherits(a) &&
677 !v3_asid_inherits(b) &&
678 asid_contains(b->asnum->u.asIdsOrRanges,
679 a->asnum->u.asIdsOrRanges) &&
680 asid_contains(b->rdi->u.asIdsOrRanges,
681 a->rdi->u.asIdsOrRanges)));
682}
683
684/*
685 * Validation error handling via callback.
686 */
687#define validation_err(_err_) \
688 do { \
689 if (ctx != NULL) { \
690 ctx->error = _err_; \
691 ctx->error_depth = i; \
692 ctx->current_cert = x; \
693 ret = ctx->verify_cb(0, ctx); \
694 } else { \
695 ret = 0; \
696 } \
697 if (!ret) \
698 goto done; \
699 } while (0)
700
701/*
702 * Core code for RFC 3779 3.3 path validation.
703 */
704static int v3_asid_validate_path_internal(X509_STORE_CTX *ctx,
705 STACK_OF(X509) *chain,
706 ASIdentifiers *ext)
707{
708 ASIdOrRanges *child_as = NULL, *child_rdi = NULL;
709 int i, ret = 1, inherit_as = 0, inherit_rdi = 0;
710 X509 *x = NULL;
711
712 assert(chain != NULL && sk_X509_num(chain) > 0);
713 assert(ctx != NULL || ext != NULL);
714 assert(ctx == NULL || ctx->verify_cb != NULL);
715
716 /*
717 * Figure out where to start. If we don't have an extension to
718 * check, we're done. Otherwise, check canonical form and
719 * set up for walking up the chain.
720 */
721 if (ext != NULL) {
722 i = -1;
723 } else {
724 i = 0;
725 x = sk_X509_value(chain, i);
726 assert(x != NULL);
727 if ((ext = x->rfc3779_asid) == NULL)
728 goto done;
729 }
730 if (!v3_asid_is_canonical(ext))
731 validation_err(X509_V_ERR_INVALID_EXTENSION);
732 if (ext->asnum != NULL) {
733 switch (ext->asnum->type) {
734 case ASIdentifierChoice_inherit:
735 inherit_as = 1;
736 break;
737 case ASIdentifierChoice_asIdsOrRanges:
738 child_as = ext->asnum->u.asIdsOrRanges;
739 break;
740 }
741 }
742 if (ext->rdi != NULL) {
743 switch (ext->rdi->type) {
744 case ASIdentifierChoice_inherit:
745 inherit_rdi = 1;
746 break;
747 case ASIdentifierChoice_asIdsOrRanges:
748 child_rdi = ext->rdi->u.asIdsOrRanges;
749 break;
750 }
751 }
752
753 /*
754 * Now walk up the chain. Extensions must be in canonical form, no
755 * cert may list resources that its parent doesn't list.
756 */
757 for (i++; i < sk_X509_num(chain); i++) {
758 x = sk_X509_value(chain, i);
759 assert(x != NULL);
760 if (x->rfc3779_asid == NULL) {
761 if (child_as != NULL || child_rdi != NULL)
762 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
763 continue;
764 }
765 if (!v3_asid_is_canonical(x->rfc3779_asid))
766 validation_err(X509_V_ERR_INVALID_EXTENSION);
767 if (x->rfc3779_asid->asnum == NULL && child_as != NULL) {
768 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
769 child_as = NULL;
770 inherit_as = 0;
771 }
772 if (x->rfc3779_asid->asnum != NULL &&
773 x->rfc3779_asid->asnum->type == ASIdentifierChoice_asIdsOrRanges) {
774 if (inherit_as ||
775 asid_contains(x->rfc3779_asid->asnum->u.asIdsOrRanges, child_as)) {
776 child_as = x->rfc3779_asid->asnum->u.asIdsOrRanges;
777 inherit_as = 0;
778 } else {
779 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
780 }
781 }
782 if (x->rfc3779_asid->rdi == NULL && child_rdi != NULL) {
783 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
784 child_rdi = NULL;
785 inherit_rdi = 0;
786 }
787 if (x->rfc3779_asid->rdi != NULL &&
788 x->rfc3779_asid->rdi->type == ASIdentifierChoice_asIdsOrRanges) {
789 if (inherit_rdi ||
790 asid_contains(x->rfc3779_asid->rdi->u.asIdsOrRanges, child_rdi)) {
791 child_rdi = x->rfc3779_asid->rdi->u.asIdsOrRanges;
792 inherit_rdi = 0;
793 } else {
794 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
795 }
796 }
797 }
798
799 /*
800 * Trust anchor can't inherit.
801 */
802 if (x->rfc3779_asid != NULL) {
803 if (x->rfc3779_asid->asnum != NULL &&
804 x->rfc3779_asid->asnum->type == ASIdentifierChoice_inherit)
805 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
806 if (x->rfc3779_asid->rdi != NULL &&
807 x->rfc3779_asid->rdi->type == ASIdentifierChoice_inherit)
808 validation_err(X509_V_ERR_UNNESTED_RESOURCE);
809 }
810
811 done:
812 return ret;
813}
814
815#undef validation_err
816
817/*
818 * RFC 3779 3.3 path validation -- called from X509_verify_cert().
819 */
820int v3_asid_validate_path(X509_STORE_CTX *ctx)
821{
822 return v3_asid_validate_path_internal(ctx, ctx->chain, NULL);
823}
824
825/*
826 * RFC 3779 3.3 path validation of an extension.
827 * Test whether chain covers extension.
828 */
829int v3_asid_validate_resource_set(STACK_OF(X509) *chain,
830 ASIdentifiers *ext,
831 int allow_inheritance)
832{
833 if (ext == NULL)
834 return 1;
835 if (chain == NULL || sk_X509_num(chain) == 0)
836 return 0;
837 if (!allow_inheritance && v3_asid_inherits(ext))
838 return 0;
839 return v3_asid_validate_path_internal(NULL, chain, ext);
840}
841
842#endif /* OPENSSL_NO_RFC3779 */
diff --git a/src/lib/libcrypto/x509v3/v3_bcons.c b/src/lib/libcrypto/x509v3/v3_bcons.c
index 74b1233071..cbb012715e 100644
--- a/src/lib/libcrypto/x509v3/v3_bcons.c
+++ b/src/lib/libcrypto/x509v3/v3_bcons.c
@@ -67,7 +67,7 @@
67static STACK_OF(CONF_VALUE) *i2v_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, BASIC_CONSTRAINTS *bcons, STACK_OF(CONF_VALUE) *extlist); 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); 68static BASIC_CONSTRAINTS *v2i_BASIC_CONSTRAINTS(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
69 69
70const X509V3_EXT_METHOD v3_bcons = { 70X509V3_EXT_METHOD v3_bcons = {
71NID_basic_constraints, 0, 71NID_basic_constraints, 0,
72ASN1_ITEM_ref(BASIC_CONSTRAINTS), 72ASN1_ITEM_ref(BASIC_CONSTRAINTS),
730,0,0,0, 730,0,0,0,
diff --git a/src/lib/libcrypto/x509v3/v3_bitst.c b/src/lib/libcrypto/x509v3/v3_bitst.c
index cf31f0816e..274965306d 100644
--- a/src/lib/libcrypto/x509v3/v3_bitst.c
+++ b/src/lib/libcrypto/x509v3/v3_bitst.c
@@ -61,6 +61,12 @@
61#include <openssl/conf.h> 61#include <openssl/conf.h>
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63 63
64static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
65 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
66static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
67 ASN1_BIT_STRING *bits,
68 STACK_OF(CONF_VALUE) *extlist);
69
64static BIT_STRING_BITNAME ns_cert_type_table[] = { 70static BIT_STRING_BITNAME ns_cert_type_table[] = {
65{0, "SSL Client", "client"}, 71{0, "SSL Client", "client"},
66{1, "SSL Server", "server"}, 72{1, "SSL Server", "server"},
@@ -88,10 +94,10 @@ static BIT_STRING_BITNAME key_usage_type_table[] = {
88 94
89 95
90 96
91const X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table); 97X509V3_EXT_METHOD v3_nscert = EXT_BITSTRING(NID_netscape_cert_type, ns_cert_type_table);
92const X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table); 98X509V3_EXT_METHOD v3_key_usage = EXT_BITSTRING(NID_key_usage, key_usage_type_table);
93 99
94STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 100static STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
95 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret) 101 ASN1_BIT_STRING *bits, STACK_OF(CONF_VALUE) *ret)
96{ 102{
97 BIT_STRING_BITNAME *bnam; 103 BIT_STRING_BITNAME *bnam;
@@ -102,7 +108,7 @@ STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
102 return ret; 108 return ret;
103} 109}
104 110
105ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method, 111static ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
106 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval) 112 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval)
107{ 113{
108 CONF_VALUE *val; 114 CONF_VALUE *val;
diff --git a/src/lib/libcrypto/x509v3/v3_conf.c b/src/lib/libcrypto/x509v3/v3_conf.c
index 2b867305fb..1284d5aaa5 100644
--- a/src/lib/libcrypto/x509v3/v3_conf.c
+++ b/src/lib/libcrypto/x509v3/v3_conf.c
@@ -3,7 +3,7 @@
3 * project 1999. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2002 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -69,12 +69,11 @@
69static int v3_check_critical(char **value); 69static int v3_check_critical(char **value);
70static int v3_check_generic(char **value); 70static int v3_check_generic(char **value);
71static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value); 71static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid, int crit, char *value);
72static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, int crit, int type, X509V3_CTX *ctx); 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); 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); 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, 75static X509_EXTENSION *do_ext_i2d(X509V3_EXT_METHOD *method, int ext_nid,
76 int crit, void *ext_struc); 76 int crit, void *ext_struc);
77static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len);
78/* CONF *conf: Config file */ 77/* CONF *conf: Config file */
79/* char *name: Name */ 78/* char *name: Name */
80/* char *value: Value */ 79/* char *value: Value */
@@ -86,11 +85,11 @@ X509_EXTENSION *X509V3_EXT_nconf(CONF *conf, X509V3_CTX *ctx, char *name,
86 X509_EXTENSION *ret; 85 X509_EXTENSION *ret;
87 crit = v3_check_critical(&value); 86 crit = v3_check_critical(&value);
88 if ((ext_type = v3_check_generic(&value))) 87 if ((ext_type = v3_check_generic(&value)))
89 return v3_generic_extension(name, value, crit, ext_type, ctx); 88 return v3_generic_extension(name, value, crit, ext_type);
90 ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value); 89 ret = do_ext_nconf(conf, ctx, OBJ_sn2nid(name), crit, value);
91 if (!ret) 90 if (!ret)
92 { 91 {
93 X509V3err(X509V3_F_X509V3_EXT_NCONF,X509V3_R_ERROR_IN_EXTENSION); 92 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_ERROR_IN_EXTENSION);
94 ERR_add_error_data(4,"name=", name, ", value=", value); 93 ERR_add_error_data(4,"name=", name, ", value=", value);
95 } 94 }
96 return ret; 95 return ret;
@@ -106,7 +105,7 @@ X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid,
106 crit = v3_check_critical(&value); 105 crit = v3_check_critical(&value);
107 if ((ext_type = v3_check_generic(&value))) 106 if ((ext_type = v3_check_generic(&value)))
108 return v3_generic_extension(OBJ_nid2sn(ext_nid), 107 return v3_generic_extension(OBJ_nid2sn(ext_nid),
109 value, crit, ext_type, ctx); 108 value, crit, ext_type);
110 return do_ext_nconf(conf, ctx, ext_nid, crit, value); 109 return do_ext_nconf(conf, ctx, ext_nid, crit, value);
111 } 110 }
112 111
@@ -121,12 +120,12 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
121 void *ext_struc; 120 void *ext_struc;
122 if (ext_nid == NID_undef) 121 if (ext_nid == NID_undef)
123 { 122 {
124 X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_UNKNOWN_EXTENSION_NAME); 123 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION_NAME);
125 return NULL; 124 return NULL;
126 } 125 }
127 if (!(method = X509V3_EXT_get_nid(ext_nid))) 126 if (!(method = X509V3_EXT_get_nid(ext_nid)))
128 { 127 {
129 X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_UNKNOWN_EXTENSION); 128 X509V3err(X509V3_F_DO_EXT_CONF,X509V3_R_UNKNOWN_EXTENSION);
130 return NULL; 129 return NULL;
131 } 130 }
132 /* Now get internal extension representation based on type */ 131 /* Now get internal extension representation based on type */
@@ -134,9 +133,9 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
134 { 133 {
135 if(*value == '@') nval = NCONF_get_section(conf, value + 1); 134 if(*value == '@') nval = NCONF_get_section(conf, value + 1);
136 else nval = X509V3_parse_list(value); 135 else nval = X509V3_parse_list(value);
137 if(sk_CONF_VALUE_num(nval) <= 0) 136 if(!nval)
138 { 137 {
139 X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_INVALID_EXTENSION_STRING); 138 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_INVALID_EXTENSION_STRING);
140 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value); 139 ERR_add_error_data(4, "name=", OBJ_nid2sn(ext_nid), ",section=", value);
141 return NULL; 140 return NULL;
142 } 141 }
@@ -151,16 +150,16 @@ static X509_EXTENSION *do_ext_nconf(CONF *conf, X509V3_CTX *ctx, int ext_nid,
151 } 150 }
152 else if(method->r2i) 151 else if(method->r2i)
153 { 152 {
154 if(!ctx->db || !ctx->db_meth) 153 if(!ctx->db)
155 { 154 {
156 X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_NO_CONFIG_DATABASE); 155 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_NO_CONFIG_DATABASE);
157 return NULL; 156 return NULL;
158 } 157 }
159 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL; 158 if(!(ext_struc = method->r2i(method, ctx, value))) return NULL;
160 } 159 }
161 else 160 else
162 { 161 {
163 X509V3err(X509V3_F_DO_EXT_NCONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED); 162 X509V3err(X509V3_F_X509V3_EXT_CONF,X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED);
164 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid)); 163 ERR_add_error_data(2, "name=", OBJ_nid2sn(ext_nid));
165 return NULL; 164 return NULL;
166 } 165 }
@@ -236,29 +235,17 @@ static int v3_check_critical(char **value)
236/* Check extension string for generic extension and return the type */ 235/* Check extension string for generic extension and return the type */
237static int v3_check_generic(char **value) 236static int v3_check_generic(char **value)
238{ 237{
239 int gen_type = 0;
240 char *p = *value; 238 char *p = *value;
241 if ((strlen(p) >= 4) && !strncmp(p, "DER:", 4)) 239 if ((strlen(p) < 4) || strncmp(p, "DER:", 4)) return 0;
242 { 240 p+=4;
243 p+=4;
244 gen_type = 1;
245 }
246 else if ((strlen(p) >= 5) && !strncmp(p, "ASN1:", 5))
247 {
248 p+=5;
249 gen_type = 2;
250 }
251 else
252 return 0;
253
254 while (isspace((unsigned char)*p)) p++; 241 while (isspace((unsigned char)*p)) p++;
255 *value = p; 242 *value = p;
256 return gen_type; 243 return 1;
257} 244}
258 245
259/* Create a generic extension: for now just handle DER type */ 246/* Create a generic extension: for now just handle DER type */
260static X509_EXTENSION *v3_generic_extension(const char *ext, char *value, 247static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
261 int crit, int gen_type, X509V3_CTX *ctx) 248 int crit, int type)
262 { 249 {
263 unsigned char *ext_der=NULL; 250 unsigned char *ext_der=NULL;
264 long ext_len; 251 long ext_len;
@@ -272,12 +259,7 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
272 goto err; 259 goto err;
273 } 260 }
274 261
275 if (gen_type == 1) 262 if (!(ext_der = string_to_hex(value, &ext_len)))
276 ext_der = string_to_hex(value, &ext_len);
277 else if (gen_type == 2)
278 ext_der = generic_asn1(value, ctx, &ext_len);
279
280 if (ext_der == NULL)
281 { 263 {
282 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR); 264 X509V3err(X509V3_F_V3_GENERIC_EXTENSION,X509V3_R_EXTENSION_VALUE_ERROR);
283 ERR_add_error_data(2, "value=", value); 265 ERR_add_error_data(2, "value=", value);
@@ -304,17 +286,6 @@ static X509_EXTENSION *v3_generic_extension(const char *ext, char *value,
304 286
305 } 287 }
306 288
307static unsigned char *generic_asn1(char *value, X509V3_CTX *ctx, long *ext_len)
308 {
309 ASN1_TYPE *typ;
310 unsigned char *ext_der = NULL;
311 typ = ASN1_generate_v3(value, ctx);
312 if (typ == NULL)
313 return NULL;
314 *ext_len = i2d_ASN1_TYPE(typ, &ext_der);
315 ASN1_TYPE_free(typ);
316 return ext_der;
317 }
318 289
319/* This is the main function: add a bunch of extensions based on a config file 290/* This is the main function: add a bunch of extensions based on a config file
320 * section to an extension STACK. 291 * section to an extension STACK.
@@ -383,11 +354,6 @@ int X509V3_EXT_REQ_add_nconf(CONF *conf, X509V3_CTX *ctx, char *section,
383 354
384char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section) 355char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
385 { 356 {
386 if(!ctx->db || !ctx->db_meth || !ctx->db_meth->get_string)
387 {
388 X509V3err(X509V3_F_X509V3_GET_STRING,X509V3_R_OPERATION_NOT_DEFINED);
389 return NULL;
390 }
391 if (ctx->db_meth->get_string) 357 if (ctx->db_meth->get_string)
392 return ctx->db_meth->get_string(ctx->db, name, section); 358 return ctx->db_meth->get_string(ctx->db, name, section);
393 return NULL; 359 return NULL;
@@ -395,11 +361,6 @@ char * X509V3_get_string(X509V3_CTX *ctx, char *name, char *section)
395 361
396STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section) 362STACK_OF(CONF_VALUE) * X509V3_get_section(X509V3_CTX *ctx, char *section)
397 { 363 {
398 if(!ctx->db || !ctx->db_meth || !ctx->db_meth->get_section)
399 {
400 X509V3err(X509V3_F_X509V3_GET_SECTION,X509V3_R_OPERATION_NOT_DEFINED);
401 return NULL;
402 }
403 if (ctx->db_meth->get_section) 364 if (ctx->db_meth->get_section)
404 return ctx->db_meth->get_section(ctx->db, section); 365 return ctx->db_meth->get_section(ctx->db, section);
405 return NULL; 366 return NULL;
diff --git a/src/lib/libcrypto/x509v3/v3_cpols.c b/src/lib/libcrypto/x509v3/v3_cpols.c
index a40f490aa9..867525f336 100644
--- a/src/lib/libcrypto/x509v3/v3_cpols.c
+++ b/src/lib/libcrypto/x509v3/v3_cpols.c
@@ -3,7 +3,7 @@
3 * project 1999. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -63,8 +63,6 @@
63#include <openssl/asn1t.h> 63#include <openssl/asn1t.h>
64#include <openssl/x509v3.h> 64#include <openssl/x509v3.h>
65 65
66#include "pcy_int.h"
67
68/* Certificate policies extension support: this one is a bit complex... */ 66/* Certificate policies extension support: this one is a bit complex... */
69 67
70static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent); 68static int i2r_certpol(X509V3_EXT_METHOD *method, STACK_OF(POLICYINFO) *pol, BIO *out, int indent);
@@ -77,7 +75,7 @@ static POLICYQUALINFO *notice_section(X509V3_CTX *ctx,
77 STACK_OF(CONF_VALUE) *unot, int ia5org); 75 STACK_OF(CONF_VALUE) *unot, int ia5org);
78static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos); 76static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos);
79 77
80const X509V3_EXT_METHOD v3_cpols = { 78X509V3_EXT_METHOD v3_cpols = {
81NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES), 79NID_certificate_policies, 0,ASN1_ITEM_ref(CERTIFICATEPOLICIES),
820,0,0,0, 800,0,0,0,
830,0, 810,0,
@@ -350,7 +348,7 @@ static int nref_nos(STACK_OF(ASN1_INTEGER) *nnums, STACK_OF(CONF_VALUE) *nos)
350 return 1; 348 return 1;
351 349
352 merr: 350 merr:
353 X509V3err(X509V3_F_NREF_NOS,ERR_R_MALLOC_FAILURE); 351 X509V3err(X509V3_F_NOTICE_SECTION,ERR_R_MALLOC_FAILURE);
354 352
355 err: 353 err:
356 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free); 354 sk_ASN1_INTEGER_pop_free(nnums, ASN1_STRING_free);
@@ -431,19 +429,3 @@ static void print_notice(BIO *out, USERNOTICE *notice, int indent)
431 notice->exptext->data); 429 notice->exptext->data);
432} 430}
433 431
434void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent)
435 {
436 const X509_POLICY_DATA *dat = node->data;
437
438 BIO_printf(out, "%*sPolicy: ", indent, "");
439
440 i2a_ASN1_OBJECT(out, dat->valid_policy);
441 BIO_puts(out, "\n");
442 BIO_printf(out, "%*s%s\n", indent + 2, "",
443 node_data_critical(dat) ? "Critical" : "Non Critical");
444 if (dat->qualifier_set)
445 print_qualifiers(out, dat->qualifier_set, indent + 2);
446 else
447 BIO_printf(out, "%*sNo Qualifiers\n", indent + 2, "");
448 }
449
diff --git a/src/lib/libcrypto/x509v3/v3_crld.c b/src/lib/libcrypto/x509v3/v3_crld.c
index c6e3ebae7b..f90829c574 100644
--- a/src/lib/libcrypto/x509v3/v3_crld.c
+++ b/src/lib/libcrypto/x509v3/v3_crld.c
@@ -68,7 +68,7 @@ static STACK_OF(CONF_VALUE) *i2v_crld(X509V3_EXT_METHOD *method,
68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method, 68static STACK_OF(DIST_POINT) *v2i_crld(X509V3_EXT_METHOD *method,
69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 69 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
70 70
71const X509V3_EXT_METHOD v3_crld = { 71X509V3_EXT_METHOD v3_crld = {
72NID_crl_distribution_points, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(CRL_DIST_POINTS), 72NID_crl_distribution_points, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(CRL_DIST_POINTS),
730,0,0,0, 730,0,0,0,
740,0, 740,0,
diff --git a/src/lib/libcrypto/x509v3/v3_enum.c b/src/lib/libcrypto/x509v3/v3_enum.c
index a236cb22e1..010c9d6260 100644
--- a/src/lib/libcrypto/x509v3/v3_enum.c
+++ b/src/lib/libcrypto/x509v3/v3_enum.c
@@ -72,7 +72,7 @@ static ENUMERATED_NAMES crl_reasons[] = {
72{-1, NULL, NULL} 72{-1, NULL, NULL}
73}; 73};
74 74
75const X509V3_EXT_METHOD v3_crl_reason = { 75X509V3_EXT_METHOD v3_crl_reason = {
76NID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED), 76NID_crl_reason, 0, ASN1_ITEM_ref(ASN1_ENUMERATED),
770,0,0,0, 770,0,0,0,
78(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE, 78(X509V3_EXT_I2S)i2s_ASN1_ENUMERATED_TABLE,
diff --git a/src/lib/libcrypto/x509v3/v3_extku.c b/src/lib/libcrypto/x509v3/v3_extku.c
index a4efe0031e..b1cfaba1aa 100644
--- a/src/lib/libcrypto/x509v3/v3_extku.c
+++ b/src/lib/libcrypto/x509v3/v3_extku.c
@@ -68,7 +68,7 @@ static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
68static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method, 68static STACK_OF(CONF_VALUE) *i2v_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
69 void *eku, STACK_OF(CONF_VALUE) *extlist); 69 void *eku, STACK_OF(CONF_VALUE) *extlist);
70 70
71const X509V3_EXT_METHOD v3_ext_ku = { 71X509V3_EXT_METHOD v3_ext_ku = {
72 NID_ext_key_usage, 0, 72 NID_ext_key_usage, 0,
73 ASN1_ITEM_ref(EXTENDED_KEY_USAGE), 73 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
74 0,0,0,0, 74 0,0,0,0,
@@ -80,7 +80,7 @@ const X509V3_EXT_METHOD v3_ext_ku = {
80}; 80};
81 81
82/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */ 82/* NB OCSP acceptable responses also is a SEQUENCE OF OBJECT */
83const X509V3_EXT_METHOD v3_ocsp_accresp = { 83X509V3_EXT_METHOD v3_ocsp_accresp = {
84 NID_id_pkix_OCSP_acceptableResponses, 0, 84 NID_id_pkix_OCSP_acceptableResponses, 0,
85 ASN1_ITEM_ref(EXTENDED_KEY_USAGE), 85 ASN1_ITEM_ref(EXTENDED_KEY_USAGE),
86 0,0,0,0, 86 0,0,0,0,
@@ -122,7 +122,7 @@ static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
122 int i; 122 int i;
123 123
124 if(!(extku = sk_ASN1_OBJECT_new_null())) { 124 if(!(extku = sk_ASN1_OBJECT_new_null())) {
125 X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,ERR_R_MALLOC_FAILURE); 125 X509V3err(X509V3_F_V2I_EXT_KU,ERR_R_MALLOC_FAILURE);
126 return NULL; 126 return NULL;
127 } 127 }
128 128
@@ -132,7 +132,7 @@ static void *v2i_EXTENDED_KEY_USAGE(X509V3_EXT_METHOD *method,
132 else extval = val->name; 132 else extval = val->name;
133 if(!(objtmp = OBJ_txt2obj(extval, 0))) { 133 if(!(objtmp = OBJ_txt2obj(extval, 0))) {
134 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free); 134 sk_ASN1_OBJECT_pop_free(extku, ASN1_OBJECT_free);
135 X509V3err(X509V3_F_V2I_EXTENDED_KEY_USAGE,X509V3_R_INVALID_OBJECT_IDENTIFIER); 135 X509V3err(X509V3_F_V2I_EXT_KU,X509V3_R_INVALID_OBJECT_IDENTIFIER);
136 X509V3_conf_err(val); 136 X509V3_conf_err(val);
137 return NULL; 137 return NULL;
138 } 138 }
diff --git a/src/lib/libcrypto/x509v3/v3_ia5.c b/src/lib/libcrypto/x509v3/v3_ia5.c
index b739ccd036..9683afa47c 100644
--- a/src/lib/libcrypto/x509v3/v3_ia5.c
+++ b/src/lib/libcrypto/x509v3/v3_ia5.c
@@ -65,7 +65,7 @@
65 65
66static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5); 66static char *i2s_ASN1_IA5STRING(X509V3_EXT_METHOD *method, ASN1_IA5STRING *ia5);
67static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); 67static ASN1_IA5STRING *s2i_ASN1_IA5STRING(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
68const X509V3_EXT_METHOD v3_ns_ia5_list[] = { 68X509V3_EXT_METHOD v3_ns_ia5_list[] = {
69EXT_IA5STRING(NID_netscape_base_url), 69EXT_IA5STRING(NID_netscape_base_url),
70EXT_IA5STRING(NID_netscape_revocation_url), 70EXT_IA5STRING(NID_netscape_revocation_url),
71EXT_IA5STRING(NID_netscape_ca_revocation_url), 71EXT_IA5STRING(NID_netscape_ca_revocation_url),
diff --git a/src/lib/libcrypto/x509v3/v3_info.c b/src/lib/libcrypto/x509v3/v3_info.c
index e0ef69de42..53e3f48859 100644
--- a/src/lib/libcrypto/x509v3/v3_info.c
+++ b/src/lib/libcrypto/x509v3/v3_info.c
@@ -69,7 +69,7 @@ static STACK_OF(CONF_VALUE) *i2v_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method
69static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method, 69static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *method,
70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval); 70 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
71 71
72const X509V3_EXT_METHOD v3_info = 72X509V3_EXT_METHOD v3_info =
73{ NID_info_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS), 73{ NID_info_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
740,0,0,0, 740,0,0,0,
750,0, 750,0,
@@ -78,7 +78,7 @@ const X509V3_EXT_METHOD v3_info =
780,0, 780,0,
79NULL}; 79NULL};
80 80
81const X509V3_EXT_METHOD v3_sinfo = 81X509V3_EXT_METHOD v3_sinfo =
82{ NID_sinfo_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS), 82{ NID_sinfo_access, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(AUTHORITY_INFO_ACCESS),
830,0,0,0, 830,0,0,0,
840,0, 840,0,
@@ -141,35 +141,36 @@ static AUTHORITY_INFO_ACCESS *v2i_AUTHORITY_INFO_ACCESS(X509V3_EXT_METHOD *metho
141 int i, objlen; 141 int i, objlen;
142 char *objtmp, *ptmp; 142 char *objtmp, *ptmp;
143 if(!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) { 143 if(!(ainfo = sk_ACCESS_DESCRIPTION_new_null())) {
144 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,ERR_R_MALLOC_FAILURE); 144 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
145 return NULL; 145 return NULL;
146 } 146 }
147 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) { 147 for(i = 0; i < sk_CONF_VALUE_num(nval); i++) {
148 cnf = sk_CONF_VALUE_value(nval, i); 148 cnf = sk_CONF_VALUE_value(nval, i);
149 if(!(acc = ACCESS_DESCRIPTION_new()) 149 if(!(acc = ACCESS_DESCRIPTION_new())
150 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) { 150 || !sk_ACCESS_DESCRIPTION_push(ainfo, acc)) {
151 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,ERR_R_MALLOC_FAILURE); 151 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
152 goto err; 152 goto err;
153 } 153 }
154 ptmp = strchr(cnf->name, ';'); 154 ptmp = strchr(cnf->name, ';');
155 if(!ptmp) { 155 if(!ptmp) {
156 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,X509V3_R_INVALID_SYNTAX); 156 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_INVALID_SYNTAX);
157 goto err; 157 goto err;
158 } 158 }
159 objlen = ptmp - cnf->name; 159 objlen = ptmp - cnf->name;
160 ctmp.name = ptmp + 1; 160 ctmp.name = ptmp + 1;
161 ctmp.value = cnf->value; 161 ctmp.value = cnf->value;
162 if(!v2i_GENERAL_NAME_ex(acc->location, method, ctx, &ctmp, 0)) 162 GENERAL_NAME_free(acc->location);
163 if(!(acc->location = v2i_GENERAL_NAME(method, ctx, &ctmp)))
163 goto err; 164 goto err;
164 if(!(objtmp = OPENSSL_malloc(objlen + 1))) { 165 if(!(objtmp = OPENSSL_malloc(objlen + 1))) {
165 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,ERR_R_MALLOC_FAILURE); 166 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,ERR_R_MALLOC_FAILURE);
166 goto err; 167 goto err;
167 } 168 }
168 strncpy(objtmp, cnf->name, objlen); 169 strncpy(objtmp, cnf->name, objlen);
169 objtmp[objlen] = 0; 170 objtmp[objlen] = 0;
170 acc->method = OBJ_txt2obj(objtmp, 0); 171 acc->method = OBJ_txt2obj(objtmp, 0);
171 if(!acc->method) { 172 if(!acc->method) {
172 X509V3err(X509V3_F_V2I_AUTHORITY_INFO_ACCESS,X509V3_R_BAD_OBJECT); 173 X509V3err(X509V3_F_V2I_ACCESS_DESCRIPTION,X509V3_R_BAD_OBJECT);
173 ERR_add_error_data(2, "value=", objtmp); 174 ERR_add_error_data(2, "value=", objtmp);
174 OPENSSL_free(objtmp); 175 OPENSSL_free(objtmp);
175 goto err; 176 goto err;
diff --git a/src/lib/libcrypto/x509v3/v3_int.c b/src/lib/libcrypto/x509v3/v3_int.c
index 9a48dc1508..7a43b4717b 100644
--- a/src/lib/libcrypto/x509v3/v3_int.c
+++ b/src/lib/libcrypto/x509v3/v3_int.c
@@ -60,30 +60,17 @@
60#include "cryptlib.h" 60#include "cryptlib.h"
61#include <openssl/x509v3.h> 61#include <openssl/x509v3.h>
62 62
63const X509V3_EXT_METHOD v3_crl_num = { 63X509V3_EXT_METHOD v3_crl_num = {
64 NID_crl_number, 0, ASN1_ITEM_ref(ASN1_INTEGER), 64 NID_crl_number, 0, ASN1_ITEM_ref(ASN1_INTEGER),
65 0,0,0,0, 65 0,0,0,0,
66 (X509V3_EXT_I2S)i2s_ASN1_INTEGER, 66 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
67 0, 67 0,
68 0,0,0,0, NULL}; 68 0,0,0,0, NULL};
69 69
70const X509V3_EXT_METHOD v3_delta_crl = { 70X509V3_EXT_METHOD v3_delta_crl = {
71 NID_delta_crl, 0, ASN1_ITEM_ref(ASN1_INTEGER), 71 NID_delta_crl, 0, ASN1_ITEM_ref(ASN1_INTEGER),
72 0,0,0,0, 72 0,0,0,0,
73 (X509V3_EXT_I2S)i2s_ASN1_INTEGER, 73 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
74 0, 74 0,
75 0,0,0,0, NULL}; 75 0,0,0,0, NULL};
76 76
77static void * s2i_asn1_int(X509V3_EXT_METHOD *meth, X509V3_CTX *ctx, char *value)
78 {
79 return s2i_ASN1_INTEGER(meth, value);
80 }
81
82const X509V3_EXT_METHOD v3_inhibit_anyp = {
83 NID_inhibit_any_policy, 0, ASN1_ITEM_ref(ASN1_INTEGER),
84 0,0,0,0,
85 (X509V3_EXT_I2S)i2s_ASN1_INTEGER,
86 (X509V3_EXT_S2I)s2i_asn1_int,
87 0,0,0,0, NULL};
88
89
diff --git a/src/lib/libcrypto/x509v3/v3_lib.c b/src/lib/libcrypto/x509v3/v3_lib.c
index f3015ea610..ca5a4a4a57 100644
--- a/src/lib/libcrypto/x509v3/v3_lib.c
+++ b/src/lib/libcrypto/x509v3/v3_lib.c
@@ -162,8 +162,7 @@ int X509V3_add_standard_extensions(void)
162void *X509V3_EXT_d2i(X509_EXTENSION *ext) 162void *X509V3_EXT_d2i(X509_EXTENSION *ext)
163{ 163{
164 X509V3_EXT_METHOD *method; 164 X509V3_EXT_METHOD *method;
165 const unsigned char *p; 165 unsigned char *p;
166
167 if(!(method = X509V3_EXT_get(ext))) return NULL; 166 if(!(method = X509V3_EXT_get(ext))) return NULL;
168 p = ext->value->data; 167 p = ext->value->data;
169 if(method->it) return ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it)); 168 if(method->it) return ASN1_item_d2i(NULL, &p, ext->value->length, ASN1_ITEM_ptr(method->it));
@@ -277,7 +276,7 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
277 ext = X509V3_EXT_i2d(nid, crit, value); 276 ext = X509V3_EXT_i2d(nid, crit, value);
278 277
279 if(!ext) { 278 if(!ext) {
280 X509V3err(X509V3_F_X509V3_ADD1_I2D, X509V3_R_ERROR_CREATING_EXTENSION); 279 X509V3err(X509V3_F_X509V3_ADD_I2D, X509V3_R_ERROR_CREATING_EXTENSION);
281 return 0; 280 return 0;
282 } 281 }
283 282
@@ -296,7 +295,7 @@ int X509V3_add1_i2d(STACK_OF(X509_EXTENSION) **x, int nid, void *value,
296 295
297 err: 296 err:
298 if(!(flags & X509V3_ADD_SILENT)) 297 if(!(flags & X509V3_ADD_SILENT))
299 X509V3err(X509V3_F_X509V3_ADD1_I2D, errcode); 298 X509V3err(X509V3_F_X509V3_ADD_I2D, errcode);
300 return 0; 299 return 0;
301} 300}
302 301
diff --git a/src/lib/libcrypto/x509v3/v3_ocsp.c b/src/lib/libcrypto/x509v3/v3_ocsp.c
index 62aac06335..21badc13f9 100644
--- a/src/lib/libcrypto/x509v3/v3_ocsp.c
+++ b/src/lib/libcrypto/x509v3/v3_ocsp.c
@@ -74,15 +74,15 @@ static int i2r_object(X509V3_EXT_METHOD *method, void *obj, BIO *out, int indent
74 74
75static void *ocsp_nonce_new(void); 75static void *ocsp_nonce_new(void);
76static int i2d_ocsp_nonce(void *a, unsigned char **pp); 76static int i2d_ocsp_nonce(void *a, unsigned char **pp);
77static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length); 77static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length);
78static void ocsp_nonce_free(void *a); 78static void ocsp_nonce_free(void *a);
79static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent); 79static int i2r_ocsp_nonce(X509V3_EXT_METHOD *method, void *nonce, BIO *out, int indent);
80 80
81static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent); 81static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out, int indent);
82static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str); 82static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
83static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind); 83static int i2r_ocsp_serviceloc(X509V3_EXT_METHOD *method, void *in, BIO *bp, int ind);
84 84
85const X509V3_EXT_METHOD v3_ocsp_crlid = { 85X509V3_EXT_METHOD v3_ocsp_crlid = {
86 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID), 86 NID_id_pkix_OCSP_CrlID, 0, ASN1_ITEM_ref(OCSP_CRLID),
87 0,0,0,0, 87 0,0,0,0,
88 0,0, 88 0,0,
@@ -91,7 +91,7 @@ const X509V3_EXT_METHOD v3_ocsp_crlid = {
91 NULL 91 NULL
92}; 92};
93 93
94const X509V3_EXT_METHOD v3_ocsp_acutoff = { 94X509V3_EXT_METHOD v3_ocsp_acutoff = {
95 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME), 95 NID_id_pkix_OCSP_archiveCutoff, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
96 0,0,0,0, 96 0,0,0,0,
97 0,0, 97 0,0,
@@ -100,7 +100,7 @@ const X509V3_EXT_METHOD v3_ocsp_acutoff = {
100 NULL 100 NULL
101}; 101};
102 102
103const X509V3_EXT_METHOD v3_crl_invdate = { 103X509V3_EXT_METHOD v3_crl_invdate = {
104 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME), 104 NID_invalidity_date, 0, ASN1_ITEM_ref(ASN1_GENERALIZEDTIME),
105 0,0,0,0, 105 0,0,0,0,
106 0,0, 106 0,0,
@@ -109,7 +109,7 @@ const X509V3_EXT_METHOD v3_crl_invdate = {
109 NULL 109 NULL
110}; 110};
111 111
112const X509V3_EXT_METHOD v3_crl_hold = { 112X509V3_EXT_METHOD v3_crl_hold = {
113 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT), 113 NID_hold_instruction_code, 0, ASN1_ITEM_ref(ASN1_OBJECT),
114 0,0,0,0, 114 0,0,0,0,
115 0,0, 115 0,0,
@@ -118,7 +118,7 @@ const X509V3_EXT_METHOD v3_crl_hold = {
118 NULL 118 NULL
119}; 119};
120 120
121const X509V3_EXT_METHOD v3_ocsp_nonce = { 121X509V3_EXT_METHOD v3_ocsp_nonce = {
122 NID_id_pkix_OCSP_Nonce, 0, NULL, 122 NID_id_pkix_OCSP_Nonce, 0, NULL,
123 ocsp_nonce_new, 123 ocsp_nonce_new,
124 ocsp_nonce_free, 124 ocsp_nonce_free,
@@ -130,7 +130,7 @@ const X509V3_EXT_METHOD v3_ocsp_nonce = {
130 NULL 130 NULL
131}; 131};
132 132
133const X509V3_EXT_METHOD v3_ocsp_nocheck = { 133X509V3_EXT_METHOD v3_ocsp_nocheck = {
134 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL), 134 NID_id_pkix_OCSP_noCheck, 0, ASN1_ITEM_ref(ASN1_NULL),
135 0,0,0,0, 135 0,0,0,0,
136 0,s2i_ocsp_nocheck, 136 0,s2i_ocsp_nocheck,
@@ -139,7 +139,7 @@ const X509V3_EXT_METHOD v3_ocsp_nocheck = {
139 NULL 139 NULL
140}; 140};
141 141
142const X509V3_EXT_METHOD v3_ocsp_serviceloc = { 142X509V3_EXT_METHOD v3_ocsp_serviceloc = {
143 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC), 143 NID_id_pkix_OCSP_serviceLocator, 0, ASN1_ITEM_ref(OCSP_SERVICELOC),
144 0,0,0,0, 144 0,0,0,0,
145 0,0, 145 0,0,
@@ -208,7 +208,7 @@ static int i2d_ocsp_nonce(void *a, unsigned char **pp)
208 return os->length; 208 return os->length;
209} 209}
210 210
211static void *d2i_ocsp_nonce(void *a, const unsigned char **pp, long length) 211static void *d2i_ocsp_nonce(void *a, unsigned char **pp, long length)
212{ 212{
213 ASN1_OCTET_STRING *os, **pos; 213 ASN1_OCTET_STRING *os, **pos;
214 pos = a; 214 pos = a;
@@ -246,7 +246,7 @@ static int i2r_ocsp_nocheck(X509V3_EXT_METHOD *method, void *nocheck, BIO *out,
246 return 1; 246 return 1;
247} 247}
248 248
249static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, const char *str) 249static void *s2i_ocsp_nocheck(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str)
250{ 250{
251 return ASN1_NULL_new(); 251 return ASN1_NULL_new();
252} 252}
diff --git a/src/lib/libcrypto/x509v3/v3_pku.c b/src/lib/libcrypto/x509v3/v3_pku.c
index 5c4626e89b..49a2e4697a 100644
--- a/src/lib/libcrypto/x509v3/v3_pku.c
+++ b/src/lib/libcrypto/x509v3/v3_pku.c
@@ -66,7 +66,7 @@ static int i2r_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, PKEY_USAGE_PERIOD *u
66/* 66/*
67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values); 67static PKEY_USAGE_PERIOD *v2i_PKEY_USAGE_PERIOD(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *values);
68*/ 68*/
69const X509V3_EXT_METHOD v3_pkey_usage_period = { 69X509V3_EXT_METHOD v3_pkey_usage_period = {
70NID_private_key_usage_period, 0, ASN1_ITEM_ref(PKEY_USAGE_PERIOD), 70NID_private_key_usage_period, 0, ASN1_ITEM_ref(PKEY_USAGE_PERIOD),
710,0,0,0, 710,0,0,0,
720,0,0,0, 720,0,0,0,
diff --git a/src/lib/libcrypto/x509v3/v3_prn.c b/src/lib/libcrypto/x509v3/v3_prn.c
index 20bd9bda19..5d268eb768 100644
--- a/src/lib/libcrypto/x509v3/v3_prn.c
+++ b/src/lib/libcrypto/x509v3/v3_prn.c
@@ -109,11 +109,10 @@ int X509V3_EXT_print(BIO *out, X509_EXTENSION *ext, unsigned long flag, int inde
109{ 109{
110 void *ext_str = NULL; 110 void *ext_str = NULL;
111 char *value = NULL; 111 char *value = NULL;
112 const unsigned char *p; 112 unsigned char *p;
113 X509V3_EXT_METHOD *method; 113 X509V3_EXT_METHOD *method;
114 STACK_OF(CONF_VALUE) *nval = NULL; 114 STACK_OF(CONF_VALUE) *nval = NULL;
115 int ok = 1; 115 int ok = 1;
116
117 if(!(method = X509V3_EXT_get(ext))) 116 if(!(method = X509V3_EXT_get(ext)))
118 return unknown_ext_print(out, ext, flag, indent, 0); 117 return unknown_ext_print(out, ext, flag, indent, 0);
119 p = ext->value->data; 118 p = ext->value->data;
@@ -183,7 +182,7 @@ int X509V3_extensions_print(BIO *bp, char *title, STACK_OF(X509_EXTENSION) *exts
183 obj=X509_EXTENSION_get_object(ex); 182 obj=X509_EXTENSION_get_object(ex);
184 i2a_ASN1_OBJECT(bp,obj); 183 i2a_ASN1_OBJECT(bp,obj);
185 j=X509_EXTENSION_get_critical(ex); 184 j=X509_EXTENSION_get_critical(ex);
186 if (BIO_printf(bp,": %s\n",j?"critical":"") <= 0) 185 if (BIO_printf(bp,": %s\n",j?"critical":"","") <= 0)
187 return 0; 186 return 0;
188 if(!X509V3_EXT_print(bp, ex, flag, indent + 4)) 187 if(!X509V3_EXT_print(bp, ex, flag, indent + 4))
189 { 188 {
diff --git a/src/lib/libcrypto/x509v3/v3_purp.c b/src/lib/libcrypto/x509v3/v3_purp.c
index b2f5cdfa05..bbdf6da493 100644
--- a/src/lib/libcrypto/x509v3/v3_purp.c
+++ b/src/lib/libcrypto/x509v3/v3_purp.c
@@ -139,7 +139,7 @@ int X509_PURPOSE_get_count(void)
139X509_PURPOSE * X509_PURPOSE_get0(int idx) 139X509_PURPOSE * X509_PURPOSE_get0(int idx)
140{ 140{
141 if(idx < 0) return NULL; 141 if(idx < 0) return NULL;
142 if(idx < (int)X509_PURPOSE_COUNT) return xstandard + idx; 142 if(idx < X509_PURPOSE_COUNT) return xstandard + idx;
143 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT); 143 return sk_X509_PURPOSE_value(xptable, idx - X509_PURPOSE_COUNT);
144} 144}
145 145
@@ -239,7 +239,7 @@ static void xptable_free(X509_PURPOSE *p)
239 239
240void X509_PURPOSE_cleanup(void) 240void X509_PURPOSE_cleanup(void)
241{ 241{
242 unsigned int i; 242 int i;
243 sk_X509_PURPOSE_pop_free(xptable, xptable_free); 243 sk_X509_PURPOSE_pop_free(xptable, xptable_free);
244 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i); 244 for(i = 0; i < X509_PURPOSE_COUNT; i++) xptable_free(xstandard + i);
245 xptable = NULL; 245 xptable = NULL;
@@ -285,12 +285,7 @@ int X509_supported_extension(X509_EXTENSION *ex)
285 NID_key_usage, /* 83 */ 285 NID_key_usage, /* 83 */
286 NID_subject_alt_name, /* 85 */ 286 NID_subject_alt_name, /* 85 */
287 NID_basic_constraints, /* 87 */ 287 NID_basic_constraints, /* 87 */
288 NID_certificate_policies, /* 89 */
289 NID_ext_key_usage, /* 126 */ 288 NID_ext_key_usage, /* 126 */
290#ifndef OPENSSL_NO_RFC3779
291 NID_sbgp_ipAddrBlock, /* 290 */
292 NID_sbgp_autonomousSysNum, /* 291 */
293#endif
294 NID_proxyCertInfo /* 661 */ 289 NID_proxyCertInfo /* 661 */
295 }; 290 };
296 291
@@ -348,10 +343,6 @@ static void x509v3_cache_extensions(X509 *x)
348 || X509_get_ext_by_NID(x, NID_issuer_alt_name, 0) >= 0) { 343 || X509_get_ext_by_NID(x, NID_issuer_alt_name, 0) >= 0) {
349 x->ex_flags |= EXFLAG_INVALID; 344 x->ex_flags |= EXFLAG_INVALID;
350 } 345 }
351 if (pci->pcPathLengthConstraint) {
352 x->ex_pcpathlen =
353 ASN1_INTEGER_get(pci->pcPathLengthConstraint);
354 } else x->ex_pcpathlen = -1;
355 PROXY_CERT_INFO_EXTENSION_free(pci); 346 PROXY_CERT_INFO_EXTENSION_free(pci);
356 x->ex_flags |= EXFLAG_PROXY; 347 x->ex_flags |= EXFLAG_PROXY;
357 } 348 }
@@ -415,11 +406,6 @@ static void x509v3_cache_extensions(X509 *x)
415 } 406 }
416 x->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL); 407 x->skid =X509_get_ext_d2i(x, NID_subject_key_identifier, NULL, NULL);
417 x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL); 408 x->akid =X509_get_ext_d2i(x, NID_authority_key_identifier, NULL, NULL);
418#ifndef OPENSSL_NO_RFC3779
419 x->rfc3779_addr =X509_get_ext_d2i(x, NID_sbgp_ipAddrBlock, NULL, NULL);
420 x->rfc3779_asid =X509_get_ext_d2i(x, NID_sbgp_autonomousSysNum,
421 NULL, NULL);
422#endif
423 for (i = 0; i < X509_get_ext_count(x); i++) 409 for (i = 0; i < X509_get_ext_count(x); i++)
424 { 410 {
425 ex = X509_get_ext(x, i); 411 ex = X509_get_ext(x, i);
diff --git a/src/lib/libcrypto/x509v3/v3_skey.c b/src/lib/libcrypto/x509v3/v3_skey.c
index da0a3558f6..c0f044ac1b 100644
--- a/src/lib/libcrypto/x509v3/v3_skey.c
+++ b/src/lib/libcrypto/x509v3/v3_skey.c
@@ -62,7 +62,7 @@
62#include <openssl/x509v3.h> 62#include <openssl/x509v3.h>
63 63
64static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str); 64static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, char *str);
65const X509V3_EXT_METHOD v3_skey_id = { 65X509V3_EXT_METHOD v3_skey_id = {
66NID_subject_key_identifier, 0, ASN1_ITEM_ref(ASN1_OCTET_STRING), 66NID_subject_key_identifier, 0, ASN1_ITEM_ref(ASN1_OCTET_STRING),
670,0,0,0, 670,0,0,0,
68(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING, 68(X509V3_EXT_I2S)i2s_ASN1_OCTET_STRING,
@@ -109,14 +109,14 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
109 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str); 109 if(strcmp(str, "hash")) return s2i_ASN1_OCTET_STRING(method, ctx, str);
110 110
111 if(!(oct = M_ASN1_OCTET_STRING_new())) { 111 if(!(oct = M_ASN1_OCTET_STRING_new())) {
112 X509V3err(X509V3_F_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); 112 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
113 return NULL; 113 return NULL;
114 } 114 }
115 115
116 if(ctx && (ctx->flags == CTX_TEST)) return oct; 116 if(ctx && (ctx->flags == CTX_TEST)) return oct;
117 117
118 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) { 118 if(!ctx || (!ctx->subject_req && !ctx->subject_cert)) {
119 X509V3err(X509V3_F_S2I_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); 119 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
120 goto err; 120 goto err;
121 } 121 }
122 122
@@ -125,14 +125,14 @@ static ASN1_OCTET_STRING *s2i_skey_id(X509V3_EXT_METHOD *method,
125 else pk = ctx->subject_cert->cert_info->key->public_key; 125 else pk = ctx->subject_cert->cert_info->key->public_key;
126 126
127 if(!pk) { 127 if(!pk) {
128 X509V3err(X509V3_F_S2I_SKEY_ID,X509V3_R_NO_PUBLIC_KEY); 128 X509V3err(X509V3_F_S2I_ASN1_SKEY_ID,X509V3_R_NO_PUBLIC_KEY);
129 goto err; 129 goto err;
130 } 130 }
131 131
132 EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL); 132 EVP_Digest(pk->data, pk->length, pkey_dig, &diglen, EVP_sha1(), NULL);
133 133
134 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) { 134 if(!M_ASN1_OCTET_STRING_set(oct, pkey_dig, diglen)) {
135 X509V3err(X509V3_F_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE); 135 X509V3err(X509V3_F_S2I_S2I_SKEY_ID,ERR_R_MALLOC_FAILURE);
136 goto err; 136 goto err;
137 } 137 }
138 138
diff --git a/src/lib/libcrypto/x509v3/v3_sxnet.c b/src/lib/libcrypto/x509v3/v3_sxnet.c
index eaea9ea01b..d3f4ba3a72 100644
--- a/src/lib/libcrypto/x509v3/v3_sxnet.c
+++ b/src/lib/libcrypto/x509v3/v3_sxnet.c
@@ -72,7 +72,7 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out, int indent)
72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, 72static SXNET * sxnet_v2i(X509V3_EXT_METHOD *method, X509V3_CTX *ctx,
73 STACK_OF(CONF_VALUE) *nval); 73 STACK_OF(CONF_VALUE) *nval);
74#endif 74#endif
75const X509V3_EXT_METHOD v3_sxnet = { 75X509V3_EXT_METHOD v3_sxnet = {
76NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET), 76NID_sxnet, X509V3_EXT_MULTILINE, ASN1_ITEM_ref(SXNET),
770,0,0,0, 770,0,0,0,
780,0, 780,0,
@@ -109,7 +109,7 @@ static int sxnet_i2r(X509V3_EXT_METHOD *method, SXNET *sx, BIO *out,
109 SXNETID *id; 109 SXNETID *id;
110 int i; 110 int i;
111 v = ASN1_INTEGER_get(sx->version); 111 v = ASN1_INTEGER_get(sx->version);
112 BIO_printf(out, "%*sVersion: %ld (0x%lX)", indent, "", v + 1, v); 112 BIO_printf(out, "%*sVersion: %d (0x%X)", indent, "", v + 1, v);
113 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) { 113 for(i = 0; i < sk_SXNETID_num(sx->ids); i++) {
114 id = sk_SXNETID_value(sx->ids, i); 114 id = sk_SXNETID_value(sx->ids, i);
115 tmp = i2s_ASN1_INTEGER(NULL, id->zone); 115 tmp = i2s_ASN1_INTEGER(NULL, id->zone);
@@ -154,7 +154,7 @@ int SXNET_add_id_asc(SXNET **psx, char *zone, char *user,
154{ 154{
155 ASN1_INTEGER *izone = NULL; 155 ASN1_INTEGER *izone = NULL;
156 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) { 156 if(!(izone = s2i_ASN1_INTEGER(NULL, zone))) {
157 X509V3err(X509V3_F_SXNET_ADD_ID_ASC,X509V3_R_ERROR_CONVERTING_ZONE); 157 X509V3err(X509V3_F_SXNET_ADD_ASC,X509V3_R_ERROR_CONVERTING_ZONE);
158 return 0; 158 return 0;
159 } 159 }
160 return SXNET_add_id_INTEGER(psx, izone, user, userlen); 160 return SXNET_add_id_INTEGER(psx, izone, user, userlen);
diff --git a/src/lib/libcrypto/x509v3/v3_utl.c b/src/lib/libcrypto/x509v3/v3_utl.c
index ac171ca940..f23a8d29a0 100644
--- a/src/lib/libcrypto/x509v3/v3_utl.c
+++ b/src/lib/libcrypto/x509v3/v3_utl.c
@@ -1,9 +1,9 @@
1/* v3_utl.c */ 1/* v3_utl.c */
2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL 2/* Written by Dr Stephen N Henson (shenson@bigfoot.com) for the OpenSSL
3 * project. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2003 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -63,7 +63,6 @@
63#include "cryptlib.h" 63#include "cryptlib.h"
64#include <openssl/conf.h> 64#include <openssl/conf.h>
65#include <openssl/x509v3.h> 65#include <openssl/x509v3.h>
66#include <openssl/bn.h>
67 66
68static char *strip_spaces(char *name); 67static char *strip_spaces(char *name);
69static int sk_strcmp(const char * const *a, const char * const *b); 68static int sk_strcmp(const char * const *a, const char * const *b);
@@ -71,11 +70,6 @@ static STACK *get_email(X509_NAME *name, GENERAL_NAMES *gens);
71static void str_free(void *str); 70static void str_free(void *str);
72static int append_ia5(STACK **sk, ASN1_IA5STRING *email); 71static int append_ia5(STACK **sk, ASN1_IA5STRING *email);
73 72
74static int ipv4_from_asc(unsigned char *v4, const char *in);
75static int ipv6_from_asc(unsigned char *v6, const char *in);
76static int ipv6_cb(const char *elem, int len, void *usr);
77static int ipv6_hex(unsigned char *out, const char *in, int inlen);
78
79/* Add a CONF_VALUE name value pair to stack */ 73/* Add a CONF_VALUE name value pair to stack */
80 74
81int X509V3_add_value(const char *name, const char *value, 75int X509V3_add_value(const char *name, const char *value,
@@ -84,7 +78,7 @@ int X509V3_add_value(const char *name, const char *value,
84 CONF_VALUE *vtmp = NULL; 78 CONF_VALUE *vtmp = NULL;
85 char *tname = NULL, *tvalue = NULL; 79 char *tname = NULL, *tvalue = NULL;
86 if(name && !(tname = BUF_strdup(name))) goto err; 80 if(name && !(tname = BUF_strdup(name))) goto err;
87 if(value && !(tvalue = BUF_strdup(value))) goto err;; 81 if(value && !(tvalue = BUF_strdup(value))) goto err;
88 if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err; 82 if(!(vtmp = (CONF_VALUE *)OPENSSL_malloc(sizeof(CONF_VALUE)))) goto err;
89 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err; 83 if(!*extlist && !(*extlist = sk_CONF_VALUE_new_null())) goto err;
90 vtmp->section = NULL; 84 vtmp->section = NULL;
@@ -162,11 +156,11 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
162 ASN1_INTEGER *aint; 156 ASN1_INTEGER *aint;
163 int isneg, ishex; 157 int isneg, ishex;
164 int ret; 158 int ret;
159 bn = BN_new();
165 if (!value) { 160 if (!value) {
166 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE); 161 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_INVALID_NULL_VALUE);
167 return 0; 162 return 0;
168 } 163 }
169 bn = BN_new();
170 if (value[0] == '-') { 164 if (value[0] == '-') {
171 value++; 165 value++;
172 isneg = 1; 166 isneg = 1;
@@ -180,8 +174,7 @@ ASN1_INTEGER *s2i_ASN1_INTEGER(X509V3_EXT_METHOD *method, char *value)
180 if (ishex) ret = BN_hex2bn(&bn, value); 174 if (ishex) ret = BN_hex2bn(&bn, value);
181 else ret = BN_dec2bn(&bn, value); 175 else ret = BN_dec2bn(&bn, value);
182 176
183 if (!ret || value[ret]) { 177 if (!ret) {
184 BN_free(bn);
185 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR); 178 X509V3err(X509V3_F_S2I_ASN1_INTEGER,X509V3_R_BN_DEC2BN_ERROR);
186 return 0; 179 return 0;
187 } 180 }
@@ -344,7 +337,7 @@ static char *strip_spaces(char *name)
344 char *p, *q; 337 char *p, *q;
345 /* Skip over leading spaces */ 338 /* Skip over leading spaces */
346 p = name; 339 p = name;
347 while(*p && isspace((unsigned char)*p)) p++; 340 while(isspace((unsigned char)*p)) p++;
348 if(!*p) return NULL; 341 if(!*p) return NULL;
349 q = p + strlen(p) - 1; 342 q = p + strlen(p) - 1;
350 while((q != p) && isspace((unsigned char)*q)) q--; 343 while((q != p) && isspace((unsigned char)*q)) q--;
@@ -365,7 +358,7 @@ char *hex_to_string(unsigned char *buffer, long len)
365 char *tmp, *q; 358 char *tmp, *q;
366 unsigned char *p; 359 unsigned char *p;
367 int i; 360 int i;
368 const static char hexdig[] = "0123456789ABCDEF"; 361 static char hexdig[] = "0123456789ABCDEF";
369 if(!buffer || !len) return NULL; 362 if(!buffer || !len) return NULL;
370 if(!(tmp = OPENSSL_malloc(len * 3 + 1))) { 363 if(!(tmp = OPENSSL_malloc(len * 3 + 1))) {
371 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE); 364 X509V3err(X509V3_F_HEX_TO_STRING,ERR_R_MALLOC_FAILURE);
@@ -473,30 +466,6 @@ STACK *X509_get1_email(X509 *x)
473 return ret; 466 return ret;
474} 467}
475 468
476STACK *X509_get1_ocsp(X509 *x)
477{
478 AUTHORITY_INFO_ACCESS *info;
479 STACK *ret = NULL;
480 int i;
481 info = X509_get_ext_d2i(x, NID_info_access, NULL, NULL);
482 if (!info)
483 return NULL;
484 for (i = 0; i < sk_ACCESS_DESCRIPTION_num(info); i++)
485 {
486 ACCESS_DESCRIPTION *ad = sk_ACCESS_DESCRIPTION_value(info, i);
487 if (OBJ_obj2nid(ad->method) == NID_ad_OCSP)
488 {
489 if (ad->location->type == GEN_URI)
490 {
491 if (!append_ia5(&ret, ad->location->d.uniformResourceIdentifier))
492 break;
493 }
494 }
495 }
496 AUTHORITY_INFO_ACCESS_free(info);
497 return ret;
498}
499
500STACK *X509_REQ_get1_email(X509_REQ *x) 469STACK *X509_REQ_get1_email(X509_REQ *x)
501{ 470{
502 GENERAL_NAMES *gens; 471 GENERAL_NAMES *gens;
@@ -564,305 +533,3 @@ void X509_email_free(STACK *sk)
564{ 533{
565 sk_pop_free(sk, str_free); 534 sk_pop_free(sk, str_free);
566} 535}
567
568/* Convert IP addresses both IPv4 and IPv6 into an
569 * OCTET STRING compatible with RFC3280.
570 */
571
572ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc)
573 {
574 unsigned char ipout[16];
575 ASN1_OCTET_STRING *ret;
576 int iplen;
577
578 /* If string contains a ':' assume IPv6 */
579
580 iplen = a2i_ipadd(ipout, ipasc);
581
582 if (!iplen)
583 return NULL;
584
585 ret = ASN1_OCTET_STRING_new();
586 if (!ret)
587 return NULL;
588 if (!ASN1_OCTET_STRING_set(ret, ipout, iplen))
589 {
590 ASN1_OCTET_STRING_free(ret);
591 return NULL;
592 }
593 return ret;
594 }
595
596ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc)
597 {
598 ASN1_OCTET_STRING *ret = NULL;
599 unsigned char ipout[32];
600 char *iptmp = NULL, *p;
601 int iplen1, iplen2;
602 p = strchr(ipasc,'/');
603 if (!p)
604 return NULL;
605 iptmp = BUF_strdup(ipasc);
606 if (!iptmp)
607 return NULL;
608 p = iptmp + (p - ipasc);
609 *p++ = 0;
610
611 iplen1 = a2i_ipadd(ipout, iptmp);
612
613 if (!iplen1)
614 goto err;
615
616 iplen2 = a2i_ipadd(ipout + iplen1, p);
617
618 OPENSSL_free(iptmp);
619 iptmp = NULL;
620
621 if (!iplen2 || (iplen1 != iplen2))
622 goto err;
623
624 ret = ASN1_OCTET_STRING_new();
625 if (!ret)
626 goto err;
627 if (!ASN1_OCTET_STRING_set(ret, ipout, iplen1 + iplen2))
628 goto err;
629
630 return ret;
631
632 err:
633 if (iptmp)
634 OPENSSL_free(iptmp);
635 if (ret)
636 ASN1_OCTET_STRING_free(ret);
637 return NULL;
638 }
639
640
641int a2i_ipadd(unsigned char *ipout, const char *ipasc)
642 {
643 /* If string contains a ':' assume IPv6 */
644
645 if (strchr(ipasc, ':'))
646 {
647 if (!ipv6_from_asc(ipout, ipasc))
648 return 0;
649 return 16;
650 }
651 else
652 {
653 if (!ipv4_from_asc(ipout, ipasc))
654 return 0;
655 return 4;
656 }
657 }
658
659static int ipv4_from_asc(unsigned char *v4, const char *in)
660 {
661 int a0, a1, a2, a3;
662 if (sscanf(in, "%d.%d.%d.%d", &a0, &a1, &a2, &a3) != 4)
663 return 0;
664 if ((a0 < 0) || (a0 > 255) || (a1 < 0) || (a1 > 255)
665 || (a2 < 0) || (a2 > 255) || (a3 < 0) || (a3 > 255))
666 return 0;
667 v4[0] = a0;
668 v4[1] = a1;
669 v4[2] = a2;
670 v4[3] = a3;
671 return 1;
672 }
673
674typedef struct {
675 /* Temporary store for IPV6 output */
676 unsigned char tmp[16];
677 /* Total number of bytes in tmp */
678 int total;
679 /* The position of a zero (corresponding to '::') */
680 int zero_pos;
681 /* Number of zeroes */
682 int zero_cnt;
683 } IPV6_STAT;
684
685
686static int ipv6_from_asc(unsigned char *v6, const char *in)
687 {
688 IPV6_STAT v6stat;
689 v6stat.total = 0;
690 v6stat.zero_pos = -1;
691 v6stat.zero_cnt = 0;
692 /* Treat the IPv6 representation as a list of values
693 * separated by ':'. The presence of a '::' will parse
694 * as one, two or three zero length elements.
695 */
696 if (!CONF_parse_list(in, ':', 0, ipv6_cb, &v6stat))
697 return 0;
698
699 /* Now for some sanity checks */
700
701 if (v6stat.zero_pos == -1)
702 {
703 /* If no '::' must have exactly 16 bytes */
704 if (v6stat.total != 16)
705 return 0;
706 }
707 else
708 {
709 /* If '::' must have less than 16 bytes */
710 if (v6stat.total == 16)
711 return 0;
712 /* More than three zeroes is an error */
713 if (v6stat.zero_cnt > 3)
714 return 0;
715 /* Can only have three zeroes if nothing else present */
716 else if (v6stat.zero_cnt == 3)
717 {
718 if (v6stat.total > 0)
719 return 0;
720 }
721 /* Can only have two zeroes if at start or end */
722 else if (v6stat.zero_cnt == 2)
723 {
724 if ((v6stat.zero_pos != 0)
725 && (v6stat.zero_pos != v6stat.total))
726 return 0;
727 }
728 else
729 /* Can only have one zero if *not* start or end */
730 {
731 if ((v6stat.zero_pos == 0)
732 || (v6stat.zero_pos == v6stat.total))
733 return 0;
734 }
735 }
736
737 /* Format result */
738
739 /* Copy initial part */
740 if (v6stat.zero_pos > 0)
741 memcpy(v6, v6stat.tmp, v6stat.zero_pos);
742 /* Zero middle */
743 if (v6stat.total != 16)
744 memset(v6 + v6stat.zero_pos, 0, 16 - v6stat.total);
745 /* Copy final part */
746 if (v6stat.total != v6stat.zero_pos)
747 memcpy(v6 + v6stat.zero_pos + 16 - v6stat.total,
748 v6stat.tmp + v6stat.zero_pos,
749 v6stat.total - v6stat.zero_pos);
750
751 return 1;
752 }
753
754static int ipv6_cb(const char *elem, int len, void *usr)
755 {
756 IPV6_STAT *s = usr;
757 /* Error if 16 bytes written */
758 if (s->total == 16)
759 return 0;
760 if (len == 0)
761 {
762 /* Zero length element, corresponds to '::' */
763 if (s->zero_pos == -1)
764 s->zero_pos = s->total;
765 /* If we've already got a :: its an error */
766 else if (s->zero_pos != s->total)
767 return 0;
768 s->zero_cnt++;
769 }
770 else
771 {
772 /* If more than 4 characters could be final a.b.c.d form */
773 if (len > 4)
774 {
775 /* Need at least 4 bytes left */
776 if (s->total > 12)
777 return 0;
778 /* Must be end of string */
779 if (elem[len])
780 return 0;
781 if (!ipv4_from_asc(s->tmp + s->total, elem))
782 return 0;
783 s->total += 4;
784 }
785 else
786 {
787 if (!ipv6_hex(s->tmp + s->total, elem, len))
788 return 0;
789 s->total += 2;
790 }
791 }
792 return 1;
793 }
794
795/* Convert a string of up to 4 hex digits into the corresponding
796 * IPv6 form.
797 */
798
799static int ipv6_hex(unsigned char *out, const char *in, int inlen)
800 {
801 unsigned char c;
802 unsigned int num = 0;
803 if (inlen > 4)
804 return 0;
805 while(inlen--)
806 {
807 c = *in++;
808 num <<= 4;
809 if ((c >= '0') && (c <= '9'))
810 num |= c - '0';
811 else if ((c >= 'A') && (c <= 'F'))
812 num |= c - 'A' + 10;
813 else if ((c >= 'a') && (c <= 'f'))
814 num |= c - 'a' + 10;
815 else
816 return 0;
817 }
818 out[0] = num >> 8;
819 out[1] = num & 0xff;
820 return 1;
821 }
822
823
824int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
825 unsigned long chtype)
826 {
827 CONF_VALUE *v;
828 int i, mval;
829 char *p, *type;
830 if (!nm)
831 return 0;
832
833 for (i = 0; i < sk_CONF_VALUE_num(dn_sk); i++)
834 {
835 v=sk_CONF_VALUE_value(dn_sk,i);
836 type=v->name;
837 /* Skip past any leading X. X: X, etc to allow for
838 * multiple instances
839 */
840 for(p = type; *p ; p++)
841#ifndef CHARSET_EBCDIC
842 if ((*p == ':') || (*p == ',') || (*p == '.'))
843#else
844 if ((*p == os_toascii[':']) || (*p == os_toascii[',']) || (*p == os_toascii['.']))
845#endif
846 {
847 p++;
848 if(*p) type = p;
849 break;
850 }
851#ifndef CHARSET_EBCDIC
852 if (*type == '+')
853#else
854 if (*type == os_toascii['+'])
855#endif
856 {
857 mval = -1;
858 type++;
859 }
860 else
861 mval = 0;
862 if (!X509_NAME_add_entry_by_txt(nm,type, chtype,
863 (unsigned char *) v->value,-1,-1,mval))
864 return 0;
865
866 }
867 return 1;
868 }
diff --git a/src/lib/libcrypto/x509v3/v3conf.c b/src/lib/libcrypto/x509v3/v3conf.c
new file mode 100644
index 0000000000..00cf5b4a5b
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3conf.c
@@ -0,0 +1,127 @@
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/conf.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67/* Test application to add extensions from a config file */
68
69int main(int argc, char **argv)
70{
71 LHASH *conf;
72 X509 *cert;
73 FILE *inf;
74 char *conf_file;
75 int i;
76 int count;
77 X509_EXTENSION *ext;
78 X509V3_add_standard_extensions();
79 ERR_load_crypto_strings();
80 if(!argv[1]) {
81 fprintf(stderr, "Usage: v3conf cert.pem [file.cnf]\n");
82 exit(1);
83 }
84 conf_file = argv[2];
85 if(!conf_file) conf_file = "test.cnf";
86 conf = CONF_load(NULL, "test.cnf", NULL);
87 if(!conf) {
88 fprintf(stderr, "Error opening Config file %s\n", conf_file);
89 ERR_print_errors_fp(stderr);
90 exit(1);
91 }
92
93 inf = fopen(argv[1], "r");
94 if(!inf) {
95 fprintf(stderr, "Can't open certificate file %s\n", argv[1]);
96 exit(1);
97 }
98 cert = PEM_read_X509(inf, NULL, NULL);
99 if(!cert) {
100 fprintf(stderr, "Error reading certificate file %s\n", argv[1]);
101 exit(1);
102 }
103 fclose(inf);
104
105 sk_pop_free(cert->cert_info->extensions, X509_EXTENSION_free);
106 cert->cert_info->extensions = NULL;
107
108 if(!X509V3_EXT_add_conf(conf, NULL, "test_section", cert)) {
109 fprintf(stderr, "Error adding extensions\n");
110 ERR_print_errors_fp(stderr);
111 exit(1);
112 }
113
114 count = X509_get_ext_count(cert);
115 printf("%d extensions\n", count);
116 for(i = 0; i < count; i++) {
117 ext = X509_get_ext(cert, i);
118 printf("%s", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
119 if(ext->critical) printf(",critical:\n");
120 else printf(":\n");
121 X509V3_EXT_print_fp(stdout, ext, 0, 0);
122 printf("\n");
123
124 }
125 return 0;
126}
127
diff --git a/src/lib/libcrypto/x509v3/v3err.c b/src/lib/libcrypto/x509v3/v3err.c
index d538ad8b80..e1edaf5248 100644
--- a/src/lib/libcrypto/x509v3/v3err.c
+++ b/src/lib/libcrypto/x509v3/v3err.c
@@ -70,15 +70,10 @@
70 70
71static ERR_STRING_DATA X509V3_str_functs[]= 71static ERR_STRING_DATA X509V3_str_functs[]=
72 { 72 {
73{ERR_FUNC(X509V3_F_ASIDENTIFIERCHOICE_CANONIZE), "ASIDENTIFIERCHOICE_CANONIZE"},
74{ERR_FUNC(X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL), "ASIDENTIFIERCHOICE_IS_CANONICAL"},
75{ERR_FUNC(X509V3_F_COPY_EMAIL), "COPY_EMAIL"}, 73{ERR_FUNC(X509V3_F_COPY_EMAIL), "COPY_EMAIL"},
76{ERR_FUNC(X509V3_F_COPY_ISSUER), "COPY_ISSUER"}, 74{ERR_FUNC(X509V3_F_COPY_ISSUER), "COPY_ISSUER"},
77{ERR_FUNC(X509V3_F_DO_DIRNAME), "DO_DIRNAME"},
78{ERR_FUNC(X509V3_F_DO_EXT_CONF), "DO_EXT_CONF"}, 75{ERR_FUNC(X509V3_F_DO_EXT_CONF), "DO_EXT_CONF"},
79{ERR_FUNC(X509V3_F_DO_EXT_I2D), "DO_EXT_I2D"}, 76{ERR_FUNC(X509V3_F_DO_EXT_I2D), "DO_EXT_I2D"},
80{ERR_FUNC(X509V3_F_DO_EXT_NCONF), "DO_EXT_NCONF"},
81{ERR_FUNC(X509V3_F_DO_I2V_NAME_CONSTRAINTS), "DO_I2V_NAME_CONSTRAINTS"},
82{ERR_FUNC(X509V3_F_HEX_TO_STRING), "hex_to_string"}, 77{ERR_FUNC(X509V3_F_HEX_TO_STRING), "hex_to_string"},
83{ERR_FUNC(X509V3_F_I2S_ASN1_ENUMERATED), "i2s_ASN1_ENUMERATED"}, 78{ERR_FUNC(X509V3_F_I2S_ASN1_ENUMERATED), "i2s_ASN1_ENUMERATED"},
84{ERR_FUNC(X509V3_F_I2S_ASN1_IA5STRING), "I2S_ASN1_IA5STRING"}, 79{ERR_FUNC(X509V3_F_I2S_ASN1_IA5STRING), "I2S_ASN1_IA5STRING"},
@@ -87,46 +82,34 @@ static ERR_STRING_DATA X509V3_str_functs[]=
87{ERR_FUNC(X509V3_F_NOTICE_SECTION), "NOTICE_SECTION"}, 82{ERR_FUNC(X509V3_F_NOTICE_SECTION), "NOTICE_SECTION"},
88{ERR_FUNC(X509V3_F_NREF_NOS), "NREF_NOS"}, 83{ERR_FUNC(X509V3_F_NREF_NOS), "NREF_NOS"},
89{ERR_FUNC(X509V3_F_POLICY_SECTION), "POLICY_SECTION"}, 84{ERR_FUNC(X509V3_F_POLICY_SECTION), "POLICY_SECTION"},
90{ERR_FUNC(X509V3_F_PROCESS_PCI_VALUE), "PROCESS_PCI_VALUE"},
91{ERR_FUNC(X509V3_F_R2I_CERTPOL), "R2I_CERTPOL"}, 85{ERR_FUNC(X509V3_F_R2I_CERTPOL), "R2I_CERTPOL"},
92{ERR_FUNC(X509V3_F_R2I_PCI), "R2I_PCI"}, 86{ERR_FUNC(X509V3_F_R2I_PCI), "R2I_PCI"},
93{ERR_FUNC(X509V3_F_S2I_ASN1_IA5STRING), "S2I_ASN1_IA5STRING"}, 87{ERR_FUNC(X509V3_F_S2I_ASN1_IA5STRING), "S2I_ASN1_IA5STRING"},
94{ERR_FUNC(X509V3_F_S2I_ASN1_INTEGER), "s2i_ASN1_INTEGER"}, 88{ERR_FUNC(X509V3_F_S2I_ASN1_INTEGER), "s2i_ASN1_INTEGER"},
95{ERR_FUNC(X509V3_F_S2I_ASN1_OCTET_STRING), "s2i_ASN1_OCTET_STRING"}, 89{ERR_FUNC(X509V3_F_S2I_ASN1_OCTET_STRING), "s2i_ASN1_OCTET_STRING"},
96{ERR_FUNC(X509V3_F_S2I_ASN1_SKEY_ID), "S2I_ASN1_SKEY_ID"}, 90{ERR_FUNC(X509V3_F_S2I_ASN1_SKEY_ID), "S2I_ASN1_SKEY_ID"},
97{ERR_FUNC(X509V3_F_S2I_SKEY_ID), "S2I_SKEY_ID"}, 91{ERR_FUNC(X509V3_F_S2I_S2I_SKEY_ID), "S2I_S2I_SKEY_ID"},
98{ERR_FUNC(X509V3_F_STRING_TO_HEX), "string_to_hex"}, 92{ERR_FUNC(X509V3_F_STRING_TO_HEX), "string_to_hex"},
99{ERR_FUNC(X509V3_F_SXNET_ADD_ID_ASC), "SXNET_add_id_asc"}, 93{ERR_FUNC(X509V3_F_SXNET_ADD_ASC), "SXNET_ADD_ASC"},
100{ERR_FUNC(X509V3_F_SXNET_ADD_ID_INTEGER), "SXNET_add_id_INTEGER"}, 94{ERR_FUNC(X509V3_F_SXNET_ADD_ID_INTEGER), "SXNET_add_id_INTEGER"},
101{ERR_FUNC(X509V3_F_SXNET_ADD_ID_ULONG), "SXNET_add_id_ulong"}, 95{ERR_FUNC(X509V3_F_SXNET_ADD_ID_ULONG), "SXNET_add_id_ulong"},
102{ERR_FUNC(X509V3_F_SXNET_GET_ID_ASC), "SXNET_get_id_asc"}, 96{ERR_FUNC(X509V3_F_SXNET_GET_ID_ASC), "SXNET_get_id_asc"},
103{ERR_FUNC(X509V3_F_SXNET_GET_ID_ULONG), "SXNET_get_id_ulong"}, 97{ERR_FUNC(X509V3_F_SXNET_GET_ID_ULONG), "SXNET_get_id_ulong"},
104{ERR_FUNC(X509V3_F_V2I_ASIDENTIFIERS), "V2I_ASIDENTIFIERS"}, 98{ERR_FUNC(X509V3_F_V2I_ACCESS_DESCRIPTION), "V2I_ACCESS_DESCRIPTION"},
105{ERR_FUNC(X509V3_F_V2I_ASN1_BIT_STRING), "v2i_ASN1_BIT_STRING"}, 99{ERR_FUNC(X509V3_F_V2I_ASN1_BIT_STRING), "V2I_ASN1_BIT_STRING"},
106{ERR_FUNC(X509V3_F_V2I_AUTHORITY_INFO_ACCESS), "V2I_AUTHORITY_INFO_ACCESS"},
107{ERR_FUNC(X509V3_F_V2I_AUTHORITY_KEYID), "V2I_AUTHORITY_KEYID"}, 100{ERR_FUNC(X509V3_F_V2I_AUTHORITY_KEYID), "V2I_AUTHORITY_KEYID"},
108{ERR_FUNC(X509V3_F_V2I_BASIC_CONSTRAINTS), "V2I_BASIC_CONSTRAINTS"}, 101{ERR_FUNC(X509V3_F_V2I_BASIC_CONSTRAINTS), "V2I_BASIC_CONSTRAINTS"},
109{ERR_FUNC(X509V3_F_V2I_CRLD), "V2I_CRLD"}, 102{ERR_FUNC(X509V3_F_V2I_CRLD), "V2I_CRLD"},
110{ERR_FUNC(X509V3_F_V2I_EXTENDED_KEY_USAGE), "V2I_EXTENDED_KEY_USAGE"}, 103{ERR_FUNC(X509V3_F_V2I_EXT_KU), "V2I_EXT_KU"},
104{ERR_FUNC(X509V3_F_V2I_GENERAL_NAME), "v2i_GENERAL_NAME"},
111{ERR_FUNC(X509V3_F_V2I_GENERAL_NAMES), "v2i_GENERAL_NAMES"}, 105{ERR_FUNC(X509V3_F_V2I_GENERAL_NAMES), "v2i_GENERAL_NAMES"},
112{ERR_FUNC(X509V3_F_V2I_GENERAL_NAME_EX), "v2i_GENERAL_NAME_ex"},
113{ERR_FUNC(X509V3_F_V2I_IPADDRBLOCKS), "V2I_IPADDRBLOCKS"},
114{ERR_FUNC(X509V3_F_V2I_ISSUER_ALT), "V2I_ISSUER_ALT"},
115{ERR_FUNC(X509V3_F_V2I_NAME_CONSTRAINTS), "V2I_NAME_CONSTRAINTS"},
116{ERR_FUNC(X509V3_F_V2I_POLICY_CONSTRAINTS), "V2I_POLICY_CONSTRAINTS"},
117{ERR_FUNC(X509V3_F_V2I_POLICY_MAPPINGS), "V2I_POLICY_MAPPINGS"},
118{ERR_FUNC(X509V3_F_V2I_SUBJECT_ALT), "V2I_SUBJECT_ALT"},
119{ERR_FUNC(X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL), "V3_ADDR_VALIDATE_PATH_INTERNAL"},
120{ERR_FUNC(X509V3_F_V3_GENERIC_EXTENSION), "V3_GENERIC_EXTENSION"}, 106{ERR_FUNC(X509V3_F_V3_GENERIC_EXTENSION), "V3_GENERIC_EXTENSION"},
121{ERR_FUNC(X509V3_F_X509V3_ADD1_I2D), "X509V3_add1_i2d"}, 107{ERR_FUNC(X509V3_F_X509V3_ADD_I2D), "X509V3_ADD_I2D"},
122{ERR_FUNC(X509V3_F_X509V3_ADD_VALUE), "X509V3_add_value"}, 108{ERR_FUNC(X509V3_F_X509V3_ADD_VALUE), "X509V3_add_value"},
123{ERR_FUNC(X509V3_F_X509V3_EXT_ADD), "X509V3_EXT_add"}, 109{ERR_FUNC(X509V3_F_X509V3_EXT_ADD), "X509V3_EXT_add"},
124{ERR_FUNC(X509V3_F_X509V3_EXT_ADD_ALIAS), "X509V3_EXT_add_alias"}, 110{ERR_FUNC(X509V3_F_X509V3_EXT_ADD_ALIAS), "X509V3_EXT_add_alias"},
125{ERR_FUNC(X509V3_F_X509V3_EXT_CONF), "X509V3_EXT_conf"}, 111{ERR_FUNC(X509V3_F_X509V3_EXT_CONF), "X509V3_EXT_conf"},
126{ERR_FUNC(X509V3_F_X509V3_EXT_I2D), "X509V3_EXT_i2d"}, 112{ERR_FUNC(X509V3_F_X509V3_EXT_I2D), "X509V3_EXT_i2d"},
127{ERR_FUNC(X509V3_F_X509V3_EXT_NCONF), "X509V3_EXT_nconf"},
128{ERR_FUNC(X509V3_F_X509V3_GET_SECTION), "X509V3_get_section"},
129{ERR_FUNC(X509V3_F_X509V3_GET_STRING), "X509V3_get_string"},
130{ERR_FUNC(X509V3_F_X509V3_GET_VALUE_BOOL), "X509V3_get_value_bool"}, 113{ERR_FUNC(X509V3_F_X509V3_GET_VALUE_BOOL), "X509V3_get_value_bool"},
131{ERR_FUNC(X509V3_F_X509V3_PARSE_LIST), "X509V3_parse_list"}, 114{ERR_FUNC(X509V3_F_X509V3_PARSE_LIST), "X509V3_parse_list"},
132{ERR_FUNC(X509V3_F_X509_PURPOSE_ADD), "X509_PURPOSE_add"}, 115{ERR_FUNC(X509V3_F_X509_PURPOSE_ADD), "X509_PURPOSE_add"},
@@ -140,7 +123,6 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
140{ERR_REASON(X509V3_R_BAD_OBJECT) ,"bad object"}, 123{ERR_REASON(X509V3_R_BAD_OBJECT) ,"bad object"},
141{ERR_REASON(X509V3_R_BN_DEC2BN_ERROR) ,"bn dec2bn error"}, 124{ERR_REASON(X509V3_R_BN_DEC2BN_ERROR) ,"bn dec2bn error"},
142{ERR_REASON(X509V3_R_BN_TO_ASN1_INTEGER_ERROR),"bn to asn1 integer error"}, 125{ERR_REASON(X509V3_R_BN_TO_ASN1_INTEGER_ERROR),"bn to asn1 integer error"},
143{ERR_REASON(X509V3_R_DIRNAME_ERROR) ,"dirname error"},
144{ERR_REASON(X509V3_R_DUPLICATE_ZONE_ID) ,"duplicate zone id"}, 126{ERR_REASON(X509V3_R_DUPLICATE_ZONE_ID) ,"duplicate zone id"},
145{ERR_REASON(X509V3_R_ERROR_CONVERTING_ZONE),"error converting zone"}, 127{ERR_REASON(X509V3_R_ERROR_CONVERTING_ZONE),"error converting zone"},
146{ERR_REASON(X509V3_R_ERROR_CREATING_EXTENSION),"error creating extension"}, 128{ERR_REASON(X509V3_R_ERROR_CREATING_EXTENSION),"error creating extension"},
@@ -151,15 +133,10 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
151{ERR_REASON(X509V3_R_EXTENSION_NOT_FOUND),"extension not found"}, 133{ERR_REASON(X509V3_R_EXTENSION_NOT_FOUND),"extension not found"},
152{ERR_REASON(X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED),"extension setting not supported"}, 134{ERR_REASON(X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED),"extension setting not supported"},
153{ERR_REASON(X509V3_R_EXTENSION_VALUE_ERROR),"extension value error"}, 135{ERR_REASON(X509V3_R_EXTENSION_VALUE_ERROR),"extension value error"},
154{ERR_REASON(X509V3_R_ILLEGAL_EMPTY_EXTENSION),"illegal empty extension"},
155{ERR_REASON(X509V3_R_ILLEGAL_HEX_DIGIT) ,"illegal hex digit"}, 136{ERR_REASON(X509V3_R_ILLEGAL_HEX_DIGIT) ,"illegal hex digit"},
156{ERR_REASON(X509V3_R_INCORRECT_POLICY_SYNTAX_TAG),"incorrect policy syntax tag"}, 137{ERR_REASON(X509V3_R_INCORRECT_POLICY_SYNTAX_TAG),"incorrect policy syntax tag"},
157{ERR_REASON(X509V3_R_INVALID_ASNUMBER) ,"invalid asnumber"},
158{ERR_REASON(X509V3_R_INVALID_ASRANGE) ,"invalid asrange"},
159{ERR_REASON(X509V3_R_INVALID_BOOLEAN_STRING),"invalid boolean string"}, 138{ERR_REASON(X509V3_R_INVALID_BOOLEAN_STRING),"invalid boolean string"},
160{ERR_REASON(X509V3_R_INVALID_EXTENSION_STRING),"invalid extension string"}, 139{ERR_REASON(X509V3_R_INVALID_EXTENSION_STRING),"invalid extension string"},
161{ERR_REASON(X509V3_R_INVALID_INHERITANCE),"invalid inheritance"},
162{ERR_REASON(X509V3_R_INVALID_IPADDRESS) ,"invalid ipaddress"},
163{ERR_REASON(X509V3_R_INVALID_NAME) ,"invalid name"}, 140{ERR_REASON(X509V3_R_INVALID_NAME) ,"invalid name"},
164{ERR_REASON(X509V3_R_INVALID_NULL_ARGUMENT),"invalid null argument"}, 141{ERR_REASON(X509V3_R_INVALID_NULL_ARGUMENT),"invalid null argument"},
165{ERR_REASON(X509V3_R_INVALID_NULL_NAME) ,"invalid null name"}, 142{ERR_REASON(X509V3_R_INVALID_NULL_NAME) ,"invalid null name"},
@@ -169,9 +146,9 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
169{ERR_REASON(X509V3_R_INVALID_OBJECT_IDENTIFIER),"invalid object identifier"}, 146{ERR_REASON(X509V3_R_INVALID_OBJECT_IDENTIFIER),"invalid object identifier"},
170{ERR_REASON(X509V3_R_INVALID_OPTION) ,"invalid option"}, 147{ERR_REASON(X509V3_R_INVALID_OPTION) ,"invalid option"},
171{ERR_REASON(X509V3_R_INVALID_POLICY_IDENTIFIER),"invalid policy identifier"}, 148{ERR_REASON(X509V3_R_INVALID_POLICY_IDENTIFIER),"invalid policy identifier"},
149{ERR_REASON(X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER),"invalid proxy policy identifier"},
172{ERR_REASON(X509V3_R_INVALID_PROXY_POLICY_SETTING),"invalid proxy policy setting"}, 150{ERR_REASON(X509V3_R_INVALID_PROXY_POLICY_SETTING),"invalid proxy policy setting"},
173{ERR_REASON(X509V3_R_INVALID_PURPOSE) ,"invalid purpose"}, 151{ERR_REASON(X509V3_R_INVALID_PURPOSE) ,"invalid purpose"},
174{ERR_REASON(X509V3_R_INVALID_SAFI) ,"invalid safi"},
175{ERR_REASON(X509V3_R_INVALID_SECTION) ,"invalid section"}, 152{ERR_REASON(X509V3_R_INVALID_SECTION) ,"invalid section"},
176{ERR_REASON(X509V3_R_INVALID_SYNTAX) ,"invalid syntax"}, 153{ERR_REASON(X509V3_R_INVALID_SYNTAX) ,"invalid syntax"},
177{ERR_REASON(X509V3_R_ISSUER_DECODE_ERROR),"issuer decode error"}, 154{ERR_REASON(X509V3_R_ISSUER_DECODE_ERROR),"issuer decode error"},
@@ -185,14 +162,12 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
185{ERR_REASON(X509V3_R_NO_PUBLIC_KEY) ,"no public key"}, 162{ERR_REASON(X509V3_R_NO_PUBLIC_KEY) ,"no public key"},
186{ERR_REASON(X509V3_R_NO_SUBJECT_DETAILS) ,"no subject details"}, 163{ERR_REASON(X509V3_R_NO_SUBJECT_DETAILS) ,"no subject details"},
187{ERR_REASON(X509V3_R_ODD_NUMBER_OF_DIGITS),"odd number of digits"}, 164{ERR_REASON(X509V3_R_ODD_NUMBER_OF_DIGITS),"odd number of digits"},
188{ERR_REASON(X509V3_R_OPERATION_NOT_DEFINED),"operation not defined"},
189{ERR_REASON(X509V3_R_OTHERNAME_ERROR) ,"othername error"},
190{ERR_REASON(X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED),"policy language alreadty defined"}, 165{ERR_REASON(X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED),"policy language alreadty defined"},
191{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH) ,"policy path length"}, 166{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH) ,"policy path length"},
192{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED),"policy path length alreadty defined"}, 167{ERR_REASON(X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED),"policy path length alreadty defined"},
168{ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT) ,"policy syntax not"},
193{ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED),"policy syntax not currently supported"}, 169{ERR_REASON(X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED),"policy syntax not currently supported"},
194{ERR_REASON(X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY),"policy when proxy language requires no policy"}, 170{ERR_REASON(X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY),"policy when proxy language requires no policy"},
195{ERR_REASON(X509V3_R_SECTION_NOT_FOUND) ,"section not found"},
196{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS),"unable to get issuer details"}, 171{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS),"unable to get issuer details"},
197{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_KEYID),"unable to get issuer keyid"}, 172{ERR_REASON(X509V3_R_UNABLE_TO_GET_ISSUER_KEYID),"unable to get issuer keyid"},
198{ERR_REASON(X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT),"unknown bit string argument"}, 173{ERR_REASON(X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT),"unknown bit string argument"},
@@ -208,12 +183,15 @@ static ERR_STRING_DATA X509V3_str_reasons[]=
208 183
209void ERR_load_X509V3_strings(void) 184void ERR_load_X509V3_strings(void)
210 { 185 {
211#ifndef OPENSSL_NO_ERR 186 static int init=1;
212 187
213 if (ERR_func_error_string(X509V3_str_functs[0].error) == NULL) 188 if (init)
214 { 189 {
190 init=0;
191#ifndef OPENSSL_NO_ERR
215 ERR_load_strings(0,X509V3_str_functs); 192 ERR_load_strings(0,X509V3_str_functs);
216 ERR_load_strings(0,X509V3_str_reasons); 193 ERR_load_strings(0,X509V3_str_reasons);
217 }
218#endif 194#endif
195
196 }
219 } 197 }
diff --git a/src/lib/libcrypto/x509v3/v3prin.c b/src/lib/libcrypto/x509v3/v3prin.c
new file mode 100644
index 0000000000..b529814319
--- /dev/null
+++ b/src/lib/libcrypto/x509v3/v3prin.c
@@ -0,0 +1,99 @@
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 <openssl/asn1.h>
63#include <openssl/conf.h>
64#include <openssl/x509.h>
65#include <openssl/x509v3.h>
66
67int main(int argc, char **argv)
68{
69 X509 *cert;
70 FILE *inf;
71 int i, count;
72 X509_EXTENSION *ext;
73 X509V3_add_standard_extensions();
74 ERR_load_crypto_strings();
75 if(!argv[1]) {
76 fprintf(stderr, "Usage v3prin cert.pem\n");
77 exit(1);
78 }
79 if(!(inf = fopen(argv[1], "r"))) {
80 fprintf(stderr, "Can't open %s\n", argv[1]);
81 exit(1);
82 }
83 if(!(cert = PEM_read_X509(inf, NULL, NULL))) {
84 fprintf(stderr, "Can't read certificate %s\n", argv[1]);
85 ERR_print_errors_fp(stderr);
86 exit(1);
87 }
88 fclose(inf);
89 count = X509_get_ext_count(cert);
90 printf("%d extensions\n", count);
91 for(i = 0; i < count; i++) {
92 ext = X509_get_ext(cert, i);
93 printf("%s\n", OBJ_nid2ln(OBJ_obj2nid(ext->object)));
94 if(!X509V3_EXT_print_fp(stdout, ext, 0, 0)) ERR_print_errors_fp(stderr);
95 printf("\n");
96
97 }
98 return 0;
99}
diff --git a/src/lib/libcrypto/x509v3/x509v3.h b/src/lib/libcrypto/x509v3/x509v3.h
index db2b0482c1..e6d91251c2 100644
--- a/src/lib/libcrypto/x509v3/x509v3.h
+++ b/src/lib/libcrypto/x509v3/x509v3.h
@@ -3,7 +3,7 @@
3 * project 1999. 3 * project 1999.
4 */ 4 */
5/* ==================================================================== 5/* ====================================================================
6 * Copyright (c) 1999-2004 The OpenSSL Project. All rights reserved. 6 * Copyright (c) 1999 The OpenSSL Project. All rights reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
@@ -74,14 +74,14 @@ struct v3_ext_ctx;
74 74
75typedef void * (*X509V3_EXT_NEW)(void); 75typedef void * (*X509V3_EXT_NEW)(void);
76typedef void (*X509V3_EXT_FREE)(void *); 76typedef void (*X509V3_EXT_FREE)(void *);
77typedef void * (*X509V3_EXT_D2I)(void *, const unsigned char ** , long); 77typedef void * (*X509V3_EXT_D2I)(void *, unsigned char ** , long);
78typedef int (*X509V3_EXT_I2D)(void *, unsigned char **); 78typedef int (*X509V3_EXT_I2D)(void *, unsigned char **);
79typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist); 79typedef STACK_OF(CONF_VALUE) * (*X509V3_EXT_I2V)(struct v3_ext_method *method, void *ext, STACK_OF(CONF_VALUE) *extlist);
80typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values); 80typedef void * (*X509V3_EXT_V2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, STACK_OF(CONF_VALUE) *values);
81typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext); 81typedef char * (*X509V3_EXT_I2S)(struct v3_ext_method *method, void *ext);
82typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str); 82typedef void * (*X509V3_EXT_S2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
83typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent); 83typedef int (*X509V3_EXT_I2R)(struct v3_ext_method *method, void *ext, BIO *out, int indent);
84typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, const char *str); 84typedef void * (*X509V3_EXT_R2I)(struct v3_ext_method *method, struct v3_ext_ctx *ctx, char *str);
85 85
86/* V3 extension structure */ 86/* V3 extension structure */
87 87
@@ -132,6 +132,7 @@ void *db;
132}; 132};
133 133
134typedef struct v3_ext_method X509V3_EXT_METHOD; 134typedef struct v3_ext_method X509V3_EXT_METHOD;
135typedef struct v3_ext_ctx X509V3_CTX;
135 136
136DECLARE_STACK_OF(X509V3_EXT_METHOD) 137DECLARE_STACK_OF(X509V3_EXT_METHOD)
137 138
@@ -286,33 +287,6 @@ typedef STACK_OF(POLICYINFO) CERTIFICATEPOLICIES;
286DECLARE_STACK_OF(POLICYINFO) 287DECLARE_STACK_OF(POLICYINFO)
287DECLARE_ASN1_SET_OF(POLICYINFO) 288DECLARE_ASN1_SET_OF(POLICYINFO)
288 289
289typedef struct POLICY_MAPPING_st {
290 ASN1_OBJECT *issuerDomainPolicy;
291 ASN1_OBJECT *subjectDomainPolicy;
292} POLICY_MAPPING;
293
294DECLARE_STACK_OF(POLICY_MAPPING)
295
296typedef STACK_OF(POLICY_MAPPING) POLICY_MAPPINGS;
297
298typedef struct GENERAL_SUBTREE_st {
299 GENERAL_NAME *base;
300 ASN1_INTEGER *minimum;
301 ASN1_INTEGER *maximum;
302} GENERAL_SUBTREE;
303
304DECLARE_STACK_OF(GENERAL_SUBTREE)
305
306typedef struct NAME_CONSTRAINTS_st {
307 STACK_OF(GENERAL_SUBTREE) *permittedSubtrees;
308 STACK_OF(GENERAL_SUBTREE) *excludedSubtrees;
309} NAME_CONSTRAINTS;
310
311typedef struct POLICY_CONSTRAINTS_st {
312 ASN1_INTEGER *requireExplicitPolicy;
313 ASN1_INTEGER *inhibitPolicyMapping;
314} POLICY_CONSTRAINTS;
315
316/* Proxy certificate structures, see RFC 3820 */ 290/* Proxy certificate structures, see RFC 3820 */
317typedef struct PROXY_POLICY_st 291typedef struct PROXY_POLICY_st
318 { 292 {
@@ -370,8 +344,6 @@ DECLARE_ASN1_FUNCTIONS(PROXY_CERT_INFO_EXTENSION)
370#define EXFLAG_CRITICAL 0x200 344#define EXFLAG_CRITICAL 0x200
371#define EXFLAG_PROXY 0x400 345#define EXFLAG_PROXY 0x400
372 346
373#define EXFLAG_INVALID_POLICY 0x400
374
375#define KU_DIGITAL_SIGNATURE 0x0080 347#define KU_DIGITAL_SIGNATURE 0x0080
376#define KU_NON_REPUDIATION 0x0040 348#define KU_NON_REPUDIATION 0x0040
377#define KU_KEY_ENCIPHERMENT 0x0020 349#define KU_KEY_ENCIPHERMENT 0x0020
@@ -470,13 +442,6 @@ DECLARE_ASN1_FUNCTIONS(PKEY_USAGE_PERIOD)
470 442
471DECLARE_ASN1_FUNCTIONS(GENERAL_NAME) 443DECLARE_ASN1_FUNCTIONS(GENERAL_NAME)
472 444
473
474ASN1_BIT_STRING *v2i_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
475 X509V3_CTX *ctx, STACK_OF(CONF_VALUE) *nval);
476STACK_OF(CONF_VALUE) *i2v_ASN1_BIT_STRING(X509V3_EXT_METHOD *method,
477 ASN1_BIT_STRING *bits,
478 STACK_OF(CONF_VALUE) *extlist);
479
480STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret); 445STACK_OF(CONF_VALUE) *i2v_GENERAL_NAME(X509V3_EXT_METHOD *method, GENERAL_NAME *gen, STACK_OF(CONF_VALUE) *ret);
481int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen); 446int GENERAL_NAME_print(BIO *out, GENERAL_NAME *gen);
482 447
@@ -509,24 +474,8 @@ DECLARE_ASN1_FUNCTIONS(DIST_POINT_NAME)
509DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION) 474DECLARE_ASN1_FUNCTIONS(ACCESS_DESCRIPTION)
510DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS) 475DECLARE_ASN1_FUNCTIONS(AUTHORITY_INFO_ACCESS)
511 476
512DECLARE_ASN1_ITEM(POLICY_MAPPING)
513DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_MAPPING)
514DECLARE_ASN1_ITEM(POLICY_MAPPINGS)
515
516DECLARE_ASN1_ITEM(GENERAL_SUBTREE)
517DECLARE_ASN1_ALLOC_FUNCTIONS(GENERAL_SUBTREE)
518
519DECLARE_ASN1_ITEM(NAME_CONSTRAINTS)
520DECLARE_ASN1_ALLOC_FUNCTIONS(NAME_CONSTRAINTS)
521
522DECLARE_ASN1_ALLOC_FUNCTIONS(POLICY_CONSTRAINTS)
523DECLARE_ASN1_ITEM(POLICY_CONSTRAINTS)
524
525#ifdef HEADER_CONF_H 477#ifdef HEADER_CONF_H
526GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, 478GENERAL_NAME *v2i_GENERAL_NAME(X509V3_EXT_METHOD *method, X509V3_CTX *ctx, CONF_VALUE *cnf);
527 CONF_VALUE *cnf);
528GENERAL_NAME *v2i_GENERAL_NAME_ex(GENERAL_NAME *out, X509V3_EXT_METHOD *method,
529 X509V3_CTX *ctx, CONF_VALUE *cnf, int is_nc);
530void X509V3_conf_free(CONF_VALUE *val); 479void X509V3_conf_free(CONF_VALUE *val);
531 480
532X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value); 481X509_EXTENSION *X509V3_EXT_nconf_nid(CONF *conf, X509V3_CTX *ctx, int ext_nid, char *value);
@@ -617,164 +566,7 @@ int X509_PURPOSE_get_id(X509_PURPOSE *);
617STACK *X509_get1_email(X509 *x); 566STACK *X509_get1_email(X509 *x);
618STACK *X509_REQ_get1_email(X509_REQ *x); 567STACK *X509_REQ_get1_email(X509_REQ *x);
619void X509_email_free(STACK *sk); 568void X509_email_free(STACK *sk);
620STACK *X509_get1_ocsp(X509 *x);
621
622ASN1_OCTET_STRING *a2i_IPADDRESS(const char *ipasc);
623ASN1_OCTET_STRING *a2i_IPADDRESS_NC(const char *ipasc);
624int a2i_ipadd(unsigned char *ipout, const char *ipasc);
625int X509V3_NAME_from_section(X509_NAME *nm, STACK_OF(CONF_VALUE)*dn_sk,
626 unsigned long chtype);
627
628void X509_POLICY_NODE_print(BIO *out, X509_POLICY_NODE *node, int indent);
629
630#ifndef OPENSSL_NO_RFC3779
631
632typedef struct ASRange_st {
633 ASN1_INTEGER *min, *max;
634} ASRange;
635
636#define ASIdOrRange_id 0
637#define ASIdOrRange_range 1
638
639typedef struct ASIdOrRange_st {
640 int type;
641 union {
642 ASN1_INTEGER *id;
643 ASRange *range;
644 } u;
645} ASIdOrRange;
646
647typedef STACK_OF(ASIdOrRange) ASIdOrRanges;
648DECLARE_STACK_OF(ASIdOrRange)
649
650#define ASIdentifierChoice_inherit 0
651#define ASIdentifierChoice_asIdsOrRanges 1
652
653typedef struct ASIdentifierChoice_st {
654 int type;
655 union {
656 ASN1_NULL *inherit;
657 ASIdOrRanges *asIdsOrRanges;
658 } u;
659} ASIdentifierChoice;
660
661typedef struct ASIdentifiers_st {
662 ASIdentifierChoice *asnum, *rdi;
663} ASIdentifiers;
664
665DECLARE_ASN1_FUNCTIONS(ASRange)
666DECLARE_ASN1_FUNCTIONS(ASIdOrRange)
667DECLARE_ASN1_FUNCTIONS(ASIdentifierChoice)
668DECLARE_ASN1_FUNCTIONS(ASIdentifiers)
669
670
671typedef struct IPAddressRange_st {
672 ASN1_BIT_STRING *min, *max;
673} IPAddressRange;
674
675#define IPAddressOrRange_addressPrefix 0
676#define IPAddressOrRange_addressRange 1
677
678typedef struct IPAddressOrRange_st {
679 int type;
680 union {
681 ASN1_BIT_STRING *addressPrefix;
682 IPAddressRange *addressRange;
683 } u;
684} IPAddressOrRange;
685
686typedef STACK_OF(IPAddressOrRange) IPAddressOrRanges;
687DECLARE_STACK_OF(IPAddressOrRange)
688
689#define IPAddressChoice_inherit 0
690#define IPAddressChoice_addressesOrRanges 1
691
692typedef struct IPAddressChoice_st {
693 int type;
694 union {
695 ASN1_NULL *inherit;
696 IPAddressOrRanges *addressesOrRanges;
697 } u;
698} IPAddressChoice;
699
700typedef struct IPAddressFamily_st {
701 ASN1_OCTET_STRING *addressFamily;
702 IPAddressChoice *ipAddressChoice;
703} IPAddressFamily;
704
705typedef STACK_OF(IPAddressFamily) IPAddrBlocks;
706DECLARE_STACK_OF(IPAddressFamily)
707
708DECLARE_ASN1_FUNCTIONS(IPAddressRange)
709DECLARE_ASN1_FUNCTIONS(IPAddressOrRange)
710DECLARE_ASN1_FUNCTIONS(IPAddressChoice)
711DECLARE_ASN1_FUNCTIONS(IPAddressFamily)
712
713/*
714 * API tag for elements of the ASIdentifer SEQUENCE.
715 */
716#define V3_ASID_ASNUM 0
717#define V3_ASID_RDI 1
718
719/*
720 * AFI values, assigned by IANA. It'd be nice to make the AFI
721 * handling code totally generic, but there are too many little things
722 * that would need to be defined for other address families for it to
723 * be worth the trouble.
724 */
725#define IANA_AFI_IPV4 1
726#define IANA_AFI_IPV6 2
727
728/*
729 * Utilities to construct and extract values from RFC3779 extensions,
730 * since some of the encodings (particularly for IP address prefixes
731 * and ranges) are a bit tedious to work with directly.
732 */
733int v3_asid_add_inherit(ASIdentifiers *asid, int which);
734int v3_asid_add_id_or_range(ASIdentifiers *asid, int which,
735 ASN1_INTEGER *min, ASN1_INTEGER *max);
736int v3_addr_add_inherit(IPAddrBlocks *addr,
737 const unsigned afi, const unsigned *safi);
738int v3_addr_add_prefix(IPAddrBlocks *addr,
739 const unsigned afi, const unsigned *safi,
740 unsigned char *a, const int prefixlen);
741int v3_addr_add_range(IPAddrBlocks *addr,
742 const unsigned afi, const unsigned *safi,
743 unsigned char *min, unsigned char *max);
744unsigned v3_addr_get_afi(const IPAddressFamily *f);
745int v3_addr_get_range(IPAddressOrRange *aor, const unsigned afi,
746 unsigned char *min, unsigned char *max,
747 const int length);
748
749/*
750 * Canonical forms.
751 */
752int v3_asid_is_canonical(ASIdentifiers *asid);
753int v3_addr_is_canonical(IPAddrBlocks *addr);
754int v3_asid_canonize(ASIdentifiers *asid);
755int v3_addr_canonize(IPAddrBlocks *addr);
756
757/*
758 * Tests for inheritance and containment.
759 */
760int v3_asid_inherits(ASIdentifiers *asid);
761int v3_addr_inherits(IPAddrBlocks *addr);
762int v3_asid_subset(ASIdentifiers *a, ASIdentifiers *b);
763int v3_addr_subset(IPAddrBlocks *a, IPAddrBlocks *b);
764
765/*
766 * Check whether RFC 3779 extensions nest properly in chains.
767 */
768int v3_asid_validate_path(X509_STORE_CTX *);
769int v3_addr_validate_path(X509_STORE_CTX *);
770int v3_asid_validate_resource_set(STACK_OF(X509) *chain,
771 ASIdentifiers *ext,
772 int allow_inheritance);
773int v3_addr_validate_resource_set(STACK_OF(X509) *chain,
774 IPAddrBlocks *ext,
775 int allow_inheritance);
776 569
777#endif /* OPENSSL_NO_RFC3779 */
778 570
779/* BEGIN ERROR CODES */ 571/* BEGIN ERROR CODES */
780/* The following lines are auto generated by the script mkerr.pl. Any changes 572/* The following lines are auto generated by the script mkerr.pl. Any changes
@@ -785,63 +577,46 @@ void ERR_load_X509V3_strings(void);
785/* Error codes for the X509V3 functions. */ 577/* Error codes for the X509V3 functions. */
786 578
787/* Function codes. */ 579/* Function codes. */
788#define X509V3_F_ASIDENTIFIERCHOICE_CANONIZE 156
789#define X509V3_F_ASIDENTIFIERCHOICE_IS_CANONICAL 157
790#define X509V3_F_COPY_EMAIL 122 580#define X509V3_F_COPY_EMAIL 122
791#define X509V3_F_COPY_ISSUER 123 581#define X509V3_F_COPY_ISSUER 123
792#define X509V3_F_DO_DIRNAME 144
793#define X509V3_F_DO_EXT_CONF 124 582#define X509V3_F_DO_EXT_CONF 124
794#define X509V3_F_DO_EXT_I2D 135 583#define X509V3_F_DO_EXT_I2D 135
795#define X509V3_F_DO_EXT_NCONF 151
796#define X509V3_F_DO_I2V_NAME_CONSTRAINTS 148
797#define X509V3_F_HEX_TO_STRING 111 584#define X509V3_F_HEX_TO_STRING 111
798#define X509V3_F_I2S_ASN1_ENUMERATED 121 585#define X509V3_F_I2S_ASN1_ENUMERATED 121
799#define X509V3_F_I2S_ASN1_IA5STRING 149 586#define X509V3_F_I2S_ASN1_IA5STRING 142
800#define X509V3_F_I2S_ASN1_INTEGER 120 587#define X509V3_F_I2S_ASN1_INTEGER 120
801#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138 588#define X509V3_F_I2V_AUTHORITY_INFO_ACCESS 138
802#define X509V3_F_NOTICE_SECTION 132 589#define X509V3_F_NOTICE_SECTION 132
803#define X509V3_F_NREF_NOS 133 590#define X509V3_F_NREF_NOS 133
804#define X509V3_F_POLICY_SECTION 131 591#define X509V3_F_POLICY_SECTION 131
805#define X509V3_F_PROCESS_PCI_VALUE 150
806#define X509V3_F_R2I_CERTPOL 130 592#define X509V3_F_R2I_CERTPOL 130
807#define X509V3_F_R2I_PCI 155 593#define X509V3_F_R2I_PCI 142
808#define X509V3_F_S2I_ASN1_IA5STRING 100 594#define X509V3_F_S2I_ASN1_IA5STRING 100
809#define X509V3_F_S2I_ASN1_INTEGER 108 595#define X509V3_F_S2I_ASN1_INTEGER 108
810#define X509V3_F_S2I_ASN1_OCTET_STRING 112 596#define X509V3_F_S2I_ASN1_OCTET_STRING 112
811#define X509V3_F_S2I_ASN1_SKEY_ID 114 597#define X509V3_F_S2I_ASN1_SKEY_ID 114
812#define X509V3_F_S2I_SKEY_ID 115 598#define X509V3_F_S2I_S2I_SKEY_ID 115
813#define X509V3_F_STRING_TO_HEX 113 599#define X509V3_F_STRING_TO_HEX 113
814#define X509V3_F_SXNET_ADD_ID_ASC 125 600#define X509V3_F_SXNET_ADD_ASC 125
815#define X509V3_F_SXNET_ADD_ID_INTEGER 126 601#define X509V3_F_SXNET_ADD_ID_INTEGER 126
816#define X509V3_F_SXNET_ADD_ID_ULONG 127 602#define X509V3_F_SXNET_ADD_ID_ULONG 127
817#define X509V3_F_SXNET_GET_ID_ASC 128 603#define X509V3_F_SXNET_GET_ID_ASC 128
818#define X509V3_F_SXNET_GET_ID_ULONG 129 604#define X509V3_F_SXNET_GET_ID_ULONG 129
819#define X509V3_F_V2I_ASIDENTIFIERS 158 605#define X509V3_F_V2I_ACCESS_DESCRIPTION 139
820#define X509V3_F_V2I_ASN1_BIT_STRING 101 606#define X509V3_F_V2I_ASN1_BIT_STRING 101
821#define X509V3_F_V2I_AUTHORITY_INFO_ACCESS 139
822#define X509V3_F_V2I_AUTHORITY_KEYID 119 607#define X509V3_F_V2I_AUTHORITY_KEYID 119
823#define X509V3_F_V2I_BASIC_CONSTRAINTS 102 608#define X509V3_F_V2I_BASIC_CONSTRAINTS 102
824#define X509V3_F_V2I_CRLD 134 609#define X509V3_F_V2I_CRLD 134
825#define X509V3_F_V2I_EXTENDED_KEY_USAGE 103 610#define X509V3_F_V2I_EXT_KU 103
611#define X509V3_F_V2I_GENERAL_NAME 117
826#define X509V3_F_V2I_GENERAL_NAMES 118 612#define X509V3_F_V2I_GENERAL_NAMES 118
827#define X509V3_F_V2I_GENERAL_NAME_EX 117
828#define X509V3_F_V2I_IPADDRBLOCKS 159
829#define X509V3_F_V2I_ISSUER_ALT 153
830#define X509V3_F_V2I_NAME_CONSTRAINTS 147
831#define X509V3_F_V2I_POLICY_CONSTRAINTS 146
832#define X509V3_F_V2I_POLICY_MAPPINGS 145
833#define X509V3_F_V2I_SUBJECT_ALT 154
834#define X509V3_F_V3_ADDR_VALIDATE_PATH_INTERNAL 160
835#define X509V3_F_V3_GENERIC_EXTENSION 116 613#define X509V3_F_V3_GENERIC_EXTENSION 116
836#define X509V3_F_X509V3_ADD1_I2D 140 614#define X509V3_F_X509V3_ADD_I2D 140
837#define X509V3_F_X509V3_ADD_VALUE 105 615#define X509V3_F_X509V3_ADD_VALUE 105
838#define X509V3_F_X509V3_EXT_ADD 104 616#define X509V3_F_X509V3_EXT_ADD 104
839#define X509V3_F_X509V3_EXT_ADD_ALIAS 106 617#define X509V3_F_X509V3_EXT_ADD_ALIAS 106
840#define X509V3_F_X509V3_EXT_CONF 107 618#define X509V3_F_X509V3_EXT_CONF 107
841#define X509V3_F_X509V3_EXT_I2D 136 619#define X509V3_F_X509V3_EXT_I2D 136
842#define X509V3_F_X509V3_EXT_NCONF 152
843#define X509V3_F_X509V3_GET_SECTION 142
844#define X509V3_F_X509V3_GET_STRING 143
845#define X509V3_F_X509V3_GET_VALUE_BOOL 110 620#define X509V3_F_X509V3_GET_VALUE_BOOL 110
846#define X509V3_F_X509V3_PARSE_LIST 109 621#define X509V3_F_X509V3_PARSE_LIST 109
847#define X509V3_F_X509_PURPOSE_ADD 137 622#define X509V3_F_X509_PURPOSE_ADD 137
@@ -852,7 +627,6 @@ void ERR_load_X509V3_strings(void);
852#define X509V3_R_BAD_OBJECT 119 627#define X509V3_R_BAD_OBJECT 119
853#define X509V3_R_BN_DEC2BN_ERROR 100 628#define X509V3_R_BN_DEC2BN_ERROR 100
854#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101 629#define X509V3_R_BN_TO_ASN1_INTEGER_ERROR 101
855#define X509V3_R_DIRNAME_ERROR 149
856#define X509V3_R_DUPLICATE_ZONE_ID 133 630#define X509V3_R_DUPLICATE_ZONE_ID 133
857#define X509V3_R_ERROR_CONVERTING_ZONE 131 631#define X509V3_R_ERROR_CONVERTING_ZONE 131
858#define X509V3_R_ERROR_CREATING_EXTENSION 144 632#define X509V3_R_ERROR_CREATING_EXTENSION 144
@@ -863,15 +637,10 @@ void ERR_load_X509V3_strings(void);
863#define X509V3_R_EXTENSION_NOT_FOUND 102 637#define X509V3_R_EXTENSION_NOT_FOUND 102
864#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103 638#define X509V3_R_EXTENSION_SETTING_NOT_SUPPORTED 103
865#define X509V3_R_EXTENSION_VALUE_ERROR 116 639#define X509V3_R_EXTENSION_VALUE_ERROR 116
866#define X509V3_R_ILLEGAL_EMPTY_EXTENSION 151
867#define X509V3_R_ILLEGAL_HEX_DIGIT 113 640#define X509V3_R_ILLEGAL_HEX_DIGIT 113
868#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 152 641#define X509V3_R_INCORRECT_POLICY_SYNTAX_TAG 153
869#define X509V3_R_INVALID_ASNUMBER 160
870#define X509V3_R_INVALID_ASRANGE 161
871#define X509V3_R_INVALID_BOOLEAN_STRING 104 642#define X509V3_R_INVALID_BOOLEAN_STRING 104
872#define X509V3_R_INVALID_EXTENSION_STRING 105 643#define X509V3_R_INVALID_EXTENSION_STRING 105
873#define X509V3_R_INVALID_INHERITANCE 162
874#define X509V3_R_INVALID_IPADDRESS 163
875#define X509V3_R_INVALID_NAME 106 644#define X509V3_R_INVALID_NAME 106
876#define X509V3_R_INVALID_NULL_ARGUMENT 107 645#define X509V3_R_INVALID_NULL_ARGUMENT 107
877#define X509V3_R_INVALID_NULL_NAME 108 646#define X509V3_R_INVALID_NULL_NAME 108
@@ -881,9 +650,9 @@ void ERR_load_X509V3_strings(void);
881#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110 650#define X509V3_R_INVALID_OBJECT_IDENTIFIER 110
882#define X509V3_R_INVALID_OPTION 138 651#define X509V3_R_INVALID_OPTION 138
883#define X509V3_R_INVALID_POLICY_IDENTIFIER 134 652#define X509V3_R_INVALID_POLICY_IDENTIFIER 134
884#define X509V3_R_INVALID_PROXY_POLICY_SETTING 153 653#define X509V3_R_INVALID_PROXY_POLICY_IDENTIFIER 147
654#define X509V3_R_INVALID_PROXY_POLICY_SETTING 151
885#define X509V3_R_INVALID_PURPOSE 146 655#define X509V3_R_INVALID_PURPOSE 146
886#define X509V3_R_INVALID_SAFI 164
887#define X509V3_R_INVALID_SECTION 135 656#define X509V3_R_INVALID_SECTION 135
888#define X509V3_R_INVALID_SYNTAX 143 657#define X509V3_R_INVALID_SYNTAX 143
889#define X509V3_R_ISSUER_DECODE_ERROR 126 658#define X509V3_R_ISSUER_DECODE_ERROR 126
@@ -893,18 +662,16 @@ void ERR_load_X509V3_strings(void);
893#define X509V3_R_NO_ISSUER_CERTIFICATE 121 662#define X509V3_R_NO_ISSUER_CERTIFICATE 121
894#define X509V3_R_NO_ISSUER_DETAILS 127 663#define X509V3_R_NO_ISSUER_DETAILS 127
895#define X509V3_R_NO_POLICY_IDENTIFIER 139 664#define X509V3_R_NO_POLICY_IDENTIFIER 139
896#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 154 665#define X509V3_R_NO_PROXY_CERT_POLICY_LANGUAGE_DEFINED 148
897#define X509V3_R_NO_PUBLIC_KEY 114 666#define X509V3_R_NO_PUBLIC_KEY 114
898#define X509V3_R_NO_SUBJECT_DETAILS 125 667#define X509V3_R_NO_SUBJECT_DETAILS 125
899#define X509V3_R_ODD_NUMBER_OF_DIGITS 112 668#define X509V3_R_ODD_NUMBER_OF_DIGITS 112
900#define X509V3_R_OPERATION_NOT_DEFINED 148 669#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED 149
901#define X509V3_R_OTHERNAME_ERROR 147 670#define X509V3_R_POLICY_PATH_LENGTH 152
902#define X509V3_R_POLICY_LANGUAGE_ALREADTY_DEFINED 155 671#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED 150
903#define X509V3_R_POLICY_PATH_LENGTH 156 672#define X509V3_R_POLICY_SYNTAX_NOT 154
904#define X509V3_R_POLICY_PATH_LENGTH_ALREADTY_DEFINED 157 673#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED 155
905#define X509V3_R_POLICY_SYNTAX_NOT_CURRENTLY_SUPPORTED 158 674#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 156
906#define X509V3_R_POLICY_WHEN_PROXY_LANGUAGE_REQUIRES_NO_POLICY 159
907#define X509V3_R_SECTION_NOT_FOUND 150
908#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122 675#define X509V3_R_UNABLE_TO_GET_ISSUER_DETAILS 122
909#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123 676#define X509V3_R_UNABLE_TO_GET_ISSUER_KEYID 123
910#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111 677#define X509V3_R_UNKNOWN_BIT_STRING_ARGUMENT 111